blob: b70d18f7fcd93e21ccdfd3e211fa7748dad83d13 [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
Michael Hanselmanne01af032006-07-10 04:44:45 -0700285/* Call with fb_info->bl_mutex held */
Michael Hanselmann5474c122006-06-25 05:47:08 -0700286static int riva_bl_get_level_brightness(struct riva_par *par,
287 int level)
288{
289 struct fb_info *info = pci_get_drvdata(par->pdev);
290 int nlevel;
291
292 /* Get and convert the 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
Michael Hanselmanne01af032006-07-10 04:44:45 -0700305/* Call with fb_info->bl_mutex held */
306static int __riva_bl_update_status(struct backlight_device *bd)
Michael Hanselmann5474c122006-06-25 05:47:08 -0700307{
308 struct riva_par *par = class_get_devdata(&bd->class_dev);
309 U032 tmp_pcrt, tmp_pmc;
310 int level;
311
312 if (bd->props->power != FB_BLANK_UNBLANK ||
313 bd->props->fb_blank != FB_BLANK_UNBLANK)
314 level = 0;
315 else
316 level = bd->props->brightness;
317
318 tmp_pmc = par->riva.PMC[0x10F0/4] & 0x0000FFFF;
319 tmp_pcrt = par->riva.PCRTC0[0x081C/4] & 0xFFFFFFFC;
320 if(level > 0) {
321 tmp_pcrt |= 0x1;
322 tmp_pmc |= (1 << 31); /* backlight bit */
323 tmp_pmc |= riva_bl_get_level_brightness(par, level) << 16; /* level */
324 }
325 par->riva.PCRTC0[0x081C/4] = tmp_pcrt;
326 par->riva.PMC[0x10F0/4] = tmp_pmc;
327
328 return 0;
329}
330
Michael Hanselmanne01af032006-07-10 04:44:45 -0700331static int riva_bl_update_status(struct backlight_device *bd)
332{
333 struct riva_par *par = class_get_devdata(&bd->class_dev);
334 struct fb_info *info = pci_get_drvdata(par->pdev);
335 int ret;
336
337 mutex_lock(&info->bl_mutex);
338 ret = __riva_bl_update_status(bd);
339 mutex_unlock(&info->bl_mutex);
340
341 return ret;
342}
343
Michael Hanselmann5474c122006-06-25 05:47:08 -0700344static int riva_bl_get_brightness(struct backlight_device *bd)
345{
346 return bd->props->brightness;
347}
348
349static struct backlight_properties riva_bl_data = {
Michael Hanselmann5474c122006-06-25 05:47:08 -0700350 .get_brightness = riva_bl_get_brightness,
351 .update_status = riva_bl_update_status,
352 .max_brightness = (FB_BACKLIGHT_LEVELS - 1),
353};
354
Michael Hanselmanne01af032006-07-10 04:44:45 -0700355static void riva_bl_set_power(struct fb_info *info, int power)
356{
357 mutex_lock(&info->bl_mutex);
Benjamin Herrenschmidta9303632006-08-31 21:27:54 -0700358
359 if (info->bl_dev) {
Benjamin Herrenschmidta9303632006-08-31 21:27:54 -0700360 info->bl_dev->props->power = power;
361 __riva_bl_update_status(info->bl_dev);
Benjamin Herrenschmidta9303632006-08-31 21:27:54 -0700362 }
363
Michael Hanselmanne01af032006-07-10 04:44:45 -0700364 mutex_unlock(&info->bl_mutex);
365}
366
Michael Hanselmann5474c122006-06-25 05:47:08 -0700367static void riva_bl_init(struct riva_par *par)
368{
369 struct fb_info *info = pci_get_drvdata(par->pdev);
370 struct backlight_device *bd;
371 char name[12];
372
373 if (!par->FlatPanel)
374 return;
375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376#ifdef CONFIG_PMAC_BACKLIGHT
Michael Hanselmann5474c122006-06-25 05:47:08 -0700377 if (!machine_is(powermac) ||
378 !pmac_has_backlight_type("mnca"))
379 return;
380#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Michael Hanselmann5474c122006-06-25 05:47:08 -0700382 snprintf(name, sizeof(name), "rivabl%d", info->node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
James Simmonsa8274d52006-12-19 12:56:16 -0800384 bd = backlight_device_register(name, info->dev, par, &riva_bl_data);
Michael Hanselmann5474c122006-06-25 05:47:08 -0700385 if (IS_ERR(bd)) {
386 info->bl_dev = NULL;
Benjamin Herrenschmidt98a3c782006-08-31 14:04:34 +1000387 printk(KERN_WARNING "riva: Backlight registration failed\n");
Michael Hanselmann5474c122006-06-25 05:47:08 -0700388 goto error;
389 }
390
391 mutex_lock(&info->bl_mutex);
392 info->bl_dev = bd;
393 fb_bl_default_curve(info, 0,
Guido Guenther535a09a2006-10-03 01:14:40 -0700394 MIN_LEVEL * FB_BACKLIGHT_MAX / MAX_LEVEL,
395 FB_BACKLIGHT_MAX);
Michael Hanselmann5474c122006-06-25 05:47:08 -0700396 mutex_unlock(&info->bl_mutex);
397
Michael Hanselmann5474c122006-06-25 05:47:08 -0700398 bd->props->brightness = riva_bl_data.max_brightness;
399 bd->props->power = FB_BLANK_UNBLANK;
Richard Purdie28ee0862007-02-08 22:25:09 +0000400 backlight_update_status(bd);
Michael Hanselmann5474c122006-06-25 05:47:08 -0700401
402#ifdef CONFIG_PMAC_BACKLIGHT
403 mutex_lock(&pmac_backlight_mutex);
404 if (!pmac_backlight)
405 pmac_backlight = bd;
406 mutex_unlock(&pmac_backlight_mutex);
407#endif
408
409 printk("riva: Backlight initialized (%s)\n", name);
410
411 return;
412
413error:
414 return;
415}
416
417static void riva_bl_exit(struct riva_par *par)
418{
419 struct fb_info *info = pci_get_drvdata(par->pdev);
420
421#ifdef CONFIG_PMAC_BACKLIGHT
422 mutex_lock(&pmac_backlight_mutex);
423#endif
424
425 mutex_lock(&info->bl_mutex);
426 if (info->bl_dev) {
427#ifdef CONFIG_PMAC_BACKLIGHT
428 if (pmac_backlight == info->bl_dev)
429 pmac_backlight = NULL;
430#endif
431
432 backlight_device_unregister(info->bl_dev);
433
434 printk("riva: Backlight unloaded\n");
435 }
436 mutex_unlock(&info->bl_mutex);
437
438#ifdef CONFIG_PMAC_BACKLIGHT
439 mutex_unlock(&pmac_backlight_mutex);
440#endif
441}
442#else
443static inline void riva_bl_init(struct riva_par *par) {}
444static inline void riva_bl_exit(struct riva_par *par) {}
Michael Hanselmanne01af032006-07-10 04:44:45 -0700445static inline void riva_bl_set_power(struct fb_info *info, int power) {}
Michael Hanselmann5474c122006-06-25 05:47:08 -0700446#endif /* CONFIG_FB_RIVA_BACKLIGHT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448/* ------------------------------------------------------------------------- *
449 *
450 * MMIO access macros
451 *
452 * ------------------------------------------------------------------------- */
453
454static inline void CRTCout(struct riva_par *par, unsigned char index,
455 unsigned char val)
456{
457 VGA_WR08(par->riva.PCIO, 0x3d4, index);
458 VGA_WR08(par->riva.PCIO, 0x3d5, val);
459}
460
461static inline unsigned char CRTCin(struct riva_par *par,
462 unsigned char index)
463{
464 VGA_WR08(par->riva.PCIO, 0x3d4, index);
465 return (VGA_RD08(par->riva.PCIO, 0x3d5));
466}
467
468static inline void GRAout(struct riva_par *par, unsigned char index,
469 unsigned char val)
470{
471 VGA_WR08(par->riva.PVIO, 0x3ce, index);
472 VGA_WR08(par->riva.PVIO, 0x3cf, val);
473}
474
475static inline unsigned char GRAin(struct riva_par *par,
476 unsigned char index)
477{
478 VGA_WR08(par->riva.PVIO, 0x3ce, index);
479 return (VGA_RD08(par->riva.PVIO, 0x3cf));
480}
481
482static inline void SEQout(struct riva_par *par, unsigned char index,
483 unsigned char val)
484{
485 VGA_WR08(par->riva.PVIO, 0x3c4, index);
486 VGA_WR08(par->riva.PVIO, 0x3c5, val);
487}
488
489static inline unsigned char SEQin(struct riva_par *par,
490 unsigned char index)
491{
492 VGA_WR08(par->riva.PVIO, 0x3c4, index);
493 return (VGA_RD08(par->riva.PVIO, 0x3c5));
494}
495
496static inline void ATTRout(struct riva_par *par, unsigned char index,
497 unsigned char val)
498{
499 VGA_WR08(par->riva.PCIO, 0x3c0, index);
500 VGA_WR08(par->riva.PCIO, 0x3c0, val);
501}
502
503static inline unsigned char ATTRin(struct riva_par *par,
504 unsigned char index)
505{
506 VGA_WR08(par->riva.PCIO, 0x3c0, index);
507 return (VGA_RD08(par->riva.PCIO, 0x3c1));
508}
509
510static inline void MISCout(struct riva_par *par, unsigned char val)
511{
512 VGA_WR08(par->riva.PVIO, 0x3c2, val);
513}
514
515static inline unsigned char MISCin(struct riva_par *par)
516{
517 return (VGA_RD08(par->riva.PVIO, 0x3cc));
518}
519
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520static inline void reverse_order(u32 *l)
521{
522 u8 *a = (u8 *)l;
Akinobu Mita1c667682006-12-08 02:36:26 -0800523 a[0] = bitrev8(a[0]);
524 a[1] = bitrev8(a[1]);
525 a[2] = bitrev8(a[2]);
526 a[3] = bitrev8(a[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527}
528
529/* ------------------------------------------------------------------------- *
530 *
531 * cursor stuff
532 *
533 * ------------------------------------------------------------------------- */
534
535/**
536 * rivafb_load_cursor_image - load cursor image to hardware
537 * @data: address to monochrome bitmap (1 = foreground color, 0 = background)
538 * @par: pointer to private data
539 * @w: width of cursor image in pixels
540 * @h: height of cursor image in scanlines
541 * @bg: background color (ARGB1555) - alpha bit determines opacity
542 * @fg: foreground color (ARGB1555)
543 *
544 * DESCRIPTiON:
545 * Loads cursor image based on a monochrome source and mask bitmap. The
546 * image bits determines the color of the pixel, 0 for background, 1 for
547 * foreground. Only the affected region (as determined by @w and @h
548 * parameters) will be updated.
549 *
550 * CALLED FROM:
551 * rivafb_cursor()
552 */
553static void rivafb_load_cursor_image(struct riva_par *par, u8 *data8,
554 u16 bg, u16 fg, u32 w, u32 h)
555{
556 int i, j, k = 0;
557 u32 b, tmp;
558 u32 *data = (u32 *)data8;
559 bg = le16_to_cpu(bg);
560 fg = le16_to_cpu(fg);
561
562 w = (w + 1) & ~1;
563
564 for (i = 0; i < h; i++) {
565 b = *data++;
566 reverse_order(&b);
567
568 for (j = 0; j < w/2; j++) {
569 tmp = 0;
570#if defined (__BIG_ENDIAN)
571 tmp = (b & (1 << 31)) ? fg << 16 : bg << 16;
572 b <<= 1;
573 tmp |= (b & (1 << 31)) ? fg : bg;
574 b <<= 1;
575#else
576 tmp = (b & 1) ? fg : bg;
577 b >>= 1;
578 tmp |= (b & 1) ? fg << 16 : bg << 16;
579 b >>= 1;
580#endif
581 writel(tmp, &par->riva.CURSOR[k++]);
582 }
583 k += (MAX_CURS - w)/2;
584 }
585}
586
587/* ------------------------------------------------------------------------- *
588 *
589 * general utility functions
590 *
591 * ------------------------------------------------------------------------- */
592
593/**
594 * riva_wclut - set CLUT entry
595 * @chip: pointer to RIVA_HW_INST object
596 * @regnum: register number
597 * @red: red component
598 * @green: green component
599 * @blue: blue component
600 *
601 * DESCRIPTION:
602 * Sets color register @regnum.
603 *
604 * CALLED FROM:
605 * rivafb_setcolreg()
606 */
607static void riva_wclut(RIVA_HW_INST *chip,
608 unsigned char regnum, unsigned char red,
609 unsigned char green, unsigned char blue)
610{
611 VGA_WR08(chip->PDIO, 0x3c8, regnum);
612 VGA_WR08(chip->PDIO, 0x3c9, red);
613 VGA_WR08(chip->PDIO, 0x3c9, green);
614 VGA_WR08(chip->PDIO, 0x3c9, blue);
615}
616
617/**
618 * riva_rclut - read fromCLUT register
619 * @chip: pointer to RIVA_HW_INST object
620 * @regnum: register number
621 * @red: red component
622 * @green: green component
623 * @blue: blue component
624 *
625 * DESCRIPTION:
626 * Reads red, green, and blue from color register @regnum.
627 *
628 * CALLED FROM:
629 * rivafb_setcolreg()
630 */
631static void riva_rclut(RIVA_HW_INST *chip,
632 unsigned char regnum, unsigned char *red,
633 unsigned char *green, unsigned char *blue)
634{
635
636 VGA_WR08(chip->PDIO, 0x3c7, regnum);
637 *red = VGA_RD08(chip->PDIO, 0x3c9);
638 *green = VGA_RD08(chip->PDIO, 0x3c9);
639 *blue = VGA_RD08(chip->PDIO, 0x3c9);
640}
641
642/**
643 * riva_save_state - saves current chip state
644 * @par: pointer to riva_par object containing info for current riva board
645 * @regs: pointer to riva_regs object
646 *
647 * DESCRIPTION:
648 * Saves current chip state to @regs.
649 *
650 * CALLED FROM:
651 * rivafb_probe()
652 */
653/* from GGI */
654static void riva_save_state(struct riva_par *par, struct riva_regs *regs)
655{
656 int i;
657
658 NVTRACE_ENTER();
659 par->riva.LockUnlock(&par->riva, 0);
660
661 par->riva.UnloadStateExt(&par->riva, &regs->ext);
662
663 regs->misc_output = MISCin(par);
664
665 for (i = 0; i < NUM_CRT_REGS; i++)
666 regs->crtc[i] = CRTCin(par, i);
667
668 for (i = 0; i < NUM_ATC_REGS; i++)
669 regs->attr[i] = ATTRin(par, i);
670
671 for (i = 0; i < NUM_GRC_REGS; i++)
672 regs->gra[i] = GRAin(par, i);
673
674 for (i = 0; i < NUM_SEQ_REGS; i++)
675 regs->seq[i] = SEQin(par, i);
676 NVTRACE_LEAVE();
677}
678
679/**
680 * riva_load_state - loads current chip state
681 * @par: pointer to riva_par object containing info for current riva board
682 * @regs: pointer to riva_regs object
683 *
684 * DESCRIPTION:
685 * Loads chip state from @regs.
686 *
687 * CALLED FROM:
688 * riva_load_video_mode()
689 * rivafb_probe()
690 * rivafb_remove()
691 */
692/* from GGI */
693static void riva_load_state(struct riva_par *par, struct riva_regs *regs)
694{
695 RIVA_HW_STATE *state = &regs->ext;
696 int i;
697
698 NVTRACE_ENTER();
699 CRTCout(par, 0x11, 0x00);
700
701 par->riva.LockUnlock(&par->riva, 0);
702
703 par->riva.LoadStateExt(&par->riva, state);
704
705 MISCout(par, regs->misc_output);
706
707 for (i = 0; i < NUM_CRT_REGS; i++) {
708 switch (i) {
709 case 0x19:
710 case 0x20 ... 0x40:
711 break;
712 default:
713 CRTCout(par, i, regs->crtc[i]);
714 }
715 }
716
717 for (i = 0; i < NUM_ATC_REGS; i++)
718 ATTRout(par, i, regs->attr[i]);
719
720 for (i = 0; i < NUM_GRC_REGS; i++)
721 GRAout(par, i, regs->gra[i]);
722
723 for (i = 0; i < NUM_SEQ_REGS; i++)
724 SEQout(par, i, regs->seq[i]);
725 NVTRACE_LEAVE();
726}
727
728/**
729 * riva_load_video_mode - calculate timings
730 * @info: pointer to fb_info object containing info for current riva board
731 *
732 * DESCRIPTION:
733 * Calculate some timings and then send em off to riva_load_state().
734 *
735 * CALLED FROM:
736 * rivafb_set_par()
737 */
Jeff Garzikfd717682006-12-08 02:40:17 -0800738static int riva_load_video_mode(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739{
740 int bpp, width, hDisplaySize, hDisplay, hStart,
741 hEnd, hTotal, height, vDisplay, vStart, vEnd, vTotal, dotClock;
742 int hBlankStart, hBlankEnd, vBlankStart, vBlankEnd;
Jeff Garzikfd717682006-12-08 02:40:17 -0800743 int rc;
Antonino A. Daplasf4a41832006-01-09 20:53:04 -0800744 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 struct riva_regs newmode;
746
747 NVTRACE_ENTER();
748 /* time to calculate */
Guido Guenther535a09a2006-10-03 01:14:40 -0700749 rivafb_blank(FB_BLANK_NORMAL, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
751 bpp = info->var.bits_per_pixel;
752 if (bpp == 16 && info->var.green.length == 5)
753 bpp = 15;
754 width = info->var.xres_virtual;
755 hDisplaySize = info->var.xres;
756 hDisplay = (hDisplaySize / 8) - 1;
757 hStart = (hDisplaySize + info->var.right_margin) / 8 - 1;
758 hEnd = (hDisplaySize + info->var.right_margin +
759 info->var.hsync_len) / 8 - 1;
760 hTotal = (hDisplaySize + info->var.right_margin +
761 info->var.hsync_len + info->var.left_margin) / 8 - 5;
762 hBlankStart = hDisplay;
763 hBlankEnd = hTotal + 4;
764
765 height = info->var.yres_virtual;
766 vDisplay = info->var.yres - 1;
767 vStart = info->var.yres + info->var.lower_margin - 1;
768 vEnd = info->var.yres + info->var.lower_margin +
769 info->var.vsync_len - 1;
770 vTotal = info->var.yres + info->var.lower_margin +
771 info->var.vsync_len + info->var.upper_margin + 2;
772 vBlankStart = vDisplay;
773 vBlankEnd = vTotal + 1;
774 dotClock = 1000000000 / info->var.pixclock;
775
776 memcpy(&newmode, &reg_template, sizeof(struct riva_regs));
777
778 if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED)
779 vTotal |= 1;
780
781 if (par->FlatPanel) {
782 vStart = vTotal - 3;
783 vEnd = vTotal - 2;
784 vBlankStart = vStart;
785 hStart = hTotal - 3;
786 hEnd = hTotal - 2;
787 hBlankEnd = hTotal + 4;
788 }
789
790 newmode.crtc[0x0] = Set8Bits (hTotal);
791 newmode.crtc[0x1] = Set8Bits (hDisplay);
792 newmode.crtc[0x2] = Set8Bits (hBlankStart);
793 newmode.crtc[0x3] = SetBitField (hBlankEnd, 4: 0, 4:0) | SetBit (7);
794 newmode.crtc[0x4] = Set8Bits (hStart);
795 newmode.crtc[0x5] = SetBitField (hBlankEnd, 5: 5, 7:7)
796 | SetBitField (hEnd, 4: 0, 4:0);
797 newmode.crtc[0x6] = SetBitField (vTotal, 7: 0, 7:0);
798 newmode.crtc[0x7] = SetBitField (vTotal, 8: 8, 0:0)
799 | SetBitField (vDisplay, 8: 8, 1:1)
800 | SetBitField (vStart, 8: 8, 2:2)
801 | SetBitField (vBlankStart, 8: 8, 3:3)
802 | SetBit (4)
803 | SetBitField (vTotal, 9: 9, 5:5)
804 | SetBitField (vDisplay, 9: 9, 6:6)
805 | SetBitField (vStart, 9: 9, 7:7);
806 newmode.crtc[0x9] = SetBitField (vBlankStart, 9: 9, 5:5)
807 | SetBit (6);
808 newmode.crtc[0x10] = Set8Bits (vStart);
809 newmode.crtc[0x11] = SetBitField (vEnd, 3: 0, 3:0)
810 | SetBit (5);
811 newmode.crtc[0x12] = Set8Bits (vDisplay);
812 newmode.crtc[0x13] = (width / 8) * ((bpp + 1) / 8);
813 newmode.crtc[0x15] = Set8Bits (vBlankStart);
814 newmode.crtc[0x16] = Set8Bits (vBlankEnd);
815
816 newmode.ext.screen = SetBitField(hBlankEnd,6:6,4:4)
817 | SetBitField(vBlankStart,10:10,3:3)
818 | SetBitField(vStart,10:10,2:2)
819 | SetBitField(vDisplay,10:10,1:1)
820 | SetBitField(vTotal,10:10,0:0);
821 newmode.ext.horiz = SetBitField(hTotal,8:8,0:0)
822 | SetBitField(hDisplay,8:8,1:1)
823 | SetBitField(hBlankStart,8:8,2:2)
824 | SetBitField(hStart,8:8,3:3);
825 newmode.ext.extra = SetBitField(vTotal,11:11,0:0)
826 | SetBitField(vDisplay,11:11,2:2)
827 | SetBitField(vStart,11:11,4:4)
828 | SetBitField(vBlankStart,11:11,6:6);
829
830 if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
831 int tmp = (hTotal >> 1) & ~1;
832 newmode.ext.interlace = Set8Bits(tmp);
833 newmode.ext.horiz |= SetBitField(tmp, 8:8,4:4);
834 } else
835 newmode.ext.interlace = 0xff; /* interlace off */
836
837 if (par->riva.Architecture >= NV_ARCH_10)
838 par->riva.CURSOR = (U032 __iomem *)(info->screen_base + par->riva.CursorStart);
839
840 if (info->var.sync & FB_SYNC_HOR_HIGH_ACT)
841 newmode.misc_output &= ~0x40;
842 else
843 newmode.misc_output |= 0x40;
844 if (info->var.sync & FB_SYNC_VERT_HIGH_ACT)
845 newmode.misc_output &= ~0x80;
846 else
847 newmode.misc_output |= 0x80;
848
Jeff Garzikfd717682006-12-08 02:40:17 -0800849 rc = CalcStateExt(&par->riva, &newmode.ext, bpp, width,
850 hDisplaySize, height, dotClock);
851 if (rc)
852 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
854 newmode.ext.scale = NV_RD32(par->riva.PRAMDAC, 0x00000848) &
855 0xfff000ff;
856 if (par->FlatPanel == 1) {
857 newmode.ext.pixel |= (1 << 7);
858 newmode.ext.scale |= (1 << 8);
859 }
860 if (par->SecondCRTC) {
861 newmode.ext.head = NV_RD32(par->riva.PCRTC0, 0x00000860) &
862 ~0x00001000;
863 newmode.ext.head2 = NV_RD32(par->riva.PCRTC0, 0x00002860) |
864 0x00001000;
865 newmode.ext.crtcOwner = 3;
866 newmode.ext.pllsel |= 0x20000800;
867 newmode.ext.vpll2 = newmode.ext.vpll;
868 } else if (par->riva.twoHeads) {
869 newmode.ext.head = NV_RD32(par->riva.PCRTC0, 0x00000860) |
870 0x00001000;
871 newmode.ext.head2 = NV_RD32(par->riva.PCRTC0, 0x00002860) &
872 ~0x00001000;
873 newmode.ext.crtcOwner = 0;
874 newmode.ext.vpll2 = NV_RD32(par->riva.PRAMDAC0, 0x00000520);
875 }
876 if (par->FlatPanel == 1) {
877 newmode.ext.pixel |= (1 << 7);
878 newmode.ext.scale |= (1 << 8);
879 }
880 newmode.ext.cursorConfig = 0x02000100;
881 par->current_state = newmode;
882 riva_load_state(par, &par->current_state);
883 par->riva.LockUnlock(&par->riva, 0); /* important for HW cursor */
Jeff Garzikfd717682006-12-08 02:40:17 -0800884
885out:
Guido Guenther535a09a2006-10-03 01:14:40 -0700886 rivafb_blank(FB_BLANK_UNBLANK, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 NVTRACE_LEAVE();
Jeff Garzikfd717682006-12-08 02:40:17 -0800888
889 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890}
891
Geert Uytterhoeven9791d762007-02-12 00:55:19 -0800892static void riva_update_var(struct fb_var_screeninfo *var,
893 const struct fb_videomode *modedb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894{
895 NVTRACE_ENTER();
896 var->xres = var->xres_virtual = modedb->xres;
897 var->yres = modedb->yres;
898 if (var->yres_virtual < var->yres)
899 var->yres_virtual = var->yres;
900 var->xoffset = var->yoffset = 0;
901 var->pixclock = modedb->pixclock;
902 var->left_margin = modedb->left_margin;
903 var->right_margin = modedb->right_margin;
904 var->upper_margin = modedb->upper_margin;
905 var->lower_margin = modedb->lower_margin;
906 var->hsync_len = modedb->hsync_len;
907 var->vsync_len = modedb->vsync_len;
908 var->sync = modedb->sync;
909 var->vmode = modedb->vmode;
910 NVTRACE_LEAVE();
911}
912
913/**
914 * rivafb_do_maximize -
915 * @info: pointer to fb_info object containing info for current riva board
916 * @var:
917 * @nom:
918 * @den:
919 *
920 * DESCRIPTION:
921 * .
922 *
923 * RETURNS:
924 * -EINVAL on failure, 0 on success
925 *
926 *
927 * CALLED FROM:
928 * rivafb_check_var()
929 */
930static int rivafb_do_maximize(struct fb_info *info,
931 struct fb_var_screeninfo *var,
932 int nom, int den)
933{
934 static struct {
935 int xres, yres;
936 } modes[] = {
937 {1600, 1280},
938 {1280, 1024},
939 {1024, 768},
940 {800, 600},
941 {640, 480},
942 {-1, -1}
943 };
944 int i;
945
946 NVTRACE_ENTER();
947 /* use highest possible virtual resolution */
948 if (var->xres_virtual == -1 && var->yres_virtual == -1) {
949 printk(KERN_WARNING PFX
950 "using maximum available virtual resolution\n");
951 for (i = 0; modes[i].xres != -1; i++) {
952 if (modes[i].xres * nom / den * modes[i].yres <
953 info->fix.smem_len)
954 break;
955 }
956 if (modes[i].xres == -1) {
957 printk(KERN_ERR PFX
958 "could not find a virtual resolution that fits into video memory!!\n");
959 NVTRACE("EXIT - EINVAL error\n");
960 return -EINVAL;
961 }
962 var->xres_virtual = modes[i].xres;
963 var->yres_virtual = modes[i].yres;
964
965 printk(KERN_INFO PFX
966 "virtual resolution set to maximum of %dx%d\n",
967 var->xres_virtual, var->yres_virtual);
968 } else if (var->xres_virtual == -1) {
969 var->xres_virtual = (info->fix.smem_len * den /
970 (nom * var->yres_virtual)) & ~15;
971 printk(KERN_WARNING PFX
972 "setting virtual X resolution to %d\n", var->xres_virtual);
973 } else if (var->yres_virtual == -1) {
974 var->xres_virtual = (var->xres_virtual + 15) & ~15;
975 var->yres_virtual = info->fix.smem_len * den /
976 (nom * var->xres_virtual);
977 printk(KERN_WARNING PFX
978 "setting virtual Y resolution to %d\n", var->yres_virtual);
979 } else {
980 var->xres_virtual = (var->xres_virtual + 15) & ~15;
981 if (var->xres_virtual * nom / den * var->yres_virtual > info->fix.smem_len) {
982 printk(KERN_ERR PFX
983 "mode %dx%dx%d rejected...resolution too high to fit into video memory!\n",
984 var->xres, var->yres, var->bits_per_pixel);
985 NVTRACE("EXIT - EINVAL error\n");
986 return -EINVAL;
987 }
988 }
989
990 if (var->xres_virtual * nom / den >= 8192) {
991 printk(KERN_WARNING PFX
992 "virtual X resolution (%d) is too high, lowering to %d\n",
993 var->xres_virtual, 8192 * den / nom - 16);
994 var->xres_virtual = 8192 * den / nom - 16;
995 }
996
997 if (var->xres_virtual < var->xres) {
998 printk(KERN_ERR PFX
999 "virtual X resolution (%d) is smaller than real\n", var->xres_virtual);
1000 return -EINVAL;
1001 }
1002
1003 if (var->yres_virtual < var->yres) {
1004 printk(KERN_ERR PFX
1005 "virtual Y resolution (%d) is smaller than real\n", var->yres_virtual);
1006 return -EINVAL;
1007 }
1008 if (var->yres_virtual > 0x7fff/nom)
1009 var->yres_virtual = 0x7fff/nom;
1010 if (var->xres_virtual > 0x7fff/nom)
1011 var->xres_virtual = 0x7fff/nom;
1012 NVTRACE_LEAVE();
1013 return 0;
1014}
1015
1016static void
1017riva_set_pattern(struct riva_par *par, int clr0, int clr1, int pat0, int pat1)
1018{
1019 RIVA_FIFO_FREE(par->riva, Patt, 4);
1020 NV_WR32(&par->riva.Patt->Color0, 0, clr0);
1021 NV_WR32(&par->riva.Patt->Color1, 0, clr1);
1022 NV_WR32(par->riva.Patt->Monochrome, 0, pat0);
1023 NV_WR32(par->riva.Patt->Monochrome, 4, pat1);
1024}
1025
1026/* acceleration routines */
1027static inline void wait_for_idle(struct riva_par *par)
1028{
1029 while (par->riva.Busy(&par->riva));
1030}
1031
1032/*
1033 * Set ROP. Translate X rop into ROP3. Internal routine.
1034 */
1035static void
1036riva_set_rop_solid(struct riva_par *par, int rop)
1037{
1038 riva_set_pattern(par, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
1039 RIVA_FIFO_FREE(par->riva, Rop, 1);
1040 NV_WR32(&par->riva.Rop->Rop3, 0, rop);
1041
1042}
1043
1044static void riva_setup_accel(struct fb_info *info)
1045{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001046 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
1048 RIVA_FIFO_FREE(par->riva, Clip, 2);
1049 NV_WR32(&par->riva.Clip->TopLeft, 0, 0x0);
1050 NV_WR32(&par->riva.Clip->WidthHeight, 0,
1051 (info->var.xres_virtual & 0xffff) |
1052 (info->var.yres_virtual << 16));
1053 riva_set_rop_solid(par, 0xcc);
1054 wait_for_idle(par);
1055}
1056
1057/**
1058 * riva_get_cmap_len - query current color map length
1059 * @var: standard kernel fb changeable data
1060 *
1061 * DESCRIPTION:
1062 * Get current color map length.
1063 *
1064 * RETURNS:
1065 * Length of color map
1066 *
1067 * CALLED FROM:
1068 * rivafb_setcolreg()
1069 */
1070static int riva_get_cmap_len(const struct fb_var_screeninfo *var)
1071{
1072 int rc = 256; /* reasonable default */
1073
1074 switch (var->green.length) {
1075 case 8:
1076 rc = 256; /* 256 entries (2^8), 8 bpp and RGB8888 */
1077 break;
1078 case 5:
1079 rc = 32; /* 32 entries (2^5), 16 bpp, RGB555 */
1080 break;
1081 case 6:
1082 rc = 64; /* 64 entries (2^6), 16 bpp, RGB565 */
1083 break;
1084 default:
1085 /* should not occur */
1086 break;
1087 }
1088 return rc;
1089}
1090
1091/* ------------------------------------------------------------------------- *
1092 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 * framebuffer operations
1094 *
1095 * ------------------------------------------------------------------------- */
1096
1097static int rivafb_open(struct fb_info *info, int user)
1098{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001099 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
1101 NVTRACE_ENTER();
Jiri Slabyc4f28e52007-02-12 00:55:11 -08001102 mutex_lock(&par->open_lock);
1103 if (!par->ref_count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104#ifdef CONFIG_X86
1105 memset(&par->state, 0, sizeof(struct vgastate));
1106 par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS;
1107 /* save the DAC for Riva128 */
1108 if (par->riva.Architecture == NV_ARCH_03)
1109 par->state.flags |= VGA_SAVE_CMAP;
1110 save_vga(&par->state);
1111#endif
1112 /* vgaHWunlock() + riva unlock (0x7F) */
1113 CRTCout(par, 0x11, 0xFF);
1114 par->riva.LockUnlock(&par->riva, 0);
1115
1116 riva_save_state(par, &par->initial_state);
1117 }
Jiri Slabyc4f28e52007-02-12 00:55:11 -08001118 par->ref_count++;
1119 mutex_unlock(&par->open_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 NVTRACE_LEAVE();
1121 return 0;
1122}
1123
1124static int rivafb_release(struct fb_info *info, int user)
1125{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001126 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
1128 NVTRACE_ENTER();
Jiri Slabyc4f28e52007-02-12 00:55:11 -08001129 mutex_lock(&par->open_lock);
1130 if (!par->ref_count) {
1131 mutex_unlock(&par->open_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 return -EINVAL;
Jiri Slabyc4f28e52007-02-12 00:55:11 -08001133 }
1134 if (par->ref_count == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 par->riva.LockUnlock(&par->riva, 0);
1136 par->riva.LoadStateExt(&par->riva, &par->initial_state.ext);
1137 riva_load_state(par, &par->initial_state);
1138#ifdef CONFIG_X86
1139 restore_vga(&par->state);
1140#endif
1141 par->riva.LockUnlock(&par->riva, 1);
1142 }
Jiri Slabyc4f28e52007-02-12 00:55:11 -08001143 par->ref_count--;
1144 mutex_unlock(&par->open_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 NVTRACE_LEAVE();
1146 return 0;
1147}
1148
1149static int rivafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1150{
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08001151 const struct fb_videomode *mode;
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001152 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 int nom, den; /* translating from pixels->bytes */
1154 int mode_valid = 0;
1155
1156 NVTRACE_ENTER();
1157 switch (var->bits_per_pixel) {
1158 case 1 ... 8:
1159 var->red.offset = var->green.offset = var->blue.offset = 0;
1160 var->red.length = var->green.length = var->blue.length = 8;
1161 var->bits_per_pixel = 8;
1162 nom = den = 1;
1163 break;
1164 case 9 ... 15:
1165 var->green.length = 5;
1166 /* fall through */
1167 case 16:
1168 var->bits_per_pixel = 16;
1169 /* The Riva128 supports RGB555 only */
1170 if (par->riva.Architecture == NV_ARCH_03)
1171 var->green.length = 5;
1172 if (var->green.length == 5) {
1173 /* 0rrrrrgg gggbbbbb */
1174 var->red.offset = 10;
1175 var->green.offset = 5;
1176 var->blue.offset = 0;
1177 var->red.length = 5;
1178 var->green.length = 5;
1179 var->blue.length = 5;
1180 } else {
1181 /* rrrrrggg gggbbbbb */
1182 var->red.offset = 11;
1183 var->green.offset = 5;
1184 var->blue.offset = 0;
1185 var->red.length = 5;
1186 var->green.length = 6;
1187 var->blue.length = 5;
1188 }
1189 nom = 2;
1190 den = 1;
1191 break;
1192 case 17 ... 32:
1193 var->red.length = var->green.length = var->blue.length = 8;
1194 var->bits_per_pixel = 32;
1195 var->red.offset = 16;
1196 var->green.offset = 8;
1197 var->blue.offset = 0;
1198 nom = 4;
1199 den = 1;
1200 break;
1201 default:
1202 printk(KERN_ERR PFX
1203 "mode %dx%dx%d rejected...color depth not supported.\n",
1204 var->xres, var->yres, var->bits_per_pixel);
1205 NVTRACE("EXIT, returning -EINVAL\n");
1206 return -EINVAL;
1207 }
1208
1209 if (!strictmode) {
1210 if (!info->monspecs.vfmax || !info->monspecs.hfmax ||
1211 !info->monspecs.dclkmax || !fb_validate_mode(var, info))
1212 mode_valid = 1;
1213 }
1214
1215 /* calculate modeline if supported by monitor */
1216 if (!mode_valid && info->monspecs.gtf) {
1217 if (!fb_get_mode(FB_MAXTIMINGS, 0, var, info))
1218 mode_valid = 1;
1219 }
1220
1221 if (!mode_valid) {
1222 mode = fb_find_best_mode(var, &info->modelist);
1223 if (mode) {
1224 riva_update_var(var, mode);
1225 mode_valid = 1;
1226 }
1227 }
1228
1229 if (!mode_valid && info->monspecs.modedb_len)
1230 return -EINVAL;
1231
1232 if (var->xres_virtual < var->xres)
1233 var->xres_virtual = var->xres;
1234 if (var->yres_virtual <= var->yres)
1235 var->yres_virtual = -1;
1236 if (rivafb_do_maximize(info, var, nom, den) < 0)
1237 return -EINVAL;
1238
1239 if (var->xoffset < 0)
1240 var->xoffset = 0;
1241 if (var->yoffset < 0)
1242 var->yoffset = 0;
1243
1244 /* truncate xoffset and yoffset to maximum if too high */
1245 if (var->xoffset > var->xres_virtual - var->xres)
1246 var->xoffset = var->xres_virtual - var->xres - 1;
1247
1248 if (var->yoffset > var->yres_virtual - var->yres)
1249 var->yoffset = var->yres_virtual - var->yres - 1;
1250
1251 var->red.msb_right =
1252 var->green.msb_right =
1253 var->blue.msb_right =
1254 var->transp.offset = var->transp.length = var->transp.msb_right = 0;
1255 NVTRACE_LEAVE();
1256 return 0;
1257}
1258
1259static int rivafb_set_par(struct fb_info *info)
1260{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001261 struct riva_par *par = info->par;
Jeff Garzikfd717682006-12-08 02:40:17 -08001262 int rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
1264 NVTRACE_ENTER();
1265 /* vgaHWunlock() + riva unlock (0x7F) */
1266 CRTCout(par, 0x11, 0xFF);
1267 par->riva.LockUnlock(&par->riva, 0);
Jeff Garzikfd717682006-12-08 02:40:17 -08001268 rc = riva_load_video_mode(info);
1269 if (rc)
1270 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 if(!(info->flags & FBINFO_HWACCEL_DISABLED))
1272 riva_setup_accel(info);
1273
1274 par->cursor_reset = 1;
1275 info->fix.line_length = (info->var.xres_virtual * (info->var.bits_per_pixel >> 3));
1276 info->fix.visual = (info->var.bits_per_pixel == 8) ?
1277 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
1278
1279 if (info->flags & FBINFO_HWACCEL_DISABLED)
1280 info->pixmap.scan_align = 1;
1281 else
1282 info->pixmap.scan_align = 4;
Jeff Garzikfd717682006-12-08 02:40:17 -08001283
1284out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 NVTRACE_LEAVE();
Jeff Garzikfd717682006-12-08 02:40:17 -08001286 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287}
1288
1289/**
1290 * rivafb_pan_display
1291 * @var: standard kernel fb changeable data
1292 * @con: TODO
1293 * @info: pointer to fb_info object containing info for current riva board
1294 *
1295 * DESCRIPTION:
1296 * Pan (or wrap, depending on the `vmode' field) the display using the
1297 * `xoffset' and `yoffset' fields of the `var' structure.
1298 * If the values don't fit, return -EINVAL.
1299 *
1300 * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
1301 */
1302static int rivafb_pan_display(struct fb_var_screeninfo *var,
1303 struct fb_info *info)
1304{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001305 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 unsigned int base;
1307
1308 NVTRACE_ENTER();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 base = var->yoffset * info->fix.line_length + var->xoffset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 par->riva.SetStartAddress(&par->riva, base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 NVTRACE_LEAVE();
1312 return 0;
1313}
1314
1315static int rivafb_blank(int blank, struct fb_info *info)
1316{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001317 struct riva_par *par= info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 unsigned char tmp, vesa;
1319
1320 tmp = SEQin(par, 0x01) & ~0x20; /* screen on/off */
1321 vesa = CRTCin(par, 0x1a) & ~0xc0; /* sync on/off */
1322
1323 NVTRACE_ENTER();
1324
1325 if (blank)
1326 tmp |= 0x20;
1327
1328 switch (blank) {
1329 case FB_BLANK_UNBLANK:
1330 case FB_BLANK_NORMAL:
1331 break;
1332 case FB_BLANK_VSYNC_SUSPEND:
1333 vesa |= 0x80;
1334 break;
1335 case FB_BLANK_HSYNC_SUSPEND:
1336 vesa |= 0x40;
1337 break;
1338 case FB_BLANK_POWERDOWN:
1339 vesa |= 0xc0;
1340 break;
1341 }
1342
1343 SEQout(par, 0x01, tmp);
1344 CRTCout(par, 0x1a, vesa);
1345
Michael Hanselmanne01af032006-07-10 04:44:45 -07001346 riva_bl_set_power(info, blank);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347
1348 NVTRACE_LEAVE();
1349
1350 return 0;
1351}
1352
1353/**
1354 * rivafb_setcolreg
1355 * @regno: register index
1356 * @red: red component
1357 * @green: green component
1358 * @blue: blue component
1359 * @transp: transparency
1360 * @info: pointer to fb_info object containing info for current riva board
1361 *
1362 * DESCRIPTION:
1363 * Set a single color register. The values supplied have a 16 bit
1364 * magnitude.
1365 *
1366 * RETURNS:
1367 * Return != 0 for invalid regno.
1368 *
1369 * CALLED FROM:
1370 * fbcmap.c:fb_set_cmap()
1371 */
1372static int rivafb_setcolreg(unsigned regno, unsigned red, unsigned green,
1373 unsigned blue, unsigned transp,
1374 struct fb_info *info)
1375{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001376 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 RIVA_HW_INST *chip = &par->riva;
1378 int i;
1379
1380 if (regno >= riva_get_cmap_len(&info->var))
1381 return -EINVAL;
1382
1383 if (info->var.grayscale) {
1384 /* gray = 0.30*R + 0.59*G + 0.11*B */
1385 red = green = blue =
1386 (red * 77 + green * 151 + blue * 28) >> 8;
1387 }
1388
1389 if (regno < 16 && info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
1390 ((u32 *) info->pseudo_palette)[regno] =
1391 (regno << info->var.red.offset) |
1392 (regno << info->var.green.offset) |
1393 (regno << info->var.blue.offset);
1394 /*
1395 * The Riva128 2D engine requires color information in
1396 * TrueColor format even if framebuffer is in DirectColor
1397 */
1398 if (par->riva.Architecture == NV_ARCH_03) {
1399 switch (info->var.bits_per_pixel) {
1400 case 16:
1401 par->palette[regno] = ((red & 0xf800) >> 1) |
1402 ((green & 0xf800) >> 6) |
1403 ((blue & 0xf800) >> 11);
1404 break;
1405 case 32:
1406 par->palette[regno] = ((red & 0xff00) << 8) |
1407 ((green & 0xff00)) |
1408 ((blue & 0xff00) >> 8);
1409 break;
1410 }
1411 }
1412 }
1413
1414 switch (info->var.bits_per_pixel) {
1415 case 8:
1416 /* "transparent" stuff is completely ignored. */
1417 riva_wclut(chip, regno, red >> 8, green >> 8, blue >> 8);
1418 break;
1419 case 16:
1420 if (info->var.green.length == 5) {
1421 for (i = 0; i < 8; i++) {
1422 riva_wclut(chip, regno*8+i, red >> 8,
1423 green >> 8, blue >> 8);
1424 }
1425 } else {
1426 u8 r, g, b;
1427
1428 if (regno < 32) {
1429 for (i = 0; i < 8; i++) {
1430 riva_wclut(chip, regno*8+i,
1431 red >> 8, green >> 8,
1432 blue >> 8);
1433 }
1434 }
1435 riva_rclut(chip, regno*4, &r, &g, &b);
1436 for (i = 0; i < 4; i++)
1437 riva_wclut(chip, regno*4+i, r,
1438 green >> 8, b);
1439 }
1440 break;
1441 case 32:
1442 riva_wclut(chip, regno, red >> 8, green >> 8, blue >> 8);
1443 break;
1444 default:
1445 /* do nothing */
1446 break;
1447 }
1448 return 0;
1449}
1450
1451/**
1452 * rivafb_fillrect - hardware accelerated color fill function
1453 * @info: pointer to fb_info structure
1454 * @rect: pointer to fb_fillrect structure
1455 *
1456 * DESCRIPTION:
1457 * This function fills up a region of framebuffer memory with a solid
1458 * color with a choice of two different ROP's, copy or invert.
1459 *
1460 * CALLED FROM:
1461 * framebuffer hook
1462 */
1463static void rivafb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
1464{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001465 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 u_int color, rop = 0;
1467
1468 if ((info->flags & FBINFO_HWACCEL_DISABLED)) {
1469 cfb_fillrect(info, rect);
1470 return;
1471 }
1472
1473 if (info->var.bits_per_pixel == 8)
1474 color = rect->color;
1475 else {
1476 if (par->riva.Architecture != NV_ARCH_03)
1477 color = ((u32 *)info->pseudo_palette)[rect->color];
1478 else
1479 color = par->palette[rect->color];
1480 }
1481
1482 switch (rect->rop) {
1483 case ROP_XOR:
1484 rop = 0x66;
1485 break;
1486 case ROP_COPY:
1487 default:
1488 rop = 0xCC;
1489 break;
1490 }
1491
1492 riva_set_rop_solid(par, rop);
1493
1494 RIVA_FIFO_FREE(par->riva, Bitmap, 1);
1495 NV_WR32(&par->riva.Bitmap->Color1A, 0, color);
1496
1497 RIVA_FIFO_FREE(par->riva, Bitmap, 2);
1498 NV_WR32(&par->riva.Bitmap->UnclippedRectangle[0].TopLeft, 0,
1499 (rect->dx << 16) | rect->dy);
1500 mb();
1501 NV_WR32(&par->riva.Bitmap->UnclippedRectangle[0].WidthHeight, 0,
1502 (rect->width << 16) | rect->height);
1503 mb();
1504 riva_set_rop_solid(par, 0xcc);
1505
1506}
1507
1508/**
1509 * rivafb_copyarea - hardware accelerated blit function
1510 * @info: pointer to fb_info structure
1511 * @region: pointer to fb_copyarea structure
1512 *
1513 * DESCRIPTION:
1514 * This copies an area of pixels from one location to another
1515 *
1516 * CALLED FROM:
1517 * framebuffer hook
1518 */
1519static void rivafb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
1520{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001521 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
1523 if ((info->flags & FBINFO_HWACCEL_DISABLED)) {
1524 cfb_copyarea(info, region);
1525 return;
1526 }
1527
1528 RIVA_FIFO_FREE(par->riva, Blt, 3);
1529 NV_WR32(&par->riva.Blt->TopLeftSrc, 0,
1530 (region->sy << 16) | region->sx);
1531 NV_WR32(&par->riva.Blt->TopLeftDst, 0,
1532 (region->dy << 16) | region->dx);
1533 mb();
1534 NV_WR32(&par->riva.Blt->WidthHeight, 0,
1535 (region->height << 16) | region->width);
1536 mb();
1537}
1538
1539static inline void convert_bgcolor_16(u32 *col)
1540{
1541 *col = ((*col & 0x0000F800) << 8)
1542 | ((*col & 0x00007E0) << 5)
1543 | ((*col & 0x0000001F) << 3)
1544 | 0xFF000000;
1545 mb();
1546}
1547
1548/**
1549 * rivafb_imageblit: hardware accelerated color expand function
1550 * @info: pointer to fb_info structure
1551 * @image: pointer to fb_image structure
1552 *
1553 * DESCRIPTION:
1554 * If the source is a monochrome bitmap, the function fills up a a region
1555 * of framebuffer memory with pixels whose color is determined by the bit
1556 * setting of the bitmap, 1 - foreground, 0 - background.
1557 *
1558 * If the source is not a monochrome bitmap, color expansion is not done.
1559 * In this case, it is channeled to a software function.
1560 *
1561 * CALLED FROM:
1562 * framebuffer hook
1563 */
1564static void rivafb_imageblit(struct fb_info *info,
1565 const struct fb_image *image)
1566{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001567 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 u32 fgx = 0, bgx = 0, width, tmp;
1569 u8 *cdat = (u8 *) image->data;
1570 volatile u32 __iomem *d;
1571 int i, size;
1572
1573 if ((info->flags & FBINFO_HWACCEL_DISABLED) || image->depth != 1) {
1574 cfb_imageblit(info, image);
1575 return;
1576 }
1577
1578 switch (info->var.bits_per_pixel) {
1579 case 8:
1580 fgx = image->fg_color;
1581 bgx = image->bg_color;
1582 break;
1583 case 16:
1584 case 32:
1585 if (par->riva.Architecture != NV_ARCH_03) {
1586 fgx = ((u32 *)info->pseudo_palette)[image->fg_color];
1587 bgx = ((u32 *)info->pseudo_palette)[image->bg_color];
1588 } else {
1589 fgx = par->palette[image->fg_color];
1590 bgx = par->palette[image->bg_color];
1591 }
1592 if (info->var.green.length == 6)
1593 convert_bgcolor_16(&bgx);
1594 break;
1595 }
1596
1597 RIVA_FIFO_FREE(par->riva, Bitmap, 7);
1598 NV_WR32(&par->riva.Bitmap->ClipE.TopLeft, 0,
1599 (image->dy << 16) | (image->dx & 0xFFFF));
1600 NV_WR32(&par->riva.Bitmap->ClipE.BottomRight, 0,
1601 (((image->dy + image->height) << 16) |
1602 ((image->dx + image->width) & 0xffff)));
1603 NV_WR32(&par->riva.Bitmap->Color0E, 0, bgx);
1604 NV_WR32(&par->riva.Bitmap->Color1E, 0, fgx);
1605 NV_WR32(&par->riva.Bitmap->WidthHeightInE, 0,
1606 (image->height << 16) | ((image->width + 31) & ~31));
1607 NV_WR32(&par->riva.Bitmap->WidthHeightOutE, 0,
1608 (image->height << 16) | ((image->width + 31) & ~31));
1609 NV_WR32(&par->riva.Bitmap->PointE, 0,
1610 (image->dy << 16) | (image->dx & 0xFFFF));
1611
1612 d = &par->riva.Bitmap->MonochromeData01E;
1613
1614 width = (image->width + 31)/32;
1615 size = width * image->height;
1616 while (size >= 16) {
1617 RIVA_FIFO_FREE(par->riva, Bitmap, 16);
1618 for (i = 0; i < 16; i++) {
1619 tmp = *((u32 *)cdat);
1620 cdat = (u8 *)((u32 *)cdat + 1);
1621 reverse_order(&tmp);
1622 NV_WR32(d, i*4, tmp);
1623 }
1624 size -= 16;
1625 }
1626 if (size) {
1627 RIVA_FIFO_FREE(par->riva, Bitmap, size);
1628 for (i = 0; i < size; i++) {
1629 tmp = *((u32 *) cdat);
1630 cdat = (u8 *)((u32 *)cdat + 1);
1631 reverse_order(&tmp);
1632 NV_WR32(d, i*4, tmp);
1633 }
1634 }
1635}
1636
1637/**
1638 * rivafb_cursor - hardware cursor function
1639 * @info: pointer to info structure
1640 * @cursor: pointer to fbcursor structure
1641 *
1642 * DESCRIPTION:
1643 * A cursor function that supports displaying a cursor image via hardware.
1644 * Within the kernel, copy and invert rops are supported. If exported
1645 * to user space, only the copy rop will be supported.
1646 *
1647 * CALLED FROM
1648 * framebuffer hook
1649 */
1650static int rivafb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1651{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001652 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 u8 data[MAX_CURS * MAX_CURS/8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 int i, set = cursor->set;
James Simmonsf1ab5da2005-06-21 17:17:07 -07001655 u16 fg, bg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656
James Simmonsf1ab5da2005-06-21 17:17:07 -07001657 if (cursor->image.width > MAX_CURS || cursor->image.height > MAX_CURS)
1658 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659
1660 par->riva.ShowHideCursor(&par->riva, 0);
1661
1662 if (par->cursor_reset) {
1663 set = FB_CUR_SETALL;
1664 par->cursor_reset = 0;
1665 }
1666
1667 if (set & FB_CUR_SETSIZE)
1668 memset_io(par->riva.CURSOR, 0, MAX_CURS * MAX_CURS * 2);
1669
1670 if (set & FB_CUR_SETPOS) {
1671 u32 xx, yy, temp;
1672
1673 yy = cursor->image.dy - info->var.yoffset;
1674 xx = cursor->image.dx - info->var.xoffset;
1675 temp = xx & 0xFFFF;
1676 temp |= yy << 16;
1677
1678 NV_WR32(par->riva.PRAMDAC, 0x0000300, temp);
1679 }
1680
1681
1682 if (set & (FB_CUR_SETSHAPE | FB_CUR_SETCMAP | FB_CUR_SETIMAGE)) {
1683 u32 bg_idx = cursor->image.bg_color;
1684 u32 fg_idx = cursor->image.fg_color;
1685 u32 s_pitch = (cursor->image.width+7) >> 3;
1686 u32 d_pitch = MAX_CURS/8;
1687 u8 *dat = (u8 *) cursor->image.data;
1688 u8 *msk = (u8 *) cursor->mask;
1689 u8 *src;
1690
1691 src = kmalloc(s_pitch * cursor->image.height, GFP_ATOMIC);
1692
1693 if (src) {
1694 switch (cursor->rop) {
1695 case ROP_XOR:
James Simmonsf1ab5da2005-06-21 17:17:07 -07001696 for (i = 0; i < s_pitch * cursor->image.height; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 src[i] = dat[i] ^ msk[i];
1698 break;
1699 case ROP_COPY:
1700 default:
James Simmonsf1ab5da2005-06-21 17:17:07 -07001701 for (i = 0; i < s_pitch * cursor->image.height; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 src[i] = dat[i] & msk[i];
1703 break;
1704 }
1705
James Simmonsf1ab5da2005-06-21 17:17:07 -07001706 fb_pad_aligned_buffer(data, d_pitch, src, s_pitch,
1707 cursor->image.height);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
1709 bg = ((info->cmap.red[bg_idx] & 0xf8) << 7) |
1710 ((info->cmap.green[bg_idx] & 0xf8) << 2) |
1711 ((info->cmap.blue[bg_idx] & 0xf8) >> 3) |
1712 1 << 15;
1713
1714 fg = ((info->cmap.red[fg_idx] & 0xf8) << 7) |
1715 ((info->cmap.green[fg_idx] & 0xf8) << 2) |
1716 ((info->cmap.blue[fg_idx] & 0xf8) >> 3) |
1717 1 << 15;
1718
1719 par->riva.LockUnlock(&par->riva, 0);
1720
1721 rivafb_load_cursor_image(par, data, bg, fg,
1722 cursor->image.width,
1723 cursor->image.height);
1724 kfree(src);
1725 }
1726 }
1727
1728 if (cursor->enable)
1729 par->riva.ShowHideCursor(&par->riva, 1);
1730
1731 return 0;
1732}
1733
1734static int rivafb_sync(struct fb_info *info)
1735{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001736 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737
1738 wait_for_idle(par);
1739 return 0;
1740}
1741
1742/* ------------------------------------------------------------------------- *
1743 *
1744 * initialization helper functions
1745 *
1746 * ------------------------------------------------------------------------- */
1747
1748/* kernel interface */
1749static struct fb_ops riva_fb_ops = {
1750 .owner = THIS_MODULE,
1751 .fb_open = rivafb_open,
1752 .fb_release = rivafb_release,
1753 .fb_check_var = rivafb_check_var,
1754 .fb_set_par = rivafb_set_par,
1755 .fb_setcolreg = rivafb_setcolreg,
1756 .fb_pan_display = rivafb_pan_display,
1757 .fb_blank = rivafb_blank,
1758 .fb_fillrect = rivafb_fillrect,
1759 .fb_copyarea = rivafb_copyarea,
1760 .fb_imageblit = rivafb_imageblit,
1761 .fb_cursor = rivafb_cursor,
1762 .fb_sync = rivafb_sync,
1763};
1764
1765static int __devinit riva_set_fbinfo(struct fb_info *info)
1766{
1767 unsigned int cmap_len;
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001768 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769
1770 NVTRACE_ENTER();
1771 info->flags = FBINFO_DEFAULT
1772 | FBINFO_HWACCEL_XPAN
1773 | FBINFO_HWACCEL_YPAN
1774 | FBINFO_HWACCEL_COPYAREA
1775 | FBINFO_HWACCEL_FILLRECT
1776 | FBINFO_HWACCEL_IMAGEBLIT;
1777
1778 /* Accel seems to not work properly on NV30 yet...*/
1779 if ((par->riva.Architecture == NV_ARCH_30) || noaccel) {
1780 printk(KERN_DEBUG PFX "disabling acceleration\n");
1781 info->flags |= FBINFO_HWACCEL_DISABLED;
1782 }
1783
1784 info->var = rivafb_default_var;
1785 info->fix.visual = (info->var.bits_per_pixel == 8) ?
1786 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
1787
1788 info->pseudo_palette = par->pseudo_palette;
1789
1790 cmap_len = riva_get_cmap_len(&info->var);
1791 fb_alloc_cmap(&info->cmap, cmap_len, 0);
1792
1793 info->pixmap.size = 8 * 1024;
1794 info->pixmap.buf_align = 4;
James Simmons58a60642005-06-21 17:17:08 -07001795 info->pixmap.access_align = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 info->pixmap.flags = FB_PIXMAP_SYSTEM;
1797 info->var.yres_virtual = -1;
1798 NVTRACE_LEAVE();
1799 return (rivafb_check_var(&info->var, info));
1800}
1801
1802#ifdef CONFIG_PPC_OF
1803static int __devinit riva_get_EDID_OF(struct fb_info *info, struct pci_dev *pd)
1804{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001805 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 struct device_node *dp;
Al Viro79da3422006-09-23 18:21:35 +01001807 const unsigned char *pedid = NULL;
Al Viro13b5aec2006-09-23 16:44:58 +01001808 const unsigned char *disptype = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 static char *propnames[] = {
1810 "DFP,EDID", "LCD,EDID", "EDID", "EDID1", "EDID,B", "EDID,A", NULL };
1811 int i;
1812
1813 NVTRACE_ENTER();
1814 dp = pci_device_to_OF_node(pd);
1815 for (; dp != NULL; dp = dp->child) {
Jeremy Kerrb04e3dd2006-07-12 15:40:40 +10001816 disptype = get_property(dp, "display-type", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 if (disptype == NULL)
1818 continue;
1819 if (strncmp(disptype, "LCD", 3) != 0)
1820 continue;
1821 for (i = 0; propnames[i] != NULL; ++i) {
Jeremy Kerrb04e3dd2006-07-12 15:40:40 +10001822 pedid = get_property(dp, propnames[i], NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 if (pedid != NULL) {
Andrew Morton0271eb92006-10-04 02:16:24 -07001824 par->EDID = (unsigned char *)pedid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 NVTRACE("LCD found.\n");
1826 return 1;
1827 }
1828 }
1829 }
1830 NVTRACE_LEAVE();
1831 return 0;
1832}
1833#endif /* CONFIG_PPC_OF */
1834
1835#if defined(CONFIG_FB_RIVA_I2C) && !defined(CONFIG_PPC_OF)
1836static int __devinit riva_get_EDID_i2c(struct fb_info *info)
1837{
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001838 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 struct fb_var_screeninfo var;
1840 int i;
1841
1842 NVTRACE_ENTER();
1843 riva_create_i2c_busses(par);
1844 for (i = 0; i < par->bus; i++) {
1845 riva_probe_i2c_connector(par, i+1, &par->EDID);
1846 if (par->EDID && !fb_parse_edid(par->EDID, &var)) {
1847 printk(PFX "Found EDID Block from BUS %i\n", i);
1848 break;
1849 }
1850 }
1851
1852 NVTRACE_LEAVE();
1853 return (par->EDID) ? 1 : 0;
1854}
1855#endif /* CONFIG_FB_RIVA_I2C */
1856
1857static void __devinit riva_update_default_var(struct fb_var_screeninfo *var,
1858 struct fb_info *info)
1859{
1860 struct fb_monspecs *specs = &info->monspecs;
1861 struct fb_videomode modedb;
1862
1863 NVTRACE_ENTER();
1864 /* respect mode options */
1865 if (mode_option) {
1866 fb_find_mode(var, info, mode_option,
1867 specs->modedb, specs->modedb_len,
1868 NULL, 8);
1869 } else if (specs->modedb != NULL) {
1870 /* get preferred timing */
1871 if (info->monspecs.misc & FB_MISC_1ST_DETAIL) {
1872 int i;
1873
1874 for (i = 0; i < specs->modedb_len; i++) {
1875 if (specs->modedb[i].flag & FB_MODE_IS_FIRST) {
1876 modedb = specs->modedb[i];
1877 break;
1878 }
1879 }
1880 } else {
1881 /* otherwise, get first mode in database */
1882 modedb = specs->modedb[0];
1883 }
1884 var->bits_per_pixel = 8;
1885 riva_update_var(var, &modedb);
1886 }
1887 NVTRACE_LEAVE();
1888}
1889
1890
1891static void __devinit riva_get_EDID(struct fb_info *info, struct pci_dev *pdev)
1892{
1893 NVTRACE_ENTER();
1894#ifdef CONFIG_PPC_OF
1895 if (!riva_get_EDID_OF(info, pdev))
1896 printk(PFX "could not retrieve EDID from OF\n");
Olaf Hering44456d32005-07-27 11:45:17 -07001897#elif defined(CONFIG_FB_RIVA_I2C)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 if (!riva_get_EDID_i2c(info))
1899 printk(PFX "could not retrieve EDID from DDC/I2C\n");
1900#endif
1901 NVTRACE_LEAVE();
1902}
1903
1904
1905static void __devinit riva_get_edidinfo(struct fb_info *info)
1906{
1907 struct fb_var_screeninfo *var = &rivafb_default_var;
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001908 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909
1910 fb_edid_to_monspecs(par->EDID, &info->monspecs);
1911 fb_videomode_to_modelist(info->monspecs.modedb, info->monspecs.modedb_len,
1912 &info->modelist);
1913 riva_update_default_var(var, info);
1914
1915 /* if user specified flatpanel, we respect that */
1916 if (info->monspecs.input & FB_DISP_DDI)
1917 par->FlatPanel = 1;
1918}
1919
1920/* ------------------------------------------------------------------------- *
1921 *
1922 * PCI bus
1923 *
1924 * ------------------------------------------------------------------------- */
1925
1926static u32 __devinit riva_get_arch(struct pci_dev *pd)
1927{
1928 u32 arch = 0;
1929
1930 switch (pd->device & 0x0ff0) {
1931 case 0x0100: /* GeForce 256 */
1932 case 0x0110: /* GeForce2 MX */
1933 case 0x0150: /* GeForce2 */
1934 case 0x0170: /* GeForce4 MX */
1935 case 0x0180: /* GeForce4 MX (8x AGP) */
1936 case 0x01A0: /* nForce */
1937 case 0x01F0: /* nForce2 */
1938 arch = NV_ARCH_10;
1939 break;
1940 case 0x0200: /* GeForce3 */
1941 case 0x0250: /* GeForce4 Ti */
1942 case 0x0280: /* GeForce4 Ti (8x AGP) */
1943 arch = NV_ARCH_20;
1944 break;
1945 case 0x0300: /* GeForceFX 5800 */
1946 case 0x0310: /* GeForceFX 5600 */
1947 case 0x0320: /* GeForceFX 5200 */
1948 case 0x0330: /* GeForceFX 5900 */
1949 case 0x0340: /* GeForceFX 5700 */
1950 arch = NV_ARCH_30;
1951 break;
1952 case 0x0020: /* TNT, TNT2 */
1953 arch = NV_ARCH_04;
1954 break;
1955 case 0x0010: /* Riva128 */
1956 arch = NV_ARCH_03;
1957 break;
1958 default: /* unknown architecture */
1959 break;
1960 }
1961 return arch;
1962}
1963
1964static int __devinit rivafb_probe(struct pci_dev *pd,
1965 const struct pci_device_id *ent)
1966{
1967 struct riva_par *default_par;
1968 struct fb_info *info;
1969 int ret;
1970
1971 NVTRACE_ENTER();
1972 assert(pd != NULL);
1973
1974 info = framebuffer_alloc(sizeof(struct riva_par), &pd->dev);
1975 if (!info) {
1976 printk (KERN_ERR PFX "could not allocate memory\n");
1977 ret = -ENOMEM;
1978 goto err_ret;
1979 }
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08001980 default_par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 default_par->pdev = pd;
1982
Jiri Slabyf5610b92007-02-12 00:55:12 -08001983 info->pixmap.addr = kzalloc(8 * 1024, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 if (info->pixmap.addr == NULL) {
1985 ret = -ENOMEM;
1986 goto err_framebuffer_release;
1987 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988
1989 ret = pci_enable_device(pd);
1990 if (ret < 0) {
1991 printk(KERN_ERR PFX "cannot enable PCI device\n");
1992 goto err_free_pixmap;
1993 }
1994
1995 ret = pci_request_regions(pd, "rivafb");
1996 if (ret < 0) {
1997 printk(KERN_ERR PFX "cannot request PCI regions\n");
1998 goto err_disable_device;
1999 }
2000
Jiri Slabyc4f28e52007-02-12 00:55:11 -08002001 mutex_init(&default_par->open_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 default_par->riva.Architecture = riva_get_arch(pd);
2003
2004 default_par->Chipset = (pd->vendor << 16) | pd->device;
2005 printk(KERN_INFO PFX "nVidia device/chipset %X\n",default_par->Chipset);
2006
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 if(default_par->riva.Architecture == 0) {
2008 printk(KERN_ERR PFX "unknown NV_ARCH\n");
2009 ret=-ENODEV;
2010 goto err_release_region;
2011 }
2012 if(default_par->riva.Architecture == NV_ARCH_10 ||
2013 default_par->riva.Architecture == NV_ARCH_20 ||
2014 default_par->riva.Architecture == NV_ARCH_30) {
2015 sprintf(rivafb_fix.id, "NV%x", (pd->device & 0x0ff0) >> 4);
2016 } else {
2017 sprintf(rivafb_fix.id, "NV%x", default_par->riva.Architecture);
2018 }
2019
2020 default_par->FlatPanel = flatpanel;
2021 if (flatpanel == 1)
2022 printk(KERN_INFO PFX "flatpanel support enabled\n");
2023 default_par->forceCRTC = forceCRTC;
2024
2025 rivafb_fix.mmio_len = pci_resource_len(pd, 0);
2026 rivafb_fix.smem_len = pci_resource_len(pd, 1);
2027
2028 {
2029 /* enable IO and mem if not already done */
2030 unsigned short cmd;
2031
2032 pci_read_config_word(pd, PCI_COMMAND, &cmd);
2033 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
2034 pci_write_config_word(pd, PCI_COMMAND, cmd);
2035 }
2036
2037 rivafb_fix.mmio_start = pci_resource_start(pd, 0);
2038 rivafb_fix.smem_start = pci_resource_start(pd, 1);
2039
2040 default_par->ctrl_base = ioremap(rivafb_fix.mmio_start,
2041 rivafb_fix.mmio_len);
2042 if (!default_par->ctrl_base) {
2043 printk(KERN_ERR PFX "cannot ioremap MMIO base\n");
2044 ret = -EIO;
2045 goto err_release_region;
2046 }
2047
2048 switch (default_par->riva.Architecture) {
2049 case NV_ARCH_03:
2050 /* Riva128's PRAMIN is in the "framebuffer" space
2051 * Since these cards were never made with more than 8 megabytes
2052 * we can safely allocate this separately.
2053 */
2054 default_par->riva.PRAMIN = ioremap(rivafb_fix.smem_start + 0x00C00000, 0x00008000);
2055 if (!default_par->riva.PRAMIN) {
2056 printk(KERN_ERR PFX "cannot ioremap PRAMIN region\n");
2057 ret = -EIO;
2058 goto err_iounmap_ctrl_base;
2059 }
2060 break;
2061 case NV_ARCH_04:
2062 case NV_ARCH_10:
2063 case NV_ARCH_20:
2064 case NV_ARCH_30:
2065 default_par->riva.PCRTC0 =
2066 (u32 __iomem *)(default_par->ctrl_base + 0x00600000);
2067 default_par->riva.PRAMIN =
2068 (u32 __iomem *)(default_par->ctrl_base + 0x00710000);
2069 break;
2070 }
2071 riva_common_setup(default_par);
2072
2073 if (default_par->riva.Architecture == NV_ARCH_03) {
2074 default_par->riva.PCRTC = default_par->riva.PCRTC0
2075 = default_par->riva.PGRAPH;
2076 }
2077
2078 rivafb_fix.smem_len = riva_get_memlen(default_par) * 1024;
2079 default_par->dclk_max = riva_get_maxdclk(default_par) * 1000;
2080 info->screen_base = ioremap(rivafb_fix.smem_start,
2081 rivafb_fix.smem_len);
2082 if (!info->screen_base) {
2083 printk(KERN_ERR PFX "cannot ioremap FB base\n");
2084 ret = -EIO;
2085 goto err_iounmap_pramin;
2086 }
2087
2088#ifdef CONFIG_MTRR
2089 if (!nomtrr) {
2090 default_par->mtrr.vram = mtrr_add(rivafb_fix.smem_start,
2091 rivafb_fix.smem_len,
2092 MTRR_TYPE_WRCOMB, 1);
2093 if (default_par->mtrr.vram < 0) {
2094 printk(KERN_ERR PFX "unable to setup MTRR\n");
2095 } else {
2096 default_par->mtrr.vram_valid = 1;
2097 /* let there be speed */
2098 printk(KERN_INFO PFX "RIVA MTRR set to ON\n");
2099 }
2100 }
2101#endif /* CONFIG_MTRR */
2102
2103 info->fbops = &riva_fb_ops;
2104 info->fix = rivafb_fix;
2105 riva_get_EDID(info, pd);
2106 riva_get_edidinfo(info);
2107
2108 ret=riva_set_fbinfo(info);
2109 if (ret < 0) {
2110 printk(KERN_ERR PFX "error setting initial video mode\n");
2111 goto err_iounmap_screen_base;
2112 }
2113
2114 fb_destroy_modedb(info->monspecs.modedb);
2115 info->monspecs.modedb = NULL;
Guido Guentherce38cac2006-07-30 03:04:21 -07002116
2117 pci_set_drvdata(pd, info);
2118 riva_bl_init(info->par);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 ret = register_framebuffer(info);
2120 if (ret < 0) {
2121 printk(KERN_ERR PFX
2122 "error registering riva framebuffer\n");
2123 goto err_iounmap_screen_base;
2124 }
2125
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 printk(KERN_INFO PFX
2127 "PCI nVidia %s framebuffer ver %s (%dMB @ 0x%lX)\n",
2128 info->fix.id,
2129 RIVAFB_VERSION,
2130 info->fix.smem_len / (1024 * 1024),
2131 info->fix.smem_start);
Michael Hanselmann5474c122006-06-25 05:47:08 -07002132
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 NVTRACE_LEAVE();
2134 return 0;
2135
2136err_iounmap_screen_base:
2137#ifdef CONFIG_FB_RIVA_I2C
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08002138 riva_delete_i2c_busses(info->par);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139#endif
2140 iounmap(info->screen_base);
2141err_iounmap_pramin:
2142 if (default_par->riva.Architecture == NV_ARCH_03)
2143 iounmap(default_par->riva.PRAMIN);
2144err_iounmap_ctrl_base:
2145 iounmap(default_par->ctrl_base);
2146err_release_region:
2147 pci_release_regions(pd);
2148err_disable_device:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149err_free_pixmap:
2150 kfree(info->pixmap.addr);
2151err_framebuffer_release:
2152 framebuffer_release(info);
2153err_ret:
2154 return ret;
2155}
2156
2157static void __exit rivafb_remove(struct pci_dev *pd)
2158{
2159 struct fb_info *info = pci_get_drvdata(pd);
Antonino A. Daplasf4a41832006-01-09 20:53:04 -08002160 struct riva_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161
2162 NVTRACE_ENTER();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
Michael Hanselmann5474c122006-06-25 05:47:08 -07002164 riva_bl_exit(par);
2165
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166#ifdef CONFIG_FB_RIVA_I2C
2167 riva_delete_i2c_busses(par);
2168 kfree(par->EDID);
2169#endif
2170
2171 unregister_framebuffer(info);
2172#ifdef CONFIG_MTRR
2173 if (par->mtrr.vram_valid)
2174 mtrr_del(par->mtrr.vram, info->fix.smem_start,
2175 info->fix.smem_len);
2176#endif /* CONFIG_MTRR */
2177
2178 iounmap(par->ctrl_base);
2179 iounmap(info->screen_base);
2180 if (par->riva.Architecture == NV_ARCH_03)
2181 iounmap(par->riva.PRAMIN);
2182 pci_release_regions(pd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 kfree(info->pixmap.addr);
2184 framebuffer_release(info);
2185 pci_set_drvdata(pd, NULL);
2186 NVTRACE_LEAVE();
2187}
2188
2189/* ------------------------------------------------------------------------- *
2190 *
2191 * initialization
2192 *
2193 * ------------------------------------------------------------------------- */
2194
2195#ifndef MODULE
2196static int __init rivafb_setup(char *options)
2197{
2198 char *this_opt;
2199
2200 NVTRACE_ENTER();
2201 if (!options || !*options)
2202 return 0;
2203
2204 while ((this_opt = strsep(&options, ",")) != NULL) {
2205 if (!strncmp(this_opt, "forceCRTC", 9)) {
2206 char *p;
2207
2208 p = this_opt + 9;
2209 if (!*p || !*(++p)) continue;
2210 forceCRTC = *p - '0';
2211 if (forceCRTC < 0 || forceCRTC > 1)
2212 forceCRTC = -1;
2213 } else if (!strncmp(this_opt, "flatpanel", 9)) {
2214 flatpanel = 1;
2215#ifdef CONFIG_MTRR
2216 } else if (!strncmp(this_opt, "nomtrr", 6)) {
2217 nomtrr = 1;
2218#endif
2219 } else if (!strncmp(this_opt, "strictmode", 10)) {
2220 strictmode = 1;
2221 } else if (!strncmp(this_opt, "noaccel", 7)) {
2222 noaccel = 1;
2223 } else
2224 mode_option = this_opt;
2225 }
2226 NVTRACE_LEAVE();
2227 return 0;
2228}
2229#endif /* !MODULE */
2230
2231static struct pci_driver rivafb_driver = {
2232 .name = "rivafb",
2233 .id_table = rivafb_pci_tbl,
2234 .probe = rivafb_probe,
2235 .remove = __exit_p(rivafb_remove),
2236};
2237
2238
2239
2240/* ------------------------------------------------------------------------- *
2241 *
2242 * modularization
2243 *
2244 * ------------------------------------------------------------------------- */
2245
2246static int __devinit rivafb_init(void)
2247{
2248#ifndef MODULE
2249 char *option = NULL;
2250
2251 if (fb_get_options("rivafb", &option))
2252 return -ENODEV;
2253 rivafb_setup(option);
2254#endif
2255 return pci_register_driver(&rivafb_driver);
2256}
2257
2258
2259module_init(rivafb_init);
2260
2261#ifdef MODULE
2262static void __exit rivafb_exit(void)
2263{
2264 pci_unregister_driver(&rivafb_driver);
2265}
2266
2267module_exit(rivafb_exit);
2268#endif /* MODULE */
2269
2270module_param(noaccel, bool, 0);
2271MODULE_PARM_DESC(noaccel, "bool: disable acceleration");
2272module_param(flatpanel, int, 0);
2273MODULE_PARM_DESC(flatpanel, "Enables experimental flat panel support for some chipsets. (0 or 1=enabled) (default=0)");
2274module_param(forceCRTC, int, 0);
2275MODULE_PARM_DESC(forceCRTC, "Forces usage of a particular CRTC in case autodetection fails. (0 or 1) (default=autodetect)");
2276#ifdef CONFIG_MTRR
2277module_param(nomtrr, bool, 0);
2278MODULE_PARM_DESC(nomtrr, "Disables MTRR support (0 or 1=disabled) (default=0)");
2279#endif
2280module_param(strictmode, bool, 0);
2281MODULE_PARM_DESC(strictmode, "Only use video modes from EDID");
2282
2283MODULE_AUTHOR("Ani Joshi, maintainer");
2284MODULE_DESCRIPTION("Framebuffer driver for nVidia Riva 128, TNT, TNT2, and the GeForce series");
2285MODULE_LICENSE("GPL");