2 * linux/drivers/video/riva/fbdev.c - nVidia RIVA 128/TNT/TNT2 fb driver
4 * Maintained by Ani Joshi <ajoshi@shell.unixbox.com>
6 * Copyright 1999-2000 Jeff Garzik
10 * Ani Joshi: Lots of debugging and cleanup work, really helped
11 * get the driver going
13 * Ferenc Bakonyi: Bug fixes, cleanup, modularization
15 * Jindrich Makovicka: Accel code help, hw cursor, mtrr
17 * Paul Richards: Bug fixes, updates
19 * Initial template from skeletonfb.c, created 28 Dec 1997 by Geert Uytterhoeven
20 * Includes riva_hw.c from nVidia, see copyright below.
21 * KGI code provided the basis for state storage, init, and mode switching.
23 * This file is subject to the terms and conditions of the GNU General Public
24 * License. See the file COPYING in the main directory of this archive
27 * Known bugs and issues:
28 * restoring text mode fails
29 * doublescan modes are broken
32 #include <linux/module.h>
33 #include <linux/kernel.h>
34 #include <linux/errno.h>
35 #include <linux/string.h>
37 #include <linux/slab.h>
38 #include <linux/delay.h>
40 #include <linux/init.h>
41 #include <linux/pci.h>
42 #include <linux/backlight.h>
43 #include <linux/bitrev.h>
49 #include <asm/pci-bridge.h>
51 #ifdef CONFIG_PMAC_BACKLIGHT
52 #include <asm/machdep.h>
53 #include <asm/backlight.h>
59 /* version number of this driver */
60 #define RIVAFB_VERSION "0.9.5b"
62 /* ------------------------------------------------------------------------- *
64 * various helpful macros and constants
66 * ------------------------------------------------------------------------- */
67 #ifdef CONFIG_FB_RIVA_DEBUG
68 #define NVTRACE printk
70 #define NVTRACE if(0) printk
73 #define NVTRACE_ENTER(...) NVTRACE("%s START\n", __func__)
74 #define NVTRACE_LEAVE(...) NVTRACE("%s END\n", __func__)
76 #ifdef CONFIG_FB_RIVA_DEBUG
77 #define assert(expr) \
79 printk( "Assertion failed! %s,%s,%s,line=%d\n",\
80 #expr,__FILE__,__func__,__LINE__); \
87 #define PFX "rivafb: "
89 /* macro that allows you to set overflow bits */
90 #define SetBitField(value,from,to) SetBF(to,GetBF(value,from))
91 #define SetBit(n) (1<<(n))
92 #define Set8Bits(value) ((value)&0xff)
94 /* HW cursor parameters */
97 /* ------------------------------------------------------------------------- *
101 * ------------------------------------------------------------------------- */
103 static int rivafb_blank(int blank
, struct fb_info
*info
);
105 /* ------------------------------------------------------------------------- *
107 * card identification
109 * ------------------------------------------------------------------------- */
111 static struct pci_device_id rivafb_pci_tbl
[] = {
112 { PCI_VENDOR_ID_NVIDIA_SGS
, PCI_DEVICE_ID_NVIDIA_SGS_RIVA128
,
113 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
114 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_TNT
,
115 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
116 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_TNT2
,
117 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
118 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_UTNT2
,
119 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
120 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_VTNT2
,
121 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
122 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_UVTNT2
,
123 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
124 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_ITNT2
,
125 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
126 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE_SDR
,
127 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
128 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE_DDR
,
129 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
130 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_QUADRO
,
131 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
132 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE2_MX
,
133 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
134 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE2_MX2
,
135 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
136 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE2_GO
,
137 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
138 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_QUADRO2_MXR
,
139 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
140 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE2_GTS
,
141 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
142 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE2_GTS2
,
143 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
144 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE2_ULTRA
,
145 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
146 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_QUADRO2_PRO
,
147 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
148 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE4_MX_460
,
149 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
150 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE4_MX_440
,
151 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
152 // NF2/IGP version, GeForce 4 MX, NV18
153 { PCI_VENDOR_ID_NVIDIA
, 0x01f0,
154 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
155 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE4_MX_420
,
156 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
157 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE4_440_GO
,
158 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
159 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE4_420_GO
,
160 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
161 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE4_420_GO_M32
,
162 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
163 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_QUADRO4_500XGL
,
164 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
165 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE4_440_GO_M64
,
166 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
167 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_QUADRO4_200
,
168 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
169 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_QUADRO4_550XGL
,
170 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
171 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_QUADRO4_500_GOGL
,
172 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
173 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_IGEFORCE2
,
174 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
175 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE3
,
176 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
177 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE3_1
,
178 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
179 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE3_2
,
180 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
181 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_QUADRO_DDC
,
182 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
183 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE4_TI_4600
,
184 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
185 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE4_TI_4400
,
186 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
187 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE4_TI_4200
,
188 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
189 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_QUADRO4_900XGL
,
190 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
191 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_QUADRO4_750XGL
,
192 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
193 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_QUADRO4_700XGL
,
194 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
195 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE_FX_GO_5200
,
196 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
197 { 0, } /* terminate list */
199 MODULE_DEVICE_TABLE(pci
, rivafb_pci_tbl
);
201 /* ------------------------------------------------------------------------- *
205 * ------------------------------------------------------------------------- */
207 /* command line data, set in rivafb_setup() */
208 static int flatpanel
= -1; /* Autodetect later */
209 static int forceCRTC
= -1;
210 static bool noaccel
= 0;
212 static bool nomtrr
= 0;
214 #ifdef CONFIG_PMAC_BACKLIGHT
215 static int backlight
= 1;
217 static int backlight
= 0;
220 static char *mode_option
= NULL
;
221 static bool strictmode
= 0;
223 static struct fb_fix_screeninfo rivafb_fix
= {
224 .type
= FB_TYPE_PACKED_PIXELS
,
229 static struct fb_var_screeninfo rivafb_default_var
= {
239 .activate
= FB_ACTIVATE_NOW
,
249 .vmode
= FB_VMODE_NONINTERLACED
253 static const struct riva_regs reg_template
= {
254 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* ATTR */
255 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
256 0x41, 0x01, 0x0F, 0x00, 0x00},
257 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* CRT */
258 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE3, /* 0x10 */
260 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
261 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20 */
262 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
263 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30 */
264 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
267 {0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, /* GRA */
269 {0x03, 0x01, 0x0F, 0x00, 0x0E}, /* SEQ */
276 #ifdef CONFIG_FB_RIVA_BACKLIGHT
277 /* We do not have any information about which values are allowed, thus
278 * we used safe values.
280 #define MIN_LEVEL 0x158
281 #define MAX_LEVEL 0x534
282 #define LEVEL_STEP ((MAX_LEVEL - MIN_LEVEL) / FB_BACKLIGHT_MAX)
284 static int riva_bl_get_level_brightness(struct riva_par
*par
,
287 struct fb_info
*info
= pci_get_drvdata(par
->pdev
);
290 /* Get and convert the value */
291 /* No locking on bl_curve since accessing a single value */
292 nlevel
= MIN_LEVEL
+ info
->bl_curve
[level
] * LEVEL_STEP
;
296 else if (nlevel
< MIN_LEVEL
)
298 else if (nlevel
> MAX_LEVEL
)
304 static int riva_bl_update_status(struct backlight_device
*bd
)
306 struct riva_par
*par
= bl_get_data(bd
);
307 U032 tmp_pcrt
, tmp_pmc
;
310 if (bd
->props
.power
!= FB_BLANK_UNBLANK
||
311 bd
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
314 level
= bd
->props
.brightness
;
316 tmp_pmc
= NV_RD32(par
->riva
.PMC
, 0x10F0) & 0x0000FFFF;
317 tmp_pcrt
= NV_RD32(par
->riva
.PCRTC0
, 0x081C) & 0xFFFFFFFC;
320 tmp_pmc
|= (1 << 31); /* backlight bit */
321 tmp_pmc
|= riva_bl_get_level_brightness(par
, level
) << 16; /* level */
323 NV_WR32(par
->riva
.PCRTC0
, 0x081C, tmp_pcrt
);
324 NV_WR32(par
->riva
.PMC
, 0x10F0, tmp_pmc
);
329 static int riva_bl_get_brightness(struct backlight_device
*bd
)
331 return bd
->props
.brightness
;
334 static const struct backlight_ops riva_bl_ops
= {
335 .get_brightness
= riva_bl_get_brightness
,
336 .update_status
= riva_bl_update_status
,
339 static void riva_bl_init(struct riva_par
*par
)
341 struct backlight_properties props
;
342 struct fb_info
*info
= pci_get_drvdata(par
->pdev
);
343 struct backlight_device
*bd
;
349 #ifdef CONFIG_PMAC_BACKLIGHT
350 if (!machine_is(powermac
) ||
351 !pmac_has_backlight_type("mnca"))
355 snprintf(name
, sizeof(name
), "rivabl%d", info
->node
);
357 memset(&props
, 0, sizeof(struct backlight_properties
));
358 props
.type
= BACKLIGHT_RAW
;
359 props
.max_brightness
= FB_BACKLIGHT_LEVELS
- 1;
360 bd
= backlight_device_register(name
, info
->dev
, par
, &riva_bl_ops
,
364 printk(KERN_WARNING
"riva: Backlight registration failed\n");
369 fb_bl_default_curve(info
, 0,
370 MIN_LEVEL
* FB_BACKLIGHT_MAX
/ MAX_LEVEL
,
373 bd
->props
.brightness
= bd
->props
.max_brightness
;
374 bd
->props
.power
= FB_BLANK_UNBLANK
;
375 backlight_update_status(bd
);
377 printk("riva: Backlight initialized (%s)\n", name
);
385 static void riva_bl_exit(struct fb_info
*info
)
387 struct backlight_device
*bd
= info
->bl_dev
;
389 backlight_device_unregister(bd
);
390 printk("riva: Backlight unloaded\n");
393 static inline void riva_bl_init(struct riva_par
*par
) {}
394 static inline void riva_bl_exit(struct fb_info
*info
) {}
395 #endif /* CONFIG_FB_RIVA_BACKLIGHT */
397 /* ------------------------------------------------------------------------- *
401 * ------------------------------------------------------------------------- */
403 static inline void CRTCout(struct riva_par
*par
, unsigned char index
,
406 VGA_WR08(par
->riva
.PCIO
, 0x3d4, index
);
407 VGA_WR08(par
->riva
.PCIO
, 0x3d5, val
);
410 static inline unsigned char CRTCin(struct riva_par
*par
,
413 VGA_WR08(par
->riva
.PCIO
, 0x3d4, index
);
414 return (VGA_RD08(par
->riva
.PCIO
, 0x3d5));
417 static inline void GRAout(struct riva_par
*par
, unsigned char index
,
420 VGA_WR08(par
->riva
.PVIO
, 0x3ce, index
);
421 VGA_WR08(par
->riva
.PVIO
, 0x3cf, val
);
424 static inline unsigned char GRAin(struct riva_par
*par
,
427 VGA_WR08(par
->riva
.PVIO
, 0x3ce, index
);
428 return (VGA_RD08(par
->riva
.PVIO
, 0x3cf));
431 static inline void SEQout(struct riva_par
*par
, unsigned char index
,
434 VGA_WR08(par
->riva
.PVIO
, 0x3c4, index
);
435 VGA_WR08(par
->riva
.PVIO
, 0x3c5, val
);
438 static inline unsigned char SEQin(struct riva_par
*par
,
441 VGA_WR08(par
->riva
.PVIO
, 0x3c4, index
);
442 return (VGA_RD08(par
->riva
.PVIO
, 0x3c5));
445 static inline void ATTRout(struct riva_par
*par
, unsigned char index
,
448 VGA_WR08(par
->riva
.PCIO
, 0x3c0, index
);
449 VGA_WR08(par
->riva
.PCIO
, 0x3c0, val
);
452 static inline unsigned char ATTRin(struct riva_par
*par
,
455 VGA_WR08(par
->riva
.PCIO
, 0x3c0, index
);
456 return (VGA_RD08(par
->riva
.PCIO
, 0x3c1));
459 static inline void MISCout(struct riva_par
*par
, unsigned char val
)
461 VGA_WR08(par
->riva
.PVIO
, 0x3c2, val
);
464 static inline unsigned char MISCin(struct riva_par
*par
)
466 return (VGA_RD08(par
->riva
.PVIO
, 0x3cc));
469 static inline void reverse_order(u32
*l
)
472 a
[0] = bitrev8(a
[0]);
473 a
[1] = bitrev8(a
[1]);
474 a
[2] = bitrev8(a
[2]);
475 a
[3] = bitrev8(a
[3]);
478 /* ------------------------------------------------------------------------- *
482 * ------------------------------------------------------------------------- */
485 * rivafb_load_cursor_image - load cursor image to hardware
486 * @data: address to monochrome bitmap (1 = foreground color, 0 = background)
487 * @par: pointer to private data
488 * @w: width of cursor image in pixels
489 * @h: height of cursor image in scanlines
490 * @bg: background color (ARGB1555) - alpha bit determines opacity
491 * @fg: foreground color (ARGB1555)
494 * Loads cursor image based on a monochrome source and mask bitmap. The
495 * image bits determines the color of the pixel, 0 for background, 1 for
496 * foreground. Only the affected region (as determined by @w and @h
497 * parameters) will be updated.
502 static void rivafb_load_cursor_image(struct riva_par
*par
, u8
*data8
,
503 u16 bg
, u16 fg
, u32 w
, u32 h
)
507 u32
*data
= (u32
*)data8
;
508 bg
= le16_to_cpu(bg
);
509 fg
= le16_to_cpu(fg
);
513 for (i
= 0; i
< h
; i
++) {
517 for (j
= 0; j
< w
/2; j
++) {
519 #if defined (__BIG_ENDIAN)
520 tmp
= (b
& (1 << 31)) ? fg
<< 16 : bg
<< 16;
522 tmp
|= (b
& (1 << 31)) ? fg
: bg
;
525 tmp
= (b
& 1) ? fg
: bg
;
527 tmp
|= (b
& 1) ? fg
<< 16 : bg
<< 16;
530 writel(tmp
, &par
->riva
.CURSOR
[k
++]);
532 k
+= (MAX_CURS
- w
)/2;
536 /* ------------------------------------------------------------------------- *
538 * general utility functions
540 * ------------------------------------------------------------------------- */
543 * riva_wclut - set CLUT entry
544 * @chip: pointer to RIVA_HW_INST object
545 * @regnum: register number
546 * @red: red component
547 * @green: green component
548 * @blue: blue component
551 * Sets color register @regnum.
556 static void riva_wclut(RIVA_HW_INST
*chip
,
557 unsigned char regnum
, unsigned char red
,
558 unsigned char green
, unsigned char blue
)
560 VGA_WR08(chip
->PDIO
, 0x3c8, regnum
);
561 VGA_WR08(chip
->PDIO
, 0x3c9, red
);
562 VGA_WR08(chip
->PDIO
, 0x3c9, green
);
563 VGA_WR08(chip
->PDIO
, 0x3c9, blue
);
567 * riva_rclut - read fromCLUT register
568 * @chip: pointer to RIVA_HW_INST object
569 * @regnum: register number
570 * @red: red component
571 * @green: green component
572 * @blue: blue component
575 * Reads red, green, and blue from color register @regnum.
580 static void riva_rclut(RIVA_HW_INST
*chip
,
581 unsigned char regnum
, unsigned char *red
,
582 unsigned char *green
, unsigned char *blue
)
585 VGA_WR08(chip
->PDIO
, 0x3c7, regnum
);
586 *red
= VGA_RD08(chip
->PDIO
, 0x3c9);
587 *green
= VGA_RD08(chip
->PDIO
, 0x3c9);
588 *blue
= VGA_RD08(chip
->PDIO
, 0x3c9);
592 * riva_save_state - saves current chip state
593 * @par: pointer to riva_par object containing info for current riva board
594 * @regs: pointer to riva_regs object
597 * Saves current chip state to @regs.
603 static void riva_save_state(struct riva_par
*par
, struct riva_regs
*regs
)
608 par
->riva
.LockUnlock(&par
->riva
, 0);
610 par
->riva
.UnloadStateExt(&par
->riva
, ®s
->ext
);
612 regs
->misc_output
= MISCin(par
);
614 for (i
= 0; i
< NUM_CRT_REGS
; i
++)
615 regs
->crtc
[i
] = CRTCin(par
, i
);
617 for (i
= 0; i
< NUM_ATC_REGS
; i
++)
618 regs
->attr
[i
] = ATTRin(par
, i
);
620 for (i
= 0; i
< NUM_GRC_REGS
; i
++)
621 regs
->gra
[i
] = GRAin(par
, i
);
623 for (i
= 0; i
< NUM_SEQ_REGS
; i
++)
624 regs
->seq
[i
] = SEQin(par
, i
);
629 * riva_load_state - loads current chip state
630 * @par: pointer to riva_par object containing info for current riva board
631 * @regs: pointer to riva_regs object
634 * Loads chip state from @regs.
637 * riva_load_video_mode()
642 static void riva_load_state(struct riva_par
*par
, struct riva_regs
*regs
)
644 RIVA_HW_STATE
*state
= ®s
->ext
;
648 CRTCout(par
, 0x11, 0x00);
650 par
->riva
.LockUnlock(&par
->riva
, 0);
652 par
->riva
.LoadStateExt(&par
->riva
, state
);
654 MISCout(par
, regs
->misc_output
);
656 for (i
= 0; i
< NUM_CRT_REGS
; i
++) {
662 CRTCout(par
, i
, regs
->crtc
[i
]);
666 for (i
= 0; i
< NUM_ATC_REGS
; i
++)
667 ATTRout(par
, i
, regs
->attr
[i
]);
669 for (i
= 0; i
< NUM_GRC_REGS
; i
++)
670 GRAout(par
, i
, regs
->gra
[i
]);
672 for (i
= 0; i
< NUM_SEQ_REGS
; i
++)
673 SEQout(par
, i
, regs
->seq
[i
]);
678 * riva_load_video_mode - calculate timings
679 * @info: pointer to fb_info object containing info for current riva board
682 * Calculate some timings and then send em off to riva_load_state().
687 static int riva_load_video_mode(struct fb_info
*info
)
689 int bpp
, width
, hDisplaySize
, hDisplay
, hStart
,
690 hEnd
, hTotal
, height
, vDisplay
, vStart
, vEnd
, vTotal
, dotClock
;
691 int hBlankStart
, hBlankEnd
, vBlankStart
, vBlankEnd
;
693 struct riva_par
*par
= info
->par
;
694 struct riva_regs newmode
;
697 /* time to calculate */
698 rivafb_blank(FB_BLANK_NORMAL
, info
);
700 bpp
= info
->var
.bits_per_pixel
;
701 if (bpp
== 16 && info
->var
.green
.length
== 5)
703 width
= info
->var
.xres_virtual
;
704 hDisplaySize
= info
->var
.xres
;
705 hDisplay
= (hDisplaySize
/ 8) - 1;
706 hStart
= (hDisplaySize
+ info
->var
.right_margin
) / 8 - 1;
707 hEnd
= (hDisplaySize
+ info
->var
.right_margin
+
708 info
->var
.hsync_len
) / 8 - 1;
709 hTotal
= (hDisplaySize
+ info
->var
.right_margin
+
710 info
->var
.hsync_len
+ info
->var
.left_margin
) / 8 - 5;
711 hBlankStart
= hDisplay
;
712 hBlankEnd
= hTotal
+ 4;
714 height
= info
->var
.yres_virtual
;
715 vDisplay
= info
->var
.yres
- 1;
716 vStart
= info
->var
.yres
+ info
->var
.lower_margin
- 1;
717 vEnd
= info
->var
.yres
+ info
->var
.lower_margin
+
718 info
->var
.vsync_len
- 1;
719 vTotal
= info
->var
.yres
+ info
->var
.lower_margin
+
720 info
->var
.vsync_len
+ info
->var
.upper_margin
+ 2;
721 vBlankStart
= vDisplay
;
722 vBlankEnd
= vTotal
+ 1;
723 dotClock
= 1000000000 / info
->var
.pixclock
;
725 memcpy(&newmode
, ®_template
, sizeof(struct riva_regs
));
727 if ((info
->var
.vmode
& FB_VMODE_MASK
) == FB_VMODE_INTERLACED
)
730 if (par
->FlatPanel
) {
733 vBlankStart
= vStart
;
736 hBlankEnd
= hTotal
+ 4;
739 newmode
.crtc
[0x0] = Set8Bits (hTotal
);
740 newmode
.crtc
[0x1] = Set8Bits (hDisplay
);
741 newmode
.crtc
[0x2] = Set8Bits (hBlankStart
);
742 newmode
.crtc
[0x3] = SetBitField (hBlankEnd
, 4: 0, 4:0) | SetBit (7);
743 newmode
.crtc
[0x4] = Set8Bits (hStart
);
744 newmode
.crtc
[0x5] = SetBitField (hBlankEnd
, 5: 5, 7:7)
745 | SetBitField (hEnd
, 4: 0, 4:0);
746 newmode
.crtc
[0x6] = SetBitField (vTotal
, 7: 0, 7:0);
747 newmode
.crtc
[0x7] = SetBitField (vTotal
, 8: 8, 0:0)
748 | SetBitField (vDisplay
, 8: 8, 1:1)
749 | SetBitField (vStart
, 8: 8, 2:2)
750 | SetBitField (vBlankStart
, 8: 8, 3:3)
752 | SetBitField (vTotal
, 9: 9, 5:5)
753 | SetBitField (vDisplay
, 9: 9, 6:6)
754 | SetBitField (vStart
, 9: 9, 7:7);
755 newmode
.crtc
[0x9] = SetBitField (vBlankStart
, 9: 9, 5:5)
757 newmode
.crtc
[0x10] = Set8Bits (vStart
);
758 newmode
.crtc
[0x11] = SetBitField (vEnd
, 3: 0, 3:0)
760 newmode
.crtc
[0x12] = Set8Bits (vDisplay
);
761 newmode
.crtc
[0x13] = (width
/ 8) * ((bpp
+ 1) / 8);
762 newmode
.crtc
[0x15] = Set8Bits (vBlankStart
);
763 newmode
.crtc
[0x16] = Set8Bits (vBlankEnd
);
765 newmode
.ext
.screen
= SetBitField(hBlankEnd
,6:6,4:4)
766 | SetBitField(vBlankStart
,10:10,3:3)
767 | SetBitField(vStart
,10:10,2:2)
768 | SetBitField(vDisplay
,10:10,1:1)
769 | SetBitField(vTotal
,10:10,0:0);
770 newmode
.ext
.horiz
= SetBitField(hTotal
,8:8,0:0)
771 | SetBitField(hDisplay
,8:8,1:1)
772 | SetBitField(hBlankStart
,8:8,2:2)
773 | SetBitField(hStart
,8:8,3:3);
774 newmode
.ext
.extra
= SetBitField(vTotal
,11:11,0:0)
775 | SetBitField(vDisplay
,11:11,2:2)
776 | SetBitField(vStart
,11:11,4:4)
777 | SetBitField(vBlankStart
,11:11,6:6);
779 if ((info
->var
.vmode
& FB_VMODE_MASK
) == FB_VMODE_INTERLACED
) {
780 int tmp
= (hTotal
>> 1) & ~1;
781 newmode
.ext
.interlace
= Set8Bits(tmp
);
782 newmode
.ext
.horiz
|= SetBitField(tmp
, 8:8,4:4);
784 newmode
.ext
.interlace
= 0xff; /* interlace off */
786 if (par
->riva
.Architecture
>= NV_ARCH_10
)
787 par
->riva
.CURSOR
= (U032 __iomem
*)(info
->screen_base
+ par
->riva
.CursorStart
);
789 if (info
->var
.sync
& FB_SYNC_HOR_HIGH_ACT
)
790 newmode
.misc_output
&= ~0x40;
792 newmode
.misc_output
|= 0x40;
793 if (info
->var
.sync
& FB_SYNC_VERT_HIGH_ACT
)
794 newmode
.misc_output
&= ~0x80;
796 newmode
.misc_output
|= 0x80;
798 rc
= CalcStateExt(&par
->riva
, &newmode
.ext
, bpp
, width
,
799 hDisplaySize
, height
, dotClock
);
803 newmode
.ext
.scale
= NV_RD32(par
->riva
.PRAMDAC
, 0x00000848) &
805 if (par
->FlatPanel
== 1) {
806 newmode
.ext
.pixel
|= (1 << 7);
807 newmode
.ext
.scale
|= (1 << 8);
809 if (par
->SecondCRTC
) {
810 newmode
.ext
.head
= NV_RD32(par
->riva
.PCRTC0
, 0x00000860) &
812 newmode
.ext
.head2
= NV_RD32(par
->riva
.PCRTC0
, 0x00002860) |
814 newmode
.ext
.crtcOwner
= 3;
815 newmode
.ext
.pllsel
|= 0x20000800;
816 newmode
.ext
.vpll2
= newmode
.ext
.vpll
;
817 } else if (par
->riva
.twoHeads
) {
818 newmode
.ext
.head
= NV_RD32(par
->riva
.PCRTC0
, 0x00000860) |
820 newmode
.ext
.head2
= NV_RD32(par
->riva
.PCRTC0
, 0x00002860) &
822 newmode
.ext
.crtcOwner
= 0;
823 newmode
.ext
.vpll2
= NV_RD32(par
->riva
.PRAMDAC0
, 0x00000520);
825 if (par
->FlatPanel
== 1) {
826 newmode
.ext
.pixel
|= (1 << 7);
827 newmode
.ext
.scale
|= (1 << 8);
829 newmode
.ext
.cursorConfig
= 0x02000100;
830 par
->current_state
= newmode
;
831 riva_load_state(par
, &par
->current_state
);
832 par
->riva
.LockUnlock(&par
->riva
, 0); /* important for HW cursor */
835 rivafb_blank(FB_BLANK_UNBLANK
, info
);
841 static void riva_update_var(struct fb_var_screeninfo
*var
,
842 const struct fb_videomode
*modedb
)
845 var
->xres
= var
->xres_virtual
= modedb
->xres
;
846 var
->yres
= modedb
->yres
;
847 if (var
->yres_virtual
< var
->yres
)
848 var
->yres_virtual
= var
->yres
;
849 var
->xoffset
= var
->yoffset
= 0;
850 var
->pixclock
= modedb
->pixclock
;
851 var
->left_margin
= modedb
->left_margin
;
852 var
->right_margin
= modedb
->right_margin
;
853 var
->upper_margin
= modedb
->upper_margin
;
854 var
->lower_margin
= modedb
->lower_margin
;
855 var
->hsync_len
= modedb
->hsync_len
;
856 var
->vsync_len
= modedb
->vsync_len
;
857 var
->sync
= modedb
->sync
;
858 var
->vmode
= modedb
->vmode
;
863 * rivafb_do_maximize -
864 * @info: pointer to fb_info object containing info for current riva board
873 * -EINVAL on failure, 0 on success
879 static int rivafb_do_maximize(struct fb_info
*info
,
880 struct fb_var_screeninfo
*var
,
896 /* use highest possible virtual resolution */
897 if (var
->xres_virtual
== -1 && var
->yres_virtual
== -1) {
898 printk(KERN_WARNING PFX
899 "using maximum available virtual resolution\n");
900 for (i
= 0; modes
[i
].xres
!= -1; i
++) {
901 if (modes
[i
].xres
* nom
/ den
* modes
[i
].yres
<
905 if (modes
[i
].xres
== -1) {
907 "could not find a virtual resolution that fits into video memory!!\n");
908 NVTRACE("EXIT - EINVAL error\n");
911 var
->xres_virtual
= modes
[i
].xres
;
912 var
->yres_virtual
= modes
[i
].yres
;
915 "virtual resolution set to maximum of %dx%d\n",
916 var
->xres_virtual
, var
->yres_virtual
);
917 } else if (var
->xres_virtual
== -1) {
918 var
->xres_virtual
= (info
->fix
.smem_len
* den
/
919 (nom
* var
->yres_virtual
)) & ~15;
920 printk(KERN_WARNING PFX
921 "setting virtual X resolution to %d\n", var
->xres_virtual
);
922 } else if (var
->yres_virtual
== -1) {
923 var
->xres_virtual
= (var
->xres_virtual
+ 15) & ~15;
924 var
->yres_virtual
= info
->fix
.smem_len
* den
/
925 (nom
* var
->xres_virtual
);
926 printk(KERN_WARNING PFX
927 "setting virtual Y resolution to %d\n", var
->yres_virtual
);
929 var
->xres_virtual
= (var
->xres_virtual
+ 15) & ~15;
930 if (var
->xres_virtual
* nom
/ den
* var
->yres_virtual
> info
->fix
.smem_len
) {
932 "mode %dx%dx%d rejected...resolution too high to fit into video memory!\n",
933 var
->xres
, var
->yres
, var
->bits_per_pixel
);
934 NVTRACE("EXIT - EINVAL error\n");
939 if (var
->xres_virtual
* nom
/ den
>= 8192) {
940 printk(KERN_WARNING PFX
941 "virtual X resolution (%d) is too high, lowering to %d\n",
942 var
->xres_virtual
, 8192 * den
/ nom
- 16);
943 var
->xres_virtual
= 8192 * den
/ nom
- 16;
946 if (var
->xres_virtual
< var
->xres
) {
948 "virtual X resolution (%d) is smaller than real\n", var
->xres_virtual
);
952 if (var
->yres_virtual
< var
->yres
) {
954 "virtual Y resolution (%d) is smaller than real\n", var
->yres_virtual
);
957 if (var
->yres_virtual
> 0x7fff/nom
)
958 var
->yres_virtual
= 0x7fff/nom
;
959 if (var
->xres_virtual
> 0x7fff/nom
)
960 var
->xres_virtual
= 0x7fff/nom
;
966 riva_set_pattern(struct riva_par
*par
, int clr0
, int clr1
, int pat0
, int pat1
)
968 RIVA_FIFO_FREE(par
->riva
, Patt
, 4);
969 NV_WR32(&par
->riva
.Patt
->Color0
, 0, clr0
);
970 NV_WR32(&par
->riva
.Patt
->Color1
, 0, clr1
);
971 NV_WR32(par
->riva
.Patt
->Monochrome
, 0, pat0
);
972 NV_WR32(par
->riva
.Patt
->Monochrome
, 4, pat1
);
975 /* acceleration routines */
976 static inline void wait_for_idle(struct riva_par
*par
)
978 while (par
->riva
.Busy(&par
->riva
));
982 * Set ROP. Translate X rop into ROP3. Internal routine.
985 riva_set_rop_solid(struct riva_par
*par
, int rop
)
987 riva_set_pattern(par
, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
988 RIVA_FIFO_FREE(par
->riva
, Rop
, 1);
989 NV_WR32(&par
->riva
.Rop
->Rop3
, 0, rop
);
993 static void riva_setup_accel(struct fb_info
*info
)
995 struct riva_par
*par
= info
->par
;
997 RIVA_FIFO_FREE(par
->riva
, Clip
, 2);
998 NV_WR32(&par
->riva
.Clip
->TopLeft
, 0, 0x0);
999 NV_WR32(&par
->riva
.Clip
->WidthHeight
, 0,
1000 (info
->var
.xres_virtual
& 0xffff) |
1001 (info
->var
.yres_virtual
<< 16));
1002 riva_set_rop_solid(par
, 0xcc);
1007 * riva_get_cmap_len - query current color map length
1008 * @var: standard kernel fb changeable data
1011 * Get current color map length.
1014 * Length of color map
1017 * rivafb_setcolreg()
1019 static int riva_get_cmap_len(const struct fb_var_screeninfo
*var
)
1021 int rc
= 256; /* reasonable default */
1023 switch (var
->green
.length
) {
1025 rc
= 256; /* 256 entries (2^8), 8 bpp and RGB8888 */
1028 rc
= 32; /* 32 entries (2^5), 16 bpp, RGB555 */
1031 rc
= 64; /* 64 entries (2^6), 16 bpp, RGB565 */
1034 /* should not occur */
1040 /* ------------------------------------------------------------------------- *
1042 * framebuffer operations
1044 * ------------------------------------------------------------------------- */
1046 static int rivafb_open(struct fb_info
*info
, int user
)
1048 struct riva_par
*par
= info
->par
;
1051 mutex_lock(&par
->open_lock
);
1052 if (!par
->ref_count
) {
1054 memset(&par
->state
, 0, sizeof(struct vgastate
));
1055 par
->state
.flags
= VGA_SAVE_MODE
| VGA_SAVE_FONTS
;
1056 /* save the DAC for Riva128 */
1057 if (par
->riva
.Architecture
== NV_ARCH_03
)
1058 par
->state
.flags
|= VGA_SAVE_CMAP
;
1059 save_vga(&par
->state
);
1061 /* vgaHWunlock() + riva unlock (0x7F) */
1062 CRTCout(par
, 0x11, 0xFF);
1063 par
->riva
.LockUnlock(&par
->riva
, 0);
1065 riva_save_state(par
, &par
->initial_state
);
1068 mutex_unlock(&par
->open_lock
);
1073 static int rivafb_release(struct fb_info
*info
, int user
)
1075 struct riva_par
*par
= info
->par
;
1078 mutex_lock(&par
->open_lock
);
1079 if (!par
->ref_count
) {
1080 mutex_unlock(&par
->open_lock
);
1083 if (par
->ref_count
== 1) {
1084 par
->riva
.LockUnlock(&par
->riva
, 0);
1085 par
->riva
.LoadStateExt(&par
->riva
, &par
->initial_state
.ext
);
1086 riva_load_state(par
, &par
->initial_state
);
1088 restore_vga(&par
->state
);
1090 par
->riva
.LockUnlock(&par
->riva
, 1);
1093 mutex_unlock(&par
->open_lock
);
1098 static int rivafb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
1100 const struct fb_videomode
*mode
;
1101 struct riva_par
*par
= info
->par
;
1102 int nom
, den
; /* translating from pixels->bytes */
1106 switch (var
->bits_per_pixel
) {
1108 var
->red
.offset
= var
->green
.offset
= var
->blue
.offset
= 0;
1109 var
->red
.length
= var
->green
.length
= var
->blue
.length
= 8;
1110 var
->bits_per_pixel
= 8;
1114 var
->green
.length
= 5;
1117 var
->bits_per_pixel
= 16;
1118 /* The Riva128 supports RGB555 only */
1119 if (par
->riva
.Architecture
== NV_ARCH_03
)
1120 var
->green
.length
= 5;
1121 if (var
->green
.length
== 5) {
1122 /* 0rrrrrgg gggbbbbb */
1123 var
->red
.offset
= 10;
1124 var
->green
.offset
= 5;
1125 var
->blue
.offset
= 0;
1126 var
->red
.length
= 5;
1127 var
->green
.length
= 5;
1128 var
->blue
.length
= 5;
1130 /* rrrrrggg gggbbbbb */
1131 var
->red
.offset
= 11;
1132 var
->green
.offset
= 5;
1133 var
->blue
.offset
= 0;
1134 var
->red
.length
= 5;
1135 var
->green
.length
= 6;
1136 var
->blue
.length
= 5;
1142 var
->red
.length
= var
->green
.length
= var
->blue
.length
= 8;
1143 var
->bits_per_pixel
= 32;
1144 var
->red
.offset
= 16;
1145 var
->green
.offset
= 8;
1146 var
->blue
.offset
= 0;
1152 "mode %dx%dx%d rejected...color depth not supported.\n",
1153 var
->xres
, var
->yres
, var
->bits_per_pixel
);
1154 NVTRACE("EXIT, returning -EINVAL\n");
1159 if (!info
->monspecs
.vfmax
|| !info
->monspecs
.hfmax
||
1160 !info
->monspecs
.dclkmax
|| !fb_validate_mode(var
, info
))
1164 /* calculate modeline if supported by monitor */
1165 if (!mode_valid
&& info
->monspecs
.gtf
) {
1166 if (!fb_get_mode(FB_MAXTIMINGS
, 0, var
, info
))
1171 mode
= fb_find_best_mode(var
, &info
->modelist
);
1173 riva_update_var(var
, mode
);
1178 if (!mode_valid
&& info
->monspecs
.modedb_len
)
1181 if (var
->xres_virtual
< var
->xres
)
1182 var
->xres_virtual
= var
->xres
;
1183 if (var
->yres_virtual
<= var
->yres
)
1184 var
->yres_virtual
= -1;
1185 if (rivafb_do_maximize(info
, var
, nom
, den
) < 0)
1188 /* truncate xoffset and yoffset to maximum if too high */
1189 if (var
->xoffset
> var
->xres_virtual
- var
->xres
)
1190 var
->xoffset
= var
->xres_virtual
- var
->xres
- 1;
1192 if (var
->yoffset
> var
->yres_virtual
- var
->yres
)
1193 var
->yoffset
= var
->yres_virtual
- var
->yres
- 1;
1195 var
->red
.msb_right
=
1196 var
->green
.msb_right
=
1197 var
->blue
.msb_right
=
1198 var
->transp
.offset
= var
->transp
.length
= var
->transp
.msb_right
= 0;
1203 static int rivafb_set_par(struct fb_info
*info
)
1205 struct riva_par
*par
= info
->par
;
1209 /* vgaHWunlock() + riva unlock (0x7F) */
1210 CRTCout(par
, 0x11, 0xFF);
1211 par
->riva
.LockUnlock(&par
->riva
, 0);
1212 rc
= riva_load_video_mode(info
);
1215 if(!(info
->flags
& FBINFO_HWACCEL_DISABLED
))
1216 riva_setup_accel(info
);
1218 par
->cursor_reset
= 1;
1219 info
->fix
.line_length
= (info
->var
.xres_virtual
* (info
->var
.bits_per_pixel
>> 3));
1220 info
->fix
.visual
= (info
->var
.bits_per_pixel
== 8) ?
1221 FB_VISUAL_PSEUDOCOLOR
: FB_VISUAL_DIRECTCOLOR
;
1223 if (info
->flags
& FBINFO_HWACCEL_DISABLED
)
1224 info
->pixmap
.scan_align
= 1;
1226 info
->pixmap
.scan_align
= 4;
1234 * rivafb_pan_display
1235 * @var: standard kernel fb changeable data
1237 * @info: pointer to fb_info object containing info for current riva board
1240 * Pan (or wrap, depending on the `vmode' field) the display using the
1241 * `xoffset' and `yoffset' fields of the `var' structure.
1242 * If the values don't fit, return -EINVAL.
1244 * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
1246 static int rivafb_pan_display(struct fb_var_screeninfo
*var
,
1247 struct fb_info
*info
)
1249 struct riva_par
*par
= info
->par
;
1253 base
= var
->yoffset
* info
->fix
.line_length
+ var
->xoffset
;
1254 par
->riva
.SetStartAddress(&par
->riva
, base
);
1259 static int rivafb_blank(int blank
, struct fb_info
*info
)
1261 struct riva_par
*par
= info
->par
;
1262 unsigned char tmp
, vesa
;
1264 tmp
= SEQin(par
, 0x01) & ~0x20; /* screen on/off */
1265 vesa
= CRTCin(par
, 0x1a) & ~0xc0; /* sync on/off */
1273 case FB_BLANK_UNBLANK
:
1274 case FB_BLANK_NORMAL
:
1276 case FB_BLANK_VSYNC_SUSPEND
:
1279 case FB_BLANK_HSYNC_SUSPEND
:
1282 case FB_BLANK_POWERDOWN
:
1287 SEQout(par
, 0x01, tmp
);
1288 CRTCout(par
, 0x1a, vesa
);
1297 * @regno: register index
1298 * @red: red component
1299 * @green: green component
1300 * @blue: blue component
1301 * @transp: transparency
1302 * @info: pointer to fb_info object containing info for current riva board
1305 * Set a single color register. The values supplied have a 16 bit
1309 * Return != 0 for invalid regno.
1312 * fbcmap.c:fb_set_cmap()
1314 static int rivafb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
1315 unsigned blue
, unsigned transp
,
1316 struct fb_info
*info
)
1318 struct riva_par
*par
= info
->par
;
1319 RIVA_HW_INST
*chip
= &par
->riva
;
1322 if (regno
>= riva_get_cmap_len(&info
->var
))
1325 if (info
->var
.grayscale
) {
1326 /* gray = 0.30*R + 0.59*G + 0.11*B */
1327 red
= green
= blue
=
1328 (red
* 77 + green
* 151 + blue
* 28) >> 8;
1331 if (regno
< 16 && info
->fix
.visual
== FB_VISUAL_DIRECTCOLOR
) {
1332 ((u32
*) info
->pseudo_palette
)[regno
] =
1333 (regno
<< info
->var
.red
.offset
) |
1334 (regno
<< info
->var
.green
.offset
) |
1335 (regno
<< info
->var
.blue
.offset
);
1337 * The Riva128 2D engine requires color information in
1338 * TrueColor format even if framebuffer is in DirectColor
1340 if (par
->riva
.Architecture
== NV_ARCH_03
) {
1341 switch (info
->var
.bits_per_pixel
) {
1343 par
->palette
[regno
] = ((red
& 0xf800) >> 1) |
1344 ((green
& 0xf800) >> 6) |
1345 ((blue
& 0xf800) >> 11);
1348 par
->palette
[regno
] = ((red
& 0xff00) << 8) |
1349 ((green
& 0xff00)) |
1350 ((blue
& 0xff00) >> 8);
1356 switch (info
->var
.bits_per_pixel
) {
1358 /* "transparent" stuff is completely ignored. */
1359 riva_wclut(chip
, regno
, red
>> 8, green
>> 8, blue
>> 8);
1362 if (info
->var
.green
.length
== 5) {
1363 for (i
= 0; i
< 8; i
++) {
1364 riva_wclut(chip
, regno
*8+i
, red
>> 8,
1365 green
>> 8, blue
>> 8);
1371 for (i
= 0; i
< 8; i
++) {
1372 riva_wclut(chip
, regno
*8+i
,
1373 red
>> 8, green
>> 8,
1377 riva_rclut(chip
, regno
*4, &r
, &g
, &b
);
1378 for (i
= 0; i
< 4; i
++)
1379 riva_wclut(chip
, regno
*4+i
, r
,
1384 riva_wclut(chip
, regno
, red
>> 8, green
>> 8, blue
>> 8);
1394 * rivafb_fillrect - hardware accelerated color fill function
1395 * @info: pointer to fb_info structure
1396 * @rect: pointer to fb_fillrect structure
1399 * This function fills up a region of framebuffer memory with a solid
1400 * color with a choice of two different ROP's, copy or invert.
1405 static void rivafb_fillrect(struct fb_info
*info
, const struct fb_fillrect
*rect
)
1407 struct riva_par
*par
= info
->par
;
1408 u_int color
, rop
= 0;
1410 if ((info
->flags
& FBINFO_HWACCEL_DISABLED
)) {
1411 cfb_fillrect(info
, rect
);
1415 if (info
->var
.bits_per_pixel
== 8)
1416 color
= rect
->color
;
1418 if (par
->riva
.Architecture
!= NV_ARCH_03
)
1419 color
= ((u32
*)info
->pseudo_palette
)[rect
->color
];
1421 color
= par
->palette
[rect
->color
];
1424 switch (rect
->rop
) {
1434 riva_set_rop_solid(par
, rop
);
1436 RIVA_FIFO_FREE(par
->riva
, Bitmap
, 1);
1437 NV_WR32(&par
->riva
.Bitmap
->Color1A
, 0, color
);
1439 RIVA_FIFO_FREE(par
->riva
, Bitmap
, 2);
1440 NV_WR32(&par
->riva
.Bitmap
->UnclippedRectangle
[0].TopLeft
, 0,
1441 (rect
->dx
<< 16) | rect
->dy
);
1443 NV_WR32(&par
->riva
.Bitmap
->UnclippedRectangle
[0].WidthHeight
, 0,
1444 (rect
->width
<< 16) | rect
->height
);
1446 riva_set_rop_solid(par
, 0xcc);
1451 * rivafb_copyarea - hardware accelerated blit function
1452 * @info: pointer to fb_info structure
1453 * @region: pointer to fb_copyarea structure
1456 * This copies an area of pixels from one location to another
1461 static void rivafb_copyarea(struct fb_info
*info
, const struct fb_copyarea
*region
)
1463 struct riva_par
*par
= info
->par
;
1465 if ((info
->flags
& FBINFO_HWACCEL_DISABLED
)) {
1466 cfb_copyarea(info
, region
);
1470 RIVA_FIFO_FREE(par
->riva
, Blt
, 3);
1471 NV_WR32(&par
->riva
.Blt
->TopLeftSrc
, 0,
1472 (region
->sy
<< 16) | region
->sx
);
1473 NV_WR32(&par
->riva
.Blt
->TopLeftDst
, 0,
1474 (region
->dy
<< 16) | region
->dx
);
1476 NV_WR32(&par
->riva
.Blt
->WidthHeight
, 0,
1477 (region
->height
<< 16) | region
->width
);
1481 static inline void convert_bgcolor_16(u32
*col
)
1483 *col
= ((*col
& 0x0000F800) << 8)
1484 | ((*col
& 0x00007E0) << 5)
1485 | ((*col
& 0x0000001F) << 3)
1491 * rivafb_imageblit: hardware accelerated color expand function
1492 * @info: pointer to fb_info structure
1493 * @image: pointer to fb_image structure
1496 * If the source is a monochrome bitmap, the function fills up a a region
1497 * of framebuffer memory with pixels whose color is determined by the bit
1498 * setting of the bitmap, 1 - foreground, 0 - background.
1500 * If the source is not a monochrome bitmap, color expansion is not done.
1501 * In this case, it is channeled to a software function.
1506 static void rivafb_imageblit(struct fb_info
*info
,
1507 const struct fb_image
*image
)
1509 struct riva_par
*par
= info
->par
;
1510 u32 fgx
= 0, bgx
= 0, width
, tmp
;
1511 u8
*cdat
= (u8
*) image
->data
;
1512 volatile u32 __iomem
*d
;
1515 if ((info
->flags
& FBINFO_HWACCEL_DISABLED
) || image
->depth
!= 1) {
1516 cfb_imageblit(info
, image
);
1520 switch (info
->var
.bits_per_pixel
) {
1522 fgx
= image
->fg_color
;
1523 bgx
= image
->bg_color
;
1527 if (par
->riva
.Architecture
!= NV_ARCH_03
) {
1528 fgx
= ((u32
*)info
->pseudo_palette
)[image
->fg_color
];
1529 bgx
= ((u32
*)info
->pseudo_palette
)[image
->bg_color
];
1531 fgx
= par
->palette
[image
->fg_color
];
1532 bgx
= par
->palette
[image
->bg_color
];
1534 if (info
->var
.green
.length
== 6)
1535 convert_bgcolor_16(&bgx
);
1539 RIVA_FIFO_FREE(par
->riva
, Bitmap
, 7);
1540 NV_WR32(&par
->riva
.Bitmap
->ClipE
.TopLeft
, 0,
1541 (image
->dy
<< 16) | (image
->dx
& 0xFFFF));
1542 NV_WR32(&par
->riva
.Bitmap
->ClipE
.BottomRight
, 0,
1543 (((image
->dy
+ image
->height
) << 16) |
1544 ((image
->dx
+ image
->width
) & 0xffff)));
1545 NV_WR32(&par
->riva
.Bitmap
->Color0E
, 0, bgx
);
1546 NV_WR32(&par
->riva
.Bitmap
->Color1E
, 0, fgx
);
1547 NV_WR32(&par
->riva
.Bitmap
->WidthHeightInE
, 0,
1548 (image
->height
<< 16) | ((image
->width
+ 31) & ~31));
1549 NV_WR32(&par
->riva
.Bitmap
->WidthHeightOutE
, 0,
1550 (image
->height
<< 16) | ((image
->width
+ 31) & ~31));
1551 NV_WR32(&par
->riva
.Bitmap
->PointE
, 0,
1552 (image
->dy
<< 16) | (image
->dx
& 0xFFFF));
1554 d
= &par
->riva
.Bitmap
->MonochromeData01E
;
1556 width
= (image
->width
+ 31)/32;
1557 size
= width
* image
->height
;
1558 while (size
>= 16) {
1559 RIVA_FIFO_FREE(par
->riva
, Bitmap
, 16);
1560 for (i
= 0; i
< 16; i
++) {
1561 tmp
= *((u32
*)cdat
);
1562 cdat
= (u8
*)((u32
*)cdat
+ 1);
1563 reverse_order(&tmp
);
1564 NV_WR32(d
, i
*4, tmp
);
1569 RIVA_FIFO_FREE(par
->riva
, Bitmap
, size
);
1570 for (i
= 0; i
< size
; i
++) {
1571 tmp
= *((u32
*) cdat
);
1572 cdat
= (u8
*)((u32
*)cdat
+ 1);
1573 reverse_order(&tmp
);
1574 NV_WR32(d
, i
*4, tmp
);
1580 * rivafb_cursor - hardware cursor function
1581 * @info: pointer to info structure
1582 * @cursor: pointer to fbcursor structure
1585 * A cursor function that supports displaying a cursor image via hardware.
1586 * Within the kernel, copy and invert rops are supported. If exported
1587 * to user space, only the copy rop will be supported.
1592 static int rivafb_cursor(struct fb_info
*info
, struct fb_cursor
*cursor
)
1594 struct riva_par
*par
= info
->par
;
1595 u8 data
[MAX_CURS
* MAX_CURS
/8];
1596 int i
, set
= cursor
->set
;
1599 if (cursor
->image
.width
> MAX_CURS
|| cursor
->image
.height
> MAX_CURS
)
1602 par
->riva
.ShowHideCursor(&par
->riva
, 0);
1604 if (par
->cursor_reset
) {
1605 set
= FB_CUR_SETALL
;
1606 par
->cursor_reset
= 0;
1609 if (set
& FB_CUR_SETSIZE
)
1610 memset_io(par
->riva
.CURSOR
, 0, MAX_CURS
* MAX_CURS
* 2);
1612 if (set
& FB_CUR_SETPOS
) {
1615 yy
= cursor
->image
.dy
- info
->var
.yoffset
;
1616 xx
= cursor
->image
.dx
- info
->var
.xoffset
;
1620 NV_WR32(par
->riva
.PRAMDAC
, 0x0000300, temp
);
1624 if (set
& (FB_CUR_SETSHAPE
| FB_CUR_SETCMAP
| FB_CUR_SETIMAGE
)) {
1625 u32 bg_idx
= cursor
->image
.bg_color
;
1626 u32 fg_idx
= cursor
->image
.fg_color
;
1627 u32 s_pitch
= (cursor
->image
.width
+7) >> 3;
1628 u32 d_pitch
= MAX_CURS
/8;
1629 u8
*dat
= (u8
*) cursor
->image
.data
;
1630 u8
*msk
= (u8
*) cursor
->mask
;
1633 src
= kmalloc(s_pitch
* cursor
->image
.height
, GFP_ATOMIC
);
1636 switch (cursor
->rop
) {
1638 for (i
= 0; i
< s_pitch
* cursor
->image
.height
; i
++)
1639 src
[i
] = dat
[i
] ^ msk
[i
];
1643 for (i
= 0; i
< s_pitch
* cursor
->image
.height
; i
++)
1644 src
[i
] = dat
[i
] & msk
[i
];
1648 fb_pad_aligned_buffer(data
, d_pitch
, src
, s_pitch
,
1649 cursor
->image
.height
);
1651 bg
= ((info
->cmap
.red
[bg_idx
] & 0xf8) << 7) |
1652 ((info
->cmap
.green
[bg_idx
] & 0xf8) << 2) |
1653 ((info
->cmap
.blue
[bg_idx
] & 0xf8) >> 3) |
1656 fg
= ((info
->cmap
.red
[fg_idx
] & 0xf8) << 7) |
1657 ((info
->cmap
.green
[fg_idx
] & 0xf8) << 2) |
1658 ((info
->cmap
.blue
[fg_idx
] & 0xf8) >> 3) |
1661 par
->riva
.LockUnlock(&par
->riva
, 0);
1663 rivafb_load_cursor_image(par
, data
, bg
, fg
,
1664 cursor
->image
.width
,
1665 cursor
->image
.height
);
1671 par
->riva
.ShowHideCursor(&par
->riva
, 1);
1676 static int rivafb_sync(struct fb_info
*info
)
1678 struct riva_par
*par
= info
->par
;
1684 /* ------------------------------------------------------------------------- *
1686 * initialization helper functions
1688 * ------------------------------------------------------------------------- */
1690 /* kernel interface */
1691 static struct fb_ops riva_fb_ops
= {
1692 .owner
= THIS_MODULE
,
1693 .fb_open
= rivafb_open
,
1694 .fb_release
= rivafb_release
,
1695 .fb_check_var
= rivafb_check_var
,
1696 .fb_set_par
= rivafb_set_par
,
1697 .fb_setcolreg
= rivafb_setcolreg
,
1698 .fb_pan_display
= rivafb_pan_display
,
1699 .fb_blank
= rivafb_blank
,
1700 .fb_fillrect
= rivafb_fillrect
,
1701 .fb_copyarea
= rivafb_copyarea
,
1702 .fb_imageblit
= rivafb_imageblit
,
1703 .fb_cursor
= rivafb_cursor
,
1704 .fb_sync
= rivafb_sync
,
1707 static int riva_set_fbinfo(struct fb_info
*info
)
1709 unsigned int cmap_len
;
1710 struct riva_par
*par
= info
->par
;
1713 info
->flags
= FBINFO_DEFAULT
1714 | FBINFO_HWACCEL_XPAN
1715 | FBINFO_HWACCEL_YPAN
1716 | FBINFO_HWACCEL_COPYAREA
1717 | FBINFO_HWACCEL_FILLRECT
1718 | FBINFO_HWACCEL_IMAGEBLIT
;
1720 /* Accel seems to not work properly on NV30 yet...*/
1721 if ((par
->riva
.Architecture
== NV_ARCH_30
) || noaccel
) {
1722 printk(KERN_DEBUG PFX
"disabling acceleration\n");
1723 info
->flags
|= FBINFO_HWACCEL_DISABLED
;
1726 info
->var
= rivafb_default_var
;
1727 info
->fix
.visual
= (info
->var
.bits_per_pixel
== 8) ?
1728 FB_VISUAL_PSEUDOCOLOR
: FB_VISUAL_DIRECTCOLOR
;
1730 info
->pseudo_palette
= par
->pseudo_palette
;
1732 cmap_len
= riva_get_cmap_len(&info
->var
);
1733 fb_alloc_cmap(&info
->cmap
, cmap_len
, 0);
1735 info
->pixmap
.size
= 8 * 1024;
1736 info
->pixmap
.buf_align
= 4;
1737 info
->pixmap
.access_align
= 32;
1738 info
->pixmap
.flags
= FB_PIXMAP_SYSTEM
;
1739 info
->var
.yres_virtual
= -1;
1741 return (rivafb_check_var(&info
->var
, info
));
1744 #ifdef CONFIG_PPC_OF
1745 static int riva_get_EDID_OF(struct fb_info
*info
, struct pci_dev
*pd
)
1747 struct riva_par
*par
= info
->par
;
1748 struct device_node
*dp
;
1749 const unsigned char *pedid
= NULL
;
1750 const unsigned char *disptype
= NULL
;
1751 static char *propnames
[] = {
1752 "DFP,EDID", "LCD,EDID", "EDID", "EDID1", "EDID,B", "EDID,A", NULL
};
1756 dp
= pci_device_to_OF_node(pd
);
1757 for (; dp
!= NULL
; dp
= dp
->child
) {
1758 disptype
= of_get_property(dp
, "display-type", NULL
);
1759 if (disptype
== NULL
)
1761 if (strncmp(disptype
, "LCD", 3) != 0)
1763 for (i
= 0; propnames
[i
] != NULL
; ++i
) {
1764 pedid
= of_get_property(dp
, propnames
[i
], NULL
);
1765 if (pedid
!= NULL
) {
1766 par
->EDID
= (unsigned char *)pedid
;
1767 NVTRACE("LCD found.\n");
1775 #endif /* CONFIG_PPC_OF */
1777 #if defined(CONFIG_FB_RIVA_I2C) && !defined(CONFIG_PPC_OF)
1778 static int riva_get_EDID_i2c(struct fb_info
*info
)
1780 struct riva_par
*par
= info
->par
;
1781 struct fb_var_screeninfo var
;
1785 riva_create_i2c_busses(par
);
1786 for (i
= 0; i
< 3; i
++) {
1787 if (!par
->chan
[i
].par
)
1789 riva_probe_i2c_connector(par
, i
, &par
->EDID
);
1790 if (par
->EDID
&& !fb_parse_edid(par
->EDID
, &var
)) {
1791 printk(PFX
"Found EDID Block from BUS %i\n", i
);
1797 return (par
->EDID
) ? 1 : 0;
1799 #endif /* CONFIG_FB_RIVA_I2C */
1801 static void riva_update_default_var(struct fb_var_screeninfo
*var
,
1802 struct fb_info
*info
)
1804 struct fb_monspecs
*specs
= &info
->monspecs
;
1805 struct fb_videomode modedb
;
1808 /* respect mode options */
1810 fb_find_mode(var
, info
, mode_option
,
1811 specs
->modedb
, specs
->modedb_len
,
1813 } else if (specs
->modedb
!= NULL
) {
1814 /* get first mode in database as fallback */
1815 modedb
= specs
->modedb
[0];
1816 /* get preferred timing */
1817 if (info
->monspecs
.misc
& FB_MISC_1ST_DETAIL
) {
1820 for (i
= 0; i
< specs
->modedb_len
; i
++) {
1821 if (specs
->modedb
[i
].flag
& FB_MODE_IS_FIRST
) {
1822 modedb
= specs
->modedb
[i
];
1827 var
->bits_per_pixel
= 8;
1828 riva_update_var(var
, &modedb
);
1834 static void riva_get_EDID(struct fb_info
*info
, struct pci_dev
*pdev
)
1837 #ifdef CONFIG_PPC_OF
1838 if (!riva_get_EDID_OF(info
, pdev
))
1839 printk(PFX
"could not retrieve EDID from OF\n");
1840 #elif defined(CONFIG_FB_RIVA_I2C)
1841 if (!riva_get_EDID_i2c(info
))
1842 printk(PFX
"could not retrieve EDID from DDC/I2C\n");
1848 static void riva_get_edidinfo(struct fb_info
*info
)
1850 struct fb_var_screeninfo
*var
= &rivafb_default_var
;
1851 struct riva_par
*par
= info
->par
;
1853 fb_edid_to_monspecs(par
->EDID
, &info
->monspecs
);
1854 fb_videomode_to_modelist(info
->monspecs
.modedb
, info
->monspecs
.modedb_len
,
1856 riva_update_default_var(var
, info
);
1858 /* if user specified flatpanel, we respect that */
1859 if (info
->monspecs
.input
& FB_DISP_DDI
)
1863 /* ------------------------------------------------------------------------- *
1867 * ------------------------------------------------------------------------- */
1869 static u32
riva_get_arch(struct pci_dev
*pd
)
1873 switch (pd
->device
& 0x0ff0) {
1874 case 0x0100: /* GeForce 256 */
1875 case 0x0110: /* GeForce2 MX */
1876 case 0x0150: /* GeForce2 */
1877 case 0x0170: /* GeForce4 MX */
1878 case 0x0180: /* GeForce4 MX (8x AGP) */
1879 case 0x01A0: /* nForce */
1880 case 0x01F0: /* nForce2 */
1883 case 0x0200: /* GeForce3 */
1884 case 0x0250: /* GeForce4 Ti */
1885 case 0x0280: /* GeForce4 Ti (8x AGP) */
1888 case 0x0300: /* GeForceFX 5800 */
1889 case 0x0310: /* GeForceFX 5600 */
1890 case 0x0320: /* GeForceFX 5200 */
1891 case 0x0330: /* GeForceFX 5900 */
1892 case 0x0340: /* GeForceFX 5700 */
1895 case 0x0020: /* TNT, TNT2 */
1898 case 0x0010: /* Riva128 */
1901 default: /* unknown architecture */
1907 static int rivafb_probe(struct pci_dev
*pd
, const struct pci_device_id
*ent
)
1909 struct riva_par
*default_par
;
1910 struct fb_info
*info
;
1916 info
= framebuffer_alloc(sizeof(struct riva_par
), &pd
->dev
);
1918 printk (KERN_ERR PFX
"could not allocate memory\n");
1922 default_par
= info
->par
;
1923 default_par
->pdev
= pd
;
1925 info
->pixmap
.addr
= kzalloc(8 * 1024, GFP_KERNEL
);
1926 if (info
->pixmap
.addr
== NULL
) {
1928 goto err_framebuffer_release
;
1931 ret
= pci_enable_device(pd
);
1933 printk(KERN_ERR PFX
"cannot enable PCI device\n");
1934 goto err_free_pixmap
;
1937 ret
= pci_request_regions(pd
, "rivafb");
1939 printk(KERN_ERR PFX
"cannot request PCI regions\n");
1940 goto err_disable_device
;
1943 mutex_init(&default_par
->open_lock
);
1944 default_par
->riva
.Architecture
= riva_get_arch(pd
);
1946 default_par
->Chipset
= (pd
->vendor
<< 16) | pd
->device
;
1947 printk(KERN_INFO PFX
"nVidia device/chipset %X\n",default_par
->Chipset
);
1949 if(default_par
->riva
.Architecture
== 0) {
1950 printk(KERN_ERR PFX
"unknown NV_ARCH\n");
1952 goto err_release_region
;
1954 if(default_par
->riva
.Architecture
== NV_ARCH_10
||
1955 default_par
->riva
.Architecture
== NV_ARCH_20
||
1956 default_par
->riva
.Architecture
== NV_ARCH_30
) {
1957 sprintf(rivafb_fix
.id
, "NV%x", (pd
->device
& 0x0ff0) >> 4);
1959 sprintf(rivafb_fix
.id
, "NV%x", default_par
->riva
.Architecture
);
1962 default_par
->FlatPanel
= flatpanel
;
1964 printk(KERN_INFO PFX
"flatpanel support enabled\n");
1965 default_par
->forceCRTC
= forceCRTC
;
1967 rivafb_fix
.mmio_len
= pci_resource_len(pd
, 0);
1968 rivafb_fix
.smem_len
= pci_resource_len(pd
, 1);
1971 /* enable IO and mem if not already done */
1974 pci_read_config_word(pd
, PCI_COMMAND
, &cmd
);
1975 cmd
|= (PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
);
1976 pci_write_config_word(pd
, PCI_COMMAND
, cmd
);
1979 rivafb_fix
.mmio_start
= pci_resource_start(pd
, 0);
1980 rivafb_fix
.smem_start
= pci_resource_start(pd
, 1);
1982 default_par
->ctrl_base
= ioremap(rivafb_fix
.mmio_start
,
1983 rivafb_fix
.mmio_len
);
1984 if (!default_par
->ctrl_base
) {
1985 printk(KERN_ERR PFX
"cannot ioremap MMIO base\n");
1987 goto err_release_region
;
1990 switch (default_par
->riva
.Architecture
) {
1992 /* Riva128's PRAMIN is in the "framebuffer" space
1993 * Since these cards were never made with more than 8 megabytes
1994 * we can safely allocate this separately.
1996 default_par
->riva
.PRAMIN
= ioremap(rivafb_fix
.smem_start
+ 0x00C00000, 0x00008000);
1997 if (!default_par
->riva
.PRAMIN
) {
1998 printk(KERN_ERR PFX
"cannot ioremap PRAMIN region\n");
2000 goto err_iounmap_ctrl_base
;
2007 default_par
->riva
.PCRTC0
=
2008 (u32 __iomem
*)(default_par
->ctrl_base
+ 0x00600000);
2009 default_par
->riva
.PRAMIN
=
2010 (u32 __iomem
*)(default_par
->ctrl_base
+ 0x00710000);
2013 riva_common_setup(default_par
);
2015 if (default_par
->riva
.Architecture
== NV_ARCH_03
) {
2016 default_par
->riva
.PCRTC
= default_par
->riva
.PCRTC0
2017 = default_par
->riva
.PGRAPH
;
2020 rivafb_fix
.smem_len
= riva_get_memlen(default_par
) * 1024;
2021 default_par
->dclk_max
= riva_get_maxdclk(default_par
) * 1000;
2022 info
->screen_base
= ioremap(rivafb_fix
.smem_start
,
2023 rivafb_fix
.smem_len
);
2024 if (!info
->screen_base
) {
2025 printk(KERN_ERR PFX
"cannot ioremap FB base\n");
2027 goto err_iounmap_pramin
;
2032 default_par
->mtrr
.vram
= mtrr_add(rivafb_fix
.smem_start
,
2033 rivafb_fix
.smem_len
,
2034 MTRR_TYPE_WRCOMB
, 1);
2035 if (default_par
->mtrr
.vram
< 0) {
2036 printk(KERN_ERR PFX
"unable to setup MTRR\n");
2038 default_par
->mtrr
.vram_valid
= 1;
2039 /* let there be speed */
2040 printk(KERN_INFO PFX
"RIVA MTRR set to ON\n");
2043 #endif /* CONFIG_MTRR */
2045 info
->fbops
= &riva_fb_ops
;
2046 info
->fix
= rivafb_fix
;
2047 riva_get_EDID(info
, pd
);
2048 riva_get_edidinfo(info
);
2050 ret
=riva_set_fbinfo(info
);
2052 printk(KERN_ERR PFX
"error setting initial video mode\n");
2053 goto err_iounmap_screen_base
;
2056 fb_destroy_modedb(info
->monspecs
.modedb
);
2057 info
->monspecs
.modedb
= NULL
;
2059 pci_set_drvdata(pd
, info
);
2062 riva_bl_init(info
->par
);
2064 ret
= register_framebuffer(info
);
2067 "error registering riva framebuffer\n");
2068 goto err_iounmap_screen_base
;
2071 printk(KERN_INFO PFX
2072 "PCI nVidia %s framebuffer ver %s (%dMB @ 0x%lX)\n",
2075 info
->fix
.smem_len
/ (1024 * 1024),
2076 info
->fix
.smem_start
);
2081 err_iounmap_screen_base
:
2082 #ifdef CONFIG_FB_RIVA_I2C
2083 riva_delete_i2c_busses(info
->par
);
2085 iounmap(info
->screen_base
);
2087 if (default_par
->riva
.Architecture
== NV_ARCH_03
)
2088 iounmap(default_par
->riva
.PRAMIN
);
2089 err_iounmap_ctrl_base
:
2090 iounmap(default_par
->ctrl_base
);
2092 pci_release_regions(pd
);
2095 kfree(info
->pixmap
.addr
);
2096 err_framebuffer_release
:
2097 framebuffer_release(info
);
2102 static void rivafb_remove(struct pci_dev
*pd
)
2104 struct fb_info
*info
= pci_get_drvdata(pd
);
2105 struct riva_par
*par
= info
->par
;
2109 #ifdef CONFIG_FB_RIVA_I2C
2110 riva_delete_i2c_busses(par
);
2114 unregister_framebuffer(info
);
2119 if (par
->mtrr
.vram_valid
)
2120 mtrr_del(par
->mtrr
.vram
, info
->fix
.smem_start
,
2121 info
->fix
.smem_len
);
2122 #endif /* CONFIG_MTRR */
2124 iounmap(par
->ctrl_base
);
2125 iounmap(info
->screen_base
);
2126 if (par
->riva
.Architecture
== NV_ARCH_03
)
2127 iounmap(par
->riva
.PRAMIN
);
2128 pci_release_regions(pd
);
2129 kfree(info
->pixmap
.addr
);
2130 framebuffer_release(info
);
2134 /* ------------------------------------------------------------------------- *
2138 * ------------------------------------------------------------------------- */
2141 static int rivafb_setup(char *options
)
2146 if (!options
|| !*options
)
2149 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
2150 if (!strncmp(this_opt
, "forceCRTC", 9)) {
2154 if (!*p
|| !*(++p
)) continue;
2155 forceCRTC
= *p
- '0';
2156 if (forceCRTC
< 0 || forceCRTC
> 1)
2158 } else if (!strncmp(this_opt
, "flatpanel", 9)) {
2160 } else if (!strncmp(this_opt
, "backlight:", 10)) {
2161 backlight
= simple_strtoul(this_opt
+10, NULL
, 0);
2163 } else if (!strncmp(this_opt
, "nomtrr", 6)) {
2166 } else if (!strncmp(this_opt
, "strictmode", 10)) {
2168 } else if (!strncmp(this_opt
, "noaccel", 7)) {
2171 mode_option
= this_opt
;
2176 #endif /* !MODULE */
2178 static struct pci_driver rivafb_driver
= {
2180 .id_table
= rivafb_pci_tbl
,
2181 .probe
= rivafb_probe
,
2182 .remove
= rivafb_remove
,
2187 /* ------------------------------------------------------------------------- *
2191 * ------------------------------------------------------------------------- */
2193 static int rivafb_init(void)
2196 char *option
= NULL
;
2198 if (fb_get_options("rivafb", &option
))
2200 rivafb_setup(option
);
2202 return pci_register_driver(&rivafb_driver
);
2206 module_init(rivafb_init
);
2208 static void __exit
rivafb_exit(void)
2210 pci_unregister_driver(&rivafb_driver
);
2213 module_exit(rivafb_exit
);
2215 module_param(noaccel
, bool, 0);
2216 MODULE_PARM_DESC(noaccel
, "bool: disable acceleration");
2217 module_param(flatpanel
, int, 0);
2218 MODULE_PARM_DESC(flatpanel
, "Enables experimental flat panel support for some chipsets. (0 or 1=enabled) (default=0)");
2219 module_param(forceCRTC
, int, 0);
2220 MODULE_PARM_DESC(forceCRTC
, "Forces usage of a particular CRTC in case autodetection fails. (0 or 1) (default=autodetect)");
2222 module_param(nomtrr
, bool, 0);
2223 MODULE_PARM_DESC(nomtrr
, "Disables MTRR support (0 or 1=disabled) (default=0)");
2225 module_param(strictmode
, bool, 0);
2226 MODULE_PARM_DESC(strictmode
, "Only use video modes from EDID");
2228 MODULE_AUTHOR("Ani Joshi, maintainer");
2229 MODULE_DESCRIPTION("Framebuffer driver for nVidia Riva 128, TNT, TNT2, and the GeForce series");
2230 MODULE_LICENSE("GPL");