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/config.h>
40 #include <linux/module.h>
41 #include <linux/kernel.h>
42 #include <linux/errno.h>
43 #include <linux/string.h>
45 #include <linux/tty.h>
46 #include <linux/slab.h>
47 #include <linux/delay.h>
49 #include <linux/init.h>
50 #include <linux/selection.h>
51 #include <asm/pgtable.h>
54 #include <linux/zorro.h>
57 #include <linux/pci.h>
60 #include <asm/amigahw.h>
62 #ifdef CONFIG_PPC_PREP
63 #include <asm/processor.h>
64 #define isPReP (_machine == _MACH_prep)
69 #include "video/vga.h"
70 #include "video/cirrus.h"
73 /*****************************************************************
75 * debugging and utility macros
79 /* enable debug output? */
80 /* #define CIRRUSFB_DEBUG 1 */
82 /* disable runtime assertions? */
83 /* #define CIRRUSFB_NDEBUG */
87 #define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
89 #define DPRINTK(fmt, args...)
92 /* debugging assertions */
93 #ifndef CIRRUSFB_NDEBUG
94 #define assert(expr) \
96 printk( "Assertion failed! %s,%s,%s,line=%d\n",\
97 #expr,__FILE__,__FUNCTION__,__LINE__); \
112 #define MB_ (1024*1024)
115 #define MAX_NUM_BOARDS 7
118 /*****************************************************************
120 * chipset information
131 BT_PICASSO4, /* GD5446 */
132 BT_ALPINE, /* GD543x/4x */
134 BT_LAGUNA, /* GD546x */
139 * per-board-type information, used for enumerating and abstracting
140 * chip-specific information
141 * NOTE: MUST be in the same order as cirrusfb_board_t in order to
142 * use direct indexing on this array
143 * NOTE: '__initdata' cannot be used as some of this info
144 * is required at runtime. Maybe separate into an init-only and
147 static const struct cirrusfb_board_info_rec {
148 char *name; /* ASCII name of chipset */
149 long maxclock[5]; /* maximum video clock */
150 /* for 1/4bpp, 8bpp 15/16bpp, 24bpp, 32bpp - numbers from xorg code */
151 unsigned init_sr07 : 1; /* init SR07 during init_vgachip() */
152 unsigned init_sr1f : 1; /* write SR1F during init_vgachip() */
153 unsigned scrn_start_bit19 : 1; /* construct bit 19 of screen start address */
155 /* initial SR07 value, then for each mode */
157 unsigned char sr07_1bpp;
158 unsigned char sr07_1bpp_mux;
159 unsigned char sr07_8bpp;
160 unsigned char sr07_8bpp_mux;
162 unsigned char sr1f; /* SR1F VGA initial register value */
163 } cirrusfb_board_info[] = {
168 /* the SD64/P4 have a higher max. videoclock */
169 140000, 140000, 140000, 140000, 140000,
173 .scrn_start_bit19 = TRUE,
180 .name = "CL Piccolo",
183 90000, 90000, 90000, 90000, 90000
187 .scrn_start_bit19 = FALSE,
194 .name = "CL Picasso",
197 90000, 90000, 90000, 90000, 90000
201 .scrn_start_bit19 = FALSE,
208 .name = "CL Spectrum",
211 90000, 90000, 90000, 90000, 90000
215 .scrn_start_bit19 = FALSE,
222 .name = "CL Picasso4",
224 135100, 135100, 85500, 85500, 0
228 .scrn_start_bit19 = TRUE,
237 /* for the GD5430. GD5446 can do more... */
238 85500, 85500, 50000, 28500, 0
242 .scrn_start_bit19 = TRUE,
245 .sr07_1bpp_mux = 0xA7,
247 .sr07_8bpp_mux = 0xA7,
253 135100, 200000, 200000, 135100, 135100
257 .scrn_start_bit19 = TRUE,
267 135100, 135100, 135100, 135100, 135100,
271 .scrn_start_bit19 = TRUE,
277 #define CHIP(id, btype) \
278 { PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_##id, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (btype) }
280 static struct pci_device_id cirrusfb_pci_table[] = {
281 CHIP( CIRRUS_5436, BT_ALPINE ),
282 CHIP( CIRRUS_5434_8, BT_ALPINE ),
283 CHIP( CIRRUS_5434_4, BT_ALPINE ),
284 CHIP( CIRRUS_5430, BT_ALPINE ), /* GD-5440 has identical id */
285 CHIP( CIRRUS_7543, BT_ALPINE ),
286 CHIP( CIRRUS_7548, BT_ALPINE ),
287 CHIP( CIRRUS_5480, BT_GD5480 ), /* MacPicasso probably */
288 CHIP( CIRRUS_5446, BT_PICASSO4 ), /* Picasso 4 is a GD5446 */
289 CHIP( CIRRUS_5462, BT_LAGUNA ), /* CL Laguna */
290 CHIP( CIRRUS_5464, BT_LAGUNA ), /* CL Laguna 3D */
291 CHIP( CIRRUS_5465, BT_LAGUNA ), /* CL Laguna 3DA*/
294 MODULE_DEVICE_TABLE(pci, cirrusfb_pci_table);
296 #endif /* CONFIG_PCI */
300 static const struct zorro_device_id cirrusfb_zorro_table[] = {
302 .id = ZORRO_PROD_HELFRICH_SD64_RAM,
303 .driver_data = BT_SD64,
305 .id = ZORRO_PROD_HELFRICH_PICCOLO_RAM,
306 .driver_data = BT_PICCOLO,
308 .id = ZORRO_PROD_VILLAGE_TRONIC_PICASSO_II_II_PLUS_RAM,
309 .driver_data = BT_PICASSO,
311 .id = ZORRO_PROD_GVP_EGS_28_24_SPECTRUM_RAM,
312 .driver_data = BT_SPECTRUM,
314 .id = ZORRO_PROD_VILLAGE_TRONIC_PICASSO_IV_Z3,
315 .driver_data = BT_PICASSO4,
320 static const struct {
323 } cirrusfb_zorro_table2[] = {
325 .id2 = ZORRO_PROD_HELFRICH_SD64_REG,
329 .id2 = ZORRO_PROD_HELFRICH_PICCOLO_REG,
333 .id2 = ZORRO_PROD_VILLAGE_TRONIC_PICASSO_II_II_PLUS_REG,
337 .id2 = ZORRO_PROD_GVP_EGS_28_24_SPECTRUM_REG,
345 #endif /* CONFIG_ZORRO */
348 struct cirrusfb_regs {
349 __u32 line_length; /* in BYTES! */
361 long HorizRes; /* The x resolution in pixel */
364 long HorizBlankStart;
369 long VertRes; /* the physical y resolution in scanlines */
380 #ifdef CIRRUSFB_DEBUG
384 } cirrusfb_dbg_reg_class_t;
385 #endif /* CIRRUSFB_DEBUG */
390 /* info about board */
391 struct cirrusfb_info {
392 struct fb_info *info;
398 cirrusfb_board_t btype;
399 unsigned char SFR; /* Shadow of special function register */
401 unsigned long fbmem_phys;
402 unsigned long fbregs_phys;
404 struct cirrusfb_regs currentmode;
407 u32 pseudo_palette[17];
408 struct { u8 red, green, blue, pad; } palette[256];
411 struct zorro_dev *zdev;
414 struct pci_dev *pdev;
416 void (*unmap)(struct cirrusfb_info *cinfo);
420 static unsigned cirrusfb_def_mode = 1;
421 static int noaccel = 0;
424 * Predefined Video Modes
427 static const struct {
429 struct fb_var_screeninfo var;
430 } cirrusfb_predefined[] = {
432 /* autodetect mode */
433 .name = "Autodetect",
435 /* 640x480, 31.25 kHz, 60 Hz, 25 MHz PixClock */
443 .red = { .length = 8 },
444 .green = { .length = 8 },
445 .blue = { .length = 8 },
455 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
456 .vmode = FB_VMODE_NONINTERLACED
459 /* 800x600, 48 kHz, 76 Hz, 50 MHz PixClock */
467 .red = { .length = 8 },
468 .green = { .length = 8 },
469 .blue = { .length = 8 },
479 .vmode = FB_VMODE_NONINTERLACED
483 * Modeline from XF86Config:
484 * Mode "1024x768" 80 1024 1136 1340 1432 768 770 774 805
486 /* 1024x768, 55.8 kHz, 70 Hz, 80 MHz PixClock */
491 .xres_virtual = 1024,
494 .red = { .length = 8 },
495 .green = { .length = 8 },
496 .blue = { .length = 8 },
506 .vmode = FB_VMODE_NONINTERLACED
511 #define NUM_TOTAL_MODES ARRAY_SIZE(cirrusfb_predefined)
513 /****************************************************************************/
514 /**** BEGIN PROTOTYPES ******************************************************/
517 /*--- Interface used by the world ------------------------------------------*/
518 int cirrusfb_init (void);
519 int cirrusfb_setup (char *options);
521 int cirrusfb_open (struct fb_info *info, int user);
522 int cirrusfb_release (struct fb_info *info, int user);
523 int cirrusfb_setcolreg (unsigned regno, unsigned red, unsigned green,
524 unsigned blue, unsigned transp,
525 struct fb_info *info);
526 int cirrusfb_check_var (struct fb_var_screeninfo *var,
527 struct fb_info *info);
528 int cirrusfb_set_par (struct fb_info *info);
529 int cirrusfb_pan_display (struct fb_var_screeninfo *var,
530 struct fb_info *info);
531 int cirrusfb_blank (int blank_mode, struct fb_info *info);
532 void cirrusfb_fillrect (struct fb_info *info, const struct fb_fillrect *region);
533 void cirrusfb_copyarea(struct fb_info *info, const struct fb_copyarea *area);
534 void cirrusfb_imageblit(struct fb_info *info, const struct fb_image *image);
536 /* function table of the above functions */
537 static struct fb_ops cirrusfb_ops = {
538 .owner = THIS_MODULE,
539 .fb_open = cirrusfb_open,
540 .fb_release = cirrusfb_release,
541 .fb_setcolreg = cirrusfb_setcolreg,
542 .fb_check_var = cirrusfb_check_var,
543 .fb_set_par = cirrusfb_set_par,
544 .fb_pan_display = cirrusfb_pan_display,
545 .fb_blank = cirrusfb_blank,
546 .fb_fillrect = cirrusfb_fillrect,
547 .fb_copyarea = cirrusfb_copyarea,
548 .fb_imageblit = cirrusfb_imageblit,
549 .fb_cursor = soft_cursor,
552 /*--- Hardware Specific Routines -------------------------------------------*/
553 static int cirrusfb_decode_var (const struct fb_var_screeninfo *var,
554 struct cirrusfb_regs *regs,
555 const struct fb_info *info);
556 /*--- Internal routines ----------------------------------------------------*/
557 static void init_vgachip (struct cirrusfb_info *cinfo);
558 static void switch_monitor (struct cirrusfb_info *cinfo, int on);
559 static void WGen (const struct cirrusfb_info *cinfo,
560 int regnum, unsigned char val);
561 static unsigned char RGen (const struct cirrusfb_info *cinfo, int regnum);
562 static void AttrOn (const struct cirrusfb_info *cinfo);
563 static void WHDR (const struct cirrusfb_info *cinfo, unsigned char val);
564 static void WSFR (struct cirrusfb_info *cinfo, unsigned char val);
565 static void WSFR2 (struct cirrusfb_info *cinfo, unsigned char val);
566 static void WClut (struct cirrusfb_info *cinfo, unsigned char regnum, unsigned char red,
570 static void RClut (struct cirrusfb_info *cinfo, unsigned char regnum, unsigned char *red,
571 unsigned char *green,
572 unsigned char *blue);
574 static void cirrusfb_WaitBLT (caddr_t regbase);
575 static void cirrusfb_BitBLT (caddr_t regbase, int bits_per_pixel,
576 u_short curx, u_short cury,
577 u_short destx, u_short desty,
578 u_short width, u_short height,
579 u_short line_length);
580 static void cirrusfb_RectFill (caddr_t regbase, int bits_per_pixel,
581 u_short x, u_short y,
582 u_short width, u_short height,
583 u_char color, u_short line_length);
585 static void bestclock (long freq, long *best,
586 long *nom, long *den,
587 long *div, long maxfreq);
589 #ifdef CIRRUSFB_DEBUG
590 static void cirrusfb_dump (void);
591 static void cirrusfb_dbg_reg_dump (caddr_t regbase);
592 static void cirrusfb_dbg_print_regs (caddr_t regbase, cirrusfb_dbg_reg_class_t reg_class,...);
593 static void cirrusfb_dbg_print_byte (const char *name, unsigned char val);
594 #endif /* CIRRUSFB_DEBUG */
596 /*** END PROTOTYPES ********************************************************/
597 /*****************************************************************************/
598 /*** BEGIN Interface Used by the World ***************************************/
600 static int opencount = 0;
602 /*--- Open /dev/fbx ---------------------------------------------------------*/
603 int cirrusfb_open (struct fb_info *info, int user)
605 if (opencount++ == 0)
606 switch_monitor (info->par, 1);
610 /*--- Close /dev/fbx --------------------------------------------------------*/
611 int cirrusfb_release (struct fb_info *info, int user)
613 if (--opencount == 0)
614 switch_monitor (info->par, 0);
618 /**** END Interface used by the World *************************************/
619 /****************************************************************************/
620 /**** BEGIN Hardware specific Routines **************************************/
622 /* Get a good MCLK value */
623 static long cirrusfb_get_mclk (long freq, int bpp, long *div)
627 assert (div != NULL);
629 /* Calculate MCLK, in case VCLK is high enough to require > 50MHz.
630 * Assume a 64-bit data path for now. The formula is:
631 * ((B * PCLK * 2)/W) * 1.2
632 * B = bytes per pixel, PCLK = pixclock, W = data width in bytes */
633 mclk = ((bpp / 8) * freq * 2) / 4;
634 mclk = (mclk * 12) / 10;
637 DPRINTK ("Use MCLK of %ld kHz\n", mclk);
639 /* Calculate value for SR1F. Multiply by 2 so we can round up. */
640 mclk = ((mclk * 16) / 14318);
641 mclk = (mclk + 1) / 2;
642 DPRINTK ("Set SR1F[5:0] to 0x%lx\n", mclk);
644 /* Determine if we should use MCLK instead of VCLK, and if so, what we
645 * should divide it by to get VCLK */
647 case 24751 ... 25249:
649 DPRINTK ("Using VCLK = MCLK/2\n");
651 case 49501 ... 50499:
653 DPRINTK ("Using VCLK = MCLK\n");
663 int cirrusfb_check_var(struct fb_var_screeninfo *var,
664 struct fb_info *info)
666 struct cirrusfb_info *cinfo = info->par;
667 int nom, den; /* translyting from pixels->bytes */
669 static struct { int xres, yres; } modes[] =
677 switch (var->bits_per_pixel) {
679 var->bits_per_pixel = 1;
682 break; /* 8 pixel per byte, only 1/4th of mem usable */
684 var->bits_per_pixel = 8;
687 break; /* 1 pixel == 1 byte */
689 var->bits_per_pixel = 16;
692 break; /* 2 bytes per pixel */
694 var->bits_per_pixel = 24;
697 break; /* 3 bytes per pixel */
699 var->bits_per_pixel = 32;
702 break; /* 4 bytes per pixel */
704 printk ("cirrusfb: mode %dx%dx%d rejected...color depth not supported.\n",
705 var->xres, var->yres, var->bits_per_pixel);
706 DPRINTK ("EXIT - EINVAL error\n");
710 if (var->xres * nom / den * var->yres > cinfo->size) {
711 printk ("cirrusfb: mode %dx%dx%d rejected...resolution too high to fit into video memory!\n",
712 var->xres, var->yres, var->bits_per_pixel);
713 DPRINTK ("EXIT - EINVAL error\n");
717 /* use highest possible virtual resolution */
718 if (var->xres_virtual == -1 &&
719 var->yres_virtual == -1) {
720 printk ("cirrusfb: using maximum available virtual resolution\n");
721 for (i = 0; modes[i].xres != -1; i++) {
722 if (modes[i].xres * nom / den * modes[i].yres < cinfo->size / 2)
725 if (modes[i].xres == -1) {
726 printk ("cirrusfb: could not find a virtual resolution that fits into video memory!!\n");
727 DPRINTK ("EXIT - EINVAL error\n");
730 var->xres_virtual = modes[i].xres;
731 var->yres_virtual = modes[i].yres;
733 printk ("cirrusfb: virtual resolution set to maximum of %dx%d\n",
734 var->xres_virtual, var->yres_virtual);
737 if (var->xres_virtual < var->xres)
738 var->xres_virtual = var->xres;
739 if (var->yres_virtual < var->yres)
740 var->yres_virtual = var->yres;
742 if (var->xoffset < 0)
744 if (var->yoffset < 0)
747 /* truncate xoffset and yoffset to maximum if too high */
748 if (var->xoffset > var->xres_virtual - var->xres)
749 var->xoffset = var->xres_virtual - var->xres - 1;
750 if (var->yoffset > var->yres_virtual - var->yres)
751 var->yoffset = var->yres_virtual - var->yres - 1;
753 switch (var->bits_per_pixel) {
760 var->green.offset = 0;
761 var->green.length = 6;
762 var->blue.offset = 0;
763 var->blue.length = 6;
769 var->green.offset = -3;
770 var->blue.offset = 8;
772 var->red.offset = 10;
773 var->green.offset = 5;
774 var->blue.offset = 0;
777 var->green.length = 5;
778 var->blue.length = 5;
784 var->green.offset = 16;
785 var->blue.offset = 24;
787 var->red.offset = 16;
788 var->green.offset = 8;
789 var->blue.offset = 0;
792 var->green.length = 8;
793 var->blue.length = 8;
799 var->green.offset = 16;
800 var->blue.offset = 24;
802 var->red.offset = 16;
803 var->green.offset = 8;
804 var->blue.offset = 0;
807 var->green.length = 8;
808 var->blue.length = 8;
812 DPRINTK("Unsupported bpp size: %d\n", var->bits_per_pixel);
814 /* should never occur */
819 var->green.msb_right =
820 var->blue.msb_right =
823 var->transp.msb_right = 0;
826 if (var->vmode & FB_VMODE_DOUBLE)
828 else if (var->vmode & FB_VMODE_INTERLACED)
829 yres = (yres + 1) / 2;
832 printk (KERN_WARNING "cirrusfb: ERROR: VerticalTotal >= 1280; special treatment required! (TODO)\n");
833 DPRINTK ("EXIT - EINVAL error\n");
840 static int cirrusfb_decode_var (const struct fb_var_screeninfo *var,
841 struct cirrusfb_regs *regs,
842 const struct fb_info *info)
847 struct cirrusfb_info *cinfo = info->par;
848 int xres, hfront, hsync, hback;
849 int yres, vfront, vsync, vback;
851 switch(var->bits_per_pixel) {
853 regs->line_length = var->xres_virtual / 8;
854 regs->visual = FB_VISUAL_MONO10;
859 regs->line_length = var->xres_virtual;
860 regs->visual = FB_VISUAL_PSEUDOCOLOR;
865 regs->line_length = var->xres_virtual * 2;
866 regs->visual = FB_VISUAL_DIRECTCOLOR;
871 regs->line_length = var->xres_virtual * 3;
872 regs->visual = FB_VISUAL_DIRECTCOLOR;
877 regs->line_length = var->xres_virtual * 4;
878 regs->visual = FB_VISUAL_DIRECTCOLOR;
883 DPRINTK("Unsupported bpp size: %d\n", var->bits_per_pixel);
885 /* should never occur */
889 regs->type = FB_TYPE_PACKED_PIXELS;
891 /* convert from ps to kHz */
892 freq = 1000000000 / var->pixclock;
894 DPRINTK ("desired pixclock: %ld kHz\n", freq);
896 maxclock = cirrusfb_board_info[cinfo->btype].maxclock[maxclockidx];
897 regs->multiplexing = 0;
899 /* If the frequency is greater than we can support, we might be able
900 * to use multiplexing for the video mode */
901 if (freq > maxclock) {
902 switch (cinfo->btype) {
905 regs->multiplexing = 1;
909 printk (KERN_WARNING "cirrusfb: ERROR: Frequency greater than maxclock (%ld kHz)\n", maxclock);
910 DPRINTK ("EXIT - return -EINVAL\n");
915 /* TODO: If we have a 1MB 5434, we need to put ourselves in a mode where
916 * the VCLK is double the pixel clock. */
917 switch (var->bits_per_pixel) {
920 if (regs->HorizRes <= 800)
921 freq /= 2; /* Xbh has this type of clock for 32-bit */
926 bestclock (freq, ®s->freq, ®s->nom, ®s->den, ®s->div,
928 regs->mclk = cirrusfb_get_mclk (freq, var->bits_per_pixel, ®s->divMCLK);
931 hfront = var->right_margin;
932 hsync = var->hsync_len;
933 hback = var->left_margin;
936 vfront = var->lower_margin;
937 vsync = var->vsync_len;
938 vback = var->upper_margin;
940 if (var->vmode & FB_VMODE_DOUBLE) {
945 } else if (var->vmode & FB_VMODE_INTERLACED) {
946 yres = (yres + 1) / 2;
947 vfront = (vfront + 1) / 2;
948 vsync = (vsync + 1) / 2;
949 vback = (vback + 1) / 2;
951 regs->HorizRes = xres;
952 regs->HorizTotal = (xres + hfront + hsync + hback) / 8 - 5;
953 regs->HorizDispEnd = xres / 8 - 1;
954 regs->HorizBlankStart = xres / 8;
955 regs->HorizBlankEnd = regs->HorizTotal + 5; /* does not count with "-5" */
956 regs->HorizSyncStart = (xres + hfront) / 8 + 1;
957 regs->HorizSyncEnd = (xres + hfront + hsync) / 8 + 1;
959 regs->VertRes = yres;
960 regs->VertTotal = yres + vfront + vsync + vback - 2;
961 regs->VertDispEnd = yres - 1;
962 regs->VertBlankStart = yres;
963 regs->VertBlankEnd = regs->VertTotal;
964 regs->VertSyncStart = yres + vfront - 1;
965 regs->VertSyncEnd = yres + vfront + vsync - 1;
967 if (regs->VertRes >= 1024) {
968 regs->VertTotal /= 2;
969 regs->VertSyncStart /= 2;
970 regs->VertSyncEnd /= 2;
971 regs->VertDispEnd /= 2;
973 if (regs->multiplexing) {
974 regs->HorizTotal /= 2;
975 regs->HorizSyncStart /= 2;
976 regs->HorizSyncEnd /= 2;
977 regs->HorizDispEnd /= 2;
984 static void cirrusfb_set_mclk (const struct cirrusfb_info *cinfo, int val, int div)
986 assert (cinfo != NULL);
990 unsigned char old = vga_rseq (cinfo->regbase, CL_SEQR1E);
991 vga_wseq (cinfo->regbase, CL_SEQR1E, old | 0x1);
992 vga_wseq (cinfo->regbase, CL_SEQR1F, 0x40 | (val & 0x3f));
993 } else if (div == 1) {
995 unsigned char old = vga_rseq (cinfo->regbase, CL_SEQR1E);
996 vga_wseq (cinfo->regbase, CL_SEQR1E, old & ~0x1);
997 vga_wseq (cinfo->regbase, CL_SEQR1F, 0x40 | (val & 0x3f));
999 vga_wseq (cinfo->regbase, CL_SEQR1F, val & 0x3f);
1003 /*************************************************************************
1004 cirrusfb_set_par_foo()
1006 actually writes the values for a new video mode into the hardware,
1007 **************************************************************************/
1008 static int cirrusfb_set_par_foo (struct fb_info *info)
1010 struct cirrusfb_info *cinfo = info->par;
1011 struct fb_var_screeninfo *var = &info->var;
1012 struct cirrusfb_regs regs;
1013 caddr_t regbase = cinfo->regbase;
1015 int offset = 0, err;
1016 const struct cirrusfb_board_info_rec *bi;
1018 DPRINTK ("ENTER\n");
1019 DPRINTK ("Requested mode: %dx%dx%d\n",
1020 var->xres, var->yres, var->bits_per_pixel);
1021 DPRINTK ("pixclock: %d\n", var->pixclock);
1023 init_vgachip (cinfo);
1025 err = cirrusfb_decode_var(var, ®s, info);
1027 /* should never happen */
1028 DPRINTK("mode change aborted. invalid var.\n");
1032 bi = &cirrusfb_board_info[cinfo->btype];
1035 /* unlock register VGA_CRTC_H_TOTAL..CRT7 */
1036 vga_wcrt (regbase, VGA_CRTC_V_SYNC_END, 0x20); /* previously: 0x00) */
1038 /* if debugging is enabled, all parameters get output before writing */
1039 DPRINTK ("CRT0: %ld\n", regs.HorizTotal);
1040 vga_wcrt (regbase, VGA_CRTC_H_TOTAL, regs.HorizTotal);
1042 DPRINTK ("CRT1: %ld\n", regs.HorizDispEnd);
1043 vga_wcrt (regbase, VGA_CRTC_H_DISP, regs.HorizDispEnd);
1045 DPRINTK ("CRT2: %ld\n", regs.HorizBlankStart);
1046 vga_wcrt (regbase, VGA_CRTC_H_BLANK_START, regs.HorizBlankStart);
1048 DPRINTK ("CRT3: 128+%ld\n", regs.HorizBlankEnd % 32); /* + 128: Compatible read */
1049 vga_wcrt (regbase, VGA_CRTC_H_BLANK_END, 128 + (regs.HorizBlankEnd % 32));
1051 DPRINTK ("CRT4: %ld\n", regs.HorizSyncStart);
1052 vga_wcrt (regbase, VGA_CRTC_H_SYNC_START, regs.HorizSyncStart);
1054 tmp = regs.HorizSyncEnd % 32;
1055 if (regs.HorizBlankEnd & 32)
1057 DPRINTK ("CRT5: %d\n", tmp);
1058 vga_wcrt (regbase, VGA_CRTC_H_SYNC_END, tmp);
1060 DPRINTK ("CRT6: %ld\n", regs.VertTotal & 0xff);
1061 vga_wcrt (regbase, VGA_CRTC_V_TOTAL, (regs.VertTotal & 0xff));
1063 tmp = 16; /* LineCompare bit #9 */
1064 if (regs.VertTotal & 256)
1066 if (regs.VertDispEnd & 256)
1068 if (regs.VertSyncStart & 256)
1070 if (regs.VertBlankStart & 256)
1072 if (regs.VertTotal & 512)
1074 if (regs.VertDispEnd & 512)
1076 if (regs.VertSyncStart & 512)
1078 DPRINTK ("CRT7: %d\n", tmp);
1079 vga_wcrt (regbase, VGA_CRTC_OVERFLOW, tmp);
1081 tmp = 0x40; /* LineCompare bit #8 */
1082 if (regs.VertBlankStart & 512)
1084 if (var->vmode & FB_VMODE_DOUBLE)
1086 DPRINTK ("CRT9: %d\n", tmp);
1087 vga_wcrt (regbase, VGA_CRTC_MAX_SCAN, tmp);
1089 DPRINTK ("CRT10: %ld\n", regs.VertSyncStart & 0xff);
1090 vga_wcrt (regbase, VGA_CRTC_V_SYNC_START, (regs.VertSyncStart & 0xff));
1092 DPRINTK ("CRT11: 64+32+%ld\n", regs.VertSyncEnd % 16);
1093 vga_wcrt (regbase, VGA_CRTC_V_SYNC_END, (regs.VertSyncEnd % 16 + 64 + 32));
1095 DPRINTK ("CRT12: %ld\n", regs.VertDispEnd & 0xff);
1096 vga_wcrt (regbase, VGA_CRTC_V_DISP_END, (regs.VertDispEnd & 0xff));
1098 DPRINTK ("CRT15: %ld\n", regs.VertBlankStart & 0xff);
1099 vga_wcrt (regbase, VGA_CRTC_V_BLANK_START, (regs.VertBlankStart & 0xff));
1101 DPRINTK ("CRT16: %ld\n", regs.VertBlankEnd & 0xff);
1102 vga_wcrt (regbase, VGA_CRTC_V_BLANK_END, (regs.VertBlankEnd & 0xff));
1104 DPRINTK ("CRT18: 0xff\n");
1105 vga_wcrt (regbase, VGA_CRTC_LINE_COMPARE, 0xff);
1108 if (var->vmode & FB_VMODE_INTERLACED)
1110 if (regs.HorizBlankEnd & 64)
1112 if (regs.HorizBlankEnd & 128)
1114 if (regs.VertBlankEnd & 256)
1116 if (regs.VertBlankEnd & 512)
1119 DPRINTK ("CRT1a: %d\n", tmp);
1120 vga_wcrt (regbase, CL_CRT1A, tmp);
1123 /* hardware RefClock: 14.31818 MHz */
1124 /* formula: VClk = (OSC * N) / (D * (1+P)) */
1125 /* Example: VClk = (14.31818 * 91) / (23 * (1+1)) = 28.325 MHz */
1127 vga_wseq (regbase, CL_SEQRB, regs.nom);
1128 tmp = regs.den << 1;
1132 if ((cinfo->btype == BT_SD64) ||
1133 (cinfo->btype == BT_ALPINE) ||
1134 (cinfo->btype == BT_GD5480))
1135 tmp |= 0x80; /* 6 bit denom; ONLY 5434!!! (bugged me 10 days) */
1137 DPRINTK ("CL_SEQR1B: %ld\n", (long) tmp);
1138 vga_wseq (regbase, CL_SEQR1B, tmp);
1140 if (regs.VertRes >= 1024)
1142 vga_wcrt (regbase, VGA_CRTC_MODE, 0xc7);
1144 /* mode control: VGA_CRTC_START_HI enable, ROTATE(?), 16bit
1145 * address wrap, no compat. */
1146 vga_wcrt (regbase, VGA_CRTC_MODE, 0xc3);
1148 /* HAEH? vga_wcrt (regbase, VGA_CRTC_V_SYNC_END, 0x20); * previously: 0x00 unlock VGA_CRTC_H_TOTAL..CRT7 */
1150 /* don't know if it would hurt to also program this if no interlaced */
1151 /* mode is used, but I feel better this way.. :-) */
1152 if (var->vmode & FB_VMODE_INTERLACED)
1153 vga_wcrt (regbase, VGA_CRTC_REGS, regs.HorizTotal / 2);
1155 vga_wcrt (regbase, VGA_CRTC_REGS, 0x00); /* interlace control */
1157 vga_wseq (regbase, VGA_SEQ_CHARACTER_MAP, 0);
1159 /* adjust horizontal/vertical sync type (low/high) */
1160 tmp = 0x03; /* enable display memory & CRTC I/O address for color mode */
1161 if (var->sync & FB_SYNC_HOR_HIGH_ACT)
1163 if (var->sync & FB_SYNC_VERT_HIGH_ACT)
1165 WGen (cinfo, VGA_MIS_W, tmp);
1167 vga_wcrt (regbase, VGA_CRTC_PRESET_ROW, 0); /* Screen A Preset Row-Scan register */
1168 vga_wcrt (regbase, VGA_CRTC_CURSOR_START, 0); /* text cursor on and start line */
1169 vga_wcrt (regbase, VGA_CRTC_CURSOR_END, 31); /* text cursor end line */
1171 /******************************************************
1177 /* programming for different color depths */
1178 if (var->bits_per_pixel == 1) {
1179 DPRINTK ("cirrusfb: preparing for 1 bit deep display\n");
1180 vga_wgfx (regbase, VGA_GFX_MODE, 0); /* mode register */
1183 switch (cinfo->btype) {
1191 DPRINTK (" (for GD54xx)\n");
1192 vga_wseq (regbase, CL_SEQR7,
1194 bi->sr07_1bpp_mux : bi->sr07_1bpp);
1198 DPRINTK (" (for GD546x)\n");
1199 vga_wseq (regbase, CL_SEQR7,
1200 vga_rseq (regbase, CL_SEQR7) & ~0x01);
1204 printk (KERN_WARNING "cirrusfb: unknown Board\n");
1208 /* Extended Sequencer Mode */
1209 switch (cinfo->btype) {
1211 /* setting the SEQRF on SD64 is not necessary (only during init) */
1212 DPRINTK ("(for SD64)\n");
1213 vga_wseq (regbase, CL_SEQR1F, 0x1a); /* MCLK select */
1217 DPRINTK ("(for Piccolo)\n");
1218 /* ### ueberall 0x22? */
1219 vga_wseq (regbase, CL_SEQR1F, 0x22); /* ##vorher 1c MCLK select */
1220 vga_wseq (regbase, CL_SEQRF, 0xb0); /* evtl d0 bei 1 bit? avoid FIFO underruns..? */
1224 DPRINTK ("(for Picasso)\n");
1225 vga_wseq (regbase, CL_SEQR1F, 0x22); /* ##vorher 22 MCLK select */
1226 vga_wseq (regbase, CL_SEQRF, 0xd0); /* ## vorher d0 avoid FIFO underruns..? */
1230 DPRINTK ("(for Spectrum)\n");
1231 /* ### ueberall 0x22? */
1232 vga_wseq (regbase, CL_SEQR1F, 0x22); /* ##vorher 1c MCLK select */
1233 vga_wseq (regbase, CL_SEQRF, 0xb0); /* evtl d0? avoid FIFO underruns..? */
1240 DPRINTK (" (for GD54xx)\n");
1245 printk (KERN_WARNING "cirrusfb: unknown Board\n");
1249 WGen (cinfo, VGA_PEL_MSK, 0x01); /* pixel mask: pass-through for first plane */
1250 if (regs.multiplexing)
1251 WHDR (cinfo, 0x4a); /* hidden dac reg: 1280x1024 */
1253 WHDR (cinfo, 0); /* hidden dac: nothing */
1254 vga_wseq (regbase, VGA_SEQ_MEMORY_MODE, 0x06); /* memory mode: odd/even, ext. memory */
1255 vga_wseq (regbase, VGA_SEQ_PLANE_WRITE, 0x01); /* plane mask: only write to first plane */
1256 offset = var->xres_virtual / 16;
1259 /******************************************************
1265 else if (var->bits_per_pixel == 8) {
1266 DPRINTK ("cirrusfb: preparing for 8 bit deep display\n");
1267 switch (cinfo->btype) {
1275 DPRINTK (" (for GD54xx)\n");
1276 vga_wseq (regbase, CL_SEQR7,
1278 bi->sr07_8bpp_mux : bi->sr07_8bpp);
1282 DPRINTK (" (for GD546x)\n");
1283 vga_wseq (regbase, CL_SEQR7,
1284 vga_rseq (regbase, CL_SEQR7) | 0x01);
1288 printk (KERN_WARNING "cirrusfb: unknown Board\n");
1292 switch (cinfo->btype) {
1294 vga_wseq (regbase, CL_SEQR1F, 0x1d); /* MCLK select */
1298 vga_wseq (regbase, CL_SEQR1F, 0x22); /* ### vorher 1c MCLK select */
1299 vga_wseq (regbase, CL_SEQRF, 0xb0); /* Fast Page-Mode writes */
1303 vga_wseq (regbase, CL_SEQR1F, 0x22); /* ### vorher 1c MCLK select */
1304 vga_wseq (regbase, CL_SEQRF, 0xb0); /* Fast Page-Mode writes */
1308 vga_wseq (regbase, CL_SEQR1F, 0x22); /* ### vorher 1c MCLK select */
1309 vga_wseq (regbase, CL_SEQRF, 0xb0); /* Fast Page-Mode writes */
1314 vga_wseq (regbase, CL_SEQRF, 0xb8); /* ### INCOMPLETE!! */
1316 /* vga_wseq (regbase, CL_SEQR1F, 0x1c); */
1320 DPRINTK (" (for GD543x)\n");
1321 cirrusfb_set_mclk (cinfo, regs.mclk, regs.divMCLK);
1322 /* We already set SRF and SR1F */
1327 DPRINTK (" (for GD54xx)\n");
1332 printk (KERN_WARNING "cirrusfb: unknown Board\n");
1336 vga_wgfx (regbase, VGA_GFX_MODE, 64); /* mode register: 256 color mode */
1337 WGen (cinfo, VGA_PEL_MSK, 0xff); /* pixel mask: pass-through all planes */
1338 if (regs.multiplexing)
1339 WHDR (cinfo, 0x4a); /* hidden dac reg: 1280x1024 */
1341 WHDR (cinfo, 0); /* hidden dac: nothing */
1342 vga_wseq (regbase, VGA_SEQ_MEMORY_MODE, 0x0a); /* memory mode: chain4, ext. memory */
1343 vga_wseq (regbase, VGA_SEQ_PLANE_WRITE, 0xff); /* plane mask: enable writing to all 4 planes */
1344 offset = var->xres_virtual / 8;
1347 /******************************************************
1353 else if (var->bits_per_pixel == 16) {
1354 DPRINTK ("cirrusfb: preparing for 16 bit deep display\n");
1355 switch (cinfo->btype) {
1357 vga_wseq (regbase, CL_SEQR7, 0xf7); /* Extended Sequencer Mode: 256c col. mode */
1358 vga_wseq (regbase, CL_SEQR1F, 0x1e); /* MCLK select */
1362 vga_wseq (regbase, CL_SEQR7, 0x87);
1363 vga_wseq (regbase, CL_SEQRF, 0xb0); /* Fast Page-Mode writes */
1364 vga_wseq (regbase, CL_SEQR1F, 0x22); /* MCLK select */
1368 vga_wseq (regbase, CL_SEQR7, 0x27);
1369 vga_wseq (regbase, CL_SEQRF, 0xb0); /* Fast Page-Mode writes */
1370 vga_wseq (regbase, CL_SEQR1F, 0x22); /* MCLK select */
1374 vga_wseq (regbase, CL_SEQR7, 0x87);
1375 vga_wseq (regbase, CL_SEQRF, 0xb0); /* Fast Page-Mode writes */
1376 vga_wseq (regbase, CL_SEQR1F, 0x22); /* MCLK select */
1380 vga_wseq (regbase, CL_SEQR7, 0x27);
1381 /* vga_wseq (regbase, CL_SEQR1F, 0x1c); */
1385 DPRINTK (" (for GD543x)\n");
1386 if (regs.HorizRes >= 1024)
1387 vga_wseq (regbase, CL_SEQR7, 0xa7);
1389 vga_wseq (regbase, CL_SEQR7, 0xa3);
1390 cirrusfb_set_mclk (cinfo, regs.mclk, regs.divMCLK);
1394 DPRINTK (" (for GD5480)\n");
1395 vga_wseq (regbase, CL_SEQR7, 0x17);
1396 /* We already set SRF and SR1F */
1400 DPRINTK (" (for GD546x)\n");
1401 vga_wseq (regbase, CL_SEQR7,
1402 vga_rseq (regbase, CL_SEQR7) & ~0x01);
1406 printk (KERN_WARNING "CIRRUSFB: unknown Board\n");
1410 vga_wgfx (regbase, VGA_GFX_MODE, 64); /* mode register: 256 color mode */
1411 WGen (cinfo, VGA_PEL_MSK, 0xff); /* pixel mask: pass-through all planes */
1413 WHDR (cinfo, 0xc0); /* Copy Xbh */
1414 #elif defined(CONFIG_ZORRO)
1415 /* FIXME: CONFIG_PCI and CONFIG_ZORRO may be defined both */
1416 WHDR (cinfo, 0xa0); /* hidden dac reg: nothing special */
1418 vga_wseq (regbase, VGA_SEQ_MEMORY_MODE, 0x0a); /* memory mode: chain4, ext. memory */
1419 vga_wseq (regbase, VGA_SEQ_PLANE_WRITE, 0xff); /* plane mask: enable writing to all 4 planes */
1420 offset = var->xres_virtual / 4;
1423 /******************************************************
1429 else if (var->bits_per_pixel == 32) {
1430 DPRINTK ("cirrusfb: preparing for 24/32 bit deep display\n");
1431 switch (cinfo->btype) {
1433 vga_wseq (regbase, CL_SEQR7, 0xf9); /* Extended Sequencer Mode: 256c col. mode */
1434 vga_wseq (regbase, CL_SEQR1F, 0x1e); /* MCLK select */
1438 vga_wseq (regbase, CL_SEQR7, 0x85);
1439 vga_wseq (regbase, CL_SEQRF, 0xb0); /* Fast Page-Mode writes */
1440 vga_wseq (regbase, CL_SEQR1F, 0x22); /* MCLK select */
1444 vga_wseq (regbase, CL_SEQR7, 0x25);
1445 vga_wseq (regbase, CL_SEQRF, 0xb0); /* Fast Page-Mode writes */
1446 vga_wseq (regbase, CL_SEQR1F, 0x22); /* MCLK select */
1450 vga_wseq (regbase, CL_SEQR7, 0x85);
1451 vga_wseq (regbase, CL_SEQRF, 0xb0); /* Fast Page-Mode writes */
1452 vga_wseq (regbase, CL_SEQR1F, 0x22); /* MCLK select */
1456 vga_wseq (regbase, CL_SEQR7, 0x25);
1457 /* vga_wseq (regbase, CL_SEQR1F, 0x1c); */
1461 DPRINTK (" (for GD543x)\n");
1462 vga_wseq (regbase, CL_SEQR7, 0xa9);
1463 cirrusfb_set_mclk (cinfo, regs.mclk, regs.divMCLK);
1467 DPRINTK (" (for GD5480)\n");
1468 vga_wseq (regbase, CL_SEQR7, 0x19);
1469 /* We already set SRF and SR1F */
1473 DPRINTK (" (for GD546x)\n");
1474 vga_wseq (regbase, CL_SEQR7,
1475 vga_rseq (regbase, CL_SEQR7) & ~0x01);
1479 printk (KERN_WARNING "cirrusfb: unknown Board\n");
1483 vga_wgfx (regbase, VGA_GFX_MODE, 64); /* mode register: 256 color mode */
1484 WGen (cinfo, VGA_PEL_MSK, 0xff); /* pixel mask: pass-through all planes */
1485 WHDR (cinfo, 0xc5); /* hidden dac reg: 8-8-8 mode (24 or 32) */
1486 vga_wseq (regbase, VGA_SEQ_MEMORY_MODE, 0x0a); /* memory mode: chain4, ext. memory */
1487 vga_wseq (regbase, VGA_SEQ_PLANE_WRITE, 0xff); /* plane mask: enable writing to all 4 planes */
1488 offset = var->xres_virtual / 4;
1491 /******************************************************
1493 * unknown/unsupported bpp
1498 printk (KERN_ERR "cirrusfb: What's this?? requested color depth == %d.\n",
1499 var->bits_per_pixel);
1502 vga_wcrt (regbase, VGA_CRTC_OFFSET, offset & 0xff);
1505 tmp |= 0x10; /* offset overflow bit */
1507 vga_wcrt (regbase, CL_CRT1B, tmp); /* screen start addr #16-18, fastpagemode cycles */
1509 if (cinfo->btype == BT_SD64 ||
1510 cinfo->btype == BT_PICASSO4 ||
1511 cinfo->btype == BT_ALPINE ||
1512 cinfo->btype == BT_GD5480)
1513 vga_wcrt (regbase, CL_CRT1D, 0x00); /* screen start address bit 19 */
1515 vga_wcrt (regbase, VGA_CRTC_CURSOR_HI, 0); /* text cursor location high */
1516 vga_wcrt (regbase, VGA_CRTC_CURSOR_LO, 0); /* text cursor location low */
1517 vga_wcrt (regbase, VGA_CRTC_UNDERLINE, 0); /* underline row scanline = at very bottom */
1519 vga_wattr (regbase, VGA_ATC_MODE, 1); /* controller mode */
1520 vga_wattr (regbase, VGA_ATC_OVERSCAN, 0); /* overscan (border) color */
1521 vga_wattr (regbase, VGA_ATC_PLANE_ENABLE, 15); /* color plane enable */
1522 vga_wattr (regbase, CL_AR33, 0); /* pixel panning */
1523 vga_wattr (regbase, VGA_ATC_COLOR_PAGE, 0); /* color select */
1525 /* [ EGS: SetOffset(); ] */
1526 /* From SetOffset(): Turn on VideoEnable bit in Attribute controller */
1529 vga_wgfx (regbase, VGA_GFX_SR_VALUE, 0); /* set/reset register */
1530 vga_wgfx (regbase, VGA_GFX_SR_ENABLE, 0); /* set/reset enable */
1531 vga_wgfx (regbase, VGA_GFX_COMPARE_VALUE, 0); /* color compare */
1532 vga_wgfx (regbase, VGA_GFX_DATA_ROTATE, 0); /* data rotate */
1533 vga_wgfx (regbase, VGA_GFX_PLANE_READ, 0); /* read map select */
1534 vga_wgfx (regbase, VGA_GFX_MISC, 1); /* miscellaneous register */
1535 vga_wgfx (regbase, VGA_GFX_COMPARE_MASK, 15); /* color don't care */
1536 vga_wgfx (regbase, VGA_GFX_BIT_MASK, 255); /* bit mask */
1538 vga_wseq (regbase, CL_SEQR12, 0x0); /* graphics cursor attributes: nothing special */
1540 /* finally, turn on everything - turn off "FullBandwidth" bit */
1541 /* also, set "DotClock%2" bit where requested */
1544 /*** FB_VMODE_CLOCK_HALVE in linux/fb.h not defined anymore ?
1545 if (var->vmode & FB_VMODE_CLOCK_HALVE)
1549 vga_wseq (regbase, VGA_SEQ_CLOCK_MODE, tmp);
1550 DPRINTK ("CL_SEQR1: %d\n", tmp);
1552 cinfo->currentmode = regs;
1553 info->fix.type = regs.type;
1554 info->fix.visual = regs.visual;
1555 info->fix.line_length = regs.line_length;
1557 /* pan to requested offset */
1558 cirrusfb_pan_display (var, info);
1560 #ifdef CIRRUSFB_DEBUG
1568 /* for some reason incomprehensible to me, cirrusfb requires that you write
1569 * the registers twice for the settings to take..grr. -dte */
1570 int cirrusfb_set_par (struct fb_info *info)
1572 cirrusfb_set_par_foo (info);
1573 return cirrusfb_set_par_foo (info);
1576 int cirrusfb_setcolreg (unsigned regno, unsigned red, unsigned green,
1577 unsigned blue, unsigned transp,
1578 struct fb_info *info)
1580 struct cirrusfb_info *cinfo = info->par;
1585 if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
1587 red >>= (16 - info->var.red.length);
1588 green >>= (16 - info->var.green.length);
1589 blue >>= (16 - info->var.blue.length);
1593 v = (red << info->var.red.offset) |
1594 (green << info->var.green.offset) |
1595 (blue << info->var.blue.offset);
1597 switch (info->var.bits_per_pixel) {
1599 ((u8*)(info->pseudo_palette))[regno] = v;
1602 ((u16*)(info->pseudo_palette))[regno] = v;
1606 ((u32*)(info->pseudo_palette))[regno] = v;
1612 cinfo->palette[regno].red = red;
1613 cinfo->palette[regno].green = green;
1614 cinfo->palette[regno].blue = blue;
1616 if (info->var.bits_per_pixel == 8) {
1617 WClut (cinfo, regno, red >> 10, green >> 10, blue >> 10);
1624 /*************************************************************************
1625 cirrusfb_pan_display()
1627 performs display panning - provided hardware permits this
1628 **************************************************************************/
1629 int cirrusfb_pan_display (struct fb_var_screeninfo *var,
1630 struct fb_info *info)
1635 unsigned char tmp = 0, tmp2 = 0, xpix;
1636 struct cirrusfb_info *cinfo = info->par;
1638 DPRINTK ("ENTER\n");
1639 DPRINTK ("virtual offset: (%d,%d)\n", var->xoffset, var->yoffset);
1641 /* no range checks for xoffset and yoffset, */
1642 /* as fb_pan_display has already done this */
1643 if (var->vmode & FB_VMODE_YWRAP)
1646 info->var.xoffset = var->xoffset;
1647 info->var.yoffset = var->yoffset;
1649 xoffset = var->xoffset * info->var.bits_per_pixel / 8;
1650 yoffset = var->yoffset;
1652 base = yoffset * cinfo->currentmode.line_length + xoffset;
1654 if (info->var.bits_per_pixel == 1) {
1655 /* base is already correct */
1656 xpix = (unsigned char) (var->xoffset % 8);
1659 xpix = (unsigned char) ((xoffset % 4) * 2);
1662 cirrusfb_WaitBLT(cinfo->regbase); /* make sure all the BLT's are done */
1664 /* lower 8 + 8 bits of screen start address */
1665 vga_wcrt (cinfo->regbase, VGA_CRTC_START_LO, (unsigned char) (base & 0xff));
1666 vga_wcrt (cinfo->regbase, VGA_CRTC_START_HI, (unsigned char) (base >> 8));
1668 /* construct bits 16, 17 and 18 of screen start address */
1676 tmp2 = (vga_rcrt (cinfo->regbase, CL_CRT1B) & 0xf2) | tmp; /* 0xf2 is %11110010, exclude tmp bits */
1677 vga_wcrt (cinfo->regbase, CL_CRT1B, tmp2);
1679 /* construct bit 19 of screen start address */
1680 if (cirrusfb_board_info[cinfo->btype].scrn_start_bit19) {
1684 vga_wcrt (cinfo->regbase, CL_CRT1D, tmp2);
1687 /* write pixel panning value to AR33; this does not quite work in 8bpp */
1688 /* ### Piccolo..? Will this work? */
1689 if (info->var.bits_per_pixel == 1)
1690 vga_wattr (cinfo->regbase, CL_AR33, xpix);
1692 cirrusfb_WaitBLT (cinfo->regbase);
1699 int cirrusfb_blank (int blank_mode, struct fb_info *info)
1702 * Blank the screen if blank_mode != 0, else unblank. If blank == NULL
1703 * then the caller blanks by setting the CLUT (Color Look Up Table) to all
1704 * black. Return 0 if blanking succeeded, != 0 if un-/blanking failed due
1705 * to e.g. a video mode which doesn't support it. Implements VESA suspend
1706 * and powerdown modes on hardware that supports disabling hsync/vsync:
1707 * blank_mode == 2: suspend vsync
1708 * blank_mode == 3: suspend hsync
1709 * blank_mode == 4: powerdown
1712 struct cirrusfb_info *cinfo = info->par;
1713 int current_mode = cinfo->blank_mode;
1715 DPRINTK ("ENTER, blank mode = %d\n", blank_mode);
1717 if (info->state != FBINFO_STATE_RUNNING ||
1718 current_mode == blank_mode) {
1719 DPRINTK ("EXIT, returning 0\n");
1724 if (current_mode != VESA_NO_BLANKING) {
1725 /* unblank the screen */
1726 val = vga_rseq (cinfo->regbase, VGA_SEQ_CLOCK_MODE);
1727 vga_wseq (cinfo->regbase, VGA_SEQ_CLOCK_MODE, val & 0xdf); /* clear "FullBandwidth" bit */
1728 /* and undo VESA suspend trickery */
1729 vga_wgfx (cinfo->regbase, CL_GRE, 0x00);
1733 if(blank_mode != VESA_NO_BLANKING) {
1734 /* blank the screen */
1735 val = vga_rseq (cinfo->regbase, VGA_SEQ_CLOCK_MODE);
1736 vga_wseq (cinfo->regbase, VGA_SEQ_CLOCK_MODE, val | 0x20); /* set "FullBandwidth" bit */
1739 switch (blank_mode) {
1740 case VESA_NO_BLANKING:
1742 case VESA_VSYNC_SUSPEND:
1743 vga_wgfx (cinfo->regbase, CL_GRE, 0x04);
1745 case VESA_HSYNC_SUSPEND:
1746 vga_wgfx (cinfo->regbase, CL_GRE, 0x02);
1748 case VESA_POWERDOWN:
1749 vga_wgfx (cinfo->regbase, CL_GRE, 0x06);
1752 DPRINTK ("EXIT, returning 1\n");
1756 cinfo->blank_mode = blank_mode;
1757 DPRINTK ("EXIT, returning 0\n");
1760 /**** END Hardware specific Routines **************************************/
1761 /****************************************************************************/
1762 /**** BEGIN Internal Routines ***********************************************/
1764 static void init_vgachip (struct cirrusfb_info *cinfo)
1766 const struct cirrusfb_board_info_rec *bi;
1768 DPRINTK ("ENTER\n");
1770 assert (cinfo != NULL);
1772 bi = &cirrusfb_board_info[cinfo->btype];
1774 /* reset board globally */
1775 switch (cinfo->btype) {
1783 WSFR2 (cinfo, 0xff);
1794 vga_wcrt (cinfo->regbase, CL_CRT51, 0x00); /* disable flickerfixer */
1796 vga_wgfx (cinfo->regbase, CL_GR2F, 0x00); /* from Klaus' NetBSD driver: */
1797 vga_wgfx (cinfo->regbase, CL_GR33, 0x00); /* put blitter into 542x compat */
1798 vga_wgfx (cinfo->regbase, CL_GR31, 0x00); /* mode */
1802 vga_wgfx (cinfo->regbase, CL_GR2F, 0x00); /* from Klaus' NetBSD driver: */
1806 /* Nothing to do to reset the board. */
1810 printk (KERN_ERR "cirrusfb: Warning: Unknown board type\n");
1814 assert (cinfo->size > 0); /* make sure RAM size set by this point */
1816 /* the P4 is not fully initialized here; I rely on it having been */
1817 /* inited under AmigaOS already, which seems to work just fine */
1818 /* (Klaus advised to do it this way) */
1820 if (cinfo->btype != BT_PICASSO4) {
1821 WGen (cinfo, CL_VSSM, 0x10); /* EGS: 0x16 */
1822 WGen (cinfo, CL_POS102, 0x01);
1823 WGen (cinfo, CL_VSSM, 0x08); /* EGS: 0x0e */
1825 if (cinfo->btype != BT_SD64)
1826 WGen (cinfo, CL_VSSM2, 0x01);
1828 vga_wseq (cinfo->regbase, CL_SEQR0, 0x03); /* reset sequencer logic */
1830 vga_wseq (cinfo->regbase, VGA_SEQ_CLOCK_MODE, 0x21); /* FullBandwidth (video off) and 8/9 dot clock */
1831 WGen (cinfo, VGA_MIS_W, 0xc1); /* polarity (-/-), disable access to display memory, VGA_CRTC_START_HI base address: color */
1833 /* vga_wgfx (cinfo->regbase, CL_GRA, 0xce); "magic cookie" - doesn't make any sense to me.. */
1834 vga_wseq (cinfo->regbase, CL_SEQR6, 0x12); /* unlock all extension registers */
1836 vga_wgfx (cinfo->regbase, CL_GR31, 0x04); /* reset blitter */
1838 switch (cinfo->btype) {
1840 vga_wseq (cinfo->regbase, CL_SEQRF, 0x98);
1845 vga_wseq (cinfo->regbase, CL_SEQRF, 0xb8);
1848 vga_wseq (cinfo->regbase, CL_SEQR16, 0x0f);
1849 vga_wseq (cinfo->regbase, CL_SEQRF, 0xb0);
1853 vga_wseq (cinfo->regbase, VGA_SEQ_PLANE_WRITE, 0xff); /* plane mask: nothing */
1854 vga_wseq (cinfo->regbase, VGA_SEQ_CHARACTER_MAP, 0x00); /* character map select: doesn't even matter in gx mode */
1855 vga_wseq (cinfo->regbase, VGA_SEQ_MEMORY_MODE, 0x0e); /* memory mode: chain-4, no odd/even, ext. memory */
1857 /* controller-internal base address of video memory */
1859 vga_wseq (cinfo->regbase, CL_SEQR7, bi->sr07);
1861 /* vga_wseq (cinfo->regbase, CL_SEQR8, 0x00); *//* EEPROM control: shouldn't be necessary to write to this at all.. */
1863 vga_wseq (cinfo->regbase, CL_SEQR10, 0x00); /* graphics cursor X position (incomplete; position gives rem. 3 bits */
1864 vga_wseq (cinfo->regbase, CL_SEQR11, 0x00); /* graphics cursor Y position (..."... ) */
1865 vga_wseq (cinfo->regbase, CL_SEQR12, 0x00); /* graphics cursor attributes */
1866 vga_wseq (cinfo->regbase, CL_SEQR13, 0x00); /* graphics cursor pattern address */
1868 /* writing these on a P4 might give problems.. */
1869 if (cinfo->btype != BT_PICASSO4) {
1870 vga_wseq (cinfo->regbase, CL_SEQR17, 0x00); /* configuration readback and ext. color */
1871 vga_wseq (cinfo->regbase, CL_SEQR18, 0x02); /* signature generator */
1874 /* MCLK select etc. */
1876 vga_wseq (cinfo->regbase, CL_SEQR1F, bi->sr1f);
1878 vga_wcrt (cinfo->regbase, VGA_CRTC_PRESET_ROW, 0x00); /* Screen A preset row scan: none */
1879 vga_wcrt (cinfo->regbase, VGA_CRTC_CURSOR_START, 0x20); /* Text cursor start: disable text cursor */
1880 vga_wcrt (cinfo->regbase, VGA_CRTC_CURSOR_END, 0x00); /* Text cursor end: - */
1881 vga_wcrt (cinfo->regbase, VGA_CRTC_START_HI, 0x00); /* Screen start address high: 0 */
1882 vga_wcrt (cinfo->regbase, VGA_CRTC_START_LO, 0x00); /* Screen start address low: 0 */
1883 vga_wcrt (cinfo->regbase, VGA_CRTC_CURSOR_HI, 0x00); /* text cursor location high: 0 */
1884 vga_wcrt (cinfo->regbase, VGA_CRTC_CURSOR_LO, 0x00); /* text cursor location low: 0 */
1886 vga_wcrt (cinfo->regbase, VGA_CRTC_UNDERLINE, 0x00); /* Underline Row scanline: - */
1887 vga_wcrt (cinfo->regbase, VGA_CRTC_MODE, 0xc3); /* mode control: timing enable, byte mode, no compat modes */
1888 vga_wcrt (cinfo->regbase, VGA_CRTC_LINE_COMPARE, 0x00); /* Line Compare: not needed */
1889 /* ### add 0x40 for text modes with > 30 MHz pixclock */
1890 vga_wcrt (cinfo->regbase, CL_CRT1B, 0x02); /* ext. display controls: ext.adr. wrap */
1892 vga_wgfx (cinfo->regbase, VGA_GFX_SR_VALUE, 0x00); /* Set/Reset registes: - */
1893 vga_wgfx (cinfo->regbase, VGA_GFX_SR_ENABLE, 0x00); /* Set/Reset enable: - */
1894 vga_wgfx (cinfo->regbase, VGA_GFX_COMPARE_VALUE, 0x00); /* Color Compare: - */
1895 vga_wgfx (cinfo->regbase, VGA_GFX_DATA_ROTATE, 0x00); /* Data Rotate: - */
1896 vga_wgfx (cinfo->regbase, VGA_GFX_PLANE_READ, 0x00); /* Read Map Select: - */
1897 vga_wgfx (cinfo->regbase, VGA_GFX_MODE, 0x00); /* Mode: conf. for 16/4/2 color mode, no odd/even, read/write mode 0 */
1898 vga_wgfx (cinfo->regbase, VGA_GFX_MISC, 0x01); /* Miscellaneous: memory map base address, graphics mode */
1899 vga_wgfx (cinfo->regbase, VGA_GFX_COMPARE_MASK, 0x0f); /* Color Don't care: involve all planes */
1900 vga_wgfx (cinfo->regbase, VGA_GFX_BIT_MASK, 0xff); /* Bit Mask: no mask at all */
1901 if (cinfo->btype == BT_ALPINE)
1902 vga_wgfx (cinfo->regbase, CL_GRB, 0x20); /* (5434 can't have bit 3 set for bitblt) */
1904 vga_wgfx (cinfo->regbase, CL_GRB, 0x28); /* Graphics controller mode extensions: finer granularity, 8byte data latches */
1906 vga_wgfx (cinfo->regbase, CL_GRC, 0xff); /* Color Key compare: - */
1907 vga_wgfx (cinfo->regbase, CL_GRD, 0x00); /* Color Key compare mask: - */
1908 vga_wgfx (cinfo->regbase, CL_GRE, 0x00); /* Miscellaneous control: - */
1909 /* vga_wgfx (cinfo->regbase, CL_GR10, 0x00); *//* Background color byte 1: - */
1910 /* vga_wgfx (cinfo->regbase, CL_GR11, 0x00); */
1912 vga_wattr (cinfo->regbase, VGA_ATC_PALETTE0, 0x00); /* Attribute Controller palette registers: "identity mapping" */
1913 vga_wattr (cinfo->regbase, VGA_ATC_PALETTE1, 0x01);
1914 vga_wattr (cinfo->regbase, VGA_ATC_PALETTE2, 0x02);
1915 vga_wattr (cinfo->regbase, VGA_ATC_PALETTE3, 0x03);
1916 vga_wattr (cinfo->regbase, VGA_ATC_PALETTE4, 0x04);
1917 vga_wattr (cinfo->regbase, VGA_ATC_PALETTE5, 0x05);
1918 vga_wattr (cinfo->regbase, VGA_ATC_PALETTE6, 0x06);
1919 vga_wattr (cinfo->regbase, VGA_ATC_PALETTE7, 0x07);
1920 vga_wattr (cinfo->regbase, VGA_ATC_PALETTE8, 0x08);
1921 vga_wattr (cinfo->regbase, VGA_ATC_PALETTE9, 0x09);
1922 vga_wattr (cinfo->regbase, VGA_ATC_PALETTEA, 0x0a);
1923 vga_wattr (cinfo->regbase, VGA_ATC_PALETTEB, 0x0b);
1924 vga_wattr (cinfo->regbase, VGA_ATC_PALETTEC, 0x0c);
1925 vga_wattr (cinfo->regbase, VGA_ATC_PALETTED, 0x0d);
1926 vga_wattr (cinfo->regbase, VGA_ATC_PALETTEE, 0x0e);
1927 vga_wattr (cinfo->regbase, VGA_ATC_PALETTEF, 0x0f);
1929 vga_wattr (cinfo->regbase, VGA_ATC_MODE, 0x01); /* Attribute Controller mode: graphics mode */
1930 vga_wattr (cinfo->regbase, VGA_ATC_OVERSCAN, 0x00); /* Overscan color reg.: reg. 0 */
1931 vga_wattr (cinfo->regbase, VGA_ATC_PLANE_ENABLE, 0x0f); /* Color Plane enable: Enable all 4 planes */
1932 /* ### vga_wattr (cinfo->regbase, CL_AR33, 0x00); * Pixel Panning: - */
1933 vga_wattr (cinfo->regbase, VGA_ATC_COLOR_PAGE, 0x00); /* Color Select: - */
1935 WGen (cinfo, VGA_PEL_MSK, 0xff); /* Pixel mask: no mask */
1937 if (cinfo->btype != BT_ALPINE && cinfo->btype != BT_GD5480)
1938 WGen (cinfo, VGA_MIS_W, 0xc3); /* polarity (-/-), enable display mem, VGA_CRTC_START_HI i/o base = color */
1940 vga_wgfx (cinfo->regbase, CL_GR31, 0x04); /* BLT Start/status: Blitter reset */
1941 vga_wgfx (cinfo->regbase, CL_GR31, 0x00); /* - " - : "end-of-reset" */
1944 WHDR (cinfo, 0); /* Hidden DAC register: - */
1946 printk (KERN_DEBUG "cirrusfb: This board has %ld bytes of DRAM memory\n", cinfo->size);
1951 static void switch_monitor (struct cirrusfb_info *cinfo, int on)
1953 #ifdef CONFIG_ZORRO /* only works on Zorro boards */
1954 static int IsOn = 0; /* XXX not ok for multiple boards */
1956 DPRINTK ("ENTER\n");
1958 if (cinfo->btype == BT_PICASSO4)
1959 return; /* nothing to switch */
1960 if (cinfo->btype == BT_ALPINE)
1961 return; /* nothing to switch */
1962 if (cinfo->btype == BT_GD5480)
1963 return; /* nothing to switch */
1964 if (cinfo->btype == BT_PICASSO) {
1965 if ((on && !IsOn) || (!on && IsOn))
1972 switch (cinfo->btype) {
1974 WSFR (cinfo, cinfo->SFR | 0x21);
1977 WSFR (cinfo, cinfo->SFR | 0x28);
1982 default: /* do nothing */ break;
1985 switch (cinfo->btype) {
1987 WSFR (cinfo, cinfo->SFR & 0xde);
1990 WSFR (cinfo, cinfo->SFR & 0xd7);
1995 default: /* do nothing */ break;
2000 #endif /* CONFIG_ZORRO */
2004 /******************************************/
2005 /* Linux 2.6-style accelerated functions */
2006 /******************************************/
2008 static void cirrusfb_prim_fillrect(struct cirrusfb_info *cinfo,
2009 const struct fb_fillrect *region)
2011 int m; /* bytes per pixel */
2012 if(cinfo->info->var.bits_per_pixel == 1) {
2013 cirrusfb_RectFill(cinfo->regbase, cinfo->info->var.bits_per_pixel,
2014 region->dx / 8, region->dy,
2015 region->width / 8, region->height,
2017 cinfo->currentmode.line_length);
2019 m = ( cinfo->info->var.bits_per_pixel + 7 ) / 8;
2020 cirrusfb_RectFill(cinfo->regbase, cinfo->info->var.bits_per_pixel,
2021 region->dx * m, region->dy,
2022 region->width * m, region->height,
2024 cinfo->currentmode.line_length);
2029 void cirrusfb_fillrect (struct fb_info *info, const struct fb_fillrect *region)
2031 struct cirrusfb_info *cinfo = info->par;
2032 struct fb_fillrect modded;
2035 if (info->state != FBINFO_STATE_RUNNING)
2037 if (info->flags & FBINFO_HWACCEL_DISABLED) {
2038 cfb_fillrect(info, region);
2042 vxres = info->var.xres_virtual;
2043 vyres = info->var.yres_virtual;
2045 memcpy(&modded, region, sizeof(struct fb_fillrect));
2047 if(!modded.width || !modded.height ||
2048 modded.dx >= vxres || modded.dy >= vyres)
2051 if(modded.dx + modded.width > vxres) modded.width = vxres - modded.dx;
2052 if(modded.dy + modded.height > vyres) modded.height = vyres - modded.dy;
2054 cirrusfb_prim_fillrect(cinfo, &modded);
2057 static void cirrusfb_prim_copyarea(struct cirrusfb_info *cinfo,
2058 const struct fb_copyarea *area)
2060 int m; /* bytes per pixel */
2061 if(cinfo->info->var.bits_per_pixel == 1) {
2062 cirrusfb_BitBLT(cinfo->regbase, cinfo->info->var.bits_per_pixel,
2063 area->sx / 8, area->sy,
2064 area->dx / 8, area->dy,
2065 area->width / 8, area->height,
2066 cinfo->currentmode.line_length);
2068 m = ( cinfo->info->var.bits_per_pixel + 7 ) / 8;
2069 cirrusfb_BitBLT(cinfo->regbase, cinfo->info->var.bits_per_pixel,
2070 area->sx * m, area->sy,
2071 area->dx * m, area->dy,
2072 area->width * m, area->height,
2073 cinfo->currentmode.line_length);
2079 void cirrusfb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
2081 struct cirrusfb_info *cinfo = info->par;
2082 struct fb_copyarea modded;
2084 modded.sx = area->sx;
2085 modded.sy = area->sy;
2086 modded.dx = area->dx;
2087 modded.dy = area->dy;
2088 modded.width = area->width;
2089 modded.height = area->height;
2091 if (info->state != FBINFO_STATE_RUNNING)
2093 if (info->flags & FBINFO_HWACCEL_DISABLED) {
2094 cfb_copyarea(info, area);
2098 vxres = info->var.xres_virtual;
2099 vyres = info->var.yres_virtual;
2101 if(!modded.width || !modded.height ||
2102 modded.sx >= vxres || modded.sy >= vyres ||
2103 modded.dx >= vxres || modded.dy >= vyres)
2106 if(modded.sx + modded.width > vxres) modded.width = vxres - modded.sx;
2107 if(modded.dx + modded.width > vxres) modded.width = vxres - modded.dx;
2108 if(modded.sy + modded.height > vyres) modded.height = vyres - modded.sy;
2109 if(modded.dy + modded.height > vyres) modded.height = vyres - modded.dy;
2111 cirrusfb_prim_copyarea(cinfo, &modded);
2114 void cirrusfb_imageblit(struct fb_info *info, const struct fb_image *image)
2116 struct cirrusfb_info *cinfo = info->par;
2118 cirrusfb_WaitBLT(cinfo->regbase);
2119 cfb_imageblit(info, image);
2123 #ifdef CONFIG_PPC_PREP
2124 #define PREP_VIDEO_BASE ((volatile unsigned long) 0xC0000000)
2125 #define PREP_IO_BASE ((volatile unsigned char *) 0x80000000)
2126 static void get_prep_addrs (unsigned long *display, unsigned long *registers)
2128 DPRINTK ("ENTER\n");
2130 *display = PREP_VIDEO_BASE;
2131 *registers = (unsigned long) PREP_IO_BASE;
2136 #endif /* CONFIG_PPC_PREP */
2140 static int release_io_ports = 0;
2142 /* Pulled the logic from XFree86 Cirrus driver to get the memory size,
2143 * based on the DRAM bandwidth bit and DRAM bank switching bit. This
2144 * works with 1MB, 2MB and 4MB configurations (which the Motorola boards
2146 static unsigned int cirrusfb_get_memsize (caddr_t regbase)
2151 DPRINTK ("ENTER\n");
2153 SRF = vga_rseq (regbase, CL_SEQRF);
2154 switch ((SRF & 0x18)) {
2155 case 0x08: mem = 512 * 1024; break;
2156 case 0x10: mem = 1024 * 1024; break;
2157 /* 64-bit DRAM data bus width; assume 2MB. Also indicates 2MB memory
2159 case 0x18: mem = 2048 * 1024; break;
2160 default: printk ("CLgenfb: Unknown memory size!\n");
2164 /* If DRAM bank switching is enabled, there must be twice as much
2165 * memory installed. (4MB on the 5434) */
2168 /* TODO: Handling of GD5446/5480 (see XF86 sources ...) */
2176 static void get_pci_addrs (const struct pci_dev *pdev,
2177 unsigned long *display, unsigned long *registers)
2179 assert (pdev != NULL);
2180 assert (display != NULL);
2181 assert (registers != NULL);
2183 DPRINTK ("ENTER\n");
2188 /* This is a best-guess for now */
2190 if (pci_resource_flags(pdev, 0) & IORESOURCE_IO) {
2191 *display = pci_resource_start(pdev, 1);
2192 *registers = pci_resource_start(pdev, 0);
2194 *display = pci_resource_start(pdev, 0);
2195 *registers = pci_resource_start(pdev, 1);
2198 assert (*display != 0);
2204 static void cirrusfb_pci_unmap (struct cirrusfb_info *cinfo)
2206 struct pci_dev *pdev = cinfo->pdev;
2208 iounmap(cinfo->fbmem);
2209 #if 0 /* if system didn't claim this region, we would... */
2210 release_mem_region(0xA0000, 65535);
2212 if (release_io_ports)
2213 release_region(0x3C0, 32);
2214 pci_release_regions(pdev);
2215 framebuffer_release(cinfo->info);
2216 pci_disable_device(pdev);
2218 #endif /* CONFIG_PCI */
2222 static void __devexit cirrusfb_zorro_unmap (struct cirrusfb_info *cinfo)
2224 zorro_release_device(cinfo->zdev);
2226 if (cinfo->btype == BT_PICASSO4) {
2227 cinfo->regbase -= 0x600000;
2228 iounmap ((void *)cinfo->regbase);
2229 iounmap ((void *)cinfo->fbmem);
2231 if (zorro_resource_start(cinfo->zdev) > 0x01000000)
2232 iounmap ((void *)cinfo->fbmem);
2234 framebuffer_release(cinfo->info);
2236 #endif /* CONFIG_ZORRO */
2238 static int cirrusfb_set_fbinfo(struct cirrusfb_info *cinfo)
2240 struct fb_info *info = cinfo->info;
2241 struct fb_var_screeninfo *var = &info->var;
2245 info->pseudo_palette = cinfo->pseudo_palette;
2246 info->flags = FBINFO_DEFAULT
2247 | FBINFO_HWACCEL_XPAN
2248 | FBINFO_HWACCEL_YPAN
2249 | FBINFO_HWACCEL_FILLRECT
2250 | FBINFO_HWACCEL_COPYAREA;
2252 info->flags |= FBINFO_HWACCEL_DISABLED;
2253 info->fbops = &cirrusfb_ops;
2254 info->screen_base = cinfo->fbmem;
2255 if (cinfo->btype == BT_GD5480) {
2256 if (var->bits_per_pixel == 16)
2257 info->screen_base += 1 * MB_;
2258 if (var->bits_per_pixel == 24 || var->bits_per_pixel == 32)
2259 info->screen_base += 2 * MB_;
2262 /* Fill fix common fields */
2263 strlcpy(info->fix.id, cirrusfb_board_info[cinfo->btype].name,
2264 sizeof(info->fix.id));
2266 /* monochrome: only 1 memory plane */
2267 /* 8 bit and above: Use whole memory area */
2268 info->fix.smem_start = cinfo->fbmem_phys;
2269 info->fix.smem_len = (var->bits_per_pixel == 1) ? cinfo->size / 4 : cinfo->size;
2270 info->fix.type = cinfo->currentmode.type;
2271 info->fix.type_aux = 0;
2272 info->fix.visual = cinfo->currentmode.visual;
2273 info->fix.xpanstep = 1;
2274 info->fix.ypanstep = 1;
2275 info->fix.ywrapstep = 0;
2276 info->fix.line_length = cinfo->currentmode.line_length;
2278 /* FIXME: map region at 0xB8000 if available, fill in here */
2279 info->fix.mmio_start = cinfo->fbregs_phys;
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 cirrusfb_info *cinfo)
2290 struct fb_info *info;
2292 cirrusfb_board_t btype;
2294 DPRINTK ("ENTER\n");
2296 printk (KERN_INFO "cirrusfb: Driver for Cirrus Logic based 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", cinfo->fbmem);
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(cinfo);
2321 err = register_framebuffer(info);
2323 printk (KERN_ERR "cirrusfb: could not register fb device; err = %d!\n", err);
2324 goto err_dealloc_cmap;
2327 DPRINTK ("EXIT, returning 0\n");
2331 fb_dealloc_cmap(&info->cmap);
2333 cinfo->unmap(cinfo);
2337 static void __devexit cirrusfb_cleanup (struct fb_info *info)
2339 struct cirrusfb_info *cinfo = info->par;
2340 DPRINTK ("ENTER\n");
2342 switch_monitor (cinfo, 0);
2344 unregister_framebuffer (info);
2345 fb_dealloc_cmap (&info->cmap);
2346 printk ("Framebuffer unregistered\n");
2347 cinfo->unmap(cinfo);
2354 static int cirrusfb_pci_register (struct pci_dev *pdev,
2355 const struct pci_device_id *ent)
2357 struct cirrusfb_info *cinfo;
2358 struct fb_info *info;
2359 cirrusfb_board_t btype;
2360 unsigned long board_addr, board_size;
2363 ret = pci_enable_device(pdev);
2365 printk(KERN_ERR "cirrusfb: Cannot enable PCI device\n");
2369 info = framebuffer_alloc(sizeof(struct cirrusfb_info), &pdev->dev);
2371 printk(KERN_ERR "cirrusfb: could not allocate memory\n");
2379 cinfo->btype = btype = (cirrusfb_board_t) ent->driver_data;
2381 DPRINTK (" Found PCI device, base address 0 is 0x%lx, btype set to %d\n",
2382 pdev->resource[0].start, btype);
2383 DPRINTK (" base address 1 is 0x%lx\n", pdev->resource[1].start);
2386 pci_write_config_dword (pdev, PCI_BASE_ADDRESS_0, 0x00000000);
2387 #ifdef CONFIG_PPC_PREP
2388 get_prep_addrs (&board_addr, &cinfo->fbregs_phys);
2390 /* PReP dies if we ioremap the IO registers, but it works w/out... */
2391 cinfo->regbase = (char *) cinfo->fbregs_phys;
2393 DPRINTK ("Attempt to get PCI info for Cirrus Graphics Card\n");
2394 get_pci_addrs (pdev, &board_addr, &cinfo->fbregs_phys);
2395 cinfo->regbase = NULL; /* FIXME: this forces VGA. alternatives? */
2398 DPRINTK ("Board address: 0x%lx, register address: 0x%lx\n", board_addr, cinfo->fbregs_phys);
2400 board_size = (btype == BT_GD5480) ?
2401 32 * MB_ : cirrusfb_get_memsize (cinfo->regbase);
2403 ret = pci_request_regions(pdev, "cirrusfb");
2405 printk(KERN_ERR "cirrusfb: cannot reserve region 0x%lx, abort\n",
2407 goto err_release_fb;
2409 #if 0 /* if the system didn't claim this region, we would... */
2410 if (!request_mem_region(0xA0000, 65535, "cirrusfb")) {
2411 printk(KERN_ERR "cirrusfb: cannot reserve region 0x%lx, abort\n"
2415 goto err_release_regions;
2418 if (request_region(0x3C0, 32, "cirrusfb"))
2419 release_io_ports = 1;
2421 cinfo->fbmem = ioremap(board_addr, board_size);
2422 if (!cinfo->fbmem) {
2424 goto err_release_legacy;
2427 cinfo->fbmem_phys = board_addr;
2428 cinfo->size = board_size;
2429 cinfo->unmap = cirrusfb_pci_unmap;
2431 printk (" RAM (%lu kB) at 0xx%lx, ", cinfo->size / KB_, board_addr);
2432 printk ("Cirrus Logic chipset on PCI bus\n");
2433 pci_set_drvdata(pdev, info);
2435 return cirrusfb_register(cinfo);
2438 if (release_io_ports)
2439 release_region(0x3C0, 32);
2441 release_mem_region(0xA0000, 65535);
2442 err_release_regions:
2444 pci_release_regions(pdev);
2446 framebuffer_release(info);
2448 pci_disable_device(pdev);
2453 void __devexit cirrusfb_pci_unregister (struct pci_dev *pdev)
2455 struct fb_info *info = pci_get_drvdata(pdev);
2456 DPRINTK ("ENTER\n");
2458 cirrusfb_cleanup (info);
2463 static struct pci_driver cirrusfb_pci_driver = {
2465 .id_table = cirrusfb_pci_table,
2466 .probe = cirrusfb_pci_register,
2467 .remove = __devexit_p(cirrusfb_pci_unregister),
2470 .suspend = cirrusfb_pci_suspend,
2471 .resume = cirrusfb_pci_resume,
2475 #endif /* CONFIG_PCI */
2479 static int cirrusfb_zorro_register(struct zorro_dev *z,
2480 const struct zorro_device_id *ent)
2482 struct cirrusfb_info *cinfo;
2483 struct fb_info *info;
2484 cirrusfb_board_t btype;
2485 struct zorro_dev *z2 = NULL;
2486 unsigned long board_addr, board_size, size;
2489 btype = ent->driver_data;
2490 if (cirrusfb_zorro_table2[btype].id2)
2491 z2 = zorro_find_device(cirrusfb_zorro_table2[btype].id2, NULL);
2492 size = cirrusfb_zorro_table2[btype].size;
2493 printk(KERN_INFO "cirrusfb: %s board detected; ",
2494 cirrusfb_board_info[btype].name);
2496 info = framebuffer_alloc(sizeof(struct cirrusfb_info), &z->dev);
2498 printk (KERN_ERR "cirrusfb: could not allocate memory\n");
2505 cinfo->btype = btype;
2509 assert (btype != BT_NONE);
2512 board_addr = zorro_resource_start(z);
2513 board_size = zorro_resource_len(z);
2516 if (!zorro_request_device(z, "cirrusfb")) {
2517 printk(KERN_ERR "cirrusfb: cannot reserve region 0x%lx, abort\n",
2520 goto err_release_fb;
2523 printk (" RAM (%lu MB) at $%lx, ", board_size / MB_, board_addr);
2527 if (btype == BT_PICASSO4) {
2528 printk (" REG at $%lx\n", board_addr + 0x600000);
2530 /* To be precise, for the P4 this is not the */
2531 /* begin of the board, but the begin of RAM. */
2532 /* for P4, map in its address space in 2 chunks (### TEST! ) */
2533 /* (note the ugly hardcoded 16M number) */
2534 cinfo->regbase = ioremap (board_addr, 16777216);
2535 if (!cinfo->regbase)
2536 goto err_release_region;
2538 DPRINTK ("cirrusfb: Virtual address for board set to: $%p\n", cinfo->regbase);
2539 cinfo->regbase += 0x600000;
2540 cinfo->fbregs_phys = board_addr + 0x600000;
2542 cinfo->fbmem_phys = board_addr + 16777216;
2543 cinfo->fbmem = ioremap (cinfo->fbmem_phys, 16777216);
2545 goto err_unmap_regbase;
2547 printk (" REG at $%lx\n", (unsigned long) z2->resource.start);
2549 cinfo->fbmem_phys = board_addr;
2550 if (board_addr > 0x01000000)
2551 cinfo->fbmem = ioremap (board_addr, board_size);
2553 cinfo->fbmem = (caddr_t) ZTWO_VADDR (board_addr);
2555 goto err_release_region;
2557 /* set address for REG area of board */
2558 cinfo->regbase = (caddr_t) ZTWO_VADDR (z2->resource.start);
2559 cinfo->fbregs_phys = z2->resource.start;
2561 DPRINTK ("cirrusfb: Virtual address for board set to: $%p\n", cinfo->regbase);
2563 cinfo->unmap = cirrusfb_zorro_unmap;
2565 printk (KERN_INFO "Cirrus Logic chipset on Zorro bus\n");
2566 zorro_set_drvdata(z, info);
2568 return cirrusfb_register(cinfo);
2571 /* Parental advisory: explicit hack */
2572 iounmap(cinfo->regbase - 0x600000);
2574 release_region(board_addr, board_size);
2576 framebuffer_release(info);
2581 void __devexit cirrusfb_zorro_unregister(struct zorro_dev *z)
2583 struct fb_info *info = zorro_get_drvdata(z);
2584 DPRINTK ("ENTER\n");
2586 cirrusfb_cleanup (info);
2591 static struct zorro_driver cirrusfb_zorro_driver = {
2593 .id_table = cirrusfb_zorro_table,
2594 .probe = cirrusfb_zorro_register,
2595 .remove = __devexit_p(cirrusfb_zorro_unregister),
2597 #endif /* CONFIG_ZORRO */
2599 int __init cirrusfb_init(void)
2604 error |= zorro_module_init(&cirrusfb_zorro_driver);
2607 error |= pci_module_init(&cirrusfb_pci_driver);
2615 int __init cirrusfb_setup(char *options) {
2616 char *this_opt, s[32];
2619 DPRINTK ("ENTER\n");
2621 if (!options || !*options)
2624 while ((this_opt = strsep (&options, ",")) != NULL) {
2625 if (!*this_opt) continue;
2627 DPRINTK("cirrusfb_setup: option '%s'\n", this_opt);
2629 for (i = 0; i < NUM_TOTAL_MODES; i++) {
2630 sprintf (s, "mode:%s", cirrusfb_predefined[i].name);
2631 if (strcmp (this_opt, s) == 0)
2632 cirrusfb_def_mode = i;
2634 if (!strcmp(this_opt, "noaccel"))
2646 MODULE_AUTHOR("Copyright 1999,2000 Jeff Garzik <jgarzik@pobox.com>");
2647 MODULE_DESCRIPTION("Accelerated FBDev driver for Cirrus Logic chips");
2648 MODULE_LICENSE("GPL");
2650 void __exit cirrusfb_exit (void)
2653 pci_unregister_driver(&cirrusfb_pci_driver);
2656 zorro_unregister_driver(&cirrusfb_zorro_driver);
2661 module_init(cirrusfb_init);
2662 module_exit(cirrusfb_exit);
2666 /**********************************************************************/
2667 /* about the following functions - I have used the same names for the */
2668 /* functions as Markus Wild did in his Retina driver for NetBSD as */
2669 /* they just made sense for this purpose. Apart from that, I wrote */
2670 /* these functions myself. */
2671 /**********************************************************************/
2673 /*** WGen() - write into one of the external/general registers ***/
2674 static void WGen (const struct cirrusfb_info *cinfo,
2675 int regnum, unsigned char val)
2677 unsigned long regofs = 0;
2679 if (cinfo->btype == BT_PICASSO) {
2680 /* Picasso II specific hack */
2681 /* if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D || regnum == CL_VSSM2) */
2682 if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D)
2686 vga_w (cinfo->regbase, regofs + regnum, val);
2689 /*** RGen() - read out one of the external/general registers ***/
2690 static unsigned char RGen (const struct cirrusfb_info *cinfo, int regnum)
2692 unsigned long regofs = 0;
2694 if (cinfo->btype == BT_PICASSO) {
2695 /* Picasso II specific hack */
2696 /* if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D || regnum == CL_VSSM2) */
2697 if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D)
2701 return vga_r (cinfo->regbase, regofs + regnum);
2704 /*** AttrOn() - turn on VideoEnable for Attribute controller ***/
2705 static void AttrOn (const struct cirrusfb_info *cinfo)
2707 assert (cinfo != NULL);
2709 DPRINTK ("ENTER\n");
2711 if (vga_rcrt (cinfo->regbase, CL_CRT24) & 0x80) {
2712 /* if we're just in "write value" mode, write back the */
2713 /* same value as before to not modify anything */
2714 vga_w (cinfo->regbase, VGA_ATT_IW,
2715 vga_r (cinfo->regbase, VGA_ATT_R));
2717 /* turn on video bit */
2718 /* vga_w (cinfo->regbase, VGA_ATT_IW, 0x20); */
2719 vga_w (cinfo->regbase, VGA_ATT_IW, 0x33);
2721 /* dummy write on Reg0 to be on "write index" mode next time */
2722 vga_w (cinfo->regbase, VGA_ATT_IW, 0x00);
2727 /*** WHDR() - write into the Hidden DAC register ***/
2728 /* as the HDR is the only extension register that requires special treatment
2729 * (the other extension registers are accessible just like the "ordinary"
2730 * registers of their functional group) here is a specialized routine for
2733 static void WHDR (const struct cirrusfb_info *cinfo, unsigned char val)
2735 unsigned char dummy;
2737 if (cinfo->btype == BT_PICASSO) {
2738 /* Klaus' hint for correct access to HDR on some boards */
2739 /* first write 0 to pixel mask (3c6) */
2740 WGen (cinfo, VGA_PEL_MSK, 0x00);
2742 /* next read dummy from pixel address (3c8) */
2743 dummy = RGen (cinfo, VGA_PEL_IW);
2746 /* now do the usual stuff to access the HDR */
2748 dummy = RGen (cinfo, VGA_PEL_MSK);
2750 dummy = RGen (cinfo, VGA_PEL_MSK);
2752 dummy = RGen (cinfo, VGA_PEL_MSK);
2754 dummy = RGen (cinfo, VGA_PEL_MSK);
2757 WGen (cinfo, VGA_PEL_MSK, val);
2760 if (cinfo->btype == BT_PICASSO) {
2761 /* now first reset HDR access counter */
2762 dummy = RGen (cinfo, VGA_PEL_IW);
2765 /* and at the end, restore the mask value */
2766 /* ## is this mask always 0xff? */
2767 WGen (cinfo, VGA_PEL_MSK, 0xff);
2773 /*** WSFR() - write to the "special function register" (SFR) ***/
2774 static void WSFR (struct cirrusfb_info *cinfo, unsigned char val)
2777 assert (cinfo->regbase != NULL);
2779 z_writeb (val, cinfo->regbase + 0x8000);
2783 /* The Picasso has a second register for switching the monitor bit */
2784 static void WSFR2 (struct cirrusfb_info *cinfo, unsigned char val)
2787 /* writing an arbitrary value to this one causes the monitor switcher */
2788 /* to flip to Amiga display */
2789 assert (cinfo->regbase != NULL);
2791 z_writeb (val, cinfo->regbase + 0x9000);
2796 /*** WClut - set CLUT entry (range: 0..63) ***/
2797 static void WClut (struct cirrusfb_info *cinfo, unsigned char regnum, unsigned char red,
2798 unsigned char green, unsigned char blue)
2800 unsigned int data = VGA_PEL_D;
2802 /* address write mode register is not translated.. */
2803 vga_w (cinfo->regbase, VGA_PEL_IW, regnum);
2805 if (cinfo->btype == BT_PICASSO || cinfo->btype == BT_PICASSO4 ||
2806 cinfo->btype == BT_ALPINE || cinfo->btype == BT_GD5480) {
2807 /* but DAC data register IS, at least for Picasso II */
2808 if (cinfo->btype == BT_PICASSO)
2810 vga_w (cinfo->regbase, data, red);
2811 vga_w (cinfo->regbase, data, green);
2812 vga_w (cinfo->regbase, data, blue);
2814 vga_w (cinfo->regbase, data, blue);
2815 vga_w (cinfo->regbase, data, green);
2816 vga_w (cinfo->regbase, data, red);
2822 /*** RClut - read CLUT entry (range 0..63) ***/
2823 static void RClut (struct cirrusfb_info *cinfo, unsigned char regnum, unsigned char *red,
2824 unsigned char *green, unsigned char *blue)
2826 unsigned int data = VGA_PEL_D;
2828 vga_w (cinfo->regbase, VGA_PEL_IR, regnum);
2830 if (cinfo->btype == BT_PICASSO || cinfo->btype == BT_PICASSO4 ||
2831 cinfo->btype == BT_ALPINE || cinfo->btype == BT_GD5480) {
2832 if (cinfo->btype == BT_PICASSO)
2834 *red = vga_r (cinfo->regbase, data);
2835 *green = vga_r (cinfo->regbase, data);
2836 *blue = vga_r (cinfo->regbase, data);
2838 *blue = vga_r (cinfo->regbase, data);
2839 *green = vga_r (cinfo->regbase, data);
2840 *red = vga_r (cinfo->regbase, data);
2846 /*******************************************************************
2849 Wait for the BitBLT engine to complete a possible earlier job
2850 *********************************************************************/
2852 /* FIXME: use interrupts instead */
2853 static void cirrusfb_WaitBLT (caddr_t regbase)
2855 /* now busy-wait until we're done */
2856 while (vga_rgfx (regbase, CL_GR31) & 0x08)
2860 /*******************************************************************
2863 perform accelerated "scrolling"
2864 ********************************************************************/
2866 static void cirrusfb_BitBLT (caddr_t regbase, int bits_per_pixel,
2867 u_short curx, u_short cury, u_short destx, u_short desty,
2868 u_short width, u_short height, u_short line_length)
2870 u_short nwidth, nheight;
2874 DPRINTK ("ENTER\n");
2877 nheight = height - 1;
2880 /* if source adr < dest addr, do the Blt backwards */
2881 if (cury <= desty) {
2882 if (cury == desty) {
2883 /* if src and dest are on the same line, check x */
2890 /* standard case: forward blitting */
2891 nsrc = (cury * line_length) + curx;
2892 ndest = (desty * line_length) + destx;
2894 /* this means start addresses are at the end, counting backwards */
2895 nsrc = cury * line_length + curx + nheight * line_length + nwidth;
2896 ndest = desty * line_length + destx + nheight * line_length + nwidth;
2900 run-down of registers to be programmed:
2908 VGA_GFX_SR_VALUE / VGA_GFX_SR_ENABLE: "fill color"
2912 cirrusfb_WaitBLT(regbase);
2914 /* pitch: set to line_length */
2915 vga_wgfx (regbase, CL_GR24, line_length & 0xff); /* dest pitch low */
2916 vga_wgfx (regbase, CL_GR25, (line_length >> 8)); /* dest pitch hi */
2917 vga_wgfx (regbase, CL_GR26, line_length & 0xff); /* source pitch low */
2918 vga_wgfx (regbase, CL_GR27, (line_length >> 8)); /* source pitch hi */
2920 /* BLT width: actual number of pixels - 1 */
2921 vga_wgfx (regbase, CL_GR20, nwidth & 0xff); /* BLT width low */
2922 vga_wgfx (regbase, CL_GR21, (nwidth >> 8)); /* BLT width hi */
2924 /* BLT height: actual number of lines -1 */
2925 vga_wgfx (regbase, CL_GR22, nheight & 0xff); /* BLT height low */
2926 vga_wgfx (regbase, CL_GR23, (nheight >> 8)); /* BLT width hi */
2928 /* BLT destination */
2929 vga_wgfx (regbase, CL_GR28, (u_char) (ndest & 0xff)); /* BLT dest low */
2930 vga_wgfx (regbase, CL_GR29, (u_char) (ndest >> 8)); /* BLT dest mid */
2931 vga_wgfx (regbase, CL_GR2A, (u_char) (ndest >> 16)); /* BLT dest hi */
2934 vga_wgfx (regbase, CL_GR2C, (u_char) (nsrc & 0xff)); /* BLT src low */
2935 vga_wgfx (regbase, CL_GR2D, (u_char) (nsrc >> 8)); /* BLT src mid */
2936 vga_wgfx (regbase, CL_GR2E, (u_char) (nsrc >> 16)); /* BLT src hi */
2939 vga_wgfx (regbase, CL_GR30, bltmode); /* BLT mode */
2941 /* BLT ROP: SrcCopy */
2942 vga_wgfx (regbase, CL_GR32, 0x0d); /* BLT ROP */
2944 /* and finally: GO! */
2945 vga_wgfx (regbase, CL_GR31, 0x02); /* BLT Start/status */
2951 /*******************************************************************
2954 perform accelerated rectangle fill
2955 ********************************************************************/
2957 static void cirrusfb_RectFill (caddr_t regbase, int bits_per_pixel,
2958 u_short x, u_short y, u_short width, u_short height,
2959 u_char color, u_short line_length)
2961 u_short nwidth, nheight;
2965 DPRINTK ("ENTER\n");
2968 nheight = height - 1;
2970 ndest = (y * line_length) + x;
2972 cirrusfb_WaitBLT(regbase);
2974 /* pitch: set to line_length */
2975 vga_wgfx (regbase, CL_GR24, line_length & 0xff); /* dest pitch low */
2976 vga_wgfx (regbase, CL_GR25, (line_length >> 8)); /* dest pitch hi */
2977 vga_wgfx (regbase, CL_GR26, line_length & 0xff); /* source pitch low */
2978 vga_wgfx (regbase, CL_GR27, (line_length >> 8)); /* source pitch hi */
2980 /* BLT width: actual number of pixels - 1 */
2981 vga_wgfx (regbase, CL_GR20, nwidth & 0xff); /* BLT width low */
2982 vga_wgfx (regbase, CL_GR21, (nwidth >> 8)); /* BLT width hi */
2984 /* BLT height: actual number of lines -1 */
2985 vga_wgfx (regbase, CL_GR22, nheight & 0xff); /* BLT height low */
2986 vga_wgfx (regbase, CL_GR23, (nheight >> 8)); /* BLT width hi */
2988 /* BLT destination */
2989 vga_wgfx (regbase, CL_GR28, (u_char) (ndest & 0xff)); /* BLT dest low */
2990 vga_wgfx (regbase, CL_GR29, (u_char) (ndest >> 8)); /* BLT dest mid */
2991 vga_wgfx (regbase, CL_GR2A, (u_char) (ndest >> 16)); /* BLT dest hi */
2993 /* BLT source: set to 0 (is a dummy here anyway) */
2994 vga_wgfx (regbase, CL_GR2C, 0x00); /* BLT src low */
2995 vga_wgfx (regbase, CL_GR2D, 0x00); /* BLT src mid */
2996 vga_wgfx (regbase, CL_GR2E, 0x00); /* BLT src hi */
2998 /* This is a ColorExpand Blt, using the */
2999 /* same color for foreground and background */
3000 vga_wgfx (regbase, VGA_GFX_SR_VALUE, color); /* foreground color */
3001 vga_wgfx (regbase, VGA_GFX_SR_ENABLE, color); /* background color */
3004 if (bits_per_pixel == 16) {
3005 vga_wgfx (regbase, CL_GR10, color); /* foreground color */
3006 vga_wgfx (regbase, CL_GR11, color); /* background color */
3009 } else if (bits_per_pixel == 32) {
3010 vga_wgfx (regbase, CL_GR10, color); /* foreground color */
3011 vga_wgfx (regbase, CL_GR11, color); /* background color */
3012 vga_wgfx (regbase, CL_GR12, color); /* foreground color */
3013 vga_wgfx (regbase, CL_GR13, color); /* background color */
3014 vga_wgfx (regbase, CL_GR14, 0); /* foreground color */
3015 vga_wgfx (regbase, CL_GR15, 0); /* background color */
3019 /* BLT mode: color expand, Enable 8x8 copy (faster?) */
3020 vga_wgfx (regbase, CL_GR30, op); /* BLT mode */
3022 /* BLT ROP: SrcCopy */
3023 vga_wgfx (regbase, CL_GR32, 0x0d); /* BLT ROP */
3025 /* and finally: GO! */
3026 vga_wgfx (regbase, CL_GR31, 0x02); /* BLT Start/status */
3032 /**************************************************************************
3033 * bestclock() - determine closest possible clock lower(?) than the
3034 * desired pixel clock
3035 **************************************************************************/
3036 static void bestclock (long freq, long *best, long *nom,
3037 long *den, long *div, long maxfreq)
3041 assert (best != NULL);
3042 assert (nom != NULL);
3043 assert (den != NULL);
3044 assert (div != NULL);
3045 assert (maxfreq > 0);
3051 DPRINTK ("ENTER\n");
3062 for (n = 32; n < 128; n++) {
3063 d = (143181 * n) / f;
3064 if ((d >= 7) && (d <= 63)) {
3067 h = (14318 * n) / d;
3068 if (abs (h - freq) < abs (*best - freq)) {
3080 d = ((143181 * n) + f - 1) / f;
3081 if ((d >= 7) && (d <= 63)) {
3084 h = (14318 * n) / d;
3085 if (abs (h - freq) < abs (*best - freq)) {
3099 DPRINTK ("Best possible values for given frequency:\n");
3100 DPRINTK (" best: %ld kHz nom: %ld den: %ld div: %ld\n",
3101 freq, *nom, *den, *div);
3107 /* -------------------------------------------------------------------------
3109 * debugging functions
3111 * -------------------------------------------------------------------------
3114 #ifdef CIRRUSFB_DEBUG
3117 * cirrusfb_dbg_print_byte
3118 * @name: name associated with byte value to be displayed
3119 * @val: byte value to be displayed
3122 * Display an indented string, along with a hexidecimal byte value, and
3123 * its decoded bits. Bits 7 through 0 are listed in left-to-right
3128 void cirrusfb_dbg_print_byte (const char *name, unsigned char val)
3130 DPRINTK ("%8s = 0x%02X (bits 7-0: %c%c%c%c%c%c%c%c)\n",
3132 val & 0x80 ? '1' : '0',
3133 val & 0x40 ? '1' : '0',
3134 val & 0x20 ? '1' : '0',
3135 val & 0x10 ? '1' : '0',
3136 val & 0x08 ? '1' : '0',
3137 val & 0x04 ? '1' : '0',
3138 val & 0x02 ? '1' : '0',
3139 val & 0x01 ? '1' : '0');
3144 * cirrusfb_dbg_print_regs
3145 * @base: If using newmmio, the newmmio base address, otherwise %NULL
3146 * @reg_class: type of registers to read: %CRT, or %SEQ
3149 * Dumps the given list of VGA CRTC registers. If @base is %NULL,
3150 * old-style I/O ports are queried for information, otherwise MMIO is
3151 * used at the given @base address to query the information.
3155 void cirrusfb_dbg_print_regs (caddr_t regbase, cirrusfb_dbg_reg_class_t reg_class,...)
3158 unsigned char val = 0;
3162 va_start (list, reg_class);
3164 name = va_arg (list, char *);
3165 while (name != NULL) {
3166 reg = va_arg (list, int);
3168 switch (reg_class) {
3170 val = vga_rcrt (regbase, (unsigned char) reg);
3173 val = vga_rseq (regbase, (unsigned char) reg);
3176 /* should never occur */
3181 cirrusfb_dbg_print_byte (name, val);
3183 name = va_arg (list, char *);
3198 void cirrusfb_dump (void)
3200 cirrusfb_dbg_reg_dump (NULL);
3205 * cirrusfb_dbg_reg_dump
3206 * @base: If using newmmio, the newmmio base address, otherwise %NULL
3209 * Dumps a list of interesting VGA and CIRRUSFB registers. If @base is %NULL,
3210 * old-style I/O ports are queried for information, otherwise MMIO is
3211 * used at the given @base address to query the information.
3215 void cirrusfb_dbg_reg_dump (caddr_t regbase)
3217 DPRINTK ("CIRRUSFB VGA CRTC register dump:\n");
3219 cirrusfb_dbg_print_regs (regbase, CRT,
3271 DPRINTK ("CIRRUSFB VGA SEQ register dump:\n");
3273 cirrusfb_dbg_print_regs (regbase, SEQ,
3305 #endif /* CIRRUSFB_DEBUG */