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