]>
Commit | Line | Data |
---|---|---|
79e53945 JB |
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 | ||
c1c7af60 JB |
27 | #include <linux/module.h> |
28 | #include <linux/input.h> | |
79e53945 | 29 | #include <linux/i2c.h> |
7662c8bd | 30 | #include <linux/kernel.h> |
79e53945 JB |
31 | #include "drmP.h" |
32 | #include "intel_drv.h" | |
33 | #include "i915_drm.h" | |
34 | #include "i915_drv.h" | |
a4fc5ed6 | 35 | #include "intel_dp.h" |
79e53945 JB |
36 | |
37 | #include "drm_crtc_helper.h" | |
38 | ||
32f9d658 ZW |
39 | #define HAS_eDP (intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) |
40 | ||
79e53945 | 41 | bool intel_pipe_has_type (struct drm_crtc *crtc, int type); |
7662c8bd | 42 | static void intel_update_watermarks(struct drm_device *dev); |
652c393a | 43 | static void intel_increase_pllclock(struct drm_crtc *crtc, bool schedule); |
79e53945 JB |
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 | |
d4906093 ML |
67 | typedef struct intel_limit intel_limit_t; |
68 | struct intel_limit { | |
79e53945 JB |
69 | intel_range_t dot, vco, n, m, m1, m2, p, p1; |
70 | intel_p2_t p2; | |
d4906093 ML |
71 | bool (* find_pll)(const intel_limit_t *, struct drm_crtc *, |
72 | int, int, intel_clock_t *); | |
652c393a JB |
73 | bool (* find_reduced_pll)(const intel_limit_t *, struct drm_crtc *, |
74 | int, int, intel_clock_t *); | |
d4906093 | 75 | }; |
79e53945 JB |
76 | |
77 | #define I8XX_DOT_MIN 25000 | |
78 | #define I8XX_DOT_MAX 350000 | |
79 | #define I8XX_VCO_MIN 930000 | |
80 | #define I8XX_VCO_MAX 1400000 | |
81 | #define I8XX_N_MIN 3 | |
82 | #define I8XX_N_MAX 16 | |
83 | #define I8XX_M_MIN 96 | |
84 | #define I8XX_M_MAX 140 | |
85 | #define I8XX_M1_MIN 18 | |
86 | #define I8XX_M1_MAX 26 | |
87 | #define I8XX_M2_MIN 6 | |
88 | #define I8XX_M2_MAX 16 | |
89 | #define I8XX_P_MIN 4 | |
90 | #define I8XX_P_MAX 128 | |
91 | #define I8XX_P1_MIN 2 | |
92 | #define I8XX_P1_MAX 33 | |
93 | #define I8XX_P1_LVDS_MIN 1 | |
94 | #define I8XX_P1_LVDS_MAX 6 | |
95 | #define I8XX_P2_SLOW 4 | |
96 | #define I8XX_P2_FAST 2 | |
97 | #define I8XX_P2_LVDS_SLOW 14 | |
0c2e3952 | 98 | #define I8XX_P2_LVDS_FAST 7 |
79e53945 JB |
99 | #define I8XX_P2_SLOW_LIMIT 165000 |
100 | ||
101 | #define I9XX_DOT_MIN 20000 | |
102 | #define I9XX_DOT_MAX 400000 | |
103 | #define I9XX_VCO_MIN 1400000 | |
104 | #define I9XX_VCO_MAX 2800000 | |
2177832f SL |
105 | #define IGD_VCO_MIN 1700000 |
106 | #define IGD_VCO_MAX 3500000 | |
f3cade5c KH |
107 | #define I9XX_N_MIN 1 |
108 | #define I9XX_N_MAX 6 | |
2177832f SL |
109 | /* IGD's Ncounter is a ring counter */ |
110 | #define IGD_N_MIN 3 | |
111 | #define IGD_N_MAX 6 | |
79e53945 JB |
112 | #define I9XX_M_MIN 70 |
113 | #define I9XX_M_MAX 120 | |
2177832f SL |
114 | #define IGD_M_MIN 2 |
115 | #define IGD_M_MAX 256 | |
79e53945 | 116 | #define I9XX_M1_MIN 10 |
f3cade5c | 117 | #define I9XX_M1_MAX 22 |
79e53945 JB |
118 | #define I9XX_M2_MIN 5 |
119 | #define I9XX_M2_MAX 9 | |
2177832f SL |
120 | /* IGD M1 is reserved, and must be 0 */ |
121 | #define IGD_M1_MIN 0 | |
122 | #define IGD_M1_MAX 0 | |
123 | #define IGD_M2_MIN 0 | |
124 | #define IGD_M2_MAX 254 | |
79e53945 JB |
125 | #define I9XX_P_SDVO_DAC_MIN 5 |
126 | #define I9XX_P_SDVO_DAC_MAX 80 | |
127 | #define I9XX_P_LVDS_MIN 7 | |
128 | #define I9XX_P_LVDS_MAX 98 | |
2177832f SL |
129 | #define IGD_P_LVDS_MIN 7 |
130 | #define IGD_P_LVDS_MAX 112 | |
79e53945 JB |
131 | #define I9XX_P1_MIN 1 |
132 | #define I9XX_P1_MAX 8 | |
133 | #define I9XX_P2_SDVO_DAC_SLOW 10 | |
134 | #define I9XX_P2_SDVO_DAC_FAST 5 | |
135 | #define I9XX_P2_SDVO_DAC_SLOW_LIMIT 200000 | |
136 | #define I9XX_P2_LVDS_SLOW 14 | |
137 | #define I9XX_P2_LVDS_FAST 7 | |
138 | #define I9XX_P2_LVDS_SLOW_LIMIT 112000 | |
139 | ||
044c7c41 ML |
140 | /*The parameter is for SDVO on G4x platform*/ |
141 | #define G4X_DOT_SDVO_MIN 25000 | |
142 | #define G4X_DOT_SDVO_MAX 270000 | |
143 | #define G4X_VCO_MIN 1750000 | |
144 | #define G4X_VCO_MAX 3500000 | |
145 | #define G4X_N_SDVO_MIN 1 | |
146 | #define G4X_N_SDVO_MAX 4 | |
147 | #define G4X_M_SDVO_MIN 104 | |
148 | #define G4X_M_SDVO_MAX 138 | |
149 | #define G4X_M1_SDVO_MIN 17 | |
150 | #define G4X_M1_SDVO_MAX 23 | |
151 | #define G4X_M2_SDVO_MIN 5 | |
152 | #define G4X_M2_SDVO_MAX 11 | |
153 | #define G4X_P_SDVO_MIN 10 | |
154 | #define G4X_P_SDVO_MAX 30 | |
155 | #define G4X_P1_SDVO_MIN 1 | |
156 | #define G4X_P1_SDVO_MAX 3 | |
157 | #define G4X_P2_SDVO_SLOW 10 | |
158 | #define G4X_P2_SDVO_FAST 10 | |
159 | #define G4X_P2_SDVO_LIMIT 270000 | |
160 | ||
161 | /*The parameter is for HDMI_DAC on G4x platform*/ | |
162 | #define G4X_DOT_HDMI_DAC_MIN 22000 | |
163 | #define G4X_DOT_HDMI_DAC_MAX 400000 | |
164 | #define G4X_N_HDMI_DAC_MIN 1 | |
165 | #define G4X_N_HDMI_DAC_MAX 4 | |
166 | #define G4X_M_HDMI_DAC_MIN 104 | |
167 | #define G4X_M_HDMI_DAC_MAX 138 | |
168 | #define G4X_M1_HDMI_DAC_MIN 16 | |
169 | #define G4X_M1_HDMI_DAC_MAX 23 | |
170 | #define G4X_M2_HDMI_DAC_MIN 5 | |
171 | #define G4X_M2_HDMI_DAC_MAX 11 | |
172 | #define G4X_P_HDMI_DAC_MIN 5 | |
173 | #define G4X_P_HDMI_DAC_MAX 80 | |
174 | #define G4X_P1_HDMI_DAC_MIN 1 | |
175 | #define G4X_P1_HDMI_DAC_MAX 8 | |
176 | #define G4X_P2_HDMI_DAC_SLOW 10 | |
177 | #define G4X_P2_HDMI_DAC_FAST 5 | |
178 | #define G4X_P2_HDMI_DAC_LIMIT 165000 | |
179 | ||
180 | /*The parameter is for SINGLE_CHANNEL_LVDS on G4x platform*/ | |
181 | #define G4X_DOT_SINGLE_CHANNEL_LVDS_MIN 20000 | |
182 | #define G4X_DOT_SINGLE_CHANNEL_LVDS_MAX 115000 | |
183 | #define G4X_N_SINGLE_CHANNEL_LVDS_MIN 1 | |
184 | #define G4X_N_SINGLE_CHANNEL_LVDS_MAX 3 | |
185 | #define G4X_M_SINGLE_CHANNEL_LVDS_MIN 104 | |
186 | #define G4X_M_SINGLE_CHANNEL_LVDS_MAX 138 | |
187 | #define G4X_M1_SINGLE_CHANNEL_LVDS_MIN 17 | |
188 | #define G4X_M1_SINGLE_CHANNEL_LVDS_MAX 23 | |
189 | #define G4X_M2_SINGLE_CHANNEL_LVDS_MIN 5 | |
190 | #define G4X_M2_SINGLE_CHANNEL_LVDS_MAX 11 | |
191 | #define G4X_P_SINGLE_CHANNEL_LVDS_MIN 28 | |
192 | #define G4X_P_SINGLE_CHANNEL_LVDS_MAX 112 | |
193 | #define G4X_P1_SINGLE_CHANNEL_LVDS_MIN 2 | |
194 | #define G4X_P1_SINGLE_CHANNEL_LVDS_MAX 8 | |
195 | #define G4X_P2_SINGLE_CHANNEL_LVDS_SLOW 14 | |
196 | #define G4X_P2_SINGLE_CHANNEL_LVDS_FAST 14 | |
197 | #define G4X_P2_SINGLE_CHANNEL_LVDS_LIMIT 0 | |
198 | ||
199 | /*The parameter is for DUAL_CHANNEL_LVDS on G4x platform*/ | |
200 | #define G4X_DOT_DUAL_CHANNEL_LVDS_MIN 80000 | |
201 | #define G4X_DOT_DUAL_CHANNEL_LVDS_MAX 224000 | |
202 | #define G4X_N_DUAL_CHANNEL_LVDS_MIN 1 | |
203 | #define G4X_N_DUAL_CHANNEL_LVDS_MAX 3 | |
204 | #define G4X_M_DUAL_CHANNEL_LVDS_MIN 104 | |
205 | #define G4X_M_DUAL_CHANNEL_LVDS_MAX 138 | |
206 | #define G4X_M1_DUAL_CHANNEL_LVDS_MIN 17 | |
207 | #define G4X_M1_DUAL_CHANNEL_LVDS_MAX 23 | |
208 | #define G4X_M2_DUAL_CHANNEL_LVDS_MIN 5 | |
209 | #define G4X_M2_DUAL_CHANNEL_LVDS_MAX 11 | |
210 | #define G4X_P_DUAL_CHANNEL_LVDS_MIN 14 | |
211 | #define G4X_P_DUAL_CHANNEL_LVDS_MAX 42 | |
212 | #define G4X_P1_DUAL_CHANNEL_LVDS_MIN 2 | |
213 | #define G4X_P1_DUAL_CHANNEL_LVDS_MAX 6 | |
214 | #define G4X_P2_DUAL_CHANNEL_LVDS_SLOW 7 | |
215 | #define G4X_P2_DUAL_CHANNEL_LVDS_FAST 7 | |
216 | #define G4X_P2_DUAL_CHANNEL_LVDS_LIMIT 0 | |
217 | ||
a4fc5ed6 KP |
218 | /*The parameter is for DISPLAY PORT on G4x platform*/ |
219 | #define G4X_DOT_DISPLAY_PORT_MIN 161670 | |
220 | #define G4X_DOT_DISPLAY_PORT_MAX 227000 | |
221 | #define G4X_N_DISPLAY_PORT_MIN 1 | |
222 | #define G4X_N_DISPLAY_PORT_MAX 2 | |
223 | #define G4X_M_DISPLAY_PORT_MIN 97 | |
224 | #define G4X_M_DISPLAY_PORT_MAX 108 | |
225 | #define G4X_M1_DISPLAY_PORT_MIN 0x10 | |
226 | #define G4X_M1_DISPLAY_PORT_MAX 0x12 | |
227 | #define G4X_M2_DISPLAY_PORT_MIN 0x05 | |
228 | #define G4X_M2_DISPLAY_PORT_MAX 0x06 | |
229 | #define G4X_P_DISPLAY_PORT_MIN 10 | |
230 | #define G4X_P_DISPLAY_PORT_MAX 20 | |
231 | #define G4X_P1_DISPLAY_PORT_MIN 1 | |
232 | #define G4X_P1_DISPLAY_PORT_MAX 2 | |
233 | #define G4X_P2_DISPLAY_PORT_SLOW 10 | |
234 | #define G4X_P2_DISPLAY_PORT_FAST 10 | |
235 | #define G4X_P2_DISPLAY_PORT_LIMIT 0 | |
236 | ||
2c07245f ZW |
237 | /* IGDNG */ |
238 | /* as we calculate clock using (register_value + 2) for | |
239 | N/M1/M2, so here the range value for them is (actual_value-2). | |
240 | */ | |
241 | #define IGDNG_DOT_MIN 25000 | |
242 | #define IGDNG_DOT_MAX 350000 | |
243 | #define IGDNG_VCO_MIN 1760000 | |
244 | #define IGDNG_VCO_MAX 3510000 | |
245 | #define IGDNG_N_MIN 1 | |
246 | #define IGDNG_N_MAX 5 | |
247 | #define IGDNG_M_MIN 79 | |
248 | #define IGDNG_M_MAX 118 | |
249 | #define IGDNG_M1_MIN 12 | |
250 | #define IGDNG_M1_MAX 23 | |
251 | #define IGDNG_M2_MIN 5 | |
252 | #define IGDNG_M2_MAX 9 | |
253 | #define IGDNG_P_SDVO_DAC_MIN 5 | |
254 | #define IGDNG_P_SDVO_DAC_MAX 80 | |
255 | #define IGDNG_P_LVDS_MIN 28 | |
256 | #define IGDNG_P_LVDS_MAX 112 | |
257 | #define IGDNG_P1_MIN 1 | |
258 | #define IGDNG_P1_MAX 8 | |
259 | #define IGDNG_P2_SDVO_DAC_SLOW 10 | |
260 | #define IGDNG_P2_SDVO_DAC_FAST 5 | |
261 | #define IGDNG_P2_LVDS_SLOW 14 /* single channel */ | |
262 | #define IGDNG_P2_LVDS_FAST 7 /* double channel */ | |
263 | #define IGDNG_P2_DOT_LIMIT 225000 /* 225Mhz */ | |
264 | ||
d4906093 ML |
265 | static bool |
266 | intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, | |
267 | int target, int refclk, intel_clock_t *best_clock); | |
268 | static bool | |
652c393a JB |
269 | intel_find_best_reduced_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, |
270 | int target, int refclk, intel_clock_t *best_clock); | |
271 | static bool | |
d4906093 ML |
272 | intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, |
273 | int target, int refclk, intel_clock_t *best_clock); | |
2c07245f ZW |
274 | static bool |
275 | intel_igdng_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, | |
276 | int target, int refclk, intel_clock_t *best_clock); | |
79e53945 | 277 | |
a4fc5ed6 KP |
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); | |
5eb08b69 ZW |
281 | static bool |
282 | intel_find_pll_igdng_dp(const intel_limit_t *, struct drm_crtc *crtc, | |
283 | int target, int refclk, intel_clock_t *best_clock); | |
a4fc5ed6 | 284 | |
e4b36699 | 285 | static const intel_limit_t intel_limits_i8xx_dvo = { |
79e53945 JB |
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 }, | |
d4906093 | 296 | .find_pll = intel_find_best_PLL, |
652c393a | 297 | .find_reduced_pll = intel_find_best_reduced_PLL, |
e4b36699 KP |
298 | }; |
299 | ||
300 | static const intel_limit_t intel_limits_i8xx_lvds = { | |
79e53945 JB |
301 | .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX }, |
302 | .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX }, | |
303 | .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX }, | |
304 | .m = { .min = I8XX_M_MIN, .max = I8XX_M_MAX }, | |
305 | .m1 = { .min = I8XX_M1_MIN, .max = I8XX_M1_MAX }, | |
306 | .m2 = { .min = I8XX_M2_MIN, .max = I8XX_M2_MAX }, | |
307 | .p = { .min = I8XX_P_MIN, .max = I8XX_P_MAX }, | |
308 | .p1 = { .min = I8XX_P1_LVDS_MIN, .max = I8XX_P1_LVDS_MAX }, | |
309 | .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT, | |
310 | .p2_slow = I8XX_P2_LVDS_SLOW, .p2_fast = I8XX_P2_LVDS_FAST }, | |
d4906093 | 311 | .find_pll = intel_find_best_PLL, |
652c393a | 312 | .find_reduced_pll = intel_find_best_reduced_PLL, |
e4b36699 KP |
313 | }; |
314 | ||
315 | static const intel_limit_t intel_limits_i9xx_sdvo = { | |
79e53945 JB |
316 | .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX }, |
317 | .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX }, | |
318 | .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX }, | |
319 | .m = { .min = I9XX_M_MIN, .max = I9XX_M_MAX }, | |
320 | .m1 = { .min = I9XX_M1_MIN, .max = I9XX_M1_MAX }, | |
321 | .m2 = { .min = I9XX_M2_MIN, .max = I9XX_M2_MAX }, | |
322 | .p = { .min = I9XX_P_SDVO_DAC_MIN, .max = I9XX_P_SDVO_DAC_MAX }, | |
323 | .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX }, | |
324 | .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT, | |
325 | .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST }, | |
d4906093 | 326 | .find_pll = intel_find_best_PLL, |
652c393a | 327 | .find_reduced_pll = intel_find_best_reduced_PLL, |
e4b36699 KP |
328 | }; |
329 | ||
330 | static const intel_limit_t intel_limits_i9xx_lvds = { | |
79e53945 JB |
331 | .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX }, |
332 | .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX }, | |
333 | .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX }, | |
334 | .m = { .min = I9XX_M_MIN, .max = I9XX_M_MAX }, | |
335 | .m1 = { .min = I9XX_M1_MIN, .max = I9XX_M1_MAX }, | |
336 | .m2 = { .min = I9XX_M2_MIN, .max = I9XX_M2_MAX }, | |
337 | .p = { .min = I9XX_P_LVDS_MIN, .max = I9XX_P_LVDS_MAX }, | |
338 | .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX }, | |
339 | /* The single-channel range is 25-112Mhz, and dual-channel | |
340 | * is 80-224Mhz. Prefer single channel as much as possible. | |
341 | */ | |
342 | .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT, | |
343 | .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_FAST }, | |
d4906093 | 344 | .find_pll = intel_find_best_PLL, |
652c393a | 345 | .find_reduced_pll = intel_find_best_reduced_PLL, |
e4b36699 KP |
346 | }; |
347 | ||
044c7c41 | 348 | /* below parameter and function is for G4X Chipset Family*/ |
e4b36699 | 349 | static const intel_limit_t intel_limits_g4x_sdvo = { |
044c7c41 ML |
350 | .dot = { .min = G4X_DOT_SDVO_MIN, .max = G4X_DOT_SDVO_MAX }, |
351 | .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX}, | |
352 | .n = { .min = G4X_N_SDVO_MIN, .max = G4X_N_SDVO_MAX }, | |
353 | .m = { .min = G4X_M_SDVO_MIN, .max = G4X_M_SDVO_MAX }, | |
354 | .m1 = { .min = G4X_M1_SDVO_MIN, .max = G4X_M1_SDVO_MAX }, | |
355 | .m2 = { .min = G4X_M2_SDVO_MIN, .max = G4X_M2_SDVO_MAX }, | |
356 | .p = { .min = G4X_P_SDVO_MIN, .max = G4X_P_SDVO_MAX }, | |
357 | .p1 = { .min = G4X_P1_SDVO_MIN, .max = G4X_P1_SDVO_MAX}, | |
358 | .p2 = { .dot_limit = G4X_P2_SDVO_LIMIT, | |
359 | .p2_slow = G4X_P2_SDVO_SLOW, | |
360 | .p2_fast = G4X_P2_SDVO_FAST | |
361 | }, | |
d4906093 | 362 | .find_pll = intel_g4x_find_best_PLL, |
652c393a | 363 | .find_reduced_pll = intel_g4x_find_best_PLL, |
e4b36699 KP |
364 | }; |
365 | ||
366 | static const intel_limit_t intel_limits_g4x_hdmi = { | |
044c7c41 ML |
367 | .dot = { .min = G4X_DOT_HDMI_DAC_MIN, .max = G4X_DOT_HDMI_DAC_MAX }, |
368 | .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX}, | |
369 | .n = { .min = G4X_N_HDMI_DAC_MIN, .max = G4X_N_HDMI_DAC_MAX }, | |
370 | .m = { .min = G4X_M_HDMI_DAC_MIN, .max = G4X_M_HDMI_DAC_MAX }, | |
371 | .m1 = { .min = G4X_M1_HDMI_DAC_MIN, .max = G4X_M1_HDMI_DAC_MAX }, | |
372 | .m2 = { .min = G4X_M2_HDMI_DAC_MIN, .max = G4X_M2_HDMI_DAC_MAX }, | |
373 | .p = { .min = G4X_P_HDMI_DAC_MIN, .max = G4X_P_HDMI_DAC_MAX }, | |
374 | .p1 = { .min = G4X_P1_HDMI_DAC_MIN, .max = G4X_P1_HDMI_DAC_MAX}, | |
375 | .p2 = { .dot_limit = G4X_P2_HDMI_DAC_LIMIT, | |
376 | .p2_slow = G4X_P2_HDMI_DAC_SLOW, | |
377 | .p2_fast = G4X_P2_HDMI_DAC_FAST | |
378 | }, | |
d4906093 | 379 | .find_pll = intel_g4x_find_best_PLL, |
652c393a | 380 | .find_reduced_pll = intel_g4x_find_best_PLL, |
e4b36699 KP |
381 | }; |
382 | ||
383 | static const intel_limit_t intel_limits_g4x_single_channel_lvds = { | |
044c7c41 ML |
384 | .dot = { .min = G4X_DOT_SINGLE_CHANNEL_LVDS_MIN, |
385 | .max = G4X_DOT_SINGLE_CHANNEL_LVDS_MAX }, | |
386 | .vco = { .min = G4X_VCO_MIN, | |
387 | .max = G4X_VCO_MAX }, | |
388 | .n = { .min = G4X_N_SINGLE_CHANNEL_LVDS_MIN, | |
389 | .max = G4X_N_SINGLE_CHANNEL_LVDS_MAX }, | |
390 | .m = { .min = G4X_M_SINGLE_CHANNEL_LVDS_MIN, | |
391 | .max = G4X_M_SINGLE_CHANNEL_LVDS_MAX }, | |
392 | .m1 = { .min = G4X_M1_SINGLE_CHANNEL_LVDS_MIN, | |
393 | .max = G4X_M1_SINGLE_CHANNEL_LVDS_MAX }, | |
394 | .m2 = { .min = G4X_M2_SINGLE_CHANNEL_LVDS_MIN, | |
395 | .max = G4X_M2_SINGLE_CHANNEL_LVDS_MAX }, | |
396 | .p = { .min = G4X_P_SINGLE_CHANNEL_LVDS_MIN, | |
397 | .max = G4X_P_SINGLE_CHANNEL_LVDS_MAX }, | |
398 | .p1 = { .min = G4X_P1_SINGLE_CHANNEL_LVDS_MIN, | |
399 | .max = G4X_P1_SINGLE_CHANNEL_LVDS_MAX }, | |
400 | .p2 = { .dot_limit = G4X_P2_SINGLE_CHANNEL_LVDS_LIMIT, | |
401 | .p2_slow = G4X_P2_SINGLE_CHANNEL_LVDS_SLOW, | |
402 | .p2_fast = G4X_P2_SINGLE_CHANNEL_LVDS_FAST | |
403 | }, | |
d4906093 | 404 | .find_pll = intel_g4x_find_best_PLL, |
652c393a | 405 | .find_reduced_pll = intel_g4x_find_best_PLL, |
e4b36699 KP |
406 | }; |
407 | ||
408 | static const intel_limit_t intel_limits_g4x_dual_channel_lvds = { | |
044c7c41 ML |
409 | .dot = { .min = G4X_DOT_DUAL_CHANNEL_LVDS_MIN, |
410 | .max = G4X_DOT_DUAL_CHANNEL_LVDS_MAX }, | |
411 | .vco = { .min = G4X_VCO_MIN, | |
412 | .max = G4X_VCO_MAX }, | |
413 | .n = { .min = G4X_N_DUAL_CHANNEL_LVDS_MIN, | |
414 | .max = G4X_N_DUAL_CHANNEL_LVDS_MAX }, | |
415 | .m = { .min = G4X_M_DUAL_CHANNEL_LVDS_MIN, | |
416 | .max = G4X_M_DUAL_CHANNEL_LVDS_MAX }, | |
417 | .m1 = { .min = G4X_M1_DUAL_CHANNEL_LVDS_MIN, | |
418 | .max = G4X_M1_DUAL_CHANNEL_LVDS_MAX }, | |
419 | .m2 = { .min = G4X_M2_DUAL_CHANNEL_LVDS_MIN, | |
420 | .max = G4X_M2_DUAL_CHANNEL_LVDS_MAX }, | |
421 | .p = { .min = G4X_P_DUAL_CHANNEL_LVDS_MIN, | |
422 | .max = G4X_P_DUAL_CHANNEL_LVDS_MAX }, | |
423 | .p1 = { .min = G4X_P1_DUAL_CHANNEL_LVDS_MIN, | |
424 | .max = G4X_P1_DUAL_CHANNEL_LVDS_MAX }, | |
425 | .p2 = { .dot_limit = G4X_P2_DUAL_CHANNEL_LVDS_LIMIT, | |
426 | .p2_slow = G4X_P2_DUAL_CHANNEL_LVDS_SLOW, | |
427 | .p2_fast = G4X_P2_DUAL_CHANNEL_LVDS_FAST | |
428 | }, | |
d4906093 | 429 | .find_pll = intel_g4x_find_best_PLL, |
652c393a | 430 | .find_reduced_pll = intel_g4x_find_best_PLL, |
e4b36699 KP |
431 | }; |
432 | ||
433 | static const intel_limit_t intel_limits_g4x_display_port = { | |
a4fc5ed6 KP |
434 | .dot = { .min = G4X_DOT_DISPLAY_PORT_MIN, |
435 | .max = G4X_DOT_DISPLAY_PORT_MAX }, | |
436 | .vco = { .min = G4X_VCO_MIN, | |
437 | .max = G4X_VCO_MAX}, | |
438 | .n = { .min = G4X_N_DISPLAY_PORT_MIN, | |
439 | .max = G4X_N_DISPLAY_PORT_MAX }, | |
440 | .m = { .min = G4X_M_DISPLAY_PORT_MIN, | |
441 | .max = G4X_M_DISPLAY_PORT_MAX }, | |
442 | .m1 = { .min = G4X_M1_DISPLAY_PORT_MIN, | |
443 | .max = G4X_M1_DISPLAY_PORT_MAX }, | |
444 | .m2 = { .min = G4X_M2_DISPLAY_PORT_MIN, | |
445 | .max = G4X_M2_DISPLAY_PORT_MAX }, | |
446 | .p = { .min = G4X_P_DISPLAY_PORT_MIN, | |
447 | .max = G4X_P_DISPLAY_PORT_MAX }, | |
448 | .p1 = { .min = G4X_P1_DISPLAY_PORT_MIN, | |
449 | .max = G4X_P1_DISPLAY_PORT_MAX}, | |
450 | .p2 = { .dot_limit = G4X_P2_DISPLAY_PORT_LIMIT, | |
451 | .p2_slow = G4X_P2_DISPLAY_PORT_SLOW, | |
452 | .p2_fast = G4X_P2_DISPLAY_PORT_FAST }, | |
453 | .find_pll = intel_find_pll_g4x_dp, | |
e4b36699 KP |
454 | }; |
455 | ||
456 | static const intel_limit_t intel_limits_igd_sdvo = { | |
2177832f SL |
457 | .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX}, |
458 | .vco = { .min = IGD_VCO_MIN, .max = IGD_VCO_MAX }, | |
459 | .n = { .min = IGD_N_MIN, .max = IGD_N_MAX }, | |
460 | .m = { .min = IGD_M_MIN, .max = IGD_M_MAX }, | |
461 | .m1 = { .min = IGD_M1_MIN, .max = IGD_M1_MAX }, | |
462 | .m2 = { .min = IGD_M2_MIN, .max = IGD_M2_MAX }, | |
463 | .p = { .min = I9XX_P_SDVO_DAC_MIN, .max = I9XX_P_SDVO_DAC_MAX }, | |
464 | .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX }, | |
465 | .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT, | |
466 | .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST }, | |
6115707b | 467 | .find_pll = intel_find_best_PLL, |
652c393a | 468 | .find_reduced_pll = intel_find_best_reduced_PLL, |
e4b36699 KP |
469 | }; |
470 | ||
471 | static const intel_limit_t intel_limits_igd_lvds = { | |
2177832f SL |
472 | .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX }, |
473 | .vco = { .min = IGD_VCO_MIN, .max = IGD_VCO_MAX }, | |
474 | .n = { .min = IGD_N_MIN, .max = IGD_N_MAX }, | |
475 | .m = { .min = IGD_M_MIN, .max = IGD_M_MAX }, | |
476 | .m1 = { .min = IGD_M1_MIN, .max = IGD_M1_MAX }, | |
477 | .m2 = { .min = IGD_M2_MIN, .max = IGD_M2_MAX }, | |
478 | .p = { .min = IGD_P_LVDS_MIN, .max = IGD_P_LVDS_MAX }, | |
479 | .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX }, | |
480 | /* IGD only supports single-channel mode. */ | |
481 | .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT, | |
482 | .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_SLOW }, | |
6115707b | 483 | .find_pll = intel_find_best_PLL, |
652c393a | 484 | .find_reduced_pll = intel_find_best_reduced_PLL, |
e4b36699 KP |
485 | }; |
486 | ||
487 | static const intel_limit_t intel_limits_igdng_sdvo = { | |
2c07245f ZW |
488 | .dot = { .min = IGDNG_DOT_MIN, .max = IGDNG_DOT_MAX }, |
489 | .vco = { .min = IGDNG_VCO_MIN, .max = IGDNG_VCO_MAX }, | |
490 | .n = { .min = IGDNG_N_MIN, .max = IGDNG_N_MAX }, | |
491 | .m = { .min = IGDNG_M_MIN, .max = IGDNG_M_MAX }, | |
492 | .m1 = { .min = IGDNG_M1_MIN, .max = IGDNG_M1_MAX }, | |
493 | .m2 = { .min = IGDNG_M2_MIN, .max = IGDNG_M2_MAX }, | |
494 | .p = { .min = IGDNG_P_SDVO_DAC_MIN, .max = IGDNG_P_SDVO_DAC_MAX }, | |
495 | .p1 = { .min = IGDNG_P1_MIN, .max = IGDNG_P1_MAX }, | |
496 | .p2 = { .dot_limit = IGDNG_P2_DOT_LIMIT, | |
497 | .p2_slow = IGDNG_P2_SDVO_DAC_SLOW, | |
498 | .p2_fast = IGDNG_P2_SDVO_DAC_FAST }, | |
499 | .find_pll = intel_igdng_find_best_PLL, | |
e4b36699 KP |
500 | }; |
501 | ||
502 | static const intel_limit_t intel_limits_igdng_lvds = { | |
2c07245f ZW |
503 | .dot = { .min = IGDNG_DOT_MIN, .max = IGDNG_DOT_MAX }, |
504 | .vco = { .min = IGDNG_VCO_MIN, .max = IGDNG_VCO_MAX }, | |
505 | .n = { .min = IGDNG_N_MIN, .max = IGDNG_N_MAX }, | |
506 | .m = { .min = IGDNG_M_MIN, .max = IGDNG_M_MAX }, | |
507 | .m1 = { .min = IGDNG_M1_MIN, .max = IGDNG_M1_MAX }, | |
508 | .m2 = { .min = IGDNG_M2_MIN, .max = IGDNG_M2_MAX }, | |
509 | .p = { .min = IGDNG_P_LVDS_MIN, .max = IGDNG_P_LVDS_MAX }, | |
510 | .p1 = { .min = IGDNG_P1_MIN, .max = IGDNG_P1_MAX }, | |
511 | .p2 = { .dot_limit = IGDNG_P2_DOT_LIMIT, | |
512 | .p2_slow = IGDNG_P2_LVDS_SLOW, | |
513 | .p2_fast = IGDNG_P2_LVDS_FAST }, | |
514 | .find_pll = intel_igdng_find_best_PLL, | |
79e53945 JB |
515 | }; |
516 | ||
2c07245f ZW |
517 | static const intel_limit_t *intel_igdng_limit(struct drm_crtc *crtc) |
518 | { | |
519 | const intel_limit_t *limit; | |
520 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) | |
e4b36699 | 521 | limit = &intel_limits_igdng_lvds; |
2c07245f | 522 | else |
e4b36699 | 523 | limit = &intel_limits_igdng_sdvo; |
2c07245f ZW |
524 | |
525 | return limit; | |
526 | } | |
527 | ||
044c7c41 ML |
528 | static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc) |
529 | { | |
530 | struct drm_device *dev = crtc->dev; | |
531 | struct drm_i915_private *dev_priv = dev->dev_private; | |
532 | const intel_limit_t *limit; | |
533 | ||
534 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { | |
535 | if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) == | |
536 | LVDS_CLKB_POWER_UP) | |
537 | /* LVDS with dual channel */ | |
e4b36699 | 538 | limit = &intel_limits_g4x_dual_channel_lvds; |
044c7c41 ML |
539 | else |
540 | /* LVDS with dual channel */ | |
e4b36699 | 541 | limit = &intel_limits_g4x_single_channel_lvds; |
044c7c41 ML |
542 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) || |
543 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) { | |
e4b36699 | 544 | limit = &intel_limits_g4x_hdmi; |
044c7c41 | 545 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) { |
e4b36699 | 546 | limit = &intel_limits_g4x_sdvo; |
a4fc5ed6 | 547 | } else if (intel_pipe_has_type (crtc, INTEL_OUTPUT_DISPLAYPORT)) { |
e4b36699 | 548 | limit = &intel_limits_g4x_display_port; |
044c7c41 | 549 | } else /* The option is for other outputs */ |
e4b36699 | 550 | limit = &intel_limits_i9xx_sdvo; |
044c7c41 ML |
551 | |
552 | return limit; | |
553 | } | |
554 | ||
79e53945 JB |
555 | static const intel_limit_t *intel_limit(struct drm_crtc *crtc) |
556 | { | |
557 | struct drm_device *dev = crtc->dev; | |
558 | const intel_limit_t *limit; | |
559 | ||
2c07245f ZW |
560 | if (IS_IGDNG(dev)) |
561 | limit = intel_igdng_limit(crtc); | |
562 | else if (IS_G4X(dev)) { | |
044c7c41 | 563 | limit = intel_g4x_limit(crtc); |
2177832f | 564 | } else if (IS_I9XX(dev) && !IS_IGD(dev)) { |
79e53945 | 565 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) |
e4b36699 | 566 | limit = &intel_limits_i9xx_lvds; |
79e53945 | 567 | else |
e4b36699 | 568 | limit = &intel_limits_i9xx_sdvo; |
2177832f SL |
569 | } else if (IS_IGD(dev)) { |
570 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) | |
e4b36699 | 571 | limit = &intel_limits_igd_lvds; |
2177832f | 572 | else |
e4b36699 | 573 | limit = &intel_limits_igd_sdvo; |
79e53945 JB |
574 | } else { |
575 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) | |
e4b36699 | 576 | limit = &intel_limits_i8xx_lvds; |
79e53945 | 577 | else |
e4b36699 | 578 | limit = &intel_limits_i8xx_dvo; |
79e53945 JB |
579 | } |
580 | return limit; | |
581 | } | |
582 | ||
2177832f SL |
583 | /* m1 is reserved as 0 in IGD, n is a ring counter */ |
584 | static void igd_clock(int refclk, intel_clock_t *clock) | |
79e53945 | 585 | { |
2177832f SL |
586 | clock->m = clock->m2 + 2; |
587 | clock->p = clock->p1 * clock->p2; | |
588 | clock->vco = refclk * clock->m / clock->n; | |
589 | clock->dot = clock->vco / clock->p; | |
590 | } | |
591 | ||
592 | static void intel_clock(struct drm_device *dev, int refclk, intel_clock_t *clock) | |
593 | { | |
594 | if (IS_IGD(dev)) { | |
595 | igd_clock(refclk, clock); | |
596 | return; | |
597 | } | |
79e53945 JB |
598 | clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2); |
599 | clock->p = clock->p1 * clock->p2; | |
600 | clock->vco = refclk * clock->m / (clock->n + 2); | |
601 | clock->dot = clock->vco / clock->p; | |
602 | } | |
603 | ||
79e53945 JB |
604 | /** |
605 | * Returns whether any output on the specified pipe is of the specified type | |
606 | */ | |
607 | bool intel_pipe_has_type (struct drm_crtc *crtc, int type) | |
608 | { | |
609 | struct drm_device *dev = crtc->dev; | |
610 | struct drm_mode_config *mode_config = &dev->mode_config; | |
611 | struct drm_connector *l_entry; | |
612 | ||
613 | list_for_each_entry(l_entry, &mode_config->connector_list, head) { | |
614 | if (l_entry->encoder && | |
615 | l_entry->encoder->crtc == crtc) { | |
616 | struct intel_output *intel_output = to_intel_output(l_entry); | |
617 | if (intel_output->type == type) | |
618 | return true; | |
619 | } | |
620 | } | |
621 | return false; | |
622 | } | |
623 | ||
32f9d658 ZW |
624 | struct drm_connector * |
625 | intel_pipe_get_output (struct drm_crtc *crtc) | |
626 | { | |
627 | struct drm_device *dev = crtc->dev; | |
628 | struct drm_mode_config *mode_config = &dev->mode_config; | |
629 | struct drm_connector *l_entry, *ret = NULL; | |
630 | ||
631 | list_for_each_entry(l_entry, &mode_config->connector_list, head) { | |
632 | if (l_entry->encoder && | |
633 | l_entry->encoder->crtc == crtc) { | |
634 | ret = l_entry; | |
635 | break; | |
636 | } | |
637 | } | |
638 | return ret; | |
639 | } | |
640 | ||
7c04d1d9 | 641 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
79e53945 JB |
642 | /** |
643 | * Returns whether the given set of divisors are valid for a given refclk with | |
644 | * the given connectors. | |
645 | */ | |
646 | ||
647 | static bool intel_PLL_is_valid(struct drm_crtc *crtc, intel_clock_t *clock) | |
648 | { | |
649 | const intel_limit_t *limit = intel_limit (crtc); | |
2177832f | 650 | struct drm_device *dev = crtc->dev; |
79e53945 JB |
651 | |
652 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) | |
653 | INTELPllInvalid ("p1 out of range\n"); | |
654 | if (clock->p < limit->p.min || limit->p.max < clock->p) | |
655 | INTELPllInvalid ("p out of range\n"); | |
656 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) | |
657 | INTELPllInvalid ("m2 out of range\n"); | |
658 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) | |
659 | INTELPllInvalid ("m1 out of range\n"); | |
2177832f | 660 | if (clock->m1 <= clock->m2 && !IS_IGD(dev)) |
79e53945 JB |
661 | INTELPllInvalid ("m1 <= m2\n"); |
662 | if (clock->m < limit->m.min || limit->m.max < clock->m) | |
663 | INTELPllInvalid ("m out of range\n"); | |
664 | if (clock->n < limit->n.min || limit->n.max < clock->n) | |
665 | INTELPllInvalid ("n out of range\n"); | |
666 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) | |
667 | INTELPllInvalid ("vco out of range\n"); | |
668 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, | |
669 | * connector, etc., rather than just a single range. | |
670 | */ | |
671 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) | |
672 | INTELPllInvalid ("dot out of range\n"); | |
673 | ||
674 | return true; | |
675 | } | |
676 | ||
d4906093 ML |
677 | static bool |
678 | intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, | |
679 | int target, int refclk, intel_clock_t *best_clock) | |
680 | ||
79e53945 JB |
681 | { |
682 | struct drm_device *dev = crtc->dev; | |
683 | struct drm_i915_private *dev_priv = dev->dev_private; | |
684 | intel_clock_t clock; | |
79e53945 JB |
685 | int err = target; |
686 | ||
bc5e5718 | 687 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) && |
832cc28d | 688 | (I915_READ(LVDS)) != 0) { |
79e53945 JB |
689 | /* |
690 | * For LVDS, if the panel is on, just rely on its current | |
691 | * settings for dual-channel. We haven't figured out how to | |
692 | * reliably set up different single/dual channel state, if we | |
693 | * even can. | |
694 | */ | |
695 | if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) == | |
696 | LVDS_CLKB_POWER_UP) | |
697 | clock.p2 = limit->p2.p2_fast; | |
698 | else | |
699 | clock.p2 = limit->p2.p2_slow; | |
700 | } else { | |
701 | if (target < limit->p2.dot_limit) | |
702 | clock.p2 = limit->p2.p2_slow; | |
703 | else | |
704 | clock.p2 = limit->p2.p2_fast; | |
705 | } | |
706 | ||
707 | memset (best_clock, 0, sizeof (*best_clock)); | |
708 | ||
652c393a JB |
709 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
710 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; | |
711 | clock.m1++) { | |
712 | for (clock.m2 = limit->m2.min; | |
713 | clock.m2 <= limit->m2.max; clock.m2++) { | |
714 | /* m1 is always 0 in IGD */ | |
715 | if (clock.m2 >= clock.m1 && !IS_IGD(dev)) | |
716 | break; | |
717 | for (clock.n = limit->n.min; | |
718 | clock.n <= limit->n.max; clock.n++) { | |
79e53945 JB |
719 | int this_err; |
720 | ||
2177832f | 721 | intel_clock(dev, refclk, &clock); |
79e53945 JB |
722 | |
723 | if (!intel_PLL_is_valid(crtc, &clock)) | |
724 | continue; | |
725 | ||
726 | this_err = abs(clock.dot - target); | |
727 | if (this_err < err) { | |
728 | *best_clock = clock; | |
729 | err = this_err; | |
730 | } | |
731 | } | |
732 | } | |
733 | } | |
734 | } | |
735 | ||
736 | return (err != target); | |
737 | } | |
738 | ||
652c393a JB |
739 | |
740 | static bool | |
741 | intel_find_best_reduced_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, | |
742 | int target, int refclk, intel_clock_t *best_clock) | |
743 | ||
744 | { | |
745 | struct drm_device *dev = crtc->dev; | |
746 | intel_clock_t clock; | |
747 | int err = target; | |
748 | bool found = false; | |
749 | ||
750 | memcpy(&clock, best_clock, sizeof(intel_clock_t)); | |
751 | ||
752 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) { | |
753 | for (clock.m2 = limit->m2.min; clock.m2 <= limit->m2.max; clock.m2++) { | |
754 | /* m1 is always 0 in IGD */ | |
755 | if (clock.m2 >= clock.m1 && !IS_IGD(dev)) | |
756 | break; | |
757 | for (clock.n = limit->n.min; clock.n <= limit->n.max; | |
758 | clock.n++) { | |
759 | int this_err; | |
760 | ||
761 | intel_clock(dev, refclk, &clock); | |
762 | ||
763 | if (!intel_PLL_is_valid(crtc, &clock)) | |
764 | continue; | |
765 | ||
766 | this_err = abs(clock.dot - target); | |
767 | if (this_err < err) { | |
768 | *best_clock = clock; | |
769 | err = this_err; | |
770 | found = true; | |
771 | } | |
772 | } | |
773 | } | |
774 | } | |
775 | ||
776 | return found; | |
777 | } | |
778 | ||
d4906093 ML |
779 | static bool |
780 | intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, | |
781 | int target, int refclk, intel_clock_t *best_clock) | |
782 | { | |
783 | struct drm_device *dev = crtc->dev; | |
784 | struct drm_i915_private *dev_priv = dev->dev_private; | |
785 | intel_clock_t clock; | |
786 | int max_n; | |
787 | bool found; | |
788 | /* approximately equals target * 0.00488 */ | |
789 | int err_most = (target >> 8) + (target >> 10); | |
790 | found = false; | |
791 | ||
792 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { | |
793 | if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) == | |
794 | LVDS_CLKB_POWER_UP) | |
795 | clock.p2 = limit->p2.p2_fast; | |
796 | else | |
797 | clock.p2 = limit->p2.p2_slow; | |
798 | } else { | |
799 | if (target < limit->p2.dot_limit) | |
800 | clock.p2 = limit->p2.p2_slow; | |
801 | else | |
802 | clock.p2 = limit->p2.p2_fast; | |
803 | } | |
804 | ||
805 | memset(best_clock, 0, sizeof(*best_clock)); | |
806 | max_n = limit->n.max; | |
807 | /* based on hardware requriment prefer smaller n to precision */ | |
808 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { | |
652c393a | 809 | /* based on hardware requirment prefere larger m1,m2 */ |
d4906093 ML |
810 | for (clock.m1 = limit->m1.max; |
811 | clock.m1 >= limit->m1.min; clock.m1--) { | |
812 | for (clock.m2 = limit->m2.max; | |
813 | clock.m2 >= limit->m2.min; clock.m2--) { | |
814 | for (clock.p1 = limit->p1.max; | |
815 | clock.p1 >= limit->p1.min; clock.p1--) { | |
816 | int this_err; | |
817 | ||
2177832f | 818 | intel_clock(dev, refclk, &clock); |
d4906093 ML |
819 | if (!intel_PLL_is_valid(crtc, &clock)) |
820 | continue; | |
821 | this_err = abs(clock.dot - target) ; | |
822 | if (this_err < err_most) { | |
823 | *best_clock = clock; | |
824 | err_most = this_err; | |
825 | max_n = clock.n; | |
826 | found = true; | |
827 | } | |
828 | } | |
829 | } | |
830 | } | |
831 | } | |
2c07245f ZW |
832 | return found; |
833 | } | |
834 | ||
5eb08b69 ZW |
835 | static bool |
836 | intel_find_pll_igdng_dp(const intel_limit_t *limit, struct drm_crtc *crtc, | |
837 | int target, int refclk, intel_clock_t *best_clock) | |
838 | { | |
839 | struct drm_device *dev = crtc->dev; | |
840 | intel_clock_t clock; | |
841 | if (target < 200000) { | |
842 | clock.n = 1; | |
843 | clock.p1 = 2; | |
844 | clock.p2 = 10; | |
845 | clock.m1 = 12; | |
846 | clock.m2 = 9; | |
847 | } else { | |
848 | clock.n = 2; | |
849 | clock.p1 = 1; | |
850 | clock.p2 = 10; | |
851 | clock.m1 = 14; | |
852 | clock.m2 = 8; | |
853 | } | |
854 | intel_clock(dev, refclk, &clock); | |
855 | memcpy(best_clock, &clock, sizeof(intel_clock_t)); | |
856 | return true; | |
857 | } | |
858 | ||
2c07245f ZW |
859 | static bool |
860 | intel_igdng_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, | |
861 | int target, int refclk, intel_clock_t *best_clock) | |
862 | { | |
863 | struct drm_device *dev = crtc->dev; | |
864 | struct drm_i915_private *dev_priv = dev->dev_private; | |
865 | intel_clock_t clock; | |
866 | int max_n; | |
867 | bool found; | |
868 | int err_most = 47; | |
869 | found = false; | |
870 | ||
32f9d658 ZW |
871 | /* eDP has only 2 clock choice, no n/m/p setting */ |
872 | if (HAS_eDP) | |
873 | return true; | |
874 | ||
5eb08b69 ZW |
875 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) |
876 | return intel_find_pll_igdng_dp(limit, crtc, target, | |
877 | refclk, best_clock); | |
878 | ||
2c07245f ZW |
879 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
880 | if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) == | |
881 | LVDS_CLKB_POWER_UP) | |
882 | clock.p2 = limit->p2.p2_fast; | |
883 | else | |
884 | clock.p2 = limit->p2.p2_slow; | |
885 | } else { | |
886 | if (target < limit->p2.dot_limit) | |
887 | clock.p2 = limit->p2.p2_slow; | |
888 | else | |
889 | clock.p2 = limit->p2.p2_fast; | |
890 | } | |
891 | ||
892 | memset(best_clock, 0, sizeof(*best_clock)); | |
893 | max_n = limit->n.max; | |
652c393a JB |
894 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
895 | /* based on hardware requriment prefer smaller n to precision */ | |
896 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { | |
897 | /* based on hardware requirment prefere larger m1,m2 */ | |
898 | for (clock.m1 = limit->m1.max; | |
899 | clock.m1 >= limit->m1.min; clock.m1--) { | |
900 | for (clock.m2 = limit->m2.max; | |
901 | clock.m2 >= limit->m2.min; clock.m2--) { | |
2c07245f | 902 | int this_err; |
d4906093 | 903 | |
2c07245f ZW |
904 | intel_clock(dev, refclk, &clock); |
905 | if (!intel_PLL_is_valid(crtc, &clock)) | |
906 | continue; | |
907 | this_err = abs((10000 - (target*10000/clock.dot))); | |
908 | if (this_err < err_most) { | |
909 | *best_clock = clock; | |
910 | err_most = this_err; | |
911 | max_n = clock.n; | |
912 | found = true; | |
913 | /* found on first matching */ | |
914 | goto out; | |
915 | } | |
916 | } | |
917 | } | |
918 | } | |
919 | } | |
920 | out: | |
d4906093 ML |
921 | return found; |
922 | } | |
923 | ||
a4fc5ed6 KP |
924 | /* DisplayPort has only two frequencies, 162MHz and 270MHz */ |
925 | static bool | |
926 | intel_find_pll_g4x_dp(const intel_limit_t *limit, struct drm_crtc *crtc, | |
927 | int target, int refclk, intel_clock_t *best_clock) | |
928 | { | |
929 | intel_clock_t clock; | |
930 | if (target < 200000) { | |
a4fc5ed6 KP |
931 | clock.p1 = 2; |
932 | clock.p2 = 10; | |
b3d25495 KP |
933 | clock.n = 2; |
934 | clock.m1 = 23; | |
935 | clock.m2 = 8; | |
a4fc5ed6 | 936 | } else { |
a4fc5ed6 KP |
937 | clock.p1 = 1; |
938 | clock.p2 = 10; | |
b3d25495 KP |
939 | clock.n = 1; |
940 | clock.m1 = 14; | |
941 | clock.m2 = 2; | |
a4fc5ed6 | 942 | } |
b3d25495 KP |
943 | clock.m = 5 * (clock.m1 + 2) + (clock.m2 + 2); |
944 | clock.p = (clock.p1 * clock.p2); | |
945 | clock.dot = 96000 * clock.m / (clock.n + 2) / clock.p; | |
a4fc5ed6 KP |
946 | memcpy(best_clock, &clock, sizeof(intel_clock_t)); |
947 | return true; | |
948 | } | |
949 | ||
79e53945 JB |
950 | void |
951 | intel_wait_for_vblank(struct drm_device *dev) | |
952 | { | |
953 | /* Wait for 20ms, i.e. one cycle at 50hz. */ | |
580982d3 | 954 | mdelay(20); |
79e53945 JB |
955 | } |
956 | ||
5c3b82e2 | 957 | static int |
3c4fdcfb KH |
958 | intel_pipe_set_base(struct drm_crtc *crtc, int x, int y, |
959 | struct drm_framebuffer *old_fb) | |
79e53945 JB |
960 | { |
961 | struct drm_device *dev = crtc->dev; | |
962 | struct drm_i915_private *dev_priv = dev->dev_private; | |
963 | struct drm_i915_master_private *master_priv; | |
964 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
965 | struct intel_framebuffer *intel_fb; | |
966 | struct drm_i915_gem_object *obj_priv; | |
967 | struct drm_gem_object *obj; | |
968 | int pipe = intel_crtc->pipe; | |
969 | unsigned long Start, Offset; | |
970 | int dspbase = (pipe == 0 ? DSPAADDR : DSPBADDR); | |
971 | int dspsurf = (pipe == 0 ? DSPASURF : DSPBSURF); | |
972 | int dspstride = (pipe == 0) ? DSPASTRIDE : DSPBSTRIDE; | |
f544847f | 973 | int dsptileoff = (pipe == 0 ? DSPATILEOFF : DSPBTILEOFF); |
79e53945 | 974 | int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR; |
3c4fdcfb | 975 | u32 dspcntr, alignment; |
5c3b82e2 | 976 | int ret; |
79e53945 JB |
977 | |
978 | /* no fb bound */ | |
979 | if (!crtc->fb) { | |
980 | DRM_DEBUG("No FB bound\n"); | |
5c3b82e2 CW |
981 | return 0; |
982 | } | |
983 | ||
984 | switch (pipe) { | |
985 | case 0: | |
986 | case 1: | |
987 | break; | |
988 | default: | |
989 | DRM_ERROR("Can't update pipe %d in SAREA\n", pipe); | |
990 | return -EINVAL; | |
79e53945 JB |
991 | } |
992 | ||
993 | intel_fb = to_intel_framebuffer(crtc->fb); | |
79e53945 JB |
994 | obj = intel_fb->obj; |
995 | obj_priv = obj->driver_private; | |
996 | ||
3c4fdcfb KH |
997 | switch (obj_priv->tiling_mode) { |
998 | case I915_TILING_NONE: | |
999 | alignment = 64 * 1024; | |
1000 | break; | |
1001 | case I915_TILING_X: | |
2ebed176 CW |
1002 | /* pin() will align the object as required by fence */ |
1003 | alignment = 0; | |
3c4fdcfb KH |
1004 | break; |
1005 | case I915_TILING_Y: | |
1006 | /* FIXME: Is this true? */ | |
1007 | DRM_ERROR("Y tiled not allowed for scan out buffers\n"); | |
5c3b82e2 | 1008 | return -EINVAL; |
3c4fdcfb KH |
1009 | default: |
1010 | BUG(); | |
1011 | } | |
1012 | ||
5c3b82e2 | 1013 | mutex_lock(&dev->struct_mutex); |
8c4b8c3f | 1014 | ret = i915_gem_object_pin(obj, alignment); |
5c3b82e2 CW |
1015 | if (ret != 0) { |
1016 | mutex_unlock(&dev->struct_mutex); | |
1017 | return ret; | |
1018 | } | |
79e53945 | 1019 | |
8c4b8c3f | 1020 | ret = i915_gem_object_set_to_gtt_domain(obj, 1); |
5c3b82e2 | 1021 | if (ret != 0) { |
8c4b8c3f | 1022 | i915_gem_object_unpin(obj); |
5c3b82e2 CW |
1023 | mutex_unlock(&dev->struct_mutex); |
1024 | return ret; | |
1025 | } | |
79e53945 | 1026 | |
8c4b8c3f CW |
1027 | /* Pre-i965 needs to install a fence for tiled scan-out */ |
1028 | if (!IS_I965G(dev) && | |
1029 | obj_priv->fence_reg == I915_FENCE_REG_NONE && | |
1030 | obj_priv->tiling_mode != I915_TILING_NONE) { | |
1031 | ret = i915_gem_object_get_fence_reg(obj); | |
1032 | if (ret != 0) { | |
1033 | i915_gem_object_unpin(obj); | |
1034 | mutex_unlock(&dev->struct_mutex); | |
1035 | return ret; | |
1036 | } | |
1037 | } | |
1038 | ||
79e53945 | 1039 | dspcntr = I915_READ(dspcntr_reg); |
712531bf JB |
1040 | /* Mask out pixel format bits in case we change it */ |
1041 | dspcntr &= ~DISPPLANE_PIXFORMAT_MASK; | |
79e53945 JB |
1042 | switch (crtc->fb->bits_per_pixel) { |
1043 | case 8: | |
1044 | dspcntr |= DISPPLANE_8BPP; | |
1045 | break; | |
1046 | case 16: | |
1047 | if (crtc->fb->depth == 15) | |
1048 | dspcntr |= DISPPLANE_15_16BPP; | |
1049 | else | |
1050 | dspcntr |= DISPPLANE_16BPP; | |
1051 | break; | |
1052 | case 24: | |
1053 | case 32: | |
1054 | dspcntr |= DISPPLANE_32BPP_NO_ALPHA; | |
1055 | break; | |
1056 | default: | |
1057 | DRM_ERROR("Unknown color depth\n"); | |
8c4b8c3f | 1058 | i915_gem_object_unpin(obj); |
5c3b82e2 CW |
1059 | mutex_unlock(&dev->struct_mutex); |
1060 | return -EINVAL; | |
79e53945 | 1061 | } |
f544847f JB |
1062 | if (IS_I965G(dev)) { |
1063 | if (obj_priv->tiling_mode != I915_TILING_NONE) | |
1064 | dspcntr |= DISPPLANE_TILED; | |
1065 | else | |
1066 | dspcntr &= ~DISPPLANE_TILED; | |
1067 | } | |
1068 | ||
553bd149 ZW |
1069 | if (IS_IGDNG(dev)) |
1070 | /* must disable */ | |
1071 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; | |
1072 | ||
79e53945 JB |
1073 | I915_WRITE(dspcntr_reg, dspcntr); |
1074 | ||
5c3b82e2 CW |
1075 | Start = obj_priv->gtt_offset; |
1076 | Offset = y * crtc->fb->pitch + x * (crtc->fb->bits_per_pixel / 8); | |
1077 | ||
79e53945 | 1078 | DRM_DEBUG("Writing base %08lX %08lX %d %d\n", Start, Offset, x, y); |
5c3b82e2 | 1079 | I915_WRITE(dspstride, crtc->fb->pitch); |
79e53945 JB |
1080 | if (IS_I965G(dev)) { |
1081 | I915_WRITE(dspbase, Offset); | |
1082 | I915_READ(dspbase); | |
1083 | I915_WRITE(dspsurf, Start); | |
1084 | I915_READ(dspsurf); | |
f544847f | 1085 | I915_WRITE(dsptileoff, (y << 16) | x); |
79e53945 JB |
1086 | } else { |
1087 | I915_WRITE(dspbase, Start + Offset); | |
1088 | I915_READ(dspbase); | |
1089 | } | |
1090 | ||
3c4fdcfb KH |
1091 | intel_wait_for_vblank(dev); |
1092 | ||
1093 | if (old_fb) { | |
1094 | intel_fb = to_intel_framebuffer(old_fb); | |
652c393a | 1095 | obj_priv = intel_fb->obj->driver_private; |
3c4fdcfb KH |
1096 | i915_gem_object_unpin(intel_fb->obj); |
1097 | } | |
652c393a JB |
1098 | intel_increase_pllclock(crtc, true); |
1099 | ||
5c3b82e2 | 1100 | mutex_unlock(&dev->struct_mutex); |
79e53945 JB |
1101 | |
1102 | if (!dev->primary->master) | |
5c3b82e2 | 1103 | return 0; |
79e53945 JB |
1104 | |
1105 | master_priv = dev->primary->master->driver_priv; | |
1106 | if (!master_priv->sarea_priv) | |
5c3b82e2 | 1107 | return 0; |
79e53945 | 1108 | |
5c3b82e2 | 1109 | if (pipe) { |
79e53945 JB |
1110 | master_priv->sarea_priv->pipeB_x = x; |
1111 | master_priv->sarea_priv->pipeB_y = y; | |
5c3b82e2 CW |
1112 | } else { |
1113 | master_priv->sarea_priv->pipeA_x = x; | |
1114 | master_priv->sarea_priv->pipeA_y = y; | |
79e53945 | 1115 | } |
5c3b82e2 CW |
1116 | |
1117 | return 0; | |
79e53945 JB |
1118 | } |
1119 | ||
24f119c7 ZW |
1120 | /* Disable the VGA plane that we never use */ |
1121 | static void i915_disable_vga (struct drm_device *dev) | |
1122 | { | |
1123 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1124 | u8 sr1; | |
1125 | u32 vga_reg; | |
1126 | ||
1127 | if (IS_IGDNG(dev)) | |
1128 | vga_reg = CPU_VGACNTRL; | |
1129 | else | |
1130 | vga_reg = VGACNTRL; | |
1131 | ||
1132 | if (I915_READ(vga_reg) & VGA_DISP_DISABLE) | |
1133 | return; | |
1134 | ||
1135 | I915_WRITE8(VGA_SR_INDEX, 1); | |
1136 | sr1 = I915_READ8(VGA_SR_DATA); | |
1137 | I915_WRITE8(VGA_SR_DATA, sr1 | (1 << 5)); | |
1138 | udelay(100); | |
1139 | ||
1140 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); | |
1141 | } | |
1142 | ||
32f9d658 ZW |
1143 | static void igdng_disable_pll_edp (struct drm_crtc *crtc) |
1144 | { | |
1145 | struct drm_device *dev = crtc->dev; | |
1146 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1147 | u32 dpa_ctl; | |
1148 | ||
1149 | DRM_DEBUG("\n"); | |
1150 | dpa_ctl = I915_READ(DP_A); | |
1151 | dpa_ctl &= ~DP_PLL_ENABLE; | |
1152 | I915_WRITE(DP_A, dpa_ctl); | |
1153 | } | |
1154 | ||
1155 | static void igdng_enable_pll_edp (struct drm_crtc *crtc) | |
1156 | { | |
1157 | struct drm_device *dev = crtc->dev; | |
1158 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1159 | u32 dpa_ctl; | |
1160 | ||
1161 | dpa_ctl = I915_READ(DP_A); | |
1162 | dpa_ctl |= DP_PLL_ENABLE; | |
1163 | I915_WRITE(DP_A, dpa_ctl); | |
1164 | udelay(200); | |
1165 | } | |
1166 | ||
1167 | ||
1168 | static void igdng_set_pll_edp (struct drm_crtc *crtc, int clock) | |
1169 | { | |
1170 | struct drm_device *dev = crtc->dev; | |
1171 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1172 | u32 dpa_ctl; | |
1173 | ||
1174 | DRM_DEBUG("eDP PLL enable for clock %d\n", clock); | |
1175 | dpa_ctl = I915_READ(DP_A); | |
1176 | dpa_ctl &= ~DP_PLL_FREQ_MASK; | |
1177 | ||
1178 | if (clock < 200000) { | |
1179 | u32 temp; | |
1180 | dpa_ctl |= DP_PLL_FREQ_160MHZ; | |
1181 | /* workaround for 160Mhz: | |
1182 | 1) program 0x4600c bits 15:0 = 0x8124 | |
1183 | 2) program 0x46010 bit 0 = 1 | |
1184 | 3) program 0x46034 bit 24 = 1 | |
1185 | 4) program 0x64000 bit 14 = 1 | |
1186 | */ | |
1187 | temp = I915_READ(0x4600c); | |
1188 | temp &= 0xffff0000; | |
1189 | I915_WRITE(0x4600c, temp | 0x8124); | |
1190 | ||
1191 | temp = I915_READ(0x46010); | |
1192 | I915_WRITE(0x46010, temp | 1); | |
1193 | ||
1194 | temp = I915_READ(0x46034); | |
1195 | I915_WRITE(0x46034, temp | (1 << 24)); | |
1196 | } else { | |
1197 | dpa_ctl |= DP_PLL_FREQ_270MHZ; | |
1198 | } | |
1199 | I915_WRITE(DP_A, dpa_ctl); | |
1200 | ||
1201 | udelay(500); | |
1202 | } | |
1203 | ||
2c07245f ZW |
1204 | static void igdng_crtc_dpms(struct drm_crtc *crtc, int mode) |
1205 | { | |
1206 | struct drm_device *dev = crtc->dev; | |
1207 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1208 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
1209 | int pipe = intel_crtc->pipe; | |
7662c8bd | 1210 | int plane = intel_crtc->plane; |
2c07245f ZW |
1211 | int pch_dpll_reg = (pipe == 0) ? PCH_DPLL_A : PCH_DPLL_B; |
1212 | int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF; | |
1213 | int dspcntr_reg = (plane == 0) ? DSPACNTR : DSPBCNTR; | |
1214 | int dspbase_reg = (plane == 0) ? DSPAADDR : DSPBADDR; | |
1215 | int fdi_tx_reg = (pipe == 0) ? FDI_TXA_CTL : FDI_TXB_CTL; | |
1216 | int fdi_rx_reg = (pipe == 0) ? FDI_RXA_CTL : FDI_RXB_CTL; | |
1217 | int fdi_rx_iir_reg = (pipe == 0) ? FDI_RXA_IIR : FDI_RXB_IIR; | |
1218 | int fdi_rx_imr_reg = (pipe == 0) ? FDI_RXA_IMR : FDI_RXB_IMR; | |
1219 | int transconf_reg = (pipe == 0) ? TRANSACONF : TRANSBCONF; | |
1220 | int pf_ctl_reg = (pipe == 0) ? PFA_CTL_1 : PFB_CTL_1; | |
249c0e64 | 1221 | int pf_win_size = (pipe == 0) ? PFA_WIN_SZ : PFB_WIN_SZ; |
2c07245f ZW |
1222 | int cpu_htot_reg = (pipe == 0) ? HTOTAL_A : HTOTAL_B; |
1223 | int cpu_hblank_reg = (pipe == 0) ? HBLANK_A : HBLANK_B; | |
1224 | int cpu_hsync_reg = (pipe == 0) ? HSYNC_A : HSYNC_B; | |
1225 | int cpu_vtot_reg = (pipe == 0) ? VTOTAL_A : VTOTAL_B; | |
1226 | int cpu_vblank_reg = (pipe == 0) ? VBLANK_A : VBLANK_B; | |
1227 | int cpu_vsync_reg = (pipe == 0) ? VSYNC_A : VSYNC_B; | |
1228 | int trans_htot_reg = (pipe == 0) ? TRANS_HTOTAL_A : TRANS_HTOTAL_B; | |
1229 | int trans_hblank_reg = (pipe == 0) ? TRANS_HBLANK_A : TRANS_HBLANK_B; | |
1230 | int trans_hsync_reg = (pipe == 0) ? TRANS_HSYNC_A : TRANS_HSYNC_B; | |
1231 | int trans_vtot_reg = (pipe == 0) ? TRANS_VTOTAL_A : TRANS_VTOTAL_B; | |
1232 | int trans_vblank_reg = (pipe == 0) ? TRANS_VBLANK_A : TRANS_VBLANK_B; | |
1233 | int trans_vsync_reg = (pipe == 0) ? TRANS_VSYNC_A : TRANS_VSYNC_B; | |
1234 | u32 temp; | |
249c0e64 | 1235 | int tries = 5, j, n; |
79e53945 | 1236 | |
2c07245f ZW |
1237 | /* XXX: When our outputs are all unaware of DPMS modes other than off |
1238 | * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC. | |
1239 | */ | |
1240 | switch (mode) { | |
1241 | case DRM_MODE_DPMS_ON: | |
1242 | case DRM_MODE_DPMS_STANDBY: | |
1243 | case DRM_MODE_DPMS_SUSPEND: | |
1244 | DRM_DEBUG("crtc %d dpms on\n", pipe); | |
32f9d658 ZW |
1245 | if (HAS_eDP) { |
1246 | /* enable eDP PLL */ | |
1247 | igdng_enable_pll_edp(crtc); | |
1248 | } else { | |
1249 | /* enable PCH DPLL */ | |
1250 | temp = I915_READ(pch_dpll_reg); | |
1251 | if ((temp & DPLL_VCO_ENABLE) == 0) { | |
1252 | I915_WRITE(pch_dpll_reg, temp | DPLL_VCO_ENABLE); | |
1253 | I915_READ(pch_dpll_reg); | |
1254 | } | |
2c07245f | 1255 | |
32f9d658 ZW |
1256 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
1257 | temp = I915_READ(fdi_rx_reg); | |
1258 | I915_WRITE(fdi_rx_reg, temp | FDI_RX_PLL_ENABLE | | |
1259 | FDI_SEL_PCDCLK | | |
1260 | FDI_DP_PORT_WIDTH_X4); /* default 4 lanes */ | |
1261 | I915_READ(fdi_rx_reg); | |
1262 | udelay(200); | |
1263 | ||
1264 | /* Enable CPU FDI TX PLL, always on for IGDNG */ | |
1265 | temp = I915_READ(fdi_tx_reg); | |
1266 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { | |
1267 | I915_WRITE(fdi_tx_reg, temp | FDI_TX_PLL_ENABLE); | |
1268 | I915_READ(fdi_tx_reg); | |
1269 | udelay(100); | |
1270 | } | |
2c07245f ZW |
1271 | } |
1272 | ||
1273 | /* Enable CPU pipe */ | |
1274 | temp = I915_READ(pipeconf_reg); | |
1275 | if ((temp & PIPEACONF_ENABLE) == 0) { | |
1276 | I915_WRITE(pipeconf_reg, temp | PIPEACONF_ENABLE); | |
1277 | I915_READ(pipeconf_reg); | |
1278 | udelay(100); | |
1279 | } | |
1280 | ||
1281 | /* configure and enable CPU plane */ | |
1282 | temp = I915_READ(dspcntr_reg); | |
1283 | if ((temp & DISPLAY_PLANE_ENABLE) == 0) { | |
1284 | I915_WRITE(dspcntr_reg, temp | DISPLAY_PLANE_ENABLE); | |
1285 | /* Flush the plane changes */ | |
1286 | I915_WRITE(dspbase_reg, I915_READ(dspbase_reg)); | |
1287 | } | |
1288 | ||
32f9d658 ZW |
1289 | if (!HAS_eDP) { |
1290 | /* enable CPU FDI TX and PCH FDI RX */ | |
1291 | temp = I915_READ(fdi_tx_reg); | |
1292 | temp |= FDI_TX_ENABLE; | |
1293 | temp |= FDI_DP_PORT_WIDTH_X4; /* default */ | |
1294 | temp &= ~FDI_LINK_TRAIN_NONE; | |
1295 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
1296 | I915_WRITE(fdi_tx_reg, temp); | |
1297 | I915_READ(fdi_tx_reg); | |
2c07245f | 1298 | |
32f9d658 ZW |
1299 | temp = I915_READ(fdi_rx_reg); |
1300 | temp &= ~FDI_LINK_TRAIN_NONE; | |
1301 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
1302 | I915_WRITE(fdi_rx_reg, temp | FDI_RX_ENABLE); | |
1303 | I915_READ(fdi_rx_reg); | |
2c07245f | 1304 | |
32f9d658 | 1305 | udelay(150); |
2c07245f | 1306 | |
32f9d658 ZW |
1307 | /* Train FDI. */ |
1308 | /* umask FDI RX Interrupt symbol_lock and bit_lock bit | |
1309 | for train result */ | |
1310 | temp = I915_READ(fdi_rx_imr_reg); | |
1311 | temp &= ~FDI_RX_SYMBOL_LOCK; | |
1312 | temp &= ~FDI_RX_BIT_LOCK; | |
1313 | I915_WRITE(fdi_rx_imr_reg, temp); | |
1314 | I915_READ(fdi_rx_imr_reg); | |
1315 | udelay(150); | |
2c07245f | 1316 | |
32f9d658 ZW |
1317 | temp = I915_READ(fdi_rx_iir_reg); |
1318 | DRM_DEBUG("FDI_RX_IIR 0x%x\n", temp); | |
2c07245f | 1319 | |
32f9d658 ZW |
1320 | if ((temp & FDI_RX_BIT_LOCK) == 0) { |
1321 | for (j = 0; j < tries; j++) { | |
1322 | temp = I915_READ(fdi_rx_iir_reg); | |
1323 | DRM_DEBUG("FDI_RX_IIR 0x%x\n", temp); | |
1324 | if (temp & FDI_RX_BIT_LOCK) | |
1325 | break; | |
1326 | udelay(200); | |
1327 | } | |
1328 | if (j != tries) | |
1329 | I915_WRITE(fdi_rx_iir_reg, | |
1330 | temp | FDI_RX_BIT_LOCK); | |
1331 | else | |
1332 | DRM_DEBUG("train 1 fail\n"); | |
1333 | } else { | |
2c07245f ZW |
1334 | I915_WRITE(fdi_rx_iir_reg, |
1335 | temp | FDI_RX_BIT_LOCK); | |
32f9d658 ZW |
1336 | DRM_DEBUG("train 1 ok 2!\n"); |
1337 | } | |
1338 | temp = I915_READ(fdi_tx_reg); | |
1339 | temp &= ~FDI_LINK_TRAIN_NONE; | |
1340 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
1341 | I915_WRITE(fdi_tx_reg, temp); | |
1342 | ||
1343 | temp = I915_READ(fdi_rx_reg); | |
1344 | temp &= ~FDI_LINK_TRAIN_NONE; | |
1345 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
1346 | I915_WRITE(fdi_rx_reg, temp); | |
2c07245f | 1347 | |
32f9d658 | 1348 | udelay(150); |
2c07245f | 1349 | |
32f9d658 ZW |
1350 | temp = I915_READ(fdi_rx_iir_reg); |
1351 | DRM_DEBUG("FDI_RX_IIR 0x%x\n", temp); | |
2c07245f | 1352 | |
32f9d658 ZW |
1353 | if ((temp & FDI_RX_SYMBOL_LOCK) == 0) { |
1354 | for (j = 0; j < tries; j++) { | |
1355 | temp = I915_READ(fdi_rx_iir_reg); | |
1356 | DRM_DEBUG("FDI_RX_IIR 0x%x\n", temp); | |
1357 | if (temp & FDI_RX_SYMBOL_LOCK) | |
1358 | break; | |
1359 | udelay(200); | |
1360 | } | |
1361 | if (j != tries) { | |
1362 | I915_WRITE(fdi_rx_iir_reg, | |
1363 | temp | FDI_RX_SYMBOL_LOCK); | |
1364 | DRM_DEBUG("train 2 ok 1!\n"); | |
1365 | } else | |
1366 | DRM_DEBUG("train 2 fail\n"); | |
1367 | } else { | |
2c07245f ZW |
1368 | I915_WRITE(fdi_rx_iir_reg, |
1369 | temp | FDI_RX_SYMBOL_LOCK); | |
32f9d658 ZW |
1370 | DRM_DEBUG("train 2 ok 2!\n"); |
1371 | } | |
1372 | DRM_DEBUG("train done\n"); | |
2c07245f | 1373 | |
32f9d658 ZW |
1374 | /* set transcoder timing */ |
1375 | I915_WRITE(trans_htot_reg, I915_READ(cpu_htot_reg)); | |
1376 | I915_WRITE(trans_hblank_reg, I915_READ(cpu_hblank_reg)); | |
1377 | I915_WRITE(trans_hsync_reg, I915_READ(cpu_hsync_reg)); | |
2c07245f | 1378 | |
32f9d658 ZW |
1379 | I915_WRITE(trans_vtot_reg, I915_READ(cpu_vtot_reg)); |
1380 | I915_WRITE(trans_vblank_reg, I915_READ(cpu_vblank_reg)); | |
1381 | I915_WRITE(trans_vsync_reg, I915_READ(cpu_vsync_reg)); | |
2c07245f | 1382 | |
32f9d658 ZW |
1383 | /* enable PCH transcoder */ |
1384 | temp = I915_READ(transconf_reg); | |
1385 | I915_WRITE(transconf_reg, temp | TRANS_ENABLE); | |
1386 | I915_READ(transconf_reg); | |
2c07245f | 1387 | |
32f9d658 ZW |
1388 | while ((I915_READ(transconf_reg) & TRANS_STATE_ENABLE) == 0) |
1389 | ; | |
2c07245f | 1390 | |
32f9d658 | 1391 | /* enable normal */ |
2c07245f | 1392 | |
32f9d658 ZW |
1393 | temp = I915_READ(fdi_tx_reg); |
1394 | temp &= ~FDI_LINK_TRAIN_NONE; | |
1395 | I915_WRITE(fdi_tx_reg, temp | FDI_LINK_TRAIN_NONE | | |
1396 | FDI_TX_ENHANCE_FRAME_ENABLE); | |
1397 | I915_READ(fdi_tx_reg); | |
2c07245f | 1398 | |
32f9d658 ZW |
1399 | temp = I915_READ(fdi_rx_reg); |
1400 | temp &= ~FDI_LINK_TRAIN_NONE; | |
1401 | I915_WRITE(fdi_rx_reg, temp | FDI_LINK_TRAIN_NONE | | |
1402 | FDI_RX_ENHANCE_FRAME_ENABLE); | |
1403 | I915_READ(fdi_rx_reg); | |
2c07245f | 1404 | |
32f9d658 ZW |
1405 | /* wait one idle pattern time */ |
1406 | udelay(100); | |
1407 | ||
1408 | } | |
2c07245f ZW |
1409 | |
1410 | intel_crtc_load_lut(crtc); | |
1411 | ||
1412 | break; | |
1413 | case DRM_MODE_DPMS_OFF: | |
1414 | DRM_DEBUG("crtc %d dpms off\n", pipe); | |
1415 | ||
24f119c7 | 1416 | i915_disable_vga(dev); |
2c07245f ZW |
1417 | |
1418 | /* Disable display plane */ | |
1419 | temp = I915_READ(dspcntr_reg); | |
1420 | if ((temp & DISPLAY_PLANE_ENABLE) != 0) { | |
1421 | I915_WRITE(dspcntr_reg, temp & ~DISPLAY_PLANE_ENABLE); | |
1422 | /* Flush the plane changes */ | |
1423 | I915_WRITE(dspbase_reg, I915_READ(dspbase_reg)); | |
1424 | I915_READ(dspbase_reg); | |
1425 | } | |
1426 | ||
1427 | /* disable cpu pipe, disable after all planes disabled */ | |
1428 | temp = I915_READ(pipeconf_reg); | |
1429 | if ((temp & PIPEACONF_ENABLE) != 0) { | |
1430 | I915_WRITE(pipeconf_reg, temp & ~PIPEACONF_ENABLE); | |
1431 | I915_READ(pipeconf_reg); | |
249c0e64 | 1432 | n = 0; |
2c07245f | 1433 | /* wait for cpu pipe off, pipe state */ |
249c0e64 ZW |
1434 | while ((I915_READ(pipeconf_reg) & I965_PIPECONF_ACTIVE) != 0) { |
1435 | n++; | |
1436 | if (n < 60) { | |
1437 | udelay(500); | |
1438 | continue; | |
1439 | } else { | |
1440 | DRM_DEBUG("pipe %d off delay\n", pipe); | |
1441 | break; | |
1442 | } | |
1443 | } | |
2c07245f ZW |
1444 | } else |
1445 | DRM_DEBUG("crtc %d is disabled\n", pipe); | |
1446 | ||
32f9d658 ZW |
1447 | if (HAS_eDP) { |
1448 | igdng_disable_pll_edp(crtc); | |
1449 | } | |
1450 | ||
2c07245f ZW |
1451 | /* disable CPU FDI tx and PCH FDI rx */ |
1452 | temp = I915_READ(fdi_tx_reg); | |
1453 | I915_WRITE(fdi_tx_reg, temp & ~FDI_TX_ENABLE); | |
1454 | I915_READ(fdi_tx_reg); | |
1455 | ||
1456 | temp = I915_READ(fdi_rx_reg); | |
1457 | I915_WRITE(fdi_rx_reg, temp & ~FDI_RX_ENABLE); | |
1458 | I915_READ(fdi_rx_reg); | |
1459 | ||
249c0e64 ZW |
1460 | udelay(100); |
1461 | ||
2c07245f ZW |
1462 | /* still set train pattern 1 */ |
1463 | temp = I915_READ(fdi_tx_reg); | |
1464 | temp &= ~FDI_LINK_TRAIN_NONE; | |
1465 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
1466 | I915_WRITE(fdi_tx_reg, temp); | |
1467 | ||
1468 | temp = I915_READ(fdi_rx_reg); | |
1469 | temp &= ~FDI_LINK_TRAIN_NONE; | |
1470 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
1471 | I915_WRITE(fdi_rx_reg, temp); | |
1472 | ||
249c0e64 ZW |
1473 | udelay(100); |
1474 | ||
2c07245f ZW |
1475 | /* disable PCH transcoder */ |
1476 | temp = I915_READ(transconf_reg); | |
1477 | if ((temp & TRANS_ENABLE) != 0) { | |
1478 | I915_WRITE(transconf_reg, temp & ~TRANS_ENABLE); | |
1479 | I915_READ(transconf_reg); | |
249c0e64 | 1480 | n = 0; |
2c07245f | 1481 | /* wait for PCH transcoder off, transcoder state */ |
249c0e64 ZW |
1482 | while ((I915_READ(transconf_reg) & TRANS_STATE_ENABLE) != 0) { |
1483 | n++; | |
1484 | if (n < 60) { | |
1485 | udelay(500); | |
1486 | continue; | |
1487 | } else { | |
1488 | DRM_DEBUG("transcoder %d off delay\n", pipe); | |
1489 | break; | |
1490 | } | |
1491 | } | |
2c07245f ZW |
1492 | } |
1493 | ||
1494 | /* disable PCH DPLL */ | |
1495 | temp = I915_READ(pch_dpll_reg); | |
1496 | if ((temp & DPLL_VCO_ENABLE) != 0) { | |
1497 | I915_WRITE(pch_dpll_reg, temp & ~DPLL_VCO_ENABLE); | |
1498 | I915_READ(pch_dpll_reg); | |
1499 | } | |
1500 | ||
1501 | temp = I915_READ(fdi_rx_reg); | |
1502 | if ((temp & FDI_RX_PLL_ENABLE) != 0) { | |
1503 | temp &= ~FDI_SEL_PCDCLK; | |
1504 | temp &= ~FDI_RX_PLL_ENABLE; | |
1505 | I915_WRITE(fdi_rx_reg, temp); | |
1506 | I915_READ(fdi_rx_reg); | |
1507 | } | |
1508 | ||
249c0e64 ZW |
1509 | /* Disable CPU FDI TX PLL */ |
1510 | temp = I915_READ(fdi_tx_reg); | |
1511 | if ((temp & FDI_TX_PLL_ENABLE) != 0) { | |
1512 | I915_WRITE(fdi_tx_reg, temp & ~FDI_TX_PLL_ENABLE); | |
1513 | I915_READ(fdi_tx_reg); | |
1514 | udelay(100); | |
1515 | } | |
1516 | ||
1517 | /* Disable PF */ | |
1518 | temp = I915_READ(pf_ctl_reg); | |
1519 | if ((temp & PF_ENABLE) != 0) { | |
1520 | I915_WRITE(pf_ctl_reg, temp & ~PF_ENABLE); | |
1521 | I915_READ(pf_ctl_reg); | |
1522 | } | |
1523 | I915_WRITE(pf_win_size, 0); | |
1524 | ||
2c07245f ZW |
1525 | /* Wait for the clocks to turn off. */ |
1526 | udelay(150); | |
1527 | break; | |
1528 | } | |
1529 | } | |
1530 | ||
1531 | static void i9xx_crtc_dpms(struct drm_crtc *crtc, int mode) | |
79e53945 JB |
1532 | { |
1533 | struct drm_device *dev = crtc->dev; | |
79e53945 JB |
1534 | struct drm_i915_private *dev_priv = dev->dev_private; |
1535 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
1536 | int pipe = intel_crtc->pipe; | |
1537 | int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B; | |
1538 | int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR; | |
1539 | int dspbase_reg = (pipe == 0) ? DSPAADDR : DSPBADDR; | |
1540 | int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF; | |
1541 | u32 temp; | |
79e53945 JB |
1542 | |
1543 | /* XXX: When our outputs are all unaware of DPMS modes other than off | |
1544 | * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC. | |
1545 | */ | |
1546 | switch (mode) { | |
1547 | case DRM_MODE_DPMS_ON: | |
1548 | case DRM_MODE_DPMS_STANDBY: | |
1549 | case DRM_MODE_DPMS_SUSPEND: | |
1550 | /* Enable the DPLL */ | |
1551 | temp = I915_READ(dpll_reg); | |
1552 | if ((temp & DPLL_VCO_ENABLE) == 0) { | |
1553 | I915_WRITE(dpll_reg, temp); | |
1554 | I915_READ(dpll_reg); | |
1555 | /* Wait for the clocks to stabilize. */ | |
1556 | udelay(150); | |
1557 | I915_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE); | |
1558 | I915_READ(dpll_reg); | |
1559 | /* Wait for the clocks to stabilize. */ | |
1560 | udelay(150); | |
1561 | I915_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE); | |
1562 | I915_READ(dpll_reg); | |
1563 | /* Wait for the clocks to stabilize. */ | |
1564 | udelay(150); | |
1565 | } | |
1566 | ||
1567 | /* Enable the pipe */ | |
1568 | temp = I915_READ(pipeconf_reg); | |
1569 | if ((temp & PIPEACONF_ENABLE) == 0) | |
1570 | I915_WRITE(pipeconf_reg, temp | PIPEACONF_ENABLE); | |
1571 | ||
1572 | /* Enable the plane */ | |
1573 | temp = I915_READ(dspcntr_reg); | |
1574 | if ((temp & DISPLAY_PLANE_ENABLE) == 0) { | |
1575 | I915_WRITE(dspcntr_reg, temp | DISPLAY_PLANE_ENABLE); | |
1576 | /* Flush the plane changes */ | |
1577 | I915_WRITE(dspbase_reg, I915_READ(dspbase_reg)); | |
1578 | } | |
1579 | ||
1580 | intel_crtc_load_lut(crtc); | |
1581 | ||
1582 | /* Give the overlay scaler a chance to enable if it's on this pipe */ | |
1583 | //intel_crtc_dpms_video(crtc, true); TODO | |
7662c8bd | 1584 | intel_update_watermarks(dev); |
79e53945 JB |
1585 | break; |
1586 | case DRM_MODE_DPMS_OFF: | |
7662c8bd | 1587 | intel_update_watermarks(dev); |
79e53945 JB |
1588 | /* Give the overlay scaler a chance to disable if it's on this pipe */ |
1589 | //intel_crtc_dpms_video(crtc, FALSE); TODO | |
1590 | ||
1591 | /* Disable the VGA plane that we never use */ | |
24f119c7 | 1592 | i915_disable_vga(dev); |
79e53945 JB |
1593 | |
1594 | /* Disable display plane */ | |
1595 | temp = I915_READ(dspcntr_reg); | |
1596 | if ((temp & DISPLAY_PLANE_ENABLE) != 0) { | |
1597 | I915_WRITE(dspcntr_reg, temp & ~DISPLAY_PLANE_ENABLE); | |
1598 | /* Flush the plane changes */ | |
1599 | I915_WRITE(dspbase_reg, I915_READ(dspbase_reg)); | |
1600 | I915_READ(dspbase_reg); | |
1601 | } | |
1602 | ||
1603 | if (!IS_I9XX(dev)) { | |
1604 | /* Wait for vblank for the disable to take effect */ | |
1605 | intel_wait_for_vblank(dev); | |
1606 | } | |
1607 | ||
1608 | /* Next, disable display pipes */ | |
1609 | temp = I915_READ(pipeconf_reg); | |
1610 | if ((temp & PIPEACONF_ENABLE) != 0) { | |
1611 | I915_WRITE(pipeconf_reg, temp & ~PIPEACONF_ENABLE); | |
1612 | I915_READ(pipeconf_reg); | |
1613 | } | |
1614 | ||
1615 | /* Wait for vblank for the disable to take effect. */ | |
1616 | intel_wait_for_vblank(dev); | |
1617 | ||
1618 | temp = I915_READ(dpll_reg); | |
1619 | if ((temp & DPLL_VCO_ENABLE) != 0) { | |
1620 | I915_WRITE(dpll_reg, temp & ~DPLL_VCO_ENABLE); | |
1621 | I915_READ(dpll_reg); | |
1622 | } | |
1623 | ||
1624 | /* Wait for the clocks to turn off. */ | |
1625 | udelay(150); | |
1626 | break; | |
1627 | } | |
2c07245f ZW |
1628 | } |
1629 | ||
1630 | /** | |
1631 | * Sets the power management mode of the pipe and plane. | |
1632 | * | |
1633 | * This code should probably grow support for turning the cursor off and back | |
1634 | * on appropriately at the same time as we're turning the pipe off/on. | |
1635 | */ | |
1636 | static void intel_crtc_dpms(struct drm_crtc *crtc, int mode) | |
1637 | { | |
1638 | struct drm_device *dev = crtc->dev; | |
1639 | struct drm_i915_master_private *master_priv; | |
1640 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
1641 | int pipe = intel_crtc->pipe; | |
1642 | bool enabled; | |
1643 | ||
1644 | if (IS_IGDNG(dev)) | |
1645 | igdng_crtc_dpms(crtc, mode); | |
1646 | else | |
1647 | i9xx_crtc_dpms(crtc, mode); | |
79e53945 | 1648 | |
65655d4a DV |
1649 | intel_crtc->dpms_mode = mode; |
1650 | ||
79e53945 JB |
1651 | if (!dev->primary->master) |
1652 | return; | |
1653 | ||
1654 | master_priv = dev->primary->master->driver_priv; | |
1655 | if (!master_priv->sarea_priv) | |
1656 | return; | |
1657 | ||
1658 | enabled = crtc->enabled && mode != DRM_MODE_DPMS_OFF; | |
1659 | ||
1660 | switch (pipe) { | |
1661 | case 0: | |
1662 | master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0; | |
1663 | master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0; | |
1664 | break; | |
1665 | case 1: | |
1666 | master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0; | |
1667 | master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0; | |
1668 | break; | |
1669 | default: | |
1670 | DRM_ERROR("Can't update pipe %d in SAREA\n", pipe); | |
1671 | break; | |
1672 | } | |
79e53945 JB |
1673 | } |
1674 | ||
1675 | static void intel_crtc_prepare (struct drm_crtc *crtc) | |
1676 | { | |
1677 | struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; | |
1678 | crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF); | |
1679 | } | |
1680 | ||
1681 | static void intel_crtc_commit (struct drm_crtc *crtc) | |
1682 | { | |
1683 | struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; | |
1684 | crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON); | |
1685 | } | |
1686 | ||
1687 | void intel_encoder_prepare (struct drm_encoder *encoder) | |
1688 | { | |
1689 | struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; | |
1690 | /* lvds has its own version of prepare see intel_lvds_prepare */ | |
1691 | encoder_funcs->dpms(encoder, DRM_MODE_DPMS_OFF); | |
1692 | } | |
1693 | ||
1694 | void intel_encoder_commit (struct drm_encoder *encoder) | |
1695 | { | |
1696 | struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; | |
1697 | /* lvds has its own version of commit see intel_lvds_commit */ | |
1698 | encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON); | |
1699 | } | |
1700 | ||
1701 | static bool intel_crtc_mode_fixup(struct drm_crtc *crtc, | |
1702 | struct drm_display_mode *mode, | |
1703 | struct drm_display_mode *adjusted_mode) | |
1704 | { | |
2c07245f ZW |
1705 | struct drm_device *dev = crtc->dev; |
1706 | if (IS_IGDNG(dev)) { | |
1707 | /* FDI link clock is fixed at 2.7G */ | |
1708 | if (mode->clock * 3 > 27000 * 4) | |
1709 | return MODE_CLOCK_HIGH; | |
1710 | } | |
79e53945 JB |
1711 | return true; |
1712 | } | |
1713 | ||
1714 | ||
1715 | /** Returns the core display clock speed for i830 - i945 */ | |
1716 | static int intel_get_core_clock_speed(struct drm_device *dev) | |
1717 | { | |
1718 | ||
1719 | /* Core clock values taken from the published datasheets. | |
1720 | * The 830 may go up to 166 Mhz, which we should check. | |
1721 | */ | |
1722 | if (IS_I945G(dev)) | |
1723 | return 400000; | |
1724 | else if (IS_I915G(dev)) | |
1725 | return 333000; | |
2177832f | 1726 | else if (IS_I945GM(dev) || IS_845G(dev) || IS_IGDGM(dev)) |
79e53945 JB |
1727 | return 200000; |
1728 | else if (IS_I915GM(dev)) { | |
1729 | u16 gcfgc = 0; | |
1730 | ||
1731 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); | |
1732 | ||
1733 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) | |
1734 | return 133000; | |
1735 | else { | |
1736 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
1737 | case GC_DISPLAY_CLOCK_333_MHZ: | |
1738 | return 333000; | |
1739 | default: | |
1740 | case GC_DISPLAY_CLOCK_190_200_MHZ: | |
1741 | return 190000; | |
1742 | } | |
1743 | } | |
1744 | } else if (IS_I865G(dev)) | |
1745 | return 266000; | |
1746 | else if (IS_I855(dev)) { | |
1747 | u16 hpllcc = 0; | |
1748 | /* Assume that the hardware is in the high speed state. This | |
1749 | * should be the default. | |
1750 | */ | |
1751 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { | |
1752 | case GC_CLOCK_133_200: | |
1753 | case GC_CLOCK_100_200: | |
1754 | return 200000; | |
1755 | case GC_CLOCK_166_250: | |
1756 | return 250000; | |
1757 | case GC_CLOCK_100_133: | |
1758 | return 133000; | |
1759 | } | |
1760 | } else /* 852, 830 */ | |
1761 | return 133000; | |
1762 | ||
1763 | return 0; /* Silence gcc warning */ | |
1764 | } | |
1765 | ||
79e53945 JB |
1766 | /** |
1767 | * Return the pipe currently connected to the panel fitter, | |
1768 | * or -1 if the panel fitter is not present or not in use | |
1769 | */ | |
1770 | static int intel_panel_fitter_pipe (struct drm_device *dev) | |
1771 | { | |
1772 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1773 | u32 pfit_control; | |
1774 | ||
1775 | /* i830 doesn't have a panel fitter */ | |
1776 | if (IS_I830(dev)) | |
1777 | return -1; | |
1778 | ||
1779 | pfit_control = I915_READ(PFIT_CONTROL); | |
1780 | ||
1781 | /* See if the panel fitter is in use */ | |
1782 | if ((pfit_control & PFIT_ENABLE) == 0) | |
1783 | return -1; | |
1784 | ||
1785 | /* 965 can place panel fitter on either pipe */ | |
1786 | if (IS_I965G(dev)) | |
1787 | return (pfit_control >> 29) & 0x3; | |
1788 | ||
1789 | /* older chips can only use pipe 1 */ | |
1790 | return 1; | |
1791 | } | |
1792 | ||
2c07245f ZW |
1793 | struct fdi_m_n { |
1794 | u32 tu; | |
1795 | u32 gmch_m; | |
1796 | u32 gmch_n; | |
1797 | u32 link_m; | |
1798 | u32 link_n; | |
1799 | }; | |
1800 | ||
1801 | static void | |
1802 | fdi_reduce_ratio(u32 *num, u32 *den) | |
1803 | { | |
1804 | while (*num > 0xffffff || *den > 0xffffff) { | |
1805 | *num >>= 1; | |
1806 | *den >>= 1; | |
1807 | } | |
1808 | } | |
1809 | ||
1810 | #define DATA_N 0x800000 | |
1811 | #define LINK_N 0x80000 | |
1812 | ||
1813 | static void | |
1814 | igdng_compute_m_n(int bytes_per_pixel, int nlanes, | |
1815 | int pixel_clock, int link_clock, | |
1816 | struct fdi_m_n *m_n) | |
1817 | { | |
1818 | u64 temp; | |
1819 | ||
1820 | m_n->tu = 64; /* default size */ | |
1821 | ||
1822 | temp = (u64) DATA_N * pixel_clock; | |
1823 | temp = div_u64(temp, link_clock); | |
956dba3c | 1824 | m_n->gmch_m = div_u64(temp * bytes_per_pixel, nlanes); |
2c07245f ZW |
1825 | m_n->gmch_n = DATA_N; |
1826 | fdi_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n); | |
1827 | ||
1828 | temp = (u64) LINK_N * pixel_clock; | |
1829 | m_n->link_m = div_u64(temp, link_clock); | |
1830 | m_n->link_n = LINK_N; | |
1831 | fdi_reduce_ratio(&m_n->link_m, &m_n->link_n); | |
1832 | } | |
1833 | ||
1834 | ||
7662c8bd SL |
1835 | struct intel_watermark_params { |
1836 | unsigned long fifo_size; | |
1837 | unsigned long max_wm; | |
1838 | unsigned long default_wm; | |
1839 | unsigned long guard_size; | |
1840 | unsigned long cacheline_size; | |
1841 | }; | |
1842 | ||
1843 | /* IGD has different values for various configs */ | |
1844 | static struct intel_watermark_params igd_display_wm = { | |
1845 | IGD_DISPLAY_FIFO, | |
1846 | IGD_MAX_WM, | |
1847 | IGD_DFT_WM, | |
1848 | IGD_GUARD_WM, | |
1849 | IGD_FIFO_LINE_SIZE | |
1850 | }; | |
1851 | static struct intel_watermark_params igd_display_hplloff_wm = { | |
1852 | IGD_DISPLAY_FIFO, | |
1853 | IGD_MAX_WM, | |
1854 | IGD_DFT_HPLLOFF_WM, | |
1855 | IGD_GUARD_WM, | |
1856 | IGD_FIFO_LINE_SIZE | |
1857 | }; | |
1858 | static struct intel_watermark_params igd_cursor_wm = { | |
1859 | IGD_CURSOR_FIFO, | |
1860 | IGD_CURSOR_MAX_WM, | |
1861 | IGD_CURSOR_DFT_WM, | |
1862 | IGD_CURSOR_GUARD_WM, | |
1863 | IGD_FIFO_LINE_SIZE, | |
1864 | }; | |
1865 | static struct intel_watermark_params igd_cursor_hplloff_wm = { | |
1866 | IGD_CURSOR_FIFO, | |
1867 | IGD_CURSOR_MAX_WM, | |
1868 | IGD_CURSOR_DFT_WM, | |
1869 | IGD_CURSOR_GUARD_WM, | |
1870 | IGD_FIFO_LINE_SIZE | |
1871 | }; | |
1872 | static struct intel_watermark_params i945_wm_info = { | |
dff33cfc | 1873 | I945_FIFO_SIZE, |
7662c8bd SL |
1874 | I915_MAX_WM, |
1875 | 1, | |
dff33cfc JB |
1876 | 2, |
1877 | I915_FIFO_LINE_SIZE | |
7662c8bd SL |
1878 | }; |
1879 | static struct intel_watermark_params i915_wm_info = { | |
dff33cfc | 1880 | I915_FIFO_SIZE, |
7662c8bd SL |
1881 | I915_MAX_WM, |
1882 | 1, | |
dff33cfc | 1883 | 2, |
7662c8bd SL |
1884 | I915_FIFO_LINE_SIZE |
1885 | }; | |
1886 | static struct intel_watermark_params i855_wm_info = { | |
1887 | I855GM_FIFO_SIZE, | |
1888 | I915_MAX_WM, | |
1889 | 1, | |
dff33cfc | 1890 | 2, |
7662c8bd SL |
1891 | I830_FIFO_LINE_SIZE |
1892 | }; | |
1893 | static struct intel_watermark_params i830_wm_info = { | |
1894 | I830_FIFO_SIZE, | |
1895 | I915_MAX_WM, | |
1896 | 1, | |
dff33cfc | 1897 | 2, |
7662c8bd SL |
1898 | I830_FIFO_LINE_SIZE |
1899 | }; | |
1900 | ||
dff33cfc JB |
1901 | /** |
1902 | * intel_calculate_wm - calculate watermark level | |
1903 | * @clock_in_khz: pixel clock | |
1904 | * @wm: chip FIFO params | |
1905 | * @pixel_size: display pixel size | |
1906 | * @latency_ns: memory latency for the platform | |
1907 | * | |
1908 | * Calculate the watermark level (the level at which the display plane will | |
1909 | * start fetching from memory again). Each chip has a different display | |
1910 | * FIFO size and allocation, so the caller needs to figure that out and pass | |
1911 | * in the correct intel_watermark_params structure. | |
1912 | * | |
1913 | * As the pixel clock runs, the FIFO will be drained at a rate that depends | |
1914 | * on the pixel size. When it reaches the watermark level, it'll start | |
1915 | * fetching FIFO line sized based chunks from memory until the FIFO fills | |
1916 | * past the watermark point. If the FIFO drains completely, a FIFO underrun | |
1917 | * will occur, and a display engine hang could result. | |
1918 | */ | |
7662c8bd SL |
1919 | static unsigned long intel_calculate_wm(unsigned long clock_in_khz, |
1920 | struct intel_watermark_params *wm, | |
1921 | int pixel_size, | |
1922 | unsigned long latency_ns) | |
1923 | { | |
390c4dd4 | 1924 | long entries_required, wm_size; |
dff33cfc JB |
1925 | |
1926 | entries_required = (clock_in_khz * pixel_size * latency_ns) / 1000000; | |
1927 | entries_required /= wm->cacheline_size; | |
7662c8bd | 1928 | |
dff33cfc JB |
1929 | DRM_DEBUG("FIFO entries required for mode: %d\n", entries_required); |
1930 | ||
1931 | wm_size = wm->fifo_size - (entries_required + wm->guard_size); | |
1932 | ||
1933 | DRM_DEBUG("FIFO watermark level: %d\n", wm_size); | |
7662c8bd | 1934 | |
390c4dd4 JB |
1935 | /* Don't promote wm_size to unsigned... */ |
1936 | if (wm_size > (long)wm->max_wm) | |
7662c8bd | 1937 | wm_size = wm->max_wm; |
390c4dd4 | 1938 | if (wm_size <= 0) |
7662c8bd SL |
1939 | wm_size = wm->default_wm; |
1940 | return wm_size; | |
1941 | } | |
1942 | ||
1943 | struct cxsr_latency { | |
1944 | int is_desktop; | |
1945 | unsigned long fsb_freq; | |
1946 | unsigned long mem_freq; | |
1947 | unsigned long display_sr; | |
1948 | unsigned long display_hpll_disable; | |
1949 | unsigned long cursor_sr; | |
1950 | unsigned long cursor_hpll_disable; | |
1951 | }; | |
1952 | ||
1953 | static struct cxsr_latency cxsr_latency_table[] = { | |
1954 | {1, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ | |
1955 | {1, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ | |
1956 | {1, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ | |
1957 | ||
1958 | {1, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ | |
1959 | {1, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ | |
1960 | {1, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ | |
1961 | ||
1962 | {1, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ | |
1963 | {1, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ | |
1964 | {1, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ | |
1965 | ||
1966 | {0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ | |
1967 | {0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ | |
1968 | {0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ | |
1969 | ||
1970 | {0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ | |
1971 | {0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ | |
1972 | {0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ | |
1973 | ||
1974 | {0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ | |
1975 | {0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ | |
1976 | {0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ | |
1977 | }; | |
1978 | ||
1979 | static struct cxsr_latency *intel_get_cxsr_latency(int is_desktop, int fsb, | |
1980 | int mem) | |
1981 | { | |
1982 | int i; | |
1983 | struct cxsr_latency *latency; | |
1984 | ||
1985 | if (fsb == 0 || mem == 0) | |
1986 | return NULL; | |
1987 | ||
1988 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { | |
1989 | latency = &cxsr_latency_table[i]; | |
1990 | if (is_desktop == latency->is_desktop && | |
1991 | fsb == latency->fsb_freq && mem == latency->mem_freq) | |
1992 | break; | |
1993 | } | |
1994 | if (i >= ARRAY_SIZE(cxsr_latency_table)) { | |
1995 | DRM_DEBUG("Unknown FSB/MEM found, disable CxSR\n"); | |
1996 | return NULL; | |
1997 | } | |
1998 | return latency; | |
1999 | } | |
2000 | ||
2001 | static void igd_disable_cxsr(struct drm_device *dev) | |
2002 | { | |
2003 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2004 | u32 reg; | |
2005 | ||
2006 | /* deactivate cxsr */ | |
2007 | reg = I915_READ(DSPFW3); | |
2008 | reg &= ~(IGD_SELF_REFRESH_EN); | |
2009 | I915_WRITE(DSPFW3, reg); | |
2010 | DRM_INFO("Big FIFO is disabled\n"); | |
2011 | } | |
2012 | ||
2013 | static void igd_enable_cxsr(struct drm_device *dev, unsigned long clock, | |
2014 | int pixel_size) | |
2015 | { | |
2016 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2017 | u32 reg; | |
2018 | unsigned long wm; | |
2019 | struct cxsr_latency *latency; | |
2020 | ||
2021 | latency = intel_get_cxsr_latency(IS_IGDG(dev), dev_priv->fsb_freq, | |
2022 | dev_priv->mem_freq); | |
2023 | if (!latency) { | |
2024 | DRM_DEBUG("Unknown FSB/MEM found, disable CxSR\n"); | |
2025 | igd_disable_cxsr(dev); | |
2026 | return; | |
2027 | } | |
2028 | ||
2029 | /* Display SR */ | |
2030 | wm = intel_calculate_wm(clock, &igd_display_wm, pixel_size, | |
2031 | latency->display_sr); | |
2032 | reg = I915_READ(DSPFW1); | |
2033 | reg &= 0x7fffff; | |
2034 | reg |= wm << 23; | |
2035 | I915_WRITE(DSPFW1, reg); | |
2036 | DRM_DEBUG("DSPFW1 register is %x\n", reg); | |
2037 | ||
2038 | /* cursor SR */ | |
2039 | wm = intel_calculate_wm(clock, &igd_cursor_wm, pixel_size, | |
2040 | latency->cursor_sr); | |
2041 | reg = I915_READ(DSPFW3); | |
2042 | reg &= ~(0x3f << 24); | |
2043 | reg |= (wm & 0x3f) << 24; | |
2044 | I915_WRITE(DSPFW3, reg); | |
2045 | ||
2046 | /* Display HPLL off SR */ | |
2047 | wm = intel_calculate_wm(clock, &igd_display_hplloff_wm, | |
2048 | latency->display_hpll_disable, I915_FIFO_LINE_SIZE); | |
2049 | reg = I915_READ(DSPFW3); | |
2050 | reg &= 0xfffffe00; | |
2051 | reg |= wm & 0x1ff; | |
2052 | I915_WRITE(DSPFW3, reg); | |
2053 | ||
2054 | /* cursor HPLL off SR */ | |
2055 | wm = intel_calculate_wm(clock, &igd_cursor_hplloff_wm, pixel_size, | |
2056 | latency->cursor_hpll_disable); | |
2057 | reg = I915_READ(DSPFW3); | |
2058 | reg &= ~(0x3f << 16); | |
2059 | reg |= (wm & 0x3f) << 16; | |
2060 | I915_WRITE(DSPFW3, reg); | |
2061 | DRM_DEBUG("DSPFW3 register is %x\n", reg); | |
2062 | ||
2063 | /* activate cxsr */ | |
2064 | reg = I915_READ(DSPFW3); | |
2065 | reg |= IGD_SELF_REFRESH_EN; | |
2066 | I915_WRITE(DSPFW3, reg); | |
2067 | ||
2068 | DRM_INFO("Big FIFO is enabled\n"); | |
2069 | ||
2070 | return; | |
2071 | } | |
2072 | ||
bcc24fb4 JB |
2073 | /* |
2074 | * Latency for FIFO fetches is dependent on several factors: | |
2075 | * - memory configuration (speed, channels) | |
2076 | * - chipset | |
2077 | * - current MCH state | |
2078 | * It can be fairly high in some situations, so here we assume a fairly | |
2079 | * pessimal value. It's a tradeoff between extra memory fetches (if we | |
2080 | * set this value too high, the FIFO will fetch frequently to stay full) | |
2081 | * and power consumption (set it too low to save power and we might see | |
2082 | * FIFO underruns and display "flicker"). | |
2083 | * | |
2084 | * A value of 5us seems to be a good balance; safe for very low end | |
2085 | * platforms but not overly aggressive on lower latency configs. | |
2086 | */ | |
2087 | const static int latency_ns = 5000; | |
7662c8bd | 2088 | |
dff33cfc JB |
2089 | static int intel_get_fifo_size(struct drm_device *dev, int plane) |
2090 | { | |
2091 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2092 | uint32_t dsparb = I915_READ(DSPARB); | |
2093 | int size; | |
2094 | ||
2095 | if (IS_I9XX(dev)) { | |
2096 | if (plane == 0) | |
2097 | size = dsparb & 0x7f; | |
2098 | else | |
2099 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - | |
2100 | (dsparb & 0x7f); | |
2101 | } else if (IS_I85X(dev)) { | |
2102 | if (plane == 0) | |
2103 | size = dsparb & 0x1ff; | |
2104 | else | |
2105 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - | |
2106 | (dsparb & 0x1ff); | |
2107 | size >>= 1; /* Convert to cachelines */ | |
f3601326 JB |
2108 | } else if (IS_845G(dev)) { |
2109 | size = dsparb & 0x7f; | |
2110 | size >>= 2; /* Convert to cachelines */ | |
dff33cfc JB |
2111 | } else { |
2112 | size = dsparb & 0x7f; | |
2113 | size >>= 1; /* Convert to cachelines */ | |
2114 | } | |
2115 | ||
2116 | DRM_DEBUG("FIFO size - (0x%08x) %s: %d\n", dsparb, plane ? "B" : "A", | |
2117 | size); | |
2118 | ||
2119 | return size; | |
2120 | } | |
7662c8bd | 2121 | |
652c393a JB |
2122 | static void g4x_update_wm(struct drm_device *dev) |
2123 | { | |
2124 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2125 | u32 fw_blc_self = I915_READ(FW_BLC_SELF); | |
2126 | ||
2127 | if (i915_powersave) | |
2128 | fw_blc_self |= FW_BLC_SELF_EN; | |
2129 | else | |
2130 | fw_blc_self &= ~FW_BLC_SELF_EN; | |
2131 | I915_WRITE(FW_BLC_SELF, fw_blc_self); | |
2132 | } | |
2133 | ||
7662c8bd SL |
2134 | static void i965_update_wm(struct drm_device *dev) |
2135 | { | |
2136 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2137 | ||
2138 | DRM_DEBUG("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR 8\n"); | |
2139 | ||
2140 | /* 965 has limitations... */ | |
2141 | I915_WRITE(DSPFW1, (8 << 16) | (8 << 8) | (8 << 0)); | |
2142 | I915_WRITE(DSPFW2, (8 << 8) | (8 << 0)); | |
2143 | } | |
2144 | ||
2145 | static void i9xx_update_wm(struct drm_device *dev, int planea_clock, | |
2146 | int planeb_clock, int sr_hdisplay, int pixel_size) | |
2147 | { | |
2148 | struct drm_i915_private *dev_priv = dev->dev_private; | |
dff33cfc JB |
2149 | uint32_t fwater_lo; |
2150 | uint32_t fwater_hi; | |
2151 | int total_size, cacheline_size, cwm, srwm = 1; | |
2152 | int planea_wm, planeb_wm; | |
2153 | struct intel_watermark_params planea_params, planeb_params; | |
7662c8bd SL |
2154 | unsigned long line_time_us; |
2155 | int sr_clock, sr_entries = 0; | |
2156 | ||
dff33cfc | 2157 | /* Create copies of the base settings for each pipe */ |
7662c8bd | 2158 | if (IS_I965GM(dev) || IS_I945GM(dev)) |
dff33cfc | 2159 | planea_params = planeb_params = i945_wm_info; |
7662c8bd | 2160 | else if (IS_I9XX(dev)) |
dff33cfc | 2161 | planea_params = planeb_params = i915_wm_info; |
7662c8bd | 2162 | else |
dff33cfc | 2163 | planea_params = planeb_params = i855_wm_info; |
7662c8bd | 2164 | |
dff33cfc JB |
2165 | /* Grab a couple of global values before we overwrite them */ |
2166 | total_size = planea_params.fifo_size; | |
2167 | cacheline_size = planea_params.cacheline_size; | |
7662c8bd | 2168 | |
dff33cfc JB |
2169 | /* Update per-plane FIFO sizes */ |
2170 | planea_params.fifo_size = intel_get_fifo_size(dev, 0); | |
2171 | planeb_params.fifo_size = intel_get_fifo_size(dev, 1); | |
7662c8bd | 2172 | |
dff33cfc JB |
2173 | planea_wm = intel_calculate_wm(planea_clock, &planea_params, |
2174 | pixel_size, latency_ns); | |
2175 | planeb_wm = intel_calculate_wm(planeb_clock, &planeb_params, | |
2176 | pixel_size, latency_ns); | |
2177 | DRM_DEBUG("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); | |
7662c8bd SL |
2178 | |
2179 | /* | |
2180 | * Overlay gets an aggressive default since video jitter is bad. | |
2181 | */ | |
2182 | cwm = 2; | |
2183 | ||
dff33cfc | 2184 | /* Calc sr entries for one plane configs */ |
652c393a JB |
2185 | if (HAS_FW_BLC(dev) && sr_hdisplay && |
2186 | (!planea_clock || !planeb_clock)) { | |
dff33cfc JB |
2187 | /* self-refresh has much higher latency */ |
2188 | const static int sr_latency_ns = 6000; | |
2189 | ||
7662c8bd | 2190 | sr_clock = planea_clock ? planea_clock : planeb_clock; |
dff33cfc JB |
2191 | line_time_us = ((sr_hdisplay * 1000) / sr_clock); |
2192 | ||
2193 | /* Use ns/us then divide to preserve precision */ | |
2194 | sr_entries = (((sr_latency_ns / line_time_us) + 1) * | |
2195 | pixel_size * sr_hdisplay) / 1000; | |
2196 | sr_entries = roundup(sr_entries / cacheline_size, 1); | |
2197 | DRM_DEBUG("self-refresh entries: %d\n", sr_entries); | |
2198 | srwm = total_size - sr_entries; | |
2199 | if (srwm < 0) | |
2200 | srwm = 1; | |
652c393a | 2201 | I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN | (srwm & 0x3f)); |
7662c8bd SL |
2202 | } |
2203 | ||
2204 | DRM_DEBUG("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", | |
dff33cfc | 2205 | planea_wm, planeb_wm, cwm, srwm); |
7662c8bd | 2206 | |
dff33cfc JB |
2207 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
2208 | fwater_hi = (cwm & 0x1f); | |
2209 | ||
2210 | /* Set request length to 8 cachelines per fetch */ | |
2211 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); | |
2212 | fwater_hi = fwater_hi | (1 << 8); | |
7662c8bd SL |
2213 | |
2214 | I915_WRITE(FW_BLC, fwater_lo); | |
2215 | I915_WRITE(FW_BLC2, fwater_hi); | |
7662c8bd SL |
2216 | } |
2217 | ||
2218 | static void i830_update_wm(struct drm_device *dev, int planea_clock, | |
2219 | int pixel_size) | |
2220 | { | |
2221 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f3601326 | 2222 | uint32_t fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
dff33cfc | 2223 | int planea_wm; |
7662c8bd | 2224 | |
dff33cfc | 2225 | i830_wm_info.fifo_size = intel_get_fifo_size(dev, 0); |
7662c8bd | 2226 | |
dff33cfc JB |
2227 | planea_wm = intel_calculate_wm(planea_clock, &i830_wm_info, |
2228 | pixel_size, latency_ns); | |
f3601326 JB |
2229 | fwater_lo |= (3<<8) | planea_wm; |
2230 | ||
2231 | DRM_DEBUG("Setting FIFO watermarks - A: %d\n", planea_wm); | |
7662c8bd SL |
2232 | |
2233 | I915_WRITE(FW_BLC, fwater_lo); | |
2234 | } | |
2235 | ||
2236 | /** | |
2237 | * intel_update_watermarks - update FIFO watermark values based on current modes | |
2238 | * | |
2239 | * Calculate watermark values for the various WM regs based on current mode | |
2240 | * and plane configuration. | |
2241 | * | |
2242 | * There are several cases to deal with here: | |
2243 | * - normal (i.e. non-self-refresh) | |
2244 | * - self-refresh (SR) mode | |
2245 | * - lines are large relative to FIFO size (buffer can hold up to 2) | |
2246 | * - lines are small relative to FIFO size (buffer can hold more than 2 | |
2247 | * lines), so need to account for TLB latency | |
2248 | * | |
2249 | * The normal calculation is: | |
2250 | * watermark = dotclock * bytes per pixel * latency | |
2251 | * where latency is platform & configuration dependent (we assume pessimal | |
2252 | * values here). | |
2253 | * | |
2254 | * The SR calculation is: | |
2255 | * watermark = (trunc(latency/line time)+1) * surface width * | |
2256 | * bytes per pixel | |
2257 | * where | |
2258 | * line time = htotal / dotclock | |
2259 | * and latency is assumed to be high, as above. | |
2260 | * | |
2261 | * The final value programmed to the register should always be rounded up, | |
2262 | * and include an extra 2 entries to account for clock crossings. | |
2263 | * | |
2264 | * We don't use the sprite, so we can ignore that. And on Crestline we have | |
2265 | * to set the non-SR watermarks to 8. | |
2266 | */ | |
2267 | static void intel_update_watermarks(struct drm_device *dev) | |
2268 | { | |
2269 | struct drm_crtc *crtc; | |
2270 | struct intel_crtc *intel_crtc; | |
2271 | int sr_hdisplay = 0; | |
2272 | unsigned long planea_clock = 0, planeb_clock = 0, sr_clock = 0; | |
2273 | int enabled = 0, pixel_size = 0; | |
2274 | ||
7662c8bd SL |
2275 | /* Get the clock config from both planes */ |
2276 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { | |
2277 | intel_crtc = to_intel_crtc(crtc); | |
2278 | if (crtc->enabled) { | |
2279 | enabled++; | |
2280 | if (intel_crtc->plane == 0) { | |
2281 | DRM_DEBUG("plane A (pipe %d) clock: %d\n", | |
2282 | intel_crtc->pipe, crtc->mode.clock); | |
2283 | planea_clock = crtc->mode.clock; | |
2284 | } else { | |
2285 | DRM_DEBUG("plane B (pipe %d) clock: %d\n", | |
2286 | intel_crtc->pipe, crtc->mode.clock); | |
2287 | planeb_clock = crtc->mode.clock; | |
2288 | } | |
2289 | sr_hdisplay = crtc->mode.hdisplay; | |
2290 | sr_clock = crtc->mode.clock; | |
2291 | if (crtc->fb) | |
2292 | pixel_size = crtc->fb->bits_per_pixel / 8; | |
2293 | else | |
2294 | pixel_size = 4; /* by default */ | |
2295 | } | |
2296 | } | |
2297 | ||
2298 | if (enabled <= 0) | |
2299 | return; | |
2300 | ||
dff33cfc | 2301 | /* Single plane configs can enable self refresh */ |
7662c8bd SL |
2302 | if (enabled == 1 && IS_IGD(dev)) |
2303 | igd_enable_cxsr(dev, sr_clock, pixel_size); | |
2304 | else if (IS_IGD(dev)) | |
2305 | igd_disable_cxsr(dev); | |
2306 | ||
652c393a JB |
2307 | if (IS_G4X(dev)) |
2308 | g4x_update_wm(dev); | |
2309 | else if (IS_I965G(dev)) | |
7662c8bd SL |
2310 | i965_update_wm(dev); |
2311 | else if (IS_I9XX(dev) || IS_MOBILE(dev)) | |
2312 | i9xx_update_wm(dev, planea_clock, planeb_clock, sr_hdisplay, | |
2313 | pixel_size); | |
2314 | else | |
2315 | i830_update_wm(dev, planea_clock, pixel_size); | |
2316 | } | |
2317 | ||
5c3b82e2 CW |
2318 | static int intel_crtc_mode_set(struct drm_crtc *crtc, |
2319 | struct drm_display_mode *mode, | |
2320 | struct drm_display_mode *adjusted_mode, | |
2321 | int x, int y, | |
2322 | struct drm_framebuffer *old_fb) | |
79e53945 JB |
2323 | { |
2324 | struct drm_device *dev = crtc->dev; | |
2325 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2326 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
2327 | int pipe = intel_crtc->pipe; | |
2328 | int fp_reg = (pipe == 0) ? FPA0 : FPB0; | |
2329 | int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B; | |
2330 | int dpll_md_reg = (intel_crtc->pipe == 0) ? DPLL_A_MD : DPLL_B_MD; | |
2331 | int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR; | |
2332 | int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF; | |
2333 | int htot_reg = (pipe == 0) ? HTOTAL_A : HTOTAL_B; | |
2334 | int hblank_reg = (pipe == 0) ? HBLANK_A : HBLANK_B; | |
2335 | int hsync_reg = (pipe == 0) ? HSYNC_A : HSYNC_B; | |
2336 | int vtot_reg = (pipe == 0) ? VTOTAL_A : VTOTAL_B; | |
2337 | int vblank_reg = (pipe == 0) ? VBLANK_A : VBLANK_B; | |
2338 | int vsync_reg = (pipe == 0) ? VSYNC_A : VSYNC_B; | |
2339 | int dspsize_reg = (pipe == 0) ? DSPASIZE : DSPBSIZE; | |
2340 | int dsppos_reg = (pipe == 0) ? DSPAPOS : DSPBPOS; | |
2341 | int pipesrc_reg = (pipe == 0) ? PIPEASRC : PIPEBSRC; | |
43565a06 | 2342 | int refclk, num_outputs = 0; |
652c393a JB |
2343 | intel_clock_t clock, reduced_clock; |
2344 | u32 dpll = 0, fp = 0, fp2 = 0, dspcntr, pipeconf; | |
2345 | bool ok, has_reduced_clock = false, is_sdvo = false, is_dvo = false; | |
a4fc5ed6 | 2346 | bool is_crt = false, is_lvds = false, is_tv = false, is_dp = false; |
32f9d658 | 2347 | bool is_edp = false; |
79e53945 JB |
2348 | struct drm_mode_config *mode_config = &dev->mode_config; |
2349 | struct drm_connector *connector; | |
d4906093 | 2350 | const intel_limit_t *limit; |
5c3b82e2 | 2351 | int ret; |
2c07245f ZW |
2352 | struct fdi_m_n m_n = {0}; |
2353 | int data_m1_reg = (pipe == 0) ? PIPEA_DATA_M1 : PIPEB_DATA_M1; | |
2354 | int data_n1_reg = (pipe == 0) ? PIPEA_DATA_N1 : PIPEB_DATA_N1; | |
2355 | int link_m1_reg = (pipe == 0) ? PIPEA_LINK_M1 : PIPEB_LINK_M1; | |
2356 | int link_n1_reg = (pipe == 0) ? PIPEA_LINK_N1 : PIPEB_LINK_N1; | |
2357 | int pch_fp_reg = (pipe == 0) ? PCH_FPA0 : PCH_FPB0; | |
2358 | int pch_dpll_reg = (pipe == 0) ? PCH_DPLL_A : PCH_DPLL_B; | |
2359 | int fdi_rx_reg = (pipe == 0) ? FDI_RXA_CTL : FDI_RXB_CTL; | |
541998a1 | 2360 | int lvds_reg = LVDS; |
2c07245f ZW |
2361 | u32 temp; |
2362 | int sdvo_pixel_multiply; | |
5eb08b69 | 2363 | int target_clock; |
79e53945 JB |
2364 | |
2365 | drm_vblank_pre_modeset(dev, pipe); | |
2366 | ||
2367 | list_for_each_entry(connector, &mode_config->connector_list, head) { | |
2368 | struct intel_output *intel_output = to_intel_output(connector); | |
2369 | ||
2370 | if (!connector->encoder || connector->encoder->crtc != crtc) | |
2371 | continue; | |
2372 | ||
2373 | switch (intel_output->type) { | |
2374 | case INTEL_OUTPUT_LVDS: | |
2375 | is_lvds = true; | |
2376 | break; | |
2377 | case INTEL_OUTPUT_SDVO: | |
7d57382e | 2378 | case INTEL_OUTPUT_HDMI: |
79e53945 | 2379 | is_sdvo = true; |
e2f0ba97 JB |
2380 | if (intel_output->needs_tv_clock) |
2381 | is_tv = true; | |
79e53945 JB |
2382 | break; |
2383 | case INTEL_OUTPUT_DVO: | |
2384 | is_dvo = true; | |
2385 | break; | |
2386 | case INTEL_OUTPUT_TVOUT: | |
2387 | is_tv = true; | |
2388 | break; | |
2389 | case INTEL_OUTPUT_ANALOG: | |
2390 | is_crt = true; | |
2391 | break; | |
a4fc5ed6 KP |
2392 | case INTEL_OUTPUT_DISPLAYPORT: |
2393 | is_dp = true; | |
2394 | break; | |
32f9d658 ZW |
2395 | case INTEL_OUTPUT_EDP: |
2396 | is_edp = true; | |
2397 | break; | |
79e53945 | 2398 | } |
43565a06 KH |
2399 | |
2400 | num_outputs++; | |
79e53945 JB |
2401 | } |
2402 | ||
43565a06 KH |
2403 | if (is_lvds && dev_priv->lvds_use_ssc && num_outputs < 2) { |
2404 | refclk = dev_priv->lvds_ssc_freq * 1000; | |
2405 | DRM_DEBUG("using SSC reference clock of %d MHz\n", refclk / 1000); | |
2406 | } else if (IS_I9XX(dev)) { | |
79e53945 | 2407 | refclk = 96000; |
2c07245f ZW |
2408 | if (IS_IGDNG(dev)) |
2409 | refclk = 120000; /* 120Mhz refclk */ | |
79e53945 JB |
2410 | } else { |
2411 | refclk = 48000; | |
2412 | } | |
a4fc5ed6 | 2413 | |
79e53945 | 2414 | |
d4906093 ML |
2415 | /* |
2416 | * Returns a set of divisors for the desired target clock with the given | |
2417 | * refclk, or FALSE. The returned values represent the clock equation: | |
2418 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. | |
2419 | */ | |
2420 | limit = intel_limit(crtc); | |
2421 | ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, &clock); | |
79e53945 JB |
2422 | if (!ok) { |
2423 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); | |
1f803ee5 | 2424 | drm_vblank_post_modeset(dev, pipe); |
5c3b82e2 | 2425 | return -EINVAL; |
79e53945 JB |
2426 | } |
2427 | ||
652c393a JB |
2428 | if (limit->find_reduced_pll && dev_priv->lvds_downclock_avail) { |
2429 | memcpy(&reduced_clock, &clock, sizeof(intel_clock_t)); | |
2430 | has_reduced_clock = limit->find_reduced_pll(limit, crtc, | |
2431 | (adjusted_mode->clock*3/4), | |
2432 | refclk, | |
2433 | &reduced_clock); | |
2434 | } | |
2435 | ||
7026d4ac ZW |
2436 | /* SDVO TV has fixed PLL values depend on its clock range, |
2437 | this mirrors vbios setting. */ | |
2438 | if (is_sdvo && is_tv) { | |
2439 | if (adjusted_mode->clock >= 100000 | |
2440 | && adjusted_mode->clock < 140500) { | |
2441 | clock.p1 = 2; | |
2442 | clock.p2 = 10; | |
2443 | clock.n = 3; | |
2444 | clock.m1 = 16; | |
2445 | clock.m2 = 8; | |
2446 | } else if (adjusted_mode->clock >= 140500 | |
2447 | && adjusted_mode->clock <= 200000) { | |
2448 | clock.p1 = 1; | |
2449 | clock.p2 = 10; | |
2450 | clock.n = 6; | |
2451 | clock.m1 = 12; | |
2452 | clock.m2 = 8; | |
2453 | } | |
2454 | } | |
2455 | ||
2c07245f | 2456 | /* FDI link */ |
5eb08b69 | 2457 | if (IS_IGDNG(dev)) { |
32f9d658 ZW |
2458 | int lane, link_bw; |
2459 | /* eDP doesn't require FDI link, so just set DP M/N | |
2460 | according to current link config */ | |
2461 | if (is_edp) { | |
2462 | struct drm_connector *edp; | |
5eb08b69 | 2463 | target_clock = mode->clock; |
32f9d658 ZW |
2464 | edp = intel_pipe_get_output(crtc); |
2465 | intel_edp_link_config(to_intel_output(edp), | |
2466 | &lane, &link_bw); | |
2467 | } else { | |
2468 | /* DP over FDI requires target mode clock | |
2469 | instead of link clock */ | |
2470 | if (is_dp) | |
2471 | target_clock = mode->clock; | |
2472 | else | |
2473 | target_clock = adjusted_mode->clock; | |
2474 | lane = 4; | |
2475 | link_bw = 270000; | |
2476 | } | |
2477 | igdng_compute_m_n(3, lane, target_clock, | |
2478 | link_bw, &m_n); | |
5eb08b69 | 2479 | } |
2c07245f | 2480 | |
652c393a | 2481 | if (IS_IGD(dev)) { |
2177832f | 2482 | fp = (1 << clock.n) << 16 | clock.m1 << 8 | clock.m2; |
652c393a JB |
2483 | if (has_reduced_clock) |
2484 | fp2 = (1 << reduced_clock.n) << 16 | | |
2485 | reduced_clock.m1 << 8 | reduced_clock.m2; | |
2486 | } else { | |
2177832f | 2487 | fp = clock.n << 16 | clock.m1 << 8 | clock.m2; |
652c393a JB |
2488 | if (has_reduced_clock) |
2489 | fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 | | |
2490 | reduced_clock.m2; | |
2491 | } | |
79e53945 | 2492 | |
2c07245f ZW |
2493 | if (!IS_IGDNG(dev)) |
2494 | dpll = DPLL_VGA_MODE_DIS; | |
2495 | ||
79e53945 JB |
2496 | if (IS_I9XX(dev)) { |
2497 | if (is_lvds) | |
2498 | dpll |= DPLLB_MODE_LVDS; | |
2499 | else | |
2500 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
2501 | if (is_sdvo) { | |
2502 | dpll |= DPLL_DVO_HIGH_SPEED; | |
2c07245f | 2503 | sdvo_pixel_multiply = adjusted_mode->clock / mode->clock; |
942642a4 | 2504 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) |
79e53945 | 2505 | dpll |= (sdvo_pixel_multiply - 1) << SDVO_MULTIPLIER_SHIFT_HIRES; |
2c07245f ZW |
2506 | else if (IS_IGDNG(dev)) |
2507 | dpll |= (sdvo_pixel_multiply - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; | |
79e53945 | 2508 | } |
a4fc5ed6 KP |
2509 | if (is_dp) |
2510 | dpll |= DPLL_DVO_HIGH_SPEED; | |
79e53945 JB |
2511 | |
2512 | /* compute bitmask from p1 value */ | |
2177832f SL |
2513 | if (IS_IGD(dev)) |
2514 | dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_IGD; | |
2c07245f | 2515 | else { |
2177832f | 2516 | dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
2c07245f ZW |
2517 | /* also FPA1 */ |
2518 | if (IS_IGDNG(dev)) | |
2519 | dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; | |
652c393a JB |
2520 | if (IS_G4X(dev) && has_reduced_clock) |
2521 | dpll |= (1 << (reduced_clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; | |
2c07245f | 2522 | } |
79e53945 JB |
2523 | switch (clock.p2) { |
2524 | case 5: | |
2525 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
2526 | break; | |
2527 | case 7: | |
2528 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
2529 | break; | |
2530 | case 10: | |
2531 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
2532 | break; | |
2533 | case 14: | |
2534 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
2535 | break; | |
2536 | } | |
2c07245f | 2537 | if (IS_I965G(dev) && !IS_IGDNG(dev)) |
79e53945 JB |
2538 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
2539 | } else { | |
2540 | if (is_lvds) { | |
2541 | dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
2542 | } else { | |
2543 | if (clock.p1 == 2) | |
2544 | dpll |= PLL_P1_DIVIDE_BY_TWO; | |
2545 | else | |
2546 | dpll |= (clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
2547 | if (clock.p2 == 4) | |
2548 | dpll |= PLL_P2_DIVIDE_BY_4; | |
2549 | } | |
2550 | } | |
2551 | ||
43565a06 KH |
2552 | if (is_sdvo && is_tv) |
2553 | dpll |= PLL_REF_INPUT_TVCLKINBC; | |
2554 | else if (is_tv) | |
79e53945 | 2555 | /* XXX: just matching BIOS for now */ |
43565a06 | 2556 | /* dpll |= PLL_REF_INPUT_TVCLKINBC; */ |
79e53945 | 2557 | dpll |= 3; |
43565a06 KH |
2558 | else if (is_lvds && dev_priv->lvds_use_ssc && num_outputs < 2) |
2559 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
79e53945 JB |
2560 | else |
2561 | dpll |= PLL_REF_INPUT_DREFCLK; | |
2562 | ||
2563 | /* setup pipeconf */ | |
2564 | pipeconf = I915_READ(pipeconf_reg); | |
2565 | ||
2566 | /* Set up the display plane register */ | |
2567 | dspcntr = DISPPLANE_GAMMA_ENABLE; | |
2568 | ||
2c07245f ZW |
2569 | /* IGDNG's plane is forced to pipe, bit 24 is to |
2570 | enable color space conversion */ | |
2571 | if (!IS_IGDNG(dev)) { | |
2572 | if (pipe == 0) | |
2573 | dspcntr |= DISPPLANE_SEL_PIPE_A; | |
2574 | else | |
2575 | dspcntr |= DISPPLANE_SEL_PIPE_B; | |
2576 | } | |
79e53945 JB |
2577 | |
2578 | if (pipe == 0 && !IS_I965G(dev)) { | |
2579 | /* Enable pixel doubling when the dot clock is > 90% of the (display) | |
2580 | * core speed. | |
2581 | * | |
2582 | * XXX: No double-wide on 915GM pipe B. Is that the only reason for the | |
2583 | * pipe == 0 check? | |
2584 | */ | |
2585 | if (mode->clock > intel_get_core_clock_speed(dev) * 9 / 10) | |
2586 | pipeconf |= PIPEACONF_DOUBLE_WIDE; | |
2587 | else | |
2588 | pipeconf &= ~PIPEACONF_DOUBLE_WIDE; | |
2589 | } | |
2590 | ||
2591 | dspcntr |= DISPLAY_PLANE_ENABLE; | |
2592 | pipeconf |= PIPEACONF_ENABLE; | |
2593 | dpll |= DPLL_VCO_ENABLE; | |
2594 | ||
2595 | ||
2596 | /* Disable the panel fitter if it was on our pipe */ | |
2c07245f | 2597 | if (!IS_IGDNG(dev) && intel_panel_fitter_pipe(dev) == pipe) |
79e53945 JB |
2598 | I915_WRITE(PFIT_CONTROL, 0); |
2599 | ||
2600 | DRM_DEBUG("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B'); | |
2601 | drm_mode_debug_printmodeline(mode); | |
2602 | ||
2c07245f ZW |
2603 | /* assign to IGDNG registers */ |
2604 | if (IS_IGDNG(dev)) { | |
2605 | fp_reg = pch_fp_reg; | |
2606 | dpll_reg = pch_dpll_reg; | |
2607 | } | |
79e53945 | 2608 | |
32f9d658 ZW |
2609 | if (is_edp) { |
2610 | igdng_disable_pll_edp(crtc); | |
2611 | } else if ((dpll & DPLL_VCO_ENABLE)) { | |
79e53945 JB |
2612 | I915_WRITE(fp_reg, fp); |
2613 | I915_WRITE(dpll_reg, dpll & ~DPLL_VCO_ENABLE); | |
2614 | I915_READ(dpll_reg); | |
2615 | udelay(150); | |
2616 | } | |
2617 | ||
2618 | /* The LVDS pin pair needs to be on before the DPLLs are enabled. | |
2619 | * This is an exception to the general rule that mode_set doesn't turn | |
2620 | * things on. | |
2621 | */ | |
2622 | if (is_lvds) { | |
541998a1 | 2623 | u32 lvds; |
79e53945 | 2624 | |
541998a1 ZW |
2625 | if (IS_IGDNG(dev)) |
2626 | lvds_reg = PCH_LVDS; | |
2627 | ||
2628 | lvds = I915_READ(lvds_reg); | |
79e53945 JB |
2629 | lvds |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP | LVDS_PIPEB_SELECT; |
2630 | /* Set the B0-B3 data pairs corresponding to whether we're going to | |
2631 | * set the DPLLs for dual-channel mode or not. | |
2632 | */ | |
2633 | if (clock.p2 == 7) | |
2634 | lvds |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP; | |
2635 | else | |
2636 | lvds &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP); | |
2637 | ||
2638 | /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP) | |
2639 | * appropriately here, but we need to look more thoroughly into how | |
2640 | * panels behave in the two modes. | |
2641 | */ | |
2642 | ||
541998a1 ZW |
2643 | I915_WRITE(lvds_reg, lvds); |
2644 | I915_READ(lvds_reg); | |
79e53945 | 2645 | } |
a4fc5ed6 KP |
2646 | if (is_dp) |
2647 | intel_dp_set_m_n(crtc, mode, adjusted_mode); | |
79e53945 | 2648 | |
32f9d658 ZW |
2649 | if (!is_edp) { |
2650 | I915_WRITE(fp_reg, fp); | |
79e53945 | 2651 | I915_WRITE(dpll_reg, dpll); |
32f9d658 ZW |
2652 | I915_READ(dpll_reg); |
2653 | /* Wait for the clocks to stabilize. */ | |
2654 | udelay(150); | |
2655 | ||
2656 | if (IS_I965G(dev) && !IS_IGDNG(dev)) { | |
bb66c512 ZY |
2657 | if (is_sdvo) { |
2658 | sdvo_pixel_multiply = adjusted_mode->clock / mode->clock; | |
2659 | I915_WRITE(dpll_md_reg, (0 << DPLL_MD_UDI_DIVIDER_SHIFT) | | |
32f9d658 | 2660 | ((sdvo_pixel_multiply - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT)); |
bb66c512 ZY |
2661 | } else |
2662 | I915_WRITE(dpll_md_reg, 0); | |
32f9d658 ZW |
2663 | } else { |
2664 | /* write it again -- the BIOS does, after all */ | |
2665 | I915_WRITE(dpll_reg, dpll); | |
2666 | } | |
2667 | I915_READ(dpll_reg); | |
2668 | /* Wait for the clocks to stabilize. */ | |
2669 | udelay(150); | |
79e53945 | 2670 | } |
79e53945 | 2671 | |
652c393a JB |
2672 | if (is_lvds && has_reduced_clock && i915_powersave) { |
2673 | I915_WRITE(fp_reg + 4, fp2); | |
2674 | intel_crtc->lowfreq_avail = true; | |
2675 | if (HAS_PIPE_CXSR(dev)) { | |
2676 | DRM_DEBUG("enabling CxSR downclocking\n"); | |
2677 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; | |
2678 | } | |
2679 | } else { | |
2680 | I915_WRITE(fp_reg + 4, fp); | |
2681 | intel_crtc->lowfreq_avail = false; | |
2682 | if (HAS_PIPE_CXSR(dev)) { | |
2683 | DRM_DEBUG("disabling CxSR downclocking\n"); | |
2684 | pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK; | |
2685 | } | |
2686 | } | |
2687 | ||
79e53945 JB |
2688 | I915_WRITE(htot_reg, (adjusted_mode->crtc_hdisplay - 1) | |
2689 | ((adjusted_mode->crtc_htotal - 1) << 16)); | |
2690 | I915_WRITE(hblank_reg, (adjusted_mode->crtc_hblank_start - 1) | | |
2691 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); | |
2692 | I915_WRITE(hsync_reg, (adjusted_mode->crtc_hsync_start - 1) | | |
2693 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); | |
2694 | I915_WRITE(vtot_reg, (adjusted_mode->crtc_vdisplay - 1) | | |
2695 | ((adjusted_mode->crtc_vtotal - 1) << 16)); | |
2696 | I915_WRITE(vblank_reg, (adjusted_mode->crtc_vblank_start - 1) | | |
2697 | ((adjusted_mode->crtc_vblank_end - 1) << 16)); | |
2698 | I915_WRITE(vsync_reg, (adjusted_mode->crtc_vsync_start - 1) | | |
2699 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); | |
2700 | /* pipesrc and dspsize control the size that is scaled from, which should | |
2701 | * always be the user's requested size. | |
2702 | */ | |
2c07245f ZW |
2703 | if (!IS_IGDNG(dev)) { |
2704 | I915_WRITE(dspsize_reg, ((mode->vdisplay - 1) << 16) | | |
2705 | (mode->hdisplay - 1)); | |
2706 | I915_WRITE(dsppos_reg, 0); | |
2707 | } | |
79e53945 | 2708 | I915_WRITE(pipesrc_reg, ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1)); |
2c07245f ZW |
2709 | |
2710 | if (IS_IGDNG(dev)) { | |
2711 | I915_WRITE(data_m1_reg, TU_SIZE(m_n.tu) | m_n.gmch_m); | |
2712 | I915_WRITE(data_n1_reg, TU_SIZE(m_n.tu) | m_n.gmch_n); | |
2713 | I915_WRITE(link_m1_reg, m_n.link_m); | |
2714 | I915_WRITE(link_n1_reg, m_n.link_n); | |
2715 | ||
32f9d658 ZW |
2716 | if (is_edp) { |
2717 | igdng_set_pll_edp(crtc, adjusted_mode->clock); | |
2718 | } else { | |
2719 | /* enable FDI RX PLL too */ | |
2720 | temp = I915_READ(fdi_rx_reg); | |
2721 | I915_WRITE(fdi_rx_reg, temp | FDI_RX_PLL_ENABLE); | |
2722 | udelay(200); | |
2723 | } | |
2c07245f ZW |
2724 | } |
2725 | ||
79e53945 JB |
2726 | I915_WRITE(pipeconf_reg, pipeconf); |
2727 | I915_READ(pipeconf_reg); | |
2728 | ||
2729 | intel_wait_for_vblank(dev); | |
2730 | ||
553bd149 ZW |
2731 | if (IS_IGDNG(dev)) { |
2732 | /* enable address swizzle for tiling buffer */ | |
2733 | temp = I915_READ(DISP_ARB_CTL); | |
2734 | I915_WRITE(DISP_ARB_CTL, temp | DISP_TILE_SURFACE_SWIZZLING); | |
2735 | } | |
2736 | ||
79e53945 JB |
2737 | I915_WRITE(dspcntr_reg, dspcntr); |
2738 | ||
2739 | /* Flush the plane changes */ | |
5c3b82e2 | 2740 | ret = intel_pipe_set_base(crtc, x, y, old_fb); |
7662c8bd SL |
2741 | |
2742 | intel_update_watermarks(dev); | |
2743 | ||
79e53945 | 2744 | drm_vblank_post_modeset(dev, pipe); |
5c3b82e2 | 2745 | |
1f803ee5 | 2746 | return ret; |
79e53945 JB |
2747 | } |
2748 | ||
2749 | /** Loads the palette/gamma unit for the CRTC with the prepared values */ | |
2750 | void intel_crtc_load_lut(struct drm_crtc *crtc) | |
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 palreg = (intel_crtc->pipe == 0) ? PALETTE_A : PALETTE_B; | |
2756 | int i; | |
2757 | ||
2758 | /* The clocks have to be on to load the palette. */ | |
2759 | if (!crtc->enabled) | |
2760 | return; | |
2761 | ||
2c07245f ZW |
2762 | /* use legacy palette for IGDNG */ |
2763 | if (IS_IGDNG(dev)) | |
2764 | palreg = (intel_crtc->pipe == 0) ? LGC_PALETTE_A : | |
2765 | LGC_PALETTE_B; | |
2766 | ||
79e53945 JB |
2767 | for (i = 0; i < 256; i++) { |
2768 | I915_WRITE(palreg + 4 * i, | |
2769 | (intel_crtc->lut_r[i] << 16) | | |
2770 | (intel_crtc->lut_g[i] << 8) | | |
2771 | intel_crtc->lut_b[i]); | |
2772 | } | |
2773 | } | |
2774 | ||
2775 | static int intel_crtc_cursor_set(struct drm_crtc *crtc, | |
2776 | struct drm_file *file_priv, | |
2777 | uint32_t handle, | |
2778 | uint32_t width, uint32_t height) | |
2779 | { | |
2780 | struct drm_device *dev = crtc->dev; | |
2781 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2782 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
2783 | struct drm_gem_object *bo; | |
2784 | struct drm_i915_gem_object *obj_priv; | |
2785 | int pipe = intel_crtc->pipe; | |
2786 | uint32_t control = (pipe == 0) ? CURACNTR : CURBCNTR; | |
2787 | uint32_t base = (pipe == 0) ? CURABASE : CURBBASE; | |
14b60391 | 2788 | uint32_t temp = I915_READ(control); |
79e53945 | 2789 | size_t addr; |
3f8bc370 | 2790 | int ret; |
79e53945 JB |
2791 | |
2792 | DRM_DEBUG("\n"); | |
2793 | ||
2794 | /* if we want to turn off the cursor ignore width and height */ | |
2795 | if (!handle) { | |
2796 | DRM_DEBUG("cursor off\n"); | |
14b60391 JB |
2797 | if (IS_MOBILE(dev) || IS_I9XX(dev)) { |
2798 | temp &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE); | |
2799 | temp |= CURSOR_MODE_DISABLE; | |
2800 | } else { | |
2801 | temp &= ~(CURSOR_ENABLE | CURSOR_GAMMA_ENABLE); | |
2802 | } | |
3f8bc370 KH |
2803 | addr = 0; |
2804 | bo = NULL; | |
5004417d | 2805 | mutex_lock(&dev->struct_mutex); |
3f8bc370 | 2806 | goto finish; |
79e53945 JB |
2807 | } |
2808 | ||
2809 | /* Currently we only support 64x64 cursors */ | |
2810 | if (width != 64 || height != 64) { | |
2811 | DRM_ERROR("we currently only support 64x64 cursors\n"); | |
2812 | return -EINVAL; | |
2813 | } | |
2814 | ||
2815 | bo = drm_gem_object_lookup(dev, file_priv, handle); | |
2816 | if (!bo) | |
2817 | return -ENOENT; | |
2818 | ||
2819 | obj_priv = bo->driver_private; | |
2820 | ||
2821 | if (bo->size < width * height * 4) { | |
2822 | DRM_ERROR("buffer is to small\n"); | |
34b8686e DA |
2823 | ret = -ENOMEM; |
2824 | goto fail; | |
79e53945 JB |
2825 | } |
2826 | ||
71acb5eb | 2827 | /* we only need to pin inside GTT if cursor is non-phy */ |
7f9872e0 | 2828 | mutex_lock(&dev->struct_mutex); |
71acb5eb DA |
2829 | if (!dev_priv->cursor_needs_physical) { |
2830 | ret = i915_gem_object_pin(bo, PAGE_SIZE); | |
2831 | if (ret) { | |
2832 | DRM_ERROR("failed to pin cursor bo\n"); | |
7f9872e0 | 2833 | goto fail_locked; |
71acb5eb | 2834 | } |
79e53945 | 2835 | addr = obj_priv->gtt_offset; |
71acb5eb DA |
2836 | } else { |
2837 | ret = i915_gem_attach_phys_object(dev, bo, (pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1); | |
2838 | if (ret) { | |
2839 | DRM_ERROR("failed to attach phys object\n"); | |
7f9872e0 | 2840 | goto fail_locked; |
71acb5eb DA |
2841 | } |
2842 | addr = obj_priv->phys_obj->handle->busaddr; | |
3f8bc370 KH |
2843 | } |
2844 | ||
14b60391 JB |
2845 | if (!IS_I9XX(dev)) |
2846 | I915_WRITE(CURSIZE, (height << 12) | width); | |
2847 | ||
2848 | /* Hooray for CUR*CNTR differences */ | |
2849 | if (IS_MOBILE(dev) || IS_I9XX(dev)) { | |
2850 | temp &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT); | |
2851 | temp |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE; | |
2852 | temp |= (pipe << 28); /* Connect to correct pipe */ | |
2853 | } else { | |
2854 | temp &= ~(CURSOR_FORMAT_MASK); | |
2855 | temp |= CURSOR_ENABLE; | |
2856 | temp |= CURSOR_FORMAT_ARGB | CURSOR_GAMMA_ENABLE; | |
2857 | } | |
79e53945 | 2858 | |
3f8bc370 | 2859 | finish: |
79e53945 JB |
2860 | I915_WRITE(control, temp); |
2861 | I915_WRITE(base, addr); | |
2862 | ||
3f8bc370 | 2863 | if (intel_crtc->cursor_bo) { |
71acb5eb DA |
2864 | if (dev_priv->cursor_needs_physical) { |
2865 | if (intel_crtc->cursor_bo != bo) | |
2866 | i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo); | |
2867 | } else | |
2868 | i915_gem_object_unpin(intel_crtc->cursor_bo); | |
3f8bc370 KH |
2869 | drm_gem_object_unreference(intel_crtc->cursor_bo); |
2870 | } | |
7f9872e0 | 2871 | mutex_unlock(&dev->struct_mutex); |
3f8bc370 KH |
2872 | |
2873 | intel_crtc->cursor_addr = addr; | |
2874 | intel_crtc->cursor_bo = bo; | |
2875 | ||
79e53945 | 2876 | return 0; |
34b8686e DA |
2877 | fail: |
2878 | mutex_lock(&dev->struct_mutex); | |
7f9872e0 | 2879 | fail_locked: |
34b8686e DA |
2880 | drm_gem_object_unreference(bo); |
2881 | mutex_unlock(&dev->struct_mutex); | |
2882 | return ret; | |
79e53945 JB |
2883 | } |
2884 | ||
2885 | static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) | |
2886 | { | |
2887 | struct drm_device *dev = crtc->dev; | |
2888 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2889 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
652c393a | 2890 | struct intel_framebuffer *intel_fb; |
79e53945 JB |
2891 | int pipe = intel_crtc->pipe; |
2892 | uint32_t temp = 0; | |
2893 | uint32_t adder; | |
2894 | ||
652c393a JB |
2895 | if (crtc->fb) { |
2896 | intel_fb = to_intel_framebuffer(crtc->fb); | |
2897 | intel_mark_busy(dev, intel_fb->obj); | |
2898 | } | |
2899 | ||
79e53945 | 2900 | if (x < 0) { |
2245fda8 | 2901 | temp |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
79e53945 JB |
2902 | x = -x; |
2903 | } | |
2904 | if (y < 0) { | |
2245fda8 | 2905 | temp |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
79e53945 JB |
2906 | y = -y; |
2907 | } | |
2908 | ||
2245fda8 KP |
2909 | temp |= x << CURSOR_X_SHIFT; |
2910 | temp |= y << CURSOR_Y_SHIFT; | |
79e53945 JB |
2911 | |
2912 | adder = intel_crtc->cursor_addr; | |
2913 | I915_WRITE((pipe == 0) ? CURAPOS : CURBPOS, temp); | |
2914 | I915_WRITE((pipe == 0) ? CURABASE : CURBBASE, adder); | |
2915 | ||
2916 | return 0; | |
2917 | } | |
2918 | ||
2919 | /** Sets the color ramps on behalf of RandR */ | |
2920 | void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green, | |
2921 | u16 blue, int regno) | |
2922 | { | |
2923 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
2924 | ||
2925 | intel_crtc->lut_r[regno] = red >> 8; | |
2926 | intel_crtc->lut_g[regno] = green >> 8; | |
2927 | intel_crtc->lut_b[regno] = blue >> 8; | |
2928 | } | |
2929 | ||
2930 | static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, | |
2931 | u16 *blue, uint32_t size) | |
2932 | { | |
2933 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
2934 | int i; | |
2935 | ||
2936 | if (size != 256) | |
2937 | return; | |
2938 | ||
2939 | for (i = 0; i < 256; i++) { | |
2940 | intel_crtc->lut_r[i] = red[i] >> 8; | |
2941 | intel_crtc->lut_g[i] = green[i] >> 8; | |
2942 | intel_crtc->lut_b[i] = blue[i] >> 8; | |
2943 | } | |
2944 | ||
2945 | intel_crtc_load_lut(crtc); | |
2946 | } | |
2947 | ||
2948 | /** | |
2949 | * Get a pipe with a simple mode set on it for doing load-based monitor | |
2950 | * detection. | |
2951 | * | |
2952 | * It will be up to the load-detect code to adjust the pipe as appropriate for | |
2953 | * its requirements. The pipe will be connected to no other outputs. | |
2954 | * | |
2955 | * Currently this code will only succeed if there is a pipe with no outputs | |
2956 | * configured for it. In the future, it could choose to temporarily disable | |
2957 | * some outputs to free up a pipe for its use. | |
2958 | * | |
2959 | * \return crtc, or NULL if no pipes are available. | |
2960 | */ | |
2961 | ||
2962 | /* VESA 640x480x72Hz mode to set on the pipe */ | |
2963 | static struct drm_display_mode load_detect_mode = { | |
2964 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, | |
2965 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), | |
2966 | }; | |
2967 | ||
2968 | struct drm_crtc *intel_get_load_detect_pipe(struct intel_output *intel_output, | |
2969 | struct drm_display_mode *mode, | |
2970 | int *dpms_mode) | |
2971 | { | |
2972 | struct intel_crtc *intel_crtc; | |
2973 | struct drm_crtc *possible_crtc; | |
2974 | struct drm_crtc *supported_crtc =NULL; | |
2975 | struct drm_encoder *encoder = &intel_output->enc; | |
2976 | struct drm_crtc *crtc = NULL; | |
2977 | struct drm_device *dev = encoder->dev; | |
2978 | struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; | |
2979 | struct drm_crtc_helper_funcs *crtc_funcs; | |
2980 | int i = -1; | |
2981 | ||
2982 | /* | |
2983 | * Algorithm gets a little messy: | |
2984 | * - if the connector already has an assigned crtc, use it (but make | |
2985 | * sure it's on first) | |
2986 | * - try to find the first unused crtc that can drive this connector, | |
2987 | * and use that if we find one | |
2988 | * - if there are no unused crtcs available, try to use the first | |
2989 | * one we found that supports the connector | |
2990 | */ | |
2991 | ||
2992 | /* See if we already have a CRTC for this connector */ | |
2993 | if (encoder->crtc) { | |
2994 | crtc = encoder->crtc; | |
2995 | /* Make sure the crtc and connector are running */ | |
2996 | intel_crtc = to_intel_crtc(crtc); | |
2997 | *dpms_mode = intel_crtc->dpms_mode; | |
2998 | if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) { | |
2999 | crtc_funcs = crtc->helper_private; | |
3000 | crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON); | |
3001 | encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON); | |
3002 | } | |
3003 | return crtc; | |
3004 | } | |
3005 | ||
3006 | /* Find an unused one (if possible) */ | |
3007 | list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) { | |
3008 | i++; | |
3009 | if (!(encoder->possible_crtcs & (1 << i))) | |
3010 | continue; | |
3011 | if (!possible_crtc->enabled) { | |
3012 | crtc = possible_crtc; | |
3013 | break; | |
3014 | } | |
3015 | if (!supported_crtc) | |
3016 | supported_crtc = possible_crtc; | |
3017 | } | |
3018 | ||
3019 | /* | |
3020 | * If we didn't find an unused CRTC, don't use any. | |
3021 | */ | |
3022 | if (!crtc) { | |
3023 | return NULL; | |
3024 | } | |
3025 | ||
3026 | encoder->crtc = crtc; | |
03d60699 | 3027 | intel_output->base.encoder = encoder; |
79e53945 JB |
3028 | intel_output->load_detect_temp = true; |
3029 | ||
3030 | intel_crtc = to_intel_crtc(crtc); | |
3031 | *dpms_mode = intel_crtc->dpms_mode; | |
3032 | ||
3033 | if (!crtc->enabled) { | |
3034 | if (!mode) | |
3035 | mode = &load_detect_mode; | |
3c4fdcfb | 3036 | drm_crtc_helper_set_mode(crtc, mode, 0, 0, crtc->fb); |
79e53945 JB |
3037 | } else { |
3038 | if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) { | |
3039 | crtc_funcs = crtc->helper_private; | |
3040 | crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON); | |
3041 | } | |
3042 | ||
3043 | /* Add this connector to the crtc */ | |
3044 | encoder_funcs->mode_set(encoder, &crtc->mode, &crtc->mode); | |
3045 | encoder_funcs->commit(encoder); | |
3046 | } | |
3047 | /* let the connector get through one full cycle before testing */ | |
3048 | intel_wait_for_vblank(dev); | |
3049 | ||
3050 | return crtc; | |
3051 | } | |
3052 | ||
3053 | void intel_release_load_detect_pipe(struct intel_output *intel_output, int dpms_mode) | |
3054 | { | |
3055 | struct drm_encoder *encoder = &intel_output->enc; | |
3056 | struct drm_device *dev = encoder->dev; | |
3057 | struct drm_crtc *crtc = encoder->crtc; | |
3058 | struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; | |
3059 | struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; | |
3060 | ||
3061 | if (intel_output->load_detect_temp) { | |
3062 | encoder->crtc = NULL; | |
03d60699 | 3063 | intel_output->base.encoder = NULL; |
79e53945 JB |
3064 | intel_output->load_detect_temp = false; |
3065 | crtc->enabled = drm_helper_crtc_in_use(crtc); | |
3066 | drm_helper_disable_unused_functions(dev); | |
3067 | } | |
3068 | ||
3069 | /* Switch crtc and output back off if necessary */ | |
3070 | if (crtc->enabled && dpms_mode != DRM_MODE_DPMS_ON) { | |
3071 | if (encoder->crtc == crtc) | |
3072 | encoder_funcs->dpms(encoder, dpms_mode); | |
3073 | crtc_funcs->dpms(crtc, dpms_mode); | |
3074 | } | |
3075 | } | |
3076 | ||
3077 | /* Returns the clock of the currently programmed mode of the given pipe. */ | |
3078 | static int intel_crtc_clock_get(struct drm_device *dev, struct drm_crtc *crtc) | |
3079 | { | |
3080 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3081 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3082 | int pipe = intel_crtc->pipe; | |
3083 | u32 dpll = I915_READ((pipe == 0) ? DPLL_A : DPLL_B); | |
3084 | u32 fp; | |
3085 | intel_clock_t clock; | |
3086 | ||
3087 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) | |
3088 | fp = I915_READ((pipe == 0) ? FPA0 : FPB0); | |
3089 | else | |
3090 | fp = I915_READ((pipe == 0) ? FPA1 : FPB1); | |
3091 | ||
3092 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; | |
2177832f SL |
3093 | if (IS_IGD(dev)) { |
3094 | clock.n = ffs((fp & FP_N_IGD_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; | |
3095 | clock.m2 = (fp & FP_M2_IGD_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
3096 | } else { | |
3097 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; | |
3098 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
3099 | } | |
3100 | ||
79e53945 | 3101 | if (IS_I9XX(dev)) { |
2177832f SL |
3102 | if (IS_IGD(dev)) |
3103 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_IGD) >> | |
3104 | DPLL_FPA01_P1_POST_DIV_SHIFT_IGD); | |
3105 | else | |
3106 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> | |
79e53945 JB |
3107 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
3108 | ||
3109 | switch (dpll & DPLL_MODE_MASK) { | |
3110 | case DPLLB_MODE_DAC_SERIAL: | |
3111 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? | |
3112 | 5 : 10; | |
3113 | break; | |
3114 | case DPLLB_MODE_LVDS: | |
3115 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? | |
3116 | 7 : 14; | |
3117 | break; | |
3118 | default: | |
3119 | DRM_DEBUG("Unknown DPLL mode %08x in programmed " | |
3120 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); | |
3121 | return 0; | |
3122 | } | |
3123 | ||
3124 | /* XXX: Handle the 100Mhz refclk */ | |
2177832f | 3125 | intel_clock(dev, 96000, &clock); |
79e53945 JB |
3126 | } else { |
3127 | bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN); | |
3128 | ||
3129 | if (is_lvds) { | |
3130 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> | |
3131 | DPLL_FPA01_P1_POST_DIV_SHIFT); | |
3132 | clock.p2 = 14; | |
3133 | ||
3134 | if ((dpll & PLL_REF_INPUT_MASK) == | |
3135 | PLLB_REF_INPUT_SPREADSPECTRUMIN) { | |
3136 | /* XXX: might not be 66MHz */ | |
2177832f | 3137 | intel_clock(dev, 66000, &clock); |
79e53945 | 3138 | } else |
2177832f | 3139 | intel_clock(dev, 48000, &clock); |
79e53945 JB |
3140 | } else { |
3141 | if (dpll & PLL_P1_DIVIDE_BY_TWO) | |
3142 | clock.p1 = 2; | |
3143 | else { | |
3144 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> | |
3145 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; | |
3146 | } | |
3147 | if (dpll & PLL_P2_DIVIDE_BY_4) | |
3148 | clock.p2 = 4; | |
3149 | else | |
3150 | clock.p2 = 2; | |
3151 | ||
2177832f | 3152 | intel_clock(dev, 48000, &clock); |
79e53945 JB |
3153 | } |
3154 | } | |
3155 | ||
3156 | /* XXX: It would be nice to validate the clocks, but we can't reuse | |
3157 | * i830PllIsValid() because it relies on the xf86_config connector | |
3158 | * configuration being accurate, which it isn't necessarily. | |
3159 | */ | |
3160 | ||
3161 | return clock.dot; | |
3162 | } | |
3163 | ||
3164 | /** Returns the currently programmed mode of the given pipe. */ | |
3165 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, | |
3166 | struct drm_crtc *crtc) | |
3167 | { | |
3168 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3169 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3170 | int pipe = intel_crtc->pipe; | |
3171 | struct drm_display_mode *mode; | |
3172 | int htot = I915_READ((pipe == 0) ? HTOTAL_A : HTOTAL_B); | |
3173 | int hsync = I915_READ((pipe == 0) ? HSYNC_A : HSYNC_B); | |
3174 | int vtot = I915_READ((pipe == 0) ? VTOTAL_A : VTOTAL_B); | |
3175 | int vsync = I915_READ((pipe == 0) ? VSYNC_A : VSYNC_B); | |
3176 | ||
3177 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); | |
3178 | if (!mode) | |
3179 | return NULL; | |
3180 | ||
3181 | mode->clock = intel_crtc_clock_get(dev, crtc); | |
3182 | mode->hdisplay = (htot & 0xffff) + 1; | |
3183 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; | |
3184 | mode->hsync_start = (hsync & 0xffff) + 1; | |
3185 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; | |
3186 | mode->vdisplay = (vtot & 0xffff) + 1; | |
3187 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; | |
3188 | mode->vsync_start = (vsync & 0xffff) + 1; | |
3189 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; | |
3190 | ||
3191 | drm_mode_set_name(mode); | |
3192 | drm_mode_set_crtcinfo(mode, 0); | |
3193 | ||
3194 | return mode; | |
3195 | } | |
3196 | ||
652c393a JB |
3197 | #define GPU_IDLE_TIMEOUT 500 /* ms */ |
3198 | ||
3199 | /* When this timer fires, we've been idle for awhile */ | |
3200 | static void intel_gpu_idle_timer(unsigned long arg) | |
3201 | { | |
3202 | struct drm_device *dev = (struct drm_device *)arg; | |
3203 | drm_i915_private_t *dev_priv = dev->dev_private; | |
3204 | ||
3205 | DRM_DEBUG("idle timer fired, downclocking\n"); | |
3206 | ||
3207 | dev_priv->busy = false; | |
3208 | ||
01dfba93 | 3209 | queue_work(dev_priv->wq, &dev_priv->idle_work); |
652c393a JB |
3210 | } |
3211 | ||
3212 | void intel_increase_renderclock(struct drm_device *dev, bool schedule) | |
3213 | { | |
3214 | drm_i915_private_t *dev_priv = dev->dev_private; | |
3215 | ||
3216 | if (IS_IGDNG(dev)) | |
3217 | return; | |
3218 | ||
3219 | if (!dev_priv->render_reclock_avail) { | |
67cf781b | 3220 | DRM_DEBUG("not reclocking render clock\n"); |
652c393a JB |
3221 | return; |
3222 | } | |
3223 | ||
3224 | /* Restore render clock frequency to original value */ | |
3225 | if (IS_G4X(dev) || IS_I9XX(dev)) | |
3226 | pci_write_config_word(dev->pdev, GCFGC, dev_priv->orig_clock); | |
3227 | else if (IS_I85X(dev)) | |
3228 | pci_write_config_word(dev->pdev, HPLLCC, dev_priv->orig_clock); | |
3229 | DRM_DEBUG("increasing render clock frequency\n"); | |
3230 | ||
3231 | /* Schedule downclock */ | |
3232 | if (schedule) | |
3233 | mod_timer(&dev_priv->idle_timer, jiffies + | |
3234 | msecs_to_jiffies(GPU_IDLE_TIMEOUT)); | |
3235 | } | |
3236 | ||
3237 | void intel_decrease_renderclock(struct drm_device *dev) | |
3238 | { | |
3239 | drm_i915_private_t *dev_priv = dev->dev_private; | |
3240 | ||
3241 | if (IS_IGDNG(dev)) | |
3242 | return; | |
3243 | ||
3244 | if (!dev_priv->render_reclock_avail) { | |
67cf781b | 3245 | DRM_DEBUG("not reclocking render clock\n"); |
652c393a JB |
3246 | return; |
3247 | } | |
3248 | ||
3249 | if (IS_G4X(dev)) { | |
3250 | u16 gcfgc; | |
3251 | ||
3252 | /* Adjust render clock... */ | |
3253 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); | |
3254 | ||
3255 | /* Down to minimum... */ | |
3256 | gcfgc &= ~GM45_GC_RENDER_CLOCK_MASK; | |
3257 | gcfgc |= GM45_GC_RENDER_CLOCK_266_MHZ; | |
3258 | ||
3259 | pci_write_config_word(dev->pdev, GCFGC, gcfgc); | |
3260 | } else if (IS_I965G(dev)) { | |
3261 | u16 gcfgc; | |
3262 | ||
3263 | /* Adjust render clock... */ | |
3264 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); | |
3265 | ||
3266 | /* Down to minimum... */ | |
3267 | gcfgc &= ~I965_GC_RENDER_CLOCK_MASK; | |
3268 | gcfgc |= I965_GC_RENDER_CLOCK_267_MHZ; | |
3269 | ||
3270 | pci_write_config_word(dev->pdev, GCFGC, gcfgc); | |
3271 | } else if (IS_I945G(dev) || IS_I945GM(dev)) { | |
3272 | u16 gcfgc; | |
3273 | ||
3274 | /* Adjust render clock... */ | |
3275 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); | |
3276 | ||
3277 | /* Down to minimum... */ | |
3278 | gcfgc &= ~I945_GC_RENDER_CLOCK_MASK; | |
3279 | gcfgc |= I945_GC_RENDER_CLOCK_166_MHZ; | |
3280 | ||
3281 | pci_write_config_word(dev->pdev, GCFGC, gcfgc); | |
3282 | } else if (IS_I915G(dev)) { | |
3283 | u16 gcfgc; | |
3284 | ||
3285 | /* Adjust render clock... */ | |
3286 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); | |
3287 | ||
3288 | /* Down to minimum... */ | |
3289 | gcfgc &= ~I915_GC_RENDER_CLOCK_MASK; | |
3290 | gcfgc |= I915_GC_RENDER_CLOCK_166_MHZ; | |
3291 | ||
3292 | pci_write_config_word(dev->pdev, GCFGC, gcfgc); | |
3293 | } else if (IS_I85X(dev)) { | |
3294 | u16 hpllcc; | |
3295 | ||
3296 | /* Adjust render clock... */ | |
3297 | pci_read_config_word(dev->pdev, HPLLCC, &hpllcc); | |
3298 | ||
3299 | /* Up to maximum... */ | |
3300 | hpllcc &= ~GC_CLOCK_CONTROL_MASK; | |
3301 | hpllcc |= GC_CLOCK_133_200; | |
3302 | ||
3303 | pci_write_config_word(dev->pdev, HPLLCC, hpllcc); | |
3304 | } | |
3305 | DRM_DEBUG("decreasing render clock frequency\n"); | |
3306 | } | |
3307 | ||
3308 | /* Note that no increase function is needed for this - increase_renderclock() | |
3309 | * will also rewrite these bits | |
3310 | */ | |
3311 | void intel_decrease_displayclock(struct drm_device *dev) | |
3312 | { | |
3313 | if (IS_IGDNG(dev)) | |
3314 | return; | |
3315 | ||
3316 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_I915G(dev) || | |
3317 | IS_I915GM(dev)) { | |
3318 | u16 gcfgc; | |
3319 | ||
3320 | /* Adjust render clock... */ | |
3321 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); | |
3322 | ||
3323 | /* Down to minimum... */ | |
3324 | gcfgc &= ~0xf0; | |
3325 | gcfgc |= 0x80; | |
3326 | ||
3327 | pci_write_config_word(dev->pdev, GCFGC, gcfgc); | |
3328 | } | |
3329 | } | |
3330 | ||
3331 | #define CRTC_IDLE_TIMEOUT 1000 /* ms */ | |
3332 | ||
3333 | static void intel_crtc_idle_timer(unsigned long arg) | |
3334 | { | |
3335 | struct intel_crtc *intel_crtc = (struct intel_crtc *)arg; | |
3336 | struct drm_crtc *crtc = &intel_crtc->base; | |
3337 | drm_i915_private_t *dev_priv = crtc->dev->dev_private; | |
3338 | ||
3339 | DRM_DEBUG("idle timer fired, downclocking\n"); | |
3340 | ||
3341 | intel_crtc->busy = false; | |
3342 | ||
01dfba93 | 3343 | queue_work(dev_priv->wq, &dev_priv->idle_work); |
652c393a JB |
3344 | } |
3345 | ||
3346 | static void intel_increase_pllclock(struct drm_crtc *crtc, bool schedule) | |
3347 | { | |
3348 | struct drm_device *dev = crtc->dev; | |
3349 | drm_i915_private_t *dev_priv = dev->dev_private; | |
3350 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3351 | int pipe = intel_crtc->pipe; | |
3352 | int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B; | |
3353 | int dpll = I915_READ(dpll_reg); | |
3354 | ||
3355 | if (IS_IGDNG(dev)) | |
3356 | return; | |
3357 | ||
3358 | if (!dev_priv->lvds_downclock_avail) | |
3359 | return; | |
3360 | ||
3361 | if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) { | |
3362 | DRM_DEBUG("upclocking LVDS\n"); | |
3363 | ||
3364 | /* Unlock panel regs */ | |
3365 | I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) | (0xabcd << 16)); | |
3366 | ||
3367 | dpll &= ~DISPLAY_RATE_SELECT_FPA1; | |
3368 | I915_WRITE(dpll_reg, dpll); | |
3369 | dpll = I915_READ(dpll_reg); | |
3370 | intel_wait_for_vblank(dev); | |
3371 | dpll = I915_READ(dpll_reg); | |
3372 | if (dpll & DISPLAY_RATE_SELECT_FPA1) | |
3373 | DRM_DEBUG("failed to upclock LVDS!\n"); | |
3374 | ||
3375 | /* ...and lock them again */ | |
3376 | I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) & 0x3); | |
3377 | } | |
3378 | ||
3379 | /* Schedule downclock */ | |
3380 | if (schedule) | |
3381 | mod_timer(&intel_crtc->idle_timer, jiffies + | |
3382 | msecs_to_jiffies(CRTC_IDLE_TIMEOUT)); | |
3383 | } | |
3384 | ||
3385 | static void intel_decrease_pllclock(struct drm_crtc *crtc) | |
3386 | { | |
3387 | struct drm_device *dev = crtc->dev; | |
3388 | drm_i915_private_t *dev_priv = dev->dev_private; | |
3389 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3390 | int pipe = intel_crtc->pipe; | |
3391 | int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B; | |
3392 | int dpll = I915_READ(dpll_reg); | |
3393 | ||
3394 | if (IS_IGDNG(dev)) | |
3395 | return; | |
3396 | ||
3397 | if (!dev_priv->lvds_downclock_avail) | |
3398 | return; | |
3399 | ||
3400 | /* | |
3401 | * Since this is called by a timer, we should never get here in | |
3402 | * the manual case. | |
3403 | */ | |
3404 | if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) { | |
3405 | DRM_DEBUG("downclocking LVDS\n"); | |
3406 | ||
3407 | /* Unlock panel regs */ | |
3408 | I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) | (0xabcd << 16)); | |
3409 | ||
3410 | dpll |= DISPLAY_RATE_SELECT_FPA1; | |
3411 | I915_WRITE(dpll_reg, dpll); | |
3412 | dpll = I915_READ(dpll_reg); | |
3413 | intel_wait_for_vblank(dev); | |
3414 | dpll = I915_READ(dpll_reg); | |
3415 | if (!(dpll & DISPLAY_RATE_SELECT_FPA1)) | |
3416 | DRM_DEBUG("failed to downclock LVDS!\n"); | |
3417 | ||
3418 | /* ...and lock them again */ | |
3419 | I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) & 0x3); | |
3420 | } | |
3421 | ||
3422 | } | |
3423 | ||
3424 | /** | |
3425 | * intel_idle_update - adjust clocks for idleness | |
3426 | * @work: work struct | |
3427 | * | |
3428 | * Either the GPU or display (or both) went idle. Check the busy status | |
3429 | * here and adjust the CRTC and GPU clocks as necessary. | |
3430 | */ | |
3431 | static void intel_idle_update(struct work_struct *work) | |
3432 | { | |
3433 | drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, | |
3434 | idle_work); | |
3435 | struct drm_device *dev = dev_priv->dev; | |
3436 | struct drm_crtc *crtc; | |
3437 | struct intel_crtc *intel_crtc; | |
3438 | ||
3439 | if (!i915_powersave) | |
3440 | return; | |
3441 | ||
3442 | mutex_lock(&dev->struct_mutex); | |
3443 | ||
3444 | /* GPU isn't processing, downclock it. */ | |
3445 | if (!dev_priv->busy) { | |
3446 | intel_decrease_renderclock(dev); | |
3447 | intel_decrease_displayclock(dev); | |
3448 | } | |
3449 | ||
3450 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { | |
3451 | /* Skip inactive CRTCs */ | |
3452 | if (!crtc->fb) | |
3453 | continue; | |
3454 | ||
3455 | intel_crtc = to_intel_crtc(crtc); | |
3456 | if (!intel_crtc->busy) | |
3457 | intel_decrease_pllclock(crtc); | |
3458 | } | |
3459 | ||
3460 | mutex_unlock(&dev->struct_mutex); | |
3461 | } | |
3462 | ||
3463 | /** | |
3464 | * intel_mark_busy - mark the GPU and possibly the display busy | |
3465 | * @dev: drm device | |
3466 | * @obj: object we're operating on | |
3467 | * | |
3468 | * Callers can use this function to indicate that the GPU is busy processing | |
3469 | * commands. If @obj matches one of the CRTC objects (i.e. it's a scanout | |
3470 | * buffer), we'll also mark the display as busy, so we know to increase its | |
3471 | * clock frequency. | |
3472 | */ | |
3473 | void intel_mark_busy(struct drm_device *dev, struct drm_gem_object *obj) | |
3474 | { | |
3475 | drm_i915_private_t *dev_priv = dev->dev_private; | |
3476 | struct drm_crtc *crtc = NULL; | |
3477 | struct intel_framebuffer *intel_fb; | |
3478 | struct intel_crtc *intel_crtc; | |
3479 | ||
5e17ee74 ZW |
3480 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
3481 | return; | |
3482 | ||
652c393a JB |
3483 | dev_priv->busy = true; |
3484 | intel_increase_renderclock(dev, true); | |
3485 | ||
3486 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { | |
3487 | if (!crtc->fb) | |
3488 | continue; | |
3489 | ||
3490 | intel_crtc = to_intel_crtc(crtc); | |
3491 | intel_fb = to_intel_framebuffer(crtc->fb); | |
3492 | if (intel_fb->obj == obj) { | |
3493 | if (!intel_crtc->busy) { | |
3494 | /* Non-busy -> busy, upclock */ | |
3495 | intel_increase_pllclock(crtc, true); | |
3496 | intel_crtc->busy = true; | |
3497 | } else { | |
3498 | /* Busy -> busy, put off timer */ | |
3499 | mod_timer(&intel_crtc->idle_timer, jiffies + | |
3500 | msecs_to_jiffies(CRTC_IDLE_TIMEOUT)); | |
3501 | } | |
3502 | } | |
3503 | } | |
3504 | } | |
3505 | ||
79e53945 JB |
3506 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
3507 | { | |
3508 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3509 | ||
3510 | drm_crtc_cleanup(crtc); | |
3511 | kfree(intel_crtc); | |
3512 | } | |
3513 | ||
3514 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { | |
3515 | .dpms = intel_crtc_dpms, | |
3516 | .mode_fixup = intel_crtc_mode_fixup, | |
3517 | .mode_set = intel_crtc_mode_set, | |
3518 | .mode_set_base = intel_pipe_set_base, | |
3519 | .prepare = intel_crtc_prepare, | |
3520 | .commit = intel_crtc_commit, | |
3521 | }; | |
3522 | ||
3523 | static const struct drm_crtc_funcs intel_crtc_funcs = { | |
3524 | .cursor_set = intel_crtc_cursor_set, | |
3525 | .cursor_move = intel_crtc_cursor_move, | |
3526 | .gamma_set = intel_crtc_gamma_set, | |
3527 | .set_config = drm_crtc_helper_set_config, | |
3528 | .destroy = intel_crtc_destroy, | |
3529 | }; | |
3530 | ||
3531 | ||
b358d0a6 | 3532 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
79e53945 JB |
3533 | { |
3534 | struct intel_crtc *intel_crtc; | |
3535 | int i; | |
3536 | ||
3537 | intel_crtc = kzalloc(sizeof(struct intel_crtc) + (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL); | |
3538 | if (intel_crtc == NULL) | |
3539 | return; | |
3540 | ||
3541 | drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs); | |
3542 | ||
3543 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); | |
3544 | intel_crtc->pipe = pipe; | |
7662c8bd | 3545 | intel_crtc->plane = pipe; |
79e53945 JB |
3546 | for (i = 0; i < 256; i++) { |
3547 | intel_crtc->lut_r[i] = i; | |
3548 | intel_crtc->lut_g[i] = i; | |
3549 | intel_crtc->lut_b[i] = i; | |
3550 | } | |
3551 | ||
3552 | intel_crtc->cursor_addr = 0; | |
3553 | intel_crtc->dpms_mode = DRM_MODE_DPMS_OFF; | |
3554 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); | |
3555 | ||
652c393a JB |
3556 | intel_crtc->busy = false; |
3557 | ||
3558 | setup_timer(&intel_crtc->idle_timer, intel_crtc_idle_timer, | |
3559 | (unsigned long)intel_crtc); | |
79e53945 JB |
3560 | } |
3561 | ||
08d7b3d1 CW |
3562 | int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data, |
3563 | struct drm_file *file_priv) | |
3564 | { | |
3565 | drm_i915_private_t *dev_priv = dev->dev_private; | |
3566 | struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data; | |
c05422d5 DV |
3567 | struct drm_mode_object *drmmode_obj; |
3568 | struct intel_crtc *crtc; | |
08d7b3d1 CW |
3569 | |
3570 | if (!dev_priv) { | |
3571 | DRM_ERROR("called with no initialization\n"); | |
3572 | return -EINVAL; | |
3573 | } | |
3574 | ||
c05422d5 DV |
3575 | drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id, |
3576 | DRM_MODE_OBJECT_CRTC); | |
08d7b3d1 | 3577 | |
c05422d5 | 3578 | if (!drmmode_obj) { |
08d7b3d1 CW |
3579 | DRM_ERROR("no such CRTC id\n"); |
3580 | return -EINVAL; | |
3581 | } | |
3582 | ||
c05422d5 DV |
3583 | crtc = to_intel_crtc(obj_to_crtc(drmmode_obj)); |
3584 | pipe_from_crtc_id->pipe = crtc->pipe; | |
08d7b3d1 | 3585 | |
c05422d5 | 3586 | return 0; |
08d7b3d1 CW |
3587 | } |
3588 | ||
79e53945 JB |
3589 | struct drm_crtc *intel_get_crtc_from_pipe(struct drm_device *dev, int pipe) |
3590 | { | |
3591 | struct drm_crtc *crtc = NULL; | |
3592 | ||
3593 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { | |
3594 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3595 | if (intel_crtc->pipe == pipe) | |
3596 | break; | |
3597 | } | |
3598 | return crtc; | |
3599 | } | |
3600 | ||
b358d0a6 | 3601 | static int intel_connector_clones(struct drm_device *dev, int type_mask) |
79e53945 JB |
3602 | { |
3603 | int index_mask = 0; | |
3604 | struct drm_connector *connector; | |
3605 | int entry = 0; | |
3606 | ||
3607 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { | |
3608 | struct intel_output *intel_output = to_intel_output(connector); | |
f8aed700 | 3609 | if (type_mask & intel_output->clone_mask) |
79e53945 JB |
3610 | index_mask |= (1 << entry); |
3611 | entry++; | |
3612 | } | |
3613 | return index_mask; | |
3614 | } | |
3615 | ||
3616 | ||
3617 | static void intel_setup_outputs(struct drm_device *dev) | |
3618 | { | |
725e30ad | 3619 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 JB |
3620 | struct drm_connector *connector; |
3621 | ||
3622 | intel_crt_init(dev); | |
3623 | ||
3624 | /* Set up integrated LVDS */ | |
541998a1 | 3625 | if (IS_MOBILE(dev) && !IS_I830(dev)) |
79e53945 JB |
3626 | intel_lvds_init(dev); |
3627 | ||
2c07245f | 3628 | if (IS_IGDNG(dev)) { |
30ad48b7 ZW |
3629 | int found; |
3630 | ||
32f9d658 ZW |
3631 | if (IS_MOBILE(dev) && (I915_READ(DP_A) & DP_DETECTED)) |
3632 | intel_dp_init(dev, DP_A); | |
3633 | ||
30ad48b7 ZW |
3634 | if (I915_READ(HDMIB) & PORT_DETECTED) { |
3635 | /* check SDVOB */ | |
3636 | /* found = intel_sdvo_init(dev, HDMIB); */ | |
3637 | found = 0; | |
3638 | if (!found) | |
3639 | intel_hdmi_init(dev, HDMIB); | |
5eb08b69 ZW |
3640 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
3641 | intel_dp_init(dev, PCH_DP_B); | |
30ad48b7 ZW |
3642 | } |
3643 | ||
3644 | if (I915_READ(HDMIC) & PORT_DETECTED) | |
3645 | intel_hdmi_init(dev, HDMIC); | |
3646 | ||
3647 | if (I915_READ(HDMID) & PORT_DETECTED) | |
3648 | intel_hdmi_init(dev, HDMID); | |
3649 | ||
5eb08b69 ZW |
3650 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
3651 | intel_dp_init(dev, PCH_DP_C); | |
3652 | ||
3653 | if (I915_READ(PCH_DP_D) & DP_DETECTED) | |
3654 | intel_dp_init(dev, PCH_DP_D); | |
3655 | ||
2c07245f | 3656 | } else if (IS_I9XX(dev)) { |
27185ae1 | 3657 | bool found = false; |
7d57382e | 3658 | |
725e30ad EA |
3659 | if (I915_READ(SDVOB) & SDVO_DETECTED) { |
3660 | found = intel_sdvo_init(dev, SDVOB); | |
3661 | if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) | |
3662 | intel_hdmi_init(dev, SDVOB); | |
27185ae1 | 3663 | |
a4fc5ed6 KP |
3664 | if (!found && SUPPORTS_INTEGRATED_DP(dev)) |
3665 | intel_dp_init(dev, DP_B); | |
725e30ad | 3666 | } |
13520b05 KH |
3667 | |
3668 | /* Before G4X SDVOC doesn't have its own detect register */ | |
13520b05 | 3669 | |
27185ae1 | 3670 | if (I915_READ(SDVOB) & SDVO_DETECTED) |
725e30ad | 3671 | found = intel_sdvo_init(dev, SDVOC); |
27185ae1 ML |
3672 | |
3673 | if (!found && (I915_READ(SDVOC) & SDVO_DETECTED)) { | |
3674 | ||
3675 | if (SUPPORTS_INTEGRATED_HDMI(dev)) | |
725e30ad | 3676 | intel_hdmi_init(dev, SDVOC); |
27185ae1 | 3677 | if (SUPPORTS_INTEGRATED_DP(dev)) |
a4fc5ed6 | 3678 | intel_dp_init(dev, DP_C); |
725e30ad | 3679 | } |
27185ae1 | 3680 | |
a4fc5ed6 KP |
3681 | if (SUPPORTS_INTEGRATED_DP(dev) && (I915_READ(DP_D) & DP_DETECTED)) |
3682 | intel_dp_init(dev, DP_D); | |
79e53945 JB |
3683 | } else |
3684 | intel_dvo_init(dev); | |
3685 | ||
2c07245f | 3686 | if (IS_I9XX(dev) && IS_MOBILE(dev) && !IS_IGDNG(dev)) |
79e53945 JB |
3687 | intel_tv_init(dev); |
3688 | ||
3689 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { | |
3690 | struct intel_output *intel_output = to_intel_output(connector); | |
3691 | struct drm_encoder *encoder = &intel_output->enc; | |
79e53945 | 3692 | |
f8aed700 ML |
3693 | encoder->possible_crtcs = intel_output->crtc_mask; |
3694 | encoder->possible_clones = intel_connector_clones(dev, | |
3695 | intel_output->clone_mask); | |
79e53945 JB |
3696 | } |
3697 | } | |
3698 | ||
3699 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) | |
3700 | { | |
3701 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
3702 | struct drm_device *dev = fb->dev; | |
3703 | ||
3704 | if (fb->fbdev) | |
3705 | intelfb_remove(dev, fb); | |
3706 | ||
3707 | drm_framebuffer_cleanup(fb); | |
3708 | mutex_lock(&dev->struct_mutex); | |
3709 | drm_gem_object_unreference(intel_fb->obj); | |
3710 | mutex_unlock(&dev->struct_mutex); | |
3711 | ||
3712 | kfree(intel_fb); | |
3713 | } | |
3714 | ||
3715 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, | |
3716 | struct drm_file *file_priv, | |
3717 | unsigned int *handle) | |
3718 | { | |
3719 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
3720 | struct drm_gem_object *object = intel_fb->obj; | |
3721 | ||
3722 | return drm_gem_handle_create(file_priv, object, handle); | |
3723 | } | |
3724 | ||
3725 | static const struct drm_framebuffer_funcs intel_fb_funcs = { | |
3726 | .destroy = intel_user_framebuffer_destroy, | |
3727 | .create_handle = intel_user_framebuffer_create_handle, | |
3728 | }; | |
3729 | ||
3730 | int intel_framebuffer_create(struct drm_device *dev, | |
3731 | struct drm_mode_fb_cmd *mode_cmd, | |
3732 | struct drm_framebuffer **fb, | |
3733 | struct drm_gem_object *obj) | |
3734 | { | |
3735 | struct intel_framebuffer *intel_fb; | |
3736 | int ret; | |
3737 | ||
3738 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); | |
3739 | if (!intel_fb) | |
3740 | return -ENOMEM; | |
3741 | ||
3742 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); | |
3743 | if (ret) { | |
3744 | DRM_ERROR("framebuffer init failed %d\n", ret); | |
3745 | return ret; | |
3746 | } | |
3747 | ||
3748 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); | |
3749 | ||
3750 | intel_fb->obj = obj; | |
3751 | ||
3752 | *fb = &intel_fb->base; | |
3753 | ||
3754 | return 0; | |
3755 | } | |
3756 | ||
3757 | ||
3758 | static struct drm_framebuffer * | |
3759 | intel_user_framebuffer_create(struct drm_device *dev, | |
3760 | struct drm_file *filp, | |
3761 | struct drm_mode_fb_cmd *mode_cmd) | |
3762 | { | |
3763 | struct drm_gem_object *obj; | |
3764 | struct drm_framebuffer *fb; | |
3765 | int ret; | |
3766 | ||
3767 | obj = drm_gem_object_lookup(dev, filp, mode_cmd->handle); | |
3768 | if (!obj) | |
3769 | return NULL; | |
3770 | ||
3771 | ret = intel_framebuffer_create(dev, mode_cmd, &fb, obj); | |
3772 | if (ret) { | |
496818f0 | 3773 | mutex_lock(&dev->struct_mutex); |
79e53945 | 3774 | drm_gem_object_unreference(obj); |
496818f0 | 3775 | mutex_unlock(&dev->struct_mutex); |
79e53945 JB |
3776 | return NULL; |
3777 | } | |
3778 | ||
3779 | return fb; | |
3780 | } | |
3781 | ||
79e53945 | 3782 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
79e53945 JB |
3783 | .fb_create = intel_user_framebuffer_create, |
3784 | .fb_changed = intelfb_probe, | |
3785 | }; | |
3786 | ||
652c393a JB |
3787 | void intel_init_clock_gating(struct drm_device *dev) |
3788 | { | |
3789 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3790 | ||
3791 | /* | |
3792 | * Disable clock gating reported to work incorrectly according to the | |
3793 | * specs, but enable as much else as we can. | |
3794 | */ | |
3795 | if (IS_G4X(dev)) { | |
3796 | uint32_t dspclk_gate; | |
3797 | I915_WRITE(RENCLK_GATE_D1, 0); | |
3798 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | | |
3799 | GS_UNIT_CLOCK_GATE_DISABLE | | |
3800 | CL_UNIT_CLOCK_GATE_DISABLE); | |
3801 | I915_WRITE(RAMCLK_GATE_D, 0); | |
3802 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | | |
3803 | OVRUNIT_CLOCK_GATE_DISABLE | | |
3804 | OVCUNIT_CLOCK_GATE_DISABLE; | |
3805 | if (IS_GM45(dev)) | |
3806 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; | |
3807 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); | |
3808 | } else if (IS_I965GM(dev)) { | |
3809 | I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); | |
3810 | I915_WRITE(RENCLK_GATE_D2, 0); | |
3811 | I915_WRITE(DSPCLK_GATE_D, 0); | |
3812 | I915_WRITE(RAMCLK_GATE_D, 0); | |
3813 | I915_WRITE16(DEUC, 0); | |
3814 | } else if (IS_I965G(dev)) { | |
3815 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | | |
3816 | I965_RCC_CLOCK_GATE_DISABLE | | |
3817 | I965_RCPB_CLOCK_GATE_DISABLE | | |
3818 | I965_ISC_CLOCK_GATE_DISABLE | | |
3819 | I965_FBC_CLOCK_GATE_DISABLE); | |
3820 | I915_WRITE(RENCLK_GATE_D2, 0); | |
3821 | } else if (IS_I9XX(dev)) { | |
3822 | u32 dstate = I915_READ(D_STATE); | |
3823 | ||
3824 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | | |
3825 | DSTATE_DOT_CLOCK_GATING; | |
3826 | I915_WRITE(D_STATE, dstate); | |
3827 | } else if (IS_I855(dev) || IS_I865G(dev)) { | |
3828 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); | |
3829 | } else if (IS_I830(dev)) { | |
3830 | I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE); | |
3831 | } | |
3832 | } | |
3833 | ||
79e53945 JB |
3834 | void intel_modeset_init(struct drm_device *dev) |
3835 | { | |
652c393a | 3836 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 JB |
3837 | int num_pipe; |
3838 | int i; | |
3839 | ||
3840 | drm_mode_config_init(dev); | |
3841 | ||
3842 | dev->mode_config.min_width = 0; | |
3843 | dev->mode_config.min_height = 0; | |
3844 | ||
3845 | dev->mode_config.funcs = (void *)&intel_mode_funcs; | |
3846 | ||
3847 | if (IS_I965G(dev)) { | |
3848 | dev->mode_config.max_width = 8192; | |
3849 | dev->mode_config.max_height = 8192; | |
5e4d6fa7 KP |
3850 | } else if (IS_I9XX(dev)) { |
3851 | dev->mode_config.max_width = 4096; | |
3852 | dev->mode_config.max_height = 4096; | |
79e53945 JB |
3853 | } else { |
3854 | dev->mode_config.max_width = 2048; | |
3855 | dev->mode_config.max_height = 2048; | |
3856 | } | |
3857 | ||
3858 | /* set memory base */ | |
3859 | if (IS_I9XX(dev)) | |
3860 | dev->mode_config.fb_base = pci_resource_start(dev->pdev, 2); | |
3861 | else | |
3862 | dev->mode_config.fb_base = pci_resource_start(dev->pdev, 0); | |
3863 | ||
3864 | if (IS_MOBILE(dev) || IS_I9XX(dev)) | |
3865 | num_pipe = 2; | |
3866 | else | |
3867 | num_pipe = 1; | |
3868 | DRM_DEBUG("%d display pipe%s available.\n", | |
3869 | num_pipe, num_pipe > 1 ? "s" : ""); | |
3870 | ||
652c393a JB |
3871 | if (IS_I85X(dev)) |
3872 | pci_read_config_word(dev->pdev, HPLLCC, &dev_priv->orig_clock); | |
3873 | else if (IS_I9XX(dev) || IS_G4X(dev)) | |
3874 | pci_read_config_word(dev->pdev, GCFGC, &dev_priv->orig_clock); | |
3875 | ||
79e53945 JB |
3876 | for (i = 0; i < num_pipe; i++) { |
3877 | intel_crtc_init(dev, i); | |
3878 | } | |
3879 | ||
3880 | intel_setup_outputs(dev); | |
652c393a JB |
3881 | |
3882 | intel_init_clock_gating(dev); | |
3883 | ||
3884 | INIT_WORK(&dev_priv->idle_work, intel_idle_update); | |
3885 | setup_timer(&dev_priv->idle_timer, intel_gpu_idle_timer, | |
3886 | (unsigned long)dev); | |
79e53945 JB |
3887 | } |
3888 | ||
3889 | void intel_modeset_cleanup(struct drm_device *dev) | |
3890 | { | |
652c393a JB |
3891 | struct drm_i915_private *dev_priv = dev->dev_private; |
3892 | struct drm_crtc *crtc; | |
3893 | struct intel_crtc *intel_crtc; | |
3894 | ||
3895 | mutex_lock(&dev->struct_mutex); | |
3896 | ||
3897 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { | |
3898 | /* Skip inactive CRTCs */ | |
3899 | if (!crtc->fb) | |
3900 | continue; | |
3901 | ||
3902 | intel_crtc = to_intel_crtc(crtc); | |
3903 | intel_increase_pllclock(crtc, false); | |
3904 | del_timer_sync(&intel_crtc->idle_timer); | |
3905 | } | |
3906 | ||
3907 | intel_increase_renderclock(dev, false); | |
3908 | del_timer_sync(&dev_priv->idle_timer); | |
3909 | ||
3910 | mutex_unlock(&dev->struct_mutex); | |
3911 | ||
79e53945 JB |
3912 | drm_mode_config_cleanup(dev); |
3913 | } | |
3914 | ||
3915 | ||
3916 | /* current intel driver doesn't take advantage of encoders | |
3917 | always give back the encoder for the connector | |
3918 | */ | |
3919 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) | |
3920 | { | |
3921 | struct intel_output *intel_output = to_intel_output(connector); | |
3922 | ||
3923 | return &intel_output->enc; | |
3924 | } |