2 * linux/drivers/video/virgefb.c -- CyberVision64/3D frame buffer device
4 * Copyright (C) 1997 André Heynatz
7 * This file is based on the CyberVision frame buffer device (cyberfb.c):
9 * Copyright (C) 1996 Martin Apel
12 * Zorro II additions :
14 * Copyright (C) 1998-2000 Christian T. Steigies
16 * Initialization additions :
18 * Copyright (C) 1998-2000 Ken Tyler
20 * Parts of the Initialization code are based on Cyberfb.c by Allan Bair,
21 * and on the NetBSD CyberVision64 frame buffer driver by Michael Teske who gave
22 * permission for its use.
24 * Many thanks to Frank Mariak for his assistance with ZORRO 2 access and other
29 * This file is subject to the terms and conditions of the GNU General Public
30 * License. See the file COPYING in the main directory of this archive
37 #include <linux/module.h>
38 #include <linux/kernel.h>
39 #include <linux/errno.h>
40 #include <linux/string.h>
42 #include <linux/slab.h>
43 #include <linux/delay.h>
44 #include <linux/zorro.h>
46 #include <linux/init.h>
47 #include <asm/uaccess.h>
48 #include <asm/system.h>
49 #include <asm/amigahw.h>
52 #include <video/fbcon.h>
53 #include <video/fbcon-cfb8.h>
54 #include <video/fbcon-cfb16.h>
55 #include <video/fbcon-cfb32.h>
60 #define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
62 #define DPRINTK(fmt, args...)
66 static void cv64_dump(void);
67 #define DUMP cv64_dump()
73 * Macros for register access and zorro control
76 static inline void mb_inline(void) { mb(); } /* for use in comma expressions */
83 (*(volatile u16 *)((u8 *)(vcode_switch_base + 0x04)) = 0x01); \
90 (*(volatile u16 *)((u8 *)(vcode_switch_base + 0x04)) = 0x02); \
97 (*(volatile u16 *)((u8 *)(vcode_switch_base + 0x04)) = 0x03); \
101 /* Set pass through, 0 = amiga, !=0 = cv64/3d */
103 #define SetVSwitch(x) \
105 (*(volatile u16 *)((u8 *)(vcode_switch_base)) = \
109 /* Zorro2 endian 'aperture' */
111 #define ENDIAN_BYTE 2
112 #define ENDIAN_WORD 1
113 #define ENDIAN_LONG 0
115 #define Select_Zorro2_FrameBuffer(x) \
119 (*(volatile u16 *)((u8 *)(vcode_switch_base + 0x08)) = \
125 /* SetPortVal - only used for interrupt enable (not yet implemented) */
128 #define SetPortVal(x) \
130 (*(volatile u16 *)((u8 *)(vcode_switch_base + 0x0c)) = \
137 #define byte_access_io(x) (((x) & 0x3ffc) | (((x) & 3)^3) | (((x) & 3) <<14))
138 #define byte_access_mmio(x) (((x) & 0xfffc) | (((x) & 3)^3))
140 /* Write 8 bit VGA register - used once for chip wakeup */
142 #define wb_vgaio(reg, dat) \
144 (*(volatile u8 *)(vgaio_regs + ((u32)byte_access_io(reg) & 0xffff)) = \
148 /* Read 8 bit VGA register - only used in dump (SelectIO not needed on read ?) */
151 #define rb_vgaio(reg) \
155 __zzyzx = (*(volatile u8 *)((vgaio_regs)+(u32)byte_access_io(reg))); \
163 /* Read 8 bit MMIO register */
165 #define rb_mmio(reg) \
167 (*(volatile u8 *)(mmio_regs + 0x8000 + (u32)byte_access_mmio(reg))))
169 /* Write 8 bit MMIO register */
171 #define wb_mmio(reg,dat) \
173 (*(volatile u8 *)(mmio_regs + 0x8000 + (byte_access_mmio((reg) & 0xffff))) = \
177 /* Read 32 bit MMIO register */
179 #define rl_mmio(reg) \
181 (*((volatile u32 *)((u8 *)((mmio_regs + (on_zorro2 ? 0x20000 : 0)) + (reg))))))
183 /* Write 32 bit MMIO register */
185 #define wl_mmio(reg,dat) \
187 ((*(volatile u32 *)((u8 *)((mmio_regs + (on_zorro2 ? 0x20000 : 0)) + (reg)))) = \
191 /* Write to virge graphics register */
193 #define wgfx(reg, dat) do { wb_mmio(GCT_ADDRESS, (reg)); wb_mmio(GCT_ADDRESS_W, (dat)); } while (0)
195 /* Write to virge sequencer register */
197 #define wseq(reg, dat) do { wb_mmio(SEQ_ADDRESS, (reg)); wb_mmio(SEQ_ADDRESS_W, (dat)); } while (0)
199 /* Write to virge CRT controller register */
201 #define wcrt(reg, dat) do { wb_mmio(CRT_ADDRESS, (reg)); wb_mmio(CRT_ADDRESS_W, (dat)); } while (0)
203 /* Write to virge attribute register */
205 #define watr(reg, dat) \
207 volatile unsigned char watr_tmp; \
208 watr_tmp = rb_mmio(ACT_ADDRESS_RESET); \
209 wb_mmio(ACT_ADDRESS_W, (reg)); \
210 wb_mmio(ACT_ADDRESS_W, (dat)); \
217 struct fb_var_screeninfo var
;
224 static struct virgefb_par current_par
;
226 static int current_par_valid
= 0;
228 static struct display disp
;
229 static struct fb_info fb_info
;
232 #ifdef FBCON_HAS_CFB16
235 #ifdef FBCON_HAS_CFB32
241 * Switch for Chipset Independency
244 static struct fb_hwswitch
{
250 /* Display Control */
252 int (*encode_fix
)(struct fb_fix_screeninfo
*fix
, struct virgefb_par
*par
);
253 int (*decode_var
)(struct fb_var_screeninfo
*var
, struct virgefb_par
*par
);
254 int (*encode_var
)(struct fb_var_screeninfo
*var
, struct virgefb_par
*par
);
255 int (*getcolreg
)(u_int regno
, u_int
*red
, u_int
*green
, u_int
*blue
,
256 u_int
*transp
, struct fb_info
*info
);
257 void (*blank
)(int blank
);
260 static unsigned char blit_maybe_busy
= 0;
266 static char virgefb_name
[16] = "CyberVision/3D";
269 * CyberVision64/3d Graphics Board
272 static unsigned char virgefb_colour_table
[256][3];
273 static unsigned long v_ram
;
274 static unsigned long v_ram_size
;
275 static volatile unsigned char *mmio_regs
;
276 static volatile unsigned char *vgaio_regs
;
278 static unsigned long v_ram_phys
;
279 static unsigned long mmio_regs_phys
;
280 static unsigned long vcode_switch_base
;
281 static unsigned char on_zorro2
;
284 * Offsets from start of video ram to appropriate ZIII aperture
287 #ifdef FBCON_HAS_CFB8
288 #define CYBMEM_OFFSET_8 0x800000 /* BGRX */
290 #ifdef FBCON_HAS_CFB16
291 #define CYBMEM_OFFSET_16 0x400000 /* GBXR */
293 #ifdef FBCON_HAS_CFB32
294 #define CYBMEM_OFFSET_32 0x000000 /* XRGB */
298 * MEMCLOCK was 32MHz, 64MHz works, 72MHz doesn't (on my board)
301 #define MEMCLOCK 50000000
304 * Predefined Video Modes
309 struct fb_var_screeninfo var
;
310 } virgefb_predefined
[] __initdata
= {
311 #ifdef FBCON_HAS_CFB8
313 "640x480-8", { /* Cybervision 8 bpp */
314 640, 480, 640, 480, 0, 0, 8, 0,
315 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
316 0, 0, -1, -1, FB_ACCELF_TEXT
, 31250, 160, 136, 82, 61, 88, 2,
317 0, FB_VMODE_NONINTERLACED
320 "768x576-8", { /* Cybervision 8 bpp */
321 768, 576, 768, 576, 0, 0, 8, 0,
322 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
323 0, 0, -1, -1, FB_ACCELF_TEXT
, 29411, 144, 112, 32, 15, 64, 2,
324 0, FB_VMODE_NONINTERLACED
327 "800x600-8", { /* Cybervision 8 bpp */
328 800, 600, 800, 600, 0, 0, 8, 0,
329 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
330 0, 0, -1, -1, FB_ACCELF_TEXT
, 28571, 168, 104, 22, 1, 48, 2,
331 0, FB_VMODE_NONINTERLACED
335 "1024x768-8", { /* Cybervision 8 bpp */
336 1024, 768, 1024, 768, 0, 0, 8, 0,
337 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
338 0, 0, -1, -1, FB_ACCELF_TEXT
, 20833, 272, 168, 39, 2, 72, 1,
339 0, FB_VMODE_NONINTERLACED
343 1024, 768, 1024, 768, 0, 0, 8, 0,
344 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
346 0, 0, -1, -1, FB_ACCELF_TEXT
, 12500, 184, 40, 40, 2, 96, 1,
347 FB_SYNC_COMP_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
350 0, 0, -1, -1, FB_ACCELF_TEXT
, 12699, 176, 16, 28, 1, 96, 3,
351 FB_SYNC_COMP_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
356 "1152x886-8", { /* Cybervision 8 bpp */
357 1152, 886, 1152, 886, 0, 0, 8, 0,
358 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
359 0, 0, -1, -1, FB_ACCELF_TEXT
, 19230, 280, 168, 45, 1, 64, 10,
360 0, FB_VMODE_NONINTERLACED
363 "1280x1024-8", { /* Cybervision 8 bpp */
364 1280, 1024, 1280, 1024, 0, 0, 8, 0,
365 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
367 0, 0, -1, -1, FB_ACCELF_TEXT
, 17857, 232, 232, 71, 15, 176, 12,
370 0, 0, -1, -1, FB_ACCELF_TEXT
, 7414, 232, 64, 38, 1, 112, 3,
371 FB_SYNC_COMP_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
375 "1600x1200-8", { /* Cybervision 8 bpp */
376 1600, 1200, 1600, 1200, 0, 0, 8, 0,
377 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
379 0, 0, -1, -1, FB_ACCELF_TEXT
, 13698, 336, 224, 77, 15, 176, 12,
380 0, FB_VMODE_NONINTERLACED
383 0, 0, -1, -1, FB_ACCELF_TEXT
, 6411, 256, 32, 52, 10, 160, 8,
384 FB_SYNC_COMP_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
390 #ifdef FBCON_HAS_CFB16
392 "640x480-16", { /* Cybervision 16 bpp */
393 640, 480, 640, 480, 0, 0, 16, 0,
394 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
395 0, 0, -1, -1, FB_ACCELF_TEXT
, 31250, 152, 144, 82, 61, 88, 2,
396 0, FB_VMODE_NONINTERLACED
399 "768x576-16", { /* Cybervision 16 bpp */
400 768, 576, 768, 576, 0, 0, 16, 0,
401 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
402 0, 0, -1, -1, FB_ACCELF_TEXT
, 29411, 144, 112, 32, 15, 64, 2,
403 0, FB_VMODE_NONINTERLACED
406 "800x600-16", { /* Cybervision 16 bpp */
407 800, 600, 800, 600, 0, 0, 16, 0,
408 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
409 0, 0, -1, -1, FB_ACCELF_TEXT
, 28571, 168, 104, 22, 1, 48, 2,
410 0, FB_VMODE_NONINTERLACED
414 "1024x768-16", { /* Cybervision 16 bpp */
415 1024, 768, 1024, 768, 0, 0, 16, 0,
416 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
417 0, 0, -1, -1, FB_ACCELF_TEXT
, 20833, 272, 168, 39, 2, 72, 1,
418 0, FB_VMODE_NONINTERLACED
422 1024, 768, 1024, 768, 0, 0, 16, 0,
423 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
424 0, 0, -1, -1, FB_ACCELF_TEXT
, 12500, 184, 40, 40, 2, 96, 1,
425 FB_SYNC_COMP_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
429 "1152x886-16", { /* Cybervision 16 bpp */
430 1152, 886, 1152, 886, 0, 0, 16, 0,
431 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
432 0, 0, -1, -1, FB_ACCELF_TEXT
, 19230, 280, 168, 45, 1, 64, 10,
433 0, FB_VMODE_NONINTERLACED
436 "1280x1024-16", { /* Cybervision 16 bpp */
437 1280, 1024, 1280, 1024, 0, 0, 16, 0,
438 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
439 0, 0, -1, -1, FB_ACCELF_TEXT
, 17857, 232, 232, 71, 15, 176, 12,
440 0, FB_VMODE_NONINTERLACED
443 "1600x1200-16", { /* Cybervision 16 bpp */
444 1600, 1200, 1600, 1200, 0, 0, 16, 0,
445 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
446 0, 0, -1, -1, FB_ACCELF_TEXT
, 13698, 336, 224, 77, 15, 176, 12,
447 0, FB_VMODE_NONINTERLACED
452 #ifdef FBCON_HAS_CFB32
454 "640x480-32", { /* Cybervision 32 bpp */
455 640, 480, 640, 480, 0, 0, 32, 0,
456 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {24, 0, 0},
457 0, 0, -1, -1, FB_ACCELF_TEXT
, 31250, 160, 136, 82, 61, 88, 2,
458 0, FB_VMODE_NONINTERLACED
461 "768x576-32", { /* Cybervision 32 bpp */
462 768, 576, 768, 576, 0, 0, 32, 0,
463 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {24, 0, 0},
464 0, 0, -1, -1, FB_ACCELF_TEXT
, 29411, 144, 112, 32, 15, 64, 2,
465 0, FB_VMODE_NONINTERLACED
468 "800x600-32", { /* Cybervision 32 bpp */
469 800, 600, 800, 600, 0, 0, 32, 0,
470 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {24, 0, 0},
471 0, 0, -1, -1, FB_ACCELF_TEXT
, 28571, 168, 104, 22, 1, 48, 2,
472 0, FB_VMODE_NONINTERLACED
475 "1024x768-32", { /* Cybervision 32 bpp */
476 1024, 768, 1024, 768, 0, 0, 32, 0,
477 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {24, 0, 0},
478 0, 0, -1, -1, FB_ACCELF_TEXT
, 20833, 272, 168, 39, 2, 72, 1,
479 0, FB_VMODE_NONINTERLACED
482 "1152x886-32", { /* Cybervision 32 bpp */
483 1152, 886, 1152, 886, 0, 0, 32, 0,
484 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {24, 0, 0},
485 0, 0, -1, -1, FB_ACCELF_TEXT
, 19230, 280, 168, 45, 1, 64, 10,
486 0, FB_VMODE_NONINTERLACED
489 "1280x1024-32", { /* Cybervision 32 bpp */
490 1280, 1024, 1280, 1024, 0, 0, 32, 0,
491 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {24, 0, 0},
492 0, 0, -1, -1, FB_ACCELF_TEXT
, 17857, 232, 232, 71, 15, 176, 12,
493 0, FB_VMODE_NONINTERLACED
496 "1600x1200-32", { /* Cybervision 32 bpp */
497 1600, 1200, 1600, 1200, 0, 0, 32, 0,
498 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {24, 0, 0},
499 0, 0, -1, -1, FB_ACCELF_TEXT
, 13698, 336, 224, 77, 15, 176, 12,
500 0, FB_VMODE_NONINTERLACED
505 /* interlaced modes */
507 #ifdef FBCON_HAS_CFB8
509 "1024x768-8i", { /* Cybervision 8 bpp */
510 1024, 768, 1024, 768, 0, 0, 8, 0,
511 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
512 0, 0, -1, -1, FB_ACCELF_TEXT
, 20833, 272, 168, 39, 2, 72, 1,
513 0, FB_VMODE_INTERLACED
516 "1280x1024-8i", { /* Cybervision 8 bpp */
517 1280, 1024, 1280, 1024, 0, 0, 8, 0,
518 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
519 0, 0, -1, -1, FB_ACCELF_TEXT
, 17857, 232, 232, 71, 15, 176, 12,
520 0, FB_VMODE_INTERLACED
523 "1600x1200-8i", { /* Cybervision 8 bpp */
524 1600, 1200, 1600, 1200, 0, 0, 8, 0,
525 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
526 0, 0, -1, -1, FB_ACCELF_TEXT
, 13698, 336, 224, 77, 15, 176, 12,
527 0, FB_VMODE_INTERLACED
532 #ifdef FBCON_HAS_CFB16
534 "1024x768-16i", { /* Cybervision 16 bpp */
535 1024, 768, 1024, 768, 0, 0, 16, 0,
536 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
537 0, 0, -1, -1, FB_ACCELF_TEXT
, 20833, 272, 168, 39, 2, 72, 1,
538 0, FB_VMODE_INTERLACED
541 "1280x1024-16i", { /* Cybervision 16 bpp */
542 1280, 1024, 1280, 1024, 0, 0, 16, 0,
543 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
544 0, 0, -1, -1, FB_ACCELF_TEXT
, 17857, 232, 232, 71, 15, 176, 12,
545 0, FB_VMODE_INTERLACED
548 "1600x1200-16i", { /* Cybervision 16 bpp */
549 1600, 1200, 1600, 1200, 0, 0, 16, 0,
550 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
551 0, 0, -1, -1, FB_ACCELF_TEXT
, 13698, 336, 224, 77, 15, 176, 12,
552 0, FB_VMODE_INTERLACED
557 #ifdef FBCON_HAS_CFB32
559 "1024x768-32i", { /* Cybervision 32 bpp */
560 1024, 768, 1024, 768, 0, 0, 32, 0,
561 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {24, 0, 0},
562 0, 0, -1, -1, FB_ACCELF_TEXT
, 22222, 216, 144, 39, 2, 72, 1,
563 0, FB_VMODE_INTERLACED
566 "1280x1024-32i", { /* Cybervision 32 bpp */
567 1280, 1024, 1280, 1024, 0, 0, 32, 0,
568 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {23, 0, 0},
569 0, 0, -1, -1, FB_ACCELF_TEXT
, 17857, 232, 232, 71, 15, 176, 12,
570 0, FB_VMODE_INTERLACED
573 "1600x1200-32i", { /* Cybervision 32 bpp */
574 1600, 1200, 1600, 1200, 0, 0, 32, 0,
575 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {24, 0, 0},
576 0, 0, -1, -1, FB_ACCELF_TEXT
, 13698, 336, 224, 77, 15, 176, 12,
577 0, FB_VMODE_INTERLACED
582 /* doublescan modes */
584 #ifdef FBCON_HAS_CFB8
586 "320x240-8d", { /* Cybervision 8 bpp */
587 320, 240, 320, 240, 0, 0, 8, 0,
588 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
589 0, 0, -1, -1, FB_ACCELF_TEXT
, 59259, 80, 80, 45, 26, 32, 1,
595 #ifdef FBCON_HAS_CFB16
597 "320x240-16d", { /* Cybervision 16 bpp */
598 320, 240, 320, 240, 0, 0, 16, 0,
599 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
600 0, 0, -1, -1, FB_ACCELF_TEXT
, 59259, 80, 80, 45, 26, 32, 1,
606 #ifdef FBCON_HAS_CFB32
608 "320x240-32d", { /* Cybervision 32 bpp */
609 320, 240, 320, 240, 0, 0, 32, 0,
610 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {24, 0, 0},
611 0, 0, -1, -1, FB_ACCELF_TEXT
, 59259, 80, 80, 45, 26, 32, 1,
618 #define NUM_TOTAL_MODES ARRAY_SIZE(virgefb_predefined)
621 * Default to 800x600 for video=virge8:, virge16: or virge32:
624 #ifdef FBCON_HAS_CFB8
625 #define VIRGE8_DEFMODE (2)
628 #ifdef FBCON_HAS_CFB16
629 #define VIRGE16_DEFMODE (9)
632 #ifdef FBCON_HAS_CFB32
633 #define VIRGE32_DEFMODE (16)
636 static struct fb_var_screeninfo virgefb_default
;
637 static int virgefb_inverse
= 0;
640 * Interface used by the world
643 int virgefb_setup(char*);
644 static int virgefb_get_fix(struct fb_fix_screeninfo
*fix
, int con
,
645 struct fb_info
*info
);
646 static int virgefb_get_var(struct fb_var_screeninfo
*var
, int con
,
647 struct fb_info
*info
);
648 static int virgefb_set_var(struct fb_var_screeninfo
*var
, int con
,
649 struct fb_info
*info
);
650 static int virgefb_get_cmap(struct fb_cmap
*cmap
, int kspc
, int con
,
651 struct fb_info
*info
);
652 static int virgefb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
653 u_int transp
, struct fb_info
*info
);
654 static int virgefb_blank(int blank
, struct fb_info
*info
);
657 * Interface to the low level console driver
660 int virgefb_init(void);
661 static int virgefb_switch(int con
, struct fb_info
*info
);
662 static int virgefb_updatevar(int con
, struct fb_info
*info
);
665 * Text console acceleration
668 #ifdef FBCON_HAS_CFB8
669 static struct display_switch fbcon_virge8
;
672 #ifdef FBCON_HAS_CFB16
673 static struct display_switch fbcon_virge16
;
676 #ifdef FBCON_HAS_CFB32
677 static struct display_switch fbcon_virge32
;
681 * Hardware Specific Routines
684 static int virge_init(void);
685 static int virgefb_encode_fix(struct fb_fix_screeninfo
*fix
,
686 struct virgefb_par
*par
);
687 static int virgefb_decode_var(struct fb_var_screeninfo
*var
,
688 struct virgefb_par
*par
);
689 static int virgefb_encode_var(struct fb_var_screeninfo
*var
,
690 struct virgefb_par
*par
);
691 static int virgefb_getcolreg(u_int regno
, u_int
*red
, u_int
*green
, u_int
*blue
,
692 u_int
*transp
, struct fb_info
*info
);
693 static void virgefb_gfx_on_off(int blank
);
694 static inline void virgefb_wait_for_idle(void);
695 static void virgefb_BitBLT(u_short curx
, u_short cury
, u_short destx
, u_short desty
,
696 u_short width
, u_short height
, u_short stride
, u_short depth
);
697 static void virgefb_RectFill(u_short x
, u_short y
, u_short width
, u_short height
,
698 u_short color
, u_short stride
, u_short depth
);
704 static void virgefb_get_par(struct virgefb_par
*par
);
705 static void virgefb_set_par(struct virgefb_par
*par
);
706 static int virgefb_do_fb_set_var(struct fb_var_screeninfo
*var
, int isactive
);
707 static void virgefb_set_disp(int con
, struct fb_info
*info
);
708 static int virgefb_get_video_mode(const char *name
);
709 static void virgefb_set_video(struct fb_var_screeninfo
*var
);
712 * Additions for Initialization
715 static void virgefb_load_video_mode(struct fb_var_screeninfo
*video_mode
);
716 static int cv3d_has_4mb(void);
717 static unsigned short virgefb_compute_clock(unsigned long freq
);
718 static inline unsigned char rattr(short);
719 static inline unsigned char rseq(short);
720 static inline unsigned char rcrt(short);
721 static inline unsigned char rgfx(short);
722 static inline void gfx_on_off(int toggle
);
723 static void virgefb_pci_init(void);
725 /* -------------------- Hardware specific routines ------------------------- */
728 * Functions for register access
731 /* Read attribute controller register */
733 static inline unsigned char rattr(short idx
)
735 volatile unsigned char rattr_tmp
;
737 rattr_tmp
= rb_mmio(ACT_ADDRESS_RESET
);
738 wb_mmio(ACT_ADDRESS_W
, idx
);
739 return (rb_mmio(ACT_ADDRESS_R
));
742 /* Read sequencer register */
744 static inline unsigned char rseq(short idx
)
746 wb_mmio(SEQ_ADDRESS
, idx
);
747 return (rb_mmio(SEQ_ADDRESS_R
));
750 /* Read CRT controller register */
752 static inline unsigned char rcrt(short idx
)
754 wb_mmio(CRT_ADDRESS
, idx
);
755 return (rb_mmio(CRT_ADDRESS_R
));
758 /* Read graphics controller register */
760 static inline unsigned char rgfx(short idx
)
762 wb_mmio(GCT_ADDRESS
, idx
);
763 return (rb_mmio(GCT_ADDRESS_R
));
773 void virgefb_pci_init(void) {
780 *((short *)(vgaio_regs
+ 0x00000010)) = 0;
781 *((long *)(vgaio_regs
+ 0x00000004)) = 0x02000003;
783 *((short *)(vgaio_regs
+ 0x000e0010)) = 0;
784 *((long *)(vgaio_regs
+ 0x000e0004)) = 0x02000003;
787 /* SelectIO is in wb_vgaio macro */
788 wb_vgaio(SREG_VIDEO_SUBS_ENABLE
, 0x01);
789 /* SelectMMIO is in wb_vgaio macro */
797 * Initalize all mode independent regs, find mem size and clear mem
800 static int virge_init(void)
809 wb_mmio(GREG_MISC_OUTPUT_W
, 0x07); /* colour, ram enable, clk sel */
811 wseq(SEQ_ID_UNLOCK_EXT
, 0x06); /* unlock extensions */
812 tmp
= rb_mmio(GREG_MISC_OUTPUT_R
);
813 wcrt(CRT_ID_REGISTER_LOCK_1
, 0x48); /* unlock CR2D to CR3F */
815 wcrt(CRT_ID_BACKWAD_COMP_1
, 0x00); /* irq disable */
817 wcrt(CRT_ID_REGISTER_LOCK_2
, 0xa5); /* unlock CR40 to CRFF and more */
818 wcrt(CRT_ID_REGISTER_LOCK
,0x00); /* unlock h and v timing */
819 wcrt(CRT_ID_SYSTEM_CONFIG
, 0x01); /* unlock enhanced programming registers */
821 wb_mmio(GREG_FEATURE_CONTROL_W
, 0x00);
823 wcrt(CRT_ID_EXT_MISC_CNTL
, 0x00); /* b2 = 0 to allow VDAC mmio access */
825 /* write strap options ... ? */
826 wcrt(CRT_ID_CONFIG_1
, 0x08);
827 wcrt(CRT_ID_CONFIG_2
, 0xff); /* 0x0x2 bit needs to be set ?? */
828 wcrt(CRT_ID_CONFIG_3
, 0x0f);
829 wcrt(CRT_ID_CONFIG_4
, 0x1a);
831 wcrt(CRT_ID_EXT_MISC_CNTL_1
, 0x82); /* PCI DE and software reset S3D engine */
832 /* EXT_MISC_CNTL_1, CR66 bit 0 should be the same as bit 0 MR_ADVANCED_FUNCTION_CONTROL - check */
833 wl_mmio(MR_ADVANCED_FUNCTION_CONTROL
, 0x00000011); /* enhanced mode, linear addressing */
837 wcrt(CRT_ID_PRESET_ROW_SCAN
, 0x00);
839 /* Disable h/w cursor */
841 wcrt(CRT_ID_CURSOR_START
, 0x00);
842 wcrt(CRT_ID_CURSOR_END
, 0x00);
843 wcrt(CRT_ID_START_ADDR_HIGH
, 0x00);
844 wcrt(CRT_ID_START_ADDR_LOW
, 0x00);
845 wcrt(CRT_ID_CURSOR_LOC_HIGH
, 0x00);
846 wcrt(CRT_ID_CURSOR_LOC_LOW
, 0x00);
847 wcrt(CRT_ID_EXT_MODE
, 0x00);
848 wcrt(CRT_ID_HWGC_MODE
, 0x00);
849 wcrt(CRT_ID_HWGC_ORIGIN_X_HI
, 0x00);
850 wcrt(CRT_ID_HWGC_ORIGIN_X_LO
, 0x00);
851 wcrt(CRT_ID_HWGC_ORIGIN_Y_HI
, 0x00);
852 wcrt(CRT_ID_HWGC_ORIGIN_Y_LO
, 0x00);
853 i
= rcrt(CRT_ID_HWGC_MODE
);
854 wcrt(CRT_ID_HWGC_FG_STACK
, 0x00);
855 wcrt(CRT_ID_HWGC_FG_STACK
, 0x00);
856 wcrt(CRT_ID_HWGC_FG_STACK
, 0x00);
857 wcrt(CRT_ID_HWGC_BG_STACK
, 0x00);
858 wcrt(CRT_ID_HWGC_BG_STACK
, 0x00);
859 wcrt(CRT_ID_HWGC_BG_STACK
, 0x00);
860 wcrt(CRT_ID_HWGC_START_AD_HI
, 0x00);
861 wcrt(CRT_ID_HWGC_START_AD_LO
, 0x00);
862 wcrt(CRT_ID_HWGC_DSTART_X
, 0x00);
863 wcrt(CRT_ID_HWGC_DSTART_Y
, 0x00);
865 wcrt(CRT_ID_UNDERLINE_LOC
, 0x00);
867 wcrt(CRT_ID_MODE_CONTROL
, 0xe3);
868 wcrt(CRT_ID_BACKWAD_COMP_2
, 0x22); /* blank bdr bit 5 blanking only on 8 bit */
870 wcrt(CRT_ID_EX_SYNC_1
, 0x00);
874 wcrt(CRT_ID_EXT_SYS_CNTL_3
, 0x00);
875 wcrt(CRT_ID_MEMORY_CONF
, 0x08); /* config enhanced map */
876 wcrt(CRT_ID_EXT_MEM_CNTL_1
, 0x08); /* MMIO Select (0x0c works as well)*/
877 wcrt(CRT_ID_EXT_MEM_CNTL_2
, 0x02); /* why 02 big endian 00 works ? */
878 wcrt(CRT_ID_EXT_MEM_CNTL_4
, 0x9f); /* config big endian - 0x00 ? */
879 wcrt(CRT_ID_LAW_POS_HI
, 0x00);
880 wcrt(CRT_ID_LAW_POS_LO
, 0x00);
881 wcrt(CRT_ID_EXT_MISC_CNTL_1
, 0x81);
882 wcrt(CRT_ID_MISC_1
, 0x90); /* must follow CRT_ID_EXT_MISC_CNTL_1 */
883 wcrt(CRT_ID_LAW_CNTL
, 0x13); /* force 4 Meg for test */
884 if (cv3d_has_4mb()) {
885 v_ram_size
= 0x00400000;
886 wcrt(CRT_ID_LAW_CNTL
, 0x13); /* 4 MB */
888 v_ram_size
= 0x00200000;
889 wcrt(CRT_ID_LAW_CNTL
, 0x12); /* 2 MB */
893 v_ram_size
-= 0x60000; /* we need some space for the registers */
895 wcrt(CRT_ID_EXT_SYS_CNTL_4
, 0x00);
896 wcrt(CRT_ID_EXT_DAC_CNTL
, 0x00); /* 0x10 for X11 cursor mode */
898 /* sequencer registers */
900 wseq(SEQ_ID_CLOCKING_MODE
, 0x01); /* 8 dot clock */
901 wseq(SEQ_ID_MAP_MASK
, 0xff);
902 wseq(SEQ_ID_CHAR_MAP_SELECT
, 0x00);
903 wseq(SEQ_ID_MEMORY_MODE
, 0x02);
904 wseq(SEQ_ID_RAMDAC_CNTL
, 0x00);
905 wseq(SEQ_ID_SIGNAL_SELECT
, 0x00);
906 wseq(SEQ_ID_EXT_SEQ_REG9
, 0x00); /* MMIO and PIO reg access enabled */
907 wseq(SEQ_ID_EXT_MISC_SEQ
, 0x00);
908 wseq(SEQ_ID_CLKSYN_CNTL_1
, 0x00);
909 wseq(SEQ_ID_EXT_SEQ
, 0x00);
911 /* graphic registers */
913 wgfx(GCT_ID_SET_RESET
, 0x00);
914 wgfx(GCT_ID_ENABLE_SET_RESET
, 0x00);
915 wgfx(GCT_ID_COLOR_COMPARE
, 0x00);
916 wgfx(GCT_ID_DATA_ROTATE
, 0x00);
917 wgfx(GCT_ID_READ_MAP_SELECT
, 0x00);
918 wgfx(GCT_ID_GRAPHICS_MODE
, 0x40);
919 wgfx(GCT_ID_MISC
, 0x01);
920 wgfx(GCT_ID_COLOR_XCARE
, 0x0f);
921 wgfx(GCT_ID_BITMASK
, 0xff);
923 /* attribute registers */
925 for(i
= 0; i
<= 15; i
++)
926 watr(ACT_ID_PALETTE0
+ i
, i
);
927 watr(ACT_ID_ATTR_MODE_CNTL
, 0x41);
928 watr(ACT_ID_OVERSCAN_COLOR
, 0xff);
929 watr(ACT_ID_COLOR_PLANE_ENA
, 0x0f);
930 watr(ACT_ID_HOR_PEL_PANNING
, 0x00);
931 watr(ACT_ID_COLOR_SELECT
, 0x00);
933 wb_mmio(VDAC_MASK
, 0xff);
935 /* init local cmap as greyscale levels */
937 for (i
= 0; i
< 256; i
++) {
938 virgefb_colour_table
[i
][0] = i
;
939 virgefb_colour_table
[i
][1] = i
;
940 virgefb_colour_table
[i
][2] = i
;
943 /* clear framebuffer memory */
945 memset((char*)v_ram
, 0x00, v_ram_size
);
953 * This function should fill in the `fix' structure based on the
954 * values in the `par' structure.
957 static int virgefb_encode_fix(struct fb_fix_screeninfo
*fix
,
958 struct virgefb_par
*par
)
960 DPRINTK("ENTER set video phys addr\n");
962 memset(fix
, 0, sizeof(struct fb_fix_screeninfo
));
963 strcpy(fix
->id
, virgefb_name
);
965 fix
->smem_start
= v_ram_phys
;
966 switch (par
->var
.bits_per_pixel
) {
967 #ifdef FBCON_HAS_CFB8
970 Select_Zorro2_FrameBuffer(ENDIAN_BYTE
);
972 fix
->smem_start
= (v_ram_phys
+ CYBMEM_OFFSET_8
);
975 #ifdef FBCON_HAS_CFB16
978 Select_Zorro2_FrameBuffer(ENDIAN_WORD
);
980 fix
->smem_start
= (v_ram_phys
+ CYBMEM_OFFSET_16
);
983 #ifdef FBCON_HAS_CFB32
986 Select_Zorro2_FrameBuffer(ENDIAN_LONG
);
988 fix
->smem_start
= (v_ram_phys
+ CYBMEM_OFFSET_32
);
993 fix
->smem_len
= v_ram_size
;
994 fix
->mmio_start
= mmio_regs_phys
;
995 fix
->mmio_len
= 0x10000; /* TODO: verify this for the CV64/3D */
997 fix
->type
= FB_TYPE_PACKED_PIXELS
;
999 if (par
->var
.bits_per_pixel
== 8)
1000 fix
->visual
= FB_VISUAL_PSEUDOCOLOR
;
1002 fix
->visual
= FB_VISUAL_TRUECOLOR
;
1007 fix
->line_length
= par
->var
.xres_virtual
*par
->var
.bits_per_pixel
/8;
1008 fix
->accel
= FB_ACCEL_S3_VIRGE
;
1009 DPRINTK("EXIT v_ram_phys = 0x%8.8lx\n", (unsigned long)fix
->smem_start
);
1015 * Fill the `par' structure based on the values in `var'.
1016 * TODO: Verify and adjust values, return -EINVAL if bad.
1019 static int virgefb_decode_var(struct fb_var_screeninfo
*var
,
1020 struct virgefb_par
*par
)
1023 par
->var
.xres
= var
->xres
;
1024 par
->var
.yres
= var
->yres
;
1025 par
->var
.xres_virtual
= var
->xres_virtual
;
1026 par
->var
.yres_virtual
= var
->yres_virtual
;
1027 /* roundup and validate */
1028 par
->var
.xres
= (par
->var
.xres
+7) & ~7;
1029 par
->var
.xres_virtual
= (par
->var
.xres_virtual
+7) & ~7;
1030 if (par
->var
.xres_virtual
< par
->var
.xres
)
1031 par
->var
.xres_virtual
= par
->var
.xres
;
1032 if (par
->var
.yres_virtual
< par
->var
.yres
)
1033 par
->var
.yres_virtual
= par
->var
.yres
;
1034 par
->var
.xoffset
= var
->xoffset
;
1035 par
->var
.yoffset
= var
->yoffset
;
1036 par
->var
.bits_per_pixel
= var
->bits_per_pixel
;
1037 if (par
->var
.bits_per_pixel
<= 8)
1038 par
->var
.bits_per_pixel
= 8;
1039 else if (par
->var
.bits_per_pixel
<= 16)
1040 par
->var
.bits_per_pixel
= 16;
1042 par
->var
.bits_per_pixel
= 32;
1043 #ifndef FBCON_HAS_CFB32
1044 if (par
->var
.bits_per_pixel
== 32)
1045 par
->var
.bits_per_pixel
= 16;
1047 #ifndef FBCON_HAS_CFB16
1048 if (par
->var
.bits_per_pixel
== 16)
1049 par
->var
.bits_per_pixel
= 8;
1051 par
->var
.grayscale
= var
->grayscale
;
1052 par
->var
.red
= var
->red
;
1053 par
->var
.green
= var
->green
;
1054 par
->var
.blue
= var
->blue
;
1055 par
->var
.transp
= var
->transp
;
1056 par
->var
.nonstd
= var
->nonstd
;
1057 par
->var
.activate
= var
->activate
;
1058 par
->var
.height
= var
->height
;
1059 par
->var
.width
= var
->width
;
1060 if (var
->accel_flags
& FB_ACCELF_TEXT
) {
1061 par
->var
.accel_flags
= FB_ACCELF_TEXT
;
1063 par
->var
.accel_flags
= 0;
1065 par
->var
.pixclock
= var
->pixclock
;
1066 par
->var
.left_margin
= var
->left_margin
;
1067 par
->var
.right_margin
= var
->right_margin
;
1068 par
->var
.upper_margin
= var
->upper_margin
;
1069 par
->var
.lower_margin
= var
->lower_margin
;
1070 par
->var
.hsync_len
= var
->hsync_len
;
1071 par
->var
.vsync_len
= var
->vsync_len
;
1072 par
->var
.sync
= var
->sync
;
1073 par
->var
.vmode
= var
->vmode
;
1079 * Fill the `var' structure based on the values in `par' and maybe
1080 * other values read out of the hardware.
1083 static int virgefb_encode_var(struct fb_var_screeninfo
*var
,
1084 struct virgefb_par
*par
)
1087 memset(var
, 0, sizeof(struct fb_var_screeninfo
)); /* need this ? */
1088 var
->xres
= par
->var
.xres
;
1089 var
->yres
= par
->var
.yres
;
1090 var
->xres_virtual
= par
->var
.xres_virtual
;
1091 var
->yres_virtual
= par
->var
.yres_virtual
;
1092 var
->xoffset
= par
->var
.xoffset
;
1093 var
->yoffset
= par
->var
.yoffset
;
1094 var
->bits_per_pixel
= par
->var
.bits_per_pixel
;
1095 var
->grayscale
= par
->var
.grayscale
;
1096 var
->red
= par
->var
.red
;
1097 var
->green
= par
->var
.green
;
1098 var
->blue
= par
->var
.blue
;
1099 var
->transp
= par
->var
.transp
;
1100 var
->nonstd
= par
->var
.nonstd
;
1101 var
->activate
= par
->var
.activate
;
1102 var
->height
= par
->var
.height
;
1103 var
->width
= par
->var
.width
;
1104 var
->accel_flags
= par
->var
.accel_flags
;
1105 var
->pixclock
= par
->var
.pixclock
;
1106 var
->left_margin
= par
->var
.left_margin
;
1107 var
->right_margin
= par
->var
.right_margin
;
1108 var
->upper_margin
= par
->var
.upper_margin
;
1109 var
->lower_margin
= par
->var
.lower_margin
;
1110 var
->hsync_len
= par
->var
.hsync_len
;
1111 var
->vsync_len
= par
->var
.vsync_len
;
1112 var
->sync
= par
->var
.sync
;
1113 var
->vmode
= par
->var
.vmode
;
1119 * Set a single color register. The values supplied are already
1120 * rounded down to the hardware's capabilities (according to the
1121 * entries in the var structure). Return != 0 for invalid regno.
1124 static int virgefb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
1125 u_int transp
, struct fb_info
*info
)
1128 if (((current_par
.var
.bits_per_pixel
==8) && (regno
>255)) ||
1129 ((current_par
.var
.bits_per_pixel
!=8) && (regno
>15))) {
1133 if (((current_par
.var
.bits_per_pixel
==8) && (regno
<256)) ||
1134 ((current_par
.var
.bits_per_pixel
!=8) && (regno
<16))) {
1135 virgefb_colour_table
[regno
][0] = red
>> 10;
1136 virgefb_colour_table
[regno
][1] = green
>> 10;
1137 virgefb_colour_table
[regno
][2] = blue
>> 10;
1140 switch (current_par
.var
.bits_per_pixel
) {
1141 #ifdef FBCON_HAS_CFB8
1143 wb_mmio(VDAC_ADDRESS_W
, (unsigned char)regno
);
1144 wb_mmio(VDAC_DATA
, ((unsigned char)(red
>> 10)));
1145 wb_mmio(VDAC_DATA
, ((unsigned char)(green
>> 10)));
1146 wb_mmio(VDAC_DATA
, ((unsigned char)(blue
>> 10)));
1149 #ifdef FBCON_HAS_CFB16
1151 fbcon_cmap
.cfb16
[regno
] =
1153 ((green
& 0xfc00) >> 5) |
1154 ((blue
& 0xf800) >> 11));
1157 #ifdef FBCON_HAS_CFB32
1159 fbcon_cmap
.cfb32
[regno
] =
1160 /* transp = 0's or 1's ? */
1161 (((red
& 0xff00) << 8) |
1162 ((green
& 0xff00) >> 0) |
1163 ((blue
& 0xff00) >> 8));
1173 * Read a single color register and split it into
1174 * colors/transparent. Return != 0 for invalid regno.
1177 static int virgefb_getcolreg(u_int regno
, u_int
*red
, u_int
*green
, u_int
*blue
,
1178 u_int
*transp
, struct fb_info
*info
)
1187 if (((current_par
.var
.bits_per_pixel
==8) && (regno
<256)) ||
1188 ((current_par
.var
.bits_per_pixel
!=8) && (regno
<16))) {
1190 t
= virgefb_colour_table
[regno
][0];
1191 *red
= (t
<<10) | (t
<<4) | (t
>>2);
1192 t
= virgefb_colour_table
[regno
][1];
1193 *green
= (t
<<10) | (t
<<4) | (t
>>2);
1194 t
= virgefb_colour_table
[regno
][2];
1195 *blue
= (t
<<10) | (t
<<4) | (t
>>2);
1204 * (Un)Blank the screen
1207 static void virgefb_gfx_on_off(int blank
)
1215 * CV3D low-level support
1219 static inline void wait_3d_fifo_slots(int n
) /* WaitQueue */
1223 } while (((rl_mmio(MR_SUBSYSTEM_STATUS_R
) >> 8) & 0x1f) < (n
+ 2));
1226 static inline void virgefb_wait_for_idle(void) /* WaitIdle */
1228 while(!(rl_mmio(MR_SUBSYSTEM_STATUS_R
) & 0x2000)) ;
1229 blit_maybe_busy
= 0;
1233 * BitBLT - Through the Plane
1236 static void virgefb_BitBLT(u_short curx
, u_short cury
, u_short destx
, u_short desty
,
1237 u_short width
, u_short height
, u_short stride
, u_short depth
)
1239 unsigned int blitcmd
= S3V_BITBLT
| S3V_DRAW
| S3V_BLT_COPY
;
1242 #ifdef FBCON_HAS_CFB8
1244 blitcmd
|= S3V_DST_8BPP
;
1247 #ifdef FBCON_HAS_CFB16
1249 blitcmd
|= S3V_DST_16BPP
;
1252 #ifdef FBCON_HAS_CFB32
1254 /* 32 bit uses 2 by 16 bit values, see fbcon_virge32_bmove */
1255 blitcmd
|= S3V_DST_16BPP
;
1260 /* Set drawing direction */
1261 /* -Y, X maj, -X (default) */
1263 blitcmd
|= (1 << 25); /* Drawing direction +X */
1265 curx
+= (width
- 1);
1266 destx
+= (width
- 1);
1270 blitcmd
|= (1 << 26); /* Drawing direction +Y */
1272 cury
+= (height
- 1);
1273 desty
+= (height
- 1);
1276 wait_3d_fifo_slots(8); /* wait on fifo slots for 8 writes */
1278 if (blit_maybe_busy
)
1279 virgefb_wait_for_idle();
1280 blit_maybe_busy
= 1;
1282 wl_mmio(BLT_PATTERN_COLOR
, 1); /* pattern fb color */
1283 wl_mmio(BLT_MONO_PATTERN_0
, ~0);
1284 wl_mmio(BLT_MONO_PATTERN_1
, ~0);
1285 wl_mmio(BLT_SIZE_X_Y
, ((width
<< 16) | height
));
1286 wl_mmio(BLT_SRC_X_Y
, ((curx
<< 16) | cury
));
1287 wl_mmio(BLT_DEST_X_Y
, ((destx
<< 16) | desty
));
1288 wl_mmio(BLT_SRC_DEST_STRIDE
, (((stride
<< 16) | stride
) /* & 0x0ff80ff8 */)); /* why is this needed now ? */
1289 wl_mmio(BLT_COMMAND_SET
, blitcmd
);
1293 * Rectangle Fill Solid
1296 static void virgefb_RectFill(u_short x
, u_short y
, u_short width
, u_short height
,
1297 u_short color
, u_short stride
, u_short depth
)
1299 unsigned int blitcmd
= S3V_RECTFILL
| S3V_DRAW
|
1300 S3V_BLT_CLEAR
| S3V_MONO_PAT
| (1 << 26) | (1 << 25);
1303 #ifdef FBCON_HAS_CFB8
1305 blitcmd
|= S3V_DST_8BPP
;
1308 #ifdef FBCON_HAS_CFB16
1310 blitcmd
|= S3V_DST_16BPP
;
1313 #ifdef FBCON_HAS_CFB32
1315 /* 32 bit uses 2 times 16 bit values, see fbcon_virge32_clear */
1316 blitcmd
|= S3V_DST_16BPP
;
1321 wait_3d_fifo_slots(5); /* wait on fifo slots for 5 writes */
1323 if (blit_maybe_busy
)
1324 virgefb_wait_for_idle();
1325 blit_maybe_busy
= 1;
1327 wl_mmio(BLT_PATTERN_COLOR
, (color
& 0xff));
1328 wl_mmio(BLT_SIZE_X_Y
, ((width
<< 16) | height
));
1329 wl_mmio(BLT_DEST_X_Y
, ((x
<< 16) | y
));
1330 wl_mmio(BLT_SRC_DEST_STRIDE
, (((stride
<< 16) | stride
) /* & 0x0ff80ff8 */));
1331 wl_mmio(BLT_COMMAND_SET
, blitcmd
);
1335 * Move cursor to x, y
1339 static void virgefb_move_cursor(u_short x
, u_short y
)
1341 DPRINTK("Yuck .... MoveCursor on a 3D\n");
1346 /* -------------------- Interfaces to hardware functions -------------------- */
1348 static struct fb_hwswitch virgefb_hw_switch
= {
1350 .encode_fix
= virgefb_encode_fix
,
1351 .decode_var
= virgefb_decode_var
,
1352 .encode_var
= virgefb_encode_var
,
1353 .getcolreg
= virgefb_getcolreg
,
1354 .blank
= virgefb_gfx_on_off
1358 /* -------------------- Generic routines ------------------------------------ */
1362 * Fill the hardware's `par' structure.
1365 static void virgefb_get_par(struct virgefb_par
*par
)
1368 if (current_par_valid
) {
1371 fbhw
->decode_var(&virgefb_default
, par
);
1377 static void virgefb_set_par(struct virgefb_par
*par
)
1381 current_par_valid
= 1;
1386 static void virgefb_set_video(struct fb_var_screeninfo
*var
)
1388 /* Set clipping rectangle to current screen size */
1393 wait_3d_fifo_slots(4);
1394 clip
= ((0 << 16) | (var
->xres
- 1));
1395 wl_mmio(BLT_CLIP_LEFT_RIGHT
, clip
);
1396 clip
= ((0 << 16) | (var
->yres
- 1));
1397 wl_mmio(BLT_CLIP_TOP_BOTTOM
, clip
);
1398 wl_mmio(BLT_SRC_BASE
, 0); /* seems we need to clear these two */
1399 wl_mmio(BLT_DEST_BASE
, 0);
1401 /* Load the video mode defined by the 'var' data */
1403 virgefb_load_video_mode(var
);
1408 Merge these two functions, Geert's suggestion.
1409 static int virgefb_set_var(struct fb_var_screeninfo *var, int con, struct fb_info *info);
1410 static int virgefb_do_fb_set_var(struct fb_var_screeninfo *var, int isactive);
1413 static int virgefb_do_fb_set_var(struct fb_var_screeninfo
*var
, int isactive
)
1416 struct virgefb_par par
;
1419 if ((err
= fbhw
->decode_var(var
, &par
))) {
1424 activate
= var
->activate
;
1425 if ((var
->activate
& FB_ACTIVATE_MASK
) == FB_ACTIVATE_NOW
&& isactive
)
1426 virgefb_set_par(&par
);
1427 fbhw
->encode_var(var
, &par
);
1428 var
->activate
= activate
;
1429 if ((var
->activate
& FB_ACTIVATE_MASK
) == FB_ACTIVATE_NOW
&& isactive
)
1430 virgefb_set_video(var
);
1437 * Get the Fixed Part of the Display
1440 static int virgefb_get_fix(struct fb_fix_screeninfo
*fix
, int con
,
1441 struct fb_info
*info
)
1443 struct virgefb_par par
;
1448 virgefb_get_par(&par
);
1450 error
= fbhw
->decode_var(&fb_display
[con
].var
, &par
);
1453 error
= fbhw
->encode_fix(fix
, &par
);
1460 * Get the User Defined Part of the Display
1463 static int virgefb_get_var(struct fb_var_screeninfo
*var
, int con
,
1464 struct fb_info
*info
)
1466 struct virgefb_par par
;
1471 virgefb_get_par(&par
);
1472 error
= fbhw
->encode_var(var
, &par
);
1473 disp
.var
= *var
; /* ++Andre: don't know if this is the right place */
1475 *var
= fb_display
[con
].var
;
1481 static void virgefb_set_disp(int con
, struct fb_info
*info
)
1483 struct fb_fix_screeninfo fix
;
1484 struct display
*display
;
1488 display
= &fb_display
[con
];
1490 display
= &disp
; /* used during initialization */
1492 virgefb_get_fix(&fix
, con
, info
);
1496 info
->screen_base
= (char*)v_ram
;
1498 switch (display
->var
.bits_per_pixel
) {
1499 #ifdef FBCON_HAS_CFB8
1501 info
->screen_base
= (char*)(v_ram
+ CYBMEM_OFFSET_8
);
1504 #ifdef FBCON_HAS_CFB16
1506 info
->screen_base
= (char*)(v_ram
+ CYBMEM_OFFSET_16
);
1509 #ifdef FBCON_HAS_CFB32
1511 info
->screen_base
= (char*)(v_ram
+ CYBMEM_OFFSET_32
);
1516 display
->visual
= fix
.visual
;
1517 display
->type
= fix
.type
;
1518 display
->type_aux
= fix
.type_aux
;
1519 display
->ypanstep
= fix
.ypanstep
;
1520 display
->ywrapstep
= fix
.ywrapstep
;
1521 display
->can_soft_blank
= 1;
1522 display
->inverse
= virgefb_inverse
;
1523 display
->line_length
= display
->var
.xres_virtual
*
1524 display
->var
.bits_per_pixel
/8;
1526 switch (display
->var
.bits_per_pixel
) {
1527 #ifdef FBCON_HAS_CFB8
1529 if (display
->var
.accel_flags
& FB_ACCELF_TEXT
) {
1530 display
->dispsw
= &fbcon_virge8
;
1531 #warning FIXME: We should reinit the graphics engine here
1533 display
->dispsw
= &fbcon_cfb8
;
1536 #ifdef FBCON_HAS_CFB16
1538 if (display
->var
.accel_flags
& FB_ACCELF_TEXT
) {
1539 display
->dispsw
= &fbcon_virge16
;
1541 display
->dispsw
= &fbcon_cfb16
;
1542 display
->dispsw_data
= &fbcon_cmap
.cfb16
;
1545 #ifdef FBCON_HAS_CFB32
1547 if (display
->var
.accel_flags
& FB_ACCELF_TEXT
) {
1548 display
->dispsw
= &fbcon_virge32
;
1550 display
->dispsw
= &fbcon_cfb32
;
1551 display
->dispsw_data
= &fbcon_cmap
.cfb32
;
1555 display
->dispsw
= &fbcon_dummy
;
1558 DPRINTK("EXIT v_ram virt = 0x%8.8lx\n",(unsigned long)display
->screen_base
);
1563 * Set the User Defined Part of the Display
1566 static int virgefb_set_var(struct fb_var_screeninfo
*var
, int con
,
1567 struct fb_info
*info
)
1569 int err
, oldxres
, oldyres
, oldvxres
, oldvyres
, oldbpp
, oldaccel
;
1573 if ((err
= virgefb_do_fb_set_var(var
, con
== info
->currcon
))) {
1577 if ((var
->activate
& FB_ACTIVATE_MASK
) == FB_ACTIVATE_NOW
) {
1578 oldxres
= fb_display
[con
].var
.xres
;
1579 oldyres
= fb_display
[con
].var
.yres
;
1580 oldvxres
= fb_display
[con
].var
.xres_virtual
;
1581 oldvyres
= fb_display
[con
].var
.yres_virtual
;
1582 oldbpp
= fb_display
[con
].var
.bits_per_pixel
;
1583 oldaccel
= fb_display
[con
].var
.accel_flags
;
1584 fb_display
[con
].var
= *var
;
1585 if (oldxres
!= var
->xres
|| oldyres
!= var
->yres
||
1586 oldvxres
!= var
->xres_virtual
||
1587 oldvyres
!= var
->yres_virtual
||
1588 oldbpp
!= var
->bits_per_pixel
||
1589 oldaccel
!= var
->accel_flags
) {
1590 virgefb_set_disp(con
, info
);
1591 if (fb_info
.changevar
)
1592 (*fb_info
.changevar
)(con
);
1593 fb_alloc_cmap(&fb_display
[con
].cmap
, 0, 0);
1594 do_install_cmap(con
, info
);
1607 static int virgefb_get_cmap(struct fb_cmap
*cmap
, int kspc
, int con
,
1608 struct fb_info
*info
)
1611 if (con
== info
->currcon
) { /* current console? */
1612 DPRINTK("EXIT - console is current console, fb_get_cmap\n");
1613 return(fb_get_cmap(cmap
, kspc
, fbhw
->getcolreg
, info
));
1614 } else if (fb_display
[con
].cmap
.len
) { /* non default colormap? */
1615 DPRINTK("Use console cmap\n");
1616 fb_copy_cmap(&fb_display
[con
].cmap
, cmap
, kspc
? 0 : 2);
1618 DPRINTK("Use default cmap\n");
1619 fb_copy_cmap(fb_default_cmap(fb_display
[con
].var
.bits_per_pixel
==8 ? 256 : 16),
1620 cmap
, kspc
? 0 : 2);
1626 static struct fb_ops virgefb_ops
= {
1627 .owner
= THIS_MODULE
,
1628 .fb_get_fix
= virgefb_get_fix
,
1629 .fb_get_var
= virgefb_get_var
,
1630 .fb_set_var
= virgefb_set_var
,
1631 .fb_get_cmap
= virgefb_get_cmap
,
1632 .fb_set_cmap
= gen_set_cmap
,
1633 .fb_setcolreg
= virgefb_setcolreg
,
1634 .fb_blank
= virgefb_blank
,
1637 int __init
virgefb_setup(char *options
)
1640 fb_info
.fontname
[0] = '\0';
1643 if (!options
|| !*options
) {
1648 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
1651 if (!strcmp(this_opt
, "inverse")) {
1652 virgefb_inverse
= 1;
1654 } else if (!strncmp(this_opt
, "font:", 5))
1655 strcpy(fb_info
.fontname
, this_opt
+5);
1656 #ifdef FBCON_HAS_CFB8
1657 else if (!strcmp (this_opt
, "virge8")){
1658 virgefb_default
= virgefb_predefined
[VIRGE8_DEFMODE
].var
;
1661 #ifdef FBCON_HAS_CFB16
1662 else if (!strcmp (this_opt
, "virge16")){
1663 virgefb_default
= virgefb_predefined
[VIRGE16_DEFMODE
].var
;
1666 #ifdef FBCON_HAS_CFB32
1667 else if (!strcmp (this_opt
, "virge32")){
1668 virgefb_default
= virgefb_predefined
[VIRGE32_DEFMODE
].var
;
1672 virgefb_get_video_mode(this_opt
);
1675 printk(KERN_INFO
"mode : xres=%d, yres=%d, bpp=%d\n", virgefb_default
.xres
,
1676 virgefb_default
.yres
, virgefb_default
.bits_per_pixel
);
1686 static int __init
virgefb_get_video_mode(const char *name
)
1691 for (i
= 0; i
< NUM_TOTAL_MODES
; i
++) {
1692 if (!strcmp(name
, virgefb_predefined
[i
].name
)) {
1693 virgefb_default
= virgefb_predefined
[i
].var
;
1698 /* ++Andre: set virgefb default mode */
1700 /* prefer 16 bit depth, 8 if no 16, if no 8 or 16 use 32 */
1702 #ifdef FBCON_HAS_CFB32
1703 virgefb_default
= virgefb_predefined
[VIRGE32_DEFMODE
].var
;
1705 #ifdef FBCON_HAS_CFB8
1706 virgefb_default
= virgefb_predefined
[VIRGE8_DEFMODE
].var
;
1708 #ifdef FBCON_HAS_CFB16
1709 virgefb_default
= virgefb_predefined
[VIRGE16_DEFMODE
].var
;
1719 int __init
virgefb_init(void)
1721 struct virgefb_par par
;
1722 unsigned long board_addr
, board_size
;
1723 struct zorro_dev
*z
= NULL
;
1727 z
= zorro_find_device(ZORRO_PROD_PHASE5_CYBERVISION64_3D
, NULL
);
1731 board_addr
= z
->resource
.start
;
1732 if (board_addr
< 0x01000000) {
1734 /* board running in Z2 space. This includes the video memory
1735 as well as the S3 register set */
1738 board_size
= 0x00400000;
1740 if (!request_mem_region(board_addr
, board_size
, "S3 ViRGE"))
1743 v_ram_phys
= board_addr
;
1744 v_ram
= ZTWO_VADDR(v_ram_phys
);
1745 mmio_regs_phys
= (unsigned long)(board_addr
+ 0x003c0000);
1746 vgaio_regs
= (unsigned char *) ZTWO_VADDR(board_addr
+ 0x003c0000);
1747 mmio_regs
= (unsigned char *)ZTWO_VADDR(mmio_regs_phys
);
1748 vcode_switch_base
= (unsigned long) ZTWO_VADDR(board_addr
+ 0x003a0000);
1749 printk(KERN_INFO
"CV3D detected running in Z2 mode.\n");
1753 /* board running in Z3 space. Separate video memory (3 apertures)
1754 and S3 register set */
1757 board_size
= 0x01000000;
1759 if (!request_mem_region(board_addr
, board_size
, "S3 ViRGE"))
1762 v_ram_phys
= board_addr
+ 0x04000000;
1763 v_ram
= (unsigned long)ioremap(v_ram_phys
, 0x01000000);
1764 mmio_regs_phys
= board_addr
+ 0x05000000;
1765 vgaio_regs
= (unsigned char *)ioremap(board_addr
+0x0c000000, 0x00100000); /* includes PCI regs */
1766 mmio_regs
= ioremap(mmio_regs_phys
, 0x00010000);
1767 vcode_switch_base
= (unsigned long)ioremap(board_addr
+ 0x08000000, 0x1000);
1768 printk(KERN_INFO
"CV3D detected running in Z3 mode\n");
1771 #if defined (VIRGEFBDEBUG)
1772 DPRINTK("board_addr : 0x%8.8lx\n",board_addr
);
1773 DPRINTK("board_size : 0x%8.8lx\n",board_size
);
1774 DPRINTK("mmio_regs_phy : 0x%8.8lx\n",mmio_regs_phys
);
1775 DPRINTK("v_ram_phys : 0x%8.8lx\n",v_ram_phys
);
1776 DPRINTK("vgaio_regs : 0x%8.8lx\n",(unsigned long)vgaio_regs
);
1777 DPRINTK("mmio_regs : 0x%8.8lx\n",(unsigned long)mmio_regs
);
1778 DPRINTK("v_ram : 0x%8.8lx\n",v_ram
);
1779 DPRINTK("vcode sw base : 0x%8.8lx\n",vcode_switch_base
);
1781 fbhw
= &virgefb_hw_switch
;
1782 strcpy(fb_info
.modename
, virgefb_name
);
1783 fb_info
.changevar
= NULL
;
1784 fb_info
.fbops
= &virgefb_ops
;
1785 fb_info
.disp
= &disp
;
1786 fb_info
.currcon
= -1;
1787 fb_info
.switch_con
= &virgefb_switch
;
1788 fb_info
.updatevar
= &virgefb_updatevar
;
1789 fb_info
.flags
= FBINFO_FLAG_DEFAULT
;
1791 fbhw
->decode_var(&virgefb_default
, &par
);
1792 fbhw
->encode_var(&virgefb_default
, &par
);
1793 virgefb_do_fb_set_var(&virgefb_default
, 1);
1794 virgefb_get_var(&fb_display
[0].var
, -1, &fb_info
);
1795 virgefb_set_disp(-1, &fb_info
);
1796 do_install_cmap(0, &fb_info
);
1798 if (register_framebuffer(&fb_info
) < 0) {
1799 #warning release resources
1800 printk(KERN_ERR
"virgefb.c: register_framebuffer failed\n");
1805 printk(KERN_INFO
"fb%d: %s frame buffer device, using %ldK of video memory\n",
1806 fb_info
.node
, fb_info
.modename
, v_ram_size
>>10);
1808 /* TODO: This driver cannot be unloaded yet */
1815 static int virgefb_switch(int con
, struct fb_info
*info
)
1818 /* Do we have to save the colormap? */
1819 if (fb_display
[info
->currcon
].cmap
.len
)
1820 fb_get_cmap(&fb_display
[info
->currcon
].cmap
, 1,
1821 fbhw
->getcolreg
, info
);
1822 virgefb_do_fb_set_var(&fb_display
[con
].var
, 1);
1823 info
->currcon
= con
;
1824 /* Install new colormap */
1825 do_install_cmap(con
, info
);
1832 * Update the `var' structure (called by fbcon.c)
1834 * This call looks only at yoffset and the FB_VMODE_YWRAP flag in `var'.
1835 * Since it's called by a kernel driver, no range checking is done.
1838 static int virgefb_updatevar(int con
, struct fb_info
*info
)
1846 * Blank the display.
1849 static int virgefb_blank(int blank
, struct fb_info
*info
)
1859 * Text console acceleration
1862 #ifdef FBCON_HAS_CFB8
1863 static void fbcon_virge8_bmove(struct display
*p
, int sy
, int sx
, int dy
,
1864 int dx
, int height
, int width
)
1866 sx
*= 8; dx
*= 8; width
*= 8;
1867 virgefb_BitBLT((u_short
)sx
, (u_short
)(sy
*fontheight(p
)), (u_short
)dx
,
1868 (u_short
)(dy
*fontheight(p
)), (u_short
)width
,
1869 (u_short
)(height
*fontheight(p
)), (u_short
)p
->next_line
, 8);
1872 static void fbcon_virge8_clear(struct vc_data
*conp
, struct display
*p
, int sy
,
1873 int sx
, int height
, int width
)
1877 sx
*= 8; width
*= 8;
1878 bg
= attr_bgcol_ec(p
,conp
);
1879 virgefb_RectFill((u_short
)sx
, (u_short
)(sy
*fontheight(p
)),
1880 (u_short
)width
, (u_short
)(height
*fontheight(p
)),
1881 (u_short
)bg
, (u_short
)p
->next_line
, 8);
1884 static void fbcon_virge8_putc(struct vc_data
*conp
, struct display
*p
, int c
, int yy
,
1887 if (blit_maybe_busy
)
1888 virgefb_wait_for_idle();
1889 fbcon_cfb8_putc(conp
, p
, c
, yy
, xx
);
1892 static void fbcon_virge8_putcs(struct vc_data
*conp
, struct display
*p
,
1893 const unsigned short *s
, int count
, int yy
, int xx
)
1895 if (blit_maybe_busy
)
1896 virgefb_wait_for_idle();
1897 fbcon_cfb8_putcs(conp
, p
, s
, count
, yy
, xx
);
1900 static void fbcon_virge8_revc(struct display
*p
, int xx
, int yy
)
1902 if (blit_maybe_busy
)
1903 virgefb_wait_for_idle();
1904 fbcon_cfb8_revc(p
, xx
, yy
);
1907 static void fbcon_virge8_clear_margins(struct vc_data
*conp
, struct display
*p
,
1910 if (blit_maybe_busy
)
1911 virgefb_wait_for_idle();
1912 fbcon_cfb8_clear_margins(conp
, p
, bottom_only
);
1915 static struct display_switch fbcon_virge8
= {
1916 .setup
= fbcon_cfb8_setup
,
1917 .bmove
= fbcon_virge8_bmove
,
1918 .clear
= fbcon_virge8_clear
,
1919 .putc
= fbcon_virge8_putc
,
1920 .putcs
= fbcon_virge8_putcs
,
1921 .revc
= fbcon_virge8_revc
,
1922 .clear_margins
= fbcon_virge8_clear_margins
,
1923 .fontwidthmask
= FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
1927 #ifdef FBCON_HAS_CFB16
1928 static void fbcon_virge16_bmove(struct display
*p
, int sy
, int sx
, int dy
,
1929 int dx
, int height
, int width
)
1931 sx
*= 8; dx
*= 8; width
*= 8;
1932 virgefb_BitBLT((u_short
)sx
, (u_short
)(sy
*fontheight(p
)), (u_short
)dx
,
1933 (u_short
)(dy
*fontheight(p
)), (u_short
)width
,
1934 (u_short
)(height
*fontheight(p
)), (u_short
)p
->next_line
, 16);
1937 static void fbcon_virge16_clear(struct vc_data
*conp
, struct display
*p
, int sy
,
1938 int sx
, int height
, int width
)
1942 sx
*= 8; width
*= 8;
1943 bg
= attr_bgcol_ec(p
,conp
);
1944 virgefb_RectFill((u_short
)sx
, (u_short
)(sy
*fontheight(p
)),
1945 (u_short
)width
, (u_short
)(height
*fontheight(p
)),
1946 (u_short
)bg
, (u_short
)p
->next_line
, 16);
1949 static void fbcon_virge16_putc(struct vc_data
*conp
, struct display
*p
, int c
, int yy
,
1952 if (blit_maybe_busy
)
1953 virgefb_wait_for_idle();
1954 fbcon_cfb16_putc(conp
, p
, c
, yy
, xx
);
1957 static void fbcon_virge16_putcs(struct vc_data
*conp
, struct display
*p
,
1958 const unsigned short *s
, int count
, int yy
, int xx
)
1960 if (blit_maybe_busy
)
1961 virgefb_wait_for_idle();
1962 fbcon_cfb16_putcs(conp
, p
, s
, count
, yy
, xx
);
1965 static void fbcon_virge16_revc(struct display
*p
, int xx
, int yy
)
1967 if (blit_maybe_busy
)
1968 virgefb_wait_for_idle();
1969 fbcon_cfb16_revc(p
, xx
, yy
);
1972 static void fbcon_virge16_clear_margins(struct vc_data
*conp
, struct display
*p
,
1975 if (blit_maybe_busy
)
1976 virgefb_wait_for_idle();
1977 fbcon_cfb16_clear_margins(conp
, p
, bottom_only
);
1980 static struct display_switch fbcon_virge16
= {
1981 .setup
= fbcon_cfb16_setup
,
1982 .bmove
= fbcon_virge16_bmove
,
1983 .clear
= fbcon_virge16_clear
,
1984 .putc
= fbcon_virge16_putc
,
1985 .putcs
= fbcon_virge16_putcs
,
1986 .revc
= fbcon_virge16_revc
,
1987 .clear_margins
= fbcon_virge16_clear_margins
,
1988 .fontwidthmask
= FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
1992 #ifdef FBCON_HAS_CFB32
1993 static void fbcon_virge32_bmove(struct display
*p
, int sy
, int sx
, int dy
,
1994 int dx
, int height
, int width
)
1996 sx
*= 16; dx
*= 16; width
*= 16; /* doubled these values to do 32 bit blit */
1997 virgefb_BitBLT((u_short
)sx
, (u_short
)(sy
*fontheight(p
)), (u_short
)dx
,
1998 (u_short
)(dy
*fontheight(p
)), (u_short
)width
,
1999 (u_short
)(height
*fontheight(p
)), (u_short
)p
->next_line
, 16);
2002 static void fbcon_virge32_clear(struct vc_data
*conp
, struct display
*p
, int sy
,
2003 int sx
, int height
, int width
)
2007 sx
*= 16; width
*= 16; /* doubled these values to do 32 bit blit */
2008 bg
= attr_bgcol_ec(p
,conp
);
2009 virgefb_RectFill((u_short
)sx
, (u_short
)(sy
*fontheight(p
)),
2010 (u_short
)width
, (u_short
)(height
*fontheight(p
)),
2011 (u_short
)bg
, (u_short
)p
->next_line
, 16);
2014 static void fbcon_virge32_putc(struct vc_data
*conp
, struct display
*p
, int c
, int yy
,
2017 if (blit_maybe_busy
)
2018 virgefb_wait_for_idle();
2019 fbcon_cfb32_putc(conp
, p
, c
, yy
, xx
);
2022 static void fbcon_virge32_putcs(struct vc_data
*conp
, struct display
*p
,
2023 const unsigned short *s
, int count
, int yy
, int xx
)
2025 if (blit_maybe_busy
)
2026 virgefb_wait_for_idle();
2027 fbcon_cfb32_putcs(conp
, p
, s
, count
, yy
, xx
);
2030 static void fbcon_virge32_revc(struct display
*p
, int xx
, int yy
)
2032 if (blit_maybe_busy
)
2033 virgefb_wait_for_idle();
2034 fbcon_cfb32_revc(p
, xx
, yy
);
2037 static void fbcon_virge32_clear_margins(struct vc_data
*conp
, struct display
*p
,
2040 if (blit_maybe_busy
)
2041 virgefb_wait_for_idle();
2042 fbcon_cfb32_clear_margins(conp
, p
, bottom_only
);
2045 static struct display_switch fbcon_virge32
= {
2046 .setup
= fbcon_cfb32_setup
,
2047 .bmove
= fbcon_virge32_bmove
,
2048 .clear
= fbcon_virge32_clear
,
2049 .putc
= fbcon_virge32_putc
,
2050 .putcs
= fbcon_virge32_putcs
,
2051 .revc
= fbcon_virge32_revc
,
2052 .clear_margins
= fbcon_virge32_clear_margins
,
2053 .fontwidthmask
= FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
2058 MODULE_LICENSE("GPL");
2060 int init_module(void)
2062 return virgefb_init();
2066 static int cv3d_has_4mb(void)
2068 /* cyberfb version didn't work, neither does this (not reliably)
2069 forced to return 4MB */
2071 volatile unsigned long *t0
, *t2
;
2075 /* write patterns in memory and test if they can be read */
2076 t0
= (volatile unsigned long *)v_ram
;
2077 t2
= (volatile unsigned long *)(v_ram
+ 0x00200000);
2081 if (*t0
!= 0x87654321) {
2082 /* read of first location failed */
2083 DPRINTK("EXIT - 0MB !\n");
2087 if (*t2
== 0x87654321) {
2088 /* should read 0x12345678 if 4MB */
2089 DPRINTK("EXIT - 2MB(a) \n");
2093 if (*t2
!= 0x12345678) {
2094 /* upper 2MB read back match failed */
2095 DPRINTK("EXIT - 2MB(b)\n");
2103 if(*t2
!= 0xAAAAAAAA) {
2104 /* upper 2MB read back match failed */
2105 DPRINTK("EXIT - 2MB(c)\n");
2111 if(*t2
!= 0x55555555) {
2112 /* upper 2MB read back match failed */
2113 DPRINTK("EXIT - 2MB(d)\n");
2118 DPRINTK("EXIT - 4MB\n");
2124 * Computes M, N, and R pll params for freq arg.
2125 * Returns 16 bits - hi 0MMMMMM lo 0RRNNNNN
2128 #define REFCLOCK 14318000
2130 static unsigned short virgefb_compute_clock(unsigned long freq
)
2133 unsigned char m
, n
, r
, rpwr
;
2134 unsigned long diff
, ftry
, save
= ~0UL;
2139 for (r
= 0, rpwr
= 1 ; r
< 4 ; r
++, rpwr
*= 2) {
2140 if ((135000000 <= (rpwr
* freq
)) && ((rpwr
* freq
) <= 270000000)) {
2141 for (n
= 1 ; n
< 32 ; n
++) {
2142 m
= ((freq
* (n
+ 2) * rpwr
)/REFCLOCK
) - 2;
2143 if (m
== 0 || m
>127)
2145 ftry
= ((REFCLOCK
/ (n
+ 2)) * (m
+ 2)) / rpwr
;
2152 mnr
= (m
<< 8) | (r
<<5) | (n
& 0x7f);
2158 printk("Can't compute clock PLL values for %ld Hz clock\n", freq
);
2163 static void virgefb_load_video_mode(struct fb_var_screeninfo
*video_mode
)
2165 unsigned char lace
, dblscan
, tmp
;
2167 unsigned short HT
, HDE
, HBS
, HBW
, HSS
, HSW
;
2168 unsigned short VT
, VDE
, VBS
, VBW
, VSS
, VSW
;
2173 int xres
, xres_virtual
, hfront
, hsync
, hback
;
2174 int yres
, vfront
, vsync
, vback
;
2179 DPRINTK("ENTER : %dx%d-%d\n",video_mode
->xres
, video_mode
->yres
,
2180 video_mode
->bits_per_pixel
);
2182 bpp
= video_mode
->bits_per_pixel
;
2183 xres
= video_mode
->xres
;
2184 xres_virtual
= video_mode
->xres_virtual
;
2185 hfront
= video_mode
->right_margin
;
2186 hsync
= video_mode
->hsync_len
;
2187 hback
= video_mode
->left_margin
;
2192 if (video_mode
->vmode
& FB_VMODE_DOUBLE
) {
2193 yres
= video_mode
->yres
* 2;
2194 vfront
= video_mode
->lower_margin
* 2;
2195 vsync
= video_mode
->vsync_len
* 2;
2196 vback
= video_mode
->upper_margin
* 2;
2198 } else if (video_mode
->vmode
& FB_VMODE_INTERLACED
) {
2199 yres
= (video_mode
->yres
+ 1) / 2;
2200 vfront
= (video_mode
->lower_margin
+ 1) / 2;
2201 vsync
= (video_mode
->vsync_len
+ 1) / 2;
2202 vback
= (video_mode
->upper_margin
+ 1) / 2;
2205 yres
= video_mode
->yres
;
2206 vfront
= video_mode
->lower_margin
;
2207 vsync
= video_mode
->vsync_len
;
2208 vback
= video_mode
->upper_margin
;
2213 video_mode
->red
.offset
= 0;
2214 video_mode
->green
.offset
= 0;
2215 video_mode
->blue
.offset
= 0;
2216 video_mode
->transp
.offset
= 0;
2217 video_mode
->red
.length
= 8;
2218 video_mode
->green
.length
= 8;
2219 video_mode
->blue
.length
= 8;
2220 video_mode
->transp
.length
= 0;
2223 SCO
= xres_virtual
/ 8;
2226 video_mode
->red
.offset
= 11;
2227 video_mode
->green
.offset
= 5;
2228 video_mode
->blue
.offset
= 0;
2229 video_mode
->transp
.offset
= 0;
2230 video_mode
->red
.length
= 5;
2231 video_mode
->green
.length
= 6;
2232 video_mode
->blue
.length
= 5;
2233 video_mode
->transp
.length
= 0;
2236 SCO
= xres_virtual
/ 4;
2239 video_mode
->red
.offset
= 16;
2240 video_mode
->green
.offset
= 8;
2241 video_mode
->blue
.offset
= 0;
2242 video_mode
->transp
.offset
= 24;
2243 video_mode
->red
.length
= 8;
2244 video_mode
->green
.length
= 8;
2245 video_mode
->blue
.length
= 8;
2246 video_mode
->transp
.length
= 8;
2249 SCO
= xres_virtual
/ 2;
2253 HT
= (((xres
+ hfront
+ hsync
+ hback
) / 8) * hmul
) - 5;
2254 HDE
= ((xres
/ 8) * hmul
) - 1;
2255 HBS
= (xres
/ 8) * hmul
;
2256 HSS
= ((xres
+ hfront
) / 8) * hmul
;
2257 HSW
= (hsync
/ 8) * hmul
;
2258 HBW
= (((hfront
+ hsync
+ hback
) / 8) * hmul
) - 2;
2260 VT
= yres
+ vfront
+ vsync
+ vback
- 2;
2263 VSS
= yres
+ vfront
;
2265 VBW
= vfront
+ vsync
+ vback
- 2;
2268 DPRINTK("HDE : 0x%4.4x, %4.4d\n", HDE
, HDE
);
2269 DPRINTK("HBS : 0x%4.4x, %4.4d\n", HBS
, HBS
);
2270 DPRINTK("HSS : 0x%4.4x, %4.4d\n", HSS
, HSS
);
2271 DPRINTK("HSW : 0x%4.4x, %4.4d\n", HSW
, HSW
);
2272 DPRINTK("HBW : 0x%4.4x, %4.4d\n", HBW
, HBW
);
2273 DPRINTK("HSS + HSW : 0x%4.4x, %4.4d\n", HSS
+HSW
, HSS
+HSW
);
2274 DPRINTK("HBS + HBW : 0x%4.4x, %4.4d\n", HBS
+HBW
, HBS
+HBW
);
2275 DPRINTK("HT : 0x%4.4x, %4.4d\n", HT
, HT
);
2276 DPRINTK("VDE : 0x%4.4x, %4.4d\n", VDE
, VDE
);
2277 DPRINTK("VBS : 0x%4.4x, %4.4d\n", VBS
, VBS
);
2278 DPRINTK("VSS : 0x%4.4x, %4.4d\n", VSS
, VSS
);
2279 DPRINTK("VSW : 0x%4.4x, %4.4d\n", VSW
, VSW
);
2280 DPRINTK("VBW : 0x%4.4x, %4.4d\n", VBW
, VBW
);
2281 DPRINTK("VT : 0x%4.4x, %4.4d\n", VT
, VT
);
2284 /* turn gfx off, don't mess up the display */
2288 /* H and V sync polarity */
2290 tmp
= rb_mmio(GREG_MISC_OUTPUT_R
) & 0x2f; /* colour, ram enable, clk sr12/s13 sel */
2291 if (!(video_mode
->sync
& FB_SYNC_HOR_HIGH_ACT
))
2292 tmp
|= 0x40; /* neg H sync polarity */
2293 if (!(video_mode
->sync
& FB_SYNC_VERT_HIGH_ACT
))
2294 tmp
|= 0x80; /* neg V sync polarity */
2295 tmp
|= 0x0c; /* clk from sr12/sr13 */
2296 wb_mmio(GREG_MISC_OUTPUT_W
, tmp
);
2300 wseq(SEQ_ID_BUS_REQ_CNTL
, 0xc0); /* 2 clk mem wr and /RAS1 */
2301 wseq(SEQ_ID_CLKSYN_CNTL_2
, 0x80); /* b7 is 2 mem clk wr */
2302 mnr
= virgefb_compute_clock(MEMCLOCK
);
2303 DPRINTK("mem clock %d, m %d, n %d, r %d.\n", MEMCLOCK
, ((mnr
>>8)&0x7f), (mnr
&0x1f), ((mnr
>> 5)&0x03));
2304 wseq(SEQ_ID_MCLK_LO
, (mnr
& 0x7f));
2305 wseq(SEQ_ID_MCLK_HI
, ((mnr
& 0x7f00) >> 8));
2306 freq
= (1000000000 / video_mode
->pixclock
) * 1000; /* pixclock is in ps ... convert to Hz */
2307 mnr
= virgefb_compute_clock(freq
);
2308 DPRINTK("dot clock %ld, m %d, n %d, r %d.\n", freq
, ((mnr
>>8)&0x7f), (mnr
&0x1f), ((mnr
>>5)&0x03));
2309 wseq(SEQ_ID_DCLK_LO
, (mnr
& 0x7f));
2310 wseq(SEQ_ID_DCLK_HI
, ((mnr
& 0x7f00) >> 8));
2311 wseq(SEQ_ID_CLKSYN_CNTL_2
, 0xa0);
2312 wseq(SEQ_ID_CLKSYN_CNTL_2
, 0x80);
2315 /* load display parameters into board */
2317 /* not sure about sync and blanking extensions bits in cr5d and cr5 */
2319 wcrt(CRT_ID_EXT_HOR_OVF
, /* 0x5d */
2320 ((HT
& 0x100) ? 0x01 : 0x00) |
2321 ((HDE
& 0x100) ? 0x02 : 0x00) |
2322 ((HBS
& 0x100) ? 0x04 : 0x00) |
2323 /* (((HBS + HBW) & 0x40) ? 0x08 : 0x00) | */
2324 ((HSS
& 0x100) ? 0x10 : 0x00) |
2325 /* (((HSS + HSW) & 0x20) ? 0x20 : 0x00) | */
2326 ((HSW
>= 0x20) ? 0x20 : 0x00) |
2327 (((HT
-5) & 0x100) ? 0x40 : 0x00));
2329 wcrt(CRT_ID_EXT_VER_OVF
, /* 0x5e */
2330 ((VT
& 0x400) ? 0x01 : 0x00) |
2331 ((VDE
& 0x400) ? 0x02 : 0x00) |
2332 ((VBS
& 0x400) ? 0x04 : 0x00) |
2333 ((VSS
& 0x400) ? 0x10 : 0x00) |
2334 0x40); /* line compare */
2336 wcrt(CRT_ID_START_VER_RETR
, VSS
);
2337 cr11
= rcrt(CRT_ID_END_VER_RETR
) | 0x20; /* vert interrupt flag */
2338 wcrt(CRT_ID_END_VER_RETR
, ((cr11
& 0x20) | ((VSS
+ VSW
) & 0x0f))); /* keeps vert irq enable state, also has unlock bit cr0 to 7 */
2339 wcrt(CRT_ID_VER_DISP_ENA_END
, VDE
);
2340 wcrt(CRT_ID_START_VER_BLANK
, VBS
);
2341 wcrt(CRT_ID_END_VER_BLANK
, VBS
+ VBW
); /* might be +/- 1 out */
2342 wcrt(CRT_ID_HOR_TOTAL
, HT
);
2343 wcrt(CRT_ID_DISPLAY_FIFO
, HT
- 5);
2344 wcrt(CRT_ID_BACKWAD_COMP_3
, 0x10); /* enable display fifo */
2345 wcrt(CRT_ID_HOR_DISP_ENA_END
, HDE
);
2346 wcrt(CRT_ID_START_HOR_BLANK
, HBS
);
2347 wcrt(CRT_ID_END_HOR_BLANK
, (HBS
+ HBW
) & 0x1f);
2348 wcrt(CRT_ID_START_HOR_RETR
, HSS
);
2349 wcrt(CRT_ID_END_HOR_RETR
, /* cr5 */
2350 ((HSS
+ HSW
) & 0x1f) |
2351 (((HBS
+ HBW
) & 0x20) ? 0x80 : 0x00));
2352 wcrt(CRT_ID_VER_TOTAL
, VT
);
2353 wcrt(CRT_ID_OVERFLOW
,
2354 ((VT
& 0x100) ? 0x01 : 0x00) |
2355 ((VDE
& 0x100) ? 0x02 : 0x00) |
2356 ((VSS
& 0x100) ? 0x04 : 0x00) |
2357 ((VBS
& 0x100) ? 0x08 : 0x00) |
2359 ((VT
& 0x200) ? 0x20 : 0x00) |
2360 ((VDE
& 0x200) ? 0x40 : 0x00) |
2361 ((VSS
& 0x200) ? 0x80 : 0x00));
2362 wcrt(CRT_ID_MAX_SCAN_LINE
,
2363 (dblscan
? 0x80 : 0x00) |
2365 ((VBS
& 0x200) ? 0x20 : 0x00));
2366 wcrt(CRT_ID_LINE_COMPARE
, 0xff);
2367 wcrt(CRT_ID_LACE_RETR_START
, HT
/ 2); /* (HT-5)/2 ? */
2368 wcrt(CRT_ID_LACE_CONTROL
, (lace
? 0x20 : 0x00));
2370 wcrt(CRT_ID_SCREEN_OFFSET
, SCO
);
2371 wcrt(CRT_ID_EXT_SYS_CNTL_2
, (SCO
>> 4) & 0x30 );
2373 /* wait for vert sync before cr67 update */
2375 for (i
=0; i
< 10000; i
++) {
2378 if (rb_mmio(GREG_INPUT_STATUS1_R
) & 0x08)
2382 wl_mmio(0x8200, 0x0000c000); /* fifo control (0x00110400 ?) */
2383 wcrt(CRT_ID_EXT_MISC_CNTL_2
, cr67
);
2387 tmp
= rb_mmio(ACT_ADDRESS_RESET
);
2388 wb_mmio(ACT_ADDRESS_W
, ((bpp
== 8) ? 0x20 : 0x00)); /* set b5, ENB PLT in attr idx reg) */
2389 tmp
= rb_mmio(ACT_ADDRESS_RESET
);
2391 /* turn gfx on again */
2397 SetVSwitch(1); /* cv3d */
2403 static inline void gfx_on_off(int toggle
)
2407 DPRINTK("ENTER gfx %s\n", (toggle
? "off" : "on"));
2409 toggle
= (toggle
& 0x01) << 5;
2410 tmp
= rseq(SEQ_ID_CLOCKING_MODE
) & (~(0x01 << 5));
2411 wseq(SEQ_ID_CLOCKING_MODE
, tmp
| toggle
);
2416 #if defined (VIRGEFBDUMP)
2419 * Dump board registers
2422 static void cv64_dump(void)
2429 /* crt, seq, gfx and atr regs */
2434 for (i
= 0; i
<= 0x6f; i
++) {
2435 wb_mmio(CRT_ADDRESS
, i
);
2436 printk("crt idx : 0x%2.2x : 0x%2.2x\n", i
, rb_mmio(CRT_ADDRESS_R
));
2438 for (i
= 0; i
<= 0x1c; i
++) {
2439 wb_mmio(SEQ_ADDRESS
, i
);
2440 printk("seq idx : 0x%2.2x : 0x%2.2x\n", i
, rb_mmio(SEQ_ADDRESS_R
));
2442 for (i
= 0; i
<= 8; i
++) {
2443 wb_mmio(GCT_ADDRESS
, i
);
2444 printk("gfx idx : 0x%2.2x : 0x%2.2x\n", i
, rb_mmio(GCT_ADDRESS_R
));
2446 for (i
= 0; i
<= 0x14; i
++) {
2447 c
= rb_mmio(ACT_ADDRESS_RESET
);
2448 wb_mmio(ACT_ADDRESS_W
, i
);
2449 printk("atr idx : 0x%2.2x : 0x%2.2x\n", i
, rb_mmio(ACT_ADDRESS_R
));
2452 /* re-enable video access to palette */
2454 c
= rb_mmio(ACT_ADDRESS_RESET
);
2456 wb_mmio(ACT_ADDRESS_W
, 0x20);
2457 c
= rb_mmio(ACT_ADDRESS_RESET
);
2462 printk("0x3cc(w 0x3c2) : 0x%2.2x\n", rb_mmio(0x3cc)); /* GREG_MISC_OUTPUT READ */
2463 printk("0x3c2(-------) : 0x%2.2x\n", rb_mmio(0x3c2)); /* GREG_INPUT_STATUS 0 READ */
2464 printk("0x3c3(w 0x3c3) : 0x%2.2x\n", rb_vgaio(0x3c3)); /* GREG_VIDEO_SUBS_ENABLE */
2465 printk("0x3ca(w 0x3da) : 0x%2.2x\n", rb_vgaio(0x3ca)); /* GREG_FEATURE_CONTROL read */
2466 printk("0x3da(-------) : 0x%2.2x\n", rb_mmio(0x3da)); /* GREG_INPUT_STATUS 1 READ */
2470 for (i
= 0x8180; i
<= 0x8200; i
= i
+ 4)
2471 printk("0x%8.8x : 0x%8.8x\n", i
, rl_mmio(i
));
2474 printk("0x%8.8x : 0x%8.8x\n", i
, rl_mmio(i
));
2476 printk("0x%8.8x : 0x%8.8x\n", i
, rl_mmio(i
));
2477 for (i
= 0xa4d4; i
<= 0xa50c; i
= i
+ 4)
2478 printk("0x%8.8x : 0x%8.8x\n", i
, rl_mmio(i
));
2484 for (c
= 0; c
< 0x08; c
= c
+ 2) {
2485 w
= (*((u16
*)((u32
)(vgaio_regs
+ c
+ (on_zorro2
? 0 : 0x000e0000)) ^ 2)));
2486 printk("pci 0x%2.2x : 0x%4.4x\n", c
, w
);
2489 l
= (*((u32
*)((u32
)(vgaio_regs
+ c
+ (on_zorro2
? 0 : 0x000e0000)))));
2490 printk("pci 0x%2.2x : 0x%8.8x\n", c
, l
);
2492 b
= (*((u8
*)((u32
)(vgaio_regs
+ c
+ (on_zorro2
? 0 : 0x000e0000)) ^ 3)));
2493 printk("pci 0x%2.2x : 0x%2.2x\n", c
, b
);
2495 l
= (*((u32
*)((u32
)(vgaio_regs
+ c
+ (on_zorro2
? 0 : 0x000e0000)))));
2496 printk("pci 0x%2.2x : 0x%8.8x\n", c
, l
);
2498 l
= (*((u32
*)((u32
)(vgaio_regs
+ c
+ (on_zorro2
? 0 : 0x000e0000)))));
2499 printk("pci 0x%2.2x : 0x%8.8x\n", c
, l
);
2501 b
= (*((u8
*)((u32
)(vgaio_regs
+ c
+ (on_zorro2
? 0 : 0x000e0000)) ^ 3)));
2502 printk("pci 0x%2.2x : 0x%2.2x\n", c
, b
);
2504 b
= (*((u8
*)((u32
)(vgaio_regs
+ c
+ (on_zorro2
? 0 : 0x000e0000)) ^ 3)));
2505 printk("pci 0x%2.2x : 0x%2.2x\n", c
, b
);
2507 w
= (*((u16
*)((u32
)(vgaio_regs
+ c
+ (on_zorro2
? 0 : 0x000e0000)) ^ 2)));
2508 printk("pci 0x%2.2x : 0x%4.4x\n", c
, w
);