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/slab.h>
43 #include <linux/delay.h>
45 #include <linux/init.h>
46 #include <asm/pgtable.h>
49 #include <linux/zorro.h>
52 #include <linux/pci.h>
55 #include <asm/amigahw.h>
57 #ifdef CONFIG_PPC_PREP
58 #include <asm/machdep.h>
59 #define isPReP machine_is(prep)
64 #include <video/vga.h>
65 #include <video/cirrus.h>
67 /*****************************************************************
69 * debugging and utility macros
73 /* disable runtime assertions? */
74 /* #define CIRRUSFB_NDEBUG */
76 /* debugging assertions */
77 #ifndef CIRRUSFB_NDEBUG
78 #define assert(expr) \
80 printk("Assertion failed! %s,%s,%s,line=%d\n", \
81 #expr, __FILE__, __func__, __LINE__); \
87 #define MB_ (1024 * 1024)
89 /*****************************************************************
99 BT_PICCOLO, /* GD5426 */
100 BT_PICASSO, /* GD5426 or GD5428 */
101 BT_SPECTRUM, /* GD5426 or GD5428 */
102 BT_PICASSO4, /* GD5446 */
103 BT_ALPINE, /* GD543x/4x */
105 BT_LAGUNA, /* GD5462/64 */
106 BT_LAGUNAB, /* GD5465 */
110 * per-board-type information, used for enumerating and abstracting
111 * chip-specific information
112 * NOTE: MUST be in the same order as enum cirrus_board in order to
113 * use direct indexing on this array
114 * NOTE: '__initdata' cannot be used as some of this info
115 * is required at runtime. Maybe separate into an init-only and
118 static const struct cirrusfb_board_info_rec {
119 char *name; /* ASCII name of chipset */
120 long maxclock[5]; /* maximum video clock */
121 /* for 1/4bpp, 8bpp 15/16bpp, 24bpp, 32bpp - numbers from xorg code */
122 bool init_sr07 : 1; /* init SR07 during init_vgachip() */
123 bool init_sr1f : 1; /* write SR1F during init_vgachip() */
124 /* construct bit 19 of screen start address */
125 bool scrn_start_bit19 : 1;
127 /* initial SR07 value, then for each mode */
129 unsigned char sr07_1bpp;
130 unsigned char sr07_1bpp_mux;
131 unsigned char sr07_8bpp;
132 unsigned char sr07_8bpp_mux;
134 unsigned char sr1f; /* SR1F VGA initial register value */
135 } cirrusfb_board_info[] = {
140 /* the SD64/P4 have a higher max. videoclock */
141 135100, 135100, 85500, 85500, 0
145 .scrn_start_bit19 = true,
148 .sr07_1bpp_mux = 0xF6,
150 .sr07_8bpp_mux = 0xF7,
154 .name = "CL Piccolo",
157 90000, 90000, 90000, 90000, 90000
161 .scrn_start_bit19 = false,
168 .name = "CL Picasso",
171 90000, 90000, 90000, 90000, 90000
175 .scrn_start_bit19 = false,
182 .name = "CL Spectrum",
185 90000, 90000, 90000, 90000, 90000
189 .scrn_start_bit19 = false,
196 .name = "CL Picasso4",
198 135100, 135100, 85500, 85500, 0
202 .scrn_start_bit19 = true,
205 .sr07_1bpp_mux = 0xA6,
207 .sr07_8bpp_mux = 0xA7,
213 /* for the GD5430. GD5446 can do more... */
214 85500, 85500, 50000, 28500, 0
218 .scrn_start_bit19 = true,
221 .sr07_1bpp_mux = 0xA6,
223 .sr07_8bpp_mux = 0xA7,
229 135100, 200000, 200000, 135100, 135100
233 .scrn_start_bit19 = true,
242 /* taken from X11 code */
243 170000, 170000, 170000, 170000, 135100,
247 .scrn_start_bit19 = true,
250 .name = "CL Laguna AGP",
252 /* taken from X11 code */
253 170000, 250000, 170000, 170000, 135100,
257 .scrn_start_bit19 = true,
262 #define CHIP(id, btype) \
263 { PCI_VENDOR_ID_CIRRUS, id, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (btype) }
265 static struct pci_device_id cirrusfb_pci_table[] = {
266 CHIP(PCI_DEVICE_ID_CIRRUS_5436, BT_ALPINE),
267 CHIP(PCI_DEVICE_ID_CIRRUS_5434_8, BT_SD64),
268 CHIP(PCI_DEVICE_ID_CIRRUS_5434_4, BT_SD64),
269 CHIP(PCI_DEVICE_ID_CIRRUS_5430, BT_ALPINE), /* GD-5440 is same id */
270 CHIP(PCI_DEVICE_ID_CIRRUS_7543, BT_ALPINE),
271 CHIP(PCI_DEVICE_ID_CIRRUS_7548, BT_ALPINE),
272 CHIP(PCI_DEVICE_ID_CIRRUS_5480, BT_GD5480), /* MacPicasso likely */
273 CHIP(PCI_DEVICE_ID_CIRRUS_5446, BT_PICASSO4), /* Picasso 4 is 5446 */
274 CHIP(PCI_DEVICE_ID_CIRRUS_5462, BT_LAGUNA), /* CL Laguna */
275 CHIP(PCI_DEVICE_ID_CIRRUS_5464, BT_LAGUNA), /* CL Laguna 3D */
276 CHIP(PCI_DEVICE_ID_CIRRUS_5465, BT_LAGUNAB), /* CL Laguna 3DA*/
279 MODULE_DEVICE_TABLE(pci, cirrusfb_pci_table);
281 #endif /* CONFIG_PCI */
284 static const struct zorro_device_id cirrusfb_zorro_table[] = {
286 .id = ZORRO_PROD_HELFRICH_SD64_RAM,
287 .driver_data = BT_SD64,
289 .id = ZORRO_PROD_HELFRICH_PICCOLO_RAM,
290 .driver_data = BT_PICCOLO,
292 .id = ZORRO_PROD_VILLAGE_TRONIC_PICASSO_II_II_PLUS_RAM,
293 .driver_data = BT_PICASSO,
295 .id = ZORRO_PROD_GVP_EGS_28_24_SPECTRUM_RAM,
296 .driver_data = BT_SPECTRUM,
298 .id = ZORRO_PROD_VILLAGE_TRONIC_PICASSO_IV_Z3,
299 .driver_data = BT_PICASSO4,
304 static const struct {
307 } cirrusfb_zorro_table2[] = {
309 .id2 = ZORRO_PROD_HELFRICH_SD64_REG,
313 .id2 = ZORRO_PROD_HELFRICH_PICCOLO_REG,
317 .id2 = ZORRO_PROD_VILLAGE_TRONIC_PICASSO_II_II_PLUS_REG,
321 .id2 = ZORRO_PROD_GVP_EGS_28_24_SPECTRUM_REG,
329 #endif /* CONFIG_ZORRO */
331 #ifdef CIRRUSFB_DEBUG
332 enum cirrusfb_dbg_reg_class {
336 #endif /* CIRRUSFB_DEBUG */
338 /* info about board */
339 struct cirrusfb_info {
341 u8 __iomem *laguna_mmio;
342 enum cirrus_board btype;
343 unsigned char SFR; /* Shadow of special function register */
348 u32 pseudo_palette[16];
350 void (*unmap)(struct fb_info *info);
353 static int noaccel __devinitdata;
354 static char *mode_option __devinitdata = "640x480@60";
356 /****************************************************************************/
357 /**** BEGIN PROTOTYPES ******************************************************/
359 /*--- Interface used by the world ------------------------------------------*/
360 static int cirrusfb_pan_display(struct fb_var_screeninfo *var,
361 struct fb_info *info);
363 /*--- Internal routines ----------------------------------------------------*/
364 static void init_vgachip(struct fb_info *info);
365 static void switch_monitor(struct cirrusfb_info *cinfo, int on);
366 static void WGen(const struct cirrusfb_info *cinfo,
367 int regnum, unsigned char val);
368 static unsigned char RGen(const struct cirrusfb_info *cinfo, int regnum);
369 static void AttrOn(const struct cirrusfb_info *cinfo);
370 static void WHDR(const struct cirrusfb_info *cinfo, unsigned char val);
371 static void WSFR(struct cirrusfb_info *cinfo, unsigned char val);
372 static void WSFR2(struct cirrusfb_info *cinfo, unsigned char val);
373 static void WClut(struct cirrusfb_info *cinfo, unsigned char regnum,
374 unsigned char red, unsigned char green, unsigned char blue);
376 static void RClut(struct cirrusfb_info *cinfo, unsigned char regnum,
377 unsigned char *red, unsigned char *green,
378 unsigned char *blue);
380 static void cirrusfb_WaitBLT(u8 __iomem *regbase);
381 static void cirrusfb_BitBLT(u8 __iomem *regbase, int bits_per_pixel,
382 u_short curx, u_short cury,
383 u_short destx, u_short desty,
384 u_short width, u_short height,
385 u_short line_length);
386 static void cirrusfb_RectFill(u8 __iomem *regbase, int bits_per_pixel,
387 u_short x, u_short y,
388 u_short width, u_short height,
389 u32 fg_color, u32 bg_color,
390 u_short line_length, u_char blitmode);
392 static void bestclock(long freq, int *nom, int *den, int *div);
394 #ifdef CIRRUSFB_DEBUG
395 static void cirrusfb_dbg_reg_dump(struct fb_info *info, caddr_t regbase);
396 static void cirrusfb_dbg_print_regs(struct fb_info *info,
398 enum cirrusfb_dbg_reg_class reg_class, ...);
399 #endif /* CIRRUSFB_DEBUG */
401 /*** END PROTOTYPES ********************************************************/
402 /*****************************************************************************/
403 /*** BEGIN Interface Used by the World ***************************************/
405 static inline int is_laguna(const struct cirrusfb_info *cinfo)
407 return cinfo->btype == BT_LAGUNA || cinfo->btype == BT_LAGUNAB;
410 static int opencount;
412 /*--- Open /dev/fbx ---------------------------------------------------------*/
413 static int cirrusfb_open(struct fb_info *info, int user)
415 if (opencount++ == 0)
416 switch_monitor(info->par, 1);
420 /*--- Close /dev/fbx --------------------------------------------------------*/
421 static int cirrusfb_release(struct fb_info *info, int user)
423 if (--opencount == 0)
424 switch_monitor(info->par, 0);
428 /**** END Interface used by the World *************************************/
429 /****************************************************************************/
430 /**** BEGIN Hardware specific Routines **************************************/
432 /* Check if the MCLK is not a better clock source */
433 static int cirrusfb_check_mclk(struct fb_info *info, long freq)
435 struct cirrusfb_info *cinfo = info->par;
436 long mclk = vga_rseq(cinfo->regbase, CL_SEQR1F) & 0x3f;
438 /* Read MCLK value */
439 mclk = (14318 * mclk) >> 3;
440 dev_dbg(info->device, "Read MCLK of %ld kHz\n", mclk);
442 /* Determine if we should use MCLK instead of VCLK, and if so, what we
443 * should divide it by to get VCLK
446 if (abs(freq - mclk) < 250) {
447 dev_dbg(info->device, "Using VCLK = MCLK\n");
449 } else if (abs(freq - (mclk / 2)) < 250) {
450 dev_dbg(info->device, "Using VCLK = MCLK/2\n");
457 static int cirrusfb_check_pixclock(const struct fb_var_screeninfo *var,
458 struct fb_info *info)
462 struct cirrusfb_info *cinfo = info->par;
463 unsigned maxclockidx = var->bits_per_pixel >> 3;
465 /* convert from ps to kHz */
466 freq = PICOS2KHZ(var->pixclock);
468 dev_dbg(info->device, "desired pixclock: %ld kHz\n", freq);
470 maxclock = cirrusfb_board_info[cinfo->btype].maxclock[maxclockidx];
471 cinfo->multiplexing = 0;
473 /* If the frequency is greater than we can support, we might be able
474 * to use multiplexing for the video mode */
475 if (freq > maxclock) {
476 dev_err(info->device,
477 "Frequency greater than maxclock (%ld kHz)\n",
482 * Additional constraint: 8bpp uses DAC clock doubling to allow maximum
485 if (var->bits_per_pixel == 8) {
486 switch (cinfo->btype) {
491 cinfo->multiplexing = 1;
495 cinfo->multiplexing = 1;
503 /* If we have a 1MB 5434, we need to put ourselves in a mode where
504 * the VCLK is double the pixel clock. */
505 cinfo->doubleVCLK = 0;
506 if (cinfo->btype == BT_SD64 && info->fix.smem_len <= MB_ &&
507 var->bits_per_pixel == 16) {
508 cinfo->doubleVCLK = 1;
514 static int cirrusfb_check_var(struct fb_var_screeninfo *var,
515 struct fb_info *info)
518 /* memory size in pixels */
519 unsigned pixels = info->screen_size * 8 / var->bits_per_pixel;
520 struct cirrusfb_info *cinfo = info->par;
522 switch (var->bits_per_pixel) {
526 var->green = var->red;
527 var->blue = var->red;
533 var->green = var->red;
534 var->blue = var->red;
540 var->green.offset = -3;
541 var->blue.offset = 8;
543 var->red.offset = 11;
544 var->green.offset = 5;
545 var->blue.offset = 0;
548 var->green.length = 6;
549 var->blue.length = 5;
555 var->green.offset = 8;
556 var->blue.offset = 16;
558 var->red.offset = 16;
559 var->green.offset = 8;
560 var->blue.offset = 0;
563 var->green.length = 8;
564 var->blue.length = 8;
568 dev_dbg(info->device,
569 "Unsupported bpp size: %d\n", var->bits_per_pixel);
573 if (var->xres_virtual < var->xres)
574 var->xres_virtual = var->xres;
575 /* use highest possible virtual resolution */
576 if (var->yres_virtual == -1) {
577 var->yres_virtual = pixels / var->xres_virtual;
579 dev_info(info->device,
580 "virtual resolution set to maximum of %dx%d\n",
581 var->xres_virtual, var->yres_virtual);
583 if (var->yres_virtual < var->yres)
584 var->yres_virtual = var->yres;
586 if (var->xres_virtual * var->yres_virtual > pixels) {
587 dev_err(info->device, "mode %dx%dx%d rejected... "
588 "virtual resolution too high to fit into video memory!\n",
589 var->xres_virtual, var->yres_virtual,
590 var->bits_per_pixel);
594 if (var->xoffset < 0)
596 if (var->yoffset < 0)
599 /* truncate xoffset and yoffset to maximum if too high */
600 if (var->xoffset > var->xres_virtual - var->xres)
601 var->xoffset = var->xres_virtual - var->xres - 1;
602 if (var->yoffset > var->yres_virtual - var->yres)
603 var->yoffset = var->yres_virtual - var->yres - 1;
606 var->green.msb_right =
607 var->blue.msb_right =
610 var->transp.msb_right = 0;
613 if (var->vmode & FB_VMODE_DOUBLE)
615 else if (var->vmode & FB_VMODE_INTERLACED)
616 yres = (yres + 1) / 2;
619 dev_err(info->device, "ERROR: VerticalTotal >= 1280; "
620 "special treatment required! (TODO)\n");
624 if (cirrusfb_check_pixclock(var, info))
627 if (!is_laguna(cinfo))
628 var->accel_flags = FB_ACCELF_TEXT;
633 static void cirrusfb_set_mclk_as_source(const struct fb_info *info, int div)
635 struct cirrusfb_info *cinfo = info->par;
636 unsigned char old1f, old1e;
638 assert(cinfo != NULL);
639 old1f = vga_rseq(cinfo->regbase, CL_SEQR1F) & ~0x40;
642 dev_dbg(info->device, "Set %s as pixclock source.\n",
643 (div == 2) ? "MCLK/2" : "MCLK");
645 old1e = vga_rseq(cinfo->regbase, CL_SEQR1E) & ~0x1;
649 vga_wseq(cinfo->regbase, CL_SEQR1E, old1e);
651 vga_wseq(cinfo->regbase, CL_SEQR1F, old1f);
654 /*************************************************************************
655 cirrusfb_set_par_foo()
657 actually writes the values for a new video mode into the hardware,
658 **************************************************************************/
659 static int cirrusfb_set_par_foo(struct fb_info *info)
661 struct cirrusfb_info *cinfo = info->par;
662 struct fb_var_screeninfo *var = &info->var;
663 u8 __iomem *regbase = cinfo->regbase;
666 const struct cirrusfb_board_info_rec *bi;
667 int hdispend, hsyncstart, hsyncend, htotal;
668 int yres, vdispend, vsyncstart, vsyncend, vtotal;
671 unsigned int control = 0, format = 0, threshold = 0;
673 dev_dbg(info->device, "Requested mode: %dx%dx%d\n",
674 var->xres, var->yres, var->bits_per_pixel);
676 switch (var->bits_per_pixel) {
678 info->fix.line_length = var->xres_virtual / 8;
679 info->fix.visual = FB_VISUAL_MONO10;
683 info->fix.line_length = var->xres_virtual;
684 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
689 info->fix.line_length = var->xres_virtual *
690 var->bits_per_pixel >> 3;
691 info->fix.visual = FB_VISUAL_TRUECOLOR;
694 info->fix.type = FB_TYPE_PACKED_PIXELS;
698 bi = &cirrusfb_board_info[cinfo->btype];
700 hsyncstart = var->xres + var->right_margin;
701 hsyncend = hsyncstart + var->hsync_len;
702 htotal = (hsyncend + var->left_margin) / 8;
703 hdispend = var->xres / 8;
704 hsyncstart = hsyncstart / 8;
705 hsyncend = hsyncend / 8;
707 vdispend = var->yres;
708 vsyncstart = vdispend + var->lower_margin;
709 vsyncend = vsyncstart + var->vsync_len;
710 vtotal = vsyncend + var->upper_margin;
712 if (var->vmode & FB_VMODE_DOUBLE) {
717 } else if (var->vmode & FB_VMODE_INTERLACED) {
718 vdispend = (vdispend + 1) / 2;
719 vsyncstart = (vsyncstart + 1) / 2;
720 vsyncend = (vsyncend + 1) / 2;
721 vtotal = (vtotal + 1) / 2;
736 if (cinfo->multiplexing) {
748 /* unlock register VGA_CRTC_H_TOTAL..CRT7 */
749 vga_wcrt(regbase, VGA_CRTC_V_SYNC_END, 0x20); /* previously: 0x00) */
751 /* if debugging is enabled, all parameters get output before writing */
752 dev_dbg(info->device, "CRT0: %d\n", htotal);
753 vga_wcrt(regbase, VGA_CRTC_H_TOTAL, htotal);
755 dev_dbg(info->device, "CRT1: %d\n", hdispend);
756 vga_wcrt(regbase, VGA_CRTC_H_DISP, hdispend);
758 dev_dbg(info->device, "CRT2: %d\n", var->xres / 8);
759 vga_wcrt(regbase, VGA_CRTC_H_BLANK_START, var->xres / 8);
761 /* + 128: Compatible read */
762 dev_dbg(info->device, "CRT3: 128+%d\n", (htotal + 5) % 32);
763 vga_wcrt(regbase, VGA_CRTC_H_BLANK_END,
764 128 + ((htotal + 5) % 32));
766 dev_dbg(info->device, "CRT4: %d\n", hsyncstart);
767 vga_wcrt(regbase, VGA_CRTC_H_SYNC_START, hsyncstart);
770 if ((htotal + 5) & 32)
772 dev_dbg(info->device, "CRT5: %d\n", tmp);
773 vga_wcrt(regbase, VGA_CRTC_H_SYNC_END, tmp);
775 dev_dbg(info->device, "CRT6: %d\n", vtotal & 0xff);
776 vga_wcrt(regbase, VGA_CRTC_V_TOTAL, vtotal & 0xff);
778 tmp = 16; /* LineCompare bit #9 */
783 if (vsyncstart & 256)
785 if ((vdispend + 1) & 256)
791 if (vsyncstart & 512)
793 dev_dbg(info->device, "CRT7: %d\n", tmp);
794 vga_wcrt(regbase, VGA_CRTC_OVERFLOW, tmp);
796 tmp = 0x40; /* LineCompare bit #8 */
797 if ((vdispend + 1) & 512)
799 if (var->vmode & FB_VMODE_DOUBLE)
801 dev_dbg(info->device, "CRT9: %d\n", tmp);
802 vga_wcrt(regbase, VGA_CRTC_MAX_SCAN, tmp);
804 dev_dbg(info->device, "CRT10: %d\n", vsyncstart & 0xff);
805 vga_wcrt(regbase, VGA_CRTC_V_SYNC_START, vsyncstart & 0xff);
807 dev_dbg(info->device, "CRT11: 64+32+%d\n", vsyncend % 16);
808 vga_wcrt(regbase, VGA_CRTC_V_SYNC_END, vsyncend % 16 + 64 + 32);
810 dev_dbg(info->device, "CRT12: %d\n", vdispend & 0xff);
811 vga_wcrt(regbase, VGA_CRTC_V_DISP_END, vdispend & 0xff);
813 dev_dbg(info->device, "CRT15: %d\n", (vdispend + 1) & 0xff);
814 vga_wcrt(regbase, VGA_CRTC_V_BLANK_START, (vdispend + 1) & 0xff);
816 dev_dbg(info->device, "CRT16: %d\n", vtotal & 0xff);
817 vga_wcrt(regbase, VGA_CRTC_V_BLANK_END, vtotal & 0xff);
819 dev_dbg(info->device, "CRT18: 0xff\n");
820 vga_wcrt(regbase, VGA_CRTC_LINE_COMPARE, 0xff);
823 if (var->vmode & FB_VMODE_INTERLACED)
825 if ((htotal + 5) & 64)
827 if ((htotal + 5) & 128)
834 dev_dbg(info->device, "CRT1a: %d\n", tmp);
835 vga_wcrt(regbase, CL_CRT1A, tmp);
837 freq = PICOS2KHZ(var->pixclock);
838 if (var->bits_per_pixel == 24)
839 if (cinfo->btype == BT_ALPINE || cinfo->btype == BT_SD64)
841 if (cinfo->multiplexing)
843 if (cinfo->doubleVCLK)
846 bestclock(freq, &nom, &den, &div);
848 dev_dbg(info->device, "VCLK freq: %ld kHz nom: %d den: %d div: %d\n",
849 freq, nom, den, div);
852 /* hardware RefClock: 14.31818 MHz */
853 /* formula: VClk = (OSC * N) / (D * (1+P)) */
854 /* Example: VClk = (14.31818 * 91) / (23 * (1+1)) = 28.325 MHz */
856 if (cinfo->btype == BT_ALPINE || cinfo->btype == BT_PICASSO4 ||
857 cinfo->btype == BT_SD64) {
858 /* if freq is close to mclk or mclk/2 select mclk
861 int divMCLK = cirrusfb_check_mclk(info, freq);
864 cirrusfb_set_mclk_as_source(info, divMCLK);
866 if (is_laguna(cinfo)) {
867 long pcifc = fb_readl(cinfo->laguna_mmio + 0x3fc);
868 unsigned char tile = fb_readb(cinfo->laguna_mmio + 0x407);
869 unsigned short tile_control;
871 if (cinfo->btype == BT_LAGUNAB) {
872 tile_control = fb_readw(cinfo->laguna_mmio + 0x2c4);
873 tile_control &= ~0x80;
874 fb_writew(tile_control, cinfo->laguna_mmio + 0x2c4);
877 fb_writel(pcifc | 0x10000000l, cinfo->laguna_mmio + 0x3fc);
878 fb_writeb(tile & 0x3f, cinfo->laguna_mmio + 0x407);
879 control = fb_readw(cinfo->laguna_mmio + 0x402);
880 threshold = fb_readw(cinfo->laguna_mmio + 0xea);
883 threshold &= 0xffc0 & 0x3fbf;
889 /* 6 bit denom; ONLY 5434!!! (bugged me 10 days) */
890 if ((cinfo->btype == BT_SD64) ||
891 (cinfo->btype == BT_ALPINE) ||
892 (cinfo->btype == BT_GD5480))
895 /* Laguna chipset has reversed clock registers */
896 if (is_laguna(cinfo)) {
897 vga_wseq(regbase, CL_SEQRE, tmp);
898 vga_wseq(regbase, CL_SEQR1E, nom);
900 vga_wseq(regbase, CL_SEQRE, nom);
901 vga_wseq(regbase, CL_SEQR1E, tmp);
907 vga_wcrt(regbase, VGA_CRTC_MODE, 0xc7);
909 /* mode control: VGA_CRTC_START_HI enable, ROTATE(?), 16bit
910 * address wrap, no compat. */
911 vga_wcrt(regbase, VGA_CRTC_MODE, 0xc3);
913 /* don't know if it would hurt to also program this if no interlaced */
914 /* mode is used, but I feel better this way.. :-) */
915 if (var->vmode & FB_VMODE_INTERLACED)
916 vga_wcrt(regbase, VGA_CRTC_REGS, htotal / 2);
918 vga_wcrt(regbase, VGA_CRTC_REGS, 0x00); /* interlace control */
920 /* adjust horizontal/vertical sync type (low/high), use VCLK3 */
921 /* enable display memory & CRTC I/O address for color mode */
923 if (var->sync & FB_SYNC_HOR_HIGH_ACT)
925 if (var->sync & FB_SYNC_VERT_HIGH_ACT)
927 WGen(cinfo, VGA_MIS_W, tmp);
929 /* text cursor on and start line */
930 vga_wcrt(regbase, VGA_CRTC_CURSOR_START, 0);
931 /* text cursor end line */
932 vga_wcrt(regbase, VGA_CRTC_CURSOR_END, 31);
934 /******************************************************
940 /* programming for different color depths */
941 if (var->bits_per_pixel == 1) {
942 dev_dbg(info->device, "preparing for 1 bit deep display\n");
943 vga_wgfx(regbase, VGA_GFX_MODE, 0); /* mode register */
946 switch (cinfo->btype) {
954 vga_wseq(regbase, CL_SEQR7,
955 cinfo->multiplexing ?
956 bi->sr07_1bpp_mux : bi->sr07_1bpp);
961 vga_wseq(regbase, CL_SEQR7,
962 vga_rseq(regbase, CL_SEQR7) & ~0x01);
966 dev_warn(info->device, "unknown Board\n");
970 /* Extended Sequencer Mode */
971 switch (cinfo->btype) {
975 /* evtl d0 bei 1 bit? avoid FIFO underruns..? */
976 vga_wseq(regbase, CL_SEQRF, 0xb0);
980 /* ## vorher d0 avoid FIFO underruns..? */
981 vga_wseq(regbase, CL_SEQRF, 0xd0);
994 dev_warn(info->device, "unknown Board\n");
998 /* pixel mask: pass-through for first plane */
999 WGen(cinfo, VGA_PEL_MSK, 0x01);
1000 if (cinfo->multiplexing)
1001 /* hidden dac reg: 1280x1024 */
1004 /* hidden dac: nothing */
1006 /* memory mode: odd/even, ext. memory */
1007 vga_wseq(regbase, VGA_SEQ_MEMORY_MODE, 0x06);
1008 /* plane mask: only write to first plane */
1009 vga_wseq(regbase, VGA_SEQ_PLANE_WRITE, 0x01);
1012 /******************************************************
1018 else if (var->bits_per_pixel == 8) {
1019 dev_dbg(info->device, "preparing for 8 bit deep display\n");
1020 switch (cinfo->btype) {
1028 vga_wseq(regbase, CL_SEQR7,
1029 cinfo->multiplexing ?
1030 bi->sr07_8bpp_mux : bi->sr07_8bpp);
1035 vga_wseq(regbase, CL_SEQR7,
1036 vga_rseq(regbase, CL_SEQR7) | 0x01);
1041 dev_warn(info->device, "unknown Board\n");
1045 switch (cinfo->btype) {
1049 /* Fast Page-Mode writes */
1050 vga_wseq(regbase, CL_SEQRF, 0xb0);
1055 /* ### INCOMPLETE!! */
1056 vga_wseq(regbase, CL_SEQRF, 0xb8);
1067 dev_warn(info->device, "unknown board\n");
1071 /* mode register: 256 color mode */
1072 vga_wgfx(regbase, VGA_GFX_MODE, 64);
1073 if (cinfo->multiplexing)
1074 /* hidden dac reg: 1280x1024 */
1077 /* hidden dac: nothing */
1081 /******************************************************
1087 else if (var->bits_per_pixel == 16) {
1088 dev_dbg(info->device, "preparing for 16 bit deep display\n");
1089 switch (cinfo->btype) {
1092 vga_wseq(regbase, CL_SEQR7, 0x87);
1093 /* Fast Page-Mode writes */
1094 vga_wseq(regbase, CL_SEQRF, 0xb0);
1098 vga_wseq(regbase, CL_SEQR7, 0x27);
1099 /* Fast Page-Mode writes */
1100 vga_wseq(regbase, CL_SEQRF, 0xb0);
1106 /* Extended Sequencer Mode: 256c col. mode */
1107 vga_wseq(regbase, CL_SEQR7,
1108 cinfo->doubleVCLK ? 0xa3 : 0xa7);
1112 vga_wseq(regbase, CL_SEQR7, 0x17);
1113 /* We already set SRF and SR1F */
1118 vga_wseq(regbase, CL_SEQR7,
1119 vga_rseq(regbase, CL_SEQR7) & ~0x01);
1126 dev_warn(info->device, "unknown Board\n");
1130 /* mode register: 256 color mode */
1131 vga_wgfx(regbase, VGA_GFX_MODE, 64);
1133 WHDR(cinfo, cinfo->doubleVCLK ? 0xe1 : 0xc1);
1134 #elif defined(CONFIG_ZORRO)
1135 /* FIXME: CONFIG_PCI and CONFIG_ZORRO may be defined both */
1136 WHDR(cinfo, 0xa0); /* hidden dac reg: nothing special */
1140 /******************************************************
1146 else if (var->bits_per_pixel == 24) {
1147 dev_dbg(info->device, "preparing for 24 bit deep display\n");
1148 switch (cinfo->btype) {
1151 vga_wseq(regbase, CL_SEQR7, 0x85);
1152 /* Fast Page-Mode writes */
1153 vga_wseq(regbase, CL_SEQRF, 0xb0);
1157 vga_wseq(regbase, CL_SEQR7, 0x25);
1158 /* Fast Page-Mode writes */
1159 vga_wseq(regbase, CL_SEQRF, 0xb0);
1165 /* Extended Sequencer Mode: 256c col. mode */
1166 vga_wseq(regbase, CL_SEQR7, 0xa5);
1170 vga_wseq(regbase, CL_SEQR7, 0x15);
1171 /* We already set SRF and SR1F */
1176 vga_wseq(regbase, CL_SEQR7,
1177 vga_rseq(regbase, CL_SEQR7) & ~0x01);
1184 dev_warn(info->device, "unknown Board\n");
1188 /* mode register: 256 color mode */
1189 vga_wgfx(regbase, VGA_GFX_MODE, 64);
1190 /* hidden dac reg: 8-8-8 mode (24 or 32) */
1194 /******************************************************
1196 * unknown/unsupported bpp
1201 dev_err(info->device,
1202 "What's this? requested color depth == %d.\n",
1203 var->bits_per_pixel);
1205 pitch = info->fix.line_length >> 3;
1206 vga_wcrt(regbase, VGA_CRTC_OFFSET, pitch & 0xff);
1209 tmp |= 0x10; /* offset overflow bit */
1211 /* screen start addr #16-18, fastpagemode cycles */
1212 vga_wcrt(regbase, CL_CRT1B, tmp);
1214 /* screen start address bit 19 */
1215 if (cirrusfb_board_info[cinfo->btype].scrn_start_bit19)
1216 vga_wcrt(regbase, CL_CRT1D, (pitch >> 9) & 1);
1218 if (is_laguna(cinfo)) {
1220 if ((htotal + 5) & 256)
1224 if (hsyncstart & 256)
1228 if (vdispend & 1024)
1230 if (vsyncstart & 1024)
1233 vga_wcrt(regbase, CL_CRT1E, tmp);
1234 dev_dbg(info->device, "CRT1e: %d\n", tmp);
1238 vga_wattr(regbase, CL_AR33, 0);
1240 /* [ EGS: SetOffset(); ] */
1241 /* From SetOffset(): Turn on VideoEnable bit in Attribute controller */
1244 if (is_laguna(cinfo)) {
1246 fb_writew(control | 0x1000, cinfo->laguna_mmio + 0x402);
1247 fb_writew(format, cinfo->laguna_mmio + 0xc0);
1248 fb_writew(threshold, cinfo->laguna_mmio + 0xea);
1250 /* finally, turn on everything - turn off "FullBandwidth" bit */
1251 /* also, set "DotClock%2" bit where requested */
1254 /*** FB_VMODE_CLOCK_HALVE in linux/fb.h not defined anymore ?
1255 if (var->vmode & FB_VMODE_CLOCK_HALVE)
1259 vga_wseq(regbase, VGA_SEQ_CLOCK_MODE, tmp);
1260 dev_dbg(info->device, "CL_SEQR1: %d\n", tmp);
1262 #ifdef CIRRUSFB_DEBUG
1263 cirrusfb_dbg_reg_dump(info, NULL);
1269 /* for some reason incomprehensible to me, cirrusfb requires that you write
1270 * the registers twice for the settings to take..grr. -dte */
1271 static int cirrusfb_set_par(struct fb_info *info)
1273 cirrusfb_set_par_foo(info);
1274 return cirrusfb_set_par_foo(info);
1277 static int cirrusfb_setcolreg(unsigned regno, unsigned red, unsigned green,
1278 unsigned blue, unsigned transp,
1279 struct fb_info *info)
1281 struct cirrusfb_info *cinfo = info->par;
1286 if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
1288 red >>= (16 - info->var.red.length);
1289 green >>= (16 - info->var.green.length);
1290 blue >>= (16 - info->var.blue.length);
1294 v = (red << info->var.red.offset) |
1295 (green << info->var.green.offset) |
1296 (blue << info->var.blue.offset);
1298 cinfo->pseudo_palette[regno] = v;
1302 if (info->var.bits_per_pixel == 8)
1303 WClut(cinfo, regno, red >> 10, green >> 10, blue >> 10);
1309 /*************************************************************************
1310 cirrusfb_pan_display()
1312 performs display panning - provided hardware permits this
1313 **************************************************************************/
1314 static int cirrusfb_pan_display(struct fb_var_screeninfo *var,
1315 struct fb_info *info)
1319 unsigned char tmp, xpix;
1320 struct cirrusfb_info *cinfo = info->par;
1322 /* no range checks for xoffset and yoffset, */
1323 /* as fb_pan_display has already done this */
1324 if (var->vmode & FB_VMODE_YWRAP)
1327 xoffset = var->xoffset * info->var.bits_per_pixel / 8;
1329 base = var->yoffset * info->fix.line_length + xoffset;
1331 if (info->var.bits_per_pixel == 1) {
1332 /* base is already correct */
1333 xpix = (unsigned char) (var->xoffset % 8);
1336 xpix = (unsigned char) ((xoffset % 4) * 2);
1339 if (!is_laguna(cinfo))
1340 cirrusfb_WaitBLT(cinfo->regbase);
1342 /* lower 8 + 8 bits of screen start address */
1343 vga_wcrt(cinfo->regbase, VGA_CRTC_START_LO, base & 0xff);
1344 vga_wcrt(cinfo->regbase, VGA_CRTC_START_HI, (base >> 8) & 0xff);
1346 /* 0xf2 is %11110010, exclude tmp bits */
1347 tmp = vga_rcrt(cinfo->regbase, CL_CRT1B) & 0xf2;
1348 /* construct bits 16, 17 and 18 of screen start address */
1356 vga_wcrt(cinfo->regbase, CL_CRT1B, tmp);
1358 /* construct bit 19 of screen start address */
1359 if (cirrusfb_board_info[cinfo->btype].scrn_start_bit19) {
1360 tmp = vga_rcrt(cinfo->regbase, CL_CRT1D);
1361 if (is_laguna(cinfo))
1362 tmp = (tmp & ~0x18) | ((base >> 16) & 0x18);
1364 tmp = (tmp & ~0x80) | ((base >> 12) & 0x80);
1365 vga_wcrt(cinfo->regbase, CL_CRT1D, tmp);
1368 /* write pixel panning value to AR33; this does not quite work in 8bpp
1370 * ### Piccolo..? Will this work?
1372 if (info->var.bits_per_pixel == 1)
1373 vga_wattr(cinfo->regbase, CL_AR33, xpix);
1378 static int cirrusfb_blank(int blank_mode, struct fb_info *info)
1381 * Blank the screen if blank_mode != 0, else unblank. If blank == NULL
1382 * then the caller blanks by setting the CLUT (Color Look Up Table)
1383 * to all black. Return 0 if blanking succeeded, != 0 if un-/blanking
1384 * failed due to e.g. a video mode which doesn't support it.
1385 * Implements VESA suspend and powerdown modes on hardware that
1386 * supports disabling hsync/vsync:
1387 * blank_mode == 2: suspend vsync
1388 * blank_mode == 3: suspend hsync
1389 * blank_mode == 4: powerdown
1392 struct cirrusfb_info *cinfo = info->par;
1393 int current_mode = cinfo->blank_mode;
1395 dev_dbg(info->device, "ENTER, blank mode = %d\n", blank_mode);
1397 if (info->state != FBINFO_STATE_RUNNING ||
1398 current_mode == blank_mode) {
1399 dev_dbg(info->device, "EXIT, returning 0\n");
1404 if (current_mode == FB_BLANK_NORMAL ||
1405 current_mode == FB_BLANK_UNBLANK)
1406 /* clear "FullBandwidth" bit */
1409 /* set "FullBandwidth" bit */
1412 val |= vga_rseq(cinfo->regbase, VGA_SEQ_CLOCK_MODE) & 0xdf;
1413 vga_wseq(cinfo->regbase, VGA_SEQ_CLOCK_MODE, val);
1415 switch (blank_mode) {
1416 case FB_BLANK_UNBLANK:
1417 case FB_BLANK_NORMAL:
1420 case FB_BLANK_VSYNC_SUSPEND:
1423 case FB_BLANK_HSYNC_SUSPEND:
1426 case FB_BLANK_POWERDOWN:
1430 dev_dbg(info->device, "EXIT, returning 1\n");
1434 vga_wgfx(cinfo->regbase, CL_GRE, val);
1436 cinfo->blank_mode = blank_mode;
1437 dev_dbg(info->device, "EXIT, returning 0\n");
1439 /* Let fbcon do a soft blank for us */
1440 return (blank_mode == FB_BLANK_NORMAL) ? 1 : 0;
1443 /**** END Hardware specific Routines **************************************/
1444 /****************************************************************************/
1445 /**** BEGIN Internal Routines ***********************************************/
1447 static void init_vgachip(struct fb_info *info)
1449 struct cirrusfb_info *cinfo = info->par;
1450 const struct cirrusfb_board_info_rec *bi;
1452 assert(cinfo != NULL);
1454 bi = &cirrusfb_board_info[cinfo->btype];
1456 /* reset board globally */
1457 switch (cinfo->btype) {
1476 /* disable flickerfixer */
1477 vga_wcrt(cinfo->regbase, CL_CRT51, 0x00);
1480 vga_wgfx(cinfo->regbase, CL_GR31, 0x00);
1481 case BT_GD5480: /* fall through */
1482 /* from Klaus' NetBSD driver: */
1483 vga_wgfx(cinfo->regbase, CL_GR2F, 0x00);
1484 case BT_ALPINE: /* fall through */
1485 /* put blitter into 542x compat */
1486 vga_wgfx(cinfo->regbase, CL_GR33, 0x00);
1491 /* Nothing to do to reset the board. */
1495 dev_err(info->device, "Warning: Unknown board type\n");
1499 /* make sure RAM size set by this point */
1500 assert(info->screen_size > 0);
1502 /* the P4 is not fully initialized here; I rely on it having been */
1503 /* inited under AmigaOS already, which seems to work just fine */
1504 /* (Klaus advised to do it this way) */
1506 if (cinfo->btype != BT_PICASSO4) {
1507 WGen(cinfo, CL_VSSM, 0x10); /* EGS: 0x16 */
1508 WGen(cinfo, CL_POS102, 0x01);
1509 WGen(cinfo, CL_VSSM, 0x08); /* EGS: 0x0e */
1511 if (cinfo->btype != BT_SD64)
1512 WGen(cinfo, CL_VSSM2, 0x01);
1514 /* reset sequencer logic */
1515 vga_wseq(cinfo->regbase, VGA_SEQ_RESET, 0x03);
1517 /* FullBandwidth (video off) and 8/9 dot clock */
1518 vga_wseq(cinfo->regbase, VGA_SEQ_CLOCK_MODE, 0x21);
1520 /* "magic cookie" - doesn't make any sense to me.. */
1521 /* vga_wgfx(cinfo->regbase, CL_GRA, 0xce); */
1522 /* unlock all extension registers */
1523 vga_wseq(cinfo->regbase, CL_SEQR6, 0x12);
1525 switch (cinfo->btype) {
1527 vga_wseq(cinfo->regbase, CL_SEQRF, 0x98);
1535 vga_wseq(cinfo->regbase, CL_SEQRF, 0xb8);
1539 vga_wseq(cinfo->regbase, CL_SEQR16, 0x0f);
1540 vga_wseq(cinfo->regbase, CL_SEQRF, 0xb0);
1544 /* plane mask: nothing */
1545 vga_wseq(cinfo->regbase, VGA_SEQ_PLANE_WRITE, 0xff);
1546 /* character map select: doesn't even matter in gx mode */
1547 vga_wseq(cinfo->regbase, VGA_SEQ_CHARACTER_MAP, 0x00);
1548 /* memory mode: chain4, ext. memory */
1549 vga_wseq(cinfo->regbase, VGA_SEQ_MEMORY_MODE, 0x0a);
1551 /* controller-internal base address of video memory */
1553 vga_wseq(cinfo->regbase, CL_SEQR7, bi->sr07);
1555 /* vga_wseq(cinfo->regbase, CL_SEQR8, 0x00); */
1556 /* EEPROM control: shouldn't be necessary to write to this at all.. */
1558 /* graphics cursor X position (incomplete; position gives rem. 3 bits */
1559 vga_wseq(cinfo->regbase, CL_SEQR10, 0x00);
1560 /* graphics cursor Y position (..."... ) */
1561 vga_wseq(cinfo->regbase, CL_SEQR11, 0x00);
1562 /* graphics cursor attributes */
1563 vga_wseq(cinfo->regbase, CL_SEQR12, 0x00);
1564 /* graphics cursor pattern address */
1565 vga_wseq(cinfo->regbase, CL_SEQR13, 0x00);
1567 /* writing these on a P4 might give problems.. */
1568 if (cinfo->btype != BT_PICASSO4) {
1569 /* configuration readback and ext. color */
1570 vga_wseq(cinfo->regbase, CL_SEQR17, 0x00);
1571 /* signature generator */
1572 vga_wseq(cinfo->regbase, CL_SEQR18, 0x02);
1575 /* Screen A preset row scan: none */
1576 vga_wcrt(cinfo->regbase, VGA_CRTC_PRESET_ROW, 0x00);
1577 /* Text cursor start: disable text cursor */
1578 vga_wcrt(cinfo->regbase, VGA_CRTC_CURSOR_START, 0x20);
1579 /* Text cursor end: - */
1580 vga_wcrt(cinfo->regbase, VGA_CRTC_CURSOR_END, 0x00);
1581 /* text cursor location high: 0 */
1582 vga_wcrt(cinfo->regbase, VGA_CRTC_CURSOR_HI, 0x00);
1583 /* text cursor location low: 0 */
1584 vga_wcrt(cinfo->regbase, VGA_CRTC_CURSOR_LO, 0x00);
1586 /* Underline Row scanline: - */
1587 vga_wcrt(cinfo->regbase, VGA_CRTC_UNDERLINE, 0x00);
1588 /* ### add 0x40 for text modes with > 30 MHz pixclock */
1589 /* ext. display controls: ext.adr. wrap */
1590 vga_wcrt(cinfo->regbase, CL_CRT1B, 0x02);
1592 /* Set/Reset registes: - */
1593 vga_wgfx(cinfo->regbase, VGA_GFX_SR_VALUE, 0x00);
1594 /* Set/Reset enable: - */
1595 vga_wgfx(cinfo->regbase, VGA_GFX_SR_ENABLE, 0x00);
1596 /* Color Compare: - */
1597 vga_wgfx(cinfo->regbase, VGA_GFX_COMPARE_VALUE, 0x00);
1598 /* Data Rotate: - */
1599 vga_wgfx(cinfo->regbase, VGA_GFX_DATA_ROTATE, 0x00);
1600 /* Read Map Select: - */
1601 vga_wgfx(cinfo->regbase, VGA_GFX_PLANE_READ, 0x00);
1602 /* Mode: conf. for 16/4/2 color mode, no odd/even, read/write mode 0 */
1603 vga_wgfx(cinfo->regbase, VGA_GFX_MODE, 0x00);
1604 /* Miscellaneous: memory map base address, graphics mode */
1605 vga_wgfx(cinfo->regbase, VGA_GFX_MISC, 0x01);
1606 /* Color Don't care: involve all planes */
1607 vga_wgfx(cinfo->regbase, VGA_GFX_COMPARE_MASK, 0x0f);
1608 /* Bit Mask: no mask at all */
1609 vga_wgfx(cinfo->regbase, VGA_GFX_BIT_MASK, 0xff);
1611 if (cinfo->btype == BT_ALPINE || cinfo->btype == BT_SD64 ||
1613 /* (5434 can't have bit 3 set for bitblt) */
1614 vga_wgfx(cinfo->regbase, CL_GRB, 0x20);
1616 /* Graphics controller mode extensions: finer granularity,
1617 * 8byte data latches
1619 vga_wgfx(cinfo->regbase, CL_GRB, 0x28);
1621 vga_wgfx(cinfo->regbase, CL_GRC, 0xff); /* Color Key compare: - */
1622 vga_wgfx(cinfo->regbase, CL_GRD, 0x00); /* Color Key compare mask: - */
1623 vga_wgfx(cinfo->regbase, CL_GRE, 0x00); /* Miscellaneous control: - */
1624 /* Background color byte 1: - */
1625 /* vga_wgfx (cinfo->regbase, CL_GR10, 0x00); */
1626 /* vga_wgfx (cinfo->regbase, CL_GR11, 0x00); */
1628 /* Attribute Controller palette registers: "identity mapping" */
1629 vga_wattr(cinfo->regbase, VGA_ATC_PALETTE0, 0x00);
1630 vga_wattr(cinfo->regbase, VGA_ATC_PALETTE1, 0x01);
1631 vga_wattr(cinfo->regbase, VGA_ATC_PALETTE2, 0x02);
1632 vga_wattr(cinfo->regbase, VGA_ATC_PALETTE3, 0x03);
1633 vga_wattr(cinfo->regbase, VGA_ATC_PALETTE4, 0x04);
1634 vga_wattr(cinfo->regbase, VGA_ATC_PALETTE5, 0x05);
1635 vga_wattr(cinfo->regbase, VGA_ATC_PALETTE6, 0x06);
1636 vga_wattr(cinfo->regbase, VGA_ATC_PALETTE7, 0x07);
1637 vga_wattr(cinfo->regbase, VGA_ATC_PALETTE8, 0x08);
1638 vga_wattr(cinfo->regbase, VGA_ATC_PALETTE9, 0x09);
1639 vga_wattr(cinfo->regbase, VGA_ATC_PALETTEA, 0x0a);
1640 vga_wattr(cinfo->regbase, VGA_ATC_PALETTEB, 0x0b);
1641 vga_wattr(cinfo->regbase, VGA_ATC_PALETTEC, 0x0c);
1642 vga_wattr(cinfo->regbase, VGA_ATC_PALETTED, 0x0d);
1643 vga_wattr(cinfo->regbase, VGA_ATC_PALETTEE, 0x0e);
1644 vga_wattr(cinfo->regbase, VGA_ATC_PALETTEF, 0x0f);
1646 /* Attribute Controller mode: graphics mode */
1647 vga_wattr(cinfo->regbase, VGA_ATC_MODE, 0x01);
1648 /* Overscan color reg.: reg. 0 */
1649 vga_wattr(cinfo->regbase, VGA_ATC_OVERSCAN, 0x00);
1650 /* Color Plane enable: Enable all 4 planes */
1651 vga_wattr(cinfo->regbase, VGA_ATC_PLANE_ENABLE, 0x0f);
1652 /* Color Select: - */
1653 vga_wattr(cinfo->regbase, VGA_ATC_COLOR_PAGE, 0x00);
1655 WGen(cinfo, VGA_PEL_MSK, 0xff); /* Pixel mask: no mask */
1657 /* BLT Start/status: Blitter reset */
1658 vga_wgfx(cinfo->regbase, CL_GR31, 0x04);
1659 /* - " - : "end-of-reset" */
1660 vga_wgfx(cinfo->regbase, CL_GR31, 0x00);
1663 WHDR(cinfo, 0); /* Hidden DAC register: - */
1667 static void switch_monitor(struct cirrusfb_info *cinfo, int on)
1669 #ifdef CONFIG_ZORRO /* only works on Zorro boards */
1670 static int IsOn = 0; /* XXX not ok for multiple boards */
1672 if (cinfo->btype == BT_PICASSO4)
1673 return; /* nothing to switch */
1674 if (cinfo->btype == BT_ALPINE)
1675 return; /* nothing to switch */
1676 if (cinfo->btype == BT_GD5480)
1677 return; /* nothing to switch */
1678 if (cinfo->btype == BT_PICASSO) {
1679 if ((on && !IsOn) || (!on && IsOn))
1684 switch (cinfo->btype) {
1686 WSFR(cinfo, cinfo->SFR | 0x21);
1689 WSFR(cinfo, cinfo->SFR | 0x28);
1694 default: /* do nothing */ break;
1697 switch (cinfo->btype) {
1699 WSFR(cinfo, cinfo->SFR & 0xde);
1702 WSFR(cinfo, cinfo->SFR & 0xd7);
1707 default: /* do nothing */
1711 #endif /* CONFIG_ZORRO */
1714 /******************************************/
1715 /* Linux 2.6-style accelerated functions */
1716 /******************************************/
1718 static int cirrusfb_sync(struct fb_info *info)
1720 struct cirrusfb_info *cinfo = info->par;
1722 if (!is_laguna(cinfo)) {
1723 while (vga_rgfx(cinfo->regbase, CL_GR31) & 0x03)
1729 static void cirrusfb_fillrect(struct fb_info *info,
1730 const struct fb_fillrect *region)
1732 struct fb_fillrect modded;
1734 struct cirrusfb_info *cinfo = info->par;
1735 int m = info->var.bits_per_pixel;
1736 u32 color = (info->fix.visual == FB_VISUAL_TRUECOLOR) ?
1737 cinfo->pseudo_palette[region->color] : region->color;
1739 if (info->state != FBINFO_STATE_RUNNING)
1741 if (info->flags & FBINFO_HWACCEL_DISABLED) {
1742 cfb_fillrect(info, region);
1746 vxres = info->var.xres_virtual;
1747 vyres = info->var.yres_virtual;
1749 memcpy(&modded, region, sizeof(struct fb_fillrect));
1751 if (!modded.width || !modded.height ||
1752 modded.dx >= vxres || modded.dy >= vyres)
1755 if (modded.dx + modded.width > vxres)
1756 modded.width = vxres - modded.dx;
1757 if (modded.dy + modded.height > vyres)
1758 modded.height = vyres - modded.dy;
1760 cirrusfb_RectFill(cinfo->regbase,
1761 info->var.bits_per_pixel,
1762 (region->dx * m) / 8, region->dy,
1763 (region->width * m) / 8, region->height,
1765 info->fix.line_length, 0x40);
1768 static void cirrusfb_copyarea(struct fb_info *info,
1769 const struct fb_copyarea *area)
1771 struct fb_copyarea modded;
1773 struct cirrusfb_info *cinfo = info->par;
1774 int m = info->var.bits_per_pixel;
1776 if (info->state != FBINFO_STATE_RUNNING)
1778 if (info->flags & FBINFO_HWACCEL_DISABLED) {
1779 cfb_copyarea(info, area);
1783 vxres = info->var.xres_virtual;
1784 vyres = info->var.yres_virtual;
1785 memcpy(&modded, area, sizeof(struct fb_copyarea));
1787 if (!modded.width || !modded.height ||
1788 modded.sx >= vxres || modded.sy >= vyres ||
1789 modded.dx >= vxres || modded.dy >= vyres)
1792 if (modded.sx + modded.width > vxres)
1793 modded.width = vxres - modded.sx;
1794 if (modded.dx + modded.width > vxres)
1795 modded.width = vxres - modded.dx;
1796 if (modded.sy + modded.height > vyres)
1797 modded.height = vyres - modded.sy;
1798 if (modded.dy + modded.height > vyres)
1799 modded.height = vyres - modded.dy;
1801 cirrusfb_BitBLT(cinfo->regbase, info->var.bits_per_pixel,
1802 (area->sx * m) / 8, area->sy,
1803 (area->dx * m) / 8, area->dy,
1804 (area->width * m) / 8, area->height,
1805 info->fix.line_length);
1809 static void cirrusfb_imageblit(struct fb_info *info,
1810 const struct fb_image *image)
1812 struct cirrusfb_info *cinfo = info->par;
1813 unsigned char op = (info->var.bits_per_pixel == 24) ? 0xc : 0x4;
1815 if (info->state != FBINFO_STATE_RUNNING)
1817 /* Alpine/SD64 does not work at 24bpp ??? */
1818 if (info->flags & FBINFO_HWACCEL_DISABLED || image->depth != 1)
1819 cfb_imageblit(info, image);
1820 else if ((cinfo->btype == BT_ALPINE || cinfo->btype == BT_SD64) &&
1822 cfb_imageblit(info, image);
1824 unsigned size = ((image->width + 7) >> 3) * image->height;
1825 int m = info->var.bits_per_pixel;
1828 if (info->var.bits_per_pixel == 8) {
1829 fg = image->fg_color;
1830 bg = image->bg_color;
1832 fg = ((u32 *)(info->pseudo_palette))[image->fg_color];
1833 bg = ((u32 *)(info->pseudo_palette))[image->bg_color];
1835 if (info->var.bits_per_pixel == 24) {
1836 /* clear background first */
1837 cirrusfb_RectFill(cinfo->regbase,
1838 info->var.bits_per_pixel,
1839 (image->dx * m) / 8, image->dy,
1840 (image->width * m) / 8,
1843 info->fix.line_length, 0x40);
1845 cirrusfb_RectFill(cinfo->regbase,
1846 info->var.bits_per_pixel,
1847 (image->dx * m) / 8, image->dy,
1848 (image->width * m) / 8, image->height,
1850 info->fix.line_length, op);
1851 memcpy(info->screen_base, image->data, size);
1855 #ifdef CONFIG_PPC_PREP
1856 #define PREP_VIDEO_BASE ((volatile unsigned long) 0xC0000000)
1857 #define PREP_IO_BASE ((volatile unsigned char *) 0x80000000)
1858 static void get_prep_addrs(unsigned long *display, unsigned long *registers)
1860 *display = PREP_VIDEO_BASE;
1861 *registers = (unsigned long) PREP_IO_BASE;
1864 #endif /* CONFIG_PPC_PREP */
1867 static int release_io_ports;
1869 /* Pulled the logic from XFree86 Cirrus driver to get the memory size,
1870 * based on the DRAM bandwidth bit and DRAM bank switching bit. This
1871 * works with 1MB, 2MB and 4MB configurations (which the Motorola boards
1873 static unsigned int __devinit cirrusfb_get_memsize(struct fb_info *info,
1874 u8 __iomem *regbase)
1877 struct cirrusfb_info *cinfo = info->par;
1879 if (is_laguna(cinfo)) {
1880 unsigned char SR14 = vga_rseq(regbase, CL_SEQR14);
1882 mem = ((SR14 & 7) + 1) << 20;
1884 unsigned char SRF = vga_rseq(regbase, CL_SEQRF);
1885 switch ((SRF & 0x18)) {
1892 /* 64-bit DRAM data bus width; assume 2MB.
1893 * Also indicates 2MB memory on the 5430.
1899 dev_warn(info->device, "Unknown memory size!\n");
1902 /* If DRAM bank switching is enabled, there must be
1903 * twice as much memory installed. (4MB on the 5434)
1905 if (cinfo->btype != BT_ALPINE && (SRF & 0x80) != 0)
1909 /* TODO: Handling of GD5446/5480 (see XF86 sources ...) */
1913 static void get_pci_addrs(const struct pci_dev *pdev,
1914 unsigned long *display, unsigned long *registers)
1916 assert(pdev != NULL);
1917 assert(display != NULL);
1918 assert(registers != NULL);
1923 /* This is a best-guess for now */
1925 if (pci_resource_flags(pdev, 0) & IORESOURCE_IO) {
1926 *display = pci_resource_start(pdev, 1);
1927 *registers = pci_resource_start(pdev, 0);
1929 *display = pci_resource_start(pdev, 0);
1930 *registers = pci_resource_start(pdev, 1);
1933 assert(*display != 0);
1936 static void cirrusfb_pci_unmap(struct fb_info *info)
1938 struct pci_dev *pdev = to_pci_dev(info->device);
1939 struct cirrusfb_info *cinfo = info->par;
1941 if (cinfo->laguna_mmio == NULL)
1942 iounmap(cinfo->laguna_mmio);
1943 iounmap(info->screen_base);
1944 #if 0 /* if system didn't claim this region, we would... */
1945 release_mem_region(0xA0000, 65535);
1947 if (release_io_ports)
1948 release_region(0x3C0, 32);
1949 pci_release_regions(pdev);
1951 #endif /* CONFIG_PCI */
1954 static void cirrusfb_zorro_unmap(struct fb_info *info)
1956 struct cirrusfb_info *cinfo = info->par;
1957 struct zorro_dev *zdev = to_zorro_dev(info->device);
1959 zorro_release_device(zdev);
1961 if (cinfo->btype == BT_PICASSO4) {
1962 cinfo->regbase -= 0x600000;
1963 iounmap((void *)cinfo->regbase);
1964 iounmap(info->screen_base);
1966 if (zorro_resource_start(zdev) > 0x01000000)
1967 iounmap(info->screen_base);
1970 #endif /* CONFIG_ZORRO */
1972 /* function table of the above functions */
1973 static struct fb_ops cirrusfb_ops = {
1974 .owner = THIS_MODULE,
1975 .fb_open = cirrusfb_open,
1976 .fb_release = cirrusfb_release,
1977 .fb_setcolreg = cirrusfb_setcolreg,
1978 .fb_check_var = cirrusfb_check_var,
1979 .fb_set_par = cirrusfb_set_par,
1980 .fb_pan_display = cirrusfb_pan_display,
1981 .fb_blank = cirrusfb_blank,
1982 .fb_fillrect = cirrusfb_fillrect,
1983 .fb_copyarea = cirrusfb_copyarea,
1984 .fb_sync = cirrusfb_sync,
1985 .fb_imageblit = cirrusfb_imageblit,
1988 static int __devinit cirrusfb_set_fbinfo(struct fb_info *info)
1990 struct cirrusfb_info *cinfo = info->par;
1991 struct fb_var_screeninfo *var = &info->var;
1993 info->pseudo_palette = cinfo->pseudo_palette;
1994 info->flags = FBINFO_DEFAULT
1995 | FBINFO_HWACCEL_XPAN
1996 | FBINFO_HWACCEL_YPAN
1997 | FBINFO_HWACCEL_FILLRECT
1998 | FBINFO_HWACCEL_IMAGEBLIT
1999 | FBINFO_HWACCEL_COPYAREA;
2000 if (noaccel || is_laguna(cinfo)) {
2001 info->flags |= FBINFO_HWACCEL_DISABLED;
2002 info->fix.accel = FB_ACCEL_NONE;
2004 info->fix.accel = FB_ACCEL_CIRRUS_ALPINE;
2006 info->fbops = &cirrusfb_ops;
2008 if (cinfo->btype == BT_GD5480) {
2009 if (var->bits_per_pixel == 16)
2010 info->screen_base += 1 * MB_;
2011 if (var->bits_per_pixel == 32)
2012 info->screen_base += 2 * MB_;
2015 /* Fill fix common fields */
2016 strlcpy(info->fix.id, cirrusfb_board_info[cinfo->btype].name,
2017 sizeof(info->fix.id));
2019 /* monochrome: only 1 memory plane */
2020 /* 8 bit and above: Use whole memory area */
2021 info->fix.smem_len = info->screen_size;
2022 if (var->bits_per_pixel == 1)
2023 info->fix.smem_len /= 4;
2024 info->fix.type_aux = 0;
2025 info->fix.xpanstep = 1;
2026 info->fix.ypanstep = 1;
2027 info->fix.ywrapstep = 0;
2029 /* FIXME: map region at 0xB8000 if available, fill in here */
2030 info->fix.mmio_len = 0;
2032 fb_alloc_cmap(&info->cmap, 256, 0);
2037 static int __devinit cirrusfb_register(struct fb_info *info)
2039 struct cirrusfb_info *cinfo = info->par;
2043 assert(cinfo->btype != BT_NONE);
2045 /* set all the vital stuff */
2046 cirrusfb_set_fbinfo(info);
2048 dev_dbg(info->device, "(RAM start set to: 0x%p)\n", info->screen_base);
2050 err = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 8);
2052 dev_dbg(info->device, "wrong initial video mode\n");
2054 goto err_dealloc_cmap;
2057 info->var.activate = FB_ACTIVATE_NOW;
2059 err = cirrusfb_check_var(&info->var, info);
2061 /* should never happen */
2062 dev_dbg(info->device,
2063 "choking on default var... umm, no good.\n");
2064 goto err_dealloc_cmap;
2067 err = register_framebuffer(info);
2069 dev_err(info->device,
2070 "could not register fb device; err = %d!\n", err);
2071 goto err_dealloc_cmap;
2077 fb_dealloc_cmap(&info->cmap);
2081 static void __devexit cirrusfb_cleanup(struct fb_info *info)
2083 struct cirrusfb_info *cinfo = info->par;
2085 switch_monitor(cinfo, 0);
2086 unregister_framebuffer(info);
2087 fb_dealloc_cmap(&info->cmap);
2088 dev_dbg(info->device, "Framebuffer unregistered\n");
2090 framebuffer_release(info);
2094 static int __devinit cirrusfb_pci_register(struct pci_dev *pdev,
2095 const struct pci_device_id *ent)
2097 struct cirrusfb_info *cinfo;
2098 struct fb_info *info;
2099 unsigned long board_addr, board_size;
2102 ret = pci_enable_device(pdev);
2104 printk(KERN_ERR "cirrusfb: Cannot enable PCI device\n");
2108 info = framebuffer_alloc(sizeof(struct cirrusfb_info), &pdev->dev);
2110 printk(KERN_ERR "cirrusfb: could not allocate memory\n");
2116 cinfo->btype = (enum cirrus_board) ent->driver_data;
2118 dev_dbg(info->device,
2119 " Found PCI device, base address 0 is 0x%Lx, btype set to %d\n",
2120 (unsigned long long)pdev->resource[0].start, cinfo->btype);
2121 dev_dbg(info->device, " base address 1 is 0x%Lx\n",
2122 (unsigned long long)pdev->resource[1].start);
2125 pci_write_config_dword(pdev, PCI_BASE_ADDRESS_0, 0x00000000);
2126 #ifdef CONFIG_PPC_PREP
2127 get_prep_addrs(&board_addr, &info->fix.mmio_start);
2129 /* PReP dies if we ioremap the IO registers, but it works w/out... */
2130 cinfo->regbase = (char __iomem *) info->fix.mmio_start;
2132 dev_dbg(info->device,
2133 "Attempt to get PCI info for Cirrus Graphics Card\n");
2134 get_pci_addrs(pdev, &board_addr, &info->fix.mmio_start);
2135 /* FIXME: this forces VGA. alternatives? */
2136 cinfo->regbase = NULL;
2137 cinfo->laguna_mmio = ioremap(info->fix.mmio_start, 0x1000);
2140 dev_dbg(info->device, "Board address: 0x%lx, register address: 0x%lx\n",
2141 board_addr, info->fix.mmio_start);
2143 board_size = (cinfo->btype == BT_GD5480) ?
2144 32 * MB_ : cirrusfb_get_memsize(info, cinfo->regbase);
2146 ret = pci_request_regions(pdev, "cirrusfb");
2148 dev_err(info->device, "cannot reserve region 0x%lx, abort\n",
2150 goto err_release_fb;
2152 #if 0 /* if the system didn't claim this region, we would... */
2153 if (!request_mem_region(0xA0000, 65535, "cirrusfb")) {
2154 dev_err(info->device, "cannot reserve region 0x%lx, abort\n",
2157 goto err_release_regions;
2160 if (request_region(0x3C0, 32, "cirrusfb"))
2161 release_io_ports = 1;
2163 info->screen_base = ioremap(board_addr, board_size);
2164 if (!info->screen_base) {
2166 goto err_release_legacy;
2169 info->fix.smem_start = board_addr;
2170 info->screen_size = board_size;
2171 cinfo->unmap = cirrusfb_pci_unmap;
2173 dev_info(info->device,
2174 "Cirrus Logic chipset on PCI bus, RAM (%lu kB) at 0x%lx\n",
2175 info->screen_size >> 10, board_addr);
2176 pci_set_drvdata(pdev, info);
2178 ret = cirrusfb_register(info);
2182 pci_set_drvdata(pdev, NULL);
2183 iounmap(info->screen_base);
2185 if (release_io_ports)
2186 release_region(0x3C0, 32);
2188 release_mem_region(0xA0000, 65535);
2189 err_release_regions:
2191 pci_release_regions(pdev);
2193 if (cinfo->laguna_mmio != NULL)
2194 iounmap(cinfo->laguna_mmio);
2195 framebuffer_release(info);
2200 static void __devexit cirrusfb_pci_unregister(struct pci_dev *pdev)
2202 struct fb_info *info = pci_get_drvdata(pdev);
2204 cirrusfb_cleanup(info);
2207 static struct pci_driver cirrusfb_pci_driver = {
2209 .id_table = cirrusfb_pci_table,
2210 .probe = cirrusfb_pci_register,
2211 .remove = __devexit_p(cirrusfb_pci_unregister),
2214 .suspend = cirrusfb_pci_suspend,
2215 .resume = cirrusfb_pci_resume,
2219 #endif /* CONFIG_PCI */
2222 static int __devinit cirrusfb_zorro_register(struct zorro_dev *z,
2223 const struct zorro_device_id *ent)
2225 struct cirrusfb_info *cinfo;
2226 struct fb_info *info;
2227 enum cirrus_board btype;
2228 struct zorro_dev *z2 = NULL;
2229 unsigned long board_addr, board_size, size;
2232 btype = ent->driver_data;
2233 if (cirrusfb_zorro_table2[btype].id2)
2234 z2 = zorro_find_device(cirrusfb_zorro_table2[btype].id2, NULL);
2235 size = cirrusfb_zorro_table2[btype].size;
2237 info = framebuffer_alloc(sizeof(struct cirrusfb_info), &z->dev);
2239 printk(KERN_ERR "cirrusfb: could not allocate memory\n");
2244 dev_info(info->device, "%s board detected\n",
2245 cirrusfb_board_info[btype].name);
2248 cinfo->btype = btype;
2251 assert(btype != BT_NONE);
2253 board_addr = zorro_resource_start(z);
2254 board_size = zorro_resource_len(z);
2255 info->screen_size = size;
2257 if (!zorro_request_device(z, "cirrusfb")) {
2258 dev_err(info->device, "cannot reserve region 0x%lx, abort\n",
2261 goto err_release_fb;
2266 if (btype == BT_PICASSO4) {
2267 dev_info(info->device, " REG at $%lx\n", board_addr + 0x600000);
2269 /* To be precise, for the P4 this is not the */
2270 /* begin of the board, but the begin of RAM. */
2271 /* for P4, map in its address space in 2 chunks (### TEST! ) */
2272 /* (note the ugly hardcoded 16M number) */
2273 cinfo->regbase = ioremap(board_addr, 16777216);
2274 if (!cinfo->regbase)
2275 goto err_release_region;
2277 dev_dbg(info->device, "Virtual address for board set to: $%p\n",
2279 cinfo->regbase += 0x600000;
2280 info->fix.mmio_start = board_addr + 0x600000;
2282 info->fix.smem_start = board_addr + 16777216;
2283 info->screen_base = ioremap(info->fix.smem_start, 16777216);
2284 if (!info->screen_base)
2285 goto err_unmap_regbase;
2287 dev_info(info->device, " REG at $%lx\n",
2288 (unsigned long) z2->resource.start);
2290 info->fix.smem_start = board_addr;
2291 if (board_addr > 0x01000000)
2292 info->screen_base = ioremap(board_addr, board_size);
2294 info->screen_base = (caddr_t) ZTWO_VADDR(board_addr);
2295 if (!info->screen_base)
2296 goto err_release_region;
2298 /* set address for REG area of board */
2299 cinfo->regbase = (caddr_t) ZTWO_VADDR(z2->resource.start);
2300 info->fix.mmio_start = z2->resource.start;
2302 dev_dbg(info->device, "Virtual address for board set to: $%p\n",
2305 cinfo->unmap = cirrusfb_zorro_unmap;
2307 dev_info(info->device,
2308 "Cirrus Logic chipset on Zorro bus, RAM (%lu MB) at $%lx\n",
2309 board_size / MB_, board_addr);
2311 zorro_set_drvdata(z, info);
2313 /* MCLK select etc. */
2314 if (cirrusfb_board_info[btype].init_sr1f)
2315 vga_wseq(cinfo->regbase, CL_SEQR1F,
2316 cirrusfb_board_info[btype].sr1f);
2318 ret = cirrusfb_register(info);
2322 if (btype == BT_PICASSO4 || board_addr > 0x01000000)
2323 iounmap(info->screen_base);
2326 if (btype == BT_PICASSO4)
2327 iounmap(cinfo->regbase - 0x600000);
2329 release_region(board_addr, board_size);
2331 framebuffer_release(info);
2336 void __devexit cirrusfb_zorro_unregister(struct zorro_dev *z)
2338 struct fb_info *info = zorro_get_drvdata(z);
2340 cirrusfb_cleanup(info);
2343 static struct zorro_driver cirrusfb_zorro_driver = {
2345 .id_table = cirrusfb_zorro_table,
2346 .probe = cirrusfb_zorro_register,
2347 .remove = __devexit_p(cirrusfb_zorro_unregister),
2349 #endif /* CONFIG_ZORRO */
2352 static int __init cirrusfb_setup(char *options)
2356 if (!options || !*options)
2359 while ((this_opt = strsep(&options, ",")) != NULL) {
2363 if (!strcmp(this_opt, "noaccel"))
2365 else if (!strncmp(this_opt, "mode:", 5))
2366 mode_option = this_opt + 5;
2368 mode_option = this_opt;
2378 MODULE_AUTHOR("Copyright 1999,2000 Jeff Garzik <jgarzik@pobox.com>");
2379 MODULE_DESCRIPTION("Accelerated FBDev driver for Cirrus Logic chips");
2380 MODULE_LICENSE("GPL");
2382 static int __init cirrusfb_init(void)
2387 char *option = NULL;
2389 if (fb_get_options("cirrusfb", &option))
2391 cirrusfb_setup(option);
2395 error |= zorro_register_driver(&cirrusfb_zorro_driver);
2398 error |= pci_register_driver(&cirrusfb_pci_driver);
2403 static void __exit cirrusfb_exit(void)
2406 pci_unregister_driver(&cirrusfb_pci_driver);
2409 zorro_unregister_driver(&cirrusfb_zorro_driver);
2413 module_init(cirrusfb_init);
2415 module_param(mode_option, charp, 0);
2416 MODULE_PARM_DESC(mode_option, "Initial video mode e.g. '648x480-8@60'");
2417 module_param(noaccel, bool, 0);
2418 MODULE_PARM_DESC(noaccel, "Disable acceleration");
2421 module_exit(cirrusfb_exit);
2424 /**********************************************************************/
2425 /* about the following functions - I have used the same names for the */
2426 /* functions as Markus Wild did in his Retina driver for NetBSD as */
2427 /* they just made sense for this purpose. Apart from that, I wrote */
2428 /* these functions myself. */
2429 /**********************************************************************/
2431 /*** WGen() - write into one of the external/general registers ***/
2432 static void WGen(const struct cirrusfb_info *cinfo,
2433 int regnum, unsigned char val)
2435 unsigned long regofs = 0;
2437 if (cinfo->btype == BT_PICASSO) {
2438 /* Picasso II specific hack */
2439 /* if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D ||
2440 regnum == CL_VSSM2) */
2441 if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D)
2445 vga_w(cinfo->regbase, regofs + regnum, val);
2448 /*** RGen() - read out one of the external/general registers ***/
2449 static unsigned char RGen(const struct cirrusfb_info *cinfo, int regnum)
2451 unsigned long regofs = 0;
2453 if (cinfo->btype == BT_PICASSO) {
2454 /* Picasso II specific hack */
2455 /* if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D ||
2456 regnum == CL_VSSM2) */
2457 if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D)
2461 return vga_r(cinfo->regbase, regofs + regnum);
2464 /*** AttrOn() - turn on VideoEnable for Attribute controller ***/
2465 static void AttrOn(const struct cirrusfb_info *cinfo)
2467 assert(cinfo != NULL);
2469 if (vga_rcrt(cinfo->regbase, CL_CRT24) & 0x80) {
2470 /* if we're just in "write value" mode, write back the */
2471 /* same value as before to not modify anything */
2472 vga_w(cinfo->regbase, VGA_ATT_IW,
2473 vga_r(cinfo->regbase, VGA_ATT_R));
2475 /* turn on video bit */
2476 /* vga_w(cinfo->regbase, VGA_ATT_IW, 0x20); */
2477 vga_w(cinfo->regbase, VGA_ATT_IW, 0x33);
2479 /* dummy write on Reg0 to be on "write index" mode next time */
2480 vga_w(cinfo->regbase, VGA_ATT_IW, 0x00);
2483 /*** WHDR() - write into the Hidden DAC register ***/
2484 /* as the HDR is the only extension register that requires special treatment
2485 * (the other extension registers are accessible just like the "ordinary"
2486 * registers of their functional group) here is a specialized routine for
2489 static void WHDR(const struct cirrusfb_info *cinfo, unsigned char val)
2491 unsigned char dummy;
2493 if (is_laguna(cinfo))
2495 if (cinfo->btype == BT_PICASSO) {
2496 /* Klaus' hint for correct access to HDR on some boards */
2497 /* first write 0 to pixel mask (3c6) */
2498 WGen(cinfo, VGA_PEL_MSK, 0x00);
2500 /* next read dummy from pixel address (3c8) */
2501 dummy = RGen(cinfo, VGA_PEL_IW);
2504 /* now do the usual stuff to access the HDR */
2506 dummy = RGen(cinfo, VGA_PEL_MSK);
2508 dummy = RGen(cinfo, VGA_PEL_MSK);
2510 dummy = RGen(cinfo, VGA_PEL_MSK);
2512 dummy = RGen(cinfo, VGA_PEL_MSK);
2515 WGen(cinfo, VGA_PEL_MSK, val);
2518 if (cinfo->btype == BT_PICASSO) {
2519 /* now first reset HDR access counter */
2520 dummy = RGen(cinfo, VGA_PEL_IW);
2523 /* and at the end, restore the mask value */
2524 /* ## is this mask always 0xff? */
2525 WGen(cinfo, VGA_PEL_MSK, 0xff);
2530 /*** WSFR() - write to the "special function register" (SFR) ***/
2531 static void WSFR(struct cirrusfb_info *cinfo, unsigned char val)
2534 assert(cinfo->regbase != NULL);
2536 z_writeb(val, cinfo->regbase + 0x8000);
2540 /* The Picasso has a second register for switching the monitor bit */
2541 static void WSFR2(struct cirrusfb_info *cinfo, unsigned char val)
2544 /* writing an arbitrary value to this one causes the monitor switcher */
2545 /* to flip to Amiga display */
2546 assert(cinfo->regbase != NULL);
2548 z_writeb(val, cinfo->regbase + 0x9000);
2552 /*** WClut - set CLUT entry (range: 0..63) ***/
2553 static void WClut(struct cirrusfb_info *cinfo, unsigned char regnum, unsigned char red,
2554 unsigned char green, unsigned char blue)
2556 unsigned int data = VGA_PEL_D;
2558 /* address write mode register is not translated.. */
2559 vga_w(cinfo->regbase, VGA_PEL_IW, regnum);
2561 if (cinfo->btype == BT_PICASSO || cinfo->btype == BT_PICASSO4 ||
2562 cinfo->btype == BT_ALPINE || cinfo->btype == BT_GD5480 ||
2563 cinfo->btype == BT_SD64 || is_laguna(cinfo)) {
2564 /* but DAC data register IS, at least for Picasso II */
2565 if (cinfo->btype == BT_PICASSO)
2567 vga_w(cinfo->regbase, data, red);
2568 vga_w(cinfo->regbase, data, green);
2569 vga_w(cinfo->regbase, data, blue);
2571 vga_w(cinfo->regbase, data, blue);
2572 vga_w(cinfo->regbase, data, green);
2573 vga_w(cinfo->regbase, data, red);
2578 /*** RClut - read CLUT entry (range 0..63) ***/
2579 static void RClut(struct cirrusfb_info *cinfo, unsigned char regnum, unsigned char *red,
2580 unsigned char *green, unsigned char *blue)
2582 unsigned int data = VGA_PEL_D;
2584 vga_w(cinfo->regbase, VGA_PEL_IR, regnum);
2586 if (cinfo->btype == BT_PICASSO || cinfo->btype == BT_PICASSO4 ||
2587 cinfo->btype == BT_ALPINE || cinfo->btype == BT_GD5480) {
2588 if (cinfo->btype == BT_PICASSO)
2590 *red = vga_r(cinfo->regbase, data);
2591 *green = vga_r(cinfo->regbase, data);
2592 *blue = vga_r(cinfo->regbase, data);
2594 *blue = vga_r(cinfo->regbase, data);
2595 *green = vga_r(cinfo->regbase, data);
2596 *red = vga_r(cinfo->regbase, data);
2601 /*******************************************************************
2604 Wait for the BitBLT engine to complete a possible earlier job
2605 *********************************************************************/
2607 /* FIXME: use interrupts instead */
2608 static void cirrusfb_WaitBLT(u8 __iomem *regbase)
2610 while (vga_rgfx(regbase, CL_GR31) & 0x08)
2614 /*******************************************************************
2617 perform accelerated "scrolling"
2618 ********************************************************************/
2620 static void cirrusfb_set_blitter(u8 __iomem *regbase,
2621 u_short nwidth, u_short nheight,
2622 u_long nsrc, u_long ndest,
2623 u_short bltmode, u_short line_length)
2626 /* pitch: set to line_length */
2627 /* dest pitch low */
2628 vga_wgfx(regbase, CL_GR24, line_length & 0xff);
2630 vga_wgfx(regbase, CL_GR25, line_length >> 8);
2631 /* source pitch low */
2632 vga_wgfx(regbase, CL_GR26, line_length & 0xff);
2633 /* source pitch hi */
2634 vga_wgfx(regbase, CL_GR27, line_length >> 8);
2636 /* BLT width: actual number of pixels - 1 */
2638 vga_wgfx(regbase, CL_GR20, nwidth & 0xff);
2640 vga_wgfx(regbase, CL_GR21, nwidth >> 8);
2642 /* BLT height: actual number of lines -1 */
2643 /* BLT height low */
2644 vga_wgfx(regbase, CL_GR22, nheight & 0xff);
2646 vga_wgfx(regbase, CL_GR23, nheight >> 8);
2648 /* BLT destination */
2650 vga_wgfx(regbase, CL_GR28, (u_char) (ndest & 0xff));
2652 vga_wgfx(regbase, CL_GR29, (u_char) (ndest >> 8));
2654 vga_wgfx(regbase, CL_GR2A, (u_char) (ndest >> 16));
2658 vga_wgfx(regbase, CL_GR2C, (u_char) (nsrc & 0xff));
2660 vga_wgfx(regbase, CL_GR2D, (u_char) (nsrc >> 8));
2662 vga_wgfx(regbase, CL_GR2E, (u_char) (nsrc >> 16));
2665 vga_wgfx(regbase, CL_GR30, bltmode); /* BLT mode */
2667 /* BLT ROP: SrcCopy */
2668 vga_wgfx(regbase, CL_GR32, 0x0d); /* BLT ROP */
2670 /* and finally: GO! */
2671 vga_wgfx(regbase, CL_GR31, 0x02); /* BLT Start/status */
2674 /*******************************************************************
2677 perform accelerated "scrolling"
2678 ********************************************************************/
2680 static void cirrusfb_BitBLT(u8 __iomem *regbase, int bits_per_pixel,
2681 u_short curx, u_short cury,
2682 u_short destx, u_short desty,
2683 u_short width, u_short height,
2684 u_short line_length)
2686 u_short nwidth = width - 1;
2687 u_short nheight = height - 1;
2692 /* if source adr < dest addr, do the Blt backwards */
2693 if (cury <= desty) {
2694 if (cury == desty) {
2695 /* if src and dest are on the same line, check x */
2701 /* standard case: forward blitting */
2702 nsrc = (cury * line_length) + curx;
2703 ndest = (desty * line_length) + destx;
2705 /* this means start addresses are at the end,
2706 * counting backwards
2708 nsrc += nheight * line_length + nwidth;
2709 ndest += nheight * line_length + nwidth;
2712 cirrusfb_WaitBLT(regbase);
2714 cirrusfb_set_blitter(regbase, nwidth, nheight,
2715 nsrc, ndest, bltmode, line_length);
2718 /*******************************************************************
2721 perform accelerated rectangle fill
2722 ********************************************************************/
2724 static void cirrusfb_RectFill(u8 __iomem *regbase, int bits_per_pixel,
2725 u_short x, u_short y, u_short width, u_short height,
2726 u32 fg_color, u32 bg_color, u_short line_length,
2729 u_long ndest = (y * line_length) + x;
2732 cirrusfb_WaitBLT(regbase);
2734 /* This is a ColorExpand Blt, using the */
2735 /* same color for foreground and background */
2736 vga_wgfx(regbase, VGA_GFX_SR_VALUE, bg_color);
2737 vga_wgfx(regbase, VGA_GFX_SR_ENABLE, fg_color);
2740 if (bits_per_pixel >= 16) {
2741 vga_wgfx(regbase, CL_GR10, bg_color >> 8);
2742 vga_wgfx(regbase, CL_GR11, fg_color >> 8);
2745 if (bits_per_pixel >= 24) {
2746 vga_wgfx(regbase, CL_GR12, bg_color >> 16);
2747 vga_wgfx(regbase, CL_GR13, fg_color >> 16);
2750 if (bits_per_pixel == 32) {
2751 vga_wgfx(regbase, CL_GR14, bg_color >> 24);
2752 vga_wgfx(regbase, CL_GR15, fg_color >> 24);
2755 cirrusfb_set_blitter(regbase, width - 1, height - 1,
2756 0, ndest, op | blitmode, line_length);
2759 /**************************************************************************
2760 * bestclock() - determine closest possible clock lower(?) than the
2761 * desired pixel clock
2762 **************************************************************************/
2763 static void bestclock(long freq, int *nom, int *den, int *div)
2768 assert(nom != NULL);
2769 assert(den != NULL);
2770 assert(div != NULL);
2781 for (n = 32; n < 128; n++) {
2784 d = (14318 * n) / freq;
2785 if ((d >= 7) && (d <= 63)) {
2792 h = ((14318 * n) / temp) >> s;
2793 h = h > freq ? h - freq : freq - h;
2802 if ((d >= 7) && (d <= 63)) {
2807 h = ((14318 * n) / d) >> s;
2808 h = h > freq ? h - freq : freq - h;
2819 /* -------------------------------------------------------------------------
2821 * debugging functions
2823 * -------------------------------------------------------------------------
2826 #ifdef CIRRUSFB_DEBUG
2829 * cirrusfb_dbg_print_regs
2830 * @base: If using newmmio, the newmmio base address, otherwise %NULL
2831 * @reg_class: type of registers to read: %CRT, or %SEQ
2834 * Dumps the given list of VGA CRTC registers. If @base is %NULL,
2835 * old-style I/O ports are queried for information, otherwise MMIO is
2836 * used at the given @base address to query the information.
2839 static void cirrusfb_dbg_print_regs(struct fb_info *info,
2841 enum cirrusfb_dbg_reg_class reg_class, ...)
2844 unsigned char val = 0;
2848 va_start(list, reg_class);
2850 name = va_arg(list, char *);
2851 while (name != NULL) {
2852 reg = va_arg(list, int);
2854 switch (reg_class) {
2856 val = vga_rcrt(regbase, (unsigned char) reg);
2859 val = vga_rseq(regbase, (unsigned char) reg);
2862 /* should never occur */
2867 dev_dbg(info->device, "%8s = 0x%02X\n", name, val);
2869 name = va_arg(list, char *);
2876 * cirrusfb_dbg_reg_dump
2877 * @base: If using newmmio, the newmmio base address, otherwise %NULL
2880 * Dumps a list of interesting VGA and CIRRUSFB registers. If @base is %NULL,
2881 * old-style I/O ports are queried for information, otherwise MMIO is
2882 * used at the given @base address to query the information.
2885 static void cirrusfb_dbg_reg_dump(struct fb_info *info, caddr_t regbase)
2887 dev_dbg(info->device, "VGA CRTC register dump:\n");
2889 cirrusfb_dbg_print_regs(info, regbase, CRT,
2939 dev_dbg(info->device, "\n");
2941 dev_dbg(info->device, "VGA SEQ register dump:\n");
2943 cirrusfb_dbg_print_regs(info, regbase, SEQ,
2972 dev_dbg(info->device, "\n");
2975 #endif /* CIRRUSFB_DEBUG */