blob: ab00350907dd390c4b0958fd6f0b311522177929 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/drivers/video/riva/fbdev.c - nVidia RIVA 128/TNT/TNT2 fb driver
3 *
4 * Maintained by Ani Joshi <ajoshi@shell.unixbox.com>
5 *
6 * Copyright 1999-2000 Jeff Garzik
7 *
8 * Contributors:
9 *
10 * Ani Joshi: Lots of debugging and cleanup work, really helped
11 * get the driver going
12 *
13 * Ferenc Bakonyi: Bug fixes, cleanup, modularization
14 *
15 * Jindrich Makovicka: Accel code help, hw cursor, mtrr
16 *
17 * Paul Richards: Bug fixes, updates
18 *
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.
22 *
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
25 * for more details.
26 *
27 * Known bugs and issues:
28 * restoring text mode fails
29 * doublescan modes are broken
30 */
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/module.h>
33#include <linux/kernel.h>
34#include <linux/errno.h>
35#include <linux/string.h>
36#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/slab.h>
38#include <linux/delay.h>
39#include <linux/fb.h>
40#include <linux/init.h>
41#include <linux/pci.h>
Michael Hanselmann5474c122006-06-25 05:47:08 -070042#include <linux/backlight.h>
Akinobu Mita1c667682006-12-08 02:36:26 -080043#include <linux/bitrev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#ifdef CONFIG_MTRR
45#include <asm/mtrr.h>
46#endif
47#ifdef CONFIG_PPC_OF
48#include <asm/prom.h>
49#include <asm/pci-bridge.h>
50#endif
51#ifdef CONFIG_PMAC_BACKLIGHT
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +110052#include <asm/machdep.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include <asm/backlight.h>
54#endif
55
56#include "rivafb.h"
57#include "nvreg.h"
58
59#ifndef CONFIG_PCI /* sanity check */
60#error This driver requires PCI support.
61#endif
62
63/* version number of this driver */
64#define RIVAFB_VERSION "0.9.5b"
65
66/* ------------------------------------------------------------------------- *
67 *
68 * various helpful macros and constants
69 *
70 * ------------------------------------------------------------------------- */
71#ifdef CONFIG_FB_RIVA_DEBUG
72#define NVTRACE printk
73#else
74#define NVTRACE if(0) printk
75#endif
76
77#define NVTRACE_ENTER(...) NVTRACE("%s START\n", __FUNCTION__)
78#define NVTRACE_LEAVE(...) NVTRACE("%s END\n", __FUNCTION__)
79
80#ifdef CONFIG_FB_RIVA_DEBUG
81#define assert(expr) \
82 if(!(expr)) { \
83 printk( "Assertion failed! %s,%s,%s,line=%d\n",\
84 #expr,__FILE__,__FUNCTION__,__LINE__); \
85 BUG(); \
86 }
87#else
88#define assert(expr)
89#endif
90
91#define PFX "rivafb: "
92
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)
97
98/* HW cursor parameters */
99#define MAX_CURS 32
100
101/* ------------------------------------------------------------------------- *
102 *
103 * prototypes
104 *
105 * ------------------------------------------------------------------------- */
106
107static int rivafb_blank(int blank, struct fb_info *info);
108
109/* ------------------------------------------------------------------------- *
110 *
111 * card identification
112 *
113 * ------------------------------------------------------------------------- */
114
115static 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 */
202};
203MODULE_DEVICE_TABLE(pci, rivafb_pci_tbl);
204
205/* ------------------------------------------------------------------------- *
206 *
207 * global variables
208 *
209 * ------------------------------------------------------------------------- */
210
211/* command line data, set in rivafb_setup() */
212static int flatpanel __devinitdata = -1; /* Autodetect later */
213static int forceCRTC __devinitdata = -1;
214static int noaccel __devinitdata = 0;
215#ifdef CONFIG_MTRR
216static int nomtrr __devinitdata = 0;
217#endif
218
219static char *mode_option __devinitdata = NULL;
220static int strictmode = 0;
221
222static struct fb_fix_screeninfo __devinitdata rivafb_fix = {
223 .type = FB_TYPE_PACKED_PIXELS,
224 .xpanstep = 1,
225 .ypanstep = 1,
226};
227
228static struct fb_var_screeninfo __devinitdata rivafb_default_var = {
229 .xres = 640,
230 .yres = 480,
231 .xres_virtual = 640,
232 .yres_virtual = 480,
233 .bits_per_pixel = 8,
234 .red = {0, 8, 0},
235 .green = {0, 8, 0},
236 .blue = {0, 8, 0},
237 .transp = {0, 0, 0},
238 .activate = FB_ACTIVATE_NOW,
239 .height = -1,
240 .width = -1,
241 .pixclock = 39721,
242 .left_margin = 40,
243 .right_margin = 24,
244 .upper_margin = 32,
245 .lower_margin = 11,
246 .hsync_len = 96,
247 .vsync_len = 2,
248 .vmode = FB_VMODE_NONINTERLACED
249};
250
251/* from GGI */
252static 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,
264 0x00, /* 0x40 */
265 },
266 {0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, /* GRA */
267 0xFF},
268 {0x03, 0x01, 0x0F, 0x00, 0x0E}, /* SEQ */
269 0xEB /* MISC */
270};
271
272/*
273 * Backlight control
274 */
Michael Hanselmann5474c122006-06-25 05:47:08 -0700275#ifdef CONFIG_FB_RIVA_BACKLIGHT
276/* We do not have any information about which values are allowed, thus
277 * we used safe values.
278 */
279#define MIN_LEVEL 0x158
280#define MAX_LEVEL 0x534
Michael Hanselmanne01af032006-07-10 04:44:45 -0700281#define LEVEL_STEP ((MAX_LEVEL - MIN_LEVEL) / FB_BACKLIGHT_MAX)
Michael Hanselmann5474c122006-06-25 05:47:08 -0700282
283static struct backlight_properties riva_bl_data;
284
285static int riva_bl_get_level_brightness(struct riva_par *par,
286 int level)
287{
288 struct fb_info *info = pci_get_drvdata(par->pdev);
289 int nlevel;
290
291 /* Get and convert the value */
Richard Purdie37ce69a2007-02-10 14:10:33 +0000292 /* No locking on bl_curve since accessing a single value */
Michael Hanselmanne01af032006-07-10 04:44:45 -0700293 nlevel = MIN_LEVEL + info->bl_curve[level] * LEVEL_STEP;
Michael Hanselmann5474c122006-06-25 05:47:08 -0700294
295 if (nlevel < 0)
296 nlevel = 0;
297 else if (nlevel < MIN_LEVEL)
298 nlevel = MIN_LEVEL;
299 else if (nlevel > MAX_LEVEL)
300 nlevel = MAX_LEVEL;
301
302 return nlevel;
303}
304
Richard Purdie37ce69a2007-02-10 14:10:33 +0000305static int riva_bl_update_status(struct backlight_device *bd)
Michael Hanselmann5474c122006-06-25 05:47:08 -0700306{
307 struct riva_par *par = class_get_devdata(&bd->class_dev);
308 U032 tmp_pcrt, tmp_pmc;
309 int level;
310
311 if (bd->props->power != FB_BLANK_UNBLANK ||
312 bd->props->fb_blank != FB_BLANK_UNBLANK)
313 level = 0;
314 else
315 level = bd->props->brightness;
316
317 tmp_pmc = par->riva.PMC[0x10F0/4] & 0x0000FFFF;
318 tmp_pcrt = par->riva.PCRTC0[0x081C/4] & 0xFFFFFFFC;
319 if(level > 0) {
320 tmp_pcrt |= 0x1;
321 tmp_pmc |= (1 << 31); /* backlight bit */
322 tmp_pmc |= riva_bl_get_level_brightness(par, level) << 16; /* level */
323 }
324 par->riva.PCRTC0[0x081C/4] = tmp_pcrt;
325 par->riva.PMC[0x10F0/4] = tmp_pmc;
326
327 return 0;
328}
329
330static int riva_bl_get_brightness(struct backlight_device *bd)
331{
332 return bd->props->brightness;
333}
334
335static struct backlight_properties riva_bl_data = {
Michael Hanselmann5474c122006-06-25 05:47:08 -0700336 .get_brightness = riva_bl_get_brightness,
337 .update_status = riva_bl_update_status,
338 .max_brightness = (FB_BACKLIGHT_LEVELS - 1),
339};
340
341static void riva_bl_init(struct riva_par *par)
342{
343 struct fb_info *info = pci_get_drvdata(par->pdev);
344 struct backlight_device *bd;
345 char name[12];
346
347 if (!par->FlatPanel)
348 return;
349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350#ifdef CONFIG_PMAC_BACKLIGHT
Michael Hanselmann5474c122006-06-25 05:47:08 -0700351 if (!machine_is(powermac) ||
352 !pmac_has_backlight_type("mnca"))
353 return;
354#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Michael Hanselmann5474c122006-06-25 05:47:08 -0700356 snprintf(name, sizeof(name), "rivabl%d", info->node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
James Simmonsa8274d52006-12-19 12:56:16 -0800358 bd = backlight_device_register(name, info->dev, par, &riva_bl_data);
Michael Hanselmann5474c122006-06-25 05:47:08 -0700359 if (IS_ERR(bd)) {
360 info->bl_dev = NULL;
Benjamin Herrenschmidt98a3c782006-08-31 14:04:34 +1000361 printk(KERN_WARNING "riva: Backlight registration failed\n");
Michael Hanselmann5474c122006-06-25 05:47:08 -0700362 goto error;
363 }
364
Michael Hanselmann5474c122006-06-25 05:47:08 -0700365 info->bl_dev = bd;
366 fb_bl_default_curve(info, 0,
Guido Guenther535a09a2006-10-03 01:14:40 -0700367 MIN_LEVEL * FB_BACKLIGHT_MAX / MAX_LEVEL,
368 FB_BACKLIGHT_MAX);
Michael Hanselmann5474c122006-06-25 05:47:08 -0700369
Michael Hanselmann5474c122006-06-25 05:47:08 -0700370 bd->props->brightness = riva_bl_data.max_brightness;
371 bd->props->power = FB_BLANK_UNBLANK;
Richard Purdie28ee0862007-02-08 22:25:09 +0000372 backlight_update_status(bd);
Michael Hanselmann5474c122006-06-25 05:47:08 -0700373
374#ifdef CONFIG_PMAC_BACKLIGHT
375 mutex_lock(&pmac_backlight_mutex);
376 if (!pmac_backlight)
377 pmac_backlight = bd;
378 mutex_unlock(&pmac_backlight_mutex);
379#endif
380
381 printk("riva: Backlight initialized (%s)\n", name);
382
383 return;
384
385error:
386 return;
387}
388
Richard Purdie37ce69a2007-02-10 14:10:33 +0000389static void riva_bl_exit(struct fb_info *info)
Michael Hanselmann5474c122006-06-25 05:47:08 -0700390{
Richard Purdie37ce69a2007-02-10 14:10:33 +0000391 struct backlight_device *bd = info->bl_dev;
Michael Hanselmann5474c122006-06-25 05:47:08 -0700392
Richard Purdie37ce69a2007-02-10 14:10:33 +0000393 if (bd) {
Michael Hanselmann5474c122006-06-25 05:47:08 -0700394#ifdef CONFIG_PMAC_BACKLIGHT
Richard Purdie37ce69a2007-02-10 14:10:33 +0000395 mutex_lock(&pmac_backlight_mutex);
396 if (pmac_backlight == bd)
Michael Hanselmann5474c122006-06-25 05:47:08 -0700397 pmac_backlight = NULL;
Richard Purdie37ce69a2007-02-10 14:10:33 +0000398 mutex_unlock(&pmac_backlight_mutex);
Michael Hanselmann5474c122006-06-25 05:47:08 -0700399#endif
Richard Purdie37ce69a2007-02-10 14:10:33 +0000400 backlight_device_unregister(bd);
Michael Hanselmann5474c122006-06-25 05:47:08 -0700401
402 printk("riva: Backlight unloaded\n");
403 }
Michael Hanselmann5474c122006-06-25 05:47:08 -0700404}
405#else
406static inline void riva_bl_init(struct riva_par *par) {}
Richard Purdie37ce69a2007-02-10 14:10:33 +0000407static inline void riva_bl_exit(struct fb_info *info) {}
Michael Hanselmann5474c122006-06-25 05:47:08 -0700408#endif /* CONFIG_FB_RIVA_BACKLIGHT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
410/* ------------------------------------------------------------------------- *
411 *
412 * MMIO access macros
413 *
414 * ------------------------------------------------------------------------- */
415
416static inline void CRTCout(struct riva_par *par, unsigned char index,
417 unsigned char val)
418{
419 VGA_WR08(par->riva.PCIO, 0x3d4, index);
420 VGA_WR08(par->riva.PCIO, 0x3d5, val);
421}
422
423static inline unsigned char CRTCin(struct riva_par *par,
424 unsigned char index)
425{
426 VGA_WR08(par->riva.PCIO, 0x3d4, index);
427 return (VGA_RD08(par->riva.PCIO, 0x3d5));
428}
429
430static inline void GRAout(struct riva_par *par, unsigned char index,
431 unsigned char val)
432{
433 VGA_WR08(par->riva.PVIO, 0x3ce, index);
434 VGA_WR08(par->riva.PVIO, 0x3cf, val);
435}
436
437static inline unsigned char GRAin(struct riva_par *par,
438 unsigned char index)
439{
440 VGA_WR08(par->riva.PVIO, 0x3ce, index);
441 return (VGA_RD08(par->riva.PVIO, 0x3cf));
442}
443
444static inline void SEQout(struct riva_par *par, unsigned char index,
445 unsigned char val)
446{
447 VGA_WR08(par->riva.PVIO, 0x3c4, index);
448 VGA_WR08(par->riva.PVIO, 0x3c5, val);
449}
450
451static inline unsigned char SEQin(struct riva_par *par,
452 unsigned char index)
453{
454 VGA_WR08(par->riva.PVIO, 0x3c4, index);
455 return (VGA_RD08(par->riva.PVIO, 0x3c5));
456}
457
458static inline void ATTRout(struct riva_par *par, unsigned char index,
459 unsigned char val)
460{
461 VGA_WR08(par->riva.PCIO, 0x3c0, index);
462 VGA_WR08(par->riva.PCIO, 0x3c0, val);
463}
464
465static inline unsigned char ATTRin(struct riva_par *par,
466 unsigned char index)
467{
468 VGA_WR08(par->riva.PCIO, 0x3c0, index);
469 return (VGA_RD08(par->riva.PCIO, 0x3c1));
470}
471
472static inline void MISCout(struct riva_par *par, unsigned char val)
473{
474 VGA_WR08(par->riva.PVIO, 0x3c2, val);
475}
476
477static inline unsigned char MISCin(struct riva_par *par)
478{
479 return (VGA_RD08(par->riva.PVIO, 0x3cc));
480}
481
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482static inline void reverse_order(u32 *l)
483{
484 u8 *a = (u8 *)l;
Akinobu Mita1c667682006-12-08 02:36:26 -0800485 a[0] = bitrev8(a[0]);
486 a[1] = bitrev8(a[1]);
487 a[2] = bitrev8(a[2]);
488 a[3] = bitrev8(a[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489}
490
491/* ------------------------------------------------------------------------- *
492 *
493 * cursor stuff
494 *
495 * ------------------------------------------------------------------------- */
496
497/**
498 * rivafb_load_cursor_image - load cursor image to hardware
499 * @data: address to monochrome bitmap (1 = foreground color, 0 = background)
500 * @par: pointer to private data
501 * @w: width of cursor image in pixels
502 * @h: height of cursor image in scanlines
503 * @bg: background color (ARGB1555) - alpha bit determines opacity
504 * @fg: foreground color (ARGB1555)
505 *
506 * DESCRIPTiON:
507 * Loads cursor image based on a monochrome source and mask bitmap. The
508 * image bits determines the color of the pixel, 0 for background, 1 for
509 * foreground. Only the affected region (as determined by @w and @h
510 * parameters) will be updated.
511 *
512 * CALLED FROM:
513 * rivafb_cursor()
514 */
515static void rivafb_load_cursor_image(struct riva_par *par, u8 *data8,
516 u16 bg, u16 fg, u32 w, u32 h)
517{
518 int i, j, k = 0;
519 u32 b, tmp;
520 u32 *data = (u32 *)data8;
521 bg = le16_to_cpu(bg);
522 fg = le16_to_cpu(fg);
523
524 w = (w + 1) & ~1;
525
526 for (i = 0; i < h; i++) {
527 b = *data++;
528 reverse_order(&b);
529
530 for (j = 0; j < w/2; j++) {
531 tmp = 0;
532#if defined (__BIG_ENDIAN)
533 tmp = (b & (1 << 31)) ? fg << 16 : bg << 16;
534 b <<= 1;
535 tmp |= (b & (1 << 31)) ? fg : bg;
536 b <<= 1;
537#else
538 tmp = (b & 1) ? fg : bg;
539 b >>= 1;
540 tmp |= (b & 1) ? fg << 16 : bg << 16;
541 b >>= 1;
542#endif
543 writel(tmp, &par->riva.CURSOR[k++]);
544 }
545 k += (MAX_CURS - w)/2;
546 }
547}
548
549/* ------------------------------------------------------------------------- *
550 *
551 * general utility functions
552 *
553 * ------------------------------------------------------------------------- */
554
555/**
556 * riva_wclut - set CLUT entry
557 * @chip: pointer to RIVA_HW_INST object
558 * @regnum: register number
559 * @red: red component
560 * @green: green component
561 * @blue: blue component
562 *
563 * DESCRIPTION:
564 * Sets color register @regnum.
565 *
566 * CALLED FROM:
567 * rivafb_setcolreg()
568 */
569static void riva_wclut(RIVA_HW_INST *chip,
570 unsigned char regnum, unsigned char red,
571 unsigned char green, unsigned char blue)
572{
573 VGA_WR08(chip->PDIO, 0x3c8, regnum);
574 VGA_WR08(chip->PDIO, 0x3c9, red);
575 VGA_WR08(chip->PDIO, 0x3c9, green);
576 VGA_WR08(chip->PDIO, 0x3c9, blue);
577}
578
579/**
580 * riva_rclut - read fromCLUT register
581 * @chip: pointer to RIVA_HW_INST object
582 * @regnum: register number
583 * @red: red component
584 * @green: green component
585 * @blue: blue component
586 *
587 * DESCRIPTION:
588 * Reads red, green, and blue from color register @regnum.
589 *
590 * CALLED FROM:
591 * rivafb_setcolreg()
592 */
593static void riva_rclut(RIVA_HW_INST *chip,
594 unsigned char regnum, unsigned char *red,
595 unsigned char *green, unsigned char *blue)
596{
597
598 VGA_WR08(chip->PDIO, 0x3c7, regnum);
599 *red = VGA_RD08(chip->PDIO, 0x3c9);
600 *green = VGA_RD08(chip->PDIO, 0x3c9);
601 *blue = VGA_RD08(chip->PDIO, 0x3c9);
602}
603
604/**
605 * riva_save_state - saves current chip state
606 * @par: pointer to riva_par object containing info for current riva board
607 * @regs: pointer to riva_regs object
608 *
609 * DESCRIPTION:
610 * Saves current chip state to @regs.
611 *
612 * CALLED FROM:
613 * rivafb_probe()
614 */
615/* from GGI */
616static void riva_save_state(struct riva_par *par, struct riva_regs *regs)
617{
618 int i;
619
620 NVTRACE_ENTER();
621 par->riva.LockUnlock(&par->riva, 0);
622
623 par->riva.UnloadStateExt(&par->riva, &regs->ext);
624
625 regs->misc_output = MISCin(par);
626
627 for (i = 0; i < NUM_CRT_REGS; i++)
628 regs->crtc[i] = CRTCin(par, i);
629
630 for (i = 0; i < NUM_ATC_REGS; i++)
631 regs->attr[i] = ATTRin(par, i);
632
633 for (i = 0; i < NUM_GRC_REGS; i++)
634 regs->gra[i] = GRAin(par, i);
635
636 for (i = 0; i < NUM_SEQ_REGS; i++)
637 regs->seq[i] = SEQin(par, i);
638 NVTRACE_LEAVE();
639}
640
641/**
642 * riva_load_state - loads current chip state
643 * @par: pointer to riva_par object containing info for current riva board
644 * @regs: pointer to riva_regs object
645 *
646 * DESCRIPTION:
647 * Loads chip state from @regs.
648 *
649 * CALLED FROM:
650 * riva_load_video_mode()
651 * rivafb_probe()
652 * rivafb_remove()
653 */
654/* from GGI */
655static void riva_load_state(struct riva_par *par, struct riva_regs *regs)
656{
657 RIVA_HW_STATE *state = &regs->ext;
658 int i;
659
660 NVTRACE_ENTER();
661 CRTCout(par, 0x11, 0x00);
662
663 par->riva.LockUnlock(&par->riva, 0);
664
665 par->riva.LoadStateExt(&par->riva, state);
666
667 MISCout(par, regs->misc_output);
668
669 for (i = 0; i < NUM_CRT_REGS; i++) {
670 switch (i) {
671 case 0x19:
672 case 0x20 ... 0x40:
673 break;
674 default:
675 CRTCout(par, i, regs->crtc[i]);
676 }
677 }
678
679 for (i = 0; i < NUM_ATC_REGS; i++)
680 ATTRout(par, i, regs->attr[i]);
681
682 for (i = 0; i < NUM_GRC_REGS; i++)
683 GRAout(par, i, regs->gra[i]);
684
685 for (i = 0; i < NUM_SEQ_REGS; i++)
686 SEQout(par, i, regs->seq[i]);
687 NVTRACE_LEAVE();
688}
689
690/**
691 * riva_load_video_mode - calculate timings
692 * @info: pointer to fb_info object containing info for current riva board
693 *
694 * DESCRIPTION:
695 * Calculate some timings and then send em off to riva_load_state().
696 *
697 * CALLED FROM:
698 * rivafb_set_par()
699 */
Jeff Garzikfd717682006-12-08 02:40:17 -0800700static int riva_load_video_mode(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701{
702 int bpp, width, hDisplaySize, hDisplay, hStart,
703 hEnd, hTotal, height, vDisplay, vStart, vEnd, vTotal, dotClock;
704 int hBlankStart, hBlankEnd, vBlankStart, vBlankEnd;
Jeff Garzikfd717682006-12-08 02:40:17 -0800705 int rc;
Antonino A. Daplasf4a41832006-01-09 20:53:04 -0800706 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 struct riva_regs newmode;
708
709 NVTRACE_ENTER();
710 /* time to calculate */
Guido Guenther535a09a2006-10-03 01:14:40 -0700711 rivafb_blank(FB_BLANK_NORMAL, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
713 bpp = info->var.bits_per_pixel;
714 if (bpp == 16 && info->var.green.length == 5)
715 bpp = 15;
716 width = info->var.xres_virtual;
717 hDisplaySize = info->var.xres;
718 hDisplay = (hDisplaySize / 8) - 1;
719 hStart = (hDisplaySize + info->var.right_margin) / 8 - 1;
720 hEnd = (hDisplaySize + info->var.right_margin +
721 info->var.hsync_len) / 8 - 1;
722 hTotal = (hDisplaySize + info->var.right_margin +
723 info->var.hsync_len + info->var.left_margin) / 8 - 5;
724 hBlankStart = hDisplay;
725 hBlankEnd = hTotal + 4;
726
727 height = info->var.yres_virtual;
728 vDisplay = info->var.yres - 1;
729 vStart = info->var.yres + info->var.lower_margin - 1;
730 vEnd = info->var.yres + info->var.lower_margin +
731 info->var.vsync_len - 1;
732 vTotal = info->var.yres + info->var.lower_margin +
733 info->var.vsync_len + info->var.upper_margin + 2;
734 vBlankStart = vDisplay;
735 vBlankEnd = vTotal + 1;
736 dotClock = 1000000000 / info->var.pixclock;
737
738 memcpy(&newmode, &reg_template, sizeof(struct riva_regs));
739
740 if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED)
741 vTotal |= 1;
742
743 if (par->FlatPanel) {
744 vStart = vTotal - 3;
745 vEnd = vTotal - 2;
746 vBlankStart = vStart;
747 hStart = hTotal - 3;
748 hEnd = hTotal - 2;
749 hBlankEnd = hTotal + 4;
750 }
751
752 newmode.crtc[0x0] = Set8Bits (hTotal);
753 newmode.crtc[0x1] = Set8Bits (hDisplay);
754 newmode.crtc[0x2] = Set8Bits (hBlankStart);
755 newmode.crtc[0x3] = SetBitField (hBlankEnd, 4: 0, 4:0) | SetBit (7);
756 newmode.crtc[0x4] = Set8Bits (hStart);
757 newmode.crtc[0x5] = SetBitField (hBlankEnd, 5: 5, 7:7)
758 | SetBitField (hEnd, 4: 0, 4:0);
759 newmode.crtc[0x6] = SetBitField (vTotal, 7: 0, 7:0);
760 newmode.crtc[0x7] = SetBitField (vTotal, 8: 8, 0:0)
761 | SetBitField (vDisplay, 8: 8, 1:1)
762 | SetBitField (vStart, 8: 8, 2:2)
763 | SetBitField (vBlankStart, 8: 8, 3:3)
764 | SetBit (4)
765 | SetBitField (vTotal, 9: 9, 5:5)
766 | SetBitField (vDisplay, 9: 9, 6:6)
767 | SetBitField (vStart, 9: 9, 7:7);
768 newmode.crtc[0x9] = SetBitField (vBlankStart, 9: 9, 5:5)
769 | SetBit (6);
770 newmode.crtc[0x10] = Set8Bits (vStart);
771 newmode.crtc[0x11] = SetBitField (vEnd, 3: 0, 3:0)
772 | SetBit (5);
773 newmode.crtc[0x12] = Set8Bits (vDisplay);
774 newmode.crtc[0x13] = (width / 8) * ((bpp + 1) / 8);
775 newmode.crtc[0x15] = Set8Bits (vBlankStart);
776 newmode.crtc[0x16] = Set8Bits (vBlankEnd);
777
778 newmode.ext.screen = SetBitField(hBlankEnd,6:6,4:4)
779 | SetBitField(vBlankStart,10:10,3:3)
780 | SetBitField(vStart,10:10,2:2)
781 | SetBitField(vDisplay,10:10,1:1)
782 | SetBitField(vTotal,10:10,0:0);
783 newmode.ext.horiz = SetBitField(hTotal,8:8,0:0)
784 | SetBitField(hDisplay,8:8,1:1)
785 | SetBitField(hBlankStart,8:8,2:2)
786 | SetBitField(hStart,8:8,3:3);
787 newmode.ext.extra = SetBitField(vTotal,11:11,0:0)
788 | SetBitField(vDisplay,11:11,2:2)
789 | SetBitField(vStart,11:11,4:4)
790 | SetBitField(vBlankStart,11:11,6:6);
791
792 if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
793 int tmp = (hTotal >> 1) & ~1;
794 newmode.ext.interlace = Set8Bits(tmp);
795 newmode.ext.horiz |= SetBitField(tmp, 8:8,4:4);
796 } else
797 newmode.ext.interlace = 0xff; /* interlace off */
798
799 if (par->riva.Architecture >= NV_ARCH_10)
800 par->riva.CURSOR = (U032 __iomem *)(info->screen_base + par->riva.CursorStart);
801
802 if (info->var.sync & FB_SYNC_HOR_HIGH_ACT)
803 newmode.misc_output &= ~0x40;
804 else
805 newmode.misc_output |= 0x40;
806 if (info->var.sync & FB_SYNC_VERT_HIGH_ACT)
807 newmode.misc_output &= ~0x80;
808 else
809 newmode.misc_output |= 0x80;
810
Jeff Garzikfd717682006-12-08 02:40:17 -0800811 rc = CalcStateExt(&par->riva, &newmode.ext, bpp, width,
812 hDisplaySize, height, dotClock);
813 if (rc)
814 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
816 newmode.ext.scale = NV_RD32(par->riva.PRAMDAC, 0x00000848) &
817 0xfff000ff;
818 if (par->FlatPanel == 1) {
819 newmode.ext.pixel |= (1 << 7);
820 newmode.ext.scale |= (1 << 8);
821 }
822 if (par->SecondCRTC) {
823 newmode.ext.head = NV_RD32(par->riva.PCRTC0, 0x00000860) &
824 ~0x00001000;
825 newmode.ext.head2 = NV_RD32(par->riva.PCRTC0, 0x00002860) |
826 0x00001000;
827 newmode.ext.crtcOwner = 3;
828 newmode.ext.pllsel |= 0x20000800;
829 newmode.ext.vpll2 = newmode.ext.vpll;
830 } else if (par->riva.twoHeads) {
831 newmode.ext.head = NV_RD32(par->riva.PCRTC0, 0x00000860) |
832 0x00001000;
833 newmode.ext.head2 = NV_RD32(par->riva.PCRTC0, 0x00002860) &
834 ~0x00001000;
835 newmode.ext.crtcOwner = 0;
836 newmode.ext.vpll2 = NV_RD32(par->riva.PRAMDAC0, 0x00000520);
837 }
838 if (par->FlatPanel == 1) {
839 newmode.ext.pixel |= (1 << 7);
840 newmode.ext.scale |= (1 << 8);
841 }
842 newmode.ext.cursorConfig = 0x02000100;
843 par->current_state = newmode;
844 riva_load_state(par, &par->current_state);
845 par->riva.LockUnlock(&par->riva, 0); /* important for HW cursor */
Jeff Garzikfd717682006-12-08 02:40:17 -0800846
847out:
Guido Guenther535a09a2006-10-03 01:14:40 -0700848 rivafb_blank(FB_BLANK_UNBLANK, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 NVTRACE_LEAVE();
Jeff Garzikfd717682006-12-08 02:40:17 -0800850
851 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852}
853
Geert Uytterhoeven9791d762007-02-12 00:55:19 -0800854static void riva_update_var(struct fb_var_screeninfo *var,
855 const struct fb_videomode *modedb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856{
857 NVTRACE_ENTER();
858 var->xres = var->xres_virtual = modedb->xres;
859 var->yres = modedb->yres;
860 if (var->yres_virtual < var->yres)
861 var->yres_virtual = var->yres;
862 var->xoffset = var->yoffset = 0;
863 var->pixclock = modedb->pixclock;
864 var->left_margin = modedb->left_margin;
865 var->right_margin = modedb->right_margin;
866 var->upper_margin = modedb->upper_margin;
867 var->lower_margin = modedb->lower_margin;
868 var->hsync_len = modedb->hsync_len;
869 var->vsync_len = modedb->vsync_len;
870 var->sync = modedb->sync;
871 var->vmode = modedb->vmode;
872 NVTRACE_LEAVE();
873}
874
875/**
876 * rivafb_do_maximize -
877 * @info: pointer to fb_info object containing info for current riva board
878 * @var:
879 * @nom:
880 * @den:
881 *
882 * DESCRIPTION:
883 * .
884 *
885 * RETURNS:
886 * -EINVAL on failure, 0 on success
887 *
888 *
889 * CALLED FROM:
890 * rivafb_check_var()
891 */
892static int rivafb_do_maximize(struct fb_info *info,
893 struct fb_var_screeninfo *var,
894 int nom, int den)
895{
896 static struct {
897 int xres, yres;
898 } modes[] = {
899 {1600, 1280},
900 {1280, 1024},
901 {1024, 768},
902 {800, 600},
903 {640, 480},
904 {-1, -1}
905 };
906 int i;
907
908 NVTRACE_ENTER();
909 /* use highest possible virtual resolution */
910 if (var->xres_virtual == -1 && var->yres_virtual == -1) {
911 printk(KERN_WARNING PFX
912 "using maximum available virtual resolution\n");
913 for (i = 0; modes[i].xres != -1; i++) {
914 if (modes[i].xres * nom / den * modes[i].yres <
915 info->fix.smem_len)
916 break;
917 }
918 if (modes[i].xres == -1) {
919 printk(KERN_ERR PFX
920 "could not find a virtual resolution that fits into video memory!!\n");
921 NVTRACE("EXIT - EINVAL error\n");
922 return -EINVAL;
923 }
924 var->xres_virtual = modes[i].xres;
925 var->yres_virtual = modes[i].yres;
926
927 printk(KERN_INFO PFX
928 "virtual resolution set to maximum of %dx%d\n",
929 var->xres_virtual, var->yres_virtual);
930 } else if (var->xres_virtual == -1) {
931 var->xres_virtual = (info->fix.smem_len * den /
932 (nom * var->yres_virtual)) & ~15;
933 printk(KERN_WARNING PFX
934 "setting virtual X resolution to %d\n", var->xres_virtual);
935 } else if (var->yres_virtual == -1) {
936 var->xres_virtual = (var->xres_virtual + 15) & ~15;
937 var->yres_virtual = info->fix.smem_len * den /
938 (nom * var->xres_virtual);
939 printk(KERN_WARNING PFX
940 "setting virtual Y resolution to %d\n", var->yres_virtual);
941 } else {
942 var->xres_virtual = (var->xres_virtual + 15) & ~15;
943 if (var->xres_virtual * nom / den * var->yres_virtual > info->fix.smem_len) {
944 printk(KERN_ERR PFX
945 "mode %dx%dx%d rejected...resolution too high to fit into video memory!\n",
946 var->xres, var->yres, var->bits_per_pixel);
947 NVTRACE("EXIT - EINVAL error\n");
948 return -EINVAL;
949 }
950 }
951
952 if (var->xres_virtual * nom / den >= 8192) {
953 printk(KERN_WARNING PFX
954 "virtual X resolution (%d) is too high, lowering to %d\n",
955 var->xres_virtual, 8192 * den / nom - 16);
956 var->xres_virtual = 8192 * den / nom - 16;
957 }
958
959 if (var->xres_virtual < var->xres) {
960 printk(KERN_ERR PFX
961 "virtual X resolution (%d) is smaller than real\n", var->xres_virtual);
962 return -EINVAL;
963 }
964
965 if (var->yres_virtual < var->yres) {
966 printk(KERN_ERR PFX
967 "virtual Y resolution (%d) is smaller than real\n", var->yres_virtual);
968 return -EINVAL;
969 }
970 if (var->yres_virtual > 0x7fff/nom)
971 var->yres_virtual = 0x7fff/nom;
972 if (var->xres_virtual > 0x7fff/nom)
973 var->xres_virtual = 0x7fff/nom;
974 NVTRACE_LEAVE();
975 return 0;
976}
977
978static void
979riva_set_pattern(struct riva_par *par, int clr0, int clr1, int pat0, int pat1)
980{
981 RIVA_FIFO_FREE(par->riva, Patt, 4);
982 NV_WR32(&par->riva.Patt->Color0, 0, clr0);
983 NV_WR32(&par->riva.Patt->Color1, 0, clr1);
984 NV_WR32(par->riva.Patt->Monochrome, 0, pat0);
985 NV_WR32(par->riva.Patt->Monochrome, 4, pat1);
986}
987
988/* acceleration routines */
989static inline void wait_for_idle(struct riva_par *par)
990{
991 while (par->riva.Busy(&par->riva));
992}
993
994/*
995 * Set ROP. Translate X rop into ROP3. Internal routine.
996 */
997static void
998riva_set_rop_solid(struct riva_par *par, int rop)
999{
1000 riva_set_pattern(par, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
1001 RIVA_FIFO_FREE(par->riva, Rop, 1);
1002 NV_WR32(&par->riva.Rop->Rop3, 0, rop);
1003
1004}
1005
1006static void riva_setup_accel(struct fb_info *info)
1007{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001008 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
1010 RIVA_FIFO_FREE(par->riva, Clip, 2);
1011 NV_WR32(&par->riva.Clip->TopLeft, 0, 0x0);
1012 NV_WR32(&par->riva.Clip->WidthHeight, 0,
1013 (info->var.xres_virtual & 0xffff) |
1014 (info->var.yres_virtual << 16));
1015 riva_set_rop_solid(par, 0xcc);
1016 wait_for_idle(par);
1017}
1018
1019/**
1020 * riva_get_cmap_len - query current color map length
1021 * @var: standard kernel fb changeable data
1022 *
1023 * DESCRIPTION:
1024 * Get current color map length.
1025 *
1026 * RETURNS:
1027 * Length of color map
1028 *
1029 * CALLED FROM:
1030 * rivafb_setcolreg()
1031 */
1032static int riva_get_cmap_len(const struct fb_var_screeninfo *var)
1033{
1034 int rc = 256; /* reasonable default */
1035
1036 switch (var->green.length) {
1037 case 8:
1038 rc = 256; /* 256 entries (2^8), 8 bpp and RGB8888 */
1039 break;
1040 case 5:
1041 rc = 32; /* 32 entries (2^5), 16 bpp, RGB555 */
1042 break;
1043 case 6:
1044 rc = 64; /* 64 entries (2^6), 16 bpp, RGB565 */
1045 break;
1046 default:
1047 /* should not occur */
1048 break;
1049 }
1050 return rc;
1051}
1052
1053/* ------------------------------------------------------------------------- *
1054 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 * framebuffer operations
1056 *
1057 * ------------------------------------------------------------------------- */
1058
1059static int rivafb_open(struct fb_info *info, int user)
1060{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001061 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
1063 NVTRACE_ENTER();
Jiri Slabyc4f28e52007-02-12 00:55:11 -08001064 mutex_lock(&par->open_lock);
1065 if (!par->ref_count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066#ifdef CONFIG_X86
1067 memset(&par->state, 0, sizeof(struct vgastate));
1068 par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS;
1069 /* save the DAC for Riva128 */
1070 if (par->riva.Architecture == NV_ARCH_03)
1071 par->state.flags |= VGA_SAVE_CMAP;
1072 save_vga(&par->state);
1073#endif
1074 /* vgaHWunlock() + riva unlock (0x7F) */
1075 CRTCout(par, 0x11, 0xFF);
1076 par->riva.LockUnlock(&par->riva, 0);
1077
1078 riva_save_state(par, &par->initial_state);
1079 }
Jiri Slabyc4f28e52007-02-12 00:55:11 -08001080 par->ref_count++;
1081 mutex_unlock(&par->open_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 NVTRACE_LEAVE();
1083 return 0;
1084}
1085
1086static int rivafb_release(struct fb_info *info, int user)
1087{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001088 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
1090 NVTRACE_ENTER();
Jiri Slabyc4f28e52007-02-12 00:55:11 -08001091 mutex_lock(&par->open_lock);
1092 if (!par->ref_count) {
1093 mutex_unlock(&par->open_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 return -EINVAL;
Jiri Slabyc4f28e52007-02-12 00:55:11 -08001095 }
1096 if (par->ref_count == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 par->riva.LockUnlock(&par->riva, 0);
1098 par->riva.LoadStateExt(&par->riva, &par->initial_state.ext);
1099 riva_load_state(par, &par->initial_state);
1100#ifdef CONFIG_X86
1101 restore_vga(&par->state);
1102#endif
1103 par->riva.LockUnlock(&par->riva, 1);
1104 }
Jiri Slabyc4f28e52007-02-12 00:55:11 -08001105 par->ref_count--;
1106 mutex_unlock(&par->open_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 NVTRACE_LEAVE();
1108 return 0;
1109}
1110
1111static int rivafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1112{
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08001113 const struct fb_videomode *mode;
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001114 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 int nom, den; /* translating from pixels->bytes */
1116 int mode_valid = 0;
1117
1118 NVTRACE_ENTER();
1119 switch (var->bits_per_pixel) {
1120 case 1 ... 8:
1121 var->red.offset = var->green.offset = var->blue.offset = 0;
1122 var->red.length = var->green.length = var->blue.length = 8;
1123 var->bits_per_pixel = 8;
1124 nom = den = 1;
1125 break;
1126 case 9 ... 15:
1127 var->green.length = 5;
1128 /* fall through */
1129 case 16:
1130 var->bits_per_pixel = 16;
1131 /* The Riva128 supports RGB555 only */
1132 if (par->riva.Architecture == NV_ARCH_03)
1133 var->green.length = 5;
1134 if (var->green.length == 5) {
1135 /* 0rrrrrgg gggbbbbb */
1136 var->red.offset = 10;
1137 var->green.offset = 5;
1138 var->blue.offset = 0;
1139 var->red.length = 5;
1140 var->green.length = 5;
1141 var->blue.length = 5;
1142 } else {
1143 /* rrrrrggg gggbbbbb */
1144 var->red.offset = 11;
1145 var->green.offset = 5;
1146 var->blue.offset = 0;
1147 var->red.length = 5;
1148 var->green.length = 6;
1149 var->blue.length = 5;
1150 }
1151 nom = 2;
1152 den = 1;
1153 break;
1154 case 17 ... 32:
1155 var->red.length = var->green.length = var->blue.length = 8;
1156 var->bits_per_pixel = 32;
1157 var->red.offset = 16;
1158 var->green.offset = 8;
1159 var->blue.offset = 0;
1160 nom = 4;
1161 den = 1;
1162 break;
1163 default:
1164 printk(KERN_ERR PFX
1165 "mode %dx%dx%d rejected...color depth not supported.\n",
1166 var->xres, var->yres, var->bits_per_pixel);
1167 NVTRACE("EXIT, returning -EINVAL\n");
1168 return -EINVAL;
1169 }
1170
1171 if (!strictmode) {
1172 if (!info->monspecs.vfmax || !info->monspecs.hfmax ||
1173 !info->monspecs.dclkmax || !fb_validate_mode(var, info))
1174 mode_valid = 1;
1175 }
1176
1177 /* calculate modeline if supported by monitor */
1178 if (!mode_valid && info->monspecs.gtf) {
1179 if (!fb_get_mode(FB_MAXTIMINGS, 0, var, info))
1180 mode_valid = 1;
1181 }
1182
1183 if (!mode_valid) {
1184 mode = fb_find_best_mode(var, &info->modelist);
1185 if (mode) {
1186 riva_update_var(var, mode);
1187 mode_valid = 1;
1188 }
1189 }
1190
1191 if (!mode_valid && info->monspecs.modedb_len)
1192 return -EINVAL;
1193
1194 if (var->xres_virtual < var->xres)
1195 var->xres_virtual = var->xres;
1196 if (var->yres_virtual <= var->yres)
1197 var->yres_virtual = -1;
1198 if (rivafb_do_maximize(info, var, nom, den) < 0)
1199 return -EINVAL;
1200
1201 if (var->xoffset < 0)
1202 var->xoffset = 0;
1203 if (var->yoffset < 0)
1204 var->yoffset = 0;
1205
1206 /* truncate xoffset and yoffset to maximum if too high */
1207 if (var->xoffset > var->xres_virtual - var->xres)
1208 var->xoffset = var->xres_virtual - var->xres - 1;
1209
1210 if (var->yoffset > var->yres_virtual - var->yres)
1211 var->yoffset = var->yres_virtual - var->yres - 1;
1212
1213 var->red.msb_right =
1214 var->green.msb_right =
1215 var->blue.msb_right =
1216 var->transp.offset = var->transp.length = var->transp.msb_right = 0;
1217 NVTRACE_LEAVE();
1218 return 0;
1219}
1220
1221static int rivafb_set_par(struct fb_info *info)
1222{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001223 struct riva_par *par = info->par;
Jeff Garzikfd717682006-12-08 02:40:17 -08001224 int rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225
1226 NVTRACE_ENTER();
1227 /* vgaHWunlock() + riva unlock (0x7F) */
1228 CRTCout(par, 0x11, 0xFF);
1229 par->riva.LockUnlock(&par->riva, 0);
Jeff Garzikfd717682006-12-08 02:40:17 -08001230 rc = riva_load_video_mode(info);
1231 if (rc)
1232 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 if(!(info->flags & FBINFO_HWACCEL_DISABLED))
1234 riva_setup_accel(info);
1235
1236 par->cursor_reset = 1;
1237 info->fix.line_length = (info->var.xres_virtual * (info->var.bits_per_pixel >> 3));
1238 info->fix.visual = (info->var.bits_per_pixel == 8) ?
1239 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
1240
1241 if (info->flags & FBINFO_HWACCEL_DISABLED)
1242 info->pixmap.scan_align = 1;
1243 else
1244 info->pixmap.scan_align = 4;
Jeff Garzikfd717682006-12-08 02:40:17 -08001245
1246out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 NVTRACE_LEAVE();
Jeff Garzikfd717682006-12-08 02:40:17 -08001248 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249}
1250
1251/**
1252 * rivafb_pan_display
1253 * @var: standard kernel fb changeable data
1254 * @con: TODO
1255 * @info: pointer to fb_info object containing info for current riva board
1256 *
1257 * DESCRIPTION:
1258 * Pan (or wrap, depending on the `vmode' field) the display using the
1259 * `xoffset' and `yoffset' fields of the `var' structure.
1260 * If the values don't fit, return -EINVAL.
1261 *
1262 * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
1263 */
1264static int rivafb_pan_display(struct fb_var_screeninfo *var,
1265 struct fb_info *info)
1266{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001267 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 unsigned int base;
1269
1270 NVTRACE_ENTER();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 base = var->yoffset * info->fix.line_length + var->xoffset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 par->riva.SetStartAddress(&par->riva, base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 NVTRACE_LEAVE();
1274 return 0;
1275}
1276
1277static int rivafb_blank(int blank, struct fb_info *info)
1278{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001279 struct riva_par *par= info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 unsigned char tmp, vesa;
1281
1282 tmp = SEQin(par, 0x01) & ~0x20; /* screen on/off */
1283 vesa = CRTCin(par, 0x1a) & ~0xc0; /* sync on/off */
1284
1285 NVTRACE_ENTER();
1286
1287 if (blank)
1288 tmp |= 0x20;
1289
1290 switch (blank) {
1291 case FB_BLANK_UNBLANK:
1292 case FB_BLANK_NORMAL:
1293 break;
1294 case FB_BLANK_VSYNC_SUSPEND:
1295 vesa |= 0x80;
1296 break;
1297 case FB_BLANK_HSYNC_SUSPEND:
1298 vesa |= 0x40;
1299 break;
1300 case FB_BLANK_POWERDOWN:
1301 vesa |= 0xc0;
1302 break;
1303 }
1304
1305 SEQout(par, 0x01, tmp);
1306 CRTCout(par, 0x1a, vesa);
1307
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 NVTRACE_LEAVE();
1309
1310 return 0;
1311}
1312
1313/**
1314 * rivafb_setcolreg
1315 * @regno: register index
1316 * @red: red component
1317 * @green: green component
1318 * @blue: blue component
1319 * @transp: transparency
1320 * @info: pointer to fb_info object containing info for current riva board
1321 *
1322 * DESCRIPTION:
1323 * Set a single color register. The values supplied have a 16 bit
1324 * magnitude.
1325 *
1326 * RETURNS:
1327 * Return != 0 for invalid regno.
1328 *
1329 * CALLED FROM:
1330 * fbcmap.c:fb_set_cmap()
1331 */
1332static int rivafb_setcolreg(unsigned regno, unsigned red, unsigned green,
1333 unsigned blue, unsigned transp,
1334 struct fb_info *info)
1335{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001336 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 RIVA_HW_INST *chip = &par->riva;
1338 int i;
1339
1340 if (regno >= riva_get_cmap_len(&info->var))
1341 return -EINVAL;
1342
1343 if (info->var.grayscale) {
1344 /* gray = 0.30*R + 0.59*G + 0.11*B */
1345 red = green = blue =
1346 (red * 77 + green * 151 + blue * 28) >> 8;
1347 }
1348
1349 if (regno < 16 && info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
1350 ((u32 *) info->pseudo_palette)[regno] =
1351 (regno << info->var.red.offset) |
1352 (regno << info->var.green.offset) |
1353 (regno << info->var.blue.offset);
1354 /*
1355 * The Riva128 2D engine requires color information in
1356 * TrueColor format even if framebuffer is in DirectColor
1357 */
1358 if (par->riva.Architecture == NV_ARCH_03) {
1359 switch (info->var.bits_per_pixel) {
1360 case 16:
1361 par->palette[regno] = ((red & 0xf800) >> 1) |
1362 ((green & 0xf800) >> 6) |
1363 ((blue & 0xf800) >> 11);
1364 break;
1365 case 32:
1366 par->palette[regno] = ((red & 0xff00) << 8) |
1367 ((green & 0xff00)) |
1368 ((blue & 0xff00) >> 8);
1369 break;
1370 }
1371 }
1372 }
1373
1374 switch (info->var.bits_per_pixel) {
1375 case 8:
1376 /* "transparent" stuff is completely ignored. */
1377 riva_wclut(chip, regno, red >> 8, green >> 8, blue >> 8);
1378 break;
1379 case 16:
1380 if (info->var.green.length == 5) {
1381 for (i = 0; i < 8; i++) {
1382 riva_wclut(chip, regno*8+i, red >> 8,
1383 green >> 8, blue >> 8);
1384 }
1385 } else {
1386 u8 r, g, b;
1387
1388 if (regno < 32) {
1389 for (i = 0; i < 8; i++) {
1390 riva_wclut(chip, regno*8+i,
1391 red >> 8, green >> 8,
1392 blue >> 8);
1393 }
1394 }
1395 riva_rclut(chip, regno*4, &r, &g, &b);
1396 for (i = 0; i < 4; i++)
1397 riva_wclut(chip, regno*4+i, r,
1398 green >> 8, b);
1399 }
1400 break;
1401 case 32:
1402 riva_wclut(chip, regno, red >> 8, green >> 8, blue >> 8);
1403 break;
1404 default:
1405 /* do nothing */
1406 break;
1407 }
1408 return 0;
1409}
1410
1411/**
1412 * rivafb_fillrect - hardware accelerated color fill function
1413 * @info: pointer to fb_info structure
1414 * @rect: pointer to fb_fillrect structure
1415 *
1416 * DESCRIPTION:
1417 * This function fills up a region of framebuffer memory with a solid
1418 * color with a choice of two different ROP's, copy or invert.
1419 *
1420 * CALLED FROM:
1421 * framebuffer hook
1422 */
1423static void rivafb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
1424{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001425 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 u_int color, rop = 0;
1427
1428 if ((info->flags & FBINFO_HWACCEL_DISABLED)) {
1429 cfb_fillrect(info, rect);
1430 return;
1431 }
1432
1433 if (info->var.bits_per_pixel == 8)
1434 color = rect->color;
1435 else {
1436 if (par->riva.Architecture != NV_ARCH_03)
1437 color = ((u32 *)info->pseudo_palette)[rect->color];
1438 else
1439 color = par->palette[rect->color];
1440 }
1441
1442 switch (rect->rop) {
1443 case ROP_XOR:
1444 rop = 0x66;
1445 break;
1446 case ROP_COPY:
1447 default:
1448 rop = 0xCC;
1449 break;
1450 }
1451
1452 riva_set_rop_solid(par, rop);
1453
1454 RIVA_FIFO_FREE(par->riva, Bitmap, 1);
1455 NV_WR32(&par->riva.Bitmap->Color1A, 0, color);
1456
1457 RIVA_FIFO_FREE(par->riva, Bitmap, 2);
1458 NV_WR32(&par->riva.Bitmap->UnclippedRectangle[0].TopLeft, 0,
1459 (rect->dx << 16) | rect->dy);
1460 mb();
1461 NV_WR32(&par->riva.Bitmap->UnclippedRectangle[0].WidthHeight, 0,
1462 (rect->width << 16) | rect->height);
1463 mb();
1464 riva_set_rop_solid(par, 0xcc);
1465
1466}
1467
1468/**
1469 * rivafb_copyarea - hardware accelerated blit function
1470 * @info: pointer to fb_info structure
1471 * @region: pointer to fb_copyarea structure
1472 *
1473 * DESCRIPTION:
1474 * This copies an area of pixels from one location to another
1475 *
1476 * CALLED FROM:
1477 * framebuffer hook
1478 */
1479static void rivafb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
1480{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001481 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
1483 if ((info->flags & FBINFO_HWACCEL_DISABLED)) {
1484 cfb_copyarea(info, region);
1485 return;
1486 }
1487
1488 RIVA_FIFO_FREE(par->riva, Blt, 3);
1489 NV_WR32(&par->riva.Blt->TopLeftSrc, 0,
1490 (region->sy << 16) | region->sx);
1491 NV_WR32(&par->riva.Blt->TopLeftDst, 0,
1492 (region->dy << 16) | region->dx);
1493 mb();
1494 NV_WR32(&par->riva.Blt->WidthHeight, 0,
1495 (region->height << 16) | region->width);
1496 mb();
1497}
1498
1499static inline void convert_bgcolor_16(u32 *col)
1500{
1501 *col = ((*col & 0x0000F800) << 8)
1502 | ((*col & 0x00007E0) << 5)
1503 | ((*col & 0x0000001F) << 3)
1504 | 0xFF000000;
1505 mb();
1506}
1507
1508/**
1509 * rivafb_imageblit: hardware accelerated color expand function
1510 * @info: pointer to fb_info structure
1511 * @image: pointer to fb_image structure
1512 *
1513 * DESCRIPTION:
1514 * If the source is a monochrome bitmap, the function fills up a a region
1515 * of framebuffer memory with pixels whose color is determined by the bit
1516 * setting of the bitmap, 1 - foreground, 0 - background.
1517 *
1518 * If the source is not a monochrome bitmap, color expansion is not done.
1519 * In this case, it is channeled to a software function.
1520 *
1521 * CALLED FROM:
1522 * framebuffer hook
1523 */
1524static void rivafb_imageblit(struct fb_info *info,
1525 const struct fb_image *image)
1526{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001527 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 u32 fgx = 0, bgx = 0, width, tmp;
1529 u8 *cdat = (u8 *) image->data;
1530 volatile u32 __iomem *d;
1531 int i, size;
1532
1533 if ((info->flags & FBINFO_HWACCEL_DISABLED) || image->depth != 1) {
1534 cfb_imageblit(info, image);
1535 return;
1536 }
1537
1538 switch (info->var.bits_per_pixel) {
1539 case 8:
1540 fgx = image->fg_color;
1541 bgx = image->bg_color;
1542 break;
1543 case 16:
1544 case 32:
1545 if (par->riva.Architecture != NV_ARCH_03) {
1546 fgx = ((u32 *)info->pseudo_palette)[image->fg_color];
1547 bgx = ((u32 *)info->pseudo_palette)[image->bg_color];
1548 } else {
1549 fgx = par->palette[image->fg_color];
1550 bgx = par->palette[image->bg_color];
1551 }
1552 if (info->var.green.length == 6)
1553 convert_bgcolor_16(&bgx);
1554 break;
1555 }
1556
1557 RIVA_FIFO_FREE(par->riva, Bitmap, 7);
1558 NV_WR32(&par->riva.Bitmap->ClipE.TopLeft, 0,
1559 (image->dy << 16) | (image->dx & 0xFFFF));
1560 NV_WR32(&par->riva.Bitmap->ClipE.BottomRight, 0,
1561 (((image->dy + image->height) << 16) |
1562 ((image->dx + image->width) & 0xffff)));
1563 NV_WR32(&par->riva.Bitmap->Color0E, 0, bgx);
1564 NV_WR32(&par->riva.Bitmap->Color1E, 0, fgx);
1565 NV_WR32(&par->riva.Bitmap->WidthHeightInE, 0,
1566 (image->height << 16) | ((image->width + 31) & ~31));
1567 NV_WR32(&par->riva.Bitmap->WidthHeightOutE, 0,
1568 (image->height << 16) | ((image->width + 31) & ~31));
1569 NV_WR32(&par->riva.Bitmap->PointE, 0,
1570 (image->dy << 16) | (image->dx & 0xFFFF));
1571
1572 d = &par->riva.Bitmap->MonochromeData01E;
1573
1574 width = (image->width + 31)/32;
1575 size = width * image->height;
1576 while (size >= 16) {
1577 RIVA_FIFO_FREE(par->riva, Bitmap, 16);
1578 for (i = 0; i < 16; i++) {
1579 tmp = *((u32 *)cdat);
1580 cdat = (u8 *)((u32 *)cdat + 1);
1581 reverse_order(&tmp);
1582 NV_WR32(d, i*4, tmp);
1583 }
1584 size -= 16;
1585 }
1586 if (size) {
1587 RIVA_FIFO_FREE(par->riva, Bitmap, size);
1588 for (i = 0; i < size; i++) {
1589 tmp = *((u32 *) cdat);
1590 cdat = (u8 *)((u32 *)cdat + 1);
1591 reverse_order(&tmp);
1592 NV_WR32(d, i*4, tmp);
1593 }
1594 }
1595}
1596
1597/**
1598 * rivafb_cursor - hardware cursor function
1599 * @info: pointer to info structure
1600 * @cursor: pointer to fbcursor structure
1601 *
1602 * DESCRIPTION:
1603 * A cursor function that supports displaying a cursor image via hardware.
1604 * Within the kernel, copy and invert rops are supported. If exported
1605 * to user space, only the copy rop will be supported.
1606 *
1607 * CALLED FROM
1608 * framebuffer hook
1609 */
1610static int rivafb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1611{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001612 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 u8 data[MAX_CURS * MAX_CURS/8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 int i, set = cursor->set;
James Simmonsf1ab5da2005-06-21 17:17:07 -07001615 u16 fg, bg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616
James Simmonsf1ab5da2005-06-21 17:17:07 -07001617 if (cursor->image.width > MAX_CURS || cursor->image.height > MAX_CURS)
1618 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619
1620 par->riva.ShowHideCursor(&par->riva, 0);
1621
1622 if (par->cursor_reset) {
1623 set = FB_CUR_SETALL;
1624 par->cursor_reset = 0;
1625 }
1626
1627 if (set & FB_CUR_SETSIZE)
1628 memset_io(par->riva.CURSOR, 0, MAX_CURS * MAX_CURS * 2);
1629
1630 if (set & FB_CUR_SETPOS) {
1631 u32 xx, yy, temp;
1632
1633 yy = cursor->image.dy - info->var.yoffset;
1634 xx = cursor->image.dx - info->var.xoffset;
1635 temp = xx & 0xFFFF;
1636 temp |= yy << 16;
1637
1638 NV_WR32(par->riva.PRAMDAC, 0x0000300, temp);
1639 }
1640
1641
1642 if (set & (FB_CUR_SETSHAPE | FB_CUR_SETCMAP | FB_CUR_SETIMAGE)) {
1643 u32 bg_idx = cursor->image.bg_color;
1644 u32 fg_idx = cursor->image.fg_color;
1645 u32 s_pitch = (cursor->image.width+7) >> 3;
1646 u32 d_pitch = MAX_CURS/8;
1647 u8 *dat = (u8 *) cursor->image.data;
1648 u8 *msk = (u8 *) cursor->mask;
1649 u8 *src;
1650
1651 src = kmalloc(s_pitch * cursor->image.height, GFP_ATOMIC);
1652
1653 if (src) {
1654 switch (cursor->rop) {
1655 case ROP_XOR:
James Simmonsf1ab5da2005-06-21 17:17:07 -07001656 for (i = 0; i < s_pitch * cursor->image.height; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 src[i] = dat[i] ^ msk[i];
1658 break;
1659 case ROP_COPY:
1660 default:
James Simmonsf1ab5da2005-06-21 17:17:07 -07001661 for (i = 0; i < s_pitch * cursor->image.height; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 src[i] = dat[i] & msk[i];
1663 break;
1664 }
1665
James Simmonsf1ab5da2005-06-21 17:17:07 -07001666 fb_pad_aligned_buffer(data, d_pitch, src, s_pitch,
1667 cursor->image.height);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
1669 bg = ((info->cmap.red[bg_idx] & 0xf8) << 7) |
1670 ((info->cmap.green[bg_idx] & 0xf8) << 2) |
1671 ((info->cmap.blue[bg_idx] & 0xf8) >> 3) |
1672 1 << 15;
1673
1674 fg = ((info->cmap.red[fg_idx] & 0xf8) << 7) |
1675 ((info->cmap.green[fg_idx] & 0xf8) << 2) |
1676 ((info->cmap.blue[fg_idx] & 0xf8) >> 3) |
1677 1 << 15;
1678
1679 par->riva.LockUnlock(&par->riva, 0);
1680
1681 rivafb_load_cursor_image(par, data, bg, fg,
1682 cursor->image.width,
1683 cursor->image.height);
1684 kfree(src);
1685 }
1686 }
1687
1688 if (cursor->enable)
1689 par->riva.ShowHideCursor(&par->riva, 1);
1690
1691 return 0;
1692}
1693
1694static int rivafb_sync(struct fb_info *info)
1695{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001696 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
1698 wait_for_idle(par);
1699 return 0;
1700}
1701
1702/* ------------------------------------------------------------------------- *
1703 *
1704 * initialization helper functions
1705 *
1706 * ------------------------------------------------------------------------- */
1707
1708/* kernel interface */
1709static struct fb_ops riva_fb_ops = {
1710 .owner = THIS_MODULE,
1711 .fb_open = rivafb_open,
1712 .fb_release = rivafb_release,
1713 .fb_check_var = rivafb_check_var,
1714 .fb_set_par = rivafb_set_par,
1715 .fb_setcolreg = rivafb_setcolreg,
1716 .fb_pan_display = rivafb_pan_display,
1717 .fb_blank = rivafb_blank,
1718 .fb_fillrect = rivafb_fillrect,
1719 .fb_copyarea = rivafb_copyarea,
1720 .fb_imageblit = rivafb_imageblit,
1721 .fb_cursor = rivafb_cursor,
1722 .fb_sync = rivafb_sync,
1723};
1724
1725static int __devinit riva_set_fbinfo(struct fb_info *info)
1726{
1727 unsigned int cmap_len;
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001728 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729
1730 NVTRACE_ENTER();
1731 info->flags = FBINFO_DEFAULT
1732 | FBINFO_HWACCEL_XPAN
1733 | FBINFO_HWACCEL_YPAN
1734 | FBINFO_HWACCEL_COPYAREA
1735 | FBINFO_HWACCEL_FILLRECT
1736 | FBINFO_HWACCEL_IMAGEBLIT;
1737
1738 /* Accel seems to not work properly on NV30 yet...*/
1739 if ((par->riva.Architecture == NV_ARCH_30) || noaccel) {
1740 printk(KERN_DEBUG PFX "disabling acceleration\n");
1741 info->flags |= FBINFO_HWACCEL_DISABLED;
1742 }
1743
1744 info->var = rivafb_default_var;
1745 info->fix.visual = (info->var.bits_per_pixel == 8) ?
1746 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
1747
1748 info->pseudo_palette = par->pseudo_palette;
1749
1750 cmap_len = riva_get_cmap_len(&info->var);
1751 fb_alloc_cmap(&info->cmap, cmap_len, 0);
1752
1753 info->pixmap.size = 8 * 1024;
1754 info->pixmap.buf_align = 4;
James Simmons58a60642005-06-21 17:17:08 -07001755 info->pixmap.access_align = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 info->pixmap.flags = FB_PIXMAP_SYSTEM;
1757 info->var.yres_virtual = -1;
1758 NVTRACE_LEAVE();
1759 return (rivafb_check_var(&info->var, info));
1760}
1761
1762#ifdef CONFIG_PPC_OF
1763static int __devinit riva_get_EDID_OF(struct fb_info *info, struct pci_dev *pd)
1764{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001765 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 struct device_node *dp;
Al Viro79da3422006-09-23 18:21:35 +01001767 const unsigned char *pedid = NULL;
Al Viro13b5aec2006-09-23 16:44:58 +01001768 const unsigned char *disptype = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 static char *propnames[] = {
1770 "DFP,EDID", "LCD,EDID", "EDID", "EDID1", "EDID,B", "EDID,A", NULL };
1771 int i;
1772
1773 NVTRACE_ENTER();
1774 dp = pci_device_to_OF_node(pd);
1775 for (; dp != NULL; dp = dp->child) {
Jeremy Kerrb04e3dd2006-07-12 15:40:40 +10001776 disptype = get_property(dp, "display-type", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 if (disptype == NULL)
1778 continue;
1779 if (strncmp(disptype, "LCD", 3) != 0)
1780 continue;
1781 for (i = 0; propnames[i] != NULL; ++i) {
Jeremy Kerrb04e3dd2006-07-12 15:40:40 +10001782 pedid = get_property(dp, propnames[i], NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 if (pedid != NULL) {
Andrew Morton0271eb92006-10-04 02:16:24 -07001784 par->EDID = (unsigned char *)pedid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 NVTRACE("LCD found.\n");
1786 return 1;
1787 }
1788 }
1789 }
1790 NVTRACE_LEAVE();
1791 return 0;
1792}
1793#endif /* CONFIG_PPC_OF */
1794
1795#if defined(CONFIG_FB_RIVA_I2C) && !defined(CONFIG_PPC_OF)
1796static int __devinit riva_get_EDID_i2c(struct fb_info *info)
1797{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001798 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 struct fb_var_screeninfo var;
1800 int i;
1801
1802 NVTRACE_ENTER();
1803 riva_create_i2c_busses(par);
1804 for (i = 0; i < par->bus; i++) {
1805 riva_probe_i2c_connector(par, i+1, &par->EDID);
1806 if (par->EDID && !fb_parse_edid(par->EDID, &var)) {
1807 printk(PFX "Found EDID Block from BUS %i\n", i);
1808 break;
1809 }
1810 }
1811
1812 NVTRACE_LEAVE();
1813 return (par->EDID) ? 1 : 0;
1814}
1815#endif /* CONFIG_FB_RIVA_I2C */
1816
1817static void __devinit riva_update_default_var(struct fb_var_screeninfo *var,
1818 struct fb_info *info)
1819{
1820 struct fb_monspecs *specs = &info->monspecs;
1821 struct fb_videomode modedb;
1822
1823 NVTRACE_ENTER();
1824 /* respect mode options */
1825 if (mode_option) {
1826 fb_find_mode(var, info, mode_option,
1827 specs->modedb, specs->modedb_len,
1828 NULL, 8);
1829 } else if (specs->modedb != NULL) {
1830 /* get preferred timing */
1831 if (info->monspecs.misc & FB_MISC_1ST_DETAIL) {
1832 int i;
1833
1834 for (i = 0; i < specs->modedb_len; i++) {
1835 if (specs->modedb[i].flag & FB_MODE_IS_FIRST) {
1836 modedb = specs->modedb[i];
1837 break;
1838 }
1839 }
1840 } else {
1841 /* otherwise, get first mode in database */
1842 modedb = specs->modedb[0];
1843 }
1844 var->bits_per_pixel = 8;
1845 riva_update_var(var, &modedb);
1846 }
1847 NVTRACE_LEAVE();
1848}
1849
1850
1851static void __devinit riva_get_EDID(struct fb_info *info, struct pci_dev *pdev)
1852{
1853 NVTRACE_ENTER();
1854#ifdef CONFIG_PPC_OF
1855 if (!riva_get_EDID_OF(info, pdev))
1856 printk(PFX "could not retrieve EDID from OF\n");
Olaf Hering44456d32005-07-27 11:45:17 -07001857#elif defined(CONFIG_FB_RIVA_I2C)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 if (!riva_get_EDID_i2c(info))
1859 printk(PFX "could not retrieve EDID from DDC/I2C\n");
1860#endif
1861 NVTRACE_LEAVE();
1862}
1863
1864
1865static void __devinit riva_get_edidinfo(struct fb_info *info)
1866{
1867 struct fb_var_screeninfo *var = &rivafb_default_var;
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001868 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869
1870 fb_edid_to_monspecs(par->EDID, &info->monspecs);
1871 fb_videomode_to_modelist(info->monspecs.modedb, info->monspecs.modedb_len,
1872 &info->modelist);
1873 riva_update_default_var(var, info);
1874
1875 /* if user specified flatpanel, we respect that */
1876 if (info->monspecs.input & FB_DISP_DDI)
1877 par->FlatPanel = 1;
1878}
1879
1880/* ------------------------------------------------------------------------- *
1881 *
1882 * PCI bus
1883 *
1884 * ------------------------------------------------------------------------- */
1885
1886static u32 __devinit riva_get_arch(struct pci_dev *pd)
1887{
1888 u32 arch = 0;
1889
1890 switch (pd->device & 0x0ff0) {
1891 case 0x0100: /* GeForce 256 */
1892 case 0x0110: /* GeForce2 MX */
1893 case 0x0150: /* GeForce2 */
1894 case 0x0170: /* GeForce4 MX */
1895 case 0x0180: /* GeForce4 MX (8x AGP) */
1896 case 0x01A0: /* nForce */
1897 case 0x01F0: /* nForce2 */
1898 arch = NV_ARCH_10;
1899 break;
1900 case 0x0200: /* GeForce3 */
1901 case 0x0250: /* GeForce4 Ti */
1902 case 0x0280: /* GeForce4 Ti (8x AGP) */
1903 arch = NV_ARCH_20;
1904 break;
1905 case 0x0300: /* GeForceFX 5800 */
1906 case 0x0310: /* GeForceFX 5600 */
1907 case 0x0320: /* GeForceFX 5200 */
1908 case 0x0330: /* GeForceFX 5900 */
1909 case 0x0340: /* GeForceFX 5700 */
1910 arch = NV_ARCH_30;
1911 break;
1912 case 0x0020: /* TNT, TNT2 */
1913 arch = NV_ARCH_04;
1914 break;
1915 case 0x0010: /* Riva128 */
1916 arch = NV_ARCH_03;
1917 break;
1918 default: /* unknown architecture */
1919 break;
1920 }
1921 return arch;
1922}
1923
1924static int __devinit rivafb_probe(struct pci_dev *pd,
1925 const struct pci_device_id *ent)
1926{
1927 struct riva_par *default_par;
1928 struct fb_info *info;
1929 int ret;
1930
1931 NVTRACE_ENTER();
1932 assert(pd != NULL);
1933
1934 info = framebuffer_alloc(sizeof(struct riva_par), &pd->dev);
1935 if (!info) {
1936 printk (KERN_ERR PFX "could not allocate memory\n");
1937 ret = -ENOMEM;
1938 goto err_ret;
1939 }
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001940 default_par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 default_par->pdev = pd;
1942
Jiri Slabyf5610b92007-02-12 00:55:12 -08001943 info->pixmap.addr = kzalloc(8 * 1024, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 if (info->pixmap.addr == NULL) {
1945 ret = -ENOMEM;
1946 goto err_framebuffer_release;
1947 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948
1949 ret = pci_enable_device(pd);
1950 if (ret < 0) {
1951 printk(KERN_ERR PFX "cannot enable PCI device\n");
1952 goto err_free_pixmap;
1953 }
1954
1955 ret = pci_request_regions(pd, "rivafb");
1956 if (ret < 0) {
1957 printk(KERN_ERR PFX "cannot request PCI regions\n");
1958 goto err_disable_device;
1959 }
1960
Jiri Slabyc4f28e52007-02-12 00:55:11 -08001961 mutex_init(&default_par->open_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 default_par->riva.Architecture = riva_get_arch(pd);
1963
1964 default_par->Chipset = (pd->vendor << 16) | pd->device;
1965 printk(KERN_INFO PFX "nVidia device/chipset %X\n",default_par->Chipset);
1966
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 if(default_par->riva.Architecture == 0) {
1968 printk(KERN_ERR PFX "unknown NV_ARCH\n");
1969 ret=-ENODEV;
1970 goto err_release_region;
1971 }
1972 if(default_par->riva.Architecture == NV_ARCH_10 ||
1973 default_par->riva.Architecture == NV_ARCH_20 ||
1974 default_par->riva.Architecture == NV_ARCH_30) {
1975 sprintf(rivafb_fix.id, "NV%x", (pd->device & 0x0ff0) >> 4);
1976 } else {
1977 sprintf(rivafb_fix.id, "NV%x", default_par->riva.Architecture);
1978 }
1979
1980 default_par->FlatPanel = flatpanel;
1981 if (flatpanel == 1)
1982 printk(KERN_INFO PFX "flatpanel support enabled\n");
1983 default_par->forceCRTC = forceCRTC;
1984
1985 rivafb_fix.mmio_len = pci_resource_len(pd, 0);
1986 rivafb_fix.smem_len = pci_resource_len(pd, 1);
1987
1988 {
1989 /* enable IO and mem if not already done */
1990 unsigned short cmd;
1991
1992 pci_read_config_word(pd, PCI_COMMAND, &cmd);
1993 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
1994 pci_write_config_word(pd, PCI_COMMAND, cmd);
1995 }
1996
1997 rivafb_fix.mmio_start = pci_resource_start(pd, 0);
1998 rivafb_fix.smem_start = pci_resource_start(pd, 1);
1999
2000 default_par->ctrl_base = ioremap(rivafb_fix.mmio_start,
2001 rivafb_fix.mmio_len);
2002 if (!default_par->ctrl_base) {
2003 printk(KERN_ERR PFX "cannot ioremap MMIO base\n");
2004 ret = -EIO;
2005 goto err_release_region;
2006 }
2007
2008 switch (default_par->riva.Architecture) {
2009 case NV_ARCH_03:
2010 /* Riva128's PRAMIN is in the "framebuffer" space
2011 * Since these cards were never made with more than 8 megabytes
2012 * we can safely allocate this separately.
2013 */
2014 default_par->riva.PRAMIN = ioremap(rivafb_fix.smem_start + 0x00C00000, 0x00008000);
2015 if (!default_par->riva.PRAMIN) {
2016 printk(KERN_ERR PFX "cannot ioremap PRAMIN region\n");
2017 ret = -EIO;
2018 goto err_iounmap_ctrl_base;
2019 }
2020 break;
2021 case NV_ARCH_04:
2022 case NV_ARCH_10:
2023 case NV_ARCH_20:
2024 case NV_ARCH_30:
2025 default_par->riva.PCRTC0 =
2026 (u32 __iomem *)(default_par->ctrl_base + 0x00600000);
2027 default_par->riva.PRAMIN =
2028 (u32 __iomem *)(default_par->ctrl_base + 0x00710000);
2029 break;
2030 }
2031 riva_common_setup(default_par);
2032
2033 if (default_par->riva.Architecture == NV_ARCH_03) {
2034 default_par->riva.PCRTC = default_par->riva.PCRTC0
2035 = default_par->riva.PGRAPH;
2036 }
2037
2038 rivafb_fix.smem_len = riva_get_memlen(default_par) * 1024;
2039 default_par->dclk_max = riva_get_maxdclk(default_par) * 1000;
2040 info->screen_base = ioremap(rivafb_fix.smem_start,
2041 rivafb_fix.smem_len);
2042 if (!info->screen_base) {
2043 printk(KERN_ERR PFX "cannot ioremap FB base\n");
2044 ret = -EIO;
2045 goto err_iounmap_pramin;
2046 }
2047
2048#ifdef CONFIG_MTRR
2049 if (!nomtrr) {
2050 default_par->mtrr.vram = mtrr_add(rivafb_fix.smem_start,
2051 rivafb_fix.smem_len,
2052 MTRR_TYPE_WRCOMB, 1);
2053 if (default_par->mtrr.vram < 0) {
2054 printk(KERN_ERR PFX "unable to setup MTRR\n");
2055 } else {
2056 default_par->mtrr.vram_valid = 1;
2057 /* let there be speed */
2058 printk(KERN_INFO PFX "RIVA MTRR set to ON\n");
2059 }
2060 }
2061#endif /* CONFIG_MTRR */
2062
2063 info->fbops = &riva_fb_ops;
2064 info->fix = rivafb_fix;
2065 riva_get_EDID(info, pd);
2066 riva_get_edidinfo(info);
2067
2068 ret=riva_set_fbinfo(info);
2069 if (ret < 0) {
2070 printk(KERN_ERR PFX "error setting initial video mode\n");
2071 goto err_iounmap_screen_base;
2072 }
2073
2074 fb_destroy_modedb(info->monspecs.modedb);
2075 info->monspecs.modedb = NULL;
Guido Guentherce38cac2006-07-30 03:04:21 -07002076
2077 pci_set_drvdata(pd, info);
2078 riva_bl_init(info->par);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 ret = register_framebuffer(info);
2080 if (ret < 0) {
2081 printk(KERN_ERR PFX
2082 "error registering riva framebuffer\n");
2083 goto err_iounmap_screen_base;
2084 }
2085
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 printk(KERN_INFO PFX
2087 "PCI nVidia %s framebuffer ver %s (%dMB @ 0x%lX)\n",
2088 info->fix.id,
2089 RIVAFB_VERSION,
2090 info->fix.smem_len / (1024 * 1024),
2091 info->fix.smem_start);
Michael Hanselmann5474c122006-06-25 05:47:08 -07002092
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 NVTRACE_LEAVE();
2094 return 0;
2095
2096err_iounmap_screen_base:
2097#ifdef CONFIG_FB_RIVA_I2C
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08002098 riva_delete_i2c_busses(info->par);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099#endif
2100 iounmap(info->screen_base);
2101err_iounmap_pramin:
2102 if (default_par->riva.Architecture == NV_ARCH_03)
2103 iounmap(default_par->riva.PRAMIN);
2104err_iounmap_ctrl_base:
2105 iounmap(default_par->ctrl_base);
2106err_release_region:
2107 pci_release_regions(pd);
2108err_disable_device:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109err_free_pixmap:
2110 kfree(info->pixmap.addr);
2111err_framebuffer_release:
2112 framebuffer_release(info);
2113err_ret:
2114 return ret;
2115}
2116
2117static void __exit rivafb_remove(struct pci_dev *pd)
2118{
2119 struct fb_info *info = pci_get_drvdata(pd);
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08002120 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121
2122 NVTRACE_ENTER();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124#ifdef CONFIG_FB_RIVA_I2C
2125 riva_delete_i2c_busses(par);
2126 kfree(par->EDID);
2127#endif
2128
2129 unregister_framebuffer(info);
Richard Purdie37ce69a2007-02-10 14:10:33 +00002130
2131 riva_bl_exit(info);
2132
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133#ifdef CONFIG_MTRR
2134 if (par->mtrr.vram_valid)
2135 mtrr_del(par->mtrr.vram, info->fix.smem_start,
2136 info->fix.smem_len);
2137#endif /* CONFIG_MTRR */
2138
2139 iounmap(par->ctrl_base);
2140 iounmap(info->screen_base);
2141 if (par->riva.Architecture == NV_ARCH_03)
2142 iounmap(par->riva.PRAMIN);
2143 pci_release_regions(pd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 kfree(info->pixmap.addr);
2145 framebuffer_release(info);
2146 pci_set_drvdata(pd, NULL);
2147 NVTRACE_LEAVE();
2148}
2149
2150/* ------------------------------------------------------------------------- *
2151 *
2152 * initialization
2153 *
2154 * ------------------------------------------------------------------------- */
2155
2156#ifndef MODULE
2157static int __init rivafb_setup(char *options)
2158{
2159 char *this_opt;
2160
2161 NVTRACE_ENTER();
2162 if (!options || !*options)
2163 return 0;
2164
2165 while ((this_opt = strsep(&options, ",")) != NULL) {
2166 if (!strncmp(this_opt, "forceCRTC", 9)) {
2167 char *p;
2168
2169 p = this_opt + 9;
2170 if (!*p || !*(++p)) continue;
2171 forceCRTC = *p - '0';
2172 if (forceCRTC < 0 || forceCRTC > 1)
2173 forceCRTC = -1;
2174 } else if (!strncmp(this_opt, "flatpanel", 9)) {
2175 flatpanel = 1;
2176#ifdef CONFIG_MTRR
2177 } else if (!strncmp(this_opt, "nomtrr", 6)) {
2178 nomtrr = 1;
2179#endif
2180 } else if (!strncmp(this_opt, "strictmode", 10)) {
2181 strictmode = 1;
2182 } else if (!strncmp(this_opt, "noaccel", 7)) {
2183 noaccel = 1;
2184 } else
2185 mode_option = this_opt;
2186 }
2187 NVTRACE_LEAVE();
2188 return 0;
2189}
2190#endif /* !MODULE */
2191
2192static struct pci_driver rivafb_driver = {
2193 .name = "rivafb",
2194 .id_table = rivafb_pci_tbl,
2195 .probe = rivafb_probe,
2196 .remove = __exit_p(rivafb_remove),
2197};
2198
2199
2200
2201/* ------------------------------------------------------------------------- *
2202 *
2203 * modularization
2204 *
2205 * ------------------------------------------------------------------------- */
2206
2207static int __devinit rivafb_init(void)
2208{
2209#ifndef MODULE
2210 char *option = NULL;
2211
2212 if (fb_get_options("rivafb", &option))
2213 return -ENODEV;
2214 rivafb_setup(option);
2215#endif
2216 return pci_register_driver(&rivafb_driver);
2217}
2218
2219
2220module_init(rivafb_init);
2221
2222#ifdef MODULE
2223static void __exit rivafb_exit(void)
2224{
2225 pci_unregister_driver(&rivafb_driver);
2226}
2227
2228module_exit(rivafb_exit);
2229#endif /* MODULE */
2230
2231module_param(noaccel, bool, 0);
2232MODULE_PARM_DESC(noaccel, "bool: disable acceleration");
2233module_param(flatpanel, int, 0);
2234MODULE_PARM_DESC(flatpanel, "Enables experimental flat panel support for some chipsets. (0 or 1=enabled) (default=0)");
2235module_param(forceCRTC, int, 0);
2236MODULE_PARM_DESC(forceCRTC, "Forces usage of a particular CRTC in case autodetection fails. (0 or 1) (default=autodetect)");
2237#ifdef CONFIG_MTRR
2238module_param(nomtrr, bool, 0);
2239MODULE_PARM_DESC(nomtrr, "Disables MTRR support (0 or 1=disabled) (default=0)");
2240#endif
2241module_param(strictmode, bool, 0);
2242MODULE_PARM_DESC(strictmode, "Only use video modes from EDID");
2243
2244MODULE_AUTHOR("Ani Joshi, maintainer");
2245MODULE_DESCRIPTION("Framebuffer driver for nVidia Riva 128, TNT, TNT2, and the GeForce series");
2246MODULE_LICENSE("GPL");