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
);
571 /* should never occur */
575 if (var
->xres_virtual
< var
->xres
)
576 var
->xres_virtual
= var
->xres
;
577 /* use highest possible virtual resolution */
578 if (var
->yres_virtual
== -1) {
579 var
->yres_virtual
= pixels
/ var
->xres_virtual
;
581 dev_info(info
->device
,
582 "virtual resolution set to maximum of %dx%d\n",
583 var
->xres_virtual
, var
->yres_virtual
);
585 if (var
->yres_virtual
< var
->yres
)
586 var
->yres_virtual
= var
->yres
;
588 if (var
->xres_virtual
* var
->yres_virtual
> pixels
) {
589 dev_err(info
->device
, "mode %dx%dx%d rejected... "
590 "virtual resolution too high to fit into video memory!\n",
591 var
->xres_virtual
, var
->yres_virtual
,
592 var
->bits_per_pixel
);
596 if (var
->xoffset
< 0)
598 if (var
->yoffset
< 0)
601 /* truncate xoffset and yoffset to maximum if too high */
602 if (var
->xoffset
> var
->xres_virtual
- var
->xres
)
603 var
->xoffset
= var
->xres_virtual
- var
->xres
- 1;
604 if (var
->yoffset
> var
->yres_virtual
- var
->yres
)
605 var
->yoffset
= var
->yres_virtual
- var
->yres
- 1;
608 var
->green
.msb_right
=
609 var
->blue
.msb_right
=
612 var
->transp
.msb_right
= 0;
615 if (var
->vmode
& FB_VMODE_DOUBLE
)
617 else if (var
->vmode
& FB_VMODE_INTERLACED
)
618 yres
= (yres
+ 1) / 2;
621 dev_err(info
->device
, "ERROR: VerticalTotal >= 1280; "
622 "special treatment required! (TODO)\n");
626 if (cirrusfb_check_pixclock(var
, info
))
629 if (!is_laguna(cinfo
))
630 var
->accel_flags
= FB_ACCELF_TEXT
;
635 static void cirrusfb_set_mclk_as_source(const struct fb_info
*info
, int div
)
637 struct cirrusfb_info
*cinfo
= info
->par
;
638 unsigned char old1f
, old1e
;
640 assert(cinfo
!= NULL
);
641 old1f
= vga_rseq(cinfo
->regbase
, CL_SEQR1F
) & ~0x40;
644 dev_dbg(info
->device
, "Set %s as pixclock source.\n",
645 (div
== 2) ? "MCLK/2" : "MCLK");
647 old1e
= vga_rseq(cinfo
->regbase
, CL_SEQR1E
) & ~0x1;
651 vga_wseq(cinfo
->regbase
, CL_SEQR1E
, old1e
);
653 vga_wseq(cinfo
->regbase
, CL_SEQR1F
, old1f
);
656 /*************************************************************************
657 cirrusfb_set_par_foo()
659 actually writes the values for a new video mode into the hardware,
660 **************************************************************************/
661 static int cirrusfb_set_par_foo(struct fb_info
*info
)
663 struct cirrusfb_info
*cinfo
= info
->par
;
664 struct fb_var_screeninfo
*var
= &info
->var
;
665 u8 __iomem
*regbase
= cinfo
->regbase
;
668 const struct cirrusfb_board_info_rec
*bi
;
669 int hdispend
, hsyncstart
, hsyncend
, htotal
;
670 int yres
, vdispend
, vsyncstart
, vsyncend
, vtotal
;
673 unsigned int control
= 0, format
= 0, threshold
= 0;
675 dev_dbg(info
->device
, "Requested mode: %dx%dx%d\n",
676 var
->xres
, var
->yres
, var
->bits_per_pixel
);
678 switch (var
->bits_per_pixel
) {
680 info
->fix
.line_length
= var
->xres_virtual
/ 8;
681 info
->fix
.visual
= FB_VISUAL_MONO10
;
685 info
->fix
.line_length
= var
->xres_virtual
;
686 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
691 info
->fix
.line_length
= var
->xres_virtual
*
692 var
->bits_per_pixel
>> 3;
693 info
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
696 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
700 bi
= &cirrusfb_board_info
[cinfo
->btype
];
702 hsyncstart
= var
->xres
+ var
->right_margin
;
703 hsyncend
= hsyncstart
+ var
->hsync_len
;
704 htotal
= (hsyncend
+ var
->left_margin
) / 8 - 5;
705 hdispend
= var
->xres
/ 8 - 1;
706 hsyncstart
= hsyncstart
/ 8 + 1;
707 hsyncend
= hsyncend
/ 8 + 1;
710 vsyncstart
= yres
+ var
->lower_margin
;
711 vsyncend
= vsyncstart
+ var
->vsync_len
;
712 vtotal
= vsyncend
+ var
->upper_margin
;
715 if (var
->vmode
& FB_VMODE_DOUBLE
) {
720 } else if (var
->vmode
& FB_VMODE_INTERLACED
) {
721 yres
= (yres
+ 1) / 2;
722 vsyncstart
= (vsyncstart
+ 1) / 2;
723 vsyncend
= (vsyncend
+ 1) / 2;
724 vtotal
= (vtotal
+ 1) / 2;
737 if (cinfo
->multiplexing
) {
743 /* unlock register VGA_CRTC_H_TOTAL..CRT7 */
744 vga_wcrt(regbase
, VGA_CRTC_V_SYNC_END
, 0x20); /* previously: 0x00) */
746 /* if debugging is enabled, all parameters get output before writing */
747 dev_dbg(info
->device
, "CRT0: %d\n", htotal
);
748 vga_wcrt(regbase
, VGA_CRTC_H_TOTAL
, htotal
);
750 dev_dbg(info
->device
, "CRT1: %d\n", hdispend
);
751 vga_wcrt(regbase
, VGA_CRTC_H_DISP
, hdispend
);
753 dev_dbg(info
->device
, "CRT2: %d\n", var
->xres
/ 8);
754 vga_wcrt(regbase
, VGA_CRTC_H_BLANK_START
, var
->xres
/ 8);
756 /* + 128: Compatible read */
757 dev_dbg(info
->device
, "CRT3: 128+%d\n", (htotal
+ 5) % 32);
758 vga_wcrt(regbase
, VGA_CRTC_H_BLANK_END
,
759 128 + ((htotal
+ 5) % 32));
761 dev_dbg(info
->device
, "CRT4: %d\n", hsyncstart
);
762 vga_wcrt(regbase
, VGA_CRTC_H_SYNC_START
, hsyncstart
);
765 if ((htotal
+ 5) & 32)
767 dev_dbg(info
->device
, "CRT5: %d\n", tmp
);
768 vga_wcrt(regbase
, VGA_CRTC_H_SYNC_END
, tmp
);
770 dev_dbg(info
->device
, "CRT6: %d\n", vtotal
& 0xff);
771 vga_wcrt(regbase
, VGA_CRTC_V_TOTAL
, vtotal
& 0xff);
773 tmp
= 16; /* LineCompare bit #9 */
778 if (vsyncstart
& 256)
780 if ((vdispend
+ 1) & 256)
786 if (vsyncstart
& 512)
788 dev_dbg(info
->device
, "CRT7: %d\n", tmp
);
789 vga_wcrt(regbase
, VGA_CRTC_OVERFLOW
, tmp
);
791 tmp
= 0x40; /* LineCompare bit #8 */
792 if ((vdispend
+ 1) & 512)
794 if (var
->vmode
& FB_VMODE_DOUBLE
)
796 dev_dbg(info
->device
, "CRT9: %d\n", tmp
);
797 vga_wcrt(regbase
, VGA_CRTC_MAX_SCAN
, tmp
);
799 dev_dbg(info
->device
, "CRT10: %d\n", vsyncstart
& 0xff);
800 vga_wcrt(regbase
, VGA_CRTC_V_SYNC_START
, vsyncstart
& 0xff);
802 dev_dbg(info
->device
, "CRT11: 64+32+%d\n", vsyncend
% 16);
803 vga_wcrt(regbase
, VGA_CRTC_V_SYNC_END
, vsyncend
% 16 + 64 + 32);
805 dev_dbg(info
->device
, "CRT12: %d\n", vdispend
& 0xff);
806 vga_wcrt(regbase
, VGA_CRTC_V_DISP_END
, vdispend
& 0xff);
808 dev_dbg(info
->device
, "CRT15: %d\n", (vdispend
+ 1) & 0xff);
809 vga_wcrt(regbase
, VGA_CRTC_V_BLANK_START
, (vdispend
+ 1) & 0xff);
811 dev_dbg(info
->device
, "CRT16: %d\n", vtotal
& 0xff);
812 vga_wcrt(regbase
, VGA_CRTC_V_BLANK_END
, vtotal
& 0xff);
814 dev_dbg(info
->device
, "CRT18: 0xff\n");
815 vga_wcrt(regbase
, VGA_CRTC_LINE_COMPARE
, 0xff);
818 if (var
->vmode
& FB_VMODE_INTERLACED
)
820 if ((htotal
+ 5) & 64)
822 if ((htotal
+ 5) & 128)
829 dev_dbg(info
->device
, "CRT1a: %d\n", tmp
);
830 vga_wcrt(regbase
, CL_CRT1A
, tmp
);
832 freq
= PICOS2KHZ(var
->pixclock
);
833 if (var
->bits_per_pixel
== 24)
834 if (cinfo
->btype
== BT_ALPINE
|| cinfo
->btype
== BT_SD64
)
836 if (cinfo
->multiplexing
)
838 if (cinfo
->doubleVCLK
)
841 bestclock(freq
, &nom
, &den
, &div
);
843 dev_dbg(info
->device
, "VCLK freq: %ld kHz nom: %d den: %d div: %d\n",
844 freq
, nom
, den
, div
);
847 /* hardware RefClock: 14.31818 MHz */
848 /* formula: VClk = (OSC * N) / (D * (1+P)) */
849 /* Example: VClk = (14.31818 * 91) / (23 * (1+1)) = 28.325 MHz */
851 if (cinfo
->btype
== BT_ALPINE
|| cinfo
->btype
== BT_PICASSO4
||
852 cinfo
->btype
== BT_SD64
) {
853 /* if freq is close to mclk or mclk/2 select mclk
856 int divMCLK
= cirrusfb_check_mclk(info
, freq
);
859 cirrusfb_set_mclk_as_source(info
, divMCLK
);
861 if (is_laguna(cinfo
)) {
862 long pcifc
= fb_readl(cinfo
->laguna_mmio
+ 0x3fc);
863 unsigned char tile
= fb_readb(cinfo
->laguna_mmio
+ 0x407);
864 unsigned short tile_control
;
866 if (cinfo
->btype
== BT_LAGUNAB
) {
867 tile_control
= fb_readw(cinfo
->laguna_mmio
+ 0x2c4);
868 tile_control
&= ~0x80;
869 fb_writew(tile_control
, cinfo
->laguna_mmio
+ 0x2c4);
872 fb_writel(pcifc
| 0x10000000l
, cinfo
->laguna_mmio
+ 0x3fc);
873 fb_writeb(tile
& 0x3f, cinfo
->laguna_mmio
+ 0x407);
874 control
= fb_readw(cinfo
->laguna_mmio
+ 0x402);
875 threshold
= fb_readw(cinfo
->laguna_mmio
+ 0xea);
878 threshold
&= 0xffc0 & 0x3fbf;
884 /* 6 bit denom; ONLY 5434!!! (bugged me 10 days) */
885 if ((cinfo
->btype
== BT_SD64
) ||
886 (cinfo
->btype
== BT_ALPINE
) ||
887 (cinfo
->btype
== BT_GD5480
))
890 /* Laguna chipset has reversed clock registers */
891 if (is_laguna(cinfo
)) {
892 vga_wseq(regbase
, CL_SEQRE
, tmp
);
893 vga_wseq(regbase
, CL_SEQR1E
, nom
);
895 vga_wseq(regbase
, CL_SEQRE
, nom
);
896 vga_wseq(regbase
, CL_SEQR1E
, tmp
);
902 vga_wcrt(regbase
, VGA_CRTC_MODE
, 0xc7);
904 /* mode control: VGA_CRTC_START_HI enable, ROTATE(?), 16bit
905 * address wrap, no compat. */
906 vga_wcrt(regbase
, VGA_CRTC_MODE
, 0xc3);
908 /* don't know if it would hurt to also program this if no interlaced */
909 /* mode is used, but I feel better this way.. :-) */
910 if (var
->vmode
& FB_VMODE_INTERLACED
)
911 vga_wcrt(regbase
, VGA_CRTC_REGS
, htotal
/ 2);
913 vga_wcrt(regbase
, VGA_CRTC_REGS
, 0x00); /* interlace control */
915 /* adjust horizontal/vertical sync type (low/high), use VCLK3 */
916 /* enable display memory & CRTC I/O address for color mode */
918 if (var
->sync
& FB_SYNC_HOR_HIGH_ACT
)
920 if (var
->sync
& FB_SYNC_VERT_HIGH_ACT
)
922 WGen(cinfo
, VGA_MIS_W
, tmp
);
924 /* text cursor on and start line */
925 vga_wcrt(regbase
, VGA_CRTC_CURSOR_START
, 0);
926 /* text cursor end line */
927 vga_wcrt(regbase
, VGA_CRTC_CURSOR_END
, 31);
929 /******************************************************
935 /* programming for different color depths */
936 if (var
->bits_per_pixel
== 1) {
937 dev_dbg(info
->device
, "preparing for 1 bit deep display\n");
938 vga_wgfx(regbase
, VGA_GFX_MODE
, 0); /* mode register */
941 switch (cinfo
->btype
) {
949 vga_wseq(regbase
, CL_SEQR7
,
950 cinfo
->multiplexing
?
951 bi
->sr07_1bpp_mux
: bi
->sr07_1bpp
);
956 vga_wseq(regbase
, CL_SEQR7
,
957 vga_rseq(regbase
, CL_SEQR7
) & ~0x01);
961 dev_warn(info
->device
, "unknown Board\n");
965 /* Extended Sequencer Mode */
966 switch (cinfo
->btype
) {
970 /* evtl d0 bei 1 bit? avoid FIFO underruns..? */
971 vga_wseq(regbase
, CL_SEQRF
, 0xb0);
975 /* ## vorher d0 avoid FIFO underruns..? */
976 vga_wseq(regbase
, CL_SEQRF
, 0xd0);
989 dev_warn(info
->device
, "unknown Board\n");
993 /* pixel mask: pass-through for first plane */
994 WGen(cinfo
, VGA_PEL_MSK
, 0x01);
995 if (cinfo
->multiplexing
)
996 /* hidden dac reg: 1280x1024 */
999 /* hidden dac: nothing */
1001 /* memory mode: odd/even, ext. memory */
1002 vga_wseq(regbase
, VGA_SEQ_MEMORY_MODE
, 0x06);
1003 /* plane mask: only write to first plane */
1004 vga_wseq(regbase
, VGA_SEQ_PLANE_WRITE
, 0x01);
1007 /******************************************************
1013 else if (var
->bits_per_pixel
== 8) {
1014 dev_dbg(info
->device
, "preparing for 8 bit deep display\n");
1015 switch (cinfo
->btype
) {
1023 vga_wseq(regbase
, CL_SEQR7
,
1024 cinfo
->multiplexing
?
1025 bi
->sr07_8bpp_mux
: bi
->sr07_8bpp
);
1030 vga_wseq(regbase
, CL_SEQR7
,
1031 vga_rseq(regbase
, CL_SEQR7
) | 0x01);
1036 dev_warn(info
->device
, "unknown Board\n");
1040 switch (cinfo
->btype
) {
1044 /* Fast Page-Mode writes */
1045 vga_wseq(regbase
, CL_SEQRF
, 0xb0);
1050 /* ### INCOMPLETE!! */
1051 vga_wseq(regbase
, CL_SEQRF
, 0xb8);
1062 dev_warn(info
->device
, "unknown board\n");
1066 /* mode register: 256 color mode */
1067 vga_wgfx(regbase
, VGA_GFX_MODE
, 64);
1068 if (cinfo
->multiplexing
)
1069 /* hidden dac reg: 1280x1024 */
1072 /* hidden dac: nothing */
1076 /******************************************************
1082 else if (var
->bits_per_pixel
== 16) {
1083 dev_dbg(info
->device
, "preparing for 16 bit deep display\n");
1084 switch (cinfo
->btype
) {
1087 vga_wseq(regbase
, CL_SEQR7
, 0x87);
1088 /* Fast Page-Mode writes */
1089 vga_wseq(regbase
, CL_SEQRF
, 0xb0);
1093 vga_wseq(regbase
, CL_SEQR7
, 0x27);
1094 /* Fast Page-Mode writes */
1095 vga_wseq(regbase
, CL_SEQRF
, 0xb0);
1101 /* Extended Sequencer Mode: 256c col. mode */
1102 vga_wseq(regbase
, CL_SEQR7
,
1103 cinfo
->doubleVCLK
? 0xa3 : 0xa7);
1107 vga_wseq(regbase
, CL_SEQR7
, 0x17);
1108 /* We already set SRF and SR1F */
1113 vga_wseq(regbase
, CL_SEQR7
,
1114 vga_rseq(regbase
, CL_SEQR7
) & ~0x01);
1121 dev_warn(info
->device
, "unknown Board\n");
1125 /* mode register: 256 color mode */
1126 vga_wgfx(regbase
, VGA_GFX_MODE
, 64);
1128 WHDR(cinfo
, cinfo
->doubleVCLK
? 0xe1 : 0xc1);
1129 #elif defined(CONFIG_ZORRO)
1130 /* FIXME: CONFIG_PCI and CONFIG_ZORRO may be defined both */
1131 WHDR(cinfo
, 0xa0); /* hidden dac reg: nothing special */
1135 /******************************************************
1141 else if (var
->bits_per_pixel
== 24) {
1142 dev_dbg(info
->device
, "preparing for 24 bit deep display\n");
1143 switch (cinfo
->btype
) {
1146 vga_wseq(regbase
, CL_SEQR7
, 0x85);
1147 /* Fast Page-Mode writes */
1148 vga_wseq(regbase
, CL_SEQRF
, 0xb0);
1152 vga_wseq(regbase
, CL_SEQR7
, 0x25);
1153 /* Fast Page-Mode writes */
1154 vga_wseq(regbase
, CL_SEQRF
, 0xb0);
1160 /* Extended Sequencer Mode: 256c col. mode */
1161 vga_wseq(regbase
, CL_SEQR7
, 0xa5);
1165 vga_wseq(regbase
, CL_SEQR7
, 0x15);
1166 /* We already set SRF and SR1F */
1171 vga_wseq(regbase
, CL_SEQR7
,
1172 vga_rseq(regbase
, CL_SEQR7
) & ~0x01);
1179 dev_warn(info
->device
, "unknown Board\n");
1183 /* mode register: 256 color mode */
1184 vga_wgfx(regbase
, VGA_GFX_MODE
, 64);
1185 /* hidden dac reg: 8-8-8 mode (24 or 32) */
1189 /******************************************************
1191 * unknown/unsupported bpp
1196 dev_err(info
->device
,
1197 "What's this? requested color depth == %d.\n",
1198 var
->bits_per_pixel
);
1200 pitch
= info
->fix
.line_length
>> 3;
1201 vga_wcrt(regbase
, VGA_CRTC_OFFSET
, pitch
& 0xff);
1204 tmp
|= 0x10; /* offset overflow bit */
1206 /* screen start addr #16-18, fastpagemode cycles */
1207 vga_wcrt(regbase
, CL_CRT1B
, tmp
);
1209 /* screen start address bit 19 */
1210 if (cirrusfb_board_info
[cinfo
->btype
].scrn_start_bit19
)
1211 vga_wcrt(regbase
, CL_CRT1D
, (pitch
>> 9) & 1);
1213 if (is_laguna(cinfo
)) {
1215 if ((htotal
+ 5) & 256)
1219 if (hsyncstart
& 256)
1223 if (vdispend
& 1024)
1225 if (vsyncstart
& 1024)
1228 vga_wcrt(regbase
, CL_CRT1E
, tmp
);
1229 dev_dbg(info
->device
, "CRT1e: %d\n", tmp
);
1233 vga_wattr(regbase
, CL_AR33
, 0);
1235 /* [ EGS: SetOffset(); ] */
1236 /* From SetOffset(): Turn on VideoEnable bit in Attribute controller */
1239 if (is_laguna(cinfo
)) {
1241 fb_writew(control
| 0x1000, cinfo
->laguna_mmio
+ 0x402);
1242 fb_writew(format
, cinfo
->laguna_mmio
+ 0xc0);
1243 fb_writew(threshold
, cinfo
->laguna_mmio
+ 0xea);
1245 /* finally, turn on everything - turn off "FullBandwidth" bit */
1246 /* also, set "DotClock%2" bit where requested */
1249 /*** FB_VMODE_CLOCK_HALVE in linux/fb.h not defined anymore ?
1250 if (var->vmode & FB_VMODE_CLOCK_HALVE)
1254 vga_wseq(regbase
, VGA_SEQ_CLOCK_MODE
, tmp
);
1255 dev_dbg(info
->device
, "CL_SEQR1: %d\n", tmp
);
1257 #ifdef CIRRUSFB_DEBUG
1258 cirrusfb_dbg_reg_dump(info
, NULL
);
1264 /* for some reason incomprehensible to me, cirrusfb requires that you write
1265 * the registers twice for the settings to take..grr. -dte */
1266 static int cirrusfb_set_par(struct fb_info
*info
)
1268 cirrusfb_set_par_foo(info
);
1269 return cirrusfb_set_par_foo(info
);
1272 static int cirrusfb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
1273 unsigned blue
, unsigned transp
,
1274 struct fb_info
*info
)
1276 struct cirrusfb_info
*cinfo
= info
->par
;
1281 if (info
->fix
.visual
== FB_VISUAL_TRUECOLOR
) {
1283 red
>>= (16 - info
->var
.red
.length
);
1284 green
>>= (16 - info
->var
.green
.length
);
1285 blue
>>= (16 - info
->var
.blue
.length
);
1289 v
= (red
<< info
->var
.red
.offset
) |
1290 (green
<< info
->var
.green
.offset
) |
1291 (blue
<< info
->var
.blue
.offset
);
1293 cinfo
->pseudo_palette
[regno
] = v
;
1297 if (info
->var
.bits_per_pixel
== 8)
1298 WClut(cinfo
, regno
, red
>> 10, green
>> 10, blue
>> 10);
1304 /*************************************************************************
1305 cirrusfb_pan_display()
1307 performs display panning - provided hardware permits this
1308 **************************************************************************/
1309 static int cirrusfb_pan_display(struct fb_var_screeninfo
*var
,
1310 struct fb_info
*info
)
1314 unsigned char tmp
, xpix
;
1315 struct cirrusfb_info
*cinfo
= info
->par
;
1317 /* no range checks for xoffset and yoffset, */
1318 /* as fb_pan_display has already done this */
1319 if (var
->vmode
& FB_VMODE_YWRAP
)
1322 xoffset
= var
->xoffset
* info
->var
.bits_per_pixel
/ 8;
1324 base
= var
->yoffset
* info
->fix
.line_length
+ xoffset
;
1326 if (info
->var
.bits_per_pixel
== 1) {
1327 /* base is already correct */
1328 xpix
= (unsigned char) (var
->xoffset
% 8);
1331 xpix
= (unsigned char) ((xoffset
% 4) * 2);
1334 if (!is_laguna(cinfo
))
1335 cirrusfb_WaitBLT(cinfo
->regbase
);
1337 /* lower 8 + 8 bits of screen start address */
1338 vga_wcrt(cinfo
->regbase
, VGA_CRTC_START_LO
, base
& 0xff);
1339 vga_wcrt(cinfo
->regbase
, VGA_CRTC_START_HI
, (base
>> 8) & 0xff);
1341 /* 0xf2 is %11110010, exclude tmp bits */
1342 tmp
= vga_rcrt(cinfo
->regbase
, CL_CRT1B
) & 0xf2;
1343 /* construct bits 16, 17 and 18 of screen start address */
1351 vga_wcrt(cinfo
->regbase
, CL_CRT1B
, tmp
);
1353 /* construct bit 19 of screen start address */
1354 if (cirrusfb_board_info
[cinfo
->btype
].scrn_start_bit19
) {
1355 tmp
= vga_rcrt(cinfo
->regbase
, CL_CRT1D
);
1356 if (is_laguna(cinfo
))
1357 tmp
= (tmp
& ~0x18) | ((base
>> 16) & 0x18);
1359 tmp
= (tmp
& ~0x80) | ((base
>> 12) & 0x80);
1360 vga_wcrt(cinfo
->regbase
, CL_CRT1D
, tmp
);
1363 /* write pixel panning value to AR33; this does not quite work in 8bpp
1365 * ### Piccolo..? Will this work?
1367 if (info
->var
.bits_per_pixel
== 1)
1368 vga_wattr(cinfo
->regbase
, CL_AR33
, xpix
);
1373 static int cirrusfb_blank(int blank_mode
, struct fb_info
*info
)
1376 * Blank the screen if blank_mode != 0, else unblank. If blank == NULL
1377 * then the caller blanks by setting the CLUT (Color Look Up Table)
1378 * to all black. Return 0 if blanking succeeded, != 0 if un-/blanking
1379 * failed due to e.g. a video mode which doesn't support it.
1380 * Implements VESA suspend and powerdown modes on hardware that
1381 * supports disabling hsync/vsync:
1382 * blank_mode == 2: suspend vsync
1383 * blank_mode == 3: suspend hsync
1384 * blank_mode == 4: powerdown
1387 struct cirrusfb_info
*cinfo
= info
->par
;
1388 int current_mode
= cinfo
->blank_mode
;
1390 dev_dbg(info
->device
, "ENTER, blank mode = %d\n", blank_mode
);
1392 if (info
->state
!= FBINFO_STATE_RUNNING
||
1393 current_mode
== blank_mode
) {
1394 dev_dbg(info
->device
, "EXIT, returning 0\n");
1399 if (current_mode
== FB_BLANK_NORMAL
||
1400 current_mode
== FB_BLANK_UNBLANK
)
1401 /* clear "FullBandwidth" bit */
1404 /* set "FullBandwidth" bit */
1407 val
|= vga_rseq(cinfo
->regbase
, VGA_SEQ_CLOCK_MODE
) & 0xdf;
1408 vga_wseq(cinfo
->regbase
, VGA_SEQ_CLOCK_MODE
, val
);
1410 switch (blank_mode
) {
1411 case FB_BLANK_UNBLANK
:
1412 case FB_BLANK_NORMAL
:
1415 case FB_BLANK_VSYNC_SUSPEND
:
1418 case FB_BLANK_HSYNC_SUSPEND
:
1421 case FB_BLANK_POWERDOWN
:
1425 dev_dbg(info
->device
, "EXIT, returning 1\n");
1429 vga_wgfx(cinfo
->regbase
, CL_GRE
, val
);
1431 cinfo
->blank_mode
= blank_mode
;
1432 dev_dbg(info
->device
, "EXIT, returning 0\n");
1434 /* Let fbcon do a soft blank for us */
1435 return (blank_mode
== FB_BLANK_NORMAL
) ? 1 : 0;
1438 /**** END Hardware specific Routines **************************************/
1439 /****************************************************************************/
1440 /**** BEGIN Internal Routines ***********************************************/
1442 static void init_vgachip(struct fb_info
*info
)
1444 struct cirrusfb_info
*cinfo
= info
->par
;
1445 const struct cirrusfb_board_info_rec
*bi
;
1447 assert(cinfo
!= NULL
);
1449 bi
= &cirrusfb_board_info
[cinfo
->btype
];
1451 /* reset board globally */
1452 switch (cinfo
->btype
) {
1471 /* disable flickerfixer */
1472 vga_wcrt(cinfo
->regbase
, CL_CRT51
, 0x00);
1475 vga_wgfx(cinfo
->regbase
, CL_GR31
, 0x00);
1476 case BT_GD5480
: /* fall through */
1477 /* from Klaus' NetBSD driver: */
1478 vga_wgfx(cinfo
->regbase
, CL_GR2F
, 0x00);
1479 case BT_ALPINE
: /* fall through */
1480 /* put blitter into 542x compat */
1481 vga_wgfx(cinfo
->regbase
, CL_GR33
, 0x00);
1486 /* Nothing to do to reset the board. */
1490 dev_err(info
->device
, "Warning: Unknown board type\n");
1494 /* make sure RAM size set by this point */
1495 assert(info
->screen_size
> 0);
1497 /* the P4 is not fully initialized here; I rely on it having been */
1498 /* inited under AmigaOS already, which seems to work just fine */
1499 /* (Klaus advised to do it this way) */
1501 if (cinfo
->btype
!= BT_PICASSO4
) {
1502 WGen(cinfo
, CL_VSSM
, 0x10); /* EGS: 0x16 */
1503 WGen(cinfo
, CL_POS102
, 0x01);
1504 WGen(cinfo
, CL_VSSM
, 0x08); /* EGS: 0x0e */
1506 if (cinfo
->btype
!= BT_SD64
)
1507 WGen(cinfo
, CL_VSSM2
, 0x01);
1509 /* reset sequencer logic */
1510 vga_wseq(cinfo
->regbase
, VGA_SEQ_RESET
, 0x03);
1512 /* FullBandwidth (video off) and 8/9 dot clock */
1513 vga_wseq(cinfo
->regbase
, VGA_SEQ_CLOCK_MODE
, 0x21);
1515 /* "magic cookie" - doesn't make any sense to me.. */
1516 /* vga_wgfx(cinfo->regbase, CL_GRA, 0xce); */
1517 /* unlock all extension registers */
1518 vga_wseq(cinfo
->regbase
, CL_SEQR6
, 0x12);
1520 switch (cinfo
->btype
) {
1522 vga_wseq(cinfo
->regbase
, CL_SEQRF
, 0x98);
1530 vga_wseq(cinfo
->regbase
, CL_SEQRF
, 0xb8);
1534 vga_wseq(cinfo
->regbase
, CL_SEQR16
, 0x0f);
1535 vga_wseq(cinfo
->regbase
, CL_SEQRF
, 0xb0);
1539 /* plane mask: nothing */
1540 vga_wseq(cinfo
->regbase
, VGA_SEQ_PLANE_WRITE
, 0xff);
1541 /* character map select: doesn't even matter in gx mode */
1542 vga_wseq(cinfo
->regbase
, VGA_SEQ_CHARACTER_MAP
, 0x00);
1543 /* memory mode: chain4, ext. memory */
1544 vga_wseq(cinfo
->regbase
, VGA_SEQ_MEMORY_MODE
, 0x0a);
1546 /* controller-internal base address of video memory */
1548 vga_wseq(cinfo
->regbase
, CL_SEQR7
, bi
->sr07
);
1550 /* vga_wseq(cinfo->regbase, CL_SEQR8, 0x00); */
1551 /* EEPROM control: shouldn't be necessary to write to this at all.. */
1553 /* graphics cursor X position (incomplete; position gives rem. 3 bits */
1554 vga_wseq(cinfo
->regbase
, CL_SEQR10
, 0x00);
1555 /* graphics cursor Y position (..."... ) */
1556 vga_wseq(cinfo
->regbase
, CL_SEQR11
, 0x00);
1557 /* graphics cursor attributes */
1558 vga_wseq(cinfo
->regbase
, CL_SEQR12
, 0x00);
1559 /* graphics cursor pattern address */
1560 vga_wseq(cinfo
->regbase
, CL_SEQR13
, 0x00);
1562 /* writing these on a P4 might give problems.. */
1563 if (cinfo
->btype
!= BT_PICASSO4
) {
1564 /* configuration readback and ext. color */
1565 vga_wseq(cinfo
->regbase
, CL_SEQR17
, 0x00);
1566 /* signature generator */
1567 vga_wseq(cinfo
->regbase
, CL_SEQR18
, 0x02);
1570 /* Screen A preset row scan: none */
1571 vga_wcrt(cinfo
->regbase
, VGA_CRTC_PRESET_ROW
, 0x00);
1572 /* Text cursor start: disable text cursor */
1573 vga_wcrt(cinfo
->regbase
, VGA_CRTC_CURSOR_START
, 0x20);
1574 /* Text cursor end: - */
1575 vga_wcrt(cinfo
->regbase
, VGA_CRTC_CURSOR_END
, 0x00);
1576 /* text cursor location high: 0 */
1577 vga_wcrt(cinfo
->regbase
, VGA_CRTC_CURSOR_HI
, 0x00);
1578 /* text cursor location low: 0 */
1579 vga_wcrt(cinfo
->regbase
, VGA_CRTC_CURSOR_LO
, 0x00);
1581 /* Underline Row scanline: - */
1582 vga_wcrt(cinfo
->regbase
, VGA_CRTC_UNDERLINE
, 0x00);
1583 /* ### add 0x40 for text modes with > 30 MHz pixclock */
1584 /* ext. display controls: ext.adr. wrap */
1585 vga_wcrt(cinfo
->regbase
, CL_CRT1B
, 0x02);
1587 /* Set/Reset registes: - */
1588 vga_wgfx(cinfo
->regbase
, VGA_GFX_SR_VALUE
, 0x00);
1589 /* Set/Reset enable: - */
1590 vga_wgfx(cinfo
->regbase
, VGA_GFX_SR_ENABLE
, 0x00);
1591 /* Color Compare: - */
1592 vga_wgfx(cinfo
->regbase
, VGA_GFX_COMPARE_VALUE
, 0x00);
1593 /* Data Rotate: - */
1594 vga_wgfx(cinfo
->regbase
, VGA_GFX_DATA_ROTATE
, 0x00);
1595 /* Read Map Select: - */
1596 vga_wgfx(cinfo
->regbase
, VGA_GFX_PLANE_READ
, 0x00);
1597 /* Mode: conf. for 16/4/2 color mode, no odd/even, read/write mode 0 */
1598 vga_wgfx(cinfo
->regbase
, VGA_GFX_MODE
, 0x00);
1599 /* Miscellaneous: memory map base address, graphics mode */
1600 vga_wgfx(cinfo
->regbase
, VGA_GFX_MISC
, 0x01);
1601 /* Color Don't care: involve all planes */
1602 vga_wgfx(cinfo
->regbase
, VGA_GFX_COMPARE_MASK
, 0x0f);
1603 /* Bit Mask: no mask at all */
1604 vga_wgfx(cinfo
->regbase
, VGA_GFX_BIT_MASK
, 0xff);
1606 if (cinfo
->btype
== BT_ALPINE
|| cinfo
->btype
== BT_SD64
||
1608 /* (5434 can't have bit 3 set for bitblt) */
1609 vga_wgfx(cinfo
->regbase
, CL_GRB
, 0x20);
1611 /* Graphics controller mode extensions: finer granularity,
1612 * 8byte data latches
1614 vga_wgfx(cinfo
->regbase
, CL_GRB
, 0x28);
1616 vga_wgfx(cinfo
->regbase
, CL_GRC
, 0xff); /* Color Key compare: - */
1617 vga_wgfx(cinfo
->regbase
, CL_GRD
, 0x00); /* Color Key compare mask: - */
1618 vga_wgfx(cinfo
->regbase
, CL_GRE
, 0x00); /* Miscellaneous control: - */
1619 /* Background color byte 1: - */
1620 /* vga_wgfx (cinfo->regbase, CL_GR10, 0x00); */
1621 /* vga_wgfx (cinfo->regbase, CL_GR11, 0x00); */
1623 /* Attribute Controller palette registers: "identity mapping" */
1624 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTE0
, 0x00);
1625 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTE1
, 0x01);
1626 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTE2
, 0x02);
1627 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTE3
, 0x03);
1628 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTE4
, 0x04);
1629 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTE5
, 0x05);
1630 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTE6
, 0x06);
1631 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTE7
, 0x07);
1632 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTE8
, 0x08);
1633 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTE9
, 0x09);
1634 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTEA
, 0x0a);
1635 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTEB
, 0x0b);
1636 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTEC
, 0x0c);
1637 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTED
, 0x0d);
1638 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTEE
, 0x0e);
1639 vga_wattr(cinfo
->regbase
, VGA_ATC_PALETTEF
, 0x0f);
1641 /* Attribute Controller mode: graphics mode */
1642 vga_wattr(cinfo
->regbase
, VGA_ATC_MODE
, 0x01);
1643 /* Overscan color reg.: reg. 0 */
1644 vga_wattr(cinfo
->regbase
, VGA_ATC_OVERSCAN
, 0x00);
1645 /* Color Plane enable: Enable all 4 planes */
1646 vga_wattr(cinfo
->regbase
, VGA_ATC_PLANE_ENABLE
, 0x0f);
1647 /* Color Select: - */
1648 vga_wattr(cinfo
->regbase
, VGA_ATC_COLOR_PAGE
, 0x00);
1650 WGen(cinfo
, VGA_PEL_MSK
, 0xff); /* Pixel mask: no mask */
1652 /* BLT Start/status: Blitter reset */
1653 vga_wgfx(cinfo
->regbase
, CL_GR31
, 0x04);
1654 /* - " - : "end-of-reset" */
1655 vga_wgfx(cinfo
->regbase
, CL_GR31
, 0x00);
1658 WHDR(cinfo
, 0); /* Hidden DAC register: - */
1662 static void switch_monitor(struct cirrusfb_info
*cinfo
, int on
)
1664 #ifdef CONFIG_ZORRO /* only works on Zorro boards */
1665 static int IsOn
= 0; /* XXX not ok for multiple boards */
1667 if (cinfo
->btype
== BT_PICASSO4
)
1668 return; /* nothing to switch */
1669 if (cinfo
->btype
== BT_ALPINE
)
1670 return; /* nothing to switch */
1671 if (cinfo
->btype
== BT_GD5480
)
1672 return; /* nothing to switch */
1673 if (cinfo
->btype
== BT_PICASSO
) {
1674 if ((on
&& !IsOn
) || (!on
&& IsOn
))
1679 switch (cinfo
->btype
) {
1681 WSFR(cinfo
, cinfo
->SFR
| 0x21);
1684 WSFR(cinfo
, cinfo
->SFR
| 0x28);
1689 default: /* do nothing */ break;
1692 switch (cinfo
->btype
) {
1694 WSFR(cinfo
, cinfo
->SFR
& 0xde);
1697 WSFR(cinfo
, cinfo
->SFR
& 0xd7);
1702 default: /* do nothing */
1706 #endif /* CONFIG_ZORRO */
1709 /******************************************/
1710 /* Linux 2.6-style accelerated functions */
1711 /******************************************/
1713 static int cirrusfb_sync(struct fb_info
*info
)
1715 struct cirrusfb_info
*cinfo
= info
->par
;
1717 if (!is_laguna(cinfo
)) {
1718 while (vga_rgfx(cinfo
->regbase
, CL_GR31
) & 0x03)
1724 static void cirrusfb_fillrect(struct fb_info
*info
,
1725 const struct fb_fillrect
*region
)
1727 struct fb_fillrect modded
;
1729 struct cirrusfb_info
*cinfo
= info
->par
;
1730 int m
= info
->var
.bits_per_pixel
;
1731 u32 color
= (info
->fix
.visual
== FB_VISUAL_TRUECOLOR
) ?
1732 cinfo
->pseudo_palette
[region
->color
] : region
->color
;
1734 if (info
->state
!= FBINFO_STATE_RUNNING
)
1736 if (info
->flags
& FBINFO_HWACCEL_DISABLED
) {
1737 cfb_fillrect(info
, region
);
1741 vxres
= info
->var
.xres_virtual
;
1742 vyres
= info
->var
.yres_virtual
;
1744 memcpy(&modded
, region
, sizeof(struct fb_fillrect
));
1746 if (!modded
.width
|| !modded
.height
||
1747 modded
.dx
>= vxres
|| modded
.dy
>= vyres
)
1750 if (modded
.dx
+ modded
.width
> vxres
)
1751 modded
.width
= vxres
- modded
.dx
;
1752 if (modded
.dy
+ modded
.height
> vyres
)
1753 modded
.height
= vyres
- modded
.dy
;
1755 cirrusfb_RectFill(cinfo
->regbase
,
1756 info
->var
.bits_per_pixel
,
1757 (region
->dx
* m
) / 8, region
->dy
,
1758 (region
->width
* m
) / 8, region
->height
,
1760 info
->fix
.line_length
, 0x40);
1763 static void cirrusfb_copyarea(struct fb_info
*info
,
1764 const struct fb_copyarea
*area
)
1766 struct fb_copyarea modded
;
1768 struct cirrusfb_info
*cinfo
= info
->par
;
1769 int m
= info
->var
.bits_per_pixel
;
1771 if (info
->state
!= FBINFO_STATE_RUNNING
)
1773 if (info
->flags
& FBINFO_HWACCEL_DISABLED
) {
1774 cfb_copyarea(info
, area
);
1778 vxres
= info
->var
.xres_virtual
;
1779 vyres
= info
->var
.yres_virtual
;
1780 memcpy(&modded
, area
, sizeof(struct fb_copyarea
));
1782 if (!modded
.width
|| !modded
.height
||
1783 modded
.sx
>= vxres
|| modded
.sy
>= vyres
||
1784 modded
.dx
>= vxres
|| modded
.dy
>= vyres
)
1787 if (modded
.sx
+ modded
.width
> vxres
)
1788 modded
.width
= vxres
- modded
.sx
;
1789 if (modded
.dx
+ modded
.width
> vxres
)
1790 modded
.width
= vxres
- modded
.dx
;
1791 if (modded
.sy
+ modded
.height
> vyres
)
1792 modded
.height
= vyres
- modded
.sy
;
1793 if (modded
.dy
+ modded
.height
> vyres
)
1794 modded
.height
= vyres
- modded
.dy
;
1796 cirrusfb_BitBLT(cinfo
->regbase
, info
->var
.bits_per_pixel
,
1797 (area
->sx
* m
) / 8, area
->sy
,
1798 (area
->dx
* m
) / 8, area
->dy
,
1799 (area
->width
* m
) / 8, area
->height
,
1800 info
->fix
.line_length
);
1804 static void cirrusfb_imageblit(struct fb_info
*info
,
1805 const struct fb_image
*image
)
1807 struct cirrusfb_info
*cinfo
= info
->par
;
1808 unsigned char op
= (info
->var
.bits_per_pixel
== 24) ? 0xc : 0x4;
1810 if (info
->state
!= FBINFO_STATE_RUNNING
)
1812 /* Alpine/SD64 does not work at 24bpp ??? */
1813 if (info
->flags
& FBINFO_HWACCEL_DISABLED
|| image
->depth
!= 1)
1814 cfb_imageblit(info
, image
);
1815 else if ((cinfo
->btype
== BT_ALPINE
|| cinfo
->btype
== BT_SD64
) &&
1817 cfb_imageblit(info
, image
);
1819 unsigned size
= ((image
->width
+ 7) >> 3) * image
->height
;
1820 int m
= info
->var
.bits_per_pixel
;
1823 if (info
->var
.bits_per_pixel
== 8) {
1824 fg
= image
->fg_color
;
1825 bg
= image
->bg_color
;
1827 fg
= ((u32
*)(info
->pseudo_palette
))[image
->fg_color
];
1828 bg
= ((u32
*)(info
->pseudo_palette
))[image
->bg_color
];
1830 if (info
->var
.bits_per_pixel
== 24) {
1831 /* clear background first */
1832 cirrusfb_RectFill(cinfo
->regbase
,
1833 info
->var
.bits_per_pixel
,
1834 (image
->dx
* m
) / 8, image
->dy
,
1835 (image
->width
* m
) / 8,
1838 info
->fix
.line_length
, 0x40);
1840 cirrusfb_RectFill(cinfo
->regbase
,
1841 info
->var
.bits_per_pixel
,
1842 (image
->dx
* m
) / 8, image
->dy
,
1843 (image
->width
* m
) / 8, image
->height
,
1845 info
->fix
.line_length
, op
);
1846 memcpy(info
->screen_base
, image
->data
, size
);
1850 #ifdef CONFIG_PPC_PREP
1851 #define PREP_VIDEO_BASE ((volatile unsigned long) 0xC0000000)
1852 #define PREP_IO_BASE ((volatile unsigned char *) 0x80000000)
1853 static void get_prep_addrs(unsigned long *display
, unsigned long *registers
)
1855 *display
= PREP_VIDEO_BASE
;
1856 *registers
= (unsigned long) PREP_IO_BASE
;
1859 #endif /* CONFIG_PPC_PREP */
1862 static int release_io_ports
;
1864 /* Pulled the logic from XFree86 Cirrus driver to get the memory size,
1865 * based on the DRAM bandwidth bit and DRAM bank switching bit. This
1866 * works with 1MB, 2MB and 4MB configurations (which the Motorola boards
1868 static unsigned int __devinit
cirrusfb_get_memsize(struct fb_info
*info
,
1869 u8 __iomem
*regbase
)
1872 struct cirrusfb_info
*cinfo
= info
->par
;
1874 if (is_laguna(cinfo
)) {
1875 unsigned char SR14
= vga_rseq(regbase
, CL_SEQR14
);
1877 mem
= ((SR14
& 7) + 1) << 20;
1879 unsigned char SRF
= vga_rseq(regbase
, CL_SEQRF
);
1880 switch ((SRF
& 0x18)) {
1887 /* 64-bit DRAM data bus width; assume 2MB.
1888 * Also indicates 2MB memory on the 5430.
1894 dev_warn(info
->device
, "Unknown memory size!\n");
1897 /* If DRAM bank switching is enabled, there must be
1898 * twice as much memory installed. (4MB on the 5434)
1900 if (cinfo
->btype
!= BT_ALPINE
&& (SRF
& 0x80) != 0)
1904 /* TODO: Handling of GD5446/5480 (see XF86 sources ...) */
1908 static void get_pci_addrs(const struct pci_dev
*pdev
,
1909 unsigned long *display
, unsigned long *registers
)
1911 assert(pdev
!= NULL
);
1912 assert(display
!= NULL
);
1913 assert(registers
!= NULL
);
1918 /* This is a best-guess for now */
1920 if (pci_resource_flags(pdev
, 0) & IORESOURCE_IO
) {
1921 *display
= pci_resource_start(pdev
, 1);
1922 *registers
= pci_resource_start(pdev
, 0);
1924 *display
= pci_resource_start(pdev
, 0);
1925 *registers
= pci_resource_start(pdev
, 1);
1928 assert(*display
!= 0);
1931 static void cirrusfb_pci_unmap(struct fb_info
*info
)
1933 struct pci_dev
*pdev
= to_pci_dev(info
->device
);
1934 struct cirrusfb_info
*cinfo
= info
->par
;
1936 if (cinfo
->laguna_mmio
== NULL
)
1937 iounmap(cinfo
->laguna_mmio
);
1938 iounmap(info
->screen_base
);
1939 #if 0 /* if system didn't claim this region, we would... */
1940 release_mem_region(0xA0000, 65535);
1942 if (release_io_ports
)
1943 release_region(0x3C0, 32);
1944 pci_release_regions(pdev
);
1946 #endif /* CONFIG_PCI */
1949 static void cirrusfb_zorro_unmap(struct fb_info
*info
)
1951 struct cirrusfb_info
*cinfo
= info
->par
;
1952 struct zorro_dev
*zdev
= to_zorro_dev(info
->device
);
1954 zorro_release_device(zdev
);
1956 if (cinfo
->btype
== BT_PICASSO4
) {
1957 cinfo
->regbase
-= 0x600000;
1958 iounmap((void *)cinfo
->regbase
);
1959 iounmap(info
->screen_base
);
1961 if (zorro_resource_start(zdev
) > 0x01000000)
1962 iounmap(info
->screen_base
);
1965 #endif /* CONFIG_ZORRO */
1967 /* function table of the above functions */
1968 static struct fb_ops cirrusfb_ops
= {
1969 .owner
= THIS_MODULE
,
1970 .fb_open
= cirrusfb_open
,
1971 .fb_release
= cirrusfb_release
,
1972 .fb_setcolreg
= cirrusfb_setcolreg
,
1973 .fb_check_var
= cirrusfb_check_var
,
1974 .fb_set_par
= cirrusfb_set_par
,
1975 .fb_pan_display
= cirrusfb_pan_display
,
1976 .fb_blank
= cirrusfb_blank
,
1977 .fb_fillrect
= cirrusfb_fillrect
,
1978 .fb_copyarea
= cirrusfb_copyarea
,
1979 .fb_sync
= cirrusfb_sync
,
1980 .fb_imageblit
= cirrusfb_imageblit
,
1983 static int __devinit
cirrusfb_set_fbinfo(struct fb_info
*info
)
1985 struct cirrusfb_info
*cinfo
= info
->par
;
1986 struct fb_var_screeninfo
*var
= &info
->var
;
1988 info
->pseudo_palette
= cinfo
->pseudo_palette
;
1989 info
->flags
= FBINFO_DEFAULT
1990 | FBINFO_HWACCEL_XPAN
1991 | FBINFO_HWACCEL_YPAN
1992 | FBINFO_HWACCEL_FILLRECT
1993 | FBINFO_HWACCEL_IMAGEBLIT
1994 | FBINFO_HWACCEL_COPYAREA
;
1995 if (noaccel
|| is_laguna(cinfo
)) {
1996 info
->flags
|= FBINFO_HWACCEL_DISABLED
;
1997 info
->fix
.accel
= FB_ACCEL_NONE
;
1999 info
->fix
.accel
= FB_ACCEL_CIRRUS_ALPINE
;
2001 info
->fbops
= &cirrusfb_ops
;
2003 if (cinfo
->btype
== BT_GD5480
) {
2004 if (var
->bits_per_pixel
== 16)
2005 info
->screen_base
+= 1 * MB_
;
2006 if (var
->bits_per_pixel
== 32)
2007 info
->screen_base
+= 2 * MB_
;
2010 /* Fill fix common fields */
2011 strlcpy(info
->fix
.id
, cirrusfb_board_info
[cinfo
->btype
].name
,
2012 sizeof(info
->fix
.id
));
2014 /* monochrome: only 1 memory plane */
2015 /* 8 bit and above: Use whole memory area */
2016 info
->fix
.smem_len
= info
->screen_size
;
2017 if (var
->bits_per_pixel
== 1)
2018 info
->fix
.smem_len
/= 4;
2019 info
->fix
.type_aux
= 0;
2020 info
->fix
.xpanstep
= 1;
2021 info
->fix
.ypanstep
= 1;
2022 info
->fix
.ywrapstep
= 0;
2024 /* FIXME: map region at 0xB8000 if available, fill in here */
2025 info
->fix
.mmio_len
= 0;
2027 fb_alloc_cmap(&info
->cmap
, 256, 0);
2032 static int __devinit
cirrusfb_register(struct fb_info
*info
)
2034 struct cirrusfb_info
*cinfo
= info
->par
;
2038 assert(cinfo
->btype
!= BT_NONE
);
2040 /* set all the vital stuff */
2041 cirrusfb_set_fbinfo(info
);
2043 dev_dbg(info
->device
, "(RAM start set to: 0x%p)\n", info
->screen_base
);
2045 err
= fb_find_mode(&info
->var
, info
, mode_option
, NULL
, 0, NULL
, 8);
2047 dev_dbg(info
->device
, "wrong initial video mode\n");
2049 goto err_dealloc_cmap
;
2052 info
->var
.activate
= FB_ACTIVATE_NOW
;
2054 err
= cirrusfb_check_var(&info
->var
, info
);
2056 /* should never happen */
2057 dev_dbg(info
->device
,
2058 "choking on default var... umm, no good.\n");
2059 goto err_dealloc_cmap
;
2062 err
= register_framebuffer(info
);
2064 dev_err(info
->device
,
2065 "could not register fb device; err = %d!\n", err
);
2066 goto err_dealloc_cmap
;
2072 fb_dealloc_cmap(&info
->cmap
);
2076 static void __devexit
cirrusfb_cleanup(struct fb_info
*info
)
2078 struct cirrusfb_info
*cinfo
= info
->par
;
2080 switch_monitor(cinfo
, 0);
2081 unregister_framebuffer(info
);
2082 fb_dealloc_cmap(&info
->cmap
);
2083 dev_dbg(info
->device
, "Framebuffer unregistered\n");
2085 framebuffer_release(info
);
2089 static int __devinit
cirrusfb_pci_register(struct pci_dev
*pdev
,
2090 const struct pci_device_id
*ent
)
2092 struct cirrusfb_info
*cinfo
;
2093 struct fb_info
*info
;
2094 unsigned long board_addr
, board_size
;
2097 ret
= pci_enable_device(pdev
);
2099 printk(KERN_ERR
"cirrusfb: Cannot enable PCI device\n");
2103 info
= framebuffer_alloc(sizeof(struct cirrusfb_info
), &pdev
->dev
);
2105 printk(KERN_ERR
"cirrusfb: could not allocate memory\n");
2111 cinfo
->btype
= (enum cirrus_board
) ent
->driver_data
;
2113 dev_dbg(info
->device
,
2114 " Found PCI device, base address 0 is 0x%Lx, btype set to %d\n",
2115 (unsigned long long)pdev
->resource
[0].start
, cinfo
->btype
);
2116 dev_dbg(info
->device
, " base address 1 is 0x%Lx\n",
2117 (unsigned long long)pdev
->resource
[1].start
);
2120 pci_write_config_dword(pdev
, PCI_BASE_ADDRESS_0
, 0x00000000);
2121 #ifdef CONFIG_PPC_PREP
2122 get_prep_addrs(&board_addr
, &info
->fix
.mmio_start
);
2124 /* PReP dies if we ioremap the IO registers, but it works w/out... */
2125 cinfo
->regbase
= (char __iomem
*) info
->fix
.mmio_start
;
2127 dev_dbg(info
->device
,
2128 "Attempt to get PCI info for Cirrus Graphics Card\n");
2129 get_pci_addrs(pdev
, &board_addr
, &info
->fix
.mmio_start
);
2130 /* FIXME: this forces VGA. alternatives? */
2131 cinfo
->regbase
= NULL
;
2132 cinfo
->laguna_mmio
= ioremap(info
->fix
.mmio_start
, 0x1000);
2135 dev_dbg(info
->device
, "Board address: 0x%lx, register address: 0x%lx\n",
2136 board_addr
, info
->fix
.mmio_start
);
2138 board_size
= (cinfo
->btype
== BT_GD5480
) ?
2139 32 * MB_
: cirrusfb_get_memsize(info
, cinfo
->regbase
);
2141 ret
= pci_request_regions(pdev
, "cirrusfb");
2143 dev_err(info
->device
, "cannot reserve region 0x%lx, abort\n",
2145 goto err_release_fb
;
2147 #if 0 /* if the system didn't claim this region, we would... */
2148 if (!request_mem_region(0xA0000, 65535, "cirrusfb")) {
2149 dev_err(info
->device
, "cannot reserve region 0x%lx, abort\n",
2152 goto err_release_regions
;
2155 if (request_region(0x3C0, 32, "cirrusfb"))
2156 release_io_ports
= 1;
2158 info
->screen_base
= ioremap(board_addr
, board_size
);
2159 if (!info
->screen_base
) {
2161 goto err_release_legacy
;
2164 info
->fix
.smem_start
= board_addr
;
2165 info
->screen_size
= board_size
;
2166 cinfo
->unmap
= cirrusfb_pci_unmap
;
2168 dev_info(info
->device
,
2169 "Cirrus Logic chipset on PCI bus, RAM (%lu kB) at 0x%lx\n",
2170 info
->screen_size
>> 10, board_addr
);
2171 pci_set_drvdata(pdev
, info
);
2173 ret
= cirrusfb_register(info
);
2177 pci_set_drvdata(pdev
, NULL
);
2178 iounmap(info
->screen_base
);
2180 if (release_io_ports
)
2181 release_region(0x3C0, 32);
2183 release_mem_region(0xA0000, 65535);
2184 err_release_regions
:
2186 pci_release_regions(pdev
);
2188 if (cinfo
->laguna_mmio
!= NULL
)
2189 iounmap(cinfo
->laguna_mmio
);
2190 framebuffer_release(info
);
2195 static void __devexit
cirrusfb_pci_unregister(struct pci_dev
*pdev
)
2197 struct fb_info
*info
= pci_get_drvdata(pdev
);
2199 cirrusfb_cleanup(info
);
2202 static struct pci_driver cirrusfb_pci_driver
= {
2204 .id_table
= cirrusfb_pci_table
,
2205 .probe
= cirrusfb_pci_register
,
2206 .remove
= __devexit_p(cirrusfb_pci_unregister
),
2209 .suspend
= cirrusfb_pci_suspend
,
2210 .resume
= cirrusfb_pci_resume
,
2214 #endif /* CONFIG_PCI */
2217 static int __devinit
cirrusfb_zorro_register(struct zorro_dev
*z
,
2218 const struct zorro_device_id
*ent
)
2220 struct cirrusfb_info
*cinfo
;
2221 struct fb_info
*info
;
2222 enum cirrus_board btype
;
2223 struct zorro_dev
*z2
= NULL
;
2224 unsigned long board_addr
, board_size
, size
;
2227 btype
= ent
->driver_data
;
2228 if (cirrusfb_zorro_table2
[btype
].id2
)
2229 z2
= zorro_find_device(cirrusfb_zorro_table2
[btype
].id2
, NULL
);
2230 size
= cirrusfb_zorro_table2
[btype
].size
;
2232 info
= framebuffer_alloc(sizeof(struct cirrusfb_info
), &z
->dev
);
2234 printk(KERN_ERR
"cirrusfb: could not allocate memory\n");
2239 dev_info(info
->device
, "%s board detected\n",
2240 cirrusfb_board_info
[btype
].name
);
2243 cinfo
->btype
= btype
;
2246 assert(btype
!= BT_NONE
);
2248 board_addr
= zorro_resource_start(z
);
2249 board_size
= zorro_resource_len(z
);
2250 info
->screen_size
= size
;
2252 if (!zorro_request_device(z
, "cirrusfb")) {
2253 dev_err(info
->device
, "cannot reserve region 0x%lx, abort\n",
2256 goto err_release_fb
;
2261 if (btype
== BT_PICASSO4
) {
2262 dev_info(info
->device
, " REG at $%lx\n", board_addr
+ 0x600000);
2264 /* To be precise, for the P4 this is not the */
2265 /* begin of the board, but the begin of RAM. */
2266 /* for P4, map in its address space in 2 chunks (### TEST! ) */
2267 /* (note the ugly hardcoded 16M number) */
2268 cinfo
->regbase
= ioremap(board_addr
, 16777216);
2269 if (!cinfo
->regbase
)
2270 goto err_release_region
;
2272 dev_dbg(info
->device
, "Virtual address for board set to: $%p\n",
2274 cinfo
->regbase
+= 0x600000;
2275 info
->fix
.mmio_start
= board_addr
+ 0x600000;
2277 info
->fix
.smem_start
= board_addr
+ 16777216;
2278 info
->screen_base
= ioremap(info
->fix
.smem_start
, 16777216);
2279 if (!info
->screen_base
)
2280 goto err_unmap_regbase
;
2282 dev_info(info
->device
, " REG at $%lx\n",
2283 (unsigned long) z2
->resource
.start
);
2285 info
->fix
.smem_start
= board_addr
;
2286 if (board_addr
> 0x01000000)
2287 info
->screen_base
= ioremap(board_addr
, board_size
);
2289 info
->screen_base
= (caddr_t
) ZTWO_VADDR(board_addr
);
2290 if (!info
->screen_base
)
2291 goto err_release_region
;
2293 /* set address for REG area of board */
2294 cinfo
->regbase
= (caddr_t
) ZTWO_VADDR(z2
->resource
.start
);
2295 info
->fix
.mmio_start
= z2
->resource
.start
;
2297 dev_dbg(info
->device
, "Virtual address for board set to: $%p\n",
2300 cinfo
->unmap
= cirrusfb_zorro_unmap
;
2302 dev_info(info
->device
,
2303 "Cirrus Logic chipset on Zorro bus, RAM (%lu MB) at $%lx\n",
2304 board_size
/ MB_
, board_addr
);
2306 zorro_set_drvdata(z
, info
);
2308 /* MCLK select etc. */
2309 if (cirrusfb_board_info
[btype
].init_sr1f
)
2310 vga_wseq(cinfo
->regbase
, CL_SEQR1F
,
2311 cirrusfb_board_info
[btype
].sr1f
);
2313 ret
= cirrusfb_register(info
);
2317 if (btype
== BT_PICASSO4
|| board_addr
> 0x01000000)
2318 iounmap(info
->screen_base
);
2321 if (btype
== BT_PICASSO4
)
2322 iounmap(cinfo
->regbase
- 0x600000);
2324 release_region(board_addr
, board_size
);
2326 framebuffer_release(info
);
2331 void __devexit
cirrusfb_zorro_unregister(struct zorro_dev
*z
)
2333 struct fb_info
*info
= zorro_get_drvdata(z
);
2335 cirrusfb_cleanup(info
);
2338 static struct zorro_driver cirrusfb_zorro_driver
= {
2340 .id_table
= cirrusfb_zorro_table
,
2341 .probe
= cirrusfb_zorro_register
,
2342 .remove
= __devexit_p(cirrusfb_zorro_unregister
),
2344 #endif /* CONFIG_ZORRO */
2347 static int __init
cirrusfb_setup(char *options
)
2351 if (!options
|| !*options
)
2354 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
2358 if (!strcmp(this_opt
, "noaccel"))
2360 else if (!strncmp(this_opt
, "mode:", 5))
2361 mode_option
= this_opt
+ 5;
2363 mode_option
= this_opt
;
2373 MODULE_AUTHOR("Copyright 1999,2000 Jeff Garzik <jgarzik@pobox.com>");
2374 MODULE_DESCRIPTION("Accelerated FBDev driver for Cirrus Logic chips");
2375 MODULE_LICENSE("GPL");
2377 static int __init
cirrusfb_init(void)
2382 char *option
= NULL
;
2384 if (fb_get_options("cirrusfb", &option
))
2386 cirrusfb_setup(option
);
2390 error
|= zorro_register_driver(&cirrusfb_zorro_driver
);
2393 error
|= pci_register_driver(&cirrusfb_pci_driver
);
2398 static void __exit
cirrusfb_exit(void)
2401 pci_unregister_driver(&cirrusfb_pci_driver
);
2404 zorro_unregister_driver(&cirrusfb_zorro_driver
);
2408 module_init(cirrusfb_init
);
2410 module_param(mode_option
, charp
, 0);
2411 MODULE_PARM_DESC(mode_option
, "Initial video mode e.g. '648x480-8@60'");
2412 module_param(noaccel
, bool, 0);
2413 MODULE_PARM_DESC(noaccel
, "Disable acceleration");
2416 module_exit(cirrusfb_exit
);
2419 /**********************************************************************/
2420 /* about the following functions - I have used the same names for the */
2421 /* functions as Markus Wild did in his Retina driver for NetBSD as */
2422 /* they just made sense for this purpose. Apart from that, I wrote */
2423 /* these functions myself. */
2424 /**********************************************************************/
2426 /*** WGen() - write into one of the external/general registers ***/
2427 static void WGen(const struct cirrusfb_info
*cinfo
,
2428 int regnum
, unsigned char val
)
2430 unsigned long regofs
= 0;
2432 if (cinfo
->btype
== BT_PICASSO
) {
2433 /* Picasso II specific hack */
2434 /* if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D ||
2435 regnum == CL_VSSM2) */
2436 if (regnum
== VGA_PEL_IR
|| regnum
== VGA_PEL_D
)
2440 vga_w(cinfo
->regbase
, regofs
+ regnum
, val
);
2443 /*** RGen() - read out one of the external/general registers ***/
2444 static unsigned char RGen(const struct cirrusfb_info
*cinfo
, int regnum
)
2446 unsigned long regofs
= 0;
2448 if (cinfo
->btype
== BT_PICASSO
) {
2449 /* Picasso II specific hack */
2450 /* if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D ||
2451 regnum == CL_VSSM2) */
2452 if (regnum
== VGA_PEL_IR
|| regnum
== VGA_PEL_D
)
2456 return vga_r(cinfo
->regbase
, regofs
+ regnum
);
2459 /*** AttrOn() - turn on VideoEnable for Attribute controller ***/
2460 static void AttrOn(const struct cirrusfb_info
*cinfo
)
2462 assert(cinfo
!= NULL
);
2464 if (vga_rcrt(cinfo
->regbase
, CL_CRT24
) & 0x80) {
2465 /* if we're just in "write value" mode, write back the */
2466 /* same value as before to not modify anything */
2467 vga_w(cinfo
->regbase
, VGA_ATT_IW
,
2468 vga_r(cinfo
->regbase
, VGA_ATT_R
));
2470 /* turn on video bit */
2471 /* vga_w(cinfo->regbase, VGA_ATT_IW, 0x20); */
2472 vga_w(cinfo
->regbase
, VGA_ATT_IW
, 0x33);
2474 /* dummy write on Reg0 to be on "write index" mode next time */
2475 vga_w(cinfo
->regbase
, VGA_ATT_IW
, 0x00);
2478 /*** WHDR() - write into the Hidden DAC register ***/
2479 /* as the HDR is the only extension register that requires special treatment
2480 * (the other extension registers are accessible just like the "ordinary"
2481 * registers of their functional group) here is a specialized routine for
2484 static void WHDR(const struct cirrusfb_info
*cinfo
, unsigned char val
)
2486 unsigned char dummy
;
2488 if (is_laguna(cinfo
))
2490 if (cinfo
->btype
== BT_PICASSO
) {
2491 /* Klaus' hint for correct access to HDR on some boards */
2492 /* first write 0 to pixel mask (3c6) */
2493 WGen(cinfo
, VGA_PEL_MSK
, 0x00);
2495 /* next read dummy from pixel address (3c8) */
2496 dummy
= RGen(cinfo
, VGA_PEL_IW
);
2499 /* now do the usual stuff to access the HDR */
2501 dummy
= RGen(cinfo
, VGA_PEL_MSK
);
2503 dummy
= RGen(cinfo
, VGA_PEL_MSK
);
2505 dummy
= RGen(cinfo
, VGA_PEL_MSK
);
2507 dummy
= RGen(cinfo
, VGA_PEL_MSK
);
2510 WGen(cinfo
, VGA_PEL_MSK
, val
);
2513 if (cinfo
->btype
== BT_PICASSO
) {
2514 /* now first reset HDR access counter */
2515 dummy
= RGen(cinfo
, VGA_PEL_IW
);
2518 /* and at the end, restore the mask value */
2519 /* ## is this mask always 0xff? */
2520 WGen(cinfo
, VGA_PEL_MSK
, 0xff);
2525 /*** WSFR() - write to the "special function register" (SFR) ***/
2526 static void WSFR(struct cirrusfb_info
*cinfo
, unsigned char val
)
2529 assert(cinfo
->regbase
!= NULL
);
2531 z_writeb(val
, cinfo
->regbase
+ 0x8000);
2535 /* The Picasso has a second register for switching the monitor bit */
2536 static void WSFR2(struct cirrusfb_info
*cinfo
, unsigned char val
)
2539 /* writing an arbitrary value to this one causes the monitor switcher */
2540 /* to flip to Amiga display */
2541 assert(cinfo
->regbase
!= NULL
);
2543 z_writeb(val
, cinfo
->regbase
+ 0x9000);
2547 /*** WClut - set CLUT entry (range: 0..63) ***/
2548 static void WClut(struct cirrusfb_info
*cinfo
, unsigned char regnum
, unsigned char red
,
2549 unsigned char green
, unsigned char blue
)
2551 unsigned int data
= VGA_PEL_D
;
2553 /* address write mode register is not translated.. */
2554 vga_w(cinfo
->regbase
, VGA_PEL_IW
, regnum
);
2556 if (cinfo
->btype
== BT_PICASSO
|| cinfo
->btype
== BT_PICASSO4
||
2557 cinfo
->btype
== BT_ALPINE
|| cinfo
->btype
== BT_GD5480
||
2558 cinfo
->btype
== BT_SD64
|| is_laguna(cinfo
)) {
2559 /* but DAC data register IS, at least for Picasso II */
2560 if (cinfo
->btype
== BT_PICASSO
)
2562 vga_w(cinfo
->regbase
, data
, red
);
2563 vga_w(cinfo
->regbase
, data
, green
);
2564 vga_w(cinfo
->regbase
, data
, blue
);
2566 vga_w(cinfo
->regbase
, data
, blue
);
2567 vga_w(cinfo
->regbase
, data
, green
);
2568 vga_w(cinfo
->regbase
, data
, red
);
2573 /*** RClut - read CLUT entry (range 0..63) ***/
2574 static void RClut(struct cirrusfb_info
*cinfo
, unsigned char regnum
, unsigned char *red
,
2575 unsigned char *green
, unsigned char *blue
)
2577 unsigned int data
= VGA_PEL_D
;
2579 vga_w(cinfo
->regbase
, VGA_PEL_IR
, regnum
);
2581 if (cinfo
->btype
== BT_PICASSO
|| cinfo
->btype
== BT_PICASSO4
||
2582 cinfo
->btype
== BT_ALPINE
|| cinfo
->btype
== BT_GD5480
) {
2583 if (cinfo
->btype
== BT_PICASSO
)
2585 *red
= vga_r(cinfo
->regbase
, data
);
2586 *green
= vga_r(cinfo
->regbase
, data
);
2587 *blue
= vga_r(cinfo
->regbase
, data
);
2589 *blue
= vga_r(cinfo
->regbase
, data
);
2590 *green
= vga_r(cinfo
->regbase
, data
);
2591 *red
= vga_r(cinfo
->regbase
, data
);
2596 /*******************************************************************
2599 Wait for the BitBLT engine to complete a possible earlier job
2600 *********************************************************************/
2602 /* FIXME: use interrupts instead */
2603 static void cirrusfb_WaitBLT(u8 __iomem
*regbase
)
2605 while (vga_rgfx(regbase
, CL_GR31
) & 0x08)
2609 /*******************************************************************
2612 perform accelerated "scrolling"
2613 ********************************************************************/
2615 static void cirrusfb_set_blitter(u8 __iomem
*regbase
,
2616 u_short nwidth
, u_short nheight
,
2617 u_long nsrc
, u_long ndest
,
2618 u_short bltmode
, u_short line_length
)
2621 /* pitch: set to line_length */
2622 /* dest pitch low */
2623 vga_wgfx(regbase
, CL_GR24
, line_length
& 0xff);
2625 vga_wgfx(regbase
, CL_GR25
, line_length
>> 8);
2626 /* source pitch low */
2627 vga_wgfx(regbase
, CL_GR26
, line_length
& 0xff);
2628 /* source pitch hi */
2629 vga_wgfx(regbase
, CL_GR27
, line_length
>> 8);
2631 /* BLT width: actual number of pixels - 1 */
2633 vga_wgfx(regbase
, CL_GR20
, nwidth
& 0xff);
2635 vga_wgfx(regbase
, CL_GR21
, nwidth
>> 8);
2637 /* BLT height: actual number of lines -1 */
2638 /* BLT height low */
2639 vga_wgfx(regbase
, CL_GR22
, nheight
& 0xff);
2641 vga_wgfx(regbase
, CL_GR23
, nheight
>> 8);
2643 /* BLT destination */
2645 vga_wgfx(regbase
, CL_GR28
, (u_char
) (ndest
& 0xff));
2647 vga_wgfx(regbase
, CL_GR29
, (u_char
) (ndest
>> 8));
2649 vga_wgfx(regbase
, CL_GR2A
, (u_char
) (ndest
>> 16));
2653 vga_wgfx(regbase
, CL_GR2C
, (u_char
) (nsrc
& 0xff));
2655 vga_wgfx(regbase
, CL_GR2D
, (u_char
) (nsrc
>> 8));
2657 vga_wgfx(regbase
, CL_GR2E
, (u_char
) (nsrc
>> 16));
2660 vga_wgfx(regbase
, CL_GR30
, bltmode
); /* BLT mode */
2662 /* BLT ROP: SrcCopy */
2663 vga_wgfx(regbase
, CL_GR32
, 0x0d); /* BLT ROP */
2665 /* and finally: GO! */
2666 vga_wgfx(regbase
, CL_GR31
, 0x02); /* BLT Start/status */
2669 /*******************************************************************
2672 perform accelerated "scrolling"
2673 ********************************************************************/
2675 static void cirrusfb_BitBLT(u8 __iomem
*regbase
, int bits_per_pixel
,
2676 u_short curx
, u_short cury
,
2677 u_short destx
, u_short desty
,
2678 u_short width
, u_short height
,
2679 u_short line_length
)
2681 u_short nwidth
= width
- 1;
2682 u_short nheight
= height
- 1;
2687 /* if source adr < dest addr, do the Blt backwards */
2688 if (cury
<= desty
) {
2689 if (cury
== desty
) {
2690 /* if src and dest are on the same line, check x */
2696 /* standard case: forward blitting */
2697 nsrc
= (cury
* line_length
) + curx
;
2698 ndest
= (desty
* line_length
) + destx
;
2700 /* this means start addresses are at the end,
2701 * counting backwards
2703 nsrc
+= nheight
* line_length
+ nwidth
;
2704 ndest
+= nheight
* line_length
+ nwidth
;
2707 cirrusfb_WaitBLT(regbase
);
2709 cirrusfb_set_blitter(regbase
, nwidth
, nheight
,
2710 nsrc
, ndest
, bltmode
, line_length
);
2713 /*******************************************************************
2716 perform accelerated rectangle fill
2717 ********************************************************************/
2719 static void cirrusfb_RectFill(u8 __iomem
*regbase
, int bits_per_pixel
,
2720 u_short x
, u_short y
, u_short width
, u_short height
,
2721 u32 fg_color
, u32 bg_color
, u_short line_length
,
2724 u_long ndest
= (y
* line_length
) + x
;
2727 cirrusfb_WaitBLT(regbase
);
2729 /* This is a ColorExpand Blt, using the */
2730 /* same color for foreground and background */
2731 vga_wgfx(regbase
, VGA_GFX_SR_VALUE
, bg_color
);
2732 vga_wgfx(regbase
, VGA_GFX_SR_ENABLE
, fg_color
);
2735 if (bits_per_pixel
>= 16) {
2736 vga_wgfx(regbase
, CL_GR10
, bg_color
>> 8);
2737 vga_wgfx(regbase
, CL_GR11
, fg_color
>> 8);
2740 if (bits_per_pixel
>= 24) {
2741 vga_wgfx(regbase
, CL_GR12
, bg_color
>> 16);
2742 vga_wgfx(regbase
, CL_GR13
, fg_color
>> 16);
2745 if (bits_per_pixel
== 32) {
2746 vga_wgfx(regbase
, CL_GR14
, bg_color
>> 24);
2747 vga_wgfx(regbase
, CL_GR15
, fg_color
>> 24);
2750 cirrusfb_set_blitter(regbase
, width
- 1, height
- 1,
2751 0, ndest
, op
| blitmode
, line_length
);
2754 /**************************************************************************
2755 * bestclock() - determine closest possible clock lower(?) than the
2756 * desired pixel clock
2757 **************************************************************************/
2758 static void bestclock(long freq
, int *nom
, int *den
, int *div
)
2763 assert(nom
!= NULL
);
2764 assert(den
!= NULL
);
2765 assert(div
!= NULL
);
2776 for (n
= 32; n
< 128; n
++) {
2779 d
= (14318 * n
) / freq
;
2780 if ((d
>= 7) && (d
<= 63)) {
2787 h
= ((14318 * n
) / temp
) >> s
;
2788 h
= h
> freq
? h
- freq
: freq
- h
;
2797 if ((d
>= 7) && (d
<= 63)) {
2802 h
= ((14318 * n
) / d
) >> s
;
2803 h
= h
> freq
? h
- freq
: freq
- h
;
2814 /* -------------------------------------------------------------------------
2816 * debugging functions
2818 * -------------------------------------------------------------------------
2821 #ifdef CIRRUSFB_DEBUG
2824 * cirrusfb_dbg_print_regs
2825 * @base: If using newmmio, the newmmio base address, otherwise %NULL
2826 * @reg_class: type of registers to read: %CRT, or %SEQ
2829 * Dumps the given list of VGA CRTC registers. If @base is %NULL,
2830 * old-style I/O ports are queried for information, otherwise MMIO is
2831 * used at the given @base address to query the information.
2834 static void cirrusfb_dbg_print_regs(struct fb_info
*info
,
2836 enum cirrusfb_dbg_reg_class reg_class
, ...)
2839 unsigned char val
= 0;
2843 va_start(list
, reg_class
);
2845 name
= va_arg(list
, char *);
2846 while (name
!= NULL
) {
2847 reg
= va_arg(list
, int);
2849 switch (reg_class
) {
2851 val
= vga_rcrt(regbase
, (unsigned char) reg
);
2854 val
= vga_rseq(regbase
, (unsigned char) reg
);
2857 /* should never occur */
2862 dev_dbg(info
->device
, "%8s = 0x%02X\n", name
, val
);
2864 name
= va_arg(list
, char *);
2871 * cirrusfb_dbg_reg_dump
2872 * @base: If using newmmio, the newmmio base address, otherwise %NULL
2875 * Dumps a list of interesting VGA and CIRRUSFB registers. If @base is %NULL,
2876 * old-style I/O ports are queried for information, otherwise MMIO is
2877 * used at the given @base address to query the information.
2880 static void cirrusfb_dbg_reg_dump(struct fb_info
*info
, caddr_t regbase
)
2882 dev_dbg(info
->device
, "VGA CRTC register dump:\n");
2884 cirrusfb_dbg_print_regs(info
, regbase
, CRT
,
2934 dev_dbg(info
->device
, "\n");
2936 dev_dbg(info
->device
, "VGA SEQ register dump:\n");
2938 cirrusfb_dbg_print_regs(info
, regbase
, SEQ
,
2967 dev_dbg(info
->device
, "\n");
2970 #endif /* CIRRUSFB_DEBUG */