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 #include <linux/module.h>
38 #include <linux/kernel.h>
39 #include <linux/errno.h>
40 #include <linux/string.h>
42 #include <linux/delay.h>
44 #include <linux/init.h>
45 #include <asm/pgtable.h>
48 #include <linux/zorro.h>
51 #include <linux/pci.h>
54 #include <asm/amigahw.h>
56 #ifdef CONFIG_PPC_PREP
57 #include <asm/machdep.h>
58 #define isPReP machine_is(prep)
63 #include <video/vga.h>
64 #include <video/cirrus.h>
66 /*****************************************************************
68 * debugging and utility macros
72 /* disable runtime assertions? */
73 /* #define CIRRUSFB_NDEBUG */
75 /* debugging assertions */
76 #ifndef CIRRUSFB_NDEBUG
77 #define assert(expr) \
79 printk("Assertion failed! %s,%s,%s,line=%d\n", \
80 #expr, __FILE__, __func__, __LINE__); \
86 #define MB_ (1024 * 1024)
88 /*****************************************************************
98 BT_PICCOLO, /* GD5426 */
99 BT_PICASSO, /* GD5426 or GD5428 */
100 BT_SPECTRUM, /* GD5426 or GD5428 */
101 BT_PICASSO4, /* GD5446 */
102 BT_ALPINE, /* GD543x/4x */
104 BT_LAGUNA, /* GD5462/64 */
105 BT_LAGUNAB, /* GD5465 */
109 * per-board-type information, used for enumerating and abstracting
110 * chip-specific information
111 * NOTE: MUST be in the same order as enum cirrus_board in order to
112 * use direct indexing on this array
113 * NOTE: '__initdata' cannot be used as some of this info
114 * is required at runtime. Maybe separate into an init-only and
117 static const struct cirrusfb_board_info_rec {
118 char *name; /* ASCII name of chipset */
119 long maxclock[5]; /* maximum video clock */
120 /* for 1/4bpp, 8bpp 15/16bpp, 24bpp, 32bpp - numbers from xorg code */
121 bool init_sr07 : 1; /* init SR07 during init_vgachip() */
122 bool init_sr1f : 1; /* write SR1F during init_vgachip() */
123 /* construct bit 19 of screen start address */
124 bool scrn_start_bit19 : 1;
126 /* initial SR07 value, then for each mode */
128 unsigned char sr07_1bpp;
129 unsigned char sr07_1bpp_mux;
130 unsigned char sr07_8bpp;
131 unsigned char sr07_8bpp_mux;
133 unsigned char sr1f; /* SR1F VGA initial register value */
134 } cirrusfb_board_info[] = {
139 /* the SD64/P4 have a higher max. videoclock */
140 135100, 135100, 85500, 85500, 0
144 .scrn_start_bit19 = true,
147 .sr07_1bpp_mux = 0xF6,
149 .sr07_8bpp_mux = 0xF7,
153 .name = "CL Piccolo",
156 90000, 90000, 90000, 90000, 90000
160 .scrn_start_bit19 = false,
167 .name = "CL Picasso",
170 90000, 90000, 90000, 90000, 90000
174 .scrn_start_bit19 = false,
181 .name = "CL Spectrum",
184 90000, 90000, 90000, 90000, 90000
188 .scrn_start_bit19 = false,
195 .name = "CL Picasso4",
197 135100, 135100, 85500, 85500, 0
201 .scrn_start_bit19 = true,
204 .sr07_1bpp_mux = 0xA6,
206 .sr07_8bpp_mux = 0xA7,
212 /* for the GD5430. GD5446 can do more... */
213 85500, 85500, 50000, 28500, 0
217 .scrn_start_bit19 = true,
220 .sr07_1bpp_mux = 0xA6,
222 .sr07_8bpp_mux = 0xA7,
228 135100, 200000, 200000, 135100, 135100
232 .scrn_start_bit19 = true,
241 /* taken from X11 code */
242 170000, 170000, 170000, 170000, 135100,
246 .scrn_start_bit19 = true,
249 .name = "CL Laguna AGP",
251 /* taken from X11 code */
252 170000, 250000, 170000, 170000, 135100,
256 .scrn_start_bit19 = true,
261 #define CHIP(id, btype) \
262 { PCI_VENDOR_ID_CIRRUS, id, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (btype) }
264 static struct pci_device_id cirrusfb_pci_table[] = {
265 CHIP(PCI_DEVICE_ID_CIRRUS_5436, BT_ALPINE),
266 CHIP(PCI_DEVICE_ID_CIRRUS_5434_8, BT_SD64),
267 CHIP(PCI_DEVICE_ID_CIRRUS_5434_4, BT_SD64),
268 CHIP(PCI_DEVICE_ID_CIRRUS_5430, BT_ALPINE), /* GD-5440 is same id */
269 CHIP(PCI_DEVICE_ID_CIRRUS_7543, BT_ALPINE),
270 CHIP(PCI_DEVICE_ID_CIRRUS_7548, BT_ALPINE),
271 CHIP(PCI_DEVICE_ID_CIRRUS_5480, BT_GD5480), /* MacPicasso likely */
272 CHIP(PCI_DEVICE_ID_CIRRUS_5446, BT_PICASSO4), /* Picasso 4 is 5446 */
273 CHIP(PCI_DEVICE_ID_CIRRUS_5462, BT_LAGUNA), /* CL Laguna */
274 CHIP(PCI_DEVICE_ID_CIRRUS_5464, BT_LAGUNA), /* CL Laguna 3D */
275 CHIP(PCI_DEVICE_ID_CIRRUS_5465, BT_LAGUNAB), /* CL Laguna 3DA*/
278 MODULE_DEVICE_TABLE(pci, cirrusfb_pci_table);
280 #endif /* CONFIG_PCI */
284 enum cirrus_board type; /* Board type */
285 u32 regoffset; /* Offset of registers in first Zorro device */
286 u32 ramsize; /* Size of video RAM in first Zorro device */
287 /* If zero, use autoprobe on RAM device */
288 u32 ramoffset; /* Offset of video RAM in first Zorro device */
289 zorro_id ramid; /* Zorro ID of RAM device */
290 zorro_id ramid2; /* Zorro ID of optional second RAM device */
293 static const struct zorrocl zcl_sd64 __devinitconst = {
295 .ramid = ZORRO_PROD_HELFRICH_SD64_RAM,
298 static const struct zorrocl zcl_piccolo __devinitconst = {
300 .ramid = ZORRO_PROD_HELFRICH_PICCOLO_RAM,
303 static const struct zorrocl zcl_picasso __devinitconst = {
305 .ramid = ZORRO_PROD_VILLAGE_TRONIC_PICASSO_II_II_PLUS_RAM,
308 static const struct zorrocl zcl_spectrum __devinitconst = {
310 .ramid = ZORRO_PROD_GVP_EGS_28_24_SPECTRUM_RAM,
313 static const struct zorrocl zcl_picasso4_z3 __devinitconst = {
315 .regoffset = 0x00600000,
317 .ramoffset = 0x01000000, /* 0x02000000 for 64 MiB boards */
320 static const struct zorrocl zcl_picasso4_z2 __devinitconst = {
322 .regoffset = 0x10000,
323 .ramid = ZORRO_PROD_VILLAGE_TRONIC_PICASSO_IV_Z2_RAM1,
324 .ramid2 = ZORRO_PROD_VILLAGE_TRONIC_PICASSO_IV_Z2_RAM2,
328 static const struct zorro_device_id cirrusfb_zorro_table[] __devinitconst = {
330 .id = ZORRO_PROD_HELFRICH_SD64_REG,
331 .driver_data = (unsigned long)&zcl_sd64,
333 .id = ZORRO_PROD_HELFRICH_PICCOLO_REG,
334 .driver_data = (unsigned long)&zcl_piccolo,
336 .id = ZORRO_PROD_VILLAGE_TRONIC_PICASSO_II_II_PLUS_REG,
337 .driver_data = (unsigned long)&zcl_picasso,
339 .id = ZORRO_PROD_GVP_EGS_28_24_SPECTRUM_REG,
340 .driver_data = (unsigned long)&zcl_spectrum,
342 .id = ZORRO_PROD_VILLAGE_TRONIC_PICASSO_IV_Z3,
343 .driver_data = (unsigned long)&zcl_picasso4_z3,
345 .id = ZORRO_PROD_VILLAGE_TRONIC_PICASSO_IV_Z2_REG,
346 .driver_data = (unsigned long)&zcl_picasso4_z2,
350 MODULE_DEVICE_TABLE(zorro, cirrusfb_zorro_table);
351 #endif /* CONFIG_ZORRO */
353 #ifdef CIRRUSFB_DEBUG
354 enum cirrusfb_dbg_reg_class {
358 #endif /* CIRRUSFB_DEBUG */
360 /* info about board */
361 struct cirrusfb_info {
363 u8 __iomem *laguna_mmio;
364 enum cirrus_board btype;
365 unsigned char SFR; /* Shadow of special function register */
370 u32 pseudo_palette[16];
372 void (*unmap)(struct fb_info *info);
375 static bool noaccel __devinitdata;
376 static char *mode_option __devinitdata = "640x480@60";
378 /****************************************************************************/
379 /**** BEGIN PROTOTYPES ******************************************************/
381 /*--- Interface used by the world ------------------------------------------*/
382 static int cirrusfb_pan_display(struct fb_var_screeninfo *var,
383 struct fb_info *info);
385 /*--- Internal routines ----------------------------------------------------*/
386 static void init_vgachip(struct fb_info *info);
387 static void switch_monitor(struct cirrusfb_info *cinfo, int on);
388 static void WGen(const struct cirrusfb_info *cinfo,
389 int regnum, unsigned char val);
390 static unsigned char RGen(const struct cirrusfb_info *cinfo, int regnum);
391 static void AttrOn(const struct cirrusfb_info *cinfo);
392 static void WHDR(const struct cirrusfb_info *cinfo, unsigned char val);
393 static void WSFR(struct cirrusfb_info *cinfo, unsigned char val);
394 static void WSFR2(struct cirrusfb_info *cinfo, unsigned char val);
395 static void WClut(struct cirrusfb_info *cinfo, unsigned char regnum,
396 unsigned char red, unsigned char green, unsigned char blue);
398 static void RClut(struct cirrusfb_info *cinfo, unsigned char regnum,
399 unsigned char *red, unsigned char *green,
400 unsigned char *blue);
402 static void cirrusfb_WaitBLT(u8 __iomem *regbase);
403 static void cirrusfb_BitBLT(u8 __iomem *regbase, int bits_per_pixel,
404 u_short curx, u_short cury,
405 u_short destx, u_short desty,
406 u_short width, u_short height,
407 u_short line_length);
408 static void cirrusfb_RectFill(u8 __iomem *regbase, int bits_per_pixel,
409 u_short x, u_short y,
410 u_short width, u_short height,
411 u32 fg_color, u32 bg_color,
412 u_short line_length, u_char blitmode);
414 static void bestclock(long freq, int *nom, int *den, int *div);
416 #ifdef CIRRUSFB_DEBUG
417 static void cirrusfb_dbg_reg_dump(struct fb_info *info, caddr_t regbase);
418 static void cirrusfb_dbg_print_regs(struct fb_info *info,
420 enum cirrusfb_dbg_reg_class reg_class, ...);
421 #endif /* CIRRUSFB_DEBUG */
423 /*** END PROTOTYPES ********************************************************/
424 /*****************************************************************************/
425 /*** BEGIN Interface Used by the World ***************************************/
427 static inline int is_laguna(const struct cirrusfb_info *cinfo)
429 return cinfo->btype == BT_LAGUNA || cinfo->btype == BT_LAGUNAB;
432 static int opencount;
434 /*--- Open /dev/fbx ---------------------------------------------------------*/
435 static int cirrusfb_open(struct fb_info *info, int user)
437 if (opencount++ == 0)
438 switch_monitor(info->par, 1);
442 /*--- Close /dev/fbx --------------------------------------------------------*/
443 static int cirrusfb_release(struct fb_info *info, int user)
445 if (--opencount == 0)
446 switch_monitor(info->par, 0);
450 /**** END Interface used by the World *************************************/
451 /****************************************************************************/
452 /**** BEGIN Hardware specific Routines **************************************/
454 /* Check if the MCLK is not a better clock source */
455 static int cirrusfb_check_mclk(struct fb_info *info, long freq)
457 struct cirrusfb_info *cinfo = info->par;
458 long mclk = vga_rseq(cinfo->regbase, CL_SEQR1F) & 0x3f;
460 /* Read MCLK value */
461 mclk = (14318 * mclk) >> 3;
462 dev_dbg(info->device, "Read MCLK of %ld kHz\n", mclk);
464 /* Determine if we should use MCLK instead of VCLK, and if so, what we
465 * should divide it by to get VCLK
468 if (abs(freq - mclk) < 250) {
469 dev_dbg(info->device, "Using VCLK = MCLK\n");
471 } else if (abs(freq - (mclk / 2)) < 250) {
472 dev_dbg(info->device, "Using VCLK = MCLK/2\n");
479 static int cirrusfb_check_pixclock(const struct fb_var_screeninfo *var,
480 struct fb_info *info)
484 struct cirrusfb_info *cinfo = info->par;
485 unsigned maxclockidx = var->bits_per_pixel >> 3;
487 /* convert from ps to kHz */
488 freq = PICOS2KHZ(var->pixclock);
490 dev_dbg(info->device, "desired pixclock: %ld kHz\n", freq);
492 maxclock = cirrusfb_board_info[cinfo->btype].maxclock[maxclockidx];
493 cinfo->multiplexing = 0;
495 /* If the frequency is greater than we can support, we might be able
496 * to use multiplexing for the video mode */
497 if (freq > maxclock) {
498 dev_err(info->device,
499 "Frequency greater than maxclock (%ld kHz)\n",
504 * Additional constraint: 8bpp uses DAC clock doubling to allow maximum
507 if (var->bits_per_pixel == 8) {
508 switch (cinfo->btype) {
513 cinfo->multiplexing = 1;
517 cinfo->multiplexing = 1;
525 /* If we have a 1MB 5434, we need to put ourselves in a mode where
526 * the VCLK is double the pixel clock. */
527 cinfo->doubleVCLK = 0;
528 if (cinfo->btype == BT_SD64 && info->fix.smem_len <= MB_ &&
529 var->bits_per_pixel == 16) {
530 cinfo->doubleVCLK = 1;
536 static int cirrusfb_check_var(struct fb_var_screeninfo *var,
537 struct fb_info *info)
540 /* memory size in pixels */
541 unsigned pixels = info->screen_size * 8 / var->bits_per_pixel;
542 struct cirrusfb_info *cinfo = info->par;
544 switch (var->bits_per_pixel) {
548 var->green = var->red;
549 var->blue = var->red;
555 var->green = var->red;
556 var->blue = var->red;
562 var->green.offset = -3;
563 var->blue.offset = 8;
565 var->red.offset = 11;
566 var->green.offset = 5;
567 var->blue.offset = 0;
570 var->green.length = 6;
571 var->blue.length = 5;
577 var->green.offset = 8;
578 var->blue.offset = 16;
580 var->red.offset = 16;
581 var->green.offset = 8;
582 var->blue.offset = 0;
585 var->green.length = 8;
586 var->blue.length = 8;
590 dev_dbg(info->device,
591 "Unsupported bpp size: %d\n", var->bits_per_pixel);
595 if (var->xres_virtual < var->xres)
596 var->xres_virtual = var->xres;
597 /* use highest possible virtual resolution */
598 if (var->yres_virtual == -1) {
599 var->yres_virtual = pixels / var->xres_virtual;
601 dev_info(info->device,
602 "virtual resolution set to maximum of %dx%d\n",
603 var->xres_virtual, var->yres_virtual);
605 if (var->yres_virtual < var->yres)
606 var->yres_virtual = var->yres;
608 if (var->xres_virtual * var->yres_virtual > pixels) {
609 dev_err(info->device, "mode %dx%dx%d rejected... "
610 "virtual resolution too high to fit into video memory!\n",
611 var->xres_virtual, var->yres_virtual,
612 var->bits_per_pixel);
616 if (var->xoffset < 0)
618 if (var->yoffset < 0)
621 /* truncate xoffset and yoffset to maximum if too high */
622 if (var->xoffset > var->xres_virtual - var->xres)
623 var->xoffset = var->xres_virtual - var->xres - 1;
624 if (var->yoffset > var->yres_virtual - var->yres)
625 var->yoffset = var->yres_virtual - var->yres - 1;
628 var->green.msb_right =
629 var->blue.msb_right =
632 var->transp.msb_right = 0;
635 if (var->vmode & FB_VMODE_DOUBLE)
637 else if (var->vmode & FB_VMODE_INTERLACED)
638 yres = (yres + 1) / 2;
641 dev_err(info->device, "ERROR: VerticalTotal >= 1280; "
642 "special treatment required! (TODO)\n");
646 if (cirrusfb_check_pixclock(var, info))
649 if (!is_laguna(cinfo))
650 var->accel_flags = FB_ACCELF_TEXT;
655 static void cirrusfb_set_mclk_as_source(const struct fb_info *info, int div)
657 struct cirrusfb_info *cinfo = info->par;
658 unsigned char old1f, old1e;
660 assert(cinfo != NULL);
661 old1f = vga_rseq(cinfo->regbase, CL_SEQR1F) & ~0x40;
664 dev_dbg(info->device, "Set %s as pixclock source.\n",
665 (div == 2) ? "MCLK/2" : "MCLK");
667 old1e = vga_rseq(cinfo->regbase, CL_SEQR1E) & ~0x1;
671 vga_wseq(cinfo->regbase, CL_SEQR1E, old1e);
673 vga_wseq(cinfo->regbase, CL_SEQR1F, old1f);
676 /*************************************************************************
677 cirrusfb_set_par_foo()
679 actually writes the values for a new video mode into the hardware,
680 **************************************************************************/
681 static int cirrusfb_set_par_foo(struct fb_info *info)
683 struct cirrusfb_info *cinfo = info->par;
684 struct fb_var_screeninfo *var = &info->var;
685 u8 __iomem *regbase = cinfo->regbase;
688 const struct cirrusfb_board_info_rec *bi;
689 int hdispend, hsyncstart, hsyncend, htotal;
690 int yres, vdispend, vsyncstart, vsyncend, vtotal;
693 unsigned int control = 0, format = 0, threshold = 0;
695 dev_dbg(info->device, "Requested mode: %dx%dx%d\n",
696 var->xres, var->yres, var->bits_per_pixel);
698 switch (var->bits_per_pixel) {
700 info->fix.line_length = var->xres_virtual / 8;
701 info->fix.visual = FB_VISUAL_MONO10;
705 info->fix.line_length = var->xres_virtual;
706 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
711 info->fix.line_length = var->xres_virtual *
712 var->bits_per_pixel >> 3;
713 info->fix.visual = FB_VISUAL_TRUECOLOR;
716 info->fix.type = FB_TYPE_PACKED_PIXELS;
720 bi = &cirrusfb_board_info[cinfo->btype];
722 hsyncstart = var->xres + var->right_margin;
723 hsyncend = hsyncstart + var->hsync_len;
724 htotal = (hsyncend + var->left_margin) / 8;
725 hdispend = var->xres / 8;
726 hsyncstart = hsyncstart / 8;
727 hsyncend = hsyncend / 8;
729 vdispend = var->yres;
730 vsyncstart = vdispend + var->lower_margin;
731 vsyncend = vsyncstart + var->vsync_len;
732 vtotal = vsyncend + var->upper_margin;
734 if (var->vmode & FB_VMODE_DOUBLE) {
739 } else if (var->vmode & FB_VMODE_INTERLACED) {
740 vdispend = (vdispend + 1) / 2;
741 vsyncstart = (vsyncstart + 1) / 2;
742 vsyncend = (vsyncend + 1) / 2;
743 vtotal = (vtotal + 1) / 2;
758 if (cinfo->multiplexing) {
770 /* unlock register VGA_CRTC_H_TOTAL..CRT7 */
771 vga_wcrt(regbase, VGA_CRTC_V_SYNC_END, 0x20); /* previously: 0x00) */
773 /* if debugging is enabled, all parameters get output before writing */
774 dev_dbg(info->device, "CRT0: %d\n", htotal);
775 vga_wcrt(regbase, VGA_CRTC_H_TOTAL, htotal);
777 dev_dbg(info->device, "CRT1: %d\n", hdispend);
778 vga_wcrt(regbase, VGA_CRTC_H_DISP, hdispend);
780 dev_dbg(info->device, "CRT2: %d\n", var->xres / 8);
781 vga_wcrt(regbase, VGA_CRTC_H_BLANK_START, var->xres / 8);
783 /* + 128: Compatible read */
784 dev_dbg(info->device, "CRT3: 128+%d\n", (htotal + 5) % 32);
785 vga_wcrt(regbase, VGA_CRTC_H_BLANK_END,
786 128 + ((htotal + 5) % 32));
788 dev_dbg(info->device, "CRT4: %d\n", hsyncstart);
789 vga_wcrt(regbase, VGA_CRTC_H_SYNC_START, hsyncstart);
792 if ((htotal + 5) & 32)
794 dev_dbg(info->device, "CRT5: %d\n", tmp);
795 vga_wcrt(regbase, VGA_CRTC_H_SYNC_END, tmp);
797 dev_dbg(info->device, "CRT6: %d\n", vtotal & 0xff);
798 vga_wcrt(regbase, VGA_CRTC_V_TOTAL, vtotal & 0xff);
800 tmp = 16; /* LineCompare bit #9 */
805 if (vsyncstart & 256)
807 if ((vdispend + 1) & 256)
813 if (vsyncstart & 512)
815 dev_dbg(info->device, "CRT7: %d\n", tmp);
816 vga_wcrt(regbase, VGA_CRTC_OVERFLOW, tmp);
818 tmp = 0x40; /* LineCompare bit #8 */
819 if ((vdispend + 1) & 512)
821 if (var->vmode & FB_VMODE_DOUBLE)
823 dev_dbg(info->device, "CRT9: %d\n", tmp);
824 vga_wcrt(regbase, VGA_CRTC_MAX_SCAN, tmp);
826 dev_dbg(info->device, "CRT10: %d\n", vsyncstart & 0xff);
827 vga_wcrt(regbase, VGA_CRTC_V_SYNC_START, vsyncstart & 0xff);
829 dev_dbg(info->device, "CRT11: 64+32+%d\n", vsyncend % 16);
830 vga_wcrt(regbase, VGA_CRTC_V_SYNC_END, vsyncend % 16 + 64 + 32);
832 dev_dbg(info->device, "CRT12: %d\n", vdispend & 0xff);
833 vga_wcrt(regbase, VGA_CRTC_V_DISP_END, vdispend & 0xff);
835 dev_dbg(info->device, "CRT15: %d\n", (vdispend + 1) & 0xff);
836 vga_wcrt(regbase, VGA_CRTC_V_BLANK_START, (vdispend + 1) & 0xff);
838 dev_dbg(info->device, "CRT16: %d\n", vtotal & 0xff);
839 vga_wcrt(regbase, VGA_CRTC_V_BLANK_END, vtotal & 0xff);
841 dev_dbg(info->device, "CRT18: 0xff\n");
842 vga_wcrt(regbase, VGA_CRTC_LINE_COMPARE, 0xff);
845 if (var->vmode & FB_VMODE_INTERLACED)
847 if ((htotal + 5) & 64)
849 if ((htotal + 5) & 128)
856 dev_dbg(info->device, "CRT1a: %d\n", tmp);
857 vga_wcrt(regbase, CL_CRT1A, tmp);
859 freq = PICOS2KHZ(var->pixclock);
860 if (var->bits_per_pixel == 24)
861 if (cinfo->btype == BT_ALPINE || cinfo->btype == BT_SD64)
863 if (cinfo->multiplexing)
865 if (cinfo->doubleVCLK)
868 bestclock(freq, &nom, &den, &div);
870 dev_dbg(info->device, "VCLK freq: %ld kHz nom: %d den: %d div: %d\n",
871 freq, nom, den, div);
874 /* hardware RefClock: 14.31818 MHz */
875 /* formula: VClk = (OSC * N) / (D * (1+P)) */
876 /* Example: VClk = (14.31818 * 91) / (23 * (1+1)) = 28.325 MHz */
878 if (cinfo->btype == BT_ALPINE || cinfo->btype == BT_PICASSO4 ||
879 cinfo->btype == BT_SD64) {
880 /* if freq is close to mclk or mclk/2 select mclk
883 int divMCLK = cirrusfb_check_mclk(info, freq);
886 cirrusfb_set_mclk_as_source(info, divMCLK);
888 if (is_laguna(cinfo)) {
889 long pcifc = fb_readl(cinfo->laguna_mmio + 0x3fc);
890 unsigned char tile = fb_readb(cinfo->laguna_mmio + 0x407);
891 unsigned short tile_control;
893 if (cinfo->btype == BT_LAGUNAB) {
894 tile_control = fb_readw(cinfo->laguna_mmio + 0x2c4);
895 tile_control &= ~0x80;
896 fb_writew(tile_control, cinfo->laguna_mmio + 0x2c4);
899 fb_writel(pcifc | 0x10000000l, cinfo->laguna_mmio + 0x3fc);
900 fb_writeb(tile & 0x3f, cinfo->laguna_mmio + 0x407);
901 control = fb_readw(cinfo->laguna_mmio + 0x402);
902 threshold = fb_readw(cinfo->laguna_mmio + 0xea);
905 threshold &= 0xffc0 & 0x3fbf;
911 /* 6 bit denom; ONLY 5434!!! (bugged me 10 days) */
912 if ((cinfo->btype == BT_SD64) ||
913 (cinfo->btype == BT_ALPINE) ||
914 (cinfo->btype == BT_GD5480))
917 /* Laguna chipset has reversed clock registers */
918 if (is_laguna(cinfo)) {
919 vga_wseq(regbase, CL_SEQRE, tmp);
920 vga_wseq(regbase, CL_SEQR1E, nom);
922 vga_wseq(regbase, CL_SEQRE, nom);
923 vga_wseq(regbase, CL_SEQR1E, tmp);
929 vga_wcrt(regbase, VGA_CRTC_MODE, 0xc7);
931 /* mode control: VGA_CRTC_START_HI enable, ROTATE(?), 16bit
932 * address wrap, no compat. */
933 vga_wcrt(regbase, VGA_CRTC_MODE, 0xc3);
935 /* don't know if it would hurt to also program this if no interlaced */
936 /* mode is used, but I feel better this way.. :-) */
937 if (var->vmode & FB_VMODE_INTERLACED)
938 vga_wcrt(regbase, VGA_CRTC_REGS, htotal / 2);
940 vga_wcrt(regbase, VGA_CRTC_REGS, 0x00); /* interlace control */
942 /* adjust horizontal/vertical sync type (low/high), use VCLK3 */
943 /* enable display memory & CRTC I/O address for color mode */
945 if (var->sync & FB_SYNC_HOR_HIGH_ACT)
947 if (var->sync & FB_SYNC_VERT_HIGH_ACT)
949 WGen(cinfo, VGA_MIS_W, tmp);
951 /* text cursor on and start line */
952 vga_wcrt(regbase, VGA_CRTC_CURSOR_START, 0);
953 /* text cursor end line */
954 vga_wcrt(regbase, VGA_CRTC_CURSOR_END, 31);
956 /******************************************************
962 /* programming for different color depths */
963 if (var->bits_per_pixel == 1) {
964 dev_dbg(info->device, "preparing for 1 bit deep display\n");
965 vga_wgfx(regbase, VGA_GFX_MODE, 0); /* mode register */
968 switch (cinfo->btype) {
976 vga_wseq(regbase, CL_SEQR7,
977 cinfo->multiplexing ?
978 bi->sr07_1bpp_mux : bi->sr07_1bpp);
983 vga_wseq(regbase, CL_SEQR7,
984 vga_rseq(regbase, CL_SEQR7) & ~0x01);
988 dev_warn(info->device, "unknown Board\n");
992 /* Extended Sequencer Mode */
993 switch (cinfo->btype) {
997 /* evtl d0 bei 1 bit? avoid FIFO underruns..? */
998 vga_wseq(regbase, CL_SEQRF, 0xb0);
1002 /* ## vorher d0 avoid FIFO underruns..? */
1003 vga_wseq(regbase, CL_SEQRF, 0xd0);
1016 dev_warn(info->device, "unknown Board\n");
1020 /* pixel mask: pass-through for first plane */
1021 WGen(cinfo, VGA_PEL_MSK, 0x01);
1022 if (cinfo->multiplexing)
1023 /* hidden dac reg: 1280x1024 */
1026 /* hidden dac: nothing */
1028 /* memory mode: odd/even, ext. memory */
1029 vga_wseq(regbase, VGA_SEQ_MEMORY_MODE, 0x06);
1030 /* plane mask: only write to first plane */
1031 vga_wseq(regbase, VGA_SEQ_PLANE_WRITE, 0x01);
1034 /******************************************************
1040 else if (var->bits_per_pixel == 8) {
1041 dev_dbg(info->device, "preparing for 8 bit deep display\n");
1042 switch (cinfo->btype) {
1050 vga_wseq(regbase, CL_SEQR7,
1051 cinfo->multiplexing ?
1052 bi->sr07_8bpp_mux : bi->sr07_8bpp);
1057 vga_wseq(regbase, CL_SEQR7,
1058 vga_rseq(regbase, CL_SEQR7) | 0x01);
1063 dev_warn(info->device, "unknown Board\n");
1067 switch (cinfo->btype) {
1071 /* Fast Page-Mode writes */
1072 vga_wseq(regbase, CL_SEQRF, 0xb0);
1077 /* ### INCOMPLETE!! */
1078 vga_wseq(regbase, CL_SEQRF, 0xb8);
1089 dev_warn(info->device, "unknown board\n");
1093 /* mode register: 256 color mode */
1094 vga_wgfx(regbase, VGA_GFX_MODE, 64);
1095 if (cinfo->multiplexing)
1096 /* hidden dac reg: 1280x1024 */
1099 /* hidden dac: nothing */
1103 /******************************************************
1109 else if (var->bits_per_pixel == 16) {
1110 dev_dbg(info->device, "preparing for 16 bit deep display\n");
1111 switch (cinfo->btype) {
1114 vga_wseq(regbase, CL_SEQR7, 0x87);
1115 /* Fast Page-Mode writes */
1116 vga_wseq(regbase, CL_SEQRF, 0xb0);
1120 vga_wseq(regbase, CL_SEQR7, 0x27);
1121 /* Fast Page-Mode writes */
1122 vga_wseq(regbase, CL_SEQRF, 0xb0);
1128 /* Extended Sequencer Mode: 256c col. mode */
1129 vga_wseq(regbase, CL_SEQR7,
1130 cinfo->doubleVCLK ? 0xa3 : 0xa7);
1134 vga_wseq(regbase, CL_SEQR7, 0x17);
1135 /* We already set SRF and SR1F */
1140 vga_wseq(regbase, CL_SEQR7,
1141 vga_rseq(regbase, CL_SEQR7) & ~0x01);
1148 dev_warn(info->device, "unknown Board\n");
1152 /* mode register: 256 color mode */
1153 vga_wgfx(regbase, VGA_GFX_MODE, 64);
1155 WHDR(cinfo, cinfo->doubleVCLK ? 0xe1 : 0xc1);
1156 #elif defined(CONFIG_ZORRO)
1157 /* FIXME: CONFIG_PCI and CONFIG_ZORRO may be defined both */
1158 WHDR(cinfo, 0xa0); /* hidden dac reg: nothing special */
1162 /******************************************************
1168 else if (var->bits_per_pixel == 24) {
1169 dev_dbg(info->device, "preparing for 24 bit deep display\n");
1170 switch (cinfo->btype) {
1173 vga_wseq(regbase, CL_SEQR7, 0x85);
1174 /* Fast Page-Mode writes */
1175 vga_wseq(regbase, CL_SEQRF, 0xb0);
1179 vga_wseq(regbase, CL_SEQR7, 0x25);
1180 /* Fast Page-Mode writes */
1181 vga_wseq(regbase, CL_SEQRF, 0xb0);
1187 /* Extended Sequencer Mode: 256c col. mode */
1188 vga_wseq(regbase, CL_SEQR7, 0xa5);
1192 vga_wseq(regbase, CL_SEQR7, 0x15);
1193 /* We already set SRF and SR1F */
1198 vga_wseq(regbase, CL_SEQR7,
1199 vga_rseq(regbase, CL_SEQR7) & ~0x01);
1206 dev_warn(info->device, "unknown Board\n");
1210 /* mode register: 256 color mode */
1211 vga_wgfx(regbase, VGA_GFX_MODE, 64);
1212 /* hidden dac reg: 8-8-8 mode (24 or 32) */
1216 /******************************************************
1218 * unknown/unsupported bpp
1223 dev_err(info->device,
1224 "What's this? requested color depth == %d.\n",
1225 var->bits_per_pixel);
1227 pitch = info->fix.line_length >> 3;
1228 vga_wcrt(regbase, VGA_CRTC_OFFSET, pitch & 0xff);
1231 tmp |= 0x10; /* offset overflow bit */
1233 /* screen start addr #16-18, fastpagemode cycles */
1234 vga_wcrt(regbase, CL_CRT1B, tmp);
1236 /* screen start address bit 19 */
1237 if (cirrusfb_board_info[cinfo->btype].scrn_start_bit19)
1238 vga_wcrt(regbase, CL_CRT1D, (pitch >> 9) & 1);
1240 if (is_laguna(cinfo)) {
1242 if ((htotal + 5) & 256)
1246 if (hsyncstart & 256)
1250 if (vdispend & 1024)
1252 if (vsyncstart & 1024)
1255 vga_wcrt(regbase, CL_CRT1E, tmp);
1256 dev_dbg(info->device, "CRT1e: %d\n", tmp);
1260 vga_wattr(regbase, CL_AR33, 0);
1262 /* [ EGS: SetOffset(); ] */
1263 /* From SetOffset(): Turn on VideoEnable bit in Attribute controller */
1266 if (is_laguna(cinfo)) {
1268 fb_writew(control | 0x1000, cinfo->laguna_mmio + 0x402);
1269 fb_writew(format, cinfo->laguna_mmio + 0xc0);
1270 fb_writew(threshold, cinfo->laguna_mmio + 0xea);
1272 /* finally, turn on everything - turn off "FullBandwidth" bit */
1273 /* also, set "DotClock%2" bit where requested */
1276 /*** FB_VMODE_CLOCK_HALVE in linux/fb.h not defined anymore ?
1277 if (var->vmode & FB_VMODE_CLOCK_HALVE)
1281 vga_wseq(regbase, VGA_SEQ_CLOCK_MODE, tmp);
1282 dev_dbg(info->device, "CL_SEQR1: %d\n", tmp);
1284 #ifdef CIRRUSFB_DEBUG
1285 cirrusfb_dbg_reg_dump(info, NULL);
1291 /* for some reason incomprehensible to me, cirrusfb requires that you write
1292 * the registers twice for the settings to take..grr. -dte */
1293 static int cirrusfb_set_par(struct fb_info *info)
1295 cirrusfb_set_par_foo(info);
1296 return cirrusfb_set_par_foo(info);
1299 static int cirrusfb_setcolreg(unsigned regno, unsigned red, unsigned green,
1300 unsigned blue, unsigned transp,
1301 struct fb_info *info)
1303 struct cirrusfb_info *cinfo = info->par;
1308 if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
1310 red >>= (16 - info->var.red.length);
1311 green >>= (16 - info->var.green.length);
1312 blue >>= (16 - info->var.blue.length);
1316 v = (red << info->var.red.offset) |
1317 (green << info->var.green.offset) |
1318 (blue << info->var.blue.offset);
1320 cinfo->pseudo_palette[regno] = v;
1324 if (info->var.bits_per_pixel == 8)
1325 WClut(cinfo, regno, red >> 10, green >> 10, blue >> 10);
1331 /*************************************************************************
1332 cirrusfb_pan_display()
1334 performs display panning - provided hardware permits this
1335 **************************************************************************/
1336 static int cirrusfb_pan_display(struct fb_var_screeninfo *var,
1337 struct fb_info *info)
1341 unsigned char tmp, xpix;
1342 struct cirrusfb_info *cinfo = info->par;
1344 /* no range checks for xoffset and yoffset, */
1345 /* as fb_pan_display has already done this */
1346 if (var->vmode & FB_VMODE_YWRAP)
1349 xoffset = var->xoffset * info->var.bits_per_pixel / 8;
1351 base = var->yoffset * info->fix.line_length + xoffset;
1353 if (info->var.bits_per_pixel == 1) {
1354 /* base is already correct */
1355 xpix = (unsigned char) (var->xoffset % 8);
1358 xpix = (unsigned char) ((xoffset % 4) * 2);
1361 if (!is_laguna(cinfo))
1362 cirrusfb_WaitBLT(cinfo->regbase);
1364 /* lower 8 + 8 bits of screen start address */
1365 vga_wcrt(cinfo->regbase, VGA_CRTC_START_LO, base & 0xff);
1366 vga_wcrt(cinfo->regbase, VGA_CRTC_START_HI, (base >> 8) & 0xff);
1368 /* 0xf2 is %11110010, exclude tmp bits */
1369 tmp = vga_rcrt(cinfo->regbase, CL_CRT1B) & 0xf2;
1370 /* construct bits 16, 17 and 18 of screen start address */
1378 vga_wcrt(cinfo->regbase, CL_CRT1B, tmp);
1380 /* construct bit 19 of screen start address */
1381 if (cirrusfb_board_info[cinfo->btype].scrn_start_bit19) {
1382 tmp = vga_rcrt(cinfo->regbase, CL_CRT1D);
1383 if (is_laguna(cinfo))
1384 tmp = (tmp & ~0x18) | ((base >> 16) & 0x18);
1386 tmp = (tmp & ~0x80) | ((base >> 12) & 0x80);
1387 vga_wcrt(cinfo->regbase, CL_CRT1D, tmp);
1390 /* write pixel panning value to AR33; this does not quite work in 8bpp
1392 * ### Piccolo..? Will this work?
1394 if (info->var.bits_per_pixel == 1)
1395 vga_wattr(cinfo->regbase, CL_AR33, xpix);
1400 static int cirrusfb_blank(int blank_mode, struct fb_info *info)
1403 * Blank the screen if blank_mode != 0, else unblank. If blank == NULL
1404 * then the caller blanks by setting the CLUT (Color Look Up Table)
1405 * to all black. Return 0 if blanking succeeded, != 0 if un-/blanking
1406 * failed due to e.g. a video mode which doesn't support it.
1407 * Implements VESA suspend and powerdown modes on hardware that
1408 * supports disabling hsync/vsync:
1409 * blank_mode == 2: suspend vsync
1410 * blank_mode == 3: suspend hsync
1411 * blank_mode == 4: powerdown
1414 struct cirrusfb_info *cinfo = info->par;
1415 int current_mode = cinfo->blank_mode;
1417 dev_dbg(info->device, "ENTER, blank mode = %d\n", blank_mode);
1419 if (info->state != FBINFO_STATE_RUNNING ||
1420 current_mode == blank_mode) {
1421 dev_dbg(info->device, "EXIT, returning 0\n");
1426 if (current_mode == FB_BLANK_NORMAL ||
1427 current_mode == FB_BLANK_UNBLANK)
1428 /* clear "FullBandwidth" bit */
1431 /* set "FullBandwidth" bit */
1434 val |= vga_rseq(cinfo->regbase, VGA_SEQ_CLOCK_MODE) & 0xdf;
1435 vga_wseq(cinfo->regbase, VGA_SEQ_CLOCK_MODE, val);
1437 switch (blank_mode) {
1438 case FB_BLANK_UNBLANK:
1439 case FB_BLANK_NORMAL:
1442 case FB_BLANK_VSYNC_SUSPEND:
1445 case FB_BLANK_HSYNC_SUSPEND:
1448 case FB_BLANK_POWERDOWN:
1452 dev_dbg(info->device, "EXIT, returning 1\n");
1456 vga_wgfx(cinfo->regbase, CL_GRE, val);
1458 cinfo->blank_mode = blank_mode;
1459 dev_dbg(info->device, "EXIT, returning 0\n");
1461 /* Let fbcon do a soft blank for us */
1462 return (blank_mode == FB_BLANK_NORMAL) ? 1 : 0;
1465 /**** END Hardware specific Routines **************************************/
1466 /****************************************************************************/
1467 /**** BEGIN Internal Routines ***********************************************/
1469 static void init_vgachip(struct fb_info *info)
1471 struct cirrusfb_info *cinfo = info->par;
1472 const struct cirrusfb_board_info_rec *bi;
1474 assert(cinfo != NULL);
1476 bi = &cirrusfb_board_info[cinfo->btype];
1478 /* reset board globally */
1479 switch (cinfo->btype) {
1498 /* disable flickerfixer */
1499 vga_wcrt(cinfo->regbase, CL_CRT51, 0x00);
1502 vga_wgfx(cinfo->regbase, CL_GR31, 0x00);
1503 case BT_GD5480: /* fall through */
1504 /* from Klaus' NetBSD driver: */
1505 vga_wgfx(cinfo->regbase, CL_GR2F, 0x00);
1506 case BT_ALPINE: /* fall through */
1507 /* put blitter into 542x compat */
1508 vga_wgfx(cinfo->regbase, CL_GR33, 0x00);
1513 /* Nothing to do to reset the board. */
1517 dev_err(info->device, "Warning: Unknown board type\n");
1521 /* make sure RAM size set by this point */
1522 assert(info->screen_size > 0);
1524 /* the P4 is not fully initialized here; I rely on it having been */
1525 /* inited under AmigaOS already, which seems to work just fine */
1526 /* (Klaus advised to do it this way) */
1528 if (cinfo->btype != BT_PICASSO4) {
1529 WGen(cinfo, CL_VSSM, 0x10); /* EGS: 0x16 */
1530 WGen(cinfo, CL_POS102, 0x01);
1531 WGen(cinfo, CL_VSSM, 0x08); /* EGS: 0x0e */
1533 if (cinfo->btype != BT_SD64)
1534 WGen(cinfo, CL_VSSM2, 0x01);
1536 /* reset sequencer logic */
1537 vga_wseq(cinfo->regbase, VGA_SEQ_RESET, 0x03);
1539 /* FullBandwidth (video off) and 8/9 dot clock */
1540 vga_wseq(cinfo->regbase, VGA_SEQ_CLOCK_MODE, 0x21);
1542 /* "magic cookie" - doesn't make any sense to me.. */
1543 /* vga_wgfx(cinfo->regbase, CL_GRA, 0xce); */
1544 /* unlock all extension registers */
1545 vga_wseq(cinfo->regbase, CL_SEQR6, 0x12);
1547 switch (cinfo->btype) {
1549 vga_wseq(cinfo->regbase, CL_SEQRF, 0x98);
1557 vga_wseq(cinfo->regbase, CL_SEQRF, 0xb8);
1561 vga_wseq(cinfo->regbase, CL_SEQR16, 0x0f);
1562 vga_wseq(cinfo->regbase, CL_SEQRF, 0xb0);
1566 /* plane mask: nothing */
1567 vga_wseq(cinfo->regbase, VGA_SEQ_PLANE_WRITE, 0xff);
1568 /* character map select: doesn't even matter in gx mode */
1569 vga_wseq(cinfo->regbase, VGA_SEQ_CHARACTER_MAP, 0x00);
1570 /* memory mode: chain4, ext. memory */
1571 vga_wseq(cinfo->regbase, VGA_SEQ_MEMORY_MODE, 0x0a);
1573 /* controller-internal base address of video memory */
1575 vga_wseq(cinfo->regbase, CL_SEQR7, bi->sr07);
1577 /* vga_wseq(cinfo->regbase, CL_SEQR8, 0x00); */
1578 /* EEPROM control: shouldn't be necessary to write to this at all.. */
1580 /* graphics cursor X position (incomplete; position gives rem. 3 bits */
1581 vga_wseq(cinfo->regbase, CL_SEQR10, 0x00);
1582 /* graphics cursor Y position (..."... ) */
1583 vga_wseq(cinfo->regbase, CL_SEQR11, 0x00);
1584 /* graphics cursor attributes */
1585 vga_wseq(cinfo->regbase, CL_SEQR12, 0x00);
1586 /* graphics cursor pattern address */
1587 vga_wseq(cinfo->regbase, CL_SEQR13, 0x00);
1589 /* writing these on a P4 might give problems.. */
1590 if (cinfo->btype != BT_PICASSO4) {
1591 /* configuration readback and ext. color */
1592 vga_wseq(cinfo->regbase, CL_SEQR17, 0x00);
1593 /* signature generator */
1594 vga_wseq(cinfo->regbase, CL_SEQR18, 0x02);
1597 /* Screen A preset row scan: none */
1598 vga_wcrt(cinfo->regbase, VGA_CRTC_PRESET_ROW, 0x00);
1599 /* Text cursor start: disable text cursor */
1600 vga_wcrt(cinfo->regbase, VGA_CRTC_CURSOR_START, 0x20);
1601 /* Text cursor end: - */
1602 vga_wcrt(cinfo->regbase, VGA_CRTC_CURSOR_END, 0x00);
1603 /* text cursor location high: 0 */
1604 vga_wcrt(cinfo->regbase, VGA_CRTC_CURSOR_HI, 0x00);
1605 /* text cursor location low: 0 */
1606 vga_wcrt(cinfo->regbase, VGA_CRTC_CURSOR_LO, 0x00);
1608 /* Underline Row scanline: - */
1609 vga_wcrt(cinfo->regbase, VGA_CRTC_UNDERLINE, 0x00);
1610 /* ### add 0x40 for text modes with > 30 MHz pixclock */
1611 /* ext. display controls: ext.adr. wrap */
1612 vga_wcrt(cinfo->regbase, CL_CRT1B, 0x02);
1614 /* Set/Reset registes: - */
1615 vga_wgfx(cinfo->regbase, VGA_GFX_SR_VALUE, 0x00);
1616 /* Set/Reset enable: - */
1617 vga_wgfx(cinfo->regbase, VGA_GFX_SR_ENABLE, 0x00);
1618 /* Color Compare: - */
1619 vga_wgfx(cinfo->regbase, VGA_GFX_COMPARE_VALUE, 0x00);
1620 /* Data Rotate: - */
1621 vga_wgfx(cinfo->regbase, VGA_GFX_DATA_ROTATE, 0x00);
1622 /* Read Map Select: - */
1623 vga_wgfx(cinfo->regbase, VGA_GFX_PLANE_READ, 0x00);
1624 /* Mode: conf. for 16/4/2 color mode, no odd/even, read/write mode 0 */
1625 vga_wgfx(cinfo->regbase, VGA_GFX_MODE, 0x00);
1626 /* Miscellaneous: memory map base address, graphics mode */
1627 vga_wgfx(cinfo->regbase, VGA_GFX_MISC, 0x01);
1628 /* Color Don't care: involve all planes */
1629 vga_wgfx(cinfo->regbase, VGA_GFX_COMPARE_MASK, 0x0f);
1630 /* Bit Mask: no mask at all */
1631 vga_wgfx(cinfo->regbase, VGA_GFX_BIT_MASK, 0xff);
1633 if (cinfo->btype == BT_ALPINE || cinfo->btype == BT_SD64 ||
1635 /* (5434 can't have bit 3 set for bitblt) */
1636 vga_wgfx(cinfo->regbase, CL_GRB, 0x20);
1638 /* Graphics controller mode extensions: finer granularity,
1639 * 8byte data latches
1641 vga_wgfx(cinfo->regbase, CL_GRB, 0x28);
1643 vga_wgfx(cinfo->regbase, CL_GRC, 0xff); /* Color Key compare: - */
1644 vga_wgfx(cinfo->regbase, CL_GRD, 0x00); /* Color Key compare mask: - */
1645 vga_wgfx(cinfo->regbase, CL_GRE, 0x00); /* Miscellaneous control: - */
1646 /* Background color byte 1: - */
1647 /* vga_wgfx (cinfo->regbase, CL_GR10, 0x00); */
1648 /* vga_wgfx (cinfo->regbase, CL_GR11, 0x00); */
1650 /* Attribute Controller palette registers: "identity mapping" */
1651 vga_wattr(cinfo->regbase, VGA_ATC_PALETTE0, 0x00);
1652 vga_wattr(cinfo->regbase, VGA_ATC_PALETTE1, 0x01);
1653 vga_wattr(cinfo->regbase, VGA_ATC_PALETTE2, 0x02);
1654 vga_wattr(cinfo->regbase, VGA_ATC_PALETTE3, 0x03);
1655 vga_wattr(cinfo->regbase, VGA_ATC_PALETTE4, 0x04);
1656 vga_wattr(cinfo->regbase, VGA_ATC_PALETTE5, 0x05);
1657 vga_wattr(cinfo->regbase, VGA_ATC_PALETTE6, 0x06);
1658 vga_wattr(cinfo->regbase, VGA_ATC_PALETTE7, 0x07);
1659 vga_wattr(cinfo->regbase, VGA_ATC_PALETTE8, 0x08);
1660 vga_wattr(cinfo->regbase, VGA_ATC_PALETTE9, 0x09);
1661 vga_wattr(cinfo->regbase, VGA_ATC_PALETTEA, 0x0a);
1662 vga_wattr(cinfo->regbase, VGA_ATC_PALETTEB, 0x0b);
1663 vga_wattr(cinfo->regbase, VGA_ATC_PALETTEC, 0x0c);
1664 vga_wattr(cinfo->regbase, VGA_ATC_PALETTED, 0x0d);
1665 vga_wattr(cinfo->regbase, VGA_ATC_PALETTEE, 0x0e);
1666 vga_wattr(cinfo->regbase, VGA_ATC_PALETTEF, 0x0f);
1668 /* Attribute Controller mode: graphics mode */
1669 vga_wattr(cinfo->regbase, VGA_ATC_MODE, 0x01);
1670 /* Overscan color reg.: reg. 0 */
1671 vga_wattr(cinfo->regbase, VGA_ATC_OVERSCAN, 0x00);
1672 /* Color Plane enable: Enable all 4 planes */
1673 vga_wattr(cinfo->regbase, VGA_ATC_PLANE_ENABLE, 0x0f);
1674 /* Color Select: - */
1675 vga_wattr(cinfo->regbase, VGA_ATC_COLOR_PAGE, 0x00);
1677 WGen(cinfo, VGA_PEL_MSK, 0xff); /* Pixel mask: no mask */
1679 /* BLT Start/status: Blitter reset */
1680 vga_wgfx(cinfo->regbase, CL_GR31, 0x04);
1681 /* - " - : "end-of-reset" */
1682 vga_wgfx(cinfo->regbase, CL_GR31, 0x00);
1685 WHDR(cinfo, 0); /* Hidden DAC register: - */
1689 static void switch_monitor(struct cirrusfb_info *cinfo, int on)
1691 #ifdef CONFIG_ZORRO /* only works on Zorro boards */
1692 static int IsOn = 0; /* XXX not ok for multiple boards */
1694 if (cinfo->btype == BT_PICASSO4)
1695 return; /* nothing to switch */
1696 if (cinfo->btype == BT_ALPINE)
1697 return; /* nothing to switch */
1698 if (cinfo->btype == BT_GD5480)
1699 return; /* nothing to switch */
1700 if (cinfo->btype == BT_PICASSO) {
1701 if ((on && !IsOn) || (!on && IsOn))
1706 switch (cinfo->btype) {
1708 WSFR(cinfo, cinfo->SFR | 0x21);
1711 WSFR(cinfo, cinfo->SFR | 0x28);
1716 default: /* do nothing */ break;
1719 switch (cinfo->btype) {
1721 WSFR(cinfo, cinfo->SFR & 0xde);
1724 WSFR(cinfo, cinfo->SFR & 0xd7);
1729 default: /* do nothing */
1733 #endif /* CONFIG_ZORRO */
1736 /******************************************/
1737 /* Linux 2.6-style accelerated functions */
1738 /******************************************/
1740 static int cirrusfb_sync(struct fb_info *info)
1742 struct cirrusfb_info *cinfo = info->par;
1744 if (!is_laguna(cinfo)) {
1745 while (vga_rgfx(cinfo->regbase, CL_GR31) & 0x03)
1751 static void cirrusfb_fillrect(struct fb_info *info,
1752 const struct fb_fillrect *region)
1754 struct fb_fillrect modded;
1756 struct cirrusfb_info *cinfo = info->par;
1757 int m = info->var.bits_per_pixel;
1758 u32 color = (info->fix.visual == FB_VISUAL_TRUECOLOR) ?
1759 cinfo->pseudo_palette[region->color] : region->color;
1761 if (info->state != FBINFO_STATE_RUNNING)
1763 if (info->flags & FBINFO_HWACCEL_DISABLED) {
1764 cfb_fillrect(info, region);
1768 vxres = info->var.xres_virtual;
1769 vyres = info->var.yres_virtual;
1771 memcpy(&modded, region, sizeof(struct fb_fillrect));
1773 if (!modded.width || !modded.height ||
1774 modded.dx >= vxres || modded.dy >= vyres)
1777 if (modded.dx + modded.width > vxres)
1778 modded.width = vxres - modded.dx;
1779 if (modded.dy + modded.height > vyres)
1780 modded.height = vyres - modded.dy;
1782 cirrusfb_RectFill(cinfo->regbase,
1783 info->var.bits_per_pixel,
1784 (region->dx * m) / 8, region->dy,
1785 (region->width * m) / 8, region->height,
1787 info->fix.line_length, 0x40);
1790 static void cirrusfb_copyarea(struct fb_info *info,
1791 const struct fb_copyarea *area)
1793 struct fb_copyarea modded;
1795 struct cirrusfb_info *cinfo = info->par;
1796 int m = info->var.bits_per_pixel;
1798 if (info->state != FBINFO_STATE_RUNNING)
1800 if (info->flags & FBINFO_HWACCEL_DISABLED) {
1801 cfb_copyarea(info, area);
1805 vxres = info->var.xres_virtual;
1806 vyres = info->var.yres_virtual;
1807 memcpy(&modded, area, sizeof(struct fb_copyarea));
1809 if (!modded.width || !modded.height ||
1810 modded.sx >= vxres || modded.sy >= vyres ||
1811 modded.dx >= vxres || modded.dy >= vyres)
1814 if (modded.sx + modded.width > vxres)
1815 modded.width = vxres - modded.sx;
1816 if (modded.dx + modded.width > vxres)
1817 modded.width = vxres - modded.dx;
1818 if (modded.sy + modded.height > vyres)
1819 modded.height = vyres - modded.sy;
1820 if (modded.dy + modded.height > vyres)
1821 modded.height = vyres - modded.dy;
1823 cirrusfb_BitBLT(cinfo->regbase, info->var.bits_per_pixel,
1824 (area->sx * m) / 8, area->sy,
1825 (area->dx * m) / 8, area->dy,
1826 (area->width * m) / 8, area->height,
1827 info->fix.line_length);
1831 static void cirrusfb_imageblit(struct fb_info *info,
1832 const struct fb_image *image)
1834 struct cirrusfb_info *cinfo = info->par;
1835 unsigned char op = (info->var.bits_per_pixel == 24) ? 0xc : 0x4;
1837 if (info->state != FBINFO_STATE_RUNNING)
1839 /* Alpine/SD64 does not work at 24bpp ??? */
1840 if (info->flags & FBINFO_HWACCEL_DISABLED || image->depth != 1)
1841 cfb_imageblit(info, image);
1842 else if ((cinfo->btype == BT_ALPINE || cinfo->btype == BT_SD64) &&
1844 cfb_imageblit(info, image);
1846 unsigned size = ((image->width + 7) >> 3) * image->height;
1847 int m = info->var.bits_per_pixel;
1850 if (info->var.bits_per_pixel == 8) {
1851 fg = image->fg_color;
1852 bg = image->bg_color;
1854 fg = ((u32 *)(info->pseudo_palette))[image->fg_color];
1855 bg = ((u32 *)(info->pseudo_palette))[image->bg_color];
1857 if (info->var.bits_per_pixel == 24) {
1858 /* clear background first */
1859 cirrusfb_RectFill(cinfo->regbase,
1860 info->var.bits_per_pixel,
1861 (image->dx * m) / 8, image->dy,
1862 (image->width * m) / 8,
1865 info->fix.line_length, 0x40);
1867 cirrusfb_RectFill(cinfo->regbase,
1868 info->var.bits_per_pixel,
1869 (image->dx * m) / 8, image->dy,
1870 (image->width * m) / 8, image->height,
1872 info->fix.line_length, op);
1873 memcpy(info->screen_base, image->data, size);
1877 #ifdef CONFIG_PPC_PREP
1878 #define PREP_VIDEO_BASE ((volatile unsigned long) 0xC0000000)
1879 #define PREP_IO_BASE ((volatile unsigned char *) 0x80000000)
1880 static void get_prep_addrs(unsigned long *display, unsigned long *registers)
1882 *display = PREP_VIDEO_BASE;
1883 *registers = (unsigned long) PREP_IO_BASE;
1886 #endif /* CONFIG_PPC_PREP */
1889 static int release_io_ports;
1891 /* Pulled the logic from XFree86 Cirrus driver to get the memory size,
1892 * based on the DRAM bandwidth bit and DRAM bank switching bit. This
1893 * works with 1MB, 2MB and 4MB configurations (which the Motorola boards
1895 static unsigned int __devinit cirrusfb_get_memsize(struct fb_info *info,
1896 u8 __iomem *regbase)
1899 struct cirrusfb_info *cinfo = info->par;
1901 if (is_laguna(cinfo)) {
1902 unsigned char SR14 = vga_rseq(regbase, CL_SEQR14);
1904 mem = ((SR14 & 7) + 1) << 20;
1906 unsigned char SRF = vga_rseq(regbase, CL_SEQRF);
1907 switch ((SRF & 0x18)) {
1914 /* 64-bit DRAM data bus width; assume 2MB.
1915 * Also indicates 2MB memory on the 5430.
1921 dev_warn(info->device, "Unknown memory size!\n");
1924 /* If DRAM bank switching is enabled, there must be
1925 * twice as much memory installed. (4MB on the 5434)
1927 if (cinfo->btype != BT_ALPINE && (SRF & 0x80) != 0)
1931 /* TODO: Handling of GD5446/5480 (see XF86 sources ...) */
1935 static void get_pci_addrs(const struct pci_dev *pdev,
1936 unsigned long *display, unsigned long *registers)
1938 assert(pdev != NULL);
1939 assert(display != NULL);
1940 assert(registers != NULL);
1945 /* This is a best-guess for now */
1947 if (pci_resource_flags(pdev, 0) & IORESOURCE_IO) {
1948 *display = pci_resource_start(pdev, 1);
1949 *registers = pci_resource_start(pdev, 0);
1951 *display = pci_resource_start(pdev, 0);
1952 *registers = pci_resource_start(pdev, 1);
1955 assert(*display != 0);
1958 static void cirrusfb_pci_unmap(struct fb_info *info)
1960 struct pci_dev *pdev = to_pci_dev(info->device);
1961 struct cirrusfb_info *cinfo = info->par;
1963 if (cinfo->laguna_mmio == NULL)
1964 iounmap(cinfo->laguna_mmio);
1965 iounmap(info->screen_base);
1966 #if 0 /* if system didn't claim this region, we would... */
1967 release_mem_region(0xA0000, 65535);
1969 if (release_io_ports)
1970 release_region(0x3C0, 32);
1971 pci_release_regions(pdev);
1973 #endif /* CONFIG_PCI */
1976 static void cirrusfb_zorro_unmap(struct fb_info *info)
1978 struct cirrusfb_info *cinfo = info->par;
1979 struct zorro_dev *zdev = to_zorro_dev(info->device);
1981 if (info->fix.smem_start > 16 * MB_)
1982 iounmap(info->screen_base);
1983 if (info->fix.mmio_start > 16 * MB_)
1984 iounmap(cinfo->regbase);
1986 zorro_release_device(zdev);
1988 #endif /* CONFIG_ZORRO */
1990 /* function table of the above functions */
1991 static struct fb_ops cirrusfb_ops = {
1992 .owner = THIS_MODULE,
1993 .fb_open = cirrusfb_open,
1994 .fb_release = cirrusfb_release,
1995 .fb_setcolreg = cirrusfb_setcolreg,
1996 .fb_check_var = cirrusfb_check_var,
1997 .fb_set_par = cirrusfb_set_par,
1998 .fb_pan_display = cirrusfb_pan_display,
1999 .fb_blank = cirrusfb_blank,
2000 .fb_fillrect = cirrusfb_fillrect,
2001 .fb_copyarea = cirrusfb_copyarea,
2002 .fb_sync = cirrusfb_sync,
2003 .fb_imageblit = cirrusfb_imageblit,
2006 static int __devinit cirrusfb_set_fbinfo(struct fb_info *info)
2008 struct cirrusfb_info *cinfo = info->par;
2009 struct fb_var_screeninfo *var = &info->var;
2011 info->pseudo_palette = cinfo->pseudo_palette;
2012 info->flags = FBINFO_DEFAULT
2013 | FBINFO_HWACCEL_XPAN
2014 | FBINFO_HWACCEL_YPAN
2015 | FBINFO_HWACCEL_FILLRECT
2016 | FBINFO_HWACCEL_IMAGEBLIT
2017 | FBINFO_HWACCEL_COPYAREA;
2018 if (noaccel || is_laguna(cinfo)) {
2019 info->flags |= FBINFO_HWACCEL_DISABLED;
2020 info->fix.accel = FB_ACCEL_NONE;
2022 info->fix.accel = FB_ACCEL_CIRRUS_ALPINE;
2024 info->fbops = &cirrusfb_ops;
2026 if (cinfo->btype == BT_GD5480) {
2027 if (var->bits_per_pixel == 16)
2028 info->screen_base += 1 * MB_;
2029 if (var->bits_per_pixel == 32)
2030 info->screen_base += 2 * MB_;
2033 /* Fill fix common fields */
2034 strlcpy(info->fix.id, cirrusfb_board_info[cinfo->btype].name,
2035 sizeof(info->fix.id));
2037 /* monochrome: only 1 memory plane */
2038 /* 8 bit and above: Use whole memory area */
2039 info->fix.smem_len = info->screen_size;
2040 if (var->bits_per_pixel == 1)
2041 info->fix.smem_len /= 4;
2042 info->fix.type_aux = 0;
2043 info->fix.xpanstep = 1;
2044 info->fix.ypanstep = 1;
2045 info->fix.ywrapstep = 0;
2047 /* FIXME: map region at 0xB8000 if available, fill in here */
2048 info->fix.mmio_len = 0;
2050 fb_alloc_cmap(&info->cmap, 256, 0);
2055 static int __devinit cirrusfb_register(struct fb_info *info)
2057 struct cirrusfb_info *cinfo = info->par;
2061 assert(cinfo->btype != BT_NONE);
2063 /* set all the vital stuff */
2064 cirrusfb_set_fbinfo(info);
2066 dev_dbg(info->device, "(RAM start set to: 0x%p)\n", info->screen_base);
2068 err = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 8);
2070 dev_dbg(info->device, "wrong initial video mode\n");
2072 goto err_dealloc_cmap;
2075 info->var.activate = FB_ACTIVATE_NOW;
2077 err = cirrusfb_check_var(&info->var, info);
2079 /* should never happen */
2080 dev_dbg(info->device,
2081 "choking on default var... umm, no good.\n");
2082 goto err_dealloc_cmap;
2085 err = register_framebuffer(info);
2087 dev_err(info->device,
2088 "could not register fb device; err = %d!\n", err);
2089 goto err_dealloc_cmap;
2095 fb_dealloc_cmap(&info->cmap);
2099 static void __devexit cirrusfb_cleanup(struct fb_info *info)
2101 struct cirrusfb_info *cinfo = info->par;
2103 switch_monitor(cinfo, 0);
2104 unregister_framebuffer(info);
2105 fb_dealloc_cmap(&info->cmap);
2106 dev_dbg(info->device, "Framebuffer unregistered\n");
2108 framebuffer_release(info);
2112 static int __devinit cirrusfb_pci_register(struct pci_dev *pdev,
2113 const struct pci_device_id *ent)
2115 struct cirrusfb_info *cinfo;
2116 struct fb_info *info;
2117 unsigned long board_addr, board_size;
2120 ret = pci_enable_device(pdev);
2122 printk(KERN_ERR "cirrusfb: Cannot enable PCI device\n");
2126 info = framebuffer_alloc(sizeof(struct cirrusfb_info), &pdev->dev);
2128 printk(KERN_ERR "cirrusfb: could not allocate memory\n");
2134 cinfo->btype = (enum cirrus_board) ent->driver_data;
2136 dev_dbg(info->device,
2137 " Found PCI device, base address 0 is 0x%Lx, btype set to %d\n",
2138 (unsigned long long)pdev->resource[0].start, cinfo->btype);
2139 dev_dbg(info->device, " base address 1 is 0x%Lx\n",
2140 (unsigned long long)pdev->resource[1].start);
2143 pci_write_config_dword(pdev, PCI_BASE_ADDRESS_0, 0x00000000);
2144 #ifdef CONFIG_PPC_PREP
2145 get_prep_addrs(&board_addr, &info->fix.mmio_start);
2147 /* PReP dies if we ioremap the IO registers, but it works w/out... */
2148 cinfo->regbase = (char __iomem *) info->fix.mmio_start;
2150 dev_dbg(info->device,
2151 "Attempt to get PCI info for Cirrus Graphics Card\n");
2152 get_pci_addrs(pdev, &board_addr, &info->fix.mmio_start);
2153 /* FIXME: this forces VGA. alternatives? */
2154 cinfo->regbase = NULL;
2155 cinfo->laguna_mmio = ioremap(info->fix.mmio_start, 0x1000);
2158 dev_dbg(info->device, "Board address: 0x%lx, register address: 0x%lx\n",
2159 board_addr, info->fix.mmio_start);
2161 board_size = (cinfo->btype == BT_GD5480) ?
2162 32 * MB_ : cirrusfb_get_memsize(info, cinfo->regbase);
2164 ret = pci_request_regions(pdev, "cirrusfb");
2166 dev_err(info->device, "cannot reserve region 0x%lx, abort\n",
2168 goto err_release_fb;
2170 #if 0 /* if the system didn't claim this region, we would... */
2171 if (!request_mem_region(0xA0000, 65535, "cirrusfb")) {
2172 dev_err(info->device, "cannot reserve region 0x%lx, abort\n",
2175 goto err_release_regions;
2178 if (request_region(0x3C0, 32, "cirrusfb"))
2179 release_io_ports = 1;
2181 info->screen_base = ioremap(board_addr, board_size);
2182 if (!info->screen_base) {
2184 goto err_release_legacy;
2187 info->fix.smem_start = board_addr;
2188 info->screen_size = board_size;
2189 cinfo->unmap = cirrusfb_pci_unmap;
2191 dev_info(info->device,
2192 "Cirrus Logic chipset on PCI bus, RAM (%lu kB) at 0x%lx\n",
2193 info->screen_size >> 10, board_addr);
2194 pci_set_drvdata(pdev, info);
2196 ret = cirrusfb_register(info);
2200 pci_set_drvdata(pdev, NULL);
2201 iounmap(info->screen_base);
2203 if (release_io_ports)
2204 release_region(0x3C0, 32);
2206 release_mem_region(0xA0000, 65535);
2207 err_release_regions:
2209 pci_release_regions(pdev);
2211 if (cinfo->laguna_mmio != NULL)
2212 iounmap(cinfo->laguna_mmio);
2213 framebuffer_release(info);
2218 static void __devexit cirrusfb_pci_unregister(struct pci_dev *pdev)
2220 struct fb_info *info = pci_get_drvdata(pdev);
2222 cirrusfb_cleanup(info);
2225 static struct pci_driver cirrusfb_pci_driver = {
2227 .id_table = cirrusfb_pci_table,
2228 .probe = cirrusfb_pci_register,
2229 .remove = __devexit_p(cirrusfb_pci_unregister),
2232 .suspend = cirrusfb_pci_suspend,
2233 .resume = cirrusfb_pci_resume,
2237 #endif /* CONFIG_PCI */
2240 static int __devinit cirrusfb_zorro_register(struct zorro_dev *z,
2241 const struct zorro_device_id *ent)
2243 struct fb_info *info;
2245 const struct zorrocl *zcl;
2246 enum cirrus_board btype;
2247 unsigned long regbase, ramsize, rambase;
2248 struct cirrusfb_info *cinfo;
2250 info = framebuffer_alloc(sizeof(struct cirrusfb_info), &z->dev);
2252 printk(KERN_ERR "cirrusfb: could not allocate memory\n");
2256 zcl = (const struct zorrocl *)ent->driver_data;
2258 regbase = zorro_resource_start(z) + zcl->regoffset;
2259 ramsize = zcl->ramsize;
2261 rambase = zorro_resource_start(z) + zcl->ramoffset;
2262 if (zorro_resource_len(z) == 64 * MB_) {
2263 /* Quirk for 64 MiB Picasso IV */
2264 rambase += zcl->ramoffset;
2267 struct zorro_dev *ram = zorro_find_device(zcl->ramid, NULL);
2268 if (!ram || !zorro_resource_len(ram)) {
2269 dev_err(info->device, "No video RAM found\n");
2271 goto err_release_fb;
2273 rambase = zorro_resource_start(ram);
2274 ramsize = zorro_resource_len(ram);
2276 (ram = zorro_find_device(zcl->ramid2, NULL))) {
2277 if (zorro_resource_start(ram) != rambase + ramsize) {
2278 dev_warn(info->device,
2279 "Skipping non-contiguous RAM at %pR\n",
2282 ramsize += zorro_resource_len(ram);
2287 dev_info(info->device,
2288 "%s board detected, REG at 0x%lx, %lu MiB RAM at 0x%lx\n",
2289 cirrusfb_board_info[btype].name, regbase, ramsize / MB_,
2292 if (!zorro_request_device(z, "cirrusfb")) {
2293 dev_err(info->device, "Cannot reserve %pR\n", &z->resource);
2295 goto err_release_fb;
2299 cinfo->btype = btype;
2301 info->fix.mmio_start = regbase;
2302 cinfo->regbase = regbase > 16 * MB_ ? ioremap(regbase, 64 * 1024)
2303 : (caddr_t)ZTWO_VADDR(regbase);
2304 if (!cinfo->regbase) {
2305 dev_err(info->device, "Cannot map registers\n");
2307 goto err_release_dev;
2310 info->fix.smem_start = rambase;
2311 info->screen_size = ramsize;
2312 info->screen_base = rambase > 16 * MB_ ? ioremap(rambase, ramsize)
2313 : (caddr_t)ZTWO_VADDR(rambase);
2314 if (!info->screen_base) {
2315 dev_err(info->device, "Cannot map video RAM\n");
2320 cinfo->unmap = cirrusfb_zorro_unmap;
2322 dev_info(info->device,
2323 "Cirrus Logic chipset on Zorro bus, RAM (%lu MiB) at 0x%lx\n",
2324 ramsize / MB_, rambase);
2326 /* MCLK select etc. */
2327 if (cirrusfb_board_info[btype].init_sr1f)
2328 vga_wseq(cinfo->regbase, CL_SEQR1F,
2329 cirrusfb_board_info[btype].sr1f);
2331 error = cirrusfb_register(info);
2333 dev_err(info->device, "Failed to register device, error %d\n",
2338 zorro_set_drvdata(z, info);
2342 if (rambase > 16 * MB_)
2343 iounmap(info->screen_base);
2346 if (regbase > 16 * MB_)
2347 iounmap(cinfo->regbase);
2349 zorro_release_device(z);
2351 framebuffer_release(info);
2355 void __devexit cirrusfb_zorro_unregister(struct zorro_dev *z)
2357 struct fb_info *info = zorro_get_drvdata(z);
2359 cirrusfb_cleanup(info);
2360 zorro_set_drvdata(z, NULL);
2363 static struct zorro_driver cirrusfb_zorro_driver = {
2365 .id_table = cirrusfb_zorro_table,
2366 .probe = cirrusfb_zorro_register,
2367 .remove = __devexit_p(cirrusfb_zorro_unregister),
2369 #endif /* CONFIG_ZORRO */
2372 static int __init cirrusfb_setup(char *options)
2376 if (!options || !*options)
2379 while ((this_opt = strsep(&options, ",")) != NULL) {
2383 if (!strcmp(this_opt, "noaccel"))
2385 else if (!strncmp(this_opt, "mode:", 5))
2386 mode_option = this_opt + 5;
2388 mode_option = this_opt;
2398 MODULE_AUTHOR("Copyright 1999,2000 Jeff Garzik <jgarzik@pobox.com>");
2399 MODULE_DESCRIPTION("Accelerated FBDev driver for Cirrus Logic chips");
2400 MODULE_LICENSE("GPL");
2402 static int __init cirrusfb_init(void)
2407 char *option = NULL;
2409 if (fb_get_options("cirrusfb", &option))
2411 cirrusfb_setup(option);
2415 error |= zorro_register_driver(&cirrusfb_zorro_driver);
2418 error |= pci_register_driver(&cirrusfb_pci_driver);
2423 static void __exit cirrusfb_exit(void)
2426 pci_unregister_driver(&cirrusfb_pci_driver);
2429 zorro_unregister_driver(&cirrusfb_zorro_driver);
2433 module_init(cirrusfb_init);
2435 module_param(mode_option, charp, 0);
2436 MODULE_PARM_DESC(mode_option, "Initial video mode e.g. '648x480-8@60'");
2437 module_param(noaccel, bool, 0);
2438 MODULE_PARM_DESC(noaccel, "Disable acceleration");
2441 module_exit(cirrusfb_exit);
2444 /**********************************************************************/
2445 /* about the following functions - I have used the same names for the */
2446 /* functions as Markus Wild did in his Retina driver for NetBSD as */
2447 /* they just made sense for this purpose. Apart from that, I wrote */
2448 /* these functions myself. */
2449 /**********************************************************************/
2451 /*** WGen() - write into one of the external/general registers ***/
2452 static void WGen(const struct cirrusfb_info *cinfo,
2453 int regnum, unsigned char val)
2455 unsigned long regofs = 0;
2457 if (cinfo->btype == BT_PICASSO) {
2458 /* Picasso II specific hack */
2459 /* if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D ||
2460 regnum == CL_VSSM2) */
2461 if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D)
2465 vga_w(cinfo->regbase, regofs + regnum, val);
2468 /*** RGen() - read out one of the external/general registers ***/
2469 static unsigned char RGen(const struct cirrusfb_info *cinfo, int regnum)
2471 unsigned long regofs = 0;
2473 if (cinfo->btype == BT_PICASSO) {
2474 /* Picasso II specific hack */
2475 /* if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D ||
2476 regnum == CL_VSSM2) */
2477 if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D)
2481 return vga_r(cinfo->regbase, regofs + regnum);
2484 /*** AttrOn() - turn on VideoEnable for Attribute controller ***/
2485 static void AttrOn(const struct cirrusfb_info *cinfo)
2487 assert(cinfo != NULL);
2489 if (vga_rcrt(cinfo->regbase, CL_CRT24) & 0x80) {
2490 /* if we're just in "write value" mode, write back the */
2491 /* same value as before to not modify anything */
2492 vga_w(cinfo->regbase, VGA_ATT_IW,
2493 vga_r(cinfo->regbase, VGA_ATT_R));
2495 /* turn on video bit */
2496 /* vga_w(cinfo->regbase, VGA_ATT_IW, 0x20); */
2497 vga_w(cinfo->regbase, VGA_ATT_IW, 0x33);
2499 /* dummy write on Reg0 to be on "write index" mode next time */
2500 vga_w(cinfo->regbase, VGA_ATT_IW, 0x00);
2503 /*** WHDR() - write into the Hidden DAC register ***/
2504 /* as the HDR is the only extension register that requires special treatment
2505 * (the other extension registers are accessible just like the "ordinary"
2506 * registers of their functional group) here is a specialized routine for
2509 static void WHDR(const struct cirrusfb_info *cinfo, unsigned char val)
2511 unsigned char dummy;
2513 if (is_laguna(cinfo))
2515 if (cinfo->btype == BT_PICASSO) {
2516 /* Klaus' hint for correct access to HDR on some boards */
2517 /* first write 0 to pixel mask (3c6) */
2518 WGen(cinfo, VGA_PEL_MSK, 0x00);
2520 /* next read dummy from pixel address (3c8) */
2521 dummy = RGen(cinfo, VGA_PEL_IW);
2524 /* now do the usual stuff to access the HDR */
2526 dummy = RGen(cinfo, VGA_PEL_MSK);
2528 dummy = RGen(cinfo, VGA_PEL_MSK);
2530 dummy = RGen(cinfo, VGA_PEL_MSK);
2532 dummy = RGen(cinfo, VGA_PEL_MSK);
2535 WGen(cinfo, VGA_PEL_MSK, val);
2538 if (cinfo->btype == BT_PICASSO) {
2539 /* now first reset HDR access counter */
2540 dummy = RGen(cinfo, VGA_PEL_IW);
2543 /* and at the end, restore the mask value */
2544 /* ## is this mask always 0xff? */
2545 WGen(cinfo, VGA_PEL_MSK, 0xff);
2550 /*** WSFR() - write to the "special function register" (SFR) ***/
2551 static void WSFR(struct cirrusfb_info *cinfo, unsigned char val)
2554 assert(cinfo->regbase != NULL);
2556 z_writeb(val, cinfo->regbase + 0x8000);
2560 /* The Picasso has a second register for switching the monitor bit */
2561 static void WSFR2(struct cirrusfb_info *cinfo, unsigned char val)
2564 /* writing an arbitrary value to this one causes the monitor switcher */
2565 /* to flip to Amiga display */
2566 assert(cinfo->regbase != NULL);
2568 z_writeb(val, cinfo->regbase + 0x9000);
2572 /*** WClut - set CLUT entry (range: 0..63) ***/
2573 static void WClut(struct cirrusfb_info *cinfo, unsigned char regnum, unsigned char red,
2574 unsigned char green, unsigned char blue)
2576 unsigned int data = VGA_PEL_D;
2578 /* address write mode register is not translated.. */
2579 vga_w(cinfo->regbase, VGA_PEL_IW, regnum);
2581 if (cinfo->btype == BT_PICASSO || cinfo->btype == BT_PICASSO4 ||
2582 cinfo->btype == BT_ALPINE || cinfo->btype == BT_GD5480 ||
2583 cinfo->btype == BT_SD64 || is_laguna(cinfo)) {
2584 /* but DAC data register IS, at least for Picasso II */
2585 if (cinfo->btype == BT_PICASSO)
2587 vga_w(cinfo->regbase, data, red);
2588 vga_w(cinfo->regbase, data, green);
2589 vga_w(cinfo->regbase, data, blue);
2591 vga_w(cinfo->regbase, data, blue);
2592 vga_w(cinfo->regbase, data, green);
2593 vga_w(cinfo->regbase, data, red);
2598 /*** RClut - read CLUT entry (range 0..63) ***/
2599 static void RClut(struct cirrusfb_info *cinfo, unsigned char regnum, unsigned char *red,
2600 unsigned char *green, unsigned char *blue)
2602 unsigned int data = VGA_PEL_D;
2604 vga_w(cinfo->regbase, VGA_PEL_IR, regnum);
2606 if (cinfo->btype == BT_PICASSO || cinfo->btype == BT_PICASSO4 ||
2607 cinfo->btype == BT_ALPINE || cinfo->btype == BT_GD5480) {
2608 if (cinfo->btype == BT_PICASSO)
2610 *red = vga_r(cinfo->regbase, data);
2611 *green = vga_r(cinfo->regbase, data);
2612 *blue = vga_r(cinfo->regbase, data);
2614 *blue = vga_r(cinfo->regbase, data);
2615 *green = vga_r(cinfo->regbase, data);
2616 *red = vga_r(cinfo->regbase, data);
2621 /*******************************************************************
2624 Wait for the BitBLT engine to complete a possible earlier job
2625 *********************************************************************/
2627 /* FIXME: use interrupts instead */
2628 static void cirrusfb_WaitBLT(u8 __iomem *regbase)
2630 while (vga_rgfx(regbase, CL_GR31) & 0x08)
2634 /*******************************************************************
2637 perform accelerated "scrolling"
2638 ********************************************************************/
2640 static void cirrusfb_set_blitter(u8 __iomem *regbase,
2641 u_short nwidth, u_short nheight,
2642 u_long nsrc, u_long ndest,
2643 u_short bltmode, u_short line_length)
2646 /* pitch: set to line_length */
2647 /* dest pitch low */
2648 vga_wgfx(regbase, CL_GR24, line_length & 0xff);
2650 vga_wgfx(regbase, CL_GR25, line_length >> 8);
2651 /* source pitch low */
2652 vga_wgfx(regbase, CL_GR26, line_length & 0xff);
2653 /* source pitch hi */
2654 vga_wgfx(regbase, CL_GR27, line_length >> 8);
2656 /* BLT width: actual number of pixels - 1 */
2658 vga_wgfx(regbase, CL_GR20, nwidth & 0xff);
2660 vga_wgfx(regbase, CL_GR21, nwidth >> 8);
2662 /* BLT height: actual number of lines -1 */
2663 /* BLT height low */
2664 vga_wgfx(regbase, CL_GR22, nheight & 0xff);
2666 vga_wgfx(regbase, CL_GR23, nheight >> 8);
2668 /* BLT destination */
2670 vga_wgfx(regbase, CL_GR28, (u_char) (ndest & 0xff));
2672 vga_wgfx(regbase, CL_GR29, (u_char) (ndest >> 8));
2674 vga_wgfx(regbase, CL_GR2A, (u_char) (ndest >> 16));
2678 vga_wgfx(regbase, CL_GR2C, (u_char) (nsrc & 0xff));
2680 vga_wgfx(regbase, CL_GR2D, (u_char) (nsrc >> 8));
2682 vga_wgfx(regbase, CL_GR2E, (u_char) (nsrc >> 16));
2685 vga_wgfx(regbase, CL_GR30, bltmode); /* BLT mode */
2687 /* BLT ROP: SrcCopy */
2688 vga_wgfx(regbase, CL_GR32, 0x0d); /* BLT ROP */
2690 /* and finally: GO! */
2691 vga_wgfx(regbase, CL_GR31, 0x02); /* BLT Start/status */
2694 /*******************************************************************
2697 perform accelerated "scrolling"
2698 ********************************************************************/
2700 static void cirrusfb_BitBLT(u8 __iomem *regbase, int bits_per_pixel,
2701 u_short curx, u_short cury,
2702 u_short destx, u_short desty,
2703 u_short width, u_short height,
2704 u_short line_length)
2706 u_short nwidth = width - 1;
2707 u_short nheight = height - 1;
2712 /* if source adr < dest addr, do the Blt backwards */
2713 if (cury <= desty) {
2714 if (cury == desty) {
2715 /* if src and dest are on the same line, check x */
2721 /* standard case: forward blitting */
2722 nsrc = (cury * line_length) + curx;
2723 ndest = (desty * line_length) + destx;
2725 /* this means start addresses are at the end,
2726 * counting backwards
2728 nsrc += nheight * line_length + nwidth;
2729 ndest += nheight * line_length + nwidth;
2732 cirrusfb_WaitBLT(regbase);
2734 cirrusfb_set_blitter(regbase, nwidth, nheight,
2735 nsrc, ndest, bltmode, line_length);
2738 /*******************************************************************
2741 perform accelerated rectangle fill
2742 ********************************************************************/
2744 static void cirrusfb_RectFill(u8 __iomem *regbase, int bits_per_pixel,
2745 u_short x, u_short y, u_short width, u_short height,
2746 u32 fg_color, u32 bg_color, u_short line_length,
2749 u_long ndest = (y * line_length) + x;
2752 cirrusfb_WaitBLT(regbase);
2754 /* This is a ColorExpand Blt, using the */
2755 /* same color for foreground and background */
2756 vga_wgfx(regbase, VGA_GFX_SR_VALUE, bg_color);
2757 vga_wgfx(regbase, VGA_GFX_SR_ENABLE, fg_color);
2760 if (bits_per_pixel >= 16) {
2761 vga_wgfx(regbase, CL_GR10, bg_color >> 8);
2762 vga_wgfx(regbase, CL_GR11, fg_color >> 8);
2765 if (bits_per_pixel >= 24) {
2766 vga_wgfx(regbase, CL_GR12, bg_color >> 16);
2767 vga_wgfx(regbase, CL_GR13, fg_color >> 16);
2770 if (bits_per_pixel == 32) {
2771 vga_wgfx(regbase, CL_GR14, bg_color >> 24);
2772 vga_wgfx(regbase, CL_GR15, fg_color >> 24);
2775 cirrusfb_set_blitter(regbase, width - 1, height - 1,
2776 0, ndest, op | blitmode, line_length);
2779 /**************************************************************************
2780 * bestclock() - determine closest possible clock lower(?) than the
2781 * desired pixel clock
2782 **************************************************************************/
2783 static void bestclock(long freq, int *nom, int *den, int *div)
2788 assert(nom != NULL);
2789 assert(den != NULL);
2790 assert(div != NULL);
2801 for (n = 32; n < 128; n++) {
2804 d = (14318 * n) / freq;
2805 if ((d >= 7) && (d <= 63)) {
2812 h = ((14318 * n) / temp) >> s;
2813 h = h > freq ? h - freq : freq - h;
2822 if ((d >= 7) && (d <= 63)) {
2827 h = ((14318 * n) / d) >> s;
2828 h = h > freq ? h - freq : freq - h;
2839 /* -------------------------------------------------------------------------
2841 * debugging functions
2843 * -------------------------------------------------------------------------
2846 #ifdef CIRRUSFB_DEBUG
2849 * cirrusfb_dbg_print_regs
2850 * @base: If using newmmio, the newmmio base address, otherwise %NULL
2851 * @reg_class: type of registers to read: %CRT, or %SEQ
2854 * Dumps the given list of VGA CRTC registers. If @base is %NULL,
2855 * old-style I/O ports are queried for information, otherwise MMIO is
2856 * used at the given @base address to query the information.
2859 static void cirrusfb_dbg_print_regs(struct fb_info *info,
2861 enum cirrusfb_dbg_reg_class reg_class, ...)
2864 unsigned char val = 0;
2868 va_start(list, reg_class);
2870 name = va_arg(list, char *);
2871 while (name != NULL) {
2872 reg = va_arg(list, int);
2874 switch (reg_class) {
2876 val = vga_rcrt(regbase, (unsigned char) reg);
2879 val = vga_rseq(regbase, (unsigned char) reg);
2882 /* should never occur */
2887 dev_dbg(info->device, "%8s = 0x%02X\n", name, val);
2889 name = va_arg(list, char *);
2896 * cirrusfb_dbg_reg_dump
2897 * @base: If using newmmio, the newmmio base address, otherwise %NULL
2900 * Dumps a list of interesting VGA and CIRRUSFB registers. If @base is %NULL,
2901 * old-style I/O ports are queried for information, otherwise MMIO is
2902 * used at the given @base address to query the information.
2905 static void cirrusfb_dbg_reg_dump(struct fb_info *info, caddr_t regbase)
2907 dev_dbg(info->device, "VGA CRTC register dump:\n");
2909 cirrusfb_dbg_print_regs(info, regbase, CRT,
2959 dev_dbg(info->device, "\n");
2961 dev_dbg(info->device, "VGA SEQ register dump:\n");
2963 cirrusfb_dbg_print_regs(info, regbase, SEQ,
2992 dev_dbg(info->device, "\n");
2995 #endif /* CIRRUSFB_DEBUG */