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/tty.h>
38 #include <linux/slab.h>
39 #include <linux/delay.h>
41 #include <linux/init.h>
42 #include <linux/pci.h>
43 #include <linux/backlight.h>
49 #include <asm/pci-bridge.h>
51 #ifdef CONFIG_PMAC_BACKLIGHT
52 #include <asm/machdep.h>
53 #include <asm/backlight.h>
59 #ifndef CONFIG_PCI /* sanity check */
60 #error This driver requires PCI support.
63 /* version number of this driver */
64 #define RIVAFB_VERSION "0.9.5b"
66 /* ------------------------------------------------------------------------- *
68 * various helpful macros and constants
70 * ------------------------------------------------------------------------- */
71 #ifdef CONFIG_FB_RIVA_DEBUG
72 #define NVTRACE printk
74 #define NVTRACE if(0) printk
77 #define NVTRACE_ENTER(...) NVTRACE("%s START\n", __FUNCTION__)
78 #define NVTRACE_LEAVE(...) NVTRACE("%s END\n", __FUNCTION__)
80 #ifdef CONFIG_FB_RIVA_DEBUG
81 #define assert(expr) \
83 printk( "Assertion failed! %s,%s,%s,line=%d\n",\
84 #expr,__FILE__,__FUNCTION__,__LINE__); \
91 #define PFX "rivafb: "
93 /* macro that allows you to set overflow bits */
94 #define SetBitField(value,from,to) SetBF(to,GetBF(value,from))
95 #define SetBit(n) (1<<(n))
96 #define Set8Bits(value) ((value)&0xff)
98 /* HW cursor parameters */
101 /* ------------------------------------------------------------------------- *
105 * ------------------------------------------------------------------------- */
107 static int rivafb_blank(int blank
, struct fb_info
*info
);
109 /* ------------------------------------------------------------------------- *
111 * card identification
113 * ------------------------------------------------------------------------- */
115 static struct pci_device_id rivafb_pci_tbl
[] = {
116 { PCI_VENDOR_ID_NVIDIA_SGS
, PCI_DEVICE_ID_NVIDIA_SGS_RIVA128
,
117 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
118 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_TNT
,
119 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
120 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_TNT2
,
121 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
122 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_UTNT2
,
123 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
124 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_VTNT2
,
125 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
126 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_UVTNT2
,
127 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
128 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_ITNT2
,
129 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
130 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE_SDR
,
131 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
132 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE_DDR
,
133 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
134 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_QUADRO
,
135 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
136 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE2_MX
,
137 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
138 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE2_MX2
,
139 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
140 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE2_GO
,
141 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
142 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_QUADRO2_MXR
,
143 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
144 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE2_GTS
,
145 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
146 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE2_GTS2
,
147 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
148 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE2_ULTRA
,
149 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
150 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_QUADRO2_PRO
,
151 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
152 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE4_MX_460
,
153 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
154 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE4_MX_440
,
155 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
156 // NF2/IGP version, GeForce 4 MX, NV18
157 { PCI_VENDOR_ID_NVIDIA
, 0x01f0,
158 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
159 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE4_MX_420
,
160 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
161 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE4_440_GO
,
162 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
163 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE4_420_GO
,
164 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
165 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE4_420_GO_M32
,
166 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
167 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_QUADRO4_500XGL
,
168 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
169 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE4_440_GO_M64
,
170 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
171 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_QUADRO4_200
,
172 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
173 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_QUADRO4_550XGL
,
174 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
175 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_QUADRO4_500_GOGL
,
176 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
177 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_IGEFORCE2
,
178 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
179 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE3
,
180 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
181 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE3_1
,
182 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
183 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE3_2
,
184 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
185 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_QUADRO_DDC
,
186 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
187 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE4_TI_4600
,
188 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
189 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE4_TI_4400
,
190 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
191 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE4_TI_4200
,
192 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
193 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_QUADRO4_900XGL
,
194 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
195 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_QUADRO4_750XGL
,
196 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
197 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_QUADRO4_700XGL
,
198 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
199 { PCI_VENDOR_ID_NVIDIA
, PCI_DEVICE_ID_NVIDIA_GEFORCE_FX_GO_5200
,
200 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
201 { 0, } /* terminate list */
203 MODULE_DEVICE_TABLE(pci
, rivafb_pci_tbl
);
205 /* ------------------------------------------------------------------------- *
209 * ------------------------------------------------------------------------- */
211 /* command line data, set in rivafb_setup() */
212 static int flatpanel __devinitdata
= -1; /* Autodetect later */
213 static int forceCRTC __devinitdata
= -1;
214 static int noaccel __devinitdata
= 0;
216 static int nomtrr __devinitdata
= 0;
219 static char *mode_option __devinitdata
= NULL
;
220 static int strictmode
= 0;
222 static struct fb_fix_screeninfo __devinitdata rivafb_fix
= {
223 .type
= FB_TYPE_PACKED_PIXELS
,
228 static struct fb_var_screeninfo __devinitdata rivafb_default_var
= {
238 .activate
= FB_ACTIVATE_NOW
,
248 .vmode
= FB_VMODE_NONINTERLACED
252 static const struct riva_regs reg_template
= {
253 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* ATTR */
254 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
255 0x41, 0x01, 0x0F, 0x00, 0x00},
256 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* CRT */
257 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE3, /* 0x10 */
259 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
260 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20 */
261 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
262 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30 */
263 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
266 {0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, /* GRA */
268 {0x03, 0x01, 0x0F, 0x00, 0x0E}, /* SEQ */
275 #ifdef CONFIG_FB_RIVA_BACKLIGHT
276 /* We do not have any information about which values are allowed, thus
277 * we used safe values.
279 #define MIN_LEVEL 0x158
280 #define MAX_LEVEL 0x534
282 static struct backlight_properties riva_bl_data
;
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 mutex_lock(&info
->bl_mutex
);
292 nlevel
= info
->bl_curve
[level
] * FB_BACKLIGHT_MAX
/ MAX_LEVEL
;
293 mutex_unlock(&info
->bl_mutex
);
297 else if (nlevel
< MIN_LEVEL
)
299 else if (nlevel
> MAX_LEVEL
)
305 static int riva_bl_update_status(struct backlight_device
*bd
)
307 struct riva_par
*par
= class_get_devdata(&bd
->class_dev
);
308 U032 tmp_pcrt
, tmp_pmc
;
311 if (bd
->props
->power
!= FB_BLANK_UNBLANK
||
312 bd
->props
->fb_blank
!= FB_BLANK_UNBLANK
)
315 level
= bd
->props
->brightness
;
317 tmp_pmc
= par
->riva
.PMC
[0x10F0/4] & 0x0000FFFF;
318 tmp_pcrt
= par
->riva
.PCRTC0
[0x081C/4] & 0xFFFFFFFC;
321 tmp_pmc
|= (1 << 31); /* backlight bit */
322 tmp_pmc
|= riva_bl_get_level_brightness(par
, level
) << 16; /* level */
324 par
->riva
.PCRTC0
[0x081C/4] = tmp_pcrt
;
325 par
->riva
.PMC
[0x10F0/4] = tmp_pmc
;
330 static int riva_bl_get_brightness(struct backlight_device
*bd
)
332 return bd
->props
->brightness
;
335 static struct backlight_properties riva_bl_data
= {
336 .owner
= THIS_MODULE
,
337 .get_brightness
= riva_bl_get_brightness
,
338 .update_status
= riva_bl_update_status
,
339 .max_brightness
= (FB_BACKLIGHT_LEVELS
- 1),
342 static void riva_bl_init(struct riva_par
*par
)
344 struct fb_info
*info
= pci_get_drvdata(par
->pdev
);
345 struct backlight_device
*bd
;
351 #ifdef CONFIG_PMAC_BACKLIGHT
352 if (!machine_is(powermac
) ||
353 !pmac_has_backlight_type("mnca"))
357 snprintf(name
, sizeof(name
), "rivabl%d", info
->node
);
359 bd
= backlight_device_register(name
, par
, &riva_bl_data
);
362 printk("riva: Backlight registration failed\n");
366 mutex_lock(&info
->bl_mutex
);
368 fb_bl_default_curve(info
, 0,
369 0x158 * FB_BACKLIGHT_MAX
/ MAX_LEVEL
,
370 0x534 * FB_BACKLIGHT_MAX
/ MAX_LEVEL
);
371 mutex_unlock(&info
->bl_mutex
);
374 bd
->props
->brightness
= riva_bl_data
.max_brightness
;
375 bd
->props
->power
= FB_BLANK_UNBLANK
;
376 bd
->props
->update_status(bd
);
379 #ifdef CONFIG_PMAC_BACKLIGHT
380 mutex_lock(&pmac_backlight_mutex
);
383 mutex_unlock(&pmac_backlight_mutex
);
386 printk("riva: Backlight initialized (%s)\n", name
);
394 static void riva_bl_exit(struct riva_par
*par
)
396 struct fb_info
*info
= pci_get_drvdata(par
->pdev
);
398 #ifdef CONFIG_PMAC_BACKLIGHT
399 mutex_lock(&pmac_backlight_mutex
);
402 mutex_lock(&info
->bl_mutex
);
404 #ifdef CONFIG_PMAC_BACKLIGHT
405 if (pmac_backlight
== info
->bl_dev
)
406 pmac_backlight
= NULL
;
409 backlight_device_unregister(info
->bl_dev
);
411 printk("riva: Backlight unloaded\n");
413 mutex_unlock(&info
->bl_mutex
);
415 #ifdef CONFIG_PMAC_BACKLIGHT
416 mutex_unlock(&pmac_backlight_mutex
);
420 static inline void riva_bl_init(struct riva_par
*par
) {}
421 static inline void riva_bl_exit(struct riva_par
*par
) {}
422 #endif /* CONFIG_FB_RIVA_BACKLIGHT */
424 /* ------------------------------------------------------------------------- *
428 * ------------------------------------------------------------------------- */
430 static inline void CRTCout(struct riva_par
*par
, unsigned char index
,
433 VGA_WR08(par
->riva
.PCIO
, 0x3d4, index
);
434 VGA_WR08(par
->riva
.PCIO
, 0x3d5, val
);
437 static inline unsigned char CRTCin(struct riva_par
*par
,
440 VGA_WR08(par
->riva
.PCIO
, 0x3d4, index
);
441 return (VGA_RD08(par
->riva
.PCIO
, 0x3d5));
444 static inline void GRAout(struct riva_par
*par
, unsigned char index
,
447 VGA_WR08(par
->riva
.PVIO
, 0x3ce, index
);
448 VGA_WR08(par
->riva
.PVIO
, 0x3cf, val
);
451 static inline unsigned char GRAin(struct riva_par
*par
,
454 VGA_WR08(par
->riva
.PVIO
, 0x3ce, index
);
455 return (VGA_RD08(par
->riva
.PVIO
, 0x3cf));
458 static inline void SEQout(struct riva_par
*par
, unsigned char index
,
461 VGA_WR08(par
->riva
.PVIO
, 0x3c4, index
);
462 VGA_WR08(par
->riva
.PVIO
, 0x3c5, val
);
465 static inline unsigned char SEQin(struct riva_par
*par
,
468 VGA_WR08(par
->riva
.PVIO
, 0x3c4, index
);
469 return (VGA_RD08(par
->riva
.PVIO
, 0x3c5));
472 static inline void ATTRout(struct riva_par
*par
, unsigned char index
,
475 VGA_WR08(par
->riva
.PCIO
, 0x3c0, index
);
476 VGA_WR08(par
->riva
.PCIO
, 0x3c0, val
);
479 static inline unsigned char ATTRin(struct riva_par
*par
,
482 VGA_WR08(par
->riva
.PCIO
, 0x3c0, index
);
483 return (VGA_RD08(par
->riva
.PCIO
, 0x3c1));
486 static inline void MISCout(struct riva_par
*par
, unsigned char val
)
488 VGA_WR08(par
->riva
.PVIO
, 0x3c2, val
);
491 static inline unsigned char MISCin(struct riva_par
*par
)
493 return (VGA_RD08(par
->riva
.PVIO
, 0x3cc));
496 static u8 byte_rev
[256] = {
497 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
498 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
499 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
500 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
501 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
502 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
503 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
504 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
505 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
506 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
507 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
508 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
509 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
510 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
511 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
512 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
513 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
514 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
515 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
516 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
517 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
518 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
519 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
520 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
521 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
522 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
523 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
524 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
525 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
526 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
527 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
528 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,
531 static inline void reverse_order(u32
*l
)
534 *a
= byte_rev
[*a
], a
++;
535 *a
= byte_rev
[*a
], a
++;
536 *a
= byte_rev
[*a
], a
++;
540 /* ------------------------------------------------------------------------- *
544 * ------------------------------------------------------------------------- */
547 * rivafb_load_cursor_image - load cursor image to hardware
548 * @data: address to monochrome bitmap (1 = foreground color, 0 = background)
549 * @par: pointer to private data
550 * @w: width of cursor image in pixels
551 * @h: height of cursor image in scanlines
552 * @bg: background color (ARGB1555) - alpha bit determines opacity
553 * @fg: foreground color (ARGB1555)
556 * Loads cursor image based on a monochrome source and mask bitmap. The
557 * image bits determines the color of the pixel, 0 for background, 1 for
558 * foreground. Only the affected region (as determined by @w and @h
559 * parameters) will be updated.
564 static void rivafb_load_cursor_image(struct riva_par
*par
, u8
*data8
,
565 u16 bg
, u16 fg
, u32 w
, u32 h
)
569 u32
*data
= (u32
*)data8
;
570 bg
= le16_to_cpu(bg
);
571 fg
= le16_to_cpu(fg
);
575 for (i
= 0; i
< h
; i
++) {
579 for (j
= 0; j
< w
/2; j
++) {
581 #if defined (__BIG_ENDIAN)
582 tmp
= (b
& (1 << 31)) ? fg
<< 16 : bg
<< 16;
584 tmp
|= (b
& (1 << 31)) ? fg
: bg
;
587 tmp
= (b
& 1) ? fg
: bg
;
589 tmp
|= (b
& 1) ? fg
<< 16 : bg
<< 16;
592 writel(tmp
, &par
->riva
.CURSOR
[k
++]);
594 k
+= (MAX_CURS
- w
)/2;
598 /* ------------------------------------------------------------------------- *
600 * general utility functions
602 * ------------------------------------------------------------------------- */
605 * riva_wclut - set CLUT entry
606 * @chip: pointer to RIVA_HW_INST object
607 * @regnum: register number
608 * @red: red component
609 * @green: green component
610 * @blue: blue component
613 * Sets color register @regnum.
618 static void riva_wclut(RIVA_HW_INST
*chip
,
619 unsigned char regnum
, unsigned char red
,
620 unsigned char green
, unsigned char blue
)
622 VGA_WR08(chip
->PDIO
, 0x3c8, regnum
);
623 VGA_WR08(chip
->PDIO
, 0x3c9, red
);
624 VGA_WR08(chip
->PDIO
, 0x3c9, green
);
625 VGA_WR08(chip
->PDIO
, 0x3c9, blue
);
629 * riva_rclut - read fromCLUT register
630 * @chip: pointer to RIVA_HW_INST object
631 * @regnum: register number
632 * @red: red component
633 * @green: green component
634 * @blue: blue component
637 * Reads red, green, and blue from color register @regnum.
642 static void riva_rclut(RIVA_HW_INST
*chip
,
643 unsigned char regnum
, unsigned char *red
,
644 unsigned char *green
, unsigned char *blue
)
647 VGA_WR08(chip
->PDIO
, 0x3c7, regnum
);
648 *red
= VGA_RD08(chip
->PDIO
, 0x3c9);
649 *green
= VGA_RD08(chip
->PDIO
, 0x3c9);
650 *blue
= VGA_RD08(chip
->PDIO
, 0x3c9);
654 * riva_save_state - saves current chip state
655 * @par: pointer to riva_par object containing info for current riva board
656 * @regs: pointer to riva_regs object
659 * Saves current chip state to @regs.
665 static void riva_save_state(struct riva_par
*par
, struct riva_regs
*regs
)
670 par
->riva
.LockUnlock(&par
->riva
, 0);
672 par
->riva
.UnloadStateExt(&par
->riva
, ®s
->ext
);
674 regs
->misc_output
= MISCin(par
);
676 for (i
= 0; i
< NUM_CRT_REGS
; i
++)
677 regs
->crtc
[i
] = CRTCin(par
, i
);
679 for (i
= 0; i
< NUM_ATC_REGS
; i
++)
680 regs
->attr
[i
] = ATTRin(par
, i
);
682 for (i
= 0; i
< NUM_GRC_REGS
; i
++)
683 regs
->gra
[i
] = GRAin(par
, i
);
685 for (i
= 0; i
< NUM_SEQ_REGS
; i
++)
686 regs
->seq
[i
] = SEQin(par
, i
);
691 * riva_load_state - loads current chip state
692 * @par: pointer to riva_par object containing info for current riva board
693 * @regs: pointer to riva_regs object
696 * Loads chip state from @regs.
699 * riva_load_video_mode()
704 static void riva_load_state(struct riva_par
*par
, struct riva_regs
*regs
)
706 RIVA_HW_STATE
*state
= ®s
->ext
;
710 CRTCout(par
, 0x11, 0x00);
712 par
->riva
.LockUnlock(&par
->riva
, 0);
714 par
->riva
.LoadStateExt(&par
->riva
, state
);
716 MISCout(par
, regs
->misc_output
);
718 for (i
= 0; i
< NUM_CRT_REGS
; i
++) {
724 CRTCout(par
, i
, regs
->crtc
[i
]);
728 for (i
= 0; i
< NUM_ATC_REGS
; i
++)
729 ATTRout(par
, i
, regs
->attr
[i
]);
731 for (i
= 0; i
< NUM_GRC_REGS
; i
++)
732 GRAout(par
, i
, regs
->gra
[i
]);
734 for (i
= 0; i
< NUM_SEQ_REGS
; i
++)
735 SEQout(par
, i
, regs
->seq
[i
]);
740 * riva_load_video_mode - calculate timings
741 * @info: pointer to fb_info object containing info for current riva board
744 * Calculate some timings and then send em off to riva_load_state().
749 static void riva_load_video_mode(struct fb_info
*info
)
751 int bpp
, width
, hDisplaySize
, hDisplay
, hStart
,
752 hEnd
, hTotal
, height
, vDisplay
, vStart
, vEnd
, vTotal
, dotClock
;
753 int hBlankStart
, hBlankEnd
, vBlankStart
, vBlankEnd
;
754 struct riva_par
*par
= info
->par
;
755 struct riva_regs newmode
;
758 /* time to calculate */
759 rivafb_blank(1, info
);
761 bpp
= info
->var
.bits_per_pixel
;
762 if (bpp
== 16 && info
->var
.green
.length
== 5)
764 width
= info
->var
.xres_virtual
;
765 hDisplaySize
= info
->var
.xres
;
766 hDisplay
= (hDisplaySize
/ 8) - 1;
767 hStart
= (hDisplaySize
+ info
->var
.right_margin
) / 8 - 1;
768 hEnd
= (hDisplaySize
+ info
->var
.right_margin
+
769 info
->var
.hsync_len
) / 8 - 1;
770 hTotal
= (hDisplaySize
+ info
->var
.right_margin
+
771 info
->var
.hsync_len
+ info
->var
.left_margin
) / 8 - 5;
772 hBlankStart
= hDisplay
;
773 hBlankEnd
= hTotal
+ 4;
775 height
= info
->var
.yres_virtual
;
776 vDisplay
= info
->var
.yres
- 1;
777 vStart
= info
->var
.yres
+ info
->var
.lower_margin
- 1;
778 vEnd
= info
->var
.yres
+ info
->var
.lower_margin
+
779 info
->var
.vsync_len
- 1;
780 vTotal
= info
->var
.yres
+ info
->var
.lower_margin
+
781 info
->var
.vsync_len
+ info
->var
.upper_margin
+ 2;
782 vBlankStart
= vDisplay
;
783 vBlankEnd
= vTotal
+ 1;
784 dotClock
= 1000000000 / info
->var
.pixclock
;
786 memcpy(&newmode
, ®_template
, sizeof(struct riva_regs
));
788 if ((info
->var
.vmode
& FB_VMODE_MASK
) == FB_VMODE_INTERLACED
)
791 if (par
->FlatPanel
) {
794 vBlankStart
= vStart
;
797 hBlankEnd
= hTotal
+ 4;
800 newmode
.crtc
[0x0] = Set8Bits (hTotal
);
801 newmode
.crtc
[0x1] = Set8Bits (hDisplay
);
802 newmode
.crtc
[0x2] = Set8Bits (hBlankStart
);
803 newmode
.crtc
[0x3] = SetBitField (hBlankEnd
, 4: 0, 4:0) | SetBit (7);
804 newmode
.crtc
[0x4] = Set8Bits (hStart
);
805 newmode
.crtc
[0x5] = SetBitField (hBlankEnd
, 5: 5, 7:7)
806 | SetBitField (hEnd
, 4: 0, 4:0);
807 newmode
.crtc
[0x6] = SetBitField (vTotal
, 7: 0, 7:0);
808 newmode
.crtc
[0x7] = SetBitField (vTotal
, 8: 8, 0:0)
809 | SetBitField (vDisplay
, 8: 8, 1:1)
810 | SetBitField (vStart
, 8: 8, 2:2)
811 | SetBitField (vBlankStart
, 8: 8, 3:3)
813 | SetBitField (vTotal
, 9: 9, 5:5)
814 | SetBitField (vDisplay
, 9: 9, 6:6)
815 | SetBitField (vStart
, 9: 9, 7:7);
816 newmode
.crtc
[0x9] = SetBitField (vBlankStart
, 9: 9, 5:5)
818 newmode
.crtc
[0x10] = Set8Bits (vStart
);
819 newmode
.crtc
[0x11] = SetBitField (vEnd
, 3: 0, 3:0)
821 newmode
.crtc
[0x12] = Set8Bits (vDisplay
);
822 newmode
.crtc
[0x13] = (width
/ 8) * ((bpp
+ 1) / 8);
823 newmode
.crtc
[0x15] = Set8Bits (vBlankStart
);
824 newmode
.crtc
[0x16] = Set8Bits (vBlankEnd
);
826 newmode
.ext
.screen
= SetBitField(hBlankEnd
,6:6,4:4)
827 | SetBitField(vBlankStart
,10:10,3:3)
828 | SetBitField(vStart
,10:10,2:2)
829 | SetBitField(vDisplay
,10:10,1:1)
830 | SetBitField(vTotal
,10:10,0:0);
831 newmode
.ext
.horiz
= SetBitField(hTotal
,8:8,0:0)
832 | SetBitField(hDisplay
,8:8,1:1)
833 | SetBitField(hBlankStart
,8:8,2:2)
834 | SetBitField(hStart
,8:8,3:3);
835 newmode
.ext
.extra
= SetBitField(vTotal
,11:11,0:0)
836 | SetBitField(vDisplay
,11:11,2:2)
837 | SetBitField(vStart
,11:11,4:4)
838 | SetBitField(vBlankStart
,11:11,6:6);
840 if ((info
->var
.vmode
& FB_VMODE_MASK
) == FB_VMODE_INTERLACED
) {
841 int tmp
= (hTotal
>> 1) & ~1;
842 newmode
.ext
.interlace
= Set8Bits(tmp
);
843 newmode
.ext
.horiz
|= SetBitField(tmp
, 8:8,4:4);
845 newmode
.ext
.interlace
= 0xff; /* interlace off */
847 if (par
->riva
.Architecture
>= NV_ARCH_10
)
848 par
->riva
.CURSOR
= (U032 __iomem
*)(info
->screen_base
+ par
->riva
.CursorStart
);
850 if (info
->var
.sync
& FB_SYNC_HOR_HIGH_ACT
)
851 newmode
.misc_output
&= ~0x40;
853 newmode
.misc_output
|= 0x40;
854 if (info
->var
.sync
& FB_SYNC_VERT_HIGH_ACT
)
855 newmode
.misc_output
&= ~0x80;
857 newmode
.misc_output
|= 0x80;
859 par
->riva
.CalcStateExt(&par
->riva
, &newmode
.ext
, bpp
, width
,
860 hDisplaySize
, height
, dotClock
);
862 newmode
.ext
.scale
= NV_RD32(par
->riva
.PRAMDAC
, 0x00000848) &
864 if (par
->FlatPanel
== 1) {
865 newmode
.ext
.pixel
|= (1 << 7);
866 newmode
.ext
.scale
|= (1 << 8);
868 if (par
->SecondCRTC
) {
869 newmode
.ext
.head
= NV_RD32(par
->riva
.PCRTC0
, 0x00000860) &
871 newmode
.ext
.head2
= NV_RD32(par
->riva
.PCRTC0
, 0x00002860) |
873 newmode
.ext
.crtcOwner
= 3;
874 newmode
.ext
.pllsel
|= 0x20000800;
875 newmode
.ext
.vpll2
= newmode
.ext
.vpll
;
876 } else if (par
->riva
.twoHeads
) {
877 newmode
.ext
.head
= NV_RD32(par
->riva
.PCRTC0
, 0x00000860) |
879 newmode
.ext
.head2
= NV_RD32(par
->riva
.PCRTC0
, 0x00002860) &
881 newmode
.ext
.crtcOwner
= 0;
882 newmode
.ext
.vpll2
= NV_RD32(par
->riva
.PRAMDAC0
, 0x00000520);
884 if (par
->FlatPanel
== 1) {
885 newmode
.ext
.pixel
|= (1 << 7);
886 newmode
.ext
.scale
|= (1 << 8);
888 newmode
.ext
.cursorConfig
= 0x02000100;
889 par
->current_state
= newmode
;
890 riva_load_state(par
, &par
->current_state
);
891 par
->riva
.LockUnlock(&par
->riva
, 0); /* important for HW cursor */
892 rivafb_blank(0, info
);
896 static void riva_update_var(struct fb_var_screeninfo
*var
, struct fb_videomode
*modedb
)
899 var
->xres
= var
->xres_virtual
= modedb
->xres
;
900 var
->yres
= modedb
->yres
;
901 if (var
->yres_virtual
< var
->yres
)
902 var
->yres_virtual
= var
->yres
;
903 var
->xoffset
= var
->yoffset
= 0;
904 var
->pixclock
= modedb
->pixclock
;
905 var
->left_margin
= modedb
->left_margin
;
906 var
->right_margin
= modedb
->right_margin
;
907 var
->upper_margin
= modedb
->upper_margin
;
908 var
->lower_margin
= modedb
->lower_margin
;
909 var
->hsync_len
= modedb
->hsync_len
;
910 var
->vsync_len
= modedb
->vsync_len
;
911 var
->sync
= modedb
->sync
;
912 var
->vmode
= modedb
->vmode
;
917 * rivafb_do_maximize -
918 * @info: pointer to fb_info object containing info for current riva board
927 * -EINVAL on failure, 0 on success
933 static int rivafb_do_maximize(struct fb_info
*info
,
934 struct fb_var_screeninfo
*var
,
950 /* use highest possible virtual resolution */
951 if (var
->xres_virtual
== -1 && var
->yres_virtual
== -1) {
952 printk(KERN_WARNING PFX
953 "using maximum available virtual resolution\n");
954 for (i
= 0; modes
[i
].xres
!= -1; i
++) {
955 if (modes
[i
].xres
* nom
/ den
* modes
[i
].yres
<
959 if (modes
[i
].xres
== -1) {
961 "could not find a virtual resolution that fits into video memory!!\n");
962 NVTRACE("EXIT - EINVAL error\n");
965 var
->xres_virtual
= modes
[i
].xres
;
966 var
->yres_virtual
= modes
[i
].yres
;
969 "virtual resolution set to maximum of %dx%d\n",
970 var
->xres_virtual
, var
->yres_virtual
);
971 } else if (var
->xres_virtual
== -1) {
972 var
->xres_virtual
= (info
->fix
.smem_len
* den
/
973 (nom
* var
->yres_virtual
)) & ~15;
974 printk(KERN_WARNING PFX
975 "setting virtual X resolution to %d\n", var
->xres_virtual
);
976 } else if (var
->yres_virtual
== -1) {
977 var
->xres_virtual
= (var
->xres_virtual
+ 15) & ~15;
978 var
->yres_virtual
= info
->fix
.smem_len
* den
/
979 (nom
* var
->xres_virtual
);
980 printk(KERN_WARNING PFX
981 "setting virtual Y resolution to %d\n", var
->yres_virtual
);
983 var
->xres_virtual
= (var
->xres_virtual
+ 15) & ~15;
984 if (var
->xres_virtual
* nom
/ den
* var
->yres_virtual
> info
->fix
.smem_len
) {
986 "mode %dx%dx%d rejected...resolution too high to fit into video memory!\n",
987 var
->xres
, var
->yres
, var
->bits_per_pixel
);
988 NVTRACE("EXIT - EINVAL error\n");
993 if (var
->xres_virtual
* nom
/ den
>= 8192) {
994 printk(KERN_WARNING PFX
995 "virtual X resolution (%d) is too high, lowering to %d\n",
996 var
->xres_virtual
, 8192 * den
/ nom
- 16);
997 var
->xres_virtual
= 8192 * den
/ nom
- 16;
1000 if (var
->xres_virtual
< var
->xres
) {
1002 "virtual X resolution (%d) is smaller than real\n", var
->xres_virtual
);
1006 if (var
->yres_virtual
< var
->yres
) {
1008 "virtual Y resolution (%d) is smaller than real\n", var
->yres_virtual
);
1011 if (var
->yres_virtual
> 0x7fff/nom
)
1012 var
->yres_virtual
= 0x7fff/nom
;
1013 if (var
->xres_virtual
> 0x7fff/nom
)
1014 var
->xres_virtual
= 0x7fff/nom
;
1020 riva_set_pattern(struct riva_par
*par
, int clr0
, int clr1
, int pat0
, int pat1
)
1022 RIVA_FIFO_FREE(par
->riva
, Patt
, 4);
1023 NV_WR32(&par
->riva
.Patt
->Color0
, 0, clr0
);
1024 NV_WR32(&par
->riva
.Patt
->Color1
, 0, clr1
);
1025 NV_WR32(par
->riva
.Patt
->Monochrome
, 0, pat0
);
1026 NV_WR32(par
->riva
.Patt
->Monochrome
, 4, pat1
);
1029 /* acceleration routines */
1030 static inline void wait_for_idle(struct riva_par
*par
)
1032 while (par
->riva
.Busy(&par
->riva
));
1036 * Set ROP. Translate X rop into ROP3. Internal routine.
1039 riva_set_rop_solid(struct riva_par
*par
, int rop
)
1041 riva_set_pattern(par
, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
1042 RIVA_FIFO_FREE(par
->riva
, Rop
, 1);
1043 NV_WR32(&par
->riva
.Rop
->Rop3
, 0, rop
);
1047 static void riva_setup_accel(struct fb_info
*info
)
1049 struct riva_par
*par
= info
->par
;
1051 RIVA_FIFO_FREE(par
->riva
, Clip
, 2);
1052 NV_WR32(&par
->riva
.Clip
->TopLeft
, 0, 0x0);
1053 NV_WR32(&par
->riva
.Clip
->WidthHeight
, 0,
1054 (info
->var
.xres_virtual
& 0xffff) |
1055 (info
->var
.yres_virtual
<< 16));
1056 riva_set_rop_solid(par
, 0xcc);
1061 * riva_get_cmap_len - query current color map length
1062 * @var: standard kernel fb changeable data
1065 * Get current color map length.
1068 * Length of color map
1071 * rivafb_setcolreg()
1073 static int riva_get_cmap_len(const struct fb_var_screeninfo
*var
)
1075 int rc
= 256; /* reasonable default */
1077 switch (var
->green
.length
) {
1079 rc
= 256; /* 256 entries (2^8), 8 bpp and RGB8888 */
1082 rc
= 32; /* 32 entries (2^5), 16 bpp, RGB555 */
1085 rc
= 64; /* 64 entries (2^6), 16 bpp, RGB565 */
1088 /* should not occur */
1094 /* ------------------------------------------------------------------------- *
1096 * framebuffer operations
1098 * ------------------------------------------------------------------------- */
1100 static int rivafb_open(struct fb_info
*info
, int user
)
1102 struct riva_par
*par
= info
->par
;
1103 int cnt
= atomic_read(&par
->ref_count
);
1108 memset(&par
->state
, 0, sizeof(struct vgastate
));
1109 par
->state
.flags
= VGA_SAVE_MODE
| VGA_SAVE_FONTS
;
1110 /* save the DAC for Riva128 */
1111 if (par
->riva
.Architecture
== NV_ARCH_03
)
1112 par
->state
.flags
|= VGA_SAVE_CMAP
;
1113 save_vga(&par
->state
);
1115 /* vgaHWunlock() + riva unlock (0x7F) */
1116 CRTCout(par
, 0x11, 0xFF);
1117 par
->riva
.LockUnlock(&par
->riva
, 0);
1119 riva_save_state(par
, &par
->initial_state
);
1121 atomic_inc(&par
->ref_count
);
1126 static int rivafb_release(struct fb_info
*info
, int user
)
1128 struct riva_par
*par
= info
->par
;
1129 int cnt
= atomic_read(&par
->ref_count
);
1135 par
->riva
.LockUnlock(&par
->riva
, 0);
1136 par
->riva
.LoadStateExt(&par
->riva
, &par
->initial_state
.ext
);
1137 riva_load_state(par
, &par
->initial_state
);
1139 restore_vga(&par
->state
);
1141 par
->riva
.LockUnlock(&par
->riva
, 1);
1143 atomic_dec(&par
->ref_count
);
1148 static int rivafb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
1150 struct fb_videomode
*mode
;
1151 struct riva_par
*par
= info
->par
;
1152 int nom
, den
; /* translating from pixels->bytes */
1156 switch (var
->bits_per_pixel
) {
1158 var
->red
.offset
= var
->green
.offset
= var
->blue
.offset
= 0;
1159 var
->red
.length
= var
->green
.length
= var
->blue
.length
= 8;
1160 var
->bits_per_pixel
= 8;
1164 var
->green
.length
= 5;
1167 var
->bits_per_pixel
= 16;
1168 /* The Riva128 supports RGB555 only */
1169 if (par
->riva
.Architecture
== NV_ARCH_03
)
1170 var
->green
.length
= 5;
1171 if (var
->green
.length
== 5) {
1172 /* 0rrrrrgg gggbbbbb */
1173 var
->red
.offset
= 10;
1174 var
->green
.offset
= 5;
1175 var
->blue
.offset
= 0;
1176 var
->red
.length
= 5;
1177 var
->green
.length
= 5;
1178 var
->blue
.length
= 5;
1180 /* rrrrrggg gggbbbbb */
1181 var
->red
.offset
= 11;
1182 var
->green
.offset
= 5;
1183 var
->blue
.offset
= 0;
1184 var
->red
.length
= 5;
1185 var
->green
.length
= 6;
1186 var
->blue
.length
= 5;
1192 var
->red
.length
= var
->green
.length
= var
->blue
.length
= 8;
1193 var
->bits_per_pixel
= 32;
1194 var
->red
.offset
= 16;
1195 var
->green
.offset
= 8;
1196 var
->blue
.offset
= 0;
1202 "mode %dx%dx%d rejected...color depth not supported.\n",
1203 var
->xres
, var
->yres
, var
->bits_per_pixel
);
1204 NVTRACE("EXIT, returning -EINVAL\n");
1209 if (!info
->monspecs
.vfmax
|| !info
->monspecs
.hfmax
||
1210 !info
->monspecs
.dclkmax
|| !fb_validate_mode(var
, info
))
1214 /* calculate modeline if supported by monitor */
1215 if (!mode_valid
&& info
->monspecs
.gtf
) {
1216 if (!fb_get_mode(FB_MAXTIMINGS
, 0, var
, info
))
1221 mode
= fb_find_best_mode(var
, &info
->modelist
);
1223 riva_update_var(var
, mode
);
1228 if (!mode_valid
&& info
->monspecs
.modedb_len
)
1231 if (var
->xres_virtual
< var
->xres
)
1232 var
->xres_virtual
= var
->xres
;
1233 if (var
->yres_virtual
<= var
->yres
)
1234 var
->yres_virtual
= -1;
1235 if (rivafb_do_maximize(info
, var
, nom
, den
) < 0)
1238 if (var
->xoffset
< 0)
1240 if (var
->yoffset
< 0)
1243 /* truncate xoffset and yoffset to maximum if too high */
1244 if (var
->xoffset
> var
->xres_virtual
- var
->xres
)
1245 var
->xoffset
= var
->xres_virtual
- var
->xres
- 1;
1247 if (var
->yoffset
> var
->yres_virtual
- var
->yres
)
1248 var
->yoffset
= var
->yres_virtual
- var
->yres
- 1;
1250 var
->red
.msb_right
=
1251 var
->green
.msb_right
=
1252 var
->blue
.msb_right
=
1253 var
->transp
.offset
= var
->transp
.length
= var
->transp
.msb_right
= 0;
1258 static int rivafb_set_par(struct fb_info
*info
)
1260 struct riva_par
*par
= info
->par
;
1263 /* vgaHWunlock() + riva unlock (0x7F) */
1264 CRTCout(par
, 0x11, 0xFF);
1265 par
->riva
.LockUnlock(&par
->riva
, 0);
1266 riva_load_video_mode(info
);
1267 if(!(info
->flags
& FBINFO_HWACCEL_DISABLED
))
1268 riva_setup_accel(info
);
1270 par
->cursor_reset
= 1;
1271 info
->fix
.line_length
= (info
->var
.xres_virtual
* (info
->var
.bits_per_pixel
>> 3));
1272 info
->fix
.visual
= (info
->var
.bits_per_pixel
== 8) ?
1273 FB_VISUAL_PSEUDOCOLOR
: FB_VISUAL_DIRECTCOLOR
;
1275 if (info
->flags
& FBINFO_HWACCEL_DISABLED
)
1276 info
->pixmap
.scan_align
= 1;
1278 info
->pixmap
.scan_align
= 4;
1284 * rivafb_pan_display
1285 * @var: standard kernel fb changeable data
1287 * @info: pointer to fb_info object containing info for current riva board
1290 * Pan (or wrap, depending on the `vmode' field) the display using the
1291 * `xoffset' and `yoffset' fields of the `var' structure.
1292 * If the values don't fit, return -EINVAL.
1294 * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
1296 static int rivafb_pan_display(struct fb_var_screeninfo
*var
,
1297 struct fb_info
*info
)
1299 struct riva_par
*par
= info
->par
;
1303 base
= var
->yoffset
* info
->fix
.line_length
+ var
->xoffset
;
1304 par
->riva
.SetStartAddress(&par
->riva
, base
);
1309 static int rivafb_blank(int blank
, struct fb_info
*info
)
1311 struct riva_par
*par
= info
->par
;
1312 unsigned char tmp
, vesa
;
1314 tmp
= SEQin(par
, 0x01) & ~0x20; /* screen on/off */
1315 vesa
= CRTCin(par
, 0x1a) & ~0xc0; /* sync on/off */
1323 case FB_BLANK_UNBLANK
:
1324 case FB_BLANK_NORMAL
:
1326 case FB_BLANK_VSYNC_SUSPEND
:
1329 case FB_BLANK_HSYNC_SUSPEND
:
1332 case FB_BLANK_POWERDOWN
:
1337 SEQout(par
, 0x01, tmp
);
1338 CRTCout(par
, 0x1a, vesa
);
1340 #ifdef CONFIG_FB_RIVA_BACKLIGHT
1341 mutex_lock(&info
->bl_mutex
);
1343 down(&info
->bl_dev
->sem
);
1344 info
->bl_dev
->props
->power
= blank
;
1345 info
->bl_dev
->props
->update_status(info
->bl_dev
);
1346 up(&info
->bl_dev
->sem
);
1348 mutex_unlock(&info
->bl_mutex
);
1358 * @regno: register index
1359 * @red: red component
1360 * @green: green component
1361 * @blue: blue component
1362 * @transp: transparency
1363 * @info: pointer to fb_info object containing info for current riva board
1366 * Set a single color register. The values supplied have a 16 bit
1370 * Return != 0 for invalid regno.
1373 * fbcmap.c:fb_set_cmap()
1375 static int rivafb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
1376 unsigned blue
, unsigned transp
,
1377 struct fb_info
*info
)
1379 struct riva_par
*par
= info
->par
;
1380 RIVA_HW_INST
*chip
= &par
->riva
;
1383 if (regno
>= riva_get_cmap_len(&info
->var
))
1386 if (info
->var
.grayscale
) {
1387 /* gray = 0.30*R + 0.59*G + 0.11*B */
1388 red
= green
= blue
=
1389 (red
* 77 + green
* 151 + blue
* 28) >> 8;
1392 if (regno
< 16 && info
->fix
.visual
== FB_VISUAL_DIRECTCOLOR
) {
1393 ((u32
*) info
->pseudo_palette
)[regno
] =
1394 (regno
<< info
->var
.red
.offset
) |
1395 (regno
<< info
->var
.green
.offset
) |
1396 (regno
<< info
->var
.blue
.offset
);
1398 * The Riva128 2D engine requires color information in
1399 * TrueColor format even if framebuffer is in DirectColor
1401 if (par
->riva
.Architecture
== NV_ARCH_03
) {
1402 switch (info
->var
.bits_per_pixel
) {
1404 par
->palette
[regno
] = ((red
& 0xf800) >> 1) |
1405 ((green
& 0xf800) >> 6) |
1406 ((blue
& 0xf800) >> 11);
1409 par
->palette
[regno
] = ((red
& 0xff00) << 8) |
1410 ((green
& 0xff00)) |
1411 ((blue
& 0xff00) >> 8);
1417 switch (info
->var
.bits_per_pixel
) {
1419 /* "transparent" stuff is completely ignored. */
1420 riva_wclut(chip
, regno
, red
>> 8, green
>> 8, blue
>> 8);
1423 if (info
->var
.green
.length
== 5) {
1424 for (i
= 0; i
< 8; i
++) {
1425 riva_wclut(chip
, regno
*8+i
, red
>> 8,
1426 green
>> 8, blue
>> 8);
1432 for (i
= 0; i
< 8; i
++) {
1433 riva_wclut(chip
, regno
*8+i
,
1434 red
>> 8, green
>> 8,
1438 riva_rclut(chip
, regno
*4, &r
, &g
, &b
);
1439 for (i
= 0; i
< 4; i
++)
1440 riva_wclut(chip
, regno
*4+i
, r
,
1445 riva_wclut(chip
, regno
, red
>> 8, green
>> 8, blue
>> 8);
1455 * rivafb_fillrect - hardware accelerated color fill function
1456 * @info: pointer to fb_info structure
1457 * @rect: pointer to fb_fillrect structure
1460 * This function fills up a region of framebuffer memory with a solid
1461 * color with a choice of two different ROP's, copy or invert.
1466 static void rivafb_fillrect(struct fb_info
*info
, const struct fb_fillrect
*rect
)
1468 struct riva_par
*par
= info
->par
;
1469 u_int color
, rop
= 0;
1471 if ((info
->flags
& FBINFO_HWACCEL_DISABLED
)) {
1472 cfb_fillrect(info
, rect
);
1476 if (info
->var
.bits_per_pixel
== 8)
1477 color
= rect
->color
;
1479 if (par
->riva
.Architecture
!= NV_ARCH_03
)
1480 color
= ((u32
*)info
->pseudo_palette
)[rect
->color
];
1482 color
= par
->palette
[rect
->color
];
1485 switch (rect
->rop
) {
1495 riva_set_rop_solid(par
, rop
);
1497 RIVA_FIFO_FREE(par
->riva
, Bitmap
, 1);
1498 NV_WR32(&par
->riva
.Bitmap
->Color1A
, 0, color
);
1500 RIVA_FIFO_FREE(par
->riva
, Bitmap
, 2);
1501 NV_WR32(&par
->riva
.Bitmap
->UnclippedRectangle
[0].TopLeft
, 0,
1502 (rect
->dx
<< 16) | rect
->dy
);
1504 NV_WR32(&par
->riva
.Bitmap
->UnclippedRectangle
[0].WidthHeight
, 0,
1505 (rect
->width
<< 16) | rect
->height
);
1507 riva_set_rop_solid(par
, 0xcc);
1512 * rivafb_copyarea - hardware accelerated blit function
1513 * @info: pointer to fb_info structure
1514 * @region: pointer to fb_copyarea structure
1517 * This copies an area of pixels from one location to another
1522 static void rivafb_copyarea(struct fb_info
*info
, const struct fb_copyarea
*region
)
1524 struct riva_par
*par
= info
->par
;
1526 if ((info
->flags
& FBINFO_HWACCEL_DISABLED
)) {
1527 cfb_copyarea(info
, region
);
1531 RIVA_FIFO_FREE(par
->riva
, Blt
, 3);
1532 NV_WR32(&par
->riva
.Blt
->TopLeftSrc
, 0,
1533 (region
->sy
<< 16) | region
->sx
);
1534 NV_WR32(&par
->riva
.Blt
->TopLeftDst
, 0,
1535 (region
->dy
<< 16) | region
->dx
);
1537 NV_WR32(&par
->riva
.Blt
->WidthHeight
, 0,
1538 (region
->height
<< 16) | region
->width
);
1542 static inline void convert_bgcolor_16(u32
*col
)
1544 *col
= ((*col
& 0x0000F800) << 8)
1545 | ((*col
& 0x00007E0) << 5)
1546 | ((*col
& 0x0000001F) << 3)
1552 * rivafb_imageblit: hardware accelerated color expand function
1553 * @info: pointer to fb_info structure
1554 * @image: pointer to fb_image structure
1557 * If the source is a monochrome bitmap, the function fills up a a region
1558 * of framebuffer memory with pixels whose color is determined by the bit
1559 * setting of the bitmap, 1 - foreground, 0 - background.
1561 * If the source is not a monochrome bitmap, color expansion is not done.
1562 * In this case, it is channeled to a software function.
1567 static void rivafb_imageblit(struct fb_info
*info
,
1568 const struct fb_image
*image
)
1570 struct riva_par
*par
= info
->par
;
1571 u32 fgx
= 0, bgx
= 0, width
, tmp
;
1572 u8
*cdat
= (u8
*) image
->data
;
1573 volatile u32 __iomem
*d
;
1576 if ((info
->flags
& FBINFO_HWACCEL_DISABLED
) || image
->depth
!= 1) {
1577 cfb_imageblit(info
, image
);
1581 switch (info
->var
.bits_per_pixel
) {
1583 fgx
= image
->fg_color
;
1584 bgx
= image
->bg_color
;
1588 if (par
->riva
.Architecture
!= NV_ARCH_03
) {
1589 fgx
= ((u32
*)info
->pseudo_palette
)[image
->fg_color
];
1590 bgx
= ((u32
*)info
->pseudo_palette
)[image
->bg_color
];
1592 fgx
= par
->palette
[image
->fg_color
];
1593 bgx
= par
->palette
[image
->bg_color
];
1595 if (info
->var
.green
.length
== 6)
1596 convert_bgcolor_16(&bgx
);
1600 RIVA_FIFO_FREE(par
->riva
, Bitmap
, 7);
1601 NV_WR32(&par
->riva
.Bitmap
->ClipE
.TopLeft
, 0,
1602 (image
->dy
<< 16) | (image
->dx
& 0xFFFF));
1603 NV_WR32(&par
->riva
.Bitmap
->ClipE
.BottomRight
, 0,
1604 (((image
->dy
+ image
->height
) << 16) |
1605 ((image
->dx
+ image
->width
) & 0xffff)));
1606 NV_WR32(&par
->riva
.Bitmap
->Color0E
, 0, bgx
);
1607 NV_WR32(&par
->riva
.Bitmap
->Color1E
, 0, fgx
);
1608 NV_WR32(&par
->riva
.Bitmap
->WidthHeightInE
, 0,
1609 (image
->height
<< 16) | ((image
->width
+ 31) & ~31));
1610 NV_WR32(&par
->riva
.Bitmap
->WidthHeightOutE
, 0,
1611 (image
->height
<< 16) | ((image
->width
+ 31) & ~31));
1612 NV_WR32(&par
->riva
.Bitmap
->PointE
, 0,
1613 (image
->dy
<< 16) | (image
->dx
& 0xFFFF));
1615 d
= &par
->riva
.Bitmap
->MonochromeData01E
;
1617 width
= (image
->width
+ 31)/32;
1618 size
= width
* image
->height
;
1619 while (size
>= 16) {
1620 RIVA_FIFO_FREE(par
->riva
, Bitmap
, 16);
1621 for (i
= 0; i
< 16; i
++) {
1622 tmp
= *((u32
*)cdat
);
1623 cdat
= (u8
*)((u32
*)cdat
+ 1);
1624 reverse_order(&tmp
);
1625 NV_WR32(d
, i
*4, tmp
);
1630 RIVA_FIFO_FREE(par
->riva
, Bitmap
, size
);
1631 for (i
= 0; i
< size
; i
++) {
1632 tmp
= *((u32
*) cdat
);
1633 cdat
= (u8
*)((u32
*)cdat
+ 1);
1634 reverse_order(&tmp
);
1635 NV_WR32(d
, i
*4, tmp
);
1641 * rivafb_cursor - hardware cursor function
1642 * @info: pointer to info structure
1643 * @cursor: pointer to fbcursor structure
1646 * A cursor function that supports displaying a cursor image via hardware.
1647 * Within the kernel, copy and invert rops are supported. If exported
1648 * to user space, only the copy rop will be supported.
1653 static int rivafb_cursor(struct fb_info
*info
, struct fb_cursor
*cursor
)
1655 struct riva_par
*par
= info
->par
;
1656 u8 data
[MAX_CURS
* MAX_CURS
/8];
1657 int i
, set
= cursor
->set
;
1660 if (cursor
->image
.width
> MAX_CURS
|| cursor
->image
.height
> MAX_CURS
)
1663 par
->riva
.ShowHideCursor(&par
->riva
, 0);
1665 if (par
->cursor_reset
) {
1666 set
= FB_CUR_SETALL
;
1667 par
->cursor_reset
= 0;
1670 if (set
& FB_CUR_SETSIZE
)
1671 memset_io(par
->riva
.CURSOR
, 0, MAX_CURS
* MAX_CURS
* 2);
1673 if (set
& FB_CUR_SETPOS
) {
1676 yy
= cursor
->image
.dy
- info
->var
.yoffset
;
1677 xx
= cursor
->image
.dx
- info
->var
.xoffset
;
1681 NV_WR32(par
->riva
.PRAMDAC
, 0x0000300, temp
);
1685 if (set
& (FB_CUR_SETSHAPE
| FB_CUR_SETCMAP
| FB_CUR_SETIMAGE
)) {
1686 u32 bg_idx
= cursor
->image
.bg_color
;
1687 u32 fg_idx
= cursor
->image
.fg_color
;
1688 u32 s_pitch
= (cursor
->image
.width
+7) >> 3;
1689 u32 d_pitch
= MAX_CURS
/8;
1690 u8
*dat
= (u8
*) cursor
->image
.data
;
1691 u8
*msk
= (u8
*) cursor
->mask
;
1694 src
= kmalloc(s_pitch
* cursor
->image
.height
, GFP_ATOMIC
);
1697 switch (cursor
->rop
) {
1699 for (i
= 0; i
< s_pitch
* cursor
->image
.height
; i
++)
1700 src
[i
] = dat
[i
] ^ msk
[i
];
1704 for (i
= 0; i
< s_pitch
* cursor
->image
.height
; i
++)
1705 src
[i
] = dat
[i
] & msk
[i
];
1709 fb_pad_aligned_buffer(data
, d_pitch
, src
, s_pitch
,
1710 cursor
->image
.height
);
1712 bg
= ((info
->cmap
.red
[bg_idx
] & 0xf8) << 7) |
1713 ((info
->cmap
.green
[bg_idx
] & 0xf8) << 2) |
1714 ((info
->cmap
.blue
[bg_idx
] & 0xf8) >> 3) |
1717 fg
= ((info
->cmap
.red
[fg_idx
] & 0xf8) << 7) |
1718 ((info
->cmap
.green
[fg_idx
] & 0xf8) << 2) |
1719 ((info
->cmap
.blue
[fg_idx
] & 0xf8) >> 3) |
1722 par
->riva
.LockUnlock(&par
->riva
, 0);
1724 rivafb_load_cursor_image(par
, data
, bg
, fg
,
1725 cursor
->image
.width
,
1726 cursor
->image
.height
);
1732 par
->riva
.ShowHideCursor(&par
->riva
, 1);
1737 static int rivafb_sync(struct fb_info
*info
)
1739 struct riva_par
*par
= info
->par
;
1745 /* ------------------------------------------------------------------------- *
1747 * initialization helper functions
1749 * ------------------------------------------------------------------------- */
1751 /* kernel interface */
1752 static struct fb_ops riva_fb_ops
= {
1753 .owner
= THIS_MODULE
,
1754 .fb_open
= rivafb_open
,
1755 .fb_release
= rivafb_release
,
1756 .fb_check_var
= rivafb_check_var
,
1757 .fb_set_par
= rivafb_set_par
,
1758 .fb_setcolreg
= rivafb_setcolreg
,
1759 .fb_pan_display
= rivafb_pan_display
,
1760 .fb_blank
= rivafb_blank
,
1761 .fb_fillrect
= rivafb_fillrect
,
1762 .fb_copyarea
= rivafb_copyarea
,
1763 .fb_imageblit
= rivafb_imageblit
,
1764 .fb_cursor
= rivafb_cursor
,
1765 .fb_sync
= rivafb_sync
,
1768 static int __devinit
riva_set_fbinfo(struct fb_info
*info
)
1770 unsigned int cmap_len
;
1771 struct riva_par
*par
= info
->par
;
1774 info
->flags
= FBINFO_DEFAULT
1775 | FBINFO_HWACCEL_XPAN
1776 | FBINFO_HWACCEL_YPAN
1777 | FBINFO_HWACCEL_COPYAREA
1778 | FBINFO_HWACCEL_FILLRECT
1779 | FBINFO_HWACCEL_IMAGEBLIT
;
1781 /* Accel seems to not work properly on NV30 yet...*/
1782 if ((par
->riva
.Architecture
== NV_ARCH_30
) || noaccel
) {
1783 printk(KERN_DEBUG PFX
"disabling acceleration\n");
1784 info
->flags
|= FBINFO_HWACCEL_DISABLED
;
1787 info
->var
= rivafb_default_var
;
1788 info
->fix
.visual
= (info
->var
.bits_per_pixel
== 8) ?
1789 FB_VISUAL_PSEUDOCOLOR
: FB_VISUAL_DIRECTCOLOR
;
1791 info
->pseudo_palette
= par
->pseudo_palette
;
1793 cmap_len
= riva_get_cmap_len(&info
->var
);
1794 fb_alloc_cmap(&info
->cmap
, cmap_len
, 0);
1796 info
->pixmap
.size
= 8 * 1024;
1797 info
->pixmap
.buf_align
= 4;
1798 info
->pixmap
.access_align
= 32;
1799 info
->pixmap
.flags
= FB_PIXMAP_SYSTEM
;
1800 info
->var
.yres_virtual
= -1;
1802 return (rivafb_check_var(&info
->var
, info
));
1805 #ifdef CONFIG_PPC_OF
1806 static int __devinit
riva_get_EDID_OF(struct fb_info
*info
, struct pci_dev
*pd
)
1808 struct riva_par
*par
= info
->par
;
1809 struct device_node
*dp
;
1810 unsigned char *pedid
= NULL
;
1811 unsigned char *disptype
= NULL
;
1812 static char *propnames
[] = {
1813 "DFP,EDID", "LCD,EDID", "EDID", "EDID1", "EDID,B", "EDID,A", NULL
};
1817 dp
= pci_device_to_OF_node(pd
);
1818 for (; dp
!= NULL
; dp
= dp
->child
) {
1819 disptype
= (unsigned char *)get_property(dp
, "display-type", NULL
);
1820 if (disptype
== NULL
)
1822 if (strncmp(disptype
, "LCD", 3) != 0)
1824 for (i
= 0; propnames
[i
] != NULL
; ++i
) {
1825 pedid
= (unsigned char *)
1826 get_property(dp
, propnames
[i
], NULL
);
1827 if (pedid
!= NULL
) {
1829 NVTRACE("LCD found.\n");
1837 #endif /* CONFIG_PPC_OF */
1839 #if defined(CONFIG_FB_RIVA_I2C) && !defined(CONFIG_PPC_OF)
1840 static int __devinit
riva_get_EDID_i2c(struct fb_info
*info
)
1842 struct riva_par
*par
= info
->par
;
1843 struct fb_var_screeninfo var
;
1847 riva_create_i2c_busses(par
);
1848 for (i
= 0; i
< par
->bus
; i
++) {
1849 riva_probe_i2c_connector(par
, i
+1, &par
->EDID
);
1850 if (par
->EDID
&& !fb_parse_edid(par
->EDID
, &var
)) {
1851 printk(PFX
"Found EDID Block from BUS %i\n", i
);
1857 return (par
->EDID
) ? 1 : 0;
1859 #endif /* CONFIG_FB_RIVA_I2C */
1861 static void __devinit
riva_update_default_var(struct fb_var_screeninfo
*var
,
1862 struct fb_info
*info
)
1864 struct fb_monspecs
*specs
= &info
->monspecs
;
1865 struct fb_videomode modedb
;
1868 /* respect mode options */
1870 fb_find_mode(var
, info
, mode_option
,
1871 specs
->modedb
, specs
->modedb_len
,
1873 } else if (specs
->modedb
!= NULL
) {
1874 /* get preferred timing */
1875 if (info
->monspecs
.misc
& FB_MISC_1ST_DETAIL
) {
1878 for (i
= 0; i
< specs
->modedb_len
; i
++) {
1879 if (specs
->modedb
[i
].flag
& FB_MODE_IS_FIRST
) {
1880 modedb
= specs
->modedb
[i
];
1885 /* otherwise, get first mode in database */
1886 modedb
= specs
->modedb
[0];
1888 var
->bits_per_pixel
= 8;
1889 riva_update_var(var
, &modedb
);
1895 static void __devinit
riva_get_EDID(struct fb_info
*info
, struct pci_dev
*pdev
)
1898 #ifdef CONFIG_PPC_OF
1899 if (!riva_get_EDID_OF(info
, pdev
))
1900 printk(PFX
"could not retrieve EDID from OF\n");
1901 #elif defined(CONFIG_FB_RIVA_I2C)
1902 if (!riva_get_EDID_i2c(info
))
1903 printk(PFX
"could not retrieve EDID from DDC/I2C\n");
1909 static void __devinit
riva_get_edidinfo(struct fb_info
*info
)
1911 struct fb_var_screeninfo
*var
= &rivafb_default_var
;
1912 struct riva_par
*par
= info
->par
;
1914 fb_edid_to_monspecs(par
->EDID
, &info
->monspecs
);
1915 fb_videomode_to_modelist(info
->monspecs
.modedb
, info
->monspecs
.modedb_len
,
1917 riva_update_default_var(var
, info
);
1919 /* if user specified flatpanel, we respect that */
1920 if (info
->monspecs
.input
& FB_DISP_DDI
)
1924 /* ------------------------------------------------------------------------- *
1928 * ------------------------------------------------------------------------- */
1930 static u32 __devinit
riva_get_arch(struct pci_dev
*pd
)
1934 switch (pd
->device
& 0x0ff0) {
1935 case 0x0100: /* GeForce 256 */
1936 case 0x0110: /* GeForce2 MX */
1937 case 0x0150: /* GeForce2 */
1938 case 0x0170: /* GeForce4 MX */
1939 case 0x0180: /* GeForce4 MX (8x AGP) */
1940 case 0x01A0: /* nForce */
1941 case 0x01F0: /* nForce2 */
1944 case 0x0200: /* GeForce3 */
1945 case 0x0250: /* GeForce4 Ti */
1946 case 0x0280: /* GeForce4 Ti (8x AGP) */
1949 case 0x0300: /* GeForceFX 5800 */
1950 case 0x0310: /* GeForceFX 5600 */
1951 case 0x0320: /* GeForceFX 5200 */
1952 case 0x0330: /* GeForceFX 5900 */
1953 case 0x0340: /* GeForceFX 5700 */
1956 case 0x0020: /* TNT, TNT2 */
1959 case 0x0010: /* Riva128 */
1962 default: /* unknown architecture */
1968 static int __devinit
rivafb_probe(struct pci_dev
*pd
,
1969 const struct pci_device_id
*ent
)
1971 struct riva_par
*default_par
;
1972 struct fb_info
*info
;
1978 info
= framebuffer_alloc(sizeof(struct riva_par
), &pd
->dev
);
1980 printk (KERN_ERR PFX
"could not allocate memory\n");
1984 default_par
= info
->par
;
1985 default_par
->pdev
= pd
;
1987 info
->pixmap
.addr
= kmalloc(8 * 1024, GFP_KERNEL
);
1988 if (info
->pixmap
.addr
== NULL
) {
1990 goto err_framebuffer_release
;
1992 memset(info
->pixmap
.addr
, 0, 8 * 1024);
1994 ret
= pci_enable_device(pd
);
1996 printk(KERN_ERR PFX
"cannot enable PCI device\n");
1997 goto err_free_pixmap
;
2000 ret
= pci_request_regions(pd
, "rivafb");
2002 printk(KERN_ERR PFX
"cannot request PCI regions\n");
2003 goto err_disable_device
;
2006 default_par
->riva
.Architecture
= riva_get_arch(pd
);
2008 default_par
->Chipset
= (pd
->vendor
<< 16) | pd
->device
;
2009 printk(KERN_INFO PFX
"nVidia device/chipset %X\n",default_par
->Chipset
);
2011 if(default_par
->riva
.Architecture
== 0) {
2012 printk(KERN_ERR PFX
"unknown NV_ARCH\n");
2014 goto err_release_region
;
2016 if(default_par
->riva
.Architecture
== NV_ARCH_10
||
2017 default_par
->riva
.Architecture
== NV_ARCH_20
||
2018 default_par
->riva
.Architecture
== NV_ARCH_30
) {
2019 sprintf(rivafb_fix
.id
, "NV%x", (pd
->device
& 0x0ff0) >> 4);
2021 sprintf(rivafb_fix
.id
, "NV%x", default_par
->riva
.Architecture
);
2024 default_par
->FlatPanel
= flatpanel
;
2026 printk(KERN_INFO PFX
"flatpanel support enabled\n");
2027 default_par
->forceCRTC
= forceCRTC
;
2029 rivafb_fix
.mmio_len
= pci_resource_len(pd
, 0);
2030 rivafb_fix
.smem_len
= pci_resource_len(pd
, 1);
2033 /* enable IO and mem if not already done */
2036 pci_read_config_word(pd
, PCI_COMMAND
, &cmd
);
2037 cmd
|= (PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
);
2038 pci_write_config_word(pd
, PCI_COMMAND
, cmd
);
2041 rivafb_fix
.mmio_start
= pci_resource_start(pd
, 0);
2042 rivafb_fix
.smem_start
= pci_resource_start(pd
, 1);
2044 default_par
->ctrl_base
= ioremap(rivafb_fix
.mmio_start
,
2045 rivafb_fix
.mmio_len
);
2046 if (!default_par
->ctrl_base
) {
2047 printk(KERN_ERR PFX
"cannot ioremap MMIO base\n");
2049 goto err_release_region
;
2052 switch (default_par
->riva
.Architecture
) {
2054 /* Riva128's PRAMIN is in the "framebuffer" space
2055 * Since these cards were never made with more than 8 megabytes
2056 * we can safely allocate this separately.
2058 default_par
->riva
.PRAMIN
= ioremap(rivafb_fix
.smem_start
+ 0x00C00000, 0x00008000);
2059 if (!default_par
->riva
.PRAMIN
) {
2060 printk(KERN_ERR PFX
"cannot ioremap PRAMIN region\n");
2062 goto err_iounmap_ctrl_base
;
2069 default_par
->riva
.PCRTC0
=
2070 (u32 __iomem
*)(default_par
->ctrl_base
+ 0x00600000);
2071 default_par
->riva
.PRAMIN
=
2072 (u32 __iomem
*)(default_par
->ctrl_base
+ 0x00710000);
2075 riva_common_setup(default_par
);
2077 if (default_par
->riva
.Architecture
== NV_ARCH_03
) {
2078 default_par
->riva
.PCRTC
= default_par
->riva
.PCRTC0
2079 = default_par
->riva
.PGRAPH
;
2082 rivafb_fix
.smem_len
= riva_get_memlen(default_par
) * 1024;
2083 default_par
->dclk_max
= riva_get_maxdclk(default_par
) * 1000;
2084 info
->screen_base
= ioremap(rivafb_fix
.smem_start
,
2085 rivafb_fix
.smem_len
);
2086 if (!info
->screen_base
) {
2087 printk(KERN_ERR PFX
"cannot ioremap FB base\n");
2089 goto err_iounmap_pramin
;
2094 default_par
->mtrr
.vram
= mtrr_add(rivafb_fix
.smem_start
,
2095 rivafb_fix
.smem_len
,
2096 MTRR_TYPE_WRCOMB
, 1);
2097 if (default_par
->mtrr
.vram
< 0) {
2098 printk(KERN_ERR PFX
"unable to setup MTRR\n");
2100 default_par
->mtrr
.vram_valid
= 1;
2101 /* let there be speed */
2102 printk(KERN_INFO PFX
"RIVA MTRR set to ON\n");
2105 #endif /* CONFIG_MTRR */
2107 info
->fbops
= &riva_fb_ops
;
2108 info
->fix
= rivafb_fix
;
2109 riva_get_EDID(info
, pd
);
2110 riva_get_edidinfo(info
);
2112 ret
=riva_set_fbinfo(info
);
2114 printk(KERN_ERR PFX
"error setting initial video mode\n");
2115 goto err_iounmap_screen_base
;
2118 fb_destroy_modedb(info
->monspecs
.modedb
);
2119 info
->monspecs
.modedb
= NULL
;
2120 ret
= register_framebuffer(info
);
2123 "error registering riva framebuffer\n");
2124 goto err_iounmap_screen_base
;
2127 pci_set_drvdata(pd
, info
);
2129 printk(KERN_INFO PFX
2130 "PCI nVidia %s framebuffer ver %s (%dMB @ 0x%lX)\n",
2133 info
->fix
.smem_len
/ (1024 * 1024),
2134 info
->fix
.smem_start
);
2136 riva_bl_init(info
->par
);
2141 err_iounmap_screen_base
:
2142 #ifdef CONFIG_FB_RIVA_I2C
2143 riva_delete_i2c_busses(info
->par
);
2145 iounmap(info
->screen_base
);
2147 if (default_par
->riva
.Architecture
== NV_ARCH_03
)
2148 iounmap(default_par
->riva
.PRAMIN
);
2149 err_iounmap_ctrl_base
:
2150 iounmap(default_par
->ctrl_base
);
2152 pci_release_regions(pd
);
2155 kfree(info
->pixmap
.addr
);
2156 err_framebuffer_release
:
2157 framebuffer_release(info
);
2162 static void __exit
rivafb_remove(struct pci_dev
*pd
)
2164 struct fb_info
*info
= pci_get_drvdata(pd
);
2165 struct riva_par
*par
= info
->par
;
2171 #ifdef CONFIG_FB_RIVA_I2C
2172 riva_delete_i2c_busses(par
);
2176 unregister_framebuffer(info
);
2178 if (par
->mtrr
.vram_valid
)
2179 mtrr_del(par
->mtrr
.vram
, info
->fix
.smem_start
,
2180 info
->fix
.smem_len
);
2181 #endif /* CONFIG_MTRR */
2183 iounmap(par
->ctrl_base
);
2184 iounmap(info
->screen_base
);
2185 if (par
->riva
.Architecture
== NV_ARCH_03
)
2186 iounmap(par
->riva
.PRAMIN
);
2187 pci_release_regions(pd
);
2188 kfree(info
->pixmap
.addr
);
2189 framebuffer_release(info
);
2190 pci_set_drvdata(pd
, NULL
);
2194 /* ------------------------------------------------------------------------- *
2198 * ------------------------------------------------------------------------- */
2201 static int __init
rivafb_setup(char *options
)
2206 if (!options
|| !*options
)
2209 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
2210 if (!strncmp(this_opt
, "forceCRTC", 9)) {
2214 if (!*p
|| !*(++p
)) continue;
2215 forceCRTC
= *p
- '0';
2216 if (forceCRTC
< 0 || forceCRTC
> 1)
2218 } else if (!strncmp(this_opt
, "flatpanel", 9)) {
2221 } else if (!strncmp(this_opt
, "nomtrr", 6)) {
2224 } else if (!strncmp(this_opt
, "strictmode", 10)) {
2226 } else if (!strncmp(this_opt
, "noaccel", 7)) {
2229 mode_option
= this_opt
;
2234 #endif /* !MODULE */
2236 static struct pci_driver rivafb_driver
= {
2238 .id_table
= rivafb_pci_tbl
,
2239 .probe
= rivafb_probe
,
2240 .remove
= __exit_p(rivafb_remove
),
2245 /* ------------------------------------------------------------------------- *
2249 * ------------------------------------------------------------------------- */
2251 static int __devinit
rivafb_init(void)
2254 char *option
= NULL
;
2256 if (fb_get_options("rivafb", &option
))
2258 rivafb_setup(option
);
2260 return pci_register_driver(&rivafb_driver
);
2264 module_init(rivafb_init
);
2267 static void __exit
rivafb_exit(void)
2269 pci_unregister_driver(&rivafb_driver
);
2272 module_exit(rivafb_exit
);
2275 module_param(noaccel
, bool, 0);
2276 MODULE_PARM_DESC(noaccel
, "bool: disable acceleration");
2277 module_param(flatpanel
, int, 0);
2278 MODULE_PARM_DESC(flatpanel
, "Enables experimental flat panel support for some chipsets. (0 or 1=enabled) (default=0)");
2279 module_param(forceCRTC
, int, 0);
2280 MODULE_PARM_DESC(forceCRTC
, "Forces usage of a particular CRTC in case autodetection fails. (0 or 1) (default=autodetect)");
2282 module_param(nomtrr
, bool, 0);
2283 MODULE_PARM_DESC(nomtrr
, "Disables MTRR support (0 or 1=disabled) (default=0)");
2285 module_param(strictmode
, bool, 0);
2286 MODULE_PARM_DESC(strictmode
, "Only use video modes from EDID");
2288 MODULE_AUTHOR("Ani Joshi, maintainer");
2289 MODULE_DESCRIPTION("Framebuffer driver for nVidia Riva 128, TNT, TNT2, and the GeForce series");
2290 MODULE_LICENSE("GPL");