Rev 472 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
472 | giacomo | 1 | /* |
2 | * drivers/video/radeonfb.c |
||
3 | * framebuffer driver for ATI Radeon chipset video boards |
||
4 | * |
||
5 | * Copyright 2000 Ani Joshi <ajoshi@kernel.crashing.org> |
||
6 | * |
||
7 | * |
||
8 | * ChangeLog: |
||
9 | * 2000-08-03 initial version 0.0.1 |
||
10 | * 2000-09-10 more bug fixes, public release 0.0.5 |
||
11 | * 2001-02-19 mode bug fixes, 0.0.7 |
||
12 | * 2001-07-05 fixed scrolling issues, engine initialization, |
||
13 | * and minor mode tweaking, 0.0.9 |
||
14 | * 2001-09-07 Radeon VE support, Nick Kurshev |
||
15 | * blanking, pan_display, and cmap fixes, 0.1.0 |
||
16 | * 2001-10-10 Radeon 7500 and 8500 support, and experimental |
||
17 | * flat panel support, 0.1.1 |
||
18 | * 2001-11-17 Radeon M6 (ppc) support, Daniel Berlin, 0.1.2 |
||
19 | * 2001-11-18 DFP fixes, Kevin Hendricks, 0.1.3 |
||
20 | * 2001-11-29 more cmap, backlight fixes, Benjamin Herrenschmidt |
||
21 | * 2002-01-18 DFP panel detection via BIOS, Michael Clark, 0.1.4 |
||
22 | * 2002-06-02 console switching, mode set fixes, accel fixes |
||
23 | * 2002-06-03 MTRR support, Peter Horton, 0.1.5 |
||
24 | * 2002-09-21 rv250, r300, m9 initial support, |
||
25 | * added mirror option, 0.1.6 |
||
26 | * |
||
27 | * Special thanks to ATI DevRel team for their hardware donations. |
||
28 | * |
||
29 | */ |
||
30 | |||
31 | |||
32 | #define RADEON_VERSION "0.1.6" |
||
33 | |||
34 | #include <linuxcomp.h> |
||
35 | |||
36 | #include <linux/config.h> |
||
37 | #include <linux/module.h> |
||
38 | #include <linux/kernel.h> |
||
39 | #include <linux/errno.h> |
||
40 | #include <linux/string.h> |
||
41 | #include <linux/mm.h> |
||
42 | #include <linux/tty.h> |
||
43 | #include <linux/slab.h> |
||
44 | #include <linux/delay.h> |
||
45 | #include <linux/fb.h> |
||
46 | #include <linux/ioport.h> |
||
47 | #include <linux/init.h> |
||
48 | #include <linux/pci.h> |
||
49 | #include <linux/vmalloc.h> |
||
50 | |||
51 | #include <asm/io.h> |
||
52 | #include <asm/uaccess.h> |
||
53 | #if defined(__powerpc__) |
||
54 | #include <asm/prom.h> |
||
55 | #include <asm/pci-bridge.h> |
||
56 | #include "macmodes.h" |
||
57 | |||
58 | #ifdef CONFIG_NVRAM |
||
59 | #include <linux/nvram.h> |
||
60 | #endif |
||
61 | |||
62 | #ifdef CONFIG_PMAC_BACKLIGHT |
||
63 | #include <asm/backlight.h> |
||
64 | #endif |
||
65 | |||
66 | #ifdef CONFIG_BOOTX_TEXT |
||
67 | #include <asm/btext.h> |
||
68 | #endif |
||
69 | |||
70 | #ifdef CONFIG_ADB_PMU |
||
71 | #include <linux/adb.h> |
||
72 | #include <linux/pmu.h> |
||
73 | #endif |
||
74 | |||
75 | #endif /* __powerpc__ */ |
||
76 | |||
77 | #ifdef CONFIG_MTRR |
||
78 | #include <asm/mtrr.h> |
||
79 | #endif |
||
80 | |||
81 | #include <video/radeon.h> |
||
82 | #include <linux/radeonfb.h> |
||
83 | |||
84 | #define DEBUG 1 |
||
85 | |||
86 | #if DEBUG |
||
87 | #define RTRACE printk |
||
88 | #else |
||
89 | #define RTRACE if(0) printk |
||
90 | #endif |
||
91 | |||
92 | // XXX |
||
93 | #undef CONFIG_PMAC_PBOOK |
||
94 | |||
95 | |||
96 | enum radeon_chips { |
||
97 | RADEON_QD, |
||
98 | RADEON_QE, |
||
99 | RADEON_QF, |
||
100 | RADEON_QG, |
||
101 | RADEON_QY, |
||
102 | RADEON_QZ, |
||
103 | RADEON_LW, |
||
104 | RADEON_LX, |
||
105 | RADEON_LY, |
||
106 | RADEON_LZ, |
||
107 | RADEON_QL, |
||
108 | RADEON_QN, |
||
109 | RADEON_QO, |
||
110 | RADEON_Ql, |
||
111 | RADEON_BB, |
||
112 | RADEON_QW, |
||
113 | RADEON_QX, |
||
114 | RADEON_Id, |
||
115 | RADEON_Ie, |
||
116 | RADEON_If, |
||
117 | RADEON_Ig, |
||
118 | RADEON_Ld, |
||
119 | RADEON_Le, |
||
120 | RADEON_Lf, |
||
121 | RADEON_Lg, |
||
122 | RADEON_ND, |
||
123 | RADEON_NE, |
||
124 | RADEON_NF, |
||
125 | RADEON_NG, |
||
126 | RADEON_QM |
||
127 | }; |
||
128 | |||
129 | enum radeon_arch { |
||
130 | RADEON_R100, |
||
131 | RADEON_RV100, |
||
132 | RADEON_R200, |
||
133 | RADEON_RV200, |
||
134 | RADEON_RV250, |
||
135 | RADEON_R300, |
||
136 | RADEON_M6, |
||
137 | RADEON_M7, |
||
138 | RADEON_M9 |
||
139 | }; |
||
140 | |||
141 | static struct radeon_chip_info { |
||
142 | const char *name; |
||
143 | unsigned char arch; |
||
144 | } radeon_chip_info[] __devinitdata = { |
||
145 | { "QD", RADEON_R100 }, |
||
146 | { "QE", RADEON_R100 }, |
||
147 | { "QF", RADEON_R100 }, |
||
148 | { "QG", RADEON_R100 }, |
||
149 | { "VE QY", RADEON_RV100 }, |
||
150 | { "VE QZ", RADEON_RV100 }, |
||
151 | { "M7 LW", RADEON_M7 }, |
||
152 | { "M7 LX", RADEON_M7 }, |
||
153 | { "M6 LY", RADEON_M6 }, |
||
154 | { "M6 LZ", RADEON_M6 }, |
||
155 | { "8500 QL", RADEON_R200 }, |
||
156 | { "8500 QN", RADEON_R200 }, |
||
157 | { "8500 QO", RADEON_R200 }, |
||
158 | { "8500 Ql", RADEON_R200 }, |
||
159 | { "8500 BB", RADEON_R200 }, |
||
160 | { "7500 QW", RADEON_RV200 }, |
||
161 | { "7500 QX", RADEON_RV200 }, |
||
162 | { "9000 Id", RADEON_RV250 }, |
||
163 | { "9000 Ie", RADEON_RV250 }, |
||
164 | { "9000 If", RADEON_RV250 }, |
||
165 | { "9000 Ig", RADEON_RV250 }, |
||
166 | { "M9 Ld", RADEON_M9 }, |
||
167 | { "M9 Le", RADEON_M9 }, |
||
168 | { "M9 Lf", RADEON_M9 }, |
||
169 | { "M9 Lg", RADEON_M9 }, |
||
170 | { "9700 ND", RADEON_R300 }, |
||
171 | { "9700 NE", RADEON_R300 }, |
||
172 | { "9700 NF", RADEON_R300 }, |
||
173 | { "9700 NG", RADEON_R300 }, |
||
174 | { "9100 QM", RADEON_R200 } |
||
175 | }; |
||
176 | |||
177 | |||
178 | enum radeon_montype |
||
179 | { |
||
180 | MT_NONE, |
||
181 | MT_CRT, /* CRT */ |
||
182 | MT_LCD, /* LCD */ |
||
183 | MT_DFP, /* DVI */ |
||
184 | MT_CTV, /* composite TV */ |
||
185 | MT_STV /* S-Video out */ |
||
186 | }; |
||
187 | |||
188 | |||
189 | static struct pci_device_id radeonfb_pci_table[] = { |
||
190 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QD}, |
||
191 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QE}, |
||
192 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QF}, |
||
193 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QG, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QG}, |
||
194 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QY, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QY}, |
||
195 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QZ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QZ}, |
||
196 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_LW, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_LW}, |
||
197 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_LX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_LX}, |
||
198 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_LY, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_LY}, |
||
199 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_LZ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_LZ}, |
||
200 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QL, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QL}, |
||
201 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QN, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QN}, |
||
202 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QO}, |
||
203 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Ql, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Ql}, |
||
204 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_BB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_BB}, |
||
205 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QW, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QW}, |
||
206 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QX}, |
||
207 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Id, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Id}, |
||
208 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Ie, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Ie}, |
||
209 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_If, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_If}, |
||
210 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Ig, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Ig}, |
||
211 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Ld, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Ld}, |
||
212 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Le, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Le}, |
||
213 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Lf, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Lf}, |
||
214 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Lg, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Lg}, |
||
215 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_ND, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_ND}, |
||
216 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_NE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_NE}, |
||
217 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_NF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_NF}, |
||
218 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_NG, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_NG}, |
||
219 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QM}, |
||
220 | { 0, } |
||
221 | }; |
||
222 | MODULE_DEVICE_TABLE(pci, radeonfb_pci_table); |
||
223 | |||
224 | |||
225 | typedef struct { |
||
226 | u16 reg; |
||
227 | u32 val; |
||
228 | } reg_val; |
||
229 | |||
230 | |||
231 | /* these common regs are cleared before mode setting so they do not |
||
232 | * interfere with anything |
||
233 | */ |
||
234 | reg_val common_regs[] = { |
||
235 | { OVR_CLR, 0 }, |
||
236 | { OVR_WID_LEFT_RIGHT, 0 }, |
||
237 | { OVR_WID_TOP_BOTTOM, 0 }, |
||
238 | { OV0_SCALE_CNTL, 0 }, |
||
239 | { SUBPIC_CNTL, 0 }, |
||
240 | { VIPH_CONTROL, 0 }, |
||
241 | { I2C_CNTL_1, 0 }, |
||
242 | { GEN_INT_CNTL, 0 }, |
||
243 | { CAP0_TRIG_CNTL, 0 }, |
||
244 | }; |
||
245 | |||
246 | reg_val common_regs_m6[] = { |
||
247 | { OVR_CLR, 0 }, |
||
248 | { OVR_WID_LEFT_RIGHT, 0 }, |
||
249 | { OVR_WID_TOP_BOTTOM, 0 }, |
||
250 | { OV0_SCALE_CNTL, 0 }, |
||
251 | { SUBPIC_CNTL, 0 }, |
||
252 | { GEN_INT_CNTL, 0 }, |
||
253 | { CAP0_TRIG_CNTL, 0 } |
||
254 | }; |
||
255 | |||
256 | typedef struct { |
||
257 | u8 clock_chip_type; |
||
258 | u8 struct_size; |
||
259 | u8 accelerator_entry; |
||
260 | u8 VGA_entry; |
||
261 | u16 VGA_table_offset; |
||
262 | u16 POST_table_offset; |
||
263 | u16 XCLK; |
||
264 | u16 MCLK; |
||
265 | u8 num_PLL_blocks; |
||
266 | u8 size_PLL_blocks; |
||
267 | u16 PCLK_ref_freq; |
||
268 | u16 PCLK_ref_divider; |
||
269 | u32 PCLK_min_freq; |
||
270 | u32 PCLK_max_freq; |
||
271 | u16 MCLK_ref_freq; |
||
272 | u16 MCLK_ref_divider; |
||
273 | u32 MCLK_min_freq; |
||
274 | u32 MCLK_max_freq; |
||
275 | u16 XCLK_ref_freq; |
||
276 | u16 XCLK_ref_divider; |
||
277 | u32 XCLK_min_freq; |
||
278 | u32 XCLK_max_freq; |
||
279 | } __attribute__ ((packed)) PLL_BLOCK; |
||
280 | |||
281 | |||
282 | struct pll_info { |
||
283 | int ppll_max; |
||
284 | int ppll_min; |
||
285 | int xclk; |
||
286 | int ref_div; |
||
287 | int ref_clk; |
||
288 | }; |
||
289 | |||
290 | |||
291 | struct ram_info { |
||
292 | int ml; |
||
293 | int mb; |
||
294 | int trcd; |
||
295 | int trp; |
||
296 | int twr; |
||
297 | int cl; |
||
298 | int tr2w; |
||
299 | int loop_latency; |
||
300 | int rloop; |
||
301 | }; |
||
302 | |||
303 | |||
304 | struct radeon_regs { |
||
305 | /* CRTC regs */ |
||
306 | u32 crtc_h_total_disp; |
||
307 | u32 crtc_h_sync_strt_wid; |
||
308 | u32 crtc_v_total_disp; |
||
309 | u32 crtc_v_sync_strt_wid; |
||
310 | u32 crtc_pitch; |
||
311 | u32 crtc_gen_cntl; |
||
312 | u32 crtc_ext_cntl; |
||
313 | u32 dac_cntl; |
||
314 | |||
315 | u32 flags; |
||
316 | u32 pix_clock; |
||
317 | int xres, yres; |
||
318 | |||
319 | /* DDA regs */ |
||
320 | u32 dda_config; |
||
321 | u32 dda_on_off; |
||
322 | |||
323 | /* PLL regs */ |
||
324 | u32 ppll_div_3; |
||
325 | u32 ppll_ref_div; |
||
326 | u32 vclk_ecp_cntl; |
||
327 | |||
328 | /* Flat panel regs */ |
||
329 | u32 fp_crtc_h_total_disp; |
||
330 | u32 fp_crtc_v_total_disp; |
||
331 | u32 fp_gen_cntl; |
||
332 | u32 fp_h_sync_strt_wid; |
||
333 | u32 fp_horz_stretch; |
||
334 | u32 fp_panel_cntl; |
||
335 | u32 fp_v_sync_strt_wid; |
||
336 | u32 fp_vert_stretch; |
||
337 | u32 lvds_gen_cntl; |
||
338 | u32 lvds_pll_cntl; |
||
339 | u32 tmds_crc; |
||
340 | u32 tmds_transmitter_cntl; |
||
341 | |||
342 | #if defined(__BIG_ENDIAN) |
||
343 | u32 surface_cntl; |
||
344 | #endif |
||
345 | }; |
||
346 | |||
347 | |||
348 | struct radeonfb_info { |
||
349 | struct fb_info info; |
||
350 | |||
351 | struct radeon_regs state; |
||
352 | struct radeon_regs init_state; |
||
353 | |||
354 | char name[32]; |
||
355 | char ram_type[12]; |
||
356 | |||
357 | unsigned long mmio_base_phys; |
||
358 | unsigned long fb_base_phys; |
||
359 | |||
360 | unsigned long mmio_base; |
||
361 | unsigned long fb_base; |
||
362 | |||
363 | struct pci_dev *pdev; |
||
364 | |||
365 | unsigned char *EDID; |
||
366 | unsigned char *bios_seg; |
||
367 | |||
368 | u32 pseudo_palette[17]; |
||
369 | struct { u8 red, green, blue, pad; } palette[256]; |
||
370 | |||
371 | int chipset; |
||
372 | unsigned char arch; |
||
373 | int video_ram; |
||
374 | u8 rev; |
||
375 | int pitch, bpp, depth; |
||
376 | int xres, yres, pixclock; |
||
377 | int xres_virtual, yres_virtual; |
||
378 | u32 accel_flags; |
||
379 | |||
380 | int use_default_var; |
||
381 | int got_dfpinfo; |
||
382 | |||
383 | int hasCRTC2; |
||
384 | int crtDisp_type; |
||
385 | int dviDisp_type; |
||
386 | |||
387 | int panel_xres, panel_yres; |
||
388 | int clock; |
||
389 | int hOver_plus, hSync_width, hblank; |
||
390 | int vOver_plus, vSync_width, vblank; |
||
391 | int hAct_high, vAct_high, interlaced; |
||
392 | int synct, misc; |
||
393 | |||
394 | u32 dp_gui_master_cntl; |
||
395 | |||
396 | struct pll_info pll; |
||
397 | int pll_output_freq, post_div, fb_div; |
||
398 | |||
399 | struct ram_info ram; |
||
400 | |||
401 | int mtrr_hdl; |
||
402 | |||
403 | #ifdef CONFIG_PMAC_PBOOK |
||
404 | int pm_reg; |
||
405 | u32 save_regs[64]; |
||
406 | u32 mdll, mdll2; |
||
407 | #endif /* CONFIG_PMAC_PBOOK */ |
||
408 | int asleep; |
||
409 | |||
410 | struct radeonfb_info *next; |
||
411 | }; |
||
412 | |||
413 | |||
414 | static struct fb_var_screeninfo radeonfb_default_var = { |
||
415 | 640, 480, 640, 480, 0, 0, 8, 0, |
||
416 | {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, |
||
417 | 0, 0, -1, -1, 0, 39721, 40, 24, 32, 11, 96, 2, |
||
418 | 0, FB_VMODE_NONINTERLACED |
||
419 | }; |
||
420 | |||
421 | /* |
||
422 | * IO macros |
||
423 | */ |
||
424 | |||
425 | #define INREG8(addr) readb((rinfo->mmio_base)+addr) |
||
426 | #define OUTREG8(addr,val) writeb(val, (rinfo->mmio_base)+addr) |
||
427 | #define INREG(addr) readl((rinfo->mmio_base)+addr) |
||
428 | #define OUTREG(addr,val) writel(val, (rinfo->mmio_base)+addr) |
||
429 | |||
430 | #define OUTPLL(addr,val) \ |
||
431 | do { \ |
||
432 | OUTREG8(CLOCK_CNTL_INDEX, (addr & 0x0000003f) | 0x00000080); \ |
||
433 | OUTREG(CLOCK_CNTL_DATA, val); \ |
||
434 | } while(0) |
||
435 | |||
436 | #define OUTPLLP(addr,val,mask) \ |
||
437 | do { \ |
||
438 | unsigned int _tmp = INPLL(addr); \ |
||
439 | _tmp &= (mask); \ |
||
440 | _tmp |= (val); \ |
||
441 | OUTPLL(addr, _tmp); \ |
||
442 | } while (0) |
||
443 | |||
444 | #define OUTREGP(addr,val,mask) \ |
||
445 | do { \ |
||
446 | unsigned int _tmp = INREG(addr); \ |
||
447 | _tmp &= (mask); \ |
||
448 | _tmp |= (val); \ |
||
449 | OUTREG(addr, _tmp); \ |
||
450 | } while (0) |
||
451 | |||
452 | |||
453 | static __inline__ u32 _INPLL(struct radeonfb_info *rinfo, u32 addr) |
||
454 | { |
||
455 | OUTREG8(CLOCK_CNTL_INDEX, addr & 0x0000003f); |
||
456 | return (INREG(CLOCK_CNTL_DATA)); |
||
457 | } |
||
458 | |||
459 | #define INPLL(addr) _INPLL(rinfo, addr) |
||
460 | |||
461 | #define PRIMARY_MONITOR(rinfo) ((rinfo->dviDisp_type != MT_NONE) && \ |
||
462 | (rinfo->dviDisp_type != MT_STV) && \ |
||
463 | (rinfo->dviDisp_type != MT_CTV) ? \ |
||
464 | rinfo->dviDisp_type : rinfo->crtDisp_type) |
||
465 | |||
466 | static char *GET_MON_NAME(int type) |
||
467 | { |
||
468 | char *pret = NULL; |
||
469 | |||
470 | switch (type) { |
||
471 | case MT_NONE: |
||
472 | pret = "no"; |
||
473 | break; |
||
474 | case MT_CRT: |
||
475 | pret = "CRT"; |
||
476 | break; |
||
477 | case MT_DFP: |
||
478 | pret = "DFP"; |
||
479 | break; |
||
480 | case MT_LCD: |
||
481 | pret = "LCD"; |
||
482 | break; |
||
483 | case MT_CTV: |
||
484 | pret = "CTV"; |
||
485 | break; |
||
486 | case MT_STV: |
||
487 | pret = "STV"; |
||
488 | break; |
||
489 | } |
||
490 | |||
491 | return pret; |
||
492 | } |
||
493 | |||
494 | |||
495 | /* |
||
496 | * 2D engine routines |
||
497 | */ |
||
498 | |||
499 | static __inline__ void radeon_engine_flush (struct radeonfb_info *rinfo) |
||
500 | { |
||
501 | int i; |
||
502 | |||
503 | /* initiate flush */ |
||
504 | OUTREGP(RB2D_DSTCACHE_CTLSTAT, RB2D_DC_FLUSH_ALL, |
||
505 | ~RB2D_DC_FLUSH_ALL); |
||
506 | |||
507 | for (i=0; i < 2000000; i++) { |
||
508 | if (!(INREG(RB2D_DSTCACHE_CTLSTAT) & RB2D_DC_BUSY)) |
||
509 | break; |
||
510 | } |
||
511 | } |
||
512 | |||
513 | |||
514 | static __inline__ void _radeon_fifo_wait (struct radeonfb_info *rinfo, int entries) |
||
515 | { |
||
516 | int i; |
||
517 | |||
518 | for (i=0; i<2000000; i++) |
||
519 | if ((INREG(RBBM_STATUS) & 0x7f) >= entries) |
||
520 | return; |
||
521 | } |
||
522 | |||
523 | |||
524 | static __inline__ void _radeon_engine_idle (struct radeonfb_info *rinfo) |
||
525 | { |
||
526 | int i; |
||
527 | |||
528 | /* ensure FIFO is empty before waiting for idle */ |
||
529 | _radeon_fifo_wait (rinfo, 64); |
||
530 | |||
531 | for (i=0; i<2000000; i++) { |
||
532 | if (((INREG(RBBM_STATUS) & GUI_ACTIVE)) == 0) { |
||
533 | radeon_engine_flush (rinfo); |
||
534 | return; |
||
535 | } |
||
536 | } |
||
537 | } |
||
538 | |||
539 | |||
540 | #define radeon_engine_idle() _radeon_engine_idle(rinfo) |
||
541 | #define radeon_fifo_wait(entries) _radeon_fifo_wait(rinfo,entries) |
||
542 | |||
543 | |||
544 | |||
545 | /* |
||
546 | * helper routines |
||
547 | */ |
||
548 | |||
549 | static __inline__ u32 radeon_get_dstbpp(u16 depth) |
||
550 | { |
||
551 | switch (depth) { |
||
552 | case 8: |
||
553 | return DST_8BPP; |
||
554 | case 15: |
||
555 | return DST_15BPP; |
||
556 | case 16: |
||
557 | return DST_16BPP; |
||
558 | case 32: |
||
559 | return DST_32BPP; |
||
560 | default: |
||
561 | return 0; |
||
562 | } |
||
563 | } |
||
564 | |||
565 | |||
566 | static inline int var_to_depth(const struct fb_var_screeninfo *var) |
||
567 | { |
||
568 | if (var->bits_per_pixel != 16) |
||
569 | return var->bits_per_pixel; |
||
570 | return (var->green.length == 6) ? 16 : 15; |
||
571 | } |
||
572 | |||
573 | |||
574 | static void _radeon_engine_reset(struct radeonfb_info *rinfo) |
||
575 | { |
||
576 | u32 clock_cntl_index, mclk_cntl, rbbm_soft_reset; |
||
577 | |||
578 | radeon_engine_flush (rinfo); |
||
579 | |||
580 | clock_cntl_index = INREG(CLOCK_CNTL_INDEX); |
||
581 | mclk_cntl = INPLL(MCLK_CNTL); |
||
582 | |||
583 | OUTPLL(MCLK_CNTL, (mclk_cntl | |
||
584 | FORCEON_MCLKA | |
||
585 | FORCEON_MCLKB | |
||
586 | FORCEON_YCLKA | |
||
587 | FORCEON_YCLKB | |
||
588 | FORCEON_MC | |
||
589 | FORCEON_AIC)); |
||
590 | rbbm_soft_reset = INREG(RBBM_SOFT_RESET); |
||
591 | |||
592 | OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset | |
||
593 | SOFT_RESET_CP | |
||
594 | SOFT_RESET_HI | |
||
595 | SOFT_RESET_SE | |
||
596 | SOFT_RESET_RE | |
||
597 | SOFT_RESET_PP | |
||
598 | SOFT_RESET_E2 | |
||
599 | SOFT_RESET_RB); |
||
600 | INREG(RBBM_SOFT_RESET); |
||
601 | OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset & (u32) |
||
602 | ~(SOFT_RESET_CP | |
||
603 | SOFT_RESET_HI | |
||
604 | SOFT_RESET_SE | |
||
605 | SOFT_RESET_RE | |
||
606 | SOFT_RESET_PP | |
||
607 | SOFT_RESET_E2 | |
||
608 | SOFT_RESET_RB)); |
||
609 | INREG(RBBM_SOFT_RESET); |
||
610 | |||
611 | OUTPLL(MCLK_CNTL, mclk_cntl); |
||
612 | OUTREG(CLOCK_CNTL_INDEX, clock_cntl_index); |
||
613 | OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset); |
||
614 | |||
615 | return; |
||
616 | } |
||
617 | |||
618 | #define radeon_engine_reset() _radeon_engine_reset(rinfo) |
||
619 | |||
620 | |||
621 | static __inline__ u8 radeon_get_post_div_bitval(int post_div) |
||
622 | { |
||
623 | switch (post_div) { |
||
624 | case 1: |
||
625 | return 0x00; |
||
626 | case 2: |
||
627 | return 0x01; |
||
628 | case 3: |
||
629 | return 0x04; |
||
630 | case 4: |
||
631 | return 0x02; |
||
632 | case 6: |
||
633 | return 0x06; |
||
634 | case 8: |
||
635 | return 0x03; |
||
636 | case 12: |
||
637 | return 0x07; |
||
638 | default: |
||
639 | return 0x02; |
||
640 | } |
||
641 | } |
||
642 | |||
643 | |||
644 | |||
645 | static __inline__ int round_div(int num, int den) |
||
646 | { |
||
647 | return (num + (den / 2)) / den; |
||
648 | } |
||
649 | |||
650 | |||
651 | |||
652 | static __inline__ int min_bits_req(int val) |
||
653 | { |
||
654 | int bits_req = 0; |
||
655 | |||
656 | if (val == 0) |
||
657 | bits_req = 1; |
||
658 | |||
659 | while (val) { |
||
660 | val >>= 1; |
||
661 | bits_req++; |
||
662 | } |
||
663 | |||
664 | return (bits_req); |
||
665 | } |
||
666 | |||
667 | |||
668 | static __inline__ int _max(int val1, int val2) |
||
669 | { |
||
670 | if (val1 >= val2) |
||
671 | return val1; |
||
672 | else |
||
673 | return val2; |
||
674 | } |
||
675 | |||
676 | |||
677 | |||
678 | /* |
||
679 | * globals |
||
680 | */ |
||
681 | |||
682 | static char *mode_option __initdata; |
||
683 | static char noaccel = 1; |
||
684 | static char mirror = 0; |
||
685 | static int panel_yres __initdata = 0; |
||
686 | static char force_dfp __initdata = 0; |
||
687 | static struct radeonfb_info *board_list = NULL; |
||
688 | static char nomtrr __initdata = 0; |
||
689 | |||
690 | /* |
||
691 | * prototypes |
||
692 | */ |
||
693 | |||
694 | static void radeon_save_state (struct radeonfb_info *rinfo, |
||
695 | struct radeon_regs *save); |
||
696 | static void radeon_engine_init (struct radeonfb_info *rinfo); |
||
697 | static void radeon_write_mode (struct radeonfb_info *rinfo, |
||
698 | struct radeon_regs *mode); |
||
699 | static int __devinit radeon_set_fbinfo (struct radeonfb_info *rinfo); |
||
700 | static int __devinit radeon_init_disp (struct radeonfb_info *rinfo); |
||
701 | static int radeon_init_disp_var (struct radeonfb_info *rinfo, struct fb_var_screeninfo *var); |
||
702 | static char *radeon_find_rom(struct radeonfb_info *rinfo); |
||
703 | static void radeon_get_pllinfo(struct radeonfb_info *rinfo, char *bios_seg); |
||
704 | static void radeon_get_moninfo (struct radeonfb_info *rinfo); |
||
705 | static int radeon_get_dfpinfo (struct radeonfb_info *rinfo); |
||
706 | static int radeon_get_dfpinfo_BIOS(struct radeonfb_info *rinfo); |
||
707 | static void radeon_get_EDID(struct radeonfb_info *rinfo); |
||
708 | static int radeon_dfp_parse_EDID(struct radeonfb_info *rinfo); |
||
709 | static void radeon_update_default_var(struct radeonfb_info *rinfo); |
||
710 | |||
711 | #ifdef CONFIG_PPC_OF |
||
712 | |||
713 | static int radeon_read_OF (struct radeonfb_info *rinfo); |
||
714 | static int radeon_get_EDID_OF(struct radeonfb_info *rinfo); |
||
715 | extern struct device_node *pci_device_to_OF_node(struct pci_dev *dev); |
||
716 | |||
717 | #ifdef CONFIG_PMAC_PBOOK |
||
718 | int radeon_sleep_notify(struct pmu_sleep_notifier *self, int when); |
||
719 | static struct pmu_sleep_notifier radeon_sleep_notifier = { |
||
720 | radeon_sleep_notify, SLEEP_LEVEL_VIDEO, |
||
721 | }; |
||
722 | #endif /* CONFIG_PMAC_PBOOK */ |
||
723 | #ifdef CONFIG_PMAC_BACKLIGHT |
||
724 | static int radeon_set_backlight_enable(int on, int level, void *data); |
||
725 | static int radeon_set_backlight_level(int level, void *data); |
||
726 | static struct backlight_controller radeon_backlight_controller = { |
||
727 | radeon_set_backlight_enable, |
||
728 | radeon_set_backlight_level |
||
729 | }; |
||
730 | #endif /* CONFIG_PMAC_BACKLIGHT */ |
||
731 | |||
732 | #endif /* CONFIG_PPC_OF */ |
||
733 | |||
734 | |||
735 | static char *radeon_find_rom(struct radeonfb_info *rinfo) |
||
736 | { |
||
737 | #if defined(__i386__) |
||
738 | u32 segstart; |
||
739 | char *rom_base; |
||
740 | char *rom; |
||
741 | int stage; |
||
742 | int i,j; |
||
743 | char aty_rom_sig[] = "761295520"; |
||
744 | char *radeon_sig[] = { |
||
745 | "RG6", |
||
746 | "RADEON" |
||
747 | }; |
||
748 | |||
749 | for(segstart=0x000c0000; segstart<0x000f0000; segstart+=0x00001000) { |
||
750 | |||
751 | stage = 1; |
||
752 | |||
753 | rom_base = (char *)ioremap(segstart, 0x1000); |
||
754 | |||
755 | if ((*rom_base == 0x55) && (((*(rom_base + 1)) & 0xff) == 0xaa)) |
||
756 | stage = 2; |
||
757 | |||
758 | |||
759 | if (stage != 2) { |
||
760 | iounmap(rom_base); |
||
761 | continue; |
||
762 | } |
||
763 | |||
764 | rom = rom_base; |
||
765 | |||
766 | for (i = 0; (i < 128 - strlen(aty_rom_sig)) && (stage != 3); i++) { |
||
767 | if (aty_rom_sig[0] == *rom) |
||
768 | if (strncmp(aty_rom_sig, rom, |
||
769 | strlen(aty_rom_sig)) == 0) |
||
770 | stage = 3; |
||
771 | rom++; |
||
772 | } |
||
773 | if (stage != 3) { |
||
774 | iounmap(rom_base); |
||
775 | continue; |
||
776 | } |
||
777 | rom = rom_base; |
||
778 | |||
779 | for (i = 0; (i < 512) && (stage != 4); i++) { |
||
780 | for(j = 0;j < sizeof(radeon_sig)/sizeof(char *);j++) { |
||
781 | if (radeon_sig[j][0] == *rom) |
||
782 | if (strncmp(radeon_sig[j], rom, |
||
783 | strlen(radeon_sig[j])) == 0) { |
||
784 | stage = 4; |
||
785 | break; |
||
786 | } |
||
787 | } |
||
788 | rom++; |
||
789 | } |
||
790 | if (stage != 4) { |
||
791 | iounmap(rom_base); |
||
792 | continue; |
||
793 | } |
||
794 | |||
795 | return rom_base; |
||
796 | } |
||
797 | #endif |
||
798 | return NULL; |
||
799 | } |
||
800 | |||
801 | |||
802 | |||
803 | |||
804 | static void radeon_get_pllinfo(struct radeonfb_info *rinfo, char *bios_seg) |
||
805 | { |
||
806 | void *bios_header; |
||
807 | void *header_ptr; |
||
808 | u16 bios_header_offset, pll_info_offset; |
||
809 | PLL_BLOCK pll; |
||
810 | |||
811 | if (bios_seg) { |
||
812 | bios_header = bios_seg + 0x48L; |
||
813 | header_ptr = bios_header; |
||
814 | |||
815 | bios_header_offset = readw(header_ptr); |
||
816 | bios_header = bios_seg + bios_header_offset; |
||
817 | bios_header += 0x30; |
||
818 | |||
819 | header_ptr = bios_header; |
||
820 | pll_info_offset = readw(header_ptr); |
||
821 | header_ptr = bios_seg + pll_info_offset; |
||
822 | |||
823 | memcpy_fromio(&pll, header_ptr, 50); |
||
824 | |||
825 | rinfo->pll.xclk = (u32)pll.XCLK; |
||
826 | rinfo->pll.ref_clk = (u32)pll.PCLK_ref_freq; |
||
827 | rinfo->pll.ref_div = (u32)pll.PCLK_ref_divider; |
||
828 | rinfo->pll.ppll_min = pll.PCLK_min_freq; |
||
829 | rinfo->pll.ppll_max = pll.PCLK_max_freq; |
||
830 | |||
831 | printk("radeonfb: ref_clk=%d, ref_div=%d, xclk=%d from BIOS\n", |
||
832 | rinfo->pll.ref_clk, rinfo->pll.ref_div, rinfo->pll.xclk); |
||
833 | } else { |
||
834 | #ifdef CONFIG_PPC_OF |
||
835 | if (radeon_read_OF(rinfo)) { |
||
836 | unsigned int tmp, Nx, M, ref_div, xclk; |
||
837 | |||
838 | tmp = INPLL(M_SPLL_REF_FB_DIV); |
||
839 | ref_div = INPLL(PPLL_REF_DIV) & 0x3ff; |
||
840 | |||
841 | Nx = (tmp & 0xff00) >> 8; |
||
842 | M = (tmp & 0xff); |
||
843 | xclk = ((((2 * Nx * rinfo->pll.ref_clk) + (M)) / |
||
844 | (2 * M))); |
||
845 | |||
846 | rinfo->pll.xclk = xclk; |
||
847 | rinfo->pll.ref_div = ref_div; |
||
848 | rinfo->pll.ppll_min = 12000; |
||
849 | rinfo->pll.ppll_max = 35000; |
||
850 | |||
851 | printk("radeonfb: ref_clk=%d, ref_div=%d, xclk=%d from OF\n", |
||
852 | rinfo->pll.ref_clk, rinfo->pll.ref_div, rinfo->pll.xclk); |
||
853 | |||
854 | return; |
||
855 | } |
||
856 | #endif |
||
857 | /* no BIOS or BIOS not found, use defaults */ |
||
858 | switch (rinfo->chipset) { |
||
859 | case PCI_DEVICE_ID_ATI_RADEON_QW: |
||
860 | case PCI_DEVICE_ID_ATI_RADEON_QX: |
||
861 | rinfo->pll.ppll_max = 35000; |
||
862 | rinfo->pll.ppll_min = 12000; |
||
863 | rinfo->pll.xclk = 23000; |
||
864 | rinfo->pll.ref_div = 12; |
||
865 | rinfo->pll.ref_clk = 2700; |
||
866 | break; |
||
867 | case PCI_DEVICE_ID_ATI_RADEON_QL: |
||
868 | case PCI_DEVICE_ID_ATI_RADEON_QN: |
||
869 | case PCI_DEVICE_ID_ATI_RADEON_QO: |
||
870 | case PCI_DEVICE_ID_ATI_RADEON_Ql: |
||
871 | case PCI_DEVICE_ID_ATI_RADEON_BB: |
||
872 | rinfo->pll.ppll_max = 35000; |
||
873 | rinfo->pll.ppll_min = 12000; |
||
874 | rinfo->pll.xclk = 27500; |
||
875 | rinfo->pll.ref_div = 12; |
||
876 | rinfo->pll.ref_clk = 2700; |
||
877 | break; |
||
878 | case PCI_DEVICE_ID_ATI_RADEON_Id: |
||
879 | case PCI_DEVICE_ID_ATI_RADEON_Ie: |
||
880 | case PCI_DEVICE_ID_ATI_RADEON_If: |
||
881 | case PCI_DEVICE_ID_ATI_RADEON_Ig: |
||
882 | rinfo->pll.ppll_max = 35000; |
||
883 | rinfo->pll.ppll_min = 12000; |
||
884 | rinfo->pll.xclk = 25000; |
||
885 | rinfo->pll.ref_div = 12; |
||
886 | rinfo->pll.ref_clk = 2700; |
||
887 | break; |
||
888 | case PCI_DEVICE_ID_ATI_RADEON_ND: |
||
889 | case PCI_DEVICE_ID_ATI_RADEON_NE: |
||
890 | case PCI_DEVICE_ID_ATI_RADEON_NF: |
||
891 | case PCI_DEVICE_ID_ATI_RADEON_NG: |
||
892 | rinfo->pll.ppll_max = 40000; |
||
893 | rinfo->pll.ppll_min = 20000; |
||
894 | rinfo->pll.xclk = 27000; |
||
895 | rinfo->pll.ref_div = 12; |
||
896 | rinfo->pll.ref_clk = 2700; |
||
897 | break; |
||
898 | case PCI_DEVICE_ID_ATI_RADEON_QD: |
||
899 | case PCI_DEVICE_ID_ATI_RADEON_QE: |
||
900 | case PCI_DEVICE_ID_ATI_RADEON_QF: |
||
901 | case PCI_DEVICE_ID_ATI_RADEON_QG: |
||
902 | default: |
||
903 | rinfo->pll.ppll_max = 35000; |
||
904 | rinfo->pll.ppll_min = 12000; |
||
905 | rinfo->pll.xclk = 16600; |
||
906 | rinfo->pll.ref_div = 67; |
||
907 | rinfo->pll.ref_clk = 2700; |
||
908 | break; |
||
909 | } |
||
910 | |||
911 | printk("radeonfb: ref_clk=%d, ref_div=%d, xclk=%d defaults\n", |
||
912 | rinfo->pll.ref_clk, rinfo->pll.ref_div, rinfo->pll.xclk); |
||
913 | } |
||
914 | } |
||
915 | |||
916 | |||
917 | static void radeon_get_moninfo (struct radeonfb_info *rinfo) |
||
918 | { |
||
919 | unsigned int tmp; |
||
920 | |||
921 | if (force_dfp) { |
||
922 | rinfo->dviDisp_type = MT_DFP; |
||
923 | return; |
||
924 | } |
||
925 | |||
926 | tmp = INREG(RADEON_BIOS_4_SCRATCH); |
||
927 | printk(KERN_DEBUG "radeon_get_moninfo: bios 4 scratch = %x\n", tmp); |
||
928 | |||
929 | if (rinfo->hasCRTC2) { |
||
930 | /* primary DVI port */ |
||
931 | if (tmp & 0x08) |
||
932 | rinfo->dviDisp_type = MT_DFP; |
||
933 | else if (tmp & 0x4) |
||
934 | rinfo->dviDisp_type = MT_LCD; |
||
935 | else if (tmp & 0x200) |
||
936 | rinfo->dviDisp_type = MT_CRT; |
||
937 | else if (tmp & 0x10) |
||
938 | rinfo->dviDisp_type = MT_CTV; |
||
939 | else if (tmp & 0x20) |
||
940 | rinfo->dviDisp_type = MT_STV; |
||
941 | |||
942 | /* secondary CRT port */ |
||
943 | if (tmp & 0x2) |
||
944 | rinfo->crtDisp_type = MT_CRT; |
||
945 | else if (tmp & 0x800) |
||
946 | rinfo->crtDisp_type = MT_DFP; |
||
947 | else if (tmp & 0x400) |
||
948 | rinfo->crtDisp_type = MT_LCD; |
||
949 | else if (tmp & 0x1000) |
||
950 | rinfo->crtDisp_type = MT_CTV; |
||
951 | else if (tmp & 0x2000) |
||
952 | rinfo->crtDisp_type = MT_STV; |
||
953 | } else { |
||
954 | rinfo->dviDisp_type = MT_NONE; |
||
955 | |||
956 | tmp = INREG(FP_GEN_CNTL); |
||
957 | |||
958 | if (tmp & FP_EN_TMDS) |
||
959 | rinfo->crtDisp_type = MT_DFP; |
||
960 | else |
||
961 | rinfo->crtDisp_type = MT_CRT; |
||
962 | } |
||
963 | } |
||
964 | |||
965 | |||
966 | |||
967 | static void radeon_get_EDID(struct radeonfb_info *rinfo) |
||
968 | { |
||
969 | #ifdef CONFIG_PPC_OF |
||
970 | if (!radeon_get_EDID_OF(rinfo)) |
||
971 | RTRACE("radeonfb: could not retrieve EDID from OF\n"); |
||
972 | #else |
||
973 | /* XXX use other methods later */ |
||
974 | #endif |
||
975 | } |
||
976 | |||
977 | |||
978 | #ifdef CONFIG_PPC_OF |
||
979 | static int radeon_get_EDID_OF(struct radeonfb_info *rinfo) |
||
980 | { |
||
981 | struct device_node *dp; |
||
982 | unsigned char *pedid = NULL; |
||
983 | static char *propnames[] = { "DFP,EDID", "LCD,EDID", "EDID", "EDID1", NULL }; |
||
984 | int i; |
||
985 | |||
986 | dp = pci_device_to_OF_node(rinfo->pdev); |
||
987 | while (dp != NULL) { |
||
988 | for (i = 0; propnames[i] != NULL; ++i) { |
||
989 | pedid = (unsigned char *) |
||
990 | get_property(dp, propnames[i], NULL); |
||
991 | if (pedid != NULL) { |
||
992 | rinfo->EDID = pedid; |
||
993 | return 1; |
||
994 | } |
||
995 | } |
||
996 | dp = dp->child; |
||
997 | } |
||
998 | return 0; |
||
999 | } |
||
1000 | #endif /* CONFIG_PPC_OF */ |
||
1001 | |||
1002 | |||
1003 | static int radeon_dfp_parse_EDID(struct radeonfb_info *rinfo) |
||
1004 | { |
||
1005 | unsigned char *block = rinfo->EDID; |
||
1006 | |||
1007 | if (!block) |
||
1008 | return 0; |
||
1009 | |||
1010 | /* jump to the detailed timing block section */ |
||
1011 | block += 54; |
||
1012 | |||
1013 | rinfo->clock = (block[0] + (block[1] << 8)); |
||
1014 | rinfo->panel_xres = (block[2] + ((block[4] & 0xf0) << 4)); |
||
1015 | rinfo->hblank = (block[3] + ((block[4] & 0x0f) << 8)); |
||
1016 | rinfo->panel_yres = (block[5] + ((block[7] & 0xf0) << 4)); |
||
1017 | rinfo->vblank = (block[6] + ((block[7] & 0x0f) << 8)); |
||
1018 | rinfo->hOver_plus = (block[8] + ((block[11] & 0xc0) << 2)); |
||
1019 | rinfo->hSync_width = (block[9] + ((block[11] & 0x30) << 4)); |
||
1020 | rinfo->vOver_plus = ((block[10] >> 4) + ((block[11] & 0x0c) << 2)); |
||
1021 | rinfo->vSync_width = ((block[10] & 0x0f) + ((block[11] & 0x03) << 4)); |
||
1022 | rinfo->interlaced = ((block[17] & 0x80) >> 7); |
||
1023 | rinfo->synct = ((block[17] & 0x18) >> 3); |
||
1024 | rinfo->misc = ((block[17] & 0x06) >> 1); |
||
1025 | rinfo->hAct_high = rinfo->vAct_high = 0; |
||
1026 | if (rinfo->synct == 3) { |
||
1027 | if (rinfo->misc & 2) |
||
1028 | rinfo->hAct_high = 1; |
||
1029 | if (rinfo->misc & 1) |
||
1030 | rinfo->vAct_high = 1; |
||
1031 | } |
||
1032 | |||
1033 | printk("radeonfb: detected DFP panel size from EDID: %dx%d\n", |
||
1034 | rinfo->panel_xres, rinfo->panel_yres); |
||
1035 | |||
1036 | rinfo->got_dfpinfo = 1; |
||
1037 | |||
1038 | return 1; |
||
1039 | } |
||
1040 | |||
1041 | |||
1042 | static void radeon_update_default_var(struct radeonfb_info *rinfo) |
||
1043 | { |
||
1044 | struct fb_var_screeninfo *var = &radeonfb_default_var; |
||
1045 | |||
1046 | var->xres = rinfo->panel_xres; |
||
1047 | var->yres = rinfo->panel_yres; |
||
1048 | var->xres_virtual = rinfo->panel_xres; |
||
1049 | var->yres_virtual = rinfo->panel_yres; |
||
1050 | var->xoffset = var->yoffset = 0; |
||
1051 | var->bits_per_pixel = 8; |
||
1052 | var->pixclock = 100000000 / rinfo->clock; |
||
1053 | var->left_margin = (rinfo->hblank - rinfo->hOver_plus - rinfo->hSync_width); |
||
1054 | var->right_margin = rinfo->hOver_plus; |
||
1055 | var->upper_margin = (rinfo->vblank - rinfo->vOver_plus - rinfo->vSync_width); |
||
1056 | var->lower_margin = rinfo->vOver_plus; |
||
1057 | var->hsync_len = rinfo->hSync_width; |
||
1058 | var->vsync_len = rinfo->vSync_width; |
||
1059 | var->sync = 0; |
||
1060 | if (rinfo->synct == 3) { |
||
1061 | if (rinfo->hAct_high) |
||
1062 | var->sync |= FB_SYNC_HOR_HIGH_ACT; |
||
1063 | if (rinfo->vAct_high) |
||
1064 | var->sync |= FB_SYNC_VERT_HIGH_ACT; |
||
1065 | } |
||
1066 | |||
1067 | var->vmode = 0; |
||
1068 | if (rinfo->interlaced) |
||
1069 | var->vmode |= FB_VMODE_INTERLACED; |
||
1070 | |||
1071 | rinfo->use_default_var = 1; |
||
1072 | } |
||
1073 | |||
1074 | |||
1075 | static int radeon_get_dfpinfo_BIOS(struct radeonfb_info *rinfo) |
||
1076 | { |
||
1077 | char *fpbiosstart, *tmp, *tmp0; |
||
1078 | char stmp[30]; |
||
1079 | int i; |
||
1080 | |||
1081 | if (!rinfo->bios_seg) |
||
1082 | return 0; |
||
1083 | |||
1084 | if (!(fpbiosstart = rinfo->bios_seg + readw(rinfo->bios_seg + 0x48))) { |
||
1085 | printk("radeonfb: Failed to detect DFP panel info using BIOS\n"); |
||
1086 | return 0; |
||
1087 | } |
||
1088 | |||
1089 | if (!(tmp = rinfo->bios_seg + readw(fpbiosstart + 0x40))) { |
||
1090 | printk("radeonfb: Failed to detect DFP panel info using BIOS\n"); |
||
1091 | return 0; |
||
1092 | } |
||
1093 | |||
1094 | for(i=0; i<24; i++) |
||
1095 | stmp[i] = readb(tmp+i+1); |
||
1096 | stmp[24] = 0; |
||
1097 | printk("radeonfb: panel ID string: %s\n", stmp); |
||
1098 | rinfo->panel_xres = readw(tmp + 25); |
||
1099 | rinfo->panel_yres = readw(tmp + 27); |
||
1100 | printk("radeonfb: detected DFP panel size from BIOS: %dx%d\n", |
||
1101 | rinfo->panel_xres, rinfo->panel_yres); |
||
1102 | |||
1103 | for(i=0; i<20; i++) { |
||
1104 | tmp0 = rinfo->bios_seg + readw(tmp+64+i*2); |
||
1105 | if (tmp0 == 0) |
||
1106 | break; |
||
1107 | if ((readw(tmp0) == rinfo->panel_xres) && |
||
1108 | (readw(tmp0+2) == rinfo->panel_yres)) { |
||
1109 | rinfo->hblank = (readw(tmp0+17) - readw(tmp0+19)) * 8; |
||
1110 | rinfo->hOver_plus = ((readw(tmp0+21) - readw(tmp0+19) -1) * 8) & 0x7fff; |
||
1111 | rinfo->hSync_width = readb(tmp0+23) * 8; |
||
1112 | rinfo->vblank = readw(tmp0+24) - readw(tmp0+26); |
||
1113 | rinfo->vOver_plus = (readw(tmp0+28) & 0x7ff) - readw(tmp0+26); |
||
1114 | rinfo->vSync_width = (readw(tmp0+28) & 0xf800) >> 11; |
||
1115 | rinfo->clock = readw(tmp0+9); |
||
1116 | |||
1117 | rinfo->got_dfpinfo = 1; |
||
1118 | return 1; |
||
1119 | } |
||
1120 | } |
||
1121 | |||
1122 | return 0; |
||
1123 | } |
||
1124 | |||
1125 | |||
1126 | |||
1127 | static int radeon_get_dfpinfo (struct radeonfb_info *rinfo) |
||
1128 | { |
||
1129 | unsigned int tmp; |
||
1130 | unsigned short a, b; |
||
1131 | |||
1132 | if (radeon_get_dfpinfo_BIOS(rinfo)) |
||
1133 | radeon_update_default_var(rinfo); |
||
1134 | |||
1135 | if (radeon_dfp_parse_EDID(rinfo)) |
||
1136 | radeon_update_default_var(rinfo); |
||
1137 | |||
1138 | if (!rinfo->got_dfpinfo) { |
||
1139 | /* |
||
1140 | * it seems all else has failed now and we |
||
1141 | * resort to probing registers for our DFP info |
||
1142 | */ |
||
1143 | if (panel_yres) { |
||
1144 | rinfo->panel_yres = panel_yres; |
||
1145 | } else { |
||
1146 | tmp = INREG(FP_VERT_STRETCH); |
||
1147 | tmp &= 0x00fff000; |
||
1148 | rinfo->panel_yres = (unsigned short)(tmp >> 0x0c) + 1; |
||
1149 | } |
||
1150 | |||
1151 | switch (rinfo->panel_yres) { |
||
1152 | case 480: |
||
1153 | rinfo->panel_xres = 640; |
||
1154 | break; |
||
1155 | case 600: |
||
1156 | rinfo->panel_xres = 800; |
||
1157 | break; |
||
1158 | case 768: |
||
1159 | #if defined(__powerpc__) |
||
1160 | if (rinfo->dviDisp_type == MT_LCD) |
||
1161 | rinfo->panel_xres = 1152; |
||
1162 | else |
||
1163 | #endif |
||
1164 | rinfo->panel_xres = 1024; |
||
1165 | break; |
||
1166 | case 1024: |
||
1167 | rinfo->panel_xres = 1280; |
||
1168 | break; |
||
1169 | case 1050: |
||
1170 | rinfo->panel_xres = 1400; |
||
1171 | break; |
||
1172 | case 1200: |
||
1173 | rinfo->panel_xres = 1600; |
||
1174 | break; |
||
1175 | default: |
||
1176 | printk("radeonfb: Failed to detect DFP panel size\n"); |
||
1177 | return 0; |
||
1178 | } |
||
1179 | |||
1180 | printk("radeonfb: detected DFP panel size from registers: %dx%d\n", |
||
1181 | rinfo->panel_xres, rinfo->panel_yres); |
||
1182 | |||
1183 | tmp = INREG(FP_CRTC_H_TOTAL_DISP); |
||
1184 | a = (tmp & FP_CRTC_H_TOTAL_MASK) + 4; |
||
1185 | b = (tmp & 0x01ff0000) >> FP_CRTC_H_DISP_SHIFT; |
||
1186 | rinfo->hblank = (a - b + 1) * 8; |
||
1187 | |||
1188 | tmp = INREG(FP_H_SYNC_STRT_WID); |
||
1189 | rinfo->hOver_plus = (unsigned short) ((tmp & FP_H_SYNC_STRT_CHAR_MASK) >> |
||
1190 | FP_H_SYNC_STRT_CHAR_SHIFT) - b - 1; |
||
1191 | rinfo->hOver_plus *= 8; |
||
1192 | rinfo->hSync_width = (unsigned short) ((tmp & FP_H_SYNC_WID_MASK) >> |
||
1193 | FP_H_SYNC_WID_SHIFT); |
||
1194 | rinfo->hSync_width *= 8; |
||
1195 | tmp = INREG(FP_CRTC_V_TOTAL_DISP); |
||
1196 | a = (tmp & FP_CRTC_V_TOTAL_MASK) + 1; |
||
1197 | b = (tmp & FP_CRTC_V_DISP_MASK) >> FP_CRTC_V_DISP_SHIFT; |
||
1198 | rinfo->vblank = a - b /* + 24 */ ; |
||
1199 | |||
1200 | tmp = INREG(FP_V_SYNC_STRT_WID); |
||
1201 | rinfo->vOver_plus = (unsigned short) (tmp & FP_V_SYNC_STRT_MASK) |
||
1202 | - b + 1; |
||
1203 | rinfo->vSync_width = (unsigned short) ((tmp & FP_V_SYNC_WID_MASK) >> |
||
1204 | FP_V_SYNC_WID_SHIFT); |
||
1205 | |||
1206 | return 1; |
||
1207 | } |
||
1208 | |||
1209 | return 1; |
||
1210 | } |
||
1211 | |||
1212 | |||
1213 | #ifdef CONFIG_PPC_OF |
||
1214 | static int radeon_read_OF (struct radeonfb_info *rinfo) |
||
1215 | { |
||
1216 | struct device_node *dp; |
||
1217 | unsigned int *xtal; |
||
1218 | |||
1219 | dp = pci_device_to_OF_node(rinfo->pdev); |
||
1220 | |||
1221 | xtal = (unsigned int *) get_property(dp, "ATY,RefCLK", 0); |
||
1222 | |||
1223 | rinfo->pll.ref_clk = *xtal / 10; |
||
1224 | |||
1225 | if (*xtal) |
||
1226 | return 1; |
||
1227 | else |
||
1228 | return 0; |
||
1229 | } |
||
1230 | #endif |
||
1231 | |||
1232 | |||
1233 | static void radeon_engine_init (struct radeonfb_info *rinfo) |
||
1234 | { |
||
1235 | u32 temp; |
||
1236 | |||
1237 | /* disable 3D engine */ |
||
1238 | OUTREG(RB3D_CNTL, 0); |
||
1239 | |||
1240 | radeon_engine_reset (); |
||
1241 | |||
1242 | radeon_fifo_wait (1); |
||
1243 | OUTREG(RB2D_DSTCACHE_MODE, 0); |
||
1244 | |||
1245 | /* XXX */ |
||
1246 | rinfo->pitch = ((rinfo->xres_virtual * (rinfo->bpp / 8) + 0x3f)) >> 6; |
||
1247 | |||
1248 | radeon_fifo_wait (1); |
||
1249 | temp = INREG(DEFAULT_PITCH_OFFSET); |
||
1250 | OUTREG(DEFAULT_PITCH_OFFSET, ((temp & 0xc0000000) | |
||
1251 | (rinfo->pitch << 0x16))); |
||
1252 | |||
1253 | radeon_fifo_wait (1); |
||
1254 | OUTREGP(DP_DATATYPE, 0, ~HOST_BIG_ENDIAN_EN); |
||
1255 | |||
1256 | radeon_fifo_wait (1); |
||
1257 | OUTREG(DEFAULT_SC_BOTTOM_RIGHT, (DEFAULT_SC_RIGHT_MAX | |
||
1258 | DEFAULT_SC_BOTTOM_MAX)); |
||
1259 | |||
1260 | temp = radeon_get_dstbpp(rinfo->depth); |
||
1261 | rinfo->dp_gui_master_cntl = ((temp << 8) | GMC_CLR_CMP_CNTL_DIS); |
||
1262 | radeon_fifo_wait (1); |
||
1263 | OUTREG(DP_GUI_MASTER_CNTL, (rinfo->dp_gui_master_cntl | |
||
1264 | GMC_BRUSH_SOLID_COLOR | |
||
1265 | GMC_SRC_DATATYPE_COLOR)); |
||
1266 | |||
1267 | radeon_fifo_wait (7); |
||
1268 | |||
1269 | /* clear line drawing regs */ |
||
1270 | OUTREG(DST_LINE_START, 0); |
||
1271 | OUTREG(DST_LINE_END, 0); |
||
1272 | |||
1273 | /* set brush color regs */ |
||
1274 | OUTREG(DP_BRUSH_FRGD_CLR, 0xffffffff); |
||
1275 | OUTREG(DP_BRUSH_BKGD_CLR, 0x00000000); |
||
1276 | |||
1277 | /* set source color regs */ |
||
1278 | OUTREG(DP_SRC_FRGD_CLR, 0xffffffff); |
||
1279 | OUTREG(DP_SRC_BKGD_CLR, 0x00000000); |
||
1280 | |||
1281 | /* default write mask */ |
||
1282 | OUTREG(DP_WRITE_MSK, 0xffffffff); |
||
1283 | |||
1284 | radeon_engine_idle (); |
||
1285 | } |
||
1286 | |||
1287 | |||
1288 | static int __devinit radeon_init_disp (struct radeonfb_info *rinfo) |
||
1289 | { |
||
1290 | struct fb_info *info = &rinfo->info; |
||
1291 | struct fb_var_screeninfo var; |
||
1292 | |||
1293 | var = radeonfb_default_var; |
||
1294 | if ((radeon_init_disp_var(rinfo, &var)) < 0) |
||
1295 | return -1; |
||
1296 | |||
1297 | rinfo->depth = var_to_depth(&var); |
||
1298 | rinfo->bpp = var.bits_per_pixel; |
||
1299 | |||
1300 | info->var = var; |
||
1301 | fb_alloc_cmap(&info->cmap, 256, 0); |
||
1302 | |||
1303 | var.activate = FB_ACTIVATE_NOW; |
||
1304 | return 0; |
||
1305 | } |
||
1306 | |||
1307 | |||
1308 | static int radeon_init_disp_var (struct radeonfb_info *rinfo, |
||
1309 | struct fb_var_screeninfo *var) |
||
1310 | { |
||
1311 | #ifndef MODULE |
||
1312 | if (mode_option) |
||
1313 | fb_find_mode (var, &rinfo->info, mode_option, |
||
1314 | NULL, 0, NULL, 8); |
||
1315 | else |
||
1316 | #endif |
||
1317 | if (rinfo->use_default_var) |
||
1318 | /* We will use the modified default far */ |
||
1319 | *var = radeonfb_default_var; |
||
1320 | else |
||
1321 | |||
1322 | fb_find_mode (var, &rinfo->info, "640x480-8@60", |
||
1323 | NULL, 0, NULL, 0); |
||
1324 | |||
1325 | if (noaccel) |
||
1326 | var->accel_flags &= ~FB_ACCELF_TEXT; |
||
1327 | else |
||
1328 | var->accel_flags |= FB_ACCELF_TEXT; |
||
1329 | |||
1330 | return 0; |
||
1331 | } |
||
1332 | |||
1333 | |||
1334 | static int radeon_do_maximize(struct radeonfb_info *rinfo, |
||
1335 | struct fb_var_screeninfo *var, |
||
1336 | struct fb_var_screeninfo *v, |
||
1337 | int nom, int den) |
||
1338 | { |
||
1339 | static struct { |
||
1340 | int xres, yres; |
||
1341 | } modes[] = { |
||
1342 | {1600, 1280}, |
||
1343 | {1280, 1024}, |
||
1344 | {1024, 768}, |
||
1345 | {800, 600}, |
||
1346 | {640, 480}, |
||
1347 | {-1, -1} |
||
1348 | }; |
||
1349 | int i; |
||
1350 | |||
1351 | /* use highest possible virtual resolution */ |
||
1352 | if (v->xres_virtual == -1 && v->yres_virtual == -1) { |
||
1353 | printk("radeonfb: using max available virtual resolution\n"); |
||
1354 | for (i=0; modes[i].xres != -1; i++) { |
||
1355 | if (modes[i].xres * nom / den * modes[i].yres < |
||
1356 | rinfo->video_ram / 2) |
||
1357 | break; |
||
1358 | } |
||
1359 | if (modes[i].xres == -1) { |
||
1360 | printk("radeonfb: could not find virtual resolution that fits into video memory!\n"); |
||
1361 | return -EINVAL; |
||
1362 | } |
||
1363 | v->xres_virtual = modes[i].xres; |
||
1364 | v->yres_virtual = modes[i].yres; |
||
1365 | |||
1366 | printk("radeonfb: virtual resolution set to max of %dx%d\n", |
||
1367 | v->xres_virtual, v->yres_virtual); |
||
1368 | } else if (v->xres_virtual == -1) { |
||
1369 | v->xres_virtual = (rinfo->video_ram * den / |
||
1370 | (nom * v->yres_virtual * 2)) & ~15; |
||
1371 | } else if (v->yres_virtual == -1) { |
||
1372 | v->xres_virtual = (v->xres_virtual + 15) & ~15; |
||
1373 | v->yres_virtual = rinfo->video_ram * den / |
||
1374 | (nom * v->xres_virtual *2); |
||
1375 | } else { |
||
1376 | if (v->xres_virtual * nom / den * v->yres_virtual > |
||
1377 | rinfo->video_ram) { |
||
1378 | return -EINVAL; |
||
1379 | } |
||
1380 | } |
||
1381 | |||
1382 | if (v->xres_virtual * nom / den >= 8192) { |
||
1383 | v->xres_virtual = 8192 * den / nom - 16; |
||
1384 | } |
||
1385 | |||
1386 | if (v->xres_virtual < v->xres) |
||
1387 | return -EINVAL; |
||
1388 | |||
1389 | if (v->yres_virtual < v->yres) |
||
1390 | return -EINVAL; |
||
1391 | |||
1392 | return 0; |
||
1393 | } |
||
1394 | |||
1395 | |||
1396 | static int radeonfb_check_var (struct fb_var_screeninfo *var, struct fb_info *info) |
||
1397 | { |
||
1398 | struct radeonfb_info *rinfo = (struct radeonfb_info *) info->par; |
||
1399 | struct fb_var_screeninfo v; |
||
1400 | int nom, den; |
||
1401 | |||
1402 | memcpy (&v, var, sizeof (v)); |
||
1403 | |||
1404 | switch (v.bits_per_pixel) { |
||
1405 | case 0 ... 8: |
||
1406 | v.bits_per_pixel = 8; |
||
1407 | break; |
||
1408 | case 9 ... 16: |
||
1409 | v.bits_per_pixel = 16; |
||
1410 | break; |
||
1411 | case 17 ... 24: |
||
1412 | #if 0 /* Doesn't seem to work */ |
||
1413 | v.bits_per_pixel = 24; |
||
1414 | break; |
||
1415 | #endif |
||
1416 | return -EINVAL; |
||
1417 | case 25 ... 32: |
||
1418 | v.bits_per_pixel = 32; |
||
1419 | break; |
||
1420 | default: |
||
1421 | return -EINVAL; |
||
1422 | } |
||
1423 | |||
1424 | switch (var_to_depth(&v)) { |
||
1425 | case 8: |
||
1426 | nom = den = 1; |
||
1427 | v.red.offset = v.green.offset = v.blue.offset = 0; |
||
1428 | v.red.length = v.green.length = v.blue.length = 8; |
||
1429 | v.transp.offset = v.transp.length = 0; |
||
1430 | break; |
||
1431 | case 15: |
||
1432 | nom = 2; |
||
1433 | den = 1; |
||
1434 | v.red.offset = 10; |
||
1435 | v.green.offset = 5; |
||
1436 | v.blue.offset = 0; |
||
1437 | v.red.length = v.green.length = v.blue.length = 5; |
||
1438 | v.transp.offset = v.transp.length = 0; |
||
1439 | break; |
||
1440 | case 16: |
||
1441 | nom = 2; |
||
1442 | den = 1; |
||
1443 | v.red.offset = 11; |
||
1444 | v.green.offset = 5; |
||
1445 | v.blue.offset = 0; |
||
1446 | v.red.length = 5; |
||
1447 | v.green.length = 6; |
||
1448 | v.blue.length = 5; |
||
1449 | v.transp.offset = v.transp.length = 0; |
||
1450 | break; |
||
1451 | case 24: |
||
1452 | nom = 4; |
||
1453 | den = 1; |
||
1454 | v.red.offset = 16; |
||
1455 | v.green.offset = 8; |
||
1456 | v.blue.offset = 0; |
||
1457 | v.red.length = v.blue.length = v.green.length = 8; |
||
1458 | v.transp.offset = v.transp.length = 0; |
||
1459 | break; |
||
1460 | case 32: |
||
1461 | nom = 4; |
||
1462 | den = 1; |
||
1463 | v.red.offset = 16; |
||
1464 | v.green.offset = 8; |
||
1465 | v.blue.offset = 0; |
||
1466 | v.red.length = v.blue.length = v.green.length = 8; |
||
1467 | v.transp.offset = 24; |
||
1468 | v.transp.length = 8; |
||
1469 | break; |
||
1470 | default: |
||
1471 | printk ("radeonfb: mode %dx%dx%d rejected, color depth invalid\n", |
||
1472 | var->xres, var->yres, var->bits_per_pixel); |
||
1473 | return -EINVAL; |
||
1474 | } |
||
1475 | |||
1476 | if (radeon_do_maximize(rinfo, var, &v, nom, den) < 0) |
||
1477 | return -EINVAL; |
||
1478 | |||
1479 | if (v.xoffset < 0) |
||
1480 | v.xoffset = 0; |
||
1481 | if (v.yoffset < 0) |
||
1482 | v.yoffset = 0; |
||
1483 | |||
1484 | if (v.xoffset > v.xres_virtual - v.xres) |
||
1485 | v.xoffset = v.xres_virtual - v.xres - 1; |
||
1486 | |||
1487 | if (v.yoffset > v.yres_virtual - v.yres) |
||
1488 | v.yoffset = v.yres_virtual - v.yres - 1; |
||
1489 | |||
1490 | v.red.msb_right = v.green.msb_right = v.blue.msb_right = |
||
1491 | v.transp.offset = v.transp.length = |
||
1492 | v.transp.msb_right = 0; |
||
1493 | |||
1494 | if (noaccel) |
||
1495 | v.accel_flags = 0; |
||
1496 | |||
1497 | memcpy(var, &v, sizeof(v)); |
||
1498 | |||
1499 | return 0; |
||
1500 | } |
||
1501 | |||
1502 | |||
1503 | static int radeonfb_pan_display (struct fb_var_screeninfo *var, |
||
1504 | struct fb_info *info) |
||
1505 | { |
||
1506 | struct radeonfb_info *rinfo = (struct radeonfb_info *) info; |
||
1507 | |||
1508 | if ((var->xoffset + var->xres > var->xres_virtual) |
||
1509 | || (var->yoffset + var->yres > var->yres_virtual)) |
||
1510 | return -EINVAL; |
||
1511 | |||
1512 | if (rinfo->asleep) |
||
1513 | return 0; |
||
1514 | |||
1515 | OUTREG(CRTC_OFFSET, ((var->yoffset * var->xres_virtual + var->xoffset) |
||
1516 | * var->bits_per_pixel / 8) & ~7); |
||
1517 | return 0; |
||
1518 | } |
||
1519 | |||
1520 | |||
1521 | static int radeonfb_ioctl (struct inode *inode, struct file *file, unsigned int cmd, |
||
1522 | unsigned long arg, struct fb_info *info) |
||
1523 | { |
||
1524 | struct radeonfb_info *rinfo = (struct radeonfb_info *) info; |
||
1525 | unsigned int tmp; |
||
1526 | u32 value = 0; |
||
1527 | int rc; |
||
1528 | |||
1529 | switch (cmd) { |
||
1530 | /* |
||
1531 | * TODO: set mirror accordingly for non-Mobility chipsets with 2 CRTC's |
||
1532 | */ |
||
1533 | case FBIO_RADEON_SET_MIRROR: |
||
1534 | switch (rinfo->arch) { |
||
1535 | case RADEON_R100: |
||
1536 | case RADEON_RV100: |
||
1537 | case RADEON_R200: |
||
1538 | case RADEON_RV200: |
||
1539 | case RADEON_RV250: |
||
1540 | case RADEON_R300: |
||
1541 | return -EINVAL; |
||
1542 | default: |
||
1543 | /* RADEON M6, RADEON_M7, RADEON_M9 */ |
||
1544 | break; |
||
1545 | } |
||
1546 | |||
1547 | rc = 0; |
||
475 | giacomo | 1548 | value = *(__u32*)arg; //get_user(value, (__u32*)arg); |
472 | giacomo | 1549 | |
1550 | if (rc) |
||
1551 | return rc; |
||
1552 | |||
1553 | if (value & 0x01) { |
||
1554 | tmp = INREG(LVDS_GEN_CNTL); |
||
1555 | |||
1556 | tmp |= (LVDS_ON | LVDS_BLON); |
||
1557 | } else { |
||
1558 | tmp = INREG(LVDS_GEN_CNTL); |
||
1559 | |||
1560 | tmp &= ~(LVDS_ON | LVDS_BLON); |
||
1561 | } |
||
1562 | |||
1563 | OUTREG(LVDS_GEN_CNTL, tmp); |
||
1564 | |||
1565 | if (value & 0x02) { |
||
1566 | tmp = INREG(CRTC_EXT_CNTL); |
||
1567 | tmp |= CRTC_CRT_ON; |
||
1568 | |||
1569 | mirror = 1; |
||
1570 | } else { |
||
1571 | tmp = INREG(CRTC_EXT_CNTL); |
||
1572 | tmp &= ~CRTC_CRT_ON; |
||
1573 | |||
1574 | mirror = 0; |
||
1575 | } |
||
1576 | |||
1577 | OUTREG(CRTC_EXT_CNTL, tmp); |
||
1578 | |||
1579 | break; |
||
1580 | case FBIO_RADEON_GET_MIRROR: |
||
1581 | switch (rinfo->arch) { |
||
1582 | case RADEON_R100: |
||
1583 | case RADEON_RV100: |
||
1584 | case RADEON_R200: |
||
1585 | case RADEON_RV200: |
||
1586 | case RADEON_RV250: |
||
1587 | case RADEON_R300: |
||
1588 | return -EINVAL; |
||
1589 | default: |
||
1590 | /* RADEON M6, RADEON_M7, RADEON_M9 */ |
||
1591 | break; |
||
1592 | } |
||
1593 | |||
1594 | tmp = INREG(LVDS_GEN_CNTL); |
||
1595 | if ((LVDS_ON | LVDS_BLON) & tmp) |
||
1596 | value |= 0x01; |
||
1597 | |||
1598 | tmp = INREG(CRTC_EXT_CNTL); |
||
1599 | if (CRTC_CRT_ON & tmp) |
||
1600 | value |= 0x02; |
||
1601 | |||
475 | giacomo | 1602 | (__u32*)arg = value; |
1603 | return 0; |
||
472 | giacomo | 1604 | default: |
1605 | return -EINVAL; |
||
1606 | } |
||
1607 | |||
1608 | return -EINVAL; |
||
1609 | } |
||
1610 | |||
1611 | |||
1612 | static int radeonfb_blank (int blank, struct fb_info *info) |
||
1613 | { |
||
1614 | struct radeonfb_info *rinfo = (struct radeonfb_info *) info; |
||
1615 | u32 val = INREG(CRTC_EXT_CNTL); |
||
1616 | u32 val2 = INREG(LVDS_GEN_CNTL); |
||
1617 | |||
1618 | if (rinfo->asleep) |
||
1619 | return 0; |
||
1620 | |||
1621 | #ifdef CONFIG_PMAC_BACKLIGHT |
||
1622 | if (rinfo->dviDisp_type == MT_LCD && _machine == _MACH_Pmac) { |
||
1623 | set_backlight_enable(!blank); |
||
1624 | return 0; |
||
1625 | } |
||
1626 | #endif |
||
1627 | |||
1628 | /* reset it */ |
||
1629 | val &= ~(CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS | |
||
1630 | CRTC_VSYNC_DIS); |
||
1631 | val2 &= ~(LVDS_DISPLAY_DIS); |
||
1632 | |||
1633 | switch (blank) { |
||
1634 | case VESA_NO_BLANKING: |
||
1635 | break; |
||
1636 | case VESA_VSYNC_SUSPEND: |
||
1637 | val |= (CRTC_DISPLAY_DIS | CRTC_VSYNC_DIS); |
||
1638 | break; |
||
1639 | case VESA_HSYNC_SUSPEND: |
||
1640 | val |= (CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS); |
||
1641 | break; |
||
1642 | case VESA_POWERDOWN: |
||
1643 | val |= (CRTC_DISPLAY_DIS | CRTC_VSYNC_DIS | |
||
1644 | CRTC_HSYNC_DIS); |
||
1645 | val2 |= (LVDS_DISPLAY_DIS); |
||
1646 | break; |
||
1647 | } |
||
1648 | |||
1649 | switch (rinfo->dviDisp_type) { |
||
1650 | case MT_LCD: |
||
1651 | OUTREG(LVDS_GEN_CNTL, val2); |
||
1652 | break; |
||
1653 | case MT_CRT: |
||
1654 | default: |
||
1655 | OUTREG(CRTC_EXT_CNTL, val); |
||
1656 | break; |
||
1657 | } |
||
1658 | |||
1659 | return 0; |
||
1660 | } |
||
1661 | |||
1662 | |||
1663 | static int radeonfb_setcolreg (unsigned regno, unsigned red, unsigned green, |
||
1664 | unsigned blue, unsigned transp, struct fb_info *info) |
||
1665 | { |
||
1666 | struct radeonfb_info *rinfo = (struct radeonfb_info *) info; |
||
1667 | u32 pindex, vclk_cntl; |
||
1668 | unsigned int i; |
||
1669 | |||
1670 | if (regno > 255) |
||
1671 | return 1; |
||
1672 | |||
1673 | red >>= 8; |
||
1674 | green >>= 8; |
||
1675 | blue >>= 8; |
||
1676 | rinfo->palette[regno].red = red; |
||
1677 | rinfo->palette[regno].green = green; |
||
1678 | rinfo->palette[regno].blue = blue; |
||
1679 | |||
1680 | /* default */ |
||
1681 | pindex = regno; |
||
1682 | |||
1683 | if (!rinfo->asleep) { |
||
1684 | vclk_cntl = INPLL(VCLK_ECP_CNTL); |
||
1685 | OUTPLL(VCLK_ECP_CNTL, vclk_cntl & ~PIXCLK_DAC_ALWAYS_ONb); |
||
1686 | |||
1687 | if (rinfo->bpp == 16) { |
||
1688 | pindex = regno * 8; |
||
1689 | |||
1690 | if (rinfo->depth == 16 && regno > 63) |
||
1691 | return 1; |
||
1692 | if (rinfo->depth == 15 && regno > 31) |
||
1693 | return 1; |
||
1694 | |||
1695 | /* For 565, the green component is mixed one order below */ |
||
1696 | if (rinfo->depth == 16) { |
||
1697 | OUTREG(PALETTE_INDEX, pindex>>1); |
||
1698 | OUTREG(PALETTE_DATA, (rinfo->palette[regno>>1].red << 16) | |
||
1699 | (green << 8) | (rinfo->palette[regno>>1].blue)); |
||
1700 | green = rinfo->palette[regno<<1].green; |
||
1701 | } |
||
1702 | } |
||
1703 | |||
1704 | if (rinfo->depth != 16 || regno < 32) { |
||
1705 | OUTREG(PALETTE_INDEX, pindex); |
||
1706 | OUTREG(PALETTE_DATA, (red << 16) | (green << 8) | blue); |
||
1707 | } |
||
1708 | |||
1709 | OUTPLL(VCLK_ECP_CNTL, vclk_cntl); |
||
1710 | } |
||
1711 | if (regno < 16) { |
||
1712 | switch (rinfo->depth) { |
||
1713 | case 15: |
||
1714 | ((u16 *) (info->pseudo_palette))[regno] = |
||
1715 | (regno << 10) | (regno << 5) | regno; |
||
1716 | break; |
||
1717 | case 16: |
||
1718 | ((u16 *) (info->pseudo_palette))[regno] = |
||
1719 | (regno << 11) | (regno << 6) | regno; |
||
1720 | break; |
||
1721 | case 24: |
||
1722 | ((u32 *) (info->pseudo_palette))[regno] = |
||
1723 | (regno << 16) | (regno << 8) | regno; |
||
1724 | break; |
||
1725 | case 32: |
||
1726 | i = (regno << 8) | regno; |
||
1727 | ((u32 *) (info->pseudo_palette))[regno] = |
||
1728 | (i << 16) | i; |
||
1729 | break; |
||
1730 | } |
||
1731 | } |
||
1732 | return 0; |
||
1733 | } |
||
1734 | |||
1735 | |||
1736 | |||
1737 | static void radeon_save_state (struct radeonfb_info *rinfo, |
||
1738 | struct radeon_regs *save) |
||
1739 | { |
||
1740 | /* CRTC regs */ |
||
1741 | save->crtc_gen_cntl = INREG(CRTC_GEN_CNTL); |
||
1742 | save->crtc_ext_cntl = INREG(CRTC_EXT_CNTL); |
||
1743 | save->dac_cntl = INREG(DAC_CNTL); |
||
1744 | save->crtc_h_total_disp = INREG(CRTC_H_TOTAL_DISP); |
||
1745 | save->crtc_h_sync_strt_wid = INREG(CRTC_H_SYNC_STRT_WID); |
||
1746 | save->crtc_v_total_disp = INREG(CRTC_V_TOTAL_DISP); |
||
1747 | save->crtc_v_sync_strt_wid = INREG(CRTC_V_SYNC_STRT_WID); |
||
1748 | save->crtc_pitch = INREG(CRTC_PITCH); |
||
1749 | #if defined(__BIG_ENDIAN) |
||
1750 | save->surface_cntl = INREG(SURFACE_CNTL); |
||
1751 | #endif |
||
1752 | |||
1753 | /* FP regs */ |
||
1754 | save->fp_crtc_h_total_disp = INREG(FP_CRTC_H_TOTAL_DISP); |
||
1755 | save->fp_crtc_v_total_disp = INREG(FP_CRTC_V_TOTAL_DISP); |
||
1756 | save->fp_gen_cntl = INREG(FP_GEN_CNTL); |
||
1757 | save->fp_h_sync_strt_wid = INREG(FP_H_SYNC_STRT_WID); |
||
1758 | save->fp_horz_stretch = INREG(FP_HORZ_STRETCH); |
||
1759 | save->fp_v_sync_strt_wid = INREG(FP_V_SYNC_STRT_WID); |
||
1760 | save->fp_vert_stretch = INREG(FP_VERT_STRETCH); |
||
1761 | save->lvds_gen_cntl = INREG(LVDS_GEN_CNTL); |
||
1762 | save->lvds_pll_cntl = INREG(LVDS_PLL_CNTL); |
||
1763 | save->tmds_crc = INREG(TMDS_CRC); |
||
1764 | save->tmds_transmitter_cntl = INREG(TMDS_TRANSMITTER_CNTL); |
||
1765 | save->vclk_ecp_cntl = INPLL(VCLK_ECP_CNTL); |
||
1766 | } |
||
1767 | |||
1768 | |||
1769 | |||
1770 | static int radeonfb_set_par (struct fb_info *info) |
||
1771 | { |
||
1772 | struct radeonfb_info *rinfo = (struct radeonfb_info *)info->par; |
||
1773 | struct fb_var_screeninfo *mode = &info->var; |
||
1774 | struct radeon_regs newmode; |
||
1775 | int hTotal, vTotal, hSyncStart, hSyncEnd, |
||
1776 | hSyncPol, vSyncStart, vSyncEnd, vSyncPol, cSync; |
||
1777 | u8 hsync_adj_tab[] = {0, 0x12, 9, 9, 6, 5}; |
||
1778 | u8 hsync_fudge_fp[] = {2, 2, 0, 0, 5, 5}; |
||
1779 | u32 dotClock = 1000000000 / mode->pixclock, |
||
1780 | sync, h_sync_pol, v_sync_pol; |
||
1781 | int freq = dotClock / 10; /* x 100 */ |
||
1782 | int xclk_freq, vclk_freq, xclk_per_trans, xclk_per_trans_precise; |
||
1783 | int useable_precision, roff, ron; |
||
1784 | int min_bits, format = 0; |
||
1785 | int hsync_start, hsync_fudge, bytpp, hsync_wid, vsync_wid; |
||
1786 | int primary_mon = PRIMARY_MONITOR(rinfo); |
||
1787 | int depth = var_to_depth(mode); |
||
1788 | |||
1789 | rinfo->xres = mode->xres; |
||
1790 | rinfo->yres = mode->yres; |
||
1791 | rinfo->xres_virtual = mode->xres_virtual; |
||
1792 | rinfo->yres_virtual = mode->yres_virtual; |
||
1793 | rinfo->pixclock = mode->pixclock; |
||
1794 | |||
1795 | hSyncStart = mode->xres + mode->right_margin; |
||
1796 | hSyncEnd = hSyncStart + mode->hsync_len; |
||
1797 | hTotal = hSyncEnd + mode->left_margin; |
||
1798 | |||
1799 | vSyncStart = mode->yres + mode->lower_margin; |
||
1800 | vSyncEnd = vSyncStart + mode->vsync_len; |
||
1801 | vTotal = vSyncEnd + mode->upper_margin; |
||
1802 | |||
1803 | if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) { |
||
1804 | if (rinfo->panel_xres < mode->xres) |
||
1805 | rinfo->xres = mode->xres = rinfo->panel_xres; |
||
1806 | if (rinfo->panel_yres < mode->yres) |
||
1807 | rinfo->yres = mode->yres = rinfo->panel_yres; |
||
1808 | |||
1809 | hTotal = mode->xres + rinfo->hblank; |
||
1810 | hSyncStart = mode->xres + rinfo->hOver_plus; |
||
1811 | hSyncEnd = hSyncStart + rinfo->hSync_width; |
||
1812 | |||
1813 | vTotal = mode->yres + rinfo->vblank; |
||
1814 | vSyncStart = mode->yres + rinfo->vOver_plus; |
||
1815 | vSyncEnd = vSyncStart + rinfo->vSync_width; |
||
1816 | } |
||
1817 | |||
1818 | sync = mode->sync; |
||
1819 | h_sync_pol = sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1; |
||
1820 | v_sync_pol = sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1; |
||
1821 | |||
1822 | RTRACE("hStart = %d, hEnd = %d, hTotal = %d\n", |
||
1823 | hSyncStart, hSyncEnd, hTotal); |
||
1824 | RTRACE("vStart = %d, vEnd = %d, vTotal = %d\n", |
||
1825 | vSyncStart, vSyncEnd, vTotal); |
||
1826 | |||
1827 | hsync_wid = (hSyncEnd - hSyncStart) / 8; |
||
1828 | vsync_wid = vSyncEnd - vSyncStart; |
||
1829 | if (hsync_wid == 0) |
||
1830 | hsync_wid = 1; |
||
1831 | else if (hsync_wid > 0x3f) /* max */ |
||
1832 | hsync_wid = 0x3f; |
||
1833 | |||
1834 | if (vsync_wid == 0) |
||
1835 | vsync_wid = 1; |
||
1836 | else if (vsync_wid > 0x1f) /* max */ |
||
1837 | vsync_wid = 0x1f; |
||
1838 | |||
1839 | hSyncPol = mode->sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1; |
||
1840 | vSyncPol = mode->sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1; |
||
1841 | |||
1842 | cSync = mode->sync & FB_SYNC_COMP_HIGH_ACT ? (1 << 4) : 0; |
||
1843 | |||
1844 | format = radeon_get_dstbpp(depth); |
||
1845 | bytpp = mode->bits_per_pixel >> 3; |
||
1846 | |||
1847 | if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) |
||
1848 | hsync_fudge = hsync_fudge_fp[format-1]; |
||
1849 | else |
||
1850 | hsync_fudge = hsync_adj_tab[format-1]; |
||
1851 | |||
1852 | hsync_start = hSyncStart - 8 + hsync_fudge; |
||
1853 | |||
1854 | newmode.crtc_gen_cntl = CRTC_EXT_DISP_EN | CRTC_EN | |
||
1855 | (format << 8); |
||
1856 | |||
1857 | if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) { |
||
1858 | newmode.crtc_ext_cntl = VGA_ATI_LINEAR | XCRT_CNT_EN; |
||
1859 | if (mirror) |
||
1860 | newmode.crtc_ext_cntl |= CRTC_CRT_ON; |
||
1861 | |||
1862 | newmode.crtc_gen_cntl &= ~(CRTC_DBL_SCAN_EN | |
||
1863 | CRTC_INTERLACE_EN); |
||
1864 | } else { |
||
1865 | newmode.crtc_ext_cntl = VGA_ATI_LINEAR | XCRT_CNT_EN | |
||
1866 | CRTC_CRT_ON; |
||
1867 | } |
||
1868 | |||
1869 | newmode.dac_cntl = /* INREG(DAC_CNTL) | */ DAC_MASK_ALL | DAC_VGA_ADR_EN | |
||
1870 | DAC_8BIT_EN; |
||
1871 | |||
1872 | newmode.crtc_h_total_disp = ((((hTotal / 8) - 1) & 0x3ff) | |
||
1873 | (((mode->xres / 8) - 1) << 16)); |
||
1874 | |||
1875 | newmode.crtc_h_sync_strt_wid = ((hsync_start & 0x1fff) | |
||
1876 | (hsync_wid << 16) | (h_sync_pol << 23)); |
||
1877 | |||
1878 | newmode.crtc_v_total_disp = ((vTotal - 1) & 0xffff) | |
||
1879 | ((mode->yres - 1) << 16); |
||
1880 | |||
1881 | newmode.crtc_v_sync_strt_wid = (((vSyncStart - 1) & 0xfff) | |
||
1882 | (vsync_wid << 16) | (v_sync_pol << 23)); |
||
1883 | |||
1884 | newmode.crtc_pitch = (mode->xres_virtual >> 3); |
||
1885 | newmode.crtc_pitch |= (newmode.crtc_pitch << 16); |
||
1886 | |||
1887 | #if defined(__BIG_ENDIAN) |
||
1888 | /* |
||
1889 | * It looks like recent chips have a problem with SURFACE_CNTL, |
||
1890 | * setting SURF_TRANSLATION_DIS completely disables the |
||
1891 | * swapper as well, so we leave it unset now. |
||
1892 | */ |
||
1893 | newmode.surface_cntl = 0; |
||
1894 | |||
1895 | /* Setup swapping on both apertures, though we currently |
||
1896 | * only use aperture 0, enabling swapper on aperture 1 |
||
1897 | * won't harm |
||
1898 | */ |
||
1899 | switch (mode->bits_per_pixel) { |
||
1900 | case 16: |
||
1901 | newmode.surface_cntl |= NONSURF_AP0_SWP_16BPP; |
||
1902 | newmode.surface_cntl |= NONSURF_AP1_SWP_16BPP; |
||
1903 | break; |
||
1904 | case 24: |
||
1905 | case 32: |
||
1906 | newmode.surface_cntl |= NONSURF_AP0_SWP_32BPP; |
||
1907 | newmode.surface_cntl |= NONSURF_AP1_SWP_32BPP; |
||
1908 | break; |
||
1909 | } |
||
1910 | #endif |
||
1911 | |||
1912 | rinfo->pitch = ((mode->xres_virtual * ((mode->bits_per_pixel + 1) / 8) + 0x3f) |
||
1913 | & ~(0x3f)) / 64; |
||
1914 | |||
1915 | RTRACE("h_total_disp = 0x%x\t hsync_strt_wid = 0x%x\n", |
||
1916 | newmode.crtc_h_total_disp, newmode.crtc_h_sync_strt_wid); |
||
1917 | RTRACE("v_total_disp = 0x%x\t vsync_strt_wid = 0x%x\n", |
||
1918 | newmode.crtc_v_total_disp, newmode.crtc_v_sync_strt_wid); |
||
1919 | |||
1920 | newmode.xres = mode->xres; |
||
1921 | newmode.yres = mode->yres; |
||
1922 | |||
1923 | rinfo->bpp = mode->bits_per_pixel; |
||
1924 | rinfo->depth = depth; |
||
1925 | |||
1926 | if (freq > rinfo->pll.ppll_max) |
||
1927 | freq = rinfo->pll.ppll_max; |
||
1928 | if (freq*12 < rinfo->pll.ppll_min) |
||
1929 | freq = rinfo->pll.ppll_min / 12; |
||
1930 | |||
1931 | { |
||
1932 | struct { |
||
1933 | int divider; |
||
1934 | int bitvalue; |
||
1935 | } *post_div, |
||
1936 | post_divs[] = { |
||
1937 | { 1, 0 }, |
||
1938 | { 2, 1 }, |
||
1939 | { 4, 2 }, |
||
1940 | { 8, 3 }, |
||
1941 | { 3, 4 }, |
||
1942 | { 16, 5 }, |
||
1943 | { 6, 6 }, |
||
1944 | { 12, 7 }, |
||
1945 | { 0, 0 }, |
||
1946 | }; |
||
1947 | |||
1948 | for (post_div = &post_divs[0]; post_div->divider; ++post_div) { |
||
1949 | rinfo->pll_output_freq = post_div->divider * freq; |
||
1950 | if (rinfo->pll_output_freq >= rinfo->pll.ppll_min && |
||
1951 | rinfo->pll_output_freq <= rinfo->pll.ppll_max) |
||
1952 | break; |
||
1953 | } |
||
1954 | |||
1955 | rinfo->post_div = post_div->divider; |
||
1956 | rinfo->fb_div = round_div(rinfo->pll.ref_div*rinfo->pll_output_freq, |
||
1957 | rinfo->pll.ref_clk); |
||
1958 | newmode.ppll_ref_div = rinfo->pll.ref_div; |
||
1959 | newmode.ppll_div_3 = rinfo->fb_div | (post_div->bitvalue << 16); |
||
1960 | } |
||
1961 | newmode.vclk_ecp_cntl = rinfo->init_state.vclk_ecp_cntl; |
||
1962 | |||
1963 | #ifdef CONFIG_PPC_OF |
||
1964 | /* Gross hack for iBook with M7 until I find out a proper fix */ |
||
1965 | if (machine_is_compatible("PowerBook4,3") && rinfo->arch == RADEON_M7) |
||
1966 | newmode.ppll_div_3 = 0x000600ad; |
||
1967 | #endif /* CONFIG_PPC_OF */ |
||
1968 | |||
1969 | RTRACE("post div = 0x%x\n", rinfo->post_div); |
||
1970 | RTRACE("fb_div = 0x%x\n", rinfo->fb_div); |
||
1971 | RTRACE("ppll_div_3 = 0x%x\n", newmode.ppll_div_3); |
||
1972 | |||
1973 | /* DDA */ |
||
1974 | vclk_freq = round_div(rinfo->pll.ref_clk * rinfo->fb_div, |
||
1975 | rinfo->pll.ref_div * rinfo->post_div); |
||
1976 | xclk_freq = rinfo->pll.xclk; |
||
1977 | |||
1978 | xclk_per_trans = round_div(xclk_freq * 128, vclk_freq * mode->bits_per_pixel); |
||
1979 | |||
1980 | min_bits = min_bits_req(xclk_per_trans); |
||
1981 | useable_precision = min_bits + 1; |
||
1982 | |||
1983 | xclk_per_trans_precise = round_div((xclk_freq * 128) << (11 - useable_precision), |
||
1984 | vclk_freq * mode->bits_per_pixel); |
||
1985 | |||
1986 | ron = (4 * rinfo->ram.mb + 3 * _max(rinfo->ram.trcd - 2, 0) + |
||
1987 | 2 * rinfo->ram.trp + rinfo->ram.twr + rinfo->ram.cl + rinfo->ram.tr2w + |
||
1988 | xclk_per_trans) << (11 - useable_precision); |
||
1989 | roff = xclk_per_trans_precise * (32 - 4); |
||
1990 | |||
1991 | RTRACE("ron = %d, roff = %d\n", ron, roff); |
||
1992 | RTRACE("vclk_freq = %d, per = %d\n", vclk_freq, xclk_per_trans_precise); |
||
1993 | |||
1994 | if ((ron + rinfo->ram.rloop) >= roff) { |
||
1995 | printk("radeonfb: error ron out of range\n"); |
||
1996 | return -EINVAL; |
||
1997 | } |
||
1998 | |||
1999 | newmode.dda_config = (xclk_per_trans_precise | |
||
2000 | (useable_precision << 16) | |
||
2001 | (rinfo->ram.rloop << 20)); |
||
2002 | newmode.dda_on_off = (ron << 16) | roff; |
||
2003 | |||
2004 | if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) { |
||
2005 | unsigned int hRatio, vRatio; |
||
2006 | |||
2007 | /* We force the pixel clock to be always enabled. Allowing it |
||
2008 | * to be power managed during blanking would save power, but has |
||
2009 | * nasty interactions with the 2D engine & sleep code that haven't |
||
2010 | * been solved yet. --BenH |
||
2011 | */ |
||
2012 | newmode.vclk_ecp_cntl &= ~PIXCLK_DAC_ALWAYS_ONb; |
||
2013 | |||
2014 | if (mode->xres > rinfo->panel_xres) |
||
2015 | mode->xres = rinfo->panel_xres; |
||
2016 | if (mode->yres > rinfo->panel_yres) |
||
2017 | mode->yres = rinfo->panel_yres; |
||
2018 | |||
2019 | newmode.fp_horz_stretch = (((rinfo->panel_xres / 8) - 1) |
||
2020 | << HORZ_PANEL_SHIFT); |
||
2021 | newmode.fp_vert_stretch = ((rinfo->panel_yres - 1) |
||
2022 | << VERT_PANEL_SHIFT); |
||
2023 | |||
2024 | if (mode->xres != rinfo->panel_xres) { |
||
2025 | hRatio = round_div(mode->xres * HORZ_STRETCH_RATIO_MAX, |
||
2026 | rinfo->panel_xres); |
||
2027 | newmode.fp_horz_stretch = (((((unsigned long)hRatio) & HORZ_STRETCH_RATIO_MASK)) | |
||
2028 | (newmode.fp_horz_stretch & |
||
2029 | (HORZ_PANEL_SIZE | HORZ_FP_LOOP_STRETCH | |
||
2030 | HORZ_AUTO_RATIO_INC))); |
||
2031 | newmode.fp_horz_stretch |= (HORZ_STRETCH_BLEND | |
||
2032 | HORZ_STRETCH_ENABLE); |
||
2033 | } |
||
2034 | newmode.fp_horz_stretch &= ~HORZ_AUTO_RATIO; |
||
2035 | |||
2036 | if (mode->yres != rinfo->panel_yres) { |
||
2037 | vRatio = round_div(mode->yres * VERT_STRETCH_RATIO_MAX, |
||
2038 | rinfo->panel_yres); |
||
2039 | newmode.fp_vert_stretch = (((((unsigned long)vRatio) & VERT_STRETCH_RATIO_MASK)) | |
||
2040 | (newmode.fp_vert_stretch & |
||
2041 | (VERT_PANEL_SIZE | VERT_STRETCH_RESERVED))); |
||
2042 | newmode.fp_vert_stretch |= (VERT_STRETCH_BLEND | |
||
2043 | VERT_STRETCH_ENABLE); |
||
2044 | } |
||
2045 | newmode.fp_vert_stretch &= ~VERT_AUTO_RATIO_EN; |
||
2046 | |||
2047 | newmode.fp_gen_cntl = (rinfo->init_state.fp_gen_cntl & (u32) |
||
2048 | ~(FP_SEL_CRTC2 | |
||
2049 | FP_RMX_HVSYNC_CONTROL_EN | |
||
2050 | FP_DFP_SYNC_SEL | |
||
2051 | FP_CRT_SYNC_SEL | |
||
2052 | FP_CRTC_LOCK_8DOT | |
||
2053 | FP_USE_SHADOW_EN | |
||
2054 | FP_CRTC_USE_SHADOW_VEND | |
||
2055 | FP_CRT_SYNC_ALT)); |
||
2056 | |||
2057 | newmode.fp_gen_cntl |= (FP_CRTC_DONT_SHADOW_VPAR | |
||
2058 | FP_CRTC_DONT_SHADOW_HEND); |
||
2059 | |||
2060 | newmode.lvds_gen_cntl = rinfo->init_state.lvds_gen_cntl; |
||
2061 | newmode.lvds_pll_cntl = rinfo->init_state.lvds_pll_cntl; |
||
2062 | newmode.tmds_crc = rinfo->init_state.tmds_crc; |
||
2063 | newmode.tmds_transmitter_cntl = rinfo->init_state.tmds_transmitter_cntl; |
||
2064 | |||
2065 | if (primary_mon == MT_LCD) { |
||
2066 | newmode.lvds_gen_cntl |= (LVDS_ON | LVDS_BLON); |
||
2067 | newmode.fp_gen_cntl &= ~(FP_FPON | FP_TMDS_EN); |
||
2068 | } else { |
||
2069 | /* DFP */ |
||
2070 | newmode.fp_gen_cntl |= (FP_FPON | FP_TMDS_EN); |
||
2071 | newmode.tmds_transmitter_cntl = (TMDS_RAN_PAT_RST | |
||
2072 | ICHCSEL | TMDS_PLL_EN) & |
||
2073 | ~(TMDS_PLLRST); |
||
2074 | newmode.crtc_ext_cntl &= ~CRTC_CRT_ON; |
||
2075 | } |
||
2076 | |||
2077 | newmode.fp_crtc_h_total_disp = (((rinfo->hblank / 8) & 0x3ff) | |
||
2078 | (((mode->xres / 8) - 1) << 16)); |
||
2079 | newmode.fp_crtc_v_total_disp = (rinfo->vblank & 0xffff) | |
||
2080 | ((mode->yres - 1) << 16); |
||
2081 | newmode.fp_h_sync_strt_wid = ((rinfo->hOver_plus & 0x1fff) | |
||
2082 | (hsync_wid << 16) | (h_sync_pol << 23)); |
||
2083 | newmode.fp_v_sync_strt_wid = ((rinfo->vOver_plus & 0xfff) | |
||
2084 | (vsync_wid << 16) | (v_sync_pol << 23)); |
||
2085 | } |
||
2086 | |||
2087 | /* do it! */ |
||
2088 | if (!rinfo->asleep) { |
||
2089 | radeon_write_mode (rinfo, &newmode); |
||
2090 | /* (re)initialize the engine */ |
||
2091 | if (!noaccel) |
||
2092 | radeon_engine_init (rinfo); |
||
2093 | |||
2094 | } |
||
2095 | /* Update fix */ |
||
2096 | info->fix.line_length = rinfo->pitch*64; |
||
2097 | info->fix.visual = rinfo->depth == 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR; |
||
2098 | |||
2099 | #ifdef CONFIG_BOOTX_TEXT |
||
2100 | /* Update debug text engine */ |
||
2101 | btext_update_display(rinfo->fb_base_phys, mode->xres, mode->yres, |
||
2102 | rinfo->depth, rinfo->pitch*64); |
||
2103 | #endif |
||
2104 | |||
2105 | return 0; |
||
2106 | } |
||
2107 | |||
2108 | |||
2109 | static void radeon_write_mode (struct radeonfb_info *rinfo, |
||
2110 | struct radeon_regs *mode) |
||
2111 | { |
||
2112 | int i; |
||
2113 | int primary_mon = PRIMARY_MONITOR(rinfo); |
||
2114 | |||
2115 | radeonfb_blank(VESA_POWERDOWN, (struct fb_info *)rinfo); |
||
2116 | |||
2117 | |||
2118 | if (rinfo->arch == RADEON_M6) { |
||
2119 | for (i=0; i<8; i++) |
||
2120 | OUTREG(common_regs_m6[i].reg, common_regs_m6[i].val); |
||
2121 | } else { |
||
2122 | for (i=0; i<9; i++) |
||
2123 | OUTREG(common_regs[i].reg, common_regs[i].val); |
||
2124 | } |
||
2125 | |||
2126 | OUTREG(CRTC_GEN_CNTL, mode->crtc_gen_cntl); |
||
2127 | OUTREGP(CRTC_EXT_CNTL, mode->crtc_ext_cntl, |
||
2128 | CRTC_HSYNC_DIS | CRTC_VSYNC_DIS | CRTC_DISPLAY_DIS); |
||
2129 | OUTREGP(DAC_CNTL, mode->dac_cntl, DAC_RANGE_CNTL | DAC_BLANKING); |
||
2130 | OUTREG(CRTC_H_TOTAL_DISP, mode->crtc_h_total_disp); |
||
2131 | OUTREG(CRTC_H_SYNC_STRT_WID, mode->crtc_h_sync_strt_wid); |
||
2132 | OUTREG(CRTC_V_TOTAL_DISP, mode->crtc_v_total_disp); |
||
2133 | OUTREG(CRTC_V_SYNC_STRT_WID, mode->crtc_v_sync_strt_wid); |
||
2134 | OUTREG(CRTC_OFFSET, 0); |
||
2135 | OUTREG(CRTC_OFFSET_CNTL, 0); |
||
2136 | OUTREG(CRTC_PITCH, mode->crtc_pitch); |
||
2137 | |||
2138 | #if defined(__BIG_ENDIAN) |
||
2139 | OUTREG(SURFACE_CNTL, mode->surface_cntl); |
||
2140 | #endif |
||
2141 | |||
2142 | while ((INREG(CLOCK_CNTL_INDEX) & PPLL_DIV_SEL_MASK) != |
||
2143 | PPLL_DIV_SEL_MASK) { |
||
2144 | OUTREGP(CLOCK_CNTL_INDEX, PPLL_DIV_SEL_MASK, 0xffff); |
||
2145 | } |
||
2146 | |||
2147 | OUTPLLP(PPLL_CNTL, PPLL_RESET, 0xffff); |
||
2148 | |||
2149 | while ((INPLL(PPLL_REF_DIV) & PPLL_REF_DIV_MASK) != |
||
2150 | (mode->ppll_ref_div & PPLL_REF_DIV_MASK)) { |
||
2151 | OUTPLLP(PPLL_REF_DIV, mode->ppll_ref_div, ~PPLL_REF_DIV_MASK); |
||
2152 | } |
||
2153 | |||
2154 | while ((INPLL(PPLL_DIV_3) & PPLL_FB3_DIV_MASK) != |
||
2155 | (mode->ppll_div_3 & PPLL_FB3_DIV_MASK)) { |
||
2156 | OUTPLLP(PPLL_DIV_3, mode->ppll_div_3, ~PPLL_FB3_DIV_MASK); |
||
2157 | } |
||
2158 | |||
2159 | while ((INPLL(PPLL_DIV_3) & PPLL_POST3_DIV_MASK) != |
||
2160 | (mode->ppll_div_3 & PPLL_POST3_DIV_MASK)) { |
||
2161 | OUTPLLP(PPLL_DIV_3, mode->ppll_div_3, ~PPLL_POST3_DIV_MASK); |
||
2162 | } |
||
2163 | |||
2164 | OUTPLL(HTOTAL_CNTL, 0); |
||
2165 | |||
2166 | OUTPLLP(PPLL_CNTL, 0, ~PPLL_RESET); |
||
2167 | |||
2168 | // OUTREG(DDA_CONFIG, mode->dda_config); |
||
2169 | // OUTREG(DDA_ON_OFF, mode->dda_on_off); |
||
2170 | |||
2171 | if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) { |
||
2172 | OUTREG(FP_CRTC_H_TOTAL_DISP, mode->fp_crtc_h_total_disp); |
||
2173 | OUTREG(FP_CRTC_V_TOTAL_DISP, mode->fp_crtc_v_total_disp); |
||
2174 | OUTREG(FP_H_SYNC_STRT_WID, mode->fp_h_sync_strt_wid); |
||
2175 | OUTREG(FP_V_SYNC_STRT_WID, mode->fp_v_sync_strt_wid); |
||
2176 | OUTREG(FP_HORZ_STRETCH, mode->fp_horz_stretch); |
||
2177 | OUTREG(FP_VERT_STRETCH, mode->fp_vert_stretch); |
||
2178 | OUTREG(FP_GEN_CNTL, mode->fp_gen_cntl); |
||
2179 | OUTREG(TMDS_CRC, mode->tmds_crc); |
||
2180 | OUTREG(TMDS_TRANSMITTER_CNTL, mode->tmds_transmitter_cntl); |
||
2181 | |||
2182 | if (primary_mon == MT_LCD) { |
||
2183 | unsigned int tmp = INREG(LVDS_GEN_CNTL); |
||
2184 | |||
2185 | mode->lvds_gen_cntl &= ~LVDS_STATE_MASK; |
||
2186 | mode->lvds_gen_cntl |= (rinfo->init_state.lvds_gen_cntl & LVDS_STATE_MASK); |
||
2187 | |||
2188 | if ((tmp & (LVDS_ON | LVDS_BLON)) == |
||
2189 | (mode->lvds_gen_cntl & (LVDS_ON | LVDS_BLON))) { |
||
2190 | OUTREG(LVDS_GEN_CNTL, mode->lvds_gen_cntl); |
||
2191 | } else { |
||
2192 | if (mode->lvds_gen_cntl & (LVDS_ON | LVDS_BLON)) { |
||
2193 | udelay(1000); |
||
2194 | OUTREG(LVDS_GEN_CNTL, mode->lvds_gen_cntl); |
||
2195 | } else { |
||
2196 | OUTREG(LVDS_GEN_CNTL, mode->lvds_gen_cntl | |
||
2197 | LVDS_BLON); |
||
2198 | udelay(1000); |
||
2199 | OUTREG(LVDS_GEN_CNTL, mode->lvds_gen_cntl); |
||
2200 | } |
||
2201 | } |
||
2202 | } |
||
2203 | } |
||
2204 | |||
2205 | radeonfb_blank(VESA_NO_BLANKING, (struct fb_info *)rinfo); |
||
2206 | |||
2207 | OUTPLL(VCLK_ECP_CNTL, mode->vclk_ecp_cntl); |
||
2208 | |||
2209 | return; |
||
2210 | } |
||
2211 | |||
2212 | static struct fb_ops radeonfb_ops = { |
||
2213 | .owner = THIS_MODULE, |
||
2214 | .fb_check_var = radeonfb_check_var, |
||
2215 | .fb_set_par = radeonfb_set_par, |
||
2216 | .fb_setcolreg = radeonfb_setcolreg, |
||
2217 | .fb_pan_display = radeonfb_pan_display, |
||
2218 | .fb_blank = radeonfb_blank, |
||
2219 | .fb_ioctl = radeonfb_ioctl, |
||
2220 | #if 0 |
||
2221 | .fb_fillrect = radeonfb_fillrect, |
||
2222 | .fb_copyarea = radeonfb_copyarea, |
||
2223 | .fb_imageblit = radeonfb_imageblit, |
||
2224 | .fb_rasterimg = radeonfb_rasterimg, |
||
2225 | #else |
||
2226 | .fb_fillrect = cfb_fillrect, |
||
2227 | .fb_copyarea = cfb_copyarea, |
||
2228 | .fb_imageblit = cfb_imageblit, |
||
2229 | #endif |
||
2230 | .fb_cursor = soft_cursor, |
||
2231 | }; |
||
2232 | |||
2233 | |||
2234 | static int __devinit radeon_set_fbinfo (struct radeonfb_info *rinfo) |
||
2235 | { |
||
2236 | struct fb_info *info; |
||
2237 | |||
2238 | info = &rinfo->info; |
||
2239 | |||
2240 | info->currcon = -1; |
||
2241 | info->par = rinfo; |
||
2242 | info->pseudo_palette = rinfo->pseudo_palette; |
||
2243 | info->flags = FBINFO_FLAG_DEFAULT; |
||
2244 | info->fbops = &radeonfb_ops; |
||
2245 | info->display_fg = NULL; |
||
2246 | info->screen_base = (char *)rinfo->fb_base; |
||
2247 | |||
2248 | /* Fill fix common fields */ |
||
2249 | strncpy(info->fix.id, rinfo->name, sizeof(info->fix.id)); |
||
2250 | info->fix.smem_start = rinfo->fb_base_phys; |
||
2251 | info->fix.smem_len = rinfo->video_ram; |
||
2252 | info->fix.type = FB_TYPE_PACKED_PIXELS; |
||
2253 | info->fix.visual = FB_VISUAL_PSEUDOCOLOR; |
||
2254 | info->fix.xpanstep = 8; |
||
2255 | info->fix.ypanstep = 1; |
||
2256 | info->fix.ywrapstep = 0; |
||
2257 | info->fix.type_aux = 0; |
||
2258 | info->fix.mmio_start = rinfo->mmio_base_phys; |
||
2259 | info->fix.mmio_len = RADEON_REGSIZE; |
||
2260 | if (noaccel) |
||
2261 | info->fix.accel = FB_ACCEL_NONE; |
||
2262 | else |
||
2263 | info->fix.accel = FB_ACCEL_ATI_RADEON; |
||
2264 | |||
2265 | if (radeon_init_disp (rinfo) < 0) |
||
2266 | return -1; |
||
2267 | |||
2268 | return 0; |
||
2269 | } |
||
2270 | |||
2271 | |||
2272 | #ifdef CONFIG_PMAC_BACKLIGHT |
||
2273 | |||
2274 | /* TODO: Dbl check these tables, we don't go up to full ON backlight |
||
2275 | * in these, possibly because we noticed MacOS doesn't, but I'd prefer |
||
2276 | * having some more official numbers from ATI |
||
2277 | */ |
||
2278 | static int backlight_conv_m6[] = { |
||
2279 | 0xff, 0xc0, 0xb5, 0xaa, 0x9f, 0x94, 0x89, 0x7e, |
||
2280 | 0x73, 0x68, 0x5d, 0x52, 0x47, 0x3c, 0x31, 0x24 |
||
2281 | }; |
||
2282 | static int backlight_conv_m7[] = { |
||
2283 | 0x00, 0x3f, 0x4a, 0x55, 0x60, 0x6b, 0x76, 0x81, |
||
2284 | 0x8c, 0x97, 0xa2, 0xad, 0xb8, 0xc3, 0xce, 0xd9 |
||
2285 | }; |
||
2286 | |||
2287 | #define BACKLIGHT_LVDS_OFF |
||
2288 | #undef BACKLIGHT_DAC_OFF |
||
2289 | |||
2290 | /* We turn off the LCD completely instead of just dimming the backlight. |
||
2291 | * This provides some greater power saving and the display is useless |
||
2292 | * without backlight anyway. |
||
2293 | */ |
||
2294 | |||
2295 | static int radeon_set_backlight_enable(int on, int level, void *data) |
||
2296 | { |
||
2297 | struct radeonfb_info *rinfo = (struct radeonfb_info *)data; |
||
2298 | unsigned int lvds_gen_cntl = INREG(LVDS_GEN_CNTL); |
||
2299 | int* conv_table; |
||
2300 | |||
2301 | /* Pardon me for that hack... maybe some day we can figure |
||
2302 | * out in what direction backlight should work on a given |
||
2303 | * panel ? |
||
2304 | */ |
||
2305 | if ((rinfo->arch == RADEON_M7 || rinfo->arch == RADEON_M9) |
||
2306 | && !machine_is_compatible("PowerBook4,3")) |
||
2307 | conv_table = backlight_conv_m7; |
||
2308 | else |
||
2309 | conv_table = backlight_conv_m6; |
||
2310 | |||
2311 | lvds_gen_cntl |= (LVDS_BL_MOD_EN | LVDS_BLON); |
||
2312 | if (on && (level > BACKLIGHT_OFF)) { |
||
2313 | lvds_gen_cntl |= LVDS_DIGON; |
||
2314 | if (!lvds_gen_cntl & LVDS_ON) { |
||
2315 | lvds_gen_cntl &= ~LVDS_BLON; |
||
2316 | OUTREG(LVDS_GEN_CNTL, lvds_gen_cntl); |
||
2317 | (void)INREG(LVDS_GEN_CNTL); |
||
2318 | mdelay(10); |
||
2319 | lvds_gen_cntl |= LVDS_BLON; |
||
2320 | OUTREG(LVDS_GEN_CNTL, lvds_gen_cntl); |
||
2321 | } |
||
2322 | lvds_gen_cntl &= ~LVDS_BL_MOD_LEVEL_MASK; |
||
2323 | lvds_gen_cntl |= (conv_table[level] << |
||
2324 | LVDS_BL_MOD_LEVEL_SHIFT); |
||
2325 | lvds_gen_cntl |= (LVDS_ON | LVDS_EN); |
||
2326 | lvds_gen_cntl &= ~LVDS_DISPLAY_DIS; |
||
2327 | } else { |
||
2328 | lvds_gen_cntl &= ~LVDS_BL_MOD_LEVEL_MASK; |
||
2329 | lvds_gen_cntl |= (conv_table[0] << |
||
2330 | LVDS_BL_MOD_LEVEL_SHIFT); |
||
2331 | lvds_gen_cntl |= LVDS_DISPLAY_DIS; |
||
2332 | OUTREG(LVDS_GEN_CNTL, lvds_gen_cntl); |
||
2333 | udelay(10); |
||
2334 | lvds_gen_cntl &= ~(LVDS_ON | LVDS_EN | LVDS_BLON | LVDS_DIGON); |
||
2335 | } |
||
2336 | |||
2337 | OUTREG(LVDS_GEN_CNTL, lvds_gen_cntl); |
||
2338 | rinfo->init_state.lvds_gen_cntl &= ~LVDS_STATE_MASK; |
||
2339 | rinfo->init_state.lvds_gen_cntl |= (lvds_gen_cntl & LVDS_STATE_MASK); |
||
2340 | |||
2341 | return 0; |
||
2342 | } |
||
2343 | |||
2344 | static int radeon_set_backlight_level(int level, void *data) |
||
2345 | { |
||
2346 | return radeon_set_backlight_enable(1, level, data); |
||
2347 | } |
||
2348 | #endif /* CONFIG_PMAC_BACKLIGHT */ |
||
2349 | |||
2350 | |||
2351 | #ifdef CONFIG_PMAC_PBOOK |
||
2352 | |||
2353 | static u32 dbg_clk; |
||
2354 | |||
2355 | /* |
||
2356 | * Radeon M6 Power Management code. This code currently only supports |
||
2357 | * the mobile chips, it's based from some informations provided by ATI |
||
2358 | * along with hours of tracing of MacOS drivers |
||
2359 | */ |
||
2360 | |||
2361 | static void radeon_pm_save_regs(struct radeonfb_info *rinfo) |
||
2362 | { |
||
2363 | rinfo->save_regs[0] = INPLL(PLL_PWRMGT_CNTL); |
||
2364 | rinfo->save_regs[1] = INPLL(CLK_PWRMGT_CNTL); |
||
2365 | rinfo->save_regs[2] = INPLL(MCLK_CNTL); |
||
2366 | rinfo->save_regs[3] = INPLL(SCLK_CNTL); |
||
2367 | rinfo->save_regs[4] = INPLL(CLK_PIN_CNTL); |
||
2368 | rinfo->save_regs[5] = INPLL(VCLK_ECP_CNTL); |
||
2369 | rinfo->save_regs[6] = INPLL(PIXCLKS_CNTL); |
||
2370 | rinfo->save_regs[7] = INPLL(MCLK_MISC); |
||
2371 | rinfo->save_regs[8] = INPLL(P2PLL_CNTL); |
||
2372 | |||
2373 | rinfo->save_regs[9] = INREG(DISP_MISC_CNTL); |
||
2374 | rinfo->save_regs[10] = INREG(DISP_PWR_MAN); |
||
2375 | rinfo->save_regs[11] = INREG(LVDS_GEN_CNTL); |
||
2376 | rinfo->save_regs[12] = INREG(LVDS_PLL_CNTL); |
||
2377 | rinfo->save_regs[13] = INREG(TV_DAC_CNTL); |
||
2378 | rinfo->save_regs[14] = INREG(BUS_CNTL1); |
||
2379 | rinfo->save_regs[15] = INREG(CRTC_OFFSET_CNTL); |
||
2380 | rinfo->save_regs[16] = INREG(AGP_CNTL); |
||
2381 | rinfo->save_regs[17] = (INREG(CRTC_GEN_CNTL) & 0xfdffffff) | 0x04000000; |
||
2382 | rinfo->save_regs[18] = (INREG(CRTC2_GEN_CNTL) & 0xfdffffff) | 0x04000000; |
||
2383 | rinfo->save_regs[19] = INREG(GPIOPAD_A); |
||
2384 | rinfo->save_regs[20] = INREG(GPIOPAD_EN); |
||
2385 | rinfo->save_regs[21] = INREG(GPIOPAD_MASK); |
||
2386 | rinfo->save_regs[22] = INREG(ZV_LCDPAD_A); |
||
2387 | rinfo->save_regs[23] = INREG(ZV_LCDPAD_EN); |
||
2388 | rinfo->save_regs[24] = INREG(ZV_LCDPAD_MASK); |
||
2389 | rinfo->save_regs[25] = INREG(GPIO_VGA_DDC); |
||
2390 | rinfo->save_regs[26] = INREG(GPIO_DVI_DDC); |
||
2391 | rinfo->save_regs[27] = INREG(GPIO_MONID); |
||
2392 | rinfo->save_regs[28] = INREG(GPIO_CRT2_DDC); |
||
2393 | |||
2394 | rinfo->save_regs[29] = INREG(SURFACE_CNTL); |
||
2395 | rinfo->save_regs[30] = INREG(MC_FB_LOCATION); |
||
2396 | rinfo->save_regs[31] = INREG(DISPLAY_BASE_ADDR); |
||
2397 | rinfo->save_regs[32] = INREG(MC_AGP_LOCATION); |
||
2398 | rinfo->save_regs[33] = INREG(CRTC2_DISPLAY_BASE_ADDR); |
||
2399 | } |
||
2400 | |||
2401 | static void radeon_pm_restore_regs(struct radeonfb_info *rinfo) |
||
2402 | { |
||
2403 | OUTPLL(P2PLL_CNTL, rinfo->save_regs[8] & 0xFFFFFFFE); /* First */ |
||
2404 | |||
2405 | OUTPLL(PLL_PWRMGT_CNTL, rinfo->save_regs[0]); |
||
2406 | OUTPLL(CLK_PWRMGT_CNTL, rinfo->save_regs[1]); |
||
2407 | OUTPLL(MCLK_CNTL, rinfo->save_regs[2]); |
||
2408 | OUTPLL(SCLK_CNTL, rinfo->save_regs[3]); |
||
2409 | OUTPLL(CLK_PIN_CNTL, rinfo->save_regs[4]); |
||
2410 | OUTPLL(VCLK_ECP_CNTL, rinfo->save_regs[5]); |
||
2411 | OUTPLL(PIXCLKS_CNTL, rinfo->save_regs[6]); |
||
2412 | OUTPLL(MCLK_MISC, rinfo->save_regs[7]); |
||
2413 | |||
2414 | OUTREG(DISP_MISC_CNTL, rinfo->save_regs[9]); |
||
2415 | OUTREG(DISP_PWR_MAN, rinfo->save_regs[10]); |
||
2416 | OUTREG(LVDS_GEN_CNTL, rinfo->save_regs[11]); |
||
2417 | OUTREG(LVDS_PLL_CNTL,rinfo->save_regs[12]); |
||
2418 | OUTREG(TV_DAC_CNTL, rinfo->save_regs[13]); |
||
2419 | OUTREG(BUS_CNTL1, rinfo->save_regs[14]); |
||
2420 | OUTREG(CRTC_OFFSET_CNTL, rinfo->save_regs[15]); |
||
2421 | OUTREG(AGP_CNTL, rinfo->save_regs[16]); |
||
2422 | OUTREG(CRTC_GEN_CNTL, rinfo->save_regs[17]); |
||
2423 | OUTREG(CRTC2_GEN_CNTL, rinfo->save_regs[18]); |
||
2424 | |||
2425 | // wait VBL before that one ? |
||
2426 | OUTPLL(P2PLL_CNTL, rinfo->save_regs[8]); |
||
2427 | |||
2428 | OUTREG(GPIOPAD_A, rinfo->save_regs[19]); |
||
2429 | OUTREG(GPIOPAD_EN, rinfo->save_regs[20]); |
||
2430 | OUTREG(GPIOPAD_MASK, rinfo->save_regs[21]); |
||
2431 | OUTREG(ZV_LCDPAD_A, rinfo->save_regs[22]); |
||
2432 | OUTREG(ZV_LCDPAD_EN, rinfo->save_regs[23]); |
||
2433 | OUTREG(ZV_LCDPAD_MASK, rinfo->save_regs[24]); |
||
2434 | OUTREG(GPIO_VGA_DDC, rinfo->save_regs[25]); |
||
2435 | OUTREG(GPIO_DVI_DDC, rinfo->save_regs[26]); |
||
2436 | OUTREG(GPIO_MONID, rinfo->save_regs[27]); |
||
2437 | OUTREG(GPIO_CRT2_DDC, rinfo->save_regs[28]); |
||
2438 | } |
||
2439 | |||
2440 | static void radeon_pm_disable_iopad(struct radeonfb_info *rinfo) |
||
2441 | { |
||
2442 | OUTREG(GPIOPAD_MASK, 0x0001ffff); |
||
2443 | OUTREG(GPIOPAD_EN, 0x00000400); |
||
2444 | OUTREG(GPIOPAD_A, 0x00000000); |
||
2445 | OUTREG(ZV_LCDPAD_MASK, 0x00000000); |
||
2446 | OUTREG(ZV_LCDPAD_EN, 0x00000000); |
||
2447 | OUTREG(ZV_LCDPAD_A, 0x00000000); |
||
2448 | OUTREG(GPIO_VGA_DDC, 0x00030000); |
||
2449 | OUTREG(GPIO_DVI_DDC, 0x00000000); |
||
2450 | OUTREG(GPIO_MONID, 0x00030000); |
||
2451 | OUTREG(GPIO_CRT2_DDC, 0x00000000); |
||
2452 | } |
||
2453 | |||
2454 | static void radeon_pm_program_v2clk(struct radeonfb_info *rinfo) |
||
2455 | { |
||
2456 | // |
||
2457 | // u32 reg; |
||
2458 | // |
||
2459 | // OUTPLL(P2PLL_REF_DIV, 0x0c); |
||
2460 | // |
||
2461 | // .../... figure out what macos does here |
||
2462 | } |
||
2463 | |||
2464 | static void radeon_pm_low_current(struct radeonfb_info *rinfo) |
||
2465 | { |
||
2466 | u32 reg; |
||
2467 | |||
2468 | reg = INREG(BUS_CNTL1); |
||
2469 | reg &= ~BUS_CNTL1_MOBILE_PLATFORM_SEL_MASK; |
||
2470 | reg |= BUS_CNTL1_AGPCLK_VALID | (1<<BUS_CNTL1_MOBILE_PLATFORM_SEL_SHIFT); |
||
2471 | OUTREG(BUS_CNTL1, reg); |
||
2472 | |||
2473 | reg = INPLL(PLL_PWRMGT_CNTL); |
||
2474 | reg |= PLL_PWRMGT_CNTL_SPLL_TURNOFF | PLL_PWRMGT_CNTL_PPLL_TURNOFF | |
||
2475 | PLL_PWRMGT_CNTL_P2PLL_TURNOFF | PLL_PWRMGT_CNTL_TVPLL_TURNOFF; |
||
2476 | reg &= ~PLL_PWRMGT_CNTL_SU_MCLK_USE_BCLK; |
||
2477 | reg &= ~PLL_PWRMGT_CNTL_MOBILE_SU; |
||
2478 | OUTPLL(PLL_PWRMGT_CNTL, reg); |
||
2479 | |||
2480 | // reg = INPLL(TV_PLL_CNTL1); |
||
2481 | // reg |= TV_PLL_CNTL1__TVPLL_RESET | TV_PLL_CNTL1__TVPLL_SLEEP; |
||
2482 | // OUTPLL(TV_PLL_CNTL1, reg); |
||
2483 | |||
2484 | reg = INREG(TV_DAC_CNTL); |
||
2485 | reg &= ~(TV_DAC_CNTL_BGADJ_MASK |TV_DAC_CNTL_DACADJ_MASK); |
||
2486 | reg |=TV_DAC_CNTL_BGSLEEP | TV_DAC_CNTL_RDACPD | TV_DAC_CNTL_GDACPD | |
||
2487 | TV_DAC_CNTL_BDACPD | |
||
2488 | (8<<TV_DAC_CNTL_BGADJ__SHIFT) | (8<<TV_DAC_CNTL_DACADJ__SHIFT); |
||
2489 | OUTREG(TV_DAC_CNTL, reg); |
||
2490 | |||
2491 | reg = INREG(TMDS_TRANSMITTER_CNTL); |
||
2492 | reg &= ~(TMDS_PLL_EN |TMDS_PLLRST); |
||
2493 | OUTREG(TMDS_TRANSMITTER_CNTL, reg); |
||
2494 | |||
2495 | // lvds_pll_cntl = regr32(g, LVDS_PLL_CNTL); |
||
2496 | // lvds_pll_cntl &= ~LVDS_PLL_CNTL__LVDS_PLL_EN; |
||
2497 | // lvds_pll_cntl |= LVDS_PLL_CNTL__LVDS_PLL_RESET; |
||
2498 | // regw32(g, LVDS_PLL_CNTL, lvds_pll_cntl); |
||
2499 | |||
2500 | reg = INREG(DAC_CNTL); |
||
2501 | reg &= ~DAC_CMP_EN; |
||
2502 | OUTREG(DAC_CNTL, reg); |
||
2503 | |||
2504 | reg = INREG(DAC_CNTL2); |
||
2505 | reg &= ~DAC2_CMP_EN; |
||
2506 | OUTREG(DAC_CNTL2, reg); |
||
2507 | |||
2508 | reg = INREG(TV_DAC_CNTL); |
||
2509 | reg &= ~TV_DAC_CNTL_DETECT; |
||
2510 | OUTREG(TV_DAC_CNTL, reg); |
||
2511 | } |
||
2512 | |||
2513 | static void radeon_pm_setup_for_suspend(struct radeonfb_info *rinfo) |
||
2514 | { |
||
2515 | /* This code is disabled. It does what is in the pm_init |
||
2516 | * function of the MacOS driver code ATI sent me. However, |
||
2517 | * it doesn't fix my sleep problem, and is causing other issues |
||
2518 | * on wakeup (bascially the machine dying when switching consoles |
||
2519 | * I haven't had time to investigate this yet |
||
2520 | */ |
||
2521 | #if 0 |
||
2522 | u32 disp_misc_cntl; |
||
2523 | u32 disp_pwr_man; |
||
2524 | u32 temp; |
||
2525 | |||
2526 | // set SPLL, MPLL, PPLL, P2PLL, TVPLL, SCLK, MCLK, PCLK, P2CLK, |
||
2527 | // TCLK and TEST_MODE to 0 |
||
2528 | temp = INPLL(CLK_PWRMGT_CNTL); |
||
2529 | OUTPLL(CLK_PWRMGT_CNTL , temp & ~0xc00002ff); |
||
2530 | |||
2531 | // Turn on Power Management |
||
2532 | temp = INPLL(CLK_PWRMGT_CNTL); |
||
2533 | OUTPLL(CLK_PWRMGT_CNTL , temp | 0x00000400); |
||
2534 | |||
2535 | // Turn off display clock if using mobile chips |
||
2536 | temp = INPLL(CLK_PWRMGT_CNTL); |
||
2537 | OUTREG(CLK_PWRMGT_CNTL , temp | 0x00100000); |
||
2538 | |||
2539 | // Force PIXCLK_ALWAYS_ON and PIXCLK_DAC_ALWAYS_ON |
||
2540 | temp = INPLL(VCLK_ECP_CNTL); |
||
2541 | OUTPLL(VCLK_ECP_CNTL, temp & ~0x000000c0); |
||
2542 | |||
2543 | // Force ECP_FORCE_ON to 1 |
||
2544 | temp = INPLL(VCLK_ECP_CNTL); |
||
2545 | OUTPLL(VCLK_ECP_CNTL, temp | 0x00040000); |
||
2546 | |||
2547 | // Force PIXCLK_BLEND_ALWAYS_ON and PIXCLK_GV_ALWAYS_ON |
||
2548 | temp = INPLL(PIXCLKS_CNTL); |
||
2549 | OUTPLL(PIXCLKS_CNTL, temp & ~0x00001800); |
||
2550 | |||
2551 | // Forcing SCLK_CNTL to ON |
||
2552 | OUTPLL(SCLK_CNTL, (INPLL(SCLK_CNTL)& 0x00000007) | 0xffff8000 ); |
||
2553 | |||
2554 | // Set PM control over XTALIN pad |
||
2555 | temp = INPLL(CLK_PIN_CNTL); |
||
2556 | OUTPLL(CLK_PIN_CNTL, temp | 0x00080000); |
||
2557 | |||
2558 | // Force MCLK and YCLK and MC as dynamic |
||
2559 | temp = INPLL(MCLK_CNTL); |
||
2560 | OUTPLL(MCLK_CNTL, temp & 0xffeaffff); |
||
2561 | |||
2562 | // PLL_TURNOFF |
||
2563 | temp = INPLL(PLL_PWRMGT_CNTL); |
||
2564 | OUTPLL(PLL_PWRMGT_CNTL, temp | 0x0000001f); |
||
2565 | |||
2566 | // set MOBILE_SU to 1 if M6 or DDR64 is detected |
||
2567 | temp = INPLL(PLL_PWRMGT_CNTL); |
||
2568 | OUTPLL(PLL_PWRMGT_CNTL, temp | 0x00010000); |
||
2569 | |||
2570 | // select PM access mode (PM_MODE_SEL) (use ACPI mode) |
||
2571 | // temp = INPLL(PLL_PWRMGT_CNTL); |
||
2572 | // OUTPLL(PLL_PWRMGT_CNTL, temp | 0x00002000); |
||
2573 | temp = INPLL(PLL_PWRMGT_CNTL); |
||
2574 | OUTPLL(PLL_PWRMGT_CNTL, temp & ~0x00002000); |
||
2575 | |||
2576 | // set DISP_MISC_CNTL register |
||
2577 | disp_misc_cntl = INREG(DISP_MISC_CNTL); |
||
2578 | disp_misc_cntl &= ~( DISP_MISC_CNTL_SOFT_RESET_GRPH_PP | |
||
2579 | DISP_MISC_CNTL_SOFT_RESET_SUBPIC_PP | |
||
2580 | DISP_MISC_CNTL_SOFT_RESET_OV0_PP | |
||
2581 | DISP_MISC_CNTL_SOFT_RESET_GRPH_SCLK | |
||
2582 | DISP_MISC_CNTL_SOFT_RESET_SUBPIC_SCLK | |
||
2583 | DISP_MISC_CNTL_SOFT_RESET_OV0_SCLK | |
||
2584 | DISP_MISC_CNTL_SOFT_RESET_GRPH2_PP | |
||
2585 | DISP_MISC_CNTL_SOFT_RESET_GRPH2_SCLK | |
||
2586 | DISP_MISC_CNTL_SOFT_RESET_LVDS | |
||
2587 | DISP_MISC_CNTL_SOFT_RESET_TMDS | |
||
2588 | DISP_MISC_CNTL_SOFT_RESET_DIG_TMDS | |
||
2589 | DISP_MISC_CNTL_SOFT_RESET_TV); |
||
2590 | OUTREG(DISP_MISC_CNTL, disp_misc_cntl); |
||
2591 | |||
2592 | // set DISP_PWR_MAN register |
||
2593 | disp_pwr_man = INREG(DISP_PWR_MAN); |
||
2594 | // clau - 9.29.2000 - changes made to bit23:18 to set to 1 as requested by George |
||
2595 | disp_pwr_man |= (DISP_PWR_MAN_DIG_TMDS_ENABLE_RST | |
||
2596 | DISP_PWR_MAN_TV_ENABLE_RST | |
||
2597 | // DISP_PWR_MAN_AUTO_PWRUP_EN | |
||
2598 | DISP_PWR_MAN_DISP_D3_GRPH_RST | |
||
2599 | DISP_PWR_MAN_DISP_D3_SUBPIC_RST | |
||
2600 | DISP_PWR_MAN_DISP_D3_OV0_RST | |
||
2601 | DISP_PWR_MAN_DISP_D1D2_GRPH_RST | |
||
2602 | DISP_PWR_MAN_DISP_D1D2_SUBPIC_RST | |
||
2603 | DISP_PWR_MAN_DISP_D1D2_OV0_RST); |
||
2604 | disp_pwr_man &= ~(DISP_PWR_MAN_DISP_PWR_MAN_D3_CRTC_EN | |
||
2605 | DISP_PWR_MAN_DISP2_PWR_MAN_D3_CRTC2_EN| |
||
2606 | DISP_PWR_MAN_DISP_D3_RST | |
||
2607 | DISP_PWR_MAN_DISP_D3_REG_RST); |
||
2608 | OUTREG(DISP_PWR_MAN, disp_pwr_man); |
||
2609 | |||
2610 | // clau - 10.24.2000 |
||
2611 | // - add in setting for BUS_CNTL1 b27:26 = 0x01 and b31 = 0x1 |
||
2612 | // - add in setting for AGP_CNTL b7:0 = 0x20 |
||
2613 | // - add in setting for DVI_DDC_DATA_OUT_EN b17:16 = 0x0 |
||
2614 | |||
2615 | // the following settings (two lines) are applied at a later part of this function, only on mobile platform |
||
2616 | // requres -mobile flag |
||
2617 | OUTREG(BUS_CNTL1, (INREG(BUS_CNTL1) & 0xf3ffffff) | 0x04000000); |
||
2618 | OUTREG(BUS_CNTL1, INREG(BUS_CNTL1) | 0x80000000); |
||
2619 | OUTREG(AGP_CNTL, (INREG(AGP_CNTL) & 0xffffff00) | 0x20); |
||
2620 | OUTREG(GPIO_DVI_DDC, INREG(GPIO_DVI_DDC) & 0xfffcffff); |
||
2621 | |||
2622 | // yulee - 12.12.2000 |
||
2623 | // A12 only |
||
2624 | // EN_MCLK_TRISTATE_IN_SUSPEND@MCLK_MISC = 1 |
||
2625 | // ACCESS_REGS_IN_SUSPEND@CLK_PIN_CNTL = 0 |
||
2626 | // only on mobile platform |
||
2627 | OUTPLL(MCLK_MISC, INPLL(MCLK_MISC) | 0x00040000 ); |
||
2628 | |||
2629 | // yulee -12.12.2000 |
||
2630 | // AGPCLK_VALID@BUS_CNTL1 = 1 |
||
2631 | // MOBILE_PLATFORM_SEL@BUS_CNTL1 = 01 |
||
2632 | // CRTC_STEREO_SYNC_OUT_EN@CRTC_OFFSET_CNTL = 0 |
||
2633 | // CG_CLK_TO_OUTPIN@CLK_PIN_CNTL = 0 |
||
2634 | // only on mobile platform |
||
2635 | OUTPLL(CLK_PIN_CNTL, INPLL(CLK_PIN_CNTL ) & 0xFFFFF7FF ); |
||
2636 | OUTREG(BUS_CNTL1, (INREG(BUS_CNTL1 ) & 0xF3FFFFFF) | 0x84000000 ); |
||
2637 | OUTREG(CRTC_OFFSET_CNTL, INREG(CRTC_OFFSET_CNTL ) & 0xFFEFFFFF ); |
||
2638 | |||
2639 | mdelay(100); |
||
2640 | #endif |
||
2641 | |||
2642 | /* Disable CRTCs */ |
||
2643 | OUTREG(CRTC_GEN_CNTL, (INREG(CRTC_GEN_CNTL) & ~CRTC_EN) | CRTC_DISP_REQ_EN_B); |
||
2644 | OUTREG(CRTC2_GEN_CNTL, (INREG(CRTC2_GEN_CNTL) & ~CRTC2_EN) | CRTC2_DISP_REQ_EN_B); |
||
2645 | (void)INREG(CRTC2_GEN_CNTL); |
||
2646 | mdelay(17); |
||
2647 | } |
||
2648 | |||
2649 | static void radeon_set_suspend(struct radeonfb_info *rinfo, int suspend) |
||
2650 | { |
||
2651 | u16 pwr_cmd; |
||
2652 | |||
2653 | if (!rinfo->pm_reg) |
||
2654 | return; |
||
2655 | |||
2656 | /* Set the chip into appropriate suspend mode (we use D2, |
||
2657 | * D3 would require a compete re-initialization of the chip, |
||
2658 | * including PCI config registers, clocks, AGP conf, ...) |
||
2659 | */ |
||
2660 | if (suspend) { |
||
2661 | /* According to ATI, we should program V2CLK here, I have |
||
2662 | * to verify what's up exactly |
||
2663 | */ |
||
2664 | /* Save some registers */ |
||
2665 | radeon_pm_save_regs(rinfo); |
||
2666 | |||
2667 | /* Check that on M7 too, might work might not. M7 may also |
||
2668 | * need explicit enabling of PM |
||
2669 | */ |
||
2670 | if (rinfo->arch == RADEON_M6) { |
||
2671 | /* Program V2CLK */ |
||
2672 | radeon_pm_program_v2clk(rinfo); |
||
2673 | |||
2674 | /* Disable IO PADs */ |
||
2675 | radeon_pm_disable_iopad(rinfo); |
||
2676 | |||
2677 | /* Set low current */ |
||
2678 | radeon_pm_low_current(rinfo); |
||
2679 | |||
2680 | /* Prepare chip for power management */ |
||
2681 | radeon_pm_setup_for_suspend(rinfo); |
||
2682 | |||
2683 | /* Reset the MDLL */ |
||
2684 | OUTPLL(MDLL_CKO, INPLL(MDLL_CKO) | MCKOA_RESET); |
||
2685 | (void)INPLL(MDLL_RDCKA); |
||
2686 | OUTPLL(MDLL_CKO, INPLL(MDLL_CKO) & ~MCKOA_RESET); |
||
2687 | (void)INPLL(MDLL_RDCKA); |
||
2688 | } |
||
2689 | |||
2690 | /* Switch PCI power managment to D2. */ |
||
2691 | for (;;) { |
||
2692 | pci_read_config_word( |
||
2693 | rinfo->pdev, rinfo->pm_reg+PCI_PM_CTRL, |
||
2694 | &pwr_cmd); |
||
2695 | if (pwr_cmd & 2) |
||
2696 | break; |
||
2697 | pci_write_config_word( |
||
2698 | rinfo->pdev, rinfo->pm_reg+PCI_PM_CTRL, |
||
2699 | (pwr_cmd & ~PCI_PM_CTRL_STATE_MASK) | 2); |
||
2700 | mdelay(500); |
||
2701 | } |
||
2702 | } else { |
||
2703 | /* Switch back PCI powermanagment to D0 */ |
||
2704 | mdelay(200); |
||
2705 | pci_write_config_word(rinfo->pdev, rinfo->pm_reg+PCI_PM_CTRL, 0); |
||
2706 | mdelay(500); |
||
2707 | |||
2708 | dbg_clk = INPLL(1); |
||
2709 | |||
2710 | /* Do we need that on M7 ? */ |
||
2711 | if (rinfo->arch == RADEON_M6) { |
||
2712 | /* Restore the MDLL */ |
||
2713 | OUTPLL(MDLL_CKO, INPLL(MDLL_CKO) & ~MCKOA_RESET); |
||
2714 | (void)INPLL(MDLL_CKO); |
||
2715 | } |
||
2716 | |||
2717 | /* Restore some registers */ |
||
2718 | radeon_pm_restore_regs(rinfo); |
||
2719 | } |
||
2720 | } |
||
2721 | |||
2722 | /* |
||
2723 | * Save the contents of the framebuffer when we go to sleep, |
||
2724 | * and restore it when we wake up again. |
||
2725 | */ |
||
2726 | |||
2727 | int radeon_sleep_notify(struct pmu_sleep_notifier *self, int when) |
||
2728 | { |
||
2729 | struct radeonfb_info *rinfo; |
||
2730 | |||
2731 | for (rinfo = board_list; rinfo != NULL; rinfo = rinfo->next) { |
||
2732 | struct fb_fix_screeninfo fix; |
||
2733 | int nb; |
||
2734 | struct display *disp; |
||
2735 | |||
2736 | disp = (rinfo->currcon < 0) ? rinfo->info.disp : &fb_display[rinfo->currcon]; |
||
2737 | |||
2738 | switch (rinfo->arch) { |
||
2739 | case RADEON_M6: |
||
2740 | case RADEON_M7: |
||
2741 | case RADEON_M9: |
||
2742 | break; |
||
2743 | default: |
||
2744 | return PBOOK_SLEEP_REFUSE; |
||
2745 | } |
||
2746 | |||
2747 | radeonfb_get_fix(&fix, fg_console, (struct fb_info *)rinfo); |
||
2748 | nb = fb_display[fg_console].var.yres * fix.line_length; |
||
2749 | |||
2750 | switch (when) { |
||
2751 | case PBOOK_SLEEP_NOW: |
||
2752 | acquire_console_sem(); |
||
2753 | disp->dispsw = &fbcon_dummy; |
||
2754 | |||
2755 | if (!noaccel) { |
||
2756 | /* Make sure engine is reset */ |
||
2757 | radeon_engine_reset(); |
||
2758 | radeon_engine_idle(); |
||
2759 | } |
||
2760 | |||
2761 | /* Blank display and LCD */ |
||
2762 | radeonfb_blank(VESA_POWERDOWN+1, |
||
2763 | (struct fb_info *)rinfo); |
||
2764 | |||
2765 | /* Sleep */ |
||
2766 | rinfo->asleep = 1; |
||
2767 | radeon_set_suspend(rinfo, 1); |
||
2768 | release_console_sem(); |
||
2769 | |||
2770 | break; |
||
2771 | case PBOOK_WAKE: |
||
2772 | acquire_console_sem(); |
||
2773 | /* Wakeup */ |
||
2774 | radeon_set_suspend(rinfo, 0); |
||
2775 | |||
2776 | if (!noaccel) |
||
2777 | radeon_engine_init(rinfo); |
||
2778 | rinfo->asleep = 0; |
||
2779 | radeon_set_dispsw(rinfo, disp); |
||
2780 | radeon_load_video_mode(rinfo, &disp->var); |
||
2781 | do_install_cmap(rinfo->currcon < 0 ? 0 : rinfo->currcon, |
||
2782 | (struct fb_info *)rinfo); |
||
2783 | |||
2784 | radeonfb_blank(0, (struct fb_info *)rinfo); |
||
2785 | release_console_sem(); |
||
2786 | printk("CLK_PIN_CNTL on wakeup was: %08x\n", dbg_clk); |
||
2787 | break; |
||
2788 | } |
||
2789 | } |
||
2790 | |||
2791 | return PBOOK_SLEEP_OK; |
||
2792 | } |
||
2793 | |||
2794 | #endif /* CONFIG_PMAC_PBOOK */ |
||
2795 | |||
2796 | static int radeonfb_pci_register (struct pci_dev *pdev, |
||
2797 | const struct pci_device_id *ent) |
||
2798 | { |
||
2799 | struct radeonfb_info *rinfo; |
||
2800 | struct radeon_chip_info *rci = &radeon_chip_info[ent->driver_data]; |
||
2801 | u32 tmp; |
||
2802 | |||
2803 | RTRACE("radeonfb_pci_register BEGIN\n"); |
||
2804 | |||
2805 | /* Enable device in PCI config */ |
||
2806 | if (pci_enable_device(pdev) != 0) { |
||
2807 | printk(KERN_ERR "radeonfb: Cannot enable PCI device\n"); |
||
2808 | return -ENODEV; |
||
2809 | } |
||
2810 | |||
2811 | rinfo = kmalloc (sizeof (struct radeonfb_info), GFP_KERNEL); |
||
2812 | if (!rinfo) { |
||
2813 | printk ("radeonfb: could not allocate memory\n"); |
||
2814 | return -ENODEV; |
||
2815 | } |
||
2816 | |||
2817 | memset (rinfo, 0, sizeof (struct radeonfb_info)); |
||
2818 | //info = &rinfo->info; |
||
2819 | rinfo->pdev = pdev; |
||
2820 | strcpy(rinfo->name, rci->name); |
||
2821 | rinfo->arch = rci->arch; |
||
2822 | |||
2823 | /* Set base addrs */ |
||
2824 | rinfo->fb_base_phys = pci_resource_start (pdev, 0); |
||
2825 | rinfo->mmio_base_phys = pci_resource_start (pdev, 2); |
||
2826 | |||
2827 | /* request the mem regions */ |
||
2828 | if (!request_mem_region (rinfo->fb_base_phys, |
||
2829 | pci_resource_len(pdev, 0), "radeonfb")) { |
||
2830 | printk ("radeonfb: cannot reserve FB region\n"); |
||
2831 | kfree (rinfo); |
||
2832 | return -ENODEV; |
||
2833 | } |
||
2834 | |||
2835 | if (!request_mem_region (rinfo->mmio_base_phys, |
||
2836 | pci_resource_len(pdev, 2), "radeonfb")) { |
||
2837 | printk ("radeonfb: cannot reserve MMIO region\n"); |
||
2838 | release_mem_region (rinfo->fb_base_phys, |
||
2839 | pci_resource_len(pdev, 0)); |
||
2840 | kfree (rinfo); |
||
2841 | return -ENODEV; |
||
2842 | } |
||
2843 | |||
2844 | /* map the regions */ |
||
2845 | rinfo->mmio_base = (unsigned long) ioremap (rinfo->mmio_base_phys, RADEON_REGSIZE); |
||
2846 | if (!rinfo->mmio_base) { |
||
2847 | printk ("radeonfb: cannot map MMIO\n"); |
||
2848 | release_mem_region (rinfo->mmio_base_phys, |
||
2849 | pci_resource_len(pdev, 2)); |
||
2850 | release_mem_region (rinfo->fb_base_phys, |
||
2851 | pci_resource_len(pdev, 0)); |
||
2852 | kfree (rinfo); |
||
2853 | return -ENODEV; |
||
2854 | } |
||
2855 | |||
2856 | rinfo->chipset = pdev->device; |
||
2857 | |||
2858 | switch (rinfo->arch) { |
||
2859 | case RADEON_R100: |
||
2860 | rinfo->hasCRTC2 = 0; |
||
2861 | break; |
||
2862 | default: |
||
2863 | /* all the rest have it */ |
||
2864 | rinfo->hasCRTC2 = 1; |
||
2865 | break; |
||
2866 | } |
||
2867 | #if 0 |
||
2868 | if (rinfo->arch == RADEON_M7) { |
||
2869 | /* |
||
2870 | * Noticed some errors in accel with M7, will have to work these out... |
||
2871 | */ |
||
2872 | noaccel = 1; |
||
2873 | } |
||
2874 | #endif |
||
2875 | if (mirror) |
||
2876 | printk("radeonfb: mirroring display to CRT\n"); |
||
2877 | |||
2878 | /* framebuffer size */ |
||
2879 | tmp = INREG(CONFIG_MEMSIZE); |
||
2880 | |||
2881 | /* mem size is bits [28:0], mask off the rest */ |
||
2882 | rinfo->video_ram = tmp & CONFIG_MEMSIZE_MASK; |
||
2883 | |||
2884 | /* ram type */ |
||
2885 | tmp = INREG(MEM_SDRAM_MODE_REG); |
||
2886 | switch ((MEM_CFG_TYPE & tmp) >> 30) { |
||
2887 | case 0: |
||
2888 | /* SDR SGRAM (2:1) */ |
||
2889 | strcpy(rinfo->ram_type, "SDR SGRAM"); |
||
2890 | rinfo->ram.ml = 4; |
||
2891 | rinfo->ram.mb = 4; |
||
2892 | rinfo->ram.trcd = 1; |
||
2893 | rinfo->ram.trp = 2; |
||
2894 | rinfo->ram.twr = 1; |
||
2895 | rinfo->ram.cl = 2; |
||
2896 | rinfo->ram.loop_latency = 16; |
||
2897 | rinfo->ram.rloop = 16; |
||
2898 | |||
2899 | break; |
||
2900 | case 1: |
||
2901 | /* DDR SGRAM */ |
||
2902 | strcpy(rinfo->ram_type, "DDR SGRAM"); |
||
2903 | rinfo->ram.ml = 4; |
||
2904 | rinfo->ram.mb = 4; |
||
2905 | rinfo->ram.trcd = 3; |
||
2906 | rinfo->ram.trp = 3; |
||
2907 | rinfo->ram.twr = 2; |
||
2908 | rinfo->ram.cl = 3; |
||
2909 | rinfo->ram.tr2w = 1; |
||
2910 | rinfo->ram.loop_latency = 16; |
||
2911 | rinfo->ram.rloop = 16; |
||
2912 | |||
2913 | break; |
||
2914 | default: |
||
2915 | /* 64-bit SDR SGRAM */ |
||
2916 | strcpy(rinfo->ram_type, "SDR SGRAM 64"); |
||
2917 | rinfo->ram.ml = 4; |
||
2918 | rinfo->ram.mb = 8; |
||
2919 | rinfo->ram.trcd = 3; |
||
2920 | rinfo->ram.trp = 3; |
||
2921 | rinfo->ram.twr = 1; |
||
2922 | rinfo->ram.cl = 3; |
||
2923 | rinfo->ram.tr2w = 1; |
||
2924 | rinfo->ram.loop_latency = 17; |
||
2925 | rinfo->ram.rloop = 17; |
||
2926 | |||
2927 | break; |
||
2928 | } |
||
2929 | |||
2930 | rinfo->bios_seg = radeon_find_rom(rinfo); |
||
2931 | radeon_get_pllinfo(rinfo, rinfo->bios_seg); |
||
2932 | |||
2933 | /* |
||
2934 | * Hack to get around some busted production M6's |
||
2935 | * reporting no ram |
||
2936 | */ |
||
2937 | if (rinfo->video_ram == 0) { |
||
2938 | switch (pdev->device) { |
||
2939 | case PCI_DEVICE_ID_ATI_RADEON_LY: |
||
2940 | case PCI_DEVICE_ID_ATI_RADEON_LZ: |
||
2941 | rinfo->video_ram = 8192 * 1024; |
||
2942 | break; |
||
2943 | default: |
||
2944 | break; |
||
2945 | } |
||
2946 | } |
||
2947 | |||
2948 | |||
2949 | RTRACE("radeonfb: probed %s %dk videoram\n", (rinfo->ram_type), (rinfo->video_ram/1024)); |
||
2950 | |||
2951 | #if !defined(__powerpc__) |
||
2952 | radeon_get_moninfo(rinfo); |
||
2953 | #else |
||
2954 | switch (pdev->device) { |
||
2955 | case PCI_DEVICE_ID_ATI_RADEON_LW: |
||
2956 | case PCI_DEVICE_ID_ATI_RADEON_LX: |
||
2957 | case PCI_DEVICE_ID_ATI_RADEON_LY: |
||
2958 | case PCI_DEVICE_ID_ATI_RADEON_LZ: |
||
2959 | rinfo->dviDisp_type = MT_LCD; |
||
2960 | break; |
||
2961 | default: |
||
2962 | radeon_get_moninfo(rinfo); |
||
2963 | break; |
||
2964 | } |
||
2965 | #endif |
||
2966 | |||
2967 | radeon_get_EDID(rinfo); |
||
2968 | |||
2969 | if ((rinfo->dviDisp_type == MT_DFP) || (rinfo->dviDisp_type == MT_LCD) || |
||
2970 | (rinfo->crtDisp_type == MT_DFP)) { |
||
2971 | if (!radeon_get_dfpinfo(rinfo)) { |
||
2972 | iounmap ((void*)rinfo->mmio_base); |
||
2973 | release_mem_region (rinfo->mmio_base_phys, |
||
2974 | pci_resource_len(pdev, 2)); |
||
2975 | release_mem_region (rinfo->fb_base_phys, |
||
2976 | pci_resource_len(pdev, 0)); |
||
2977 | kfree (rinfo); |
||
2978 | return -ENODEV; |
||
2979 | } |
||
2980 | } |
||
2981 | |||
2982 | rinfo->fb_base = (unsigned long) ioremap (rinfo->fb_base_phys, rinfo->video_ram); |
||
2983 | if (!rinfo->fb_base) { |
||
2984 | printk ("radeonfb: cannot map FB\n"); |
||
2985 | iounmap ((void*)rinfo->mmio_base); |
||
2986 | release_mem_region (rinfo->mmio_base_phys, |
||
2987 | pci_resource_len(pdev, 2)); |
||
2988 | release_mem_region (rinfo->fb_base_phys, |
||
2989 | pci_resource_len(pdev, 0)); |
||
2990 | kfree (rinfo); |
||
2991 | return -ENODEV; |
||
2992 | } |
||
2993 | |||
2994 | /* I SHOULD FIX THAT CRAP ! I should probably mimmic XFree DRI |
||
2995 | * driver setup here. |
||
2996 | * |
||
2997 | * On PPC, OF based cards setup the internal memory |
||
2998 | * mapping in strange ways. We change it so that the |
||
2999 | * framebuffer is mapped at 0 and given half of the card's |
||
3000 | * address space (2Gb). AGP is mapped high (0xe0000000) and |
||
3001 | * can use up to 512Mb. Once DRI is fully implemented, we |
||
3002 | * will have to setup the PCI remapper to remap the agp_special_page |
||
3003 | * memory page somewhere between those regions so that the card |
||
3004 | * use a normal PCI bus master cycle to access the ring read ptr. |
||
3005 | * --BenH. |
||
3006 | */ |
||
3007 | #ifdef CONFIG_ALL_PPC |
||
3008 | if (rinfo->hasCRTC2) |
||
3009 | OUTREG(CRTC2_GEN_CNTL, |
||
3010 | (INREG(CRTC2_GEN_CNTL) & ~CRTC2_EN) | CRTC2_DISP_REQ_EN_B); |
||
3011 | OUTREG(CRTC_EXT_CNTL, INREG(CRTC_EXT_CNTL) | CRTC_DISPLAY_DIS); |
||
3012 | OUTREG(MC_FB_LOCATION, 0x7fff0000); |
||
3013 | OUTREG(MC_AGP_LOCATION, 0xffffe000); |
||
3014 | OUTREG(DISPLAY_BASE_ADDR, 0x00000000); |
||
3015 | if (rinfo->hasCRTC2) |
||
3016 | OUTREG(CRTC2_DISPLAY_BASE_ADDR, 0x00000000); |
||
3017 | OUTREG(SRC_OFFSET, 0x00000000); |
||
3018 | OUTREG(DST_OFFSET, 0x00000000); |
||
3019 | mdelay(10); |
||
3020 | OUTREG(CRTC_EXT_CNTL, INREG(CRTC_EXT_CNTL) & ~CRTC_DISPLAY_DIS); |
||
3021 | #endif /* CONFIG_ALL_PPC */ |
||
3022 | |||
3023 | /* save current mode regs before we switch into the new one |
||
3024 | * so we can restore this upon __exit |
||
3025 | */ |
||
3026 | radeon_save_state (rinfo, &rinfo->init_state); |
||
3027 | |||
3028 | if (!noaccel) { |
||
3029 | /* initialize the engine */ |
||
3030 | radeon_engine_init (rinfo); |
||
3031 | } |
||
3032 | |||
3033 | /* set all the vital stuff */ |
||
3034 | radeon_set_fbinfo (rinfo); |
||
3035 | |||
3036 | pci_set_drvdata(pdev, rinfo); |
||
3037 | rinfo->next = board_list; |
||
3038 | board_list = rinfo; |
||
3039 | |||
3040 | if (register_framebuffer ((struct fb_info *) rinfo) < 0) { |
||
3041 | printk ("radeonfb: could not register framebuffer\n"); |
||
3042 | iounmap ((void*)rinfo->fb_base); |
||
3043 | iounmap ((void*)rinfo->mmio_base); |
||
3044 | release_mem_region (rinfo->mmio_base_phys, |
||
3045 | pci_resource_len(pdev, 2)); |
||
3046 | release_mem_region (rinfo->fb_base_phys, |
||
3047 | pci_resource_len(pdev, 0)); |
||
3048 | kfree (rinfo); |
||
3049 | return -ENODEV; |
||
3050 | } |
||
3051 | |||
3052 | #ifdef CONFIG_MTRR |
||
3053 | rinfo->mtrr_hdl = nomtrr ? -1 : mtrr_add(rinfo->fb_base_phys, |
||
3054 | rinfo->video_ram, |
||
3055 | MTRR_TYPE_WRCOMB, 1); |
||
3056 | #endif |
||
3057 | |||
3058 | #ifdef CONFIG_PMAC_BACKLIGHT |
||
3059 | if (rinfo->dviDisp_type == MT_LCD) |
||
3060 | register_backlight_controller(&radeon_backlight_controller, |
||
3061 | rinfo, "ati"); |
||
3062 | #endif |
||
3063 | |||
3064 | #ifdef CONFIG_PMAC_PBOOK |
||
3065 | if (rinfo->dviDisp_type == MT_LCD) { |
||
3066 | rinfo->pm_reg = pci_find_capability(pdev, PCI_CAP_ID_PM); |
||
3067 | pmu_register_sleep_notifier(&radeon_sleep_notifier); |
||
3068 | } |
||
3069 | #endif |
||
3070 | |||
3071 | printk ("radeonfb: ATI Radeon %s %s %d MB\n", rinfo->name, rinfo->ram_type, |
||
3072 | (rinfo->video_ram/(1024*1024))); |
||
3073 | |||
3074 | if (rinfo->hasCRTC2) { |
||
3075 | printk("radeonfb: DVI port %s monitor connected\n", |
||
3076 | GET_MON_NAME(rinfo->dviDisp_type)); |
||
3077 | printk("radeonfb: CRT port %s monitor connected\n", |
||
3078 | GET_MON_NAME(rinfo->crtDisp_type)); |
||
3079 | } else { |
||
3080 | printk("radeonfb: CRT port %s monitor connected\n", |
||
3081 | GET_MON_NAME(rinfo->crtDisp_type)); |
||
3082 | } |
||
3083 | |||
3084 | RTRACE("radeonfb_pci_register END\n"); |
||
3085 | |||
3086 | return 0; |
||
3087 | } |
||
3088 | |||
3089 | |||
3090 | |||
3091 | static void __devexit radeonfb_pci_unregister (struct pci_dev *pdev) |
||
3092 | { |
||
3093 | struct radeonfb_info *rinfo = pci_get_drvdata(pdev); |
||
3094 | |||
3095 | if (!rinfo) |
||
3096 | return; |
||
3097 | |||
3098 | /* restore original state |
||
3099 | * |
||
3100 | * Doesn't quite work yet, possibly because of the PPC hacking |
||
3101 | * I do on startup, disable for now. --BenH |
||
3102 | */ |
||
3103 | radeon_write_mode (rinfo, &rinfo->init_state); |
||
3104 | |||
3105 | #ifdef CONFIG_MTRR |
||
3106 | if (rinfo->mtrr_hdl >= 0) |
||
3107 | mtrr_del(rinfo->mtrr_hdl, 0, 0); |
||
3108 | #endif |
||
3109 | |||
3110 | unregister_framebuffer ((struct fb_info *) rinfo); |
||
3111 | |||
3112 | iounmap ((void*)rinfo->mmio_base); |
||
3113 | iounmap ((void*)rinfo->fb_base); |
||
3114 | |||
3115 | release_mem_region (rinfo->mmio_base_phys, |
||
3116 | pci_resource_len(pdev, 2)); |
||
3117 | release_mem_region (rinfo->fb_base_phys, |
||
3118 | pci_resource_len(pdev, 0)); |
||
3119 | |||
3120 | kfree (rinfo); |
||
3121 | } |
||
3122 | |||
3123 | |||
3124 | static struct pci_driver radeonfb_driver = { |
||
3125 | .name = "radeonfb", |
||
3126 | .id_table = radeonfb_pci_table, |
||
3127 | .probe = radeonfb_pci_register, |
||
3128 | .remove = __devexit_p(radeonfb_pci_unregister), |
||
3129 | }; |
||
3130 | |||
3131 | |||
3132 | int __init radeonfb_init (void) |
||
3133 | { |
||
3134 | return pci_module_init (&radeonfb_driver); |
||
3135 | } |
||
3136 | |||
3137 | |||
3138 | void __exit radeonfb_exit (void) |
||
3139 | { |
||
3140 | pci_unregister_driver (&radeonfb_driver); |
||
3141 | } |
||
3142 | |||
3143 | |||
3144 | int __init radeonfb_setup (char *options) |
||
3145 | { |
||
3146 | char *this_opt; |
||
3147 | |||
3148 | if (!options || !*options) |
||
3149 | return 0; |
||
3150 | |||
3151 | while ((this_opt = strsep (&options, ",")) != NULL) { |
||
3152 | if (!*this_opt) |
||
3153 | continue; |
||
3154 | if (!strncmp(this_opt, "noaccel", 7)) { |
||
3155 | noaccel = 1; |
||
3156 | } else if (!strncmp(this_opt, "mirror", 6)) { |
||
3157 | mirror = 1; |
||
3158 | } else if (!strncmp(this_opt, "dfp", 3)) { |
||
3159 | force_dfp = 1; |
||
3160 | } else if (!strncmp(this_opt, "panel_yres:", 11)) { |
||
3161 | panel_yres = simple_strtoul((this_opt+11), NULL, 0); |
||
3162 | } else if (!strncmp(this_opt, "nomtrr", 6)) { |
||
3163 | nomtrr = 1; |
||
3164 | } else |
||
3165 | mode_option = this_opt; |
||
3166 | } |
||
3167 | |||
3168 | return 0; |
||
3169 | } |
||
3170 | |||
3171 | #ifdef MODULE |
||
3172 | module_init(radeonfb_init); |
||
3173 | module_exit(radeonfb_exit); |
||
3174 | #endif |
||
3175 | |||
3176 | |||
3177 | MODULE_AUTHOR("Ani Joshi"); |
||
3178 | MODULE_DESCRIPTION("framebuffer driver for ATI Radeon chipset"); |
||
3179 | MODULE_LICENSE("GPL"); |