Mercurial > mplayer.hg
annotate drivers/mga_vid.c @ 2226:9582af160d04
skin chaning bug fix.
author | pontscho |
---|---|
date | Tue, 16 Oct 2001 21:23:59 +0000 |
parents | ae67940c9d12 |
children | 8cae22120633 |
rev | line source |
---|---|
1 | 1 // YUY2 support (see config.format) added by A'rpi/ESP-team |
57 | 2 // double buffering added by A'rpi/ESP-team |
3 | |
4 // Set this value, if autodetection fails! (video ram size in megabytes) | |
91 | 5 // #define MGA_MEMORY_SIZE 16 |
1 | 6 |
68 | 7 //#define MGA_ALLOW_IRQ |
8 | |
9 #define MGA_VSYNC_POS 2 | |
10 | |
1 | 11 /* |
12 * | |
13 * mga_vid.c | |
14 * | |
15 * Copyright (C) 1999 Aaron Holtzman | |
16 * | |
17 * Module skeleton based on gutted agpgart module by Jeff Hartmann | |
18 * <slicer@ionet.net> | |
19 * | |
20 * Matrox MGA G200/G400 YUV Video Interface module Version 0.1.0 | |
21 * | |
22 * BES == Back End Scaler | |
23 * | |
24 * This software has been released under the terms of the GNU Public | |
25 * license. See http://www.gnu.org/copyleft/gpl.html for details. | |
26 */ | |
27 | |
28 //It's entirely possible this major conflicts with something else | |
29 /* mknod /dev/mga_vid c 178 0 */ | |
30 | |
31 #include <linux/config.h> | |
32 #include <linux/version.h> | |
33 #include <linux/module.h> | |
34 #include <linux/types.h> | |
35 #include <linux/kernel.h> | |
36 #include <linux/sched.h> | |
37 #include <linux/mm.h> | |
38 #include <linux/string.h> | |
39 #include <linux/errno.h> | |
40 #include <linux/malloc.h> | |
41 #include <linux/pci.h> | |
63 | 42 #include <linux/ioport.h> |
1 | 43 #include <linux/init.h> |
44 | |
45 #include "mga_vid.h" | |
46 | |
47 #ifdef CONFIG_MTRR | |
48 #include <asm/mtrr.h> | |
49 #endif | |
50 | |
51 #include <asm/uaccess.h> | |
52 #include <asm/system.h> | |
53 #include <asm/io.h> | |
54 | |
55 #define TRUE 1 | |
56 #define FALSE 0 | |
57 | |
58 #define MGA_VID_MAJOR 178 | |
59 | |
57 | 60 //#define MGA_VIDMEM_SIZE mga_ram_size |
1 | 61 |
62 #ifndef PCI_DEVICE_ID_MATROX_G200_PCI | |
63 #define PCI_DEVICE_ID_MATROX_G200_PCI 0x0520 | |
64 #endif | |
65 | |
66 #ifndef PCI_DEVICE_ID_MATROX_G200_AGP | |
67 #define PCI_DEVICE_ID_MATROX_G200_AGP 0x0521 | |
68 #endif | |
69 | |
70 #ifndef PCI_DEVICE_ID_MATROX_G400 | |
71 #define PCI_DEVICE_ID_MATROX_G400 0x0525 | |
72 #endif | |
73 | |
1989 | 74 #ifndef PCI_DEVICE_ID_MATROX_G550 |
75 #define PCI_DEVICE_ID_MATROX_G550 0x2527 | |
76 #endif | |
77 | |
1 | 78 MODULE_AUTHOR("Aaron Holtzman <aholtzma@engr.uvic.ca>"); |
79 | |
80 | |
81 typedef struct bes_registers_s | |
82 { | |
83 //BES Control | |
84 uint32_t besctl; | |
85 //BES Global control | |
86 uint32_t besglobctl; | |
87 //Luma control (brightness and contrast) | |
88 uint32_t beslumactl; | |
89 //Line pitch | |
90 uint32_t bespitch; | |
91 | |
92 //Buffer A-1 Chroma 3 plane org | |
93 uint32_t besa1c3org; | |
94 //Buffer A-1 Chroma org | |
95 uint32_t besa1corg; | |
96 //Buffer A-1 Luma org | |
97 uint32_t besa1org; | |
98 | |
99 //Buffer A-2 Chroma 3 plane org | |
100 uint32_t besa2c3org; | |
101 //Buffer A-2 Chroma org | |
102 uint32_t besa2corg; | |
103 //Buffer A-2 Luma org | |
104 uint32_t besa2org; | |
105 | |
106 //Buffer B-1 Chroma 3 plane org | |
107 uint32_t besb1c3org; | |
108 //Buffer B-1 Chroma org | |
109 uint32_t besb1corg; | |
110 //Buffer B-1 Luma org | |
111 uint32_t besb1org; | |
112 | |
113 //Buffer B-2 Chroma 3 plane org | |
114 uint32_t besb2c3org; | |
115 //Buffer B-2 Chroma org | |
116 uint32_t besb2corg; | |
117 //Buffer B-2 Luma org | |
118 uint32_t besb2org; | |
119 | |
120 //BES Horizontal coord | |
121 uint32_t beshcoord; | |
122 //BES Horizontal inverse scaling [5.14] | |
123 uint32_t beshiscal; | |
124 //BES Horizontal source start [10.14] (for scaling) | |
125 uint32_t beshsrcst; | |
126 //BES Horizontal source ending [10.14] (for scaling) | |
127 uint32_t beshsrcend; | |
128 //BES Horizontal source last | |
129 uint32_t beshsrclst; | |
130 | |
131 | |
132 //BES Vertical coord | |
133 uint32_t besvcoord; | |
134 //BES Vertical inverse scaling [5.14] | |
135 uint32_t besviscal; | |
136 //BES Field 1 vertical source last position | |
137 uint32_t besv1srclst; | |
138 //BES Field 1 weight start | |
139 uint32_t besv1wght; | |
140 //BES Field 2 vertical source last position | |
141 uint32_t besv2srclst; | |
142 //BES Field 2 weight start | |
143 uint32_t besv2wght; | |
144 | |
145 } bes_registers_t; | |
146 | |
147 static bes_registers_t regs; | |
148 static uint32_t mga_vid_in_use = 0; | |
149 static uint32_t is_g400 = 0; | |
150 static uint32_t vid_src_ready = 0; | |
151 static uint32_t vid_overlay_on = 0; | |
152 | |
153 static uint8_t *mga_mmio_base = 0; | |
154 static uint32_t mga_mem_base = 0; | |
155 | |
57 | 156 static int mga_src_base = 0; // YUV buffer position in video memory |
157 | |
158 static uint32_t mga_ram_size = 0; // how much megabytes videoram we have | |
1 | 159 |
95 | 160 //static int mga_force_memsize = 0; |
90 | 161 |
95 | 162 MODULE_PARM(mga_ram_size, "i"); |
90 | 163 |
1 | 164 static struct pci_dev *pci_dev; |
165 | |
166 static mga_vid_config_t mga_config; | |
167 | |
2086 | 168 static int colkey_saved=0; |
169 static int colkey_on=0; | |
170 static unsigned char colkey_color[4]; | |
171 static unsigned char colkey_mask[4]; | |
172 | |
48 | 173 static int mga_irq = -1; |
1 | 174 |
175 //All register offsets are converted to word aligned offsets (32 bit) | |
176 //because we want all our register accesses to be 32 bits | |
177 #define VCOUNT 0x1e20 | |
178 | |
179 #define PALWTADD 0x3c00 // Index register for X_DATAREG port | |
180 #define X_DATAREG 0x3c0a | |
181 | |
182 #define XMULCTRL 0x19 | |
183 #define BPP_8 0x00 | |
184 #define BPP_15 0x01 | |
185 #define BPP_16 0x02 | |
186 #define BPP_24 0x03 | |
187 #define BPP_32_DIR 0x04 | |
188 #define BPP_32_PAL 0x07 | |
189 | |
190 #define XCOLMSK 0x40 | |
191 #define X_COLKEY 0x42 | |
192 #define XKEYOPMODE 0x51 | |
193 #define XCOLMSK0RED 0x52 | |
194 #define XCOLMSK0GREEN 0x53 | |
195 #define XCOLMSK0BLUE 0x54 | |
196 #define XCOLKEY0RED 0x55 | |
197 #define XCOLKEY0GREEN 0x56 | |
198 #define XCOLKEY0BLUE 0x57 | |
199 | |
200 // Backend Scaler registers | |
201 #define BESCTL 0x3d20 | |
202 #define BESGLOBCTL 0x3dc0 | |
203 #define BESLUMACTL 0x3d40 | |
204 #define BESPITCH 0x3d24 | |
48 | 205 |
1 | 206 #define BESA1C3ORG 0x3d60 |
207 #define BESA1CORG 0x3d10 | |
208 #define BESA1ORG 0x3d00 | |
48 | 209 |
1 | 210 #define BESA2C3ORG 0x3d64 |
211 #define BESA2CORG 0x3d14 | |
212 #define BESA2ORG 0x3d04 | |
48 | 213 |
1 | 214 #define BESB1C3ORG 0x3d68 |
215 #define BESB1CORG 0x3d18 | |
216 #define BESB1ORG 0x3d08 | |
48 | 217 |
1 | 218 #define BESB2C3ORG 0x3d6C |
219 #define BESB2CORG 0x3d1C | |
220 #define BESB2ORG 0x3d0C | |
48 | 221 |
1 | 222 #define BESHCOORD 0x3d28 |
223 #define BESHISCAL 0x3d30 | |
224 #define BESHSRCEND 0x3d3C | |
225 #define BESHSRCLST 0x3d50 | |
226 #define BESHSRCST 0x3d38 | |
227 #define BESV1WGHT 0x3d48 | |
228 #define BESV2WGHT 0x3d4c | |
229 #define BESV1SRCLST 0x3d54 | |
230 #define BESV2SRCLST 0x3d58 | |
231 #define BESVISCAL 0x3d34 | |
232 #define BESVCOORD 0x3d2c | |
233 #define BESSTATUS 0x3dc4 | |
234 | |
48 | 235 #define CRTCX 0x1fd4 |
236 #define CRTCD 0x1fd5 | |
237 #define IEN 0x1e1c | |
238 #define ICLEAR 0x1e18 | |
239 #define STATUS 0x1e14 | |
240 | |
241 static int mga_next_frame=0; | |
1 | 242 |
243 static void mga_vid_frame_sel(int frame) | |
244 { | |
48 | 245 if ( mga_irq != -1 ) { |
246 mga_next_frame=frame; | |
247 } else { | |
248 | |
1 | 249 //we don't need the vcount protection as we're only hitting |
250 //one register (and it doesn't seem to be double buffered) | |
251 regs.besctl = (regs.besctl & ~0x07000000) + (frame << 25); | |
252 writel( regs.besctl, mga_mmio_base + BESCTL ); | |
68 | 253 |
254 // writel( regs.besglobctl + ((readl(mga_mmio_base + VCOUNT)+2)<<16), | |
255 writel( regs.besglobctl + (MGA_VSYNC_POS<<16), | |
256 mga_mmio_base + BESGLOBCTL); | |
257 | |
48 | 258 } |
1 | 259 } |
260 | |
261 | |
2086 | 262 static void mga_vid_write_regs(int restore) |
1 | 263 { |
264 //Make sure internal registers don't get updated until we're done | |
265 writel( (readl(mga_mmio_base + VCOUNT)-1)<<16, | |
266 mga_mmio_base + BESGLOBCTL); | |
267 | |
268 // color or coordinate keying | |
2086 | 269 |
270 if(restore && colkey_saved){ | |
271 // restore it | |
272 colkey_saved=0; | |
273 | |
274 printk("mga_vid: Restoring colorkey (ON: %d %02X:%02X:%02X)\n", | |
275 colkey_on,colkey_color[0],colkey_color[1],colkey_color[2]); | |
276 | |
277 // Set color key registers: | |
278 writeb( XKEYOPMODE, mga_mmio_base + PALWTADD); | |
279 writeb( colkey_on, mga_mmio_base + X_DATAREG); | |
280 | |
281 writeb( XCOLKEY0RED, mga_mmio_base + PALWTADD); | |
282 writeb( colkey_color[0], mga_mmio_base + X_DATAREG); | |
283 writeb( XCOLKEY0GREEN, mga_mmio_base + PALWTADD); | |
284 writeb( colkey_color[1], mga_mmio_base + X_DATAREG); | |
285 writeb( XCOLKEY0BLUE, mga_mmio_base + PALWTADD); | |
286 writeb( colkey_color[2], mga_mmio_base + X_DATAREG); | |
287 writeb( X_COLKEY, mga_mmio_base + PALWTADD); | |
288 writeb( colkey_color[3], mga_mmio_base + X_DATAREG); | |
289 | |
290 writeb( XCOLMSK0RED, mga_mmio_base + PALWTADD); | |
291 writeb( colkey_mask[0], mga_mmio_base + X_DATAREG); | |
292 writeb( XCOLMSK0GREEN, mga_mmio_base + PALWTADD); | |
293 writeb( colkey_mask[1], mga_mmio_base + X_DATAREG); | |
294 writeb( XCOLMSK0BLUE, mga_mmio_base + PALWTADD); | |
295 writeb( colkey_mask[2], mga_mmio_base + X_DATAREG); | |
296 writeb( XCOLMSK, mga_mmio_base + PALWTADD); | |
297 writeb( colkey_mask[3], mga_mmio_base + X_DATAREG); | |
298 | |
299 } else if(!colkey_saved){ | |
300 // save it | |
301 colkey_saved=1; | |
302 // Get color key registers: | |
303 writeb( XKEYOPMODE, mga_mmio_base + PALWTADD); | |
304 colkey_on=(unsigned char)readb(mga_mmio_base + X_DATAREG) & 1; | |
305 | |
306 writeb( XCOLKEY0RED, mga_mmio_base + PALWTADD); | |
307 colkey_color[0]=(unsigned char)readb(mga_mmio_base + X_DATAREG); | |
308 writeb( XCOLKEY0GREEN, mga_mmio_base + PALWTADD); | |
309 colkey_color[1]=(unsigned char)readb(mga_mmio_base + X_DATAREG); | |
310 writeb( XCOLKEY0BLUE, mga_mmio_base + PALWTADD); | |
311 colkey_color[2]=(unsigned char)readb(mga_mmio_base + X_DATAREG); | |
312 writeb( X_COLKEY, mga_mmio_base + PALWTADD); | |
313 colkey_color[3]=(unsigned char)readb(mga_mmio_base + X_DATAREG); | |
314 | |
315 writeb( XCOLMSK0RED, mga_mmio_base + PALWTADD); | |
316 colkey_mask[0]=(unsigned char)readb(mga_mmio_base + X_DATAREG); | |
317 writeb( XCOLMSK0GREEN, mga_mmio_base + PALWTADD); | |
318 colkey_mask[1]=(unsigned char)readb(mga_mmio_base + X_DATAREG); | |
319 writeb( XCOLMSK0BLUE, mga_mmio_base + PALWTADD); | |
320 colkey_mask[2]=(unsigned char)readb(mga_mmio_base + X_DATAREG); | |
321 writeb( XCOLMSK, mga_mmio_base + PALWTADD); | |
322 colkey_mask[3]=(unsigned char)readb(mga_mmio_base + X_DATAREG); | |
323 | |
324 printk("mga_vid: Saved colorkey (ON: %d %02X:%02X:%02X)\n", | |
325 colkey_on,colkey_color[0],colkey_color[1],colkey_color[2]); | |
326 | |
327 } | |
328 | |
329 if(!restore){ | |
1 | 330 writeb( XKEYOPMODE, mga_mmio_base + PALWTADD); |
331 writeb( mga_config.colkey_on, mga_mmio_base + X_DATAREG); | |
332 if ( mga_config.colkey_on ) | |
333 { | |
334 uint32_t r=0, g=0, b=0; | |
335 | |
336 writeb( XMULCTRL, mga_mmio_base + PALWTADD); | |
337 switch (readb (mga_mmio_base + X_DATAREG)) | |
338 { | |
339 case BPP_8: | |
340 /* Need to look up the color index, just using | |
341 color 0 for now. */ | |
342 break; | |
343 | |
344 case BPP_15: | |
345 r = mga_config.colkey_red >> 3; | |
346 g = mga_config.colkey_green >> 3; | |
347 b = mga_config.colkey_blue >> 3; | |
348 break; | |
349 | |
350 case BPP_16: | |
351 r = mga_config.colkey_red >> 3; | |
352 g = mga_config.colkey_green >> 2; | |
353 b = mga_config.colkey_blue >> 3; | |
354 break; | |
355 | |
356 case BPP_24: | |
357 case BPP_32_DIR: | |
358 case BPP_32_PAL: | |
359 r = mga_config.colkey_red; | |
360 g = mga_config.colkey_green; | |
361 b = mga_config.colkey_blue; | |
362 break; | |
363 } | |
364 | |
365 // Disable color keying on alpha channel | |
366 writeb( XCOLMSK, mga_mmio_base + PALWTADD); | |
367 writeb( 0x00, mga_mmio_base + X_DATAREG); | |
368 writeb( X_COLKEY, mga_mmio_base + PALWTADD); | |
369 writeb( 0x00, mga_mmio_base + X_DATAREG); | |
370 | |
2086 | 371 |
1 | 372 // Set up color key registers |
373 writeb( XCOLKEY0RED, mga_mmio_base + PALWTADD); | |
374 writeb( r, mga_mmio_base + X_DATAREG); | |
375 writeb( XCOLKEY0GREEN, mga_mmio_base + PALWTADD); | |
376 writeb( g, mga_mmio_base + X_DATAREG); | |
377 writeb( XCOLKEY0BLUE, mga_mmio_base + PALWTADD); | |
378 writeb( b, mga_mmio_base + X_DATAREG); | |
379 | |
380 // Set up color key mask registers | |
381 writeb( XCOLMSK0RED, mga_mmio_base + PALWTADD); | |
382 writeb( 0xff, mga_mmio_base + X_DATAREG); | |
383 writeb( XCOLMSK0GREEN, mga_mmio_base + PALWTADD); | |
384 writeb( 0xff, mga_mmio_base + X_DATAREG); | |
385 writeb( XCOLMSK0BLUE, mga_mmio_base + PALWTADD); | |
386 writeb( 0xff, mga_mmio_base + X_DATAREG); | |
387 } | |
388 | |
2086 | 389 } |
390 | |
1 | 391 // Backend Scaler |
392 writel( regs.besctl, mga_mmio_base + BESCTL); | |
393 if(is_g400) | |
394 writel( regs.beslumactl, mga_mmio_base + BESLUMACTL); | |
395 writel( regs.bespitch, mga_mmio_base + BESPITCH); | |
396 | |
397 writel( regs.besa1org, mga_mmio_base + BESA1ORG); | |
398 writel( regs.besa1corg, mga_mmio_base + BESA1CORG); | |
48 | 399 writel( regs.besa2org, mga_mmio_base + BESA2ORG); |
400 writel( regs.besa2corg, mga_mmio_base + BESA2CORG); | |
1 | 401 writel( regs.besb1org, mga_mmio_base + BESB1ORG); |
402 writel( regs.besb1corg, mga_mmio_base + BESB1CORG); | |
48 | 403 writel( regs.besb2org, mga_mmio_base + BESB2ORG); |
404 writel( regs.besb2corg, mga_mmio_base + BESB2CORG); | |
1 | 405 if(is_g400) |
406 { | |
407 writel( regs.besa1c3org, mga_mmio_base + BESA1C3ORG); | |
48 | 408 writel( regs.besa2c3org, mga_mmio_base + BESA2C3ORG); |
1 | 409 writel( regs.besb1c3org, mga_mmio_base + BESB1C3ORG); |
48 | 410 writel( regs.besb2c3org, mga_mmio_base + BESB2C3ORG); |
1 | 411 } |
412 | |
413 writel( regs.beshcoord, mga_mmio_base + BESHCOORD); | |
414 writel( regs.beshiscal, mga_mmio_base + BESHISCAL); | |
415 writel( regs.beshsrcst, mga_mmio_base + BESHSRCST); | |
416 writel( regs.beshsrcend, mga_mmio_base + BESHSRCEND); | |
417 writel( regs.beshsrclst, mga_mmio_base + BESHSRCLST); | |
418 | |
419 writel( regs.besvcoord, mga_mmio_base + BESVCOORD); | |
420 writel( regs.besviscal, mga_mmio_base + BESVISCAL); | |
48 | 421 |
1 | 422 writel( regs.besv1srclst, mga_mmio_base + BESV1SRCLST); |
423 writel( regs.besv1wght, mga_mmio_base + BESV1WGHT); | |
48 | 424 writel( regs.besv2srclst, mga_mmio_base + BESV2SRCLST); |
425 writel( regs.besv2wght, mga_mmio_base + BESV2WGHT); | |
1 | 426 |
427 //update the registers somewhere between 1 and 2 frames from now. | |
428 writel( regs.besglobctl + ((readl(mga_mmio_base + VCOUNT)+2)<<16), | |
429 mga_mmio_base + BESGLOBCTL); | |
430 | |
77 | 431 #if 0 |
61 | 432 printk(KERN_DEBUG "mga_vid: wrote BES registers\n"); |
433 printk(KERN_DEBUG "mga_vid: BESCTL = 0x%08x\n", | |
1 | 434 readl(mga_mmio_base + BESCTL)); |
61 | 435 printk(KERN_DEBUG "mga_vid: BESGLOBCTL = 0x%08x\n", |
1 | 436 readl(mga_mmio_base + BESGLOBCTL)); |
61 | 437 printk(KERN_DEBUG "mga_vid: BESSTATUS= 0x%08x\n", |
1 | 438 readl(mga_mmio_base + BESSTATUS)); |
77 | 439 #endif |
1 | 440 } |
441 | |
442 static int mga_vid_set_config(mga_vid_config_t *config) | |
443 { | |
444 int x, y, sw, sh, dw, dh; | |
445 int besleft, bestop, ifactor, ofsleft, ofstop, baseadrofs, weight, weights; | |
57 | 446 int frame_size=config->frame_size; |
1 | 447 x = config->x_org; |
448 y = config->y_org; | |
449 sw = config->src_width; | |
450 sh = config->src_height; | |
451 dw = config->dest_width; | |
452 dh = config->dest_height; | |
453 | |
61 | 454 printk(KERN_DEBUG "mga_vid: Setting up a %dx%d+%d+%d video window (src %dx%d) format %X\n", |
1 | 455 dw, dh, x, y, sw, sh, config->format); |
456 | |
457 //FIXME check that window is valid and inside desktop | |
458 | |
459 //FIXME figure out a better way to allocate memory on card | |
460 //allocate 2 megs | |
461 //mga_src_base = mga_mem_base + (MGA_VIDMEM_SIZE-2) * 0x100000; | |
57 | 462 //mga_src_base = (MGA_VIDMEM_SIZE-3) * 0x100000; |
1 | 463 |
464 | |
465 //Setup the BES registers for a three plane 4:2:0 video source | |
466 | |
466 | 467 regs.besglobctl = 0; |
468 | |
1 | 469 switch(config->format){ |
470 case MGA_VID_FORMAT_YV12: | |
470 | 471 case MGA_VID_FORMAT_I420: |
472 case MGA_VID_FORMAT_IYUV: | |
1 | 473 regs.besctl = 1 // BES enabled |
474 + (0<<6) // even start polarity | |
475 + (1<<10) // x filtering enabled | |
476 + (1<<11) // y filtering enabled | |
477 + (1<<16) // chroma upsampling | |
478 + (1<<17) // 4:2:0 mode | |
479 + (1<<18); // dither enabled | |
466 | 480 #if 0 |
1 | 481 if(is_g400) |
482 { | |
483 //zoom disabled, zoom filter disabled, 420 3 plane format, proc amp | |
484 //disabled, rgb mode disabled | |
485 regs.besglobctl = (1<<5); | |
486 } | |
487 else | |
488 { | |
489 //zoom disabled, zoom filter disabled, Cb samples in 0246, Cr | |
490 //in 1357, BES register update on besvcnt | |
466 | 491 regs.besglobctl = 0; |
1 | 492 } |
466 | 493 #endif |
1 | 494 break; |
495 | |
496 case MGA_VID_FORMAT_YUY2: | |
497 regs.besctl = 1 // BES enabled | |
498 + (0<<6) // even start polarity | |
499 + (1<<10) // x filtering enabled | |
500 + (1<<11) // y filtering enabled | |
501 + (1<<16) // chroma upsampling | |
502 + (0<<17) // 4:2:2 mode | |
503 + (1<<18); // dither enabled | |
504 | |
505 regs.besglobctl = 0; // YUY2 format selected | |
506 break; | |
466 | 507 |
508 case MGA_VID_FORMAT_UYVY: | |
509 regs.besctl = 1 // BES enabled | |
510 + (0<<6) // even start polarity | |
511 + (1<<10) // x filtering enabled | |
512 + (1<<11) // y filtering enabled | |
513 + (1<<16) // chroma upsampling | |
514 + (0<<17) // 4:2:2 mode | |
515 + (1<<18); // dither enabled | |
516 | |
517 regs.besglobctl = 1<<6; // UYVY format selected | |
518 break; | |
519 | |
1 | 520 default: |
61 | 521 printk(KERN_ERR "mga_vid: Unsupported pixel format: 0x%X\n",config->format); |
1 | 522 return -1; |
523 } | |
524 | |
525 | |
526 //Disable contrast and brightness control | |
466 | 527 regs.besglobctl |= (1<<5) + (1<<7); |
1 | 528 regs.beslumactl = (0x7f << 16) + (0x80<<0); |
529 regs.beslumactl = 0x80<<0; | |
530 | |
531 //Setup destination window boundaries | |
532 besleft = x > 0 ? x : 0; | |
533 bestop = y > 0 ? y : 0; | |
534 regs.beshcoord = (besleft<<16) + (x + dw-1); | |
535 regs.besvcoord = (bestop<<16) + (y + dh-1); | |
536 | |
537 //Setup source dimensions | |
538 regs.beshsrclst = (sw - 1) << 16; | |
539 regs.bespitch = (sw + 31) & ~31 ; | |
540 | |
541 //Setup horizontal scaling | |
542 ifactor = ((sw-1)<<14)/(dw-1); | |
543 ofsleft = besleft - x; | |
544 | |
545 regs.beshiscal = ifactor<<2; | |
546 regs.beshsrcst = (ofsleft*ifactor)<<2; | |
547 regs.beshsrcend = regs.beshsrcst + (((dw - ofsleft - 1) * ifactor) << 2); | |
548 | |
549 //Setup vertical scaling | |
550 ifactor = ((sh-1)<<14)/(dh-1); | |
551 ofstop = bestop - y; | |
552 | |
553 regs.besviscal = ifactor<<2; | |
554 | |
555 baseadrofs = ((ofstop*regs.besviscal)>>16)*regs.bespitch; | |
57 | 556 //frame_size = ((sw + 31) & ~31) * sh + (((sw + 31) & ~31) * sh) / 2; |
1 | 557 regs.besa1org = (uint32_t) mga_src_base + baseadrofs; |
48 | 558 regs.besa2org = (uint32_t) mga_src_base + baseadrofs + 1*frame_size; |
559 regs.besb1org = (uint32_t) mga_src_base + baseadrofs + 2*frame_size; | |
560 regs.besb2org = (uint32_t) mga_src_base + baseadrofs + 3*frame_size; | |
1 | 561 |
470 | 562 if(config->format==MGA_VID_FORMAT_YV12 |
563 ||config->format==MGA_VID_FORMAT_IYUV | |
564 ||config->format==MGA_VID_FORMAT_I420 | |
565 ){ | |
57 | 566 // planar YUV frames: |
1 | 567 if (is_g400) |
568 baseadrofs = (((ofstop*regs.besviscal)/4)>>16)*regs.bespitch; | |
569 else | |
570 baseadrofs = (((ofstop*regs.besviscal)/2)>>16)*regs.bespitch; | |
571 | |
470 | 572 if(config->format==MGA_VID_FORMAT_YV12){ |
1 | 573 regs.besa1corg = (uint32_t) mga_src_base + baseadrofs + regs.bespitch * sh ; |
48 | 574 regs.besa2corg = (uint32_t) mga_src_base + baseadrofs + 1*frame_size + regs.bespitch * sh; |
575 regs.besb1corg = (uint32_t) mga_src_base + baseadrofs + 2*frame_size + regs.bespitch * sh; | |
576 regs.besb2corg = (uint32_t) mga_src_base + baseadrofs + 3*frame_size + regs.bespitch * sh; | |
1 | 577 regs.besa1c3org = regs.besa1corg + ((regs.bespitch * sh) / 4); |
48 | 578 regs.besa2c3org = regs.besa2corg + ((regs.bespitch * sh) / 4); |
1 | 579 regs.besb1c3org = regs.besb1corg + ((regs.bespitch * sh) / 4); |
48 | 580 regs.besb2c3org = regs.besb2corg + ((regs.bespitch * sh) / 4); |
470 | 581 } else { |
582 regs.besa1c3org = (uint32_t) mga_src_base + baseadrofs + regs.bespitch * sh ; | |
583 regs.besa2c3org = (uint32_t) mga_src_base + baseadrofs + 1*frame_size + regs.bespitch * sh; | |
584 regs.besb1c3org = (uint32_t) mga_src_base + baseadrofs + 2*frame_size + regs.bespitch * sh; | |
585 regs.besb2c3org = (uint32_t) mga_src_base + baseadrofs + 3*frame_size + regs.bespitch * sh; | |
586 regs.besa1corg = regs.besa1c3org + ((regs.bespitch * sh) / 4); | |
587 regs.besa2corg = regs.besa2c3org + ((regs.bespitch * sh) / 4); | |
588 regs.besb1corg = regs.besb1c3org + ((regs.bespitch * sh) / 4); | |
589 regs.besb2corg = regs.besb2c3org + ((regs.bespitch * sh) / 4); | |
590 } | |
591 | |
57 | 592 } |
1 | 593 |
594 weight = ofstop * (regs.besviscal >> 2); | |
595 weights = weight < 0 ? 1 : 0; | |
48 | 596 regs.besv2wght = regs.besv1wght = (weights << 16) + ((weight & 0x3FFF) << 2); |
597 regs.besv2srclst = regs.besv1srclst = sh - 1 - (((ofstop * regs.besviscal) >> 16) & 0x03FF); | |
1 | 598 |
2086 | 599 mga_vid_write_regs(0); |
1 | 600 return 0; |
601 } | |
602 | |
68 | 603 #ifdef MGA_ALLOW_IRQ |
604 | |
48 | 605 static void enable_irq(){ |
606 long int cc; | |
607 | |
608 cc = readl(mga_mmio_base + IEN); | |
63 | 609 // printk(KERN_ALERT "*** !!! IRQREG = %d\n", (int)(cc&0xff)); |
48 | 610 |
611 writeb( 0x11, mga_mmio_base + CRTCX); | |
612 | |
613 writeb(0x20, mga_mmio_base + CRTCD ); /* clear 0, enable off */ | |
614 writeb(0x00, mga_mmio_base + CRTCD ); /* enable on */ | |
615 writeb(0x10, mga_mmio_base + CRTCD ); /* clear = 1 */ | |
616 | |
617 writel( regs.besglobctl , mga_mmio_base + BESGLOBCTL); | |
618 | |
619 } | |
620 | |
621 static void disable_irq(){ | |
622 | |
623 writeb( 0x11, mga_mmio_base + CRTCX); | |
624 writeb(0x20, mga_mmio_base + CRTCD ); /* clear 0, enable off */ | |
625 | |
626 } | |
627 | |
628 void mga_handle_irq(int irq, void *dev_id, struct pt_regs *pregs) { | |
629 // static int frame=0; | |
854
76ca00724e12
gcc warnings fixed - patch by Aelius aelius@wish.net
arpi_esp
parents:
662
diff
changeset
|
630 // static int counter=0; |
48 | 631 long int cc; |
632 // if ( ! mga_enabled_flag ) return; | |
633 | |
68 | 634 // printk(KERN_DEBUG "vcount = %d\n",readl(mga_mmio_base + VCOUNT)); |
635 | |
48 | 636 //printk("mga_interrupt #%d\n", irq); |
637 | |
638 if ( irq != -1 ) { | |
639 | |
640 cc = readl(mga_mmio_base + STATUS); | |
641 if ( ! (cc & 0x10) ) return; /* vsyncpen */ | |
642 // debug_irqcnt++; | |
643 } | |
644 | |
645 // if ( debug_irqignore ) { | |
646 // debug_irqignore = 0; | |
647 | |
648 | |
649 /* | |
650 if ( mga_conf_deinterlace ) { | |
651 if ( mga_first_field ) { | |
652 // printk("mga_interrupt first field\n"); | |
653 if ( syncfb_interrupt() ) | |
654 mga_first_field = 0; | |
655 } else { | |
656 // printk("mga_interrupt second field\n"); | |
657 mga_select_buffer( mga_current_field | 2 ); | |
658 mga_first_field = 1; | |
659 } | |
660 } else { | |
661 syncfb_interrupt(); | |
662 } | |
663 */ | |
664 | |
665 // frame=(frame+1)&1; | |
666 regs.besctl = (regs.besctl & ~0x07000000) + (mga_next_frame << 25); | |
667 writel( regs.besctl, mga_mmio_base + BESCTL ); | |
668 | |
669 #if 0 | |
670 ++counter; | |
671 if(!(counter&63)){ | |
672 printk("mga irq counter = %d\n",counter); | |
673 } | |
674 #endif | |
675 | |
676 // } else { | |
677 // debug_irqignore = 1; | |
678 // } | |
679 | |
680 if ( irq != -1 ) { | |
681 writeb( 0x11, mga_mmio_base + CRTCX); | |
682 writeb( 0, mga_mmio_base + CRTCD ); | |
683 writeb( 0x10, mga_mmio_base + CRTCD ); | |
684 } | |
685 | |
686 // writel( regs.besglobctl, mga_mmio_base + BESGLOBCTL); | |
687 | |
688 | |
689 return; | |
690 | |
691 } | |
692 | |
68 | 693 #endif |
1 | 694 |
695 static int mga_vid_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) | |
696 { | |
697 int frame; | |
698 | |
699 switch(cmd) | |
700 { | |
701 case MGA_VID_CONFIG: | |
702 //FIXME remove | |
68 | 703 // printk(KERN_DEBUG "vcount = %d\n",readl(mga_mmio_base + VCOUNT)); |
61 | 704 printk(KERN_DEBUG "mga_mmio_base = %p\n",mga_mmio_base); |
854
76ca00724e12
gcc warnings fixed - patch by Aelius aelius@wish.net
arpi_esp
parents:
662
diff
changeset
|
705 printk(KERN_DEBUG "mga_mem_base = %08x\n",mga_mem_base); |
1 | 706 //FIXME remove |
707 | |
61 | 708 printk(KERN_DEBUG "mga_vid: Received configuration\n"); |
1 | 709 |
710 if(copy_from_user(&mga_config,(mga_vid_config_t*) arg,sizeof(mga_vid_config_t))) | |
711 { | |
61 | 712 printk(KERN_ERR "mga_vid: failed copy from userspace\n"); |
1 | 713 return(-EFAULT); |
714 } | |
57 | 715 if(mga_config.version != MGA_VID_VERSION){ |
61 | 716 printk(KERN_ERR "mga_vid: incompatible version! driver: %X requested: %X\n",MGA_VID_VERSION,mga_config.version); |
57 | 717 return(-EFAULT); |
718 } | |
719 | |
720 if(mga_config.frame_size==0 || mga_config.frame_size>1024*768*2){ | |
61 | 721 printk(KERN_ERR "mga_vid: illegal frame_size: %d\n",mga_config.frame_size); |
57 | 722 return(-EFAULT); |
723 } | |
724 | |
725 if(mga_config.num_frames<1 || mga_config.num_frames>4){ | |
61 | 726 printk(KERN_ERR "mga_vid: illegal num_frames: %d\n",mga_config.num_frames); |
57 | 727 return(-EFAULT); |
728 } | |
729 | |
730 mga_src_base = (mga_ram_size*0x100000-mga_config.num_frames*mga_config.frame_size); | |
731 if(mga_src_base<0){ | |
61 | 732 printk(KERN_ERR "mga_vid: not enough memory for frames!\n"); |
57 | 733 return(-EFAULT); |
734 } | |
735 mga_src_base &= (~0xFFFF); // 64k boundary | |
61 | 736 printk(KERN_DEBUG "mga YUV buffer base: 0x%X\n", mga_src_base); |
57 | 737 |
1 | 738 if (is_g400) |
739 mga_config.card_type = MGA_G400; | |
740 else | |
741 mga_config.card_type = MGA_G200; | |
742 | |
743 mga_config.ram_size = mga_ram_size; | |
744 | |
745 if (copy_to_user((mga_vid_config_t *) arg, &mga_config, sizeof(mga_vid_config_t))) | |
746 { | |
61 | 747 printk(KERN_ERR "mga_vid: failed copy to userspace\n"); |
1 | 748 return(-EFAULT); |
749 } | |
750 return mga_vid_set_config(&mga_config); | |
751 break; | |
752 | |
753 case MGA_VID_ON: | |
61 | 754 printk(KERN_DEBUG "mga_vid: Video ON\n"); |
1 | 755 vid_src_ready = 1; |
756 if(vid_overlay_on) | |
757 { | |
758 regs.besctl |= 1; | |
2086 | 759 mga_vid_write_regs(0); |
1 | 760 } |
68 | 761 #ifdef MGA_ALLOW_IRQ |
48 | 762 if ( mga_irq != -1 ) enable_irq(); |
68 | 763 #endif |
48 | 764 mga_next_frame=0; |
1 | 765 break; |
766 | |
767 case MGA_VID_OFF: | |
94
fbd99740af99
printk() message for video off when releasing mga without ioctl()
lgb
parents:
93
diff
changeset
|
768 printk(KERN_DEBUG "mga_vid: Video OFF (ioctl)\n"); |
1 | 769 vid_src_ready = 0; |
68 | 770 #ifdef MGA_ALLOW_IRQ |
48 | 771 if ( mga_irq != -1 ) disable_irq(); |
68 | 772 #endif |
1 | 773 regs.besctl &= ~1; |
466 | 774 regs.besglobctl &= ~(1<<6); // UYVY format selected |
2086 | 775 mga_vid_write_regs(0); |
1 | 776 break; |
777 | |
778 case MGA_VID_FSEL: | |
779 if(copy_from_user(&frame,(int *) arg,sizeof(int))) | |
780 { | |
61 | 781 printk(KERN_ERR "mga_vid: FSEL failed copy from userspace\n"); |
1 | 782 return(-EFAULT); |
783 } | |
784 | |
785 mga_vid_frame_sel(frame); | |
786 break; | |
787 | |
788 default: | |
61 | 789 printk(KERN_ERR "mga_vid: Invalid ioctl\n"); |
1 | 790 return (-EINVAL); |
791 } | |
792 | |
793 return 0; | |
794 } | |
795 | |
796 | |
797 static int mga_vid_find_card(void) | |
798 { | |
799 struct pci_dev *dev = NULL; | |
854
76ca00724e12
gcc warnings fixed - patch by Aelius aelius@wish.net
arpi_esp
parents:
662
diff
changeset
|
800 unsigned int card_option; |
1 | 801 |
1989 | 802 if((dev = pci_find_device(PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G550, NULL))) |
803 { | |
804 is_g400 = 1; | |
805 printk(KERN_INFO "mga_vid: Found MGA G550\n"); | |
806 } | |
807 else if((dev = pci_find_device(PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G400, NULL))) | |
1 | 808 { |
809 is_g400 = 1; | |
77 | 810 printk(KERN_INFO "mga_vid: Found MGA G400/G450\n"); |
1 | 811 } |
812 else if((dev = pci_find_device(PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, NULL))) | |
813 { | |
814 is_g400 = 0; | |
63 | 815 printk(KERN_INFO "mga_vid: Found MGA G200 AGP\n"); |
1 | 816 } |
817 else if((dev = pci_find_device(PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_PCI, NULL))) | |
818 { | |
819 is_g400 = 0; | |
63 | 820 printk(KERN_INFO "mga_vid: Found MGA G200 PCI\n"); |
1 | 821 } |
822 else | |
823 { | |
61 | 824 printk(KERN_ERR "mga_vid: No supported cards found\n"); |
1 | 825 return FALSE; |
826 } | |
827 | |
828 pci_dev = dev; | |
48 | 829 |
830 mga_irq = pci_dev->irq; | |
1 | 831 |
832 #if LINUX_VERSION_CODE >= 0x020300 | |
833 mga_mmio_base = ioremap_nocache(dev->resource[1].start,0x4000); | |
834 mga_mem_base = dev->resource[0].start; | |
835 #else | |
836 mga_mmio_base = ioremap_nocache(dev->base_address[1] & PCI_BASE_ADDRESS_MEM_MASK,0x4000); | |
837 mga_mem_base = dev->base_address[0] & PCI_BASE_ADDRESS_MEM_MASK; | |
838 #endif | |
854
76ca00724e12
gcc warnings fixed - patch by Aelius aelius@wish.net
arpi_esp
parents:
662
diff
changeset
|
839 printk(KERN_INFO "mga_vid: MMIO at 0x%p IRQ: %d framebuffer: 0x%08X\n", mga_mmio_base, mga_irq, mga_mem_base); |
1 | 840 |
841 pci_read_config_dword(dev, 0x40, &card_option); | |
77 | 842 printk(KERN_INFO "mga_vid: OPTION word: 0x%08X mem: 0x%02X %s\n", card_option, |
843 (card_option>>10)&0x17, ((card_option>>14)&1)?"SGRAM":"SDRAM"); | |
1 | 844 |
57 | 845 // temp = (card_option >> 10) & 0x17; |
846 | |
95 | 847 if (mga_ram_size) { |
848 printk(KERN_INFO "mga_vid: RAMSIZE forced to %d MB\n", mga_ram_size); | |
91 | 849 } else { |
90 | 850 |
101
7fe6855f19cd
mga_ram_size=x works with hard-coded ramsize too (szabi)
arpi_esp
parents:
95
diff
changeset
|
851 #ifdef MGA_MEMORY_SIZE |
7fe6855f19cd
mga_ram_size=x works with hard-coded ramsize too (szabi)
arpi_esp
parents:
95
diff
changeset
|
852 mga_ram_size = MGA_MEMORY_SIZE; |
7fe6855f19cd
mga_ram_size=x works with hard-coded ramsize too (szabi)
arpi_esp
parents:
95
diff
changeset
|
853 printk(KERN_INFO "mga_vid: hard-coded RAMSIZE is %d MB\n", (unsigned int) mga_ram_size); |
7fe6855f19cd
mga_ram_size=x works with hard-coded ramsize too (szabi)
arpi_esp
parents:
95
diff
changeset
|
854 |
7fe6855f19cd
mga_ram_size=x works with hard-coded ramsize too (szabi)
arpi_esp
parents:
95
diff
changeset
|
855 #else |
7fe6855f19cd
mga_ram_size=x works with hard-coded ramsize too (szabi)
arpi_esp
parents:
95
diff
changeset
|
856 |
95 | 857 if (is_g400){ |
75 | 858 switch((card_option>>10)&0x17){ |
859 // SDRAM: | |
860 case 0x00: | |
861 case 0x04: mga_ram_size = 16; break; | |
105 | 862 case 0x03: mga_ram_size = 32; break; |
75 | 863 // SGRAM: |
864 case 0x10: | |
865 case 0x14: mga_ram_size = 32; break; | |
866 case 0x11: | |
867 case 0x12: mga_ram_size = 16; break; | |
868 default: | |
869 mga_ram_size = 16; | |
870 printk(KERN_INFO "mga_vid: Couldn't detect RAMSIZE, assuming 16MB!"); | |
871 } | |
95 | 872 }else{ |
662
4a959b73d51e
G200 ramsize detection disabled, using 8M by default
arpi_esp
parents:
470
diff
changeset
|
873 switch((card_option>>10)&0x17){ |
4a959b73d51e
G200 ramsize detection disabled, using 8M by default
arpi_esp
parents:
470
diff
changeset
|
874 // case 0x10: |
4a959b73d51e
G200 ramsize detection disabled, using 8M by default
arpi_esp
parents:
470
diff
changeset
|
875 // case 0x13: mga_ram_size = 8; break; |
4a959b73d51e
G200 ramsize detection disabled, using 8M by default
arpi_esp
parents:
470
diff
changeset
|
876 default: mga_ram_size = 8; |
64 | 877 } |
95 | 878 } |
64 | 879 #if 0 |
95 | 880 // printk("List resources -----------\n"); |
881 for(temp=0;temp<DEVICE_COUNT_RESOURCE;temp++){ | |
882 struct resource *res=&pci_dev->resource[temp]; | |
883 if(res->flags){ | |
884 int size=(1+res->end-res->start)>>20; | |
885 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); | |
886 if(res->flags&(IORESOURCE_MEM|IORESOURCE_PREFETCH)){ | |
887 if(size>mga_ram_size && size<=64) mga_ram_size=size; | |
888 } | |
889 } | |
57 | 890 } |
64 | 891 #endif |
95 | 892 printk(KERN_INFO "mga_vid: detected RAMSIZE is %d MB\n", (unsigned int) mga_ram_size); |
101
7fe6855f19cd
mga_ram_size=x works with hard-coded ramsize too (szabi)
arpi_esp
parents:
95
diff
changeset
|
893 #endif |
95 | 894 } |
57 | 895 |
48 | 896 |
68 | 897 #ifdef MGA_ALLOW_IRQ |
48 | 898 if ( mga_irq != -1 ) { |
899 int tmp = request_irq(mga_irq, mga_handle_irq, SA_INTERRUPT | SA_SHIRQ, "Syncfb Time Base", &mga_irq); | |
900 if ( tmp ) { | |
61 | 901 printk(KERN_INFO "syncfb (mga): cannot register irq %d (Err: %d)\n", mga_irq, tmp); |
48 | 902 mga_irq=-1; |
903 } else { | |
61 | 904 printk(KERN_DEBUG "syncfb (mga): registered irq %d\n", mga_irq); |
48 | 905 } |
906 } else { | |
61 | 907 printk(KERN_INFO "syncfb (mga): No valid irq was found\n"); |
48 | 908 mga_irq=-1; |
909 } | |
68 | 910 #else |
911 printk(KERN_INFO "syncfb (mga): IRQ disabled in mga_vid.c\n"); | |
912 mga_irq=-1; | |
913 #endif | |
48 | 914 |
1 | 915 return TRUE; |
916 } | |
917 | |
918 | |
919 static ssize_t mga_vid_read(struct file *file, char *buf, size_t count, loff_t *ppos) | |
920 { | |
921 return -EINVAL; | |
922 } | |
923 | |
924 static ssize_t mga_vid_write(struct file *file, const char *buf, size_t count, loff_t *ppos) | |
925 { | |
926 return -EINVAL; | |
927 } | |
928 | |
929 static int mga_vid_mmap(struct file *file, struct vm_area_struct *vma) | |
930 { | |
931 | |
61 | 932 printk(KERN_DEBUG "mga_vid: mapping video memory into userspace\n"); |
57 | 933 if(remap_page_range(vma->vm_start, mga_mem_base + mga_src_base, |
1 | 934 vma->vm_end - vma->vm_start, vma->vm_page_prot)) |
935 { | |
63 | 936 printk(KERN_ERR "mga_vid: error mapping video memory\n"); |
1 | 937 return(-EAGAIN); |
938 } | |
939 | |
940 return(0); | |
941 } | |
942 | |
943 static int mga_vid_release(struct inode *inode, struct file *file) | |
944 { | |
945 //Close the window just in case | |
94
fbd99740af99
printk() message for video off when releasing mga without ioctl()
lgb
parents:
93
diff
changeset
|
946 printk(KERN_DEBUG "mga_vid: Video OFF (release)\n"); |
fbd99740af99
printk() message for video off when releasing mga without ioctl()
lgb
parents:
93
diff
changeset
|
947 |
1 | 948 vid_src_ready = 0; |
949 regs.besctl &= ~1; | |
466 | 950 regs.besglobctl &= ~(1<<6); // UYVY format selected |
2086 | 951 // mga_config.colkey_on=0; //!!! |
952 mga_vid_write_regs(1); | |
1 | 953 mga_vid_in_use = 0; |
954 | |
93 | 955 MOD_DEC_USE_COUNT; |
1 | 956 return 0; |
957 } | |
958 | |
959 static long long mga_vid_lseek(struct file *file, long long offset, int origin) | |
960 { | |
961 return -ESPIPE; | |
962 } | |
963 | |
964 static int mga_vid_open(struct inode *inode, struct file *file) | |
965 { | |
966 int minor = MINOR(inode->i_rdev); | |
967 | |
968 if(minor != 0) | |
969 return(-ENXIO); | |
970 | |
971 if(mga_vid_in_use == 1) | |
972 return(-EBUSY); | |
973 | |
974 mga_vid_in_use = 1; | |
93 | 975 MOD_INC_USE_COUNT; |
1 | 976 return(0); |
977 } | |
978 | |
979 #if LINUX_VERSION_CODE >= 0x020400 | |
980 static struct file_operations mga_vid_fops = | |
981 { | |
982 llseek: mga_vid_lseek, | |
983 read: mga_vid_read, | |
984 write: mga_vid_write, | |
985 ioctl: mga_vid_ioctl, | |
986 mmap: mga_vid_mmap, | |
987 open: mga_vid_open, | |
988 release: mga_vid_release | |
989 }; | |
990 #else | |
991 static struct file_operations mga_vid_fops = | |
992 { | |
993 mga_vid_lseek, | |
994 mga_vid_read, | |
995 mga_vid_write, | |
996 NULL, | |
997 NULL, | |
998 mga_vid_ioctl, | |
999 mga_vid_mmap, | |
1000 mga_vid_open, | |
1001 NULL, | |
1002 mga_vid_release | |
1003 }; | |
1004 #endif | |
1005 | |
1006 | |
1007 /* | |
1008 * Main Initialization Function | |
1009 */ | |
1010 | |
1011 static int mga_vid_initialize(void) | |
1012 { | |
1013 mga_vid_in_use = 0; | |
1014 | |
77 | 1015 // printk(KERN_INFO "Matrox MGA G200/G400 YUV Video interface v0.01 (c) Aaron Holtzman \n"); |
1016 printk(KERN_INFO "Matrox MGA G200/G400/G450 YUV Video interface v2.01 (c) Aaron Holtzman & A'rpi\n"); | |
90 | 1017 |
95 | 1018 if (mga_ram_size) { |
1019 if (mga_ram_size<4 || mga_ram_size>64) { | |
1020 printk(KERN_ERR "mga_vid: invalid RAMSIZE: %d MB\n", mga_ram_size); | |
90 | 1021 return -EINVAL; |
1022 } | |
1023 } | |
1024 | |
1 | 1025 if(register_chrdev(MGA_VID_MAJOR, "mga_vid", &mga_vid_fops)) |
1026 { | |
61 | 1027 printk(KERN_ERR "mga_vid: unable to get major: %d\n", MGA_VID_MAJOR); |
1 | 1028 return -EIO; |
1029 } | |
1030 | |
1031 if (!mga_vid_find_card()) | |
1032 { | |
61 | 1033 printk(KERN_ERR "mga_vid: no supported devices found\n"); |
1 | 1034 unregister_chrdev(MGA_VID_MAJOR, "mga_vid"); |
1035 return -EINVAL; | |
1036 } | |
1037 | |
1038 return(0); | |
1039 } | |
1040 | |
1041 int init_module(void) | |
1042 { | |
1043 return mga_vid_initialize(); | |
1044 } | |
1045 | |
1046 void cleanup_module(void) | |
1047 { | |
48 | 1048 |
68 | 1049 #ifdef MGA_ALLOW_IRQ |
48 | 1050 if ( mga_irq != -1) |
1051 free_irq(mga_irq, &mga_irq); | |
68 | 1052 #endif |
48 | 1053 |
1 | 1054 if(mga_mmio_base) |
1055 iounmap(mga_mmio_base); | |
1056 | |
1057 //FIXME turn off BES | |
63 | 1058 printk(KERN_INFO "mga_vid: Cleaning up module\n"); |
1 | 1059 unregister_chrdev(MGA_VID_MAJOR, "mga_vid"); |
1060 } | |
1061 |