Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2006-2007 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 | * Authors: |
| 24 | * Eric Anholt <eric@anholt.net> |
| 25 | */ |
| 26 | |
Jesse Barnes | c1c7af6 | 2009-09-10 15:28:03 -0700 | [diff] [blame] | 27 | #include <linux/module.h> |
| 28 | #include <linux/input.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 29 | #include <linux/i2c.h> |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 30 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 32 | #include <linux/vgaarb.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 33 | #include "drmP.h" |
| 34 | #include "intel_drv.h" |
| 35 | #include "i915_drm.h" |
| 36 | #include "i915_drv.h" |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 37 | #include "i915_trace.h" |
Dave Airlie | ab2c067 | 2009-12-04 10:55:24 +1000 | [diff] [blame] | 38 | #include "drm_dp_helper.h" |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 39 | |
| 40 | #include "drm_crtc_helper.h" |
| 41 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 42 | #define HAS_eDP (intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) |
| 43 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 44 | bool intel_pipe_has_type (struct drm_crtc *crtc, int type); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 45 | static void intel_update_watermarks(struct drm_device *dev); |
Daniel Vetter | 3dec009 | 2010-08-20 21:40:52 +0200 | [diff] [blame] | 46 | static void intel_increase_pllclock(struct drm_crtc *crtc); |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 47 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 48 | |
| 49 | typedef struct { |
| 50 | /* given values */ |
| 51 | int n; |
| 52 | int m1, m2; |
| 53 | int p1, p2; |
| 54 | /* derived values */ |
| 55 | int dot; |
| 56 | int vco; |
| 57 | int m; |
| 58 | int p; |
| 59 | } intel_clock_t; |
| 60 | |
| 61 | typedef struct { |
| 62 | int min, max; |
| 63 | } intel_range_t; |
| 64 | |
| 65 | typedef struct { |
| 66 | int dot_limit; |
| 67 | int p2_slow, p2_fast; |
| 68 | } intel_p2_t; |
| 69 | |
| 70 | #define INTEL_P2_NUM 2 |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 71 | typedef struct intel_limit intel_limit_t; |
| 72 | struct intel_limit { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 73 | intel_range_t dot, vco, n, m, m1, m2, p, p1; |
| 74 | intel_p2_t p2; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 75 | bool (* find_pll)(const intel_limit_t *, struct drm_crtc *, |
| 76 | int, int, intel_clock_t *); |
| 77 | }; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 78 | |
| 79 | #define I8XX_DOT_MIN 25000 |
| 80 | #define I8XX_DOT_MAX 350000 |
| 81 | #define I8XX_VCO_MIN 930000 |
| 82 | #define I8XX_VCO_MAX 1400000 |
| 83 | #define I8XX_N_MIN 3 |
| 84 | #define I8XX_N_MAX 16 |
| 85 | #define I8XX_M_MIN 96 |
| 86 | #define I8XX_M_MAX 140 |
| 87 | #define I8XX_M1_MIN 18 |
| 88 | #define I8XX_M1_MAX 26 |
| 89 | #define I8XX_M2_MIN 6 |
| 90 | #define I8XX_M2_MAX 16 |
| 91 | #define I8XX_P_MIN 4 |
| 92 | #define I8XX_P_MAX 128 |
| 93 | #define I8XX_P1_MIN 2 |
| 94 | #define I8XX_P1_MAX 33 |
| 95 | #define I8XX_P1_LVDS_MIN 1 |
| 96 | #define I8XX_P1_LVDS_MAX 6 |
| 97 | #define I8XX_P2_SLOW 4 |
| 98 | #define I8XX_P2_FAST 2 |
| 99 | #define I8XX_P2_LVDS_SLOW 14 |
ling.ma@intel.com | 0c2e395 | 2009-07-17 11:44:30 +0800 | [diff] [blame] | 100 | #define I8XX_P2_LVDS_FAST 7 |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 101 | #define I8XX_P2_SLOW_LIMIT 165000 |
| 102 | |
| 103 | #define I9XX_DOT_MIN 20000 |
| 104 | #define I9XX_DOT_MAX 400000 |
| 105 | #define I9XX_VCO_MIN 1400000 |
| 106 | #define I9XX_VCO_MAX 2800000 |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 107 | #define PINEVIEW_VCO_MIN 1700000 |
| 108 | #define PINEVIEW_VCO_MAX 3500000 |
Kristian Høgsberg | f3cade5 | 2009-02-13 20:56:50 -0500 | [diff] [blame] | 109 | #define I9XX_N_MIN 1 |
| 110 | #define I9XX_N_MAX 6 |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 111 | /* Pineview's Ncounter is a ring counter */ |
| 112 | #define PINEVIEW_N_MIN 3 |
| 113 | #define PINEVIEW_N_MAX 6 |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 114 | #define I9XX_M_MIN 70 |
| 115 | #define I9XX_M_MAX 120 |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 116 | #define PINEVIEW_M_MIN 2 |
| 117 | #define PINEVIEW_M_MAX 256 |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 118 | #define I9XX_M1_MIN 10 |
Kristian Høgsberg | f3cade5 | 2009-02-13 20:56:50 -0500 | [diff] [blame] | 119 | #define I9XX_M1_MAX 22 |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 120 | #define I9XX_M2_MIN 5 |
| 121 | #define I9XX_M2_MAX 9 |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 122 | /* Pineview M1 is reserved, and must be 0 */ |
| 123 | #define PINEVIEW_M1_MIN 0 |
| 124 | #define PINEVIEW_M1_MAX 0 |
| 125 | #define PINEVIEW_M2_MIN 0 |
| 126 | #define PINEVIEW_M2_MAX 254 |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 127 | #define I9XX_P_SDVO_DAC_MIN 5 |
| 128 | #define I9XX_P_SDVO_DAC_MAX 80 |
| 129 | #define I9XX_P_LVDS_MIN 7 |
| 130 | #define I9XX_P_LVDS_MAX 98 |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 131 | #define PINEVIEW_P_LVDS_MIN 7 |
| 132 | #define PINEVIEW_P_LVDS_MAX 112 |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 133 | #define I9XX_P1_MIN 1 |
| 134 | #define I9XX_P1_MAX 8 |
| 135 | #define I9XX_P2_SDVO_DAC_SLOW 10 |
| 136 | #define I9XX_P2_SDVO_DAC_FAST 5 |
| 137 | #define I9XX_P2_SDVO_DAC_SLOW_LIMIT 200000 |
| 138 | #define I9XX_P2_LVDS_SLOW 14 |
| 139 | #define I9XX_P2_LVDS_FAST 7 |
| 140 | #define I9XX_P2_LVDS_SLOW_LIMIT 112000 |
| 141 | |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 142 | /*The parameter is for SDVO on G4x platform*/ |
| 143 | #define G4X_DOT_SDVO_MIN 25000 |
| 144 | #define G4X_DOT_SDVO_MAX 270000 |
| 145 | #define G4X_VCO_MIN 1750000 |
| 146 | #define G4X_VCO_MAX 3500000 |
| 147 | #define G4X_N_SDVO_MIN 1 |
| 148 | #define G4X_N_SDVO_MAX 4 |
| 149 | #define G4X_M_SDVO_MIN 104 |
| 150 | #define G4X_M_SDVO_MAX 138 |
| 151 | #define G4X_M1_SDVO_MIN 17 |
| 152 | #define G4X_M1_SDVO_MAX 23 |
| 153 | #define G4X_M2_SDVO_MIN 5 |
| 154 | #define G4X_M2_SDVO_MAX 11 |
| 155 | #define G4X_P_SDVO_MIN 10 |
| 156 | #define G4X_P_SDVO_MAX 30 |
| 157 | #define G4X_P1_SDVO_MIN 1 |
| 158 | #define G4X_P1_SDVO_MAX 3 |
| 159 | #define G4X_P2_SDVO_SLOW 10 |
| 160 | #define G4X_P2_SDVO_FAST 10 |
| 161 | #define G4X_P2_SDVO_LIMIT 270000 |
| 162 | |
| 163 | /*The parameter is for HDMI_DAC on G4x platform*/ |
| 164 | #define G4X_DOT_HDMI_DAC_MIN 22000 |
| 165 | #define G4X_DOT_HDMI_DAC_MAX 400000 |
| 166 | #define G4X_N_HDMI_DAC_MIN 1 |
| 167 | #define G4X_N_HDMI_DAC_MAX 4 |
| 168 | #define G4X_M_HDMI_DAC_MIN 104 |
| 169 | #define G4X_M_HDMI_DAC_MAX 138 |
| 170 | #define G4X_M1_HDMI_DAC_MIN 16 |
| 171 | #define G4X_M1_HDMI_DAC_MAX 23 |
| 172 | #define G4X_M2_HDMI_DAC_MIN 5 |
| 173 | #define G4X_M2_HDMI_DAC_MAX 11 |
| 174 | #define G4X_P_HDMI_DAC_MIN 5 |
| 175 | #define G4X_P_HDMI_DAC_MAX 80 |
| 176 | #define G4X_P1_HDMI_DAC_MIN 1 |
| 177 | #define G4X_P1_HDMI_DAC_MAX 8 |
| 178 | #define G4X_P2_HDMI_DAC_SLOW 10 |
| 179 | #define G4X_P2_HDMI_DAC_FAST 5 |
| 180 | #define G4X_P2_HDMI_DAC_LIMIT 165000 |
| 181 | |
| 182 | /*The parameter is for SINGLE_CHANNEL_LVDS on G4x platform*/ |
| 183 | #define G4X_DOT_SINGLE_CHANNEL_LVDS_MIN 20000 |
| 184 | #define G4X_DOT_SINGLE_CHANNEL_LVDS_MAX 115000 |
| 185 | #define G4X_N_SINGLE_CHANNEL_LVDS_MIN 1 |
| 186 | #define G4X_N_SINGLE_CHANNEL_LVDS_MAX 3 |
| 187 | #define G4X_M_SINGLE_CHANNEL_LVDS_MIN 104 |
| 188 | #define G4X_M_SINGLE_CHANNEL_LVDS_MAX 138 |
| 189 | #define G4X_M1_SINGLE_CHANNEL_LVDS_MIN 17 |
| 190 | #define G4X_M1_SINGLE_CHANNEL_LVDS_MAX 23 |
| 191 | #define G4X_M2_SINGLE_CHANNEL_LVDS_MIN 5 |
| 192 | #define G4X_M2_SINGLE_CHANNEL_LVDS_MAX 11 |
| 193 | #define G4X_P_SINGLE_CHANNEL_LVDS_MIN 28 |
| 194 | #define G4X_P_SINGLE_CHANNEL_LVDS_MAX 112 |
| 195 | #define G4X_P1_SINGLE_CHANNEL_LVDS_MIN 2 |
| 196 | #define G4X_P1_SINGLE_CHANNEL_LVDS_MAX 8 |
| 197 | #define G4X_P2_SINGLE_CHANNEL_LVDS_SLOW 14 |
| 198 | #define G4X_P2_SINGLE_CHANNEL_LVDS_FAST 14 |
| 199 | #define G4X_P2_SINGLE_CHANNEL_LVDS_LIMIT 0 |
| 200 | |
| 201 | /*The parameter is for DUAL_CHANNEL_LVDS on G4x platform*/ |
| 202 | #define G4X_DOT_DUAL_CHANNEL_LVDS_MIN 80000 |
| 203 | #define G4X_DOT_DUAL_CHANNEL_LVDS_MAX 224000 |
| 204 | #define G4X_N_DUAL_CHANNEL_LVDS_MIN 1 |
| 205 | #define G4X_N_DUAL_CHANNEL_LVDS_MAX 3 |
| 206 | #define G4X_M_DUAL_CHANNEL_LVDS_MIN 104 |
| 207 | #define G4X_M_DUAL_CHANNEL_LVDS_MAX 138 |
| 208 | #define G4X_M1_DUAL_CHANNEL_LVDS_MIN 17 |
| 209 | #define G4X_M1_DUAL_CHANNEL_LVDS_MAX 23 |
| 210 | #define G4X_M2_DUAL_CHANNEL_LVDS_MIN 5 |
| 211 | #define G4X_M2_DUAL_CHANNEL_LVDS_MAX 11 |
| 212 | #define G4X_P_DUAL_CHANNEL_LVDS_MIN 14 |
| 213 | #define G4X_P_DUAL_CHANNEL_LVDS_MAX 42 |
| 214 | #define G4X_P1_DUAL_CHANNEL_LVDS_MIN 2 |
| 215 | #define G4X_P1_DUAL_CHANNEL_LVDS_MAX 6 |
| 216 | #define G4X_P2_DUAL_CHANNEL_LVDS_SLOW 7 |
| 217 | #define G4X_P2_DUAL_CHANNEL_LVDS_FAST 7 |
| 218 | #define G4X_P2_DUAL_CHANNEL_LVDS_LIMIT 0 |
| 219 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 220 | /*The parameter is for DISPLAY PORT on G4x platform*/ |
| 221 | #define G4X_DOT_DISPLAY_PORT_MIN 161670 |
| 222 | #define G4X_DOT_DISPLAY_PORT_MAX 227000 |
| 223 | #define G4X_N_DISPLAY_PORT_MIN 1 |
| 224 | #define G4X_N_DISPLAY_PORT_MAX 2 |
| 225 | #define G4X_M_DISPLAY_PORT_MIN 97 |
| 226 | #define G4X_M_DISPLAY_PORT_MAX 108 |
| 227 | #define G4X_M1_DISPLAY_PORT_MIN 0x10 |
| 228 | #define G4X_M1_DISPLAY_PORT_MAX 0x12 |
| 229 | #define G4X_M2_DISPLAY_PORT_MIN 0x05 |
| 230 | #define G4X_M2_DISPLAY_PORT_MAX 0x06 |
| 231 | #define G4X_P_DISPLAY_PORT_MIN 10 |
| 232 | #define G4X_P_DISPLAY_PORT_MAX 20 |
| 233 | #define G4X_P1_DISPLAY_PORT_MIN 1 |
| 234 | #define G4X_P1_DISPLAY_PORT_MAX 2 |
| 235 | #define G4X_P2_DISPLAY_PORT_SLOW 10 |
| 236 | #define G4X_P2_DISPLAY_PORT_FAST 10 |
| 237 | #define G4X_P2_DISPLAY_PORT_LIMIT 0 |
| 238 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 239 | /* Ironlake / Sandybridge */ |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 240 | /* as we calculate clock using (register_value + 2) for |
| 241 | N/M1/M2, so here the range value for them is (actual_value-2). |
| 242 | */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 243 | #define IRONLAKE_DOT_MIN 25000 |
| 244 | #define IRONLAKE_DOT_MAX 350000 |
| 245 | #define IRONLAKE_VCO_MIN 1760000 |
| 246 | #define IRONLAKE_VCO_MAX 3510000 |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 247 | #define IRONLAKE_M1_MIN 12 |
Zhao Yakui | a59e385 | 2010-01-06 22:05:57 +0800 | [diff] [blame] | 248 | #define IRONLAKE_M1_MAX 22 |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 249 | #define IRONLAKE_M2_MIN 5 |
| 250 | #define IRONLAKE_M2_MAX 9 |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 251 | #define IRONLAKE_P2_DOT_LIMIT 225000 /* 225Mhz */ |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 252 | |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 253 | /* We have parameter ranges for different type of outputs. */ |
| 254 | |
| 255 | /* DAC & HDMI Refclk 120Mhz */ |
| 256 | #define IRONLAKE_DAC_N_MIN 1 |
| 257 | #define IRONLAKE_DAC_N_MAX 5 |
| 258 | #define IRONLAKE_DAC_M_MIN 79 |
| 259 | #define IRONLAKE_DAC_M_MAX 127 |
| 260 | #define IRONLAKE_DAC_P_MIN 5 |
| 261 | #define IRONLAKE_DAC_P_MAX 80 |
| 262 | #define IRONLAKE_DAC_P1_MIN 1 |
| 263 | #define IRONLAKE_DAC_P1_MAX 8 |
| 264 | #define IRONLAKE_DAC_P2_SLOW 10 |
| 265 | #define IRONLAKE_DAC_P2_FAST 5 |
| 266 | |
| 267 | /* LVDS single-channel 120Mhz refclk */ |
| 268 | #define IRONLAKE_LVDS_S_N_MIN 1 |
| 269 | #define IRONLAKE_LVDS_S_N_MAX 3 |
| 270 | #define IRONLAKE_LVDS_S_M_MIN 79 |
| 271 | #define IRONLAKE_LVDS_S_M_MAX 118 |
| 272 | #define IRONLAKE_LVDS_S_P_MIN 28 |
| 273 | #define IRONLAKE_LVDS_S_P_MAX 112 |
| 274 | #define IRONLAKE_LVDS_S_P1_MIN 2 |
| 275 | #define IRONLAKE_LVDS_S_P1_MAX 8 |
| 276 | #define IRONLAKE_LVDS_S_P2_SLOW 14 |
| 277 | #define IRONLAKE_LVDS_S_P2_FAST 14 |
| 278 | |
| 279 | /* LVDS dual-channel 120Mhz refclk */ |
| 280 | #define IRONLAKE_LVDS_D_N_MIN 1 |
| 281 | #define IRONLAKE_LVDS_D_N_MAX 3 |
| 282 | #define IRONLAKE_LVDS_D_M_MIN 79 |
| 283 | #define IRONLAKE_LVDS_D_M_MAX 127 |
| 284 | #define IRONLAKE_LVDS_D_P_MIN 14 |
| 285 | #define IRONLAKE_LVDS_D_P_MAX 56 |
| 286 | #define IRONLAKE_LVDS_D_P1_MIN 2 |
| 287 | #define IRONLAKE_LVDS_D_P1_MAX 8 |
| 288 | #define IRONLAKE_LVDS_D_P2_SLOW 7 |
| 289 | #define IRONLAKE_LVDS_D_P2_FAST 7 |
| 290 | |
| 291 | /* LVDS single-channel 100Mhz refclk */ |
| 292 | #define IRONLAKE_LVDS_S_SSC_N_MIN 1 |
| 293 | #define IRONLAKE_LVDS_S_SSC_N_MAX 2 |
| 294 | #define IRONLAKE_LVDS_S_SSC_M_MIN 79 |
| 295 | #define IRONLAKE_LVDS_S_SSC_M_MAX 126 |
| 296 | #define IRONLAKE_LVDS_S_SSC_P_MIN 28 |
| 297 | #define IRONLAKE_LVDS_S_SSC_P_MAX 112 |
| 298 | #define IRONLAKE_LVDS_S_SSC_P1_MIN 2 |
| 299 | #define IRONLAKE_LVDS_S_SSC_P1_MAX 8 |
| 300 | #define IRONLAKE_LVDS_S_SSC_P2_SLOW 14 |
| 301 | #define IRONLAKE_LVDS_S_SSC_P2_FAST 14 |
| 302 | |
| 303 | /* LVDS dual-channel 100Mhz refclk */ |
| 304 | #define IRONLAKE_LVDS_D_SSC_N_MIN 1 |
| 305 | #define IRONLAKE_LVDS_D_SSC_N_MAX 3 |
| 306 | #define IRONLAKE_LVDS_D_SSC_M_MIN 79 |
| 307 | #define IRONLAKE_LVDS_D_SSC_M_MAX 126 |
| 308 | #define IRONLAKE_LVDS_D_SSC_P_MIN 14 |
| 309 | #define IRONLAKE_LVDS_D_SSC_P_MAX 42 |
| 310 | #define IRONLAKE_LVDS_D_SSC_P1_MIN 2 |
| 311 | #define IRONLAKE_LVDS_D_SSC_P1_MAX 6 |
| 312 | #define IRONLAKE_LVDS_D_SSC_P2_SLOW 7 |
| 313 | #define IRONLAKE_LVDS_D_SSC_P2_FAST 7 |
| 314 | |
| 315 | /* DisplayPort */ |
| 316 | #define IRONLAKE_DP_N_MIN 1 |
| 317 | #define IRONLAKE_DP_N_MAX 2 |
| 318 | #define IRONLAKE_DP_M_MIN 81 |
| 319 | #define IRONLAKE_DP_M_MAX 90 |
| 320 | #define IRONLAKE_DP_P_MIN 10 |
| 321 | #define IRONLAKE_DP_P_MAX 20 |
| 322 | #define IRONLAKE_DP_P2_FAST 10 |
| 323 | #define IRONLAKE_DP_P2_SLOW 10 |
| 324 | #define IRONLAKE_DP_P2_LIMIT 0 |
| 325 | #define IRONLAKE_DP_P1_MIN 1 |
| 326 | #define IRONLAKE_DP_P1_MAX 2 |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 327 | |
Jesse Barnes | 2377b74 | 2010-07-07 14:06:43 -0700 | [diff] [blame] | 328 | /* FDI */ |
| 329 | #define IRONLAKE_FDI_FREQ 2700000 /* in kHz for mode->clock */ |
| 330 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 331 | static bool |
| 332 | intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, |
| 333 | int target, int refclk, intel_clock_t *best_clock); |
| 334 | static bool |
| 335 | intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, |
| 336 | int target, int refclk, intel_clock_t *best_clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 337 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 338 | static bool |
| 339 | intel_find_pll_g4x_dp(const intel_limit_t *, struct drm_crtc *crtc, |
| 340 | int target, int refclk, intel_clock_t *best_clock); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 341 | static bool |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 342 | intel_find_pll_ironlake_dp(const intel_limit_t *, struct drm_crtc *crtc, |
| 343 | int target, int refclk, intel_clock_t *best_clock); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 344 | |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 345 | static inline u32 /* units of 100MHz */ |
| 346 | intel_fdi_link_freq(struct drm_device *dev) |
| 347 | { |
Chris Wilson | 8b99e68 | 2010-10-13 09:59:17 +0100 | [diff] [blame] | 348 | if (IS_GEN5(dev)) { |
| 349 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 350 | return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2; |
| 351 | } else |
| 352 | return 27; |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 353 | } |
| 354 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 355 | static const intel_limit_t intel_limits_i8xx_dvo = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 356 | .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX }, |
| 357 | .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX }, |
| 358 | .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX }, |
| 359 | .m = { .min = I8XX_M_MIN, .max = I8XX_M_MAX }, |
| 360 | .m1 = { .min = I8XX_M1_MIN, .max = I8XX_M1_MAX }, |
| 361 | .m2 = { .min = I8XX_M2_MIN, .max = I8XX_M2_MAX }, |
| 362 | .p = { .min = I8XX_P_MIN, .max = I8XX_P_MAX }, |
| 363 | .p1 = { .min = I8XX_P1_MIN, .max = I8XX_P1_MAX }, |
| 364 | .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT, |
| 365 | .p2_slow = I8XX_P2_SLOW, .p2_fast = I8XX_P2_FAST }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 366 | .find_pll = intel_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 367 | }; |
| 368 | |
| 369 | static const intel_limit_t intel_limits_i8xx_lvds = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 370 | .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX }, |
| 371 | .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX }, |
| 372 | .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX }, |
| 373 | .m = { .min = I8XX_M_MIN, .max = I8XX_M_MAX }, |
| 374 | .m1 = { .min = I8XX_M1_MIN, .max = I8XX_M1_MAX }, |
| 375 | .m2 = { .min = I8XX_M2_MIN, .max = I8XX_M2_MAX }, |
| 376 | .p = { .min = I8XX_P_MIN, .max = I8XX_P_MAX }, |
| 377 | .p1 = { .min = I8XX_P1_LVDS_MIN, .max = I8XX_P1_LVDS_MAX }, |
| 378 | .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT, |
| 379 | .p2_slow = I8XX_P2_LVDS_SLOW, .p2_fast = I8XX_P2_LVDS_FAST }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 380 | .find_pll = intel_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 381 | }; |
| 382 | |
| 383 | static const intel_limit_t intel_limits_i9xx_sdvo = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 384 | .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX }, |
| 385 | .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX }, |
| 386 | .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX }, |
| 387 | .m = { .min = I9XX_M_MIN, .max = I9XX_M_MAX }, |
| 388 | .m1 = { .min = I9XX_M1_MIN, .max = I9XX_M1_MAX }, |
| 389 | .m2 = { .min = I9XX_M2_MIN, .max = I9XX_M2_MAX }, |
| 390 | .p = { .min = I9XX_P_SDVO_DAC_MIN, .max = I9XX_P_SDVO_DAC_MAX }, |
| 391 | .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX }, |
| 392 | .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT, |
| 393 | .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 394 | .find_pll = intel_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 395 | }; |
| 396 | |
| 397 | static const intel_limit_t intel_limits_i9xx_lvds = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 398 | .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX }, |
| 399 | .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX }, |
| 400 | .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX }, |
| 401 | .m = { .min = I9XX_M_MIN, .max = I9XX_M_MAX }, |
| 402 | .m1 = { .min = I9XX_M1_MIN, .max = I9XX_M1_MAX }, |
| 403 | .m2 = { .min = I9XX_M2_MIN, .max = I9XX_M2_MAX }, |
| 404 | .p = { .min = I9XX_P_LVDS_MIN, .max = I9XX_P_LVDS_MAX }, |
| 405 | .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX }, |
| 406 | /* The single-channel range is 25-112Mhz, and dual-channel |
| 407 | * is 80-224Mhz. Prefer single channel as much as possible. |
| 408 | */ |
| 409 | .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT, |
| 410 | .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_FAST }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 411 | .find_pll = intel_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 412 | }; |
| 413 | |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 414 | /* below parameter and function is for G4X Chipset Family*/ |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 415 | static const intel_limit_t intel_limits_g4x_sdvo = { |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 416 | .dot = { .min = G4X_DOT_SDVO_MIN, .max = G4X_DOT_SDVO_MAX }, |
| 417 | .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX}, |
| 418 | .n = { .min = G4X_N_SDVO_MIN, .max = G4X_N_SDVO_MAX }, |
| 419 | .m = { .min = G4X_M_SDVO_MIN, .max = G4X_M_SDVO_MAX }, |
| 420 | .m1 = { .min = G4X_M1_SDVO_MIN, .max = G4X_M1_SDVO_MAX }, |
| 421 | .m2 = { .min = G4X_M2_SDVO_MIN, .max = G4X_M2_SDVO_MAX }, |
| 422 | .p = { .min = G4X_P_SDVO_MIN, .max = G4X_P_SDVO_MAX }, |
| 423 | .p1 = { .min = G4X_P1_SDVO_MIN, .max = G4X_P1_SDVO_MAX}, |
| 424 | .p2 = { .dot_limit = G4X_P2_SDVO_LIMIT, |
| 425 | .p2_slow = G4X_P2_SDVO_SLOW, |
| 426 | .p2_fast = G4X_P2_SDVO_FAST |
| 427 | }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 428 | .find_pll = intel_g4x_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 429 | }; |
| 430 | |
| 431 | static const intel_limit_t intel_limits_g4x_hdmi = { |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 432 | .dot = { .min = G4X_DOT_HDMI_DAC_MIN, .max = G4X_DOT_HDMI_DAC_MAX }, |
| 433 | .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX}, |
| 434 | .n = { .min = G4X_N_HDMI_DAC_MIN, .max = G4X_N_HDMI_DAC_MAX }, |
| 435 | .m = { .min = G4X_M_HDMI_DAC_MIN, .max = G4X_M_HDMI_DAC_MAX }, |
| 436 | .m1 = { .min = G4X_M1_HDMI_DAC_MIN, .max = G4X_M1_HDMI_DAC_MAX }, |
| 437 | .m2 = { .min = G4X_M2_HDMI_DAC_MIN, .max = G4X_M2_HDMI_DAC_MAX }, |
| 438 | .p = { .min = G4X_P_HDMI_DAC_MIN, .max = G4X_P_HDMI_DAC_MAX }, |
| 439 | .p1 = { .min = G4X_P1_HDMI_DAC_MIN, .max = G4X_P1_HDMI_DAC_MAX}, |
| 440 | .p2 = { .dot_limit = G4X_P2_HDMI_DAC_LIMIT, |
| 441 | .p2_slow = G4X_P2_HDMI_DAC_SLOW, |
| 442 | .p2_fast = G4X_P2_HDMI_DAC_FAST |
| 443 | }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 444 | .find_pll = intel_g4x_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 445 | }; |
| 446 | |
| 447 | static const intel_limit_t intel_limits_g4x_single_channel_lvds = { |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 448 | .dot = { .min = G4X_DOT_SINGLE_CHANNEL_LVDS_MIN, |
| 449 | .max = G4X_DOT_SINGLE_CHANNEL_LVDS_MAX }, |
| 450 | .vco = { .min = G4X_VCO_MIN, |
| 451 | .max = G4X_VCO_MAX }, |
| 452 | .n = { .min = G4X_N_SINGLE_CHANNEL_LVDS_MIN, |
| 453 | .max = G4X_N_SINGLE_CHANNEL_LVDS_MAX }, |
| 454 | .m = { .min = G4X_M_SINGLE_CHANNEL_LVDS_MIN, |
| 455 | .max = G4X_M_SINGLE_CHANNEL_LVDS_MAX }, |
| 456 | .m1 = { .min = G4X_M1_SINGLE_CHANNEL_LVDS_MIN, |
| 457 | .max = G4X_M1_SINGLE_CHANNEL_LVDS_MAX }, |
| 458 | .m2 = { .min = G4X_M2_SINGLE_CHANNEL_LVDS_MIN, |
| 459 | .max = G4X_M2_SINGLE_CHANNEL_LVDS_MAX }, |
| 460 | .p = { .min = G4X_P_SINGLE_CHANNEL_LVDS_MIN, |
| 461 | .max = G4X_P_SINGLE_CHANNEL_LVDS_MAX }, |
| 462 | .p1 = { .min = G4X_P1_SINGLE_CHANNEL_LVDS_MIN, |
| 463 | .max = G4X_P1_SINGLE_CHANNEL_LVDS_MAX }, |
| 464 | .p2 = { .dot_limit = G4X_P2_SINGLE_CHANNEL_LVDS_LIMIT, |
| 465 | .p2_slow = G4X_P2_SINGLE_CHANNEL_LVDS_SLOW, |
| 466 | .p2_fast = G4X_P2_SINGLE_CHANNEL_LVDS_FAST |
| 467 | }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 468 | .find_pll = intel_g4x_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 469 | }; |
| 470 | |
| 471 | static const intel_limit_t intel_limits_g4x_dual_channel_lvds = { |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 472 | .dot = { .min = G4X_DOT_DUAL_CHANNEL_LVDS_MIN, |
| 473 | .max = G4X_DOT_DUAL_CHANNEL_LVDS_MAX }, |
| 474 | .vco = { .min = G4X_VCO_MIN, |
| 475 | .max = G4X_VCO_MAX }, |
| 476 | .n = { .min = G4X_N_DUAL_CHANNEL_LVDS_MIN, |
| 477 | .max = G4X_N_DUAL_CHANNEL_LVDS_MAX }, |
| 478 | .m = { .min = G4X_M_DUAL_CHANNEL_LVDS_MIN, |
| 479 | .max = G4X_M_DUAL_CHANNEL_LVDS_MAX }, |
| 480 | .m1 = { .min = G4X_M1_DUAL_CHANNEL_LVDS_MIN, |
| 481 | .max = G4X_M1_DUAL_CHANNEL_LVDS_MAX }, |
| 482 | .m2 = { .min = G4X_M2_DUAL_CHANNEL_LVDS_MIN, |
| 483 | .max = G4X_M2_DUAL_CHANNEL_LVDS_MAX }, |
| 484 | .p = { .min = G4X_P_DUAL_CHANNEL_LVDS_MIN, |
| 485 | .max = G4X_P_DUAL_CHANNEL_LVDS_MAX }, |
| 486 | .p1 = { .min = G4X_P1_DUAL_CHANNEL_LVDS_MIN, |
| 487 | .max = G4X_P1_DUAL_CHANNEL_LVDS_MAX }, |
| 488 | .p2 = { .dot_limit = G4X_P2_DUAL_CHANNEL_LVDS_LIMIT, |
| 489 | .p2_slow = G4X_P2_DUAL_CHANNEL_LVDS_SLOW, |
| 490 | .p2_fast = G4X_P2_DUAL_CHANNEL_LVDS_FAST |
| 491 | }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 492 | .find_pll = intel_g4x_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 493 | }; |
| 494 | |
| 495 | static const intel_limit_t intel_limits_g4x_display_port = { |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 496 | .dot = { .min = G4X_DOT_DISPLAY_PORT_MIN, |
| 497 | .max = G4X_DOT_DISPLAY_PORT_MAX }, |
| 498 | .vco = { .min = G4X_VCO_MIN, |
| 499 | .max = G4X_VCO_MAX}, |
| 500 | .n = { .min = G4X_N_DISPLAY_PORT_MIN, |
| 501 | .max = G4X_N_DISPLAY_PORT_MAX }, |
| 502 | .m = { .min = G4X_M_DISPLAY_PORT_MIN, |
| 503 | .max = G4X_M_DISPLAY_PORT_MAX }, |
| 504 | .m1 = { .min = G4X_M1_DISPLAY_PORT_MIN, |
| 505 | .max = G4X_M1_DISPLAY_PORT_MAX }, |
| 506 | .m2 = { .min = G4X_M2_DISPLAY_PORT_MIN, |
| 507 | .max = G4X_M2_DISPLAY_PORT_MAX }, |
| 508 | .p = { .min = G4X_P_DISPLAY_PORT_MIN, |
| 509 | .max = G4X_P_DISPLAY_PORT_MAX }, |
| 510 | .p1 = { .min = G4X_P1_DISPLAY_PORT_MIN, |
| 511 | .max = G4X_P1_DISPLAY_PORT_MAX}, |
| 512 | .p2 = { .dot_limit = G4X_P2_DISPLAY_PORT_LIMIT, |
| 513 | .p2_slow = G4X_P2_DISPLAY_PORT_SLOW, |
| 514 | .p2_fast = G4X_P2_DISPLAY_PORT_FAST }, |
| 515 | .find_pll = intel_find_pll_g4x_dp, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 516 | }; |
| 517 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 518 | static const intel_limit_t intel_limits_pineview_sdvo = { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 519 | .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX}, |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 520 | .vco = { .min = PINEVIEW_VCO_MIN, .max = PINEVIEW_VCO_MAX }, |
| 521 | .n = { .min = PINEVIEW_N_MIN, .max = PINEVIEW_N_MAX }, |
| 522 | .m = { .min = PINEVIEW_M_MIN, .max = PINEVIEW_M_MAX }, |
| 523 | .m1 = { .min = PINEVIEW_M1_MIN, .max = PINEVIEW_M1_MAX }, |
| 524 | .m2 = { .min = PINEVIEW_M2_MIN, .max = PINEVIEW_M2_MAX }, |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 525 | .p = { .min = I9XX_P_SDVO_DAC_MIN, .max = I9XX_P_SDVO_DAC_MAX }, |
| 526 | .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX }, |
| 527 | .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT, |
| 528 | .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST }, |
Shaohua Li | 6115707 | 2009-04-03 15:24:43 +0800 | [diff] [blame] | 529 | .find_pll = intel_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 530 | }; |
| 531 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 532 | static const intel_limit_t intel_limits_pineview_lvds = { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 533 | .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX }, |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 534 | .vco = { .min = PINEVIEW_VCO_MIN, .max = PINEVIEW_VCO_MAX }, |
| 535 | .n = { .min = PINEVIEW_N_MIN, .max = PINEVIEW_N_MAX }, |
| 536 | .m = { .min = PINEVIEW_M_MIN, .max = PINEVIEW_M_MAX }, |
| 537 | .m1 = { .min = PINEVIEW_M1_MIN, .max = PINEVIEW_M1_MAX }, |
| 538 | .m2 = { .min = PINEVIEW_M2_MIN, .max = PINEVIEW_M2_MAX }, |
| 539 | .p = { .min = PINEVIEW_P_LVDS_MIN, .max = PINEVIEW_P_LVDS_MAX }, |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 540 | .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX }, |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 541 | /* Pineview only supports single-channel mode. */ |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 542 | .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT, |
| 543 | .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_SLOW }, |
Shaohua Li | 6115707 | 2009-04-03 15:24:43 +0800 | [diff] [blame] | 544 | .find_pll = intel_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 545 | }; |
| 546 | |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 547 | static const intel_limit_t intel_limits_ironlake_dac = { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 548 | .dot = { .min = IRONLAKE_DOT_MIN, .max = IRONLAKE_DOT_MAX }, |
| 549 | .vco = { .min = IRONLAKE_VCO_MIN, .max = IRONLAKE_VCO_MAX }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 550 | .n = { .min = IRONLAKE_DAC_N_MIN, .max = IRONLAKE_DAC_N_MAX }, |
| 551 | .m = { .min = IRONLAKE_DAC_M_MIN, .max = IRONLAKE_DAC_M_MAX }, |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 552 | .m1 = { .min = IRONLAKE_M1_MIN, .max = IRONLAKE_M1_MAX }, |
| 553 | .m2 = { .min = IRONLAKE_M2_MIN, .max = IRONLAKE_M2_MAX }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 554 | .p = { .min = IRONLAKE_DAC_P_MIN, .max = IRONLAKE_DAC_P_MAX }, |
| 555 | .p1 = { .min = IRONLAKE_DAC_P1_MIN, .max = IRONLAKE_DAC_P1_MAX }, |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 556 | .p2 = { .dot_limit = IRONLAKE_P2_DOT_LIMIT, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 557 | .p2_slow = IRONLAKE_DAC_P2_SLOW, |
| 558 | .p2_fast = IRONLAKE_DAC_P2_FAST }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 559 | .find_pll = intel_g4x_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 560 | }; |
| 561 | |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 562 | static const intel_limit_t intel_limits_ironlake_single_lvds = { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 563 | .dot = { .min = IRONLAKE_DOT_MIN, .max = IRONLAKE_DOT_MAX }, |
| 564 | .vco = { .min = IRONLAKE_VCO_MIN, .max = IRONLAKE_VCO_MAX }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 565 | .n = { .min = IRONLAKE_LVDS_S_N_MIN, .max = IRONLAKE_LVDS_S_N_MAX }, |
| 566 | .m = { .min = IRONLAKE_LVDS_S_M_MIN, .max = IRONLAKE_LVDS_S_M_MAX }, |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 567 | .m1 = { .min = IRONLAKE_M1_MIN, .max = IRONLAKE_M1_MAX }, |
| 568 | .m2 = { .min = IRONLAKE_M2_MIN, .max = IRONLAKE_M2_MAX }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 569 | .p = { .min = IRONLAKE_LVDS_S_P_MIN, .max = IRONLAKE_LVDS_S_P_MAX }, |
| 570 | .p1 = { .min = IRONLAKE_LVDS_S_P1_MIN, .max = IRONLAKE_LVDS_S_P1_MAX }, |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 571 | .p2 = { .dot_limit = IRONLAKE_P2_DOT_LIMIT, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 572 | .p2_slow = IRONLAKE_LVDS_S_P2_SLOW, |
| 573 | .p2_fast = IRONLAKE_LVDS_S_P2_FAST }, |
| 574 | .find_pll = intel_g4x_find_best_PLL, |
| 575 | }; |
| 576 | |
| 577 | static const intel_limit_t intel_limits_ironlake_dual_lvds = { |
| 578 | .dot = { .min = IRONLAKE_DOT_MIN, .max = IRONLAKE_DOT_MAX }, |
| 579 | .vco = { .min = IRONLAKE_VCO_MIN, .max = IRONLAKE_VCO_MAX }, |
| 580 | .n = { .min = IRONLAKE_LVDS_D_N_MIN, .max = IRONLAKE_LVDS_D_N_MAX }, |
| 581 | .m = { .min = IRONLAKE_LVDS_D_M_MIN, .max = IRONLAKE_LVDS_D_M_MAX }, |
| 582 | .m1 = { .min = IRONLAKE_M1_MIN, .max = IRONLAKE_M1_MAX }, |
| 583 | .m2 = { .min = IRONLAKE_M2_MIN, .max = IRONLAKE_M2_MAX }, |
| 584 | .p = { .min = IRONLAKE_LVDS_D_P_MIN, .max = IRONLAKE_LVDS_D_P_MAX }, |
| 585 | .p1 = { .min = IRONLAKE_LVDS_D_P1_MIN, .max = IRONLAKE_LVDS_D_P1_MAX }, |
| 586 | .p2 = { .dot_limit = IRONLAKE_P2_DOT_LIMIT, |
| 587 | .p2_slow = IRONLAKE_LVDS_D_P2_SLOW, |
| 588 | .p2_fast = IRONLAKE_LVDS_D_P2_FAST }, |
| 589 | .find_pll = intel_g4x_find_best_PLL, |
| 590 | }; |
| 591 | |
| 592 | static const intel_limit_t intel_limits_ironlake_single_lvds_100m = { |
| 593 | .dot = { .min = IRONLAKE_DOT_MIN, .max = IRONLAKE_DOT_MAX }, |
| 594 | .vco = { .min = IRONLAKE_VCO_MIN, .max = IRONLAKE_VCO_MAX }, |
| 595 | .n = { .min = IRONLAKE_LVDS_S_SSC_N_MIN, .max = IRONLAKE_LVDS_S_SSC_N_MAX }, |
| 596 | .m = { .min = IRONLAKE_LVDS_S_SSC_M_MIN, .max = IRONLAKE_LVDS_S_SSC_M_MAX }, |
| 597 | .m1 = { .min = IRONLAKE_M1_MIN, .max = IRONLAKE_M1_MAX }, |
| 598 | .m2 = { .min = IRONLAKE_M2_MIN, .max = IRONLAKE_M2_MAX }, |
| 599 | .p = { .min = IRONLAKE_LVDS_S_SSC_P_MIN, .max = IRONLAKE_LVDS_S_SSC_P_MAX }, |
| 600 | .p1 = { .min = IRONLAKE_LVDS_S_SSC_P1_MIN,.max = IRONLAKE_LVDS_S_SSC_P1_MAX }, |
| 601 | .p2 = { .dot_limit = IRONLAKE_P2_DOT_LIMIT, |
| 602 | .p2_slow = IRONLAKE_LVDS_S_SSC_P2_SLOW, |
| 603 | .p2_fast = IRONLAKE_LVDS_S_SSC_P2_FAST }, |
| 604 | .find_pll = intel_g4x_find_best_PLL, |
| 605 | }; |
| 606 | |
| 607 | static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = { |
| 608 | .dot = { .min = IRONLAKE_DOT_MIN, .max = IRONLAKE_DOT_MAX }, |
| 609 | .vco = { .min = IRONLAKE_VCO_MIN, .max = IRONLAKE_VCO_MAX }, |
| 610 | .n = { .min = IRONLAKE_LVDS_D_SSC_N_MIN, .max = IRONLAKE_LVDS_D_SSC_N_MAX }, |
| 611 | .m = { .min = IRONLAKE_LVDS_D_SSC_M_MIN, .max = IRONLAKE_LVDS_D_SSC_M_MAX }, |
| 612 | .m1 = { .min = IRONLAKE_M1_MIN, .max = IRONLAKE_M1_MAX }, |
| 613 | .m2 = { .min = IRONLAKE_M2_MIN, .max = IRONLAKE_M2_MAX }, |
| 614 | .p = { .min = IRONLAKE_LVDS_D_SSC_P_MIN, .max = IRONLAKE_LVDS_D_SSC_P_MAX }, |
| 615 | .p1 = { .min = IRONLAKE_LVDS_D_SSC_P1_MIN,.max = IRONLAKE_LVDS_D_SSC_P1_MAX }, |
| 616 | .p2 = { .dot_limit = IRONLAKE_P2_DOT_LIMIT, |
| 617 | .p2_slow = IRONLAKE_LVDS_D_SSC_P2_SLOW, |
| 618 | .p2_fast = IRONLAKE_LVDS_D_SSC_P2_FAST }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 619 | .find_pll = intel_g4x_find_best_PLL, |
| 620 | }; |
| 621 | |
| 622 | static const intel_limit_t intel_limits_ironlake_display_port = { |
| 623 | .dot = { .min = IRONLAKE_DOT_MIN, |
| 624 | .max = IRONLAKE_DOT_MAX }, |
| 625 | .vco = { .min = IRONLAKE_VCO_MIN, |
| 626 | .max = IRONLAKE_VCO_MAX}, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 627 | .n = { .min = IRONLAKE_DP_N_MIN, |
| 628 | .max = IRONLAKE_DP_N_MAX }, |
| 629 | .m = { .min = IRONLAKE_DP_M_MIN, |
| 630 | .max = IRONLAKE_DP_M_MAX }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 631 | .m1 = { .min = IRONLAKE_M1_MIN, |
| 632 | .max = IRONLAKE_M1_MAX }, |
| 633 | .m2 = { .min = IRONLAKE_M2_MIN, |
| 634 | .max = IRONLAKE_M2_MAX }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 635 | .p = { .min = IRONLAKE_DP_P_MIN, |
| 636 | .max = IRONLAKE_DP_P_MAX }, |
| 637 | .p1 = { .min = IRONLAKE_DP_P1_MIN, |
| 638 | .max = IRONLAKE_DP_P1_MAX}, |
| 639 | .p2 = { .dot_limit = IRONLAKE_DP_P2_LIMIT, |
| 640 | .p2_slow = IRONLAKE_DP_P2_SLOW, |
| 641 | .p2_fast = IRONLAKE_DP_P2_FAST }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 642 | .find_pll = intel_find_pll_ironlake_dp, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 643 | }; |
| 644 | |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 645 | static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc, |
| 646 | int refclk) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 647 | { |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 648 | struct drm_device *dev = crtc->dev; |
| 649 | struct drm_i915_private *dev_priv = dev->dev_private; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 650 | const intel_limit_t *limit; |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 651 | |
| 652 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 653 | if ((I915_READ(PCH_LVDS) & LVDS_CLKB_POWER_MASK) == |
| 654 | LVDS_CLKB_POWER_UP) { |
| 655 | /* LVDS dual channel */ |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 656 | if (refclk == 100000) |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 657 | limit = &intel_limits_ironlake_dual_lvds_100m; |
| 658 | else |
| 659 | limit = &intel_limits_ironlake_dual_lvds; |
| 660 | } else { |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 661 | if (refclk == 100000) |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 662 | limit = &intel_limits_ironlake_single_lvds_100m; |
| 663 | else |
| 664 | limit = &intel_limits_ironlake_single_lvds; |
| 665 | } |
| 666 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 667 | HAS_eDP) |
| 668 | limit = &intel_limits_ironlake_display_port; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 669 | else |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 670 | limit = &intel_limits_ironlake_dac; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 671 | |
| 672 | return limit; |
| 673 | } |
| 674 | |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 675 | static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc) |
| 676 | { |
| 677 | struct drm_device *dev = crtc->dev; |
| 678 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 679 | const intel_limit_t *limit; |
| 680 | |
| 681 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
| 682 | if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) == |
| 683 | LVDS_CLKB_POWER_UP) |
| 684 | /* LVDS with dual channel */ |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 685 | limit = &intel_limits_g4x_dual_channel_lvds; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 686 | else |
| 687 | /* LVDS with dual channel */ |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 688 | limit = &intel_limits_g4x_single_channel_lvds; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 689 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) || |
| 690 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 691 | limit = &intel_limits_g4x_hdmi; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 692 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 693 | limit = &intel_limits_g4x_sdvo; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 694 | } else if (intel_pipe_has_type (crtc, INTEL_OUTPUT_DISPLAYPORT)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 695 | limit = &intel_limits_g4x_display_port; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 696 | } else /* The option is for other outputs */ |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 697 | limit = &intel_limits_i9xx_sdvo; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 698 | |
| 699 | return limit; |
| 700 | } |
| 701 | |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 702 | static const intel_limit_t *intel_limit(struct drm_crtc *crtc, int refclk) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 703 | { |
| 704 | struct drm_device *dev = crtc->dev; |
| 705 | const intel_limit_t *limit; |
| 706 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 707 | if (HAS_PCH_SPLIT(dev)) |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 708 | limit = intel_ironlake_limit(crtc, refclk); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 709 | else if (IS_G4X(dev)) { |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 710 | limit = intel_g4x_limit(crtc); |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 711 | } else if (IS_PINEVIEW(dev)) { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 712 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 713 | limit = &intel_limits_pineview_lvds; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 714 | else |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 715 | limit = &intel_limits_pineview_sdvo; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 716 | } else if (!IS_GEN2(dev)) { |
| 717 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) |
| 718 | limit = &intel_limits_i9xx_lvds; |
| 719 | else |
| 720 | limit = &intel_limits_i9xx_sdvo; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 721 | } else { |
| 722 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 723 | limit = &intel_limits_i8xx_lvds; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 724 | else |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 725 | limit = &intel_limits_i8xx_dvo; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 726 | } |
| 727 | return limit; |
| 728 | } |
| 729 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 730 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
| 731 | static void pineview_clock(int refclk, intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 732 | { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 733 | clock->m = clock->m2 + 2; |
| 734 | clock->p = clock->p1 * clock->p2; |
| 735 | clock->vco = refclk * clock->m / clock->n; |
| 736 | clock->dot = clock->vco / clock->p; |
| 737 | } |
| 738 | |
| 739 | static void intel_clock(struct drm_device *dev, int refclk, intel_clock_t *clock) |
| 740 | { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 741 | if (IS_PINEVIEW(dev)) { |
| 742 | pineview_clock(refclk, clock); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 743 | return; |
| 744 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 745 | clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2); |
| 746 | clock->p = clock->p1 * clock->p2; |
| 747 | clock->vco = refclk * clock->m / (clock->n + 2); |
| 748 | clock->dot = clock->vco / clock->p; |
| 749 | } |
| 750 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 751 | /** |
| 752 | * Returns whether any output on the specified pipe is of the specified type |
| 753 | */ |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 754 | bool intel_pipe_has_type(struct drm_crtc *crtc, int type) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 755 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 756 | struct drm_device *dev = crtc->dev; |
| 757 | struct drm_mode_config *mode_config = &dev->mode_config; |
| 758 | struct intel_encoder *encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 759 | |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 760 | list_for_each_entry(encoder, &mode_config->encoder_list, base.head) |
| 761 | if (encoder->base.crtc == crtc && encoder->type == type) |
| 762 | return true; |
| 763 | |
| 764 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 765 | } |
| 766 | |
Jesse Barnes | 7c04d1d | 2009-02-23 15:36:40 -0800 | [diff] [blame] | 767 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 768 | /** |
| 769 | * Returns whether the given set of divisors are valid for a given refclk with |
| 770 | * the given connectors. |
| 771 | */ |
| 772 | |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 773 | static bool intel_PLL_is_valid(struct drm_device *dev, |
| 774 | const intel_limit_t *limit, |
| 775 | const intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 776 | { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 777 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
| 778 | INTELPllInvalid ("p1 out of range\n"); |
| 779 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
| 780 | INTELPllInvalid ("p out of range\n"); |
| 781 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
| 782 | INTELPllInvalid ("m2 out of range\n"); |
| 783 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
| 784 | INTELPllInvalid ("m1 out of range\n"); |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 785 | if (clock->m1 <= clock->m2 && !IS_PINEVIEW(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 786 | INTELPllInvalid ("m1 <= m2\n"); |
| 787 | if (clock->m < limit->m.min || limit->m.max < clock->m) |
| 788 | INTELPllInvalid ("m out of range\n"); |
| 789 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
| 790 | INTELPllInvalid ("n out of range\n"); |
| 791 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
| 792 | INTELPllInvalid ("vco out of range\n"); |
| 793 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
| 794 | * connector, etc., rather than just a single range. |
| 795 | */ |
| 796 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) |
| 797 | INTELPllInvalid ("dot out of range\n"); |
| 798 | |
| 799 | return true; |
| 800 | } |
| 801 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 802 | static bool |
| 803 | intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, |
| 804 | int target, int refclk, intel_clock_t *best_clock) |
| 805 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 806 | { |
| 807 | struct drm_device *dev = crtc->dev; |
| 808 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 809 | intel_clock_t clock; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 810 | int err = target; |
| 811 | |
Bruno Prémont | bc5e571 | 2009-08-08 13:01:17 +0200 | [diff] [blame] | 812 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) && |
Florian Mickler | 832cc28 | 2009-07-13 18:40:32 +0800 | [diff] [blame] | 813 | (I915_READ(LVDS)) != 0) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 814 | /* |
| 815 | * For LVDS, if the panel is on, just rely on its current |
| 816 | * settings for dual-channel. We haven't figured out how to |
| 817 | * reliably set up different single/dual channel state, if we |
| 818 | * even can. |
| 819 | */ |
| 820 | if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) == |
| 821 | LVDS_CLKB_POWER_UP) |
| 822 | clock.p2 = limit->p2.p2_fast; |
| 823 | else |
| 824 | clock.p2 = limit->p2.p2_slow; |
| 825 | } else { |
| 826 | if (target < limit->p2.dot_limit) |
| 827 | clock.p2 = limit->p2.p2_slow; |
| 828 | else |
| 829 | clock.p2 = limit->p2.p2_fast; |
| 830 | } |
| 831 | |
| 832 | memset (best_clock, 0, sizeof (*best_clock)); |
| 833 | |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 834 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 835 | clock.m1++) { |
| 836 | for (clock.m2 = limit->m2.min; |
| 837 | clock.m2 <= limit->m2.max; clock.m2++) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 838 | /* m1 is always 0 in Pineview */ |
| 839 | if (clock.m2 >= clock.m1 && !IS_PINEVIEW(dev)) |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 840 | break; |
| 841 | for (clock.n = limit->n.min; |
| 842 | clock.n <= limit->n.max; clock.n++) { |
| 843 | for (clock.p1 = limit->p1.min; |
| 844 | clock.p1 <= limit->p1.max; clock.p1++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 845 | int this_err; |
| 846 | |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 847 | intel_clock(dev, refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 848 | if (!intel_PLL_is_valid(dev, limit, |
| 849 | &clock)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 850 | continue; |
| 851 | |
| 852 | this_err = abs(clock.dot - target); |
| 853 | if (this_err < err) { |
| 854 | *best_clock = clock; |
| 855 | err = this_err; |
| 856 | } |
| 857 | } |
| 858 | } |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | return (err != target); |
| 863 | } |
| 864 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 865 | static bool |
| 866 | intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, |
| 867 | int target, int refclk, intel_clock_t *best_clock) |
| 868 | { |
| 869 | struct drm_device *dev = crtc->dev; |
| 870 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 871 | intel_clock_t clock; |
| 872 | int max_n; |
| 873 | bool found; |
Adam Jackson | 6ba770d | 2010-07-02 16:43:30 -0400 | [diff] [blame] | 874 | /* approximately equals target * 0.00585 */ |
| 875 | int err_most = (target >> 8) + (target >> 9); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 876 | found = false; |
| 877 | |
| 878 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 879 | int lvds_reg; |
| 880 | |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 881 | if (HAS_PCH_SPLIT(dev)) |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 882 | lvds_reg = PCH_LVDS; |
| 883 | else |
| 884 | lvds_reg = LVDS; |
| 885 | if ((I915_READ(lvds_reg) & LVDS_CLKB_POWER_MASK) == |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 886 | LVDS_CLKB_POWER_UP) |
| 887 | clock.p2 = limit->p2.p2_fast; |
| 888 | else |
| 889 | clock.p2 = limit->p2.p2_slow; |
| 890 | } else { |
| 891 | if (target < limit->p2.dot_limit) |
| 892 | clock.p2 = limit->p2.p2_slow; |
| 893 | else |
| 894 | clock.p2 = limit->p2.p2_fast; |
| 895 | } |
| 896 | |
| 897 | memset(best_clock, 0, sizeof(*best_clock)); |
| 898 | max_n = limit->n.max; |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 899 | /* based on hardware requirement, prefer smaller n to precision */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 900 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 901 | /* based on hardware requirement, prefere larger m1,m2 */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 902 | for (clock.m1 = limit->m1.max; |
| 903 | clock.m1 >= limit->m1.min; clock.m1--) { |
| 904 | for (clock.m2 = limit->m2.max; |
| 905 | clock.m2 >= limit->m2.min; clock.m2--) { |
| 906 | for (clock.p1 = limit->p1.max; |
| 907 | clock.p1 >= limit->p1.min; clock.p1--) { |
| 908 | int this_err; |
| 909 | |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 910 | intel_clock(dev, refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 911 | if (!intel_PLL_is_valid(dev, limit, |
| 912 | &clock)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 913 | continue; |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 914 | |
| 915 | this_err = abs(clock.dot - target); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 916 | if (this_err < err_most) { |
| 917 | *best_clock = clock; |
| 918 | err_most = this_err; |
| 919 | max_n = clock.n; |
| 920 | found = true; |
| 921 | } |
| 922 | } |
| 923 | } |
| 924 | } |
| 925 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 926 | return found; |
| 927 | } |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 928 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 929 | static bool |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 930 | intel_find_pll_ironlake_dp(const intel_limit_t *limit, struct drm_crtc *crtc, |
| 931 | int target, int refclk, intel_clock_t *best_clock) |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 932 | { |
| 933 | struct drm_device *dev = crtc->dev; |
| 934 | intel_clock_t clock; |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 935 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 936 | if (target < 200000) { |
| 937 | clock.n = 1; |
| 938 | clock.p1 = 2; |
| 939 | clock.p2 = 10; |
| 940 | clock.m1 = 12; |
| 941 | clock.m2 = 9; |
| 942 | } else { |
| 943 | clock.n = 2; |
| 944 | clock.p1 = 1; |
| 945 | clock.p2 = 10; |
| 946 | clock.m1 = 14; |
| 947 | clock.m2 = 8; |
| 948 | } |
| 949 | intel_clock(dev, refclk, &clock); |
| 950 | memcpy(best_clock, &clock, sizeof(intel_clock_t)); |
| 951 | return true; |
| 952 | } |
| 953 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 954 | /* DisplayPort has only two frequencies, 162MHz and 270MHz */ |
| 955 | static bool |
| 956 | intel_find_pll_g4x_dp(const intel_limit_t *limit, struct drm_crtc *crtc, |
| 957 | int target, int refclk, intel_clock_t *best_clock) |
| 958 | { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 959 | intel_clock_t clock; |
| 960 | if (target < 200000) { |
| 961 | clock.p1 = 2; |
| 962 | clock.p2 = 10; |
| 963 | clock.n = 2; |
| 964 | clock.m1 = 23; |
| 965 | clock.m2 = 8; |
| 966 | } else { |
| 967 | clock.p1 = 1; |
| 968 | clock.p2 = 10; |
| 969 | clock.n = 1; |
| 970 | clock.m1 = 14; |
| 971 | clock.m2 = 2; |
| 972 | } |
| 973 | clock.m = 5 * (clock.m1 + 2) + (clock.m2 + 2); |
| 974 | clock.p = (clock.p1 * clock.p2); |
| 975 | clock.dot = 96000 * clock.m / (clock.n + 2) / clock.p; |
| 976 | clock.vco = 0; |
| 977 | memcpy(best_clock, &clock, sizeof(intel_clock_t)); |
| 978 | return true; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 979 | } |
| 980 | |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 981 | /** |
| 982 | * intel_wait_for_vblank - wait for vblank on a given pipe |
| 983 | * @dev: drm device |
| 984 | * @pipe: pipe to wait for |
| 985 | * |
| 986 | * Wait for vblank to occur on a given pipe. Needed for various bits of |
| 987 | * mode setting code. |
| 988 | */ |
| 989 | void intel_wait_for_vblank(struct drm_device *dev, int pipe) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 990 | { |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 991 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 992 | int pipestat_reg = (pipe == 0 ? PIPEASTAT : PIPEBSTAT); |
| 993 | |
Chris Wilson | 300387c | 2010-09-05 20:25:43 +0100 | [diff] [blame] | 994 | /* Clear existing vblank status. Note this will clear any other |
| 995 | * sticky status fields as well. |
| 996 | * |
| 997 | * This races with i915_driver_irq_handler() with the result |
| 998 | * that either function could miss a vblank event. Here it is not |
| 999 | * fatal, as we will either wait upon the next vblank interrupt or |
| 1000 | * timeout. Generally speaking intel_wait_for_vblank() is only |
| 1001 | * called during modeset at which time the GPU should be idle and |
| 1002 | * should *not* be performing page flips and thus not waiting on |
| 1003 | * vblanks... |
| 1004 | * Currently, the result of us stealing a vblank from the irq |
| 1005 | * handler is that a single frame will be skipped during swapbuffers. |
| 1006 | */ |
| 1007 | I915_WRITE(pipestat_reg, |
| 1008 | I915_READ(pipestat_reg) | PIPE_VBLANK_INTERRUPT_STATUS); |
| 1009 | |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1010 | /* Wait for vblank interrupt bit to set */ |
Chris Wilson | 481b6af | 2010-08-23 17:43:35 +0100 | [diff] [blame] | 1011 | if (wait_for(I915_READ(pipestat_reg) & |
| 1012 | PIPE_VBLANK_INTERRUPT_STATUS, |
| 1013 | 50)) |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1014 | DRM_DEBUG_KMS("vblank wait timed out\n"); |
| 1015 | } |
| 1016 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1017 | /* |
| 1018 | * intel_wait_for_pipe_off - wait for pipe to turn off |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1019 | * @dev: drm device |
| 1020 | * @pipe: pipe to wait for |
| 1021 | * |
| 1022 | * After disabling a pipe, we can't wait for vblank in the usual way, |
| 1023 | * spinning on the vblank interrupt status bit, since we won't actually |
| 1024 | * see an interrupt when the pipe is disabled. |
| 1025 | * |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1026 | * On Gen4 and above: |
| 1027 | * wait for the pipe register state bit to turn off |
| 1028 | * |
| 1029 | * Otherwise: |
| 1030 | * wait for the display line value to settle (it usually |
| 1031 | * ends up stopping at the start of the next frame). |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1032 | * |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1033 | */ |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1034 | void intel_wait_for_pipe_off(struct drm_device *dev, int pipe) |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1035 | { |
| 1036 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1037 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1038 | if (INTEL_INFO(dev)->gen >= 4) { |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1039 | int reg = PIPECONF(pipe); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1040 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1041 | /* Wait for the Pipe State to go off */ |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1042 | if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, |
| 1043 | 100)) |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1044 | DRM_DEBUG_KMS("pipe_off wait timed out\n"); |
| 1045 | } else { |
| 1046 | u32 last_line; |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1047 | int reg = PIPEDSL(pipe); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1048 | unsigned long timeout = jiffies + msecs_to_jiffies(100); |
| 1049 | |
| 1050 | /* Wait for the display line to settle */ |
| 1051 | do { |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1052 | last_line = I915_READ(reg) & DSL_LINEMASK; |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1053 | mdelay(5); |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1054 | } while (((I915_READ(reg) & DSL_LINEMASK) != last_line) && |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1055 | time_after(timeout, jiffies)); |
| 1056 | if (time_after(jiffies, timeout)) |
| 1057 | DRM_DEBUG_KMS("pipe_off wait timed out\n"); |
| 1058 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1059 | } |
| 1060 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1061 | static void i8xx_enable_fbc(struct drm_crtc *crtc, unsigned long interval) |
| 1062 | { |
| 1063 | struct drm_device *dev = crtc->dev; |
| 1064 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1065 | struct drm_framebuffer *fb = crtc->fb; |
| 1066 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1067 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1068 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1069 | int plane, i; |
| 1070 | u32 fbc_ctl, fbc_ctl2; |
| 1071 | |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1072 | if (fb->pitch == dev_priv->cfb_pitch && |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1073 | obj->fence_reg == dev_priv->cfb_fence && |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1074 | intel_crtc->plane == dev_priv->cfb_plane && |
| 1075 | I915_READ(FBC_CONTROL) & FBC_CTL_EN) |
| 1076 | return; |
| 1077 | |
| 1078 | i8xx_disable_fbc(dev); |
| 1079 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1080 | dev_priv->cfb_pitch = dev_priv->cfb_size / FBC_LL_SIZE; |
| 1081 | |
| 1082 | if (fb->pitch < dev_priv->cfb_pitch) |
| 1083 | dev_priv->cfb_pitch = fb->pitch; |
| 1084 | |
| 1085 | /* FBC_CTL wants 64B units */ |
| 1086 | dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1087 | dev_priv->cfb_fence = obj->fence_reg; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1088 | dev_priv->cfb_plane = intel_crtc->plane; |
| 1089 | plane = dev_priv->cfb_plane == 0 ? FBC_CTL_PLANEA : FBC_CTL_PLANEB; |
| 1090 | |
| 1091 | /* Clear old tags */ |
| 1092 | for (i = 0; i < (FBC_LL_SIZE / 32) + 1; i++) |
| 1093 | I915_WRITE(FBC_TAG + (i * 4), 0); |
| 1094 | |
| 1095 | /* Set it up... */ |
| 1096 | fbc_ctl2 = FBC_CTL_FENCE_DBL | FBC_CTL_IDLE_IMM | plane; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1097 | if (obj->tiling_mode != I915_TILING_NONE) |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1098 | fbc_ctl2 |= FBC_CTL_CPU_FENCE; |
| 1099 | I915_WRITE(FBC_CONTROL2, fbc_ctl2); |
| 1100 | I915_WRITE(FBC_FENCE_OFF, crtc->y); |
| 1101 | |
| 1102 | /* enable it... */ |
| 1103 | fbc_ctl = FBC_CTL_EN | FBC_CTL_PERIODIC; |
Jesse Barnes | ee25df2 | 2010-02-06 10:41:53 -0800 | [diff] [blame] | 1104 | if (IS_I945GM(dev)) |
Priit Laes | 4967790 | 2010-03-02 11:37:00 +0200 | [diff] [blame] | 1105 | fbc_ctl |= FBC_CTL_C3_IDLE; /* 945 needs special SR handling */ |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1106 | fbc_ctl |= (dev_priv->cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT; |
| 1107 | fbc_ctl |= (interval & 0x2fff) << FBC_CTL_INTERVAL_SHIFT; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1108 | if (obj->tiling_mode != I915_TILING_NONE) |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1109 | fbc_ctl |= dev_priv->cfb_fence; |
| 1110 | I915_WRITE(FBC_CONTROL, fbc_ctl); |
| 1111 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1112 | DRM_DEBUG_KMS("enabled FBC, pitch %ld, yoff %d, plane %d, ", |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1113 | dev_priv->cfb_pitch, crtc->y, dev_priv->cfb_plane); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | void i8xx_disable_fbc(struct drm_device *dev) |
| 1117 | { |
| 1118 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1119 | u32 fbc_ctl; |
| 1120 | |
| 1121 | /* Disable compression */ |
| 1122 | fbc_ctl = I915_READ(FBC_CONTROL); |
Chris Wilson | a5cad62 | 2010-09-22 13:15:10 +0100 | [diff] [blame] | 1123 | if ((fbc_ctl & FBC_CTL_EN) == 0) |
| 1124 | return; |
| 1125 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1126 | fbc_ctl &= ~FBC_CTL_EN; |
| 1127 | I915_WRITE(FBC_CONTROL, fbc_ctl); |
| 1128 | |
| 1129 | /* Wait for compressing bit to clear */ |
Chris Wilson | 481b6af | 2010-08-23 17:43:35 +0100 | [diff] [blame] | 1130 | if (wait_for((I915_READ(FBC_STATUS) & FBC_STAT_COMPRESSING) == 0, 10)) { |
Chris Wilson | 913d8d1 | 2010-08-07 11:01:35 +0100 | [diff] [blame] | 1131 | DRM_DEBUG_KMS("FBC idle timed out\n"); |
| 1132 | return; |
Jesse Barnes | 9517a92 | 2010-05-21 09:40:45 -0700 | [diff] [blame] | 1133 | } |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1134 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1135 | DRM_DEBUG_KMS("disabled FBC\n"); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1136 | } |
| 1137 | |
Adam Jackson | ee5382a | 2010-04-23 11:17:39 -0400 | [diff] [blame] | 1138 | static bool i8xx_fbc_enabled(struct drm_device *dev) |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1139 | { |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1140 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1141 | |
| 1142 | return I915_READ(FBC_CONTROL) & FBC_CTL_EN; |
| 1143 | } |
| 1144 | |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 1145 | static void g4x_enable_fbc(struct drm_crtc *crtc, unsigned long interval) |
| 1146 | { |
| 1147 | struct drm_device *dev = crtc->dev; |
| 1148 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1149 | struct drm_framebuffer *fb = crtc->fb; |
| 1150 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1151 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 1152 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1153 | int plane = intel_crtc->plane == 0 ? DPFC_CTL_PLANEA : DPFC_CTL_PLANEB; |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 1154 | unsigned long stall_watermark = 200; |
| 1155 | u32 dpfc_ctl; |
| 1156 | |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1157 | dpfc_ctl = I915_READ(DPFC_CONTROL); |
| 1158 | if (dpfc_ctl & DPFC_CTL_EN) { |
| 1159 | if (dev_priv->cfb_pitch == dev_priv->cfb_pitch / 64 - 1 && |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1160 | dev_priv->cfb_fence == obj->fence_reg && |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1161 | dev_priv->cfb_plane == intel_crtc->plane && |
| 1162 | dev_priv->cfb_y == crtc->y) |
| 1163 | return; |
| 1164 | |
| 1165 | I915_WRITE(DPFC_CONTROL, dpfc_ctl & ~DPFC_CTL_EN); |
| 1166 | POSTING_READ(DPFC_CONTROL); |
| 1167 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
| 1168 | } |
| 1169 | |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 1170 | dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1171 | dev_priv->cfb_fence = obj->fence_reg; |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 1172 | dev_priv->cfb_plane = intel_crtc->plane; |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1173 | dev_priv->cfb_y = crtc->y; |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 1174 | |
| 1175 | dpfc_ctl = plane | DPFC_SR_EN | DPFC_CTL_LIMIT_1X; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1176 | if (obj->tiling_mode != I915_TILING_NONE) { |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 1177 | dpfc_ctl |= DPFC_CTL_FENCE_EN | dev_priv->cfb_fence; |
| 1178 | I915_WRITE(DPFC_CHICKEN, DPFC_HT_MODIFY); |
| 1179 | } else { |
| 1180 | I915_WRITE(DPFC_CHICKEN, ~DPFC_HT_MODIFY); |
| 1181 | } |
| 1182 | |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 1183 | I915_WRITE(DPFC_RECOMP_CTL, DPFC_RECOMP_STALL_EN | |
| 1184 | (stall_watermark << DPFC_RECOMP_STALL_WM_SHIFT) | |
| 1185 | (interval << DPFC_RECOMP_TIMER_COUNT_SHIFT)); |
| 1186 | I915_WRITE(DPFC_FENCE_YOFF, crtc->y); |
| 1187 | |
| 1188 | /* enable it... */ |
| 1189 | I915_WRITE(DPFC_CONTROL, I915_READ(DPFC_CONTROL) | DPFC_CTL_EN); |
| 1190 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1191 | DRM_DEBUG_KMS("enabled fbc on plane %d\n", intel_crtc->plane); |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | void g4x_disable_fbc(struct drm_device *dev) |
| 1195 | { |
| 1196 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1197 | u32 dpfc_ctl; |
| 1198 | |
| 1199 | /* Disable compression */ |
| 1200 | dpfc_ctl = I915_READ(DPFC_CONTROL); |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1201 | if (dpfc_ctl & DPFC_CTL_EN) { |
| 1202 | dpfc_ctl &= ~DPFC_CTL_EN; |
| 1203 | I915_WRITE(DPFC_CONTROL, dpfc_ctl); |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 1204 | |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1205 | DRM_DEBUG_KMS("disabled FBC\n"); |
| 1206 | } |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 1207 | } |
| 1208 | |
Adam Jackson | ee5382a | 2010-04-23 11:17:39 -0400 | [diff] [blame] | 1209 | static bool g4x_fbc_enabled(struct drm_device *dev) |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 1210 | { |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 1211 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1212 | |
| 1213 | return I915_READ(DPFC_CONTROL) & DPFC_CTL_EN; |
| 1214 | } |
| 1215 | |
Jesse Barnes | 4efe070 | 2011-01-18 11:25:41 -0800 | [diff] [blame] | 1216 | static void sandybridge_blit_fbc_update(struct drm_device *dev) |
| 1217 | { |
| 1218 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1219 | u32 blt_ecoskpd; |
| 1220 | |
| 1221 | /* Make sure blitter notifies FBC of writes */ |
Chris Wilson | 9135583 | 2011-03-04 19:22:40 +0000 | [diff] [blame^] | 1222 | __gen6_gt_force_wake_get(dev_priv); |
Jesse Barnes | 4efe070 | 2011-01-18 11:25:41 -0800 | [diff] [blame] | 1223 | blt_ecoskpd = I915_READ(GEN6_BLITTER_ECOSKPD); |
| 1224 | blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY << |
| 1225 | GEN6_BLITTER_LOCK_SHIFT; |
| 1226 | I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd); |
| 1227 | blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY; |
| 1228 | I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd); |
| 1229 | blt_ecoskpd &= ~(GEN6_BLITTER_FBC_NOTIFY << |
| 1230 | GEN6_BLITTER_LOCK_SHIFT); |
| 1231 | I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd); |
| 1232 | POSTING_READ(GEN6_BLITTER_ECOSKPD); |
Chris Wilson | 9135583 | 2011-03-04 19:22:40 +0000 | [diff] [blame^] | 1233 | __gen6_gt_force_wake_put(dev_priv); |
Jesse Barnes | 4efe070 | 2011-01-18 11:25:41 -0800 | [diff] [blame] | 1234 | } |
| 1235 | |
Zhao Yakui | b52eb4d | 2010-06-12 14:32:27 +0800 | [diff] [blame] | 1236 | static void ironlake_enable_fbc(struct drm_crtc *crtc, unsigned long interval) |
| 1237 | { |
| 1238 | struct drm_device *dev = crtc->dev; |
| 1239 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1240 | struct drm_framebuffer *fb = crtc->fb; |
| 1241 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1242 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Zhao Yakui | b52eb4d | 2010-06-12 14:32:27 +0800 | [diff] [blame] | 1243 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1244 | int plane = intel_crtc->plane == 0 ? DPFC_CTL_PLANEA : DPFC_CTL_PLANEB; |
Zhao Yakui | b52eb4d | 2010-06-12 14:32:27 +0800 | [diff] [blame] | 1245 | unsigned long stall_watermark = 200; |
| 1246 | u32 dpfc_ctl; |
| 1247 | |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1248 | dpfc_ctl = I915_READ(ILK_DPFC_CONTROL); |
| 1249 | if (dpfc_ctl & DPFC_CTL_EN) { |
| 1250 | if (dev_priv->cfb_pitch == dev_priv->cfb_pitch / 64 - 1 && |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1251 | dev_priv->cfb_fence == obj->fence_reg && |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1252 | dev_priv->cfb_plane == intel_crtc->plane && |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1253 | dev_priv->cfb_offset == obj->gtt_offset && |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1254 | dev_priv->cfb_y == crtc->y) |
| 1255 | return; |
| 1256 | |
| 1257 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl & ~DPFC_CTL_EN); |
| 1258 | POSTING_READ(ILK_DPFC_CONTROL); |
| 1259 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
| 1260 | } |
| 1261 | |
Zhao Yakui | b52eb4d | 2010-06-12 14:32:27 +0800 | [diff] [blame] | 1262 | dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1263 | dev_priv->cfb_fence = obj->fence_reg; |
Zhao Yakui | b52eb4d | 2010-06-12 14:32:27 +0800 | [diff] [blame] | 1264 | dev_priv->cfb_plane = intel_crtc->plane; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1265 | dev_priv->cfb_offset = obj->gtt_offset; |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1266 | dev_priv->cfb_y = crtc->y; |
Zhao Yakui | b52eb4d | 2010-06-12 14:32:27 +0800 | [diff] [blame] | 1267 | |
Zhao Yakui | b52eb4d | 2010-06-12 14:32:27 +0800 | [diff] [blame] | 1268 | dpfc_ctl &= DPFC_RESERVED; |
| 1269 | dpfc_ctl |= (plane | DPFC_CTL_LIMIT_1X); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1270 | if (obj->tiling_mode != I915_TILING_NONE) { |
Zhao Yakui | b52eb4d | 2010-06-12 14:32:27 +0800 | [diff] [blame] | 1271 | dpfc_ctl |= (DPFC_CTL_FENCE_EN | dev_priv->cfb_fence); |
| 1272 | I915_WRITE(ILK_DPFC_CHICKEN, DPFC_HT_MODIFY); |
| 1273 | } else { |
| 1274 | I915_WRITE(ILK_DPFC_CHICKEN, ~DPFC_HT_MODIFY); |
| 1275 | } |
| 1276 | |
Zhao Yakui | b52eb4d | 2010-06-12 14:32:27 +0800 | [diff] [blame] | 1277 | I915_WRITE(ILK_DPFC_RECOMP_CTL, DPFC_RECOMP_STALL_EN | |
| 1278 | (stall_watermark << DPFC_RECOMP_STALL_WM_SHIFT) | |
| 1279 | (interval << DPFC_RECOMP_TIMER_COUNT_SHIFT)); |
| 1280 | I915_WRITE(ILK_DPFC_FENCE_YOFF, crtc->y); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1281 | I915_WRITE(ILK_FBC_RT_BASE, obj->gtt_offset | ILK_FBC_RT_VALID); |
Zhao Yakui | b52eb4d | 2010-06-12 14:32:27 +0800 | [diff] [blame] | 1282 | /* enable it... */ |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1283 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
Zhao Yakui | b52eb4d | 2010-06-12 14:32:27 +0800 | [diff] [blame] | 1284 | |
Yuanhan Liu | 9c04f01 | 2010-12-15 15:42:32 +0800 | [diff] [blame] | 1285 | if (IS_GEN6(dev)) { |
| 1286 | I915_WRITE(SNB_DPFC_CTL_SA, |
| 1287 | SNB_CPU_FENCE_ENABLE | dev_priv->cfb_fence); |
| 1288 | I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y); |
Jesse Barnes | 4efe070 | 2011-01-18 11:25:41 -0800 | [diff] [blame] | 1289 | sandybridge_blit_fbc_update(dev); |
Yuanhan Liu | 9c04f01 | 2010-12-15 15:42:32 +0800 | [diff] [blame] | 1290 | } |
| 1291 | |
Zhao Yakui | b52eb4d | 2010-06-12 14:32:27 +0800 | [diff] [blame] | 1292 | DRM_DEBUG_KMS("enabled fbc on plane %d\n", intel_crtc->plane); |
| 1293 | } |
| 1294 | |
| 1295 | void ironlake_disable_fbc(struct drm_device *dev) |
| 1296 | { |
| 1297 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1298 | u32 dpfc_ctl; |
| 1299 | |
| 1300 | /* Disable compression */ |
| 1301 | dpfc_ctl = I915_READ(ILK_DPFC_CONTROL); |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1302 | if (dpfc_ctl & DPFC_CTL_EN) { |
| 1303 | dpfc_ctl &= ~DPFC_CTL_EN; |
| 1304 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl); |
Zhao Yakui | b52eb4d | 2010-06-12 14:32:27 +0800 | [diff] [blame] | 1305 | |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1306 | DRM_DEBUG_KMS("disabled FBC\n"); |
| 1307 | } |
Zhao Yakui | b52eb4d | 2010-06-12 14:32:27 +0800 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | static bool ironlake_fbc_enabled(struct drm_device *dev) |
| 1311 | { |
| 1312 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1313 | |
| 1314 | return I915_READ(ILK_DPFC_CONTROL) & DPFC_CTL_EN; |
| 1315 | } |
| 1316 | |
Adam Jackson | ee5382a | 2010-04-23 11:17:39 -0400 | [diff] [blame] | 1317 | bool intel_fbc_enabled(struct drm_device *dev) |
| 1318 | { |
| 1319 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1320 | |
| 1321 | if (!dev_priv->display.fbc_enabled) |
| 1322 | return false; |
| 1323 | |
| 1324 | return dev_priv->display.fbc_enabled(dev); |
| 1325 | } |
| 1326 | |
| 1327 | void intel_enable_fbc(struct drm_crtc *crtc, unsigned long interval) |
| 1328 | { |
| 1329 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 1330 | |
| 1331 | if (!dev_priv->display.enable_fbc) |
| 1332 | return; |
| 1333 | |
| 1334 | dev_priv->display.enable_fbc(crtc, interval); |
| 1335 | } |
| 1336 | |
| 1337 | void intel_disable_fbc(struct drm_device *dev) |
| 1338 | { |
| 1339 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1340 | |
| 1341 | if (!dev_priv->display.disable_fbc) |
| 1342 | return; |
| 1343 | |
| 1344 | dev_priv->display.disable_fbc(dev); |
| 1345 | } |
| 1346 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1347 | /** |
| 1348 | * intel_update_fbc - enable/disable FBC as needed |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1349 | * @dev: the drm_device |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1350 | * |
| 1351 | * Set up the framebuffer compression hardware at mode set time. We |
| 1352 | * enable it if possible: |
| 1353 | * - plane A only (on pre-965) |
| 1354 | * - no pixel mulitply/line duplication |
| 1355 | * - no alpha buffer discard |
| 1356 | * - no dual wide |
| 1357 | * - framebuffer <= 2048 in width, 1536 in height |
| 1358 | * |
| 1359 | * We can't assume that any compression will take place (worst case), |
| 1360 | * so the compressed buffer has to be the same size as the uncompressed |
| 1361 | * one. It also must reside (along with the line length buffer) in |
| 1362 | * stolen memory. |
| 1363 | * |
| 1364 | * We need to enable/disable FBC on a global basis. |
| 1365 | */ |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1366 | static void intel_update_fbc(struct drm_device *dev) |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1367 | { |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1368 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1369 | struct drm_crtc *crtc = NULL, *tmp_crtc; |
| 1370 | struct intel_crtc *intel_crtc; |
| 1371 | struct drm_framebuffer *fb; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1372 | struct intel_framebuffer *intel_fb; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1373 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 9c928d1 | 2010-07-23 15:20:00 -0700 | [diff] [blame] | 1374 | |
| 1375 | DRM_DEBUG_KMS("\n"); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1376 | |
| 1377 | if (!i915_powersave) |
| 1378 | return; |
| 1379 | |
Adam Jackson | ee5382a | 2010-04-23 11:17:39 -0400 | [diff] [blame] | 1380 | if (!I915_HAS_FBC(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 1381 | return; |
| 1382 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1383 | /* |
| 1384 | * If FBC is already on, we just have to verify that we can |
| 1385 | * keep it that way... |
| 1386 | * Need to disable if: |
Jesse Barnes | 9c928d1 | 2010-07-23 15:20:00 -0700 | [diff] [blame] | 1387 | * - more than one pipe is active |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1388 | * - changing FBC params (stride, fence, mode) |
| 1389 | * - new fb is too large to fit in compressed buffer |
| 1390 | * - going to an unsupported config (interlace, pixel multiply, etc.) |
| 1391 | */ |
Jesse Barnes | 9c928d1 | 2010-07-23 15:20:00 -0700 | [diff] [blame] | 1392 | list_for_each_entry(tmp_crtc, &dev->mode_config.crtc_list, head) { |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1393 | if (tmp_crtc->enabled) { |
| 1394 | if (crtc) { |
| 1395 | DRM_DEBUG_KMS("more than one pipe active, disabling compression\n"); |
| 1396 | dev_priv->no_fbc_reason = FBC_MULTIPLE_PIPES; |
| 1397 | goto out_disable; |
| 1398 | } |
| 1399 | crtc = tmp_crtc; |
| 1400 | } |
Jesse Barnes | 9c928d1 | 2010-07-23 15:20:00 -0700 | [diff] [blame] | 1401 | } |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1402 | |
| 1403 | if (!crtc || crtc->fb == NULL) { |
| 1404 | DRM_DEBUG_KMS("no output, disabling\n"); |
| 1405 | dev_priv->no_fbc_reason = FBC_NO_OUTPUT; |
Jesse Barnes | 9c928d1 | 2010-07-23 15:20:00 -0700 | [diff] [blame] | 1406 | goto out_disable; |
| 1407 | } |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1408 | |
| 1409 | intel_crtc = to_intel_crtc(crtc); |
| 1410 | fb = crtc->fb; |
| 1411 | intel_fb = to_intel_framebuffer(fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1412 | obj = intel_fb->obj; |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1413 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1414 | if (intel_fb->obj->base.size > dev_priv->cfb_size) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1415 | DRM_DEBUG_KMS("framebuffer too large, disabling " |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1416 | "compression\n"); |
Jesse Barnes | b5e50c3 | 2010-02-05 12:42:41 -0800 | [diff] [blame] | 1417 | dev_priv->no_fbc_reason = FBC_STOLEN_TOO_SMALL; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1418 | goto out_disable; |
| 1419 | } |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1420 | if ((crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) || |
| 1421 | (crtc->mode.flags & DRM_MODE_FLAG_DBLSCAN)) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1422 | DRM_DEBUG_KMS("mode incompatible with compression, " |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1423 | "disabling\n"); |
Jesse Barnes | b5e50c3 | 2010-02-05 12:42:41 -0800 | [diff] [blame] | 1424 | dev_priv->no_fbc_reason = FBC_UNSUPPORTED_MODE; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1425 | goto out_disable; |
| 1426 | } |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1427 | if ((crtc->mode.hdisplay > 2048) || |
| 1428 | (crtc->mode.vdisplay > 1536)) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1429 | DRM_DEBUG_KMS("mode too large for compression, disabling\n"); |
Jesse Barnes | b5e50c3 | 2010-02-05 12:42:41 -0800 | [diff] [blame] | 1430 | dev_priv->no_fbc_reason = FBC_MODE_TOO_LARGE; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1431 | goto out_disable; |
| 1432 | } |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1433 | if ((IS_I915GM(dev) || IS_I945GM(dev)) && intel_crtc->plane != 0) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1434 | DRM_DEBUG_KMS("plane not 0, disabling compression\n"); |
Jesse Barnes | b5e50c3 | 2010-02-05 12:42:41 -0800 | [diff] [blame] | 1435 | dev_priv->no_fbc_reason = FBC_BAD_PLANE; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1436 | goto out_disable; |
| 1437 | } |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1438 | if (obj->tiling_mode != I915_TILING_X) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1439 | DRM_DEBUG_KMS("framebuffer not tiled, disabling compression\n"); |
Jesse Barnes | b5e50c3 | 2010-02-05 12:42:41 -0800 | [diff] [blame] | 1440 | dev_priv->no_fbc_reason = FBC_NOT_TILED; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1441 | goto out_disable; |
| 1442 | } |
| 1443 | |
Jason Wessel | c924b93 | 2010-08-05 09:22:32 -0500 | [diff] [blame] | 1444 | /* If the kernel debugger is active, always disable compression */ |
| 1445 | if (in_dbg_master()) |
| 1446 | goto out_disable; |
| 1447 | |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1448 | intel_enable_fbc(crtc, 500); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1449 | return; |
| 1450 | |
| 1451 | out_disable: |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1452 | /* Multiple disables should be harmless */ |
Chris Wilson | a939406 | 2010-05-27 13:18:16 +0100 | [diff] [blame] | 1453 | if (intel_fbc_enabled(dev)) { |
| 1454 | DRM_DEBUG_KMS("unsupported config, disabling FBC\n"); |
Adam Jackson | ee5382a | 2010-04-23 11:17:39 -0400 | [diff] [blame] | 1455 | intel_disable_fbc(dev); |
Chris Wilson | a939406 | 2010-05-27 13:18:16 +0100 | [diff] [blame] | 1456 | } |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
Chris Wilson | 127bd2a | 2010-07-23 23:32:05 +0100 | [diff] [blame] | 1459 | int |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 1460 | intel_pin_and_fence_fb_obj(struct drm_device *dev, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1461 | struct drm_i915_gem_object *obj, |
Chris Wilson | 919926a | 2010-11-12 13:42:53 +0000 | [diff] [blame] | 1462 | struct intel_ring_buffer *pipelined) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1463 | { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1464 | u32 alignment; |
| 1465 | int ret; |
| 1466 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1467 | switch (obj->tiling_mode) { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1468 | case I915_TILING_NONE: |
Chris Wilson | 534843d | 2010-07-05 18:01:46 +0100 | [diff] [blame] | 1469 | if (IS_BROADWATER(dev) || IS_CRESTLINE(dev)) |
| 1470 | alignment = 128 * 1024; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1471 | else if (INTEL_INFO(dev)->gen >= 4) |
Chris Wilson | 534843d | 2010-07-05 18:01:46 +0100 | [diff] [blame] | 1472 | alignment = 4 * 1024; |
| 1473 | else |
| 1474 | alignment = 64 * 1024; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1475 | break; |
| 1476 | case I915_TILING_X: |
| 1477 | /* pin() will align the object as required by fence */ |
| 1478 | alignment = 0; |
| 1479 | break; |
| 1480 | case I915_TILING_Y: |
| 1481 | /* FIXME: Is this true? */ |
| 1482 | DRM_ERROR("Y tiled not allowed for scan out buffers\n"); |
| 1483 | return -EINVAL; |
| 1484 | default: |
| 1485 | BUG(); |
| 1486 | } |
| 1487 | |
Daniel Vetter | 75e9e91 | 2010-11-04 17:11:09 +0100 | [diff] [blame] | 1488 | ret = i915_gem_object_pin(obj, alignment, true); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 1489 | if (ret) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1490 | return ret; |
| 1491 | |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 1492 | ret = i915_gem_object_set_to_display_plane(obj, pipelined); |
| 1493 | if (ret) |
| 1494 | goto err_unpin; |
Chris Wilson | 7213342 | 2010-09-13 23:56:38 +0100 | [diff] [blame] | 1495 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1496 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
| 1497 | * fence, whereas 965+ only requires a fence if using |
| 1498 | * framebuffer compression. For simplicity, we always install |
| 1499 | * a fence as the cost is not that onerous. |
| 1500 | */ |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1501 | if (obj->tiling_mode != I915_TILING_NONE) { |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 1502 | ret = i915_gem_object_get_fence(obj, pipelined, false); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 1503 | if (ret) |
| 1504 | goto err_unpin; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | return 0; |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 1508 | |
| 1509 | err_unpin: |
| 1510 | i915_gem_object_unpin(obj); |
| 1511 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1512 | } |
| 1513 | |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1514 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ |
| 1515 | static int |
| 1516 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
Jason Wessel | 21c74a8 | 2010-10-13 14:09:44 -0500 | [diff] [blame] | 1517 | int x, int y, enum mode_set_atomic state) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1518 | { |
| 1519 | struct drm_device *dev = crtc->dev; |
| 1520 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1521 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1522 | struct intel_framebuffer *intel_fb; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1523 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1524 | int plane = intel_crtc->plane; |
| 1525 | unsigned long Start, Offset; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1526 | u32 dspcntr; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1527 | u32 reg; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1528 | |
| 1529 | switch (plane) { |
| 1530 | case 0: |
| 1531 | case 1: |
| 1532 | break; |
| 1533 | default: |
| 1534 | DRM_ERROR("Can't update plane %d in SAREA\n", plane); |
| 1535 | return -EINVAL; |
| 1536 | } |
| 1537 | |
| 1538 | intel_fb = to_intel_framebuffer(fb); |
| 1539 | obj = intel_fb->obj; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1540 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1541 | reg = DSPCNTR(plane); |
| 1542 | dspcntr = I915_READ(reg); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1543 | /* Mask out pixel format bits in case we change it */ |
| 1544 | dspcntr &= ~DISPPLANE_PIXFORMAT_MASK; |
| 1545 | switch (fb->bits_per_pixel) { |
| 1546 | case 8: |
| 1547 | dspcntr |= DISPPLANE_8BPP; |
| 1548 | break; |
| 1549 | case 16: |
| 1550 | if (fb->depth == 15) |
| 1551 | dspcntr |= DISPPLANE_15_16BPP; |
| 1552 | else |
| 1553 | dspcntr |= DISPPLANE_16BPP; |
| 1554 | break; |
| 1555 | case 24: |
| 1556 | case 32: |
| 1557 | dspcntr |= DISPPLANE_32BPP_NO_ALPHA; |
| 1558 | break; |
| 1559 | default: |
| 1560 | DRM_ERROR("Unknown color depth\n"); |
| 1561 | return -EINVAL; |
| 1562 | } |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1563 | if (INTEL_INFO(dev)->gen >= 4) { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1564 | if (obj->tiling_mode != I915_TILING_NONE) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1565 | dspcntr |= DISPPLANE_TILED; |
| 1566 | else |
| 1567 | dspcntr &= ~DISPPLANE_TILED; |
| 1568 | } |
| 1569 | |
Chris Wilson | 4e6cfef | 2010-08-08 13:20:19 +0100 | [diff] [blame] | 1570 | if (HAS_PCH_SPLIT(dev)) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1571 | /* must disable */ |
| 1572 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
| 1573 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1574 | I915_WRITE(reg, dspcntr); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1575 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1576 | Start = obj->gtt_offset; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1577 | Offset = y * fb->pitch + x * (fb->bits_per_pixel / 8); |
| 1578 | |
Chris Wilson | 4e6cfef | 2010-08-08 13:20:19 +0100 | [diff] [blame] | 1579 | DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n", |
| 1580 | Start, Offset, x, y, fb->pitch); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1581 | I915_WRITE(DSPSTRIDE(plane), fb->pitch); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1582 | if (INTEL_INFO(dev)->gen >= 4) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1583 | I915_WRITE(DSPSURF(plane), Start); |
| 1584 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
| 1585 | I915_WRITE(DSPADDR(plane), Offset); |
| 1586 | } else |
| 1587 | I915_WRITE(DSPADDR(plane), Start + Offset); |
| 1588 | POSTING_READ(reg); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1589 | |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 1590 | intel_update_fbc(dev); |
Daniel Vetter | 3dec009 | 2010-08-20 21:40:52 +0200 | [diff] [blame] | 1591 | intel_increase_pllclock(crtc); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1592 | |
| 1593 | return 0; |
| 1594 | } |
| 1595 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1596 | static int |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 1597 | intel_pipe_set_base(struct drm_crtc *crtc, int x, int y, |
| 1598 | struct drm_framebuffer *old_fb) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1599 | { |
| 1600 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1601 | struct drm_i915_master_private *master_priv; |
| 1602 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1603 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1604 | |
| 1605 | /* no fb bound */ |
| 1606 | if (!crtc->fb) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1607 | DRM_DEBUG_KMS("No FB bound\n"); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1608 | return 0; |
| 1609 | } |
| 1610 | |
Chris Wilson | 265db95 | 2010-09-20 15:41:01 +0100 | [diff] [blame] | 1611 | switch (intel_crtc->plane) { |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1612 | case 0: |
| 1613 | case 1: |
| 1614 | break; |
| 1615 | default: |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1616 | return -EINVAL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1617 | } |
| 1618 | |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1619 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 265db95 | 2010-09-20 15:41:01 +0100 | [diff] [blame] | 1620 | ret = intel_pin_and_fence_fb_obj(dev, |
| 1621 | to_intel_framebuffer(crtc->fb)->obj, |
Chris Wilson | 919926a | 2010-11-12 13:42:53 +0000 | [diff] [blame] | 1622 | NULL); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1623 | if (ret != 0) { |
| 1624 | mutex_unlock(&dev->struct_mutex); |
| 1625 | return ret; |
| 1626 | } |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 1627 | |
Chris Wilson | 265db95 | 2010-09-20 15:41:01 +0100 | [diff] [blame] | 1628 | if (old_fb) { |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 1629 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1630 | struct drm_i915_gem_object *obj = to_intel_framebuffer(old_fb)->obj; |
Chris Wilson | 265db95 | 2010-09-20 15:41:01 +0100 | [diff] [blame] | 1631 | |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 1632 | wait_event(dev_priv->pending_flip_queue, |
Chris Wilson | 86b27d8 | 2011-02-11 20:47:45 +0000 | [diff] [blame] | 1633 | atomic_read(&dev_priv->mm.wedged) || |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1634 | atomic_read(&obj->pending_flip) == 0); |
Chris Wilson | 8534551 | 2010-11-13 09:49:11 +0000 | [diff] [blame] | 1635 | |
| 1636 | /* Big Hammer, we also need to ensure that any pending |
| 1637 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the |
| 1638 | * current scanout is retired before unpinning the old |
| 1639 | * framebuffer. |
Chris Wilson | 86b27d8 | 2011-02-11 20:47:45 +0000 | [diff] [blame] | 1640 | * |
| 1641 | * This should only fail upon a hung GPU, in which case we |
| 1642 | * can safely continue. |
Chris Wilson | 8534551 | 2010-11-13 09:49:11 +0000 | [diff] [blame] | 1643 | */ |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1644 | ret = i915_gem_object_flush_gpu(obj, false); |
Chris Wilson | 86b27d8 | 2011-02-11 20:47:45 +0000 | [diff] [blame] | 1645 | (void) ret; |
Chris Wilson | 265db95 | 2010-09-20 15:41:01 +0100 | [diff] [blame] | 1646 | } |
| 1647 | |
Jason Wessel | 21c74a8 | 2010-10-13 14:09:44 -0500 | [diff] [blame] | 1648 | ret = intel_pipe_set_base_atomic(crtc, crtc->fb, x, y, |
| 1649 | LEAVE_ATOMIC_MODE_SET); |
Chris Wilson | 4e6cfef | 2010-08-08 13:20:19 +0100 | [diff] [blame] | 1650 | if (ret) { |
Chris Wilson | 265db95 | 2010-09-20 15:41:01 +0100 | [diff] [blame] | 1651 | i915_gem_object_unpin(to_intel_framebuffer(crtc->fb)->obj); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1652 | mutex_unlock(&dev->struct_mutex); |
Chris Wilson | 4e6cfef | 2010-08-08 13:20:19 +0100 | [diff] [blame] | 1653 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1654 | } |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 1655 | |
Chris Wilson | b7f1de2 | 2010-12-14 16:09:31 +0000 | [diff] [blame] | 1656 | if (old_fb) { |
| 1657 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Chris Wilson | 265db95 | 2010-09-20 15:41:01 +0100 | [diff] [blame] | 1658 | i915_gem_object_unpin(to_intel_framebuffer(old_fb)->obj); |
Chris Wilson | b7f1de2 | 2010-12-14 16:09:31 +0000 | [diff] [blame] | 1659 | } |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 1660 | |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1661 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1662 | |
| 1663 | if (!dev->primary->master) |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1664 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1665 | |
| 1666 | master_priv = dev->primary->master->driver_priv; |
| 1667 | if (!master_priv->sarea_priv) |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1668 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1669 | |
Chris Wilson | 265db95 | 2010-09-20 15:41:01 +0100 | [diff] [blame] | 1670 | if (intel_crtc->pipe) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1671 | master_priv->sarea_priv->pipeB_x = x; |
| 1672 | master_priv->sarea_priv->pipeB_y = y; |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1673 | } else { |
| 1674 | master_priv->sarea_priv->pipeA_x = x; |
| 1675 | master_priv->sarea_priv->pipeA_y = y; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1676 | } |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1677 | |
| 1678 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1679 | } |
| 1680 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1681 | static void ironlake_set_pll_edp(struct drm_crtc *crtc, int clock) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1682 | { |
| 1683 | struct drm_device *dev = crtc->dev; |
| 1684 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1685 | u32 dpa_ctl; |
| 1686 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1687 | DRM_DEBUG_KMS("eDP PLL enable for clock %d\n", clock); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1688 | dpa_ctl = I915_READ(DP_A); |
| 1689 | dpa_ctl &= ~DP_PLL_FREQ_MASK; |
| 1690 | |
| 1691 | if (clock < 200000) { |
| 1692 | u32 temp; |
| 1693 | dpa_ctl |= DP_PLL_FREQ_160MHZ; |
| 1694 | /* workaround for 160Mhz: |
| 1695 | 1) program 0x4600c bits 15:0 = 0x8124 |
| 1696 | 2) program 0x46010 bit 0 = 1 |
| 1697 | 3) program 0x46034 bit 24 = 1 |
| 1698 | 4) program 0x64000 bit 14 = 1 |
| 1699 | */ |
| 1700 | temp = I915_READ(0x4600c); |
| 1701 | temp &= 0xffff0000; |
| 1702 | I915_WRITE(0x4600c, temp | 0x8124); |
| 1703 | |
| 1704 | temp = I915_READ(0x46010); |
| 1705 | I915_WRITE(0x46010, temp | 1); |
| 1706 | |
| 1707 | temp = I915_READ(0x46034); |
| 1708 | I915_WRITE(0x46034, temp | (1 << 24)); |
| 1709 | } else { |
| 1710 | dpa_ctl |= DP_PLL_FREQ_270MHZ; |
| 1711 | } |
| 1712 | I915_WRITE(DP_A, dpa_ctl); |
| 1713 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1714 | POSTING_READ(DP_A); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1715 | udelay(500); |
| 1716 | } |
| 1717 | |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 1718 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
| 1719 | { |
| 1720 | struct drm_device *dev = crtc->dev; |
| 1721 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1722 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1723 | int pipe = intel_crtc->pipe; |
| 1724 | u32 reg, temp; |
| 1725 | |
| 1726 | /* enable normal train */ |
| 1727 | reg = FDI_TX_CTL(pipe); |
| 1728 | temp = I915_READ(reg); |
| 1729 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 1730 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; |
| 1731 | I915_WRITE(reg, temp); |
| 1732 | |
| 1733 | reg = FDI_RX_CTL(pipe); |
| 1734 | temp = I915_READ(reg); |
| 1735 | if (HAS_PCH_CPT(dev)) { |
| 1736 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 1737 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; |
| 1738 | } else { |
| 1739 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 1740 | temp |= FDI_LINK_TRAIN_NONE; |
| 1741 | } |
| 1742 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); |
| 1743 | |
| 1744 | /* wait one idle pattern time */ |
| 1745 | POSTING_READ(reg); |
| 1746 | udelay(1000); |
| 1747 | } |
| 1748 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1749 | /* The FDI link training functions for ILK/Ibexpeak. */ |
| 1750 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) |
| 1751 | { |
| 1752 | struct drm_device *dev = crtc->dev; |
| 1753 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1754 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1755 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1756 | u32 reg, temp, tries; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1757 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 1758 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 1759 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1760 | reg = FDI_RX_IMR(pipe); |
| 1761 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 1762 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 1763 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1764 | I915_WRITE(reg, temp); |
| 1765 | I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 1766 | udelay(150); |
| 1767 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1768 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1769 | reg = FDI_TX_CTL(pipe); |
| 1770 | temp = I915_READ(reg); |
Adam Jackson | 77ffb59 | 2010-04-12 11:38:44 -0400 | [diff] [blame] | 1771 | temp &= ~(7 << 19); |
| 1772 | temp |= (intel_crtc->fdi_lanes - 1) << 19; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1773 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 1774 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1775 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1776 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1777 | reg = FDI_RX_CTL(pipe); |
| 1778 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1779 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 1780 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1781 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 1782 | |
| 1783 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1784 | udelay(150); |
| 1785 | |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 1786 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
| 1787 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_ENABLE); |
| 1788 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1789 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 1790 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1791 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1792 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 1793 | |
| 1794 | if ((temp & FDI_RX_BIT_LOCK)) { |
| 1795 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1796 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1797 | break; |
| 1798 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1799 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 1800 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1801 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1802 | |
| 1803 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1804 | reg = FDI_TX_CTL(pipe); |
| 1805 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1806 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 1807 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1808 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1809 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1810 | reg = FDI_RX_CTL(pipe); |
| 1811 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1812 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 1813 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1814 | I915_WRITE(reg, temp); |
| 1815 | |
| 1816 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1817 | udelay(150); |
| 1818 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1819 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 1820 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1821 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1822 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 1823 | |
| 1824 | if (temp & FDI_RX_SYMBOL_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1825 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1826 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 1827 | break; |
| 1828 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1829 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 1830 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1831 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1832 | |
| 1833 | DRM_DEBUG_KMS("FDI train done\n"); |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 1834 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1835 | } |
| 1836 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1837 | static const int const snb_b_fdi_train_param [] = { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1838 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
| 1839 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, |
| 1840 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, |
| 1841 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, |
| 1842 | }; |
| 1843 | |
| 1844 | /* The FDI link training functions for SNB/Cougarpoint. */ |
| 1845 | static void gen6_fdi_link_train(struct drm_crtc *crtc) |
| 1846 | { |
| 1847 | struct drm_device *dev = crtc->dev; |
| 1848 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1849 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1850 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1851 | u32 reg, temp, i; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1852 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 1853 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 1854 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1855 | reg = FDI_RX_IMR(pipe); |
| 1856 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 1857 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 1858 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1859 | I915_WRITE(reg, temp); |
| 1860 | |
| 1861 | POSTING_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 1862 | udelay(150); |
| 1863 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1864 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1865 | reg = FDI_TX_CTL(pipe); |
| 1866 | temp = I915_READ(reg); |
Adam Jackson | 77ffb59 | 2010-04-12 11:38:44 -0400 | [diff] [blame] | 1867 | temp &= ~(7 << 19); |
| 1868 | temp |= (intel_crtc->fdi_lanes - 1) << 19; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1869 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 1870 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 1871 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 1872 | /* SNB-B */ |
| 1873 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1874 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1875 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1876 | reg = FDI_RX_CTL(pipe); |
| 1877 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1878 | if (HAS_PCH_CPT(dev)) { |
| 1879 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 1880 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 1881 | } else { |
| 1882 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 1883 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 1884 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1885 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 1886 | |
| 1887 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1888 | udelay(150); |
| 1889 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1890 | for (i = 0; i < 4; i++ ) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1891 | reg = FDI_TX_CTL(pipe); |
| 1892 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1893 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 1894 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1895 | I915_WRITE(reg, temp); |
| 1896 | |
| 1897 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1898 | udelay(500); |
| 1899 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1900 | reg = FDI_RX_IIR(pipe); |
| 1901 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1902 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 1903 | |
| 1904 | if (temp & FDI_RX_BIT_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1905 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1906 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
| 1907 | break; |
| 1908 | } |
| 1909 | } |
| 1910 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1911 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1912 | |
| 1913 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1914 | reg = FDI_TX_CTL(pipe); |
| 1915 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1916 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 1917 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 1918 | if (IS_GEN6(dev)) { |
| 1919 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 1920 | /* SNB-B */ |
| 1921 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 1922 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1923 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1924 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1925 | reg = FDI_RX_CTL(pipe); |
| 1926 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1927 | if (HAS_PCH_CPT(dev)) { |
| 1928 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 1929 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 1930 | } else { |
| 1931 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 1932 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 1933 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1934 | I915_WRITE(reg, temp); |
| 1935 | |
| 1936 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1937 | udelay(150); |
| 1938 | |
| 1939 | for (i = 0; i < 4; i++ ) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1940 | reg = FDI_TX_CTL(pipe); |
| 1941 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1942 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 1943 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1944 | I915_WRITE(reg, temp); |
| 1945 | |
| 1946 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1947 | udelay(500); |
| 1948 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1949 | reg = FDI_RX_IIR(pipe); |
| 1950 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1951 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 1952 | |
| 1953 | if (temp & FDI_RX_SYMBOL_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1954 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1955 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 1956 | break; |
| 1957 | } |
| 1958 | } |
| 1959 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1960 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 1961 | |
| 1962 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 1963 | } |
| 1964 | |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 1965 | static void ironlake_fdi_enable(struct drm_crtc *crtc) |
| 1966 | { |
| 1967 | struct drm_device *dev = crtc->dev; |
| 1968 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1969 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1970 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1971 | u32 reg, temp; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 1972 | |
Jesse Barnes | c64e311 | 2010-09-10 11:27:03 -0700 | [diff] [blame] | 1973 | /* Write the TU size bits so error detection works */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1974 | I915_WRITE(FDI_RX_TUSIZE1(pipe), |
| 1975 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); |
Jesse Barnes | c64e311 | 2010-09-10 11:27:03 -0700 | [diff] [blame] | 1976 | |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 1977 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1978 | reg = FDI_RX_CTL(pipe); |
| 1979 | temp = I915_READ(reg); |
| 1980 | temp &= ~((0x7 << 19) | (0x7 << 16)); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 1981 | temp |= (intel_crtc->fdi_lanes - 1) << 19; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1982 | temp |= (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) << 11; |
| 1983 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
| 1984 | |
| 1985 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 1986 | udelay(200); |
| 1987 | |
| 1988 | /* Switch from Rawclk to PCDclk */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1989 | temp = I915_READ(reg); |
| 1990 | I915_WRITE(reg, temp | FDI_PCDCLK); |
| 1991 | |
| 1992 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 1993 | udelay(200); |
| 1994 | |
| 1995 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1996 | reg = FDI_TX_CTL(pipe); |
| 1997 | temp = I915_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 1998 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1999 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); |
| 2000 | |
| 2001 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 2002 | udelay(100); |
| 2003 | } |
| 2004 | } |
| 2005 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2006 | static void intel_flush_display_plane(struct drm_device *dev, |
| 2007 | int plane) |
| 2008 | { |
| 2009 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2010 | u32 reg = DSPADDR(plane); |
| 2011 | I915_WRITE(reg, I915_READ(reg)); |
| 2012 | } |
| 2013 | |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 2014 | /* |
| 2015 | * When we disable a pipe, we need to clear any pending scanline wait events |
| 2016 | * to avoid hanging the ring, which we assume we are waiting on. |
| 2017 | */ |
| 2018 | static void intel_clear_scanline_wait(struct drm_device *dev) |
| 2019 | { |
| 2020 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 8168bd4 | 2010-11-11 17:54:52 +0000 | [diff] [blame] | 2021 | struct intel_ring_buffer *ring; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 2022 | u32 tmp; |
| 2023 | |
| 2024 | if (IS_GEN2(dev)) |
| 2025 | /* Can't break the hang on i8xx */ |
| 2026 | return; |
| 2027 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2028 | ring = LP_RING(dev_priv); |
Chris Wilson | 8168bd4 | 2010-11-11 17:54:52 +0000 | [diff] [blame] | 2029 | tmp = I915_READ_CTL(ring); |
| 2030 | if (tmp & RING_WAIT) |
| 2031 | I915_WRITE_CTL(ring, tmp); |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 2032 | } |
| 2033 | |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 2034 | static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
| 2035 | { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 2036 | struct drm_i915_gem_object *obj; |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 2037 | struct drm_i915_private *dev_priv; |
| 2038 | |
| 2039 | if (crtc->fb == NULL) |
| 2040 | return; |
| 2041 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 2042 | obj = to_intel_framebuffer(crtc->fb)->obj; |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 2043 | dev_priv = crtc->dev->dev_private; |
| 2044 | wait_event(dev_priv->pending_flip_queue, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 2045 | atomic_read(&obj->pending_flip) == 0); |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 2046 | } |
| 2047 | |
Jesse Barnes | 011b991 | 2011-02-15 15:08:02 -0800 | [diff] [blame] | 2048 | static bool intel_crtc_driving_pch(struct drm_crtc *crtc) |
| 2049 | { |
| 2050 | struct drm_device *dev = crtc->dev; |
| 2051 | struct drm_mode_config *mode_config = &dev->mode_config; |
| 2052 | struct intel_encoder *encoder; |
| 2053 | |
| 2054 | /* |
| 2055 | * If there's a non-PCH eDP on this crtc, it must be DP_A, and that |
| 2056 | * must be driven by its own crtc; no sharing is possible. |
| 2057 | */ |
| 2058 | list_for_each_entry(encoder, &mode_config->encoder_list, base.head) { |
| 2059 | if (encoder->base.crtc != crtc) |
| 2060 | continue; |
| 2061 | |
| 2062 | switch (encoder->type) { |
| 2063 | case INTEL_OUTPUT_EDP: |
| 2064 | if (!intel_encoder_is_pch_edp(&encoder->base)) |
| 2065 | return false; |
| 2066 | continue; |
| 2067 | } |
| 2068 | } |
| 2069 | |
| 2070 | return true; |
| 2071 | } |
| 2072 | |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2073 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2074 | { |
| 2075 | struct drm_device *dev = crtc->dev; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2076 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2077 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2078 | int pipe = intel_crtc->pipe; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2079 | int plane = intel_crtc->plane; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2080 | u32 reg, temp; |
Jesse Barnes | 011b991 | 2011-02-15 15:08:02 -0800 | [diff] [blame] | 2081 | bool is_pch_port = false; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2082 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 2083 | if (intel_crtc->active) |
| 2084 | return; |
| 2085 | |
| 2086 | intel_crtc->active = true; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 2087 | intel_update_watermarks(dev); |
| 2088 | |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2089 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
| 2090 | temp = I915_READ(PCH_LVDS); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2091 | if ((temp & LVDS_PORT_EN) == 0) |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2092 | I915_WRITE(PCH_LVDS, temp | LVDS_PORT_EN); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2093 | } |
| 2094 | |
Jesse Barnes | 011b991 | 2011-02-15 15:08:02 -0800 | [diff] [blame] | 2095 | is_pch_port = intel_crtc_driving_pch(crtc); |
| 2096 | |
| 2097 | if (is_pch_port) |
| 2098 | ironlake_fdi_enable(crtc); |
| 2099 | else { |
| 2100 | /* disable CPU FDI tx and PCH FDI rx */ |
| 2101 | reg = FDI_TX_CTL(pipe); |
| 2102 | temp = I915_READ(reg); |
| 2103 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); |
| 2104 | POSTING_READ(reg); |
| 2105 | |
| 2106 | reg = FDI_RX_CTL(pipe); |
| 2107 | temp = I915_READ(reg); |
| 2108 | temp &= ~(0x7 << 16); |
| 2109 | temp |= (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) << 11; |
| 2110 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
| 2111 | |
| 2112 | POSTING_READ(reg); |
| 2113 | udelay(100); |
| 2114 | |
| 2115 | /* Ironlake workaround, disable clock pointer after downing FDI */ |
| 2116 | if (HAS_PCH_IBX(dev)) |
| 2117 | I915_WRITE(FDI_RX_CHICKEN(pipe), |
| 2118 | I915_READ(FDI_RX_CHICKEN(pipe) & |
| 2119 | ~FDI_RX_PHASE_SYNC_POINTER_ENABLE)); |
| 2120 | |
| 2121 | /* still set train pattern 1 */ |
| 2122 | reg = FDI_TX_CTL(pipe); |
| 2123 | temp = I915_READ(reg); |
| 2124 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2125 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 2126 | I915_WRITE(reg, temp); |
| 2127 | |
| 2128 | reg = FDI_RX_CTL(pipe); |
| 2129 | temp = I915_READ(reg); |
| 2130 | if (HAS_PCH_CPT(dev)) { |
| 2131 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 2132 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 2133 | } else { |
| 2134 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2135 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 2136 | } |
| 2137 | /* BPC in FDI rx is consistent with that in PIPECONF */ |
| 2138 | temp &= ~(0x07 << 16); |
| 2139 | temp |= (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) << 11; |
| 2140 | I915_WRITE(reg, temp); |
| 2141 | |
| 2142 | POSTING_READ(reg); |
| 2143 | udelay(100); |
| 2144 | } |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2145 | |
| 2146 | /* Enable panel fitting for LVDS */ |
| 2147 | if (dev_priv->pch_pf_size && |
Jesse Barnes | 1d85036 | 2010-10-07 16:01:10 -0700 | [diff] [blame] | 2148 | (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) || HAS_eDP)) { |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2149 | /* Force use of hard-coded filter coefficients |
| 2150 | * as some pre-programmed values are broken, |
| 2151 | * e.g. x201. |
| 2152 | */ |
| 2153 | I915_WRITE(pipe ? PFB_CTL_1 : PFA_CTL_1, |
| 2154 | PF_ENABLE | PF_FILTER_MED_3x3); |
| 2155 | I915_WRITE(pipe ? PFB_WIN_POS : PFA_WIN_POS, |
| 2156 | dev_priv->pch_pf_pos); |
| 2157 | I915_WRITE(pipe ? PFB_WIN_SZ : PFA_WIN_SZ, |
| 2158 | dev_priv->pch_pf_size); |
| 2159 | } |
| 2160 | |
| 2161 | /* Enable CPU pipe */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2162 | reg = PIPECONF(pipe); |
| 2163 | temp = I915_READ(reg); |
| 2164 | if ((temp & PIPECONF_ENABLE) == 0) { |
| 2165 | I915_WRITE(reg, temp | PIPECONF_ENABLE); |
| 2166 | POSTING_READ(reg); |
Jesse Barnes | 17f6766 | 2010-10-07 16:01:19 -0700 | [diff] [blame] | 2167 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2168 | } |
| 2169 | |
| 2170 | /* configure and enable CPU plane */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2171 | reg = DSPCNTR(plane); |
| 2172 | temp = I915_READ(reg); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2173 | if ((temp & DISPLAY_PLANE_ENABLE) == 0) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2174 | I915_WRITE(reg, temp | DISPLAY_PLANE_ENABLE); |
| 2175 | intel_flush_display_plane(dev, plane); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2176 | } |
| 2177 | |
Jesse Barnes | 011b991 | 2011-02-15 15:08:02 -0800 | [diff] [blame] | 2178 | /* Skip the PCH stuff if possible */ |
| 2179 | if (!is_pch_port) |
| 2180 | goto done; |
| 2181 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 2182 | /* For PCH output, training FDI link */ |
| 2183 | if (IS_GEN6(dev)) |
| 2184 | gen6_fdi_link_train(crtc); |
| 2185 | else |
| 2186 | ironlake_fdi_link_train(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2187 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 2188 | /* enable PCH DPLL */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2189 | reg = PCH_DPLL(pipe); |
| 2190 | temp = I915_READ(reg); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 2191 | if ((temp & DPLL_VCO_ENABLE) == 0) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2192 | I915_WRITE(reg, temp | DPLL_VCO_ENABLE); |
| 2193 | POSTING_READ(reg); |
Chris Wilson | 8c4223b | 2010-09-10 22:33:42 +0100 | [diff] [blame] | 2194 | udelay(200); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2195 | } |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 2196 | |
| 2197 | if (HAS_PCH_CPT(dev)) { |
| 2198 | /* Be sure PCH DPLL SEL is set */ |
| 2199 | temp = I915_READ(PCH_DPLL_SEL); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2200 | if (pipe == 0 && (temp & TRANSA_DPLL_ENABLE) == 0) |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 2201 | temp |= (TRANSA_DPLL_ENABLE | TRANSA_DPLLA_SEL); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2202 | else if (pipe == 1 && (temp & TRANSB_DPLL_ENABLE) == 0) |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 2203 | temp |= (TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL); |
| 2204 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 2205 | } |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 2206 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2207 | /* set transcoder timing */ |
| 2208 | I915_WRITE(TRANS_HTOTAL(pipe), I915_READ(HTOTAL(pipe))); |
| 2209 | I915_WRITE(TRANS_HBLANK(pipe), I915_READ(HBLANK(pipe))); |
| 2210 | I915_WRITE(TRANS_HSYNC(pipe), I915_READ(HSYNC(pipe))); |
| 2211 | |
| 2212 | I915_WRITE(TRANS_VTOTAL(pipe), I915_READ(VTOTAL(pipe))); |
| 2213 | I915_WRITE(TRANS_VBLANK(pipe), I915_READ(VBLANK(pipe))); |
| 2214 | I915_WRITE(TRANS_VSYNC(pipe), I915_READ(VSYNC(pipe))); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 2215 | |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 2216 | intel_fdi_normal_train(crtc); |
| 2217 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 2218 | /* For PCH DP, enable TRANS_DP_CTL */ |
| 2219 | if (HAS_PCH_CPT(dev) && |
| 2220 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2221 | reg = TRANS_DP_CTL(pipe); |
| 2222 | temp = I915_READ(reg); |
| 2223 | temp &= ~(TRANS_DP_PORT_SEL_MASK | |
Eric Anholt | 220cad3 | 2010-11-18 09:32:58 +0800 | [diff] [blame] | 2224 | TRANS_DP_SYNC_MASK | |
| 2225 | TRANS_DP_BPC_MASK); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2226 | temp |= (TRANS_DP_OUTPUT_ENABLE | |
| 2227 | TRANS_DP_ENH_FRAMING); |
Eric Anholt | 220cad3 | 2010-11-18 09:32:58 +0800 | [diff] [blame] | 2228 | temp |= TRANS_DP_8BPC; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 2229 | |
| 2230 | if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2231 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 2232 | if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2233 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 2234 | |
| 2235 | switch (intel_trans_dp_port_sel(crtc)) { |
| 2236 | case PCH_DP_B: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2237 | temp |= TRANS_DP_PORT_SEL_B; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 2238 | break; |
| 2239 | case PCH_DP_C: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2240 | temp |= TRANS_DP_PORT_SEL_C; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 2241 | break; |
| 2242 | case PCH_DP_D: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2243 | temp |= TRANS_DP_PORT_SEL_D; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 2244 | break; |
| 2245 | default: |
| 2246 | DRM_DEBUG_KMS("Wrong PCH DP port return. Guess port B\n"); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2247 | temp |= TRANS_DP_PORT_SEL_B; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 2248 | break; |
| 2249 | } |
| 2250 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2251 | I915_WRITE(reg, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 2252 | } |
| 2253 | |
| 2254 | /* enable PCH transcoder */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2255 | reg = TRANSCONF(pipe); |
| 2256 | temp = I915_READ(reg); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 2257 | /* |
| 2258 | * make the BPC in transcoder be consistent with |
| 2259 | * that in pipeconf reg. |
| 2260 | */ |
| 2261 | temp &= ~PIPE_BPC_MASK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2262 | temp |= I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK; |
| 2263 | I915_WRITE(reg, temp | TRANS_ENABLE); |
| 2264 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) |
Jesse Barnes | 17f6766 | 2010-10-07 16:01:19 -0700 | [diff] [blame] | 2265 | DRM_ERROR("failed to enable transcoder %d\n", pipe); |
Jesse Barnes | 011b991 | 2011-02-15 15:08:02 -0800 | [diff] [blame] | 2266 | done: |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2267 | intel_crtc_load_lut(crtc); |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 2268 | intel_update_fbc(dev); |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 2269 | intel_crtc_update_cursor(crtc, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2270 | } |
| 2271 | |
| 2272 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
| 2273 | { |
| 2274 | struct drm_device *dev = crtc->dev; |
| 2275 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2276 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2277 | int pipe = intel_crtc->pipe; |
| 2278 | int plane = intel_crtc->plane; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2279 | u32 reg, temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2280 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 2281 | if (!intel_crtc->active) |
| 2282 | return; |
| 2283 | |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 2284 | intel_crtc_wait_for_pending_flips(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2285 | drm_vblank_off(dev, pipe); |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 2286 | intel_crtc_update_cursor(crtc, false); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2287 | |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2288 | /* Disable display plane */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2289 | reg = DSPCNTR(plane); |
| 2290 | temp = I915_READ(reg); |
| 2291 | if (temp & DISPLAY_PLANE_ENABLE) { |
| 2292 | I915_WRITE(reg, temp & ~DISPLAY_PLANE_ENABLE); |
| 2293 | intel_flush_display_plane(dev, plane); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2294 | } |
| 2295 | |
| 2296 | if (dev_priv->cfb_plane == plane && |
| 2297 | dev_priv->display.disable_fbc) |
| 2298 | dev_priv->display.disable_fbc(dev); |
| 2299 | |
| 2300 | /* disable cpu pipe, disable after all planes disabled */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2301 | reg = PIPECONF(pipe); |
| 2302 | temp = I915_READ(reg); |
| 2303 | if (temp & PIPECONF_ENABLE) { |
| 2304 | I915_WRITE(reg, temp & ~PIPECONF_ENABLE); |
Jesse Barnes | 17f6766 | 2010-10-07 16:01:19 -0700 | [diff] [blame] | 2305 | POSTING_READ(reg); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2306 | /* wait for cpu pipe off, pipe state */ |
Jesse Barnes | 17f6766 | 2010-10-07 16:01:19 -0700 | [diff] [blame] | 2307 | intel_wait_for_pipe_off(dev, intel_crtc->pipe); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2308 | } |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2309 | |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2310 | /* Disable PF */ |
| 2311 | I915_WRITE(pipe ? PFB_CTL_1 : PFA_CTL_1, 0); |
| 2312 | I915_WRITE(pipe ? PFB_WIN_SZ : PFA_WIN_SZ, 0); |
| 2313 | |
| 2314 | /* disable CPU FDI tx and PCH FDI rx */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2315 | reg = FDI_TX_CTL(pipe); |
| 2316 | temp = I915_READ(reg); |
| 2317 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); |
| 2318 | POSTING_READ(reg); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2319 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2320 | reg = FDI_RX_CTL(pipe); |
| 2321 | temp = I915_READ(reg); |
| 2322 | temp &= ~(0x7 << 16); |
| 2323 | temp |= (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) << 11; |
| 2324 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2325 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2326 | POSTING_READ(reg); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2327 | udelay(100); |
| 2328 | |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 2329 | /* Ironlake workaround, disable clock pointer after downing FDI */ |
Zhenyu Wang | e07ac3a | 2010-11-04 09:02:54 +0000 | [diff] [blame] | 2330 | if (HAS_PCH_IBX(dev)) |
| 2331 | I915_WRITE(FDI_RX_CHICKEN(pipe), |
| 2332 | I915_READ(FDI_RX_CHICKEN(pipe) & |
| 2333 | ~FDI_RX_PHASE_SYNC_POINTER_ENABLE)); |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 2334 | |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2335 | /* still set train pattern 1 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2336 | reg = FDI_TX_CTL(pipe); |
| 2337 | temp = I915_READ(reg); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2338 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2339 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2340 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2341 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2342 | reg = FDI_RX_CTL(pipe); |
| 2343 | temp = I915_READ(reg); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2344 | if (HAS_PCH_CPT(dev)) { |
| 2345 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 2346 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 2347 | } else { |
| 2348 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2349 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 2350 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2351 | /* BPC in FDI rx is consistent with that in PIPECONF */ |
| 2352 | temp &= ~(0x07 << 16); |
| 2353 | temp |= (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) << 11; |
| 2354 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2355 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2356 | POSTING_READ(reg); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2357 | udelay(100); |
| 2358 | |
| 2359 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
| 2360 | temp = I915_READ(PCH_LVDS); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2361 | if (temp & LVDS_PORT_EN) { |
| 2362 | I915_WRITE(PCH_LVDS, temp & ~LVDS_PORT_EN); |
| 2363 | POSTING_READ(PCH_LVDS); |
| 2364 | udelay(100); |
| 2365 | } |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2366 | } |
| 2367 | |
| 2368 | /* disable PCH transcoder */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2369 | reg = TRANSCONF(plane); |
| 2370 | temp = I915_READ(reg); |
| 2371 | if (temp & TRANS_ENABLE) { |
| 2372 | I915_WRITE(reg, temp & ~TRANS_ENABLE); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2373 | /* wait for PCH transcoder off, transcoder state */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2374 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2375 | DRM_ERROR("failed to disable transcoder\n"); |
| 2376 | } |
| 2377 | |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2378 | if (HAS_PCH_CPT(dev)) { |
| 2379 | /* disable TRANS_DP_CTL */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2380 | reg = TRANS_DP_CTL(pipe); |
| 2381 | temp = I915_READ(reg); |
| 2382 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | TRANS_DP_PORT_SEL_MASK); |
| 2383 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2384 | |
| 2385 | /* disable DPLL_SEL */ |
| 2386 | temp = I915_READ(PCH_DPLL_SEL); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2387 | if (pipe == 0) |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2388 | temp &= ~(TRANSA_DPLL_ENABLE | TRANSA_DPLLB_SEL); |
| 2389 | else |
| 2390 | temp &= ~(TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL); |
| 2391 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2392 | } |
| 2393 | |
| 2394 | /* disable PCH DPLL */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2395 | reg = PCH_DPLL(pipe); |
| 2396 | temp = I915_READ(reg); |
| 2397 | I915_WRITE(reg, temp & ~DPLL_VCO_ENABLE); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2398 | |
| 2399 | /* Switch from PCDclk to Rawclk */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2400 | reg = FDI_RX_CTL(pipe); |
| 2401 | temp = I915_READ(reg); |
| 2402 | I915_WRITE(reg, temp & ~FDI_PCDCLK); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2403 | |
| 2404 | /* Disable CPU FDI TX PLL */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2405 | reg = FDI_TX_CTL(pipe); |
| 2406 | temp = I915_READ(reg); |
| 2407 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); |
| 2408 | |
| 2409 | POSTING_READ(reg); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2410 | udelay(100); |
| 2411 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2412 | reg = FDI_RX_CTL(pipe); |
| 2413 | temp = I915_READ(reg); |
| 2414 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2415 | |
| 2416 | /* Wait for the clocks to turn off. */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2417 | POSTING_READ(reg); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2418 | udelay(100); |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 2419 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 2420 | intel_crtc->active = false; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 2421 | intel_update_watermarks(dev); |
| 2422 | intel_update_fbc(dev); |
| 2423 | intel_clear_scanline_wait(dev); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2424 | } |
| 2425 | |
| 2426 | static void ironlake_crtc_dpms(struct drm_crtc *crtc, int mode) |
| 2427 | { |
| 2428 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2429 | int pipe = intel_crtc->pipe; |
| 2430 | int plane = intel_crtc->plane; |
| 2431 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2432 | /* XXX: When our outputs are all unaware of DPMS modes other than off |
| 2433 | * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC. |
| 2434 | */ |
| 2435 | switch (mode) { |
| 2436 | case DRM_MODE_DPMS_ON: |
| 2437 | case DRM_MODE_DPMS_STANDBY: |
| 2438 | case DRM_MODE_DPMS_SUSPEND: |
Chris Wilson | 868dc58 | 2010-08-07 11:01:31 +0100 | [diff] [blame] | 2439 | DRM_DEBUG_KMS("crtc %d/%d dpms on\n", pipe, plane); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2440 | ironlake_crtc_enable(crtc); |
Chris Wilson | 868dc58 | 2010-08-07 11:01:31 +0100 | [diff] [blame] | 2441 | break; |
Zhao Yakui | b52eb4d | 2010-06-12 14:32:27 +0800 | [diff] [blame] | 2442 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2443 | case DRM_MODE_DPMS_OFF: |
Chris Wilson | 868dc58 | 2010-08-07 11:01:31 +0100 | [diff] [blame] | 2444 | DRM_DEBUG_KMS("crtc %d/%d dpms off\n", pipe, plane); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2445 | ironlake_crtc_disable(crtc); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2446 | break; |
| 2447 | } |
| 2448 | } |
| 2449 | |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 2450 | static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable) |
| 2451 | { |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 2452 | if (!enable && intel_crtc->overlay) { |
Chris Wilson | 23f09ce | 2010-08-12 13:53:37 +0100 | [diff] [blame] | 2453 | struct drm_device *dev = intel_crtc->base.dev; |
Daniel Vetter | 03f77ea | 2009-09-15 22:57:37 +0200 | [diff] [blame] | 2454 | |
Chris Wilson | 23f09ce | 2010-08-12 13:53:37 +0100 | [diff] [blame] | 2455 | mutex_lock(&dev->struct_mutex); |
| 2456 | (void) intel_overlay_switch_off(intel_crtc->overlay, false); |
| 2457 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 2458 | } |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 2459 | |
Chris Wilson | 5dcdbcb | 2010-08-12 13:50:28 +0100 | [diff] [blame] | 2460 | /* Let userspace switch the overlay on again. In most cases userspace |
| 2461 | * has to recompute where to put it anyway. |
| 2462 | */ |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 2463 | } |
| 2464 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2465 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2466 | { |
| 2467 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2468 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2469 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2470 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 2471 | int plane = intel_crtc->plane; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2472 | u32 reg, temp; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2473 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 2474 | if (intel_crtc->active) |
| 2475 | return; |
| 2476 | |
| 2477 | intel_crtc->active = true; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 2478 | intel_update_watermarks(dev); |
| 2479 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2480 | /* Enable the DPLL */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2481 | reg = DPLL(pipe); |
| 2482 | temp = I915_READ(reg); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2483 | if ((temp & DPLL_VCO_ENABLE) == 0) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2484 | I915_WRITE(reg, temp); |
| 2485 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2486 | /* Wait for the clocks to stabilize. */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2487 | POSTING_READ(reg); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2488 | udelay(150); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2489 | |
| 2490 | I915_WRITE(reg, temp | DPLL_VCO_ENABLE); |
| 2491 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2492 | /* Wait for the clocks to stabilize. */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2493 | POSTING_READ(reg); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2494 | udelay(150); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2495 | |
| 2496 | I915_WRITE(reg, temp | DPLL_VCO_ENABLE); |
| 2497 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2498 | /* Wait for the clocks to stabilize. */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2499 | POSTING_READ(reg); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2500 | udelay(150); |
| 2501 | } |
| 2502 | |
| 2503 | /* Enable the pipe */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2504 | reg = PIPECONF(pipe); |
| 2505 | temp = I915_READ(reg); |
| 2506 | if ((temp & PIPECONF_ENABLE) == 0) |
| 2507 | I915_WRITE(reg, temp | PIPECONF_ENABLE); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2508 | |
| 2509 | /* Enable the plane */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2510 | reg = DSPCNTR(plane); |
| 2511 | temp = I915_READ(reg); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2512 | if ((temp & DISPLAY_PLANE_ENABLE) == 0) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2513 | I915_WRITE(reg, temp | DISPLAY_PLANE_ENABLE); |
| 2514 | intel_flush_display_plane(dev, plane); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | intel_crtc_load_lut(crtc); |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 2518 | intel_update_fbc(dev); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2519 | |
| 2520 | /* Give the overlay scaler a chance to enable if it's on this pipe */ |
| 2521 | intel_crtc_dpms_overlay(intel_crtc, true); |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 2522 | intel_crtc_update_cursor(crtc, true); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2523 | } |
| 2524 | |
| 2525 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
| 2526 | { |
| 2527 | struct drm_device *dev = crtc->dev; |
| 2528 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2529 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2530 | int pipe = intel_crtc->pipe; |
| 2531 | int plane = intel_crtc->plane; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2532 | u32 reg, temp; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2533 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 2534 | if (!intel_crtc->active) |
| 2535 | return; |
| 2536 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2537 | /* Give the overlay scaler a chance to disable if it's on this pipe */ |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 2538 | intel_crtc_wait_for_pending_flips(crtc); |
| 2539 | drm_vblank_off(dev, pipe); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2540 | intel_crtc_dpms_overlay(intel_crtc, false); |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 2541 | intel_crtc_update_cursor(crtc, false); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2542 | |
| 2543 | if (dev_priv->cfb_plane == plane && |
| 2544 | dev_priv->display.disable_fbc) |
| 2545 | dev_priv->display.disable_fbc(dev); |
| 2546 | |
| 2547 | /* Disable display plane */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2548 | reg = DSPCNTR(plane); |
| 2549 | temp = I915_READ(reg); |
| 2550 | if (temp & DISPLAY_PLANE_ENABLE) { |
| 2551 | I915_WRITE(reg, temp & ~DISPLAY_PLANE_ENABLE); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2552 | /* Flush the plane changes */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2553 | intel_flush_display_plane(dev, plane); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2554 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2555 | /* Wait for vblank for the disable to take effect */ |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 2556 | if (IS_GEN2(dev)) |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 2557 | intel_wait_for_vblank(dev, pipe); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2558 | } |
| 2559 | |
| 2560 | /* Don't disable pipe A or pipe A PLLs if needed */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2561 | if (pipe == 0 && (dev_priv->quirks & QUIRK_PIPEA_FORCE)) |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 2562 | goto done; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2563 | |
| 2564 | /* Next, disable display pipes */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2565 | reg = PIPECONF(pipe); |
| 2566 | temp = I915_READ(reg); |
| 2567 | if (temp & PIPECONF_ENABLE) { |
| 2568 | I915_WRITE(reg, temp & ~PIPECONF_ENABLE); |
| 2569 | |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 2570 | /* Wait for the pipe to turn off */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2571 | POSTING_READ(reg); |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 2572 | intel_wait_for_pipe_off(dev, pipe); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2573 | } |
| 2574 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2575 | reg = DPLL(pipe); |
| 2576 | temp = I915_READ(reg); |
| 2577 | if (temp & DPLL_VCO_ENABLE) { |
| 2578 | I915_WRITE(reg, temp & ~DPLL_VCO_ENABLE); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2579 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2580 | /* Wait for the clocks to turn off. */ |
| 2581 | POSTING_READ(reg); |
| 2582 | udelay(150); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2583 | } |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 2584 | |
| 2585 | done: |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 2586 | intel_crtc->active = false; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 2587 | intel_update_fbc(dev); |
| 2588 | intel_update_watermarks(dev); |
| 2589 | intel_clear_scanline_wait(dev); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2590 | } |
| 2591 | |
| 2592 | static void i9xx_crtc_dpms(struct drm_crtc *crtc, int mode) |
| 2593 | { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2594 | /* XXX: When our outputs are all unaware of DPMS modes other than off |
| 2595 | * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC. |
| 2596 | */ |
| 2597 | switch (mode) { |
| 2598 | case DRM_MODE_DPMS_ON: |
| 2599 | case DRM_MODE_DPMS_STANDBY: |
| 2600 | case DRM_MODE_DPMS_SUSPEND: |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2601 | i9xx_crtc_enable(crtc); |
| 2602 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2603 | case DRM_MODE_DPMS_OFF: |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 2604 | i9xx_crtc_disable(crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2605 | break; |
| 2606 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2607 | } |
| 2608 | |
| 2609 | /** |
| 2610 | * Sets the power management mode of the pipe and plane. |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2611 | */ |
| 2612 | static void intel_crtc_dpms(struct drm_crtc *crtc, int mode) |
| 2613 | { |
| 2614 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2615 | struct drm_i915_private *dev_priv = dev->dev_private; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2616 | struct drm_i915_master_private *master_priv; |
| 2617 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2618 | int pipe = intel_crtc->pipe; |
| 2619 | bool enabled; |
| 2620 | |
Chris Wilson | 032d2a0 | 2010-09-06 16:17:22 +0100 | [diff] [blame] | 2621 | if (intel_crtc->dpms_mode == mode) |
| 2622 | return; |
| 2623 | |
Chris Wilson | debcadd | 2010-08-07 11:01:33 +0100 | [diff] [blame] | 2624 | intel_crtc->dpms_mode = mode; |
Chris Wilson | debcadd | 2010-08-07 11:01:33 +0100 | [diff] [blame] | 2625 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2626 | dev_priv->display.dpms(crtc, mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2627 | |
| 2628 | if (!dev->primary->master) |
| 2629 | return; |
| 2630 | |
| 2631 | master_priv = dev->primary->master->driver_priv; |
| 2632 | if (!master_priv->sarea_priv) |
| 2633 | return; |
| 2634 | |
| 2635 | enabled = crtc->enabled && mode != DRM_MODE_DPMS_OFF; |
| 2636 | |
| 2637 | switch (pipe) { |
| 2638 | case 0: |
| 2639 | master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0; |
| 2640 | master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0; |
| 2641 | break; |
| 2642 | case 1: |
| 2643 | master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0; |
| 2644 | master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0; |
| 2645 | break; |
| 2646 | default: |
| 2647 | DRM_ERROR("Can't update pipe %d in SAREA\n", pipe); |
| 2648 | break; |
| 2649 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2650 | } |
| 2651 | |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 2652 | static void intel_crtc_disable(struct drm_crtc *crtc) |
| 2653 | { |
| 2654 | struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; |
| 2655 | struct drm_device *dev = crtc->dev; |
| 2656 | |
| 2657 | crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF); |
| 2658 | |
| 2659 | if (crtc->fb) { |
| 2660 | mutex_lock(&dev->struct_mutex); |
| 2661 | i915_gem_object_unpin(to_intel_framebuffer(crtc->fb)->obj); |
| 2662 | mutex_unlock(&dev->struct_mutex); |
| 2663 | } |
| 2664 | } |
| 2665 | |
Jesse Barnes | 7e7d76c | 2010-09-10 10:47:20 -0700 | [diff] [blame] | 2666 | /* Prepare for a mode set. |
| 2667 | * |
| 2668 | * Note we could be a lot smarter here. We need to figure out which outputs |
| 2669 | * will be enabled, which disabled (in short, how the config will changes) |
| 2670 | * and perform the minimum necessary steps to accomplish that, e.g. updating |
| 2671 | * watermarks, FBC configuration, making sure PLLs are programmed correctly, |
| 2672 | * panel fitting is in the proper state, etc. |
| 2673 | */ |
| 2674 | static void i9xx_crtc_prepare(struct drm_crtc *crtc) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2675 | { |
Jesse Barnes | 7e7d76c | 2010-09-10 10:47:20 -0700 | [diff] [blame] | 2676 | i9xx_crtc_disable(crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2677 | } |
| 2678 | |
Jesse Barnes | 7e7d76c | 2010-09-10 10:47:20 -0700 | [diff] [blame] | 2679 | static void i9xx_crtc_commit(struct drm_crtc *crtc) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2680 | { |
Jesse Barnes | 7e7d76c | 2010-09-10 10:47:20 -0700 | [diff] [blame] | 2681 | i9xx_crtc_enable(crtc); |
Jesse Barnes | 7e7d76c | 2010-09-10 10:47:20 -0700 | [diff] [blame] | 2682 | } |
| 2683 | |
| 2684 | static void ironlake_crtc_prepare(struct drm_crtc *crtc) |
| 2685 | { |
Jesse Barnes | 7e7d76c | 2010-09-10 10:47:20 -0700 | [diff] [blame] | 2686 | ironlake_crtc_disable(crtc); |
Jesse Barnes | 7e7d76c | 2010-09-10 10:47:20 -0700 | [diff] [blame] | 2687 | } |
| 2688 | |
| 2689 | static void ironlake_crtc_commit(struct drm_crtc *crtc) |
| 2690 | { |
Jesse Barnes | 7e7d76c | 2010-09-10 10:47:20 -0700 | [diff] [blame] | 2691 | ironlake_crtc_enable(crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2692 | } |
| 2693 | |
| 2694 | void intel_encoder_prepare (struct drm_encoder *encoder) |
| 2695 | { |
| 2696 | struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; |
| 2697 | /* lvds has its own version of prepare see intel_lvds_prepare */ |
| 2698 | encoder_funcs->dpms(encoder, DRM_MODE_DPMS_OFF); |
| 2699 | } |
| 2700 | |
| 2701 | void intel_encoder_commit (struct drm_encoder *encoder) |
| 2702 | { |
| 2703 | struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; |
| 2704 | /* lvds has its own version of commit see intel_lvds_commit */ |
| 2705 | encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON); |
| 2706 | } |
| 2707 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 2708 | void intel_encoder_destroy(struct drm_encoder *encoder) |
| 2709 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 2710 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 2711 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 2712 | drm_encoder_cleanup(encoder); |
| 2713 | kfree(intel_encoder); |
| 2714 | } |
| 2715 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2716 | static bool intel_crtc_mode_fixup(struct drm_crtc *crtc, |
| 2717 | struct drm_display_mode *mode, |
| 2718 | struct drm_display_mode *adjusted_mode) |
| 2719 | { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2720 | struct drm_device *dev = crtc->dev; |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 2721 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 2722 | if (HAS_PCH_SPLIT(dev)) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2723 | /* FDI link clock is fixed at 2.7G */ |
Jesse Barnes | 2377b74 | 2010-07-07 14:06:43 -0700 | [diff] [blame] | 2724 | if (mode->clock * 3 > IRONLAKE_FDI_FREQ * 4) |
| 2725 | return false; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2726 | } |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 2727 | |
| 2728 | /* XXX some encoders set the crtcinfo, others don't. |
| 2729 | * Obviously we need some form of conflict resolution here... |
| 2730 | */ |
| 2731 | if (adjusted_mode->crtc_htotal == 0) |
| 2732 | drm_mode_set_crtcinfo(adjusted_mode, 0); |
| 2733 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2734 | return true; |
| 2735 | } |
| 2736 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2737 | static int i945_get_display_clock_speed(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2738 | { |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2739 | return 400000; |
| 2740 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2741 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2742 | static int i915_get_display_clock_speed(struct drm_device *dev) |
| 2743 | { |
| 2744 | return 333000; |
| 2745 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2746 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2747 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
| 2748 | { |
| 2749 | return 200000; |
| 2750 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2751 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2752 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
| 2753 | { |
| 2754 | u16 gcfgc = 0; |
| 2755 | |
| 2756 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 2757 | |
| 2758 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2759 | return 133000; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2760 | else { |
| 2761 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 2762 | case GC_DISPLAY_CLOCK_333_MHZ: |
| 2763 | return 333000; |
| 2764 | default: |
| 2765 | case GC_DISPLAY_CLOCK_190_200_MHZ: |
| 2766 | return 190000; |
| 2767 | } |
| 2768 | } |
| 2769 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2770 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2771 | static int i865_get_display_clock_speed(struct drm_device *dev) |
| 2772 | { |
| 2773 | return 266000; |
| 2774 | } |
| 2775 | |
| 2776 | static int i855_get_display_clock_speed(struct drm_device *dev) |
| 2777 | { |
| 2778 | u16 hpllcc = 0; |
| 2779 | /* Assume that the hardware is in the high speed state. This |
| 2780 | * should be the default. |
| 2781 | */ |
| 2782 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { |
| 2783 | case GC_CLOCK_133_200: |
| 2784 | case GC_CLOCK_100_200: |
| 2785 | return 200000; |
| 2786 | case GC_CLOCK_166_250: |
| 2787 | return 250000; |
| 2788 | case GC_CLOCK_100_133: |
| 2789 | return 133000; |
| 2790 | } |
| 2791 | |
| 2792 | /* Shouldn't happen */ |
| 2793 | return 0; |
| 2794 | } |
| 2795 | |
| 2796 | static int i830_get_display_clock_speed(struct drm_device *dev) |
| 2797 | { |
| 2798 | return 133000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2799 | } |
| 2800 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2801 | struct fdi_m_n { |
| 2802 | u32 tu; |
| 2803 | u32 gmch_m; |
| 2804 | u32 gmch_n; |
| 2805 | u32 link_m; |
| 2806 | u32 link_n; |
| 2807 | }; |
| 2808 | |
| 2809 | static void |
| 2810 | fdi_reduce_ratio(u32 *num, u32 *den) |
| 2811 | { |
| 2812 | while (*num > 0xffffff || *den > 0xffffff) { |
| 2813 | *num >>= 1; |
| 2814 | *den >>= 1; |
| 2815 | } |
| 2816 | } |
| 2817 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2818 | static void |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2819 | ironlake_compute_m_n(int bits_per_pixel, int nlanes, int pixel_clock, |
| 2820 | int link_clock, struct fdi_m_n *m_n) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2821 | { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2822 | m_n->tu = 64; /* default size */ |
| 2823 | |
Chris Wilson | 22ed111 | 2010-12-04 01:01:29 +0000 | [diff] [blame] | 2824 | /* BUG_ON(pixel_clock > INT_MAX / 36); */ |
| 2825 | m_n->gmch_m = bits_per_pixel * pixel_clock; |
| 2826 | m_n->gmch_n = link_clock * nlanes * 8; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2827 | fdi_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n); |
| 2828 | |
Chris Wilson | 22ed111 | 2010-12-04 01:01:29 +0000 | [diff] [blame] | 2829 | m_n->link_m = pixel_clock; |
| 2830 | m_n->link_n = link_clock; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2831 | fdi_reduce_ratio(&m_n->link_m, &m_n->link_n); |
| 2832 | } |
| 2833 | |
| 2834 | |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2835 | struct intel_watermark_params { |
| 2836 | unsigned long fifo_size; |
| 2837 | unsigned long max_wm; |
| 2838 | unsigned long default_wm; |
| 2839 | unsigned long guard_size; |
| 2840 | unsigned long cacheline_size; |
| 2841 | }; |
| 2842 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2843 | /* Pineview has different values for various configs */ |
| 2844 | static struct intel_watermark_params pineview_display_wm = { |
| 2845 | PINEVIEW_DISPLAY_FIFO, |
| 2846 | PINEVIEW_MAX_WM, |
| 2847 | PINEVIEW_DFT_WM, |
| 2848 | PINEVIEW_GUARD_WM, |
| 2849 | PINEVIEW_FIFO_LINE_SIZE |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2850 | }; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2851 | static struct intel_watermark_params pineview_display_hplloff_wm = { |
| 2852 | PINEVIEW_DISPLAY_FIFO, |
| 2853 | PINEVIEW_MAX_WM, |
| 2854 | PINEVIEW_DFT_HPLLOFF_WM, |
| 2855 | PINEVIEW_GUARD_WM, |
| 2856 | PINEVIEW_FIFO_LINE_SIZE |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2857 | }; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2858 | static struct intel_watermark_params pineview_cursor_wm = { |
| 2859 | PINEVIEW_CURSOR_FIFO, |
| 2860 | PINEVIEW_CURSOR_MAX_WM, |
| 2861 | PINEVIEW_CURSOR_DFT_WM, |
| 2862 | PINEVIEW_CURSOR_GUARD_WM, |
| 2863 | PINEVIEW_FIFO_LINE_SIZE, |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2864 | }; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2865 | static struct intel_watermark_params pineview_cursor_hplloff_wm = { |
| 2866 | PINEVIEW_CURSOR_FIFO, |
| 2867 | PINEVIEW_CURSOR_MAX_WM, |
| 2868 | PINEVIEW_CURSOR_DFT_WM, |
| 2869 | PINEVIEW_CURSOR_GUARD_WM, |
| 2870 | PINEVIEW_FIFO_LINE_SIZE |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2871 | }; |
Jesse Barnes | 0e442c6 | 2009-10-19 10:09:33 +0900 | [diff] [blame] | 2872 | static struct intel_watermark_params g4x_wm_info = { |
| 2873 | G4X_FIFO_SIZE, |
| 2874 | G4X_MAX_WM, |
| 2875 | G4X_MAX_WM, |
| 2876 | 2, |
| 2877 | G4X_FIFO_LINE_SIZE, |
| 2878 | }; |
Zhao Yakui | 4fe5e61 | 2010-06-12 14:32:25 +0800 | [diff] [blame] | 2879 | static struct intel_watermark_params g4x_cursor_wm_info = { |
| 2880 | I965_CURSOR_FIFO, |
| 2881 | I965_CURSOR_MAX_WM, |
| 2882 | I965_CURSOR_DFT_WM, |
| 2883 | 2, |
| 2884 | G4X_FIFO_LINE_SIZE, |
| 2885 | }; |
| 2886 | static struct intel_watermark_params i965_cursor_wm_info = { |
| 2887 | I965_CURSOR_FIFO, |
| 2888 | I965_CURSOR_MAX_WM, |
| 2889 | I965_CURSOR_DFT_WM, |
| 2890 | 2, |
| 2891 | I915_FIFO_LINE_SIZE, |
| 2892 | }; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2893 | static struct intel_watermark_params i945_wm_info = { |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2894 | I945_FIFO_SIZE, |
| 2895 | I915_MAX_WM, |
| 2896 | 1, |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2897 | 2, |
| 2898 | I915_FIFO_LINE_SIZE |
| 2899 | }; |
| 2900 | static struct intel_watermark_params i915_wm_info = { |
| 2901 | I915_FIFO_SIZE, |
| 2902 | I915_MAX_WM, |
| 2903 | 1, |
| 2904 | 2, |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2905 | I915_FIFO_LINE_SIZE |
| 2906 | }; |
| 2907 | static struct intel_watermark_params i855_wm_info = { |
| 2908 | I855GM_FIFO_SIZE, |
| 2909 | I915_MAX_WM, |
| 2910 | 1, |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2911 | 2, |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2912 | I830_FIFO_LINE_SIZE |
| 2913 | }; |
| 2914 | static struct intel_watermark_params i830_wm_info = { |
| 2915 | I830_FIFO_SIZE, |
| 2916 | I915_MAX_WM, |
| 2917 | 1, |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2918 | 2, |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2919 | I830_FIFO_LINE_SIZE |
| 2920 | }; |
| 2921 | |
Zhenyu Wang | 7f8a856 | 2010-04-01 13:07:53 +0800 | [diff] [blame] | 2922 | static struct intel_watermark_params ironlake_display_wm_info = { |
| 2923 | ILK_DISPLAY_FIFO, |
| 2924 | ILK_DISPLAY_MAXWM, |
| 2925 | ILK_DISPLAY_DFTWM, |
| 2926 | 2, |
| 2927 | ILK_FIFO_LINE_SIZE |
| 2928 | }; |
| 2929 | |
Zhao Yakui | c936f44 | 2010-06-12 14:32:26 +0800 | [diff] [blame] | 2930 | static struct intel_watermark_params ironlake_cursor_wm_info = { |
| 2931 | ILK_CURSOR_FIFO, |
| 2932 | ILK_CURSOR_MAXWM, |
| 2933 | ILK_CURSOR_DFTWM, |
| 2934 | 2, |
| 2935 | ILK_FIFO_LINE_SIZE |
| 2936 | }; |
| 2937 | |
Zhenyu Wang | 7f8a856 | 2010-04-01 13:07:53 +0800 | [diff] [blame] | 2938 | static struct intel_watermark_params ironlake_display_srwm_info = { |
| 2939 | ILK_DISPLAY_SR_FIFO, |
| 2940 | ILK_DISPLAY_MAX_SRWM, |
| 2941 | ILK_DISPLAY_DFT_SRWM, |
| 2942 | 2, |
| 2943 | ILK_FIFO_LINE_SIZE |
| 2944 | }; |
| 2945 | |
| 2946 | static struct intel_watermark_params ironlake_cursor_srwm_info = { |
| 2947 | ILK_CURSOR_SR_FIFO, |
| 2948 | ILK_CURSOR_MAX_SRWM, |
| 2949 | ILK_CURSOR_DFT_SRWM, |
| 2950 | 2, |
| 2951 | ILK_FIFO_LINE_SIZE |
| 2952 | }; |
| 2953 | |
Yuanhan Liu | 1398261 | 2010-12-15 15:42:31 +0800 | [diff] [blame] | 2954 | static struct intel_watermark_params sandybridge_display_wm_info = { |
| 2955 | SNB_DISPLAY_FIFO, |
| 2956 | SNB_DISPLAY_MAXWM, |
| 2957 | SNB_DISPLAY_DFTWM, |
| 2958 | 2, |
| 2959 | SNB_FIFO_LINE_SIZE |
| 2960 | }; |
| 2961 | |
| 2962 | static struct intel_watermark_params sandybridge_cursor_wm_info = { |
| 2963 | SNB_CURSOR_FIFO, |
| 2964 | SNB_CURSOR_MAXWM, |
| 2965 | SNB_CURSOR_DFTWM, |
| 2966 | 2, |
| 2967 | SNB_FIFO_LINE_SIZE |
| 2968 | }; |
| 2969 | |
| 2970 | static struct intel_watermark_params sandybridge_display_srwm_info = { |
| 2971 | SNB_DISPLAY_SR_FIFO, |
| 2972 | SNB_DISPLAY_MAX_SRWM, |
| 2973 | SNB_DISPLAY_DFT_SRWM, |
| 2974 | 2, |
| 2975 | SNB_FIFO_LINE_SIZE |
| 2976 | }; |
| 2977 | |
| 2978 | static struct intel_watermark_params sandybridge_cursor_srwm_info = { |
| 2979 | SNB_CURSOR_SR_FIFO, |
| 2980 | SNB_CURSOR_MAX_SRWM, |
| 2981 | SNB_CURSOR_DFT_SRWM, |
| 2982 | 2, |
| 2983 | SNB_FIFO_LINE_SIZE |
| 2984 | }; |
| 2985 | |
| 2986 | |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2987 | /** |
| 2988 | * intel_calculate_wm - calculate watermark level |
| 2989 | * @clock_in_khz: pixel clock |
| 2990 | * @wm: chip FIFO params |
| 2991 | * @pixel_size: display pixel size |
| 2992 | * @latency_ns: memory latency for the platform |
| 2993 | * |
| 2994 | * Calculate the watermark level (the level at which the display plane will |
| 2995 | * start fetching from memory again). Each chip has a different display |
| 2996 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 2997 | * in the correct intel_watermark_params structure. |
| 2998 | * |
| 2999 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 3000 | * on the pixel size. When it reaches the watermark level, it'll start |
| 3001 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 3002 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 3003 | * will occur, and a display engine hang could result. |
| 3004 | */ |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3005 | static unsigned long intel_calculate_wm(unsigned long clock_in_khz, |
| 3006 | struct intel_watermark_params *wm, |
| 3007 | int pixel_size, |
| 3008 | unsigned long latency_ns) |
| 3009 | { |
Jesse Barnes | 390c4dd | 2009-07-16 13:01:01 -0700 | [diff] [blame] | 3010 | long entries_required, wm_size; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3011 | |
Jesse Barnes | d660467 | 2009-09-11 12:25:56 -0700 | [diff] [blame] | 3012 | /* |
| 3013 | * Note: we need to make sure we don't overflow for various clock & |
| 3014 | * latency values. |
| 3015 | * clocks go from a few thousand to several hundred thousand. |
| 3016 | * latency is usually a few thousand |
| 3017 | */ |
| 3018 | entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) / |
| 3019 | 1000; |
Chris Wilson | 8de9b31 | 2010-07-19 19:59:52 +0100 | [diff] [blame] | 3020 | entries_required = DIV_ROUND_UP(entries_required, wm->cacheline_size); |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 3021 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3022 | DRM_DEBUG_KMS("FIFO entries required for mode: %d\n", entries_required); |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 3023 | |
| 3024 | wm_size = wm->fifo_size - (entries_required + wm->guard_size); |
| 3025 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3026 | DRM_DEBUG_KMS("FIFO watermark level: %d\n", wm_size); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3027 | |
Jesse Barnes | 390c4dd | 2009-07-16 13:01:01 -0700 | [diff] [blame] | 3028 | /* Don't promote wm_size to unsigned... */ |
| 3029 | if (wm_size > (long)wm->max_wm) |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3030 | wm_size = wm->max_wm; |
Chris Wilson | c3add4b | 2010-09-08 09:14:08 +0100 | [diff] [blame] | 3031 | if (wm_size <= 0) |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3032 | wm_size = wm->default_wm; |
| 3033 | return wm_size; |
| 3034 | } |
| 3035 | |
| 3036 | struct cxsr_latency { |
| 3037 | int is_desktop; |
Li Peng | 9553426 | 2010-05-18 18:58:44 +0800 | [diff] [blame] | 3038 | int is_ddr3; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3039 | unsigned long fsb_freq; |
| 3040 | unsigned long mem_freq; |
| 3041 | unsigned long display_sr; |
| 3042 | unsigned long display_hpll_disable; |
| 3043 | unsigned long cursor_sr; |
| 3044 | unsigned long cursor_hpll_disable; |
| 3045 | }; |
| 3046 | |
Chris Wilson | 403c89f | 2010-08-04 15:25:31 +0100 | [diff] [blame] | 3047 | static const struct cxsr_latency cxsr_latency_table[] = { |
Li Peng | 9553426 | 2010-05-18 18:58:44 +0800 | [diff] [blame] | 3048 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 3049 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 3050 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 3051 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 3052 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3053 | |
Li Peng | 9553426 | 2010-05-18 18:58:44 +0800 | [diff] [blame] | 3054 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 3055 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 3056 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 3057 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 3058 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3059 | |
Li Peng | 9553426 | 2010-05-18 18:58:44 +0800 | [diff] [blame] | 3060 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 3061 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 3062 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 3063 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 3064 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3065 | |
Li Peng | 9553426 | 2010-05-18 18:58:44 +0800 | [diff] [blame] | 3066 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 3067 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 3068 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 3069 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 3070 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3071 | |
Li Peng | 9553426 | 2010-05-18 18:58:44 +0800 | [diff] [blame] | 3072 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 3073 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 3074 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 3075 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 3076 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3077 | |
Li Peng | 9553426 | 2010-05-18 18:58:44 +0800 | [diff] [blame] | 3078 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 3079 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 3080 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 3081 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 3082 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3083 | }; |
| 3084 | |
Chris Wilson | 403c89f | 2010-08-04 15:25:31 +0100 | [diff] [blame] | 3085 | static const struct cxsr_latency *intel_get_cxsr_latency(int is_desktop, |
| 3086 | int is_ddr3, |
| 3087 | int fsb, |
| 3088 | int mem) |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3089 | { |
Chris Wilson | 403c89f | 2010-08-04 15:25:31 +0100 | [diff] [blame] | 3090 | const struct cxsr_latency *latency; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3091 | int i; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3092 | |
| 3093 | if (fsb == 0 || mem == 0) |
| 3094 | return NULL; |
| 3095 | |
| 3096 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 3097 | latency = &cxsr_latency_table[i]; |
| 3098 | if (is_desktop == latency->is_desktop && |
Li Peng | 9553426 | 2010-05-18 18:58:44 +0800 | [diff] [blame] | 3099 | is_ddr3 == latency->is_ddr3 && |
Jaswinder Singh Rajput | decbbcd | 2009-09-12 23:15:07 +0530 | [diff] [blame] | 3100 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 3101 | return latency; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3102 | } |
Jaswinder Singh Rajput | decbbcd | 2009-09-12 23:15:07 +0530 | [diff] [blame] | 3103 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3104 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
Jaswinder Singh Rajput | decbbcd | 2009-09-12 23:15:07 +0530 | [diff] [blame] | 3105 | |
| 3106 | return NULL; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3107 | } |
| 3108 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 3109 | static void pineview_disable_cxsr(struct drm_device *dev) |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3110 | { |
| 3111 | struct drm_i915_private *dev_priv = dev->dev_private; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3112 | |
| 3113 | /* deactivate cxsr */ |
Chris Wilson | 3e33d94 | 2010-08-04 11:17:25 +0100 | [diff] [blame] | 3114 | I915_WRITE(DSPFW3, I915_READ(DSPFW3) & ~PINEVIEW_SELF_REFRESH_EN); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3115 | } |
| 3116 | |
Jesse Barnes | bcc24fb | 2009-08-31 10:24:31 -0700 | [diff] [blame] | 3117 | /* |
| 3118 | * Latency for FIFO fetches is dependent on several factors: |
| 3119 | * - memory configuration (speed, channels) |
| 3120 | * - chipset |
| 3121 | * - current MCH state |
| 3122 | * It can be fairly high in some situations, so here we assume a fairly |
| 3123 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 3124 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 3125 | * and power consumption (set it too low to save power and we might see |
| 3126 | * FIFO underruns and display "flicker"). |
| 3127 | * |
| 3128 | * A value of 5us seems to be a good balance; safe for very low end |
| 3129 | * platforms but not overly aggressive on lower latency configs. |
| 3130 | */ |
Tobias Klauser | 69e302a | 2009-12-23 14:14:34 +0100 | [diff] [blame] | 3131 | static const int latency_ns = 5000; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3132 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 3133 | static int i9xx_get_fifo_size(struct drm_device *dev, int plane) |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 3134 | { |
| 3135 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3136 | uint32_t dsparb = I915_READ(DSPARB); |
| 3137 | int size; |
| 3138 | |
Chris Wilson | 8de9b31 | 2010-07-19 19:59:52 +0100 | [diff] [blame] | 3139 | size = dsparb & 0x7f; |
| 3140 | if (plane) |
| 3141 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 3142 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3143 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3144 | plane ? "B" : "A", size); |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 3145 | |
| 3146 | return size; |
| 3147 | } |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3148 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 3149 | static int i85x_get_fifo_size(struct drm_device *dev, int plane) |
| 3150 | { |
| 3151 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3152 | uint32_t dsparb = I915_READ(DSPARB); |
| 3153 | int size; |
| 3154 | |
Chris Wilson | 8de9b31 | 2010-07-19 19:59:52 +0100 | [diff] [blame] | 3155 | size = dsparb & 0x1ff; |
| 3156 | if (plane) |
| 3157 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 3158 | size >>= 1; /* Convert to cachelines */ |
| 3159 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3160 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3161 | plane ? "B" : "A", size); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 3162 | |
| 3163 | return size; |
| 3164 | } |
| 3165 | |
| 3166 | static int i845_get_fifo_size(struct drm_device *dev, int plane) |
| 3167 | { |
| 3168 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3169 | uint32_t dsparb = I915_READ(DSPARB); |
| 3170 | int size; |
| 3171 | |
| 3172 | size = dsparb & 0x7f; |
| 3173 | size >>= 2; /* Convert to cachelines */ |
| 3174 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3175 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3176 | plane ? "B" : "A", |
| 3177 | size); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 3178 | |
| 3179 | return size; |
| 3180 | } |
| 3181 | |
| 3182 | static int i830_get_fifo_size(struct drm_device *dev, int plane) |
| 3183 | { |
| 3184 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3185 | uint32_t dsparb = I915_READ(DSPARB); |
| 3186 | int size; |
| 3187 | |
| 3188 | size = dsparb & 0x7f; |
| 3189 | size >>= 1; /* Convert to cachelines */ |
| 3190 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3191 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3192 | plane ? "B" : "A", size); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 3193 | |
| 3194 | return size; |
| 3195 | } |
| 3196 | |
Zhao Yakui | d429434 | 2010-03-22 22:45:36 +0800 | [diff] [blame] | 3197 | static void pineview_update_wm(struct drm_device *dev, int planea_clock, |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3198 | int planeb_clock, int sr_hdisplay, int unused, |
| 3199 | int pixel_size) |
Zhao Yakui | d429434 | 2010-03-22 22:45:36 +0800 | [diff] [blame] | 3200 | { |
| 3201 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 403c89f | 2010-08-04 15:25:31 +0100 | [diff] [blame] | 3202 | const struct cxsr_latency *latency; |
Zhao Yakui | d429434 | 2010-03-22 22:45:36 +0800 | [diff] [blame] | 3203 | u32 reg; |
| 3204 | unsigned long wm; |
Zhao Yakui | d429434 | 2010-03-22 22:45:36 +0800 | [diff] [blame] | 3205 | int sr_clock; |
| 3206 | |
Chris Wilson | 403c89f | 2010-08-04 15:25:31 +0100 | [diff] [blame] | 3207 | latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->is_ddr3, |
Li Peng | 9553426 | 2010-05-18 18:58:44 +0800 | [diff] [blame] | 3208 | dev_priv->fsb_freq, dev_priv->mem_freq); |
Zhao Yakui | d429434 | 2010-03-22 22:45:36 +0800 | [diff] [blame] | 3209 | if (!latency) { |
| 3210 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 3211 | pineview_disable_cxsr(dev); |
| 3212 | return; |
| 3213 | } |
| 3214 | |
| 3215 | if (!planea_clock || !planeb_clock) { |
| 3216 | sr_clock = planea_clock ? planea_clock : planeb_clock; |
| 3217 | |
| 3218 | /* Display SR */ |
| 3219 | wm = intel_calculate_wm(sr_clock, &pineview_display_wm, |
| 3220 | pixel_size, latency->display_sr); |
| 3221 | reg = I915_READ(DSPFW1); |
| 3222 | reg &= ~DSPFW_SR_MASK; |
| 3223 | reg |= wm << DSPFW_SR_SHIFT; |
| 3224 | I915_WRITE(DSPFW1, reg); |
| 3225 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
| 3226 | |
| 3227 | /* cursor SR */ |
| 3228 | wm = intel_calculate_wm(sr_clock, &pineview_cursor_wm, |
| 3229 | pixel_size, latency->cursor_sr); |
| 3230 | reg = I915_READ(DSPFW3); |
| 3231 | reg &= ~DSPFW_CURSOR_SR_MASK; |
| 3232 | reg |= (wm & 0x3f) << DSPFW_CURSOR_SR_SHIFT; |
| 3233 | I915_WRITE(DSPFW3, reg); |
| 3234 | |
| 3235 | /* Display HPLL off SR */ |
| 3236 | wm = intel_calculate_wm(sr_clock, &pineview_display_hplloff_wm, |
| 3237 | pixel_size, latency->display_hpll_disable); |
| 3238 | reg = I915_READ(DSPFW3); |
| 3239 | reg &= ~DSPFW_HPLL_SR_MASK; |
| 3240 | reg |= wm & DSPFW_HPLL_SR_MASK; |
| 3241 | I915_WRITE(DSPFW3, reg); |
| 3242 | |
| 3243 | /* cursor HPLL off SR */ |
| 3244 | wm = intel_calculate_wm(sr_clock, &pineview_cursor_hplloff_wm, |
| 3245 | pixel_size, latency->cursor_hpll_disable); |
| 3246 | reg = I915_READ(DSPFW3); |
| 3247 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
| 3248 | reg |= (wm & 0x3f) << DSPFW_HPLL_CURSOR_SHIFT; |
| 3249 | I915_WRITE(DSPFW3, reg); |
| 3250 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
| 3251 | |
| 3252 | /* activate cxsr */ |
Chris Wilson | 3e33d94 | 2010-08-04 11:17:25 +0100 | [diff] [blame] | 3253 | I915_WRITE(DSPFW3, |
| 3254 | I915_READ(DSPFW3) | PINEVIEW_SELF_REFRESH_EN); |
Zhao Yakui | d429434 | 2010-03-22 22:45:36 +0800 | [diff] [blame] | 3255 | DRM_DEBUG_KMS("Self-refresh is enabled\n"); |
| 3256 | } else { |
| 3257 | pineview_disable_cxsr(dev); |
| 3258 | DRM_DEBUG_KMS("Self-refresh is disabled\n"); |
| 3259 | } |
| 3260 | } |
| 3261 | |
Jesse Barnes | 0e442c6 | 2009-10-19 10:09:33 +0900 | [diff] [blame] | 3262 | static void g4x_update_wm(struct drm_device *dev, int planea_clock, |
Zhao Yakui | fa14321 | 2010-06-12 14:32:23 +0800 | [diff] [blame] | 3263 | int planeb_clock, int sr_hdisplay, int sr_htotal, |
| 3264 | int pixel_size) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3265 | { |
| 3266 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 0e442c6 | 2009-10-19 10:09:33 +0900 | [diff] [blame] | 3267 | int total_size, cacheline_size; |
| 3268 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm, cursor_sr; |
| 3269 | struct intel_watermark_params planea_params, planeb_params; |
| 3270 | unsigned long line_time_us; |
| 3271 | int sr_clock, sr_entries = 0, entries_required; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3272 | |
Jesse Barnes | 0e442c6 | 2009-10-19 10:09:33 +0900 | [diff] [blame] | 3273 | /* Create copies of the base settings for each pipe */ |
| 3274 | planea_params = planeb_params = g4x_wm_info; |
| 3275 | |
| 3276 | /* Grab a couple of global values before we overwrite them */ |
| 3277 | total_size = planea_params.fifo_size; |
| 3278 | cacheline_size = planea_params.cacheline_size; |
| 3279 | |
| 3280 | /* |
| 3281 | * Note: we need to make sure we don't overflow for various clock & |
| 3282 | * latency values. |
| 3283 | * clocks go from a few thousand to several hundred thousand. |
| 3284 | * latency is usually a few thousand |
| 3285 | */ |
| 3286 | entries_required = ((planea_clock / 1000) * pixel_size * latency_ns) / |
| 3287 | 1000; |
Chris Wilson | 8de9b31 | 2010-07-19 19:59:52 +0100 | [diff] [blame] | 3288 | entries_required = DIV_ROUND_UP(entries_required, G4X_FIFO_LINE_SIZE); |
Jesse Barnes | 0e442c6 | 2009-10-19 10:09:33 +0900 | [diff] [blame] | 3289 | planea_wm = entries_required + planea_params.guard_size; |
| 3290 | |
| 3291 | entries_required = ((planeb_clock / 1000) * pixel_size * latency_ns) / |
| 3292 | 1000; |
Chris Wilson | 8de9b31 | 2010-07-19 19:59:52 +0100 | [diff] [blame] | 3293 | entries_required = DIV_ROUND_UP(entries_required, G4X_FIFO_LINE_SIZE); |
Jesse Barnes | 0e442c6 | 2009-10-19 10:09:33 +0900 | [diff] [blame] | 3294 | planeb_wm = entries_required + planeb_params.guard_size; |
| 3295 | |
| 3296 | cursora_wm = cursorb_wm = 16; |
| 3297 | cursor_sr = 32; |
| 3298 | |
| 3299 | DRM_DEBUG("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 3300 | |
| 3301 | /* Calc sr entries for one plane configs */ |
| 3302 | if (sr_hdisplay && (!planea_clock || !planeb_clock)) { |
| 3303 | /* self-refresh has much higher latency */ |
Tobias Klauser | 69e302a | 2009-12-23 14:14:34 +0100 | [diff] [blame] | 3304 | static const int sr_latency_ns = 12000; |
Jesse Barnes | 0e442c6 | 2009-10-19 10:09:33 +0900 | [diff] [blame] | 3305 | |
| 3306 | sr_clock = planea_clock ? planea_clock : planeb_clock; |
Zhao Yakui | fa14321 | 2010-06-12 14:32:23 +0800 | [diff] [blame] | 3307 | line_time_us = ((sr_htotal * 1000) / sr_clock); |
Jesse Barnes | 0e442c6 | 2009-10-19 10:09:33 +0900 | [diff] [blame] | 3308 | |
| 3309 | /* Use ns/us then divide to preserve precision */ |
Zhao Yakui | fa14321 | 2010-06-12 14:32:23 +0800 | [diff] [blame] | 3310 | sr_entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3311 | pixel_size * sr_hdisplay; |
Chris Wilson | 8de9b31 | 2010-07-19 19:59:52 +0100 | [diff] [blame] | 3312 | sr_entries = DIV_ROUND_UP(sr_entries, cacheline_size); |
Zhao Yakui | 4fe5e61 | 2010-06-12 14:32:25 +0800 | [diff] [blame] | 3313 | |
| 3314 | entries_required = (((sr_latency_ns / line_time_us) + |
| 3315 | 1000) / 1000) * pixel_size * 64; |
Chris Wilson | 8de9b31 | 2010-07-19 19:59:52 +0100 | [diff] [blame] | 3316 | entries_required = DIV_ROUND_UP(entries_required, |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3317 | g4x_cursor_wm_info.cacheline_size); |
Zhao Yakui | 4fe5e61 | 2010-06-12 14:32:25 +0800 | [diff] [blame] | 3318 | cursor_sr = entries_required + g4x_cursor_wm_info.guard_size; |
| 3319 | |
| 3320 | if (cursor_sr > g4x_cursor_wm_info.max_wm) |
| 3321 | cursor_sr = g4x_cursor_wm_info.max_wm; |
| 3322 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 3323 | "cursor %d\n", sr_entries, cursor_sr); |
| 3324 | |
Jesse Barnes | 0e442c6 | 2009-10-19 10:09:33 +0900 | [diff] [blame] | 3325 | I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN); |
David John | 33c5fd1 | 2010-01-27 15:19:08 +0530 | [diff] [blame] | 3326 | } else { |
| 3327 | /* Turn off self refresh if both pipes are enabled */ |
| 3328 | I915_WRITE(FW_BLC_SELF, I915_READ(FW_BLC_SELF) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3329 | & ~FW_BLC_SELF_EN); |
Jesse Barnes | 0e442c6 | 2009-10-19 10:09:33 +0900 | [diff] [blame] | 3330 | } |
| 3331 | |
| 3332 | DRM_DEBUG("Setting FIFO watermarks - A: %d, B: %d, SR %d\n", |
| 3333 | planea_wm, planeb_wm, sr_entries); |
| 3334 | |
| 3335 | planea_wm &= 0x3f; |
| 3336 | planeb_wm &= 0x3f; |
| 3337 | |
| 3338 | I915_WRITE(DSPFW1, (sr_entries << DSPFW_SR_SHIFT) | |
| 3339 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 3340 | (planeb_wm << DSPFW_PLANEB_SHIFT) | planea_wm); |
| 3341 | I915_WRITE(DSPFW2, (I915_READ(DSPFW2) & DSPFW_CURSORA_MASK) | |
| 3342 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 3343 | /* HPLL off in SR has some issues on G4x... disable it */ |
| 3344 | I915_WRITE(DSPFW3, (I915_READ(DSPFW3) & ~DSPFW_HPLL_SR_EN) | |
| 3345 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3346 | } |
| 3347 | |
Jesse Barnes | 1dc7546 | 2009-10-19 10:08:17 +0900 | [diff] [blame] | 3348 | static void i965_update_wm(struct drm_device *dev, int planea_clock, |
Zhao Yakui | fa14321 | 2010-06-12 14:32:23 +0800 | [diff] [blame] | 3349 | int planeb_clock, int sr_hdisplay, int sr_htotal, |
| 3350 | int pixel_size) |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3351 | { |
| 3352 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 1dc7546 | 2009-10-19 10:08:17 +0900 | [diff] [blame] | 3353 | unsigned long line_time_us; |
| 3354 | int sr_clock, sr_entries, srwm = 1; |
Zhao Yakui | 4fe5e61 | 2010-06-12 14:32:25 +0800 | [diff] [blame] | 3355 | int cursor_sr = 16; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3356 | |
Jesse Barnes | 1dc7546 | 2009-10-19 10:08:17 +0900 | [diff] [blame] | 3357 | /* Calc sr entries for one plane configs */ |
| 3358 | if (sr_hdisplay && (!planea_clock || !planeb_clock)) { |
| 3359 | /* self-refresh has much higher latency */ |
Tobias Klauser | 69e302a | 2009-12-23 14:14:34 +0100 | [diff] [blame] | 3360 | static const int sr_latency_ns = 12000; |
Jesse Barnes | 1dc7546 | 2009-10-19 10:08:17 +0900 | [diff] [blame] | 3361 | |
| 3362 | sr_clock = planea_clock ? planea_clock : planeb_clock; |
Zhao Yakui | fa14321 | 2010-06-12 14:32:23 +0800 | [diff] [blame] | 3363 | line_time_us = ((sr_htotal * 1000) / sr_clock); |
Jesse Barnes | 1dc7546 | 2009-10-19 10:08:17 +0900 | [diff] [blame] | 3364 | |
| 3365 | /* Use ns/us then divide to preserve precision */ |
Zhao Yakui | fa14321 | 2010-06-12 14:32:23 +0800 | [diff] [blame] | 3366 | sr_entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3367 | pixel_size * sr_hdisplay; |
Chris Wilson | 8de9b31 | 2010-07-19 19:59:52 +0100 | [diff] [blame] | 3368 | sr_entries = DIV_ROUND_UP(sr_entries, I915_FIFO_LINE_SIZE); |
Jesse Barnes | 1dc7546 | 2009-10-19 10:08:17 +0900 | [diff] [blame] | 3369 | DRM_DEBUG("self-refresh entries: %d\n", sr_entries); |
Zhao Yakui | 1b07e04 | 2010-06-12 14:32:24 +0800 | [diff] [blame] | 3370 | srwm = I965_FIFO_SIZE - sr_entries; |
Jesse Barnes | 1dc7546 | 2009-10-19 10:08:17 +0900 | [diff] [blame] | 3371 | if (srwm < 0) |
| 3372 | srwm = 1; |
Zhao Yakui | 1b07e04 | 2010-06-12 14:32:24 +0800 | [diff] [blame] | 3373 | srwm &= 0x1ff; |
Zhao Yakui | 4fe5e61 | 2010-06-12 14:32:25 +0800 | [diff] [blame] | 3374 | |
| 3375 | sr_entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3376 | pixel_size * 64; |
Chris Wilson | 8de9b31 | 2010-07-19 19:59:52 +0100 | [diff] [blame] | 3377 | sr_entries = DIV_ROUND_UP(sr_entries, |
| 3378 | i965_cursor_wm_info.cacheline_size); |
Zhao Yakui | 4fe5e61 | 2010-06-12 14:32:25 +0800 | [diff] [blame] | 3379 | cursor_sr = i965_cursor_wm_info.fifo_size - |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3380 | (sr_entries + i965_cursor_wm_info.guard_size); |
Zhao Yakui | 4fe5e61 | 2010-06-12 14:32:25 +0800 | [diff] [blame] | 3381 | |
| 3382 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 3383 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 3384 | |
| 3385 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 3386 | "cursor %d\n", srwm, cursor_sr); |
| 3387 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 3388 | if (IS_CRESTLINE(dev)) |
Jesse Barnes | adcdbc6 | 2010-06-30 13:49:37 -0700 | [diff] [blame] | 3389 | I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN); |
David John | 33c5fd1 | 2010-01-27 15:19:08 +0530 | [diff] [blame] | 3390 | } else { |
| 3391 | /* Turn off self refresh if both pipes are enabled */ |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 3392 | if (IS_CRESTLINE(dev)) |
Jesse Barnes | adcdbc6 | 2010-06-30 13:49:37 -0700 | [diff] [blame] | 3393 | I915_WRITE(FW_BLC_SELF, I915_READ(FW_BLC_SELF) |
| 3394 | & ~FW_BLC_SELF_EN); |
Jesse Barnes | 1dc7546 | 2009-10-19 10:08:17 +0900 | [diff] [blame] | 3395 | } |
| 3396 | |
| 3397 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 3398 | srwm); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3399 | |
| 3400 | /* 965 has limitations... */ |
Jesse Barnes | 1dc7546 | 2009-10-19 10:08:17 +0900 | [diff] [blame] | 3401 | I915_WRITE(DSPFW1, (srwm << DSPFW_SR_SHIFT) | (8 << 16) | (8 << 8) | |
| 3402 | (8 << 0)); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3403 | I915_WRITE(DSPFW2, (8 << 8) | (8 << 0)); |
Zhao Yakui | 4fe5e61 | 2010-06-12 14:32:25 +0800 | [diff] [blame] | 3404 | /* update cursor SR watermark */ |
| 3405 | I915_WRITE(DSPFW3, (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3406 | } |
| 3407 | |
| 3408 | static void i9xx_update_wm(struct drm_device *dev, int planea_clock, |
Zhao Yakui | fa14321 | 2010-06-12 14:32:23 +0800 | [diff] [blame] | 3409 | int planeb_clock, int sr_hdisplay, int sr_htotal, |
| 3410 | int pixel_size) |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3411 | { |
| 3412 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 3413 | uint32_t fwater_lo; |
| 3414 | uint32_t fwater_hi; |
| 3415 | int total_size, cacheline_size, cwm, srwm = 1; |
| 3416 | int planea_wm, planeb_wm; |
| 3417 | struct intel_watermark_params planea_params, planeb_params; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3418 | unsigned long line_time_us; |
| 3419 | int sr_clock, sr_entries = 0; |
| 3420 | |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 3421 | /* Create copies of the base settings for each pipe */ |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 3422 | if (IS_CRESTLINE(dev) || IS_I945GM(dev)) |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 3423 | planea_params = planeb_params = i945_wm_info; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 3424 | else if (!IS_GEN2(dev)) |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 3425 | planea_params = planeb_params = i915_wm_info; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3426 | else |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 3427 | planea_params = planeb_params = i855_wm_info; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3428 | |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 3429 | /* Grab a couple of global values before we overwrite them */ |
| 3430 | total_size = planea_params.fifo_size; |
| 3431 | cacheline_size = planea_params.cacheline_size; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3432 | |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 3433 | /* Update per-plane FIFO sizes */ |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 3434 | planea_params.fifo_size = dev_priv->display.get_fifo_size(dev, 0); |
| 3435 | planeb_params.fifo_size = dev_priv->display.get_fifo_size(dev, 1); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3436 | |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 3437 | planea_wm = intel_calculate_wm(planea_clock, &planea_params, |
| 3438 | pixel_size, latency_ns); |
| 3439 | planeb_wm = intel_calculate_wm(planeb_clock, &planeb_params, |
| 3440 | pixel_size, latency_ns); |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3441 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3442 | |
| 3443 | /* |
| 3444 | * Overlay gets an aggressive default since video jitter is bad. |
| 3445 | */ |
| 3446 | cwm = 2; |
| 3447 | |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 3448 | /* Calc sr entries for one plane configs */ |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3449 | if (HAS_FW_BLC(dev) && sr_hdisplay && |
| 3450 | (!planea_clock || !planeb_clock)) { |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 3451 | /* self-refresh has much higher latency */ |
Tobias Klauser | 69e302a | 2009-12-23 14:14:34 +0100 | [diff] [blame] | 3452 | static const int sr_latency_ns = 6000; |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 3453 | |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3454 | sr_clock = planea_clock ? planea_clock : planeb_clock; |
Zhao Yakui | fa14321 | 2010-06-12 14:32:23 +0800 | [diff] [blame] | 3455 | line_time_us = ((sr_htotal * 1000) / sr_clock); |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 3456 | |
| 3457 | /* Use ns/us then divide to preserve precision */ |
Zhao Yakui | fa14321 | 2010-06-12 14:32:23 +0800 | [diff] [blame] | 3458 | sr_entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3459 | pixel_size * sr_hdisplay; |
Chris Wilson | 8de9b31 | 2010-07-19 19:59:52 +0100 | [diff] [blame] | 3460 | sr_entries = DIV_ROUND_UP(sr_entries, cacheline_size); |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3461 | DRM_DEBUG_KMS("self-refresh entries: %d\n", sr_entries); |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 3462 | srwm = total_size - sr_entries; |
| 3463 | if (srwm < 0) |
| 3464 | srwm = 1; |
Li Peng | ee980b8 | 2010-01-27 19:01:11 +0800 | [diff] [blame] | 3465 | |
| 3466 | if (IS_I945G(dev) || IS_I945GM(dev)) |
| 3467 | I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
| 3468 | else if (IS_I915GM(dev)) { |
| 3469 | /* 915M has a smaller SRWM field */ |
| 3470 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 3471 | I915_WRITE(INSTPM, I915_READ(INSTPM) | INSTPM_SELF_EN); |
| 3472 | } |
David John | 33c5fd1 | 2010-01-27 15:19:08 +0530 | [diff] [blame] | 3473 | } else { |
| 3474 | /* Turn off self refresh if both pipes are enabled */ |
Li Peng | ee980b8 | 2010-01-27 19:01:11 +0800 | [diff] [blame] | 3475 | if (IS_I945G(dev) || IS_I945GM(dev)) { |
| 3476 | I915_WRITE(FW_BLC_SELF, I915_READ(FW_BLC_SELF) |
| 3477 | & ~FW_BLC_SELF_EN); |
| 3478 | } else if (IS_I915GM(dev)) { |
| 3479 | I915_WRITE(INSTPM, I915_READ(INSTPM) & ~INSTPM_SELF_EN); |
| 3480 | } |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3481 | } |
| 3482 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3483 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3484 | planea_wm, planeb_wm, cwm, srwm); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3485 | |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 3486 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 3487 | fwater_hi = (cwm & 0x1f); |
| 3488 | |
| 3489 | /* Set request length to 8 cachelines per fetch */ |
| 3490 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 3491 | fwater_hi = fwater_hi | (1 << 8); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3492 | |
| 3493 | I915_WRITE(FW_BLC, fwater_lo); |
| 3494 | I915_WRITE(FW_BLC2, fwater_hi); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3495 | } |
| 3496 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 3497 | static void i830_update_wm(struct drm_device *dev, int planea_clock, int unused, |
Zhao Yakui | fa14321 | 2010-06-12 14:32:23 +0800 | [diff] [blame] | 3498 | int unused2, int unused3, int pixel_size) |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3499 | { |
| 3500 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | f360132 | 2009-07-22 12:54:59 -0700 | [diff] [blame] | 3501 | uint32_t fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 3502 | int planea_wm; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3503 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 3504 | i830_wm_info.fifo_size = dev_priv->display.get_fifo_size(dev, 0); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3505 | |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 3506 | planea_wm = intel_calculate_wm(planea_clock, &i830_wm_info, |
| 3507 | pixel_size, latency_ns); |
Jesse Barnes | f360132 | 2009-07-22 12:54:59 -0700 | [diff] [blame] | 3508 | fwater_lo |= (3<<8) | planea_wm; |
| 3509 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3510 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3511 | |
| 3512 | I915_WRITE(FW_BLC, fwater_lo); |
| 3513 | } |
| 3514 | |
Zhenyu Wang | 7f8a856 | 2010-04-01 13:07:53 +0800 | [diff] [blame] | 3515 | #define ILK_LP0_PLANE_LATENCY 700 |
Zhao Yakui | c936f44 | 2010-06-12 14:32:26 +0800 | [diff] [blame] | 3516 | #define ILK_LP0_CURSOR_LATENCY 1300 |
Zhenyu Wang | 7f8a856 | 2010-04-01 13:07:53 +0800 | [diff] [blame] | 3517 | |
Chris Wilson | 4ed765f | 2010-09-11 10:46:47 +0100 | [diff] [blame] | 3518 | static bool ironlake_compute_wm0(struct drm_device *dev, |
| 3519 | int pipe, |
Yuanhan Liu | 1398261 | 2010-12-15 15:42:31 +0800 | [diff] [blame] | 3520 | const struct intel_watermark_params *display, |
Yuanhan Liu | a0fa62d | 2010-12-23 16:35:40 +0800 | [diff] [blame] | 3521 | int display_latency_ns, |
Yuanhan Liu | 1398261 | 2010-12-15 15:42:31 +0800 | [diff] [blame] | 3522 | const struct intel_watermark_params *cursor, |
Yuanhan Liu | a0fa62d | 2010-12-23 16:35:40 +0800 | [diff] [blame] | 3523 | int cursor_latency_ns, |
Chris Wilson | 4ed765f | 2010-09-11 10:46:47 +0100 | [diff] [blame] | 3524 | int *plane_wm, |
| 3525 | int *cursor_wm) |
| 3526 | { |
| 3527 | struct drm_crtc *crtc; |
Chris Wilson | db66e37 | 2011-01-08 09:02:21 +0000 | [diff] [blame] | 3528 | int htotal, hdisplay, clock, pixel_size; |
| 3529 | int line_time_us, line_count; |
| 3530 | int entries, tlb_miss; |
Chris Wilson | 4ed765f | 2010-09-11 10:46:47 +0100 | [diff] [blame] | 3531 | |
| 3532 | crtc = intel_get_crtc_for_pipe(dev, pipe); |
| 3533 | if (crtc->fb == NULL || !crtc->enabled) |
| 3534 | return false; |
| 3535 | |
| 3536 | htotal = crtc->mode.htotal; |
| 3537 | hdisplay = crtc->mode.hdisplay; |
| 3538 | clock = crtc->mode.clock; |
| 3539 | pixel_size = crtc->fb->bits_per_pixel / 8; |
| 3540 | |
| 3541 | /* Use the small buffer method to calculate plane watermark */ |
Yuanhan Liu | a0fa62d | 2010-12-23 16:35:40 +0800 | [diff] [blame] | 3542 | entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000; |
Chris Wilson | db66e37 | 2011-01-08 09:02:21 +0000 | [diff] [blame] | 3543 | tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8; |
| 3544 | if (tlb_miss > 0) |
| 3545 | entries += tlb_miss; |
Yuanhan Liu | 1398261 | 2010-12-15 15:42:31 +0800 | [diff] [blame] | 3546 | entries = DIV_ROUND_UP(entries, display->cacheline_size); |
| 3547 | *plane_wm = entries + display->guard_size; |
| 3548 | if (*plane_wm > (int)display->max_wm) |
| 3549 | *plane_wm = display->max_wm; |
Chris Wilson | 4ed765f | 2010-09-11 10:46:47 +0100 | [diff] [blame] | 3550 | |
| 3551 | /* Use the large buffer method to calculate cursor watermark */ |
| 3552 | line_time_us = ((htotal * 1000) / clock); |
Yuanhan Liu | a0fa62d | 2010-12-23 16:35:40 +0800 | [diff] [blame] | 3553 | line_count = (cursor_latency_ns / line_time_us + 1000) / 1000; |
Chris Wilson | 4ed765f | 2010-09-11 10:46:47 +0100 | [diff] [blame] | 3554 | entries = line_count * 64 * pixel_size; |
Chris Wilson | db66e37 | 2011-01-08 09:02:21 +0000 | [diff] [blame] | 3555 | tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8; |
| 3556 | if (tlb_miss > 0) |
| 3557 | entries += tlb_miss; |
Yuanhan Liu | 1398261 | 2010-12-15 15:42:31 +0800 | [diff] [blame] | 3558 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 3559 | *cursor_wm = entries + cursor->guard_size; |
| 3560 | if (*cursor_wm > (int)cursor->max_wm) |
| 3561 | *cursor_wm = (int)cursor->max_wm; |
Chris Wilson | 4ed765f | 2010-09-11 10:46:47 +0100 | [diff] [blame] | 3562 | |
| 3563 | return true; |
| 3564 | } |
| 3565 | |
Jesse Barnes | b79d499 | 2010-12-21 13:10:23 -0800 | [diff] [blame] | 3566 | /* |
| 3567 | * Check the wm result. |
| 3568 | * |
| 3569 | * If any calculated watermark values is larger than the maximum value that |
| 3570 | * can be programmed into the associated watermark register, that watermark |
| 3571 | * must be disabled. |
| 3572 | */ |
| 3573 | static bool ironlake_check_srwm(struct drm_device *dev, int level, |
| 3574 | int fbc_wm, int display_wm, int cursor_wm, |
| 3575 | const struct intel_watermark_params *display, |
| 3576 | const struct intel_watermark_params *cursor) |
| 3577 | { |
| 3578 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3579 | |
| 3580 | DRM_DEBUG_KMS("watermark %d: display plane %d, fbc lines %d," |
| 3581 | " cursor %d\n", level, display_wm, fbc_wm, cursor_wm); |
| 3582 | |
| 3583 | if (fbc_wm > SNB_FBC_MAX_SRWM) { |
| 3584 | DRM_DEBUG_KMS("fbc watermark(%d) is too large(%d), disabling wm%d+\n", |
| 3585 | fbc_wm, SNB_FBC_MAX_SRWM, level); |
| 3586 | |
| 3587 | /* fbc has it's own way to disable FBC WM */ |
| 3588 | I915_WRITE(DISP_ARB_CTL, |
| 3589 | I915_READ(DISP_ARB_CTL) | DISP_FBC_WM_DIS); |
| 3590 | return false; |
| 3591 | } |
| 3592 | |
| 3593 | if (display_wm > display->max_wm) { |
| 3594 | DRM_DEBUG_KMS("display watermark(%d) is too large(%d), disabling wm%d+\n", |
| 3595 | display_wm, SNB_DISPLAY_MAX_SRWM, level); |
| 3596 | return false; |
| 3597 | } |
| 3598 | |
| 3599 | if (cursor_wm > cursor->max_wm) { |
| 3600 | DRM_DEBUG_KMS("cursor watermark(%d) is too large(%d), disabling wm%d+\n", |
| 3601 | cursor_wm, SNB_CURSOR_MAX_SRWM, level); |
| 3602 | return false; |
| 3603 | } |
| 3604 | |
| 3605 | if (!(fbc_wm || display_wm || cursor_wm)) { |
| 3606 | DRM_DEBUG_KMS("latency %d is 0, disabling wm%d+\n", level, level); |
| 3607 | return false; |
| 3608 | } |
| 3609 | |
| 3610 | return true; |
| 3611 | } |
| 3612 | |
| 3613 | /* |
| 3614 | * Compute watermark values of WM[1-3], |
| 3615 | */ |
| 3616 | static bool ironlake_compute_srwm(struct drm_device *dev, int level, |
| 3617 | int hdisplay, int htotal, |
| 3618 | int pixel_size, int clock, int latency_ns, |
| 3619 | const struct intel_watermark_params *display, |
| 3620 | const struct intel_watermark_params *cursor, |
| 3621 | int *fbc_wm, int *display_wm, int *cursor_wm) |
| 3622 | { |
| 3623 | |
| 3624 | unsigned long line_time_us; |
| 3625 | int line_count, line_size; |
| 3626 | int small, large; |
| 3627 | int entries; |
| 3628 | |
| 3629 | if (!latency_ns) { |
| 3630 | *fbc_wm = *display_wm = *cursor_wm = 0; |
| 3631 | return false; |
| 3632 | } |
| 3633 | |
| 3634 | line_time_us = (htotal * 1000) / clock; |
| 3635 | line_count = (latency_ns / line_time_us + 1000) / 1000; |
| 3636 | line_size = hdisplay * pixel_size; |
| 3637 | |
| 3638 | /* Use the minimum of the small and large buffer method for primary */ |
| 3639 | small = ((clock * pixel_size / 1000) * latency_ns) / 1000; |
| 3640 | large = line_count * line_size; |
| 3641 | |
| 3642 | entries = DIV_ROUND_UP(min(small, large), display->cacheline_size); |
| 3643 | *display_wm = entries + display->guard_size; |
| 3644 | |
| 3645 | /* |
| 3646 | * Spec says: |
| 3647 | * FBC WM = ((Final Primary WM * 64) / number of bytes per line) + 2 |
| 3648 | */ |
| 3649 | *fbc_wm = DIV_ROUND_UP(*display_wm * 64, line_size) + 2; |
| 3650 | |
| 3651 | /* calculate the self-refresh watermark for display cursor */ |
| 3652 | entries = line_count * pixel_size * 64; |
| 3653 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 3654 | *cursor_wm = entries + cursor->guard_size; |
| 3655 | |
| 3656 | return ironlake_check_srwm(dev, level, |
| 3657 | *fbc_wm, *display_wm, *cursor_wm, |
| 3658 | display, cursor); |
| 3659 | } |
| 3660 | |
Chris Wilson | 4ed765f | 2010-09-11 10:46:47 +0100 | [diff] [blame] | 3661 | static void ironlake_update_wm(struct drm_device *dev, |
| 3662 | int planea_clock, int planeb_clock, |
Jesse Barnes | b79d499 | 2010-12-21 13:10:23 -0800 | [diff] [blame] | 3663 | int hdisplay, int htotal, |
Chris Wilson | 4ed765f | 2010-09-11 10:46:47 +0100 | [diff] [blame] | 3664 | int pixel_size) |
Zhenyu Wang | 7f8a856 | 2010-04-01 13:07:53 +0800 | [diff] [blame] | 3665 | { |
| 3666 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | b79d499 | 2010-12-21 13:10:23 -0800 | [diff] [blame] | 3667 | int fbc_wm, plane_wm, cursor_wm, enabled; |
| 3668 | int clock; |
Zhao Yakui | c936f44 | 2010-06-12 14:32:26 +0800 | [diff] [blame] | 3669 | |
Chris Wilson | 4ed765f | 2010-09-11 10:46:47 +0100 | [diff] [blame] | 3670 | enabled = 0; |
Yuanhan Liu | 1398261 | 2010-12-15 15:42:31 +0800 | [diff] [blame] | 3671 | if (ironlake_compute_wm0(dev, 0, |
| 3672 | &ironlake_display_wm_info, |
| 3673 | ILK_LP0_PLANE_LATENCY, |
| 3674 | &ironlake_cursor_wm_info, |
| 3675 | ILK_LP0_CURSOR_LATENCY, |
| 3676 | &plane_wm, &cursor_wm)) { |
Chris Wilson | 4ed765f | 2010-09-11 10:46:47 +0100 | [diff] [blame] | 3677 | I915_WRITE(WM0_PIPEA_ILK, |
| 3678 | (plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm); |
| 3679 | DRM_DEBUG_KMS("FIFO watermarks For pipe A -" |
| 3680 | " plane %d, " "cursor: %d\n", |
| 3681 | plane_wm, cursor_wm); |
| 3682 | enabled++; |
Zhao Yakui | c936f44 | 2010-06-12 14:32:26 +0800 | [diff] [blame] | 3683 | } |
Zhenyu Wang | 7f8a856 | 2010-04-01 13:07:53 +0800 | [diff] [blame] | 3684 | |
Yuanhan Liu | 1398261 | 2010-12-15 15:42:31 +0800 | [diff] [blame] | 3685 | if (ironlake_compute_wm0(dev, 1, |
| 3686 | &ironlake_display_wm_info, |
| 3687 | ILK_LP0_PLANE_LATENCY, |
| 3688 | &ironlake_cursor_wm_info, |
| 3689 | ILK_LP0_CURSOR_LATENCY, |
| 3690 | &plane_wm, &cursor_wm)) { |
Chris Wilson | 4ed765f | 2010-09-11 10:46:47 +0100 | [diff] [blame] | 3691 | I915_WRITE(WM0_PIPEB_ILK, |
| 3692 | (plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm); |
| 3693 | DRM_DEBUG_KMS("FIFO watermarks For pipe B -" |
| 3694 | " plane %d, cursor: %d\n", |
| 3695 | plane_wm, cursor_wm); |
| 3696 | enabled++; |
Zhenyu Wang | 7f8a856 | 2010-04-01 13:07:53 +0800 | [diff] [blame] | 3697 | } |
| 3698 | |
| 3699 | /* |
| 3700 | * Calculate and update the self-refresh watermark only when one |
| 3701 | * display plane is used. |
| 3702 | */ |
Jesse Barnes | b79d499 | 2010-12-21 13:10:23 -0800 | [diff] [blame] | 3703 | I915_WRITE(WM3_LP_ILK, 0); |
| 3704 | I915_WRITE(WM2_LP_ILK, 0); |
| 3705 | I915_WRITE(WM1_LP_ILK, 0); |
Zhenyu Wang | 7f8a856 | 2010-04-01 13:07:53 +0800 | [diff] [blame] | 3706 | |
Jesse Barnes | b79d499 | 2010-12-21 13:10:23 -0800 | [diff] [blame] | 3707 | if (enabled != 1) |
| 3708 | return; |
Zhenyu Wang | 7f8a856 | 2010-04-01 13:07:53 +0800 | [diff] [blame] | 3709 | |
Jesse Barnes | b79d499 | 2010-12-21 13:10:23 -0800 | [diff] [blame] | 3710 | clock = planea_clock ? planea_clock : planeb_clock; |
Zhenyu Wang | 7f8a856 | 2010-04-01 13:07:53 +0800 | [diff] [blame] | 3711 | |
Jesse Barnes | b79d499 | 2010-12-21 13:10:23 -0800 | [diff] [blame] | 3712 | /* WM1 */ |
| 3713 | if (!ironlake_compute_srwm(dev, 1, hdisplay, htotal, pixel_size, |
| 3714 | clock, ILK_READ_WM1_LATENCY() * 500, |
| 3715 | &ironlake_display_srwm_info, |
| 3716 | &ironlake_cursor_srwm_info, |
| 3717 | &fbc_wm, &plane_wm, &cursor_wm)) |
| 3718 | return; |
Chris Wilson | 4ed765f | 2010-09-11 10:46:47 +0100 | [diff] [blame] | 3719 | |
Jesse Barnes | b79d499 | 2010-12-21 13:10:23 -0800 | [diff] [blame] | 3720 | I915_WRITE(WM1_LP_ILK, |
| 3721 | WM1_LP_SR_EN | |
| 3722 | (ILK_READ_WM1_LATENCY() << WM1_LP_LATENCY_SHIFT) | |
| 3723 | (fbc_wm << WM1_LP_FBC_SHIFT) | |
| 3724 | (plane_wm << WM1_LP_SR_SHIFT) | |
| 3725 | cursor_wm); |
Chris Wilson | 4ed765f | 2010-09-11 10:46:47 +0100 | [diff] [blame] | 3726 | |
Jesse Barnes | b79d499 | 2010-12-21 13:10:23 -0800 | [diff] [blame] | 3727 | /* WM2 */ |
| 3728 | if (!ironlake_compute_srwm(dev, 2, hdisplay, htotal, pixel_size, |
| 3729 | clock, ILK_READ_WM2_LATENCY() * 500, |
| 3730 | &ironlake_display_srwm_info, |
| 3731 | &ironlake_cursor_srwm_info, |
| 3732 | &fbc_wm, &plane_wm, &cursor_wm)) |
| 3733 | return; |
Chris Wilson | 4ed765f | 2010-09-11 10:46:47 +0100 | [diff] [blame] | 3734 | |
Jesse Barnes | b79d499 | 2010-12-21 13:10:23 -0800 | [diff] [blame] | 3735 | I915_WRITE(WM2_LP_ILK, |
| 3736 | WM2_LP_EN | |
| 3737 | (ILK_READ_WM2_LATENCY() << WM1_LP_LATENCY_SHIFT) | |
| 3738 | (fbc_wm << WM1_LP_FBC_SHIFT) | |
| 3739 | (plane_wm << WM1_LP_SR_SHIFT) | |
| 3740 | cursor_wm); |
Yuanhan Liu | 1398261 | 2010-12-15 15:42:31 +0800 | [diff] [blame] | 3741 | |
| 3742 | /* |
Jesse Barnes | b79d499 | 2010-12-21 13:10:23 -0800 | [diff] [blame] | 3743 | * WM3 is unsupported on ILK, probably because we don't have latency |
| 3744 | * data for that power state |
Yuanhan Liu | 1398261 | 2010-12-15 15:42:31 +0800 | [diff] [blame] | 3745 | */ |
Yuanhan Liu | 1398261 | 2010-12-15 15:42:31 +0800 | [diff] [blame] | 3746 | } |
| 3747 | |
| 3748 | static void sandybridge_update_wm(struct drm_device *dev, |
| 3749 | int planea_clock, int planeb_clock, |
| 3750 | int hdisplay, int htotal, |
| 3751 | int pixel_size) |
| 3752 | { |
| 3753 | struct drm_i915_private *dev_priv = dev->dev_private; |
Yuanhan Liu | a0fa62d | 2010-12-23 16:35:40 +0800 | [diff] [blame] | 3754 | int latency = SNB_READ_WM0_LATENCY() * 100; /* In unit 0.1us */ |
Yuanhan Liu | 1398261 | 2010-12-15 15:42:31 +0800 | [diff] [blame] | 3755 | int fbc_wm, plane_wm, cursor_wm, enabled; |
| 3756 | int clock; |
| 3757 | |
| 3758 | enabled = 0; |
| 3759 | if (ironlake_compute_wm0(dev, 0, |
| 3760 | &sandybridge_display_wm_info, latency, |
| 3761 | &sandybridge_cursor_wm_info, latency, |
| 3762 | &plane_wm, &cursor_wm)) { |
| 3763 | I915_WRITE(WM0_PIPEA_ILK, |
| 3764 | (plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm); |
| 3765 | DRM_DEBUG_KMS("FIFO watermarks For pipe A -" |
| 3766 | " plane %d, " "cursor: %d\n", |
| 3767 | plane_wm, cursor_wm); |
| 3768 | enabled++; |
| 3769 | } |
| 3770 | |
| 3771 | if (ironlake_compute_wm0(dev, 1, |
| 3772 | &sandybridge_display_wm_info, latency, |
| 3773 | &sandybridge_cursor_wm_info, latency, |
| 3774 | &plane_wm, &cursor_wm)) { |
| 3775 | I915_WRITE(WM0_PIPEB_ILK, |
| 3776 | (plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm); |
| 3777 | DRM_DEBUG_KMS("FIFO watermarks For pipe B -" |
| 3778 | " plane %d, cursor: %d\n", |
| 3779 | plane_wm, cursor_wm); |
| 3780 | enabled++; |
| 3781 | } |
| 3782 | |
| 3783 | /* |
| 3784 | * Calculate and update the self-refresh watermark only when one |
| 3785 | * display plane is used. |
| 3786 | * |
| 3787 | * SNB support 3 levels of watermark. |
| 3788 | * |
| 3789 | * WM1/WM2/WM2 watermarks have to be enabled in the ascending order, |
| 3790 | * and disabled in the descending order |
| 3791 | * |
| 3792 | */ |
| 3793 | I915_WRITE(WM3_LP_ILK, 0); |
| 3794 | I915_WRITE(WM2_LP_ILK, 0); |
| 3795 | I915_WRITE(WM1_LP_ILK, 0); |
| 3796 | |
| 3797 | if (enabled != 1) |
| 3798 | return; |
| 3799 | |
| 3800 | clock = planea_clock ? planea_clock : planeb_clock; |
| 3801 | |
| 3802 | /* WM1 */ |
Jesse Barnes | b79d499 | 2010-12-21 13:10:23 -0800 | [diff] [blame] | 3803 | if (!ironlake_compute_srwm(dev, 1, hdisplay, htotal, pixel_size, |
| 3804 | clock, SNB_READ_WM1_LATENCY() * 500, |
| 3805 | &sandybridge_display_srwm_info, |
| 3806 | &sandybridge_cursor_srwm_info, |
| 3807 | &fbc_wm, &plane_wm, &cursor_wm)) |
Yuanhan Liu | 1398261 | 2010-12-15 15:42:31 +0800 | [diff] [blame] | 3808 | return; |
| 3809 | |
| 3810 | I915_WRITE(WM1_LP_ILK, |
| 3811 | WM1_LP_SR_EN | |
| 3812 | (SNB_READ_WM1_LATENCY() << WM1_LP_LATENCY_SHIFT) | |
| 3813 | (fbc_wm << WM1_LP_FBC_SHIFT) | |
| 3814 | (plane_wm << WM1_LP_SR_SHIFT) | |
| 3815 | cursor_wm); |
| 3816 | |
| 3817 | /* WM2 */ |
Jesse Barnes | b79d499 | 2010-12-21 13:10:23 -0800 | [diff] [blame] | 3818 | if (!ironlake_compute_srwm(dev, 2, |
| 3819 | hdisplay, htotal, pixel_size, |
| 3820 | clock, SNB_READ_WM2_LATENCY() * 500, |
| 3821 | &sandybridge_display_srwm_info, |
| 3822 | &sandybridge_cursor_srwm_info, |
| 3823 | &fbc_wm, &plane_wm, &cursor_wm)) |
Yuanhan Liu | 1398261 | 2010-12-15 15:42:31 +0800 | [diff] [blame] | 3824 | return; |
| 3825 | |
| 3826 | I915_WRITE(WM2_LP_ILK, |
| 3827 | WM2_LP_EN | |
| 3828 | (SNB_READ_WM2_LATENCY() << WM1_LP_LATENCY_SHIFT) | |
| 3829 | (fbc_wm << WM1_LP_FBC_SHIFT) | |
| 3830 | (plane_wm << WM1_LP_SR_SHIFT) | |
| 3831 | cursor_wm); |
| 3832 | |
| 3833 | /* WM3 */ |
Jesse Barnes | b79d499 | 2010-12-21 13:10:23 -0800 | [diff] [blame] | 3834 | if (!ironlake_compute_srwm(dev, 3, |
| 3835 | hdisplay, htotal, pixel_size, |
| 3836 | clock, SNB_READ_WM3_LATENCY() * 500, |
| 3837 | &sandybridge_display_srwm_info, |
| 3838 | &sandybridge_cursor_srwm_info, |
| 3839 | &fbc_wm, &plane_wm, &cursor_wm)) |
Yuanhan Liu | 1398261 | 2010-12-15 15:42:31 +0800 | [diff] [blame] | 3840 | return; |
| 3841 | |
| 3842 | I915_WRITE(WM3_LP_ILK, |
| 3843 | WM3_LP_EN | |
| 3844 | (SNB_READ_WM3_LATENCY() << WM1_LP_LATENCY_SHIFT) | |
| 3845 | (fbc_wm << WM1_LP_FBC_SHIFT) | |
| 3846 | (plane_wm << WM1_LP_SR_SHIFT) | |
| 3847 | cursor_wm); |
| 3848 | } |
| 3849 | |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3850 | /** |
| 3851 | * intel_update_watermarks - update FIFO watermark values based on current modes |
| 3852 | * |
| 3853 | * Calculate watermark values for the various WM regs based on current mode |
| 3854 | * and plane configuration. |
| 3855 | * |
| 3856 | * There are several cases to deal with here: |
| 3857 | * - normal (i.e. non-self-refresh) |
| 3858 | * - self-refresh (SR) mode |
| 3859 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 3860 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 3861 | * lines), so need to account for TLB latency |
| 3862 | * |
| 3863 | * The normal calculation is: |
| 3864 | * watermark = dotclock * bytes per pixel * latency |
| 3865 | * where latency is platform & configuration dependent (we assume pessimal |
| 3866 | * values here). |
| 3867 | * |
| 3868 | * The SR calculation is: |
| 3869 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 3870 | * bytes per pixel |
| 3871 | * where |
| 3872 | * line time = htotal / dotclock |
Zhao Yakui | fa14321 | 2010-06-12 14:32:23 +0800 | [diff] [blame] | 3873 | * surface width = hdisplay for normal plane and 64 for cursor |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3874 | * and latency is assumed to be high, as above. |
| 3875 | * |
| 3876 | * The final value programmed to the register should always be rounded up, |
| 3877 | * and include an extra 2 entries to account for clock crossings. |
| 3878 | * |
| 3879 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 3880 | * to set the non-SR watermarks to 8. |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3881 | */ |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3882 | static void intel_update_watermarks(struct drm_device *dev) |
| 3883 | { |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 3884 | struct drm_i915_private *dev_priv = dev->dev_private; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3885 | struct drm_crtc *crtc; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3886 | int sr_hdisplay = 0; |
| 3887 | unsigned long planea_clock = 0, planeb_clock = 0, sr_clock = 0; |
| 3888 | int enabled = 0, pixel_size = 0; |
Zhao Yakui | fa14321 | 2010-06-12 14:32:23 +0800 | [diff] [blame] | 3889 | int sr_htotal = 0; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3890 | |
Zhenyu Wang | c03342f | 2009-09-29 11:01:23 +0800 | [diff] [blame] | 3891 | if (!dev_priv->display.update_wm) |
| 3892 | return; |
| 3893 | |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3894 | /* Get the clock config from both planes */ |
| 3895 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
Chris Wilson | debcadd | 2010-08-07 11:01:33 +0100 | [diff] [blame] | 3896 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 3897 | if (intel_crtc->active) { |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3898 | enabled++; |
| 3899 | if (intel_crtc->plane == 0) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3900 | DRM_DEBUG_KMS("plane A (pipe %d) clock: %d\n", |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3901 | intel_crtc->pipe, crtc->mode.clock); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3902 | planea_clock = crtc->mode.clock; |
| 3903 | } else { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3904 | DRM_DEBUG_KMS("plane B (pipe %d) clock: %d\n", |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3905 | intel_crtc->pipe, crtc->mode.clock); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3906 | planeb_clock = crtc->mode.clock; |
| 3907 | } |
| 3908 | sr_hdisplay = crtc->mode.hdisplay; |
| 3909 | sr_clock = crtc->mode.clock; |
Zhao Yakui | fa14321 | 2010-06-12 14:32:23 +0800 | [diff] [blame] | 3910 | sr_htotal = crtc->mode.htotal; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3911 | if (crtc->fb) |
| 3912 | pixel_size = crtc->fb->bits_per_pixel / 8; |
| 3913 | else |
| 3914 | pixel_size = 4; /* by default */ |
| 3915 | } |
| 3916 | } |
| 3917 | |
| 3918 | if (enabled <= 0) |
| 3919 | return; |
| 3920 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 3921 | dev_priv->display.update_wm(dev, planea_clock, planeb_clock, |
Zhao Yakui | fa14321 | 2010-06-12 14:32:23 +0800 | [diff] [blame] | 3922 | sr_hdisplay, sr_htotal, pixel_size); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3923 | } |
| 3924 | |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 3925 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
| 3926 | { |
| 3927 | return dev_priv->lvds_use_ssc && i915_panel_use_ssc; |
| 3928 | } |
| 3929 | |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 3930 | static int intel_crtc_mode_set(struct drm_crtc *crtc, |
| 3931 | struct drm_display_mode *mode, |
| 3932 | struct drm_display_mode *adjusted_mode, |
| 3933 | int x, int y, |
| 3934 | struct drm_framebuffer *old_fb) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3935 | { |
| 3936 | struct drm_device *dev = crtc->dev; |
| 3937 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3938 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3939 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 3940 | int plane = intel_crtc->plane; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3941 | u32 fp_reg, dpll_reg; |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 3942 | int refclk, num_connectors = 0; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3943 | intel_clock_t clock, reduced_clock; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3944 | u32 dpll, fp = 0, fp2 = 0, dspcntr, pipeconf; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3945 | bool ok, has_reduced_clock = false, is_sdvo = false, is_dvo = false; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3946 | bool is_crt = false, is_lvds = false, is_tv = false, is_dp = false; |
Chris Wilson | 8e647a2 | 2010-08-22 10:54:23 +0100 | [diff] [blame] | 3947 | struct intel_encoder *has_edp_encoder = NULL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3948 | struct drm_mode_config *mode_config = &dev->mode_config; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3949 | struct intel_encoder *encoder; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 3950 | const intel_limit_t *limit; |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 3951 | int ret; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3952 | struct fdi_m_n m_n = {0}; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3953 | u32 reg, temp; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 3954 | int target_clock; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3955 | |
| 3956 | drm_vblank_pre_modeset(dev, pipe); |
| 3957 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3958 | list_for_each_entry(encoder, &mode_config->encoder_list, base.head) { |
| 3959 | if (encoder->base.crtc != crtc) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3960 | continue; |
| 3961 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3962 | switch (encoder->type) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3963 | case INTEL_OUTPUT_LVDS: |
| 3964 | is_lvds = true; |
| 3965 | break; |
| 3966 | case INTEL_OUTPUT_SDVO: |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 3967 | case INTEL_OUTPUT_HDMI: |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3968 | is_sdvo = true; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3969 | if (encoder->needs_tv_clock) |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 3970 | is_tv = true; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3971 | break; |
| 3972 | case INTEL_OUTPUT_DVO: |
| 3973 | is_dvo = true; |
| 3974 | break; |
| 3975 | case INTEL_OUTPUT_TVOUT: |
| 3976 | is_tv = true; |
| 3977 | break; |
| 3978 | case INTEL_OUTPUT_ANALOG: |
| 3979 | is_crt = true; |
| 3980 | break; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3981 | case INTEL_OUTPUT_DISPLAYPORT: |
| 3982 | is_dp = true; |
| 3983 | break; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 3984 | case INTEL_OUTPUT_EDP: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3985 | has_edp_encoder = encoder; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 3986 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3987 | } |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 3988 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 3989 | num_connectors++; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3990 | } |
| 3991 | |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 3992 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 3993 | refclk = dev_priv->lvds_ssc_freq * 1000; |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3994 | DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n", |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3995 | refclk / 1000); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 3996 | } else if (!IS_GEN2(dev)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3997 | refclk = 96000; |
Jesse Barnes | 1cb1b75 | 2010-10-07 16:01:17 -0700 | [diff] [blame] | 3998 | if (HAS_PCH_SPLIT(dev) && |
| 3999 | (!has_edp_encoder || intel_encoder_is_pch_edp(&has_edp_encoder->base))) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4000 | refclk = 120000; /* 120Mhz refclk */ |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4001 | } else { |
| 4002 | refclk = 48000; |
| 4003 | } |
| 4004 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 4005 | /* |
| 4006 | * Returns a set of divisors for the desired target clock with the given |
| 4007 | * refclk, or FALSE. The returned values represent the clock equation: |
| 4008 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 4009 | */ |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 4010 | limit = intel_limit(crtc, refclk); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 4011 | ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4012 | if (!ok) { |
| 4013 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
Chris Wilson | 1f803ee | 2009-06-06 09:45:59 +0100 | [diff] [blame] | 4014 | drm_vblank_post_modeset(dev, pipe); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 4015 | return -EINVAL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4016 | } |
| 4017 | |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 4018 | /* Ensure that the cursor is valid for the new mode before changing... */ |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 4019 | intel_crtc_update_cursor(crtc, true); |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 4020 | |
Zhao Yakui | ddc9003 | 2010-01-06 22:05:56 +0800 | [diff] [blame] | 4021 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
| 4022 | has_reduced_clock = limit->find_pll(limit, crtc, |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4023 | dev_priv->lvds_downclock, |
| 4024 | refclk, |
| 4025 | &reduced_clock); |
Zhao Yakui | 18f9ed1 | 2009-11-20 03:24:16 +0000 | [diff] [blame] | 4026 | if (has_reduced_clock && (clock.p != reduced_clock.p)) { |
| 4027 | /* |
| 4028 | * If the different P is found, it means that we can't |
| 4029 | * switch the display clock by using the FP0/FP1. |
| 4030 | * In such case we will disable the LVDS downclock |
| 4031 | * feature. |
| 4032 | */ |
| 4033 | DRM_DEBUG_KMS("Different P is found for " |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4034 | "LVDS clock/downclock\n"); |
Zhao Yakui | 18f9ed1 | 2009-11-20 03:24:16 +0000 | [diff] [blame] | 4035 | has_reduced_clock = 0; |
| 4036 | } |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 4037 | } |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 4038 | /* SDVO TV has fixed PLL values depend on its clock range, |
| 4039 | this mirrors vbios setting. */ |
| 4040 | if (is_sdvo && is_tv) { |
| 4041 | if (adjusted_mode->clock >= 100000 |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4042 | && adjusted_mode->clock < 140500) { |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 4043 | clock.p1 = 2; |
| 4044 | clock.p2 = 10; |
| 4045 | clock.n = 3; |
| 4046 | clock.m1 = 16; |
| 4047 | clock.m2 = 8; |
| 4048 | } else if (adjusted_mode->clock >= 140500 |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4049 | && adjusted_mode->clock <= 200000) { |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 4050 | clock.p1 = 1; |
| 4051 | clock.p2 = 10; |
| 4052 | clock.n = 6; |
| 4053 | clock.m1 = 12; |
| 4054 | clock.m2 = 8; |
| 4055 | } |
| 4056 | } |
| 4057 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4058 | /* FDI link */ |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 4059 | if (HAS_PCH_SPLIT(dev)) { |
Chris Wilson | 49078f7 | 2010-12-04 07:45:57 +0000 | [diff] [blame] | 4060 | int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode); |
Adam Jackson | 77ffb59 | 2010-04-12 11:38:44 -0400 | [diff] [blame] | 4061 | int lane = 0, link_bw, bpp; |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 4062 | /* CPU eDP doesn't require FDI link, so just set DP M/N |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4063 | according to current link config */ |
Jesse Barnes | 858bc21 | 2011-01-04 10:46:49 -0800 | [diff] [blame] | 4064 | if (has_edp_encoder && !intel_encoder_is_pch_edp(&has_edp_encoder->base)) { |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4065 | target_clock = mode->clock; |
Chris Wilson | 8e647a2 | 2010-08-22 10:54:23 +0100 | [diff] [blame] | 4066 | intel_edp_link_config(has_edp_encoder, |
| 4067 | &lane, &link_bw); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4068 | } else { |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 4069 | /* [e]DP over FDI requires target mode clock |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4070 | instead of link clock */ |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 4071 | if (is_dp || intel_encoder_is_pch_edp(&has_edp_encoder->base)) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4072 | target_clock = mode->clock; |
| 4073 | else |
| 4074 | target_clock = adjusted_mode->clock; |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 4075 | |
| 4076 | /* FDI is a binary signal running at ~2.7GHz, encoding |
| 4077 | * each output octet as 10 bits. The actual frequency |
| 4078 | * is stored as a divider into a 100MHz clock, and the |
| 4079 | * mode pixel clock is stored in units of 1KHz. |
| 4080 | * Hence the bw of each lane in terms of the mode signal |
| 4081 | * is: |
| 4082 | */ |
| 4083 | link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4084 | } |
Zhenyu Wang | 58a2747 | 2009-09-25 08:01:28 +0000 | [diff] [blame] | 4085 | |
| 4086 | /* determine panel color depth */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4087 | temp = I915_READ(PIPECONF(pipe)); |
Zhao Yakui | e5a95eb | 2010-01-04 16:29:32 +0800 | [diff] [blame] | 4088 | temp &= ~PIPE_BPC_MASK; |
| 4089 | if (is_lvds) { |
Zhao Yakui | e5a95eb | 2010-01-04 16:29:32 +0800 | [diff] [blame] | 4090 | /* the BPC will be 6 if it is 18-bit LVDS panel */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4091 | if ((I915_READ(PCH_LVDS) & LVDS_A3_POWER_MASK) == LVDS_A3_POWER_UP) |
Zhao Yakui | e5a95eb | 2010-01-04 16:29:32 +0800 | [diff] [blame] | 4092 | temp |= PIPE_8BPC; |
| 4093 | else |
| 4094 | temp |= PIPE_6BPC; |
Jesse Barnes | 1d85036 | 2010-10-07 16:01:10 -0700 | [diff] [blame] | 4095 | } else if (has_edp_encoder) { |
Chris Wilson | 5ceb0f9 | 2010-09-24 10:24:28 +0100 | [diff] [blame] | 4096 | switch (dev_priv->edp.bpp/3) { |
Zhenyu Wang | 885a5fb | 2010-01-12 05:38:31 +0800 | [diff] [blame] | 4097 | case 8: |
| 4098 | temp |= PIPE_8BPC; |
| 4099 | break; |
| 4100 | case 10: |
| 4101 | temp |= PIPE_10BPC; |
| 4102 | break; |
| 4103 | case 6: |
| 4104 | temp |= PIPE_6BPC; |
| 4105 | break; |
| 4106 | case 12: |
| 4107 | temp |= PIPE_12BPC; |
| 4108 | break; |
| 4109 | } |
Zhao Yakui | e5a95eb | 2010-01-04 16:29:32 +0800 | [diff] [blame] | 4110 | } else |
| 4111 | temp |= PIPE_8BPC; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4112 | I915_WRITE(PIPECONF(pipe), temp); |
Zhenyu Wang | 58a2747 | 2009-09-25 08:01:28 +0000 | [diff] [blame] | 4113 | |
| 4114 | switch (temp & PIPE_BPC_MASK) { |
| 4115 | case PIPE_8BPC: |
| 4116 | bpp = 24; |
| 4117 | break; |
| 4118 | case PIPE_10BPC: |
| 4119 | bpp = 30; |
| 4120 | break; |
| 4121 | case PIPE_6BPC: |
| 4122 | bpp = 18; |
| 4123 | break; |
| 4124 | case PIPE_12BPC: |
| 4125 | bpp = 36; |
| 4126 | break; |
| 4127 | default: |
| 4128 | DRM_ERROR("unknown pipe bpc value\n"); |
| 4129 | bpp = 24; |
| 4130 | } |
| 4131 | |
Adam Jackson | 77ffb59 | 2010-04-12 11:38:44 -0400 | [diff] [blame] | 4132 | if (!lane) { |
| 4133 | /* |
| 4134 | * Account for spread spectrum to avoid |
| 4135 | * oversubscribing the link. Max center spread |
| 4136 | * is 2.5%; use 5% for safety's sake. |
| 4137 | */ |
| 4138 | u32 bps = target_clock * bpp * 21 / 20; |
| 4139 | lane = bps / (link_bw * 8) + 1; |
| 4140 | } |
| 4141 | |
| 4142 | intel_crtc->fdi_lanes = lane; |
| 4143 | |
Chris Wilson | 49078f7 | 2010-12-04 07:45:57 +0000 | [diff] [blame] | 4144 | if (pixel_multiplier > 1) |
| 4145 | link_bw *= pixel_multiplier; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 4146 | ironlake_compute_m_n(bpp, lane, target_clock, link_bw, &m_n); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4147 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4148 | |
Zhenyu Wang | c038e51 | 2009-10-19 15:43:48 +0800 | [diff] [blame] | 4149 | /* Ironlake: try to setup display ref clock before DPLL |
| 4150 | * enabling. This is only under driver's control after |
| 4151 | * PCH B stepping, previous chipset stepping should be |
| 4152 | * ignoring this setting. |
| 4153 | */ |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 4154 | if (HAS_PCH_SPLIT(dev)) { |
Zhenyu Wang | c038e51 | 2009-10-19 15:43:48 +0800 | [diff] [blame] | 4155 | temp = I915_READ(PCH_DREF_CONTROL); |
| 4156 | /* Always enable nonspread source */ |
| 4157 | temp &= ~DREF_NONSPREAD_SOURCE_MASK; |
| 4158 | temp |= DREF_NONSPREAD_SOURCE_ENABLE; |
Zhenyu Wang | c038e51 | 2009-10-19 15:43:48 +0800 | [diff] [blame] | 4159 | temp &= ~DREF_SSC_SOURCE_MASK; |
| 4160 | temp |= DREF_SSC_SOURCE_ENABLE; |
| 4161 | I915_WRITE(PCH_DREF_CONTROL, temp); |
Zhenyu Wang | c038e51 | 2009-10-19 15:43:48 +0800 | [diff] [blame] | 4162 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4163 | POSTING_READ(PCH_DREF_CONTROL); |
Zhenyu Wang | c038e51 | 2009-10-19 15:43:48 +0800 | [diff] [blame] | 4164 | udelay(200); |
| 4165 | |
Chris Wilson | 8e647a2 | 2010-08-22 10:54:23 +0100 | [diff] [blame] | 4166 | if (has_edp_encoder) { |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 4167 | if (intel_panel_use_ssc(dev_priv)) { |
Zhenyu Wang | c038e51 | 2009-10-19 15:43:48 +0800 | [diff] [blame] | 4168 | temp |= DREF_SSC1_ENABLE; |
| 4169 | I915_WRITE(PCH_DREF_CONTROL, temp); |
Zhenyu Wang | c038e51 | 2009-10-19 15:43:48 +0800 | [diff] [blame] | 4170 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4171 | POSTING_READ(PCH_DREF_CONTROL); |
Zhenyu Wang | c038e51 | 2009-10-19 15:43:48 +0800 | [diff] [blame] | 4172 | udelay(200); |
Jesse Barnes | 7f82328 | 2010-10-07 16:01:16 -0700 | [diff] [blame] | 4173 | } |
| 4174 | temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Zhenyu Wang | c038e51 | 2009-10-19 15:43:48 +0800 | [diff] [blame] | 4175 | |
Jesse Barnes | 7f82328 | 2010-10-07 16:01:16 -0700 | [diff] [blame] | 4176 | /* Enable CPU source on CPU attached eDP */ |
| 4177 | if (!intel_encoder_is_pch_edp(&has_edp_encoder->base)) { |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 4178 | if (intel_panel_use_ssc(dev_priv)) |
Jesse Barnes | 7f82328 | 2010-10-07 16:01:16 -0700 | [diff] [blame] | 4179 | temp |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
| 4180 | else |
| 4181 | temp |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
Zhenyu Wang | c038e51 | 2009-10-19 15:43:48 +0800 | [diff] [blame] | 4182 | } else { |
Jesse Barnes | 7f82328 | 2010-10-07 16:01:16 -0700 | [diff] [blame] | 4183 | /* Enable SSC on PCH eDP if needed */ |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 4184 | if (intel_panel_use_ssc(dev_priv)) { |
Jesse Barnes | 7f82328 | 2010-10-07 16:01:16 -0700 | [diff] [blame] | 4185 | DRM_ERROR("enabling SSC on PCH\n"); |
| 4186 | temp |= DREF_SUPERSPREAD_SOURCE_ENABLE; |
| 4187 | } |
Zhenyu Wang | c038e51 | 2009-10-19 15:43:48 +0800 | [diff] [blame] | 4188 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4189 | I915_WRITE(PCH_DREF_CONTROL, temp); |
Jesse Barnes | 7f82328 | 2010-10-07 16:01:16 -0700 | [diff] [blame] | 4190 | POSTING_READ(PCH_DREF_CONTROL); |
| 4191 | udelay(200); |
Zhenyu Wang | c038e51 | 2009-10-19 15:43:48 +0800 | [diff] [blame] | 4192 | } |
| 4193 | } |
| 4194 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 4195 | if (IS_PINEVIEW(dev)) { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 4196 | fp = (1 << clock.n) << 16 | clock.m1 << 8 | clock.m2; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 4197 | if (has_reduced_clock) |
| 4198 | fp2 = (1 << reduced_clock.n) << 16 | |
| 4199 | reduced_clock.m1 << 8 | reduced_clock.m2; |
| 4200 | } else { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 4201 | fp = clock.n << 16 | clock.m1 << 8 | clock.m2; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 4202 | if (has_reduced_clock) |
| 4203 | fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 | |
| 4204 | reduced_clock.m2; |
| 4205 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4206 | |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 4207 | /* Enable autotuning of the PLL clock (if permissible) */ |
| 4208 | if (HAS_PCH_SPLIT(dev)) { |
| 4209 | int factor = 21; |
| 4210 | |
| 4211 | if (is_lvds) { |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 4212 | if ((intel_panel_use_ssc(dev_priv) && |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 4213 | dev_priv->lvds_ssc_freq == 100) || |
| 4214 | (I915_READ(PCH_LVDS) & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP) |
| 4215 | factor = 25; |
| 4216 | } else if (is_sdvo && is_tv) |
| 4217 | factor = 20; |
| 4218 | |
| 4219 | if (clock.m1 < factor * clock.n) |
| 4220 | fp |= FP_CB_TUNE; |
| 4221 | } |
| 4222 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4223 | dpll = 0; |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 4224 | if (!HAS_PCH_SPLIT(dev)) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4225 | dpll = DPLL_VGA_MODE_DIS; |
| 4226 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 4227 | if (!IS_GEN2(dev)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4228 | if (is_lvds) |
| 4229 | dpll |= DPLLB_MODE_LVDS; |
| 4230 | else |
| 4231 | dpll |= DPLLB_MODE_DAC_SERIAL; |
| 4232 | if (is_sdvo) { |
Chris Wilson | 6c9547f | 2010-08-25 10:05:17 +0100 | [diff] [blame] | 4233 | int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode); |
| 4234 | if (pixel_multiplier > 1) { |
| 4235 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) |
| 4236 | dpll |= (pixel_multiplier - 1) << SDVO_MULTIPLIER_SHIFT_HIRES; |
| 4237 | else if (HAS_PCH_SPLIT(dev)) |
| 4238 | dpll |= (pixel_multiplier - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
| 4239 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4240 | dpll |= DPLL_DVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4241 | } |
Jesse Barnes | 8324012 | 2010-10-07 16:01:18 -0700 | [diff] [blame] | 4242 | if (is_dp || intel_encoder_is_pch_edp(&has_edp_encoder->base)) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4243 | dpll |= DPLL_DVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4244 | |
| 4245 | /* compute bitmask from p1 value */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 4246 | if (IS_PINEVIEW(dev)) |
| 4247 | dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4248 | else { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 4249 | dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4250 | /* also FPA1 */ |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 4251 | if (HAS_PCH_SPLIT(dev)) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4252 | dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 4253 | if (IS_G4X(dev) && has_reduced_clock) |
| 4254 | dpll |= (1 << (reduced_clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4255 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4256 | switch (clock.p2) { |
| 4257 | case 5: |
| 4258 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 4259 | break; |
| 4260 | case 7: |
| 4261 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 4262 | break; |
| 4263 | case 10: |
| 4264 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 4265 | break; |
| 4266 | case 14: |
| 4267 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 4268 | break; |
| 4269 | } |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 4270 | if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4271 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
| 4272 | } else { |
| 4273 | if (is_lvds) { |
| 4274 | dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 4275 | } else { |
| 4276 | if (clock.p1 == 2) |
| 4277 | dpll |= PLL_P1_DIVIDE_BY_TWO; |
| 4278 | else |
| 4279 | dpll |= (clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 4280 | if (clock.p2 == 4) |
| 4281 | dpll |= PLL_P2_DIVIDE_BY_4; |
| 4282 | } |
| 4283 | } |
| 4284 | |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 4285 | if (is_sdvo && is_tv) |
| 4286 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
| 4287 | else if (is_tv) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4288 | /* XXX: just matching BIOS for now */ |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 4289 | /* dpll |= PLL_REF_INPUT_TVCLKINBC; */ |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4290 | dpll |= 3; |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 4291 | else if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 4292 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4293 | else |
| 4294 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 4295 | |
| 4296 | /* setup pipeconf */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4297 | pipeconf = I915_READ(PIPECONF(pipe)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4298 | |
| 4299 | /* Set up the display plane register */ |
| 4300 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
| 4301 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 4302 | /* Ironlake's plane is forced to pipe, bit 24 is to |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4303 | enable color space conversion */ |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 4304 | if (!HAS_PCH_SPLIT(dev)) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4305 | if (pipe == 0) |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 4306 | dspcntr &= ~DISPPLANE_SEL_PIPE_MASK; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4307 | else |
| 4308 | dspcntr |= DISPPLANE_SEL_PIPE_B; |
| 4309 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4310 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 4311 | if (pipe == 0 && INTEL_INFO(dev)->gen < 4) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4312 | /* Enable pixel doubling when the dot clock is > 90% of the (display) |
| 4313 | * core speed. |
| 4314 | * |
| 4315 | * XXX: No double-wide on 915GM pipe B. Is that the only reason for the |
| 4316 | * pipe == 0 check? |
| 4317 | */ |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 4318 | if (mode->clock > |
| 4319 | dev_priv->display.get_display_clock_speed(dev) * 9 / 10) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4320 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4321 | else |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4322 | pipeconf &= ~PIPECONF_DOUBLE_WIDE; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4323 | } |
| 4324 | |
Linus Torvalds | 8d86dc6 | 2010-06-08 20:16:28 -0700 | [diff] [blame] | 4325 | dspcntr |= DISPLAY_PLANE_ENABLE; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4326 | pipeconf |= PIPECONF_ENABLE; |
Linus Torvalds | 8d86dc6 | 2010-06-08 20:16:28 -0700 | [diff] [blame] | 4327 | dpll |= DPLL_VCO_ENABLE; |
| 4328 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 4329 | DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B'); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4330 | drm_mode_debug_printmodeline(mode); |
| 4331 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 4332 | /* assign to Ironlake registers */ |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 4333 | if (HAS_PCH_SPLIT(dev)) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4334 | fp_reg = PCH_FP0(pipe); |
| 4335 | dpll_reg = PCH_DPLL(pipe); |
| 4336 | } else { |
| 4337 | fp_reg = FP0(pipe); |
| 4338 | dpll_reg = DPLL(pipe); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4339 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4340 | |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 4341 | /* PCH eDP needs FDI, but CPU eDP does not */ |
| 4342 | if (!has_edp_encoder || intel_encoder_is_pch_edp(&has_edp_encoder->base)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4343 | I915_WRITE(fp_reg, fp); |
| 4344 | I915_WRITE(dpll_reg, dpll & ~DPLL_VCO_ENABLE); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4345 | |
| 4346 | POSTING_READ(dpll_reg); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4347 | udelay(150); |
| 4348 | } |
| 4349 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4350 | /* enable transcoder DPLL */ |
| 4351 | if (HAS_PCH_CPT(dev)) { |
| 4352 | temp = I915_READ(PCH_DPLL_SEL); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4353 | if (pipe == 0) |
| 4354 | temp |= TRANSA_DPLL_ENABLE | TRANSA_DPLLA_SEL; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4355 | else |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4356 | temp |= TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4357 | I915_WRITE(PCH_DPLL_SEL, temp); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4358 | |
| 4359 | POSTING_READ(PCH_DPLL_SEL); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4360 | udelay(150); |
| 4361 | } |
| 4362 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4363 | /* The LVDS pin pair needs to be on before the DPLLs are enabled. |
| 4364 | * This is an exception to the general rule that mode_set doesn't turn |
| 4365 | * things on. |
| 4366 | */ |
| 4367 | if (is_lvds) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4368 | reg = LVDS; |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 4369 | if (HAS_PCH_SPLIT(dev)) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4370 | reg = PCH_LVDS; |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 4371 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4372 | temp = I915_READ(reg); |
| 4373 | temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP; |
Zhenyu Wang | b3b095b | 2010-04-07 16:15:56 +0800 | [diff] [blame] | 4374 | if (pipe == 1) { |
| 4375 | if (HAS_PCH_CPT(dev)) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4376 | temp |= PORT_TRANS_B_SEL_CPT; |
Zhenyu Wang | b3b095b | 2010-04-07 16:15:56 +0800 | [diff] [blame] | 4377 | else |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4378 | temp |= LVDS_PIPEB_SELECT; |
Zhenyu Wang | b3b095b | 2010-04-07 16:15:56 +0800 | [diff] [blame] | 4379 | } else { |
| 4380 | if (HAS_PCH_CPT(dev)) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4381 | temp &= ~PORT_TRANS_SEL_MASK; |
Zhenyu Wang | b3b095b | 2010-04-07 16:15:56 +0800 | [diff] [blame] | 4382 | else |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4383 | temp &= ~LVDS_PIPEB_SELECT; |
Zhenyu Wang | b3b095b | 2010-04-07 16:15:56 +0800 | [diff] [blame] | 4384 | } |
Zhao Yakui | a3e17eb | 2009-10-10 10:42:37 +0800 | [diff] [blame] | 4385 | /* set the corresponsding LVDS_BORDER bit */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4386 | temp |= dev_priv->lvds_border_bits; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4387 | /* Set the B0-B3 data pairs corresponding to whether we're going to |
| 4388 | * set the DPLLs for dual-channel mode or not. |
| 4389 | */ |
| 4390 | if (clock.p2 == 7) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4391 | temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4392 | else |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4393 | temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4394 | |
| 4395 | /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP) |
| 4396 | * appropriately here, but we need to look more thoroughly into how |
| 4397 | * panels behave in the two modes. |
| 4398 | */ |
Jesse Barnes | 434ed09 | 2010-09-07 14:48:06 -0700 | [diff] [blame] | 4399 | /* set the dithering flag on non-PCH LVDS as needed */ |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 4400 | if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev)) { |
Jesse Barnes | 434ed09 | 2010-09-07 14:48:06 -0700 | [diff] [blame] | 4401 | if (dev_priv->lvds_dither) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4402 | temp |= LVDS_ENABLE_DITHER; |
Jesse Barnes | 434ed09 | 2010-09-07 14:48:06 -0700 | [diff] [blame] | 4403 | else |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4404 | temp &= ~LVDS_ENABLE_DITHER; |
Zhao Yakui | 898822c | 2010-01-04 16:29:30 +0800 | [diff] [blame] | 4405 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4406 | I915_WRITE(reg, temp); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4407 | } |
Jesse Barnes | 434ed09 | 2010-09-07 14:48:06 -0700 | [diff] [blame] | 4408 | |
| 4409 | /* set the dithering flag and clear for anything other than a panel. */ |
| 4410 | if (HAS_PCH_SPLIT(dev)) { |
| 4411 | pipeconf &= ~PIPECONF_DITHER_EN; |
| 4412 | pipeconf &= ~PIPECONF_DITHER_TYPE_MASK; |
| 4413 | if (dev_priv->lvds_dither && (is_lvds || has_edp_encoder)) { |
| 4414 | pipeconf |= PIPECONF_DITHER_EN; |
| 4415 | pipeconf |= PIPECONF_DITHER_TYPE_ST1; |
| 4416 | } |
| 4417 | } |
| 4418 | |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 4419 | if (is_dp || intel_encoder_is_pch_edp(&has_edp_encoder->base)) { |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4420 | intel_dp_set_m_n(crtc, mode, adjusted_mode); |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 4421 | } else if (HAS_PCH_SPLIT(dev)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4422 | /* For non-DP output, clear any trans DP clock recovery setting.*/ |
| 4423 | if (pipe == 0) { |
| 4424 | I915_WRITE(TRANSA_DATA_M1, 0); |
| 4425 | I915_WRITE(TRANSA_DATA_N1, 0); |
| 4426 | I915_WRITE(TRANSA_DP_LINK_M1, 0); |
| 4427 | I915_WRITE(TRANSA_DP_LINK_N1, 0); |
| 4428 | } else { |
| 4429 | I915_WRITE(TRANSB_DATA_M1, 0); |
| 4430 | I915_WRITE(TRANSB_DATA_N1, 0); |
| 4431 | I915_WRITE(TRANSB_DP_LINK_M1, 0); |
| 4432 | I915_WRITE(TRANSB_DP_LINK_N1, 0); |
| 4433 | } |
| 4434 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4435 | |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 4436 | if (!has_edp_encoder || intel_encoder_is_pch_edp(&has_edp_encoder->base)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4437 | I915_WRITE(dpll_reg, dpll); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4438 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4439 | /* Wait for the clocks to stabilize. */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4440 | POSTING_READ(dpll_reg); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4441 | udelay(150); |
| 4442 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 4443 | if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev)) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4444 | temp = 0; |
Zhao Yakui | bb66c51 | 2009-09-10 15:45:49 +0800 | [diff] [blame] | 4445 | if (is_sdvo) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4446 | temp = intel_mode_get_pixel_multiplier(adjusted_mode); |
| 4447 | if (temp > 1) |
| 4448 | temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Chris Wilson | 6c9547f | 2010-08-25 10:05:17 +0100 | [diff] [blame] | 4449 | else |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4450 | temp = 0; |
| 4451 | } |
| 4452 | I915_WRITE(DPLL_MD(pipe), temp); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4453 | } else { |
Chris Wilson | a589b9f | 2010-12-03 21:13:16 +0000 | [diff] [blame] | 4454 | /* The pixel multiplier can only be updated once the |
| 4455 | * DPLL is enabled and the clocks are stable. |
| 4456 | * |
| 4457 | * So write it again. |
| 4458 | */ |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4459 | I915_WRITE(dpll_reg, dpll); |
| 4460 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4461 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4462 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4463 | intel_crtc->lowfreq_avail = false; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 4464 | if (is_lvds && has_reduced_clock && i915_powersave) { |
| 4465 | I915_WRITE(fp_reg + 4, fp2); |
| 4466 | intel_crtc->lowfreq_avail = true; |
| 4467 | if (HAS_PIPE_CXSR(dev)) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 4468 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 4469 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; |
| 4470 | } |
| 4471 | } else { |
| 4472 | I915_WRITE(fp_reg + 4, fp); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 4473 | if (HAS_PIPE_CXSR(dev)) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 4474 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 4475 | pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK; |
| 4476 | } |
| 4477 | } |
| 4478 | |
Krzysztof Halasa | 734b415 | 2010-05-25 18:41:46 +0200 | [diff] [blame] | 4479 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
| 4480 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
| 4481 | /* the chip adds 2 halflines automatically */ |
| 4482 | adjusted_mode->crtc_vdisplay -= 1; |
| 4483 | adjusted_mode->crtc_vtotal -= 1; |
| 4484 | adjusted_mode->crtc_vblank_start -= 1; |
| 4485 | adjusted_mode->crtc_vblank_end -= 1; |
| 4486 | adjusted_mode->crtc_vsync_end -= 1; |
| 4487 | adjusted_mode->crtc_vsync_start -= 1; |
| 4488 | } else |
| 4489 | pipeconf &= ~PIPECONF_INTERLACE_W_FIELD_INDICATION; /* progressive */ |
| 4490 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4491 | I915_WRITE(HTOTAL(pipe), |
| 4492 | (adjusted_mode->crtc_hdisplay - 1) | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4493 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4494 | I915_WRITE(HBLANK(pipe), |
| 4495 | (adjusted_mode->crtc_hblank_start - 1) | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4496 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4497 | I915_WRITE(HSYNC(pipe), |
| 4498 | (adjusted_mode->crtc_hsync_start - 1) | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4499 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4500 | |
| 4501 | I915_WRITE(VTOTAL(pipe), |
| 4502 | (adjusted_mode->crtc_vdisplay - 1) | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4503 | ((adjusted_mode->crtc_vtotal - 1) << 16)); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4504 | I915_WRITE(VBLANK(pipe), |
| 4505 | (adjusted_mode->crtc_vblank_start - 1) | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4506 | ((adjusted_mode->crtc_vblank_end - 1) << 16)); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4507 | I915_WRITE(VSYNC(pipe), |
| 4508 | (adjusted_mode->crtc_vsync_start - 1) | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4509 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4510 | |
| 4511 | /* pipesrc and dspsize control the size that is scaled from, |
| 4512 | * which should always be the user's requested size. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4513 | */ |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 4514 | if (!HAS_PCH_SPLIT(dev)) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4515 | I915_WRITE(DSPSIZE(plane), |
| 4516 | ((mode->vdisplay - 1) << 16) | |
| 4517 | (mode->hdisplay - 1)); |
| 4518 | I915_WRITE(DSPPOS(plane), 0); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4519 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4520 | I915_WRITE(PIPESRC(pipe), |
| 4521 | ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1)); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4522 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 4523 | if (HAS_PCH_SPLIT(dev)) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4524 | I915_WRITE(PIPE_DATA_M1(pipe), TU_SIZE(m_n.tu) | m_n.gmch_m); |
| 4525 | I915_WRITE(PIPE_DATA_N1(pipe), m_n.gmch_n); |
| 4526 | I915_WRITE(PIPE_LINK_M1(pipe), m_n.link_m); |
| 4527 | I915_WRITE(PIPE_LINK_N1(pipe), m_n.link_n); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4528 | |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 4529 | if (has_edp_encoder && !intel_encoder_is_pch_edp(&has_edp_encoder->base)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 4530 | ironlake_set_pll_edp(crtc, adjusted_mode->clock); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4531 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4532 | } |
| 4533 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4534 | I915_WRITE(PIPECONF(pipe), pipeconf); |
| 4535 | POSTING_READ(PIPECONF(pipe)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4536 | |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 4537 | intel_wait_for_vblank(dev, pipe); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4538 | |
Chris Wilson | f00a3dd | 2010-10-21 14:57:17 +0100 | [diff] [blame] | 4539 | if (IS_GEN5(dev)) { |
Zhenyu Wang | 553bd14 | 2009-09-02 10:57:52 +0800 | [diff] [blame] | 4540 | /* enable address swizzle for tiling buffer */ |
| 4541 | temp = I915_READ(DISP_ARB_CTL); |
| 4542 | I915_WRITE(DISP_ARB_CTL, temp | DISP_TILE_SURFACE_SWIZZLING); |
| 4543 | } |
| 4544 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4545 | I915_WRITE(DSPCNTR(plane), dspcntr); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4546 | |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 4547 | ret = intel_pipe_set_base(crtc, x, y, old_fb); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 4548 | |
| 4549 | intel_update_watermarks(dev); |
| 4550 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4551 | drm_vblank_post_modeset(dev, pipe); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 4552 | |
Chris Wilson | 1f803ee | 2009-06-06 09:45:59 +0100 | [diff] [blame] | 4553 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4554 | } |
| 4555 | |
| 4556 | /** Loads the palette/gamma unit for the CRTC with the prepared values */ |
| 4557 | void intel_crtc_load_lut(struct drm_crtc *crtc) |
| 4558 | { |
| 4559 | struct drm_device *dev = crtc->dev; |
| 4560 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4561 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4562 | int palreg = (intel_crtc->pipe == 0) ? PALETTE_A : PALETTE_B; |
| 4563 | int i; |
| 4564 | |
| 4565 | /* The clocks have to be on to load the palette. */ |
| 4566 | if (!crtc->enabled) |
| 4567 | return; |
| 4568 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 4569 | /* use legacy palette for Ironlake */ |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 4570 | if (HAS_PCH_SPLIT(dev)) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4571 | palreg = (intel_crtc->pipe == 0) ? LGC_PALETTE_A : |
| 4572 | LGC_PALETTE_B; |
| 4573 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4574 | for (i = 0; i < 256; i++) { |
| 4575 | I915_WRITE(palreg + 4 * i, |
| 4576 | (intel_crtc->lut_r[i] << 16) | |
| 4577 | (intel_crtc->lut_g[i] << 8) | |
| 4578 | intel_crtc->lut_b[i]); |
| 4579 | } |
| 4580 | } |
| 4581 | |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 4582 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base) |
| 4583 | { |
| 4584 | struct drm_device *dev = crtc->dev; |
| 4585 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4586 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4587 | bool visible = base != 0; |
| 4588 | u32 cntl; |
| 4589 | |
| 4590 | if (intel_crtc->cursor_visible == visible) |
| 4591 | return; |
| 4592 | |
| 4593 | cntl = I915_READ(CURACNTR); |
| 4594 | if (visible) { |
| 4595 | /* On these chipsets we can only modify the base whilst |
| 4596 | * the cursor is disabled. |
| 4597 | */ |
| 4598 | I915_WRITE(CURABASE, base); |
| 4599 | |
| 4600 | cntl &= ~(CURSOR_FORMAT_MASK); |
| 4601 | /* XXX width must be 64, stride 256 => 0x00 << 28 */ |
| 4602 | cntl |= CURSOR_ENABLE | |
| 4603 | CURSOR_GAMMA_ENABLE | |
| 4604 | CURSOR_FORMAT_ARGB; |
| 4605 | } else |
| 4606 | cntl &= ~(CURSOR_ENABLE | CURSOR_GAMMA_ENABLE); |
| 4607 | I915_WRITE(CURACNTR, cntl); |
| 4608 | |
| 4609 | intel_crtc->cursor_visible = visible; |
| 4610 | } |
| 4611 | |
| 4612 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base) |
| 4613 | { |
| 4614 | struct drm_device *dev = crtc->dev; |
| 4615 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4616 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4617 | int pipe = intel_crtc->pipe; |
| 4618 | bool visible = base != 0; |
| 4619 | |
| 4620 | if (intel_crtc->cursor_visible != visible) { |
| 4621 | uint32_t cntl = I915_READ(pipe == 0 ? CURACNTR : CURBCNTR); |
| 4622 | if (base) { |
| 4623 | cntl &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT); |
| 4624 | cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE; |
| 4625 | cntl |= pipe << 28; /* Connect to correct pipe */ |
| 4626 | } else { |
| 4627 | cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE); |
| 4628 | cntl |= CURSOR_MODE_DISABLE; |
| 4629 | } |
| 4630 | I915_WRITE(pipe == 0 ? CURACNTR : CURBCNTR, cntl); |
| 4631 | |
| 4632 | intel_crtc->cursor_visible = visible; |
| 4633 | } |
| 4634 | /* and commit changes on next vblank */ |
| 4635 | I915_WRITE(pipe == 0 ? CURABASE : CURBBASE, base); |
| 4636 | } |
| 4637 | |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 4638 | /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */ |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 4639 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
| 4640 | bool on) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 4641 | { |
| 4642 | struct drm_device *dev = crtc->dev; |
| 4643 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4644 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4645 | int pipe = intel_crtc->pipe; |
| 4646 | int x = intel_crtc->cursor_x; |
| 4647 | int y = intel_crtc->cursor_y; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 4648 | u32 base, pos; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 4649 | bool visible; |
| 4650 | |
| 4651 | pos = 0; |
| 4652 | |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 4653 | if (on && crtc->enabled && crtc->fb) { |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 4654 | base = intel_crtc->cursor_addr; |
| 4655 | if (x > (int) crtc->fb->width) |
| 4656 | base = 0; |
| 4657 | |
| 4658 | if (y > (int) crtc->fb->height) |
| 4659 | base = 0; |
| 4660 | } else |
| 4661 | base = 0; |
| 4662 | |
| 4663 | if (x < 0) { |
| 4664 | if (x + intel_crtc->cursor_width < 0) |
| 4665 | base = 0; |
| 4666 | |
| 4667 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
| 4668 | x = -x; |
| 4669 | } |
| 4670 | pos |= x << CURSOR_X_SHIFT; |
| 4671 | |
| 4672 | if (y < 0) { |
| 4673 | if (y + intel_crtc->cursor_height < 0) |
| 4674 | base = 0; |
| 4675 | |
| 4676 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
| 4677 | y = -y; |
| 4678 | } |
| 4679 | pos |= y << CURSOR_Y_SHIFT; |
| 4680 | |
| 4681 | visible = base != 0; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 4682 | if (!visible && !intel_crtc->cursor_visible) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 4683 | return; |
| 4684 | |
| 4685 | I915_WRITE(pipe == 0 ? CURAPOS : CURBPOS, pos); |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 4686 | if (IS_845G(dev) || IS_I865G(dev)) |
| 4687 | i845_update_cursor(crtc, base); |
| 4688 | else |
| 4689 | i9xx_update_cursor(crtc, base); |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 4690 | |
| 4691 | if (visible) |
| 4692 | intel_mark_busy(dev, to_intel_framebuffer(crtc->fb)->obj); |
| 4693 | } |
| 4694 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4695 | static int intel_crtc_cursor_set(struct drm_crtc *crtc, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 4696 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4697 | uint32_t handle, |
| 4698 | uint32_t width, uint32_t height) |
| 4699 | { |
| 4700 | struct drm_device *dev = crtc->dev; |
| 4701 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4702 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 4703 | struct drm_i915_gem_object *obj; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 4704 | uint32_t addr; |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 4705 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4706 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 4707 | DRM_DEBUG_KMS("\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4708 | |
| 4709 | /* if we want to turn off the cursor ignore width and height */ |
| 4710 | if (!handle) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 4711 | DRM_DEBUG_KMS("cursor off\n"); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 4712 | addr = 0; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 4713 | obj = NULL; |
Pierre Willenbrock | 5004417 | 2009-02-23 10:12:15 +1000 | [diff] [blame] | 4714 | mutex_lock(&dev->struct_mutex); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 4715 | goto finish; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4716 | } |
| 4717 | |
| 4718 | /* Currently we only support 64x64 cursors */ |
| 4719 | if (width != 64 || height != 64) { |
| 4720 | DRM_ERROR("we currently only support 64x64 cursors\n"); |
| 4721 | return -EINVAL; |
| 4722 | } |
| 4723 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 4724 | obj = to_intel_bo(drm_gem_object_lookup(dev, file, handle)); |
| 4725 | if (!obj) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4726 | return -ENOENT; |
| 4727 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 4728 | if (obj->base.size < width * height * 4) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4729 | DRM_ERROR("buffer is to small\n"); |
Dave Airlie | 34b8686e | 2009-01-15 14:03:07 +1000 | [diff] [blame] | 4730 | ret = -ENOMEM; |
| 4731 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4732 | } |
| 4733 | |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 4734 | /* we only need to pin inside GTT if cursor is non-phy */ |
Kristian Høgsberg | 7f9872e | 2009-02-13 20:56:49 -0500 | [diff] [blame] | 4735 | mutex_lock(&dev->struct_mutex); |
Kristian Høgsberg | b295d1b | 2009-12-16 15:16:17 -0500 | [diff] [blame] | 4736 | if (!dev_priv->info->cursor_needs_physical) { |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 4737 | if (obj->tiling_mode) { |
| 4738 | DRM_ERROR("cursor cannot be tiled\n"); |
| 4739 | ret = -EINVAL; |
| 4740 | goto fail_locked; |
| 4741 | } |
| 4742 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 4743 | ret = i915_gem_object_pin(obj, PAGE_SIZE, true); |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 4744 | if (ret) { |
| 4745 | DRM_ERROR("failed to pin cursor bo\n"); |
Kristian Høgsberg | 7f9872e | 2009-02-13 20:56:49 -0500 | [diff] [blame] | 4746 | goto fail_locked; |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 4747 | } |
Chris Wilson | e7b526b | 2010-06-02 08:30:48 +0100 | [diff] [blame] | 4748 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 4749 | ret = i915_gem_object_set_to_gtt_domain(obj, 0); |
Chris Wilson | e7b526b | 2010-06-02 08:30:48 +0100 | [diff] [blame] | 4750 | if (ret) { |
| 4751 | DRM_ERROR("failed to move cursor bo into the GTT\n"); |
| 4752 | goto fail_unpin; |
| 4753 | } |
| 4754 | |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 4755 | ret = i915_gem_object_put_fence(obj); |
| 4756 | if (ret) { |
| 4757 | DRM_ERROR("failed to move cursor bo into the GTT\n"); |
| 4758 | goto fail_unpin; |
| 4759 | } |
| 4760 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 4761 | addr = obj->gtt_offset; |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 4762 | } else { |
Chris Wilson | 6eeefaf | 2010-08-07 11:01:39 +0100 | [diff] [blame] | 4763 | int align = IS_I830(dev) ? 16 * 1024 : 256; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 4764 | ret = i915_gem_attach_phys_object(dev, obj, |
Chris Wilson | 6eeefaf | 2010-08-07 11:01:39 +0100 | [diff] [blame] | 4765 | (intel_crtc->pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1, |
| 4766 | align); |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 4767 | if (ret) { |
| 4768 | DRM_ERROR("failed to attach phys object\n"); |
Kristian Høgsberg | 7f9872e | 2009-02-13 20:56:49 -0500 | [diff] [blame] | 4769 | goto fail_locked; |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 4770 | } |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 4771 | addr = obj->phys_obj->handle->busaddr; |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 4772 | } |
| 4773 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 4774 | if (IS_GEN2(dev)) |
Jesse Barnes | 14b6039 | 2009-05-20 16:47:08 -0400 | [diff] [blame] | 4775 | I915_WRITE(CURSIZE, (height << 12) | width); |
| 4776 | |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 4777 | finish: |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 4778 | if (intel_crtc->cursor_bo) { |
Kristian Høgsberg | b295d1b | 2009-12-16 15:16:17 -0500 | [diff] [blame] | 4779 | if (dev_priv->info->cursor_needs_physical) { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 4780 | if (intel_crtc->cursor_bo != obj) |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 4781 | i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo); |
| 4782 | } else |
| 4783 | i915_gem_object_unpin(intel_crtc->cursor_bo); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 4784 | drm_gem_object_unreference(&intel_crtc->cursor_bo->base); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 4785 | } |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 4786 | |
Kristian Høgsberg | 7f9872e | 2009-02-13 20:56:49 -0500 | [diff] [blame] | 4787 | mutex_unlock(&dev->struct_mutex); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 4788 | |
| 4789 | intel_crtc->cursor_addr = addr; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 4790 | intel_crtc->cursor_bo = obj; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 4791 | intel_crtc->cursor_width = width; |
| 4792 | intel_crtc->cursor_height = height; |
| 4793 | |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 4794 | intel_crtc_update_cursor(crtc, true); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 4795 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4796 | return 0; |
Chris Wilson | e7b526b | 2010-06-02 08:30:48 +0100 | [diff] [blame] | 4797 | fail_unpin: |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 4798 | i915_gem_object_unpin(obj); |
Kristian Høgsberg | 7f9872e | 2009-02-13 20:56:49 -0500 | [diff] [blame] | 4799 | fail_locked: |
Dave Airlie | 34b8686e | 2009-01-15 14:03:07 +1000 | [diff] [blame] | 4800 | mutex_unlock(&dev->struct_mutex); |
Luca Barbieri | bc9025b | 2010-02-09 05:49:12 +0000 | [diff] [blame] | 4801 | fail: |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 4802 | drm_gem_object_unreference_unlocked(&obj->base); |
Dave Airlie | 34b8686e | 2009-01-15 14:03:07 +1000 | [diff] [blame] | 4803 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4804 | } |
| 4805 | |
| 4806 | static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) |
| 4807 | { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4808 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4809 | |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 4810 | intel_crtc->cursor_x = x; |
| 4811 | intel_crtc->cursor_y = y; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 4812 | |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 4813 | intel_crtc_update_cursor(crtc, true); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4814 | |
| 4815 | return 0; |
| 4816 | } |
| 4817 | |
| 4818 | /** Sets the color ramps on behalf of RandR */ |
| 4819 | void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green, |
| 4820 | u16 blue, int regno) |
| 4821 | { |
| 4822 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4823 | |
| 4824 | intel_crtc->lut_r[regno] = red >> 8; |
| 4825 | intel_crtc->lut_g[regno] = green >> 8; |
| 4826 | intel_crtc->lut_b[regno] = blue >> 8; |
| 4827 | } |
| 4828 | |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 4829 | void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green, |
| 4830 | u16 *blue, int regno) |
| 4831 | { |
| 4832 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4833 | |
| 4834 | *red = intel_crtc->lut_r[regno] << 8; |
| 4835 | *green = intel_crtc->lut_g[regno] << 8; |
| 4836 | *blue = intel_crtc->lut_b[regno] << 8; |
| 4837 | } |
| 4838 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4839 | static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 4840 | u16 *blue, uint32_t start, uint32_t size) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4841 | { |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 4842 | int end = (start + size > 256) ? 256 : start + size, i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4843 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4844 | |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 4845 | for (i = start; i < end; i++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4846 | intel_crtc->lut_r[i] = red[i] >> 8; |
| 4847 | intel_crtc->lut_g[i] = green[i] >> 8; |
| 4848 | intel_crtc->lut_b[i] = blue[i] >> 8; |
| 4849 | } |
| 4850 | |
| 4851 | intel_crtc_load_lut(crtc); |
| 4852 | } |
| 4853 | |
| 4854 | /** |
| 4855 | * Get a pipe with a simple mode set on it for doing load-based monitor |
| 4856 | * detection. |
| 4857 | * |
| 4858 | * It will be up to the load-detect code to adjust the pipe as appropriate for |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 4859 | * its requirements. The pipe will be connected to no other encoders. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4860 | * |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 4861 | * Currently this code will only succeed if there is a pipe with no encoders |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4862 | * configured for it. In the future, it could choose to temporarily disable |
| 4863 | * some outputs to free up a pipe for its use. |
| 4864 | * |
| 4865 | * \return crtc, or NULL if no pipes are available. |
| 4866 | */ |
| 4867 | |
| 4868 | /* VESA 640x480x72Hz mode to set on the pipe */ |
| 4869 | static struct drm_display_mode load_detect_mode = { |
| 4870 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
| 4871 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
| 4872 | }; |
| 4873 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 4874 | struct drm_crtc *intel_get_load_detect_pipe(struct intel_encoder *intel_encoder, |
Zhenyu Wang | c1c4397 | 2010-03-30 14:39:30 +0800 | [diff] [blame] | 4875 | struct drm_connector *connector, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4876 | struct drm_display_mode *mode, |
| 4877 | int *dpms_mode) |
| 4878 | { |
| 4879 | struct intel_crtc *intel_crtc; |
| 4880 | struct drm_crtc *possible_crtc; |
| 4881 | struct drm_crtc *supported_crtc =NULL; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 4882 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4883 | struct drm_crtc *crtc = NULL; |
| 4884 | struct drm_device *dev = encoder->dev; |
| 4885 | struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; |
| 4886 | struct drm_crtc_helper_funcs *crtc_funcs; |
| 4887 | int i = -1; |
| 4888 | |
| 4889 | /* |
| 4890 | * Algorithm gets a little messy: |
| 4891 | * - if the connector already has an assigned crtc, use it (but make |
| 4892 | * sure it's on first) |
| 4893 | * - try to find the first unused crtc that can drive this connector, |
| 4894 | * and use that if we find one |
| 4895 | * - if there are no unused crtcs available, try to use the first |
| 4896 | * one we found that supports the connector |
| 4897 | */ |
| 4898 | |
| 4899 | /* See if we already have a CRTC for this connector */ |
| 4900 | if (encoder->crtc) { |
| 4901 | crtc = encoder->crtc; |
| 4902 | /* Make sure the crtc and connector are running */ |
| 4903 | intel_crtc = to_intel_crtc(crtc); |
| 4904 | *dpms_mode = intel_crtc->dpms_mode; |
| 4905 | if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) { |
| 4906 | crtc_funcs = crtc->helper_private; |
| 4907 | crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON); |
| 4908 | encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON); |
| 4909 | } |
| 4910 | return crtc; |
| 4911 | } |
| 4912 | |
| 4913 | /* Find an unused one (if possible) */ |
| 4914 | list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) { |
| 4915 | i++; |
| 4916 | if (!(encoder->possible_crtcs & (1 << i))) |
| 4917 | continue; |
| 4918 | if (!possible_crtc->enabled) { |
| 4919 | crtc = possible_crtc; |
| 4920 | break; |
| 4921 | } |
| 4922 | if (!supported_crtc) |
| 4923 | supported_crtc = possible_crtc; |
| 4924 | } |
| 4925 | |
| 4926 | /* |
| 4927 | * If we didn't find an unused CRTC, don't use any. |
| 4928 | */ |
| 4929 | if (!crtc) { |
| 4930 | return NULL; |
| 4931 | } |
| 4932 | |
| 4933 | encoder->crtc = crtc; |
Zhenyu Wang | c1c4397 | 2010-03-30 14:39:30 +0800 | [diff] [blame] | 4934 | connector->encoder = encoder; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 4935 | intel_encoder->load_detect_temp = true; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4936 | |
| 4937 | intel_crtc = to_intel_crtc(crtc); |
| 4938 | *dpms_mode = intel_crtc->dpms_mode; |
| 4939 | |
| 4940 | if (!crtc->enabled) { |
| 4941 | if (!mode) |
| 4942 | mode = &load_detect_mode; |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 4943 | drm_crtc_helper_set_mode(crtc, mode, 0, 0, crtc->fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4944 | } else { |
| 4945 | if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) { |
| 4946 | crtc_funcs = crtc->helper_private; |
| 4947 | crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON); |
| 4948 | } |
| 4949 | |
| 4950 | /* Add this connector to the crtc */ |
| 4951 | encoder_funcs->mode_set(encoder, &crtc->mode, &crtc->mode); |
| 4952 | encoder_funcs->commit(encoder); |
| 4953 | } |
| 4954 | /* let the connector get through one full cycle before testing */ |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 4955 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4956 | |
| 4957 | return crtc; |
| 4958 | } |
| 4959 | |
Zhenyu Wang | c1c4397 | 2010-03-30 14:39:30 +0800 | [diff] [blame] | 4960 | void intel_release_load_detect_pipe(struct intel_encoder *intel_encoder, |
| 4961 | struct drm_connector *connector, int dpms_mode) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4962 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 4963 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4964 | struct drm_device *dev = encoder->dev; |
| 4965 | struct drm_crtc *crtc = encoder->crtc; |
| 4966 | struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; |
| 4967 | struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; |
| 4968 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 4969 | if (intel_encoder->load_detect_temp) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4970 | encoder->crtc = NULL; |
Zhenyu Wang | c1c4397 | 2010-03-30 14:39:30 +0800 | [diff] [blame] | 4971 | connector->encoder = NULL; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 4972 | intel_encoder->load_detect_temp = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4973 | crtc->enabled = drm_helper_crtc_in_use(crtc); |
| 4974 | drm_helper_disable_unused_functions(dev); |
| 4975 | } |
| 4976 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 4977 | /* Switch crtc and encoder back off if necessary */ |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4978 | if (crtc->enabled && dpms_mode != DRM_MODE_DPMS_ON) { |
| 4979 | if (encoder->crtc == crtc) |
| 4980 | encoder_funcs->dpms(encoder, dpms_mode); |
| 4981 | crtc_funcs->dpms(crtc, dpms_mode); |
| 4982 | } |
| 4983 | } |
| 4984 | |
| 4985 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
| 4986 | static int intel_crtc_clock_get(struct drm_device *dev, struct drm_crtc *crtc) |
| 4987 | { |
| 4988 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4989 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4990 | int pipe = intel_crtc->pipe; |
| 4991 | u32 dpll = I915_READ((pipe == 0) ? DPLL_A : DPLL_B); |
| 4992 | u32 fp; |
| 4993 | intel_clock_t clock; |
| 4994 | |
| 4995 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) |
| 4996 | fp = I915_READ((pipe == 0) ? FPA0 : FPB0); |
| 4997 | else |
| 4998 | fp = I915_READ((pipe == 0) ? FPA1 : FPB1); |
| 4999 | |
| 5000 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 5001 | if (IS_PINEVIEW(dev)) { |
| 5002 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
| 5003 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 5004 | } else { |
| 5005 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; |
| 5006 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; |
| 5007 | } |
| 5008 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 5009 | if (!IS_GEN2(dev)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 5010 | if (IS_PINEVIEW(dev)) |
| 5011 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
| 5012 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 5013 | else |
| 5014 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5015 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 5016 | |
| 5017 | switch (dpll & DPLL_MODE_MASK) { |
| 5018 | case DPLLB_MODE_DAC_SERIAL: |
| 5019 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? |
| 5020 | 5 : 10; |
| 5021 | break; |
| 5022 | case DPLLB_MODE_LVDS: |
| 5023 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? |
| 5024 | 7 : 14; |
| 5025 | break; |
| 5026 | default: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 5027 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5028 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
| 5029 | return 0; |
| 5030 | } |
| 5031 | |
| 5032 | /* XXX: Handle the 100Mhz refclk */ |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 5033 | intel_clock(dev, 96000, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5034 | } else { |
| 5035 | bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN); |
| 5036 | |
| 5037 | if (is_lvds) { |
| 5038 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> |
| 5039 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 5040 | clock.p2 = 14; |
| 5041 | |
| 5042 | if ((dpll & PLL_REF_INPUT_MASK) == |
| 5043 | PLLB_REF_INPUT_SPREADSPECTRUMIN) { |
| 5044 | /* XXX: might not be 66MHz */ |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 5045 | intel_clock(dev, 66000, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5046 | } else |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 5047 | intel_clock(dev, 48000, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5048 | } else { |
| 5049 | if (dpll & PLL_P1_DIVIDE_BY_TWO) |
| 5050 | clock.p1 = 2; |
| 5051 | else { |
| 5052 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> |
| 5053 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; |
| 5054 | } |
| 5055 | if (dpll & PLL_P2_DIVIDE_BY_4) |
| 5056 | clock.p2 = 4; |
| 5057 | else |
| 5058 | clock.p2 = 2; |
| 5059 | |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 5060 | intel_clock(dev, 48000, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5061 | } |
| 5062 | } |
| 5063 | |
| 5064 | /* XXX: It would be nice to validate the clocks, but we can't reuse |
| 5065 | * i830PllIsValid() because it relies on the xf86_config connector |
| 5066 | * configuration being accurate, which it isn't necessarily. |
| 5067 | */ |
| 5068 | |
| 5069 | return clock.dot; |
| 5070 | } |
| 5071 | |
| 5072 | /** Returns the currently programmed mode of the given pipe. */ |
| 5073 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, |
| 5074 | struct drm_crtc *crtc) |
| 5075 | { |
| 5076 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5077 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5078 | int pipe = intel_crtc->pipe; |
| 5079 | struct drm_display_mode *mode; |
| 5080 | int htot = I915_READ((pipe == 0) ? HTOTAL_A : HTOTAL_B); |
| 5081 | int hsync = I915_READ((pipe == 0) ? HSYNC_A : HSYNC_B); |
| 5082 | int vtot = I915_READ((pipe == 0) ? VTOTAL_A : VTOTAL_B); |
| 5083 | int vsync = I915_READ((pipe == 0) ? VSYNC_A : VSYNC_B); |
| 5084 | |
| 5085 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 5086 | if (!mode) |
| 5087 | return NULL; |
| 5088 | |
| 5089 | mode->clock = intel_crtc_clock_get(dev, crtc); |
| 5090 | mode->hdisplay = (htot & 0xffff) + 1; |
| 5091 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; |
| 5092 | mode->hsync_start = (hsync & 0xffff) + 1; |
| 5093 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; |
| 5094 | mode->vdisplay = (vtot & 0xffff) + 1; |
| 5095 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; |
| 5096 | mode->vsync_start = (vsync & 0xffff) + 1; |
| 5097 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; |
| 5098 | |
| 5099 | drm_mode_set_name(mode); |
| 5100 | drm_mode_set_crtcinfo(mode, 0); |
| 5101 | |
| 5102 | return mode; |
| 5103 | } |
| 5104 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5105 | #define GPU_IDLE_TIMEOUT 500 /* ms */ |
| 5106 | |
| 5107 | /* When this timer fires, we've been idle for awhile */ |
| 5108 | static void intel_gpu_idle_timer(unsigned long arg) |
| 5109 | { |
| 5110 | struct drm_device *dev = (struct drm_device *)arg; |
| 5111 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 5112 | |
Chris Wilson | ff7ea4c | 2010-12-08 09:43:41 +0000 | [diff] [blame] | 5113 | if (!list_empty(&dev_priv->mm.active_list)) { |
| 5114 | /* Still processing requests, so just re-arm the timer. */ |
| 5115 | mod_timer(&dev_priv->idle_timer, jiffies + |
| 5116 | msecs_to_jiffies(GPU_IDLE_TIMEOUT)); |
| 5117 | return; |
| 5118 | } |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5119 | |
Chris Wilson | ff7ea4c | 2010-12-08 09:43:41 +0000 | [diff] [blame] | 5120 | dev_priv->busy = false; |
Eric Anholt | 01dfba9 | 2009-09-06 15:18:53 -0700 | [diff] [blame] | 5121 | queue_work(dev_priv->wq, &dev_priv->idle_work); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5122 | } |
| 5123 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5124 | #define CRTC_IDLE_TIMEOUT 1000 /* ms */ |
| 5125 | |
| 5126 | static void intel_crtc_idle_timer(unsigned long arg) |
| 5127 | { |
| 5128 | struct intel_crtc *intel_crtc = (struct intel_crtc *)arg; |
| 5129 | struct drm_crtc *crtc = &intel_crtc->base; |
| 5130 | drm_i915_private_t *dev_priv = crtc->dev->dev_private; |
Chris Wilson | ff7ea4c | 2010-12-08 09:43:41 +0000 | [diff] [blame] | 5131 | struct intel_framebuffer *intel_fb; |
| 5132 | |
| 5133 | intel_fb = to_intel_framebuffer(crtc->fb); |
| 5134 | if (intel_fb && intel_fb->obj->active) { |
| 5135 | /* The framebuffer is still being accessed by the GPU. */ |
| 5136 | mod_timer(&intel_crtc->idle_timer, jiffies + |
| 5137 | msecs_to_jiffies(CRTC_IDLE_TIMEOUT)); |
| 5138 | return; |
| 5139 | } |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5140 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5141 | intel_crtc->busy = false; |
Eric Anholt | 01dfba9 | 2009-09-06 15:18:53 -0700 | [diff] [blame] | 5142 | queue_work(dev_priv->wq, &dev_priv->idle_work); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5143 | } |
| 5144 | |
Daniel Vetter | 3dec009 | 2010-08-20 21:40:52 +0200 | [diff] [blame] | 5145 | static void intel_increase_pllclock(struct drm_crtc *crtc) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5146 | { |
| 5147 | struct drm_device *dev = crtc->dev; |
| 5148 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 5149 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5150 | int pipe = intel_crtc->pipe; |
Jesse Barnes | dbdc647 | 2010-12-30 09:36:39 -0800 | [diff] [blame] | 5151 | int dpll_reg = DPLL(pipe); |
| 5152 | int dpll; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5153 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 5154 | if (HAS_PCH_SPLIT(dev)) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5155 | return; |
| 5156 | |
| 5157 | if (!dev_priv->lvds_downclock_avail) |
| 5158 | return; |
| 5159 | |
Jesse Barnes | dbdc647 | 2010-12-30 09:36:39 -0800 | [diff] [blame] | 5160 | dpll = I915_READ(dpll_reg); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5161 | if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) { |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 5162 | DRM_DEBUG_DRIVER("upclocking LVDS\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5163 | |
| 5164 | /* Unlock panel regs */ |
Jesse Barnes | dbdc647 | 2010-12-30 09:36:39 -0800 | [diff] [blame] | 5165 | I915_WRITE(PP_CONTROL, |
| 5166 | I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5167 | |
| 5168 | dpll &= ~DISPLAY_RATE_SELECT_FPA1; |
| 5169 | I915_WRITE(dpll_reg, dpll); |
Jesse Barnes | dbdc647 | 2010-12-30 09:36:39 -0800 | [diff] [blame] | 5170 | POSTING_READ(dpll_reg); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 5171 | intel_wait_for_vblank(dev, pipe); |
Jesse Barnes | dbdc647 | 2010-12-30 09:36:39 -0800 | [diff] [blame] | 5172 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5173 | dpll = I915_READ(dpll_reg); |
| 5174 | if (dpll & DISPLAY_RATE_SELECT_FPA1) |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 5175 | DRM_DEBUG_DRIVER("failed to upclock LVDS!\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5176 | |
| 5177 | /* ...and lock them again */ |
| 5178 | I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) & 0x3); |
| 5179 | } |
| 5180 | |
| 5181 | /* Schedule downclock */ |
Daniel Vetter | 3dec009 | 2010-08-20 21:40:52 +0200 | [diff] [blame] | 5182 | mod_timer(&intel_crtc->idle_timer, jiffies + |
| 5183 | msecs_to_jiffies(CRTC_IDLE_TIMEOUT)); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5184 | } |
| 5185 | |
| 5186 | static void intel_decrease_pllclock(struct drm_crtc *crtc) |
| 5187 | { |
| 5188 | struct drm_device *dev = crtc->dev; |
| 5189 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 5190 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5191 | int pipe = intel_crtc->pipe; |
| 5192 | int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B; |
| 5193 | int dpll = I915_READ(dpll_reg); |
| 5194 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 5195 | if (HAS_PCH_SPLIT(dev)) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5196 | return; |
| 5197 | |
| 5198 | if (!dev_priv->lvds_downclock_avail) |
| 5199 | return; |
| 5200 | |
| 5201 | /* |
| 5202 | * Since this is called by a timer, we should never get here in |
| 5203 | * the manual case. |
| 5204 | */ |
| 5205 | if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) { |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 5206 | DRM_DEBUG_DRIVER("downclocking LVDS\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5207 | |
| 5208 | /* Unlock panel regs */ |
Jesse Barnes | 4a655f0 | 2010-07-22 13:18:18 -0700 | [diff] [blame] | 5209 | I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) | |
| 5210 | PANEL_UNLOCK_REGS); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5211 | |
| 5212 | dpll |= DISPLAY_RATE_SELECT_FPA1; |
| 5213 | I915_WRITE(dpll_reg, dpll); |
| 5214 | dpll = I915_READ(dpll_reg); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 5215 | intel_wait_for_vblank(dev, pipe); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5216 | dpll = I915_READ(dpll_reg); |
| 5217 | if (!(dpll & DISPLAY_RATE_SELECT_FPA1)) |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 5218 | DRM_DEBUG_DRIVER("failed to downclock LVDS!\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5219 | |
| 5220 | /* ...and lock them again */ |
| 5221 | I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) & 0x3); |
| 5222 | } |
| 5223 | |
| 5224 | } |
| 5225 | |
| 5226 | /** |
| 5227 | * intel_idle_update - adjust clocks for idleness |
| 5228 | * @work: work struct |
| 5229 | * |
| 5230 | * Either the GPU or display (or both) went idle. Check the busy status |
| 5231 | * here and adjust the CRTC and GPU clocks as necessary. |
| 5232 | */ |
| 5233 | static void intel_idle_update(struct work_struct *work) |
| 5234 | { |
| 5235 | drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, |
| 5236 | idle_work); |
| 5237 | struct drm_device *dev = dev_priv->dev; |
| 5238 | struct drm_crtc *crtc; |
| 5239 | struct intel_crtc *intel_crtc; |
Li Peng | 45ac22c | 2010-06-12 23:38:35 +0800 | [diff] [blame] | 5240 | int enabled = 0; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5241 | |
| 5242 | if (!i915_powersave) |
| 5243 | return; |
| 5244 | |
| 5245 | mutex_lock(&dev->struct_mutex); |
| 5246 | |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 5247 | i915_update_gfx_val(dev_priv); |
| 5248 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5249 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 5250 | /* Skip inactive CRTCs */ |
| 5251 | if (!crtc->fb) |
| 5252 | continue; |
| 5253 | |
Li Peng | 45ac22c | 2010-06-12 23:38:35 +0800 | [diff] [blame] | 5254 | enabled++; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5255 | intel_crtc = to_intel_crtc(crtc); |
| 5256 | if (!intel_crtc->busy) |
| 5257 | intel_decrease_pllclock(crtc); |
| 5258 | } |
| 5259 | |
Li Peng | 45ac22c | 2010-06-12 23:38:35 +0800 | [diff] [blame] | 5260 | if ((enabled == 1) && (IS_I945G(dev) || IS_I945GM(dev))) { |
| 5261 | DRM_DEBUG_DRIVER("enable memory self refresh on 945\n"); |
| 5262 | I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN_MASK | FW_BLC_SELF_EN); |
| 5263 | } |
| 5264 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5265 | mutex_unlock(&dev->struct_mutex); |
| 5266 | } |
| 5267 | |
| 5268 | /** |
| 5269 | * intel_mark_busy - mark the GPU and possibly the display busy |
| 5270 | * @dev: drm device |
| 5271 | * @obj: object we're operating on |
| 5272 | * |
| 5273 | * Callers can use this function to indicate that the GPU is busy processing |
| 5274 | * commands. If @obj matches one of the CRTC objects (i.e. it's a scanout |
| 5275 | * buffer), we'll also mark the display as busy, so we know to increase its |
| 5276 | * clock frequency. |
| 5277 | */ |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5278 | void intel_mark_busy(struct drm_device *dev, struct drm_i915_gem_object *obj) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5279 | { |
| 5280 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 5281 | struct drm_crtc *crtc = NULL; |
| 5282 | struct intel_framebuffer *intel_fb; |
| 5283 | struct intel_crtc *intel_crtc; |
| 5284 | |
Zhenyu Wang | 5e17ee7 | 2009-09-03 09:30:06 +0800 | [diff] [blame] | 5285 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 5286 | return; |
| 5287 | |
Li Peng | 060e645 | 2010-02-10 01:54:24 +0800 | [diff] [blame] | 5288 | if (!dev_priv->busy) { |
| 5289 | if (IS_I945G(dev) || IS_I945GM(dev)) { |
| 5290 | u32 fw_blc_self; |
Li Peng | ee980b8 | 2010-01-27 19:01:11 +0800 | [diff] [blame] | 5291 | |
Li Peng | 060e645 | 2010-02-10 01:54:24 +0800 | [diff] [blame] | 5292 | DRM_DEBUG_DRIVER("disable memory self refresh on 945\n"); |
| 5293 | fw_blc_self = I915_READ(FW_BLC_SELF); |
| 5294 | fw_blc_self &= ~FW_BLC_SELF_EN; |
| 5295 | I915_WRITE(FW_BLC_SELF, fw_blc_self | FW_BLC_SELF_EN_MASK); |
| 5296 | } |
Chris Wilson | 28cf798 | 2009-11-30 01:08:56 +0000 | [diff] [blame] | 5297 | dev_priv->busy = true; |
Li Peng | 060e645 | 2010-02-10 01:54:24 +0800 | [diff] [blame] | 5298 | } else |
Chris Wilson | 28cf798 | 2009-11-30 01:08:56 +0000 | [diff] [blame] | 5299 | mod_timer(&dev_priv->idle_timer, jiffies + |
| 5300 | msecs_to_jiffies(GPU_IDLE_TIMEOUT)); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5301 | |
| 5302 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 5303 | if (!crtc->fb) |
| 5304 | continue; |
| 5305 | |
| 5306 | intel_crtc = to_intel_crtc(crtc); |
| 5307 | intel_fb = to_intel_framebuffer(crtc->fb); |
| 5308 | if (intel_fb->obj == obj) { |
| 5309 | if (!intel_crtc->busy) { |
Li Peng | 060e645 | 2010-02-10 01:54:24 +0800 | [diff] [blame] | 5310 | if (IS_I945G(dev) || IS_I945GM(dev)) { |
| 5311 | u32 fw_blc_self; |
| 5312 | |
| 5313 | DRM_DEBUG_DRIVER("disable memory self refresh on 945\n"); |
| 5314 | fw_blc_self = I915_READ(FW_BLC_SELF); |
| 5315 | fw_blc_self &= ~FW_BLC_SELF_EN; |
| 5316 | I915_WRITE(FW_BLC_SELF, fw_blc_self | FW_BLC_SELF_EN_MASK); |
| 5317 | } |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5318 | /* Non-busy -> busy, upclock */ |
Daniel Vetter | 3dec009 | 2010-08-20 21:40:52 +0200 | [diff] [blame] | 5319 | intel_increase_pllclock(crtc); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5320 | intel_crtc->busy = true; |
| 5321 | } else { |
| 5322 | /* Busy -> busy, put off timer */ |
| 5323 | mod_timer(&intel_crtc->idle_timer, jiffies + |
| 5324 | msecs_to_jiffies(CRTC_IDLE_TIMEOUT)); |
| 5325 | } |
| 5326 | } |
| 5327 | } |
| 5328 | } |
| 5329 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5330 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
| 5331 | { |
| 5332 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 5333 | struct drm_device *dev = crtc->dev; |
| 5334 | struct intel_unpin_work *work; |
| 5335 | unsigned long flags; |
| 5336 | |
| 5337 | spin_lock_irqsave(&dev->event_lock, flags); |
| 5338 | work = intel_crtc->unpin_work; |
| 5339 | intel_crtc->unpin_work = NULL; |
| 5340 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 5341 | |
| 5342 | if (work) { |
| 5343 | cancel_work_sync(&work->work); |
| 5344 | kfree(work); |
| 5345 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5346 | |
| 5347 | drm_crtc_cleanup(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 5348 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5349 | kfree(intel_crtc); |
| 5350 | } |
| 5351 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5352 | static void intel_unpin_work_fn(struct work_struct *__work) |
| 5353 | { |
| 5354 | struct intel_unpin_work *work = |
| 5355 | container_of(__work, struct intel_unpin_work, work); |
| 5356 | |
| 5357 | mutex_lock(&work->dev->struct_mutex); |
Jesse Barnes | b1b87f6 | 2010-01-26 14:40:05 -0800 | [diff] [blame] | 5358 | i915_gem_object_unpin(work->old_fb_obj); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5359 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
| 5360 | drm_gem_object_unreference(&work->old_fb_obj->base); |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 5361 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5362 | mutex_unlock(&work->dev->struct_mutex); |
| 5363 | kfree(work); |
| 5364 | } |
| 5365 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 5366 | static void do_intel_finish_page_flip(struct drm_device *dev, |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 5367 | struct drm_crtc *crtc) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5368 | { |
| 5369 | drm_i915_private_t *dev_priv = dev->dev_private; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5370 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5371 | struct intel_unpin_work *work; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5372 | struct drm_i915_gem_object *obj; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5373 | struct drm_pending_vblank_event *e; |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 5374 | struct timeval tnow, tvbl; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5375 | unsigned long flags; |
| 5376 | |
| 5377 | /* Ignore early vblank irqs */ |
| 5378 | if (intel_crtc == NULL) |
| 5379 | return; |
| 5380 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 5381 | do_gettimeofday(&tnow); |
| 5382 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5383 | spin_lock_irqsave(&dev->event_lock, flags); |
| 5384 | work = intel_crtc->unpin_work; |
| 5385 | if (work == NULL || !work->pending) { |
| 5386 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 5387 | return; |
| 5388 | } |
| 5389 | |
| 5390 | intel_crtc->unpin_work = NULL; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5391 | |
| 5392 | if (work->event) { |
| 5393 | e = work->event; |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 5394 | e->event.sequence = drm_vblank_count_and_time(dev, intel_crtc->pipe, &tvbl); |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 5395 | |
| 5396 | /* Called before vblank count and timestamps have |
| 5397 | * been updated for the vblank interval of flip |
| 5398 | * completion? Need to increment vblank count and |
| 5399 | * add one videorefresh duration to returned timestamp |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 5400 | * to account for this. We assume this happened if we |
| 5401 | * get called over 0.9 frame durations after the last |
| 5402 | * timestamped vblank. |
| 5403 | * |
| 5404 | * This calculation can not be used with vrefresh rates |
| 5405 | * below 5Hz (10Hz to be on the safe side) without |
| 5406 | * promoting to 64 integers. |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 5407 | */ |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 5408 | if (10 * (timeval_to_ns(&tnow) - timeval_to_ns(&tvbl)) > |
| 5409 | 9 * crtc->framedur_ns) { |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 5410 | e->event.sequence++; |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 5411 | tvbl = ns_to_timeval(timeval_to_ns(&tvbl) + |
| 5412 | crtc->framedur_ns); |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 5413 | } |
| 5414 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 5415 | e->event.tv_sec = tvbl.tv_sec; |
| 5416 | e->event.tv_usec = tvbl.tv_usec; |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 5417 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5418 | list_add_tail(&e->base.link, |
| 5419 | &e->base.file_priv->event_list); |
| 5420 | wake_up_interruptible(&e->base.file_priv->event_wait); |
| 5421 | } |
| 5422 | |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 5423 | drm_vblank_put(dev, intel_crtc->pipe); |
| 5424 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5425 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 5426 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5427 | obj = work->old_fb_obj; |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 5428 | |
Chris Wilson | e59f2ba | 2010-10-07 17:28:15 +0100 | [diff] [blame] | 5429 | atomic_clear_mask(1 << intel_crtc->plane, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5430 | &obj->pending_flip.counter); |
| 5431 | if (atomic_read(&obj->pending_flip) == 0) |
Chris Wilson | f787a5f | 2010-09-24 16:02:42 +0100 | [diff] [blame] | 5432 | wake_up(&dev_priv->pending_flip_queue); |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 5433 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5434 | schedule_work(&work->work); |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 5435 | |
| 5436 | trace_i915_flip_complete(intel_crtc->plane, work->pending_flip_obj); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5437 | } |
| 5438 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 5439 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
| 5440 | { |
| 5441 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 5442 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 5443 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 5444 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 5445 | } |
| 5446 | |
| 5447 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) |
| 5448 | { |
| 5449 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 5450 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; |
| 5451 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 5452 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 5453 | } |
| 5454 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5455 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
| 5456 | { |
| 5457 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 5458 | struct intel_crtc *intel_crtc = |
| 5459 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); |
| 5460 | unsigned long flags; |
| 5461 | |
| 5462 | spin_lock_irqsave(&dev->event_lock, flags); |
Jesse Barnes | de3f440 | 2010-01-14 13:18:02 -0800 | [diff] [blame] | 5463 | if (intel_crtc->unpin_work) { |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 5464 | if ((++intel_crtc->unpin_work->pending) > 1) |
| 5465 | DRM_ERROR("Prepared flip multiple times\n"); |
Jesse Barnes | de3f440 | 2010-01-14 13:18:02 -0800 | [diff] [blame] | 5466 | } else { |
| 5467 | DRM_DEBUG_DRIVER("preparing flip with no unpin work?\n"); |
| 5468 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5469 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 5470 | } |
| 5471 | |
| 5472 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
| 5473 | struct drm_framebuffer *fb, |
| 5474 | struct drm_pending_vblank_event *event) |
| 5475 | { |
| 5476 | struct drm_device *dev = crtc->dev; |
| 5477 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5478 | struct intel_framebuffer *intel_fb; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5479 | struct drm_i915_gem_object *obj; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5480 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5481 | struct intel_unpin_work *work; |
Jesse Barnes | be9a3db | 2010-07-23 12:03:37 -0700 | [diff] [blame] | 5482 | unsigned long flags, offset; |
Chris Wilson | 52e6863 | 2010-08-08 10:15:59 +0100 | [diff] [blame] | 5483 | int pipe = intel_crtc->pipe; |
Chris Wilson | 20f0cd5 | 2010-09-23 11:00:38 +0100 | [diff] [blame] | 5484 | u32 pf, pipesrc; |
Chris Wilson | 52e6863 | 2010-08-08 10:15:59 +0100 | [diff] [blame] | 5485 | int ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5486 | |
| 5487 | work = kzalloc(sizeof *work, GFP_KERNEL); |
| 5488 | if (work == NULL) |
| 5489 | return -ENOMEM; |
| 5490 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5491 | work->event = event; |
| 5492 | work->dev = crtc->dev; |
| 5493 | intel_fb = to_intel_framebuffer(crtc->fb); |
Jesse Barnes | b1b87f6 | 2010-01-26 14:40:05 -0800 | [diff] [blame] | 5494 | work->old_fb_obj = intel_fb->obj; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5495 | INIT_WORK(&work->work, intel_unpin_work_fn); |
| 5496 | |
| 5497 | /* We borrow the event spin lock for protecting unpin_work */ |
| 5498 | spin_lock_irqsave(&dev->event_lock, flags); |
| 5499 | if (intel_crtc->unpin_work) { |
| 5500 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 5501 | kfree(work); |
Chris Wilson | 468f0b4 | 2010-05-27 13:18:13 +0100 | [diff] [blame] | 5502 | |
| 5503 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5504 | return -EBUSY; |
| 5505 | } |
| 5506 | intel_crtc->unpin_work = work; |
| 5507 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 5508 | |
| 5509 | intel_fb = to_intel_framebuffer(fb); |
| 5510 | obj = intel_fb->obj; |
| 5511 | |
Chris Wilson | 468f0b4 | 2010-05-27 13:18:13 +0100 | [diff] [blame] | 5512 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 5513 | ret = intel_pin_and_fence_fb_obj(dev, obj, LP_RING(dev_priv)); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 5514 | if (ret) |
| 5515 | goto cleanup_work; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5516 | |
Jesse Barnes | 75dfca8 | 2010-02-10 15:09:44 -0800 | [diff] [blame] | 5517 | /* Reference the objects for the scheduled work. */ |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5518 | drm_gem_object_reference(&work->old_fb_obj->base); |
| 5519 | drm_gem_object_reference(&obj->base); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5520 | |
| 5521 | crtc->fb = fb; |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 5522 | |
| 5523 | ret = drm_vblank_get(dev, intel_crtc->pipe); |
| 5524 | if (ret) |
| 5525 | goto cleanup_objs; |
| 5526 | |
Chris Wilson | c7f9f9a | 2010-09-19 15:05:13 +0100 | [diff] [blame] | 5527 | if (IS_GEN3(dev) || IS_GEN2(dev)) { |
| 5528 | u32 flip_mask; |
| 5529 | |
| 5530 | /* Can't queue multiple flips, so wait for the previous |
| 5531 | * one to finish before executing the next. |
| 5532 | */ |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 5533 | ret = BEGIN_LP_RING(2); |
| 5534 | if (ret) |
| 5535 | goto cleanup_objs; |
| 5536 | |
Chris Wilson | c7f9f9a | 2010-09-19 15:05:13 +0100 | [diff] [blame] | 5537 | if (intel_crtc->plane) |
| 5538 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 5539 | else |
| 5540 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
| 5541 | OUT_RING(MI_WAIT_FOR_EVENT | flip_mask); |
| 5542 | OUT_RING(MI_NOOP); |
Daniel Vetter | 6146b3d | 2010-08-04 21:22:10 +0200 | [diff] [blame] | 5543 | ADVANCE_LP_RING(); |
| 5544 | } |
Jesse Barnes | 83f7fd0 | 2010-04-05 14:03:51 -0700 | [diff] [blame] | 5545 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 5546 | work->pending_flip_obj = obj; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 5547 | |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 5548 | work->enable_stall_check = true; |
| 5549 | |
Jesse Barnes | be9a3db | 2010-07-23 12:03:37 -0700 | [diff] [blame] | 5550 | /* Offset into the new buffer for cases of shared fbs between CRTCs */ |
Chris Wilson | 52e6863 | 2010-08-08 10:15:59 +0100 | [diff] [blame] | 5551 | offset = crtc->y * fb->pitch + crtc->x * fb->bits_per_pixel/8; |
Jesse Barnes | be9a3db | 2010-07-23 12:03:37 -0700 | [diff] [blame] | 5552 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 5553 | ret = BEGIN_LP_RING(4); |
| 5554 | if (ret) |
| 5555 | goto cleanup_objs; |
| 5556 | |
| 5557 | /* Block clients from rendering to the new back buffer until |
| 5558 | * the flip occurs and the object is no longer visible. |
| 5559 | */ |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5560 | atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip); |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 5561 | |
| 5562 | switch (INTEL_INFO(dev)->gen) { |
Chris Wilson | 52e6863 | 2010-08-08 10:15:59 +0100 | [diff] [blame] | 5563 | case 2: |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 5564 | OUT_RING(MI_DISPLAY_FLIP | |
| 5565 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 5566 | OUT_RING(fb->pitch); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5567 | OUT_RING(obj->gtt_offset + offset); |
Chris Wilson | 52e6863 | 2010-08-08 10:15:59 +0100 | [diff] [blame] | 5568 | OUT_RING(MI_NOOP); |
| 5569 | break; |
| 5570 | |
| 5571 | case 3: |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 5572 | OUT_RING(MI_DISPLAY_FLIP_I915 | |
| 5573 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 5574 | OUT_RING(fb->pitch); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5575 | OUT_RING(obj->gtt_offset + offset); |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 5576 | OUT_RING(MI_NOOP); |
Chris Wilson | 52e6863 | 2010-08-08 10:15:59 +0100 | [diff] [blame] | 5577 | break; |
| 5578 | |
| 5579 | case 4: |
| 5580 | case 5: |
| 5581 | /* i965+ uses the linear or tiled offsets from the |
| 5582 | * Display Registers (which do not change across a page-flip) |
| 5583 | * so we need only reprogram the base address. |
| 5584 | */ |
Daniel Vetter | 69d0b96 | 2010-08-04 21:22:09 +0200 | [diff] [blame] | 5585 | OUT_RING(MI_DISPLAY_FLIP | |
| 5586 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 5587 | OUT_RING(fb->pitch); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5588 | OUT_RING(obj->gtt_offset | obj->tiling_mode); |
Chris Wilson | 52e6863 | 2010-08-08 10:15:59 +0100 | [diff] [blame] | 5589 | |
| 5590 | /* XXX Enabling the panel-fitter across page-flip is so far |
| 5591 | * untested on non-native modes, so ignore it for now. |
| 5592 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; |
| 5593 | */ |
| 5594 | pf = 0; |
| 5595 | pipesrc = I915_READ(pipe == 0 ? PIPEASRC : PIPEBSRC) & 0x0fff0fff; |
| 5596 | OUT_RING(pf | pipesrc); |
| 5597 | break; |
| 5598 | |
| 5599 | case 6: |
| 5600 | OUT_RING(MI_DISPLAY_FLIP | |
| 5601 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5602 | OUT_RING(fb->pitch | obj->tiling_mode); |
| 5603 | OUT_RING(obj->gtt_offset); |
Chris Wilson | 52e6863 | 2010-08-08 10:15:59 +0100 | [diff] [blame] | 5604 | |
| 5605 | pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; |
| 5606 | pipesrc = I915_READ(pipe == 0 ? PIPEASRC : PIPEBSRC) & 0x0fff0fff; |
| 5607 | OUT_RING(pf | pipesrc); |
| 5608 | break; |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 5609 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5610 | ADVANCE_LP_RING(); |
| 5611 | |
| 5612 | mutex_unlock(&dev->struct_mutex); |
| 5613 | |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 5614 | trace_i915_flip_request(intel_crtc->plane, obj); |
| 5615 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5616 | return 0; |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 5617 | |
| 5618 | cleanup_objs: |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5619 | drm_gem_object_unreference(&work->old_fb_obj->base); |
| 5620 | drm_gem_object_unreference(&obj->base); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 5621 | cleanup_work: |
| 5622 | mutex_unlock(&dev->struct_mutex); |
| 5623 | |
| 5624 | spin_lock_irqsave(&dev->event_lock, flags); |
| 5625 | intel_crtc->unpin_work = NULL; |
| 5626 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 5627 | |
| 5628 | kfree(work); |
| 5629 | |
| 5630 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5631 | } |
| 5632 | |
Chris Wilson | 5d1d0cc | 2011-01-24 15:02:15 +0000 | [diff] [blame] | 5633 | static void intel_crtc_reset(struct drm_crtc *crtc) |
| 5634 | { |
| 5635 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5636 | |
| 5637 | /* Reset flags back to the 'unknown' status so that they |
| 5638 | * will be correctly set on the initial modeset. |
| 5639 | */ |
Chris Wilson | 5d1d0cc | 2011-01-24 15:02:15 +0000 | [diff] [blame] | 5640 | intel_crtc->dpms_mode = -1; |
Chris Wilson | 5d1d0cc | 2011-01-24 15:02:15 +0000 | [diff] [blame] | 5641 | } |
| 5642 | |
Jesse Barnes | 7e7d76c | 2010-09-10 10:47:20 -0700 | [diff] [blame] | 5643 | static struct drm_crtc_helper_funcs intel_helper_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5644 | .dpms = intel_crtc_dpms, |
| 5645 | .mode_fixup = intel_crtc_mode_fixup, |
| 5646 | .mode_set = intel_crtc_mode_set, |
| 5647 | .mode_set_base = intel_pipe_set_base, |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 5648 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 5649 | .load_lut = intel_crtc_load_lut, |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 5650 | .disable = intel_crtc_disable, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5651 | }; |
| 5652 | |
| 5653 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
Chris Wilson | 5d1d0cc | 2011-01-24 15:02:15 +0000 | [diff] [blame] | 5654 | .reset = intel_crtc_reset, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5655 | .cursor_set = intel_crtc_cursor_set, |
| 5656 | .cursor_move = intel_crtc_cursor_move, |
| 5657 | .gamma_set = intel_crtc_gamma_set, |
| 5658 | .set_config = drm_crtc_helper_set_config, |
| 5659 | .destroy = intel_crtc_destroy, |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 5660 | .page_flip = intel_crtc_page_flip, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5661 | }; |
| 5662 | |
Chris Wilson | 47f1c6c | 2010-12-03 15:37:31 +0000 | [diff] [blame] | 5663 | static void intel_sanitize_modesetting(struct drm_device *dev, |
| 5664 | int pipe, int plane) |
| 5665 | { |
| 5666 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5667 | u32 reg, val; |
| 5668 | |
| 5669 | if (HAS_PCH_SPLIT(dev)) |
| 5670 | return; |
| 5671 | |
| 5672 | /* Who knows what state these registers were left in by the BIOS or |
| 5673 | * grub? |
| 5674 | * |
| 5675 | * If we leave the registers in a conflicting state (e.g. with the |
| 5676 | * display plane reading from the other pipe than the one we intend |
| 5677 | * to use) then when we attempt to teardown the active mode, we will |
| 5678 | * not disable the pipes and planes in the correct order -- leaving |
| 5679 | * a plane reading from a disabled pipe and possibly leading to |
| 5680 | * undefined behaviour. |
| 5681 | */ |
| 5682 | |
| 5683 | reg = DSPCNTR(plane); |
| 5684 | val = I915_READ(reg); |
| 5685 | |
| 5686 | if ((val & DISPLAY_PLANE_ENABLE) == 0) |
| 5687 | return; |
| 5688 | if (!!(val & DISPPLANE_SEL_PIPE_MASK) == pipe) |
| 5689 | return; |
| 5690 | |
| 5691 | /* This display plane is active and attached to the other CPU pipe. */ |
| 5692 | pipe = !pipe; |
| 5693 | |
| 5694 | /* Disable the plane and wait for it to stop reading from the pipe. */ |
| 5695 | I915_WRITE(reg, val & ~DISPLAY_PLANE_ENABLE); |
| 5696 | intel_flush_display_plane(dev, plane); |
| 5697 | |
| 5698 | if (IS_GEN2(dev)) |
| 5699 | intel_wait_for_vblank(dev, pipe); |
| 5700 | |
| 5701 | if (pipe == 0 && (dev_priv->quirks & QUIRK_PIPEA_FORCE)) |
| 5702 | return; |
| 5703 | |
| 5704 | /* Switch off the pipe. */ |
| 5705 | reg = PIPECONF(pipe); |
| 5706 | val = I915_READ(reg); |
| 5707 | if (val & PIPECONF_ENABLE) { |
| 5708 | I915_WRITE(reg, val & ~PIPECONF_ENABLE); |
| 5709 | intel_wait_for_pipe_off(dev, pipe); |
| 5710 | } |
| 5711 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5712 | |
Hannes Eder | b358d0a | 2008-12-18 21:18:47 +0100 | [diff] [blame] | 5713 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5714 | { |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 5715 | drm_i915_private_t *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5716 | struct intel_crtc *intel_crtc; |
| 5717 | int i; |
| 5718 | |
| 5719 | intel_crtc = kzalloc(sizeof(struct intel_crtc) + (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL); |
| 5720 | if (intel_crtc == NULL) |
| 5721 | return; |
| 5722 | |
| 5723 | drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs); |
| 5724 | |
| 5725 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5726 | for (i = 0; i < 256; i++) { |
| 5727 | intel_crtc->lut_r[i] = i; |
| 5728 | intel_crtc->lut_g[i] = i; |
| 5729 | intel_crtc->lut_b[i] = i; |
| 5730 | } |
| 5731 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 5732 | /* Swap pipes & planes for FBC on pre-965 */ |
| 5733 | intel_crtc->pipe = pipe; |
| 5734 | intel_crtc->plane = pipe; |
Chris Wilson | e2e767a | 2010-09-13 16:53:12 +0100 | [diff] [blame] | 5735 | if (IS_MOBILE(dev) && IS_GEN3(dev)) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 5736 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
Chris Wilson | e2e767a | 2010-09-13 16:53:12 +0100 | [diff] [blame] | 5737 | intel_crtc->plane = !pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 5738 | } |
| 5739 | |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 5740 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
| 5741 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); |
| 5742 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; |
| 5743 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; |
| 5744 | |
Chris Wilson | 5d1d0cc | 2011-01-24 15:02:15 +0000 | [diff] [blame] | 5745 | intel_crtc_reset(&intel_crtc->base); |
Chris Wilson | 04dbff5 | 2011-02-10 17:38:35 +0000 | [diff] [blame] | 5746 | intel_crtc->active = true; /* force the pipe off on setup_init_config */ |
Jesse Barnes | 7e7d76c | 2010-09-10 10:47:20 -0700 | [diff] [blame] | 5747 | |
| 5748 | if (HAS_PCH_SPLIT(dev)) { |
| 5749 | intel_helper_funcs.prepare = ironlake_crtc_prepare; |
| 5750 | intel_helper_funcs.commit = ironlake_crtc_commit; |
| 5751 | } else { |
| 5752 | intel_helper_funcs.prepare = i9xx_crtc_prepare; |
| 5753 | intel_helper_funcs.commit = i9xx_crtc_commit; |
| 5754 | } |
| 5755 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5756 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
| 5757 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5758 | intel_crtc->busy = false; |
| 5759 | |
| 5760 | setup_timer(&intel_crtc->idle_timer, intel_crtc_idle_timer, |
| 5761 | (unsigned long)intel_crtc); |
Chris Wilson | 47f1c6c | 2010-12-03 15:37:31 +0000 | [diff] [blame] | 5762 | |
| 5763 | intel_sanitize_modesetting(dev, intel_crtc->pipe, intel_crtc->plane); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5764 | } |
| 5765 | |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 5766 | int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5767 | struct drm_file *file) |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 5768 | { |
| 5769 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 5770 | struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data; |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 5771 | struct drm_mode_object *drmmode_obj; |
| 5772 | struct intel_crtc *crtc; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 5773 | |
| 5774 | if (!dev_priv) { |
| 5775 | DRM_ERROR("called with no initialization\n"); |
| 5776 | return -EINVAL; |
| 5777 | } |
| 5778 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 5779 | drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id, |
| 5780 | DRM_MODE_OBJECT_CRTC); |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 5781 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 5782 | if (!drmmode_obj) { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 5783 | DRM_ERROR("no such CRTC id\n"); |
| 5784 | return -EINVAL; |
| 5785 | } |
| 5786 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 5787 | crtc = to_intel_crtc(obj_to_crtc(drmmode_obj)); |
| 5788 | pipe_from_crtc_id->pipe = crtc->pipe; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 5789 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 5790 | return 0; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 5791 | } |
| 5792 | |
Zhenyu Wang | c5e4df3 | 2010-03-30 14:39:27 +0800 | [diff] [blame] | 5793 | static int intel_encoder_clones(struct drm_device *dev, int type_mask) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5794 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 5795 | struct intel_encoder *encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5796 | int index_mask = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5797 | int entry = 0; |
| 5798 | |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 5799 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) { |
| 5800 | if (type_mask & encoder->clone_mask) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5801 | index_mask |= (1 << entry); |
| 5802 | entry++; |
| 5803 | } |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 5804 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5805 | return index_mask; |
| 5806 | } |
| 5807 | |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 5808 | static bool has_edp_a(struct drm_device *dev) |
| 5809 | { |
| 5810 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5811 | |
| 5812 | if (!IS_MOBILE(dev)) |
| 5813 | return false; |
| 5814 | |
| 5815 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) |
| 5816 | return false; |
| 5817 | |
| 5818 | if (IS_GEN5(dev) && |
| 5819 | (I915_READ(ILK_DISPLAY_CHICKEN_FUSES) & ILK_eDP_A_DISABLE)) |
| 5820 | return false; |
| 5821 | |
| 5822 | return true; |
| 5823 | } |
| 5824 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5825 | static void intel_setup_outputs(struct drm_device *dev) |
| 5826 | { |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 5827 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 5828 | struct intel_encoder *encoder; |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 5829 | bool dpd_is_edp = false; |
Chris Wilson | c5d1b51 | 2010-11-29 18:00:23 +0000 | [diff] [blame] | 5830 | bool has_lvds = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5831 | |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 5832 | if (IS_MOBILE(dev) && !IS_I830(dev)) |
Chris Wilson | c5d1b51 | 2010-11-29 18:00:23 +0000 | [diff] [blame] | 5833 | has_lvds = intel_lvds_init(dev); |
| 5834 | if (!has_lvds && !HAS_PCH_SPLIT(dev)) { |
| 5835 | /* disable the panel fitter on everything but LVDS */ |
| 5836 | I915_WRITE(PFIT_CONTROL, 0); |
| 5837 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5838 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 5839 | if (HAS_PCH_SPLIT(dev)) { |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 5840 | dpd_is_edp = intel_dpd_is_edp(dev); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 5841 | |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 5842 | if (has_edp_a(dev)) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 5843 | intel_dp_init(dev, DP_A); |
| 5844 | |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 5845 | if (dpd_is_edp && (I915_READ(PCH_DP_D) & DP_DETECTED)) |
| 5846 | intel_dp_init(dev, PCH_DP_D); |
| 5847 | } |
| 5848 | |
| 5849 | intel_crt_init(dev); |
| 5850 | |
| 5851 | if (HAS_PCH_SPLIT(dev)) { |
| 5852 | int found; |
| 5853 | |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 5854 | if (I915_READ(HDMIB) & PORT_DETECTED) { |
Zhao Yakui | 461ed3c | 2010-03-30 15:11:33 +0800 | [diff] [blame] | 5855 | /* PCH SDVOB multiplex with HDMIB */ |
| 5856 | found = intel_sdvo_init(dev, PCH_SDVOB); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 5857 | if (!found) |
| 5858 | intel_hdmi_init(dev, HDMIB); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 5859 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
| 5860 | intel_dp_init(dev, PCH_DP_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 5861 | } |
| 5862 | |
| 5863 | if (I915_READ(HDMIC) & PORT_DETECTED) |
| 5864 | intel_hdmi_init(dev, HDMIC); |
| 5865 | |
| 5866 | if (I915_READ(HDMID) & PORT_DETECTED) |
| 5867 | intel_hdmi_init(dev, HDMID); |
| 5868 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 5869 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
| 5870 | intel_dp_init(dev, PCH_DP_C); |
| 5871 | |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 5872 | if (!dpd_is_edp && (I915_READ(PCH_DP_D) & DP_DETECTED)) |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 5873 | intel_dp_init(dev, PCH_DP_D); |
| 5874 | |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 5875 | } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 5876 | bool found = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 5877 | |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 5878 | if (I915_READ(SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 5879 | DRM_DEBUG_KMS("probing SDVOB\n"); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 5880 | found = intel_sdvo_init(dev, SDVOB); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 5881 | if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) { |
| 5882 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 5883 | intel_hdmi_init(dev, SDVOB); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 5884 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 5885 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 5886 | if (!found && SUPPORTS_INTEGRATED_DP(dev)) { |
| 5887 | DRM_DEBUG_KMS("probing DP_B\n"); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5888 | intel_dp_init(dev, DP_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 5889 | } |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 5890 | } |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 5891 | |
| 5892 | /* Before G4X SDVOC doesn't have its own detect register */ |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 5893 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 5894 | if (I915_READ(SDVOB) & SDVO_DETECTED) { |
| 5895 | DRM_DEBUG_KMS("probing SDVOC\n"); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 5896 | found = intel_sdvo_init(dev, SDVOC); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 5897 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 5898 | |
| 5899 | if (!found && (I915_READ(SDVOC) & SDVO_DETECTED)) { |
| 5900 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 5901 | if (SUPPORTS_INTEGRATED_HDMI(dev)) { |
| 5902 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 5903 | intel_hdmi_init(dev, SDVOC); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 5904 | } |
| 5905 | if (SUPPORTS_INTEGRATED_DP(dev)) { |
| 5906 | DRM_DEBUG_KMS("probing DP_C\n"); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5907 | intel_dp_init(dev, DP_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 5908 | } |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 5909 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 5910 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 5911 | if (SUPPORTS_INTEGRATED_DP(dev) && |
| 5912 | (I915_READ(DP_D) & DP_DETECTED)) { |
| 5913 | DRM_DEBUG_KMS("probing DP_D\n"); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5914 | intel_dp_init(dev, DP_D); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 5915 | } |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 5916 | } else if (IS_GEN2(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5917 | intel_dvo_init(dev); |
| 5918 | |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 5919 | if (SUPPORTS_TV(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5920 | intel_tv_init(dev); |
| 5921 | |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 5922 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) { |
| 5923 | encoder->base.possible_crtcs = encoder->crtc_mask; |
| 5924 | encoder->base.possible_clones = |
| 5925 | intel_encoder_clones(dev, encoder->clone_mask); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5926 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 5927 | |
| 5928 | intel_panel_setup_backlight(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5929 | } |
| 5930 | |
| 5931 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 5932 | { |
| 5933 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5934 | |
| 5935 | drm_framebuffer_cleanup(fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5936 | drm_gem_object_unreference_unlocked(&intel_fb->obj->base); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5937 | |
| 5938 | kfree(intel_fb); |
| 5939 | } |
| 5940 | |
| 5941 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5942 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5943 | unsigned int *handle) |
| 5944 | { |
| 5945 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5946 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5947 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5948 | return drm_gem_handle_create(file, &obj->base, handle); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5949 | } |
| 5950 | |
| 5951 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
| 5952 | .destroy = intel_user_framebuffer_destroy, |
| 5953 | .create_handle = intel_user_framebuffer_create_handle, |
| 5954 | }; |
| 5955 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 5956 | int intel_framebuffer_init(struct drm_device *dev, |
| 5957 | struct intel_framebuffer *intel_fb, |
| 5958 | struct drm_mode_fb_cmd *mode_cmd, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5959 | struct drm_i915_gem_object *obj) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5960 | { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5961 | int ret; |
| 5962 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5963 | if (obj->tiling_mode == I915_TILING_Y) |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 5964 | return -EINVAL; |
| 5965 | |
| 5966 | if (mode_cmd->pitch & 63) |
| 5967 | return -EINVAL; |
| 5968 | |
| 5969 | switch (mode_cmd->bpp) { |
| 5970 | case 8: |
| 5971 | case 16: |
| 5972 | case 24: |
| 5973 | case 32: |
| 5974 | break; |
| 5975 | default: |
| 5976 | return -EINVAL; |
| 5977 | } |
| 5978 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5979 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
| 5980 | if (ret) { |
| 5981 | DRM_ERROR("framebuffer init failed %d\n", ret); |
| 5982 | return ret; |
| 5983 | } |
| 5984 | |
| 5985 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5986 | intel_fb->obj = obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5987 | return 0; |
| 5988 | } |
| 5989 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5990 | static struct drm_framebuffer * |
| 5991 | intel_user_framebuffer_create(struct drm_device *dev, |
| 5992 | struct drm_file *filp, |
| 5993 | struct drm_mode_fb_cmd *mode_cmd) |
| 5994 | { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5995 | struct drm_i915_gem_object *obj; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 5996 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5997 | int ret; |
| 5998 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5999 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, mode_cmd->handle)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6000 | if (!obj) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 6001 | return ERR_PTR(-ENOENT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6002 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 6003 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
| 6004 | if (!intel_fb) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 6005 | return ERR_PTR(-ENOMEM); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 6006 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6007 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6008 | if (ret) { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6009 | drm_gem_object_unreference_unlocked(&obj->base); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 6010 | kfree(intel_fb); |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 6011 | return ERR_PTR(ret); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6012 | } |
| 6013 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 6014 | return &intel_fb->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6015 | } |
| 6016 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6017 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6018 | .fb_create = intel_user_framebuffer_create, |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 6019 | .output_poll_changed = intel_fb_output_poll_changed, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6020 | }; |
| 6021 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6022 | static struct drm_i915_gem_object * |
Zou Nan hai | aa40d6b | 2010-06-25 13:40:23 +0800 | [diff] [blame] | 6023 | intel_alloc_context_page(struct drm_device *dev) |
Chris Wilson | 9ea8d05 | 2010-01-04 18:57:56 +0000 | [diff] [blame] | 6024 | { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6025 | struct drm_i915_gem_object *ctx; |
Chris Wilson | 9ea8d05 | 2010-01-04 18:57:56 +0000 | [diff] [blame] | 6026 | int ret; |
| 6027 | |
Zou Nan hai | aa40d6b | 2010-06-25 13:40:23 +0800 | [diff] [blame] | 6028 | ctx = i915_gem_alloc_object(dev, 4096); |
| 6029 | if (!ctx) { |
Chris Wilson | 9ea8d05 | 2010-01-04 18:57:56 +0000 | [diff] [blame] | 6030 | DRM_DEBUG("failed to alloc power context, RC6 disabled\n"); |
| 6031 | return NULL; |
| 6032 | } |
| 6033 | |
| 6034 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | 75e9e91 | 2010-11-04 17:11:09 +0100 | [diff] [blame] | 6035 | ret = i915_gem_object_pin(ctx, 4096, true); |
Chris Wilson | 9ea8d05 | 2010-01-04 18:57:56 +0000 | [diff] [blame] | 6036 | if (ret) { |
| 6037 | DRM_ERROR("failed to pin power context: %d\n", ret); |
| 6038 | goto err_unref; |
| 6039 | } |
| 6040 | |
Zou Nan hai | aa40d6b | 2010-06-25 13:40:23 +0800 | [diff] [blame] | 6041 | ret = i915_gem_object_set_to_gtt_domain(ctx, 1); |
Chris Wilson | 9ea8d05 | 2010-01-04 18:57:56 +0000 | [diff] [blame] | 6042 | if (ret) { |
| 6043 | DRM_ERROR("failed to set-domain on power context: %d\n", ret); |
| 6044 | goto err_unpin; |
| 6045 | } |
| 6046 | mutex_unlock(&dev->struct_mutex); |
| 6047 | |
Zou Nan hai | aa40d6b | 2010-06-25 13:40:23 +0800 | [diff] [blame] | 6048 | return ctx; |
Chris Wilson | 9ea8d05 | 2010-01-04 18:57:56 +0000 | [diff] [blame] | 6049 | |
| 6050 | err_unpin: |
Zou Nan hai | aa40d6b | 2010-06-25 13:40:23 +0800 | [diff] [blame] | 6051 | i915_gem_object_unpin(ctx); |
Chris Wilson | 9ea8d05 | 2010-01-04 18:57:56 +0000 | [diff] [blame] | 6052 | err_unref: |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6053 | drm_gem_object_unreference(&ctx->base); |
Chris Wilson | 9ea8d05 | 2010-01-04 18:57:56 +0000 | [diff] [blame] | 6054 | mutex_unlock(&dev->struct_mutex); |
| 6055 | return NULL; |
| 6056 | } |
| 6057 | |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 6058 | bool ironlake_set_drps(struct drm_device *dev, u8 val) |
| 6059 | { |
| 6060 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6061 | u16 rgvswctl; |
| 6062 | |
| 6063 | rgvswctl = I915_READ16(MEMSWCTL); |
| 6064 | if (rgvswctl & MEMCTL_CMD_STS) { |
| 6065 | DRM_DEBUG("gpu busy, RCS change rejected\n"); |
| 6066 | return false; /* still busy with another command */ |
| 6067 | } |
| 6068 | |
| 6069 | rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | |
| 6070 | (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; |
| 6071 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 6072 | POSTING_READ16(MEMSWCTL); |
| 6073 | |
| 6074 | rgvswctl |= MEMCTL_CMD_STS; |
| 6075 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 6076 | |
| 6077 | return true; |
| 6078 | } |
| 6079 | |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 6080 | void ironlake_enable_drps(struct drm_device *dev) |
| 6081 | { |
| 6082 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 6083 | u32 rgvmodectl = I915_READ(MEMMODECTL); |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 6084 | u8 fmax, fmin, fstart, vstart; |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 6085 | |
Jesse Barnes | ea056c1 | 2010-09-10 10:02:13 -0700 | [diff] [blame] | 6086 | /* Enable temp reporting */ |
| 6087 | I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN); |
| 6088 | I915_WRITE16(TSC1, I915_READ(TSC1) | TSE); |
| 6089 | |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 6090 | /* 100ms RC evaluation intervals */ |
| 6091 | I915_WRITE(RCUPEI, 100000); |
| 6092 | I915_WRITE(RCDNEI, 100000); |
| 6093 | |
| 6094 | /* Set max/min thresholds to 90ms and 80ms respectively */ |
| 6095 | I915_WRITE(RCBMAXAVG, 90000); |
| 6096 | I915_WRITE(RCBMINAVG, 80000); |
| 6097 | |
| 6098 | I915_WRITE(MEMIHYST, 1); |
| 6099 | |
| 6100 | /* Set up min, max, and cur for interrupt handling */ |
| 6101 | fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; |
| 6102 | fmin = (rgvmodectl & MEMMODE_FMIN_MASK); |
| 6103 | fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> |
| 6104 | MEMMODE_FSTART_SHIFT; |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 6105 | |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 6106 | vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >> |
| 6107 | PXVFREQ_PX_SHIFT; |
| 6108 | |
Jesse Barnes | 80dbf4b | 2010-11-01 14:12:01 -0700 | [diff] [blame] | 6109 | dev_priv->fmax = fmax; /* IPS callback will increase this */ |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 6110 | dev_priv->fstart = fstart; |
| 6111 | |
Jesse Barnes | 80dbf4b | 2010-11-01 14:12:01 -0700 | [diff] [blame] | 6112 | dev_priv->max_delay = fstart; |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 6113 | dev_priv->min_delay = fmin; |
| 6114 | dev_priv->cur_delay = fstart; |
| 6115 | |
Jesse Barnes | 80dbf4b | 2010-11-01 14:12:01 -0700 | [diff] [blame] | 6116 | DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", |
| 6117 | fmax, fmin, fstart); |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 6118 | |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 6119 | I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); |
| 6120 | |
| 6121 | /* |
| 6122 | * Interrupts will be enabled in ironlake_irq_postinstall |
| 6123 | */ |
| 6124 | |
| 6125 | I915_WRITE(VIDSTART, vstart); |
| 6126 | POSTING_READ(VIDSTART); |
| 6127 | |
| 6128 | rgvmodectl |= MEMMODE_SWMODE_EN; |
| 6129 | I915_WRITE(MEMMODECTL, rgvmodectl); |
| 6130 | |
Chris Wilson | 481b6af | 2010-08-23 17:43:35 +0100 | [diff] [blame] | 6131 | if (wait_for((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10)) |
Chris Wilson | 913d8d1 | 2010-08-07 11:01:35 +0100 | [diff] [blame] | 6132 | DRM_ERROR("stuck trying to change perf mode\n"); |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 6133 | msleep(1); |
| 6134 | |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 6135 | ironlake_set_drps(dev, fstart); |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 6136 | |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 6137 | dev_priv->last_count1 = I915_READ(0x112e4) + I915_READ(0x112e8) + |
| 6138 | I915_READ(0x112e0); |
| 6139 | dev_priv->last_time1 = jiffies_to_msecs(jiffies); |
| 6140 | dev_priv->last_count2 = I915_READ(0x112f4); |
| 6141 | getrawmonotonic(&dev_priv->last_time2); |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 6142 | } |
| 6143 | |
| 6144 | void ironlake_disable_drps(struct drm_device *dev) |
| 6145 | { |
| 6146 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 6147 | u16 rgvswctl = I915_READ16(MEMSWCTL); |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 6148 | |
| 6149 | /* Ack interrupts, disable EFC interrupt */ |
| 6150 | I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN); |
| 6151 | I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG); |
| 6152 | I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT); |
| 6153 | I915_WRITE(DEIIR, DE_PCU_EVENT); |
| 6154 | I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT); |
| 6155 | |
| 6156 | /* Go back to the starting frequency */ |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 6157 | ironlake_set_drps(dev, dev_priv->fstart); |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 6158 | msleep(1); |
| 6159 | rgvswctl |= MEMCTL_CMD_STS; |
| 6160 | I915_WRITE(MEMSWCTL, rgvswctl); |
| 6161 | msleep(1); |
| 6162 | |
| 6163 | } |
| 6164 | |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 6165 | void gen6_set_rps(struct drm_device *dev, u8 val) |
| 6166 | { |
| 6167 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6168 | u32 swreq; |
| 6169 | |
| 6170 | swreq = (val & 0x3ff) << 25; |
| 6171 | I915_WRITE(GEN6_RPNSWREQ, swreq); |
| 6172 | } |
| 6173 | |
| 6174 | void gen6_disable_rps(struct drm_device *dev) |
| 6175 | { |
| 6176 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6177 | |
| 6178 | I915_WRITE(GEN6_RPNSWREQ, 1 << 31); |
| 6179 | I915_WRITE(GEN6_PMINTRMSK, 0xffffffff); |
| 6180 | I915_WRITE(GEN6_PMIER, 0); |
| 6181 | I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR)); |
| 6182 | } |
| 6183 | |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 6184 | static unsigned long intel_pxfreq(u32 vidfreq) |
| 6185 | { |
| 6186 | unsigned long freq; |
| 6187 | int div = (vidfreq & 0x3f0000) >> 16; |
| 6188 | int post = (vidfreq & 0x3000) >> 12; |
| 6189 | int pre = (vidfreq & 0x7); |
| 6190 | |
| 6191 | if (!pre) |
| 6192 | return 0; |
| 6193 | |
| 6194 | freq = ((div * 133333) / ((1<<post) * pre)); |
| 6195 | |
| 6196 | return freq; |
| 6197 | } |
| 6198 | |
| 6199 | void intel_init_emon(struct drm_device *dev) |
| 6200 | { |
| 6201 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6202 | u32 lcfuse; |
| 6203 | u8 pxw[16]; |
| 6204 | int i; |
| 6205 | |
| 6206 | /* Disable to program */ |
| 6207 | I915_WRITE(ECR, 0); |
| 6208 | POSTING_READ(ECR); |
| 6209 | |
| 6210 | /* Program energy weights for various events */ |
| 6211 | I915_WRITE(SDEW, 0x15040d00); |
| 6212 | I915_WRITE(CSIEW0, 0x007f0000); |
| 6213 | I915_WRITE(CSIEW1, 0x1e220004); |
| 6214 | I915_WRITE(CSIEW2, 0x04000004); |
| 6215 | |
| 6216 | for (i = 0; i < 5; i++) |
| 6217 | I915_WRITE(PEW + (i * 4), 0); |
| 6218 | for (i = 0; i < 3; i++) |
| 6219 | I915_WRITE(DEW + (i * 4), 0); |
| 6220 | |
| 6221 | /* Program P-state weights to account for frequency power adjustment */ |
| 6222 | for (i = 0; i < 16; i++) { |
| 6223 | u32 pxvidfreq = I915_READ(PXVFREQ_BASE + (i * 4)); |
| 6224 | unsigned long freq = intel_pxfreq(pxvidfreq); |
| 6225 | unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >> |
| 6226 | PXVFREQ_PX_SHIFT; |
| 6227 | unsigned long val; |
| 6228 | |
| 6229 | val = vid * vid; |
| 6230 | val *= (freq / 1000); |
| 6231 | val *= 255; |
| 6232 | val /= (127*127*900); |
| 6233 | if (val > 0xff) |
| 6234 | DRM_ERROR("bad pxval: %ld\n", val); |
| 6235 | pxw[i] = val; |
| 6236 | } |
| 6237 | /* Render standby states get 0 weight */ |
| 6238 | pxw[14] = 0; |
| 6239 | pxw[15] = 0; |
| 6240 | |
| 6241 | for (i = 0; i < 4; i++) { |
| 6242 | u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) | |
| 6243 | (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]); |
| 6244 | I915_WRITE(PXW + (i * 4), val); |
| 6245 | } |
| 6246 | |
| 6247 | /* Adjust magic regs to magic values (more experimental results) */ |
| 6248 | I915_WRITE(OGW0, 0); |
| 6249 | I915_WRITE(OGW1, 0); |
| 6250 | I915_WRITE(EG0, 0x00007f00); |
| 6251 | I915_WRITE(EG1, 0x0000000e); |
| 6252 | I915_WRITE(EG2, 0x000e0000); |
| 6253 | I915_WRITE(EG3, 0x68000300); |
| 6254 | I915_WRITE(EG4, 0x42000000); |
| 6255 | I915_WRITE(EG5, 0x00140031); |
| 6256 | I915_WRITE(EG6, 0); |
| 6257 | I915_WRITE(EG7, 0); |
| 6258 | |
| 6259 | for (i = 0; i < 8; i++) |
| 6260 | I915_WRITE(PXWL + (i * 4), 0); |
| 6261 | |
| 6262 | /* Enable PMON + select events */ |
| 6263 | I915_WRITE(ECR, 0x80000019); |
| 6264 | |
| 6265 | lcfuse = I915_READ(LCFUSE02); |
| 6266 | |
| 6267 | dev_priv->corr = (lcfuse & LCFUSE_HIV_MASK); |
| 6268 | } |
| 6269 | |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 6270 | void gen6_enable_rps(struct drm_i915_private *dev_priv) |
Chris Wilson | 8fd2685 | 2010-12-08 18:40:43 +0000 | [diff] [blame] | 6271 | { |
Jesse Barnes | a6044e2 | 2010-12-20 11:34:20 -0800 | [diff] [blame] | 6272 | u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
| 6273 | u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS); |
| 6274 | u32 pcu_mbox; |
| 6275 | int cur_freq, min_freq, max_freq; |
Chris Wilson | 8fd2685 | 2010-12-08 18:40:43 +0000 | [diff] [blame] | 6276 | int i; |
| 6277 | |
| 6278 | /* Here begins a magic sequence of register writes to enable |
| 6279 | * auto-downclocking. |
| 6280 | * |
| 6281 | * Perhaps there might be some value in exposing these to |
| 6282 | * userspace... |
| 6283 | */ |
| 6284 | I915_WRITE(GEN6_RC_STATE, 0); |
Chris Wilson | 9135583 | 2011-03-04 19:22:40 +0000 | [diff] [blame^] | 6285 | __gen6_gt_force_wake_get(dev_priv); |
Chris Wilson | 8fd2685 | 2010-12-08 18:40:43 +0000 | [diff] [blame] | 6286 | |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 6287 | /* disable the counters and set deterministic thresholds */ |
Chris Wilson | 8fd2685 | 2010-12-08 18:40:43 +0000 | [diff] [blame] | 6288 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 6289 | |
| 6290 | I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16); |
| 6291 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30); |
| 6292 | I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30); |
| 6293 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 6294 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 6295 | |
| 6296 | for (i = 0; i < I915_NUM_RINGS; i++) |
| 6297 | I915_WRITE(RING_MAX_IDLE(dev_priv->ring[i].mmio_base), 10); |
| 6298 | |
| 6299 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 6300 | I915_WRITE(GEN6_RC1e_THRESHOLD, 1000); |
| 6301 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); |
| 6302 | I915_WRITE(GEN6_RC6p_THRESHOLD, 100000); |
| 6303 | I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */ |
| 6304 | |
| 6305 | I915_WRITE(GEN6_RC_CONTROL, |
| 6306 | GEN6_RC_CTL_RC6p_ENABLE | |
| 6307 | GEN6_RC_CTL_RC6_ENABLE | |
Chris Wilson | 9c3d2f7 | 2010-12-17 10:54:26 +0000 | [diff] [blame] | 6308 | GEN6_RC_CTL_EI_MODE(1) | |
Chris Wilson | 8fd2685 | 2010-12-08 18:40:43 +0000 | [diff] [blame] | 6309 | GEN6_RC_CTL_HW_ENABLE); |
| 6310 | |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 6311 | I915_WRITE(GEN6_RPNSWREQ, |
Chris Wilson | 8fd2685 | 2010-12-08 18:40:43 +0000 | [diff] [blame] | 6312 | GEN6_FREQUENCY(10) | |
| 6313 | GEN6_OFFSET(0) | |
| 6314 | GEN6_AGGRESSIVE_TURBO); |
| 6315 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 6316 | GEN6_FREQUENCY(12)); |
| 6317 | |
| 6318 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
| 6319 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
| 6320 | 18 << 24 | |
| 6321 | 6 << 16); |
| 6322 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 90000); |
| 6323 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 100000); |
| 6324 | I915_WRITE(GEN6_RP_UP_EI, 100000); |
| 6325 | I915_WRITE(GEN6_RP_DOWN_EI, 300000); |
| 6326 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 6327 | I915_WRITE(GEN6_RP_CONTROL, |
| 6328 | GEN6_RP_MEDIA_TURBO | |
| 6329 | GEN6_RP_USE_NORMAL_FREQ | |
| 6330 | GEN6_RP_MEDIA_IS_GFX | |
| 6331 | GEN6_RP_ENABLE | |
| 6332 | GEN6_RP_UP_BUSY_MAX | |
| 6333 | GEN6_RP_DOWN_BUSY_MIN); |
| 6334 | |
| 6335 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 6336 | 500)) |
| 6337 | DRM_ERROR("timeout waiting for pcode mailbox to become idle\n"); |
| 6338 | |
| 6339 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 6340 | I915_WRITE(GEN6_PCODE_MAILBOX, |
| 6341 | GEN6_PCODE_READY | |
| 6342 | GEN6_PCODE_WRITE_MIN_FREQ_TABLE); |
| 6343 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 6344 | 500)) |
| 6345 | DRM_ERROR("timeout waiting for pcode mailbox to finish\n"); |
| 6346 | |
Jesse Barnes | a6044e2 | 2010-12-20 11:34:20 -0800 | [diff] [blame] | 6347 | min_freq = (rp_state_cap & 0xff0000) >> 16; |
| 6348 | max_freq = rp_state_cap & 0xff; |
| 6349 | cur_freq = (gt_perf_status & 0xff00) >> 8; |
| 6350 | |
| 6351 | /* Check for overclock support */ |
| 6352 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 6353 | 500)) |
| 6354 | DRM_ERROR("timeout waiting for pcode mailbox to become idle\n"); |
| 6355 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_READ_OC_PARAMS); |
| 6356 | pcu_mbox = I915_READ(GEN6_PCODE_DATA); |
| 6357 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 6358 | 500)) |
| 6359 | DRM_ERROR("timeout waiting for pcode mailbox to finish\n"); |
| 6360 | if (pcu_mbox & (1<<31)) { /* OC supported */ |
| 6361 | max_freq = pcu_mbox & 0xff; |
| 6362 | DRM_DEBUG_DRIVER("overclocking supported, adjusting frequency max to %dMHz\n", pcu_mbox * 100); |
| 6363 | } |
| 6364 | |
| 6365 | /* In units of 100MHz */ |
| 6366 | dev_priv->max_delay = max_freq; |
| 6367 | dev_priv->min_delay = min_freq; |
| 6368 | dev_priv->cur_delay = cur_freq; |
| 6369 | |
Chris Wilson | 8fd2685 | 2010-12-08 18:40:43 +0000 | [diff] [blame] | 6370 | /* requires MSI enabled */ |
| 6371 | I915_WRITE(GEN6_PMIER, |
| 6372 | GEN6_PM_MBOX_EVENT | |
| 6373 | GEN6_PM_THERMAL_EVENT | |
| 6374 | GEN6_PM_RP_DOWN_TIMEOUT | |
| 6375 | GEN6_PM_RP_UP_THRESHOLD | |
| 6376 | GEN6_PM_RP_DOWN_THRESHOLD | |
| 6377 | GEN6_PM_RP_UP_EI_EXPIRED | |
| 6378 | GEN6_PM_RP_DOWN_EI_EXPIRED); |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 6379 | I915_WRITE(GEN6_PMIMR, 0); |
| 6380 | /* enable all PM interrupts */ |
| 6381 | I915_WRITE(GEN6_PMINTRMSK, 0); |
Chris Wilson | 8fd2685 | 2010-12-08 18:40:43 +0000 | [diff] [blame] | 6382 | |
Chris Wilson | 9135583 | 2011-03-04 19:22:40 +0000 | [diff] [blame^] | 6383 | __gen6_gt_force_wake_put(dev_priv); |
Chris Wilson | 8fd2685 | 2010-12-08 18:40:43 +0000 | [diff] [blame] | 6384 | } |
| 6385 | |
Chris Wilson | 0cdab21 | 2010-12-05 17:27:06 +0000 | [diff] [blame] | 6386 | void intel_enable_clock_gating(struct drm_device *dev) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6387 | { |
| 6388 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6389 | |
| 6390 | /* |
| 6391 | * Disable clock gating reported to work incorrectly according to the |
| 6392 | * specs, but enable as much else as we can. |
| 6393 | */ |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 6394 | if (HAS_PCH_SPLIT(dev)) { |
Eric Anholt | 8956c8b | 2010-03-18 13:21:14 -0700 | [diff] [blame] | 6395 | uint32_t dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE; |
| 6396 | |
Chris Wilson | f00a3dd | 2010-10-21 14:57:17 +0100 | [diff] [blame] | 6397 | if (IS_GEN5(dev)) { |
Eric Anholt | 8956c8b | 2010-03-18 13:21:14 -0700 | [diff] [blame] | 6398 | /* Required for FBC */ |
Jesse Barnes | 1ffa325 | 2011-01-17 13:35:57 -0800 | [diff] [blame] | 6399 | dspclk_gate |= DPFCUNIT_CLOCK_GATE_DISABLE | |
| 6400 | DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 6401 | DPFDUNIT_CLOCK_GATE_DISABLE; |
Eric Anholt | 8956c8b | 2010-03-18 13:21:14 -0700 | [diff] [blame] | 6402 | /* Required for CxSR */ |
| 6403 | dspclk_gate |= DPARBUNIT_CLOCK_GATE_DISABLE; |
| 6404 | |
| 6405 | I915_WRITE(PCH_3DCGDIS0, |
| 6406 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 6407 | SVSMUNIT_CLOCK_GATE_DISABLE); |
Eric Anholt | 06f3775 | 2010-12-14 10:06:46 -0800 | [diff] [blame] | 6408 | I915_WRITE(PCH_3DCGDIS1, |
| 6409 | VFMUNIT_CLOCK_GATE_DISABLE); |
Eric Anholt | 8956c8b | 2010-03-18 13:21:14 -0700 | [diff] [blame] | 6410 | } |
| 6411 | |
| 6412 | I915_WRITE(PCH_DSPCLK_GATE_D, dspclk_gate); |
Zhenyu Wang | 7f8a856 | 2010-04-01 13:07:53 +0800 | [diff] [blame] | 6413 | |
| 6414 | /* |
Jesse Barnes | 382b093 | 2010-10-07 16:01:25 -0700 | [diff] [blame] | 6415 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 6416 | * gating for the panel power sequencer or it will fail to |
| 6417 | * start up when no ports are active. |
| 6418 | */ |
| 6419 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 6420 | |
| 6421 | /* |
Zhenyu Wang | 7f8a856 | 2010-04-01 13:07:53 +0800 | [diff] [blame] | 6422 | * According to the spec the following bits should be set in |
| 6423 | * order to enable memory self-refresh |
| 6424 | * The bit 22/21 of 0x42004 |
| 6425 | * The bit 5 of 0x42020 |
| 6426 | * The bit 15 of 0x45000 |
| 6427 | */ |
Chris Wilson | f00a3dd | 2010-10-21 14:57:17 +0100 | [diff] [blame] | 6428 | if (IS_GEN5(dev)) { |
Zhenyu Wang | 7f8a856 | 2010-04-01 13:07:53 +0800 | [diff] [blame] | 6429 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6430 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6431 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
| 6432 | I915_WRITE(ILK_DSPCLK_GATE, |
| 6433 | (I915_READ(ILK_DSPCLK_GATE) | |
| 6434 | ILK_DPARB_CLK_GATE)); |
| 6435 | I915_WRITE(DISP_ARB_CTL, |
| 6436 | (I915_READ(DISP_ARB_CTL) | |
| 6437 | DISP_FBC_WM_DIS)); |
Yuanhan Liu | 1398261 | 2010-12-15 15:42:31 +0800 | [diff] [blame] | 6438 | I915_WRITE(WM3_LP_ILK, 0); |
| 6439 | I915_WRITE(WM2_LP_ILK, 0); |
| 6440 | I915_WRITE(WM1_LP_ILK, 0); |
Zhenyu Wang | 7f8a856 | 2010-04-01 13:07:53 +0800 | [diff] [blame] | 6441 | } |
Zhao Yakui | b52eb4d | 2010-06-12 14:32:27 +0800 | [diff] [blame] | 6442 | /* |
| 6443 | * Based on the document from hardware guys the following bits |
| 6444 | * should be set unconditionally in order to enable FBC. |
| 6445 | * The bit 22 of 0x42000 |
| 6446 | * The bit 22 of 0x42004 |
| 6447 | * The bit 7,8,9 of 0x42020. |
| 6448 | */ |
| 6449 | if (IS_IRONLAKE_M(dev)) { |
| 6450 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 6451 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 6452 | ILK_FBCQ_DIS); |
| 6453 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6454 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6455 | ILK_DPARB_GATE); |
| 6456 | I915_WRITE(ILK_DSPCLK_GATE, |
| 6457 | I915_READ(ILK_DSPCLK_GATE) | |
| 6458 | ILK_DPFC_DIS1 | |
| 6459 | ILK_DPFC_DIS2 | |
| 6460 | ILK_CLK_FBC); |
| 6461 | } |
Eric Anholt | de6e2ea | 2010-11-06 14:53:32 -0700 | [diff] [blame] | 6462 | |
Eric Anholt | 67e92af | 2010-11-06 14:53:33 -0700 | [diff] [blame] | 6463 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6464 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6465 | ILK_ELPIN_409_SELECT); |
| 6466 | |
Eric Anholt | de6e2ea | 2010-11-06 14:53:32 -0700 | [diff] [blame] | 6467 | if (IS_GEN5(dev)) { |
| 6468 | I915_WRITE(_3D_CHICKEN2, |
| 6469 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 6470 | _3D_CHICKEN2_WM_READ_PIPELINED); |
| 6471 | } |
Chris Wilson | 8fd2685 | 2010-12-08 18:40:43 +0000 | [diff] [blame] | 6472 | |
Yuanhan Liu | 1398261 | 2010-12-15 15:42:31 +0800 | [diff] [blame] | 6473 | if (IS_GEN6(dev)) { |
| 6474 | I915_WRITE(WM3_LP_ILK, 0); |
| 6475 | I915_WRITE(WM2_LP_ILK, 0); |
| 6476 | I915_WRITE(WM1_LP_ILK, 0); |
| 6477 | |
| 6478 | /* |
| 6479 | * According to the spec the following bits should be |
| 6480 | * set in order to enable memory self-refresh and fbc: |
| 6481 | * The bit21 and bit22 of 0x42000 |
| 6482 | * The bit21 and bit22 of 0x42004 |
| 6483 | * The bit5 and bit7 of 0x42020 |
| 6484 | * The bit14 of 0x70180 |
| 6485 | * The bit14 of 0x71180 |
| 6486 | */ |
| 6487 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 6488 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 6489 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 6490 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6491 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6492 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
| 6493 | I915_WRITE(ILK_DSPCLK_GATE, |
| 6494 | I915_READ(ILK_DSPCLK_GATE) | |
| 6495 | ILK_DPARB_CLK_GATE | |
| 6496 | ILK_DPFD_CLK_GATE); |
| 6497 | |
| 6498 | I915_WRITE(DSPACNTR, |
| 6499 | I915_READ(DSPACNTR) | |
| 6500 | DISPPLANE_TRICKLE_FEED_DISABLE); |
| 6501 | I915_WRITE(DSPBCNTR, |
| 6502 | I915_READ(DSPBCNTR) | |
| 6503 | DISPPLANE_TRICKLE_FEED_DISABLE); |
| 6504 | } |
Zhenyu Wang | c03342f | 2009-09-29 11:01:23 +0800 | [diff] [blame] | 6505 | } else if (IS_G4X(dev)) { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6506 | uint32_t dspclk_gate; |
| 6507 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 6508 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 6509 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 6510 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 6511 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 6512 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 6513 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 6514 | OVCUNIT_CLOCK_GATE_DISABLE; |
| 6515 | if (IS_GM45(dev)) |
| 6516 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 6517 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 6518 | } else if (IS_CRESTLINE(dev)) { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6519 | I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 6520 | I915_WRITE(RENCLK_GATE_D2, 0); |
| 6521 | I915_WRITE(DSPCLK_GATE_D, 0); |
| 6522 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 6523 | I915_WRITE16(DEUC, 0); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 6524 | } else if (IS_BROADWATER(dev)) { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6525 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 6526 | I965_RCC_CLOCK_GATE_DISABLE | |
| 6527 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 6528 | I965_ISC_CLOCK_GATE_DISABLE | |
| 6529 | I965_FBC_CLOCK_GATE_DISABLE); |
| 6530 | I915_WRITE(RENCLK_GATE_D2, 0); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 6531 | } else if (IS_GEN3(dev)) { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6532 | u32 dstate = I915_READ(D_STATE); |
| 6533 | |
| 6534 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 6535 | DSTATE_DOT_CLOCK_GATING; |
| 6536 | I915_WRITE(D_STATE, dstate); |
Daniel Vetter | f0f8a9c | 2009-09-15 22:57:33 +0200 | [diff] [blame] | 6537 | } else if (IS_I85X(dev) || IS_I865G(dev)) { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6538 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
| 6539 | } else if (IS_I830(dev)) { |
| 6540 | I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE); |
| 6541 | } |
| 6542 | } |
| 6543 | |
Chris Wilson | ac66808 | 2011-02-09 16:15:32 +0000 | [diff] [blame] | 6544 | static void ironlake_teardown_rc6(struct drm_device *dev) |
Chris Wilson | 0cdab21 | 2010-12-05 17:27:06 +0000 | [diff] [blame] | 6545 | { |
| 6546 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6547 | |
| 6548 | if (dev_priv->renderctx) { |
Chris Wilson | ac66808 | 2011-02-09 16:15:32 +0000 | [diff] [blame] | 6549 | i915_gem_object_unpin(dev_priv->renderctx); |
| 6550 | drm_gem_object_unreference(&dev_priv->renderctx->base); |
Chris Wilson | 0cdab21 | 2010-12-05 17:27:06 +0000 | [diff] [blame] | 6551 | dev_priv->renderctx = NULL; |
| 6552 | } |
| 6553 | |
| 6554 | if (dev_priv->pwrctx) { |
Chris Wilson | ac66808 | 2011-02-09 16:15:32 +0000 | [diff] [blame] | 6555 | i915_gem_object_unpin(dev_priv->pwrctx); |
| 6556 | drm_gem_object_unreference(&dev_priv->pwrctx->base); |
Chris Wilson | 0cdab21 | 2010-12-05 17:27:06 +0000 | [diff] [blame] | 6557 | dev_priv->pwrctx = NULL; |
| 6558 | } |
| 6559 | } |
| 6560 | |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 6561 | static void ironlake_disable_rc6(struct drm_device *dev) |
| 6562 | { |
| 6563 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6564 | |
Chris Wilson | ac66808 | 2011-02-09 16:15:32 +0000 | [diff] [blame] | 6565 | if (I915_READ(PWRCTXA)) { |
| 6566 | /* Wake the GPU, prevent RC6, then restore RSTDBYCTL */ |
| 6567 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) | RCX_SW_EXIT); |
| 6568 | wait_for(((I915_READ(RSTDBYCTL) & RSX_STATUS_MASK) == RSX_STATUS_ON), |
| 6569 | 50); |
| 6570 | |
| 6571 | I915_WRITE(PWRCTXA, 0); |
| 6572 | POSTING_READ(PWRCTXA); |
| 6573 | |
| 6574 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT); |
| 6575 | POSTING_READ(RSTDBYCTL); |
| 6576 | } |
| 6577 | |
Chris Wilson | 9950730 | 2011-02-24 09:42:52 +0000 | [diff] [blame] | 6578 | ironlake_teardown_rc6(dev); |
Chris Wilson | ac66808 | 2011-02-09 16:15:32 +0000 | [diff] [blame] | 6579 | } |
| 6580 | |
| 6581 | static int ironlake_setup_rc6(struct drm_device *dev) |
| 6582 | { |
| 6583 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6584 | |
| 6585 | if (dev_priv->renderctx == NULL) |
| 6586 | dev_priv->renderctx = intel_alloc_context_page(dev); |
| 6587 | if (!dev_priv->renderctx) |
| 6588 | return -ENOMEM; |
| 6589 | |
| 6590 | if (dev_priv->pwrctx == NULL) |
| 6591 | dev_priv->pwrctx = intel_alloc_context_page(dev); |
| 6592 | if (!dev_priv->pwrctx) { |
| 6593 | ironlake_teardown_rc6(dev); |
| 6594 | return -ENOMEM; |
| 6595 | } |
| 6596 | |
| 6597 | return 0; |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 6598 | } |
| 6599 | |
| 6600 | void ironlake_enable_rc6(struct drm_device *dev) |
| 6601 | { |
| 6602 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6603 | int ret; |
| 6604 | |
Chris Wilson | ac66808 | 2011-02-09 16:15:32 +0000 | [diff] [blame] | 6605 | /* rc6 disabled by default due to repeated reports of hanging during |
| 6606 | * boot and resume. |
| 6607 | */ |
| 6608 | if (!i915_enable_rc6) |
| 6609 | return; |
| 6610 | |
| 6611 | ret = ironlake_setup_rc6(dev); |
| 6612 | if (ret) |
| 6613 | return; |
| 6614 | |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 6615 | /* |
| 6616 | * GPU can automatically power down the render unit if given a page |
| 6617 | * to save state. |
| 6618 | */ |
| 6619 | ret = BEGIN_LP_RING(6); |
| 6620 | if (ret) { |
Chris Wilson | ac66808 | 2011-02-09 16:15:32 +0000 | [diff] [blame] | 6621 | ironlake_teardown_rc6(dev); |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 6622 | return; |
| 6623 | } |
Chris Wilson | ac66808 | 2011-02-09 16:15:32 +0000 | [diff] [blame] | 6624 | |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 6625 | OUT_RING(MI_SUSPEND_FLUSH | MI_SUSPEND_FLUSH_EN); |
| 6626 | OUT_RING(MI_SET_CONTEXT); |
| 6627 | OUT_RING(dev_priv->renderctx->gtt_offset | |
| 6628 | MI_MM_SPACE_GTT | |
| 6629 | MI_SAVE_EXT_STATE_EN | |
| 6630 | MI_RESTORE_EXT_STATE_EN | |
| 6631 | MI_RESTORE_INHIBIT); |
| 6632 | OUT_RING(MI_SUSPEND_FLUSH); |
| 6633 | OUT_RING(MI_NOOP); |
| 6634 | OUT_RING(MI_FLUSH); |
| 6635 | ADVANCE_LP_RING(); |
| 6636 | |
| 6637 | I915_WRITE(PWRCTXA, dev_priv->pwrctx->gtt_offset | PWRCTX_EN); |
| 6638 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT); |
| 6639 | } |
| 6640 | |
Chris Wilson | ac66808 | 2011-02-09 16:15:32 +0000 | [diff] [blame] | 6641 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6642 | /* Set up chip specific display functions */ |
| 6643 | static void intel_init_display(struct drm_device *dev) |
| 6644 | { |
| 6645 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6646 | |
| 6647 | /* We always want a DPMS function */ |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 6648 | if (HAS_PCH_SPLIT(dev)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 6649 | dev_priv->display.dpms = ironlake_crtc_dpms; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6650 | else |
| 6651 | dev_priv->display.dpms = i9xx_crtc_dpms; |
| 6652 | |
Adam Jackson | ee5382a | 2010-04-23 11:17:39 -0400 | [diff] [blame] | 6653 | if (I915_HAS_FBC(dev)) { |
Yuanhan Liu | 9c04f01 | 2010-12-15 15:42:32 +0800 | [diff] [blame] | 6654 | if (HAS_PCH_SPLIT(dev)) { |
Zhao Yakui | b52eb4d | 2010-06-12 14:32:27 +0800 | [diff] [blame] | 6655 | dev_priv->display.fbc_enabled = ironlake_fbc_enabled; |
| 6656 | dev_priv->display.enable_fbc = ironlake_enable_fbc; |
| 6657 | dev_priv->display.disable_fbc = ironlake_disable_fbc; |
| 6658 | } else if (IS_GM45(dev)) { |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 6659 | dev_priv->display.fbc_enabled = g4x_fbc_enabled; |
| 6660 | dev_priv->display.enable_fbc = g4x_enable_fbc; |
| 6661 | dev_priv->display.disable_fbc = g4x_disable_fbc; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 6662 | } else if (IS_CRESTLINE(dev)) { |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6663 | dev_priv->display.fbc_enabled = i8xx_fbc_enabled; |
| 6664 | dev_priv->display.enable_fbc = i8xx_enable_fbc; |
| 6665 | dev_priv->display.disable_fbc = i8xx_disable_fbc; |
| 6666 | } |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 6667 | /* 855GM needs testing */ |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6668 | } |
| 6669 | |
| 6670 | /* Returns the core display clock speed */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 6671 | if (IS_I945G(dev) || (IS_G33(dev) && ! IS_PINEVIEW_M(dev))) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6672 | dev_priv->display.get_display_clock_speed = |
| 6673 | i945_get_display_clock_speed; |
| 6674 | else if (IS_I915G(dev)) |
| 6675 | dev_priv->display.get_display_clock_speed = |
| 6676 | i915_get_display_clock_speed; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 6677 | else if (IS_I945GM(dev) || IS_845G(dev) || IS_PINEVIEW_M(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6678 | dev_priv->display.get_display_clock_speed = |
| 6679 | i9xx_misc_get_display_clock_speed; |
| 6680 | else if (IS_I915GM(dev)) |
| 6681 | dev_priv->display.get_display_clock_speed = |
| 6682 | i915gm_get_display_clock_speed; |
| 6683 | else if (IS_I865G(dev)) |
| 6684 | dev_priv->display.get_display_clock_speed = |
| 6685 | i865_get_display_clock_speed; |
Daniel Vetter | f0f8a9c | 2009-09-15 22:57:33 +0200 | [diff] [blame] | 6686 | else if (IS_I85X(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6687 | dev_priv->display.get_display_clock_speed = |
| 6688 | i855_get_display_clock_speed; |
| 6689 | else /* 852, 830 */ |
| 6690 | dev_priv->display.get_display_clock_speed = |
| 6691 | i830_get_display_clock_speed; |
| 6692 | |
| 6693 | /* For FIFO watermark updates */ |
Zhenyu Wang | 7f8a856 | 2010-04-01 13:07:53 +0800 | [diff] [blame] | 6694 | if (HAS_PCH_SPLIT(dev)) { |
Chris Wilson | f00a3dd | 2010-10-21 14:57:17 +0100 | [diff] [blame] | 6695 | if (IS_GEN5(dev)) { |
Zhenyu Wang | 7f8a856 | 2010-04-01 13:07:53 +0800 | [diff] [blame] | 6696 | if (I915_READ(MLTR_ILK) & ILK_SRLT_MASK) |
| 6697 | dev_priv->display.update_wm = ironlake_update_wm; |
| 6698 | else { |
| 6699 | DRM_DEBUG_KMS("Failed to get proper latency. " |
| 6700 | "Disable CxSR\n"); |
| 6701 | dev_priv->display.update_wm = NULL; |
| 6702 | } |
Yuanhan Liu | 1398261 | 2010-12-15 15:42:31 +0800 | [diff] [blame] | 6703 | } else if (IS_GEN6(dev)) { |
| 6704 | if (SNB_READ_WM0_LATENCY()) { |
| 6705 | dev_priv->display.update_wm = sandybridge_update_wm; |
| 6706 | } else { |
| 6707 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 6708 | "Disable CxSR\n"); |
| 6709 | dev_priv->display.update_wm = NULL; |
| 6710 | } |
Zhenyu Wang | 7f8a856 | 2010-04-01 13:07:53 +0800 | [diff] [blame] | 6711 | } else |
| 6712 | dev_priv->display.update_wm = NULL; |
| 6713 | } else if (IS_PINEVIEW(dev)) { |
Zhao Yakui | d429434 | 2010-03-22 22:45:36 +0800 | [diff] [blame] | 6714 | if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev), |
Li Peng | 9553426 | 2010-05-18 18:58:44 +0800 | [diff] [blame] | 6715 | dev_priv->is_ddr3, |
Zhao Yakui | d429434 | 2010-03-22 22:45:36 +0800 | [diff] [blame] | 6716 | dev_priv->fsb_freq, |
| 6717 | dev_priv->mem_freq)) { |
| 6718 | DRM_INFO("failed to find known CxSR latency " |
Li Peng | 9553426 | 2010-05-18 18:58:44 +0800 | [diff] [blame] | 6719 | "(found ddr%s fsb freq %d, mem freq %d), " |
Zhao Yakui | d429434 | 2010-03-22 22:45:36 +0800 | [diff] [blame] | 6720 | "disabling CxSR\n", |
Li Peng | 9553426 | 2010-05-18 18:58:44 +0800 | [diff] [blame] | 6721 | (dev_priv->is_ddr3 == 1) ? "3": "2", |
Zhao Yakui | d429434 | 2010-03-22 22:45:36 +0800 | [diff] [blame] | 6722 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 6723 | /* Disable CxSR and never update its watermark again */ |
| 6724 | pineview_disable_cxsr(dev); |
| 6725 | dev_priv->display.update_wm = NULL; |
| 6726 | } else |
| 6727 | dev_priv->display.update_wm = pineview_update_wm; |
| 6728 | } else if (IS_G4X(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6729 | dev_priv->display.update_wm = g4x_update_wm; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 6730 | else if (IS_GEN4(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6731 | dev_priv->display.update_wm = i965_update_wm; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 6732 | else if (IS_GEN3(dev)) { |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6733 | dev_priv->display.update_wm = i9xx_update_wm; |
| 6734 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
Adam Jackson | 8f4695e | 2010-04-16 18:20:57 -0400 | [diff] [blame] | 6735 | } else if (IS_I85X(dev)) { |
| 6736 | dev_priv->display.update_wm = i9xx_update_wm; |
| 6737 | dev_priv->display.get_fifo_size = i85x_get_fifo_size; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6738 | } else { |
Adam Jackson | 8f4695e | 2010-04-16 18:20:57 -0400 | [diff] [blame] | 6739 | dev_priv->display.update_wm = i830_update_wm; |
| 6740 | if (IS_845G(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6741 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
| 6742 | else |
| 6743 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6744 | } |
| 6745 | } |
| 6746 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 6747 | /* |
| 6748 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, |
| 6749 | * resume, or other times. This quirk makes sure that's the case for |
| 6750 | * affected systems. |
| 6751 | */ |
| 6752 | static void quirk_pipea_force (struct drm_device *dev) |
| 6753 | { |
| 6754 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6755 | |
| 6756 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; |
| 6757 | DRM_DEBUG_DRIVER("applying pipe a force quirk\n"); |
| 6758 | } |
| 6759 | |
| 6760 | struct intel_quirk { |
| 6761 | int device; |
| 6762 | int subsystem_vendor; |
| 6763 | int subsystem_device; |
| 6764 | void (*hook)(struct drm_device *dev); |
| 6765 | }; |
| 6766 | |
| 6767 | struct intel_quirk intel_quirks[] = { |
| 6768 | /* HP Compaq 2730p needs pipe A force quirk (LP: #291555) */ |
| 6769 | { 0x2a42, 0x103c, 0x30eb, quirk_pipea_force }, |
| 6770 | /* HP Mini needs pipe A force quirk (LP: #322104) */ |
| 6771 | { 0x27ae,0x103c, 0x361a, quirk_pipea_force }, |
| 6772 | |
| 6773 | /* Thinkpad R31 needs pipe A force quirk */ |
| 6774 | { 0x3577, 0x1014, 0x0505, quirk_pipea_force }, |
| 6775 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
| 6776 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, |
| 6777 | |
| 6778 | /* ThinkPad X30 needs pipe A force quirk (LP: #304614) */ |
| 6779 | { 0x3577, 0x1014, 0x0513, quirk_pipea_force }, |
| 6780 | /* ThinkPad X40 needs pipe A force quirk */ |
| 6781 | |
| 6782 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
| 6783 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, |
| 6784 | |
| 6785 | /* 855 & before need to leave pipe A & dpll A up */ |
| 6786 | { 0x3582, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, |
| 6787 | { 0x2562, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, |
| 6788 | }; |
| 6789 | |
| 6790 | static void intel_init_quirks(struct drm_device *dev) |
| 6791 | { |
| 6792 | struct pci_dev *d = dev->pdev; |
| 6793 | int i; |
| 6794 | |
| 6795 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { |
| 6796 | struct intel_quirk *q = &intel_quirks[i]; |
| 6797 | |
| 6798 | if (d->device == q->device && |
| 6799 | (d->subsystem_vendor == q->subsystem_vendor || |
| 6800 | q->subsystem_vendor == PCI_ANY_ID) && |
| 6801 | (d->subsystem_device == q->subsystem_device || |
| 6802 | q->subsystem_device == PCI_ANY_ID)) |
| 6803 | q->hook(dev); |
| 6804 | } |
| 6805 | } |
| 6806 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 6807 | /* Disable the VGA plane that we never use */ |
| 6808 | static void i915_disable_vga(struct drm_device *dev) |
| 6809 | { |
| 6810 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6811 | u8 sr1; |
| 6812 | u32 vga_reg; |
| 6813 | |
| 6814 | if (HAS_PCH_SPLIT(dev)) |
| 6815 | vga_reg = CPU_VGACNTRL; |
| 6816 | else |
| 6817 | vga_reg = VGACNTRL; |
| 6818 | |
| 6819 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 6820 | outb(1, VGA_SR_INDEX); |
| 6821 | sr1 = inb(VGA_SR_DATA); |
| 6822 | outb(sr1 | 1<<5, VGA_SR_DATA); |
| 6823 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 6824 | udelay(300); |
| 6825 | |
| 6826 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
| 6827 | POSTING_READ(vga_reg); |
| 6828 | } |
| 6829 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6830 | void intel_modeset_init(struct drm_device *dev) |
| 6831 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6832 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6833 | int i; |
| 6834 | |
| 6835 | drm_mode_config_init(dev); |
| 6836 | |
| 6837 | dev->mode_config.min_width = 0; |
| 6838 | dev->mode_config.min_height = 0; |
| 6839 | |
| 6840 | dev->mode_config.funcs = (void *)&intel_mode_funcs; |
| 6841 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 6842 | intel_init_quirks(dev); |
| 6843 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6844 | intel_init_display(dev); |
| 6845 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 6846 | if (IS_GEN2(dev)) { |
| 6847 | dev->mode_config.max_width = 2048; |
| 6848 | dev->mode_config.max_height = 2048; |
| 6849 | } else if (IS_GEN3(dev)) { |
Keith Packard | 5e4d6fa | 2009-07-12 23:53:17 -0700 | [diff] [blame] | 6850 | dev->mode_config.max_width = 4096; |
| 6851 | dev->mode_config.max_height = 4096; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6852 | } else { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 6853 | dev->mode_config.max_width = 8192; |
| 6854 | dev->mode_config.max_height = 8192; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6855 | } |
Chris Wilson | 35c3047 | 2010-12-22 14:07:12 +0000 | [diff] [blame] | 6856 | dev->mode_config.fb_base = dev->agp->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6857 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 6858 | if (IS_MOBILE(dev) || !IS_GEN2(dev)) |
Dave Airlie | a3524f1 | 2010-06-06 18:59:41 +1000 | [diff] [blame] | 6859 | dev_priv->num_pipe = 2; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6860 | else |
Dave Airlie | a3524f1 | 2010-06-06 18:59:41 +1000 | [diff] [blame] | 6861 | dev_priv->num_pipe = 1; |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 6862 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
Dave Airlie | a3524f1 | 2010-06-06 18:59:41 +1000 | [diff] [blame] | 6863 | dev_priv->num_pipe, dev_priv->num_pipe > 1 ? "s" : ""); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6864 | |
Dave Airlie | a3524f1 | 2010-06-06 18:59:41 +1000 | [diff] [blame] | 6865 | for (i = 0; i < dev_priv->num_pipe; i++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6866 | intel_crtc_init(dev, i); |
| 6867 | } |
| 6868 | |
| 6869 | intel_setup_outputs(dev); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6870 | |
Chris Wilson | 0cdab21 | 2010-12-05 17:27:06 +0000 | [diff] [blame] | 6871 | intel_enable_clock_gating(dev); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6872 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 6873 | /* Just disable it once at startup */ |
| 6874 | i915_disable_vga(dev); |
| 6875 | |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 6876 | if (IS_IRONLAKE_M(dev)) { |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 6877 | ironlake_enable_drps(dev); |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 6878 | intel_init_emon(dev); |
| 6879 | } |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 6880 | |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 6881 | if (IS_GEN6(dev)) |
| 6882 | gen6_enable_rps(dev_priv); |
| 6883 | |
Chris Wilson | ac66808 | 2011-02-09 16:15:32 +0000 | [diff] [blame] | 6884 | if (IS_IRONLAKE_M(dev)) |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 6885 | ironlake_enable_rc6(dev); |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 6886 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6887 | INIT_WORK(&dev_priv->idle_work, intel_idle_update); |
| 6888 | setup_timer(&dev_priv->idle_timer, intel_gpu_idle_timer, |
| 6889 | (unsigned long)dev); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 6890 | |
| 6891 | intel_setup_overlay(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6892 | } |
| 6893 | |
| 6894 | void intel_modeset_cleanup(struct drm_device *dev) |
| 6895 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6896 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6897 | struct drm_crtc *crtc; |
| 6898 | struct intel_crtc *intel_crtc; |
| 6899 | |
Keith Packard | f87ea76 | 2010-10-03 19:36:26 -0700 | [diff] [blame] | 6900 | drm_kms_helper_poll_fini(dev); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6901 | mutex_lock(&dev->struct_mutex); |
| 6902 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 6903 | intel_unregister_dsm_handler(); |
| 6904 | |
| 6905 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6906 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 6907 | /* Skip inactive CRTCs */ |
| 6908 | if (!crtc->fb) |
| 6909 | continue; |
| 6910 | |
| 6911 | intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 3dec009 | 2010-08-20 21:40:52 +0200 | [diff] [blame] | 6912 | intel_increase_pllclock(crtc); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6913 | } |
| 6914 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6915 | if (dev_priv->display.disable_fbc) |
| 6916 | dev_priv->display.disable_fbc(dev); |
| 6917 | |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 6918 | if (IS_IRONLAKE_M(dev)) |
| 6919 | ironlake_disable_drps(dev); |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 6920 | if (IS_GEN6(dev)) |
| 6921 | gen6_disable_rps(dev); |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 6922 | |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 6923 | if (IS_IRONLAKE_M(dev)) |
| 6924 | ironlake_disable_rc6(dev); |
Chris Wilson | 0cdab21 | 2010-12-05 17:27:06 +0000 | [diff] [blame] | 6925 | |
Kristian Høgsberg | 69341a5 | 2009-11-11 12:19:17 -0500 | [diff] [blame] | 6926 | mutex_unlock(&dev->struct_mutex); |
| 6927 | |
Daniel Vetter | 6c0d9350 | 2010-08-20 18:26:46 +0200 | [diff] [blame] | 6928 | /* Disable the irq before mode object teardown, for the irq might |
| 6929 | * enqueue unpin/hotplug work. */ |
| 6930 | drm_irq_uninstall(dev); |
| 6931 | cancel_work_sync(&dev_priv->hotplug_work); |
| 6932 | |
Daniel Vetter | 3dec009 | 2010-08-20 21:40:52 +0200 | [diff] [blame] | 6933 | /* Shut off idle work before the crtcs get freed. */ |
| 6934 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 6935 | intel_crtc = to_intel_crtc(crtc); |
| 6936 | del_timer_sync(&intel_crtc->idle_timer); |
| 6937 | } |
| 6938 | del_timer_sync(&dev_priv->idle_timer); |
| 6939 | cancel_work_sync(&dev_priv->idle_work); |
| 6940 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6941 | drm_mode_config_cleanup(dev); |
| 6942 | } |
| 6943 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 6944 | /* |
Zhenyu Wang | f1c79df | 2010-03-30 14:39:29 +0800 | [diff] [blame] | 6945 | * Return which encoder is currently attached for connector. |
| 6946 | */ |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 6947 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6948 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 6949 | return &intel_attached_encoder(connector)->base; |
| 6950 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6951 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 6952 | void intel_connector_attach_encoder(struct intel_connector *connector, |
| 6953 | struct intel_encoder *encoder) |
| 6954 | { |
| 6955 | connector->encoder = encoder; |
| 6956 | drm_mode_connector_attach_encoder(&connector->base, |
| 6957 | &encoder->base); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6958 | } |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 6959 | |
| 6960 | /* |
| 6961 | * set vga decode state - true == enable VGA decode |
| 6962 | */ |
| 6963 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) |
| 6964 | { |
| 6965 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6966 | u16 gmch_ctrl; |
| 6967 | |
| 6968 | pci_read_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, &gmch_ctrl); |
| 6969 | if (state) |
| 6970 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; |
| 6971 | else |
| 6972 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; |
| 6973 | pci_write_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, gmch_ctrl); |
| 6974 | return 0; |
| 6975 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 6976 | |
| 6977 | #ifdef CONFIG_DEBUG_FS |
| 6978 | #include <linux/seq_file.h> |
| 6979 | |
| 6980 | struct intel_display_error_state { |
| 6981 | struct intel_cursor_error_state { |
| 6982 | u32 control; |
| 6983 | u32 position; |
| 6984 | u32 base; |
| 6985 | u32 size; |
| 6986 | } cursor[2]; |
| 6987 | |
| 6988 | struct intel_pipe_error_state { |
| 6989 | u32 conf; |
| 6990 | u32 source; |
| 6991 | |
| 6992 | u32 htotal; |
| 6993 | u32 hblank; |
| 6994 | u32 hsync; |
| 6995 | u32 vtotal; |
| 6996 | u32 vblank; |
| 6997 | u32 vsync; |
| 6998 | } pipe[2]; |
| 6999 | |
| 7000 | struct intel_plane_error_state { |
| 7001 | u32 control; |
| 7002 | u32 stride; |
| 7003 | u32 size; |
| 7004 | u32 pos; |
| 7005 | u32 addr; |
| 7006 | u32 surface; |
| 7007 | u32 tile_offset; |
| 7008 | } plane[2]; |
| 7009 | }; |
| 7010 | |
| 7011 | struct intel_display_error_state * |
| 7012 | intel_display_capture_error_state(struct drm_device *dev) |
| 7013 | { |
| 7014 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 7015 | struct intel_display_error_state *error; |
| 7016 | int i; |
| 7017 | |
| 7018 | error = kmalloc(sizeof(*error), GFP_ATOMIC); |
| 7019 | if (error == NULL) |
| 7020 | return NULL; |
| 7021 | |
| 7022 | for (i = 0; i < 2; i++) { |
| 7023 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
| 7024 | error->cursor[i].position = I915_READ(CURPOS(i)); |
| 7025 | error->cursor[i].base = I915_READ(CURBASE(i)); |
| 7026 | |
| 7027 | error->plane[i].control = I915_READ(DSPCNTR(i)); |
| 7028 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); |
| 7029 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
| 7030 | error->plane[i].pos= I915_READ(DSPPOS(i)); |
| 7031 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
| 7032 | if (INTEL_INFO(dev)->gen >= 4) { |
| 7033 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
| 7034 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); |
| 7035 | } |
| 7036 | |
| 7037 | error->pipe[i].conf = I915_READ(PIPECONF(i)); |
| 7038 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
| 7039 | error->pipe[i].htotal = I915_READ(HTOTAL(i)); |
| 7040 | error->pipe[i].hblank = I915_READ(HBLANK(i)); |
| 7041 | error->pipe[i].hsync = I915_READ(HSYNC(i)); |
| 7042 | error->pipe[i].vtotal = I915_READ(VTOTAL(i)); |
| 7043 | error->pipe[i].vblank = I915_READ(VBLANK(i)); |
| 7044 | error->pipe[i].vsync = I915_READ(VSYNC(i)); |
| 7045 | } |
| 7046 | |
| 7047 | return error; |
| 7048 | } |
| 7049 | |
| 7050 | void |
| 7051 | intel_display_print_error_state(struct seq_file *m, |
| 7052 | struct drm_device *dev, |
| 7053 | struct intel_display_error_state *error) |
| 7054 | { |
| 7055 | int i; |
| 7056 | |
| 7057 | for (i = 0; i < 2; i++) { |
| 7058 | seq_printf(m, "Pipe [%d]:\n", i); |
| 7059 | seq_printf(m, " CONF: %08x\n", error->pipe[i].conf); |
| 7060 | seq_printf(m, " SRC: %08x\n", error->pipe[i].source); |
| 7061 | seq_printf(m, " HTOTAL: %08x\n", error->pipe[i].htotal); |
| 7062 | seq_printf(m, " HBLANK: %08x\n", error->pipe[i].hblank); |
| 7063 | seq_printf(m, " HSYNC: %08x\n", error->pipe[i].hsync); |
| 7064 | seq_printf(m, " VTOTAL: %08x\n", error->pipe[i].vtotal); |
| 7065 | seq_printf(m, " VBLANK: %08x\n", error->pipe[i].vblank); |
| 7066 | seq_printf(m, " VSYNC: %08x\n", error->pipe[i].vsync); |
| 7067 | |
| 7068 | seq_printf(m, "Plane [%d]:\n", i); |
| 7069 | seq_printf(m, " CNTR: %08x\n", error->plane[i].control); |
| 7070 | seq_printf(m, " STRIDE: %08x\n", error->plane[i].stride); |
| 7071 | seq_printf(m, " SIZE: %08x\n", error->plane[i].size); |
| 7072 | seq_printf(m, " POS: %08x\n", error->plane[i].pos); |
| 7073 | seq_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
| 7074 | if (INTEL_INFO(dev)->gen >= 4) { |
| 7075 | seq_printf(m, " SURF: %08x\n", error->plane[i].surface); |
| 7076 | seq_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); |
| 7077 | } |
| 7078 | |
| 7079 | seq_printf(m, "Cursor [%d]:\n", i); |
| 7080 | seq_printf(m, " CNTR: %08x\n", error->cursor[i].control); |
| 7081 | seq_printf(m, " POS: %08x\n", error->cursor[i].position); |
| 7082 | seq_printf(m, " BASE: %08x\n", error->cursor[i].base); |
| 7083 | } |
| 7084 | } |
| 7085 | #endif |