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> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 31 | #include "drmP.h" |
| 32 | #include "intel_drv.h" |
| 33 | #include "i915_drm.h" |
| 34 | #include "i915_drv.h" |
Dave Airlie | ab2c067 | 2009-12-04 10:55:24 +1000 | [diff] [blame] | 35 | #include "drm_dp_helper.h" |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 36 | |
| 37 | #include "drm_crtc_helper.h" |
| 38 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 39 | #define HAS_eDP (intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) |
| 40 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 41 | bool intel_pipe_has_type (struct drm_crtc *crtc, int type); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 42 | static void intel_update_watermarks(struct drm_device *dev); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 43 | static void intel_increase_pllclock(struct drm_crtc *crtc, bool schedule); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 44 | |
| 45 | typedef struct { |
| 46 | /* given values */ |
| 47 | int n; |
| 48 | int m1, m2; |
| 49 | int p1, p2; |
| 50 | /* derived values */ |
| 51 | int dot; |
| 52 | int vco; |
| 53 | int m; |
| 54 | int p; |
| 55 | } intel_clock_t; |
| 56 | |
| 57 | typedef struct { |
| 58 | int min, max; |
| 59 | } intel_range_t; |
| 60 | |
| 61 | typedef struct { |
| 62 | int dot_limit; |
| 63 | int p2_slow, p2_fast; |
| 64 | } intel_p2_t; |
| 65 | |
| 66 | #define INTEL_P2_NUM 2 |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 67 | typedef struct intel_limit intel_limit_t; |
| 68 | struct intel_limit { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 69 | intel_range_t dot, vco, n, m, m1, m2, p, p1; |
| 70 | intel_p2_t p2; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 71 | bool (* find_pll)(const intel_limit_t *, struct drm_crtc *, |
| 72 | int, int, intel_clock_t *); |
| 73 | }; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 74 | |
| 75 | #define I8XX_DOT_MIN 25000 |
| 76 | #define I8XX_DOT_MAX 350000 |
| 77 | #define I8XX_VCO_MIN 930000 |
| 78 | #define I8XX_VCO_MAX 1400000 |
| 79 | #define I8XX_N_MIN 3 |
| 80 | #define I8XX_N_MAX 16 |
| 81 | #define I8XX_M_MIN 96 |
| 82 | #define I8XX_M_MAX 140 |
| 83 | #define I8XX_M1_MIN 18 |
| 84 | #define I8XX_M1_MAX 26 |
| 85 | #define I8XX_M2_MIN 6 |
| 86 | #define I8XX_M2_MAX 16 |
| 87 | #define I8XX_P_MIN 4 |
| 88 | #define I8XX_P_MAX 128 |
| 89 | #define I8XX_P1_MIN 2 |
| 90 | #define I8XX_P1_MAX 33 |
| 91 | #define I8XX_P1_LVDS_MIN 1 |
| 92 | #define I8XX_P1_LVDS_MAX 6 |
| 93 | #define I8XX_P2_SLOW 4 |
| 94 | #define I8XX_P2_FAST 2 |
| 95 | #define I8XX_P2_LVDS_SLOW 14 |
ling.ma@intel.com | 0c2e395 | 2009-07-17 11:44:30 +0800 | [diff] [blame] | 96 | #define I8XX_P2_LVDS_FAST 7 |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 97 | #define I8XX_P2_SLOW_LIMIT 165000 |
| 98 | |
| 99 | #define I9XX_DOT_MIN 20000 |
| 100 | #define I9XX_DOT_MAX 400000 |
| 101 | #define I9XX_VCO_MIN 1400000 |
| 102 | #define I9XX_VCO_MAX 2800000 |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 103 | #define PINEVIEW_VCO_MIN 1700000 |
| 104 | #define PINEVIEW_VCO_MAX 3500000 |
Kristian Høgsberg | f3cade5 | 2009-02-13 20:56:50 -0500 | [diff] [blame] | 105 | #define I9XX_N_MIN 1 |
| 106 | #define I9XX_N_MAX 6 |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 107 | /* Pineview's Ncounter is a ring counter */ |
| 108 | #define PINEVIEW_N_MIN 3 |
| 109 | #define PINEVIEW_N_MAX 6 |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 110 | #define I9XX_M_MIN 70 |
| 111 | #define I9XX_M_MAX 120 |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 112 | #define PINEVIEW_M_MIN 2 |
| 113 | #define PINEVIEW_M_MAX 256 |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 114 | #define I9XX_M1_MIN 10 |
Kristian Høgsberg | f3cade5 | 2009-02-13 20:56:50 -0500 | [diff] [blame] | 115 | #define I9XX_M1_MAX 22 |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 116 | #define I9XX_M2_MIN 5 |
| 117 | #define I9XX_M2_MAX 9 |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 118 | /* Pineview M1 is reserved, and must be 0 */ |
| 119 | #define PINEVIEW_M1_MIN 0 |
| 120 | #define PINEVIEW_M1_MAX 0 |
| 121 | #define PINEVIEW_M2_MIN 0 |
| 122 | #define PINEVIEW_M2_MAX 254 |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 123 | #define I9XX_P_SDVO_DAC_MIN 5 |
| 124 | #define I9XX_P_SDVO_DAC_MAX 80 |
| 125 | #define I9XX_P_LVDS_MIN 7 |
| 126 | #define I9XX_P_LVDS_MAX 98 |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 127 | #define PINEVIEW_P_LVDS_MIN 7 |
| 128 | #define PINEVIEW_P_LVDS_MAX 112 |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 129 | #define I9XX_P1_MIN 1 |
| 130 | #define I9XX_P1_MAX 8 |
| 131 | #define I9XX_P2_SDVO_DAC_SLOW 10 |
| 132 | #define I9XX_P2_SDVO_DAC_FAST 5 |
| 133 | #define I9XX_P2_SDVO_DAC_SLOW_LIMIT 200000 |
| 134 | #define I9XX_P2_LVDS_SLOW 14 |
| 135 | #define I9XX_P2_LVDS_FAST 7 |
| 136 | #define I9XX_P2_LVDS_SLOW_LIMIT 112000 |
| 137 | |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 138 | /*The parameter is for SDVO on G4x platform*/ |
| 139 | #define G4X_DOT_SDVO_MIN 25000 |
| 140 | #define G4X_DOT_SDVO_MAX 270000 |
| 141 | #define G4X_VCO_MIN 1750000 |
| 142 | #define G4X_VCO_MAX 3500000 |
| 143 | #define G4X_N_SDVO_MIN 1 |
| 144 | #define G4X_N_SDVO_MAX 4 |
| 145 | #define G4X_M_SDVO_MIN 104 |
| 146 | #define G4X_M_SDVO_MAX 138 |
| 147 | #define G4X_M1_SDVO_MIN 17 |
| 148 | #define G4X_M1_SDVO_MAX 23 |
| 149 | #define G4X_M2_SDVO_MIN 5 |
| 150 | #define G4X_M2_SDVO_MAX 11 |
| 151 | #define G4X_P_SDVO_MIN 10 |
| 152 | #define G4X_P_SDVO_MAX 30 |
| 153 | #define G4X_P1_SDVO_MIN 1 |
| 154 | #define G4X_P1_SDVO_MAX 3 |
| 155 | #define G4X_P2_SDVO_SLOW 10 |
| 156 | #define G4X_P2_SDVO_FAST 10 |
| 157 | #define G4X_P2_SDVO_LIMIT 270000 |
| 158 | |
| 159 | /*The parameter is for HDMI_DAC on G4x platform*/ |
| 160 | #define G4X_DOT_HDMI_DAC_MIN 22000 |
| 161 | #define G4X_DOT_HDMI_DAC_MAX 400000 |
| 162 | #define G4X_N_HDMI_DAC_MIN 1 |
| 163 | #define G4X_N_HDMI_DAC_MAX 4 |
| 164 | #define G4X_M_HDMI_DAC_MIN 104 |
| 165 | #define G4X_M_HDMI_DAC_MAX 138 |
| 166 | #define G4X_M1_HDMI_DAC_MIN 16 |
| 167 | #define G4X_M1_HDMI_DAC_MAX 23 |
| 168 | #define G4X_M2_HDMI_DAC_MIN 5 |
| 169 | #define G4X_M2_HDMI_DAC_MAX 11 |
| 170 | #define G4X_P_HDMI_DAC_MIN 5 |
| 171 | #define G4X_P_HDMI_DAC_MAX 80 |
| 172 | #define G4X_P1_HDMI_DAC_MIN 1 |
| 173 | #define G4X_P1_HDMI_DAC_MAX 8 |
| 174 | #define G4X_P2_HDMI_DAC_SLOW 10 |
| 175 | #define G4X_P2_HDMI_DAC_FAST 5 |
| 176 | #define G4X_P2_HDMI_DAC_LIMIT 165000 |
| 177 | |
| 178 | /*The parameter is for SINGLE_CHANNEL_LVDS on G4x platform*/ |
| 179 | #define G4X_DOT_SINGLE_CHANNEL_LVDS_MIN 20000 |
| 180 | #define G4X_DOT_SINGLE_CHANNEL_LVDS_MAX 115000 |
| 181 | #define G4X_N_SINGLE_CHANNEL_LVDS_MIN 1 |
| 182 | #define G4X_N_SINGLE_CHANNEL_LVDS_MAX 3 |
| 183 | #define G4X_M_SINGLE_CHANNEL_LVDS_MIN 104 |
| 184 | #define G4X_M_SINGLE_CHANNEL_LVDS_MAX 138 |
| 185 | #define G4X_M1_SINGLE_CHANNEL_LVDS_MIN 17 |
| 186 | #define G4X_M1_SINGLE_CHANNEL_LVDS_MAX 23 |
| 187 | #define G4X_M2_SINGLE_CHANNEL_LVDS_MIN 5 |
| 188 | #define G4X_M2_SINGLE_CHANNEL_LVDS_MAX 11 |
| 189 | #define G4X_P_SINGLE_CHANNEL_LVDS_MIN 28 |
| 190 | #define G4X_P_SINGLE_CHANNEL_LVDS_MAX 112 |
| 191 | #define G4X_P1_SINGLE_CHANNEL_LVDS_MIN 2 |
| 192 | #define G4X_P1_SINGLE_CHANNEL_LVDS_MAX 8 |
| 193 | #define G4X_P2_SINGLE_CHANNEL_LVDS_SLOW 14 |
| 194 | #define G4X_P2_SINGLE_CHANNEL_LVDS_FAST 14 |
| 195 | #define G4X_P2_SINGLE_CHANNEL_LVDS_LIMIT 0 |
| 196 | |
| 197 | /*The parameter is for DUAL_CHANNEL_LVDS on G4x platform*/ |
| 198 | #define G4X_DOT_DUAL_CHANNEL_LVDS_MIN 80000 |
| 199 | #define G4X_DOT_DUAL_CHANNEL_LVDS_MAX 224000 |
| 200 | #define G4X_N_DUAL_CHANNEL_LVDS_MIN 1 |
| 201 | #define G4X_N_DUAL_CHANNEL_LVDS_MAX 3 |
| 202 | #define G4X_M_DUAL_CHANNEL_LVDS_MIN 104 |
| 203 | #define G4X_M_DUAL_CHANNEL_LVDS_MAX 138 |
| 204 | #define G4X_M1_DUAL_CHANNEL_LVDS_MIN 17 |
| 205 | #define G4X_M1_DUAL_CHANNEL_LVDS_MAX 23 |
| 206 | #define G4X_M2_DUAL_CHANNEL_LVDS_MIN 5 |
| 207 | #define G4X_M2_DUAL_CHANNEL_LVDS_MAX 11 |
| 208 | #define G4X_P_DUAL_CHANNEL_LVDS_MIN 14 |
| 209 | #define G4X_P_DUAL_CHANNEL_LVDS_MAX 42 |
| 210 | #define G4X_P1_DUAL_CHANNEL_LVDS_MIN 2 |
| 211 | #define G4X_P1_DUAL_CHANNEL_LVDS_MAX 6 |
| 212 | #define G4X_P2_DUAL_CHANNEL_LVDS_SLOW 7 |
| 213 | #define G4X_P2_DUAL_CHANNEL_LVDS_FAST 7 |
| 214 | #define G4X_P2_DUAL_CHANNEL_LVDS_LIMIT 0 |
| 215 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 216 | /*The parameter is for DISPLAY PORT on G4x platform*/ |
| 217 | #define G4X_DOT_DISPLAY_PORT_MIN 161670 |
| 218 | #define G4X_DOT_DISPLAY_PORT_MAX 227000 |
| 219 | #define G4X_N_DISPLAY_PORT_MIN 1 |
| 220 | #define G4X_N_DISPLAY_PORT_MAX 2 |
| 221 | #define G4X_M_DISPLAY_PORT_MIN 97 |
| 222 | #define G4X_M_DISPLAY_PORT_MAX 108 |
| 223 | #define G4X_M1_DISPLAY_PORT_MIN 0x10 |
| 224 | #define G4X_M1_DISPLAY_PORT_MAX 0x12 |
| 225 | #define G4X_M2_DISPLAY_PORT_MIN 0x05 |
| 226 | #define G4X_M2_DISPLAY_PORT_MAX 0x06 |
| 227 | #define G4X_P_DISPLAY_PORT_MIN 10 |
| 228 | #define G4X_P_DISPLAY_PORT_MAX 20 |
| 229 | #define G4X_P1_DISPLAY_PORT_MIN 1 |
| 230 | #define G4X_P1_DISPLAY_PORT_MAX 2 |
| 231 | #define G4X_P2_DISPLAY_PORT_SLOW 10 |
| 232 | #define G4X_P2_DISPLAY_PORT_FAST 10 |
| 233 | #define G4X_P2_DISPLAY_PORT_LIMIT 0 |
| 234 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 235 | /* Ironlake */ |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 236 | /* as we calculate clock using (register_value + 2) for |
| 237 | N/M1/M2, so here the range value for them is (actual_value-2). |
| 238 | */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 239 | #define IRONLAKE_DOT_MIN 25000 |
| 240 | #define IRONLAKE_DOT_MAX 350000 |
| 241 | #define IRONLAKE_VCO_MIN 1760000 |
| 242 | #define IRONLAKE_VCO_MAX 3510000 |
| 243 | #define IRONLAKE_N_MIN 1 |
Zhao Yakui | a59e385 | 2010-01-06 22:05:57 +0800 | [diff] [blame] | 244 | #define IRONLAKE_N_MAX 6 |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 245 | #define IRONLAKE_M_MIN 79 |
Zhao Yakui | a59e385 | 2010-01-06 22:05:57 +0800 | [diff] [blame] | 246 | #define IRONLAKE_M_MAX 127 |
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 |
| 251 | #define IRONLAKE_P_SDVO_DAC_MIN 5 |
| 252 | #define IRONLAKE_P_SDVO_DAC_MAX 80 |
| 253 | #define IRONLAKE_P_LVDS_MIN 28 |
| 254 | #define IRONLAKE_P_LVDS_MAX 112 |
| 255 | #define IRONLAKE_P1_MIN 1 |
| 256 | #define IRONLAKE_P1_MAX 8 |
| 257 | #define IRONLAKE_P2_SDVO_DAC_SLOW 10 |
| 258 | #define IRONLAKE_P2_SDVO_DAC_FAST 5 |
| 259 | #define IRONLAKE_P2_LVDS_SLOW 14 /* single channel */ |
| 260 | #define IRONLAKE_P2_LVDS_FAST 7 /* double channel */ |
| 261 | #define IRONLAKE_P2_DOT_LIMIT 225000 /* 225Mhz */ |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 262 | |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 263 | #define IRONLAKE_P_DISPLAY_PORT_MIN 10 |
| 264 | #define IRONLAKE_P_DISPLAY_PORT_MAX 20 |
| 265 | #define IRONLAKE_P2_DISPLAY_PORT_FAST 10 |
| 266 | #define IRONLAKE_P2_DISPLAY_PORT_SLOW 10 |
| 267 | #define IRONLAKE_P2_DISPLAY_PORT_LIMIT 0 |
| 268 | #define IRONLAKE_P1_DISPLAY_PORT_MIN 1 |
| 269 | #define IRONLAKE_P1_DISPLAY_PORT_MAX 2 |
| 270 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 271 | static bool |
| 272 | intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, |
| 273 | int target, int refclk, intel_clock_t *best_clock); |
| 274 | static bool |
| 275 | intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, |
| 276 | int target, int refclk, intel_clock_t *best_clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 277 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 278 | static bool |
| 279 | intel_find_pll_g4x_dp(const intel_limit_t *, struct drm_crtc *crtc, |
| 280 | int target, int refclk, intel_clock_t *best_clock); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 281 | static bool |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 282 | intel_find_pll_ironlake_dp(const intel_limit_t *, struct drm_crtc *crtc, |
| 283 | int target, int refclk, intel_clock_t *best_clock); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 284 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 285 | static const intel_limit_t intel_limits_i8xx_dvo = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 286 | .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX }, |
| 287 | .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX }, |
| 288 | .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX }, |
| 289 | .m = { .min = I8XX_M_MIN, .max = I8XX_M_MAX }, |
| 290 | .m1 = { .min = I8XX_M1_MIN, .max = I8XX_M1_MAX }, |
| 291 | .m2 = { .min = I8XX_M2_MIN, .max = I8XX_M2_MAX }, |
| 292 | .p = { .min = I8XX_P_MIN, .max = I8XX_P_MAX }, |
| 293 | .p1 = { .min = I8XX_P1_MIN, .max = I8XX_P1_MAX }, |
| 294 | .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT, |
| 295 | .p2_slow = I8XX_P2_SLOW, .p2_fast = I8XX_P2_FAST }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 296 | .find_pll = intel_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 297 | }; |
| 298 | |
| 299 | static const intel_limit_t intel_limits_i8xx_lvds = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 300 | .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX }, |
| 301 | .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX }, |
| 302 | .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX }, |
| 303 | .m = { .min = I8XX_M_MIN, .max = I8XX_M_MAX }, |
| 304 | .m1 = { .min = I8XX_M1_MIN, .max = I8XX_M1_MAX }, |
| 305 | .m2 = { .min = I8XX_M2_MIN, .max = I8XX_M2_MAX }, |
| 306 | .p = { .min = I8XX_P_MIN, .max = I8XX_P_MAX }, |
| 307 | .p1 = { .min = I8XX_P1_LVDS_MIN, .max = I8XX_P1_LVDS_MAX }, |
| 308 | .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT, |
| 309 | .p2_slow = I8XX_P2_LVDS_SLOW, .p2_fast = I8XX_P2_LVDS_FAST }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 310 | .find_pll = intel_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 311 | }; |
| 312 | |
| 313 | static const intel_limit_t intel_limits_i9xx_sdvo = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 314 | .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX }, |
| 315 | .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX }, |
| 316 | .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX }, |
| 317 | .m = { .min = I9XX_M_MIN, .max = I9XX_M_MAX }, |
| 318 | .m1 = { .min = I9XX_M1_MIN, .max = I9XX_M1_MAX }, |
| 319 | .m2 = { .min = I9XX_M2_MIN, .max = I9XX_M2_MAX }, |
| 320 | .p = { .min = I9XX_P_SDVO_DAC_MIN, .max = I9XX_P_SDVO_DAC_MAX }, |
| 321 | .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX }, |
| 322 | .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT, |
| 323 | .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] | 324 | .find_pll = intel_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 325 | }; |
| 326 | |
| 327 | static const intel_limit_t intel_limits_i9xx_lvds = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 328 | .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX }, |
| 329 | .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX }, |
| 330 | .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX }, |
| 331 | .m = { .min = I9XX_M_MIN, .max = I9XX_M_MAX }, |
| 332 | .m1 = { .min = I9XX_M1_MIN, .max = I9XX_M1_MAX }, |
| 333 | .m2 = { .min = I9XX_M2_MIN, .max = I9XX_M2_MAX }, |
| 334 | .p = { .min = I9XX_P_LVDS_MIN, .max = I9XX_P_LVDS_MAX }, |
| 335 | .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX }, |
| 336 | /* The single-channel range is 25-112Mhz, and dual-channel |
| 337 | * is 80-224Mhz. Prefer single channel as much as possible. |
| 338 | */ |
| 339 | .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT, |
| 340 | .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_FAST }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 341 | .find_pll = intel_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 342 | }; |
| 343 | |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 344 | /* below parameter and function is for G4X Chipset Family*/ |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 345 | static const intel_limit_t intel_limits_g4x_sdvo = { |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 346 | .dot = { .min = G4X_DOT_SDVO_MIN, .max = G4X_DOT_SDVO_MAX }, |
| 347 | .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX}, |
| 348 | .n = { .min = G4X_N_SDVO_MIN, .max = G4X_N_SDVO_MAX }, |
| 349 | .m = { .min = G4X_M_SDVO_MIN, .max = G4X_M_SDVO_MAX }, |
| 350 | .m1 = { .min = G4X_M1_SDVO_MIN, .max = G4X_M1_SDVO_MAX }, |
| 351 | .m2 = { .min = G4X_M2_SDVO_MIN, .max = G4X_M2_SDVO_MAX }, |
| 352 | .p = { .min = G4X_P_SDVO_MIN, .max = G4X_P_SDVO_MAX }, |
| 353 | .p1 = { .min = G4X_P1_SDVO_MIN, .max = G4X_P1_SDVO_MAX}, |
| 354 | .p2 = { .dot_limit = G4X_P2_SDVO_LIMIT, |
| 355 | .p2_slow = G4X_P2_SDVO_SLOW, |
| 356 | .p2_fast = G4X_P2_SDVO_FAST |
| 357 | }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 358 | .find_pll = intel_g4x_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 359 | }; |
| 360 | |
| 361 | static const intel_limit_t intel_limits_g4x_hdmi = { |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 362 | .dot = { .min = G4X_DOT_HDMI_DAC_MIN, .max = G4X_DOT_HDMI_DAC_MAX }, |
| 363 | .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX}, |
| 364 | .n = { .min = G4X_N_HDMI_DAC_MIN, .max = G4X_N_HDMI_DAC_MAX }, |
| 365 | .m = { .min = G4X_M_HDMI_DAC_MIN, .max = G4X_M_HDMI_DAC_MAX }, |
| 366 | .m1 = { .min = G4X_M1_HDMI_DAC_MIN, .max = G4X_M1_HDMI_DAC_MAX }, |
| 367 | .m2 = { .min = G4X_M2_HDMI_DAC_MIN, .max = G4X_M2_HDMI_DAC_MAX }, |
| 368 | .p = { .min = G4X_P_HDMI_DAC_MIN, .max = G4X_P_HDMI_DAC_MAX }, |
| 369 | .p1 = { .min = G4X_P1_HDMI_DAC_MIN, .max = G4X_P1_HDMI_DAC_MAX}, |
| 370 | .p2 = { .dot_limit = G4X_P2_HDMI_DAC_LIMIT, |
| 371 | .p2_slow = G4X_P2_HDMI_DAC_SLOW, |
| 372 | .p2_fast = G4X_P2_HDMI_DAC_FAST |
| 373 | }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 374 | .find_pll = intel_g4x_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 375 | }; |
| 376 | |
| 377 | static const intel_limit_t intel_limits_g4x_single_channel_lvds = { |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 378 | .dot = { .min = G4X_DOT_SINGLE_CHANNEL_LVDS_MIN, |
| 379 | .max = G4X_DOT_SINGLE_CHANNEL_LVDS_MAX }, |
| 380 | .vco = { .min = G4X_VCO_MIN, |
| 381 | .max = G4X_VCO_MAX }, |
| 382 | .n = { .min = G4X_N_SINGLE_CHANNEL_LVDS_MIN, |
| 383 | .max = G4X_N_SINGLE_CHANNEL_LVDS_MAX }, |
| 384 | .m = { .min = G4X_M_SINGLE_CHANNEL_LVDS_MIN, |
| 385 | .max = G4X_M_SINGLE_CHANNEL_LVDS_MAX }, |
| 386 | .m1 = { .min = G4X_M1_SINGLE_CHANNEL_LVDS_MIN, |
| 387 | .max = G4X_M1_SINGLE_CHANNEL_LVDS_MAX }, |
| 388 | .m2 = { .min = G4X_M2_SINGLE_CHANNEL_LVDS_MIN, |
| 389 | .max = G4X_M2_SINGLE_CHANNEL_LVDS_MAX }, |
| 390 | .p = { .min = G4X_P_SINGLE_CHANNEL_LVDS_MIN, |
| 391 | .max = G4X_P_SINGLE_CHANNEL_LVDS_MAX }, |
| 392 | .p1 = { .min = G4X_P1_SINGLE_CHANNEL_LVDS_MIN, |
| 393 | .max = G4X_P1_SINGLE_CHANNEL_LVDS_MAX }, |
| 394 | .p2 = { .dot_limit = G4X_P2_SINGLE_CHANNEL_LVDS_LIMIT, |
| 395 | .p2_slow = G4X_P2_SINGLE_CHANNEL_LVDS_SLOW, |
| 396 | .p2_fast = G4X_P2_SINGLE_CHANNEL_LVDS_FAST |
| 397 | }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 398 | .find_pll = intel_g4x_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 399 | }; |
| 400 | |
| 401 | static const intel_limit_t intel_limits_g4x_dual_channel_lvds = { |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 402 | .dot = { .min = G4X_DOT_DUAL_CHANNEL_LVDS_MIN, |
| 403 | .max = G4X_DOT_DUAL_CHANNEL_LVDS_MAX }, |
| 404 | .vco = { .min = G4X_VCO_MIN, |
| 405 | .max = G4X_VCO_MAX }, |
| 406 | .n = { .min = G4X_N_DUAL_CHANNEL_LVDS_MIN, |
| 407 | .max = G4X_N_DUAL_CHANNEL_LVDS_MAX }, |
| 408 | .m = { .min = G4X_M_DUAL_CHANNEL_LVDS_MIN, |
| 409 | .max = G4X_M_DUAL_CHANNEL_LVDS_MAX }, |
| 410 | .m1 = { .min = G4X_M1_DUAL_CHANNEL_LVDS_MIN, |
| 411 | .max = G4X_M1_DUAL_CHANNEL_LVDS_MAX }, |
| 412 | .m2 = { .min = G4X_M2_DUAL_CHANNEL_LVDS_MIN, |
| 413 | .max = G4X_M2_DUAL_CHANNEL_LVDS_MAX }, |
| 414 | .p = { .min = G4X_P_DUAL_CHANNEL_LVDS_MIN, |
| 415 | .max = G4X_P_DUAL_CHANNEL_LVDS_MAX }, |
| 416 | .p1 = { .min = G4X_P1_DUAL_CHANNEL_LVDS_MIN, |
| 417 | .max = G4X_P1_DUAL_CHANNEL_LVDS_MAX }, |
| 418 | .p2 = { .dot_limit = G4X_P2_DUAL_CHANNEL_LVDS_LIMIT, |
| 419 | .p2_slow = G4X_P2_DUAL_CHANNEL_LVDS_SLOW, |
| 420 | .p2_fast = G4X_P2_DUAL_CHANNEL_LVDS_FAST |
| 421 | }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 422 | .find_pll = intel_g4x_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 423 | }; |
| 424 | |
| 425 | static const intel_limit_t intel_limits_g4x_display_port = { |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 426 | .dot = { .min = G4X_DOT_DISPLAY_PORT_MIN, |
| 427 | .max = G4X_DOT_DISPLAY_PORT_MAX }, |
| 428 | .vco = { .min = G4X_VCO_MIN, |
| 429 | .max = G4X_VCO_MAX}, |
| 430 | .n = { .min = G4X_N_DISPLAY_PORT_MIN, |
| 431 | .max = G4X_N_DISPLAY_PORT_MAX }, |
| 432 | .m = { .min = G4X_M_DISPLAY_PORT_MIN, |
| 433 | .max = G4X_M_DISPLAY_PORT_MAX }, |
| 434 | .m1 = { .min = G4X_M1_DISPLAY_PORT_MIN, |
| 435 | .max = G4X_M1_DISPLAY_PORT_MAX }, |
| 436 | .m2 = { .min = G4X_M2_DISPLAY_PORT_MIN, |
| 437 | .max = G4X_M2_DISPLAY_PORT_MAX }, |
| 438 | .p = { .min = G4X_P_DISPLAY_PORT_MIN, |
| 439 | .max = G4X_P_DISPLAY_PORT_MAX }, |
| 440 | .p1 = { .min = G4X_P1_DISPLAY_PORT_MIN, |
| 441 | .max = G4X_P1_DISPLAY_PORT_MAX}, |
| 442 | .p2 = { .dot_limit = G4X_P2_DISPLAY_PORT_LIMIT, |
| 443 | .p2_slow = G4X_P2_DISPLAY_PORT_SLOW, |
| 444 | .p2_fast = G4X_P2_DISPLAY_PORT_FAST }, |
| 445 | .find_pll = intel_find_pll_g4x_dp, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 446 | }; |
| 447 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 448 | static const intel_limit_t intel_limits_pineview_sdvo = { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 449 | .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX}, |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 450 | .vco = { .min = PINEVIEW_VCO_MIN, .max = PINEVIEW_VCO_MAX }, |
| 451 | .n = { .min = PINEVIEW_N_MIN, .max = PINEVIEW_N_MAX }, |
| 452 | .m = { .min = PINEVIEW_M_MIN, .max = PINEVIEW_M_MAX }, |
| 453 | .m1 = { .min = PINEVIEW_M1_MIN, .max = PINEVIEW_M1_MAX }, |
| 454 | .m2 = { .min = PINEVIEW_M2_MIN, .max = PINEVIEW_M2_MAX }, |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 455 | .p = { .min = I9XX_P_SDVO_DAC_MIN, .max = I9XX_P_SDVO_DAC_MAX }, |
| 456 | .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX }, |
| 457 | .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT, |
| 458 | .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] | 459 | .find_pll = intel_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 460 | }; |
| 461 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 462 | static const intel_limit_t intel_limits_pineview_lvds = { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 463 | .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX }, |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 464 | .vco = { .min = PINEVIEW_VCO_MIN, .max = PINEVIEW_VCO_MAX }, |
| 465 | .n = { .min = PINEVIEW_N_MIN, .max = PINEVIEW_N_MAX }, |
| 466 | .m = { .min = PINEVIEW_M_MIN, .max = PINEVIEW_M_MAX }, |
| 467 | .m1 = { .min = PINEVIEW_M1_MIN, .max = PINEVIEW_M1_MAX }, |
| 468 | .m2 = { .min = PINEVIEW_M2_MIN, .max = PINEVIEW_M2_MAX }, |
| 469 | .p = { .min = PINEVIEW_P_LVDS_MIN, .max = PINEVIEW_P_LVDS_MAX }, |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 470 | .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX }, |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 471 | /* Pineview only supports single-channel mode. */ |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 472 | .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT, |
| 473 | .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_SLOW }, |
Shaohua Li | 6115707 | 2009-04-03 15:24:43 +0800 | [diff] [blame] | 474 | .find_pll = intel_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 475 | }; |
| 476 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 477 | static const intel_limit_t intel_limits_ironlake_sdvo = { |
| 478 | .dot = { .min = IRONLAKE_DOT_MIN, .max = IRONLAKE_DOT_MAX }, |
| 479 | .vco = { .min = IRONLAKE_VCO_MIN, .max = IRONLAKE_VCO_MAX }, |
| 480 | .n = { .min = IRONLAKE_N_MIN, .max = IRONLAKE_N_MAX }, |
| 481 | .m = { .min = IRONLAKE_M_MIN, .max = IRONLAKE_M_MAX }, |
| 482 | .m1 = { .min = IRONLAKE_M1_MIN, .max = IRONLAKE_M1_MAX }, |
| 483 | .m2 = { .min = IRONLAKE_M2_MIN, .max = IRONLAKE_M2_MAX }, |
| 484 | .p = { .min = IRONLAKE_P_SDVO_DAC_MIN, .max = IRONLAKE_P_SDVO_DAC_MAX }, |
| 485 | .p1 = { .min = IRONLAKE_P1_MIN, .max = IRONLAKE_P1_MAX }, |
| 486 | .p2 = { .dot_limit = IRONLAKE_P2_DOT_LIMIT, |
| 487 | .p2_slow = IRONLAKE_P2_SDVO_DAC_SLOW, |
| 488 | .p2_fast = IRONLAKE_P2_SDVO_DAC_FAST }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 489 | .find_pll = intel_g4x_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 490 | }; |
| 491 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 492 | static const intel_limit_t intel_limits_ironlake_lvds = { |
| 493 | .dot = { .min = IRONLAKE_DOT_MIN, .max = IRONLAKE_DOT_MAX }, |
| 494 | .vco = { .min = IRONLAKE_VCO_MIN, .max = IRONLAKE_VCO_MAX }, |
| 495 | .n = { .min = IRONLAKE_N_MIN, .max = IRONLAKE_N_MAX }, |
| 496 | .m = { .min = IRONLAKE_M_MIN, .max = IRONLAKE_M_MAX }, |
| 497 | .m1 = { .min = IRONLAKE_M1_MIN, .max = IRONLAKE_M1_MAX }, |
| 498 | .m2 = { .min = IRONLAKE_M2_MIN, .max = IRONLAKE_M2_MAX }, |
| 499 | .p = { .min = IRONLAKE_P_LVDS_MIN, .max = IRONLAKE_P_LVDS_MAX }, |
| 500 | .p1 = { .min = IRONLAKE_P1_MIN, .max = IRONLAKE_P1_MAX }, |
| 501 | .p2 = { .dot_limit = IRONLAKE_P2_DOT_LIMIT, |
| 502 | .p2_slow = IRONLAKE_P2_LVDS_SLOW, |
| 503 | .p2_fast = IRONLAKE_P2_LVDS_FAST }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 504 | .find_pll = intel_g4x_find_best_PLL, |
| 505 | }; |
| 506 | |
| 507 | static const intel_limit_t intel_limits_ironlake_display_port = { |
| 508 | .dot = { .min = IRONLAKE_DOT_MIN, |
| 509 | .max = IRONLAKE_DOT_MAX }, |
| 510 | .vco = { .min = IRONLAKE_VCO_MIN, |
| 511 | .max = IRONLAKE_VCO_MAX}, |
| 512 | .n = { .min = IRONLAKE_N_MIN, |
| 513 | .max = IRONLAKE_N_MAX }, |
| 514 | .m = { .min = IRONLAKE_M_MIN, |
| 515 | .max = IRONLAKE_M_MAX }, |
| 516 | .m1 = { .min = IRONLAKE_M1_MIN, |
| 517 | .max = IRONLAKE_M1_MAX }, |
| 518 | .m2 = { .min = IRONLAKE_M2_MIN, |
| 519 | .max = IRONLAKE_M2_MAX }, |
| 520 | .p = { .min = IRONLAKE_P_DISPLAY_PORT_MIN, |
| 521 | .max = IRONLAKE_P_DISPLAY_PORT_MAX }, |
| 522 | .p1 = { .min = IRONLAKE_P1_DISPLAY_PORT_MIN, |
| 523 | .max = IRONLAKE_P1_DISPLAY_PORT_MAX}, |
| 524 | .p2 = { .dot_limit = IRONLAKE_P2_DISPLAY_PORT_LIMIT, |
| 525 | .p2_slow = IRONLAKE_P2_DISPLAY_PORT_SLOW, |
| 526 | .p2_fast = IRONLAKE_P2_DISPLAY_PORT_FAST }, |
| 527 | .find_pll = intel_find_pll_ironlake_dp, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 528 | }; |
| 529 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 530 | static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 531 | { |
| 532 | const intel_limit_t *limit; |
| 533 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 534 | limit = &intel_limits_ironlake_lvds; |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 535 | else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
| 536 | HAS_eDP) |
| 537 | limit = &intel_limits_ironlake_display_port; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 538 | else |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 539 | limit = &intel_limits_ironlake_sdvo; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 540 | |
| 541 | return limit; |
| 542 | } |
| 543 | |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 544 | static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc) |
| 545 | { |
| 546 | struct drm_device *dev = crtc->dev; |
| 547 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 548 | const intel_limit_t *limit; |
| 549 | |
| 550 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
| 551 | if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) == |
| 552 | LVDS_CLKB_POWER_UP) |
| 553 | /* LVDS with dual channel */ |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 554 | limit = &intel_limits_g4x_dual_channel_lvds; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 555 | else |
| 556 | /* LVDS with dual channel */ |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 557 | limit = &intel_limits_g4x_single_channel_lvds; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 558 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) || |
| 559 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 560 | limit = &intel_limits_g4x_hdmi; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 561 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 562 | limit = &intel_limits_g4x_sdvo; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 563 | } else if (intel_pipe_has_type (crtc, INTEL_OUTPUT_DISPLAYPORT)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 564 | limit = &intel_limits_g4x_display_port; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 565 | } else /* The option is for other outputs */ |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 566 | limit = &intel_limits_i9xx_sdvo; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 567 | |
| 568 | return limit; |
| 569 | } |
| 570 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 571 | static const intel_limit_t *intel_limit(struct drm_crtc *crtc) |
| 572 | { |
| 573 | struct drm_device *dev = crtc->dev; |
| 574 | const intel_limit_t *limit; |
| 575 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 576 | if (IS_IRONLAKE(dev)) |
| 577 | limit = intel_ironlake_limit(crtc); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 578 | else if (IS_G4X(dev)) { |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 579 | limit = intel_g4x_limit(crtc); |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 580 | } else if (IS_I9XX(dev) && !IS_PINEVIEW(dev)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 581 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 582 | limit = &intel_limits_i9xx_lvds; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 583 | else |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 584 | limit = &intel_limits_i9xx_sdvo; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 585 | } else if (IS_PINEVIEW(dev)) { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 586 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 587 | limit = &intel_limits_pineview_lvds; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 588 | else |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 589 | limit = &intel_limits_pineview_sdvo; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 590 | } else { |
| 591 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 592 | limit = &intel_limits_i8xx_lvds; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 593 | else |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 594 | limit = &intel_limits_i8xx_dvo; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 595 | } |
| 596 | return limit; |
| 597 | } |
| 598 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 599 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
| 600 | static void pineview_clock(int refclk, intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 601 | { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 602 | clock->m = clock->m2 + 2; |
| 603 | clock->p = clock->p1 * clock->p2; |
| 604 | clock->vco = refclk * clock->m / clock->n; |
| 605 | clock->dot = clock->vco / clock->p; |
| 606 | } |
| 607 | |
| 608 | static void intel_clock(struct drm_device *dev, int refclk, intel_clock_t *clock) |
| 609 | { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 610 | if (IS_PINEVIEW(dev)) { |
| 611 | pineview_clock(refclk, clock); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 612 | return; |
| 613 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 614 | clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2); |
| 615 | clock->p = clock->p1 * clock->p2; |
| 616 | clock->vco = refclk * clock->m / (clock->n + 2); |
| 617 | clock->dot = clock->vco / clock->p; |
| 618 | } |
| 619 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 620 | /** |
| 621 | * Returns whether any output on the specified pipe is of the specified type |
| 622 | */ |
| 623 | bool intel_pipe_has_type (struct drm_crtc *crtc, int type) |
| 624 | { |
| 625 | struct drm_device *dev = crtc->dev; |
| 626 | struct drm_mode_config *mode_config = &dev->mode_config; |
| 627 | struct drm_connector *l_entry; |
| 628 | |
| 629 | list_for_each_entry(l_entry, &mode_config->connector_list, head) { |
| 630 | if (l_entry->encoder && |
| 631 | l_entry->encoder->crtc == crtc) { |
| 632 | struct intel_output *intel_output = to_intel_output(l_entry); |
| 633 | if (intel_output->type == type) |
| 634 | return true; |
| 635 | } |
| 636 | } |
| 637 | return false; |
| 638 | } |
| 639 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 640 | struct drm_connector * |
| 641 | intel_pipe_get_output (struct drm_crtc *crtc) |
| 642 | { |
| 643 | struct drm_device *dev = crtc->dev; |
| 644 | struct drm_mode_config *mode_config = &dev->mode_config; |
| 645 | struct drm_connector *l_entry, *ret = NULL; |
| 646 | |
| 647 | list_for_each_entry(l_entry, &mode_config->connector_list, head) { |
| 648 | if (l_entry->encoder && |
| 649 | l_entry->encoder->crtc == crtc) { |
| 650 | ret = l_entry; |
| 651 | break; |
| 652 | } |
| 653 | } |
| 654 | return ret; |
| 655 | } |
| 656 | |
Jesse Barnes | 7c04d1d | 2009-02-23 15:36:40 -0800 | [diff] [blame] | 657 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 658 | /** |
| 659 | * Returns whether the given set of divisors are valid for a given refclk with |
| 660 | * the given connectors. |
| 661 | */ |
| 662 | |
| 663 | static bool intel_PLL_is_valid(struct drm_crtc *crtc, intel_clock_t *clock) |
| 664 | { |
| 665 | const intel_limit_t *limit = intel_limit (crtc); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 666 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 667 | |
| 668 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
| 669 | INTELPllInvalid ("p1 out of range\n"); |
| 670 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
| 671 | INTELPllInvalid ("p out of range\n"); |
| 672 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
| 673 | INTELPllInvalid ("m2 out of range\n"); |
| 674 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
| 675 | INTELPllInvalid ("m1 out of range\n"); |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 676 | if (clock->m1 <= clock->m2 && !IS_PINEVIEW(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 677 | INTELPllInvalid ("m1 <= m2\n"); |
| 678 | if (clock->m < limit->m.min || limit->m.max < clock->m) |
| 679 | INTELPllInvalid ("m out of range\n"); |
| 680 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
| 681 | INTELPllInvalid ("n out of range\n"); |
| 682 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
| 683 | INTELPllInvalid ("vco out of range\n"); |
| 684 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
| 685 | * connector, etc., rather than just a single range. |
| 686 | */ |
| 687 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) |
| 688 | INTELPllInvalid ("dot out of range\n"); |
| 689 | |
| 690 | return true; |
| 691 | } |
| 692 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 693 | static bool |
| 694 | intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, |
| 695 | int target, int refclk, intel_clock_t *best_clock) |
| 696 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 697 | { |
| 698 | struct drm_device *dev = crtc->dev; |
| 699 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 700 | intel_clock_t clock; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 701 | int err = target; |
| 702 | |
Bruno Prémont | bc5e571 | 2009-08-08 13:01:17 +0200 | [diff] [blame] | 703 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) && |
Florian Mickler | 832cc28 | 2009-07-13 18:40:32 +0800 | [diff] [blame] | 704 | (I915_READ(LVDS)) != 0) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 705 | /* |
| 706 | * For LVDS, if the panel is on, just rely on its current |
| 707 | * settings for dual-channel. We haven't figured out how to |
| 708 | * reliably set up different single/dual channel state, if we |
| 709 | * even can. |
| 710 | */ |
| 711 | if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) == |
| 712 | LVDS_CLKB_POWER_UP) |
| 713 | clock.p2 = limit->p2.p2_fast; |
| 714 | else |
| 715 | clock.p2 = limit->p2.p2_slow; |
| 716 | } else { |
| 717 | if (target < limit->p2.dot_limit) |
| 718 | clock.p2 = limit->p2.p2_slow; |
| 719 | else |
| 720 | clock.p2 = limit->p2.p2_fast; |
| 721 | } |
| 722 | |
| 723 | memset (best_clock, 0, sizeof (*best_clock)); |
| 724 | |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 725 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 726 | clock.m1++) { |
| 727 | for (clock.m2 = limit->m2.min; |
| 728 | clock.m2 <= limit->m2.max; clock.m2++) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 729 | /* m1 is always 0 in Pineview */ |
| 730 | if (clock.m2 >= clock.m1 && !IS_PINEVIEW(dev)) |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 731 | break; |
| 732 | for (clock.n = limit->n.min; |
| 733 | clock.n <= limit->n.max; clock.n++) { |
| 734 | for (clock.p1 = limit->p1.min; |
| 735 | clock.p1 <= limit->p1.max; clock.p1++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 736 | int this_err; |
| 737 | |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 738 | intel_clock(dev, refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 739 | |
| 740 | if (!intel_PLL_is_valid(crtc, &clock)) |
| 741 | continue; |
| 742 | |
| 743 | this_err = abs(clock.dot - target); |
| 744 | if (this_err < err) { |
| 745 | *best_clock = clock; |
| 746 | err = this_err; |
| 747 | } |
| 748 | } |
| 749 | } |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | return (err != target); |
| 754 | } |
| 755 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 756 | static bool |
| 757 | intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, |
| 758 | int target, int refclk, intel_clock_t *best_clock) |
| 759 | { |
| 760 | struct drm_device *dev = crtc->dev; |
| 761 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 762 | intel_clock_t clock; |
| 763 | int max_n; |
| 764 | bool found; |
| 765 | /* approximately equals target * 0.00488 */ |
| 766 | int err_most = (target >> 8) + (target >> 10); |
| 767 | found = false; |
| 768 | |
| 769 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 770 | int lvds_reg; |
| 771 | |
| 772 | if (IS_IRONLAKE(dev)) |
| 773 | lvds_reg = PCH_LVDS; |
| 774 | else |
| 775 | lvds_reg = LVDS; |
| 776 | if ((I915_READ(lvds_reg) & LVDS_CLKB_POWER_MASK) == |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 777 | LVDS_CLKB_POWER_UP) |
| 778 | clock.p2 = limit->p2.p2_fast; |
| 779 | else |
| 780 | clock.p2 = limit->p2.p2_slow; |
| 781 | } else { |
| 782 | if (target < limit->p2.dot_limit) |
| 783 | clock.p2 = limit->p2.p2_slow; |
| 784 | else |
| 785 | clock.p2 = limit->p2.p2_fast; |
| 786 | } |
| 787 | |
| 788 | memset(best_clock, 0, sizeof(*best_clock)); |
| 789 | max_n = limit->n.max; |
| 790 | /* based on hardware requriment prefer smaller n to precision */ |
| 791 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 792 | /* based on hardware requirment prefere larger m1,m2 */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 793 | for (clock.m1 = limit->m1.max; |
| 794 | clock.m1 >= limit->m1.min; clock.m1--) { |
| 795 | for (clock.m2 = limit->m2.max; |
| 796 | clock.m2 >= limit->m2.min; clock.m2--) { |
| 797 | for (clock.p1 = limit->p1.max; |
| 798 | clock.p1 >= limit->p1.min; clock.p1--) { |
| 799 | int this_err; |
| 800 | |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 801 | intel_clock(dev, refclk, &clock); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 802 | if (!intel_PLL_is_valid(crtc, &clock)) |
| 803 | continue; |
| 804 | this_err = abs(clock.dot - target) ; |
| 805 | if (this_err < err_most) { |
| 806 | *best_clock = clock; |
| 807 | err_most = this_err; |
| 808 | max_n = clock.n; |
| 809 | found = true; |
| 810 | } |
| 811 | } |
| 812 | } |
| 813 | } |
| 814 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 815 | return found; |
| 816 | } |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 817 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 818 | static bool |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 819 | intel_find_pll_ironlake_dp(const intel_limit_t *limit, struct drm_crtc *crtc, |
| 820 | int target, int refclk, intel_clock_t *best_clock) |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 821 | { |
| 822 | struct drm_device *dev = crtc->dev; |
| 823 | intel_clock_t clock; |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 824 | |
| 825 | /* return directly when it is eDP */ |
| 826 | if (HAS_eDP) |
| 827 | return true; |
| 828 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 829 | if (target < 200000) { |
| 830 | clock.n = 1; |
| 831 | clock.p1 = 2; |
| 832 | clock.p2 = 10; |
| 833 | clock.m1 = 12; |
| 834 | clock.m2 = 9; |
| 835 | } else { |
| 836 | clock.n = 2; |
| 837 | clock.p1 = 1; |
| 838 | clock.p2 = 10; |
| 839 | clock.m1 = 14; |
| 840 | clock.m2 = 8; |
| 841 | } |
| 842 | intel_clock(dev, refclk, &clock); |
| 843 | memcpy(best_clock, &clock, sizeof(intel_clock_t)); |
| 844 | return true; |
| 845 | } |
| 846 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 847 | /* DisplayPort has only two frequencies, 162MHz and 270MHz */ |
| 848 | static bool |
| 849 | intel_find_pll_g4x_dp(const intel_limit_t *limit, struct drm_crtc *crtc, |
| 850 | int target, int refclk, intel_clock_t *best_clock) |
| 851 | { |
| 852 | intel_clock_t clock; |
| 853 | if (target < 200000) { |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 854 | clock.p1 = 2; |
| 855 | clock.p2 = 10; |
Keith Packard | b3d2549 | 2009-06-24 23:09:15 -0700 | [diff] [blame] | 856 | clock.n = 2; |
| 857 | clock.m1 = 23; |
| 858 | clock.m2 = 8; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 859 | } else { |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 860 | clock.p1 = 1; |
| 861 | clock.p2 = 10; |
Keith Packard | b3d2549 | 2009-06-24 23:09:15 -0700 | [diff] [blame] | 862 | clock.n = 1; |
| 863 | clock.m1 = 14; |
| 864 | clock.m2 = 2; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 865 | } |
Keith Packard | b3d2549 | 2009-06-24 23:09:15 -0700 | [diff] [blame] | 866 | clock.m = 5 * (clock.m1 + 2) + (clock.m2 + 2); |
| 867 | clock.p = (clock.p1 * clock.p2); |
| 868 | clock.dot = 96000 * clock.m / (clock.n + 2) / clock.p; |
Jesse Barnes | fe798b9 | 2009-10-20 07:55:28 +0900 | [diff] [blame] | 869 | clock.vco = 0; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 870 | memcpy(best_clock, &clock, sizeof(intel_clock_t)); |
| 871 | return true; |
| 872 | } |
| 873 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 874 | void |
| 875 | intel_wait_for_vblank(struct drm_device *dev) |
| 876 | { |
| 877 | /* Wait for 20ms, i.e. one cycle at 50hz. */ |
Shaohua Li | 311089d | 2009-11-26 14:22:41 +0800 | [diff] [blame] | 878 | msleep(20); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 879 | } |
| 880 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 881 | /* Parameters have changed, update FBC info */ |
| 882 | static void i8xx_enable_fbc(struct drm_crtc *crtc, unsigned long interval) |
| 883 | { |
| 884 | struct drm_device *dev = crtc->dev; |
| 885 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 886 | struct drm_framebuffer *fb = crtc->fb; |
| 887 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 888 | struct drm_i915_gem_object *obj_priv = intel_fb->obj->driver_private; |
| 889 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 890 | int plane, i; |
| 891 | u32 fbc_ctl, fbc_ctl2; |
| 892 | |
| 893 | dev_priv->cfb_pitch = dev_priv->cfb_size / FBC_LL_SIZE; |
| 894 | |
| 895 | if (fb->pitch < dev_priv->cfb_pitch) |
| 896 | dev_priv->cfb_pitch = fb->pitch; |
| 897 | |
| 898 | /* FBC_CTL wants 64B units */ |
| 899 | dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1; |
| 900 | dev_priv->cfb_fence = obj_priv->fence_reg; |
| 901 | dev_priv->cfb_plane = intel_crtc->plane; |
| 902 | plane = dev_priv->cfb_plane == 0 ? FBC_CTL_PLANEA : FBC_CTL_PLANEB; |
| 903 | |
| 904 | /* Clear old tags */ |
| 905 | for (i = 0; i < (FBC_LL_SIZE / 32) + 1; i++) |
| 906 | I915_WRITE(FBC_TAG + (i * 4), 0); |
| 907 | |
| 908 | /* Set it up... */ |
| 909 | fbc_ctl2 = FBC_CTL_FENCE_DBL | FBC_CTL_IDLE_IMM | plane; |
| 910 | if (obj_priv->tiling_mode != I915_TILING_NONE) |
| 911 | fbc_ctl2 |= FBC_CTL_CPU_FENCE; |
| 912 | I915_WRITE(FBC_CONTROL2, fbc_ctl2); |
| 913 | I915_WRITE(FBC_FENCE_OFF, crtc->y); |
| 914 | |
| 915 | /* enable it... */ |
| 916 | fbc_ctl = FBC_CTL_EN | FBC_CTL_PERIODIC; |
| 917 | fbc_ctl |= (dev_priv->cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT; |
| 918 | fbc_ctl |= (interval & 0x2fff) << FBC_CTL_INTERVAL_SHIFT; |
| 919 | if (obj_priv->tiling_mode != I915_TILING_NONE) |
| 920 | fbc_ctl |= dev_priv->cfb_fence; |
| 921 | I915_WRITE(FBC_CONTROL, fbc_ctl); |
| 922 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 923 | DRM_DEBUG_KMS("enabled FBC, pitch %ld, yoff %d, plane %d, ", |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 924 | dev_priv->cfb_pitch, crtc->y, dev_priv->cfb_plane); |
| 925 | } |
| 926 | |
| 927 | void i8xx_disable_fbc(struct drm_device *dev) |
| 928 | { |
| 929 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 930 | u32 fbc_ctl; |
| 931 | |
Jesse Barnes | c1a1cdc | 2009-09-16 15:05:00 -0700 | [diff] [blame] | 932 | if (!I915_HAS_FBC(dev)) |
| 933 | return; |
| 934 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 935 | /* Disable compression */ |
| 936 | fbc_ctl = I915_READ(FBC_CONTROL); |
| 937 | fbc_ctl &= ~FBC_CTL_EN; |
| 938 | I915_WRITE(FBC_CONTROL, fbc_ctl); |
| 939 | |
| 940 | /* Wait for compressing bit to clear */ |
| 941 | while (I915_READ(FBC_STATUS) & FBC_STAT_COMPRESSING) |
| 942 | ; /* nothing */ |
| 943 | |
| 944 | intel_wait_for_vblank(dev); |
| 945 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 946 | DRM_DEBUG_KMS("disabled FBC\n"); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | static bool i8xx_fbc_enabled(struct drm_crtc *crtc) |
| 950 | { |
| 951 | struct drm_device *dev = crtc->dev; |
| 952 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 953 | |
| 954 | return I915_READ(FBC_CONTROL) & FBC_CTL_EN; |
| 955 | } |
| 956 | |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 957 | static void g4x_enable_fbc(struct drm_crtc *crtc, unsigned long interval) |
| 958 | { |
| 959 | struct drm_device *dev = crtc->dev; |
| 960 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 961 | struct drm_framebuffer *fb = crtc->fb; |
| 962 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 963 | struct drm_i915_gem_object *obj_priv = intel_fb->obj->driver_private; |
| 964 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 965 | int plane = (intel_crtc->plane == 0 ? DPFC_CTL_PLANEA : |
| 966 | DPFC_CTL_PLANEB); |
| 967 | unsigned long stall_watermark = 200; |
| 968 | u32 dpfc_ctl; |
| 969 | |
| 970 | dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1; |
| 971 | dev_priv->cfb_fence = obj_priv->fence_reg; |
| 972 | dev_priv->cfb_plane = intel_crtc->plane; |
| 973 | |
| 974 | dpfc_ctl = plane | DPFC_SR_EN | DPFC_CTL_LIMIT_1X; |
| 975 | if (obj_priv->tiling_mode != I915_TILING_NONE) { |
| 976 | dpfc_ctl |= DPFC_CTL_FENCE_EN | dev_priv->cfb_fence; |
| 977 | I915_WRITE(DPFC_CHICKEN, DPFC_HT_MODIFY); |
| 978 | } else { |
| 979 | I915_WRITE(DPFC_CHICKEN, ~DPFC_HT_MODIFY); |
| 980 | } |
| 981 | |
| 982 | I915_WRITE(DPFC_CONTROL, dpfc_ctl); |
| 983 | I915_WRITE(DPFC_RECOMP_CTL, DPFC_RECOMP_STALL_EN | |
| 984 | (stall_watermark << DPFC_RECOMP_STALL_WM_SHIFT) | |
| 985 | (interval << DPFC_RECOMP_TIMER_COUNT_SHIFT)); |
| 986 | I915_WRITE(DPFC_FENCE_YOFF, crtc->y); |
| 987 | |
| 988 | /* enable it... */ |
| 989 | I915_WRITE(DPFC_CONTROL, I915_READ(DPFC_CONTROL) | DPFC_CTL_EN); |
| 990 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 991 | DRM_DEBUG_KMS("enabled fbc on plane %d\n", intel_crtc->plane); |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | void g4x_disable_fbc(struct drm_device *dev) |
| 995 | { |
| 996 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 997 | u32 dpfc_ctl; |
| 998 | |
| 999 | /* Disable compression */ |
| 1000 | dpfc_ctl = I915_READ(DPFC_CONTROL); |
| 1001 | dpfc_ctl &= ~DPFC_CTL_EN; |
| 1002 | I915_WRITE(DPFC_CONTROL, dpfc_ctl); |
| 1003 | intel_wait_for_vblank(dev); |
| 1004 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1005 | DRM_DEBUG_KMS("disabled FBC\n"); |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | static bool g4x_fbc_enabled(struct drm_crtc *crtc) |
| 1009 | { |
| 1010 | struct drm_device *dev = crtc->dev; |
| 1011 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1012 | |
| 1013 | return I915_READ(DPFC_CONTROL) & DPFC_CTL_EN; |
| 1014 | } |
| 1015 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1016 | /** |
| 1017 | * intel_update_fbc - enable/disable FBC as needed |
| 1018 | * @crtc: CRTC to point the compressor at |
| 1019 | * @mode: mode in use |
| 1020 | * |
| 1021 | * Set up the framebuffer compression hardware at mode set time. We |
| 1022 | * enable it if possible: |
| 1023 | * - plane A only (on pre-965) |
| 1024 | * - no pixel mulitply/line duplication |
| 1025 | * - no alpha buffer discard |
| 1026 | * - no dual wide |
| 1027 | * - framebuffer <= 2048 in width, 1536 in height |
| 1028 | * |
| 1029 | * We can't assume that any compression will take place (worst case), |
| 1030 | * so the compressed buffer has to be the same size as the uncompressed |
| 1031 | * one. It also must reside (along with the line length buffer) in |
| 1032 | * stolen memory. |
| 1033 | * |
| 1034 | * We need to enable/disable FBC on a global basis. |
| 1035 | */ |
| 1036 | static void intel_update_fbc(struct drm_crtc *crtc, |
| 1037 | struct drm_display_mode *mode) |
| 1038 | { |
| 1039 | struct drm_device *dev = crtc->dev; |
| 1040 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1041 | struct drm_framebuffer *fb = crtc->fb; |
| 1042 | struct intel_framebuffer *intel_fb; |
| 1043 | struct drm_i915_gem_object *obj_priv; |
| 1044 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1045 | int plane = intel_crtc->plane; |
| 1046 | |
| 1047 | if (!i915_powersave) |
| 1048 | return; |
| 1049 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 1050 | if (!dev_priv->display.fbc_enabled || |
| 1051 | !dev_priv->display.enable_fbc || |
| 1052 | !dev_priv->display.disable_fbc) |
| 1053 | return; |
| 1054 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1055 | if (!crtc->fb) |
| 1056 | return; |
| 1057 | |
| 1058 | intel_fb = to_intel_framebuffer(fb); |
| 1059 | obj_priv = intel_fb->obj->driver_private; |
| 1060 | |
| 1061 | /* |
| 1062 | * If FBC is already on, we just have to verify that we can |
| 1063 | * keep it that way... |
| 1064 | * Need to disable if: |
| 1065 | * - changing FBC params (stride, fence, mode) |
| 1066 | * - new fb is too large to fit in compressed buffer |
| 1067 | * - going to an unsupported config (interlace, pixel multiply, etc.) |
| 1068 | */ |
| 1069 | if (intel_fb->obj->size > dev_priv->cfb_size) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1070 | DRM_DEBUG_KMS("framebuffer too large, disabling " |
| 1071 | "compression\n"); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1072 | goto out_disable; |
| 1073 | } |
| 1074 | if ((mode->flags & DRM_MODE_FLAG_INTERLACE) || |
| 1075 | (mode->flags & DRM_MODE_FLAG_DBLSCAN)) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1076 | DRM_DEBUG_KMS("mode incompatible with compression, " |
| 1077 | "disabling\n"); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1078 | goto out_disable; |
| 1079 | } |
| 1080 | if ((mode->hdisplay > 2048) || |
| 1081 | (mode->vdisplay > 1536)) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1082 | DRM_DEBUG_KMS("mode too large for compression, disabling\n"); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1083 | goto out_disable; |
| 1084 | } |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 1085 | if ((IS_I915GM(dev) || IS_I945GM(dev)) && plane != 0) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1086 | DRM_DEBUG_KMS("plane not 0, disabling compression\n"); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1087 | goto out_disable; |
| 1088 | } |
| 1089 | if (obj_priv->tiling_mode != I915_TILING_X) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1090 | DRM_DEBUG_KMS("framebuffer not tiled, disabling compression\n"); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1091 | goto out_disable; |
| 1092 | } |
| 1093 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 1094 | if (dev_priv->display.fbc_enabled(crtc)) { |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1095 | /* We can re-enable it in this case, but need to update pitch */ |
| 1096 | if (fb->pitch > dev_priv->cfb_pitch) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 1097 | dev_priv->display.disable_fbc(dev); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1098 | if (obj_priv->fence_reg != dev_priv->cfb_fence) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 1099 | dev_priv->display.disable_fbc(dev); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1100 | if (plane != dev_priv->cfb_plane) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 1101 | dev_priv->display.disable_fbc(dev); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 1104 | if (!dev_priv->display.fbc_enabled(crtc)) { |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1105 | /* Now try to turn it back on if possible */ |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 1106 | dev_priv->display.enable_fbc(crtc, 500); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | return; |
| 1110 | |
| 1111 | out_disable: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1112 | DRM_DEBUG_KMS("unsupported config, disabling FBC\n"); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1113 | /* Multiple disables should be harmless */ |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 1114 | if (dev_priv->display.fbc_enabled(crtc)) |
| 1115 | dev_priv->display.disable_fbc(dev); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1116 | } |
| 1117 | |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1118 | static int |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1119 | intel_pin_and_fence_fb_obj(struct drm_device *dev, struct drm_gem_object *obj) |
| 1120 | { |
| 1121 | struct drm_i915_gem_object *obj_priv = obj->driver_private; |
| 1122 | u32 alignment; |
| 1123 | int ret; |
| 1124 | |
| 1125 | switch (obj_priv->tiling_mode) { |
| 1126 | case I915_TILING_NONE: |
| 1127 | alignment = 64 * 1024; |
| 1128 | break; |
| 1129 | case I915_TILING_X: |
| 1130 | /* pin() will align the object as required by fence */ |
| 1131 | alignment = 0; |
| 1132 | break; |
| 1133 | case I915_TILING_Y: |
| 1134 | /* FIXME: Is this true? */ |
| 1135 | DRM_ERROR("Y tiled not allowed for scan out buffers\n"); |
| 1136 | return -EINVAL; |
| 1137 | default: |
| 1138 | BUG(); |
| 1139 | } |
| 1140 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1141 | ret = i915_gem_object_pin(obj, alignment); |
| 1142 | if (ret != 0) |
| 1143 | return ret; |
| 1144 | |
| 1145 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
| 1146 | * fence, whereas 965+ only requires a fence if using |
| 1147 | * framebuffer compression. For simplicity, we always install |
| 1148 | * a fence as the cost is not that onerous. |
| 1149 | */ |
| 1150 | if (obj_priv->fence_reg == I915_FENCE_REG_NONE && |
| 1151 | obj_priv->tiling_mode != I915_TILING_NONE) { |
| 1152 | ret = i915_gem_object_get_fence_reg(obj); |
| 1153 | if (ret != 0) { |
| 1154 | i915_gem_object_unpin(obj); |
| 1155 | return ret; |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | return 0; |
| 1160 | } |
| 1161 | |
| 1162 | static int |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 1163 | intel_pipe_set_base(struct drm_crtc *crtc, int x, int y, |
| 1164 | struct drm_framebuffer *old_fb) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1165 | { |
| 1166 | struct drm_device *dev = crtc->dev; |
| 1167 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1168 | struct drm_i915_master_private *master_priv; |
| 1169 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1170 | struct intel_framebuffer *intel_fb; |
| 1171 | struct drm_i915_gem_object *obj_priv; |
| 1172 | struct drm_gem_object *obj; |
| 1173 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1174 | int plane = intel_crtc->plane; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1175 | unsigned long Start, Offset; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1176 | int dspbase = (plane == 0 ? DSPAADDR : DSPBADDR); |
| 1177 | int dspsurf = (plane == 0 ? DSPASURF : DSPBSURF); |
| 1178 | int dspstride = (plane == 0) ? DSPASTRIDE : DSPBSTRIDE; |
| 1179 | int dsptileoff = (plane == 0 ? DSPATILEOFF : DSPBTILEOFF); |
| 1180 | int dspcntr_reg = (plane == 0) ? DSPACNTR : DSPBCNTR; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1181 | u32 dspcntr; |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1182 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1183 | |
| 1184 | /* no fb bound */ |
| 1185 | if (!crtc->fb) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1186 | DRM_DEBUG_KMS("No FB bound\n"); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1187 | return 0; |
| 1188 | } |
| 1189 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1190 | switch (plane) { |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1191 | case 0: |
| 1192 | case 1: |
| 1193 | break; |
| 1194 | default: |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1195 | DRM_ERROR("Can't update plane %d in SAREA\n", plane); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1196 | return -EINVAL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | intel_fb = to_intel_framebuffer(crtc->fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1200 | obj = intel_fb->obj; |
| 1201 | obj_priv = obj->driver_private; |
| 1202 | |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1203 | mutex_lock(&dev->struct_mutex); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1204 | ret = intel_pin_and_fence_fb_obj(dev, obj); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1205 | if (ret != 0) { |
| 1206 | mutex_unlock(&dev->struct_mutex); |
| 1207 | return ret; |
| 1208 | } |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 1209 | |
Zhenyu Wang | b9241ea | 2009-11-25 13:09:39 +0800 | [diff] [blame^] | 1210 | ret = i915_gem_object_set_to_display_plane(obj); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1211 | if (ret != 0) { |
Chris Wilson | 8c4b8c3 | 2009-06-17 22:08:52 +0100 | [diff] [blame] | 1212 | i915_gem_object_unpin(obj); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1213 | mutex_unlock(&dev->struct_mutex); |
| 1214 | return ret; |
| 1215 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1216 | |
| 1217 | dspcntr = I915_READ(dspcntr_reg); |
Jesse Barnes | 712531b | 2009-01-09 13:56:14 -0800 | [diff] [blame] | 1218 | /* Mask out pixel format bits in case we change it */ |
| 1219 | dspcntr &= ~DISPPLANE_PIXFORMAT_MASK; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1220 | switch (crtc->fb->bits_per_pixel) { |
| 1221 | case 8: |
| 1222 | dspcntr |= DISPPLANE_8BPP; |
| 1223 | break; |
| 1224 | case 16: |
| 1225 | if (crtc->fb->depth == 15) |
| 1226 | dspcntr |= DISPPLANE_15_16BPP; |
| 1227 | else |
| 1228 | dspcntr |= DISPPLANE_16BPP; |
| 1229 | break; |
| 1230 | case 24: |
| 1231 | case 32: |
Kristian Høgsberg | a4f45cf | 2009-10-19 14:35:30 -0400 | [diff] [blame] | 1232 | if (crtc->fb->depth == 30) |
| 1233 | dspcntr |= DISPPLANE_32BPP_30BIT_NO_ALPHA; |
| 1234 | else |
| 1235 | dspcntr |= DISPPLANE_32BPP_NO_ALPHA; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1236 | break; |
| 1237 | default: |
| 1238 | DRM_ERROR("Unknown color depth\n"); |
Chris Wilson | 8c4b8c3 | 2009-06-17 22:08:52 +0100 | [diff] [blame] | 1239 | i915_gem_object_unpin(obj); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1240 | mutex_unlock(&dev->struct_mutex); |
| 1241 | return -EINVAL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1242 | } |
Jesse Barnes | f544847 | 2009-04-14 14:17:47 -0700 | [diff] [blame] | 1243 | if (IS_I965G(dev)) { |
| 1244 | if (obj_priv->tiling_mode != I915_TILING_NONE) |
| 1245 | dspcntr |= DISPPLANE_TILED; |
| 1246 | else |
| 1247 | dspcntr &= ~DISPPLANE_TILED; |
| 1248 | } |
| 1249 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 1250 | if (IS_IRONLAKE(dev)) |
Zhenyu Wang | 553bd14 | 2009-09-02 10:57:52 +0800 | [diff] [blame] | 1251 | /* must disable */ |
| 1252 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
| 1253 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1254 | I915_WRITE(dspcntr_reg, dspcntr); |
| 1255 | |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1256 | Start = obj_priv->gtt_offset; |
| 1257 | Offset = y * crtc->fb->pitch + x * (crtc->fb->bits_per_pixel / 8); |
| 1258 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1259 | DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d\n", Start, Offset, x, y); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1260 | I915_WRITE(dspstride, crtc->fb->pitch); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1261 | if (IS_I965G(dev)) { |
| 1262 | I915_WRITE(dspbase, Offset); |
| 1263 | I915_READ(dspbase); |
| 1264 | I915_WRITE(dspsurf, Start); |
| 1265 | I915_READ(dspsurf); |
Jesse Barnes | f544847 | 2009-04-14 14:17:47 -0700 | [diff] [blame] | 1266 | I915_WRITE(dsptileoff, (y << 16) | x); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1267 | } else { |
| 1268 | I915_WRITE(dspbase, Start + Offset); |
| 1269 | I915_READ(dspbase); |
| 1270 | } |
| 1271 | |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 1272 | if ((IS_I965G(dev) || plane == 0)) |
Jesse Barnes | edb8195 | 2009-09-17 17:06:47 -0700 | [diff] [blame] | 1273 | intel_update_fbc(crtc, &crtc->mode); |
| 1274 | |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 1275 | intel_wait_for_vblank(dev); |
| 1276 | |
| 1277 | if (old_fb) { |
| 1278 | intel_fb = to_intel_framebuffer(old_fb); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 1279 | obj_priv = intel_fb->obj->driver_private; |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 1280 | i915_gem_object_unpin(intel_fb->obj); |
| 1281 | } |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 1282 | intel_increase_pllclock(crtc, true); |
| 1283 | |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1284 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1285 | |
| 1286 | if (!dev->primary->master) |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1287 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1288 | |
| 1289 | master_priv = dev->primary->master->driver_priv; |
| 1290 | if (!master_priv->sarea_priv) |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1291 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1292 | |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1293 | if (pipe) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1294 | master_priv->sarea_priv->pipeB_x = x; |
| 1295 | master_priv->sarea_priv->pipeB_y = y; |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1296 | } else { |
| 1297 | master_priv->sarea_priv->pipeA_x = x; |
| 1298 | master_priv->sarea_priv->pipeA_y = y; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1299 | } |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 1300 | |
| 1301 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1302 | } |
| 1303 | |
Zhenyu Wang | 24f119c | 2009-07-24 01:00:28 +0800 | [diff] [blame] | 1304 | /* Disable the VGA plane that we never use */ |
| 1305 | static void i915_disable_vga (struct drm_device *dev) |
| 1306 | { |
| 1307 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1308 | u8 sr1; |
| 1309 | u32 vga_reg; |
| 1310 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 1311 | if (IS_IRONLAKE(dev)) |
Zhenyu Wang | 24f119c | 2009-07-24 01:00:28 +0800 | [diff] [blame] | 1312 | vga_reg = CPU_VGACNTRL; |
| 1313 | else |
| 1314 | vga_reg = VGACNTRL; |
| 1315 | |
| 1316 | if (I915_READ(vga_reg) & VGA_DISP_DISABLE) |
| 1317 | return; |
| 1318 | |
| 1319 | I915_WRITE8(VGA_SR_INDEX, 1); |
| 1320 | sr1 = I915_READ8(VGA_SR_DATA); |
| 1321 | I915_WRITE8(VGA_SR_DATA, sr1 | (1 << 5)); |
| 1322 | udelay(100); |
| 1323 | |
| 1324 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
| 1325 | } |
| 1326 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 1327 | static void ironlake_disable_pll_edp (struct drm_crtc *crtc) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1328 | { |
| 1329 | struct drm_device *dev = crtc->dev; |
| 1330 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1331 | u32 dpa_ctl; |
| 1332 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1333 | DRM_DEBUG_KMS("\n"); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1334 | dpa_ctl = I915_READ(DP_A); |
| 1335 | dpa_ctl &= ~DP_PLL_ENABLE; |
| 1336 | I915_WRITE(DP_A, dpa_ctl); |
| 1337 | } |
| 1338 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 1339 | static void ironlake_enable_pll_edp (struct drm_crtc *crtc) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1340 | { |
| 1341 | struct drm_device *dev = crtc->dev; |
| 1342 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1343 | u32 dpa_ctl; |
| 1344 | |
| 1345 | dpa_ctl = I915_READ(DP_A); |
| 1346 | dpa_ctl |= DP_PLL_ENABLE; |
| 1347 | I915_WRITE(DP_A, dpa_ctl); |
| 1348 | udelay(200); |
| 1349 | } |
| 1350 | |
| 1351 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 1352 | static void ironlake_set_pll_edp (struct drm_crtc *crtc, int clock) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1353 | { |
| 1354 | struct drm_device *dev = crtc->dev; |
| 1355 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1356 | u32 dpa_ctl; |
| 1357 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1358 | DRM_DEBUG_KMS("eDP PLL enable for clock %d\n", clock); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1359 | dpa_ctl = I915_READ(DP_A); |
| 1360 | dpa_ctl &= ~DP_PLL_FREQ_MASK; |
| 1361 | |
| 1362 | if (clock < 200000) { |
| 1363 | u32 temp; |
| 1364 | dpa_ctl |= DP_PLL_FREQ_160MHZ; |
| 1365 | /* workaround for 160Mhz: |
| 1366 | 1) program 0x4600c bits 15:0 = 0x8124 |
| 1367 | 2) program 0x46010 bit 0 = 1 |
| 1368 | 3) program 0x46034 bit 24 = 1 |
| 1369 | 4) program 0x64000 bit 14 = 1 |
| 1370 | */ |
| 1371 | temp = I915_READ(0x4600c); |
| 1372 | temp &= 0xffff0000; |
| 1373 | I915_WRITE(0x4600c, temp | 0x8124); |
| 1374 | |
| 1375 | temp = I915_READ(0x46010); |
| 1376 | I915_WRITE(0x46010, temp | 1); |
| 1377 | |
| 1378 | temp = I915_READ(0x46034); |
| 1379 | I915_WRITE(0x46034, temp | (1 << 24)); |
| 1380 | } else { |
| 1381 | dpa_ctl |= DP_PLL_FREQ_270MHZ; |
| 1382 | } |
| 1383 | I915_WRITE(DP_A, dpa_ctl); |
| 1384 | |
| 1385 | udelay(500); |
| 1386 | } |
| 1387 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 1388 | static void ironlake_crtc_dpms(struct drm_crtc *crtc, int mode) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1389 | { |
| 1390 | struct drm_device *dev = crtc->dev; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1391 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1392 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1393 | int pipe = intel_crtc->pipe; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 1394 | int plane = intel_crtc->plane; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1395 | int pch_dpll_reg = (pipe == 0) ? PCH_DPLL_A : PCH_DPLL_B; |
| 1396 | int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF; |
| 1397 | int dspcntr_reg = (plane == 0) ? DSPACNTR : DSPBCNTR; |
| 1398 | int dspbase_reg = (plane == 0) ? DSPAADDR : DSPBADDR; |
| 1399 | int fdi_tx_reg = (pipe == 0) ? FDI_TXA_CTL : FDI_TXB_CTL; |
| 1400 | int fdi_rx_reg = (pipe == 0) ? FDI_RXA_CTL : FDI_RXB_CTL; |
| 1401 | int fdi_rx_iir_reg = (pipe == 0) ? FDI_RXA_IIR : FDI_RXB_IIR; |
| 1402 | int fdi_rx_imr_reg = (pipe == 0) ? FDI_RXA_IMR : FDI_RXB_IMR; |
| 1403 | int transconf_reg = (pipe == 0) ? TRANSACONF : TRANSBCONF; |
| 1404 | int pf_ctl_reg = (pipe == 0) ? PFA_CTL_1 : PFB_CTL_1; |
Zhenyu Wang | 249c0e6 | 2009-07-24 01:00:29 +0800 | [diff] [blame] | 1405 | int pf_win_size = (pipe == 0) ? PFA_WIN_SZ : PFB_WIN_SZ; |
Zhenyu Wang | 8dd81a3 | 2009-09-19 14:54:09 +0800 | [diff] [blame] | 1406 | int pf_win_pos = (pipe == 0) ? PFA_WIN_POS : PFB_WIN_POS; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1407 | int cpu_htot_reg = (pipe == 0) ? HTOTAL_A : HTOTAL_B; |
| 1408 | int cpu_hblank_reg = (pipe == 0) ? HBLANK_A : HBLANK_B; |
| 1409 | int cpu_hsync_reg = (pipe == 0) ? HSYNC_A : HSYNC_B; |
| 1410 | int cpu_vtot_reg = (pipe == 0) ? VTOTAL_A : VTOTAL_B; |
| 1411 | int cpu_vblank_reg = (pipe == 0) ? VBLANK_A : VBLANK_B; |
| 1412 | int cpu_vsync_reg = (pipe == 0) ? VSYNC_A : VSYNC_B; |
| 1413 | int trans_htot_reg = (pipe == 0) ? TRANS_HTOTAL_A : TRANS_HTOTAL_B; |
| 1414 | int trans_hblank_reg = (pipe == 0) ? TRANS_HBLANK_A : TRANS_HBLANK_B; |
| 1415 | int trans_hsync_reg = (pipe == 0) ? TRANS_HSYNC_A : TRANS_HSYNC_B; |
| 1416 | int trans_vtot_reg = (pipe == 0) ? TRANS_VTOTAL_A : TRANS_VTOTAL_B; |
| 1417 | int trans_vblank_reg = (pipe == 0) ? TRANS_VBLANK_A : TRANS_VBLANK_B; |
| 1418 | int trans_vsync_reg = (pipe == 0) ? TRANS_VSYNC_A : TRANS_VSYNC_B; |
| 1419 | u32 temp; |
Zhenyu Wang | 249c0e6 | 2009-07-24 01:00:29 +0800 | [diff] [blame] | 1420 | int tries = 5, j, n; |
Zhao Yakui | 8faf3b3 | 2010-01-04 16:29:31 +0800 | [diff] [blame] | 1421 | u32 pipe_bpc; |
| 1422 | |
| 1423 | temp = I915_READ(pipeconf_reg); |
| 1424 | pipe_bpc = temp & PIPE_BPC_MASK; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1425 | |
| 1426 | /* XXX: When our outputs are all unaware of DPMS modes other than off |
| 1427 | * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC. |
| 1428 | */ |
| 1429 | switch (mode) { |
| 1430 | case DRM_MODE_DPMS_ON: |
| 1431 | case DRM_MODE_DPMS_STANDBY: |
| 1432 | case DRM_MODE_DPMS_SUSPEND: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1433 | DRM_DEBUG_KMS("crtc %d dpms on\n", pipe); |
Zhenyu Wang | 1b3c7a4 | 2009-11-25 13:09:38 +0800 | [diff] [blame] | 1434 | |
| 1435 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
| 1436 | temp = I915_READ(PCH_LVDS); |
| 1437 | if ((temp & LVDS_PORT_EN) == 0) { |
| 1438 | I915_WRITE(PCH_LVDS, temp | LVDS_PORT_EN); |
| 1439 | POSTING_READ(PCH_LVDS); |
| 1440 | } |
| 1441 | } |
| 1442 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1443 | if (HAS_eDP) { |
| 1444 | /* enable eDP PLL */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 1445 | ironlake_enable_pll_edp(crtc); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1446 | } else { |
| 1447 | /* enable PCH DPLL */ |
| 1448 | temp = I915_READ(pch_dpll_reg); |
| 1449 | if ((temp & DPLL_VCO_ENABLE) == 0) { |
| 1450 | I915_WRITE(pch_dpll_reg, temp | DPLL_VCO_ENABLE); |
| 1451 | I915_READ(pch_dpll_reg); |
| 1452 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1453 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1454 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
| 1455 | temp = I915_READ(fdi_rx_reg); |
Zhao Yakui | 8faf3b3 | 2010-01-04 16:29:31 +0800 | [diff] [blame] | 1456 | /* |
| 1457 | * make the BPC in FDI Rx be consistent with that in |
| 1458 | * pipeconf reg. |
| 1459 | */ |
| 1460 | temp &= ~(0x7 << 16); |
| 1461 | temp |= (pipe_bpc << 11); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1462 | I915_WRITE(fdi_rx_reg, temp | FDI_RX_PLL_ENABLE | |
| 1463 | FDI_SEL_PCDCLK | |
| 1464 | FDI_DP_PORT_WIDTH_X4); /* default 4 lanes */ |
| 1465 | I915_READ(fdi_rx_reg); |
| 1466 | udelay(200); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1467 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 1468 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1469 | temp = I915_READ(fdi_tx_reg); |
| 1470 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { |
| 1471 | I915_WRITE(fdi_tx_reg, temp | FDI_TX_PLL_ENABLE); |
| 1472 | I915_READ(fdi_tx_reg); |
| 1473 | udelay(100); |
| 1474 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1475 | } |
| 1476 | |
Zhenyu Wang | 8dd81a3 | 2009-09-19 14:54:09 +0800 | [diff] [blame] | 1477 | /* Enable panel fitting for LVDS */ |
| 1478 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
| 1479 | temp = I915_READ(pf_ctl_reg); |
Zhenyu Wang | b1f60b7 | 2009-10-19 15:43:49 +0800 | [diff] [blame] | 1480 | I915_WRITE(pf_ctl_reg, temp | PF_ENABLE | PF_FILTER_MED_3x3); |
Zhenyu Wang | 8dd81a3 | 2009-09-19 14:54:09 +0800 | [diff] [blame] | 1481 | |
| 1482 | /* currently full aspect */ |
| 1483 | I915_WRITE(pf_win_pos, 0); |
| 1484 | |
| 1485 | I915_WRITE(pf_win_size, |
| 1486 | (dev_priv->panel_fixed_mode->hdisplay << 16) | |
| 1487 | (dev_priv->panel_fixed_mode->vdisplay)); |
| 1488 | } |
| 1489 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1490 | /* Enable CPU pipe */ |
| 1491 | temp = I915_READ(pipeconf_reg); |
| 1492 | if ((temp & PIPEACONF_ENABLE) == 0) { |
| 1493 | I915_WRITE(pipeconf_reg, temp | PIPEACONF_ENABLE); |
| 1494 | I915_READ(pipeconf_reg); |
| 1495 | udelay(100); |
| 1496 | } |
| 1497 | |
| 1498 | /* configure and enable CPU plane */ |
| 1499 | temp = I915_READ(dspcntr_reg); |
| 1500 | if ((temp & DISPLAY_PLANE_ENABLE) == 0) { |
| 1501 | I915_WRITE(dspcntr_reg, temp | DISPLAY_PLANE_ENABLE); |
| 1502 | /* Flush the plane changes */ |
| 1503 | I915_WRITE(dspbase_reg, I915_READ(dspbase_reg)); |
| 1504 | } |
| 1505 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1506 | if (!HAS_eDP) { |
| 1507 | /* enable CPU FDI TX and PCH FDI RX */ |
| 1508 | temp = I915_READ(fdi_tx_reg); |
| 1509 | temp |= FDI_TX_ENABLE; |
| 1510 | temp |= FDI_DP_PORT_WIDTH_X4; /* default */ |
| 1511 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 1512 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 1513 | I915_WRITE(fdi_tx_reg, temp); |
| 1514 | I915_READ(fdi_tx_reg); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1515 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1516 | temp = I915_READ(fdi_rx_reg); |
| 1517 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 1518 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 1519 | I915_WRITE(fdi_rx_reg, temp | FDI_RX_ENABLE); |
| 1520 | I915_READ(fdi_rx_reg); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1521 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1522 | udelay(150); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1523 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1524 | /* Train FDI. */ |
| 1525 | /* umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 1526 | for train result */ |
| 1527 | temp = I915_READ(fdi_rx_imr_reg); |
| 1528 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 1529 | temp &= ~FDI_RX_BIT_LOCK; |
| 1530 | I915_WRITE(fdi_rx_imr_reg, temp); |
| 1531 | I915_READ(fdi_rx_imr_reg); |
| 1532 | udelay(150); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1533 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1534 | temp = I915_READ(fdi_rx_iir_reg); |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1535 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1536 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1537 | if ((temp & FDI_RX_BIT_LOCK) == 0) { |
| 1538 | for (j = 0; j < tries; j++) { |
| 1539 | temp = I915_READ(fdi_rx_iir_reg); |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1540 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", |
| 1541 | temp); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1542 | if (temp & FDI_RX_BIT_LOCK) |
| 1543 | break; |
| 1544 | udelay(200); |
| 1545 | } |
| 1546 | if (j != tries) |
| 1547 | I915_WRITE(fdi_rx_iir_reg, |
| 1548 | temp | FDI_RX_BIT_LOCK); |
| 1549 | else |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1550 | DRM_DEBUG_KMS("train 1 fail\n"); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1551 | } else { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1552 | I915_WRITE(fdi_rx_iir_reg, |
| 1553 | temp | FDI_RX_BIT_LOCK); |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1554 | DRM_DEBUG_KMS("train 1 ok 2!\n"); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1555 | } |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1556 | temp = I915_READ(fdi_tx_reg); |
| 1557 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 1558 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 1559 | I915_WRITE(fdi_tx_reg, temp); |
| 1560 | |
| 1561 | temp = I915_READ(fdi_rx_reg); |
| 1562 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 1563 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 1564 | I915_WRITE(fdi_rx_reg, temp); |
| 1565 | |
| 1566 | udelay(150); |
| 1567 | |
| 1568 | temp = I915_READ(fdi_rx_iir_reg); |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1569 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1570 | |
| 1571 | if ((temp & FDI_RX_SYMBOL_LOCK) == 0) { |
| 1572 | for (j = 0; j < tries; j++) { |
| 1573 | temp = I915_READ(fdi_rx_iir_reg); |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1574 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", |
| 1575 | temp); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1576 | if (temp & FDI_RX_SYMBOL_LOCK) |
| 1577 | break; |
| 1578 | udelay(200); |
| 1579 | } |
| 1580 | if (j != tries) { |
| 1581 | I915_WRITE(fdi_rx_iir_reg, |
| 1582 | temp | FDI_RX_SYMBOL_LOCK); |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1583 | DRM_DEBUG_KMS("train 2 ok 1!\n"); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1584 | } else |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1585 | DRM_DEBUG_KMS("train 2 fail\n"); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1586 | } else { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1587 | I915_WRITE(fdi_rx_iir_reg, |
| 1588 | temp | FDI_RX_SYMBOL_LOCK); |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1589 | DRM_DEBUG_KMS("train 2 ok 2!\n"); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1590 | } |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1591 | DRM_DEBUG_KMS("train done\n"); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1592 | |
| 1593 | /* set transcoder timing */ |
| 1594 | I915_WRITE(trans_htot_reg, I915_READ(cpu_htot_reg)); |
| 1595 | I915_WRITE(trans_hblank_reg, I915_READ(cpu_hblank_reg)); |
| 1596 | I915_WRITE(trans_hsync_reg, I915_READ(cpu_hsync_reg)); |
| 1597 | |
| 1598 | I915_WRITE(trans_vtot_reg, I915_READ(cpu_vtot_reg)); |
| 1599 | I915_WRITE(trans_vblank_reg, I915_READ(cpu_vblank_reg)); |
| 1600 | I915_WRITE(trans_vsync_reg, I915_READ(cpu_vsync_reg)); |
| 1601 | |
| 1602 | /* enable PCH transcoder */ |
| 1603 | temp = I915_READ(transconf_reg); |
Zhao Yakui | 8faf3b3 | 2010-01-04 16:29:31 +0800 | [diff] [blame] | 1604 | /* |
| 1605 | * make the BPC in transcoder be consistent with |
| 1606 | * that in pipeconf reg. |
| 1607 | */ |
| 1608 | temp &= ~PIPE_BPC_MASK; |
| 1609 | temp |= pipe_bpc; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1610 | I915_WRITE(transconf_reg, temp | TRANS_ENABLE); |
| 1611 | I915_READ(transconf_reg); |
| 1612 | |
| 1613 | while ((I915_READ(transconf_reg) & TRANS_STATE_ENABLE) == 0) |
| 1614 | ; |
| 1615 | |
| 1616 | /* enable normal */ |
| 1617 | |
| 1618 | temp = I915_READ(fdi_tx_reg); |
| 1619 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 1620 | I915_WRITE(fdi_tx_reg, temp | FDI_LINK_TRAIN_NONE | |
| 1621 | FDI_TX_ENHANCE_FRAME_ENABLE); |
| 1622 | I915_READ(fdi_tx_reg); |
| 1623 | |
| 1624 | temp = I915_READ(fdi_rx_reg); |
| 1625 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 1626 | I915_WRITE(fdi_rx_reg, temp | FDI_LINK_TRAIN_NONE | |
| 1627 | FDI_RX_ENHANCE_FRAME_ENABLE); |
| 1628 | I915_READ(fdi_rx_reg); |
| 1629 | |
| 1630 | /* wait one idle pattern time */ |
| 1631 | udelay(100); |
| 1632 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1633 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1634 | |
| 1635 | intel_crtc_load_lut(crtc); |
| 1636 | |
| 1637 | break; |
| 1638 | case DRM_MODE_DPMS_OFF: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1639 | DRM_DEBUG_KMS("crtc %d dpms off\n", pipe); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1640 | |
| 1641 | /* Disable display plane */ |
| 1642 | temp = I915_READ(dspcntr_reg); |
| 1643 | if ((temp & DISPLAY_PLANE_ENABLE) != 0) { |
| 1644 | I915_WRITE(dspcntr_reg, temp & ~DISPLAY_PLANE_ENABLE); |
| 1645 | /* Flush the plane changes */ |
| 1646 | I915_WRITE(dspbase_reg, I915_READ(dspbase_reg)); |
| 1647 | I915_READ(dspbase_reg); |
| 1648 | } |
| 1649 | |
Zhenyu Wang | 1b3c7a4 | 2009-11-25 13:09:38 +0800 | [diff] [blame] | 1650 | i915_disable_vga(dev); |
| 1651 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1652 | /* disable cpu pipe, disable after all planes disabled */ |
| 1653 | temp = I915_READ(pipeconf_reg); |
| 1654 | if ((temp & PIPEACONF_ENABLE) != 0) { |
| 1655 | I915_WRITE(pipeconf_reg, temp & ~PIPEACONF_ENABLE); |
| 1656 | I915_READ(pipeconf_reg); |
Zhenyu Wang | 249c0e6 | 2009-07-24 01:00:29 +0800 | [diff] [blame] | 1657 | n = 0; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1658 | /* wait for cpu pipe off, pipe state */ |
Zhenyu Wang | 249c0e6 | 2009-07-24 01:00:29 +0800 | [diff] [blame] | 1659 | while ((I915_READ(pipeconf_reg) & I965_PIPECONF_ACTIVE) != 0) { |
| 1660 | n++; |
| 1661 | if (n < 60) { |
| 1662 | udelay(500); |
| 1663 | continue; |
| 1664 | } else { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1665 | DRM_DEBUG_KMS("pipe %d off delay\n", |
| 1666 | pipe); |
Zhenyu Wang | 249c0e6 | 2009-07-24 01:00:29 +0800 | [diff] [blame] | 1667 | break; |
| 1668 | } |
| 1669 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1670 | } else |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1671 | DRM_DEBUG_KMS("crtc %d is disabled\n", pipe); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1672 | |
Zhenyu Wang | 1b3c7a4 | 2009-11-25 13:09:38 +0800 | [diff] [blame] | 1673 | udelay(100); |
| 1674 | |
| 1675 | /* Disable PF */ |
| 1676 | temp = I915_READ(pf_ctl_reg); |
| 1677 | if ((temp & PF_ENABLE) != 0) { |
| 1678 | I915_WRITE(pf_ctl_reg, temp & ~PF_ENABLE); |
| 1679 | I915_READ(pf_ctl_reg); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1680 | } |
Zhenyu Wang | 1b3c7a4 | 2009-11-25 13:09:38 +0800 | [diff] [blame] | 1681 | I915_WRITE(pf_win_size, 0); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1682 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1683 | /* disable CPU FDI tx and PCH FDI rx */ |
| 1684 | temp = I915_READ(fdi_tx_reg); |
| 1685 | I915_WRITE(fdi_tx_reg, temp & ~FDI_TX_ENABLE); |
| 1686 | I915_READ(fdi_tx_reg); |
| 1687 | |
| 1688 | temp = I915_READ(fdi_rx_reg); |
Zhao Yakui | 8faf3b3 | 2010-01-04 16:29:31 +0800 | [diff] [blame] | 1689 | /* BPC in FDI rx is consistent with that in pipeconf */ |
| 1690 | temp &= ~(0x07 << 16); |
| 1691 | temp |= (pipe_bpc << 11); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1692 | I915_WRITE(fdi_rx_reg, temp & ~FDI_RX_ENABLE); |
| 1693 | I915_READ(fdi_rx_reg); |
| 1694 | |
Zhenyu Wang | 249c0e6 | 2009-07-24 01:00:29 +0800 | [diff] [blame] | 1695 | udelay(100); |
| 1696 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1697 | /* still set train pattern 1 */ |
| 1698 | temp = I915_READ(fdi_tx_reg); |
| 1699 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 1700 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 1701 | I915_WRITE(fdi_tx_reg, temp); |
| 1702 | |
| 1703 | temp = I915_READ(fdi_rx_reg); |
| 1704 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 1705 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 1706 | I915_WRITE(fdi_rx_reg, temp); |
| 1707 | |
Zhenyu Wang | 249c0e6 | 2009-07-24 01:00:29 +0800 | [diff] [blame] | 1708 | udelay(100); |
| 1709 | |
Zhenyu Wang | 1b3c7a4 | 2009-11-25 13:09:38 +0800 | [diff] [blame] | 1710 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
| 1711 | temp = I915_READ(PCH_LVDS); |
| 1712 | I915_WRITE(PCH_LVDS, temp & ~LVDS_PORT_EN); |
| 1713 | I915_READ(PCH_LVDS); |
| 1714 | udelay(100); |
| 1715 | } |
| 1716 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1717 | /* disable PCH transcoder */ |
| 1718 | temp = I915_READ(transconf_reg); |
| 1719 | if ((temp & TRANS_ENABLE) != 0) { |
| 1720 | I915_WRITE(transconf_reg, temp & ~TRANS_ENABLE); |
| 1721 | I915_READ(transconf_reg); |
Zhenyu Wang | 249c0e6 | 2009-07-24 01:00:29 +0800 | [diff] [blame] | 1722 | n = 0; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1723 | /* wait for PCH transcoder off, transcoder state */ |
Zhenyu Wang | 249c0e6 | 2009-07-24 01:00:29 +0800 | [diff] [blame] | 1724 | while ((I915_READ(transconf_reg) & TRANS_STATE_ENABLE) != 0) { |
| 1725 | n++; |
| 1726 | if (n < 60) { |
| 1727 | udelay(500); |
| 1728 | continue; |
| 1729 | } else { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1730 | DRM_DEBUG_KMS("transcoder %d off " |
| 1731 | "delay\n", pipe); |
Zhenyu Wang | 249c0e6 | 2009-07-24 01:00:29 +0800 | [diff] [blame] | 1732 | break; |
| 1733 | } |
| 1734 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1735 | } |
Zhao Yakui | 8faf3b3 | 2010-01-04 16:29:31 +0800 | [diff] [blame] | 1736 | temp = I915_READ(transconf_reg); |
| 1737 | /* BPC in transcoder is consistent with that in pipeconf */ |
| 1738 | temp &= ~PIPE_BPC_MASK; |
| 1739 | temp |= pipe_bpc; |
| 1740 | I915_WRITE(transconf_reg, temp); |
| 1741 | I915_READ(transconf_reg); |
Zhenyu Wang | 1b3c7a4 | 2009-11-25 13:09:38 +0800 | [diff] [blame] | 1742 | udelay(100); |
| 1743 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1744 | /* disable PCH DPLL */ |
| 1745 | temp = I915_READ(pch_dpll_reg); |
| 1746 | if ((temp & DPLL_VCO_ENABLE) != 0) { |
| 1747 | I915_WRITE(pch_dpll_reg, temp & ~DPLL_VCO_ENABLE); |
| 1748 | I915_READ(pch_dpll_reg); |
| 1749 | } |
| 1750 | |
Zhenyu Wang | 1b3c7a4 | 2009-11-25 13:09:38 +0800 | [diff] [blame] | 1751 | if (HAS_eDP) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 1752 | ironlake_disable_pll_edp(crtc); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1753 | } |
| 1754 | |
Zhenyu Wang | 1b3c7a4 | 2009-11-25 13:09:38 +0800 | [diff] [blame] | 1755 | temp = I915_READ(fdi_rx_reg); |
| 1756 | temp &= ~FDI_SEL_PCDCLK; |
| 1757 | I915_WRITE(fdi_rx_reg, temp); |
| 1758 | I915_READ(fdi_rx_reg); |
| 1759 | |
| 1760 | temp = I915_READ(fdi_rx_reg); |
| 1761 | temp &= ~FDI_RX_PLL_ENABLE; |
| 1762 | I915_WRITE(fdi_rx_reg, temp); |
| 1763 | I915_READ(fdi_rx_reg); |
| 1764 | |
Zhenyu Wang | 249c0e6 | 2009-07-24 01:00:29 +0800 | [diff] [blame] | 1765 | /* Disable CPU FDI TX PLL */ |
| 1766 | temp = I915_READ(fdi_tx_reg); |
| 1767 | if ((temp & FDI_TX_PLL_ENABLE) != 0) { |
| 1768 | I915_WRITE(fdi_tx_reg, temp & ~FDI_TX_PLL_ENABLE); |
| 1769 | I915_READ(fdi_tx_reg); |
| 1770 | udelay(100); |
| 1771 | } |
| 1772 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1773 | /* Wait for the clocks to turn off. */ |
Zhenyu Wang | 1b3c7a4 | 2009-11-25 13:09:38 +0800 | [diff] [blame] | 1774 | udelay(100); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1775 | break; |
| 1776 | } |
| 1777 | } |
| 1778 | |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1779 | static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable) |
| 1780 | { |
| 1781 | struct intel_overlay *overlay; |
Daniel Vetter | 03f77ea | 2009-09-15 22:57:37 +0200 | [diff] [blame] | 1782 | int ret; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1783 | |
| 1784 | if (!enable && intel_crtc->overlay) { |
| 1785 | overlay = intel_crtc->overlay; |
| 1786 | mutex_lock(&overlay->dev->struct_mutex); |
Daniel Vetter | 03f77ea | 2009-09-15 22:57:37 +0200 | [diff] [blame] | 1787 | for (;;) { |
| 1788 | ret = intel_overlay_switch_off(overlay); |
| 1789 | if (ret == 0) |
| 1790 | break; |
| 1791 | |
| 1792 | ret = intel_overlay_recover_from_interrupt(overlay, 0); |
| 1793 | if (ret != 0) { |
| 1794 | /* overlay doesn't react anymore. Usually |
| 1795 | * results in a black screen and an unkillable |
| 1796 | * X server. */ |
| 1797 | BUG(); |
| 1798 | overlay->hw_wedged = HW_WEDGED; |
| 1799 | break; |
| 1800 | } |
| 1801 | } |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1802 | mutex_unlock(&overlay->dev->struct_mutex); |
| 1803 | } |
| 1804 | /* Let userspace switch the overlay on again. In most cases userspace |
| 1805 | * has to recompute where to put it anyway. */ |
| 1806 | |
| 1807 | return; |
| 1808 | } |
| 1809 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1810 | static void i9xx_crtc_dpms(struct drm_crtc *crtc, int mode) |
| 1811 | { |
| 1812 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1813 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1814 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1815 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1816 | int plane = intel_crtc->plane; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1817 | int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1818 | int dspcntr_reg = (plane == 0) ? DSPACNTR : DSPBCNTR; |
| 1819 | int dspbase_reg = (plane == 0) ? DSPAADDR : DSPBADDR; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1820 | int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF; |
| 1821 | u32 temp; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1822 | |
| 1823 | /* XXX: When our outputs are all unaware of DPMS modes other than off |
| 1824 | * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC. |
| 1825 | */ |
| 1826 | switch (mode) { |
| 1827 | case DRM_MODE_DPMS_ON: |
| 1828 | case DRM_MODE_DPMS_STANDBY: |
| 1829 | case DRM_MODE_DPMS_SUSPEND: |
Jesse Barnes | 629598d | 2009-10-20 07:37:32 +0900 | [diff] [blame] | 1830 | intel_update_watermarks(dev); |
| 1831 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1832 | /* Enable the DPLL */ |
| 1833 | temp = I915_READ(dpll_reg); |
| 1834 | if ((temp & DPLL_VCO_ENABLE) == 0) { |
| 1835 | I915_WRITE(dpll_reg, temp); |
| 1836 | I915_READ(dpll_reg); |
| 1837 | /* Wait for the clocks to stabilize. */ |
| 1838 | udelay(150); |
| 1839 | I915_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE); |
| 1840 | I915_READ(dpll_reg); |
| 1841 | /* Wait for the clocks to stabilize. */ |
| 1842 | udelay(150); |
| 1843 | I915_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE); |
| 1844 | I915_READ(dpll_reg); |
| 1845 | /* Wait for the clocks to stabilize. */ |
| 1846 | udelay(150); |
| 1847 | } |
| 1848 | |
| 1849 | /* Enable the pipe */ |
| 1850 | temp = I915_READ(pipeconf_reg); |
| 1851 | if ((temp & PIPEACONF_ENABLE) == 0) |
| 1852 | I915_WRITE(pipeconf_reg, temp | PIPEACONF_ENABLE); |
| 1853 | |
| 1854 | /* Enable the plane */ |
| 1855 | temp = I915_READ(dspcntr_reg); |
| 1856 | if ((temp & DISPLAY_PLANE_ENABLE) == 0) { |
| 1857 | I915_WRITE(dspcntr_reg, temp | DISPLAY_PLANE_ENABLE); |
| 1858 | /* Flush the plane changes */ |
| 1859 | I915_WRITE(dspbase_reg, I915_READ(dspbase_reg)); |
| 1860 | } |
| 1861 | |
| 1862 | intel_crtc_load_lut(crtc); |
| 1863 | |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 1864 | if ((IS_I965G(dev) || plane == 0)) |
| 1865 | intel_update_fbc(crtc, &crtc->mode); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1866 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1867 | /* Give the overlay scaler a chance to enable if it's on this pipe */ |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1868 | intel_crtc_dpms_overlay(intel_crtc, true); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1869 | break; |
| 1870 | case DRM_MODE_DPMS_OFF: |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 1871 | intel_update_watermarks(dev); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1872 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1873 | /* Give the overlay scaler a chance to disable if it's on this pipe */ |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1874 | intel_crtc_dpms_overlay(intel_crtc, false); |
Li Peng | 778c902 | 2009-11-09 12:51:22 +0800 | [diff] [blame] | 1875 | drm_vblank_off(dev, pipe); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1876 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 1877 | if (dev_priv->cfb_plane == plane && |
| 1878 | dev_priv->display.disable_fbc) |
| 1879 | dev_priv->display.disable_fbc(dev); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1880 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1881 | /* Disable the VGA plane that we never use */ |
Zhenyu Wang | 24f119c | 2009-07-24 01:00:28 +0800 | [diff] [blame] | 1882 | i915_disable_vga(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1883 | |
| 1884 | /* Disable display plane */ |
| 1885 | temp = I915_READ(dspcntr_reg); |
| 1886 | if ((temp & DISPLAY_PLANE_ENABLE) != 0) { |
| 1887 | I915_WRITE(dspcntr_reg, temp & ~DISPLAY_PLANE_ENABLE); |
| 1888 | /* Flush the plane changes */ |
| 1889 | I915_WRITE(dspbase_reg, I915_READ(dspbase_reg)); |
| 1890 | I915_READ(dspbase_reg); |
| 1891 | } |
| 1892 | |
| 1893 | if (!IS_I9XX(dev)) { |
| 1894 | /* Wait for vblank for the disable to take effect */ |
| 1895 | intel_wait_for_vblank(dev); |
| 1896 | } |
| 1897 | |
| 1898 | /* Next, disable display pipes */ |
| 1899 | temp = I915_READ(pipeconf_reg); |
| 1900 | if ((temp & PIPEACONF_ENABLE) != 0) { |
| 1901 | I915_WRITE(pipeconf_reg, temp & ~PIPEACONF_ENABLE); |
| 1902 | I915_READ(pipeconf_reg); |
| 1903 | } |
| 1904 | |
| 1905 | /* Wait for vblank for the disable to take effect. */ |
| 1906 | intel_wait_for_vblank(dev); |
| 1907 | |
| 1908 | temp = I915_READ(dpll_reg); |
| 1909 | if ((temp & DPLL_VCO_ENABLE) != 0) { |
| 1910 | I915_WRITE(dpll_reg, temp & ~DPLL_VCO_ENABLE); |
| 1911 | I915_READ(dpll_reg); |
| 1912 | } |
| 1913 | |
| 1914 | /* Wait for the clocks to turn off. */ |
| 1915 | udelay(150); |
| 1916 | break; |
| 1917 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1918 | } |
| 1919 | |
| 1920 | /** |
| 1921 | * Sets the power management mode of the pipe and plane. |
| 1922 | * |
| 1923 | * This code should probably grow support for turning the cursor off and back |
| 1924 | * on appropriately at the same time as we're turning the pipe off/on. |
| 1925 | */ |
| 1926 | static void intel_crtc_dpms(struct drm_crtc *crtc, int mode) |
| 1927 | { |
| 1928 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 1929 | struct drm_i915_private *dev_priv = dev->dev_private; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1930 | struct drm_i915_master_private *master_priv; |
| 1931 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1932 | int pipe = intel_crtc->pipe; |
| 1933 | bool enabled; |
| 1934 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 1935 | dev_priv->display.dpms(crtc, mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1936 | |
Daniel Vetter | 65655d4 | 2009-08-11 16:05:31 +0200 | [diff] [blame] | 1937 | intel_crtc->dpms_mode = mode; |
| 1938 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1939 | if (!dev->primary->master) |
| 1940 | return; |
| 1941 | |
| 1942 | master_priv = dev->primary->master->driver_priv; |
| 1943 | if (!master_priv->sarea_priv) |
| 1944 | return; |
| 1945 | |
| 1946 | enabled = crtc->enabled && mode != DRM_MODE_DPMS_OFF; |
| 1947 | |
| 1948 | switch (pipe) { |
| 1949 | case 0: |
| 1950 | master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0; |
| 1951 | master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0; |
| 1952 | break; |
| 1953 | case 1: |
| 1954 | master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0; |
| 1955 | master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0; |
| 1956 | break; |
| 1957 | default: |
| 1958 | DRM_ERROR("Can't update pipe %d in SAREA\n", pipe); |
| 1959 | break; |
| 1960 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1961 | } |
| 1962 | |
| 1963 | static void intel_crtc_prepare (struct drm_crtc *crtc) |
| 1964 | { |
| 1965 | struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; |
| 1966 | crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF); |
| 1967 | } |
| 1968 | |
| 1969 | static void intel_crtc_commit (struct drm_crtc *crtc) |
| 1970 | { |
| 1971 | struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; |
| 1972 | crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON); |
| 1973 | } |
| 1974 | |
| 1975 | void intel_encoder_prepare (struct drm_encoder *encoder) |
| 1976 | { |
| 1977 | struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; |
| 1978 | /* lvds has its own version of prepare see intel_lvds_prepare */ |
| 1979 | encoder_funcs->dpms(encoder, DRM_MODE_DPMS_OFF); |
| 1980 | } |
| 1981 | |
| 1982 | void intel_encoder_commit (struct drm_encoder *encoder) |
| 1983 | { |
| 1984 | struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; |
| 1985 | /* lvds has its own version of commit see intel_lvds_commit */ |
| 1986 | encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON); |
| 1987 | } |
| 1988 | |
| 1989 | static bool intel_crtc_mode_fixup(struct drm_crtc *crtc, |
| 1990 | struct drm_display_mode *mode, |
| 1991 | struct drm_display_mode *adjusted_mode) |
| 1992 | { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1993 | struct drm_device *dev = crtc->dev; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 1994 | if (IS_IRONLAKE(dev)) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 1995 | /* FDI link clock is fixed at 2.7G */ |
| 1996 | if (mode->clock * 3 > 27000 * 4) |
| 1997 | return MODE_CLOCK_HIGH; |
| 1998 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1999 | return true; |
| 2000 | } |
| 2001 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2002 | static int i945_get_display_clock_speed(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2003 | { |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2004 | return 400000; |
| 2005 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2006 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2007 | static int i915_get_display_clock_speed(struct drm_device *dev) |
| 2008 | { |
| 2009 | return 333000; |
| 2010 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2011 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2012 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
| 2013 | { |
| 2014 | return 200000; |
| 2015 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2016 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2017 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
| 2018 | { |
| 2019 | u16 gcfgc = 0; |
| 2020 | |
| 2021 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 2022 | |
| 2023 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2024 | return 133000; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2025 | else { |
| 2026 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 2027 | case GC_DISPLAY_CLOCK_333_MHZ: |
| 2028 | return 333000; |
| 2029 | default: |
| 2030 | case GC_DISPLAY_CLOCK_190_200_MHZ: |
| 2031 | return 190000; |
| 2032 | } |
| 2033 | } |
| 2034 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2035 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2036 | static int i865_get_display_clock_speed(struct drm_device *dev) |
| 2037 | { |
| 2038 | return 266000; |
| 2039 | } |
| 2040 | |
| 2041 | static int i855_get_display_clock_speed(struct drm_device *dev) |
| 2042 | { |
| 2043 | u16 hpllcc = 0; |
| 2044 | /* Assume that the hardware is in the high speed state. This |
| 2045 | * should be the default. |
| 2046 | */ |
| 2047 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { |
| 2048 | case GC_CLOCK_133_200: |
| 2049 | case GC_CLOCK_100_200: |
| 2050 | return 200000; |
| 2051 | case GC_CLOCK_166_250: |
| 2052 | return 250000; |
| 2053 | case GC_CLOCK_100_133: |
| 2054 | return 133000; |
| 2055 | } |
| 2056 | |
| 2057 | /* Shouldn't happen */ |
| 2058 | return 0; |
| 2059 | } |
| 2060 | |
| 2061 | static int i830_get_display_clock_speed(struct drm_device *dev) |
| 2062 | { |
| 2063 | return 133000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2064 | } |
| 2065 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2066 | /** |
| 2067 | * Return the pipe currently connected to the panel fitter, |
| 2068 | * or -1 if the panel fitter is not present or not in use |
| 2069 | */ |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 2070 | int intel_panel_fitter_pipe (struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2071 | { |
| 2072 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2073 | u32 pfit_control; |
| 2074 | |
| 2075 | /* i830 doesn't have a panel fitter */ |
| 2076 | if (IS_I830(dev)) |
| 2077 | return -1; |
| 2078 | |
| 2079 | pfit_control = I915_READ(PFIT_CONTROL); |
| 2080 | |
| 2081 | /* See if the panel fitter is in use */ |
| 2082 | if ((pfit_control & PFIT_ENABLE) == 0) |
| 2083 | return -1; |
| 2084 | |
| 2085 | /* 965 can place panel fitter on either pipe */ |
| 2086 | if (IS_I965G(dev)) |
| 2087 | return (pfit_control >> 29) & 0x3; |
| 2088 | |
| 2089 | /* older chips can only use pipe 1 */ |
| 2090 | return 1; |
| 2091 | } |
| 2092 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2093 | struct fdi_m_n { |
| 2094 | u32 tu; |
| 2095 | u32 gmch_m; |
| 2096 | u32 gmch_n; |
| 2097 | u32 link_m; |
| 2098 | u32 link_n; |
| 2099 | }; |
| 2100 | |
| 2101 | static void |
| 2102 | fdi_reduce_ratio(u32 *num, u32 *den) |
| 2103 | { |
| 2104 | while (*num > 0xffffff || *den > 0xffffff) { |
| 2105 | *num >>= 1; |
| 2106 | *den >>= 1; |
| 2107 | } |
| 2108 | } |
| 2109 | |
| 2110 | #define DATA_N 0x800000 |
| 2111 | #define LINK_N 0x80000 |
| 2112 | |
| 2113 | static void |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2114 | ironlake_compute_m_n(int bits_per_pixel, int nlanes, int pixel_clock, |
| 2115 | int link_clock, struct fdi_m_n *m_n) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2116 | { |
| 2117 | u64 temp; |
| 2118 | |
| 2119 | m_n->tu = 64; /* default size */ |
| 2120 | |
| 2121 | temp = (u64) DATA_N * pixel_clock; |
| 2122 | temp = div_u64(temp, link_clock); |
Zhenyu Wang | 58a2747 | 2009-09-25 08:01:28 +0000 | [diff] [blame] | 2123 | m_n->gmch_m = div_u64(temp * bits_per_pixel, nlanes); |
| 2124 | m_n->gmch_m >>= 3; /* convert to bytes_per_pixel */ |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2125 | m_n->gmch_n = DATA_N; |
| 2126 | fdi_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n); |
| 2127 | |
| 2128 | temp = (u64) LINK_N * pixel_clock; |
| 2129 | m_n->link_m = div_u64(temp, link_clock); |
| 2130 | m_n->link_n = LINK_N; |
| 2131 | fdi_reduce_ratio(&m_n->link_m, &m_n->link_n); |
| 2132 | } |
| 2133 | |
| 2134 | |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2135 | struct intel_watermark_params { |
| 2136 | unsigned long fifo_size; |
| 2137 | unsigned long max_wm; |
| 2138 | unsigned long default_wm; |
| 2139 | unsigned long guard_size; |
| 2140 | unsigned long cacheline_size; |
| 2141 | }; |
| 2142 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2143 | /* Pineview has different values for various configs */ |
| 2144 | static struct intel_watermark_params pineview_display_wm = { |
| 2145 | PINEVIEW_DISPLAY_FIFO, |
| 2146 | PINEVIEW_MAX_WM, |
| 2147 | PINEVIEW_DFT_WM, |
| 2148 | PINEVIEW_GUARD_WM, |
| 2149 | PINEVIEW_FIFO_LINE_SIZE |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2150 | }; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2151 | static struct intel_watermark_params pineview_display_hplloff_wm = { |
| 2152 | PINEVIEW_DISPLAY_FIFO, |
| 2153 | PINEVIEW_MAX_WM, |
| 2154 | PINEVIEW_DFT_HPLLOFF_WM, |
| 2155 | PINEVIEW_GUARD_WM, |
| 2156 | PINEVIEW_FIFO_LINE_SIZE |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2157 | }; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2158 | static struct intel_watermark_params pineview_cursor_wm = { |
| 2159 | PINEVIEW_CURSOR_FIFO, |
| 2160 | PINEVIEW_CURSOR_MAX_WM, |
| 2161 | PINEVIEW_CURSOR_DFT_WM, |
| 2162 | PINEVIEW_CURSOR_GUARD_WM, |
| 2163 | PINEVIEW_FIFO_LINE_SIZE, |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2164 | }; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2165 | static struct intel_watermark_params pineview_cursor_hplloff_wm = { |
| 2166 | PINEVIEW_CURSOR_FIFO, |
| 2167 | PINEVIEW_CURSOR_MAX_WM, |
| 2168 | PINEVIEW_CURSOR_DFT_WM, |
| 2169 | PINEVIEW_CURSOR_GUARD_WM, |
| 2170 | PINEVIEW_FIFO_LINE_SIZE |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2171 | }; |
Jesse Barnes | 0e442c6 | 2009-10-19 10:09:33 +0900 | [diff] [blame] | 2172 | static struct intel_watermark_params g4x_wm_info = { |
| 2173 | G4X_FIFO_SIZE, |
| 2174 | G4X_MAX_WM, |
| 2175 | G4X_MAX_WM, |
| 2176 | 2, |
| 2177 | G4X_FIFO_LINE_SIZE, |
| 2178 | }; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2179 | static struct intel_watermark_params i945_wm_info = { |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2180 | I945_FIFO_SIZE, |
| 2181 | I915_MAX_WM, |
| 2182 | 1, |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2183 | 2, |
| 2184 | I915_FIFO_LINE_SIZE |
| 2185 | }; |
| 2186 | static struct intel_watermark_params i915_wm_info = { |
| 2187 | I915_FIFO_SIZE, |
| 2188 | I915_MAX_WM, |
| 2189 | 1, |
| 2190 | 2, |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2191 | I915_FIFO_LINE_SIZE |
| 2192 | }; |
| 2193 | static struct intel_watermark_params i855_wm_info = { |
| 2194 | I855GM_FIFO_SIZE, |
| 2195 | I915_MAX_WM, |
| 2196 | 1, |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2197 | 2, |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2198 | I830_FIFO_LINE_SIZE |
| 2199 | }; |
| 2200 | static struct intel_watermark_params i830_wm_info = { |
| 2201 | I830_FIFO_SIZE, |
| 2202 | I915_MAX_WM, |
| 2203 | 1, |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2204 | 2, |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2205 | I830_FIFO_LINE_SIZE |
| 2206 | }; |
| 2207 | |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2208 | /** |
| 2209 | * intel_calculate_wm - calculate watermark level |
| 2210 | * @clock_in_khz: pixel clock |
| 2211 | * @wm: chip FIFO params |
| 2212 | * @pixel_size: display pixel size |
| 2213 | * @latency_ns: memory latency for the platform |
| 2214 | * |
| 2215 | * Calculate the watermark level (the level at which the display plane will |
| 2216 | * start fetching from memory again). Each chip has a different display |
| 2217 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 2218 | * in the correct intel_watermark_params structure. |
| 2219 | * |
| 2220 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 2221 | * on the pixel size. When it reaches the watermark level, it'll start |
| 2222 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 2223 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 2224 | * will occur, and a display engine hang could result. |
| 2225 | */ |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2226 | static unsigned long intel_calculate_wm(unsigned long clock_in_khz, |
| 2227 | struct intel_watermark_params *wm, |
| 2228 | int pixel_size, |
| 2229 | unsigned long latency_ns) |
| 2230 | { |
Jesse Barnes | 390c4dd | 2009-07-16 13:01:01 -0700 | [diff] [blame] | 2231 | long entries_required, wm_size; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2232 | |
Jesse Barnes | d660467 | 2009-09-11 12:25:56 -0700 | [diff] [blame] | 2233 | /* |
| 2234 | * Note: we need to make sure we don't overflow for various clock & |
| 2235 | * latency values. |
| 2236 | * clocks go from a few thousand to several hundred thousand. |
| 2237 | * latency is usually a few thousand |
| 2238 | */ |
| 2239 | entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) / |
| 2240 | 1000; |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2241 | entries_required /= wm->cacheline_size; |
| 2242 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 2243 | DRM_DEBUG_KMS("FIFO entries required for mode: %d\n", entries_required); |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2244 | |
| 2245 | wm_size = wm->fifo_size - (entries_required + wm->guard_size); |
| 2246 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 2247 | DRM_DEBUG_KMS("FIFO watermark level: %d\n", wm_size); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2248 | |
Jesse Barnes | 390c4dd | 2009-07-16 13:01:01 -0700 | [diff] [blame] | 2249 | /* Don't promote wm_size to unsigned... */ |
| 2250 | if (wm_size > (long)wm->max_wm) |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2251 | wm_size = wm->max_wm; |
Jesse Barnes | 390c4dd | 2009-07-16 13:01:01 -0700 | [diff] [blame] | 2252 | if (wm_size <= 0) |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2253 | wm_size = wm->default_wm; |
| 2254 | return wm_size; |
| 2255 | } |
| 2256 | |
| 2257 | struct cxsr_latency { |
| 2258 | int is_desktop; |
| 2259 | unsigned long fsb_freq; |
| 2260 | unsigned long mem_freq; |
| 2261 | unsigned long display_sr; |
| 2262 | unsigned long display_hpll_disable; |
| 2263 | unsigned long cursor_sr; |
| 2264 | unsigned long cursor_hpll_disable; |
| 2265 | }; |
| 2266 | |
| 2267 | static struct cxsr_latency cxsr_latency_table[] = { |
| 2268 | {1, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 2269 | {1, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 2270 | {1, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 2271 | |
| 2272 | {1, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 2273 | {1, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 2274 | {1, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 2275 | |
| 2276 | {1, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 2277 | {1, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 2278 | {1, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 2279 | |
| 2280 | {0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 2281 | {0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 2282 | {0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 2283 | |
| 2284 | {0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 2285 | {0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 2286 | {0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 2287 | |
| 2288 | {0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 2289 | {0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 2290 | {0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 2291 | }; |
| 2292 | |
| 2293 | static struct cxsr_latency *intel_get_cxsr_latency(int is_desktop, int fsb, |
| 2294 | int mem) |
| 2295 | { |
| 2296 | int i; |
| 2297 | struct cxsr_latency *latency; |
| 2298 | |
| 2299 | if (fsb == 0 || mem == 0) |
| 2300 | return NULL; |
| 2301 | |
| 2302 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 2303 | latency = &cxsr_latency_table[i]; |
| 2304 | if (is_desktop == latency->is_desktop && |
Jaswinder Singh Rajput | decbbcd | 2009-09-12 23:15:07 +0530 | [diff] [blame] | 2305 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 2306 | return latency; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2307 | } |
Jaswinder Singh Rajput | decbbcd | 2009-09-12 23:15:07 +0530 | [diff] [blame] | 2308 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 2309 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
Jaswinder Singh Rajput | decbbcd | 2009-09-12 23:15:07 +0530 | [diff] [blame] | 2310 | |
| 2311 | return NULL; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2312 | } |
| 2313 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2314 | static void pineview_disable_cxsr(struct drm_device *dev) |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2315 | { |
| 2316 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2317 | u32 reg; |
| 2318 | |
| 2319 | /* deactivate cxsr */ |
| 2320 | reg = I915_READ(DSPFW3); |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2321 | reg &= ~(PINEVIEW_SELF_REFRESH_EN); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2322 | I915_WRITE(DSPFW3, reg); |
| 2323 | DRM_INFO("Big FIFO is disabled\n"); |
| 2324 | } |
| 2325 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2326 | static void pineview_enable_cxsr(struct drm_device *dev, unsigned long clock, |
| 2327 | int pixel_size) |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2328 | { |
| 2329 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2330 | u32 reg; |
| 2331 | unsigned long wm; |
| 2332 | struct cxsr_latency *latency; |
| 2333 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2334 | latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->fsb_freq, |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2335 | dev_priv->mem_freq); |
| 2336 | if (!latency) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 2337 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2338 | pineview_disable_cxsr(dev); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2339 | return; |
| 2340 | } |
| 2341 | |
| 2342 | /* Display SR */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2343 | wm = intel_calculate_wm(clock, &pineview_display_wm, pixel_size, |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2344 | latency->display_sr); |
| 2345 | reg = I915_READ(DSPFW1); |
| 2346 | reg &= 0x7fffff; |
| 2347 | reg |= wm << 23; |
| 2348 | I915_WRITE(DSPFW1, reg); |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 2349 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2350 | |
| 2351 | /* cursor SR */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2352 | wm = intel_calculate_wm(clock, &pineview_cursor_wm, pixel_size, |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2353 | latency->cursor_sr); |
| 2354 | reg = I915_READ(DSPFW3); |
| 2355 | reg &= ~(0x3f << 24); |
| 2356 | reg |= (wm & 0x3f) << 24; |
| 2357 | I915_WRITE(DSPFW3, reg); |
| 2358 | |
| 2359 | /* Display HPLL off SR */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2360 | wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2361 | latency->display_hpll_disable, I915_FIFO_LINE_SIZE); |
| 2362 | reg = I915_READ(DSPFW3); |
| 2363 | reg &= 0xfffffe00; |
| 2364 | reg |= wm & 0x1ff; |
| 2365 | I915_WRITE(DSPFW3, reg); |
| 2366 | |
| 2367 | /* cursor HPLL off SR */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2368 | wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, pixel_size, |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2369 | latency->cursor_hpll_disable); |
| 2370 | reg = I915_READ(DSPFW3); |
| 2371 | reg &= ~(0x3f << 16); |
| 2372 | reg |= (wm & 0x3f) << 16; |
| 2373 | I915_WRITE(DSPFW3, reg); |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 2374 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2375 | |
| 2376 | /* activate cxsr */ |
| 2377 | reg = I915_READ(DSPFW3); |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2378 | reg |= PINEVIEW_SELF_REFRESH_EN; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2379 | I915_WRITE(DSPFW3, reg); |
| 2380 | |
| 2381 | DRM_INFO("Big FIFO is enabled\n"); |
| 2382 | |
| 2383 | return; |
| 2384 | } |
| 2385 | |
Jesse Barnes | bcc24fb | 2009-08-31 10:24:31 -0700 | [diff] [blame] | 2386 | /* |
| 2387 | * Latency for FIFO fetches is dependent on several factors: |
| 2388 | * - memory configuration (speed, channels) |
| 2389 | * - chipset |
| 2390 | * - current MCH state |
| 2391 | * It can be fairly high in some situations, so here we assume a fairly |
| 2392 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 2393 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 2394 | * and power consumption (set it too low to save power and we might see |
| 2395 | * FIFO underruns and display "flicker"). |
| 2396 | * |
| 2397 | * A value of 5us seems to be a good balance; safe for very low end |
| 2398 | * platforms but not overly aggressive on lower latency configs. |
| 2399 | */ |
Tobias Klauser | 69e302a | 2009-12-23 14:14:34 +0100 | [diff] [blame] | 2400 | static const int latency_ns = 5000; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2401 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2402 | static int i9xx_get_fifo_size(struct drm_device *dev, int plane) |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2403 | { |
| 2404 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2405 | uint32_t dsparb = I915_READ(DSPARB); |
| 2406 | int size; |
| 2407 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2408 | if (plane == 0) |
Jesse Barnes | f360132 | 2009-07-22 12:54:59 -0700 | [diff] [blame] | 2409 | size = dsparb & 0x7f; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2410 | else |
| 2411 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - |
| 2412 | (dsparb & 0x7f); |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2413 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 2414 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 2415 | plane ? "B" : "A", size); |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2416 | |
| 2417 | return size; |
| 2418 | } |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2419 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2420 | static int i85x_get_fifo_size(struct drm_device *dev, int plane) |
| 2421 | { |
| 2422 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2423 | uint32_t dsparb = I915_READ(DSPARB); |
| 2424 | int size; |
| 2425 | |
| 2426 | if (plane == 0) |
| 2427 | size = dsparb & 0x1ff; |
| 2428 | else |
| 2429 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - |
| 2430 | (dsparb & 0x1ff); |
| 2431 | size >>= 1; /* Convert to cachelines */ |
| 2432 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 2433 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 2434 | plane ? "B" : "A", size); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2435 | |
| 2436 | return size; |
| 2437 | } |
| 2438 | |
| 2439 | static int i845_get_fifo_size(struct drm_device *dev, int plane) |
| 2440 | { |
| 2441 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2442 | uint32_t dsparb = I915_READ(DSPARB); |
| 2443 | int size; |
| 2444 | |
| 2445 | size = dsparb & 0x7f; |
| 2446 | size >>= 2; /* Convert to cachelines */ |
| 2447 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 2448 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 2449 | plane ? "B" : "A", |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2450 | size); |
| 2451 | |
| 2452 | return size; |
| 2453 | } |
| 2454 | |
| 2455 | static int i830_get_fifo_size(struct drm_device *dev, int plane) |
| 2456 | { |
| 2457 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2458 | uint32_t dsparb = I915_READ(DSPARB); |
| 2459 | int size; |
| 2460 | |
| 2461 | size = dsparb & 0x7f; |
| 2462 | size >>= 1; /* Convert to cachelines */ |
| 2463 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 2464 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 2465 | plane ? "B" : "A", size); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2466 | |
| 2467 | return size; |
| 2468 | } |
| 2469 | |
Jesse Barnes | 0e442c6 | 2009-10-19 10:09:33 +0900 | [diff] [blame] | 2470 | static void g4x_update_wm(struct drm_device *dev, int planea_clock, |
| 2471 | int planeb_clock, int sr_hdisplay, int pixel_size) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 2472 | { |
| 2473 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 0e442c6 | 2009-10-19 10:09:33 +0900 | [diff] [blame] | 2474 | int total_size, cacheline_size; |
| 2475 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm, cursor_sr; |
| 2476 | struct intel_watermark_params planea_params, planeb_params; |
| 2477 | unsigned long line_time_us; |
| 2478 | int sr_clock, sr_entries = 0, entries_required; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 2479 | |
Jesse Barnes | 0e442c6 | 2009-10-19 10:09:33 +0900 | [diff] [blame] | 2480 | /* Create copies of the base settings for each pipe */ |
| 2481 | planea_params = planeb_params = g4x_wm_info; |
| 2482 | |
| 2483 | /* Grab a couple of global values before we overwrite them */ |
| 2484 | total_size = planea_params.fifo_size; |
| 2485 | cacheline_size = planea_params.cacheline_size; |
| 2486 | |
| 2487 | /* |
| 2488 | * Note: we need to make sure we don't overflow for various clock & |
| 2489 | * latency values. |
| 2490 | * clocks go from a few thousand to several hundred thousand. |
| 2491 | * latency is usually a few thousand |
| 2492 | */ |
| 2493 | entries_required = ((planea_clock / 1000) * pixel_size * latency_ns) / |
| 2494 | 1000; |
| 2495 | entries_required /= G4X_FIFO_LINE_SIZE; |
| 2496 | planea_wm = entries_required + planea_params.guard_size; |
| 2497 | |
| 2498 | entries_required = ((planeb_clock / 1000) * pixel_size * latency_ns) / |
| 2499 | 1000; |
| 2500 | entries_required /= G4X_FIFO_LINE_SIZE; |
| 2501 | planeb_wm = entries_required + planeb_params.guard_size; |
| 2502 | |
| 2503 | cursora_wm = cursorb_wm = 16; |
| 2504 | cursor_sr = 32; |
| 2505 | |
| 2506 | DRM_DEBUG("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 2507 | |
| 2508 | /* Calc sr entries for one plane configs */ |
| 2509 | if (sr_hdisplay && (!planea_clock || !planeb_clock)) { |
| 2510 | /* self-refresh has much higher latency */ |
Tobias Klauser | 69e302a | 2009-12-23 14:14:34 +0100 | [diff] [blame] | 2511 | static const int sr_latency_ns = 12000; |
Jesse Barnes | 0e442c6 | 2009-10-19 10:09:33 +0900 | [diff] [blame] | 2512 | |
| 2513 | sr_clock = planea_clock ? planea_clock : planeb_clock; |
| 2514 | line_time_us = ((sr_hdisplay * 1000) / sr_clock); |
| 2515 | |
| 2516 | /* Use ns/us then divide to preserve precision */ |
| 2517 | sr_entries = (((sr_latency_ns / line_time_us) + 1) * |
| 2518 | pixel_size * sr_hdisplay) / 1000; |
| 2519 | sr_entries = roundup(sr_entries / cacheline_size, 1); |
| 2520 | DRM_DEBUG("self-refresh entries: %d\n", sr_entries); |
| 2521 | I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN); |
| 2522 | } |
| 2523 | |
| 2524 | DRM_DEBUG("Setting FIFO watermarks - A: %d, B: %d, SR %d\n", |
| 2525 | planea_wm, planeb_wm, sr_entries); |
| 2526 | |
| 2527 | planea_wm &= 0x3f; |
| 2528 | planeb_wm &= 0x3f; |
| 2529 | |
| 2530 | I915_WRITE(DSPFW1, (sr_entries << DSPFW_SR_SHIFT) | |
| 2531 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 2532 | (planeb_wm << DSPFW_PLANEB_SHIFT) | planea_wm); |
| 2533 | I915_WRITE(DSPFW2, (I915_READ(DSPFW2) & DSPFW_CURSORA_MASK) | |
| 2534 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 2535 | /* HPLL off in SR has some issues on G4x... disable it */ |
| 2536 | I915_WRITE(DSPFW3, (I915_READ(DSPFW3) & ~DSPFW_HPLL_SR_EN) | |
| 2537 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 2538 | } |
| 2539 | |
Jesse Barnes | 1dc7546 | 2009-10-19 10:08:17 +0900 | [diff] [blame] | 2540 | static void i965_update_wm(struct drm_device *dev, int planea_clock, |
| 2541 | int planeb_clock, int sr_hdisplay, int pixel_size) |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2542 | { |
| 2543 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 1dc7546 | 2009-10-19 10:08:17 +0900 | [diff] [blame] | 2544 | unsigned long line_time_us; |
| 2545 | int sr_clock, sr_entries, srwm = 1; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2546 | |
Jesse Barnes | 1dc7546 | 2009-10-19 10:08:17 +0900 | [diff] [blame] | 2547 | /* Calc sr entries for one plane configs */ |
| 2548 | if (sr_hdisplay && (!planea_clock || !planeb_clock)) { |
| 2549 | /* self-refresh has much higher latency */ |
Tobias Klauser | 69e302a | 2009-12-23 14:14:34 +0100 | [diff] [blame] | 2550 | static const int sr_latency_ns = 12000; |
Jesse Barnes | 1dc7546 | 2009-10-19 10:08:17 +0900 | [diff] [blame] | 2551 | |
| 2552 | sr_clock = planea_clock ? planea_clock : planeb_clock; |
| 2553 | line_time_us = ((sr_hdisplay * 1000) / sr_clock); |
| 2554 | |
| 2555 | /* Use ns/us then divide to preserve precision */ |
| 2556 | sr_entries = (((sr_latency_ns / line_time_us) + 1) * |
| 2557 | pixel_size * sr_hdisplay) / 1000; |
| 2558 | sr_entries = roundup(sr_entries / I915_FIFO_LINE_SIZE, 1); |
| 2559 | DRM_DEBUG("self-refresh entries: %d\n", sr_entries); |
| 2560 | srwm = I945_FIFO_SIZE - sr_entries; |
| 2561 | if (srwm < 0) |
| 2562 | srwm = 1; |
| 2563 | srwm &= 0x3f; |
| 2564 | I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN); |
| 2565 | } |
| 2566 | |
| 2567 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 2568 | srwm); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2569 | |
| 2570 | /* 965 has limitations... */ |
Jesse Barnes | 1dc7546 | 2009-10-19 10:08:17 +0900 | [diff] [blame] | 2571 | I915_WRITE(DSPFW1, (srwm << DSPFW_SR_SHIFT) | (8 << 16) | (8 << 8) | |
| 2572 | (8 << 0)); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2573 | I915_WRITE(DSPFW2, (8 << 8) | (8 << 0)); |
| 2574 | } |
| 2575 | |
| 2576 | static void i9xx_update_wm(struct drm_device *dev, int planea_clock, |
| 2577 | int planeb_clock, int sr_hdisplay, int pixel_size) |
| 2578 | { |
| 2579 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2580 | uint32_t fwater_lo; |
| 2581 | uint32_t fwater_hi; |
| 2582 | int total_size, cacheline_size, cwm, srwm = 1; |
| 2583 | int planea_wm, planeb_wm; |
| 2584 | struct intel_watermark_params planea_params, planeb_params; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2585 | unsigned long line_time_us; |
| 2586 | int sr_clock, sr_entries = 0; |
| 2587 | |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2588 | /* Create copies of the base settings for each pipe */ |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2589 | if (IS_I965GM(dev) || IS_I945GM(dev)) |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2590 | planea_params = planeb_params = i945_wm_info; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2591 | else if (IS_I9XX(dev)) |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2592 | planea_params = planeb_params = i915_wm_info; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2593 | else |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2594 | planea_params = planeb_params = i855_wm_info; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2595 | |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2596 | /* Grab a couple of global values before we overwrite them */ |
| 2597 | total_size = planea_params.fifo_size; |
| 2598 | cacheline_size = planea_params.cacheline_size; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2599 | |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2600 | /* Update per-plane FIFO sizes */ |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2601 | planea_params.fifo_size = dev_priv->display.get_fifo_size(dev, 0); |
| 2602 | planeb_params.fifo_size = dev_priv->display.get_fifo_size(dev, 1); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2603 | |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2604 | planea_wm = intel_calculate_wm(planea_clock, &planea_params, |
| 2605 | pixel_size, latency_ns); |
| 2606 | planeb_wm = intel_calculate_wm(planeb_clock, &planeb_params, |
| 2607 | pixel_size, latency_ns); |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 2608 | 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] | 2609 | |
| 2610 | /* |
| 2611 | * Overlay gets an aggressive default since video jitter is bad. |
| 2612 | */ |
| 2613 | cwm = 2; |
| 2614 | |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2615 | /* Calc sr entries for one plane configs */ |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 2616 | if (HAS_FW_BLC(dev) && sr_hdisplay && |
| 2617 | (!planea_clock || !planeb_clock)) { |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2618 | /* self-refresh has much higher latency */ |
Tobias Klauser | 69e302a | 2009-12-23 14:14:34 +0100 | [diff] [blame] | 2619 | static const int sr_latency_ns = 6000; |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2620 | |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2621 | sr_clock = planea_clock ? planea_clock : planeb_clock; |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2622 | line_time_us = ((sr_hdisplay * 1000) / sr_clock); |
| 2623 | |
| 2624 | /* Use ns/us then divide to preserve precision */ |
| 2625 | sr_entries = (((sr_latency_ns / line_time_us) + 1) * |
| 2626 | pixel_size * sr_hdisplay) / 1000; |
| 2627 | sr_entries = roundup(sr_entries / cacheline_size, 1); |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 2628 | DRM_DEBUG_KMS("self-refresh entries: %d\n", sr_entries); |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2629 | srwm = total_size - sr_entries; |
| 2630 | if (srwm < 0) |
| 2631 | srwm = 1; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 2632 | I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN | (srwm & 0x3f)); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2633 | } |
| 2634 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 2635 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2636 | planea_wm, planeb_wm, cwm, srwm); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2637 | |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2638 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 2639 | fwater_hi = (cwm & 0x1f); |
| 2640 | |
| 2641 | /* Set request length to 8 cachelines per fetch */ |
| 2642 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 2643 | fwater_hi = fwater_hi | (1 << 8); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2644 | |
| 2645 | I915_WRITE(FW_BLC, fwater_lo); |
| 2646 | I915_WRITE(FW_BLC2, fwater_hi); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2647 | } |
| 2648 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2649 | static void i830_update_wm(struct drm_device *dev, int planea_clock, int unused, |
| 2650 | int unused2, int pixel_size) |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2651 | { |
| 2652 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | f360132 | 2009-07-22 12:54:59 -0700 | [diff] [blame] | 2653 | uint32_t fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2654 | int planea_wm; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2655 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2656 | 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] | 2657 | |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2658 | planea_wm = intel_calculate_wm(planea_clock, &i830_wm_info, |
| 2659 | pixel_size, latency_ns); |
Jesse Barnes | f360132 | 2009-07-22 12:54:59 -0700 | [diff] [blame] | 2660 | fwater_lo |= (3<<8) | planea_wm; |
| 2661 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 2662 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2663 | |
| 2664 | I915_WRITE(FW_BLC, fwater_lo); |
| 2665 | } |
| 2666 | |
| 2667 | /** |
| 2668 | * intel_update_watermarks - update FIFO watermark values based on current modes |
| 2669 | * |
| 2670 | * Calculate watermark values for the various WM regs based on current mode |
| 2671 | * and plane configuration. |
| 2672 | * |
| 2673 | * There are several cases to deal with here: |
| 2674 | * - normal (i.e. non-self-refresh) |
| 2675 | * - self-refresh (SR) mode |
| 2676 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 2677 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 2678 | * lines), so need to account for TLB latency |
| 2679 | * |
| 2680 | * The normal calculation is: |
| 2681 | * watermark = dotclock * bytes per pixel * latency |
| 2682 | * where latency is platform & configuration dependent (we assume pessimal |
| 2683 | * values here). |
| 2684 | * |
| 2685 | * The SR calculation is: |
| 2686 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 2687 | * bytes per pixel |
| 2688 | * where |
| 2689 | * line time = htotal / dotclock |
| 2690 | * and latency is assumed to be high, as above. |
| 2691 | * |
| 2692 | * The final value programmed to the register should always be rounded up, |
| 2693 | * and include an extra 2 entries to account for clock crossings. |
| 2694 | * |
| 2695 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 2696 | * to set the non-SR watermarks to 8. |
| 2697 | */ |
| 2698 | static void intel_update_watermarks(struct drm_device *dev) |
| 2699 | { |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2700 | struct drm_i915_private *dev_priv = dev->dev_private; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2701 | struct drm_crtc *crtc; |
| 2702 | struct intel_crtc *intel_crtc; |
| 2703 | int sr_hdisplay = 0; |
| 2704 | unsigned long planea_clock = 0, planeb_clock = 0, sr_clock = 0; |
| 2705 | int enabled = 0, pixel_size = 0; |
| 2706 | |
Zhenyu Wang | c03342f | 2009-09-29 11:01:23 +0800 | [diff] [blame] | 2707 | if (!dev_priv->display.update_wm) |
| 2708 | return; |
| 2709 | |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2710 | /* Get the clock config from both planes */ |
| 2711 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 2712 | intel_crtc = to_intel_crtc(crtc); |
| 2713 | if (crtc->enabled) { |
| 2714 | enabled++; |
| 2715 | if (intel_crtc->plane == 0) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 2716 | DRM_DEBUG_KMS("plane A (pipe %d) clock: %d\n", |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2717 | intel_crtc->pipe, crtc->mode.clock); |
| 2718 | planea_clock = crtc->mode.clock; |
| 2719 | } else { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 2720 | DRM_DEBUG_KMS("plane B (pipe %d) clock: %d\n", |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2721 | intel_crtc->pipe, crtc->mode.clock); |
| 2722 | planeb_clock = crtc->mode.clock; |
| 2723 | } |
| 2724 | sr_hdisplay = crtc->mode.hdisplay; |
| 2725 | sr_clock = crtc->mode.clock; |
| 2726 | if (crtc->fb) |
| 2727 | pixel_size = crtc->fb->bits_per_pixel / 8; |
| 2728 | else |
| 2729 | pixel_size = 4; /* by default */ |
| 2730 | } |
| 2731 | } |
| 2732 | |
| 2733 | if (enabled <= 0) |
| 2734 | return; |
| 2735 | |
Jesse Barnes | dff33cf | 2009-07-14 10:15:56 -0700 | [diff] [blame] | 2736 | /* Single plane configs can enable self refresh */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2737 | if (enabled == 1 && IS_PINEVIEW(dev)) |
| 2738 | pineview_enable_cxsr(dev, sr_clock, pixel_size); |
| 2739 | else if (IS_PINEVIEW(dev)) |
| 2740 | pineview_disable_cxsr(dev); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2741 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 2742 | dev_priv->display.update_wm(dev, planea_clock, planeb_clock, |
| 2743 | sr_hdisplay, pixel_size); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2744 | } |
| 2745 | |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2746 | static int intel_crtc_mode_set(struct drm_crtc *crtc, |
| 2747 | struct drm_display_mode *mode, |
| 2748 | struct drm_display_mode *adjusted_mode, |
| 2749 | int x, int y, |
| 2750 | struct drm_framebuffer *old_fb) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2751 | { |
| 2752 | struct drm_device *dev = crtc->dev; |
| 2753 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2754 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2755 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 2756 | int plane = intel_crtc->plane; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2757 | int fp_reg = (pipe == 0) ? FPA0 : FPB0; |
| 2758 | int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B; |
| 2759 | int dpll_md_reg = (intel_crtc->pipe == 0) ? DPLL_A_MD : DPLL_B_MD; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 2760 | int dspcntr_reg = (plane == 0) ? DSPACNTR : DSPBCNTR; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2761 | int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF; |
| 2762 | int htot_reg = (pipe == 0) ? HTOTAL_A : HTOTAL_B; |
| 2763 | int hblank_reg = (pipe == 0) ? HBLANK_A : HBLANK_B; |
| 2764 | int hsync_reg = (pipe == 0) ? HSYNC_A : HSYNC_B; |
| 2765 | int vtot_reg = (pipe == 0) ? VTOTAL_A : VTOTAL_B; |
| 2766 | int vblank_reg = (pipe == 0) ? VBLANK_A : VBLANK_B; |
| 2767 | int vsync_reg = (pipe == 0) ? VSYNC_A : VSYNC_B; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 2768 | int dspsize_reg = (plane == 0) ? DSPASIZE : DSPBSIZE; |
| 2769 | int dsppos_reg = (plane == 0) ? DSPAPOS : DSPBPOS; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2770 | int pipesrc_reg = (pipe == 0) ? PIPEASRC : PIPEBSRC; |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 2771 | int refclk, num_outputs = 0; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 2772 | intel_clock_t clock, reduced_clock; |
| 2773 | u32 dpll = 0, fp = 0, fp2 = 0, dspcntr, pipeconf; |
| 2774 | bool ok, has_reduced_clock = false, is_sdvo = false, is_dvo = false; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2775 | bool is_crt = false, is_lvds = false, is_tv = false, is_dp = false; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2776 | bool is_edp = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2777 | struct drm_mode_config *mode_config = &dev->mode_config; |
| 2778 | struct drm_connector *connector; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 2779 | const intel_limit_t *limit; |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2780 | int ret; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2781 | struct fdi_m_n m_n = {0}; |
| 2782 | int data_m1_reg = (pipe == 0) ? PIPEA_DATA_M1 : PIPEB_DATA_M1; |
| 2783 | int data_n1_reg = (pipe == 0) ? PIPEA_DATA_N1 : PIPEB_DATA_N1; |
| 2784 | int link_m1_reg = (pipe == 0) ? PIPEA_LINK_M1 : PIPEB_LINK_M1; |
| 2785 | int link_n1_reg = (pipe == 0) ? PIPEA_LINK_N1 : PIPEB_LINK_N1; |
| 2786 | int pch_fp_reg = (pipe == 0) ? PCH_FPA0 : PCH_FPB0; |
| 2787 | int pch_dpll_reg = (pipe == 0) ? PCH_DPLL_A : PCH_DPLL_B; |
| 2788 | int fdi_rx_reg = (pipe == 0) ? FDI_RXA_CTL : FDI_RXB_CTL; |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 2789 | int lvds_reg = LVDS; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2790 | u32 temp; |
| 2791 | int sdvo_pixel_multiply; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 2792 | int target_clock; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2793 | |
| 2794 | drm_vblank_pre_modeset(dev, pipe); |
| 2795 | |
| 2796 | list_for_each_entry(connector, &mode_config->connector_list, head) { |
| 2797 | struct intel_output *intel_output = to_intel_output(connector); |
| 2798 | |
| 2799 | if (!connector->encoder || connector->encoder->crtc != crtc) |
| 2800 | continue; |
| 2801 | |
| 2802 | switch (intel_output->type) { |
| 2803 | case INTEL_OUTPUT_LVDS: |
| 2804 | is_lvds = true; |
| 2805 | break; |
| 2806 | case INTEL_OUTPUT_SDVO: |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 2807 | case INTEL_OUTPUT_HDMI: |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2808 | is_sdvo = true; |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 2809 | if (intel_output->needs_tv_clock) |
| 2810 | is_tv = true; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2811 | break; |
| 2812 | case INTEL_OUTPUT_DVO: |
| 2813 | is_dvo = true; |
| 2814 | break; |
| 2815 | case INTEL_OUTPUT_TVOUT: |
| 2816 | is_tv = true; |
| 2817 | break; |
| 2818 | case INTEL_OUTPUT_ANALOG: |
| 2819 | is_crt = true; |
| 2820 | break; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2821 | case INTEL_OUTPUT_DISPLAYPORT: |
| 2822 | is_dp = true; |
| 2823 | break; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2824 | case INTEL_OUTPUT_EDP: |
| 2825 | is_edp = true; |
| 2826 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2827 | } |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 2828 | |
| 2829 | num_outputs++; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2830 | } |
| 2831 | |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 2832 | if (is_lvds && dev_priv->lvds_use_ssc && num_outputs < 2) { |
| 2833 | refclk = dev_priv->lvds_ssc_freq * 1000; |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 2834 | DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n", |
| 2835 | refclk / 1000); |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 2836 | } else if (IS_I9XX(dev)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2837 | refclk = 96000; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2838 | if (IS_IRONLAKE(dev)) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2839 | refclk = 120000; /* 120Mhz refclk */ |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2840 | } else { |
| 2841 | refclk = 48000; |
| 2842 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2843 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2844 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 2845 | /* |
| 2846 | * Returns a set of divisors for the desired target clock with the given |
| 2847 | * refclk, or FALSE. The returned values represent the clock equation: |
| 2848 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 2849 | */ |
| 2850 | limit = intel_limit(crtc); |
| 2851 | ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2852 | if (!ok) { |
| 2853 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
Chris Wilson | 1f803ee | 2009-06-06 09:45:59 +0100 | [diff] [blame] | 2854 | drm_vblank_post_modeset(dev, pipe); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2855 | return -EINVAL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2856 | } |
| 2857 | |
Zhao Yakui | ddc9003 | 2010-01-06 22:05:56 +0800 | [diff] [blame] | 2858 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
| 2859 | has_reduced_clock = limit->find_pll(limit, crtc, |
Zhao Yakui | 18f9ed1 | 2009-11-20 03:24:16 +0000 | [diff] [blame] | 2860 | dev_priv->lvds_downclock, |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 2861 | refclk, |
| 2862 | &reduced_clock); |
Zhao Yakui | 18f9ed1 | 2009-11-20 03:24:16 +0000 | [diff] [blame] | 2863 | if (has_reduced_clock && (clock.p != reduced_clock.p)) { |
| 2864 | /* |
| 2865 | * If the different P is found, it means that we can't |
| 2866 | * switch the display clock by using the FP0/FP1. |
| 2867 | * In such case we will disable the LVDS downclock |
| 2868 | * feature. |
| 2869 | */ |
| 2870 | DRM_DEBUG_KMS("Different P is found for " |
| 2871 | "LVDS clock/downclock\n"); |
| 2872 | has_reduced_clock = 0; |
| 2873 | } |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 2874 | } |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 2875 | /* SDVO TV has fixed PLL values depend on its clock range, |
| 2876 | this mirrors vbios setting. */ |
| 2877 | if (is_sdvo && is_tv) { |
| 2878 | if (adjusted_mode->clock >= 100000 |
| 2879 | && adjusted_mode->clock < 140500) { |
| 2880 | clock.p1 = 2; |
| 2881 | clock.p2 = 10; |
| 2882 | clock.n = 3; |
| 2883 | clock.m1 = 16; |
| 2884 | clock.m2 = 8; |
| 2885 | } else if (adjusted_mode->clock >= 140500 |
| 2886 | && adjusted_mode->clock <= 200000) { |
| 2887 | clock.p1 = 1; |
| 2888 | clock.p2 = 10; |
| 2889 | clock.n = 6; |
| 2890 | clock.m1 = 12; |
| 2891 | clock.m2 = 8; |
| 2892 | } |
| 2893 | } |
| 2894 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2895 | /* FDI link */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2896 | if (IS_IRONLAKE(dev)) { |
Zhenyu Wang | 58a2747 | 2009-09-25 08:01:28 +0000 | [diff] [blame] | 2897 | int lane, link_bw, bpp; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2898 | /* eDP doesn't require FDI link, so just set DP M/N |
| 2899 | according to current link config */ |
| 2900 | if (is_edp) { |
| 2901 | struct drm_connector *edp; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 2902 | target_clock = mode->clock; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2903 | edp = intel_pipe_get_output(crtc); |
| 2904 | intel_edp_link_config(to_intel_output(edp), |
| 2905 | &lane, &link_bw); |
| 2906 | } else { |
| 2907 | /* DP over FDI requires target mode clock |
| 2908 | instead of link clock */ |
| 2909 | if (is_dp) |
| 2910 | target_clock = mode->clock; |
| 2911 | else |
| 2912 | target_clock = adjusted_mode->clock; |
| 2913 | lane = 4; |
| 2914 | link_bw = 270000; |
| 2915 | } |
Zhenyu Wang | 58a2747 | 2009-09-25 08:01:28 +0000 | [diff] [blame] | 2916 | |
| 2917 | /* determine panel color depth */ |
| 2918 | temp = I915_READ(pipeconf_reg); |
Zhao Yakui | e5a95eb | 2010-01-04 16:29:32 +0800 | [diff] [blame] | 2919 | temp &= ~PIPE_BPC_MASK; |
| 2920 | if (is_lvds) { |
| 2921 | int lvds_reg = I915_READ(PCH_LVDS); |
| 2922 | /* the BPC will be 6 if it is 18-bit LVDS panel */ |
| 2923 | if ((lvds_reg & LVDS_A3_POWER_MASK) == LVDS_A3_POWER_UP) |
| 2924 | temp |= PIPE_8BPC; |
| 2925 | else |
| 2926 | temp |= PIPE_6BPC; |
| 2927 | } else |
| 2928 | temp |= PIPE_8BPC; |
| 2929 | I915_WRITE(pipeconf_reg, temp); |
| 2930 | I915_READ(pipeconf_reg); |
Zhenyu Wang | 58a2747 | 2009-09-25 08:01:28 +0000 | [diff] [blame] | 2931 | |
| 2932 | switch (temp & PIPE_BPC_MASK) { |
| 2933 | case PIPE_8BPC: |
| 2934 | bpp = 24; |
| 2935 | break; |
| 2936 | case PIPE_10BPC: |
| 2937 | bpp = 30; |
| 2938 | break; |
| 2939 | case PIPE_6BPC: |
| 2940 | bpp = 18; |
| 2941 | break; |
| 2942 | case PIPE_12BPC: |
| 2943 | bpp = 36; |
| 2944 | break; |
| 2945 | default: |
| 2946 | DRM_ERROR("unknown pipe bpc value\n"); |
| 2947 | bpp = 24; |
| 2948 | } |
| 2949 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2950 | ironlake_compute_m_n(bpp, lane, target_clock, link_bw, &m_n); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 2951 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2952 | |
Zhenyu Wang | c038e51 | 2009-10-19 15:43:48 +0800 | [diff] [blame] | 2953 | /* Ironlake: try to setup display ref clock before DPLL |
| 2954 | * enabling. This is only under driver's control after |
| 2955 | * PCH B stepping, previous chipset stepping should be |
| 2956 | * ignoring this setting. |
| 2957 | */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2958 | if (IS_IRONLAKE(dev)) { |
Zhenyu Wang | c038e51 | 2009-10-19 15:43:48 +0800 | [diff] [blame] | 2959 | temp = I915_READ(PCH_DREF_CONTROL); |
| 2960 | /* Always enable nonspread source */ |
| 2961 | temp &= ~DREF_NONSPREAD_SOURCE_MASK; |
| 2962 | temp |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 2963 | I915_WRITE(PCH_DREF_CONTROL, temp); |
| 2964 | POSTING_READ(PCH_DREF_CONTROL); |
| 2965 | |
| 2966 | temp &= ~DREF_SSC_SOURCE_MASK; |
| 2967 | temp |= DREF_SSC_SOURCE_ENABLE; |
| 2968 | I915_WRITE(PCH_DREF_CONTROL, temp); |
| 2969 | POSTING_READ(PCH_DREF_CONTROL); |
| 2970 | |
| 2971 | udelay(200); |
| 2972 | |
| 2973 | if (is_edp) { |
| 2974 | if (dev_priv->lvds_use_ssc) { |
| 2975 | temp |= DREF_SSC1_ENABLE; |
| 2976 | I915_WRITE(PCH_DREF_CONTROL, temp); |
| 2977 | POSTING_READ(PCH_DREF_CONTROL); |
| 2978 | |
| 2979 | udelay(200); |
| 2980 | |
| 2981 | temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
| 2982 | temp |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
| 2983 | I915_WRITE(PCH_DREF_CONTROL, temp); |
| 2984 | POSTING_READ(PCH_DREF_CONTROL); |
| 2985 | } else { |
| 2986 | temp |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
| 2987 | I915_WRITE(PCH_DREF_CONTROL, temp); |
| 2988 | POSTING_READ(PCH_DREF_CONTROL); |
| 2989 | } |
| 2990 | } |
| 2991 | } |
| 2992 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 2993 | if (IS_PINEVIEW(dev)) { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 2994 | fp = (1 << clock.n) << 16 | clock.m1 << 8 | clock.m2; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 2995 | if (has_reduced_clock) |
| 2996 | fp2 = (1 << reduced_clock.n) << 16 | |
| 2997 | reduced_clock.m1 << 8 | reduced_clock.m2; |
| 2998 | } else { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 2999 | fp = clock.n << 16 | clock.m1 << 8 | clock.m2; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3000 | if (has_reduced_clock) |
| 3001 | fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 | |
| 3002 | reduced_clock.m2; |
| 3003 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3004 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 3005 | if (!IS_IRONLAKE(dev)) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3006 | dpll = DPLL_VGA_MODE_DIS; |
| 3007 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3008 | if (IS_I9XX(dev)) { |
| 3009 | if (is_lvds) |
| 3010 | dpll |= DPLLB_MODE_LVDS; |
| 3011 | else |
| 3012 | dpll |= DPLLB_MODE_DAC_SERIAL; |
| 3013 | if (is_sdvo) { |
| 3014 | dpll |= DPLL_DVO_HIGH_SPEED; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3015 | sdvo_pixel_multiply = adjusted_mode->clock / mode->clock; |
Sean Young | 942642a | 2009-08-06 17:35:50 +0800 | [diff] [blame] | 3016 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3017 | dpll |= (sdvo_pixel_multiply - 1) << SDVO_MULTIPLIER_SHIFT_HIRES; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 3018 | else if (IS_IRONLAKE(dev)) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3019 | dpll |= (sdvo_pixel_multiply - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3020 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3021 | if (is_dp) |
| 3022 | dpll |= DPLL_DVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3023 | |
| 3024 | /* compute bitmask from p1 value */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 3025 | if (IS_PINEVIEW(dev)) |
| 3026 | dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3027 | else { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 3028 | dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3029 | /* also FPA1 */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 3030 | if (IS_IRONLAKE(dev)) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3031 | dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3032 | if (IS_G4X(dev) && has_reduced_clock) |
| 3033 | dpll |= (1 << (reduced_clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3034 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3035 | switch (clock.p2) { |
| 3036 | case 5: |
| 3037 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 3038 | break; |
| 3039 | case 7: |
| 3040 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 3041 | break; |
| 3042 | case 10: |
| 3043 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 3044 | break; |
| 3045 | case 14: |
| 3046 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 3047 | break; |
| 3048 | } |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 3049 | if (IS_I965G(dev) && !IS_IRONLAKE(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3050 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
| 3051 | } else { |
| 3052 | if (is_lvds) { |
| 3053 | dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 3054 | } else { |
| 3055 | if (clock.p1 == 2) |
| 3056 | dpll |= PLL_P1_DIVIDE_BY_TWO; |
| 3057 | else |
| 3058 | dpll |= (clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 3059 | if (clock.p2 == 4) |
| 3060 | dpll |= PLL_P2_DIVIDE_BY_4; |
| 3061 | } |
| 3062 | } |
| 3063 | |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 3064 | if (is_sdvo && is_tv) |
| 3065 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
| 3066 | else if (is_tv) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3067 | /* XXX: just matching BIOS for now */ |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 3068 | /* dpll |= PLL_REF_INPUT_TVCLKINBC; */ |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3069 | dpll |= 3; |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 3070 | else if (is_lvds && dev_priv->lvds_use_ssc && num_outputs < 2) |
| 3071 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3072 | else |
| 3073 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 3074 | |
| 3075 | /* setup pipeconf */ |
| 3076 | pipeconf = I915_READ(pipeconf_reg); |
| 3077 | |
| 3078 | /* Set up the display plane register */ |
| 3079 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
| 3080 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 3081 | /* Ironlake's plane is forced to pipe, bit 24 is to |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3082 | enable color space conversion */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 3083 | if (!IS_IRONLAKE(dev)) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3084 | if (pipe == 0) |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 3085 | dspcntr &= ~DISPPLANE_SEL_PIPE_MASK; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3086 | else |
| 3087 | dspcntr |= DISPPLANE_SEL_PIPE_B; |
| 3088 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3089 | |
| 3090 | if (pipe == 0 && !IS_I965G(dev)) { |
| 3091 | /* Enable pixel doubling when the dot clock is > 90% of the (display) |
| 3092 | * core speed. |
| 3093 | * |
| 3094 | * XXX: No double-wide on 915GM pipe B. Is that the only reason for the |
| 3095 | * pipe == 0 check? |
| 3096 | */ |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 3097 | if (mode->clock > |
| 3098 | dev_priv->display.get_display_clock_speed(dev) * 9 / 10) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3099 | pipeconf |= PIPEACONF_DOUBLE_WIDE; |
| 3100 | else |
| 3101 | pipeconf &= ~PIPEACONF_DOUBLE_WIDE; |
| 3102 | } |
| 3103 | |
| 3104 | dspcntr |= DISPLAY_PLANE_ENABLE; |
| 3105 | pipeconf |= PIPEACONF_ENABLE; |
| 3106 | dpll |= DPLL_VCO_ENABLE; |
| 3107 | |
| 3108 | |
| 3109 | /* Disable the panel fitter if it was on our pipe */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 3110 | if (!IS_IRONLAKE(dev) && intel_panel_fitter_pipe(dev) == pipe) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3111 | I915_WRITE(PFIT_CONTROL, 0); |
| 3112 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3113 | DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B'); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3114 | drm_mode_debug_printmodeline(mode); |
| 3115 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 3116 | /* assign to Ironlake registers */ |
| 3117 | if (IS_IRONLAKE(dev)) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3118 | fp_reg = pch_fp_reg; |
| 3119 | dpll_reg = pch_dpll_reg; |
| 3120 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3121 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 3122 | if (is_edp) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 3123 | ironlake_disable_pll_edp(crtc); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 3124 | } else if ((dpll & DPLL_VCO_ENABLE)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3125 | I915_WRITE(fp_reg, fp); |
| 3126 | I915_WRITE(dpll_reg, dpll & ~DPLL_VCO_ENABLE); |
| 3127 | I915_READ(dpll_reg); |
| 3128 | udelay(150); |
| 3129 | } |
| 3130 | |
| 3131 | /* The LVDS pin pair needs to be on before the DPLLs are enabled. |
| 3132 | * This is an exception to the general rule that mode_set doesn't turn |
| 3133 | * things on. |
| 3134 | */ |
| 3135 | if (is_lvds) { |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 3136 | u32 lvds; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3137 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 3138 | if (IS_IRONLAKE(dev)) |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 3139 | lvds_reg = PCH_LVDS; |
| 3140 | |
| 3141 | lvds = I915_READ(lvds_reg); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3142 | lvds |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP | LVDS_PIPEB_SELECT; |
Zhao Yakui | a3e17eb | 2009-10-10 10:42:37 +0800 | [diff] [blame] | 3143 | /* set the corresponsding LVDS_BORDER bit */ |
| 3144 | lvds |= dev_priv->lvds_border_bits; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3145 | /* Set the B0-B3 data pairs corresponding to whether we're going to |
| 3146 | * set the DPLLs for dual-channel mode or not. |
| 3147 | */ |
| 3148 | if (clock.p2 == 7) |
| 3149 | lvds |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP; |
| 3150 | else |
| 3151 | lvds &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP); |
| 3152 | |
| 3153 | /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP) |
| 3154 | * appropriately here, but we need to look more thoroughly into how |
| 3155 | * panels behave in the two modes. |
| 3156 | */ |
Zhao Yakui | 898822c | 2010-01-04 16:29:30 +0800 | [diff] [blame] | 3157 | /* set the dithering flag */ |
| 3158 | if (IS_I965G(dev)) { |
| 3159 | if (dev_priv->lvds_dither) { |
| 3160 | if (IS_IRONLAKE(dev)) |
| 3161 | pipeconf |= PIPE_ENABLE_DITHER; |
| 3162 | else |
| 3163 | lvds |= LVDS_ENABLE_DITHER; |
| 3164 | } else { |
| 3165 | if (IS_IRONLAKE(dev)) |
| 3166 | pipeconf &= ~PIPE_ENABLE_DITHER; |
| 3167 | else |
| 3168 | lvds &= ~LVDS_ENABLE_DITHER; |
| 3169 | } |
| 3170 | } |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 3171 | I915_WRITE(lvds_reg, lvds); |
| 3172 | I915_READ(lvds_reg); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3173 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 3174 | if (is_dp) |
| 3175 | intel_dp_set_m_n(crtc, mode, adjusted_mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3176 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 3177 | if (!is_edp) { |
| 3178 | I915_WRITE(fp_reg, fp); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3179 | I915_WRITE(dpll_reg, dpll); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 3180 | I915_READ(dpll_reg); |
| 3181 | /* Wait for the clocks to stabilize. */ |
| 3182 | udelay(150); |
| 3183 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 3184 | if (IS_I965G(dev) && !IS_IRONLAKE(dev)) { |
Zhao Yakui | bb66c51 | 2009-09-10 15:45:49 +0800 | [diff] [blame] | 3185 | if (is_sdvo) { |
| 3186 | sdvo_pixel_multiply = adjusted_mode->clock / mode->clock; |
| 3187 | I915_WRITE(dpll_md_reg, (0 << DPLL_MD_UDI_DIVIDER_SHIFT) | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 3188 | ((sdvo_pixel_multiply - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT)); |
Zhao Yakui | bb66c51 | 2009-09-10 15:45:49 +0800 | [diff] [blame] | 3189 | } else |
| 3190 | I915_WRITE(dpll_md_reg, 0); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 3191 | } else { |
| 3192 | /* write it again -- the BIOS does, after all */ |
| 3193 | I915_WRITE(dpll_reg, dpll); |
| 3194 | } |
| 3195 | I915_READ(dpll_reg); |
| 3196 | /* Wait for the clocks to stabilize. */ |
| 3197 | udelay(150); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3198 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3199 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3200 | if (is_lvds && has_reduced_clock && i915_powersave) { |
| 3201 | I915_WRITE(fp_reg + 4, fp2); |
| 3202 | intel_crtc->lowfreq_avail = true; |
| 3203 | if (HAS_PIPE_CXSR(dev)) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3204 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3205 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; |
| 3206 | } |
| 3207 | } else { |
| 3208 | I915_WRITE(fp_reg + 4, fp); |
| 3209 | intel_crtc->lowfreq_avail = false; |
| 3210 | if (HAS_PIPE_CXSR(dev)) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3211 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3212 | pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK; |
| 3213 | } |
| 3214 | } |
| 3215 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3216 | I915_WRITE(htot_reg, (adjusted_mode->crtc_hdisplay - 1) | |
| 3217 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
| 3218 | I915_WRITE(hblank_reg, (adjusted_mode->crtc_hblank_start - 1) | |
| 3219 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
| 3220 | I915_WRITE(hsync_reg, (adjusted_mode->crtc_hsync_start - 1) | |
| 3221 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
| 3222 | I915_WRITE(vtot_reg, (adjusted_mode->crtc_vdisplay - 1) | |
| 3223 | ((adjusted_mode->crtc_vtotal - 1) << 16)); |
| 3224 | I915_WRITE(vblank_reg, (adjusted_mode->crtc_vblank_start - 1) | |
| 3225 | ((adjusted_mode->crtc_vblank_end - 1) << 16)); |
| 3226 | I915_WRITE(vsync_reg, (adjusted_mode->crtc_vsync_start - 1) | |
| 3227 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
| 3228 | /* pipesrc and dspsize control the size that is scaled from, which should |
| 3229 | * always be the user's requested size. |
| 3230 | */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 3231 | if (!IS_IRONLAKE(dev)) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3232 | I915_WRITE(dspsize_reg, ((mode->vdisplay - 1) << 16) | |
| 3233 | (mode->hdisplay - 1)); |
| 3234 | I915_WRITE(dsppos_reg, 0); |
| 3235 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3236 | I915_WRITE(pipesrc_reg, ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1)); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3237 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 3238 | if (IS_IRONLAKE(dev)) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3239 | I915_WRITE(data_m1_reg, TU_SIZE(m_n.tu) | m_n.gmch_m); |
| 3240 | I915_WRITE(data_n1_reg, TU_SIZE(m_n.tu) | m_n.gmch_n); |
| 3241 | I915_WRITE(link_m1_reg, m_n.link_m); |
| 3242 | I915_WRITE(link_n1_reg, m_n.link_n); |
| 3243 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 3244 | if (is_edp) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 3245 | ironlake_set_pll_edp(crtc, adjusted_mode->clock); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 3246 | } else { |
| 3247 | /* enable FDI RX PLL too */ |
| 3248 | temp = I915_READ(fdi_rx_reg); |
| 3249 | I915_WRITE(fdi_rx_reg, temp | FDI_RX_PLL_ENABLE); |
| 3250 | udelay(200); |
| 3251 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3252 | } |
| 3253 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3254 | I915_WRITE(pipeconf_reg, pipeconf); |
| 3255 | I915_READ(pipeconf_reg); |
| 3256 | |
| 3257 | intel_wait_for_vblank(dev); |
| 3258 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 3259 | if (IS_IRONLAKE(dev)) { |
Zhenyu Wang | 553bd14 | 2009-09-02 10:57:52 +0800 | [diff] [blame] | 3260 | /* enable address swizzle for tiling buffer */ |
| 3261 | temp = I915_READ(DISP_ARB_CTL); |
| 3262 | I915_WRITE(DISP_ARB_CTL, temp | DISP_TILE_SURFACE_SWIZZLING); |
| 3263 | } |
| 3264 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3265 | I915_WRITE(dspcntr_reg, dspcntr); |
| 3266 | |
| 3267 | /* Flush the plane changes */ |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 3268 | ret = intel_pipe_set_base(crtc, x, y, old_fb); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3269 | |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 3270 | if ((IS_I965G(dev) || plane == 0)) |
| 3271 | intel_update_fbc(crtc, &crtc->mode); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 3272 | |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 3273 | intel_update_watermarks(dev); |
| 3274 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3275 | drm_vblank_post_modeset(dev, pipe); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 3276 | |
Chris Wilson | 1f803ee | 2009-06-06 09:45:59 +0100 | [diff] [blame] | 3277 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3278 | } |
| 3279 | |
| 3280 | /** Loads the palette/gamma unit for the CRTC with the prepared values */ |
| 3281 | void intel_crtc_load_lut(struct drm_crtc *crtc) |
| 3282 | { |
| 3283 | struct drm_device *dev = crtc->dev; |
| 3284 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3285 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3286 | int palreg = (intel_crtc->pipe == 0) ? PALETTE_A : PALETTE_B; |
| 3287 | int i; |
| 3288 | |
| 3289 | /* The clocks have to be on to load the palette. */ |
| 3290 | if (!crtc->enabled) |
| 3291 | return; |
| 3292 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 3293 | /* use legacy palette for Ironlake */ |
| 3294 | if (IS_IRONLAKE(dev)) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3295 | palreg = (intel_crtc->pipe == 0) ? LGC_PALETTE_A : |
| 3296 | LGC_PALETTE_B; |
| 3297 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3298 | for (i = 0; i < 256; i++) { |
| 3299 | I915_WRITE(palreg + 4 * i, |
| 3300 | (intel_crtc->lut_r[i] << 16) | |
| 3301 | (intel_crtc->lut_g[i] << 8) | |
| 3302 | intel_crtc->lut_b[i]); |
| 3303 | } |
| 3304 | } |
| 3305 | |
| 3306 | static int intel_crtc_cursor_set(struct drm_crtc *crtc, |
| 3307 | struct drm_file *file_priv, |
| 3308 | uint32_t handle, |
| 3309 | uint32_t width, uint32_t height) |
| 3310 | { |
| 3311 | struct drm_device *dev = crtc->dev; |
| 3312 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3313 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3314 | struct drm_gem_object *bo; |
| 3315 | struct drm_i915_gem_object *obj_priv; |
| 3316 | int pipe = intel_crtc->pipe; |
| 3317 | uint32_t control = (pipe == 0) ? CURACNTR : CURBCNTR; |
| 3318 | uint32_t base = (pipe == 0) ? CURABASE : CURBBASE; |
Jesse Barnes | 14b6039 | 2009-05-20 16:47:08 -0400 | [diff] [blame] | 3319 | uint32_t temp = I915_READ(control); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3320 | size_t addr; |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 3321 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3322 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3323 | DRM_DEBUG_KMS("\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3324 | |
| 3325 | /* if we want to turn off the cursor ignore width and height */ |
| 3326 | if (!handle) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3327 | DRM_DEBUG_KMS("cursor off\n"); |
Jesse Barnes | 14b6039 | 2009-05-20 16:47:08 -0400 | [diff] [blame] | 3328 | if (IS_MOBILE(dev) || IS_I9XX(dev)) { |
| 3329 | temp &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE); |
| 3330 | temp |= CURSOR_MODE_DISABLE; |
| 3331 | } else { |
| 3332 | temp &= ~(CURSOR_ENABLE | CURSOR_GAMMA_ENABLE); |
| 3333 | } |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 3334 | addr = 0; |
| 3335 | bo = NULL; |
Pierre Willenbrock | 5004417 | 2009-02-23 10:12:15 +1000 | [diff] [blame] | 3336 | mutex_lock(&dev->struct_mutex); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 3337 | goto finish; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3338 | } |
| 3339 | |
| 3340 | /* Currently we only support 64x64 cursors */ |
| 3341 | if (width != 64 || height != 64) { |
| 3342 | DRM_ERROR("we currently only support 64x64 cursors\n"); |
| 3343 | return -EINVAL; |
| 3344 | } |
| 3345 | |
| 3346 | bo = drm_gem_object_lookup(dev, file_priv, handle); |
| 3347 | if (!bo) |
| 3348 | return -ENOENT; |
| 3349 | |
| 3350 | obj_priv = bo->driver_private; |
| 3351 | |
| 3352 | if (bo->size < width * height * 4) { |
| 3353 | DRM_ERROR("buffer is to small\n"); |
Dave Airlie | 34b8686e | 2009-01-15 14:03:07 +1000 | [diff] [blame] | 3354 | ret = -ENOMEM; |
| 3355 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3356 | } |
| 3357 | |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 3358 | /* 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] | 3359 | mutex_lock(&dev->struct_mutex); |
Kristian Høgsberg | b295d1b | 2009-12-16 15:16:17 -0500 | [diff] [blame] | 3360 | if (!dev_priv->info->cursor_needs_physical) { |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 3361 | ret = i915_gem_object_pin(bo, PAGE_SIZE); |
| 3362 | if (ret) { |
| 3363 | DRM_ERROR("failed to pin cursor bo\n"); |
Kristian Høgsberg | 7f9872e | 2009-02-13 20:56:49 -0500 | [diff] [blame] | 3364 | goto fail_locked; |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 3365 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3366 | addr = obj_priv->gtt_offset; |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 3367 | } else { |
| 3368 | ret = i915_gem_attach_phys_object(dev, bo, (pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1); |
| 3369 | if (ret) { |
| 3370 | DRM_ERROR("failed to attach phys object\n"); |
Kristian Høgsberg | 7f9872e | 2009-02-13 20:56:49 -0500 | [diff] [blame] | 3371 | goto fail_locked; |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 3372 | } |
| 3373 | addr = obj_priv->phys_obj->handle->busaddr; |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 3374 | } |
| 3375 | |
Jesse Barnes | 14b6039 | 2009-05-20 16:47:08 -0400 | [diff] [blame] | 3376 | if (!IS_I9XX(dev)) |
| 3377 | I915_WRITE(CURSIZE, (height << 12) | width); |
| 3378 | |
| 3379 | /* Hooray for CUR*CNTR differences */ |
| 3380 | if (IS_MOBILE(dev) || IS_I9XX(dev)) { |
| 3381 | temp &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT); |
| 3382 | temp |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE; |
| 3383 | temp |= (pipe << 28); /* Connect to correct pipe */ |
| 3384 | } else { |
| 3385 | temp &= ~(CURSOR_FORMAT_MASK); |
| 3386 | temp |= CURSOR_ENABLE; |
| 3387 | temp |= CURSOR_FORMAT_ARGB | CURSOR_GAMMA_ENABLE; |
| 3388 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3389 | |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 3390 | finish: |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3391 | I915_WRITE(control, temp); |
| 3392 | I915_WRITE(base, addr); |
| 3393 | |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 3394 | if (intel_crtc->cursor_bo) { |
Kristian Høgsberg | b295d1b | 2009-12-16 15:16:17 -0500 | [diff] [blame] | 3395 | if (dev_priv->info->cursor_needs_physical) { |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 3396 | if (intel_crtc->cursor_bo != bo) |
| 3397 | i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo); |
| 3398 | } else |
| 3399 | i915_gem_object_unpin(intel_crtc->cursor_bo); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 3400 | drm_gem_object_unreference(intel_crtc->cursor_bo); |
| 3401 | } |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 3402 | |
Kristian Høgsberg | 7f9872e | 2009-02-13 20:56:49 -0500 | [diff] [blame] | 3403 | mutex_unlock(&dev->struct_mutex); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 3404 | |
| 3405 | intel_crtc->cursor_addr = addr; |
| 3406 | intel_crtc->cursor_bo = bo; |
| 3407 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3408 | return 0; |
Dave Airlie | 34b8686e | 2009-01-15 14:03:07 +1000 | [diff] [blame] | 3409 | fail: |
| 3410 | mutex_lock(&dev->struct_mutex); |
Kristian Høgsberg | 7f9872e | 2009-02-13 20:56:49 -0500 | [diff] [blame] | 3411 | fail_locked: |
Dave Airlie | 34b8686e | 2009-01-15 14:03:07 +1000 | [diff] [blame] | 3412 | drm_gem_object_unreference(bo); |
| 3413 | mutex_unlock(&dev->struct_mutex); |
| 3414 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3415 | } |
| 3416 | |
| 3417 | static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) |
| 3418 | { |
| 3419 | struct drm_device *dev = crtc->dev; |
| 3420 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3421 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3422 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3423 | int pipe = intel_crtc->pipe; |
| 3424 | uint32_t temp = 0; |
| 3425 | uint32_t adder; |
| 3426 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3427 | if (crtc->fb) { |
| 3428 | intel_fb = to_intel_framebuffer(crtc->fb); |
| 3429 | intel_mark_busy(dev, intel_fb->obj); |
| 3430 | } |
| 3431 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3432 | if (x < 0) { |
Keith Packard | 2245fda | 2009-05-30 20:42:29 -0700 | [diff] [blame] | 3433 | temp |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3434 | x = -x; |
| 3435 | } |
| 3436 | if (y < 0) { |
Keith Packard | 2245fda | 2009-05-30 20:42:29 -0700 | [diff] [blame] | 3437 | temp |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3438 | y = -y; |
| 3439 | } |
| 3440 | |
Keith Packard | 2245fda | 2009-05-30 20:42:29 -0700 | [diff] [blame] | 3441 | temp |= x << CURSOR_X_SHIFT; |
| 3442 | temp |= y << CURSOR_Y_SHIFT; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3443 | |
| 3444 | adder = intel_crtc->cursor_addr; |
| 3445 | I915_WRITE((pipe == 0) ? CURAPOS : CURBPOS, temp); |
| 3446 | I915_WRITE((pipe == 0) ? CURABASE : CURBBASE, adder); |
| 3447 | |
| 3448 | return 0; |
| 3449 | } |
| 3450 | |
| 3451 | /** Sets the color ramps on behalf of RandR */ |
| 3452 | void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green, |
| 3453 | u16 blue, int regno) |
| 3454 | { |
| 3455 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3456 | |
| 3457 | intel_crtc->lut_r[regno] = red >> 8; |
| 3458 | intel_crtc->lut_g[regno] = green >> 8; |
| 3459 | intel_crtc->lut_b[regno] = blue >> 8; |
| 3460 | } |
| 3461 | |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 3462 | void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green, |
| 3463 | u16 *blue, int regno) |
| 3464 | { |
| 3465 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3466 | |
| 3467 | *red = intel_crtc->lut_r[regno] << 8; |
| 3468 | *green = intel_crtc->lut_g[regno] << 8; |
| 3469 | *blue = intel_crtc->lut_b[regno] << 8; |
| 3470 | } |
| 3471 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3472 | static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, |
| 3473 | u16 *blue, uint32_t size) |
| 3474 | { |
| 3475 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3476 | int i; |
| 3477 | |
| 3478 | if (size != 256) |
| 3479 | return; |
| 3480 | |
| 3481 | for (i = 0; i < 256; i++) { |
| 3482 | intel_crtc->lut_r[i] = red[i] >> 8; |
| 3483 | intel_crtc->lut_g[i] = green[i] >> 8; |
| 3484 | intel_crtc->lut_b[i] = blue[i] >> 8; |
| 3485 | } |
| 3486 | |
| 3487 | intel_crtc_load_lut(crtc); |
| 3488 | } |
| 3489 | |
| 3490 | /** |
| 3491 | * Get a pipe with a simple mode set on it for doing load-based monitor |
| 3492 | * detection. |
| 3493 | * |
| 3494 | * It will be up to the load-detect code to adjust the pipe as appropriate for |
| 3495 | * its requirements. The pipe will be connected to no other outputs. |
| 3496 | * |
| 3497 | * Currently this code will only succeed if there is a pipe with no outputs |
| 3498 | * configured for it. In the future, it could choose to temporarily disable |
| 3499 | * some outputs to free up a pipe for its use. |
| 3500 | * |
| 3501 | * \return crtc, or NULL if no pipes are available. |
| 3502 | */ |
| 3503 | |
| 3504 | /* VESA 640x480x72Hz mode to set on the pipe */ |
| 3505 | static struct drm_display_mode load_detect_mode = { |
| 3506 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
| 3507 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
| 3508 | }; |
| 3509 | |
| 3510 | struct drm_crtc *intel_get_load_detect_pipe(struct intel_output *intel_output, |
| 3511 | struct drm_display_mode *mode, |
| 3512 | int *dpms_mode) |
| 3513 | { |
| 3514 | struct intel_crtc *intel_crtc; |
| 3515 | struct drm_crtc *possible_crtc; |
| 3516 | struct drm_crtc *supported_crtc =NULL; |
| 3517 | struct drm_encoder *encoder = &intel_output->enc; |
| 3518 | struct drm_crtc *crtc = NULL; |
| 3519 | struct drm_device *dev = encoder->dev; |
| 3520 | struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; |
| 3521 | struct drm_crtc_helper_funcs *crtc_funcs; |
| 3522 | int i = -1; |
| 3523 | |
| 3524 | /* |
| 3525 | * Algorithm gets a little messy: |
| 3526 | * - if the connector already has an assigned crtc, use it (but make |
| 3527 | * sure it's on first) |
| 3528 | * - try to find the first unused crtc that can drive this connector, |
| 3529 | * and use that if we find one |
| 3530 | * - if there are no unused crtcs available, try to use the first |
| 3531 | * one we found that supports the connector |
| 3532 | */ |
| 3533 | |
| 3534 | /* See if we already have a CRTC for this connector */ |
| 3535 | if (encoder->crtc) { |
| 3536 | crtc = encoder->crtc; |
| 3537 | /* Make sure the crtc and connector are running */ |
| 3538 | intel_crtc = to_intel_crtc(crtc); |
| 3539 | *dpms_mode = intel_crtc->dpms_mode; |
| 3540 | if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) { |
| 3541 | crtc_funcs = crtc->helper_private; |
| 3542 | crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON); |
| 3543 | encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON); |
| 3544 | } |
| 3545 | return crtc; |
| 3546 | } |
| 3547 | |
| 3548 | /* Find an unused one (if possible) */ |
| 3549 | list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) { |
| 3550 | i++; |
| 3551 | if (!(encoder->possible_crtcs & (1 << i))) |
| 3552 | continue; |
| 3553 | if (!possible_crtc->enabled) { |
| 3554 | crtc = possible_crtc; |
| 3555 | break; |
| 3556 | } |
| 3557 | if (!supported_crtc) |
| 3558 | supported_crtc = possible_crtc; |
| 3559 | } |
| 3560 | |
| 3561 | /* |
| 3562 | * If we didn't find an unused CRTC, don't use any. |
| 3563 | */ |
| 3564 | if (!crtc) { |
| 3565 | return NULL; |
| 3566 | } |
| 3567 | |
| 3568 | encoder->crtc = crtc; |
Keith Packard | 03d6069 | 2009-06-05 18:19:56 -0700 | [diff] [blame] | 3569 | intel_output->base.encoder = encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3570 | intel_output->load_detect_temp = true; |
| 3571 | |
| 3572 | intel_crtc = to_intel_crtc(crtc); |
| 3573 | *dpms_mode = intel_crtc->dpms_mode; |
| 3574 | |
| 3575 | if (!crtc->enabled) { |
| 3576 | if (!mode) |
| 3577 | mode = &load_detect_mode; |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 3578 | drm_crtc_helper_set_mode(crtc, mode, 0, 0, crtc->fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3579 | } else { |
| 3580 | if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) { |
| 3581 | crtc_funcs = crtc->helper_private; |
| 3582 | crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON); |
| 3583 | } |
| 3584 | |
| 3585 | /* Add this connector to the crtc */ |
| 3586 | encoder_funcs->mode_set(encoder, &crtc->mode, &crtc->mode); |
| 3587 | encoder_funcs->commit(encoder); |
| 3588 | } |
| 3589 | /* let the connector get through one full cycle before testing */ |
| 3590 | intel_wait_for_vblank(dev); |
| 3591 | |
| 3592 | return crtc; |
| 3593 | } |
| 3594 | |
| 3595 | void intel_release_load_detect_pipe(struct intel_output *intel_output, int dpms_mode) |
| 3596 | { |
| 3597 | struct drm_encoder *encoder = &intel_output->enc; |
| 3598 | struct drm_device *dev = encoder->dev; |
| 3599 | struct drm_crtc *crtc = encoder->crtc; |
| 3600 | struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; |
| 3601 | struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; |
| 3602 | |
| 3603 | if (intel_output->load_detect_temp) { |
| 3604 | encoder->crtc = NULL; |
Keith Packard | 03d6069 | 2009-06-05 18:19:56 -0700 | [diff] [blame] | 3605 | intel_output->base.encoder = NULL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3606 | intel_output->load_detect_temp = false; |
| 3607 | crtc->enabled = drm_helper_crtc_in_use(crtc); |
| 3608 | drm_helper_disable_unused_functions(dev); |
| 3609 | } |
| 3610 | |
| 3611 | /* Switch crtc and output back off if necessary */ |
| 3612 | if (crtc->enabled && dpms_mode != DRM_MODE_DPMS_ON) { |
| 3613 | if (encoder->crtc == crtc) |
| 3614 | encoder_funcs->dpms(encoder, dpms_mode); |
| 3615 | crtc_funcs->dpms(crtc, dpms_mode); |
| 3616 | } |
| 3617 | } |
| 3618 | |
| 3619 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
| 3620 | static int intel_crtc_clock_get(struct drm_device *dev, struct drm_crtc *crtc) |
| 3621 | { |
| 3622 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3623 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3624 | int pipe = intel_crtc->pipe; |
| 3625 | u32 dpll = I915_READ((pipe == 0) ? DPLL_A : DPLL_B); |
| 3626 | u32 fp; |
| 3627 | intel_clock_t clock; |
| 3628 | |
| 3629 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) |
| 3630 | fp = I915_READ((pipe == 0) ? FPA0 : FPB0); |
| 3631 | else |
| 3632 | fp = I915_READ((pipe == 0) ? FPA1 : FPB1); |
| 3633 | |
| 3634 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 3635 | if (IS_PINEVIEW(dev)) { |
| 3636 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
| 3637 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 3638 | } else { |
| 3639 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; |
| 3640 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; |
| 3641 | } |
| 3642 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3643 | if (IS_I9XX(dev)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 3644 | if (IS_PINEVIEW(dev)) |
| 3645 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
| 3646 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 3647 | else |
| 3648 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3649 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 3650 | |
| 3651 | switch (dpll & DPLL_MODE_MASK) { |
| 3652 | case DPLLB_MODE_DAC_SERIAL: |
| 3653 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? |
| 3654 | 5 : 10; |
| 3655 | break; |
| 3656 | case DPLLB_MODE_LVDS: |
| 3657 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? |
| 3658 | 7 : 14; |
| 3659 | break; |
| 3660 | default: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 3661 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3662 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
| 3663 | return 0; |
| 3664 | } |
| 3665 | |
| 3666 | /* XXX: Handle the 100Mhz refclk */ |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 3667 | intel_clock(dev, 96000, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3668 | } else { |
| 3669 | bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN); |
| 3670 | |
| 3671 | if (is_lvds) { |
| 3672 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> |
| 3673 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 3674 | clock.p2 = 14; |
| 3675 | |
| 3676 | if ((dpll & PLL_REF_INPUT_MASK) == |
| 3677 | PLLB_REF_INPUT_SPREADSPECTRUMIN) { |
| 3678 | /* XXX: might not be 66MHz */ |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 3679 | intel_clock(dev, 66000, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3680 | } else |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 3681 | intel_clock(dev, 48000, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3682 | } else { |
| 3683 | if (dpll & PLL_P1_DIVIDE_BY_TWO) |
| 3684 | clock.p1 = 2; |
| 3685 | else { |
| 3686 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> |
| 3687 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; |
| 3688 | } |
| 3689 | if (dpll & PLL_P2_DIVIDE_BY_4) |
| 3690 | clock.p2 = 4; |
| 3691 | else |
| 3692 | clock.p2 = 2; |
| 3693 | |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 3694 | intel_clock(dev, 48000, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3695 | } |
| 3696 | } |
| 3697 | |
| 3698 | /* XXX: It would be nice to validate the clocks, but we can't reuse |
| 3699 | * i830PllIsValid() because it relies on the xf86_config connector |
| 3700 | * configuration being accurate, which it isn't necessarily. |
| 3701 | */ |
| 3702 | |
| 3703 | return clock.dot; |
| 3704 | } |
| 3705 | |
| 3706 | /** Returns the currently programmed mode of the given pipe. */ |
| 3707 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, |
| 3708 | struct drm_crtc *crtc) |
| 3709 | { |
| 3710 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3711 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3712 | int pipe = intel_crtc->pipe; |
| 3713 | struct drm_display_mode *mode; |
| 3714 | int htot = I915_READ((pipe == 0) ? HTOTAL_A : HTOTAL_B); |
| 3715 | int hsync = I915_READ((pipe == 0) ? HSYNC_A : HSYNC_B); |
| 3716 | int vtot = I915_READ((pipe == 0) ? VTOTAL_A : VTOTAL_B); |
| 3717 | int vsync = I915_READ((pipe == 0) ? VSYNC_A : VSYNC_B); |
| 3718 | |
| 3719 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 3720 | if (!mode) |
| 3721 | return NULL; |
| 3722 | |
| 3723 | mode->clock = intel_crtc_clock_get(dev, crtc); |
| 3724 | mode->hdisplay = (htot & 0xffff) + 1; |
| 3725 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; |
| 3726 | mode->hsync_start = (hsync & 0xffff) + 1; |
| 3727 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; |
| 3728 | mode->vdisplay = (vtot & 0xffff) + 1; |
| 3729 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; |
| 3730 | mode->vsync_start = (vsync & 0xffff) + 1; |
| 3731 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; |
| 3732 | |
| 3733 | drm_mode_set_name(mode); |
| 3734 | drm_mode_set_crtcinfo(mode, 0); |
| 3735 | |
| 3736 | return mode; |
| 3737 | } |
| 3738 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3739 | #define GPU_IDLE_TIMEOUT 500 /* ms */ |
| 3740 | |
| 3741 | /* When this timer fires, we've been idle for awhile */ |
| 3742 | static void intel_gpu_idle_timer(unsigned long arg) |
| 3743 | { |
| 3744 | struct drm_device *dev = (struct drm_device *)arg; |
| 3745 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 3746 | |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 3747 | DRM_DEBUG_DRIVER("idle timer fired, downclocking\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3748 | |
| 3749 | dev_priv->busy = false; |
| 3750 | |
Eric Anholt | 01dfba9 | 2009-09-06 15:18:53 -0700 | [diff] [blame] | 3751 | queue_work(dev_priv->wq, &dev_priv->idle_work); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3752 | } |
| 3753 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3754 | #define CRTC_IDLE_TIMEOUT 1000 /* ms */ |
| 3755 | |
| 3756 | static void intel_crtc_idle_timer(unsigned long arg) |
| 3757 | { |
| 3758 | struct intel_crtc *intel_crtc = (struct intel_crtc *)arg; |
| 3759 | struct drm_crtc *crtc = &intel_crtc->base; |
| 3760 | drm_i915_private_t *dev_priv = crtc->dev->dev_private; |
| 3761 | |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 3762 | DRM_DEBUG_DRIVER("idle timer fired, downclocking\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3763 | |
| 3764 | intel_crtc->busy = false; |
| 3765 | |
Eric Anholt | 01dfba9 | 2009-09-06 15:18:53 -0700 | [diff] [blame] | 3766 | queue_work(dev_priv->wq, &dev_priv->idle_work); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | static void intel_increase_pllclock(struct drm_crtc *crtc, bool schedule) |
| 3770 | { |
| 3771 | struct drm_device *dev = crtc->dev; |
| 3772 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 3773 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3774 | int pipe = intel_crtc->pipe; |
| 3775 | int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B; |
| 3776 | int dpll = I915_READ(dpll_reg); |
| 3777 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 3778 | if (IS_IRONLAKE(dev)) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3779 | return; |
| 3780 | |
| 3781 | if (!dev_priv->lvds_downclock_avail) |
| 3782 | return; |
| 3783 | |
| 3784 | if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) { |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 3785 | DRM_DEBUG_DRIVER("upclocking LVDS\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3786 | |
| 3787 | /* Unlock panel regs */ |
| 3788 | I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) | (0xabcd << 16)); |
| 3789 | |
| 3790 | dpll &= ~DISPLAY_RATE_SELECT_FPA1; |
| 3791 | I915_WRITE(dpll_reg, dpll); |
| 3792 | dpll = I915_READ(dpll_reg); |
| 3793 | intel_wait_for_vblank(dev); |
| 3794 | dpll = I915_READ(dpll_reg); |
| 3795 | if (dpll & DISPLAY_RATE_SELECT_FPA1) |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 3796 | DRM_DEBUG_DRIVER("failed to upclock LVDS!\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3797 | |
| 3798 | /* ...and lock them again */ |
| 3799 | I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) & 0x3); |
| 3800 | } |
| 3801 | |
| 3802 | /* Schedule downclock */ |
| 3803 | if (schedule) |
| 3804 | mod_timer(&intel_crtc->idle_timer, jiffies + |
| 3805 | msecs_to_jiffies(CRTC_IDLE_TIMEOUT)); |
| 3806 | } |
| 3807 | |
| 3808 | static void intel_decrease_pllclock(struct drm_crtc *crtc) |
| 3809 | { |
| 3810 | struct drm_device *dev = crtc->dev; |
| 3811 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 3812 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3813 | int pipe = intel_crtc->pipe; |
| 3814 | int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B; |
| 3815 | int dpll = I915_READ(dpll_reg); |
| 3816 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 3817 | if (IS_IRONLAKE(dev)) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3818 | return; |
| 3819 | |
| 3820 | if (!dev_priv->lvds_downclock_avail) |
| 3821 | return; |
| 3822 | |
| 3823 | /* |
| 3824 | * Since this is called by a timer, we should never get here in |
| 3825 | * the manual case. |
| 3826 | */ |
| 3827 | if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) { |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 3828 | DRM_DEBUG_DRIVER("downclocking LVDS\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3829 | |
| 3830 | /* Unlock panel regs */ |
| 3831 | I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) | (0xabcd << 16)); |
| 3832 | |
| 3833 | dpll |= DISPLAY_RATE_SELECT_FPA1; |
| 3834 | I915_WRITE(dpll_reg, dpll); |
| 3835 | dpll = I915_READ(dpll_reg); |
| 3836 | intel_wait_for_vblank(dev); |
| 3837 | dpll = I915_READ(dpll_reg); |
| 3838 | if (!(dpll & DISPLAY_RATE_SELECT_FPA1)) |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 3839 | DRM_DEBUG_DRIVER("failed to downclock LVDS!\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3840 | |
| 3841 | /* ...and lock them again */ |
| 3842 | I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) & 0x3); |
| 3843 | } |
| 3844 | |
| 3845 | } |
| 3846 | |
| 3847 | /** |
| 3848 | * intel_idle_update - adjust clocks for idleness |
| 3849 | * @work: work struct |
| 3850 | * |
| 3851 | * Either the GPU or display (or both) went idle. Check the busy status |
| 3852 | * here and adjust the CRTC and GPU clocks as necessary. |
| 3853 | */ |
| 3854 | static void intel_idle_update(struct work_struct *work) |
| 3855 | { |
| 3856 | drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, |
| 3857 | idle_work); |
| 3858 | struct drm_device *dev = dev_priv->dev; |
| 3859 | struct drm_crtc *crtc; |
| 3860 | struct intel_crtc *intel_crtc; |
| 3861 | |
| 3862 | if (!i915_powersave) |
| 3863 | return; |
| 3864 | |
| 3865 | mutex_lock(&dev->struct_mutex); |
| 3866 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3867 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 3868 | /* Skip inactive CRTCs */ |
| 3869 | if (!crtc->fb) |
| 3870 | continue; |
| 3871 | |
| 3872 | intel_crtc = to_intel_crtc(crtc); |
| 3873 | if (!intel_crtc->busy) |
| 3874 | intel_decrease_pllclock(crtc); |
| 3875 | } |
| 3876 | |
| 3877 | mutex_unlock(&dev->struct_mutex); |
| 3878 | } |
| 3879 | |
| 3880 | /** |
| 3881 | * intel_mark_busy - mark the GPU and possibly the display busy |
| 3882 | * @dev: drm device |
| 3883 | * @obj: object we're operating on |
| 3884 | * |
| 3885 | * Callers can use this function to indicate that the GPU is busy processing |
| 3886 | * commands. If @obj matches one of the CRTC objects (i.e. it's a scanout |
| 3887 | * buffer), we'll also mark the display as busy, so we know to increase its |
| 3888 | * clock frequency. |
| 3889 | */ |
| 3890 | void intel_mark_busy(struct drm_device *dev, struct drm_gem_object *obj) |
| 3891 | { |
| 3892 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 3893 | struct drm_crtc *crtc = NULL; |
| 3894 | struct intel_framebuffer *intel_fb; |
| 3895 | struct intel_crtc *intel_crtc; |
| 3896 | |
Zhenyu Wang | 5e17ee7 | 2009-09-03 09:30:06 +0800 | [diff] [blame] | 3897 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 3898 | return; |
| 3899 | |
Jesse Barnes | cda9d05 | 2009-12-17 11:11:13 -0800 | [diff] [blame] | 3900 | if (!dev_priv->busy) |
Chris Wilson | 28cf798 | 2009-11-30 01:08:56 +0000 | [diff] [blame] | 3901 | dev_priv->busy = true; |
Jesse Barnes | cda9d05 | 2009-12-17 11:11:13 -0800 | [diff] [blame] | 3902 | else |
Chris Wilson | 28cf798 | 2009-11-30 01:08:56 +0000 | [diff] [blame] | 3903 | mod_timer(&dev_priv->idle_timer, jiffies + |
| 3904 | msecs_to_jiffies(GPU_IDLE_TIMEOUT)); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 3905 | |
| 3906 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 3907 | if (!crtc->fb) |
| 3908 | continue; |
| 3909 | |
| 3910 | intel_crtc = to_intel_crtc(crtc); |
| 3911 | intel_fb = to_intel_framebuffer(crtc->fb); |
| 3912 | if (intel_fb->obj == obj) { |
| 3913 | if (!intel_crtc->busy) { |
| 3914 | /* Non-busy -> busy, upclock */ |
| 3915 | intel_increase_pllclock(crtc, true); |
| 3916 | intel_crtc->busy = true; |
| 3917 | } else { |
| 3918 | /* Busy -> busy, put off timer */ |
| 3919 | mod_timer(&intel_crtc->idle_timer, jiffies + |
| 3920 | msecs_to_jiffies(CRTC_IDLE_TIMEOUT)); |
| 3921 | } |
| 3922 | } |
| 3923 | } |
| 3924 | } |
| 3925 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3926 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
| 3927 | { |
| 3928 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3929 | |
| 3930 | drm_crtc_cleanup(crtc); |
| 3931 | kfree(intel_crtc); |
| 3932 | } |
| 3933 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 3934 | struct intel_unpin_work { |
| 3935 | struct work_struct work; |
| 3936 | struct drm_device *dev; |
| 3937 | struct drm_gem_object *obj; |
| 3938 | struct drm_pending_vblank_event *event; |
| 3939 | int pending; |
| 3940 | }; |
| 3941 | |
| 3942 | static void intel_unpin_work_fn(struct work_struct *__work) |
| 3943 | { |
| 3944 | struct intel_unpin_work *work = |
| 3945 | container_of(__work, struct intel_unpin_work, work); |
| 3946 | |
| 3947 | mutex_lock(&work->dev->struct_mutex); |
| 3948 | i915_gem_object_unpin(work->obj); |
| 3949 | drm_gem_object_unreference(work->obj); |
| 3950 | mutex_unlock(&work->dev->struct_mutex); |
| 3951 | kfree(work); |
| 3952 | } |
| 3953 | |
| 3954 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
| 3955 | { |
| 3956 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 3957 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 3958 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3959 | struct intel_unpin_work *work; |
| 3960 | struct drm_i915_gem_object *obj_priv; |
| 3961 | struct drm_pending_vblank_event *e; |
| 3962 | struct timeval now; |
| 3963 | unsigned long flags; |
| 3964 | |
| 3965 | /* Ignore early vblank irqs */ |
| 3966 | if (intel_crtc == NULL) |
| 3967 | return; |
| 3968 | |
| 3969 | spin_lock_irqsave(&dev->event_lock, flags); |
| 3970 | work = intel_crtc->unpin_work; |
| 3971 | if (work == NULL || !work->pending) { |
| 3972 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 3973 | return; |
| 3974 | } |
| 3975 | |
| 3976 | intel_crtc->unpin_work = NULL; |
| 3977 | drm_vblank_put(dev, intel_crtc->pipe); |
| 3978 | |
| 3979 | if (work->event) { |
| 3980 | e = work->event; |
| 3981 | do_gettimeofday(&now); |
| 3982 | e->event.sequence = drm_vblank_count(dev, intel_crtc->pipe); |
| 3983 | e->event.tv_sec = now.tv_sec; |
| 3984 | e->event.tv_usec = now.tv_usec; |
| 3985 | list_add_tail(&e->base.link, |
| 3986 | &e->base.file_priv->event_list); |
| 3987 | wake_up_interruptible(&e->base.file_priv->event_wait); |
| 3988 | } |
| 3989 | |
| 3990 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 3991 | |
| 3992 | obj_priv = work->obj->driver_private; |
| 3993 | if (atomic_dec_and_test(&obj_priv->pending_flip)) |
| 3994 | DRM_WAKEUP(&dev_priv->pending_flip_queue); |
| 3995 | schedule_work(&work->work); |
| 3996 | } |
| 3997 | |
| 3998 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
| 3999 | { |
| 4000 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 4001 | struct intel_crtc *intel_crtc = |
| 4002 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); |
| 4003 | unsigned long flags; |
| 4004 | |
| 4005 | spin_lock_irqsave(&dev->event_lock, flags); |
| 4006 | if (intel_crtc->unpin_work) |
| 4007 | intel_crtc->unpin_work->pending = 1; |
| 4008 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 4009 | } |
| 4010 | |
| 4011 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
| 4012 | struct drm_framebuffer *fb, |
| 4013 | struct drm_pending_vblank_event *event) |
| 4014 | { |
| 4015 | struct drm_device *dev = crtc->dev; |
| 4016 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4017 | struct intel_framebuffer *intel_fb; |
| 4018 | struct drm_i915_gem_object *obj_priv; |
| 4019 | struct drm_gem_object *obj; |
| 4020 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4021 | struct intel_unpin_work *work; |
| 4022 | unsigned long flags; |
| 4023 | int ret; |
| 4024 | RING_LOCALS; |
| 4025 | |
| 4026 | work = kzalloc(sizeof *work, GFP_KERNEL); |
| 4027 | if (work == NULL) |
| 4028 | return -ENOMEM; |
| 4029 | |
| 4030 | mutex_lock(&dev->struct_mutex); |
| 4031 | |
| 4032 | work->event = event; |
| 4033 | work->dev = crtc->dev; |
| 4034 | intel_fb = to_intel_framebuffer(crtc->fb); |
| 4035 | work->obj = intel_fb->obj; |
| 4036 | INIT_WORK(&work->work, intel_unpin_work_fn); |
| 4037 | |
| 4038 | /* We borrow the event spin lock for protecting unpin_work */ |
| 4039 | spin_lock_irqsave(&dev->event_lock, flags); |
| 4040 | if (intel_crtc->unpin_work) { |
| 4041 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 4042 | kfree(work); |
| 4043 | mutex_unlock(&dev->struct_mutex); |
| 4044 | return -EBUSY; |
| 4045 | } |
| 4046 | intel_crtc->unpin_work = work; |
| 4047 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 4048 | |
| 4049 | intel_fb = to_intel_framebuffer(fb); |
| 4050 | obj = intel_fb->obj; |
| 4051 | |
| 4052 | ret = intel_pin_and_fence_fb_obj(dev, obj); |
| 4053 | if (ret != 0) { |
| 4054 | kfree(work); |
| 4055 | mutex_unlock(&dev->struct_mutex); |
| 4056 | return ret; |
| 4057 | } |
| 4058 | |
| 4059 | /* Reference the old fb object for the scheduled work. */ |
| 4060 | drm_gem_object_reference(work->obj); |
| 4061 | |
| 4062 | crtc->fb = fb; |
| 4063 | i915_gem_object_flush_write_domain(obj); |
| 4064 | drm_vblank_get(dev, intel_crtc->pipe); |
| 4065 | obj_priv = obj->driver_private; |
| 4066 | atomic_inc(&obj_priv->pending_flip); |
| 4067 | |
| 4068 | BEGIN_LP_RING(4); |
| 4069 | OUT_RING(MI_DISPLAY_FLIP | |
| 4070 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 4071 | OUT_RING(fb->pitch); |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 4072 | if (IS_I965G(dev)) { |
| 4073 | OUT_RING(obj_priv->gtt_offset | obj_priv->tiling_mode); |
| 4074 | OUT_RING((fb->width << 16) | fb->height); |
| 4075 | } else { |
| 4076 | OUT_RING(obj_priv->gtt_offset); |
| 4077 | OUT_RING(MI_NOOP); |
| 4078 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 4079 | ADVANCE_LP_RING(); |
| 4080 | |
| 4081 | mutex_unlock(&dev->struct_mutex); |
| 4082 | |
| 4083 | return 0; |
| 4084 | } |
| 4085 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4086 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
| 4087 | .dpms = intel_crtc_dpms, |
| 4088 | .mode_fixup = intel_crtc_mode_fixup, |
| 4089 | .mode_set = intel_crtc_mode_set, |
| 4090 | .mode_set_base = intel_pipe_set_base, |
| 4091 | .prepare = intel_crtc_prepare, |
| 4092 | .commit = intel_crtc_commit, |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 4093 | .load_lut = intel_crtc_load_lut, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4094 | }; |
| 4095 | |
| 4096 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
| 4097 | .cursor_set = intel_crtc_cursor_set, |
| 4098 | .cursor_move = intel_crtc_cursor_move, |
| 4099 | .gamma_set = intel_crtc_gamma_set, |
| 4100 | .set_config = drm_crtc_helper_set_config, |
| 4101 | .destroy = intel_crtc_destroy, |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 4102 | .page_flip = intel_crtc_page_flip, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4103 | }; |
| 4104 | |
| 4105 | |
Hannes Eder | b358d0a | 2008-12-18 21:18:47 +0100 | [diff] [blame] | 4106 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4107 | { |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 4108 | drm_i915_private_t *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4109 | struct intel_crtc *intel_crtc; |
| 4110 | int i; |
| 4111 | |
| 4112 | intel_crtc = kzalloc(sizeof(struct intel_crtc) + (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL); |
| 4113 | if (intel_crtc == NULL) |
| 4114 | return; |
| 4115 | |
| 4116 | drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs); |
| 4117 | |
| 4118 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); |
| 4119 | intel_crtc->pipe = pipe; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 4120 | intel_crtc->plane = pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4121 | for (i = 0; i < 256; i++) { |
| 4122 | intel_crtc->lut_r[i] = i; |
| 4123 | intel_crtc->lut_g[i] = i; |
| 4124 | intel_crtc->lut_b[i] = i; |
| 4125 | } |
| 4126 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 4127 | /* Swap pipes & planes for FBC on pre-965 */ |
| 4128 | intel_crtc->pipe = pipe; |
| 4129 | intel_crtc->plane = pipe; |
| 4130 | if (IS_MOBILE(dev) && (IS_I9XX(dev) && !IS_I965G(dev))) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 4131 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 4132 | intel_crtc->plane = ((pipe == 0) ? 1 : 0); |
| 4133 | } |
| 4134 | |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 4135 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
| 4136 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); |
| 4137 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; |
| 4138 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; |
| 4139 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4140 | intel_crtc->cursor_addr = 0; |
| 4141 | intel_crtc->dpms_mode = DRM_MODE_DPMS_OFF; |
| 4142 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
| 4143 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 4144 | intel_crtc->busy = false; |
| 4145 | |
| 4146 | setup_timer(&intel_crtc->idle_timer, intel_crtc_idle_timer, |
| 4147 | (unsigned long)intel_crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4148 | } |
| 4149 | |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 4150 | int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data, |
| 4151 | struct drm_file *file_priv) |
| 4152 | { |
| 4153 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 4154 | 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] | 4155 | struct drm_mode_object *drmmode_obj; |
| 4156 | struct intel_crtc *crtc; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 4157 | |
| 4158 | if (!dev_priv) { |
| 4159 | DRM_ERROR("called with no initialization\n"); |
| 4160 | return -EINVAL; |
| 4161 | } |
| 4162 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 4163 | drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id, |
| 4164 | DRM_MODE_OBJECT_CRTC); |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 4165 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 4166 | if (!drmmode_obj) { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 4167 | DRM_ERROR("no such CRTC id\n"); |
| 4168 | return -EINVAL; |
| 4169 | } |
| 4170 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 4171 | crtc = to_intel_crtc(obj_to_crtc(drmmode_obj)); |
| 4172 | pipe_from_crtc_id->pipe = crtc->pipe; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 4173 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 4174 | return 0; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 4175 | } |
| 4176 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4177 | struct drm_crtc *intel_get_crtc_from_pipe(struct drm_device *dev, int pipe) |
| 4178 | { |
| 4179 | struct drm_crtc *crtc = NULL; |
| 4180 | |
| 4181 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 4182 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4183 | if (intel_crtc->pipe == pipe) |
| 4184 | break; |
| 4185 | } |
| 4186 | return crtc; |
| 4187 | } |
| 4188 | |
Hannes Eder | b358d0a | 2008-12-18 21:18:47 +0100 | [diff] [blame] | 4189 | static int intel_connector_clones(struct drm_device *dev, int type_mask) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4190 | { |
| 4191 | int index_mask = 0; |
| 4192 | struct drm_connector *connector; |
| 4193 | int entry = 0; |
| 4194 | |
| 4195 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 4196 | struct intel_output *intel_output = to_intel_output(connector); |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 4197 | if (type_mask & intel_output->clone_mask) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4198 | index_mask |= (1 << entry); |
| 4199 | entry++; |
| 4200 | } |
| 4201 | return index_mask; |
| 4202 | } |
| 4203 | |
| 4204 | |
| 4205 | static void intel_setup_outputs(struct drm_device *dev) |
| 4206 | { |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 4207 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4208 | struct drm_connector *connector; |
| 4209 | |
| 4210 | intel_crt_init(dev); |
| 4211 | |
| 4212 | /* Set up integrated LVDS */ |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 4213 | if (IS_MOBILE(dev) && !IS_I830(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4214 | intel_lvds_init(dev); |
| 4215 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 4216 | if (IS_IRONLAKE(dev)) { |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 4217 | int found; |
| 4218 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 4219 | if (IS_MOBILE(dev) && (I915_READ(DP_A) & DP_DETECTED)) |
| 4220 | intel_dp_init(dev, DP_A); |
| 4221 | |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 4222 | if (I915_READ(HDMIB) & PORT_DETECTED) { |
| 4223 | /* check SDVOB */ |
| 4224 | /* found = intel_sdvo_init(dev, HDMIB); */ |
| 4225 | found = 0; |
| 4226 | if (!found) |
| 4227 | intel_hdmi_init(dev, HDMIB); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4228 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
| 4229 | intel_dp_init(dev, PCH_DP_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | if (I915_READ(HDMIC) & PORT_DETECTED) |
| 4233 | intel_hdmi_init(dev, HDMIC); |
| 4234 | |
| 4235 | if (I915_READ(HDMID) & PORT_DETECTED) |
| 4236 | intel_hdmi_init(dev, HDMID); |
| 4237 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 4238 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
| 4239 | intel_dp_init(dev, PCH_DP_C); |
| 4240 | |
| 4241 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
| 4242 | intel_dp_init(dev, PCH_DP_D); |
| 4243 | |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 4244 | } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 4245 | bool found = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 4246 | |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 4247 | if (I915_READ(SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 4248 | DRM_DEBUG_KMS("probing SDVOB\n"); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 4249 | found = intel_sdvo_init(dev, SDVOB); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 4250 | if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) { |
| 4251 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 4252 | intel_hdmi_init(dev, SDVOB); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 4253 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 4254 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 4255 | if (!found && SUPPORTS_INTEGRATED_DP(dev)) { |
| 4256 | DRM_DEBUG_KMS("probing DP_B\n"); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4257 | intel_dp_init(dev, DP_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 4258 | } |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 4259 | } |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 4260 | |
| 4261 | /* Before G4X SDVOC doesn't have its own detect register */ |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 4262 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 4263 | if (I915_READ(SDVOB) & SDVO_DETECTED) { |
| 4264 | DRM_DEBUG_KMS("probing SDVOC\n"); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 4265 | found = intel_sdvo_init(dev, SDVOC); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 4266 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 4267 | |
| 4268 | if (!found && (I915_READ(SDVOC) & SDVO_DETECTED)) { |
| 4269 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 4270 | if (SUPPORTS_INTEGRATED_HDMI(dev)) { |
| 4271 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 4272 | intel_hdmi_init(dev, SDVOC); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 4273 | } |
| 4274 | if (SUPPORTS_INTEGRATED_DP(dev)) { |
| 4275 | DRM_DEBUG_KMS("probing DP_C\n"); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4276 | intel_dp_init(dev, DP_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 4277 | } |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 4278 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 4279 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 4280 | if (SUPPORTS_INTEGRATED_DP(dev) && |
| 4281 | (I915_READ(DP_D) & DP_DETECTED)) { |
| 4282 | DRM_DEBUG_KMS("probing DP_D\n"); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4283 | intel_dp_init(dev, DP_D); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 4284 | } |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 4285 | } else if (IS_I8XX(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4286 | intel_dvo_init(dev); |
| 4287 | |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 4288 | if (SUPPORTS_TV(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4289 | intel_tv_init(dev); |
| 4290 | |
| 4291 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 4292 | struct intel_output *intel_output = to_intel_output(connector); |
| 4293 | struct drm_encoder *encoder = &intel_output->enc; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4294 | |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 4295 | encoder->possible_crtcs = intel_output->crtc_mask; |
| 4296 | encoder->possible_clones = intel_connector_clones(dev, |
| 4297 | intel_output->clone_mask); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4298 | } |
| 4299 | } |
| 4300 | |
| 4301 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 4302 | { |
| 4303 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 4304 | struct drm_device *dev = fb->dev; |
| 4305 | |
| 4306 | if (fb->fbdev) |
| 4307 | intelfb_remove(dev, fb); |
| 4308 | |
| 4309 | drm_framebuffer_cleanup(fb); |
| 4310 | mutex_lock(&dev->struct_mutex); |
| 4311 | drm_gem_object_unreference(intel_fb->obj); |
| 4312 | mutex_unlock(&dev->struct_mutex); |
| 4313 | |
| 4314 | kfree(intel_fb); |
| 4315 | } |
| 4316 | |
| 4317 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
| 4318 | struct drm_file *file_priv, |
| 4319 | unsigned int *handle) |
| 4320 | { |
| 4321 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 4322 | struct drm_gem_object *object = intel_fb->obj; |
| 4323 | |
| 4324 | return drm_gem_handle_create(file_priv, object, handle); |
| 4325 | } |
| 4326 | |
| 4327 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
| 4328 | .destroy = intel_user_framebuffer_destroy, |
| 4329 | .create_handle = intel_user_framebuffer_create_handle, |
| 4330 | }; |
| 4331 | |
| 4332 | int intel_framebuffer_create(struct drm_device *dev, |
| 4333 | struct drm_mode_fb_cmd *mode_cmd, |
| 4334 | struct drm_framebuffer **fb, |
| 4335 | struct drm_gem_object *obj) |
| 4336 | { |
| 4337 | struct intel_framebuffer *intel_fb; |
| 4338 | int ret; |
| 4339 | |
| 4340 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
| 4341 | if (!intel_fb) |
| 4342 | return -ENOMEM; |
| 4343 | |
| 4344 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
| 4345 | if (ret) { |
| 4346 | DRM_ERROR("framebuffer init failed %d\n", ret); |
| 4347 | return ret; |
| 4348 | } |
| 4349 | |
| 4350 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
| 4351 | |
| 4352 | intel_fb->obj = obj; |
| 4353 | |
| 4354 | *fb = &intel_fb->base; |
| 4355 | |
| 4356 | return 0; |
| 4357 | } |
| 4358 | |
| 4359 | |
| 4360 | static struct drm_framebuffer * |
| 4361 | intel_user_framebuffer_create(struct drm_device *dev, |
| 4362 | struct drm_file *filp, |
| 4363 | struct drm_mode_fb_cmd *mode_cmd) |
| 4364 | { |
| 4365 | struct drm_gem_object *obj; |
| 4366 | struct drm_framebuffer *fb; |
| 4367 | int ret; |
| 4368 | |
| 4369 | obj = drm_gem_object_lookup(dev, filp, mode_cmd->handle); |
| 4370 | if (!obj) |
| 4371 | return NULL; |
| 4372 | |
| 4373 | ret = intel_framebuffer_create(dev, mode_cmd, &fb, obj); |
| 4374 | if (ret) { |
Jesse Barnes | 496818f | 2009-02-11 13:28:14 -0800 | [diff] [blame] | 4375 | mutex_lock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4376 | drm_gem_object_unreference(obj); |
Jesse Barnes | 496818f | 2009-02-11 13:28:14 -0800 | [diff] [blame] | 4377 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4378 | return NULL; |
| 4379 | } |
| 4380 | |
| 4381 | return fb; |
| 4382 | } |
| 4383 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4384 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4385 | .fb_create = intel_user_framebuffer_create, |
| 4386 | .fb_changed = intelfb_probe, |
| 4387 | }; |
| 4388 | |
Chris Wilson | 9ea8d05 | 2010-01-04 18:57:56 +0000 | [diff] [blame] | 4389 | static struct drm_gem_object * |
| 4390 | intel_alloc_power_context(struct drm_device *dev) |
| 4391 | { |
| 4392 | struct drm_gem_object *pwrctx; |
| 4393 | int ret; |
| 4394 | |
| 4395 | pwrctx = drm_gem_object_alloc(dev, 4096); |
| 4396 | if (!pwrctx) { |
| 4397 | DRM_DEBUG("failed to alloc power context, RC6 disabled\n"); |
| 4398 | return NULL; |
| 4399 | } |
| 4400 | |
| 4401 | mutex_lock(&dev->struct_mutex); |
| 4402 | ret = i915_gem_object_pin(pwrctx, 4096); |
| 4403 | if (ret) { |
| 4404 | DRM_ERROR("failed to pin power context: %d\n", ret); |
| 4405 | goto err_unref; |
| 4406 | } |
| 4407 | |
| 4408 | ret = i915_gem_object_set_to_gtt_domain(pwrctx, 1); |
| 4409 | if (ret) { |
| 4410 | DRM_ERROR("failed to set-domain on power context: %d\n", ret); |
| 4411 | goto err_unpin; |
| 4412 | } |
| 4413 | mutex_unlock(&dev->struct_mutex); |
| 4414 | |
| 4415 | return pwrctx; |
| 4416 | |
| 4417 | err_unpin: |
| 4418 | i915_gem_object_unpin(pwrctx); |
| 4419 | err_unref: |
| 4420 | drm_gem_object_unreference(pwrctx); |
| 4421 | mutex_unlock(&dev->struct_mutex); |
| 4422 | return NULL; |
| 4423 | } |
| 4424 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 4425 | void intel_init_clock_gating(struct drm_device *dev) |
| 4426 | { |
| 4427 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4428 | |
| 4429 | /* |
| 4430 | * Disable clock gating reported to work incorrectly according to the |
| 4431 | * specs, but enable as much else as we can. |
| 4432 | */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 4433 | if (IS_IRONLAKE(dev)) { |
Zhenyu Wang | c03342f | 2009-09-29 11:01:23 +0800 | [diff] [blame] | 4434 | return; |
| 4435 | } else if (IS_G4X(dev)) { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 4436 | uint32_t dspclk_gate; |
| 4437 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 4438 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 4439 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 4440 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 4441 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 4442 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 4443 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 4444 | OVCUNIT_CLOCK_GATE_DISABLE; |
| 4445 | if (IS_GM45(dev)) |
| 4446 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 4447 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
| 4448 | } else if (IS_I965GM(dev)) { |
| 4449 | I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 4450 | I915_WRITE(RENCLK_GATE_D2, 0); |
| 4451 | I915_WRITE(DSPCLK_GATE_D, 0); |
| 4452 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 4453 | I915_WRITE16(DEUC, 0); |
| 4454 | } else if (IS_I965G(dev)) { |
| 4455 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 4456 | I965_RCC_CLOCK_GATE_DISABLE | |
| 4457 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 4458 | I965_ISC_CLOCK_GATE_DISABLE | |
| 4459 | I965_FBC_CLOCK_GATE_DISABLE); |
| 4460 | I915_WRITE(RENCLK_GATE_D2, 0); |
| 4461 | } else if (IS_I9XX(dev)) { |
| 4462 | u32 dstate = I915_READ(D_STATE); |
| 4463 | |
| 4464 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 4465 | DSTATE_DOT_CLOCK_GATING; |
| 4466 | I915_WRITE(D_STATE, dstate); |
Daniel Vetter | f0f8a9c | 2009-09-15 22:57:33 +0200 | [diff] [blame] | 4467 | } else if (IS_I85X(dev) || IS_I865G(dev)) { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 4468 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
| 4469 | } else if (IS_I830(dev)) { |
| 4470 | I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE); |
| 4471 | } |
Jesse Barnes | 97f5ab6 | 2009-10-08 10:16:48 -0700 | [diff] [blame] | 4472 | |
| 4473 | /* |
| 4474 | * GPU can automatically power down the render unit if given a page |
| 4475 | * to save state. |
| 4476 | */ |
Andrew Lutomirski | 1d3c36ad | 2009-12-21 10:10:22 -0500 | [diff] [blame] | 4477 | if (I915_HAS_RC6(dev) && drm_core_check_feature(dev, DRIVER_MODESET)) { |
Chris Wilson | 9ea8d05 | 2010-01-04 18:57:56 +0000 | [diff] [blame] | 4478 | struct drm_i915_gem_object *obj_priv = NULL; |
Jesse Barnes | 97f5ab6 | 2009-10-08 10:16:48 -0700 | [diff] [blame] | 4479 | |
Andrew Lutomirski | 7e8b60f | 2009-11-08 13:49:51 -0500 | [diff] [blame] | 4480 | if (dev_priv->pwrctx) { |
| 4481 | obj_priv = dev_priv->pwrctx->driver_private; |
| 4482 | } else { |
Chris Wilson | 9ea8d05 | 2010-01-04 18:57:56 +0000 | [diff] [blame] | 4483 | struct drm_gem_object *pwrctx; |
| 4484 | |
| 4485 | pwrctx = intel_alloc_power_context(dev); |
| 4486 | if (pwrctx) { |
| 4487 | dev_priv->pwrctx = pwrctx; |
| 4488 | obj_priv = pwrctx->driver_private; |
Andrew Lutomirski | 7e8b60f | 2009-11-08 13:49:51 -0500 | [diff] [blame] | 4489 | } |
Jesse Barnes | 97f5ab6 | 2009-10-08 10:16:48 -0700 | [diff] [blame] | 4490 | } |
| 4491 | |
Chris Wilson | 9ea8d05 | 2010-01-04 18:57:56 +0000 | [diff] [blame] | 4492 | if (obj_priv) { |
| 4493 | I915_WRITE(PWRCTXA, obj_priv->gtt_offset | PWRCTX_EN); |
| 4494 | I915_WRITE(MCHBAR_RENDER_STANDBY, |
| 4495 | I915_READ(MCHBAR_RENDER_STANDBY) & ~RCX_SW_EXIT); |
| 4496 | } |
Jesse Barnes | 97f5ab6 | 2009-10-08 10:16:48 -0700 | [diff] [blame] | 4497 | } |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 4498 | } |
| 4499 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 4500 | /* Set up chip specific display functions */ |
| 4501 | static void intel_init_display(struct drm_device *dev) |
| 4502 | { |
| 4503 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4504 | |
| 4505 | /* We always want a DPMS function */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 4506 | if (IS_IRONLAKE(dev)) |
| 4507 | dev_priv->display.dpms = ironlake_crtc_dpms; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 4508 | else |
| 4509 | dev_priv->display.dpms = i9xx_crtc_dpms; |
| 4510 | |
| 4511 | /* Only mobile has FBC, leave pointers NULL for other chips */ |
| 4512 | if (IS_MOBILE(dev)) { |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 4513 | if (IS_GM45(dev)) { |
| 4514 | dev_priv->display.fbc_enabled = g4x_fbc_enabled; |
| 4515 | dev_priv->display.enable_fbc = g4x_enable_fbc; |
| 4516 | dev_priv->display.disable_fbc = g4x_disable_fbc; |
| 4517 | } else if (IS_I965GM(dev) || IS_I945GM(dev) || IS_I915GM(dev)) { |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 4518 | dev_priv->display.fbc_enabled = i8xx_fbc_enabled; |
| 4519 | dev_priv->display.enable_fbc = i8xx_enable_fbc; |
| 4520 | dev_priv->display.disable_fbc = i8xx_disable_fbc; |
| 4521 | } |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 4522 | /* 855GM needs testing */ |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 4523 | } |
| 4524 | |
| 4525 | /* Returns the core display clock speed */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 4526 | if (IS_I945G(dev) || (IS_G33(dev) && ! IS_PINEVIEW_M(dev))) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 4527 | dev_priv->display.get_display_clock_speed = |
| 4528 | i945_get_display_clock_speed; |
| 4529 | else if (IS_I915G(dev)) |
| 4530 | dev_priv->display.get_display_clock_speed = |
| 4531 | i915_get_display_clock_speed; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 4532 | else if (IS_I945GM(dev) || IS_845G(dev) || IS_PINEVIEW_M(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 4533 | dev_priv->display.get_display_clock_speed = |
| 4534 | i9xx_misc_get_display_clock_speed; |
| 4535 | else if (IS_I915GM(dev)) |
| 4536 | dev_priv->display.get_display_clock_speed = |
| 4537 | i915gm_get_display_clock_speed; |
| 4538 | else if (IS_I865G(dev)) |
| 4539 | dev_priv->display.get_display_clock_speed = |
| 4540 | i865_get_display_clock_speed; |
Daniel Vetter | f0f8a9c | 2009-09-15 22:57:33 +0200 | [diff] [blame] | 4541 | else if (IS_I85X(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 4542 | dev_priv->display.get_display_clock_speed = |
| 4543 | i855_get_display_clock_speed; |
| 4544 | else /* 852, 830 */ |
| 4545 | dev_priv->display.get_display_clock_speed = |
| 4546 | i830_get_display_clock_speed; |
| 4547 | |
| 4548 | /* For FIFO watermark updates */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 4549 | if (IS_IRONLAKE(dev)) |
Zhenyu Wang | c03342f | 2009-09-29 11:01:23 +0800 | [diff] [blame] | 4550 | dev_priv->display.update_wm = NULL; |
| 4551 | else if (IS_G4X(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 4552 | dev_priv->display.update_wm = g4x_update_wm; |
| 4553 | else if (IS_I965G(dev)) |
| 4554 | dev_priv->display.update_wm = i965_update_wm; |
| 4555 | else if (IS_I9XX(dev) || IS_MOBILE(dev)) { |
| 4556 | dev_priv->display.update_wm = i9xx_update_wm; |
| 4557 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
| 4558 | } else { |
| 4559 | if (IS_I85X(dev)) |
| 4560 | dev_priv->display.get_fifo_size = i85x_get_fifo_size; |
| 4561 | else if (IS_845G(dev)) |
| 4562 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
| 4563 | else |
| 4564 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
| 4565 | dev_priv->display.update_wm = i830_update_wm; |
| 4566 | } |
| 4567 | } |
| 4568 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4569 | void intel_modeset_init(struct drm_device *dev) |
| 4570 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 4571 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4572 | int num_pipe; |
| 4573 | int i; |
| 4574 | |
| 4575 | drm_mode_config_init(dev); |
| 4576 | |
| 4577 | dev->mode_config.min_width = 0; |
| 4578 | dev->mode_config.min_height = 0; |
| 4579 | |
| 4580 | dev->mode_config.funcs = (void *)&intel_mode_funcs; |
| 4581 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 4582 | intel_init_display(dev); |
| 4583 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4584 | if (IS_I965G(dev)) { |
| 4585 | dev->mode_config.max_width = 8192; |
| 4586 | dev->mode_config.max_height = 8192; |
Keith Packard | 5e4d6fa | 2009-07-12 23:53:17 -0700 | [diff] [blame] | 4587 | } else if (IS_I9XX(dev)) { |
| 4588 | dev->mode_config.max_width = 4096; |
| 4589 | dev->mode_config.max_height = 4096; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4590 | } else { |
| 4591 | dev->mode_config.max_width = 2048; |
| 4592 | dev->mode_config.max_height = 2048; |
| 4593 | } |
| 4594 | |
| 4595 | /* set memory base */ |
| 4596 | if (IS_I9XX(dev)) |
| 4597 | dev->mode_config.fb_base = pci_resource_start(dev->pdev, 2); |
| 4598 | else |
| 4599 | dev->mode_config.fb_base = pci_resource_start(dev->pdev, 0); |
| 4600 | |
| 4601 | if (IS_MOBILE(dev) || IS_I9XX(dev)) |
| 4602 | num_pipe = 2; |
| 4603 | else |
| 4604 | num_pipe = 1; |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 4605 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4606 | num_pipe, num_pipe > 1 ? "s" : ""); |
| 4607 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 4608 | if (IS_I85X(dev)) |
| 4609 | pci_read_config_word(dev->pdev, HPLLCC, &dev_priv->orig_clock); |
| 4610 | else if (IS_I9XX(dev) || IS_G4X(dev)) |
| 4611 | pci_read_config_word(dev->pdev, GCFGC, &dev_priv->orig_clock); |
| 4612 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4613 | for (i = 0; i < num_pipe; i++) { |
| 4614 | intel_crtc_init(dev, i); |
| 4615 | } |
| 4616 | |
| 4617 | intel_setup_outputs(dev); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 4618 | |
| 4619 | intel_init_clock_gating(dev); |
| 4620 | |
| 4621 | INIT_WORK(&dev_priv->idle_work, intel_idle_update); |
| 4622 | setup_timer(&dev_priv->idle_timer, intel_gpu_idle_timer, |
| 4623 | (unsigned long)dev); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 4624 | |
| 4625 | intel_setup_overlay(dev); |
Jesse Barnes | 8536490 | 2009-12-03 09:52:43 -0800 | [diff] [blame] | 4626 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 4627 | if (IS_PINEVIEW(dev) && !intel_get_cxsr_latency(IS_PINEVIEW_G(dev), |
| 4628 | dev_priv->fsb_freq, |
| 4629 | dev_priv->mem_freq)) |
Jesse Barnes | 8536490 | 2009-12-03 09:52:43 -0800 | [diff] [blame] | 4630 | DRM_INFO("failed to find known CxSR latency " |
| 4631 | "(found fsb freq %d, mem freq %d), disabling CxSR\n", |
| 4632 | dev_priv->fsb_freq, dev_priv->mem_freq); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4633 | } |
| 4634 | |
| 4635 | void intel_modeset_cleanup(struct drm_device *dev) |
| 4636 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 4637 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4638 | struct drm_crtc *crtc; |
| 4639 | struct intel_crtc *intel_crtc; |
| 4640 | |
| 4641 | mutex_lock(&dev->struct_mutex); |
| 4642 | |
| 4643 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 4644 | /* Skip inactive CRTCs */ |
| 4645 | if (!crtc->fb) |
| 4646 | continue; |
| 4647 | |
| 4648 | intel_crtc = to_intel_crtc(crtc); |
| 4649 | intel_increase_pllclock(crtc, false); |
| 4650 | del_timer_sync(&intel_crtc->idle_timer); |
| 4651 | } |
| 4652 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 4653 | del_timer_sync(&dev_priv->idle_timer); |
| 4654 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 4655 | if (dev_priv->display.disable_fbc) |
| 4656 | dev_priv->display.disable_fbc(dev); |
| 4657 | |
Jesse Barnes | 97f5ab6 | 2009-10-08 10:16:48 -0700 | [diff] [blame] | 4658 | if (dev_priv->pwrctx) { |
Kristian Høgsberg | c1b5dea | 2009-11-11 12:19:18 -0500 | [diff] [blame] | 4659 | struct drm_i915_gem_object *obj_priv; |
| 4660 | |
| 4661 | obj_priv = dev_priv->pwrctx->driver_private; |
| 4662 | I915_WRITE(PWRCTXA, obj_priv->gtt_offset &~ PWRCTX_EN); |
| 4663 | I915_READ(PWRCTXA); |
Jesse Barnes | 97f5ab6 | 2009-10-08 10:16:48 -0700 | [diff] [blame] | 4664 | i915_gem_object_unpin(dev_priv->pwrctx); |
| 4665 | drm_gem_object_unreference(dev_priv->pwrctx); |
| 4666 | } |
| 4667 | |
Kristian Høgsberg | 69341a5 | 2009-11-11 12:19:17 -0500 | [diff] [blame] | 4668 | mutex_unlock(&dev->struct_mutex); |
| 4669 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4670 | drm_mode_config_cleanup(dev); |
| 4671 | } |
| 4672 | |
| 4673 | |
| 4674 | /* current intel driver doesn't take advantage of encoders |
| 4675 | always give back the encoder for the connector |
| 4676 | */ |
| 4677 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
| 4678 | { |
| 4679 | struct intel_output *intel_output = to_intel_output(connector); |
| 4680 | |
| 4681 | return &intel_output->enc; |
| 4682 | } |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 4683 | |
| 4684 | /* |
| 4685 | * set vga decode state - true == enable VGA decode |
| 4686 | */ |
| 4687 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) |
| 4688 | { |
| 4689 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4690 | u16 gmch_ctrl; |
| 4691 | |
| 4692 | pci_read_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, &gmch_ctrl); |
| 4693 | if (state) |
| 4694 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; |
| 4695 | else |
| 4696 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; |
| 4697 | pci_write_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, gmch_ctrl); |
| 4698 | return 0; |
| 4699 | } |