tremor uses integer types
[mplayer/glamo.git] / drivers / mga_vid.c
blob3b8ebac0a68e8c90c0e03010c58848e996aaaf31
1 //#define CRTC2
3 // YUY2 support (see config.format) added by A'rpi/ESP-team
4 // double buffering added by A'rpi/ESP-team
5 // brightness/contrast introduced by eyck
6 // multiple card support by Attila Kinali <attila@kinali.ch>
8 // Set this value, if autodetection fails! (video ram size in megabytes)
9 // #define MGA_MEMORY_SIZE 16
11 //#define MGA_ALLOW_IRQ
13 #define MGA_VSYNC_POS 2
17 * mga_vid.c
19 * Copyright (C) 1999 Aaron Holtzman
21 * Module skeleton based on gutted agpgart module by Jeff Hartmann
22 * <slicer@ionet.net>
24 * Matrox MGA G200/G400 YUV Video Interface module Version 0.1.0
26 * BES == Back End Scaler
28 * This software has been released under the terms of the GNU Public
29 * license. See http://www.gnu.org/copyleft/gpl.html for details.
32 //It's entirely possible this major conflicts with something else
33 //use the 'major' parameter to override the default major number (178)
34 /* mknod /dev/mga_vid c 178 0 */
36 #include <linux/config.h>
37 #include <linux/version.h>
38 #include <linux/module.h>
39 #include <linux/types.h>
40 #include <linux/kernel.h>
41 #include <linux/sched.h>
42 #include <linux/mm.h>
43 #include <linux/string.h>
44 #include <linux/errno.h>
46 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10)
47 #include <linux/malloc.h>
48 #else
49 #include <linux/slab.h>
50 #endif
52 #include <linux/pci.h>
53 #include <linux/ioport.h>
54 #include <linux/init.h>
56 #include "mga_vid.h"
58 #ifdef CONFIG_MTRR
59 #include <asm/mtrr.h>
60 #endif
62 #ifdef CONFIG_DEVFS_FS
63 #include <linux/devfs_fs_kernel.h>
64 #endif
66 #include <asm/uaccess.h>
67 #include <asm/system.h>
68 #include <asm/io.h>
70 #define TRUE 1
71 #define FALSE 0
73 #define DEFAULT_MGA_VID_MAJOR 178
75 #ifndef PCI_DEVICE_ID_MATROX_G200_PCI
76 #define PCI_DEVICE_ID_MATROX_G200_PCI 0x0520
77 #endif
79 #ifndef PCI_DEVICE_ID_MATROX_G200_AGP
80 #define PCI_DEVICE_ID_MATROX_G200_AGP 0x0521
81 #endif
83 #ifndef PCI_DEVICE_ID_MATROX_G400
84 #define PCI_DEVICE_ID_MATROX_G400 0x0525
85 #endif
87 #ifndef PCI_DEVICE_ID_MATROX_G550
88 #define PCI_DEVICE_ID_MATROX_G550 0x2527
89 #endif
91 #ifndef PCI_SUBSYSTEM_ID_MATROX_G400_DH_16MB
92 #define PCI_SUBSYSTEM_ID_MATROX_G400_DH_16MB 0x2159
93 #endif
95 #ifndef PCI_SUBSYSTEM_ID_MATROX_G400_16MB_SGRAM
96 #define PCI_SUBSYSTEM_ID_MATROX_G400_16MB_SGRAM 0x19d8
97 #endif
99 #ifndef PCI_SUBSYSTEM_ID_MATROX_G400_16MB_SDRAM
100 #define PCI_SUBSYSTEM_ID_MATROX_G400_16MB_SDRAM 0x0328
101 #endif
103 MODULE_AUTHOR("Aaron Holtzman <aholtzma@engr.uvic.ca>");
104 #ifdef MODULE_LICENSE
105 MODULE_LICENSE("GPL");
106 #endif
108 #define PARAM_BRIGHTNESS "brightness="
109 #define PARAM_CONTRAST "contrast="
110 #define PARAM_BLACKIE "blackie="
112 // set PARAM_BUFF_SIZE to just below 4k because some kernel versions
113 // store additional information in the memory page which leads to
114 // the allocation of an additional page if exactly 4k is used
115 #define PARAM_BUFF_SIZE 4000
117 #ifndef min
118 #define min(x,y) (((x)<(y))?(x):(y))
119 #endif
121 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
122 #include <linux/ctype.h>
124 static unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base)
126 unsigned long result = 0,value;
128 if (!base) {
129 base = 10;
130 if (*cp == '0') {
131 base = 8;
132 cp++;
133 if ((*cp == 'x') && isxdigit(cp[1])) {
134 cp++;
135 base = 16;
139 while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp)
140 ? toupper(*cp) : *cp)-'A'+10) < base) {
141 result = result*base + value;
142 cp++;
144 if (endp)
145 *endp = (char *)cp;
146 return result;
148 #endif
150 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) || LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,5)
151 static long simple_strtol(const char *cp,char **endp,unsigned int base)
153 if(*cp=='-')
154 return -simple_strtoul(cp+1,endp,base);
155 return simple_strtoul(cp,endp,base);
157 #endif
160 typedef struct bes_registers_s
162 //BES Control
163 uint32_t besctl;
164 //BES Global control
165 uint32_t besglobctl;
166 //Luma control (brightness and contrast)
167 uint32_t beslumactl;
168 //Line pitch
169 uint32_t bespitch;
171 //Buffer A-1 Chroma 3 plane org
172 uint32_t besa1c3org;
173 //Buffer A-1 Chroma org
174 uint32_t besa1corg;
175 //Buffer A-1 Luma org
176 uint32_t besa1org;
178 //Buffer A-2 Chroma 3 plane org
179 uint32_t besa2c3org;
180 //Buffer A-2 Chroma org
181 uint32_t besa2corg;
182 //Buffer A-2 Luma org
183 uint32_t besa2org;
185 //Buffer B-1 Chroma 3 plane org
186 uint32_t besb1c3org;
187 //Buffer B-1 Chroma org
188 uint32_t besb1corg;
189 //Buffer B-1 Luma org
190 uint32_t besb1org;
192 //Buffer B-2 Chroma 3 plane org
193 uint32_t besb2c3org;
194 //Buffer B-2 Chroma org
195 uint32_t besb2corg;
196 //Buffer B-2 Luma org
197 uint32_t besb2org;
199 //BES Horizontal coord
200 uint32_t beshcoord;
201 //BES Horizontal inverse scaling [5.14]
202 uint32_t beshiscal;
203 //BES Horizontal source start [10.14] (for scaling)
204 uint32_t beshsrcst;
205 //BES Horizontal source ending [10.14] (for scaling)
206 uint32_t beshsrcend;
207 //BES Horizontal source last
208 uint32_t beshsrclst;
211 //BES Vertical coord
212 uint32_t besvcoord;
213 //BES Vertical inverse scaling [5.14]
214 uint32_t besviscal;
215 //BES Field 1 vertical source last position
216 uint32_t besv1srclst;
217 //BES Field 1 weight start
218 uint32_t besv1wght;
219 //BES Field 2 vertical source last position
220 uint32_t besv2srclst;
221 //BES Field 2 weight start
222 uint32_t besv2wght;
225 //configurable stuff
226 int blackie;
228 } bes_registers_t;
230 #ifdef CRTC2
231 typedef struct crtc2_registers_s
233 uint32_t c2ctl;
234 uint32_t c2datactl;
235 uint32_t c2misc;
236 uint32_t c2hparam;
237 uint32_t c2hsync;
238 uint32_t c2offset;
239 uint32_t c2pl2startadd0;
240 uint32_t c2pl2startadd1;
241 uint32_t c2pl3startadd0;
242 uint32_t c2pl3startadd1;
243 uint32_t c2preload;
244 uint32_t c2spicstartadd0;
245 uint32_t c2spicstartadd1;
246 uint32_t c2startadd0;
247 uint32_t c2startadd1;
248 uint32_t c2subpiclut;
249 uint32_t c2vcount;
250 uint32_t c2vparam;
251 uint32_t c2vsync;
252 } crtc2_registers_t;
253 #endif
259 //All register offsets are converted to word aligned offsets (32 bit)
260 //because we want all our register accesses to be 32 bits
261 #define VCOUNT 0x1e20
263 #define PALWTADD 0x3c00 // Index register for X_DATAREG port
264 #define X_DATAREG 0x3c0a
266 #define XMULCTRL 0x19
267 #define BPP_8 0x00
268 #define BPP_15 0x01
269 #define BPP_16 0x02
270 #define BPP_24 0x03
271 #define BPP_32_DIR 0x04
272 #define BPP_32_PAL 0x07
274 #define XCOLMSK 0x40
275 #define X_COLKEY 0x42
276 #define XKEYOPMODE 0x51
277 #define XCOLMSK0RED 0x52
278 #define XCOLMSK0GREEN 0x53
279 #define XCOLMSK0BLUE 0x54
280 #define XCOLKEY0RED 0x55
281 #define XCOLKEY0GREEN 0x56
282 #define XCOLKEY0BLUE 0x57
284 #ifdef CRTC2
286 /*CRTC2 registers*/
287 #define XMISCCTRL 0x1e
288 #define C2CTL 0x3c10
289 #define C2DATACTL 0x3c4c
290 #define C2MISC 0x3c44
291 #define C2HPARAM 0x3c14
292 #define C2HSYNC 0x3c18
293 #define C2OFFSET 0x3c40
294 #define C2PL2STARTADD0 0x3c30 // like BESA1CORG
295 #define C2PL2STARTADD1 0x3c34 // like BESA2CORG
296 #define C2PL3STARTADD0 0x3c38 // like BESA1C3ORG
297 #define C2PL3STARTADD1 0x3c3c // like BESA2C3ORG
298 #define C2PRELOAD 0x3c24
299 #define C2SPICSTARTADD0 0x3c54
300 #define C2SPICSTARTADD1 0x3c58
301 #define C2STARTADD0 0x3c28 // like BESA1ORG
302 #define C2STARTADD1 0x3c2c // like BESA2ORG
303 #define C2SUBPICLUT 0x3c50
304 #define C2VCOUNT 0x3c48
305 #define C2VPARAM 0x3c1c
306 #define C2VSYNC 0x3c20
308 #endif
310 // Backend Scaler registers
311 #define BESCTL 0x3d20
312 #define BESGLOBCTL 0x3dc0
313 #define BESLUMACTL 0x3d40
314 #define BESPITCH 0x3d24
316 #define BESA1C3ORG 0x3d60
317 #define BESA1CORG 0x3d10
318 #define BESA1ORG 0x3d00
320 #define BESA2C3ORG 0x3d64
321 #define BESA2CORG 0x3d14
322 #define BESA2ORG 0x3d04
324 #define BESB1C3ORG 0x3d68
325 #define BESB1CORG 0x3d18
326 #define BESB1ORG 0x3d08
328 #define BESB2C3ORG 0x3d6C
329 #define BESB2CORG 0x3d1C
330 #define BESB2ORG 0x3d0C
332 #define BESHCOORD 0x3d28
333 #define BESHISCAL 0x3d30
334 #define BESHSRCEND 0x3d3C
335 #define BESHSRCLST 0x3d50
336 #define BESHSRCST 0x3d38
337 #define BESV1WGHT 0x3d48
338 #define BESV2WGHT 0x3d4c
339 #define BESV1SRCLST 0x3d54
340 #define BESV2SRCLST 0x3d58
341 #define BESVISCAL 0x3d34
342 #define BESVCOORD 0x3d2c
343 #define BESSTATUS 0x3dc4
345 #define CRTCX 0x1fd4
346 #define CRTCD 0x1fd5
347 #define IEN 0x1e1c
348 #define ICLEAR 0x1e18
349 #define STATUS 0x1e14
352 // global devfs handle for /dev/mga_vid
353 #ifdef CONFIG_DEVFS_FS
354 static devfs_handle_t dev_handle = NULL;
355 #endif
357 // card local config
358 typedef struct mga_card_s {
360 // local devfs handle for /dev/mga_vidX
361 #ifdef CONFIG_DEVFS_FS
362 devfs_handle_t dev_handle;
363 #endif
365 uint8_t *param_buff; // buffer for read()
366 uint32_t param_buff_size;
367 uint32_t param_buff_len;
368 bes_registers_t regs;
369 #ifdef CRTC2
370 crtc2_registers_t cregs;
371 #endif
372 uint32_t vid_in_use;
373 uint32_t is_g400;
374 uint32_t vid_src_ready;
375 uint32_t vid_overlay_on;
377 uint8_t *mmio_base;
378 uint32_t mem_base;
379 int src_base; // YUV buffer position in video memory
380 uint32_t ram_size; // how much megabytes videoram we have
381 uint32_t top_reserved; // reserved space for console font (matroxfb + fastfont)
383 int brightness; // initial brightness
384 int contrast; // initial contrast
386 struct pci_dev *pci_dev;
388 mga_vid_config_t config;
389 int configured; // set to 1 when the card is configured over ioctl
391 int colkey_saved;
392 int colkey_on;
393 unsigned char colkey_color[4];
394 unsigned char colkey_mask[4];
396 int irq; // = -1
397 int next_frame;
398 } mga_card_t;
400 #define MGA_MAX_CARDS 16
401 // this is used as init value for the parameter arrays
402 // it should have exactly MGA_MAX_CARDS elements
403 #define MGA_MAX_CARDS_INIT_ARRAY {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
404 static unsigned int mga_cards_num=0;
405 static mga_card_t * mga_cards[MGA_MAX_CARDS] = MGA_MAX_CARDS_INIT_ARRAY;
407 // module parameters
408 static int major = DEFAULT_MGA_VID_MAJOR;
409 static int mga_ram_size[MGA_MAX_CARDS] = MGA_MAX_CARDS_INIT_ARRAY;
410 static int mga_brightness[MGA_MAX_CARDS] = MGA_MAX_CARDS_INIT_ARRAY;
411 static int mga_contrast[MGA_MAX_CARDS] = MGA_MAX_CARDS_INIT_ARRAY;
412 static int mga_top_reserved[MGA_MAX_CARDS] = MGA_MAX_CARDS_INIT_ARRAY;
414 MODULE_PARM(mga_ram_size, "1-" __MODULE_STRING(MGA_MAX_CARDS) "i");
415 MODULE_PARM(mga_top_reserved, "1-" __MODULE_STRING(MGA_MAX_CARDS) "i");
416 MODULE_PARM(mga_brightness, "1-" __MODULE_STRING(MGA_MAX_CARDS) "i");
417 MODULE_PARM(mga_contrast, "1-" __MODULE_STRING(MGA_MAX_CARDS) "i");
418 MODULE_PARM(major, "i");
420 #ifdef CRTC2
421 static void crtc2_frame_sel(mga_card_t * card, int frame)
423 switch(frame) {
424 case 0:
425 card->cregs.c2pl2startadd0=card->regs.besa1corg;
426 card->cregs.c2pl3startadd0=card->regs.besa1c3org;
427 card->cregs.c2startadd0=card->regs.besa1org;
428 break;
429 case 1:
430 card->cregs.c2pl2startadd0=card->regs.besa2corg;
431 card->cregs.c2pl3startadd0=card->regs.besa2c3org;
432 card->cregs.c2startadd0=card->regs.besa2org;
433 break;
434 case 2:
435 card->cregs.c2pl2startadd0=card->regs.besb1corg;
436 card->cregs.c2pl3startadd0=card->regs.besb1c3org;
437 card->cregs.c2startadd0=card->regs.besb1org;
438 break;
439 case 3:
440 card->cregs.c2pl2startadd0=card->regs.besb2corg;
441 card->cregs.c2pl3startadd0=card->regs.besb2c3org;
442 card->cregs.c2startadd0=card->regs.besb2org;
443 break;
445 writel(card->cregs.c2startadd0, card->mmio_base + C2STARTADD0);
446 writel(card->cregs.c2pl2startadd0, card->mmio_base + C2PL2STARTADD0);
447 writel(card->cregs.c2pl3startadd0, card->mmio_base + C2PL3STARTADD0);
449 #endif
451 static void mga_vid_frame_sel(mga_card_t * card, int frame)
453 if ( card->irq != -1 ) {
454 card->next_frame=frame;
455 } else {
457 //we don't need the vcount protection as we're only hitting
458 //one register (and it doesn't seem to be double buffered)
459 card->regs.besctl = (card->regs.besctl & ~0x07000000) + (frame << 25);
460 writel( card->regs.besctl, card->mmio_base + BESCTL );
462 // writel( card->regs.besglobctl + ((readl(card->mmio_base + VCOUNT)+2)<<16),
463 writel( card->regs.besglobctl + (MGA_VSYNC_POS<<16),
464 card->mmio_base + BESGLOBCTL);
465 #ifdef CRTC2
466 crtc2_frame_sel(card, frame);
467 #endif
473 static void mga_vid_write_regs(mga_card_t * card, int restore)
475 //Make sure internal registers don't get updated until we're done
476 writel( (readl(card->mmio_base + VCOUNT)-1)<<16,
477 card->mmio_base + BESGLOBCTL);
479 // color or coordinate keying
481 if(restore && card->colkey_saved){
482 // restore it
483 card->colkey_saved=0;
485 #ifdef MP_DEBUG
486 printk("mga_vid: Restoring colorkey (ON: %d %02X:%02X:%02X)\n",
487 card->colkey_on,card->colkey_color[0],card->colkey_color[1],card->colkey_color[2]);
488 #endif
490 // Set color key registers:
491 writeb( XKEYOPMODE, card->mmio_base + PALWTADD);
492 writeb( card->colkey_on, card->mmio_base + X_DATAREG);
494 writeb( XCOLKEY0RED, card->mmio_base + PALWTADD);
495 writeb( card->colkey_color[0], card->mmio_base + X_DATAREG);
496 writeb( XCOLKEY0GREEN, card->mmio_base + PALWTADD);
497 writeb( card->colkey_color[1], card->mmio_base + X_DATAREG);
498 writeb( XCOLKEY0BLUE, card->mmio_base + PALWTADD);
499 writeb( card->colkey_color[2], card->mmio_base + X_DATAREG);
500 writeb( X_COLKEY, card->mmio_base + PALWTADD);
501 writeb( card->colkey_color[3], card->mmio_base + X_DATAREG);
503 writeb( XCOLMSK0RED, card->mmio_base + PALWTADD);
504 writeb( card->colkey_mask[0], card->mmio_base + X_DATAREG);
505 writeb( XCOLMSK0GREEN, card->mmio_base + PALWTADD);
506 writeb( card->colkey_mask[1], card->mmio_base + X_DATAREG);
507 writeb( XCOLMSK0BLUE, card->mmio_base + PALWTADD);
508 writeb( card->colkey_mask[2], card->mmio_base + X_DATAREG);
509 writeb( XCOLMSK, card->mmio_base + PALWTADD);
510 writeb( card->colkey_mask[3], card->mmio_base + X_DATAREG);
512 } else if(!card->colkey_saved){
513 // save it
514 card->colkey_saved=1;
515 // Get color key registers:
516 writeb( XKEYOPMODE, card->mmio_base + PALWTADD);
517 card->colkey_on=(unsigned char)readb(card->mmio_base + X_DATAREG) & 1;
519 writeb( XCOLKEY0RED, card->mmio_base + PALWTADD);
520 card->colkey_color[0]=(unsigned char)readb(card->mmio_base + X_DATAREG);
521 writeb( XCOLKEY0GREEN, card->mmio_base + PALWTADD);
522 card->colkey_color[1]=(unsigned char)readb(card->mmio_base + X_DATAREG);
523 writeb( XCOLKEY0BLUE, card->mmio_base + PALWTADD);
524 card->colkey_color[2]=(unsigned char)readb(card->mmio_base + X_DATAREG);
525 writeb( X_COLKEY, card->mmio_base + PALWTADD);
526 card->colkey_color[3]=(unsigned char)readb(card->mmio_base + X_DATAREG);
528 writeb( XCOLMSK0RED, card->mmio_base + PALWTADD);
529 card->colkey_mask[0]=(unsigned char)readb(card->mmio_base + X_DATAREG);
530 writeb( XCOLMSK0GREEN, card->mmio_base + PALWTADD);
531 card->colkey_mask[1]=(unsigned char)readb(card->mmio_base + X_DATAREG);
532 writeb( XCOLMSK0BLUE, card->mmio_base + PALWTADD);
533 card->colkey_mask[2]=(unsigned char)readb(card->mmio_base + X_DATAREG);
534 writeb( XCOLMSK, card->mmio_base + PALWTADD);
535 card->colkey_mask[3]=(unsigned char)readb(card->mmio_base + X_DATAREG);
537 #ifdef MP_DEBUG
538 printk("mga_vid: Saved colorkey (ON: %d %02X:%02X:%02X)\n",
539 card->colkey_on, card->colkey_color[0], card->colkey_color[1], card->colkey_color[2]);
540 #endif
544 if(!restore){
545 writeb( XKEYOPMODE, card->mmio_base + PALWTADD);
546 writeb( card->config.colkey_on, card->mmio_base + X_DATAREG);
547 if ( card->config.colkey_on )
549 uint32_t r=0, g=0, b=0;
551 writeb( XMULCTRL, card->mmio_base + PALWTADD);
552 switch (readb (card->mmio_base + X_DATAREG))
554 case BPP_8:
555 /* Need to look up the color index, just using color 0 for now. */
556 break;
558 case BPP_15:
559 r = card->config.colkey_red >> 3;
560 g = card->config.colkey_green >> 3;
561 b = card->config.colkey_blue >> 3;
562 break;
564 case BPP_16:
565 r = card->config.colkey_red >> 3;
566 g = card->config.colkey_green >> 2;
567 b = card->config.colkey_blue >> 3;
568 break;
570 case BPP_24:
571 case BPP_32_DIR:
572 case BPP_32_PAL:
573 r = card->config.colkey_red;
574 g = card->config.colkey_green;
575 b = card->config.colkey_blue;
576 break;
579 // Disable color keying on alpha channel
580 writeb( XCOLMSK, card->mmio_base + PALWTADD);
581 writeb( 0x00, card->mmio_base + X_DATAREG);
582 writeb( X_COLKEY, card->mmio_base + PALWTADD);
583 writeb( 0x00, card->mmio_base + X_DATAREG);
586 // Set up color key registers
587 writeb( XCOLKEY0RED, card->mmio_base + PALWTADD);
588 writeb( r, card->mmio_base + X_DATAREG);
589 writeb( XCOLKEY0GREEN, card->mmio_base + PALWTADD);
590 writeb( g, card->mmio_base + X_DATAREG);
591 writeb( XCOLKEY0BLUE, card->mmio_base + PALWTADD);
592 writeb( b, card->mmio_base + X_DATAREG);
594 // Set up color key mask registers
595 writeb( XCOLMSK0RED, card->mmio_base + PALWTADD);
596 writeb( 0xff, card->mmio_base + X_DATAREG);
597 writeb( XCOLMSK0GREEN, card->mmio_base + PALWTADD);
598 writeb( 0xff, card->mmio_base + X_DATAREG);
599 writeb( XCOLMSK0BLUE, card->mmio_base + PALWTADD);
600 writeb( 0xff, card->mmio_base + X_DATAREG);
605 // Backend Scaler
606 writel( card->regs.besctl, card->mmio_base + BESCTL);
607 if(card->is_g400)
608 writel( card->regs.beslumactl, card->mmio_base + BESLUMACTL);
609 writel( card->regs.bespitch, card->mmio_base + BESPITCH);
611 writel( card->regs.besa1org, card->mmio_base + BESA1ORG);
612 writel( card->regs.besa1corg, card->mmio_base + BESA1CORG);
613 writel( card->regs.besa2org, card->mmio_base + BESA2ORG);
614 writel( card->regs.besa2corg, card->mmio_base + BESA2CORG);
615 writel( card->regs.besb1org, card->mmio_base + BESB1ORG);
616 writel( card->regs.besb1corg, card->mmio_base + BESB1CORG);
617 writel( card->regs.besb2org, card->mmio_base + BESB2ORG);
618 writel( card->regs.besb2corg, card->mmio_base + BESB2CORG);
619 if(card->is_g400)
621 writel( card->regs.besa1c3org, card->mmio_base + BESA1C3ORG);
622 writel( card->regs.besa2c3org, card->mmio_base + BESA2C3ORG);
623 writel( card->regs.besb1c3org, card->mmio_base + BESB1C3ORG);
624 writel( card->regs.besb2c3org, card->mmio_base + BESB2C3ORG);
627 writel( card->regs.beshcoord, card->mmio_base + BESHCOORD);
628 writel( card->regs.beshiscal, card->mmio_base + BESHISCAL);
629 writel( card->regs.beshsrcst, card->mmio_base + BESHSRCST);
630 writel( card->regs.beshsrcend, card->mmio_base + BESHSRCEND);
631 writel( card->regs.beshsrclst, card->mmio_base + BESHSRCLST);
633 writel( card->regs.besvcoord, card->mmio_base + BESVCOORD);
634 writel( card->regs.besviscal, card->mmio_base + BESVISCAL);
636 writel( card->regs.besv1srclst, card->mmio_base + BESV1SRCLST);
637 writel( card->regs.besv1wght, card->mmio_base + BESV1WGHT);
638 writel( card->regs.besv2srclst, card->mmio_base + BESV2SRCLST);
639 writel( card->regs.besv2wght, card->mmio_base + BESV2WGHT);
641 //update the registers somewhere between 1 and 2 frames from now.
642 writel( card->regs.besglobctl + ((readl(card->mmio_base + VCOUNT)+2)<<16),
643 card->mmio_base + BESGLOBCTL);
645 #if 0
646 printk(KERN_DEBUG "mga_vid: wrote BES registers\n");
647 printk(KERN_DEBUG "mga_vid: BESCTL = 0x%08x\n",
648 readl(card->mmio_base + BESCTL));
649 printk(KERN_DEBUG "mga_vid: BESGLOBCTL = 0x%08x\n",
650 readl(card->mmio_base + BESGLOBCTL));
651 printk(KERN_DEBUG "mga_vid: BESSTATUS= 0x%08x\n",
652 readl(card->mmio_base + BESSTATUS));
653 #endif
654 #ifdef CRTC2
655 // printk("c2ctl:0x%08x c2datactl:0x%08x\n", readl(card->mmio_base + C2CTL), readl(card->mmio_base + C2DATACTL));
656 // printk("c2misc:0x%08x\n", readl(card->mmio_base + C2MISC));
657 // printk("c2ctl:0x%08x c2datactl:0x%08x\n", card->cregs.c2ctl, card->cregs.c2datactl);
659 // writel(card->cregs.c2ctl, card->mmio_base + C2CTL);
661 writel(((readl(card->mmio_base + C2CTL) & ~0x03e00000) + (card->cregs.c2ctl & 0x03e00000)), card->mmio_base + C2CTL);
662 writel(((readl(card->mmio_base + C2DATACTL) & ~0x000000ff) + (card->cregs.c2datactl & 0x000000ff)), card->mmio_base + C2DATACTL);
663 // ctrc2
664 // disable CRTC2 acording to specs
665 // writel(card->cregs.c2ctl & 0xfffffff0, card->mmio_base + C2CTL);
666 // je to treba ???
667 // writeb((readb(card->mmio_base + XMISCCTRL) & 0x19) | 0xa2, card->mmio_base + XMISCCTRL); // MAFC - mfcsel & vdoutsel
668 // writeb((readb(card->mmio_base + XMISCCTRL) & 0x19) | 0x92, card->mmio_base + XMISCCTRL);
669 // writeb((readb(card->mmio_base + XMISCCTRL) & ~0xe9) + 0xa2, card->mmio_base + XMISCCTRL);
670 // writel(card->cregs.c2datactl, card->mmio_base + C2DATACTL);
671 // writel(card->cregs.c2hparam, card->mmio_base + C2HPARAM);
672 // writel(card->cregs.c2hsync, card->mmio_base + C2HSYNC);
673 // writel(card->cregs.c2vparam, card->mmio_base + C2VPARAM);
674 // writel(card->cregs.c2vsync, card->mmio_base + C2VSYNC);
675 writel(card->cregs.c2misc, card->mmio_base + C2MISC);
677 #ifdef MP_DEBUG
678 printk("c2offset = %d\n",card->cregs.c2offset);
679 #endif
681 writel(card->cregs.c2offset, card->mmio_base + C2OFFSET);
682 writel(card->cregs.c2startadd0, card->mmio_base + C2STARTADD0);
683 // writel(card->cregs.c2startadd1, card->mmio_base + C2STARTADD1);
684 writel(card->cregs.c2pl2startadd0, card->mmio_base + C2PL2STARTADD0);
685 // writel(card->cregs.c2pl2startadd1, card->mmio_base + C2PL2STARTADD1);
686 writel(card->cregs.c2pl3startadd0, card->mmio_base + C2PL3STARTADD0);
687 // writel(card->cregs.c2pl3startadd1, card->mmio_base + C2PL3STARTADD1);
688 writel(card->cregs.c2spicstartadd0, card->mmio_base + C2SPICSTARTADD0);
689 // writel(card->cregs.c2spicstartadd1, card->mmio_base + C2SPICSTARTADD1);
690 // writel(card->cregs.c2subpiclut, card->mmio_base + C2SUBPICLUT);
691 // writel(card->cregs.c2preload, card->mmio_base + C2PRELOAD);
692 // finaly enable everything
693 // writel(card->cregs.c2ctl, card->mmio_base + C2CTL);
694 // printk("c2ctl:0x%08x c2datactl:0x%08x\n",readl(card->mmio_base + C2CTL),readl(card->mmio_base + C2DATACTL));
695 // printk("c2misc:0x%08x\n", readl(card->mmio_base + C2MISC));
696 #endif
699 static int mga_vid_set_config(mga_card_t * card)
701 int x, y, sw, sh, dw, dh;
702 int besleft, bestop, ifactor, ofsleft, ofstop, baseadrofs, weight, weights;
703 mga_vid_config_t *config = &card->config;
704 int frame_size = card->config.frame_size;
706 #ifdef CRTC2
707 #define right_margin 0
708 #define left_margin 18
709 #define hsync_len 46
710 #define lower_margin 10
711 #define vsync_len 4
712 #define upper_margin 39
714 unsigned int hdispend = (config->src_width + 31) & ~31;
715 unsigned int hsyncstart = hdispend + (right_margin & ~7);
716 unsigned int hsyncend = hsyncstart + (hsync_len & ~7);
717 unsigned int htotal = hsyncend + (left_margin & ~7);
718 unsigned int vdispend = config->src_height;
719 unsigned int vsyncstart = vdispend + lower_margin;
720 unsigned int vsyncend = vsyncstart + vsync_len;
721 unsigned int vtotal = vsyncend + upper_margin;
722 #endif
723 x = config->x_org;
724 y = config->y_org;
725 sw = config->src_width;
726 sh = config->src_height;
727 dw = config->dest_width;
728 dh = config->dest_height;
730 #ifdef MP_DEBUG
731 printk(KERN_DEBUG "mga_vid: Setting up a %dx%d+%d+%d video window (src %dx%d) format %X\n",
732 dw, dh, x, y, sw, sh, config->format);
733 #endif
735 if(sw<4 || sh<4 || dw<4 || dh<4){
736 printk(KERN_ERR "mga_vid: Invalid src/dest dimenstions\n");
737 return -1;
740 //FIXME check that window is valid and inside desktop
742 //Setup the BES registers for a three plane 4:2:0 video source
744 card->regs.besglobctl = 0;
746 switch(config->format){
747 case MGA_VID_FORMAT_YV12:
748 case MGA_VID_FORMAT_I420:
749 case MGA_VID_FORMAT_IYUV:
750 card->regs.besctl = 1 // BES enabled
751 + (0<<6) // even start polarity
752 + (1<<10) // x filtering enabled
753 + (1<<11) // y filtering enabled
754 + (1<<16) // chroma upsampling
755 + (1<<17) // 4:2:0 mode
756 + (1<<18); // dither enabled
757 #if 0
758 if(card->is_g400)
760 //zoom disabled, zoom filter disabled, 420 3 plane format, proc amp
761 //disabled, rgb mode disabled
762 card->regs.besglobctl = (1<<5);
764 else
766 //zoom disabled, zoom filter disabled, Cb samples in 0246, Cr
767 //in 1357, BES register update on besvcnt
768 card->regs.besglobctl = 0;
770 #endif
771 break;
773 case MGA_VID_FORMAT_YUY2:
774 card->regs.besctl = 1 // BES enabled
775 + (0<<6) // even start polarity
776 + (1<<10) // x filtering enabled
777 + (1<<11) // y filtering enabled
778 + (1<<16) // chroma upsampling
779 + (0<<17) // 4:2:2 mode
780 + (1<<18); // dither enabled
782 card->regs.besglobctl = 0; // YUY2 format selected
783 break;
785 case MGA_VID_FORMAT_UYVY:
786 card->regs.besctl = 1 // BES enabled
787 + (0<<6) // even start polarity
788 + (1<<10) // x filtering enabled
789 + (1<<11) // y filtering enabled
790 + (1<<16) // chroma upsampling
791 + (0<<17) // 4:2:2 mode
792 + (1<<18); // dither enabled
794 card->regs.besglobctl = 1<<6; // UYVY format selected
795 break;
797 default:
798 printk(KERN_ERR "mga_vid: Unsupported pixel format: 0x%X\n",config->format);
799 return -1;
802 // setting black&white mode
803 card->regs.besctl|=(card->regs.blackie<<20);
805 //Enable contrast and brightness control
806 card->regs.besglobctl |= (1<<5) + (1<<7);
808 // brightness (-128..127) && contrast (0..255)
809 card->regs.beslumactl = (card->brightness << 16) | ((card->contrast+0x80)&0xFFFF);
811 //Setup destination window boundaries
812 besleft = x > 0 ? x : 0;
813 bestop = y > 0 ? y : 0;
814 card->regs.beshcoord = (besleft<<16) + (x + dw-1);
815 card->regs.besvcoord = (bestop<<16) + (y + dh-1);
817 //Setup source dimensions
818 card->regs.beshsrclst = (sw - 1) << 16;
819 card->regs.bespitch = (sw + 31) & ~31 ;
821 //Setup horizontal scaling
822 ifactor = ((sw-1)<<14)/(dw-1);
823 ofsleft = besleft - x;
825 card->regs.beshiscal = ifactor<<2;
826 card->regs.beshsrcst = (ofsleft*ifactor)<<2;
827 card->regs.beshsrcend = card->regs.beshsrcst + (((dw - ofsleft - 1) * ifactor) << 2);
829 //Setup vertical scaling
830 ifactor = ((sh-1)<<14)/(dh-1);
831 ofstop = bestop - y;
833 card->regs.besviscal = ifactor<<2;
835 baseadrofs = ( (ofstop * card->regs.besviscal) >>16) * card->regs.bespitch;
836 //frame_size = ((sw + 31) & ~31) * sh + (((sw + 31) & ~31) * sh) / 2;
837 card->regs.besa1org = (uint32_t) card->src_base + baseadrofs;
838 card->regs.besa2org = (uint32_t) card->src_base + baseadrofs + 1*frame_size;
839 card->regs.besb1org = (uint32_t) card->src_base + baseadrofs + 2*frame_size;
840 card->regs.besb2org = (uint32_t) card->src_base + baseadrofs + 3*frame_size;
842 if(config->format==MGA_VID_FORMAT_YV12
843 ||config->format==MGA_VID_FORMAT_IYUV
844 ||config->format==MGA_VID_FORMAT_I420
846 // planar YUV frames:
847 if (card->is_g400)
848 baseadrofs = ( ( (ofstop * card->regs.besviscal ) / 4 ) >> 16 ) * card->regs.bespitch;
849 else
850 baseadrofs = ( ( ( ofstop * card->regs.besviscal ) / 2 ) >> 16 ) * card->regs.bespitch;
852 if(config->format==MGA_VID_FORMAT_YV12 || !card->is_g400){
853 card->regs.besa1corg = (uint32_t) card->src_base + baseadrofs + card->regs.bespitch * sh ;
854 card->regs.besa2corg = (uint32_t) card->src_base + baseadrofs + 1*frame_size + card->regs.bespitch * sh;
855 card->regs.besb1corg = (uint32_t) card->src_base + baseadrofs + 2*frame_size + card->regs.bespitch * sh;
856 card->regs.besb2corg = (uint32_t) card->src_base + baseadrofs + 3*frame_size + card->regs.bespitch * sh;
857 card->regs.besa1c3org = card->regs.besa1corg + ( (card->regs.bespitch * sh) / 4);
858 card->regs.besa2c3org = card->regs.besa2corg + ( (card->regs.bespitch * sh) / 4);
859 card->regs.besb1c3org = card->regs.besb1corg + ( (card->regs.bespitch * sh) / 4);
860 card->regs.besb2c3org = card->regs.besb2corg + ( (card->regs.bespitch * sh) / 4);
861 } else {
862 card->regs.besa1c3org = (uint32_t) card->src_base + baseadrofs + card->regs.bespitch * sh ;
863 card->regs.besa2c3org = (uint32_t) card->src_base + baseadrofs + 1*frame_size + card->regs.bespitch * sh;
864 card->regs.besb1c3org = (uint32_t) card->src_base + baseadrofs + 2*frame_size + card->regs.bespitch * sh;
865 card->regs.besb2c3org = (uint32_t) card->src_base + baseadrofs + 3*frame_size + card->regs.bespitch * sh;
866 card->regs.besa1corg = card->regs.besa1c3org + ((card->regs.bespitch * sh) / 4);
867 card->regs.besa2corg = card->regs.besa2c3org + ((card->regs.bespitch * sh) / 4);
868 card->regs.besb1corg = card->regs.besb1c3org + ((card->regs.bespitch * sh) / 4);
869 card->regs.besb2corg = card->regs.besb2c3org + ((card->regs.bespitch * sh) / 4);
874 weight = ofstop * (card->regs.besviscal >> 2);
875 weights = weight < 0 ? 1 : 0;
876 card->regs.besv2wght = card->regs.besv1wght = (weights << 16) + ((weight & 0x3FFF) << 2);
877 card->regs.besv2srclst = card->regs.besv1srclst = sh - 1 - (((ofstop * card->regs.besviscal) >> 16) & 0x03FF);
879 #ifdef CRTC2
880 // pridat hlavni registry - tj. casovani ...
883 switch(config->format){
884 case MGA_VID_FORMAT_YV12:
885 case MGA_VID_FORMAT_I420:
886 case MGA_VID_FORMAT_IYUV:
887 card->cregs.c2ctl = 1 // CRTC2 enabled
888 + (1<<1) // external clock
889 + (0<<2) // external clock
890 + (1<<3) // pixel clock enable - not needed ???
891 + (0<<4) // high prioryty req
892 + (1<<5) // high prioryty req
893 + (0<<6) // high prioryty req
894 + (1<<8) // high prioryty req max
895 + (0<<9) // high prioryty req max
896 + (0<<10) // high prioryty req max
897 + (0<<20) // CRTC1 to DAC
898 + (1<<21) // 420 mode
899 + (1<<22) // 420 mode
900 + (1<<23) // 420 mode
901 + (0<<24) // single chroma line for 420 mode - need to be corrected
902 + (0<<25) /*/ interlace mode - need to be corrected*/
903 + (0<<26) // field legth polariry
904 + (0<<27) // field identification polariry
905 + (1<<28) // VIDRST detection mode
906 + (0<<29) // VIDRST detection mode
907 + (1<<30) // Horizontal counter preload
908 + (1<<31) // Vertical counter preload
910 card->cregs.c2datactl = 1 // disable dither - propably not needed, we are already in YUV mode
911 + (1<<1) // Y filter enable
912 + (1<<2) // CbCr filter enable
913 + (0<<3) // subpicture enable (disabled)
914 + (0<<4) // NTSC enable (disabled - PAL)
915 + (0<<5) // C2 static subpicture enable (disabled)
916 + (0<<6) // C2 subpicture offset division (disabled)
917 + (0<<7) // 422 subformat selection !
918 /* + (0<<8) // 15 bpp high alpha
919 + (0<<9) // 15 bpp high alpha
920 + (0<<10) // 15 bpp high alpha
921 + (0<<11) // 15 bpp high alpha
922 + (0<<12) // 15 bpp high alpha
923 + (0<<13) // 15 bpp high alpha
924 + (0<<14) // 15 bpp high alpha
925 + (0<<15) // 15 bpp high alpha
926 + (0<<16) // 15 bpp low alpha
927 + (0<<17) // 15 bpp low alpha
928 + (0<<18) // 15 bpp low alpha
929 + (0<<19) // 15 bpp low alpha
930 + (0<<20) // 15 bpp low alpha
931 + (0<<21) // 15 bpp low alpha
932 + (0<<22) // 15 bpp low alpha
933 + (0<<23) // 15 bpp low alpha
934 + (0<<24) // static subpicture key
935 + (0<<25) // static subpicture key
936 + (0<<26) // static subpicture key
937 + (0<<27) // static subpicture key
938 + (0<<28) // static subpicture key
939 */ ;
940 break;
942 case MGA_VID_FORMAT_YUY2:
943 card->cregs.c2ctl = 1 // CRTC2 enabled
944 + (1<<1) // external clock
945 + (0<<2) // external clock
946 + (1<<3) // pixel clock enable - not needed ???
947 + (0<<4) // high prioryty req - acc to spec
948 + (1<<5) // high prioryty req
949 + (0<<6) // high prioryty req
950 // 7 reserved
951 + (1<<8) // high prioryty req max
952 + (0<<9) // high prioryty req max
953 + (0<<10) // high prioryty req max
954 // 11-19 reserved
955 + (0<<20) // CRTC1 to DAC
956 + (1<<21) // 422 mode
957 + (0<<22) // 422 mode
958 + (1<<23) // 422 mode
959 + (0<<24) // single chroma line for 420 mode - need to be corrected
960 + (0<<25) /*/ interlace mode - need to be corrected*/
961 + (0<<26) // field legth polariry
962 + (0<<27) // field identification polariry
963 + (1<<28) // VIDRST detection mode
964 + (0<<29) // VIDRST detection mode
965 + (1<<30) // Horizontal counter preload
966 + (1<<31) // Vertical counter preload
968 card->cregs.c2datactl = 1 // disable dither - propably not needed, we are already in YUV mode
969 + (1<<1) // Y filter enable
970 + (1<<2) // CbCr filter enable
971 + (0<<3) // subpicture enable (disabled)
972 + (0<<4) // NTSC enable (disabled - PAL)
973 + (0<<5) // C2 static subpicture enable (disabled)
974 + (0<<6) // C2 subpicture offset division (disabled)
975 + (0<<7) // 422 subformat selection !
976 /* + (0<<8) // 15 bpp high alpha
977 + (0<<9) // 15 bpp high alpha
978 + (0<<10) // 15 bpp high alpha
979 + (0<<11) // 15 bpp high alpha
980 + (0<<12) // 15 bpp high alpha
981 + (0<<13) // 15 bpp high alpha
982 + (0<<14) // 15 bpp high alpha
983 + (0<<15) // 15 bpp high alpha
984 + (0<<16) // 15 bpp low alpha
985 + (0<<17) // 15 bpp low alpha
986 + (0<<18) // 15 bpp low alpha
987 + (0<<19) // 15 bpp low alpha
988 + (0<<20) // 15 bpp low alpha
989 + (0<<21) // 15 bpp low alpha
990 + (0<<22) // 15 bpp low alpha
991 + (0<<23) // 15 bpp low alpha
992 + (0<<24) // static subpicture key
993 + (0<<25) // static subpicture key
994 + (0<<26) // static subpicture key
995 + (0<<27) // static subpicture key
996 + (0<<28) // static subpicture key
997 */ ;
998 break;
1000 case MGA_VID_FORMAT_UYVY:
1001 card->cregs.c2ctl = 1 // CRTC2 enabled
1002 + (1<<1) // external clock
1003 + (0<<2) // external clock
1004 + (1<<3) // pixel clock enable - not needed ???
1005 + (0<<4) // high prioryty req
1006 + (1<<5) // high prioryty req
1007 + (0<<6) // high prioryty req
1008 + (1<<8) // high prioryty req max
1009 + (0<<9) // high prioryty req max
1010 + (0<<10) // high prioryty req max
1011 + (0<<20) // CRTC1 to DAC
1012 + (1<<21) // 422 mode
1013 + (0<<22) // 422 mode
1014 + (1<<23) // 422 mode
1015 + (1<<24) // single chroma line for 420 mode - need to be corrected
1016 + (1<<25) /*/ interlace mode - need to be corrected*/
1017 + (0<<26) // field legth polariry
1018 + (0<<27) // field identification polariry
1019 + (1<<28) // VIDRST detection mode
1020 + (0<<29) // VIDRST detection mode
1021 + (1<<30) // Horizontal counter preload
1022 + (1<<31) // Vertical counter preload
1024 card->cregs.c2datactl = 0 // enable dither - propably not needed, we are already in YUV mode
1025 + (1<<1) // Y filter enable
1026 + (1<<2) // CbCr filter enable
1027 + (0<<3) // subpicture enable (disabled)
1028 + (0<<4) // NTSC enable (disabled - PAL)
1029 + (0<<5) // C2 static subpicture enable (disabled)
1030 + (0<<6) // C2 subpicture offset division (disabled)
1031 + (1<<7) // 422 subformat selection !
1032 /* + (0<<8) // 15 bpp high alpha
1033 + (0<<9) // 15 bpp high alpha
1034 + (0<<10) // 15 bpp high alpha
1035 + (0<<11) // 15 bpp high alpha
1036 + (0<<12) // 15 bpp high alpha
1037 + (0<<13) // 15 bpp high alpha
1038 + (0<<14) // 15 bpp high alpha
1039 + (0<<15) // 15 bpp high alpha
1040 + (0<<16) // 15 bpp low alpha
1041 + (0<<17) // 15 bpp low alpha
1042 + (0<<18) // 15 bpp low alpha
1043 + (0<<19) // 15 bpp low alpha
1044 + (0<<20) // 15 bpp low alpha
1045 + (0<<21) // 15 bpp low alpha
1046 + (0<<22) // 15 bpp low alpha
1047 + (0<<23) // 15 bpp low alpha
1048 + (0<<24) // static subpicture key
1049 + (0<<25) // static subpicture key
1050 + (0<<26) // static subpicture key
1051 + (0<<27) // static subpicture key
1052 + (0<<28) // static subpicture key
1053 */ ;
1054 break;
1056 default:
1057 printk(KERN_ERR "mga_vid: Unsupported pixel format: 0x%X\n",config->format);
1058 return -1;
1061 card->cregs.c2hparam = ( (hdispend - 8) << 16) | (htotal - 8);
1062 card->cregs.c2hsync = ( (hsyncend - 8) << 16) | (hsyncstart - 8);
1064 card->cregs.c2misc=0 // CRTCV2 656 togg f0
1065 +(0<<1) // CRTCV2 656 togg f0
1066 +(0<<2) // CRTCV2 656 togg f0
1067 +(0<<4) // CRTCV2 656 togg f1
1068 +(0<<5) // CRTCV2 656 togg f1
1069 +(0<<6) // CRTCV2 656 togg f1
1070 +(0<<8) // Hsync active high
1071 +(0<<9) // Vsync active high
1072 // 16-27 c2vlinecomp - nevim co tam dat
1074 card->cregs.c2offset=(card->regs.bespitch << 1);
1076 card->cregs.c2pl2startadd0=card->regs.besa1corg;
1077 // card->cregs.c2pl2startadd1=card->regs.besa2corg;
1078 card->cregs.c2pl3startadd0=card->regs.besa1c3org;
1079 // card->cregs.c2pl3startadd1=card->regs.besa2c3org;
1081 card->cregs.c2preload=(vsyncstart << 16) | (hsyncstart); // from
1083 card->cregs.c2spicstartadd0=0; // not used
1084 // card->cregs.c2spicstartadd1=0; // not used
1086 card->cregs.c2startadd0=card->regs.besa1org;
1087 // card->cregs.c2startadd1=card->regs.besa2org;
1089 card->cregs.c2subpiclut=0; //not used
1091 card->cregs.c2vparam = ( (vdispend - 1) << 16) | (vtotal - 1);
1092 card->cregs.c2vsync = ( (vsyncend - 1) << 16) | (vsyncstart - 1);
1095 #endif
1097 mga_vid_write_regs(card, 0);
1098 return 0;
1101 #ifdef MGA_ALLOW_IRQ
1103 static void enable_irq(mga_card_t * card){
1104 long int cc;
1106 cc = readl(card->mmio_base + IEN);
1107 // printk(KERN_ALERT "*** !!! IRQREG = %d\n", (int)(cc&0xff));
1109 writeb(0x11, card->mmio_base + CRTCX);
1111 writeb(0x20, card->mmio_base + CRTCD); /* clear 0, enable off */
1112 writeb(0x00, card->mmio_base + CRTCD); /* enable on */
1113 writeb(0x10, card->mmio_base + CRTCD); /* clear = 1 */
1115 writel(card->regs.besglobctl , card->mmio_base + BESGLOBCTL);
1119 static void disable_irq(mga_card_t * card){
1121 writeb(0x11, card->mmio_base + CRTCX);
1122 writeb(0x20, card->mmio_base + CRTCD); /* clear 0, enable off */
1126 static void mga_handle_irq(int irq, void *dev_id, struct pt_regs *pregs) {
1127 // static int frame=0;
1128 // static int counter=0;
1129 long int cc;
1130 mga_card_t * card = dev_id;
1132 // printk(KERN_DEBUG "vcount = %d\n",readl(mga_mmio_base + VCOUNT));
1134 //printk("mga_interrupt #%d\n", irq);
1136 // check whether the interrupt is really for us (irq sharing)
1137 if ( irq != -1 ) {
1138 cc = readl(card->mmio_base + STATUS);
1139 if ( ! (cc & 0x10) ) return; /* vsyncpen */
1140 // debug_irqcnt++;
1143 // if ( debug_irqignore ) {
1144 // debug_irqignore = 0;
1146 // frame=(frame+1)&1;
1147 card->regs.besctl = (card->regs.besctl & ~0x07000000) + (card->next_frame << 25);
1148 writel( card->regs.besctl, card->mmio_base + BESCTL );
1150 #ifdef CRTC2
1151 // sem pridat vyber obrazku !!!!
1152 // i han echt kei ahnig was das obe heisse söll
1153 crtc2_frame_sel(card->next_frame);
1154 #endif
1156 #if 0
1157 ++counter;
1158 if(!(counter&63)){
1159 printk("mga irq counter = %d\n",counter);
1161 #endif
1163 // } else {
1164 // debug_irqignore = 1;
1165 // }
1167 if ( irq != -1 ) {
1168 writeb( 0x11, card->mmio_base + CRTCX);
1169 writeb( 0, card->mmio_base + CRTCD );
1170 writeb( 0x10, card->mmio_base + CRTCD );
1173 // writel( card->regs.besglobctl, card->mmio_base + BESGLOBCTL);
1176 return;
1180 #endif
1182 static int mga_vid_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1184 int frame, result;
1185 uint32_t tmp;
1186 mga_card_t * card = (mga_card_t *) file->private_data;
1188 switch(cmd)
1190 case MGA_VID_CONFIG:
1191 //FIXME remove
1192 // printk(KERN_DEBUG "mga_vid: vcount = %d\n",readl(card->mmio_base + VCOUNT));
1193 #ifdef MP_DEBUG
1194 printk(KERN_DEBUG "mga_vid: mmio_base = %p\n",card->mmio_base);
1195 printk(KERN_DEBUG "mga_vid: mem_base = %08x\n",card->mem_base);
1196 //FIXME remove
1198 printk(KERN_DEBUG "mga_vid: Received configuration\n");
1199 #endif
1201 if(copy_from_user(&card->config,(mga_vid_config_t*) arg,sizeof(mga_vid_config_t)))
1203 printk(KERN_ERR "mga_vid: failed copy from userspace\n");
1204 return(-EFAULT);
1206 if(card->config.version != MGA_VID_VERSION){
1207 printk(KERN_ERR "mga_vid: incompatible version! driver: %X requested: %X\n",MGA_VID_VERSION,card->config.version);
1208 return(-EFAULT);
1211 if(card->config.frame_size==0 || card->config.frame_size>1024*768*2){
1212 printk(KERN_ERR "mga_vid: illegal frame_size: %d\n",card->config.frame_size);
1213 return(-EFAULT);
1216 if(card->config.num_frames<1 || card->config.num_frames>4){
1217 printk(KERN_ERR "mga_vid: illegal num_frames: %d\n",card->config.num_frames);
1218 return(-EFAULT);
1221 card->src_base = (card->ram_size * 0x100000 - card->config.num_frames * card->config.frame_size - card->top_reserved);
1222 if(card->src_base<0){
1223 printk(KERN_ERR "mga_vid: not enough memory for frames!\n");
1224 return(-EFAULT);
1226 card->src_base &= (~0xFFFF); // 64k boundary
1227 #ifdef MP_DEBUG
1228 printk(KERN_DEBUG "mga YUV buffer base: 0x%X\n", card->src_base);
1229 #endif
1231 if (card->is_g400)
1232 card->config.card_type = MGA_G400;
1233 else
1234 card->config.card_type = MGA_G200;
1236 card->config.ram_size = card->ram_size;
1238 if (copy_to_user((mga_vid_config_t *) arg, &card->config, sizeof(mga_vid_config_t)))
1240 printk(KERN_ERR "mga_vid: failed copy to userspace\n");
1241 return(-EFAULT);
1244 result = mga_vid_set_config(card);
1245 if(!result) card->configured=1;
1246 return result;
1247 break;
1249 case MGA_VID_ON:
1250 #ifdef MP_DEBUG
1251 printk(KERN_DEBUG "mga_vid: Video ON\n");
1252 #endif
1253 card->vid_src_ready = 1;
1254 if(card->vid_overlay_on)
1256 card->regs.besctl |= 1;
1257 mga_vid_write_regs(card, 0);
1259 #ifdef MGA_ALLOW_IRQ
1260 if ( card->irq != -1 ) enable_irq(card);
1261 #endif
1262 card->next_frame=0;
1263 break;
1265 case MGA_VID_OFF:
1266 #ifdef MP_DEBUG
1267 printk(KERN_DEBUG "mga_vid: Video OFF (ioctl)\n");
1268 #endif
1269 card->vid_src_ready = 0;
1270 #ifdef MGA_ALLOW_IRQ
1271 if ( card->irq != -1 ) disable_irq(card);
1272 #endif
1273 card->regs.besctl &= ~1;
1274 card->regs.besglobctl &= ~(1<<6); // UYVY format selected
1275 mga_vid_write_regs(card, 0);
1276 break;
1278 case MGA_VID_FSEL:
1279 if(copy_from_user(&frame,(int *) arg,sizeof(int)))
1281 printk(KERN_ERR "mga_vid: FSEL failed copy from userspace\n");
1282 return(-EFAULT);
1285 mga_vid_frame_sel(card, frame);
1286 break;
1288 case MGA_VID_GET_LUMA:
1289 //tmp = card->regs.beslumactl;
1290 //tmp = (tmp&0xFFFF0000) | (((tmp&0xFFFF) - 0x80)&0xFFFF);
1291 tmp = (card->brightness << 16) | (card->contrast&0xFFFF);
1293 if (copy_to_user((uint32_t *) arg, &tmp, sizeof(uint32_t)))
1295 printk(KERN_ERR "mga_vid: failed copy %p to userspace %p\n",
1296 &tmp, (uint32_t *) arg);
1297 return(-EFAULT);
1299 break;
1301 case MGA_VID_SET_LUMA:
1302 tmp = arg;
1303 card->brightness=tmp>>16; card->contrast=tmp&0xFFFF;
1304 //card->regs.beslumactl = (tmp&0xFFFF0000) | ((tmp + 0x80)&0xFFFF);
1305 card->regs.beslumactl = (card->brightness << 16) | ((card->contrast+0x80)&0xFFFF);
1306 mga_vid_write_regs(card, 0);
1307 break;
1309 default:
1310 printk(KERN_ERR "mga_vid: Invalid ioctl\n");
1311 return (-EINVAL);
1314 return 0;
1317 static void cards_init(mga_card_t * card, struct pci_dev * dev, int card_number, int is_g400);
1319 // returns the number of found cards
1320 static int mga_vid_find_card(void)
1322 struct pci_dev *dev = NULL;
1323 char *mga_dev_name;
1324 mga_card_t * card;
1326 while((dev = pci_find_device(PCI_VENDOR_ID_MATROX, PCI_ANY_ID, dev)))
1328 mga_dev_name = "";
1329 mga_cards_num++;
1330 if(mga_cards_num == MGA_MAX_CARDS)
1332 printk(KERN_WARNING "mga_vid: Trying to initialize more than %d cards\n",MGA_MAX_CARDS);
1333 mga_cards_num--;
1334 break;
1337 card = kmalloc(sizeof(mga_card_t), GFP_KERNEL);
1338 if(!card)
1340 printk(KERN_ERR "mga_vid: memory allocation failed\n");
1341 mga_cards_num--;
1342 break;
1345 mga_cards[mga_cards_num - 1] = card;
1347 switch(dev->device) {
1348 case PCI_DEVICE_ID_MATROX_G550:
1349 mga_dev_name = "MGA G550";
1350 printk(KERN_INFO "mga_vid: Found %s at %s [%s]\n", mga_dev_name, dev->slot_name, dev->name);
1351 cards_init(card, dev, mga_cards_num - 1, 1);
1352 break;
1353 case PCI_DEVICE_ID_MATROX_G400:
1354 mga_dev_name = "MGA G400/G450";
1355 printk(KERN_INFO "mga_vid: Found %s at %s [%s]\n", mga_dev_name, dev->slot_name, dev->name);
1356 cards_init(card, dev, mga_cards_num - 1, 1);
1357 break;
1358 case PCI_DEVICE_ID_MATROX_G200_AGP:
1359 mga_dev_name = "MGA G200 AGP";
1360 printk(KERN_INFO "mga_vid: Found %s at %s [%s]\n", mga_dev_name, dev->slot_name, dev->name);
1361 cards_init(card, dev, mga_cards_num - 1, 0);
1362 break;
1363 case PCI_DEVICE_ID_MATROX_G200_PCI:
1364 mga_dev_name = "MGA G200";
1365 printk(KERN_INFO "mga_vid: Found %s at %s [%s]\n", mga_dev_name, dev->slot_name, dev->name);
1366 cards_init(card, dev, mga_cards_num - 1, 0);
1367 break;
1368 default:
1369 mga_cards_num--;
1370 printk(KERN_INFO "mga_vid: ignoring matrox device (%d) at %s [%s]\n", dev->device, dev->slot_name, dev->name);
1371 break;
1375 if(!mga_cards_num)
1377 printk(KERN_ERR "mga_vid: No supported cards found\n");
1378 } else {
1379 printk(KERN_INFO "mga_vid: %d supported cards found\n", mga_cards_num);
1382 return mga_cards_num;
1385 static void mga_param_buff_fill( mga_card_t * card )
1387 unsigned len;
1388 unsigned size = card->param_buff_size;
1389 char * buf = card->param_buff;
1390 len = 0;
1391 len += snprintf(&buf[len],size-len,"Interface version: %04X\n",MGA_VID_VERSION);
1392 len += snprintf(&buf[len],size-len,"Memory: %x:%dM\n",card->mem_base,(unsigned int) card->ram_size);
1393 len += snprintf(&buf[len],size-len,"MMIO: %p\n",card->mmio_base);
1394 len += snprintf(&buf[len],size-len,"Configurable stuff:\n");
1395 len += snprintf(&buf[len],size-len,"~~~~~~~~~~~~~~~~~~~\n");
1396 len += snprintf(&buf[len],size-len,PARAM_BRIGHTNESS"%d\n",card->brightness);
1397 len += snprintf(&buf[len],size-len,PARAM_CONTRAST"%d\n",card->contrast);
1398 len += snprintf(&buf[len],size-len,PARAM_BLACKIE"%s\n",card->regs.blackie?"on":"off");
1399 card->param_buff_len = len;
1400 // check boundaries of mga_param_buff before writing to it!!!
1404 static ssize_t mga_vid_read(struct file *file, char *buf, size_t count, loff_t *ppos)
1406 uint32_t size;
1407 mga_card_t * card = (mga_card_t *) file->private_data;
1409 if(!card->param_buff) return -ESPIPE;
1410 if(!(*ppos)) mga_param_buff_fill(card);
1411 if(*ppos >= card->param_buff_len) return 0;
1412 size = min(count,card->param_buff_len-(uint32_t)(*ppos));
1413 memcpy(buf,card->param_buff,size);
1414 *ppos += size;
1415 return size;
1418 static ssize_t mga_vid_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
1420 mga_card_t * card = (mga_card_t *) file->private_data;
1422 if(memcmp(buf,PARAM_BRIGHTNESS,min(count,strlen(PARAM_BRIGHTNESS))) == 0)
1424 short brightness;
1425 brightness=simple_strtol(&buf[strlen(PARAM_BRIGHTNESS)],NULL,10);
1426 if (brightness>127 || brightness<-128) { brightness=0;}
1427 // printk(KERN_DEBUG "mga_vid: brightness modified ( %d ) \n",brightness);
1428 card->brightness=brightness;
1429 } else
1430 if(memcmp(buf,PARAM_CONTRAST,min(count,strlen(PARAM_CONTRAST))) == 0)
1432 short contrast;
1433 contrast=simple_strtol(&buf[strlen(PARAM_CONTRAST)],NULL,10);
1434 if (contrast>127 || contrast<-128) { contrast=0;}
1435 // printk(KERN_DEBUG "mga_vid: contrast modified ( %d ) \n",contrast);
1436 card->contrast=contrast;
1437 } else
1439 if(memcmp(buf,PARAM_BLACKIE,min(count,strlen(PARAM_BLACKIE))) == 0)
1441 short blackie;
1442 blackie=simple_strtol(&buf[strlen(PARAM_BLACKIE)],NULL,10);
1443 // printk(KERN_DEBUG "mga_vid: shadow mode: ( %d ) \n",blackie);
1444 card->regs.blackie=(blackie>0)?1:0;
1445 } else count = -EIO;
1446 // TODO: reset settings
1447 return count;
1450 static int mga_vid_mmap(struct file *file, struct vm_area_struct *vma)
1452 mga_card_t * card = (mga_card_t *) file->private_data;
1454 #ifdef MP_DEBUG
1455 printk(KERN_DEBUG "mga_vid: mapping video memory into userspace\n");
1456 #endif
1458 if(!card->configured)
1460 printk(KERN_ERR "mga_vid: card is not configured, cannot mmap\n");
1461 return(-EAGAIN);
1464 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,3)
1465 if(remap_page_range(vma, vma->vm_start, card->mem_base + card->src_base,
1466 vma->vm_end - vma->vm_start, vma->vm_page_prot))
1467 #else
1468 if(remap_page_range(vma->vm_start, card->mem_base + card->src_base,
1469 vma->vm_end - vma->vm_start, vma->vm_page_prot))
1470 #endif
1472 printk(KERN_ERR "mga_vid: error mapping video memory\n");
1473 return(-EAGAIN);
1476 return(0);
1479 static int mga_vid_release(struct inode *inode, struct file *file)
1481 mga_card_t * card;
1483 //Close the window just in case
1484 #ifdef MP_DEBUG
1485 printk(KERN_DEBUG "mga_vid: Video OFF (release)\n");
1486 #endif
1488 card = (mga_card_t *) file->private_data;
1490 card->vid_src_ready = 0;
1491 card->regs.besctl &= ~1;
1492 card->regs.besglobctl &= ~(1<<6); // UYVY format selected
1493 // card->config.colkey_on=0; //!!!
1494 mga_vid_write_regs(card, 1);
1495 card->vid_in_use = 0;
1497 MOD_DEC_USE_COUNT;
1498 return 0;
1501 static long long mga_vid_lseek(struct file *file, long long offset, int origin)
1503 return -ESPIPE;
1506 static int mga_vid_open(struct inode *inode, struct file *file)
1508 mga_card_t * card;
1510 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,2)
1511 int minor = MINOR(inode->i_rdev.value);
1512 #else
1513 int minor = MINOR(inode->i_rdev);
1514 #endif
1516 if(!file->private_data)
1518 // we are not using devfs, use the minor
1519 // number to specify the card we are using
1521 // we don't have that many cards
1522 if(minor >= mga_cards_num)
1523 return(-ENXIO);
1525 file->private_data = mga_cards[minor];
1526 #ifdef MP_DEBUG
1527 printk(KERN_DEBUG "mga_vid: Not using devfs\n");
1528 #endif
1530 #ifdef MP_DEBUG
1531 else {
1532 printk(KERN_DEBUG "mga_vid: Using devfs\n");
1534 #endif
1536 card = (mga_card_t *) file->private_data;
1538 if(card->vid_in_use == 1)
1539 return(-EBUSY);
1541 card->vid_in_use = 1;
1542 MOD_INC_USE_COUNT;
1543 return(0);
1546 #if LINUX_VERSION_CODE >= 0x020400
1547 static struct file_operations mga_vid_fops =
1549 llseek: mga_vid_lseek,
1550 read: mga_vid_read,
1551 write: mga_vid_write,
1552 ioctl: mga_vid_ioctl,
1553 mmap: mga_vid_mmap,
1554 open: mga_vid_open,
1555 release: mga_vid_release
1557 #else
1558 static struct file_operations mga_vid_fops =
1560 mga_vid_lseek,
1561 mga_vid_read,
1562 mga_vid_write,
1563 NULL,
1564 NULL,
1565 mga_vid_ioctl,
1566 mga_vid_mmap,
1567 mga_vid_open,
1568 NULL,
1569 mga_vid_release
1571 #endif
1573 static void cards_init(mga_card_t * card, struct pci_dev * dev, int card_number, int is_g400)
1575 unsigned int card_option;
1576 // temp buffer for device filename creation used only by devfs
1577 #ifdef CONFIG_DEVFS_FS
1578 char buffer[16];
1579 #endif
1581 memset(card,0,sizeof(mga_card_t));
1582 card->irq = -1;
1584 card->pci_dev = dev;
1585 card->irq = dev->irq;
1586 card->is_g400 = is_g400;
1588 card->param_buff = kmalloc(PARAM_BUFF_SIZE,GFP_KERNEL);
1589 if(card->param_buff) card->param_buff_size = PARAM_BUFF_SIZE;
1591 card->brightness = mga_brightness[card_number];
1592 card->contrast = mga_contrast[card_number];
1593 card->top_reserved = mga_top_reserved[card_number];
1595 #if LINUX_VERSION_CODE >= 0x020300
1596 card->mmio_base = ioremap_nocache(dev->resource[1].start,0x4000);
1597 card->mem_base = dev->resource[0].start;
1598 #else
1599 card->mmio_base = ioremap_nocache(dev->base_address[1] & PCI_BASE_ADDRESS_MEM_MASK,0x4000);
1600 card->mem_base = dev->base_address[0] & PCI_BASE_ADDRESS_MEM_MASK;
1601 #endif
1602 printk(KERN_INFO "mga_vid: MMIO at 0x%p IRQ: %d framebuffer: 0x%08X\n", card->mmio_base, card->irq, card->mem_base);
1604 pci_read_config_dword(dev, 0x40, &card_option);
1605 printk(KERN_INFO "mga_vid: OPTION word: 0x%08X mem: 0x%02X %s\n", card_option,
1606 (card_option>>10)&0x17, ((card_option>>14)&1)?"SGRAM":"SDRAM");
1608 if (mga_ram_size[card_number]) {
1609 printk(KERN_INFO "mga_vid: RAMSIZE forced to %d MB\n", mga_ram_size[card_number]);
1610 card->ram_size=mga_ram_size[card_number];
1611 } else {
1613 #ifdef MGA_MEMORY_SIZE
1614 card->ram_size = MGA_MEMORY_SIZE;
1615 printk(KERN_INFO "mga_vid: hard-coded RAMSIZE is %d MB\n", (unsigned int) card->ram_size);
1617 #else
1619 if (card->is_g400){
1620 switch((card_option>>10)&0x17){
1621 // SDRAM:
1622 case 0x00:
1623 case 0x04: card->ram_size = 16; break;
1624 case 0x03:
1625 case 0x05: card->ram_size = 32; break;
1626 // SGRAM:
1627 case 0x10:
1628 case 0x14: card->ram_size = 32; break;
1629 case 0x11:
1630 case 0x12: card->ram_size = 16; break;
1631 default:
1632 card->ram_size = 16;
1633 printk(KERN_INFO "mga_vid: Couldn't detect RAMSIZE, assuming 16MB!");
1635 /* Check for buggy 16MB cards reporting 32 MB */
1636 if(card->ram_size != 16 &&
1637 (dev->subsystem_device == PCI_SUBSYSTEM_ID_MATROX_G400_16MB_SDRAM ||
1638 dev->subsystem_device == PCI_SUBSYSTEM_ID_MATROX_G400_16MB_SGRAM ||
1639 dev->subsystem_device == PCI_SUBSYSTEM_ID_MATROX_G400_DH_16MB))
1641 printk(KERN_INFO "mga_vid: Detected 16MB card reporting %d MB RAMSIZE, overriding\n", card->ram_size);
1642 card->ram_size = 16;
1644 }else{
1645 switch((card_option>>10)&0x17){
1646 // case 0x10:
1647 // case 0x13: card->ram_size = 8; break;
1648 default: card->ram_size = 8;
1651 #if 0
1652 // printk("List resources -----------\n");
1653 for(temp=0;temp<DEVICE_COUNT_RESOURCE;temp++){
1654 struct resource *res=&dev->resource[temp];
1655 if(res->flags){
1656 int size=(1+res->end-res->start)>>20;
1657 printk(KERN_DEBUG "res %d: start: 0x%X end: 0x%X (%d MB) flags=0x%X\n",temp,res->start,res->end,size,res->flags);
1658 if(res->flags&(IORESOURCE_MEM|IORESOURCE_PREFETCH)){
1659 if(size>card->ram_size && size<=64) card->ram_size=size;
1663 #endif
1664 printk(KERN_INFO "mga_vid: detected RAMSIZE is %d MB\n", (unsigned int) card->ram_size);
1665 #endif
1669 #ifdef MGA_ALLOW_IRQ
1670 if ( card->irq != -1 ) {
1671 int tmp = request_irq(card->irq, mga_handle_irq, SA_INTERRUPT | SA_SHIRQ, "Syncfb Time Base", card);
1672 if ( tmp ) {
1673 printk(KERN_INFO "syncfb (mga): cannot register irq %d (Err: %d)\n", card->irq, tmp);
1674 card->irq=-1;
1675 } else {
1676 printk(KERN_DEBUG "syncfb (mga): registered irq %d\n", card->irq);
1678 } else {
1679 printk(KERN_INFO "syncfb (mga): No valid irq was found\n");
1680 card->irq=-1;
1682 #else
1683 printk(KERN_INFO "syncfb (mga): IRQ disabled in mga_vid.c\n");
1684 card->irq=-1;
1685 #endif
1687 // register devfs, let the kernel give us major and minor numbers
1688 #ifdef CONFIG_DEVFS_FS
1689 snprintf(buffer, 16, "mga_vid%d", card_number);
1690 card->dev_handle = devfs_register(NULL, buffer, DEVFS_FL_AUTO_DEVNUM,
1691 0, 0,
1692 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IFCHR,
1693 &mga_vid_fops, card);
1694 #endif
1699 * Main Initialization Function
1702 static int mga_vid_initialize(void)
1704 int i;
1706 // printk(KERN_INFO "Matrox MGA G200/G400 YUV Video interface v0.01 (c) Aaron Holtzman \n");
1707 printk(KERN_INFO "Matrox MGA G200/G400/G450/G550 YUV Video interface v2.01 (c) Aaron Holtzman & A'rpi\n");
1709 for(i = 0; i < MGA_MAX_CARDS; i++)
1711 if (mga_ram_size[i]) {
1712 if (mga_ram_size[i]<4 || mga_ram_size[i]>64) {
1713 printk(KERN_ERR "mga_vid: invalid RAMSIZE: %d MB\n", mga_ram_size[i]);
1714 return -EINVAL;
1719 if(register_chrdev(major, "mga_vid", &mga_vid_fops))
1721 printk(KERN_ERR "mga_vid: unable to get major: %d\n", major);
1722 return -EIO;
1725 if (!mga_vid_find_card())
1727 printk(KERN_ERR "mga_vid: no supported devices found\n");
1728 unregister_chrdev(major, "mga_vid");
1729 return -EINVAL;
1731 #ifdef CONFIG_DEVFS_FS
1732 else {
1733 // we assume that this always succeedes
1734 dev_handle = devfs_register(NULL, "mga_vid", DEVFS_FL_AUTO_DEVNUM,
1735 0,0,
1736 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IFCHR,
1737 &mga_vid_fops, mga_cards[0]);
1739 #endif
1741 return(0);
1744 int init_module(void)
1746 return mga_vid_initialize();
1749 void cleanup_module(void)
1751 int i;
1752 mga_card_t * card;
1754 for (i = 0; i < MGA_MAX_CARDS; i++)
1756 card = mga_cards[i];
1757 if(card)
1759 #ifdef MGA_ALLOW_IRQ
1760 if (card->irq != -1)
1761 free_irq(card->irq, &(card->irq));
1762 #endif
1764 if(card->mmio_base)
1765 iounmap(card->mmio_base);
1766 if(card->param_buff)
1767 kfree(card->param_buff);
1768 #ifdef CONFIG_DEVFS_FS
1769 if(card->dev_handle) devfs_unregister(card->dev_handle);
1770 #endif
1772 kfree(card);
1773 mga_cards[i]=NULL;
1777 //FIXME turn off BES
1778 printk(KERN_INFO "mga_vid: Cleaning up module\n");
1779 #ifdef CONFIG_DEVFS_FS
1780 if(dev_handle) devfs_unregister(dev_handle);
1781 #endif
1782 unregister_chrdev(major, "mga_vid");