2 * drivers/video/cirrusfb.c - driver for Cirrus Logic chipsets
4 * Copyright 1999-2001 Jeff Garzik <jgarzik@pobox.com>
6 * Contributors (thanks, all!)
9 * Overhaul for Linux 2.6
12 * Major contributions; Motorola PowerStack (PPC and PCI) support,
13 * GD54xx, 1280x1024 mode support, change MCLK based on VCLK.
16 * Excellent code review.
19 * Amiga updates and testing.
21 * Original cirrusfb author: Frank Neumann
23 * Based on retz3fb.c and cirrusfb.c:
24 * Copyright (C) 1997 Jes Sorensen
25 * Copyright (C) 1996 Frank Neumann
27 ***************************************************************
29 * Format this code with GNU indent '-kr -i8 -pcs' options.
31 * This file is subject to the terms and conditions of the GNU General Public
32 * License. See the file COPYING in the main directory of this archive
37 #define CIRRUSFB_VERSION "2.0-pre2"
39 #include <linux/module.h>
40 #include <linux/kernel.h>
41 #include <linux/errno.h>
42 #include <linux/string.h>
44 #include <linux/slab.h>
45 #include <linux/delay.h>
47 #include <linux/init.h>
48 #include <asm/pgtable.h>
51 #include <linux/zorro.h>
54 #include <linux/pci.h>
57 #include <asm/amigahw.h>
59 #ifdef CONFIG_PPC_PREP
60 #include <asm/machdep.h>
61 #define isPReP machine_is(prep)
66 #include <video/vga.h>
67 #include <video/cirrus.h>
69 /*****************************************************************
71 * debugging and utility macros
75 /* enable debug output? */
76 /* #define CIRRUSFB_DEBUG 1 */
78 /* disable runtime assertions? */
79 /* #define CIRRUSFB_NDEBUG */
83 #define DPRINTK(fmt, args...) \
84 printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
86 #define DPRINTK(fmt, args...)
89 /* debugging assertions */
90 #ifndef CIRRUSFB_NDEBUG
91 #define assert(expr) \
93 printk("Assertion failed! %s,%s,%s,line=%d\n", \
94 #expr, __FILE__, __func__, __LINE__); \
100 #define MB_ (1024 * 1024)
102 /*****************************************************************
104 * chipset information
115 BT_PICASSO4
, /* GD5446 */
116 BT_ALPINE
, /* GD543x/4x */
118 BT_LAGUNA
, /* GD546x */
122 * per-board-type information, used for enumerating and abstracting
123 * chip-specific information
124 * NOTE: MUST be in the same order as enum cirrus_board in order to
125 * use direct indexing on this array
126 * NOTE: '__initdata' cannot be used as some of this info
127 * is required at runtime. Maybe separate into an init-only and
130 static const struct cirrusfb_board_info_rec
{
131 char *name
; /* ASCII name of chipset */
132 long maxclock
[5]; /* maximum video clock */
133 /* for 1/4bpp, 8bpp 15/16bpp, 24bpp, 32bpp - numbers from xorg code */
134 bool init_sr07
: 1; /* init SR07 during init_vgachip() */
135 bool init_sr1f
: 1; /* write SR1F during init_vgachip() */
136 /* construct bit 19 of screen start address */
137 bool scrn_start_bit19
: 1;
139 /* initial SR07 value, then for each mode */
141 unsigned char sr07_1bpp
;
142 unsigned char sr07_1bpp_mux
;
143 unsigned char sr07_8bpp
;
144 unsigned char sr07_8bpp_mux
;
146 unsigned char sr1f
; /* SR1F VGA initial register value */
147 } cirrusfb_board_info
[] = {
152 /* the SD64/P4 have a higher max. videoclock */
153 140000, 140000, 140000, 140000, 140000,
157 .scrn_start_bit19
= true,
164 .name
= "CL Piccolo",
167 90000, 90000, 90000, 90000, 90000
171 .scrn_start_bit19
= false,
178 .name
= "CL Picasso",
181 90000, 90000, 90000, 90000, 90000
185 .scrn_start_bit19
= false,
192 .name
= "CL Spectrum",
195 90000, 90000, 90000, 90000, 90000
199 .scrn_start_bit19
= false,
206 .name
= "CL Picasso4",
208 135100, 135100, 85500, 85500, 0
212 .scrn_start_bit19
= true,
221 /* for the GD5430. GD5446 can do more... */
222 85500, 85500, 50000, 28500, 0
226 .scrn_start_bit19
= true,
229 .sr07_1bpp_mux
= 0xA7,
231 .sr07_8bpp_mux
= 0xA7,
237 135100, 200000, 200000, 135100, 135100
241 .scrn_start_bit19
= true,
251 135100, 135100, 135100, 135100, 135100,
255 .scrn_start_bit19
= true,
260 #define CHIP(id, btype) \
261 { PCI_VENDOR_ID_CIRRUS, id, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (btype) }
263 static struct pci_device_id cirrusfb_pci_table
[] = {
264 CHIP(PCI_DEVICE_ID_CIRRUS_5436
, BT_ALPINE
),
265 CHIP(PCI_DEVICE_ID_CIRRUS_5434_8
, BT_ALPINE
),
266 CHIP(PCI_DEVICE_ID_CIRRUS_5434_4
, BT_ALPINE
),
267 CHIP(PCI_DEVICE_ID_CIRRUS_5430
, BT_ALPINE
), /* GD-5440 is same id */
268 CHIP(PCI_DEVICE_ID_CIRRUS_7543
, BT_ALPINE
),
269 CHIP(PCI_DEVICE_ID_CIRRUS_7548
, BT_ALPINE
),
270 CHIP(PCI_DEVICE_ID_CIRRUS_5480
, BT_GD5480
), /* MacPicasso likely */
271 CHIP(PCI_DEVICE_ID_CIRRUS_5446
, BT_PICASSO4
), /* Picasso 4 is 5446 */
272 CHIP(PCI_DEVICE_ID_CIRRUS_5462
, BT_LAGUNA
), /* CL Laguna */
273 CHIP(PCI_DEVICE_ID_CIRRUS_5464
, BT_LAGUNA
), /* CL Laguna 3D */
274 CHIP(PCI_DEVICE_ID_CIRRUS_5465
, BT_LAGUNA
), /* CL Laguna 3DA*/
277 MODULE_DEVICE_TABLE(pci
, cirrusfb_pci_table
);
279 #endif /* CONFIG_PCI */
282 static const struct zorro_device_id cirrusfb_zorro_table
[] = {
284 .id
= ZORRO_PROD_HELFRICH_SD64_RAM
,
285 .driver_data
= BT_SD64
,
287 .id
= ZORRO_PROD_HELFRICH_PICCOLO_RAM
,
288 .driver_data
= BT_PICCOLO
,
290 .id
= ZORRO_PROD_VILLAGE_TRONIC_PICASSO_II_II_PLUS_RAM
,
291 .driver_data
= BT_PICASSO
,
293 .id
= ZORRO_PROD_GVP_EGS_28_24_SPECTRUM_RAM
,
294 .driver_data
= BT_SPECTRUM
,
296 .id
= ZORRO_PROD_VILLAGE_TRONIC_PICASSO_IV_Z3
,
297 .driver_data
= BT_PICASSO4
,
302 static const struct {
305 } cirrusfb_zorro_table2
[] = {
307 .id2
= ZORRO_PROD_HELFRICH_SD64_REG
,
311 .id2
= ZORRO_PROD_HELFRICH_PICCOLO_REG
,
315 .id2
= ZORRO_PROD_VILLAGE_TRONIC_PICASSO_II_II_PLUS_REG
,
319 .id2
= ZORRO_PROD_GVP_EGS_28_24_SPECTRUM_REG
,
327 #endif /* CONFIG_ZORRO */
329 struct cirrusfb_regs
{
338 long HorizRes
; /* The x resolution in pixel */
341 long HorizBlankStart
;
346 long VertRes
; /* the physical y resolution in scanlines */
355 #ifdef CIRRUSFB_DEBUG
356 enum cirrusfb_dbg_reg_class
{
360 #endif /* CIRRUSFB_DEBUG */
362 /* info about board */
363 struct cirrusfb_info
{
365 enum cirrus_board btype
;
366 unsigned char SFR
; /* Shadow of special function register */
368 struct cirrusfb_regs currentmode
;
371 u32 pseudo_palette
[16];
374 struct zorro_dev
*zdev
;
377 struct pci_dev
*pdev
;
379 void (*unmap
)(struct fb_info
*info
);
382 static unsigned cirrusfb_def_mode
= 1;
386 * Predefined Video Modes
389 static const struct {
391 struct fb_var_screeninfo var
;
392 } cirrusfb_predefined
[] = {
394 /* autodetect mode */
395 .name
= "Autodetect",
397 /* 640x480, 31.25 kHz, 60 Hz, 25 MHz PixClock */
405 .red
= { .length
= 8 },
406 .green
= { .length
= 8 },
407 .blue
= { .length
= 8 },
417 .sync
= FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
418 .vmode
= FB_VMODE_NONINTERLACED
421 /* 800x600, 48 kHz, 76 Hz, 50 MHz PixClock */
429 .red
= { .length
= 8 },
430 .green
= { .length
= 8 },
431 .blue
= { .length
= 8 },
441 .vmode
= FB_VMODE_NONINTERLACED
445 * Modeline from XF86Config:
446 * Mode "1024x768" 80 1024 1136 1340 1432 768 770 774 805
448 /* 1024x768, 55.8 kHz, 70 Hz, 80 MHz PixClock */
453 .xres_virtual
= 1024,
456 .red
= { .length
= 8 },
457 .green
= { .length
= 8 },
458 .blue
= { .length
= 8 },
468 .vmode
= FB_VMODE_NONINTERLACED
473 #define NUM_TOTAL_MODES ARRAY_SIZE(cirrusfb_predefined)
475 /****************************************************************************/
476 /**** BEGIN PROTOTYPES ******************************************************/
478 /*--- Interface used by the world ------------------------------------------*/
479 static int cirrusfb_init(void);
481 static int cirrusfb_setup(char *options
);
484 static int cirrusfb_open(struct fb_info
*info
, int user
);
485 static int cirrusfb_release(struct fb_info
*info
, int user
);
486 static int cirrusfb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
487 unsigned blue
, unsigned transp
,
488 struct fb_info
*info
);
489 static int cirrusfb_check_var(struct fb_var_screeninfo
*var
,
490 struct fb_info
*info
);
491 static int cirrusfb_set_par(struct fb_info
*info
);
492 static int cirrusfb_pan_display(struct fb_var_screeninfo
*var
,
493 struct fb_info
*info
);
494 static int cirrusfb_blank(int blank_mode
, struct fb_info
*info
);
495 static void cirrusfb_fillrect(struct fb_info
*info
,
496 const struct fb_fillrect
*region
);
497 static void cirrusfb_copyarea(struct fb_info
*info
,
498 const struct fb_copyarea
*area
);
499 static void cirrusfb_imageblit(struct fb_info
*info
,
500 const struct fb_image
*image
);
502 /* function table of the above functions */
503 static struct fb_ops cirrusfb_ops
= {
504 .owner
= THIS_MODULE
,
505 .fb_open
= cirrusfb_open
,
506 .fb_release
= cirrusfb_release
,
507 .fb_setcolreg
= cirrusfb_setcolreg
,
508 .fb_check_var
= cirrusfb_check_var
,
509 .fb_set_par
= cirrusfb_set_par
,
510 .fb_pan_display
= cirrusfb_pan_display
,
511 .fb_blank
= cirrusfb_blank
,
512 .fb_fillrect
= cirrusfb_fillrect
,
513 .fb_copyarea
= cirrusfb_copyarea
,
514 .fb_imageblit
= cirrusfb_imageblit
,
517 /*--- Hardware Specific Routines -------------------------------------------*/
518 static int cirrusfb_decode_var(const struct fb_var_screeninfo
*var
,
519 struct cirrusfb_regs
*regs
,
520 struct fb_info
*info
);
521 /*--- Internal routines ----------------------------------------------------*/
522 static void init_vgachip(struct fb_info
*info
);
523 static void switch_monitor(struct cirrusfb_info
*cinfo
, int on
);
524 static void WGen(const struct cirrusfb_info
*cinfo
,
525 int regnum
, unsigned char val
);
526 static unsigned char RGen(const struct cirrusfb_info
*cinfo
, int regnum
);
527 static void AttrOn(const struct cirrusfb_info
*cinfo
);
528 static void WHDR(const struct cirrusfb_info
*cinfo
, unsigned char val
);
529 static void WSFR(struct cirrusfb_info
*cinfo
, unsigned char val
);
530 static void WSFR2(struct cirrusfb_info
*cinfo
, unsigned char val
);
531 static void WClut(struct cirrusfb_info
*cinfo
, unsigned char regnum
,
532 unsigned char red
, unsigned char green
, unsigned char blue
);
534 static void RClut(struct cirrusfb_info
*cinfo
, unsigned char regnum
,
535 unsigned char *red
, unsigned char *green
,
536 unsigned char *blue
);
538 static void cirrusfb_WaitBLT(u8 __iomem
*regbase
);
539 static void cirrusfb_BitBLT(u8 __iomem
*regbase
, int bits_per_pixel
,
540 u_short curx
, u_short cury
,
541 u_short destx
, u_short desty
,
542 u_short width
, u_short height
,
543 u_short line_length
);
544 static void cirrusfb_RectFill(u8 __iomem
*regbase
, int bits_per_pixel
,
545 u_short x
, u_short y
,
546 u_short width
, u_short height
,
547 u_char color
, u_short line_length
);
549 static void bestclock(long freq
, long *best
,
550 long *nom
, long *den
,
551 long *div
, long maxfreq
);
553 #ifdef CIRRUSFB_DEBUG
554 static void cirrusfb_dump(void);
555 static void cirrusfb_dbg_reg_dump(caddr_t regbase
);
556 static void cirrusfb_dbg_print_regs(caddr_t regbase
,
557 enum cirrusfb_dbg_reg_class reg_class
, ...);
558 static void cirrusfb_dbg_print_byte(const char *name
, unsigned char val
);
559 #endif /* CIRRUSFB_DEBUG */
561 /*** END PROTOTYPES ********************************************************/
562 /*****************************************************************************/
563 /*** BEGIN Interface Used by the World ***************************************/
565 static int opencount
;
567 /*--- Open /dev/fbx ---------------------------------------------------------*/
568 static int cirrusfb_open(struct fb_info
*info
, int user
)
570 if (opencount
++ == 0)
571 switch_monitor(info
->par
, 1);
575 /*--- Close /dev/fbx --------------------------------------------------------*/
576 static int cirrusfb_release(struct fb_info
*info
, int user
)
578 if (--opencount
== 0)
579 switch_monitor(info
->par
, 0);
583 /**** END Interface used by the World *************************************/
584 /****************************************************************************/
585 /**** BEGIN Hardware specific Routines **************************************/
587 /* Get a good MCLK value */
588 static long cirrusfb_get_mclk(long freq
, int bpp
, long *div
)
594 /* Calculate MCLK, in case VCLK is high enough to require > 50MHz.
595 * Assume a 64-bit data path for now. The formula is:
596 * ((B * PCLK * 2)/W) * 1.2
597 * B = bytes per pixel, PCLK = pixclock, W = data width in bytes */
598 mclk
= ((bpp
/ 8) * freq
* 2) / 4;
599 mclk
= (mclk
* 12) / 10;
602 DPRINTK("Use MCLK of %ld kHz\n", mclk
);
604 /* Calculate value for SR1F. Multiply by 2 so we can round up. */
605 mclk
= ((mclk
* 16) / 14318);
606 mclk
= (mclk
+ 1) / 2;
607 DPRINTK("Set SR1F[5:0] to 0x%lx\n", mclk
);
609 /* Determine if we should use MCLK instead of VCLK, and if so, what we
610 * should divide it by to get VCLK */
612 case 24751 ... 25249:
614 DPRINTK("Using VCLK = MCLK/2\n");
616 case 49501 ... 50499:
618 DPRINTK("Using VCLK = MCLK\n");
628 static int cirrusfb_check_var(struct fb_var_screeninfo
*var
,
629 struct fb_info
*info
)
631 int nom
, den
; /* translyting from pixels->bytes */
633 static struct { int xres
, yres
; } modes
[] =
641 switch (var
->bits_per_pixel
) {
645 break; /* 8 pixel per byte, only 1/4th of mem usable */
650 nom
= var
->bits_per_pixel
/ 8;
652 break; /* 1 pixel == 1 byte */
654 printk(KERN_ERR
"cirrusfb: mode %dx%dx%d rejected..."
655 "color depth not supported.\n",
656 var
->xres
, var
->yres
, var
->bits_per_pixel
);
657 DPRINTK("EXIT - EINVAL error\n");
661 if (var
->xres
* nom
/ den
* var
->yres
> info
->screen_size
) {
662 printk(KERN_ERR
"cirrusfb: mode %dx%dx%d rejected..."
663 "resolution too high to fit into video memory!\n",
664 var
->xres
, var
->yres
, var
->bits_per_pixel
);
665 DPRINTK("EXIT - EINVAL error\n");
669 /* use highest possible virtual resolution */
670 if (var
->xres_virtual
== -1 &&
671 var
->yres_virtual
== -1) {
673 "cirrusfb: using maximum available virtual resolution\n");
674 for (i
= 0; modes
[i
].xres
!= -1; i
++) {
675 int size
= modes
[i
].xres
* nom
/ den
* modes
[i
].yres
;
676 if (size
< info
->screen_size
/ 2)
679 if (modes
[i
].xres
== -1) {
680 printk(KERN_ERR
"cirrusfb: could not find a virtual "
681 "resolution that fits into video memory!!\n");
682 DPRINTK("EXIT - EINVAL error\n");
685 var
->xres_virtual
= modes
[i
].xres
;
686 var
->yres_virtual
= modes
[i
].yres
;
688 printk(KERN_INFO
"cirrusfb: virtual resolution set to "
689 "maximum of %dx%d\n", var
->xres_virtual
,
693 if (var
->xres_virtual
< var
->xres
)
694 var
->xres_virtual
= var
->xres
;
695 if (var
->yres_virtual
< var
->yres
)
696 var
->yres_virtual
= var
->yres
;
698 if (var
->xoffset
< 0)
700 if (var
->yoffset
< 0)
703 /* truncate xoffset and yoffset to maximum if too high */
704 if (var
->xoffset
> var
->xres_virtual
- var
->xres
)
705 var
->xoffset
= var
->xres_virtual
- var
->xres
- 1;
706 if (var
->yoffset
> var
->yres_virtual
- var
->yres
)
707 var
->yoffset
= var
->yres_virtual
- var
->yres
- 1;
709 switch (var
->bits_per_pixel
) {
713 var
->green
= var
->red
;
714 var
->blue
= var
->red
;
720 var
->green
= var
->red
;
721 var
->blue
= var
->red
;
727 var
->green
.offset
= -3;
728 var
->blue
.offset
= 8;
730 var
->red
.offset
= 10;
731 var
->green
.offset
= 5;
732 var
->blue
.offset
= 0;
735 var
->green
.length
= 5;
736 var
->blue
.length
= 5;
743 var
->green
.offset
= 16;
744 var
->blue
.offset
= 24;
746 var
->red
.offset
= 16;
747 var
->green
.offset
= 8;
748 var
->blue
.offset
= 0;
751 var
->green
.length
= 8;
752 var
->blue
.length
= 8;
756 DPRINTK("Unsupported bpp size: %d\n", var
->bits_per_pixel
);
758 /* should never occur */
763 var
->green
.msb_right
=
764 var
->blue
.msb_right
=
767 var
->transp
.msb_right
= 0;
770 if (var
->vmode
& FB_VMODE_DOUBLE
)
772 else if (var
->vmode
& FB_VMODE_INTERLACED
)
773 yres
= (yres
+ 1) / 2;
776 printk(KERN_ERR
"cirrusfb: ERROR: VerticalTotal >= 1280; "
777 "special treatment required! (TODO)\n");
778 DPRINTK("EXIT - EINVAL error\n");
785 static int cirrusfb_decode_var(const struct fb_var_screeninfo
*var
,
786 struct cirrusfb_regs
*regs
,
787 struct fb_info
*info
)
791 int maxclockidx
= var
->bits_per_pixel
>> 3;
792 struct cirrusfb_info
*cinfo
= info
->par
;
793 int xres
, hfront
, hsync
, hback
;
794 int yres
, vfront
, vsync
, vback
;
796 switch (var
->bits_per_pixel
) {
798 info
->fix
.line_length
= var
->xres_virtual
/ 8;
799 info
->fix
.visual
= FB_VISUAL_MONO10
;
803 info
->fix
.line_length
= var
->xres_virtual
;
804 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
810 info
->fix
.line_length
= var
->xres_virtual
* maxclockidx
;
811 info
->fix
.visual
= FB_VISUAL_DIRECTCOLOR
;
815 DPRINTK("Unsupported bpp size: %d\n", var
->bits_per_pixel
);
817 /* should never occur */
821 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
823 /* convert from ps to kHz */
824 freq
= PICOS2KHZ(var
->pixclock
);
826 DPRINTK("desired pixclock: %ld kHz\n", freq
);
828 maxclock
= cirrusfb_board_info
[cinfo
->btype
].maxclock
[maxclockidx
];
829 regs
->multiplexing
= 0;
831 /* If the frequency is greater than we can support, we might be able
832 * to use multiplexing for the video mode */
833 if (freq
> maxclock
) {
834 switch (cinfo
->btype
) {
837 regs
->multiplexing
= 1;
841 printk(KERN_ERR
"cirrusfb: Frequency greater "
842 "than maxclock (%ld kHz)\n", maxclock
);
843 DPRINTK("EXIT - return -EINVAL\n");
848 /* TODO: If we have a 1MB 5434, we need to put ourselves in a mode where
849 * the VCLK is double the pixel clock. */
850 switch (var
->bits_per_pixel
) {
853 if (regs
->HorizRes
<= 800)
854 /* Xbh has this type of clock for 32-bit */
860 bestclock(freq
, ®s
->freq
, ®s
->nom
, ®s
->den
, ®s
->div
,
862 regs
->mclk
= cirrusfb_get_mclk(freq
, var
->bits_per_pixel
,
866 hfront
= var
->right_margin
;
867 hsync
= var
->hsync_len
;
868 hback
= var
->left_margin
;
871 vfront
= var
->lower_margin
;
872 vsync
= var
->vsync_len
;
873 vback
= var
->upper_margin
;
875 if (var
->vmode
& FB_VMODE_DOUBLE
) {
880 } else if (var
->vmode
& FB_VMODE_INTERLACED
) {
881 yres
= (yres
+ 1) / 2;
882 vfront
= (vfront
+ 1) / 2;
883 vsync
= (vsync
+ 1) / 2;
884 vback
= (vback
+ 1) / 2;
886 regs
->HorizRes
= xres
;
887 regs
->HorizTotal
= (xres
+ hfront
+ hsync
+ hback
) / 8 - 5;
888 regs
->HorizDispEnd
= xres
/ 8 - 1;
889 regs
->HorizBlankStart
= xres
/ 8;
890 /* does not count with "-5" */
891 regs
->HorizBlankEnd
= regs
->HorizTotal
+ 5;
892 regs
->HorizSyncStart
= (xres
+ hfront
) / 8 + 1;
893 regs
->HorizSyncEnd
= (xres
+ hfront
+ hsync
) / 8 + 1;
895 regs
->VertRes
= yres
;
896 regs
->VertTotal
= yres
+ vfront
+ vsync
+ vback
- 2;
897 regs
->VertDispEnd
= yres
- 1;
898 regs
->VertBlankStart
= yres
;
899 regs
->VertBlankEnd
= regs
->VertTotal
;
900 regs
->VertSyncStart
= yres
+ vfront
- 1;
901 regs
->VertSyncEnd
= yres
+ vfront
+ vsync
- 1;
903 if (regs
->VertRes
>= 1024) {
904 regs
->VertTotal
/= 2;
905 regs
->VertSyncStart
/= 2;
906 regs
->VertSyncEnd
/= 2;
907 regs
->VertDispEnd
/= 2;
909 if (regs
->multiplexing
) {
910 regs
->HorizTotal
/= 2;
911 regs
->HorizSyncStart
/= 2;
912 regs
->HorizSyncEnd
/= 2;
913 regs
->HorizDispEnd
/= 2;
919 static void cirrusfb_set_mclk(const struct cirrusfb_info
*cinfo
, int val
,
922 assert(cinfo
!= NULL
);
926 unsigned char old
= vga_rseq(cinfo
->regbase
, CL_SEQR1E
);
927 vga_wseq(cinfo
->regbase
, CL_SEQR1E
, old
| 0x1);
928 vga_wseq(cinfo
->regbase
, CL_SEQR1F
, 0x40 | (val
& 0x3f));
929 } else if (div
== 1) {
931 unsigned char old
= vga_rseq(cinfo
->regbase
, CL_SEQR1E
);
932 vga_wseq(cinfo
->regbase
, CL_SEQR1E
, old
& ~0x1);
933 vga_wseq(cinfo
->regbase
, CL_SEQR1F
, 0x40 | (val
& 0x3f));
935 vga_wseq(cinfo
->regbase
, CL_SEQR1F
, val
& 0x3f);
939 /*************************************************************************
940 cirrusfb_set_par_foo()
942 actually writes the values for a new video mode into the hardware,
943 **************************************************************************/
944 static int cirrusfb_set_par_foo(struct fb_info
*info
)
946 struct cirrusfb_info
*cinfo
= info
->par
;
947 struct fb_var_screeninfo
*var
= &info
->var
;
948 struct cirrusfb_regs regs
;
949 u8 __iomem
*regbase
= cinfo
->regbase
;
952 const struct cirrusfb_board_info_rec
*bi
;
955 DPRINTK("Requested mode: %dx%dx%d\n",
956 var
->xres
, var
->yres
, var
->bits_per_pixel
);
957 DPRINTK("pixclock: %d\n", var
->pixclock
);
961 err
= cirrusfb_decode_var(var
, ®s
, info
);
963 /* should never happen */
964 DPRINTK("mode change aborted. invalid var.\n");
968 bi
= &cirrusfb_board_info
[cinfo
->btype
];
970 /* unlock register VGA_CRTC_H_TOTAL..CRT7 */
971 vga_wcrt(regbase
, VGA_CRTC_V_SYNC_END
, 0x20); /* previously: 0x00) */
973 /* if debugging is enabled, all parameters get output before writing */
974 DPRINTK("CRT0: %ld\n", regs
.HorizTotal
);
975 vga_wcrt(regbase
, VGA_CRTC_H_TOTAL
, regs
.HorizTotal
);
977 DPRINTK("CRT1: %ld\n", regs
.HorizDispEnd
);
978 vga_wcrt(regbase
, VGA_CRTC_H_DISP
, regs
.HorizDispEnd
);
980 DPRINTK("CRT2: %ld\n", regs
.HorizBlankStart
);
981 vga_wcrt(regbase
, VGA_CRTC_H_BLANK_START
, regs
.HorizBlankStart
);
983 /* + 128: Compatible read */
984 DPRINTK("CRT3: 128+%ld\n", regs
.HorizBlankEnd
% 32);
985 vga_wcrt(regbase
, VGA_CRTC_H_BLANK_END
,
986 128 + (regs
.HorizBlankEnd
% 32));
988 DPRINTK("CRT4: %ld\n", regs
.HorizSyncStart
);
989 vga_wcrt(regbase
, VGA_CRTC_H_SYNC_START
, regs
.HorizSyncStart
);
991 tmp
= regs
.HorizSyncEnd
% 32;
992 if (regs
.HorizBlankEnd
& 32)
994 DPRINTK("CRT5: %d\n", tmp
);
995 vga_wcrt(regbase
, VGA_CRTC_H_SYNC_END
, tmp
);
997 DPRINTK("CRT6: %ld\n", regs
.VertTotal
& 0xff);
998 vga_wcrt(regbase
, VGA_CRTC_V_TOTAL
, (regs
.VertTotal
& 0xff));
1000 tmp
= 16; /* LineCompare bit #9 */
1001 if (regs
.VertTotal
& 256)
1003 if (regs
.VertDispEnd
& 256)
1005 if (regs
.VertSyncStart
& 256)
1007 if (regs
.VertBlankStart
& 256)
1009 if (regs
.VertTotal
& 512)
1011 if (regs
.VertDispEnd
& 512)
1013 if (regs
.VertSyncStart
& 512)
1015 DPRINTK("CRT7: %d\n", tmp
);
1016 vga_wcrt(regbase
, VGA_CRTC_OVERFLOW
, tmp
);
1018 tmp
= 0x40; /* LineCompare bit #8 */
1019 if (regs
.VertBlankStart
& 512)
1021 if (var
->vmode
& FB_VMODE_DOUBLE
)
1023 DPRINTK("CRT9: %d\n", tmp
);
1024 vga_wcrt(regbase
, VGA_CRTC_MAX_SCAN
, tmp
);
1026 DPRINTK("CRT10: %ld\n", regs
.VertSyncStart
& 0xff);
1027 vga_wcrt(regbase
, VGA_CRTC_V_SYNC_START
, regs
.VertSyncStart
& 0xff);
1029 DPRINTK("CRT11: 64+32+%ld\n", regs
.VertSyncEnd
% 16);
1030 vga_wcrt(regbase
, VGA_CRTC_V_SYNC_END
, regs
.VertSyncEnd
% 16 + 64 + 32);
1032 DPRINTK("CRT12: %ld\n", regs
.VertDispEnd
& 0xff);
1033 vga_wcrt(regbase
, VGA_CRTC_V_DISP_END
, regs
.VertDispEnd
& 0xff);
1035 DPRINTK("CRT15: %ld\n", regs
.VertBlankStart
& 0xff);
1036 vga_wcrt(regbase
, VGA_CRTC_V_BLANK_START
, regs
.VertBlankStart
& 0xff);
1038 DPRINTK("CRT16: %ld\n", regs
.VertBlankEnd
& 0xff);
1039 vga_wcrt(regbase
, VGA_CRTC_V_BLANK_END
, regs
.VertBlankEnd
& 0xff);
1041 DPRINTK("CRT18: 0xff\n");
1042 vga_wcrt(regbase
, VGA_CRTC_LINE_COMPARE
, 0xff);
1045 if (var
->vmode
& FB_VMODE_INTERLACED
)
1047 if (regs
.HorizBlankEnd
& 64)
1049 if (regs
.HorizBlankEnd
& 128)
1051 if (regs
.VertBlankEnd
& 256)
1053 if (regs
.VertBlankEnd
& 512)
1056 DPRINTK("CRT1a: %d\n", tmp
);
1057 vga_wcrt(regbase
, CL_CRT1A
, tmp
);
1060 /* hardware RefClock: 14.31818 MHz */
1061 /* formula: VClk = (OSC * N) / (D * (1+P)) */
1062 /* Example: VClk = (14.31818 * 91) / (23 * (1+1)) = 28.325 MHz */
1064 vga_wseq(regbase
, CL_SEQRB
, regs
.nom
);
1065 tmp
= regs
.den
<< 1;
1069 /* 6 bit denom; ONLY 5434!!! (bugged me 10 days) */
1070 if ((cinfo
->btype
== BT_SD64
) ||
1071 (cinfo
->btype
== BT_ALPINE
) ||
1072 (cinfo
->btype
== BT_GD5480
))
1075 DPRINTK("CL_SEQR1B: %ld\n", (long) tmp
);
1076 vga_wseq(regbase
, CL_SEQR1B
, tmp
);
1078 if (regs
.VertRes
>= 1024)
1080 vga_wcrt(regbase
, VGA_CRTC_MODE
, 0xc7);
1082 /* mode control: VGA_CRTC_START_HI enable, ROTATE(?), 16bit
1083 * address wrap, no compat. */
1084 vga_wcrt(regbase
, VGA_CRTC_MODE
, 0xc3);
1086 /* HAEH? vga_wcrt(regbase, VGA_CRTC_V_SYNC_END, 0x20);
1087 * previously: 0x00 unlock VGA_CRTC_H_TOTAL..CRT7 */
1089 /* don't know if it would hurt to also program this if no interlaced */
1090 /* mode is used, but I feel better this way.. :-) */
1091 if (var
->vmode
& FB_VMODE_INTERLACED
)
1092 vga_wcrt(regbase
, VGA_CRTC_REGS
, regs
.HorizTotal
/ 2);
1094 vga_wcrt(regbase
, VGA_CRTC_REGS
, 0x00); /* interlace control */
1096 vga_wseq(regbase
, VGA_SEQ_CHARACTER_MAP
, 0);
1098 /* adjust horizontal/vertical sync type (low/high) */
1099 /* enable display memory & CRTC I/O address for color mode */
1101 if (var
->sync
& FB_SYNC_HOR_HIGH_ACT
)
1103 if (var
->sync
& FB_SYNC_VERT_HIGH_ACT
)
1105 WGen(cinfo
, VGA_MIS_W
, tmp
);
1107 /* Screen A Preset Row-Scan register */
1108 vga_wcrt(regbase
, VGA_CRTC_PRESET_ROW
, 0);
1109 /* text cursor on and start line */
1110 vga_wcrt(regbase
, VGA_CRTC_CURSOR_START
, 0);
1111 /* text cursor end line */
1112 vga_wcrt(regbase
, VGA_CRTC_CURSOR_END
, 31);
1114 /******************************************************
1120 /* programming for different color depths */
1121 if (var
->bits_per_pixel
== 1) {
1122 DPRINTK("cirrusfb: preparing for 1 bit deep display\n");
1123 vga_wgfx(regbase
, VGA_GFX_MODE
, 0); /* mode register */
1126 switch (cinfo
->btype
) {
1134 DPRINTK(" (for GD54xx)\n");
1135 vga_wseq(regbase
, CL_SEQR7
,
1137 bi
->sr07_1bpp_mux
: bi
->sr07_1bpp
);
1141 DPRINTK(" (for GD546x)\n");
1142 vga_wseq(regbase
, CL_SEQR7
,
1143 vga_rseq(regbase
, CL_SEQR7
) & ~0x01);
1147 printk(KERN_WARNING
"cirrusfb: unknown Board\n");
1151 /* Extended Sequencer Mode */
1152 switch (cinfo
->btype
) {
1154 /* setting the SEQRF on SD64 is not necessary
1155 * (only during init)
1157 DPRINTK("(for SD64)\n");
1159 vga_wseq(regbase
, CL_SEQR1F
, 0x1a);
1164 DPRINTK("(for Piccolo/Spectrum)\n");
1165 /* ### ueberall 0x22? */
1166 /* ##vorher 1c MCLK select */
1167 vga_wseq(regbase
, CL_SEQR1F
, 0x22);
1168 /* evtl d0 bei 1 bit? avoid FIFO underruns..? */
1169 vga_wseq(regbase
, CL_SEQRF
, 0xb0);
1173 DPRINTK("(for Picasso)\n");
1174 /* ##vorher 22 MCLK select */
1175 vga_wseq(regbase
, CL_SEQR1F
, 0x22);
1176 /* ## vorher d0 avoid FIFO underruns..? */
1177 vga_wseq(regbase
, CL_SEQRF
, 0xd0);
1184 DPRINTK(" (for GD54xx)\n");
1189 printk(KERN_WARNING
"cirrusfb: unknown Board\n");
1193 /* pixel mask: pass-through for first plane */
1194 WGen(cinfo
, VGA_PEL_MSK
, 0x01);
1195 if (regs
.multiplexing
)
1196 /* hidden dac reg: 1280x1024 */
1199 /* hidden dac: nothing */
1201 /* memory mode: odd/even, ext. memory */
1202 vga_wseq(regbase
, VGA_SEQ_MEMORY_MODE
, 0x06);
1203 /* plane mask: only write to first plane */
1204 vga_wseq(regbase
, VGA_SEQ_PLANE_WRITE
, 0x01);
1205 offset
= var
->xres_virtual
/ 16;
1208 /******************************************************
1214 else if (var
->bits_per_pixel
== 8) {
1215 DPRINTK("cirrusfb: preparing for 8 bit deep display\n");
1216 switch (cinfo
->btype
) {
1224 DPRINTK(" (for GD54xx)\n");
1225 vga_wseq(regbase
, CL_SEQR7
,
1227 bi
->sr07_8bpp_mux
: bi
->sr07_8bpp
);
1231 DPRINTK(" (for GD546x)\n");
1232 vga_wseq(regbase
, CL_SEQR7
,
1233 vga_rseq(regbase
, CL_SEQR7
) | 0x01);
1237 printk(KERN_WARNING
"cirrusfb: unknown Board\n");
1241 switch (cinfo
->btype
) {
1244 vga_wseq(regbase
, CL_SEQR1F
, 0x1d);
1250 /* ### vorher 1c MCLK select */
1251 vga_wseq(regbase
, CL_SEQR1F
, 0x22);
1252 /* Fast Page-Mode writes */
1253 vga_wseq(regbase
, CL_SEQRF
, 0xb0);
1258 /* ### INCOMPLETE!! */
1259 vga_wseq(regbase
, CL_SEQRF
, 0xb8);
1261 /* vga_wseq(regbase, CL_SEQR1F, 0x1c); */
1265 DPRINTK(" (for GD543x)\n");
1266 cirrusfb_set_mclk(cinfo
, regs
.mclk
, regs
.divMCLK
);
1267 /* We already set SRF and SR1F */
1272 DPRINTK(" (for GD54xx)\n");
1277 printk(KERN_WARNING
"cirrusfb: unknown Board\n");
1281 /* mode register: 256 color mode */
1282 vga_wgfx(regbase
, VGA_GFX_MODE
, 64);
1283 /* pixel mask: pass-through all planes */
1284 WGen(cinfo
, VGA_PEL_MSK
, 0xff);
1285 if (regs
.multiplexing
)
1286 /* hidden dac reg: 1280x1024 */
1289 /* hidden dac: nothing */
1291 /* memory mode: chain4, ext. memory */
1292 vga_wseq(regbase
, VGA_SEQ_MEMORY_MODE
, 0x0a);
1293 /* plane mask: enable writing to all 4 planes */
1294 vga_wseq(regbase
, VGA_SEQ_PLANE_WRITE
, 0xff);
1295 offset
= var
->xres_virtual
/ 8;
1298 /******************************************************
1304 else if (var
->bits_per_pixel
== 16) {
1305 DPRINTK("cirrusfb: preparing for 16 bit deep display\n");
1306 switch (cinfo
->btype
) {
1308 /* Extended Sequencer Mode: 256c col. mode */
1309 vga_wseq(regbase
, CL_SEQR7
, 0xf7);
1311 vga_wseq(regbase
, CL_SEQR1F
, 0x1e);
1316 vga_wseq(regbase
, CL_SEQR7
, 0x87);
1317 /* Fast Page-Mode writes */
1318 vga_wseq(regbase
, CL_SEQRF
, 0xb0);
1320 vga_wseq(regbase
, CL_SEQR1F
, 0x22);
1324 vga_wseq(regbase
, CL_SEQR7
, 0x27);
1325 /* Fast Page-Mode writes */
1326 vga_wseq(regbase
, CL_SEQRF
, 0xb0);
1328 vga_wseq(regbase
, CL_SEQR1F
, 0x22);
1332 vga_wseq(regbase
, CL_SEQR7
, 0x27);
1333 /* vga_wseq(regbase, CL_SEQR1F, 0x1c); */
1337 DPRINTK(" (for GD543x)\n");
1338 if (regs
.HorizRes
>= 1024)
1339 vga_wseq(regbase
, CL_SEQR7
, 0xa7);
1341 vga_wseq(regbase
, CL_SEQR7
, 0xa3);
1342 cirrusfb_set_mclk(cinfo
, regs
.mclk
, regs
.divMCLK
);
1346 DPRINTK(" (for GD5480)\n");
1347 vga_wseq(regbase
, CL_SEQR7
, 0x17);
1348 /* We already set SRF and SR1F */
1352 DPRINTK(" (for GD546x)\n");
1353 vga_wseq(regbase
, CL_SEQR7
,
1354 vga_rseq(regbase
, CL_SEQR7
) & ~0x01);
1358 printk(KERN_WARNING
"CIRRUSFB: unknown Board\n");
1362 /* mode register: 256 color mode */
1363 vga_wgfx(regbase
, VGA_GFX_MODE
, 64);
1364 /* pixel mask: pass-through all planes */
1365 WGen(cinfo
, VGA_PEL_MSK
, 0xff);
1367 WHDR(cinfo
, 0xc0); /* Copy Xbh */
1368 #elif defined(CONFIG_ZORRO)
1369 /* FIXME: CONFIG_PCI and CONFIG_ZORRO may be defined both */
1370 WHDR(cinfo
, 0xa0); /* hidden dac reg: nothing special */
1372 /* memory mode: chain4, ext. memory */
1373 vga_wseq(regbase
, VGA_SEQ_MEMORY_MODE
, 0x0a);
1374 /* plane mask: enable writing to all 4 planes */
1375 vga_wseq(regbase
, VGA_SEQ_PLANE_WRITE
, 0xff);
1376 offset
= var
->xres_virtual
/ 4;
1379 /******************************************************
1385 else if (var
->bits_per_pixel
== 32) {
1386 DPRINTK("cirrusfb: preparing for 24/32 bit deep display\n");
1387 switch (cinfo
->btype
) {
1389 /* Extended Sequencer Mode: 256c col. mode */
1390 vga_wseq(regbase
, CL_SEQR7
, 0xf9);
1392 vga_wseq(regbase
, CL_SEQR1F
, 0x1e);
1397 vga_wseq(regbase
, CL_SEQR7
, 0x85);
1398 /* Fast Page-Mode writes */
1399 vga_wseq(regbase
, CL_SEQRF
, 0xb0);
1401 vga_wseq(regbase
, CL_SEQR1F
, 0x22);
1405 vga_wseq(regbase
, CL_SEQR7
, 0x25);
1406 /* Fast Page-Mode writes */
1407 vga_wseq(regbase
, CL_SEQRF
, 0xb0);
1409 vga_wseq(regbase
, CL_SEQR1F
, 0x22);
1413 vga_wseq(regbase
, CL_SEQR7
, 0x25);
1414 /* vga_wseq(regbase, CL_SEQR1F, 0x1c); */
1418 DPRINTK(" (for GD543x)\n");
1419 vga_wseq(regbase
, CL_SEQR7
, 0xa9);
1420 cirrusfb_set_mclk(cinfo
, regs
.mclk
, regs
.divMCLK
);
1424 DPRINTK(" (for GD5480)\n");
1425 vga_wseq(regbase
, CL_SEQR7
, 0x19);
1426 /* We already set SRF and SR1F */
1430 DPRINTK(" (for GD546x)\n");
1431 vga_wseq(regbase
, CL_SEQR7
,
1432 vga_rseq(regbase
, CL_SEQR7
) & ~0x01);
1436 printk(KERN_WARNING
"cirrusfb: unknown Board\n");
1440 /* mode register: 256 color mode */
1441 vga_wgfx(regbase
, VGA_GFX_MODE
, 64);
1442 /* pixel mask: pass-through all planes */
1443 WGen(cinfo
, VGA_PEL_MSK
, 0xff);
1444 /* hidden dac reg: 8-8-8 mode (24 or 32) */
1446 /* memory mode: chain4, ext. memory */
1447 vga_wseq(regbase
, VGA_SEQ_MEMORY_MODE
, 0x0a);
1448 /* plane mask: enable writing to all 4 planes */
1449 vga_wseq(regbase
, VGA_SEQ_PLANE_WRITE
, 0xff);
1450 offset
= var
->xres_virtual
/ 4;
1453 /******************************************************
1455 * unknown/unsupported bpp
1460 printk(KERN_ERR
"cirrusfb: What's this?? "
1461 " requested color depth == %d.\n",
1462 var
->bits_per_pixel
);
1464 vga_wcrt(regbase
, VGA_CRTC_OFFSET
, offset
& 0xff);
1467 tmp
|= 0x10; /* offset overflow bit */
1469 /* screen start addr #16-18, fastpagemode cycles */
1470 vga_wcrt(regbase
, CL_CRT1B
, tmp
);
1472 if (cinfo
->btype
== BT_SD64
||
1473 cinfo
->btype
== BT_PICASSO4
||
1474 cinfo
->btype
== BT_ALPINE
||
1475 cinfo
->btype
== BT_GD5480
)
1476 /* screen start address bit 19 */
1477 vga_wcrt(regbase
, CL_CRT1D
, 0x00);
1479 /* text cursor location high */
1480 vga_wcrt(regbase
, VGA_CRTC_CURSOR_HI
, 0);
1481 /* text cursor location low */
1482 vga_wcrt(regbase
, VGA_CRTC_CURSOR_LO
, 0);
1483 /* underline row scanline = at very bottom */
1484 vga_wcrt(regbase
, VGA_CRTC_UNDERLINE
, 0);
1486 /* controller mode */
1487 vga_wattr(regbase
, VGA_ATC_MODE
, 1);
1488 /* overscan (border) color */
1489 vga_wattr(regbase
, VGA_ATC_OVERSCAN
, 0);
1490 /* color plane enable */
1491 vga_wattr(regbase
, VGA_ATC_PLANE_ENABLE
, 15);
1493 vga_wattr(regbase
, CL_AR33
, 0);
1495 vga_wattr(regbase
, VGA_ATC_COLOR_PAGE
, 0);
1497 /* [ EGS: SetOffset(); ] */
1498 /* From SetOffset(): Turn on VideoEnable bit in Attribute controller */
1501 /* set/reset register */
1502 vga_wgfx(regbase
, VGA_GFX_SR_VALUE
, 0);
1503 /* set/reset enable */
1504 vga_wgfx(regbase
, VGA_GFX_SR_ENABLE
, 0);
1506 vga_wgfx(regbase
, VGA_GFX_COMPARE_VALUE
, 0);
1508 vga_wgfx(regbase
, VGA_GFX_DATA_ROTATE
, 0);
1509 /* read map select */
1510 vga_wgfx(regbase
, VGA_GFX_PLANE_READ
, 0);
1511 /* miscellaneous register */
1512 vga_wgfx(regbase
, VGA_GFX_MISC
, 1);
1513 /* color don't care */
1514 vga_wgfx(regbase
, VGA_GFX_COMPARE_MASK
, 15);
1516 vga_wgfx(regbase
, VGA_GFX_BIT_MASK
, 255);
1518 /* graphics cursor attributes: nothing special */
1519 vga_wseq(regbase
, CL_SEQR12
, 0x0);
1521 /* finally, turn on everything - turn off "FullBandwidth" bit */
1522 /* also, set "DotClock%2" bit where requested */
1525 /*** FB_VMODE_CLOCK_HALVE in linux/fb.h not defined anymore ?
1526 if (var->vmode & FB_VMODE_CLOCK_HALVE)
1530 vga_wseq(regbase
, VGA_SEQ_CLOCK_MODE
, tmp
);
1531 DPRINTK("CL_SEQR1: %d\n", tmp
);
1533 cinfo
->currentmode
= regs
;
1535 /* pan to requested offset */
1536 cirrusfb_pan_display(var
, info
);
1538 #ifdef CIRRUSFB_DEBUG
1546 /* for some reason incomprehensible to me, cirrusfb requires that you write
1547 * the registers twice for the settings to take..grr. -dte */
1548 static int cirrusfb_set_par(struct fb_info
*info
)
1550 cirrusfb_set_par_foo(info
);
1551 return cirrusfb_set_par_foo(info
);
1554 static int cirrusfb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
1555 unsigned blue
, unsigned transp
,
1556 struct fb_info
*info
)
1558 struct cirrusfb_info
*cinfo
= info
->par
;
1563 if (info
->fix
.visual
== FB_VISUAL_TRUECOLOR
) {
1565 red
>>= (16 - info
->var
.red
.length
);
1566 green
>>= (16 - info
->var
.green
.length
);
1567 blue
>>= (16 - info
->var
.blue
.length
);
1571 v
= (red
<< info
->var
.red
.offset
) |
1572 (green
<< info
->var
.green
.offset
) |
1573 (blue
<< info
->var
.blue
.offset
);
1575 cinfo
->pseudo_palette
[regno
] = v
;
1579 if (info
->var
.bits_per_pixel
== 8)
1580 WClut(cinfo
, regno
, red
>> 10, green
>> 10, blue
>> 10);
1586 /*************************************************************************
1587 cirrusfb_pan_display()
1589 performs display panning - provided hardware permits this
1590 **************************************************************************/
1591 static int cirrusfb_pan_display(struct fb_var_screeninfo
*var
,
1592 struct fb_info
*info
)
1597 unsigned char tmp
= 0, tmp2
= 0, xpix
;
1598 struct cirrusfb_info
*cinfo
= info
->par
;
1601 DPRINTK("virtual offset: (%d,%d)\n", var
->xoffset
, var
->yoffset
);
1603 /* no range checks for xoffset and yoffset, */
1604 /* as fb_pan_display has already done this */
1605 if (var
->vmode
& FB_VMODE_YWRAP
)
1608 info
->var
.xoffset
= var
->xoffset
;
1609 info
->var
.yoffset
= var
->yoffset
;
1611 xoffset
= var
->xoffset
* info
->var
.bits_per_pixel
/ 8;
1612 yoffset
= var
->yoffset
;
1614 base
= yoffset
* info
->fix
.line_length
+ xoffset
;
1616 if (info
->var
.bits_per_pixel
== 1) {
1617 /* base is already correct */
1618 xpix
= (unsigned char) (var
->xoffset
% 8);
1621 xpix
= (unsigned char) ((xoffset
% 4) * 2);
1624 cirrusfb_WaitBLT(cinfo
->regbase
); /* make sure all the BLT's are done */
1626 /* lower 8 + 8 bits of screen start address */
1627 vga_wcrt(cinfo
->regbase
, VGA_CRTC_START_LO
,
1628 (unsigned char) (base
& 0xff));
1629 vga_wcrt(cinfo
->regbase
, VGA_CRTC_START_HI
,
1630 (unsigned char) (base
>> 8));
1632 /* construct bits 16, 17 and 18 of screen start address */
1640 /* 0xf2 is %11110010, exclude tmp bits */
1641 tmp2
= (vga_rcrt(cinfo
->regbase
, CL_CRT1B
) & 0xf2) | tmp
;
1642 vga_wcrt(cinfo
->regbase
, CL_CRT1B
, tmp2
);
1644 /* construct bit 19 of screen start address */
1645 if (cirrusfb_board_info
[cinfo
->btype
].scrn_start_bit19
)
1646 vga_wcrt(cinfo
->regbase
, CL_CRT1D
, (base
>> 12) & 0x80);
1648 /* write pixel panning value to AR33; this does not quite work in 8bpp
1650 * ### Piccolo..? Will this work?
1652 if (info
->var
.bits_per_pixel
== 1)
1653 vga_wattr(cinfo
->regbase
, CL_AR33
, xpix
);
1655 cirrusfb_WaitBLT(cinfo
->regbase
);
1661 static int cirrusfb_blank(int blank_mode
, struct fb_info
*info
)
1664 * Blank the screen if blank_mode != 0, else unblank. If blank == NULL
1665 * then the caller blanks by setting the CLUT (Color Look Up Table)
1666 * to all black. Return 0 if blanking succeeded, != 0 if un-/blanking
1667 * failed due to e.g. a video mode which doesn't support it.
1668 * Implements VESA suspend and powerdown modes on hardware that
1669 * supports disabling hsync/vsync:
1670 * blank_mode == 2: suspend vsync
1671 * blank_mode == 3: suspend hsync
1672 * blank_mode == 4: powerdown
1675 struct cirrusfb_info
*cinfo
= info
->par
;
1676 int current_mode
= cinfo
->blank_mode
;
1678 DPRINTK("ENTER, blank mode = %d\n", blank_mode
);
1680 if (info
->state
!= FBINFO_STATE_RUNNING
||
1681 current_mode
== blank_mode
) {
1682 DPRINTK("EXIT, returning 0\n");
1687 if (current_mode
== FB_BLANK_NORMAL
||
1688 current_mode
== FB_BLANK_UNBLANK
) {
1689 /* unblank the screen */
1690 val
= vga_rseq(cinfo
->regbase
, VGA_SEQ_CLOCK_MODE
);
1691 /* clear "FullBandwidth" bit */
1692 vga_wseq(cinfo
->regbase
, VGA_SEQ_CLOCK_MODE
, val
& 0xdf);
1693 /* and undo VESA suspend trickery */
1694 vga_wgfx(cinfo
->regbase
, CL_GRE
, 0x00);
1698 if (blank_mode
> FB_BLANK_NORMAL
) {
1699 /* blank the screen */
1700 val
= vga_rseq(cinfo
->regbase
, VGA_SEQ_CLOCK_MODE
);
1701 /* set "FullBandwidth" bit */
1702 vga_wseq(cinfo
->regbase
, VGA_SEQ_CLOCK_MODE
, val
| 0x20);
1705 switch (blank_mode
) {
1706 case FB_BLANK_UNBLANK
:
1707 case FB_BLANK_NORMAL
:
1709 case FB_BLANK_VSYNC_SUSPEND
:
1710 vga_wgfx(cinfo
->regbase
, CL_GRE
, 0x04);
1712 case FB_BLANK_HSYNC_SUSPEND
:
1713 vga_wgfx(cinfo
->regbase
, CL_GRE
, 0x02);
1715 case FB_BLANK_POWERDOWN
:
1716 vga_wgfx(cinfo
->regbase
, CL_GRE
, 0x06);
1719 DPRINTK("EXIT, returning 1\n");
1723 cinfo
->blank_mode
= blank_mode
;
1724 DPRINTK("EXIT, returning 0\n");
1726 /* Let fbcon do a soft blank for us */
1727 return (blank_mode
== FB_BLANK_NORMAL
) ? 1 : 0;
1729 /**** END Hardware specific Routines **************************************/
1730 /****************************************************************************/
1731 /**** BEGIN Internal Routines ***********************************************/
1733 static void init_vgachip(struct fb_info
*info
)
1735 struct cirrusfb_info
*cinfo
= info
->par
;
1736 const struct cirrusfb_board_info_rec
*bi
;
1740 assert(cinfo
!= NULL
);
1742 bi
= &cirrusfb_board_info
[cinfo
->btype
];
1744 /* reset board globally */
1745 switch (cinfo
->btype
) {
1764 /* disable flickerfixer */
1765 vga_wcrt(cinfo
->regbase
, CL_CRT51
, 0x00);
1767 /* from Klaus' NetBSD driver: */
1768 vga_wgfx(cinfo
->regbase
, CL_GR2F
, 0x00);
1769 /* put blitter into 542x compat */
1770 vga_wgfx(cinfo
->regbase
, CL_GR33
, 0x00);
1772 vga_wgfx(cinfo
->regbase
, CL_GR31
, 0x00);
1776 /* from Klaus' NetBSD driver: */
1777 vga_wgfx(cinfo
->regbase
, CL_GR2F
, 0x00);
1781 /* Nothing to do to reset the board. */
1785 printk(KERN_ERR
"cirrusfb: Warning: Unknown board type\n");
1789 /* make sure RAM size set by this point */
1790 assert(info
->screen_size
> 0);
1792 /* the P4 is not fully initialized here; I rely on it having been */
1793 /* inited under AmigaOS already, which seems to work just fine */
1794 /* (Klaus advised to do it this way) */
1796 if (cinfo
->btype
!= BT_PICASSO4
) {
1797 WGen(cinfo
, CL_VSSM
, 0x10); /* EGS: 0x16 */
1798 WGen(cinfo
, CL_POS102
, 0x01);
1799 WGen(cinfo
, CL_VSSM
, 0x08); /* EGS: 0x0e */
1801 if (cinfo
->btype
!= BT_SD64
)
1802 WGen(cinfo
, CL_VSSM2
, 0x01);
1804 /* reset sequencer logic */
1805 vga_wseq(cinfo
->regbase
, CL_SEQR0
, 0x03);
1807 /* FullBandwidth (video off) and 8/9 dot clock */
1808 vga_wseq(cinfo
->regbase
, VGA_SEQ_CLOCK_MODE
, 0x21);
1809 /* polarity (-/-), disable access to display memory,
1810 * VGA_CRTC_START_HI base address: color
1812 WGen(cinfo
, VGA_MIS_W
, 0xc1);
1814 /* "magic cookie" - doesn't make any sense to me.. */
1815 /* vga_wgfx(cinfo->regbase, CL_GRA, 0xce); */
1816 /* unlock all extension registers */
1817 vga_wseq(cinfo
->regbase
, CL_SEQR6
, 0x12);
1820 vga_wgfx(cinfo
->regbase
, CL_GR31
, 0x04);
1822 switch (cinfo
->btype
) {
1824 vga_wseq(cinfo
->regbase
, CL_SEQRF
, 0x98);
1829 vga_wseq(cinfo
->regbase
, CL_SEQRF
, 0xb8);
1832 vga_wseq(cinfo
->regbase
, CL_SEQR16
, 0x0f);
1833 vga_wseq(cinfo
->regbase
, CL_SEQRF
, 0xb0);
1837 /* plane mask: nothing */
1838 vga_wseq(cinfo
->regbase
, VGA_SEQ_PLANE_WRITE
, 0xff);
1839 /* character map select: doesn't even matter in gx mode */
1840 vga_wseq(cinfo
->regbase
, VGA_SEQ_CHARACTER_MAP
, 0x00);
1841 /* memory mode: chain-4, no odd/even, ext. memory */
1842 vga_wseq(cinfo
->regbase
, VGA_SEQ_MEMORY_MODE
, 0x0e);
1844 /* controller-internal base address of video memory */
1846 vga_wseq(cinfo
->regbase
, CL_SEQR7
, bi
->sr07
);
1848 /* vga_wseq(cinfo->regbase, CL_SEQR8, 0x00); */
1849 /* EEPROM control: shouldn't be necessary to write to this at all.. */
1851 /* graphics cursor X position (incomplete; position gives rem. 3 bits */
1852 vga_wseq(cinfo
->regbase
, CL_SEQR10
, 0x00);
1853 /* graphics cursor Y position (..."... ) */
1854 vga_wseq(cinfo
->regbase
, CL_SEQR11
, 0x00);
1855 /* graphics cursor attributes */
1856 vga_wseq(cinfo
->regbase
, CL_SEQR12
, 0x00);
1857 /* graphics cursor pattern address */
1858 vga_wseq(cinfo
->regbase
, CL_SEQR13
, 0x00);
1860 /* writing these on a P4 might give problems.. */
1861 if (cinfo
->btype
!= BT_PICASSO4
) {
1862 /* configuration readback and ext. color */
1863 vga_wseq(cinfo
->regbase
, CL_SEQR17
, 0x00);
1864 /* signature generator */
1865 vga_wseq(cinfo
->regbase
, CL_SEQR18
, 0x02);
1868 /* MCLK select etc. */
1870 vga_wseq(cinfo
->regbase
, CL_SEQR1F
, bi
->sr1f
);
1872 /* Screen A preset row scan: none */
1873 vga_wcrt(cinfo
->regbase
, VGA_CRTC_PRESET_ROW
, 0x00);
1874 /* Text cursor start: disable text cursor */
1875 vga_wcrt(cinfo
->regbase
, VGA_CRTC_CURSOR_START
, 0x20);
1876 /* Text cursor end: - */
1877 vga_wcrt(cinfo
->regbase
, VGA_CRTC_CURSOR_END
, 0x00);
1878 /* Screen start address high: 0 */
1879 vga_wcrt(cinfo
->regbase
, VGA_CRTC_START_HI
, 0x00);
1880 /* Screen start address low: 0 */
1881 vga_wcrt(cinfo
->regbase
, VGA_CRTC_START_LO
, 0x00);
1882 /* text cursor location high: 0 */
1883 vga_wcrt(cinfo
->regbase
, VGA_CRTC_CURSOR_HI
, 0x00);
1884 /* text cursor location low: 0 */
1885 vga_wcrt(cinfo
->regbase
, VGA_CRTC_CURSOR_LO
, 0x00);
1887 /* Underline Row scanline: - */
1888 vga_wcrt(cinfo
->regbase
, VGA_CRTC_UNDERLINE
, 0x00);
1889 /* mode control: timing enable, byte mode, no compat modes */
1890 vga_wcrt(cinfo
->regbase
, VGA_CRTC_MODE
, 0xc3);
1891 /* Line Compare: not needed */
1892 vga_wcrt(cinfo
->regbase
, VGA_CRTC_LINE_COMPARE
, 0x00);
1893 /* ### add 0x40 for text modes with > 30 MHz pixclock */
1894 /* ext. display controls: ext.adr. wrap */
1895 vga_wcrt(cinfo
->regbase
, CL_CRT1B
, 0x02);
1897 /* Set/Reset registes: - */
1898 vga_wgfx(cinfo
->regbase
, VGA_GFX_SR_VALUE
, 0x00);
1899 /* Set/Reset enable: - */
1900 vga_wgfx(cinfo
->regbase
, VGA_GFX_SR_ENABLE
, 0x00);
1901 /* Color Compare: - */
1902 vga_wgfx(cinfo
->regbase
, VGA_GFX_COMPARE_VALUE
, 0x00);
1903 /* Data Rotate: - */
1904 vga_wgfx(cinfo
->regbase
, VGA_GFX_DATA_ROTATE
, 0x00);
1905 /* Read Map Select: - */
1906 vga_wgfx(cinfo
->regbase
, VGA_GFX_PLANE_READ
, 0x00);
1907 /* Mode: conf. for 16/4/2 color mode, no odd/even, read/write mode 0 */
1908 vga_wgfx(cinfo
->regbase
, VGA_GFX_MODE
, 0x00);
1909 /* Miscellaneous: memory map base address, graphics mode */
1910 vga_wgfx(cinfo
->regbase
, VGA_GFX_MISC
, 0x01);
1911 /* Color Don't care: involve all planes */
1912 vga_wgfx(cinfo
->regbase
, VGA_GFX_COMPARE_MASK
, 0x0f);
1913 /* Bit Mask: no mask at all */
1914 vga_wgfx(cinfo
->regbase
, VGA_GFX_BIT_MASK
, 0xff);
1915 if (cinfo
->btype
== BT_ALPINE
)
1916 /* (5434 can't have bit 3 set for bitblt) */
1917 vga_wgfx(cinfo
->regbase
, CL_GRB
, 0x20);
1919 /* Graphics controller mode extensions: finer granularity,
1920 * 8byte data latches
1922 vga_wgfx(cinfo
->regbase
, CL_GRB
, 0x28);
1924 vga_wgfx(cinfo
->regbase
, CL_GRC
, 0xff); /* Color Key compare: - */
1925 vga_wgfx(cinfo
->regbase
, CL_GRD
, 0x00); /* Color Key compare mask: - */
1926 vga_wgfx(cinfo
->regbase
, CL_GRE
, 0x00); /* Miscellaneous control: - */
1927 /* Background color byte 1: - */
1928 /* vga_wgfx (cinfo->regbase, CL_GR10, 0x00); */
1929 /* vga_wgfx (cinfo->regbase, CL_GR11, 0x00); */
1931 /* Attribute Controller palette registers: "identity mapping" */
1932 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTE0
, 0x00);
1933 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTE1
, 0x01);
1934 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTE2
, 0x02);
1935 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTE3
, 0x03);
1936 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTE4
, 0x04);
1937 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTE5
, 0x05);
1938 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTE6
, 0x06);
1939 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTE7
, 0x07);
1940 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTE8
, 0x08);
1941 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTE9
, 0x09);
1942 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTEA
, 0x0a);
1943 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTEB
, 0x0b);
1944 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTEC
, 0x0c);
1945 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTED
, 0x0d);
1946 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTEE
, 0x0e);
1947 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTEF
, 0x0f);
1949 /* Attribute Controller mode: graphics mode */
1950 vga_wattr(cinfo
->regbase
, VGA_ATC_MODE
, 0x01);
1951 /* Overscan color reg.: reg. 0 */
1952 vga_wattr(cinfo
->regbase
, VGA_ATC_OVERSCAN
, 0x00);
1953 /* Color Plane enable: Enable all 4 planes */
1954 vga_wattr(cinfo
->regbase
, VGA_ATC_PLANE_ENABLE
, 0x0f);
1955 /* ### vga_wattr(cinfo->regbase, CL_AR33, 0x00); * Pixel Panning: - */
1956 /* Color Select: - */
1957 vga_wattr(cinfo
->regbase
, VGA_ATC_COLOR_PAGE
, 0x00);
1959 WGen(cinfo
, VGA_PEL_MSK
, 0xff); /* Pixel mask: no mask */
1961 if (cinfo
->btype
!= BT_ALPINE
&& cinfo
->btype
!= BT_GD5480
)
1962 /* polarity (-/-), enable display mem,
1963 * VGA_CRTC_START_HI i/o base = color
1965 WGen(cinfo
, VGA_MIS_W
, 0xc3);
1967 /* BLT Start/status: Blitter reset */
1968 vga_wgfx(cinfo
->regbase
, CL_GR31
, 0x04);
1969 /* - " - : "end-of-reset" */
1970 vga_wgfx(cinfo
->regbase
, CL_GR31
, 0x00);
1973 WHDR(cinfo
, 0); /* Hidden DAC register: - */
1975 printk(KERN_DEBUG
"cirrusfb: This board has %ld bytes of DRAM memory\n",
1981 static void switch_monitor(struct cirrusfb_info
*cinfo
, int on
)
1983 #ifdef CONFIG_ZORRO /* only works on Zorro boards */
1984 static int IsOn
= 0; /* XXX not ok for multiple boards */
1988 if (cinfo
->btype
== BT_PICASSO4
)
1989 return; /* nothing to switch */
1990 if (cinfo
->btype
== BT_ALPINE
)
1991 return; /* nothing to switch */
1992 if (cinfo
->btype
== BT_GD5480
)
1993 return; /* nothing to switch */
1994 if (cinfo
->btype
== BT_PICASSO
) {
1995 if ((on
&& !IsOn
) || (!on
&& IsOn
))
2002 switch (cinfo
->btype
) {
2004 WSFR(cinfo
, cinfo
->SFR
| 0x21);
2007 WSFR(cinfo
, cinfo
->SFR
| 0x28);
2012 default: /* do nothing */ break;
2015 switch (cinfo
->btype
) {
2017 WSFR(cinfo
, cinfo
->SFR
& 0xde);
2020 WSFR(cinfo
, cinfo
->SFR
& 0xd7);
2025 default: /* do nothing */ break;
2030 #endif /* CONFIG_ZORRO */
2033 /******************************************/
2034 /* Linux 2.6-style accelerated functions */
2035 /******************************************/
2037 static void cirrusfb_fillrect(struct fb_info
*info
,
2038 const struct fb_fillrect
*region
)
2040 struct fb_fillrect modded
;
2042 struct cirrusfb_info
*cinfo
= info
->par
;
2043 int m
= info
->var
.bits_per_pixel
;
2044 u32 color
= (info
->fix
.visual
== FB_VISUAL_TRUECOLOR
) ?
2045 cinfo
->pseudo_palette
[region
->color
] : region
->color
;
2047 if (info
->state
!= FBINFO_STATE_RUNNING
)
2049 if (info
->flags
& FBINFO_HWACCEL_DISABLED
) {
2050 cfb_fillrect(info
, region
);
2054 vxres
= info
->var
.xres_virtual
;
2055 vyres
= info
->var
.yres_virtual
;
2057 memcpy(&modded
, region
, sizeof(struct fb_fillrect
));
2059 if (!modded
.width
|| !modded
.height
||
2060 modded
.dx
>= vxres
|| modded
.dy
>= vyres
)
2063 if (modded
.dx
+ modded
.width
> vxres
)
2064 modded
.width
= vxres
- modded
.dx
;
2065 if (modded
.dy
+ modded
.height
> vyres
)
2066 modded
.height
= vyres
- modded
.dy
;
2068 cirrusfb_RectFill(cinfo
->regbase
,
2069 info
->var
.bits_per_pixel
,
2070 (region
->dx
* m
) / 8, region
->dy
,
2071 (region
->width
* m
) / 8, region
->height
,
2073 info
->fix
.line_length
);
2076 static void cirrusfb_copyarea(struct fb_info
*info
,
2077 const struct fb_copyarea
*area
)
2079 struct fb_copyarea modded
;
2081 struct cirrusfb_info
*cinfo
= info
->par
;
2082 int m
= info
->var
.bits_per_pixel
;
2084 if (info
->state
!= FBINFO_STATE_RUNNING
)
2086 if (info
->flags
& FBINFO_HWACCEL_DISABLED
) {
2087 cfb_copyarea(info
, area
);
2091 vxres
= info
->var
.xres_virtual
;
2092 vyres
= info
->var
.yres_virtual
;
2093 memcpy(&modded
, area
, sizeof(struct fb_copyarea
));
2095 if (!modded
.width
|| !modded
.height
||
2096 modded
.sx
>= vxres
|| modded
.sy
>= vyres
||
2097 modded
.dx
>= vxres
|| modded
.dy
>= vyres
)
2100 if (modded
.sx
+ modded
.width
> vxres
)
2101 modded
.width
= vxres
- modded
.sx
;
2102 if (modded
.dx
+ modded
.width
> vxres
)
2103 modded
.width
= vxres
- modded
.dx
;
2104 if (modded
.sy
+ modded
.height
> vyres
)
2105 modded
.height
= vyres
- modded
.sy
;
2106 if (modded
.dy
+ modded
.height
> vyres
)
2107 modded
.height
= vyres
- modded
.dy
;
2109 cirrusfb_BitBLT(cinfo
->regbase
, info
->var
.bits_per_pixel
,
2110 (area
->sx
* m
) / 8, area
->sy
,
2111 (area
->dx
* m
) / 8, area
->dy
,
2112 (area
->width
* m
) / 8, area
->height
,
2113 info
->fix
.line_length
);
2117 static void cirrusfb_imageblit(struct fb_info
*info
,
2118 const struct fb_image
*image
)
2120 struct cirrusfb_info
*cinfo
= info
->par
;
2122 cirrusfb_WaitBLT(cinfo
->regbase
);
2123 cfb_imageblit(info
, image
);
2126 #ifdef CONFIG_PPC_PREP
2127 #define PREP_VIDEO_BASE ((volatile unsigned long) 0xC0000000)
2128 #define PREP_IO_BASE ((volatile unsigned char *) 0x80000000)
2129 static void get_prep_addrs(unsigned long *display
, unsigned long *registers
)
2133 *display
= PREP_VIDEO_BASE
;
2134 *registers
= (unsigned long) PREP_IO_BASE
;
2139 #endif /* CONFIG_PPC_PREP */
2142 static int release_io_ports
;
2144 /* Pulled the logic from XFree86 Cirrus driver to get the memory size,
2145 * based on the DRAM bandwidth bit and DRAM bank switching bit. This
2146 * works with 1MB, 2MB and 4MB configurations (which the Motorola boards
2148 static unsigned int cirrusfb_get_memsize(u8 __iomem
*regbase
)
2155 SRF
= vga_rseq(regbase
, CL_SEQRF
);
2156 switch ((SRF
& 0x18)) {
2163 /* 64-bit DRAM data bus width; assume 2MB. Also indicates 2MB memory
2170 printk(KERN_WARNING
"CLgenfb: Unknown memory size!\n");
2174 /* If DRAM bank switching is enabled, there must be twice as much
2175 * memory installed. (4MB on the 5434)
2179 /* TODO: Handling of GD5446/5480 (see XF86 sources ...) */
2185 static void get_pci_addrs(const struct pci_dev
*pdev
,
2186 unsigned long *display
, unsigned long *registers
)
2188 assert(pdev
!= NULL
);
2189 assert(display
!= NULL
);
2190 assert(registers
!= NULL
);
2197 /* This is a best-guess for now */
2199 if (pci_resource_flags(pdev
, 0) & IORESOURCE_IO
) {
2200 *display
= pci_resource_start(pdev
, 1);
2201 *registers
= pci_resource_start(pdev
, 0);
2203 *display
= pci_resource_start(pdev
, 0);
2204 *registers
= pci_resource_start(pdev
, 1);
2207 assert(*display
!= 0);
2212 static void cirrusfb_pci_unmap(struct fb_info
*info
)
2214 struct cirrusfb_info
*cinfo
= info
->par
;
2215 struct pci_dev
*pdev
= cinfo
->pdev
;
2217 iounmap(info
->screen_base
);
2218 #if 0 /* if system didn't claim this region, we would... */
2219 release_mem_region(0xA0000, 65535);
2221 if (release_io_ports
)
2222 release_region(0x3C0, 32);
2223 pci_release_regions(pdev
);
2225 #endif /* CONFIG_PCI */
2228 static void __devexit
cirrusfb_zorro_unmap(struct fb_info
*info
)
2230 struct cirrusfb_info
*cinfo
= info
->par
;
2231 zorro_release_device(cinfo
->zdev
);
2233 if (cinfo
->btype
== BT_PICASSO4
) {
2234 cinfo
->regbase
-= 0x600000;
2235 iounmap((void *)cinfo
->regbase
);
2236 iounmap(info
->screen_base
);
2238 if (zorro_resource_start(cinfo
->zdev
) > 0x01000000)
2239 iounmap(info
->screen_base
);
2242 #endif /* CONFIG_ZORRO */
2244 static int cirrusfb_set_fbinfo(struct fb_info
*info
)
2246 struct cirrusfb_info
*cinfo
= info
->par
;
2247 struct fb_var_screeninfo
*var
= &info
->var
;
2249 info
->pseudo_palette
= cinfo
->pseudo_palette
;
2250 info
->flags
= FBINFO_DEFAULT
2251 | FBINFO_HWACCEL_XPAN
2252 | FBINFO_HWACCEL_YPAN
2253 | FBINFO_HWACCEL_FILLRECT
2254 | FBINFO_HWACCEL_COPYAREA
;
2256 info
->flags
|= FBINFO_HWACCEL_DISABLED
;
2257 info
->fbops
= &cirrusfb_ops
;
2258 if (cinfo
->btype
== BT_GD5480
) {
2259 if (var
->bits_per_pixel
== 16)
2260 info
->screen_base
+= 1 * MB_
;
2261 if (var
->bits_per_pixel
== 24 || var
->bits_per_pixel
== 32)
2262 info
->screen_base
+= 2 * MB_
;
2265 /* Fill fix common fields */
2266 strlcpy(info
->fix
.id
, cirrusfb_board_info
[cinfo
->btype
].name
,
2267 sizeof(info
->fix
.id
));
2269 /* monochrome: only 1 memory plane */
2270 /* 8 bit and above: Use whole memory area */
2271 info
->fix
.smem_len
= info
->screen_size
;
2272 if (var
->bits_per_pixel
== 1)
2273 info
->fix
.smem_len
/= 4;
2274 info
->fix
.type_aux
= 0;
2275 info
->fix
.xpanstep
= 1;
2276 info
->fix
.ypanstep
= 1;
2277 info
->fix
.ywrapstep
= 0;
2279 /* FIXME: map region at 0xB8000 if available, fill in here */
2280 info
->fix
.mmio_len
= 0;
2281 info
->fix
.accel
= FB_ACCEL_NONE
;
2283 fb_alloc_cmap(&info
->cmap
, 256, 0);
2288 static int cirrusfb_register(struct fb_info
*info
)
2290 struct cirrusfb_info
*cinfo
= info
->par
;
2292 enum cirrus_board btype
;
2296 printk(KERN_INFO
"cirrusfb: Driver for Cirrus Logic based "
2297 "graphic boards, v" CIRRUSFB_VERSION
"\n");
2299 btype
= cinfo
->btype
;
2302 assert(btype
!= BT_NONE
);
2304 DPRINTK("cirrusfb: (RAM start set to: 0x%p)\n", info
->screen_base
);
2306 /* Make pretend we've set the var so our structures are in a "good" */
2307 /* state, even though we haven't written the mode to the hw yet... */
2308 info
->var
= cirrusfb_predefined
[cirrusfb_def_mode
].var
;
2309 info
->var
.activate
= FB_ACTIVATE_NOW
;
2311 err
= cirrusfb_decode_var(&info
->var
, &cinfo
->currentmode
, info
);
2313 /* should never happen */
2314 DPRINTK("choking on default var... umm, no good.\n");
2315 goto err_unmap_cirrusfb
;
2318 /* set all the vital stuff */
2319 cirrusfb_set_fbinfo(info
);
2321 err
= register_framebuffer(info
);
2323 printk(KERN_ERR
"cirrusfb: could not register "
2324 "fb device; err = %d!\n", err
);
2325 goto err_dealloc_cmap
;
2328 DPRINTK("EXIT, returning 0\n");
2332 fb_dealloc_cmap(&info
->cmap
);
2335 framebuffer_release(info
);
2339 static void __devexit
cirrusfb_cleanup(struct fb_info
*info
)
2341 struct cirrusfb_info
*cinfo
= info
->par
;
2344 switch_monitor(cinfo
, 0);
2346 unregister_framebuffer(info
);
2347 fb_dealloc_cmap(&info
->cmap
);
2348 printk("Framebuffer unregistered\n");
2350 framebuffer_release(info
);
2356 static int cirrusfb_pci_register(struct pci_dev
*pdev
,
2357 const struct pci_device_id
*ent
)
2359 struct cirrusfb_info
*cinfo
;
2360 struct fb_info
*info
;
2361 enum cirrus_board btype
;
2362 unsigned long board_addr
, board_size
;
2365 ret
= pci_enable_device(pdev
);
2367 printk(KERN_ERR
"cirrusfb: Cannot enable PCI device\n");
2371 info
= framebuffer_alloc(sizeof(struct cirrusfb_info
), &pdev
->dev
);
2373 printk(KERN_ERR
"cirrusfb: could not allocate memory\n");
2380 cinfo
->btype
= btype
= (enum cirrus_board
) ent
->driver_data
;
2382 DPRINTK(" Found PCI device, base address 0 is 0x%x, btype set to %d\n",
2383 pdev
->resource
[0].start
, btype
);
2384 DPRINTK(" base address 1 is 0x%x\n", pdev
->resource
[1].start
);
2387 pci_write_config_dword(pdev
, PCI_BASE_ADDRESS_0
, 0x00000000);
2388 #ifdef CONFIG_PPC_PREP
2389 get_prep_addrs(&board_addr
, &info
->fix
.mmio_start
);
2391 /* PReP dies if we ioremap the IO registers, but it works w/out... */
2392 cinfo
->regbase
= (char __iomem
*) info
->fix
.mmio_start
;
2394 DPRINTK("Attempt to get PCI info for Cirrus Graphics Card\n");
2395 get_pci_addrs(pdev
, &board_addr
, &info
->fix
.mmio_start
);
2396 /* FIXME: this forces VGA. alternatives? */
2397 cinfo
->regbase
= NULL
;
2400 DPRINTK("Board address: 0x%lx, register address: 0x%lx\n",
2401 board_addr
, info
->fix
.mmio_start
);
2403 board_size
= (btype
== BT_GD5480
) ?
2404 32 * MB_
: cirrusfb_get_memsize(cinfo
->regbase
);
2406 ret
= pci_request_regions(pdev
, "cirrusfb");
2408 printk(KERN_ERR
"cirrusfb: cannot reserve region 0x%lx, "
2411 goto err_release_fb
;
2413 #if 0 /* if the system didn't claim this region, we would... */
2414 if (!request_mem_region(0xA0000, 65535, "cirrusfb")) {
2415 printk(KERN_ERR
"cirrusfb: cannot reserve region 0x%lx, abort\n"
2419 goto err_release_regions
;
2422 if (request_region(0x3C0, 32, "cirrusfb"))
2423 release_io_ports
= 1;
2425 info
->screen_base
= ioremap(board_addr
, board_size
);
2426 if (!info
->screen_base
) {
2428 goto err_release_legacy
;
2431 info
->fix
.smem_start
= board_addr
;
2432 info
->screen_size
= board_size
;
2433 cinfo
->unmap
= cirrusfb_pci_unmap
;
2435 printk(KERN_INFO
" RAM (%lu kB) at 0xx%lx, ",
2436 info
->screen_size
>> 10, board_addr
);
2437 printk(KERN_INFO
"Cirrus Logic chipset on PCI bus\n");
2438 pci_set_drvdata(pdev
, info
);
2440 ret
= cirrusfb_register(info
);
2442 iounmap(info
->screen_base
);
2446 if (release_io_ports
)
2447 release_region(0x3C0, 32);
2449 release_mem_region(0xA0000, 65535);
2450 err_release_regions
:
2452 pci_release_regions(pdev
);
2454 framebuffer_release(info
);
2460 static void __devexit
cirrusfb_pci_unregister(struct pci_dev
*pdev
)
2462 struct fb_info
*info
= pci_get_drvdata(pdev
);
2465 cirrusfb_cleanup(info
);
2470 static struct pci_driver cirrusfb_pci_driver
= {
2472 .id_table
= cirrusfb_pci_table
,
2473 .probe
= cirrusfb_pci_register
,
2474 .remove
= __devexit_p(cirrusfb_pci_unregister
),
2477 .suspend
= cirrusfb_pci_suspend
,
2478 .resume
= cirrusfb_pci_resume
,
2482 #endif /* CONFIG_PCI */
2485 static int cirrusfb_zorro_register(struct zorro_dev
*z
,
2486 const struct zorro_device_id
*ent
)
2488 struct cirrusfb_info
*cinfo
;
2489 struct fb_info
*info
;
2490 enum cirrus_board btype
;
2491 struct zorro_dev
*z2
= NULL
;
2492 unsigned long board_addr
, board_size
, size
;
2495 btype
= ent
->driver_data
;
2496 if (cirrusfb_zorro_table2
[btype
].id2
)
2497 z2
= zorro_find_device(cirrusfb_zorro_table2
[btype
].id2
, NULL
);
2498 size
= cirrusfb_zorro_table2
[btype
].size
;
2499 printk(KERN_INFO
"cirrusfb: %s board detected; ",
2500 cirrusfb_board_info
[btype
].name
);
2502 info
= framebuffer_alloc(sizeof(struct cirrusfb_info
), &z
->dev
);
2504 printk(KERN_ERR
"cirrusfb: could not allocate memory\n");
2510 cinfo
->btype
= btype
;
2513 assert(btype
!= BT_NONE
);
2516 board_addr
= zorro_resource_start(z
);
2517 board_size
= zorro_resource_len(z
);
2518 info
->screen_size
= size
;
2520 if (!zorro_request_device(z
, "cirrusfb")) {
2521 printk(KERN_ERR
"cirrusfb: cannot reserve region 0x%lx, "
2525 goto err_release_fb
;
2528 printk(" RAM (%lu MB) at $%lx, ", board_size
/ MB_
, board_addr
);
2532 if (btype
== BT_PICASSO4
) {
2533 printk(KERN_INFO
" REG at $%lx\n", board_addr
+ 0x600000);
2535 /* To be precise, for the P4 this is not the */
2536 /* begin of the board, but the begin of RAM. */
2537 /* for P4, map in its address space in 2 chunks (### TEST! ) */
2538 /* (note the ugly hardcoded 16M number) */
2539 cinfo
->regbase
= ioremap(board_addr
, 16777216);
2540 if (!cinfo
->regbase
)
2541 goto err_release_region
;
2543 DPRINTK("cirrusfb: Virtual address for board set to: $%p\n",
2545 cinfo
->regbase
+= 0x600000;
2546 info
->fix
.mmio_start
= board_addr
+ 0x600000;
2548 info
->fix
.smem_start
= board_addr
+ 16777216;
2549 info
->screen_base
= ioremap(info
->fix
.smem_start
, 16777216);
2550 if (!info
->screen_base
)
2551 goto err_unmap_regbase
;
2553 printk(KERN_INFO
" REG at $%lx\n",
2554 (unsigned long) z2
->resource
.start
);
2556 info
->fix
.smem_start
= board_addr
;
2557 if (board_addr
> 0x01000000)
2558 info
->screen_base
= ioremap(board_addr
, board_size
);
2560 info
->screen_base
= (caddr_t
) ZTWO_VADDR(board_addr
);
2561 if (!info
->screen_base
)
2562 goto err_release_region
;
2564 /* set address for REG area of board */
2565 cinfo
->regbase
= (caddr_t
) ZTWO_VADDR(z2
->resource
.start
);
2566 info
->fix
.mmio_start
= z2
->resource
.start
;
2568 DPRINTK("cirrusfb: Virtual address for board set to: $%p\n",
2571 cinfo
->unmap
= cirrusfb_zorro_unmap
;
2573 printk(KERN_INFO
"Cirrus Logic chipset on Zorro bus\n");
2574 zorro_set_drvdata(z
, info
);
2576 ret
= cirrusfb_register(info
);
2578 if (btype
== BT_PICASSO4
) {
2579 iounmap(info
->screen_base
);
2580 iounmap(cinfo
->regbase
- 0x600000);
2581 } else if (board_addr
> 0x01000000)
2582 iounmap(info
->screen_base
);
2587 /* Parental advisory: explicit hack */
2588 iounmap(cinfo
->regbase
- 0x600000);
2590 release_region(board_addr
, board_size
);
2592 framebuffer_release(info
);
2597 void __devexit
cirrusfb_zorro_unregister(struct zorro_dev
*z
)
2599 struct fb_info
*info
= zorro_get_drvdata(z
);
2602 cirrusfb_cleanup(info
);
2607 static struct zorro_driver cirrusfb_zorro_driver
= {
2609 .id_table
= cirrusfb_zorro_table
,
2610 .probe
= cirrusfb_zorro_register
,
2611 .remove
= __devexit_p(cirrusfb_zorro_unregister
),
2613 #endif /* CONFIG_ZORRO */
2615 static int __init
cirrusfb_init(void)
2620 char *option
= NULL
;
2622 if (fb_get_options("cirrusfb", &option
))
2624 cirrusfb_setup(option
);
2628 error
|= zorro_register_driver(&cirrusfb_zorro_driver
);
2631 error
|= pci_register_driver(&cirrusfb_pci_driver
);
2637 static int __init
cirrusfb_setup(char *options
) {
2638 char *this_opt
, s
[32];
2643 if (!options
|| !*options
)
2646 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
2647 if (!*this_opt
) continue;
2649 DPRINTK("cirrusfb_setup: option '%s'\n", this_opt
);
2651 for (i
= 0; i
< NUM_TOTAL_MODES
; i
++) {
2652 sprintf(s
, "mode:%s", cirrusfb_predefined
[i
].name
);
2653 if (strcmp(this_opt
, s
) == 0)
2654 cirrusfb_def_mode
= i
;
2656 if (!strcmp(this_opt
, "noaccel"))
2667 MODULE_AUTHOR("Copyright 1999,2000 Jeff Garzik <jgarzik@pobox.com>");
2668 MODULE_DESCRIPTION("Accelerated FBDev driver for Cirrus Logic chips");
2669 MODULE_LICENSE("GPL");
2671 static void __exit
cirrusfb_exit(void)
2674 pci_unregister_driver(&cirrusfb_pci_driver
);
2677 zorro_unregister_driver(&cirrusfb_zorro_driver
);
2681 module_init(cirrusfb_init
);
2684 module_exit(cirrusfb_exit
);
2687 /**********************************************************************/
2688 /* about the following functions - I have used the same names for the */
2689 /* functions as Markus Wild did in his Retina driver for NetBSD as */
2690 /* they just made sense for this purpose. Apart from that, I wrote */
2691 /* these functions myself. */
2692 /**********************************************************************/
2694 /*** WGen() - write into one of the external/general registers ***/
2695 static void WGen(const struct cirrusfb_info
*cinfo
,
2696 int regnum
, unsigned char val
)
2698 unsigned long regofs
= 0;
2700 if (cinfo
->btype
== BT_PICASSO
) {
2701 /* Picasso II specific hack */
2702 /* if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D ||
2703 regnum == CL_VSSM2) */
2704 if (regnum
== VGA_PEL_IR
|| regnum
== VGA_PEL_D
)
2708 vga_w(cinfo
->regbase
, regofs
+ regnum
, val
);
2711 /*** RGen() - read out one of the external/general registers ***/
2712 static unsigned char RGen(const struct cirrusfb_info
*cinfo
, int regnum
)
2714 unsigned long regofs
= 0;
2716 if (cinfo
->btype
== BT_PICASSO
) {
2717 /* Picasso II specific hack */
2718 /* if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D ||
2719 regnum == CL_VSSM2) */
2720 if (regnum
== VGA_PEL_IR
|| regnum
== VGA_PEL_D
)
2724 return vga_r(cinfo
->regbase
, regofs
+ regnum
);
2727 /*** AttrOn() - turn on VideoEnable for Attribute controller ***/
2728 static void AttrOn(const struct cirrusfb_info
*cinfo
)
2730 assert(cinfo
!= NULL
);
2734 if (vga_rcrt(cinfo
->regbase
, CL_CRT24
) & 0x80) {
2735 /* if we're just in "write value" mode, write back the */
2736 /* same value as before to not modify anything */
2737 vga_w(cinfo
->regbase
, VGA_ATT_IW
,
2738 vga_r(cinfo
->regbase
, VGA_ATT_R
));
2740 /* turn on video bit */
2741 /* vga_w(cinfo->regbase, VGA_ATT_IW, 0x20); */
2742 vga_w(cinfo
->regbase
, VGA_ATT_IW
, 0x33);
2744 /* dummy write on Reg0 to be on "write index" mode next time */
2745 vga_w(cinfo
->regbase
, VGA_ATT_IW
, 0x00);
2750 /*** WHDR() - write into the Hidden DAC register ***/
2751 /* as the HDR is the only extension register that requires special treatment
2752 * (the other extension registers are accessible just like the "ordinary"
2753 * registers of their functional group) here is a specialized routine for
2756 static void WHDR(const struct cirrusfb_info
*cinfo
, unsigned char val
)
2758 unsigned char dummy
;
2760 if (cinfo
->btype
== BT_PICASSO
) {
2761 /* Klaus' hint for correct access to HDR on some boards */
2762 /* first write 0 to pixel mask (3c6) */
2763 WGen(cinfo
, VGA_PEL_MSK
, 0x00);
2765 /* next read dummy from pixel address (3c8) */
2766 dummy
= RGen(cinfo
, VGA_PEL_IW
);
2769 /* now do the usual stuff to access the HDR */
2771 dummy
= RGen(cinfo
, VGA_PEL_MSK
);
2773 dummy
= RGen(cinfo
, VGA_PEL_MSK
);
2775 dummy
= RGen(cinfo
, VGA_PEL_MSK
);
2777 dummy
= RGen(cinfo
, VGA_PEL_MSK
);
2780 WGen(cinfo
, VGA_PEL_MSK
, val
);
2783 if (cinfo
->btype
== BT_PICASSO
) {
2784 /* now first reset HDR access counter */
2785 dummy
= RGen(cinfo
, VGA_PEL_IW
);
2788 /* and at the end, restore the mask value */
2789 /* ## is this mask always 0xff? */
2790 WGen(cinfo
, VGA_PEL_MSK
, 0xff);
2795 /*** WSFR() - write to the "special function register" (SFR) ***/
2796 static void WSFR(struct cirrusfb_info
*cinfo
, unsigned char val
)
2799 assert(cinfo
->regbase
!= NULL
);
2801 z_writeb(val
, cinfo
->regbase
+ 0x8000);
2805 /* The Picasso has a second register for switching the monitor bit */
2806 static void WSFR2(struct cirrusfb_info
*cinfo
, unsigned char val
)
2809 /* writing an arbitrary value to this one causes the monitor switcher */
2810 /* to flip to Amiga display */
2811 assert(cinfo
->regbase
!= NULL
);
2813 z_writeb(val
, cinfo
->regbase
+ 0x9000);
2817 /*** WClut - set CLUT entry (range: 0..63) ***/
2818 static void WClut(struct cirrusfb_info
*cinfo
, unsigned char regnum
, unsigned char red
,
2819 unsigned char green
, unsigned char blue
)
2821 unsigned int data
= VGA_PEL_D
;
2823 /* address write mode register is not translated.. */
2824 vga_w(cinfo
->regbase
, VGA_PEL_IW
, regnum
);
2826 if (cinfo
->btype
== BT_PICASSO
|| cinfo
->btype
== BT_PICASSO4
||
2827 cinfo
->btype
== BT_ALPINE
|| cinfo
->btype
== BT_GD5480
) {
2828 /* but DAC data register IS, at least for Picasso II */
2829 if (cinfo
->btype
== BT_PICASSO
)
2831 vga_w(cinfo
->regbase
, data
, red
);
2832 vga_w(cinfo
->regbase
, data
, green
);
2833 vga_w(cinfo
->regbase
, data
, blue
);
2835 vga_w(cinfo
->regbase
, data
, blue
);
2836 vga_w(cinfo
->regbase
, data
, green
);
2837 vga_w(cinfo
->regbase
, data
, red
);
2842 /*** RClut - read CLUT entry (range 0..63) ***/
2843 static void RClut(struct cirrusfb_info
*cinfo
, unsigned char regnum
, unsigned char *red
,
2844 unsigned char *green
, unsigned char *blue
)
2846 unsigned int data
= VGA_PEL_D
;
2848 vga_w(cinfo
->regbase
, VGA_PEL_IR
, regnum
);
2850 if (cinfo
->btype
== BT_PICASSO
|| cinfo
->btype
== BT_PICASSO4
||
2851 cinfo
->btype
== BT_ALPINE
|| cinfo
->btype
== BT_GD5480
) {
2852 if (cinfo
->btype
== BT_PICASSO
)
2854 *red
= vga_r(cinfo
->regbase
, data
);
2855 *green
= vga_r(cinfo
->regbase
, data
);
2856 *blue
= vga_r(cinfo
->regbase
, data
);
2858 *blue
= vga_r(cinfo
->regbase
, data
);
2859 *green
= vga_r(cinfo
->regbase
, data
);
2860 *red
= vga_r(cinfo
->regbase
, data
);
2865 /*******************************************************************
2868 Wait for the BitBLT engine to complete a possible earlier job
2869 *********************************************************************/
2871 /* FIXME: use interrupts instead */
2872 static void cirrusfb_WaitBLT(u8 __iomem
*regbase
)
2874 /* now busy-wait until we're done */
2875 while (vga_rgfx(regbase
, CL_GR31
) & 0x08)
2879 /*******************************************************************
2882 perform accelerated "scrolling"
2883 ********************************************************************/
2885 static void cirrusfb_BitBLT(u8 __iomem
*regbase
, int bits_per_pixel
,
2886 u_short curx
, u_short cury
,
2887 u_short destx
, u_short desty
,
2888 u_short width
, u_short height
,
2889 u_short line_length
)
2891 u_short nwidth
, nheight
;
2898 nheight
= height
- 1;
2901 /* if source adr < dest addr, do the Blt backwards */
2902 if (cury
<= desty
) {
2903 if (cury
== desty
) {
2904 /* if src and dest are on the same line, check x */
2911 /* standard case: forward blitting */
2912 nsrc
= (cury
* line_length
) + curx
;
2913 ndest
= (desty
* line_length
) + destx
;
2915 /* this means start addresses are at the end,
2916 * counting backwards
2918 nsrc
= cury
* line_length
+ curx
+
2919 nheight
* line_length
+ nwidth
;
2920 ndest
= desty
* line_length
+ destx
+
2921 nheight
* line_length
+ nwidth
;
2925 run-down of registers to be programmed:
2933 VGA_GFX_SR_VALUE / VGA_GFX_SR_ENABLE: "fill color"
2937 cirrusfb_WaitBLT(regbase
);
2939 /* pitch: set to line_length */
2940 /* dest pitch low */
2941 vga_wgfx(regbase
, CL_GR24
, line_length
& 0xff);
2943 vga_wgfx(regbase
, CL_GR25
, line_length
>> 8);
2944 /* source pitch low */
2945 vga_wgfx(regbase
, CL_GR26
, line_length
& 0xff);
2946 /* source pitch hi */
2947 vga_wgfx(regbase
, CL_GR27
, line_length
>> 8);
2949 /* BLT width: actual number of pixels - 1 */
2951 vga_wgfx(regbase
, CL_GR20
, nwidth
& 0xff);
2953 vga_wgfx(regbase
, CL_GR21
, nwidth
>> 8);
2955 /* BLT height: actual number of lines -1 */
2956 /* BLT height low */
2957 vga_wgfx(regbase
, CL_GR22
, nheight
& 0xff);
2959 vga_wgfx(regbase
, CL_GR23
, nheight
>> 8);
2961 /* BLT destination */
2963 vga_wgfx(regbase
, CL_GR28
, (u_char
) (ndest
& 0xff));
2965 vga_wgfx(regbase
, CL_GR29
, (u_char
) (ndest
>> 8));
2967 vga_wgfx(regbase
, CL_GR2A
, (u_char
) (ndest
>> 16));
2971 vga_wgfx(regbase
, CL_GR2C
, (u_char
) (nsrc
& 0xff));
2973 vga_wgfx(regbase
, CL_GR2D
, (u_char
) (nsrc
>> 8));
2975 vga_wgfx(regbase
, CL_GR2E
, (u_char
) (nsrc
>> 16));
2978 vga_wgfx(regbase
, CL_GR30
, bltmode
); /* BLT mode */
2980 /* BLT ROP: SrcCopy */
2981 vga_wgfx(regbase
, CL_GR32
, 0x0d); /* BLT ROP */
2983 /* and finally: GO! */
2984 vga_wgfx(regbase
, CL_GR31
, 0x02); /* BLT Start/status */
2989 /*******************************************************************
2992 perform accelerated rectangle fill
2993 ********************************************************************/
2995 static void cirrusfb_RectFill(u8 __iomem
*regbase
, int bits_per_pixel
,
2996 u_short x
, u_short y
, u_short width
, u_short height
,
2997 u_char color
, u_short line_length
)
2999 u_short nwidth
, nheight
;
3006 nheight
= height
- 1;
3008 ndest
= (y
* line_length
) + x
;
3010 cirrusfb_WaitBLT(regbase
);
3012 /* pitch: set to line_length */
3013 vga_wgfx(regbase
, CL_GR24
, line_length
& 0xff); /* dest pitch low */
3014 vga_wgfx(regbase
, CL_GR25
, line_length
>> 8); /* dest pitch hi */
3015 vga_wgfx(regbase
, CL_GR26
, line_length
& 0xff); /* source pitch low */
3016 vga_wgfx(regbase
, CL_GR27
, line_length
>> 8); /* source pitch hi */
3018 /* BLT width: actual number of pixels - 1 */
3019 vga_wgfx(regbase
, CL_GR20
, nwidth
& 0xff); /* BLT width low */
3020 vga_wgfx(regbase
, CL_GR21
, nwidth
>> 8); /* BLT width hi */
3022 /* BLT height: actual number of lines -1 */
3023 vga_wgfx(regbase
, CL_GR22
, nheight
& 0xff); /* BLT height low */
3024 vga_wgfx(regbase
, CL_GR23
, nheight
>> 8); /* BLT width hi */
3026 /* BLT destination */
3028 vga_wgfx(regbase
, CL_GR28
, (u_char
) (ndest
& 0xff));
3030 vga_wgfx(regbase
, CL_GR29
, (u_char
) (ndest
>> 8));
3032 vga_wgfx(regbase
, CL_GR2A
, (u_char
) (ndest
>> 16));
3034 /* BLT source: set to 0 (is a dummy here anyway) */
3035 vga_wgfx(regbase
, CL_GR2C
, 0x00); /* BLT src low */
3036 vga_wgfx(regbase
, CL_GR2D
, 0x00); /* BLT src mid */
3037 vga_wgfx(regbase
, CL_GR2E
, 0x00); /* BLT src hi */
3039 /* This is a ColorExpand Blt, using the */
3040 /* same color for foreground and background */
3041 vga_wgfx(regbase
, VGA_GFX_SR_VALUE
, color
); /* foreground color */
3042 vga_wgfx(regbase
, VGA_GFX_SR_ENABLE
, color
); /* background color */
3045 if (bits_per_pixel
== 16) {
3046 vga_wgfx(regbase
, CL_GR10
, color
); /* foreground color */
3047 vga_wgfx(regbase
, CL_GR11
, color
); /* background color */
3050 } else if (bits_per_pixel
== 32) {
3051 vga_wgfx(regbase
, CL_GR10
, color
); /* foreground color */
3052 vga_wgfx(regbase
, CL_GR11
, color
); /* background color */
3053 vga_wgfx(regbase
, CL_GR12
, color
); /* foreground color */
3054 vga_wgfx(regbase
, CL_GR13
, color
); /* background color */
3055 vga_wgfx(regbase
, CL_GR14
, 0); /* foreground color */
3056 vga_wgfx(regbase
, CL_GR15
, 0); /* background color */
3060 /* BLT mode: color expand, Enable 8x8 copy (faster?) */
3061 vga_wgfx(regbase
, CL_GR30
, op
); /* BLT mode */
3063 /* BLT ROP: SrcCopy */
3064 vga_wgfx(regbase
, CL_GR32
, 0x0d); /* BLT ROP */
3066 /* and finally: GO! */
3067 vga_wgfx(regbase
, CL_GR31
, 0x02); /* BLT Start/status */
3072 /**************************************************************************
3073 * bestclock() - determine closest possible clock lower(?) than the
3074 * desired pixel clock
3075 **************************************************************************/
3076 static void bestclock(long freq
, long *best
, long *nom
,
3077 long *den
, long *div
, long maxfreq
)
3081 assert(best
!= NULL
);
3082 assert(nom
!= NULL
);
3083 assert(den
!= NULL
);
3084 assert(div
!= NULL
);
3085 assert(maxfreq
> 0);
3102 for (n
= 32; n
< 128; n
++) {
3103 d
= (143181 * n
) / f
;
3104 if ((d
>= 7) && (d
<= 63)) {
3107 h
= (14318 * n
) / d
;
3108 if (abs(h
- freq
) < abs(*best
- freq
)) {
3120 d
= DIV_ROUND_UP(143181 * n
, f
);
3121 if ((d
>= 7) && (d
<= 63)) {
3124 h
= (14318 * n
) / d
;
3125 if (abs(h
- freq
) < abs(*best
- freq
)) {
3139 DPRINTK("Best possible values for given frequency:\n");
3140 DPRINTK(" best: %ld kHz nom: %ld den: %ld div: %ld\n",
3141 freq
, *nom
, *den
, *div
);
3146 /* -------------------------------------------------------------------------
3148 * debugging functions
3150 * -------------------------------------------------------------------------
3153 #ifdef CIRRUSFB_DEBUG
3156 * cirrusfb_dbg_print_byte
3157 * @name: name associated with byte value to be displayed
3158 * @val: byte value to be displayed
3161 * Display an indented string, along with a hexidecimal byte value, and
3162 * its decoded bits. Bits 7 through 0 are listed in left-to-right
3167 void cirrusfb_dbg_print_byte(const char *name
, unsigned char val
)
3169 DPRINTK("%8s = 0x%02X (bits 7-0: %c%c%c%c%c%c%c%c)\n",
3171 val
& 0x80 ? '1' : '0',
3172 val
& 0x40 ? '1' : '0',
3173 val
& 0x20 ? '1' : '0',
3174 val
& 0x10 ? '1' : '0',
3175 val
& 0x08 ? '1' : '0',
3176 val
& 0x04 ? '1' : '0',
3177 val
& 0x02 ? '1' : '0',
3178 val
& 0x01 ? '1' : '0');
3182 * cirrusfb_dbg_print_regs
3183 * @base: If using newmmio, the newmmio base address, otherwise %NULL
3184 * @reg_class: type of registers to read: %CRT, or %SEQ
3187 * Dumps the given list of VGA CRTC registers. If @base is %NULL,
3188 * old-style I/O ports are queried for information, otherwise MMIO is
3189 * used at the given @base address to query the information.
3193 void cirrusfb_dbg_print_regs(caddr_t regbase
,
3194 enum cirrusfb_dbg_reg_class reg_class
, ...)
3197 unsigned char val
= 0;
3201 va_start(list
, reg_class
);
3203 name
= va_arg(list
, char *);
3204 while (name
!= NULL
) {
3205 reg
= va_arg(list
, int);
3207 switch (reg_class
) {
3209 val
= vga_rcrt(regbase
, (unsigned char) reg
);
3212 val
= vga_rseq(regbase
, (unsigned char) reg
);
3215 /* should never occur */
3220 cirrusfb_dbg_print_byte(name
, val
);
3222 name
= va_arg(list
, char *);
3235 static void cirrusfb_dump(void)
3237 cirrusfb_dbg_reg_dump(NULL
);
3241 * cirrusfb_dbg_reg_dump
3242 * @base: If using newmmio, the newmmio base address, otherwise %NULL
3245 * Dumps a list of interesting VGA and CIRRUSFB registers. If @base is %NULL,
3246 * old-style I/O ports are queried for information, otherwise MMIO is
3247 * used at the given @base address to query the information.
3251 void cirrusfb_dbg_reg_dump(caddr_t regbase
)
3253 DPRINTK("CIRRUSFB VGA CRTC register dump:\n");
3255 cirrusfb_dbg_print_regs(regbase
, CRT
,
3307 DPRINTK("CIRRUSFB VGA SEQ register dump:\n");
3309 cirrusfb_dbg_print_regs(regbase
, SEQ
,
3341 #endif /* CIRRUSFB_DEBUG */