1911
|
1 /*
|
|
2 * drivers/video/radeonfb.c
|
|
3 * framebuffer driver for ATI Radeon chipset video boards
|
|
4 *
|
|
5 * Copyright 2000 Ani Joshi <ajoshi@unixbox.com>
|
|
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
|
1914
|
14 * 2001-09-06 console switching fixes, blanking fixes,
|
|
15 * 0.1.0
|
1911
|
16 *
|
1912
|
17 * 2001-09-07 Radeon VE support
|
1913
|
18 * 2001-09-10 Radeon VE QZ support by Nick Kurshev <nickols_k@mail.ru>
|
|
19 * (limitations: on dualhead Radeons (VE, M6, M7)
|
|
20 * driver works only on second head (DVI port).
|
|
21 * TVout is not supported too. M6 & M7 chips
|
|
22 * currently are not supported. Driver has a lot
|
|
23 * of other bugs. Probably they can be solved by
|
|
24 * importing XFree86 code, which has ATI's support).,
|
|
25 * 0.0.11
|
1914
|
26 * 2001-09-13 merge Ani Joshi radeonfb-0.1.0:
|
|
27 * console switching fixes, blanking fixes,
|
|
28 * 0.1.0-ve.0
|
1911
|
29 *
|
|
30 * Special thanks to ATI DevRel team for their hardware donations.
|
|
31 *
|
|
32 */
|
|
33
|
|
34
|
1914
|
35 #define RADEON_VERSION "0.1.0-ve.0"
|
1911
|
36
|
|
37
|
|
38 #include <linux/config.h>
|
|
39 #include <linux/module.h>
|
|
40 #include <linux/kernel.h>
|
|
41 #include <linux/errno.h>
|
|
42 #include <linux/string.h>
|
|
43 #include <linux/mm.h>
|
|
44 #include <linux/tty.h>
|
|
45 #include <linux/malloc.h>
|
|
46 #include <linux/delay.h>
|
|
47 #include <linux/fb.h>
|
|
48 #include <linux/console.h>
|
|
49 #include <linux/selection.h>
|
|
50 #include <linux/ioport.h>
|
|
51 #include <linux/init.h>
|
|
52 #include <linux/pci.h>
|
|
53
|
|
54 #include <asm/io.h>
|
|
55
|
|
56 #include <video/fbcon.h>
|
|
57 #include <video/fbcon-cfb8.h>
|
|
58 #include <video/fbcon-cfb16.h>
|
|
59 #include <video/fbcon-cfb24.h>
|
|
60 #include <video/fbcon-cfb32.h>
|
|
61
|
|
62 #include "radeon.h"
|
|
63
|
|
64
|
|
65 #define DEBUG 0
|
|
66
|
|
67 #if DEBUG
|
|
68 #define RTRACE printk
|
|
69 #else
|
|
70 #define RTRACE if(0) printk
|
|
71 #endif
|
|
72
|
|
73
|
|
74
|
|
75 enum radeon_chips {
|
|
76 RADEON_QD,
|
|
77 RADEON_QE,
|
|
78 RADEON_QF,
|
1912
|
79 RADEON_QG,
|
1913
|
80 RADEON_QY,
|
|
81 RADEON_QZ
|
1911
|
82 };
|
|
83
|
|
84
|
|
85 static struct pci_device_id radeonfb_pci_table[] __devinitdata = {
|
|
86 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_RADEON_QD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QD},
|
|
87 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_RADEON_QE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QE},
|
|
88 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_RADEON_QF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QF},
|
|
89 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_RADEON_QG, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QG},
|
1913
|
90 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_RADEON_QY, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QY},
|
|
91 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_RADEON_QZ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QZ},
|
1911
|
92 { 0, }
|
|
93 };
|
|
94 MODULE_DEVICE_TABLE(pci, radeonfb_pci_table);
|
|
95
|
|
96
|
|
97 typedef struct {
|
|
98 u16 reg;
|
|
99 u32 val;
|
|
100 } reg_val;
|
|
101
|
|
102
|
|
103 /* these common regs are cleared before mode setting so they do not
|
|
104 * interfere with anything
|
|
105 */
|
|
106 reg_val common_regs[] = {
|
|
107 { OVR_CLR, 0 },
|
|
108 { OVR_WID_LEFT_RIGHT, 0 },
|
|
109 { OVR_WID_TOP_BOTTOM, 0 },
|
|
110 { OV0_SCALE_CNTL, 0 },
|
|
111 { SUBPIC_CNTL, 0 },
|
|
112 { VIPH_CONTROL, 0 },
|
|
113 { I2C_CNTL_1, 0 },
|
|
114 { GEN_INT_CNTL, 0 },
|
|
115 { CAP0_TRIG_CNTL, 0 },
|
|
116 };
|
|
117
|
|
118 #define COMMON_REGS_SIZE = (sizeof(common_regs)/sizeof(common_regs[0]))
|
|
119
|
|
120 typedef struct {
|
|
121 u8 clock_chip_type;
|
|
122 u8 struct_size;
|
|
123 u8 accelerator_entry;
|
|
124 u8 VGA_entry;
|
|
125 u16 VGA_table_offset;
|
|
126 u16 POST_table_offset;
|
|
127 u16 XCLK;
|
|
128 u16 MCLK;
|
|
129 u8 num_PLL_blocks;
|
|
130 u8 size_PLL_blocks;
|
|
131 u16 PCLK_ref_freq;
|
|
132 u16 PCLK_ref_divider;
|
|
133 u32 PCLK_min_freq;
|
|
134 u32 PCLK_max_freq;
|
|
135 u16 MCLK_ref_freq;
|
|
136 u16 MCLK_ref_divider;
|
|
137 u32 MCLK_min_freq;
|
|
138 u32 MCLK_max_freq;
|
|
139 u16 XCLK_ref_freq;
|
|
140 u16 XCLK_ref_divider;
|
|
141 u32 XCLK_min_freq;
|
|
142 u32 XCLK_max_freq;
|
|
143 } __attribute__ ((packed)) PLL_BLOCK;
|
|
144
|
|
145
|
|
146 struct pll_info {
|
|
147 int ppll_max;
|
|
148 int ppll_min;
|
|
149 int xclk;
|
|
150 int ref_div;
|
|
151 int ref_clk;
|
|
152 };
|
|
153
|
|
154
|
|
155 struct ram_info {
|
|
156 int ml;
|
|
157 int mb;
|
|
158 int trcd;
|
|
159 int trp;
|
|
160 int twr;
|
|
161 int cl;
|
|
162 int tr2w;
|
|
163 int loop_latency;
|
|
164 int rloop;
|
|
165 };
|
|
166
|
|
167
|
|
168 struct radeon_regs {
|
|
169 u32 crtc_h_total_disp;
|
|
170 u32 crtc_h_sync_strt_wid;
|
|
171 u32 crtc_v_total_disp;
|
|
172 u32 crtc_v_sync_strt_wid;
|
|
173 u32 crtc_pitch;
|
|
174 u32 flags;
|
|
175 u32 pix_clock;
|
|
176 int xres, yres;
|
|
177 int bpp;
|
|
178 u32 crtc_gen_cntl;
|
|
179 u32 crtc_ext_cntl;
|
1914
|
180 u32 surface_cntl;
|
1911
|
181 u32 dac_cntl;
|
|
182 u32 dda_config;
|
|
183 u32 dda_on_off;
|
|
184 u32 ppll_div_3;
|
|
185 u32 ppll_ref_div;
|
|
186 };
|
|
187
|
|
188
|
|
189 struct radeonfb_info {
|
|
190 struct fb_info info;
|
|
191
|
|
192 struct radeon_regs state;
|
|
193 struct radeon_regs init_state;
|
|
194
|
1913
|
195 char name[14];
|
1911
|
196 char ram_type[12];
|
|
197
|
|
198 u32 mmio_base_phys;
|
|
199 u32 fb_base_phys;
|
|
200
|
|
201 u32 mmio_base;
|
|
202 u32 fb_base;
|
|
203
|
|
204 struct pci_dev *pdev;
|
|
205
|
|
206 struct display disp;
|
|
207 int currcon;
|
|
208 struct display *currcon_display;
|
|
209
|
|
210 struct { u8 red, green, blue, pad; } palette[256];
|
|
211
|
|
212 int chipset;
|
|
213 int video_ram;
|
|
214 u8 rev;
|
|
215 int pitch, bpp, depth;
|
|
216 int xres, yres, pixclock;
|
|
217
|
|
218 u32 dp_gui_master_cntl;
|
|
219
|
|
220 struct pll_info pll;
|
|
221 int pll_output_freq, post_div, fb_div;
|
|
222
|
|
223 struct ram_info ram;
|
|
224
|
1914
|
225 u32 hack_crtc_ext_cntl;
|
|
226 u32 hack_crtc_v_sync_strt_wid;
|
|
227
|
1911
|
228 #if defined(FBCON_HAS_CFB16) || defined(FBCON_HAS_CFB32)
|
|
229 union {
|
|
230 #if defined(FBCON_HAS_CFB16)
|
|
231 u_int16_t cfb16[16];
|
|
232 #endif
|
1914
|
233 #if defined(FBCON_HAS_CFB24)
|
|
234 u_int32_t cfb24[16];
|
|
235 #endif
|
1911
|
236 #if defined(FBCON_HAS_CFB32)
|
|
237 u_int32_t cfb32[16];
|
|
238 #endif
|
|
239 } con_cmap;
|
|
240 #endif
|
|
241 };
|
|
242
|
|
243
|
|
244 static struct fb_var_screeninfo radeonfb_default_var = {
|
|
245 640, 480, 640, 480, 0, 0, 8, 0,
|
|
246 {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0},
|
|
247 0, 0, -1, -1, 0, 39721, 40, 24, 32, 11, 96, 2,
|
|
248 0, FB_VMODE_NONINTERLACED
|
|
249 };
|
|
250
|
|
251
|
|
252 /*
|
|
253 * IO macros
|
|
254 */
|
|
255
|
|
256 #define INREG8(addr) readb((rinfo->mmio_base)+addr)
|
|
257 #define OUTREG8(addr,val) writeb(val, (rinfo->mmio_base)+addr)
|
|
258 #define INREG(addr) readl((rinfo->mmio_base)+addr)
|
|
259 #define OUTREG(addr,val) writel(val, (rinfo->mmio_base)+addr)
|
|
260
|
|
261 #define OUTPLL(addr,val) OUTREG8(CLOCK_CNTL_INDEX, (addr & 0x0000001f) | 0x00000080); \
|
|
262 OUTREG(CLOCK_CNTL_DATA, val)
|
|
263 #define OUTPLLP(addr,val,mask) \
|
|
264 do { \
|
|
265 unsigned int _tmp = INPLL(addr); \
|
|
266 _tmp &= (mask); \
|
|
267 _tmp |= (val); \
|
|
268 OUTPLL(addr, _tmp); \
|
|
269 } while (0)
|
|
270
|
|
271 #define OUTREGP(addr,val,mask) \
|
|
272 do { \
|
|
273 unsigned int _tmp = INREG(addr); \
|
|
274 _tmp &= (mask); \
|
|
275 _tmp |= (val); \
|
|
276 OUTREG(addr, _tmp); \
|
|
277 } while (0)
|
|
278
|
|
279
|
|
280 static __inline__ u32 _INPLL(struct radeonfb_info *rinfo, u32 addr)
|
|
281 {
|
|
282 OUTREG8(CLOCK_CNTL_INDEX, addr & 0x0000001f);
|
|
283 return (INREG(CLOCK_CNTL_DATA));
|
|
284 }
|
|
285
|
|
286 #define INPLL(addr) _INPLL(rinfo, addr)
|
|
287
|
|
288
|
|
289 /*
|
|
290 * 2D engine routines
|
|
291 */
|
|
292
|
|
293 static __inline__ void radeon_engine_flush (struct radeonfb_info *rinfo)
|
|
294 {
|
|
295 int i;
|
|
296
|
|
297 /* initiate flush */
|
|
298 OUTREGP(RB2D_DSTCACHE_CTLSTAT, RB2D_DC_FLUSH_ALL,
|
|
299 ~RB2D_DC_FLUSH_ALL);
|
|
300
|
|
301 for (i=0; i < 2000000; i++) {
|
|
302 if (!(INREG(RB2D_DSTCACHE_CTLSTAT) & RB2D_DC_BUSY))
|
|
303 break;
|
|
304 }
|
|
305 }
|
|
306
|
|
307
|
|
308 static __inline__ void _radeon_fifo_wait (struct radeonfb_info *rinfo, int entries)
|
|
309 {
|
|
310 int i;
|
|
311
|
|
312 for (i=0; i<2000000; i++)
|
|
313 if ((INREG(RBBM_STATUS) & 0x7f) >= entries)
|
|
314 return;
|
|
315 }
|
|
316
|
|
317
|
|
318 static __inline__ void _radeon_engine_idle (struct radeonfb_info *rinfo)
|
|
319 {
|
|
320 int i;
|
|
321
|
|
322 /* ensure FIFO is empty before waiting for idle */
|
|
323 _radeon_fifo_wait (rinfo, 64);
|
|
324
|
|
325 for (i=0; i<2000000; i++) {
|
|
326 if (((INREG(RBBM_STATUS) & GUI_ACTIVE)) == 0) {
|
|
327 radeon_engine_flush (rinfo);
|
|
328 return;
|
|
329 }
|
|
330 }
|
|
331 }
|
|
332
|
|
333
|
|
334 #define radeon_engine_idle() _radeon_engine_idle(rinfo)
|
|
335 #define radeon_fifo_wait(entries) _radeon_fifo_wait(rinfo,entries)
|
|
336
|
|
337
|
|
338
|
|
339 /*
|
|
340 * helper routines
|
|
341 */
|
|
342
|
|
343 static __inline__ u32 radeon_get_dstbpp(u16 depth)
|
|
344 {
|
|
345 switch (depth) {
|
|
346 case 8:
|
|
347 return DST_8BPP;
|
|
348 case 15:
|
|
349 return DST_15BPP;
|
|
350 case 16:
|
|
351 return DST_16BPP;
|
1914
|
352 case 24:
|
|
353 return DST_24BPP;
|
1911
|
354 case 32:
|
|
355 return DST_32BPP;
|
|
356 default:
|
|
357 return 0;
|
|
358 }
|
|
359 }
|
|
360
|
|
361
|
|
362 static void _radeon_engine_reset(struct radeonfb_info *rinfo)
|
|
363 {
|
|
364 u32 clock_cntl_index, mclk_cntl, rbbm_soft_reset;
|
|
365
|
|
366 radeon_engine_flush (rinfo);
|
|
367
|
|
368 clock_cntl_index = INREG(CLOCK_CNTL_INDEX);
|
|
369 mclk_cntl = INPLL(MCLK_CNTL);
|
|
370
|
|
371 OUTPLL(MCLK_CNTL, (mclk_cntl |
|
|
372 FORCEON_MCLKA |
|
|
373 FORCEON_MCLKB |
|
|
374 FORCEON_YCLKA |
|
|
375 FORCEON_YCLKB |
|
|
376 FORCEON_MC |
|
|
377 FORCEON_AIC));
|
|
378 rbbm_soft_reset = INREG(RBBM_SOFT_RESET);
|
|
379
|
|
380 OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset |
|
|
381 SOFT_RESET_CP |
|
|
382 SOFT_RESET_HI |
|
|
383 SOFT_RESET_SE |
|
|
384 SOFT_RESET_RE |
|
|
385 SOFT_RESET_PP |
|
|
386 SOFT_RESET_E2 |
|
|
387 SOFT_RESET_RB |
|
|
388 SOFT_RESET_HDP);
|
|
389 INREG(RBBM_SOFT_RESET);
|
|
390 OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset & (u32)
|
|
391 ~(SOFT_RESET_CP |
|
|
392 SOFT_RESET_HI |
|
|
393 SOFT_RESET_SE |
|
|
394 SOFT_RESET_RE |
|
|
395 SOFT_RESET_PP |
|
|
396 SOFT_RESET_E2 |
|
|
397 SOFT_RESET_RB |
|
|
398 SOFT_RESET_HDP));
|
|
399 INREG(RBBM_SOFT_RESET);
|
|
400
|
|
401 OUTPLL(MCLK_CNTL, mclk_cntl);
|
|
402 OUTREG(CLOCK_CNTL_INDEX, clock_cntl_index);
|
|
403 OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset);
|
|
404
|
|
405 return;
|
|
406 }
|
|
407
|
|
408 #define radeon_engine_reset() _radeon_engine_reset(rinfo)
|
|
409
|
|
410
|
|
411 static __inline__ u8 radeon_get_post_div_bitval(int post_div)
|
|
412 {
|
|
413 switch (post_div) {
|
|
414 case 1:
|
|
415 return 0x00;
|
|
416 case 2:
|
|
417 return 0x01;
|
|
418 case 3:
|
|
419 return 0x04;
|
|
420 case 4:
|
|
421 return 0x02;
|
|
422 case 6:
|
|
423 return 0x06;
|
|
424 case 8:
|
|
425 return 0x03;
|
|
426 case 12:
|
|
427 return 0x07;
|
|
428 default:
|
|
429 return 0x02;
|
|
430 }
|
|
431 }
|
|
432
|
|
433
|
|
434
|
|
435 static __inline__ int round_div(int num, int den)
|
|
436 {
|
|
437 return (num + (den / 2)) / den;
|
|
438 }
|
|
439
|
|
440
|
|
441
|
|
442 static __inline__ int min_bits_req(int val)
|
|
443 {
|
|
444 int bits_req = 0;
|
|
445
|
|
446 if (val == 0)
|
|
447 bits_req = 1;
|
|
448
|
|
449 while (val) {
|
|
450 val >>= 1;
|
|
451 bits_req++;
|
|
452 }
|
|
453
|
|
454 return (bits_req);
|
|
455 }
|
|
456
|
|
457
|
|
458 static __inline__ int _max(int val1, int val2)
|
|
459 {
|
|
460 if (val1 >= val2)
|
|
461 return val1;
|
|
462 else
|
|
463 return val2;
|
|
464 }
|
|
465
|
|
466
|
|
467
|
|
468 /*
|
|
469 * globals
|
|
470 */
|
|
471
|
|
472 static char fontname[40] __initdata;
|
|
473 static char *mode_option __initdata;
|
|
474 static char noaccel __initdata = 0;
|
|
475
|
1914
|
476 #if 0
|
1911
|
477 #ifdef FBCON_HAS_CFB8
|
|
478 static struct display_switch fbcon_radeon8;
|
|
479 #endif
|
1914
|
480 #endif
|
1911
|
481
|
|
482 /*
|
|
483 * prototypes
|
|
484 */
|
|
485
|
|
486 static int radeonfb_get_fix (struct fb_fix_screeninfo *fix, int con,
|
|
487 struct fb_info *info);
|
|
488 static int radeonfb_get_var (struct fb_var_screeninfo *var, int con,
|
|
489 struct fb_info *info);
|
|
490 static int radeonfb_set_var (struct fb_var_screeninfo *var, int con,
|
|
491 struct fb_info *info);
|
|
492 static int radeonfb_get_cmap (struct fb_cmap *cmap, int kspc, int con,
|
|
493 struct fb_info *info);
|
|
494 static int radeonfb_set_cmap (struct fb_cmap *cmap, int kspc, int con,
|
|
495 struct fb_info *info);
|
|
496 static int radeonfb_pan_display (struct fb_var_screeninfo *var, int con,
|
|
497 struct fb_info *info);
|
|
498 static int radeonfb_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
|
|
499 unsigned long arg, int con, struct fb_info *info);
|
|
500 static int radeonfb_switch (int con, struct fb_info *info);
|
|
501 static int radeonfb_updatevar (int con, struct fb_info *info);
|
|
502 static void radeonfb_blank (int blank, struct fb_info *info);
|
|
503 static int radeon_get_cmap_len (const struct fb_var_screeninfo *var);
|
|
504 static int radeon_getcolreg (unsigned regno, unsigned *red, unsigned *green,
|
|
505 unsigned *blue, unsigned *transp,
|
|
506 struct fb_info *info);
|
|
507 static int radeon_setcolreg (unsigned regno, unsigned red, unsigned green,
|
|
508 unsigned blue, unsigned transp, struct fb_info *info);
|
1914
|
509 static void radeon_set_dispsw (struct radeonfb_info *rinfo, struct display *disp);
|
1911
|
510 static void radeon_save_state (struct radeonfb_info *rinfo,
|
|
511 struct radeon_regs *save);
|
|
512 static void radeon_engine_init (struct radeonfb_info *rinfo);
|
|
513 static void radeon_load_video_mode (struct radeonfb_info *rinfo,
|
|
514 struct fb_var_screeninfo *mode);
|
|
515 static void radeon_write_mode (struct radeonfb_info *rinfo,
|
|
516 struct radeon_regs *mode);
|
|
517 static int __devinit radeon_set_fbinfo (struct radeonfb_info *rinfo);
|
|
518 static int __devinit radeon_init_disp (struct radeonfb_info *rinfo);
|
|
519 static int radeon_init_disp_var (struct radeonfb_info *rinfo);
|
|
520 static int radeonfb_pci_register (struct pci_dev *pdev,
|
|
521 const struct pci_device_id *ent);
|
|
522 static void __devexit radeonfb_pci_unregister (struct pci_dev *pdev);
|
|
523 static char *radeon_find_rom(struct radeonfb_info *rinfo);
|
|
524 static void radeon_get_pllinfo(struct radeonfb_info *rinfo, char *bios_seg);
|
1914
|
525 static void do_install_cmap(int con, struct fb_info *info);
|
|
526 static int radeonfb_do_maximize(struct radeonfb_info *rinfo,
|
|
527 struct fb_var_screeninfo *var,
|
|
528 struct fb_var_screeninfo *v,
|
|
529 int nom, int den);
|
1911
|
530
|
|
531 static struct fb_ops radeon_fb_ops = {
|
|
532 fb_get_fix: radeonfb_get_fix,
|
|
533 fb_get_var: radeonfb_get_var,
|
|
534 fb_set_var: radeonfb_set_var,
|
|
535 fb_get_cmap: radeonfb_get_cmap,
|
|
536 fb_set_cmap: radeonfb_set_cmap,
|
|
537 fb_pan_display: radeonfb_pan_display,
|
|
538 fb_ioctl: radeonfb_ioctl,
|
|
539 };
|
|
540
|
|
541
|
|
542 static struct pci_driver radeonfb_driver = {
|
|
543 name: "radeonfb",
|
|
544 id_table: radeonfb_pci_table,
|
|
545 probe: radeonfb_pci_register,
|
|
546 remove: radeonfb_pci_unregister,
|
|
547 };
|
|
548
|
|
549
|
|
550 int __init radeonfb_init (void)
|
|
551 {
|
|
552 return pci_module_init (&radeonfb_driver);
|
|
553 }
|
|
554
|
|
555
|
|
556 void __exit radeonfb_exit (void)
|
|
557 {
|
|
558 pci_unregister_driver (&radeonfb_driver);
|
|
559 }
|
|
560
|
|
561
|
|
562 int __init radeonfb_setup (char *options)
|
|
563 {
|
|
564 char *this_opt;
|
|
565
|
|
566 if (!options || !*options)
|
|
567 return 0;
|
|
568
|
|
569 for (this_opt = strtok (options, ","); this_opt;
|
|
570 this_opt = strtok (NULL, ",")) {
|
|
571 if (!strncmp (this_opt, "font:", 5)) {
|
|
572 char *p;
|
|
573 int i;
|
|
574
|
|
575 p = this_opt + 5;
|
|
576 for (i=0; i<sizeof (fontname) - 1; i++)
|
|
577 if (!*p || *p == ' ' || *p == ',')
|
|
578 break;
|
|
579 memcpy(fontname, this_opt + 5, i);
|
|
580 } else if (!strncmp(this_opt, "noaccel", 7)) {
|
|
581 noaccel = 1;
|
|
582 }
|
|
583 else mode_option = this_opt;
|
|
584 }
|
|
585
|
|
586 return 0;
|
|
587 }
|
|
588
|
|
589 #ifdef MODULE
|
|
590 module_init(radeonfb_init);
|
|
591 module_exit(radeonfb_exit);
|
|
592 #endif
|
|
593
|
|
594
|
|
595 MODULE_AUTHOR("Ani Joshi");
|
|
596 MODULE_DESCRIPTION("framebuffer driver for ATI Radeon chipset");
|
|
597
|
|
598
|
|
599
|
|
600 static int radeonfb_pci_register (struct pci_dev *pdev,
|
|
601 const struct pci_device_id *ent)
|
|
602 {
|
|
603 struct radeonfb_info *rinfo;
|
|
604 u32 tmp;
|
|
605 int i, j;
|
|
606 char *bios_seg = NULL;
|
|
607
|
|
608 rinfo = kmalloc (sizeof (struct radeonfb_info), GFP_KERNEL);
|
|
609 if (!rinfo) {
|
|
610 printk ("radeonfb: could not allocate memory\n");
|
|
611 return -ENODEV;
|
|
612 }
|
|
613
|
|
614 memset (rinfo, 0, sizeof (struct radeonfb_info));
|
|
615
|
|
616 /* enable device */
|
|
617 {
|
|
618 int err;
|
|
619
|
|
620 if ((err = pci_enable_device(pdev))) {
|
|
621 printk("radeonfb: cannot enable device\n");
|
|
622 kfree (rinfo);
|
|
623 return -ENODEV;
|
|
624 }
|
|
625 }
|
|
626
|
|
627 /* set base addrs */
|
|
628 rinfo->fb_base_phys = pci_resource_start (pdev, 0);
|
|
629 rinfo->mmio_base_phys = pci_resource_start (pdev, 2);
|
|
630
|
|
631 /* request the mem regions */
|
|
632 if (!request_mem_region (rinfo->fb_base_phys,
|
|
633 pci_resource_len(pdev, 0), "radeonfb")) {
|
|
634 printk ("radeonfb: cannot reserve FB region\n");
|
|
635 kfree (rinfo);
|
|
636 return -ENODEV;
|
|
637 }
|
|
638
|
|
639 if (!request_mem_region (rinfo->mmio_base_phys,
|
|
640 pci_resource_len(pdev, 2), "radeonfb")) {
|
|
641 printk ("radeonfb: cannot reserve MMIO region\n");
|
|
642 release_mem_region (rinfo->fb_base_phys,
|
|
643 pci_resource_len(pdev, 0));
|
|
644 kfree (rinfo);
|
|
645 return -ENODEV;
|
|
646 }
|
|
647
|
|
648 /* map the regions */
|
|
649 rinfo->mmio_base = (u32) ioremap (rinfo->mmio_base_phys,
|
|
650 RADEON_REGSIZE);
|
|
651 if (!rinfo->mmio_base) {
|
|
652 printk ("radeonfb: cannot map MMIO\n");
|
|
653 release_mem_region (rinfo->mmio_base_phys,
|
|
654 pci_resource_len(pdev, 2));
|
|
655 release_mem_region (rinfo->fb_base_phys,
|
|
656 pci_resource_len(pdev, 0));
|
|
657 kfree (rinfo);
|
|
658 return -ENODEV;
|
|
659 }
|
|
660
|
|
661 /* chipset */
|
|
662 switch (pdev->device) {
|
|
663 case PCI_DEVICE_ID_RADEON_QD:
|
|
664 strcpy(rinfo->name, "Radeon QD ");
|
|
665 break;
|
|
666 case PCI_DEVICE_ID_RADEON_QE:
|
|
667 strcpy(rinfo->name, "Radeon QE ");
|
|
668 break;
|
|
669 case PCI_DEVICE_ID_RADEON_QF:
|
|
670 strcpy(rinfo->name, "Radeon QF ");
|
|
671 break;
|
|
672 case PCI_DEVICE_ID_RADEON_QG:
|
|
673 strcpy(rinfo->name, "Radeon QG ");
|
|
674 break;
|
1913
|
675 case PCI_DEVICE_ID_RADEON_QY:
|
|
676 strcpy(rinfo->name, "Radeon VE QY");
|
|
677 break;
|
|
678 case PCI_DEVICE_ID_RADEON_QZ:
|
|
679 strcpy(rinfo->name, "Radeon VE QZ");
|
1912
|
680 break;
|
1911
|
681 default:
|
|
682 return -ENODEV;
|
|
683 }
|
|
684
|
|
685 /* framebuffer size */
|
|
686 tmp = INREG(CONFIG_MEMSIZE);
|
|
687
|
|
688 /* mem size is bits [28:0], mask off the rest */
|
|
689 rinfo->video_ram = tmp & CONFIG_MEMSIZE_MASK;
|
|
690
|
|
691 /* ram type */
|
|
692 tmp = INREG(MEM_SDRAM_MODE_REG);
|
|
693 switch ((MEM_CFG_TYPE & tmp) >> 30) {
|
|
694 case 0:
|
|
695 /* SDR SGRAM (2:1) */
|
|
696 strcpy(rinfo->ram_type, "SDR SGRAM");
|
|
697 rinfo->ram.ml = 4;
|
|
698 rinfo->ram.mb = 4;
|
|
699 rinfo->ram.trcd = 1;
|
|
700 rinfo->ram.trp = 2;
|
|
701 rinfo->ram.twr = 1;
|
|
702 rinfo->ram.cl = 2;
|
|
703 rinfo->ram.loop_latency = 16;
|
|
704 rinfo->ram.rloop = 16;
|
|
705
|
|
706 break;
|
|
707 case 1:
|
|
708 /* DDR SGRAM */
|
|
709 strcpy(rinfo->ram_type, "DDR SGRAM");
|
|
710 rinfo->ram.ml = 4;
|
|
711 rinfo->ram.mb = 4;
|
|
712 rinfo->ram.trcd = 3;
|
|
713 rinfo->ram.trp = 3;
|
|
714 rinfo->ram.twr = 2;
|
|
715 rinfo->ram.cl = 3;
|
|
716 rinfo->ram.tr2w = 1;
|
|
717 rinfo->ram.loop_latency = 16;
|
|
718 rinfo->ram.rloop = 16;
|
|
719
|
|
720 break;
|
|
721 default:
|
|
722 /* 64-bit SDR SGRAM */
|
|
723 strcpy(rinfo->ram_type, "SDR SGRAM 64");
|
|
724 rinfo->ram.ml = 4;
|
|
725 rinfo->ram.mb = 8;
|
|
726 rinfo->ram.trcd = 3;
|
|
727 rinfo->ram.trp = 3;
|
|
728 rinfo->ram.twr = 1;
|
|
729 rinfo->ram.cl = 3;
|
|
730 rinfo->ram.tr2w = 1;
|
|
731 rinfo->ram.loop_latency = 17;
|
|
732 rinfo->ram.rloop = 17;
|
|
733
|
|
734 break;
|
|
735 }
|
|
736
|
|
737 bios_seg = radeon_find_rom(rinfo);
|
|
738 radeon_get_pllinfo(rinfo, bios_seg);
|
|
739
|
|
740 printk("radeonfb: ref_clk=%d, ref_div=%d, xclk=%d\n",
|
|
741 rinfo->pll.ref_clk, rinfo->pll.ref_div, rinfo->pll.xclk);
|
|
742
|
|
743 RTRACE("radeonfb: probed %s %dk videoram\n", (rinfo->ram_type), (rinfo->video_ram/1024));
|
|
744
|
|
745 rinfo->fb_base = (u32) ioremap (rinfo->fb_base_phys,
|
|
746 rinfo->video_ram);
|
|
747 if (!rinfo->fb_base) {
|
|
748 printk ("radeonfb: cannot map FB\n");
|
|
749 iounmap ((void*)rinfo->mmio_base);
|
|
750 release_mem_region (rinfo->mmio_base_phys,
|
|
751 pci_resource_len(pdev, 2));
|
|
752 release_mem_region (rinfo->fb_base_phys,
|
|
753 pci_resource_len(pdev, 0));
|
|
754 kfree (rinfo);
|
|
755 return -ENODEV;
|
|
756 }
|
|
757
|
|
758 /* XXX turn off accel for now, blts aren't working right */
|
|
759 noaccel = 1;
|
|
760
|
|
761 /* set all the vital stuff */
|
|
762 radeon_set_fbinfo (rinfo);
|
|
763
|
|
764 /* save current mode regs before we switch into the new one
|
|
765 * so we can restore this upon __exit
|
|
766 */
|
|
767 radeon_save_state (rinfo, &rinfo->init_state);
|
|
768
|
|
769 /* init palette */
|
|
770 for (i=0; i<16; i++) {
|
|
771 j = color_table[i];
|
|
772 rinfo->palette[i].red = default_red[j];
|
|
773 rinfo->palette[i].green = default_grn[j];
|
|
774 rinfo->palette[i].blue = default_blu[j];
|
|
775 }
|
|
776
|
|
777 pdev->driver_data = rinfo;
|
|
778
|
|
779 if (register_framebuffer ((struct fb_info *) rinfo) < 0) {
|
|
780 printk ("radeonfb: could not register framebuffer\n");
|
|
781 iounmap ((void*)rinfo->fb_base);
|
|
782 iounmap ((void*)rinfo->mmio_base);
|
|
783 release_mem_region (rinfo->mmio_base_phys,
|
|
784 pci_resource_len(pdev, 2));
|
|
785 release_mem_region (rinfo->fb_base_phys,
|
|
786 pci_resource_len(pdev, 0));
|
|
787 kfree (rinfo);
|
|
788 return -ENODEV;
|
|
789 }
|
|
790
|
|
791 if (!noaccel) {
|
|
792 /* initialize the engine */
|
|
793 radeon_engine_init (rinfo);
|
|
794 }
|
|
795
|
1912
|
796 printk ("radeonfb: ATI %s %d MB\n", rinfo->name,
|
1911
|
797 (rinfo->video_ram/(1024*1024)));
|
|
798
|
|
799 return 0;
|
|
800 }
|
|
801
|
|
802
|
|
803
|
|
804 static void __devexit radeonfb_pci_unregister (struct pci_dev *pdev)
|
|
805 {
|
|
806 struct radeonfb_info *rinfo = pdev->driver_data;
|
|
807
|
|
808 if (!rinfo)
|
|
809 return;
|
|
810
|
|
811 /* restore original state */
|
|
812 radeon_write_mode (rinfo, &rinfo->init_state);
|
|
813
|
|
814 unregister_framebuffer ((struct fb_info *) rinfo);
|
|
815
|
|
816 iounmap ((void*)rinfo->mmio_base);
|
|
817 iounmap ((void*)rinfo->fb_base);
|
|
818
|
|
819 release_mem_region (rinfo->mmio_base_phys,
|
|
820 pci_resource_len(pdev, 2));
|
|
821 release_mem_region (rinfo->fb_base_phys,
|
|
822 pci_resource_len(pdev, 0));
|
|
823
|
|
824 kfree (rinfo);
|
|
825 }
|
|
826
|
|
827
|
|
828
|
|
829 static char *radeon_find_rom(struct radeonfb_info *rinfo)
|
|
830 {
|
1914
|
831 #if defined(__i386__)
|
1911
|
832 u32 segstart;
|
|
833 char *rom_base;
|
|
834 char *rom;
|
|
835 int stage;
|
|
836 int i;
|
|
837 char aty_rom_sig[] = "761295520";
|
|
838 char radeon_sig[] = "RG6";
|
|
839
|
|
840 for(segstart=0x000c0000; segstart<0x000f0000; segstart+=0x00001000) {
|
|
841 stage = 1;
|
|
842
|
|
843 rom_base = (char *)ioremap(segstart, 0x1000);
|
|
844
|
|
845 if ((*rom_base == 0x55) && (((*(rom_base + 1)) & 0xff) == 0xaa))
|
|
846 stage = 2;
|
|
847
|
|
848
|
|
849 if (stage != 2) {
|
|
850 iounmap(rom_base);
|
|
851 continue;
|
|
852 }
|
|
853
|
|
854 rom = rom_base;
|
|
855
|
|
856 for (i = 0; (i < 128 - strlen(aty_rom_sig)) && (stage != 3); i++) {
|
|
857 if (aty_rom_sig[0] == *rom)
|
|
858 if (strncmp(aty_rom_sig, rom,
|
|
859 strlen(aty_rom_sig)) == 0)
|
|
860 stage = 3;
|
|
861 rom++;
|
|
862 }
|
|
863 if (stage != 3) {
|
|
864 iounmap(rom_base);
|
|
865 continue;
|
|
866 }
|
|
867 rom = rom_base;
|
|
868
|
|
869 for (i = 0; (i < 512) && (stage != 4); i++) {
|
|
870 if (radeon_sig[0] == *rom)
|
|
871 if (strncmp(radeon_sig, rom,
|
|
872 strlen(radeon_sig)) == 0)
|
|
873 stage = 4;
|
|
874 rom++;
|
|
875 }
|
|
876 if (stage != 4) {
|
|
877 iounmap(rom_base);
|
|
878 continue;
|
|
879 }
|
|
880
|
|
881 return rom_base;
|
|
882 }
|
|
883 #endif
|
|
884 return NULL;
|
|
885 }
|
|
886
|
|
887
|
|
888
|
|
889 static void radeon_get_pllinfo(struct radeonfb_info *rinfo, char *bios_seg)
|
|
890 {
|
|
891 void *bios_header;
|
|
892 void *header_ptr;
|
|
893 u16 bios_header_offset, pll_info_offset;
|
|
894 PLL_BLOCK pll;
|
|
895
|
|
896 if (bios_seg) {
|
|
897 bios_header = bios_seg + 0x48L;
|
|
898 header_ptr = bios_header;
|
|
899
|
|
900 bios_header_offset = readw(header_ptr);
|
|
901 bios_header = bios_seg + bios_header_offset;
|
|
902 bios_header += 0x30;
|
|
903
|
|
904 header_ptr = bios_header;
|
|
905 pll_info_offset = readw(header_ptr);
|
|
906 header_ptr = bios_seg + pll_info_offset;
|
|
907
|
|
908 memcpy_fromio(&pll, header_ptr, 50);
|
|
909
|
|
910 rinfo->pll.xclk = (u32)pll.XCLK;
|
|
911 rinfo->pll.ref_clk = (u32)pll.PCLK_ref_freq;
|
|
912 rinfo->pll.ref_div = (u32)pll.PCLK_ref_divider;
|
|
913 rinfo->pll.ppll_min = pll.PCLK_min_freq;
|
|
914 rinfo->pll.ppll_max = pll.PCLK_max_freq;
|
|
915 } else {
|
|
916 /* no BIOS or BIOS not found, use defaults */
|
|
917
|
|
918 rinfo->pll.ppll_max = 35000;
|
|
919 rinfo->pll.ppll_min = 12000;
|
|
920 rinfo->pll.xclk = 16600;
|
|
921 rinfo->pll.ref_div = 67;
|
|
922 rinfo->pll.ref_clk = 2700;
|
|
923 }
|
|
924 }
|
|
925
|
|
926 static void radeon_engine_init (struct radeonfb_info *rinfo)
|
|
927 {
|
|
928 u32 temp;
|
|
929
|
|
930 /* disable 3D engine */
|
|
931 OUTREG(RB3D_CNTL, 0);
|
|
932
|
|
933 radeon_engine_reset ();
|
|
934
|
|
935 radeon_fifo_wait (1);
|
|
936 OUTREG(DSTCACHE_MODE, 0);
|
|
937
|
|
938 /* XXX */
|
|
939 rinfo->pitch = ((rinfo->xres * (rinfo->depth / 8) + 0x3f)) >> 6;
|
|
940
|
|
941 radeon_fifo_wait (1);
|
|
942 temp = INREG(DEFAULT_PITCH_OFFSET);
|
|
943 OUTREG(DEFAULT_PITCH_OFFSET, ((temp & 0xc0000000) |
|
|
944 (rinfo->pitch << 0x16)));
|
|
945
|
|
946 radeon_fifo_wait (1);
|
|
947 OUTREGP(DP_DATATYPE, 0, ~HOST_BIG_ENDIAN_EN);
|
|
948
|
|
949 radeon_fifo_wait (1);
|
|
950 OUTREG(DEFAULT_SC_BOTTOM_RIGHT, (DEFAULT_SC_RIGHT_MAX |
|
|
951 DEFAULT_SC_BOTTOM_MAX));
|
|
952
|
|
953 temp = radeon_get_dstbpp(rinfo->depth);
|
|
954 rinfo->dp_gui_master_cntl = ((temp << 8) | GMC_CLR_CMP_CNTL_DIS);
|
|
955 radeon_fifo_wait (1);
|
|
956 OUTREG(DP_GUI_MASTER_CNTL, (rinfo->dp_gui_master_cntl |
|
|
957 GMC_BRUSH_SOLID_COLOR |
|
|
958 GMC_SRC_DATATYPE_COLOR));
|
|
959
|
|
960 radeon_fifo_wait (7);
|
|
961
|
|
962 /* clear line drawing regs */
|
|
963 OUTREG(DST_LINE_START, 0);
|
|
964 OUTREG(DST_LINE_END, 0);
|
|
965
|
|
966 /* set brush color regs */
|
|
967 OUTREG(DP_BRUSH_FRGD_CLR, 0xffffffff);
|
|
968 OUTREG(DP_BRUSH_BKGD_CLR, 0x00000000);
|
|
969
|
|
970 /* set source color regs */
|
|
971 OUTREG(DP_SRC_FRGD_CLR, 0xffffffff);
|
|
972 OUTREG(DP_SRC_BKGD_CLR, 0x00000000);
|
|
973
|
|
974 /* default write mask */
|
|
975 OUTREG(DP_WRITE_MSK, 0xffffffff);
|
|
976
|
|
977 radeon_engine_idle ();
|
|
978 }
|
|
979
|
|
980
|
|
981
|
|
982 static int __devinit radeon_set_fbinfo (struct radeonfb_info *rinfo)
|
|
983 {
|
|
984 struct fb_info *info;
|
|
985
|
|
986 info = &rinfo->info;
|
|
987
|
|
988 strcpy (info->modename, rinfo->name);
|
|
989 info->node = -1;
|
|
990 info->flags = FBINFO_FLAG_DEFAULT;
|
|
991 info->fbops = &radeon_fb_ops;
|
|
992 info->display_fg = NULL;
|
|
993 strncpy (info->fontname, fontname, sizeof (info->fontname));
|
|
994 info->fontname[sizeof (info->fontname) - 1] = 0;
|
|
995 info->changevar = NULL;
|
|
996 info->switch_con = radeonfb_switch;
|
|
997 info->updatevar = radeonfb_updatevar;
|
|
998 info->blank = radeonfb_blank;
|
|
999
|
|
1000 if (radeon_init_disp (rinfo) < 0)
|
|
1001 return -1;
|
|
1002
|
|
1003 return 0;
|
|
1004 }
|
|
1005
|
|
1006
|
|
1007
|
|
1008 static int __devinit radeon_init_disp (struct radeonfb_info *rinfo)
|
|
1009 {
|
|
1010 struct fb_info *info;
|
|
1011 struct display *disp;
|
|
1012
|
|
1013 info = &rinfo->info;
|
|
1014 disp = &rinfo->disp;
|
|
1015
|
|
1016 disp->var = radeonfb_default_var;
|
|
1017 info->disp = disp;
|
|
1018
|
1914
|
1019 radeon_set_dispsw (rinfo, disp);
|
1911
|
1020
|
|
1021 if (noaccel)
|
|
1022 disp->scrollmode = SCROLL_YREDRAW;
|
|
1023 else
|
|
1024 disp->scrollmode = 0;
|
|
1025
|
|
1026 rinfo->currcon_display = disp;
|
|
1027
|
|
1028 if ((radeon_init_disp_var (rinfo)) < 0)
|
|
1029 return -1;
|
|
1030
|
|
1031 return 0;
|
|
1032 }
|
|
1033
|
|
1034
|
|
1035
|
|
1036 static int radeon_init_disp_var (struct radeonfb_info *rinfo)
|
|
1037 {
|
|
1038 #ifndef MODULE
|
|
1039 if (mode_option)
|
|
1040 fb_find_mode (&rinfo->disp.var, &rinfo->info, mode_option,
|
|
1041 NULL, 0, NULL, 8);
|
|
1042 else
|
|
1043 #endif
|
|
1044 fb_find_mode (&rinfo->disp.var, &rinfo->info, "640x480-8@60",
|
|
1045 NULL, 0, NULL, 0);
|
|
1046
|
|
1047 if (noaccel)
|
|
1048 rinfo->disp.var.accel_flags &= ~FB_ACCELF_TEXT;
|
|
1049 else
|
|
1050 rinfo->disp.var.accel_flags |= FB_ACCELF_TEXT;
|
|
1051
|
|
1052 return 0;
|
|
1053 }
|
|
1054
|
|
1055
|
1914
|
1056 static void radeon_set_dispsw (struct radeonfb_info *rinfo, struct display *disp)
|
1911
|
1057 {
|
|
1058 int accel;
|
|
1059
|
|
1060 accel = disp->var.accel_flags & FB_ACCELF_TEXT;
|
|
1061
|
|
1062 disp->dispsw_data = NULL;
|
|
1063
|
|
1064 disp->screen_base = (char*)rinfo->fb_base;
|
|
1065 disp->type = FB_TYPE_PACKED_PIXELS;
|
|
1066 disp->type_aux = 0;
|
|
1067 disp->ypanstep = 1;
|
|
1068 disp->ywrapstep = 0;
|
|
1069 disp->can_soft_blank = 1;
|
|
1070 disp->inverse = 0;
|
|
1071
|
|
1072 rinfo->depth = disp->var.bits_per_pixel;
|
|
1073 switch (disp->var.bits_per_pixel) {
|
|
1074 #ifdef FBCON_HAS_CFB8
|
|
1075 case 8:
|
1914
|
1076 disp->dispsw = &fbcon_cfb8;
|
1911
|
1077 disp->visual = FB_VISUAL_PSEUDOCOLOR;
|
|
1078 disp->line_length = disp->var.xres_virtual;
|
|
1079 break;
|
|
1080 #endif
|
|
1081 #ifdef FBCON_HAS_CFB16
|
|
1082 case 16:
|
|
1083 disp->dispsw = &fbcon_cfb16;
|
|
1084 disp->dispsw_data = &rinfo->con_cmap.cfb16;
|
|
1085 disp->visual = FB_VISUAL_DIRECTCOLOR;
|
|
1086 disp->line_length = disp->var.xres_virtual * 2;
|
|
1087 break;
|
|
1088 #endif
|
|
1089 #ifdef FBCON_HAS_CFB32
|
1914
|
1090 case 24:
|
|
1091 disp->dispsw = &fbcon_cfb24;
|
|
1092 disp->dispsw_data = &rinfo->con_cmap.cfb24;
|
|
1093 disp->visual = FB_VISUAL_DIRECTCOLOR;
|
|
1094 disp->line_length = disp->var.xres_virtual * 4;
|
|
1095 break;
|
|
1096 #endif
|
|
1097 #ifdef FBCON_HAS_CFB32
|
1911
|
1098 case 32:
|
|
1099 disp->dispsw = &fbcon_cfb32;
|
|
1100 disp->dispsw_data = &rinfo->con_cmap.cfb32;
|
|
1101 disp->visual = FB_VISUAL_DIRECTCOLOR;
|
|
1102 disp->line_length = disp->var.xres_virtual * 4;
|
|
1103 break;
|
|
1104 #endif
|
|
1105 default:
|
|
1106 printk ("radeonfb: setting fbcon_dummy renderer\n");
|
|
1107 disp->dispsw = &fbcon_dummy;
|
|
1108 }
|
|
1109
|
|
1110 return;
|
|
1111 }
|
|
1112
|
|
1113
|
|
1114
|
|
1115 /*
|
|
1116 * fb ops
|
|
1117 */
|
|
1118
|
|
1119 static int radeonfb_get_fix (struct fb_fix_screeninfo *fix, int con,
|
|
1120 struct fb_info *info)
|
|
1121 {
|
|
1122 struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
|
|
1123 struct display *disp;
|
|
1124
|
|
1125 disp = (con < 0) ? rinfo->info.disp : &fb_display[con];
|
|
1126
|
|
1127 memset (fix, 0, sizeof (struct fb_fix_screeninfo));
|
|
1128 strcpy (fix->id, rinfo->name);
|
|
1129
|
|
1130 fix->smem_start = rinfo->fb_base_phys;
|
|
1131 fix->smem_len = rinfo->video_ram;
|
|
1132
|
|
1133 fix->type = disp->type;
|
|
1134 fix->type_aux = disp->type_aux;
|
|
1135 fix->visual = disp->visual;
|
|
1136
|
|
1137 fix->xpanstep = 1;
|
|
1138 fix->ypanstep = 1;
|
|
1139 fix->ywrapstep = 0;
|
|
1140
|
|
1141 fix->line_length = disp->line_length;
|
|
1142
|
|
1143 fix->mmio_start = rinfo->mmio_base_phys;
|
|
1144 fix->mmio_len = RADEON_REGSIZE;
|
|
1145 if (noaccel)
|
|
1146 fix->accel = FB_ACCEL_NONE;
|
|
1147 else
|
|
1148 fix->accel = 40; /* XXX */
|
|
1149
|
|
1150 return 0;
|
|
1151 }
|
|
1152
|
|
1153
|
|
1154
|
|
1155 static int radeonfb_get_var (struct fb_var_screeninfo *var, int con,
|
|
1156 struct fb_info *info)
|
|
1157 {
|
|
1158 struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
|
|
1159
|
|
1160 *var = (con < 0) ? rinfo->disp.var : fb_display[con].var;
|
|
1161
|
|
1162 return 0;
|
|
1163 }
|
|
1164
|
|
1165
|
|
1166
|
|
1167 static int radeonfb_set_var (struct fb_var_screeninfo *var, int con,
|
|
1168 struct fb_info *info)
|
|
1169 {
|
|
1170 struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
|
|
1171 struct display *disp;
|
|
1172 struct fb_var_screeninfo v;
|
1914
|
1173 int nom, den, accel;
|
1911
|
1174 unsigned chgvar = 0;
|
|
1175
|
|
1176 disp = (con < 0) ? rinfo->info.disp : &fb_display[con];
|
|
1177
|
|
1178 accel = var->accel_flags & FB_ACCELF_TEXT;
|
|
1179
|
|
1180 if (con >= 0) {
|
|
1181 chgvar = ((disp->var.xres != var->xres) ||
|
|
1182 (disp->var.yres != var->yres) ||
|
|
1183 (disp->var.xres_virtual != var->xres_virtual) ||
|
|
1184 (disp->var.yres_virtual != var->yres_virtual) ||
|
1914
|
1185 (disp->var.bits_per_pixel != var->bits_per_pixel) ||
|
1911
|
1186 memcmp (&disp->var.red, &var->red, sizeof (var->red)) ||
|
|
1187 memcmp (&disp->var.green, &var->green, sizeof (var->green)) ||
|
|
1188 memcmp (&disp->var.blue, &var->blue, sizeof (var->blue)));
|
|
1189 }
|
|
1190
|
|
1191 memcpy (&v, var, sizeof (v));
|
|
1192
|
|
1193 switch (v.bits_per_pixel) {
|
|
1194 #ifdef FBCON_HAS_CFB8
|
|
1195 case 8:
|
|
1196 nom = den = 1;
|
|
1197 disp->line_length = v.xres_virtual;
|
|
1198 disp->visual = FB_VISUAL_PSEUDOCOLOR;
|
|
1199 v.red.offset = v.green.offset = v.blue.offset = 0;
|
|
1200 v.red.length = v.green.length = v.blue.length = 8;
|
1914
|
1201 v.transp.offset = v.transp.length = 0;
|
1911
|
1202 break;
|
|
1203 #endif
|
|
1204
|
|
1205 #ifdef FBCON_HAS_CFB16
|
|
1206 case 16:
|
|
1207 nom = 2;
|
|
1208 den = 1;
|
|
1209 disp->line_length = v.xres_virtual * 2;
|
|
1210 disp->visual = FB_VISUAL_DIRECTCOLOR;
|
|
1211 v.red.offset = 11;
|
|
1212 v.green.offset = 5;
|
|
1213 v.blue.offset = 0;
|
|
1214 v.red.length = 5;
|
|
1215 v.green.length = 6;
|
|
1216 v.blue.length = 5;
|
1914
|
1217 v.transp.offset = v.transp.length = 0;
|
1911
|
1218 break;
|
|
1219 #endif
|
|
1220
|
1914
|
1221 #ifdef FBCON_HAS_CFB24
|
|
1222 case 24:
|
|
1223 nom = 4;
|
|
1224 den = 1;
|
|
1225 disp->line_length = v.xres_virtual * 3;
|
|
1226 disp->visual = FB_VISUAL_DIRECTCOLOR;
|
|
1227 v.red.offset = 16;
|
|
1228 v.green.offset = 8;
|
|
1229 v.blue.offset = 0;
|
|
1230 v.red.length = v.blue.length = v.green.length = 8;
|
|
1231 v.transp.offset = v.transp.length = 0;
|
|
1232 break;
|
|
1233 #endif
|
1911
|
1234 #ifdef FBCON_HAS_CFB32
|
|
1235 case 32:
|
|
1236 nom = 4;
|
|
1237 den = 1;
|
|
1238 disp->line_length = v.xres_virtual * 4;
|
|
1239 disp->visual = FB_VISUAL_DIRECTCOLOR;
|
|
1240 v.red.offset = 16;
|
|
1241 v.green.offset = 8;
|
|
1242 v.blue.offset = 0;
|
|
1243 v.red.length = v.blue.length = v.green.length = 8;
|
1914
|
1244 v.transp.offset = 24;
|
|
1245 v.transp.length = 8;
|
1911
|
1246 break;
|
|
1247 #endif
|
|
1248 default:
|
|
1249 printk ("radeonfb: mode %dx%dx%d rejected, color depth invalid\n",
|
|
1250 var->xres, var->yres, var->bits_per_pixel);
|
|
1251 return -EINVAL;
|
|
1252 }
|
|
1253
|
1914
|
1254 if (radeonfb_do_maximize(rinfo, var, &v, nom, den) < 0)
|
|
1255 return -EINVAL;
|
1911
|
1256
|
|
1257 if (v.xoffset < 0)
|
|
1258 v.xoffset = 0;
|
|
1259 if (v.yoffset < 0)
|
|
1260 v.yoffset = 0;
|
|
1261
|
|
1262 if (v.xoffset > v.xres_virtual - v.xres)
|
|
1263 v.xoffset = v.xres_virtual - v.xres - 1;
|
|
1264
|
|
1265 if (v.yoffset > v.yres_virtual - v.yres)
|
|
1266 v.yoffset = v.yres_virtual - v.yres - 1;
|
|
1267
|
|
1268 v.red.msb_right = v.green.msb_right = v.blue.msb_right =
|
|
1269 v.transp.offset = v.transp.length =
|
|
1270 v.transp.msb_right = 0;
|
|
1271
|
|
1272 switch (v.activate & FB_ACTIVATE_MASK) {
|
|
1273 case FB_ACTIVATE_TEST:
|
|
1274 return 0;
|
|
1275 case FB_ACTIVATE_NXTOPEN:
|
|
1276 case FB_ACTIVATE_NOW:
|
|
1277 break;
|
|
1278 default:
|
|
1279 return -EINVAL;
|
|
1280 }
|
|
1281
|
|
1282 memcpy (&disp->var, &v, sizeof (v));
|
|
1283
|
1914
|
1284 if (chgvar) {
|
|
1285 radeon_set_dispsw(rinfo, disp);
|
|
1286
|
|
1287 if (noaccel)
|
|
1288 disp->scrollmode = SCROLL_YREDRAW;
|
|
1289 else
|
|
1290 disp->scrollmode = 0;
|
|
1291
|
|
1292 if (info && info->changevar)
|
|
1293 info->changevar(con);
|
|
1294 }
|
|
1295
|
1911
|
1296 radeon_load_video_mode (rinfo, &v);
|
|
1297
|
1914
|
1298 do_install_cmap(con, info);
|
|
1299
|
1911
|
1300 return 0;
|
|
1301 }
|
|
1302
|
|
1303
|
|
1304
|
|
1305 static int radeonfb_get_cmap (struct fb_cmap *cmap, int kspc, int con,
|
|
1306 struct fb_info *info)
|
|
1307 {
|
|
1308 struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
|
|
1309 struct display *disp;
|
|
1310
|
|
1311 disp = (con < 0) ? rinfo->info.disp : &fb_display[con];
|
|
1312
|
|
1313 if (con == rinfo->currcon) {
|
|
1314 int rc = fb_get_cmap (cmap, kspc, radeon_getcolreg, info);
|
|
1315 return rc;
|
|
1316 } else if (disp->cmap.len)
|
|
1317 fb_copy_cmap (&disp->cmap, cmap, kspc ? 0 : 2);
|
|
1318 else
|
|
1319 fb_copy_cmap (fb_default_cmap (radeon_get_cmap_len (&disp->var)),
|
|
1320 cmap, kspc ? 0 : 2);
|
|
1321
|
|
1322 return 0;
|
|
1323 }
|
|
1324
|
|
1325
|
|
1326
|
|
1327 static int radeonfb_set_cmap (struct fb_cmap *cmap, int kspc, int con,
|
|
1328 struct fb_info *info)
|
|
1329 {
|
|
1330 struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
|
|
1331 struct display *disp;
|
|
1332 unsigned int cmap_len;
|
|
1333
|
|
1334 disp = (con < 0) ? rinfo->info.disp : &fb_display[con];
|
|
1335
|
|
1336 cmap_len = radeon_get_cmap_len (&disp->var);
|
|
1337 if (disp->cmap.len != cmap_len) {
|
|
1338 int err = fb_alloc_cmap (&disp->cmap, cmap_len, 0);
|
|
1339 if (err)
|
|
1340 return err;
|
|
1341 }
|
|
1342
|
|
1343 if (con == rinfo->currcon) {
|
|
1344 int rc = fb_set_cmap (cmap, kspc, radeon_setcolreg, info);
|
|
1345 return rc;
|
|
1346 } else
|
|
1347 fb_copy_cmap (cmap, &disp->cmap, kspc ? 0 : 1);
|
|
1348
|
|
1349 return 0;
|
|
1350 }
|
|
1351
|
|
1352
|
|
1353
|
|
1354 static int radeonfb_pan_display (struct fb_var_screeninfo *var, int con,
|
|
1355 struct fb_info *info)
|
|
1356 {
|
|
1357 struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
|
1914
|
1358 u32 offset, xoffset, yoffset;
|
|
1359
|
|
1360 xoffset = (var->xoffset + 7) & ~7;
|
|
1361 yoffset = var->yoffset;
|
1911
|
1362
|
1914
|
1363 if ((xoffset + var->xres > var->xres_virtual) || (yoffset+var->yres >
|
|
1364 var->yres_virtual))
|
|
1365 return -EINVAL;
|
1911
|
1366
|
1914
|
1367 offset = ((yoffset * var->xres + xoffset) * var->bits_per_pixel) >> 6;
|
|
1368
|
|
1369 OUTREG(CRTC_OFFSET, offset);
|
1911
|
1370
|
|
1371 return 0;
|
|
1372 }
|
|
1373
|
|
1374
|
1914
|
1375 static void do_install_cmap(int con, struct fb_info *info)
|
|
1376 {
|
|
1377 struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
|
|
1378
|
|
1379 if (con != rinfo->currcon)
|
|
1380 return;
|
|
1381
|
|
1382 if (fb_display[con].cmap.len)
|
|
1383 fb_set_cmap(&fb_display[con].cmap, 1, radeon_setcolreg, info);
|
|
1384 else {
|
|
1385 int size = fb_display[con].var.bits_per_pixel == 8 ? 256 : 32;
|
|
1386 fb_set_cmap(fb_default_cmap(size), 1, radeon_setcolreg, info);
|
|
1387 }
|
|
1388 }
|
|
1389
|
|
1390
|
|
1391 static int radeonfb_do_maximize(struct radeonfb_info *rinfo,
|
|
1392 struct fb_var_screeninfo *var,
|
|
1393 struct fb_var_screeninfo *v,
|
|
1394 int nom, int den)
|
|
1395 {
|
|
1396 static struct {
|
|
1397 int xres, yres;
|
|
1398 } modes[] = {
|
|
1399 {1600, 1280},
|
|
1400 {1280, 1024},
|
|
1401 {1024, 768},
|
|
1402 {800, 600},
|
|
1403 {640, 480},
|
|
1404 {-1, -1}
|
|
1405 };
|
|
1406 int i;
|
|
1407
|
|
1408 /* use highest possible virtual resolution */
|
|
1409 if (v->xres_virtual == -1 && v->yres_virtual == -1) {
|
|
1410 printk("radeonfb: using max availabe virtual resolution\n");
|
|
1411 for (i=0; modes[i].xres != -1; i++) {
|
|
1412 if (modes[i].xres * nom / den * modes[i].yres <
|
|
1413 rinfo->video_ram / 2)
|
|
1414 break;
|
|
1415 }
|
|
1416 if (modes[i].xres == -1) {
|
|
1417 printk("radeonfb: could not find virtual resolution that fits into video memory!\n");
|
|
1418 return -EINVAL;
|
|
1419 }
|
|
1420 v->xres_virtual = modes[i].xres;
|
|
1421 v->yres_virtual = modes[i].yres;
|
|
1422
|
|
1423 printk("radeonfb: virtual resolution set to max of %dx%d\n",
|
|
1424 v->xres_virtual, v->yres_virtual);
|
|
1425 } else if (v->xres_virtual == -1) {
|
|
1426 v->xres_virtual = (rinfo->video_ram * den /
|
|
1427 (nom * v->yres_virtual * 2)) & ~15;
|
|
1428 } else if (v->yres_virtual == -1) {
|
|
1429 v->xres_virtual = (v->xres_virtual + 15) & ~15;
|
|
1430 v->yres_virtual = rinfo->video_ram * den /
|
|
1431 (nom * v->xres_virtual *2);
|
|
1432 } else {
|
|
1433 if (v->xres_virtual * nom / den * v->yres_virtual >
|
|
1434 rinfo->video_ram) {
|
|
1435 return -EINVAL;
|
|
1436 }
|
|
1437 }
|
|
1438
|
|
1439 if (v->xres_virtual * nom / den >= 8192) {
|
|
1440 v->xres_virtual = 8192 * den / nom - 16;
|
|
1441 }
|
|
1442
|
|
1443 if (v->xres_virtual < v->xres)
|
|
1444 return -EINVAL;
|
|
1445
|
|
1446 if (v->yres_virtual < v->yres)
|
|
1447 return -EINVAL;
|
|
1448
|
|
1449 return 0;
|
|
1450 }
|
|
1451
|
1911
|
1452
|
|
1453 static int radeonfb_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
|
|
1454 unsigned long arg, int con, struct fb_info *info)
|
|
1455 {
|
|
1456 return -EINVAL;
|
|
1457 }
|
|
1458
|
|
1459
|
|
1460
|
|
1461 static int radeonfb_switch (int con, struct fb_info *info)
|
|
1462 {
|
|
1463 struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
|
|
1464 struct display *disp;
|
|
1465 struct fb_cmap *cmap;
|
|
1466 int switchcon = 0;
|
1914
|
1467
|
1911
|
1468 disp = (con < 0) ? rinfo->info.disp : &fb_display[con];
|
|
1469
|
|
1470 if (rinfo->currcon >= 0) {
|
|
1471 cmap = &(rinfo->currcon_display->cmap);
|
|
1472 if (cmap->len)
|
|
1473 fb_get_cmap (cmap, 1, radeon_getcolreg, info);
|
|
1474 }
|
|
1475
|
|
1476 if ((disp->var.xres != rinfo->xres) ||
|
|
1477 (disp->var.yres != rinfo->yres) ||
|
|
1478 (disp->var.pixclock != rinfo->pixclock) ||
|
|
1479 (disp->var.bits_per_pixel != rinfo->depth))
|
|
1480 switchcon = 1;
|
|
1481
|
|
1482 if (switchcon) {
|
|
1483 rinfo->currcon = con;
|
|
1484 rinfo->currcon_display = disp;
|
|
1485 disp->var.activate = FB_ACTIVATE_NOW;
|
|
1486
|
|
1487 radeonfb_set_var (&disp->var, con, info);
|
1914
|
1488 radeon_set_dispsw (rinfo, disp);
|
|
1489 do_install_cmap(con, info);
|
1911
|
1490 }
|
1914
|
1491
|
|
1492 /* XXX absurd hack for X to restore console */
|
|
1493 {
|
|
1494 OUTREG(CRTC_EXT_CNTL, rinfo->hack_crtc_ext_cntl);
|
|
1495 OUTREG(CRTC_V_SYNC_STRT_WID, rinfo->hack_crtc_v_sync_strt_wid);
|
|
1496 }
|
|
1497
|
1911
|
1498 return 0;
|
|
1499 }
|
|
1500
|
|
1501
|
|
1502
|
|
1503 static int radeonfb_updatevar (int con, struct fb_info *info)
|
|
1504 {
|
|
1505 int rc;
|
|
1506
|
|
1507 rc = (con < 0) ? -EINVAL : radeonfb_pan_display (&fb_display[con].var,
|
|
1508 con, info);
|
|
1509
|
|
1510 return rc;
|
|
1511 }
|
|
1512
|
|
1513 static void radeonfb_blank (int blank, struct fb_info *info)
|
|
1514 {
|
|
1515 struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
|
1914
|
1516 u32 val = INREG(CRTC_EXT_CNTL);
|
|
1517
|
|
1518 /* reset it */
|
|
1519 val &= ~(CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS |
|
|
1520 CRTC_VSYNC_DIS);
|
1911
|
1521
|
|
1522 switch (blank) {
|
1914
|
1523 case VESA_NO_BLANKING:
|
|
1524 break;
|
|
1525 case VESA_VSYNC_SUSPEND:
|
|
1526 val |= (CRTC_DISPLAY_DIS | CRTC_VSYNC_DIS);
|
1911
|
1527 break;
|
1914
|
1528 case VESA_HSYNC_SUSPEND:
|
|
1529 val |= (CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS);
|
1911
|
1530 break;
|
1914
|
1531 case VESA_POWERDOWN:
|
|
1532 val |= (CRTC_DISPLAY_DIS | CRTC_VSYNC_DIS |
|
|
1533 CRTC_HSYNC_DIS);
|
1911
|
1534 break;
|
|
1535 }
|
|
1536
|
1914
|
1537 OUTREG(CRTC_EXT_CNTL, val);
|
1911
|
1538 }
|
|
1539
|
|
1540
|
|
1541
|
|
1542 static int radeon_get_cmap_len (const struct fb_var_screeninfo *var)
|
|
1543 {
|
|
1544 int rc = 16; /* reasonable default */
|
|
1545
|
|
1546 switch (var->bits_per_pixel) {
|
|
1547 case 8:
|
|
1548 rc = 256;
|
|
1549 break;
|
|
1550 case 16:
|
|
1551 rc = 64;
|
|
1552 break;
|
|
1553 default:
|
|
1554 rc = 32;
|
|
1555 break;
|
|
1556 }
|
|
1557
|
|
1558 return rc;
|
|
1559 }
|
|
1560
|
|
1561
|
|
1562
|
|
1563 static int radeon_getcolreg (unsigned regno, unsigned *red, unsigned *green,
|
|
1564 unsigned *blue, unsigned *transp,
|
|
1565 struct fb_info *info)
|
|
1566 {
|
|
1567 struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
|
|
1568
|
|
1569 if (regno > 255)
|
|
1570 return 1;
|
|
1571
|
|
1572 *red = (rinfo->palette[regno].red<<8) | rinfo->palette[regno].red;
|
|
1573 *green = (rinfo->palette[regno].green<<8) | rinfo->palette[regno].green;
|
|
1574 *blue = (rinfo->palette[regno].blue<<8) | rinfo->palette[regno].blue;
|
|
1575 *transp = 0;
|
|
1576
|
|
1577 return 0;
|
|
1578 }
|
|
1579
|
|
1580
|
|
1581
|
|
1582 static int radeon_setcolreg (unsigned regno, unsigned red, unsigned green,
|
|
1583 unsigned blue, unsigned transp, struct fb_info *info)
|
|
1584 {
|
|
1585 struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
|
1914
|
1586 u32 pindex;
|
1911
|
1587
|
|
1588 if (regno > 255)
|
|
1589 return 1;
|
|
1590
|
|
1591 red >>= 8;
|
|
1592 green >>= 8;
|
|
1593 blue >>= 8;
|
|
1594 rinfo->palette[regno].red = red;
|
|
1595 rinfo->palette[regno].green = green;
|
|
1596 rinfo->palette[regno].blue = blue;
|
|
1597
|
|
1598 /* init gamma for hicolor */
|
|
1599 if ((rinfo->depth > 8) && (regno == 0)) {
|
|
1600 int i;
|
|
1601
|
|
1602 for (i=0; i<255; i++) {
|
|
1603 OUTREG(PALETTE_INDEX, i);
|
1914
|
1604 OUTREG(PALETTE_DATA, (i << 16) | (i << 8) | i);
|
1911
|
1605 }
|
|
1606 }
|
|
1607
|
|
1608 /* default */
|
|
1609 pindex = regno;
|
1914
|
1610
|
|
1611 /* XXX actually bpp, fixme */
|
|
1612 if (rinfo->depth == 16)
|
|
1613 pindex = regno * 8;
|
|
1614
|
|
1615 if (rinfo->depth == 16) {
|
|
1616 OUTREG(PALETTE_INDEX, pindex/2);
|
|
1617 OUTREG(PALETTE_DATA, (rinfo->palette[regno/2].red << 16) |
|
|
1618 (green << 8) | (rinfo->palette[regno/2].blue));
|
|
1619 green = rinfo->palette[regno/2].green;
|
|
1620 }
|
|
1621
|
|
1622 if ((rinfo->depth == 8) || (regno < 32)) {
|
|
1623 OUTREG(PALETTE_INDEX, pindex);
|
|
1624 OUTREG(PALETTE_DATA, (red << 16) | (green << 8) | blue);
|
|
1625 }
|
|
1626
|
|
1627 #if 0
|
1911
|
1628 col = (red << 16) | (green << 8) | blue;
|
|
1629
|
|
1630 if (rinfo->depth == 16) {
|
|
1631 pindex = regno << 3;
|
|
1632
|
|
1633 if ((rinfo->depth == 16) && (regno >= 32)) {
|
|
1634 pindex -= 252;
|
|
1635
|
|
1636 col = (rinfo->palette[regno >> 1].red << 16) |
|
|
1637 (green << 8) |
|
|
1638 (rinfo->palette[regno >> 1].blue);
|
|
1639 } else {
|
|
1640 col = (red << 16) | (green << 8) | blue;
|
|
1641 }
|
|
1642 }
|
|
1643
|
|
1644 OUTREG8(PALETTE_INDEX, pindex);
|
|
1645 radeon_fifo_wait(32);
|
|
1646 OUTREG(PALETTE_DATA, col);
|
1914
|
1647 #endif
|
1911
|
1648
|
|
1649 #if defined(FBCON_HAS_CFB16) || defined(FBCON_HAS_CFB32)
|
|
1650 if (regno < 32) {
|
|
1651 switch (rinfo->depth) {
|
|
1652 #ifdef FBCON_HAS_CFB16
|
|
1653 case 16:
|
1914
|
1654 rinfo->con_cmap.cfb16[regno] = (regno << 11) | (regno << 5) |
|
1911
|
1655 regno;
|
|
1656 break;
|
|
1657 #endif
|
1914
|
1658 #ifdef FBCON_HAS_CFB24
|
|
1659 case 24:
|
|
1660 rinfo->con_cmap.cfb24[regno] = (regno << 16) | (regno << 8) | regno;
|
|
1661 break;
|
|
1662 #endif
|
1911
|
1663 #ifdef FBCON_HAS_CFB32
|
|
1664 case 32: {
|
|
1665 u32 i;
|
|
1666
|
|
1667 i = (regno << 8) | regno;
|
|
1668 rinfo->con_cmap.cfb32[regno] = (i << 16) | i;
|
|
1669 break;
|
|
1670 }
|
|
1671 #endif
|
|
1672 }
|
|
1673 }
|
|
1674 #endif
|
|
1675 return 0;
|
|
1676 }
|
|
1677
|
|
1678
|
|
1679
|
|
1680 static void radeon_save_state (struct radeonfb_info *rinfo,
|
|
1681 struct radeon_regs *save)
|
|
1682 {
|
|
1683 save->crtc_gen_cntl = INREG(CRTC_GEN_CNTL);
|
|
1684 save->crtc_ext_cntl = INREG(CRTC_EXT_CNTL);
|
|
1685 save->dac_cntl = INREG(DAC_CNTL);
|
|
1686 save->crtc_h_total_disp = INREG(CRTC_H_TOTAL_DISP);
|
|
1687 save->crtc_h_sync_strt_wid = INREG(CRTC_H_SYNC_STRT_WID);
|
|
1688 save->crtc_v_total_disp = INREG(CRTC_V_TOTAL_DISP);
|
|
1689 save->crtc_v_sync_strt_wid = INREG(CRTC_V_SYNC_STRT_WID);
|
|
1690 save->crtc_pitch = INREG(CRTC_PITCH);
|
|
1691 }
|
|
1692
|
|
1693
|
|
1694
|
|
1695 static void radeon_load_video_mode (struct radeonfb_info *rinfo,
|
|
1696 struct fb_var_screeninfo *mode)
|
|
1697 {
|
|
1698 struct radeon_regs newmode;
|
|
1699 int hTotal, vTotal, hSyncStart, hSyncEnd,
|
|
1700 hSyncPol, vSyncStart, vSyncEnd, vSyncPol, cSync;
|
|
1701 u8 hsync_adj_tab[] = {0, 0x12, 9, 9, 6, 5};
|
|
1702 u32 dotClock = 1000000000 / mode->pixclock,
|
|
1703 sync, h_sync_pol, v_sync_pol;
|
|
1704 int freq = dotClock / 10; /* x 100 */
|
|
1705 int xclk_freq, vclk_freq, xclk_per_trans, xclk_per_trans_precise;
|
|
1706 int useable_precision, roff, ron;
|
|
1707 int min_bits, format = 0;
|
|
1708 int hsync_start, hsync_fudge, bytpp, hsync_wid, vsync_wid;
|
|
1709
|
|
1710 rinfo->xres = mode->xres;
|
|
1711 rinfo->yres = mode->yres;
|
|
1712 rinfo->pixclock = mode->pixclock;
|
|
1713
|
|
1714 hSyncStart = mode->xres + mode->right_margin;
|
|
1715 hSyncEnd = hSyncStart + mode->hsync_len;
|
|
1716 hTotal = hSyncEnd + mode->left_margin;
|
|
1717
|
|
1718 vSyncStart = mode->yres + mode->lower_margin;
|
|
1719 vSyncEnd = vSyncStart + mode->vsync_len;
|
|
1720 vTotal = vSyncEnd + mode->upper_margin;
|
|
1721
|
|
1722 sync = mode->sync;
|
|
1723 h_sync_pol = sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1;
|
|
1724 v_sync_pol = sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1;
|
|
1725
|
|
1726 RTRACE("hStart = %d, hEnd = %d, hTotal = %d\n",
|
|
1727 hSyncStart, hSyncEnd, hTotal);
|
|
1728 RTRACE("vStart = %d, vEnd = %d, vTotal = %d\n",
|
|
1729 vSyncStart, vSyncEnd, vTotal);
|
|
1730
|
|
1731 hsync_wid = (hSyncEnd - hSyncStart) / 8;
|
|
1732 vsync_wid = vSyncEnd - vSyncStart;
|
|
1733 if (hsync_wid == 0)
|
|
1734 hsync_wid = 1;
|
|
1735 else if (hsync_wid > 0x3f) /* max */
|
|
1736 hsync_wid = 0x3f;
|
1914
|
1737 vsync_wid = mode->vsync_len;
|
1911
|
1738 if (vsync_wid == 0)
|
|
1739 vsync_wid = 1;
|
|
1740 else if (vsync_wid > 0x1f) /* max */
|
|
1741 vsync_wid = 0x1f;
|
|
1742
|
1914
|
1743 hSyncPol = mode->sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1;
|
|
1744 vSyncPol = mode->sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1;
|
1911
|
1745
|
|
1746 cSync = mode->sync & FB_SYNC_COMP_HIGH_ACT ? (1 << 4) : 0;
|
|
1747
|
|
1748 switch (mode->bits_per_pixel) {
|
|
1749 case 8:
|
|
1750 format = DST_8BPP;
|
|
1751 bytpp = 1;
|
|
1752 break;
|
|
1753 case 16:
|
|
1754 format = DST_16BPP;
|
|
1755 bytpp = 2;
|
|
1756 break;
|
|
1757 case 24:
|
|
1758 format = DST_24BPP;
|
|
1759 bytpp = 3;
|
|
1760 break;
|
|
1761 case 32:
|
|
1762 format = DST_32BPP;
|
|
1763 bytpp = 4;
|
|
1764 break;
|
|
1765 }
|
|
1766
|
|
1767 hsync_fudge = hsync_adj_tab[format-1];
|
|
1768 hsync_start = hSyncStart - 8 + hsync_fudge;
|
|
1769
|
|
1770 newmode.crtc_gen_cntl = CRTC_EXT_DISP_EN | CRTC_EN |
|
|
1771 (format << 8);
|
|
1772
|
|
1773 newmode.crtc_ext_cntl = VGA_ATI_LINEAR | XCRT_CNT_EN;
|
|
1774
|
|
1775 newmode.dac_cntl = INREG(DAC_CNTL) | DAC_MASK_ALL | DAC_VGA_ADR_EN |
|
|
1776 DAC_8BIT_EN;
|
|
1777
|
|
1778 newmode.crtc_h_total_disp = ((((hTotal / 8) - 1) & 0xffff) |
|
|
1779 (((mode->xres / 8) - 1) << 16));
|
|
1780
|
|
1781 newmode.crtc_h_sync_strt_wid = ((hsync_start & 0x1fff) |
|
1914
|
1782 (hsync_wid << 16) | (h_sync_pol << 23));
|
1911
|
1783
|
|
1784 newmode.crtc_v_total_disp = ((vTotal - 1) & 0xffff) |
|
|
1785 ((mode->yres - 1) << 16);
|
|
1786
|
|
1787 newmode.crtc_v_sync_strt_wid = (((vSyncStart - 1) & 0xfff) |
|
1914
|
1788 (vsync_wid << 16) | (v_sync_pol << 23));
|
1911
|
1789
|
|
1790 newmode.crtc_pitch = (mode->xres >> 3);
|
|
1791
|
1914
|
1792 newmode.surface_cntl = SURF_TRANSLATION_DIS;
|
|
1793 #if defined(__BIG_ENDIAN)
|
|
1794 switch (mode->bits_per_pixel) {
|
|
1795 case 16:
|
|
1796 newmode.surface_cntl |= NONSURF_AP0_SWP_16BPP;
|
|
1797 break;
|
|
1798 case 24:
|
|
1799 case 32:
|
|
1800 newmode.surface_cntl |= NONSURF_AP0_SWP_32BPP;
|
|
1801 break;
|
|
1802 }
|
|
1803 #endif
|
|
1804
|
1911
|
1805 rinfo->pitch = ((mode->xres * ((mode->bits_per_pixel + 1) / 8) + 0x3f)
|
|
1806 & ~(0x3f)) / 64;
|
|
1807
|
|
1808 RTRACE("h_total_disp = 0x%x\t hsync_strt_wid = 0x%x\n",
|
|
1809 newmode.crtc_h_total_disp, newmode.crtc_h_sync_strt_wid);
|
|
1810 RTRACE("v_total_disp = 0x%x\t vsync_strt_wid = 0x%x\n",
|
|
1811 newmode.crtc_v_total_disp, newmode.crtc_v_sync_strt_wid);
|
|
1812
|
|
1813 newmode.xres = mode->xres;
|
|
1814 newmode.yres = mode->yres;
|
|
1815
|
|
1816 rinfo->bpp = mode->bits_per_pixel;
|
1914
|
1817 rinfo->hack_crtc_ext_cntl = newmode.crtc_ext_cntl;
|
|
1818 rinfo->hack_crtc_v_sync_strt_wid = newmode.crtc_v_sync_strt_wid;
|
1911
|
1819
|
|
1820 if (freq > rinfo->pll.ppll_max)
|
|
1821 freq = rinfo->pll.ppll_max;
|
|
1822 if (freq*12 < rinfo->pll.ppll_min)
|
|
1823 freq = rinfo->pll.ppll_min / 12;
|
|
1824
|
|
1825 {
|
|
1826 struct {
|
|
1827 int divider;
|
|
1828 int bitvalue;
|
|
1829 } *post_div,
|
|
1830 post_divs[] = {
|
|
1831 { 1, 0 },
|
|
1832 { 2, 1 },
|
|
1833 { 4, 2 },
|
|
1834 { 8, 3 },
|
|
1835 { 3, 4 },
|
|
1836 { 16, 5 },
|
|
1837 { 6, 6 },
|
|
1838 { 12, 7 },
|
|
1839 { 0, 0 },
|
|
1840 };
|
|
1841
|
|
1842 for (post_div = &post_divs[0]; post_div->divider; ++post_div) {
|
|
1843 rinfo->pll_output_freq = post_div->divider * freq;
|
|
1844 if (rinfo->pll_output_freq >= rinfo->pll.ppll_min &&
|
|
1845 rinfo->pll_output_freq <= rinfo->pll.ppll_max)
|
|
1846 break;
|
|
1847 }
|
|
1848
|
|
1849 rinfo->post_div = post_div->divider;
|
|
1850 rinfo->fb_div = round_div(rinfo->pll.ref_div*rinfo->pll_output_freq,
|
|
1851 rinfo->pll.ref_clk);
|
|
1852 newmode.ppll_ref_div = rinfo->pll.ref_div;
|
|
1853 newmode.ppll_div_3 = rinfo->fb_div | (post_div->bitvalue << 16);
|
|
1854 }
|
|
1855
|
|
1856 RTRACE("post div = 0x%x\n", rinfo->post_div);
|
|
1857 RTRACE("fb_div = 0x%x\n", rinfo->fb_div);
|
|
1858 RTRACE("ppll_div_3 = 0x%x\n", newmode.ppll_div_3);
|
|
1859
|
|
1860 /* DDA */
|
|
1861 vclk_freq = round_div(rinfo->pll.ref_clk * rinfo->fb_div,
|
|
1862 rinfo->pll.ref_div * rinfo->post_div);
|
|
1863 xclk_freq = rinfo->pll.xclk;
|
|
1864
|
|
1865 xclk_per_trans = round_div(xclk_freq * 128, vclk_freq * mode->bits_per_pixel);
|
|
1866
|
|
1867 min_bits = min_bits_req(xclk_per_trans);
|
|
1868 useable_precision = min_bits + 1;
|
|
1869
|
|
1870 xclk_per_trans_precise = round_div((xclk_freq * 128) << (11 - useable_precision),
|
|
1871 vclk_freq * mode->bits_per_pixel);
|
|
1872
|
|
1873 ron = (4 * rinfo->ram.mb + 3 * _max(rinfo->ram.trcd - 2, 0) +
|
|
1874 2 * rinfo->ram.trp + rinfo->ram.twr + rinfo->ram.cl + rinfo->ram.tr2w +
|
|
1875 xclk_per_trans) << (11 - useable_precision);
|
|
1876 roff = xclk_per_trans_precise * (32 - 4);
|
|
1877
|
|
1878 RTRACE("ron = %d, roff = %d\n", ron, roff);
|
|
1879 RTRACE("vclk_freq = %d, per = %d\n", vclk_freq, xclk_per_trans_precise);
|
|
1880
|
|
1881 if ((ron + rinfo->ram.rloop) >= roff) {
|
|
1882 printk("radeonfb: error ron out of range\n");
|
|
1883 return;
|
|
1884 }
|
|
1885
|
|
1886 newmode.dda_config = (xclk_per_trans_precise |
|
|
1887 (useable_precision << 16) |
|
|
1888 (rinfo->ram.rloop << 20));
|
|
1889 newmode.dda_on_off = (ron << 16) | roff;
|
|
1890
|
|
1891 /* do it! */
|
|
1892 radeon_write_mode (rinfo, &newmode);
|
|
1893
|
|
1894 return;
|
|
1895 }
|
|
1896
|
|
1897
|
|
1898
|
|
1899 static void radeon_write_mode (struct radeonfb_info *rinfo,
|
|
1900 struct radeon_regs *mode)
|
|
1901 {
|
|
1902 int i;
|
|
1903
|
|
1904 /* blank screen */
|
|
1905 OUTREG8(CRTC_EXT_CNTL + 1, 4);
|
|
1906
|
|
1907 for (i=0; i<9; i++)
|
|
1908 OUTREG(common_regs[i].reg, common_regs[i].val);
|
|
1909
|
|
1910 OUTREG(CRTC_GEN_CNTL, mode->crtc_gen_cntl);
|
|
1911 OUTREGP(CRTC_EXT_CNTL, mode->crtc_ext_cntl,
|
|
1912 CRTC_HSYNC_DIS | CRTC_VSYNC_DIS | CRTC_DISPLAY_DIS);
|
|
1913 OUTREGP(DAC_CNTL, mode->dac_cntl, DAC_RANGE_CNTL | DAC_BLANKING);
|
|
1914 OUTREG(CRTC_H_TOTAL_DISP, mode->crtc_h_total_disp);
|
|
1915 OUTREG(CRTC_H_SYNC_STRT_WID, mode->crtc_h_sync_strt_wid);
|
|
1916 OUTREG(CRTC_V_TOTAL_DISP, mode->crtc_v_total_disp);
|
|
1917 OUTREG(CRTC_V_SYNC_STRT_WID, mode->crtc_v_sync_strt_wid);
|
|
1918 OUTREG(CRTC_OFFSET, 0);
|
|
1919 OUTREG(CRTC_OFFSET_CNTL, 0);
|
|
1920 OUTREG(CRTC_PITCH, mode->crtc_pitch);
|
1914
|
1921 OUTREG(SURFACE_CNTL, mode->surface_cntl);
|
1911
|
1922
|
|
1923 while ((INREG(CLOCK_CNTL_INDEX) & PPLL_DIV_SEL_MASK) !=
|
|
1924 PPLL_DIV_SEL_MASK) {
|
|
1925 OUTREGP(CLOCK_CNTL_INDEX, PPLL_DIV_SEL_MASK, 0xffff);
|
|
1926 }
|
|
1927
|
|
1928 OUTPLLP(PPLL_CNTL, PPLL_RESET, 0xffff);
|
|
1929
|
|
1930 while ((INPLL(PPLL_REF_DIV) & PPLL_REF_DIV_MASK) !=
|
|
1931 (mode->ppll_ref_div & PPLL_REF_DIV_MASK)) {
|
|
1932 OUTPLLP(PPLL_REF_DIV, mode->ppll_ref_div, ~PPLL_REF_DIV_MASK);
|
|
1933 }
|
|
1934
|
|
1935 while ((INPLL(PPLL_DIV_3) & PPLL_FB3_DIV_MASK) !=
|
|
1936 (mode->ppll_div_3 & PPLL_FB3_DIV_MASK)) {
|
|
1937 OUTPLLP(PPLL_DIV_3, mode->ppll_div_3, ~PPLL_FB3_DIV_MASK);
|
|
1938 }
|
|
1939
|
|
1940 while ((INPLL(PPLL_DIV_3) & PPLL_POST3_DIV_MASK) !=
|
|
1941 (mode->ppll_div_3 & PPLL_POST3_DIV_MASK)) {
|
|
1942 OUTPLLP(PPLL_DIV_3, mode->ppll_div_3, ~PPLL_POST3_DIV_MASK);
|
|
1943 }
|
|
1944
|
|
1945 OUTPLL(HTOTAL_CNTL, 0);
|
|
1946
|
|
1947 OUTPLLP(PPLL_CNTL, 0, ~PPLL_RESET);
|
|
1948
|
|
1949 OUTREG(DDA_CONFIG, mode->dda_config);
|
|
1950 OUTREG(DDA_ON_OFF, mode->dda_on_off);
|
|
1951
|
|
1952 /* unblank screen */
|
|
1953 OUTREG8(CRTC_EXT_CNTL + 1, 0);
|
|
1954
|
|
1955 return;
|
|
1956 }
|
|
1957
|
1914
|
1958 #if 0
|
1911
|
1959
|
|
1960 /*
|
|
1961 * text console acceleration
|
|
1962 */
|
|
1963
|
|
1964
|
|
1965 static void fbcon_radeon_bmove(struct display *p, int srcy, int srcx,
|
|
1966 int dsty, int dstx, int height, int width)
|
|
1967 {
|
|
1968 struct radeonfb_info *rinfo = (struct radeonfb_info *)(p->fb_info);
|
|
1969 u32 dp_cntl = DST_LAST_PEL;
|
|
1970
|
|
1971 srcx *= fontwidth(p);
|
|
1972 srcy *= fontheight(p);
|
|
1973 dstx *= fontwidth(p);
|
|
1974 dsty *= fontheight(p);
|
|
1975 width *= fontwidth(p);
|
|
1976 height *= fontheight(p);
|
|
1977
|
|
1978 if (srcy < dsty) {
|
|
1979 srcy += height - 1;
|
|
1980 dsty += height - 1;
|
|
1981 } else
|
|
1982 dp_cntl |= DST_Y_TOP_TO_BOTTOM;
|
|
1983
|
|
1984 if (srcx < dstx) {
|
|
1985 srcx += width - 1;
|
|
1986 dstx += width - 1;
|
|
1987 } else
|
|
1988 dp_cntl |= DST_X_LEFT_TO_RIGHT;
|
|
1989
|
|
1990 radeon_fifo_wait(6);
|
|
1991 OUTREG(DP_GUI_MASTER_CNTL, (rinfo->dp_gui_master_cntl |
|
|
1992 GMC_BRUSH_NONE |
|
|
1993 GMC_SRC_DATATYPE_COLOR |
|
|
1994 ROP3_S |
|
|
1995 DP_SRC_SOURCE_MEMORY));
|
|
1996 OUTREG(DP_WRITE_MSK, 0xffffffff);
|
|
1997 OUTREG(DP_CNTL, dp_cntl);
|
|
1998 OUTREG(SRC_Y_X, (srcy << 16) | srcx);
|
|
1999 OUTREG(DST_Y_X, (dsty << 16) | dstx);
|
|
2000 OUTREG(DST_HEIGHT_WIDTH, (height << 16) | width);
|
|
2001 }
|
|
2002
|
|
2003
|
|
2004
|
|
2005 static void fbcon_radeon_clear(struct vc_data *conp, struct display *p,
|
|
2006 int srcy, int srcx, int height, int width)
|
|
2007 {
|
|
2008 struct radeonfb_info *rinfo = (struct radeonfb_info *)(p->fb_info);
|
|
2009 u32 clr;
|
|
2010
|
|
2011 clr = attr_bgcol_ec(p, conp);
|
|
2012 clr |= (clr << 8);
|
|
2013 clr |= (clr << 16);
|
|
2014
|
|
2015 srcx *= fontwidth(p);
|
|
2016 srcy *= fontheight(p);
|
|
2017 width *= fontwidth(p);
|
|
2018 height *= fontheight(p);
|
|
2019
|
|
2020 radeon_fifo_wait(6);
|
|
2021 OUTREG(DP_GUI_MASTER_CNTL, (rinfo->dp_gui_master_cntl |
|
|
2022 GMC_BRUSH_SOLID_COLOR |
|
|
2023 GMC_SRC_DATATYPE_COLOR |
|
|
2024 ROP3_P));
|
|
2025 OUTREG(DP_BRUSH_FRGD_CLR, clr);
|
|
2026 OUTREG(DP_WRITE_MSK, 0xffffffff);
|
|
2027 OUTREG(DP_CNTL, (DST_X_LEFT_TO_RIGHT | DST_Y_TOP_TO_BOTTOM));
|
|
2028 OUTREG(DST_Y_X, (srcy << 16) | srcx);
|
|
2029 OUTREG(DST_WIDTH_HEIGHT, (width << 16) | height);
|
|
2030 }
|
|
2031
|
|
2032
|
|
2033
|
|
2034
|
|
2035 #ifdef FBCON_HAS_CFB8
|
|
2036 static struct display_switch fbcon_radeon8 = {
|
|
2037 setup: fbcon_cfb8_setup,
|
|
2038 bmove: fbcon_radeon_bmove,
|
|
2039 clear: fbcon_cfb8_clear,
|
|
2040 putc: fbcon_cfb8_putc,
|
|
2041 putcs: fbcon_cfb8_putcs,
|
|
2042 revc: fbcon_cfb8_revc,
|
|
2043 clear_margins: fbcon_cfb8_clear_margins,
|
|
2044 fontwidthmask: FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
|
|
2045 };
|
|
2046 #endif
|
1914
|
2047
|
|
2048 #endif /* 0 */
|