1
|
1 // YUY2 support (see config.format) added by A'rpi/ESP-team
|
|
2
|
|
3 /*
|
|
4 *
|
|
5 * mga_vid.c
|
|
6 *
|
|
7 * Copyright (C) 1999 Aaron Holtzman
|
|
8 *
|
|
9 * Module skeleton based on gutted agpgart module by Jeff Hartmann
|
|
10 * <slicer@ionet.net>
|
|
11 *
|
|
12 * Matrox MGA G200/G400 YUV Video Interface module Version 0.1.0
|
|
13 *
|
|
14 * BES == Back End Scaler
|
|
15 *
|
|
16 * This software has been released under the terms of the GNU Public
|
|
17 * license. See http://www.gnu.org/copyleft/gpl.html for details.
|
|
18 */
|
|
19
|
|
20 //It's entirely possible this major conflicts with something else
|
|
21 /* mknod /dev/mga_vid c 178 0 */
|
|
22
|
|
23 #include <linux/config.h>
|
|
24 #include <linux/version.h>
|
|
25 #include <linux/module.h>
|
|
26 #include <linux/types.h>
|
|
27 #include <linux/kernel.h>
|
|
28 #include <linux/sched.h>
|
|
29 #include <linux/mm.h>
|
|
30 #include <linux/string.h>
|
|
31 #include <linux/errno.h>
|
|
32 #include <linux/malloc.h>
|
|
33 #include <linux/pci.h>
|
|
34 #include <linux/init.h>
|
|
35 #include <linux/videodev.h>
|
|
36
|
|
37 #include "mga_vid.h"
|
|
38
|
|
39 #ifdef CONFIG_MTRR
|
|
40 #include <asm/mtrr.h>
|
|
41 #endif
|
|
42
|
|
43 #include <asm/uaccess.h>
|
|
44 #include <asm/system.h>
|
|
45 #include <asm/io.h>
|
|
46
|
|
47 #define TRUE 1
|
|
48 #define FALSE 0
|
|
49
|
|
50 #define MGA_VID_MAJOR 178
|
|
51
|
|
52 #define MGA_VIDMEM_SIZE mga_ram_size
|
|
53
|
|
54 #ifndef PCI_DEVICE_ID_MATROX_G200_PCI
|
|
55 #define PCI_DEVICE_ID_MATROX_G200_PCI 0x0520
|
|
56 #endif
|
|
57
|
|
58 #ifndef PCI_DEVICE_ID_MATROX_G200_AGP
|
|
59 #define PCI_DEVICE_ID_MATROX_G200_AGP 0x0521
|
|
60 #endif
|
|
61
|
|
62 #ifndef PCI_DEVICE_ID_MATROX_G400
|
|
63 #define PCI_DEVICE_ID_MATROX_G400 0x0525
|
|
64 #endif
|
|
65
|
|
66 MODULE_AUTHOR("Aaron Holtzman <aholtzma@engr.uvic.ca>");
|
|
67
|
|
68
|
|
69 typedef struct bes_registers_s
|
|
70 {
|
|
71 //BES Control
|
|
72 uint32_t besctl;
|
|
73 //BES Global control
|
|
74 uint32_t besglobctl;
|
|
75 //Luma control (brightness and contrast)
|
|
76 uint32_t beslumactl;
|
|
77 //Line pitch
|
|
78 uint32_t bespitch;
|
|
79
|
|
80 //Buffer A-1 Chroma 3 plane org
|
|
81 uint32_t besa1c3org;
|
|
82 //Buffer A-1 Chroma org
|
|
83 uint32_t besa1corg;
|
|
84 //Buffer A-1 Luma org
|
|
85 uint32_t besa1org;
|
|
86
|
|
87 //Buffer A-2 Chroma 3 plane org
|
|
88 uint32_t besa2c3org;
|
|
89 //Buffer A-2 Chroma org
|
|
90 uint32_t besa2corg;
|
|
91 //Buffer A-2 Luma org
|
|
92 uint32_t besa2org;
|
|
93
|
|
94 //Buffer B-1 Chroma 3 plane org
|
|
95 uint32_t besb1c3org;
|
|
96 //Buffer B-1 Chroma org
|
|
97 uint32_t besb1corg;
|
|
98 //Buffer B-1 Luma org
|
|
99 uint32_t besb1org;
|
|
100
|
|
101 //Buffer B-2 Chroma 3 plane org
|
|
102 uint32_t besb2c3org;
|
|
103 //Buffer B-2 Chroma org
|
|
104 uint32_t besb2corg;
|
|
105 //Buffer B-2 Luma org
|
|
106 uint32_t besb2org;
|
|
107
|
|
108 //BES Horizontal coord
|
|
109 uint32_t beshcoord;
|
|
110 //BES Horizontal inverse scaling [5.14]
|
|
111 uint32_t beshiscal;
|
|
112 //BES Horizontal source start [10.14] (for scaling)
|
|
113 uint32_t beshsrcst;
|
|
114 //BES Horizontal source ending [10.14] (for scaling)
|
|
115 uint32_t beshsrcend;
|
|
116 //BES Horizontal source last
|
|
117 uint32_t beshsrclst;
|
|
118
|
|
119
|
|
120 //BES Vertical coord
|
|
121 uint32_t besvcoord;
|
|
122 //BES Vertical inverse scaling [5.14]
|
|
123 uint32_t besviscal;
|
|
124 //BES Field 1 vertical source last position
|
|
125 uint32_t besv1srclst;
|
|
126 //BES Field 1 weight start
|
|
127 uint32_t besv1wght;
|
|
128 //BES Field 2 vertical source last position
|
|
129 uint32_t besv2srclst;
|
|
130 //BES Field 2 weight start
|
|
131 uint32_t besv2wght;
|
|
132
|
|
133 } bes_registers_t;
|
|
134
|
|
135 static bes_registers_t regs;
|
|
136 static uint32_t mga_vid_in_use = 0;
|
|
137 static uint32_t is_g400 = 0;
|
|
138 static uint32_t vid_src_ready = 0;
|
|
139 static uint32_t vid_overlay_on = 0;
|
|
140
|
|
141 static uint8_t *mga_mmio_base = 0;
|
|
142 static uint32_t mga_mem_base = 0;
|
|
143 static uint32_t mga_src_base = 0;
|
|
144
|
|
145 static uint32_t mga_ram_size = 0;
|
|
146
|
|
147 static struct pci_dev *pci_dev;
|
|
148
|
|
149 static struct video_window mga_win;
|
|
150 static mga_vid_config_t mga_config;
|
|
151
|
|
152
|
|
153 //All register offsets are converted to word aligned offsets (32 bit)
|
|
154 //because we want all our register accesses to be 32 bits
|
|
155 #define VCOUNT 0x1e20
|
|
156
|
|
157 #define PALWTADD 0x3c00 // Index register for X_DATAREG port
|
|
158 #define X_DATAREG 0x3c0a
|
|
159
|
|
160 #define XMULCTRL 0x19
|
|
161 #define BPP_8 0x00
|
|
162 #define BPP_15 0x01
|
|
163 #define BPP_16 0x02
|
|
164 #define BPP_24 0x03
|
|
165 #define BPP_32_DIR 0x04
|
|
166 #define BPP_32_PAL 0x07
|
|
167
|
|
168 #define XCOLMSK 0x40
|
|
169 #define X_COLKEY 0x42
|
|
170 #define XKEYOPMODE 0x51
|
|
171 #define XCOLMSK0RED 0x52
|
|
172 #define XCOLMSK0GREEN 0x53
|
|
173 #define XCOLMSK0BLUE 0x54
|
|
174 #define XCOLKEY0RED 0x55
|
|
175 #define XCOLKEY0GREEN 0x56
|
|
176 #define XCOLKEY0BLUE 0x57
|
|
177
|
|
178 // Backend Scaler registers
|
|
179 #define BESCTL 0x3d20
|
|
180 #define BESGLOBCTL 0x3dc0
|
|
181 #define BESLUMACTL 0x3d40
|
|
182 #define BESPITCH 0x3d24
|
|
183 #define BESA1C3ORG 0x3d60
|
|
184 #define BESA1CORG 0x3d10
|
|
185 #define BESA1ORG 0x3d00
|
|
186 #define BESA2C3ORG 0x3d64
|
|
187 #define BESA2CORG 0x3d14
|
|
188 #define BESA2ORG 0x3d04
|
|
189 #define BESB1C3ORG 0x3d68
|
|
190 #define BESB1CORG 0x3d18
|
|
191 #define BESB1ORG 0x3d08
|
|
192 #define BESB2C3ORG 0x3d6C
|
|
193 #define BESB2CORG 0x3d1C
|
|
194 #define BESB2ORG 0x3d0C
|
|
195 #define BESHCOORD 0x3d28
|
|
196 #define BESHISCAL 0x3d30
|
|
197 #define BESHSRCEND 0x3d3C
|
|
198 #define BESHSRCLST 0x3d50
|
|
199 #define BESHSRCST 0x3d38
|
|
200 #define BESV1WGHT 0x3d48
|
|
201 #define BESV2WGHT 0x3d4c
|
|
202 #define BESV1SRCLST 0x3d54
|
|
203 #define BESV2SRCLST 0x3d58
|
|
204 #define BESVISCAL 0x3d34
|
|
205 #define BESVCOORD 0x3d2c
|
|
206 #define BESSTATUS 0x3dc4
|
|
207
|
|
208
|
|
209 static void mga_vid_frame_sel(int frame)
|
|
210 {
|
|
211 //we don't need the vcount protection as we're only hitting
|
|
212 //one register (and it doesn't seem to be double buffered)
|
|
213 regs.besctl = (regs.besctl & ~0x07000000) + (frame << 25);
|
|
214 writel( regs.besctl, mga_mmio_base + BESCTL );
|
|
215 }
|
|
216
|
|
217
|
|
218 static void mga_vid_write_regs(void)
|
|
219 {
|
|
220 //Make sure internal registers don't get updated until we're done
|
|
221 writel( (readl(mga_mmio_base + VCOUNT)-1)<<16,
|
|
222 mga_mmio_base + BESGLOBCTL);
|
|
223
|
|
224 // color or coordinate keying
|
|
225 writeb( XKEYOPMODE, mga_mmio_base + PALWTADD);
|
|
226 writeb( mga_config.colkey_on, mga_mmio_base + X_DATAREG);
|
|
227 if ( mga_config.colkey_on )
|
|
228 {
|
|
229 uint32_t r=0, g=0, b=0;
|
|
230
|
|
231 writeb( XMULCTRL, mga_mmio_base + PALWTADD);
|
|
232 switch (readb (mga_mmio_base + X_DATAREG))
|
|
233 {
|
|
234 case BPP_8:
|
|
235 /* Need to look up the color index, just using
|
|
236 color 0 for now. */
|
|
237 break;
|
|
238
|
|
239 case BPP_15:
|
|
240 r = mga_config.colkey_red >> 3;
|
|
241 g = mga_config.colkey_green >> 3;
|
|
242 b = mga_config.colkey_blue >> 3;
|
|
243 break;
|
|
244
|
|
245 case BPP_16:
|
|
246 r = mga_config.colkey_red >> 3;
|
|
247 g = mga_config.colkey_green >> 2;
|
|
248 b = mga_config.colkey_blue >> 3;
|
|
249 break;
|
|
250
|
|
251 case BPP_24:
|
|
252 case BPP_32_DIR:
|
|
253 case BPP_32_PAL:
|
|
254 r = mga_config.colkey_red;
|
|
255 g = mga_config.colkey_green;
|
|
256 b = mga_config.colkey_blue;
|
|
257 break;
|
|
258 }
|
|
259
|
|
260 // Disable color keying on alpha channel
|
|
261 writeb( XCOLMSK, mga_mmio_base + PALWTADD);
|
|
262 writeb( 0x00, mga_mmio_base + X_DATAREG);
|
|
263 writeb( X_COLKEY, mga_mmio_base + PALWTADD);
|
|
264 writeb( 0x00, mga_mmio_base + X_DATAREG);
|
|
265
|
|
266 // Set up color key registers
|
|
267 writeb( XCOLKEY0RED, mga_mmio_base + PALWTADD);
|
|
268 writeb( r, mga_mmio_base + X_DATAREG);
|
|
269 writeb( XCOLKEY0GREEN, mga_mmio_base + PALWTADD);
|
|
270 writeb( g, mga_mmio_base + X_DATAREG);
|
|
271 writeb( XCOLKEY0BLUE, mga_mmio_base + PALWTADD);
|
|
272 writeb( b, mga_mmio_base + X_DATAREG);
|
|
273
|
|
274 // Set up color key mask registers
|
|
275 writeb( XCOLMSK0RED, mga_mmio_base + PALWTADD);
|
|
276 writeb( 0xff, mga_mmio_base + X_DATAREG);
|
|
277 writeb( XCOLMSK0GREEN, mga_mmio_base + PALWTADD);
|
|
278 writeb( 0xff, mga_mmio_base + X_DATAREG);
|
|
279 writeb( XCOLMSK0BLUE, mga_mmio_base + PALWTADD);
|
|
280 writeb( 0xff, mga_mmio_base + X_DATAREG);
|
|
281 }
|
|
282
|
|
283 // Backend Scaler
|
|
284 writel( regs.besctl, mga_mmio_base + BESCTL);
|
|
285 if(is_g400)
|
|
286 writel( regs.beslumactl, mga_mmio_base + BESLUMACTL);
|
|
287 writel( regs.bespitch, mga_mmio_base + BESPITCH);
|
|
288
|
|
289 writel( regs.besa1org, mga_mmio_base + BESA1ORG);
|
|
290 writel( regs.besa1corg, mga_mmio_base + BESA1CORG);
|
|
291 writel( regs.besb1org, mga_mmio_base + BESB1ORG);
|
|
292 writel( regs.besb1corg, mga_mmio_base + BESB1CORG);
|
|
293 if(is_g400)
|
|
294 {
|
|
295 writel( regs.besa1c3org, mga_mmio_base + BESA1C3ORG);
|
|
296 writel( regs.besb1c3org, mga_mmio_base + BESB1C3ORG);
|
|
297 }
|
|
298
|
|
299 writel( regs.beshcoord, mga_mmio_base + BESHCOORD);
|
|
300 writel( regs.beshiscal, mga_mmio_base + BESHISCAL);
|
|
301 writel( regs.beshsrcst, mga_mmio_base + BESHSRCST);
|
|
302 writel( regs.beshsrcend, mga_mmio_base + BESHSRCEND);
|
|
303 writel( regs.beshsrclst, mga_mmio_base + BESHSRCLST);
|
|
304
|
|
305 writel( regs.besvcoord, mga_mmio_base + BESVCOORD);
|
|
306 writel( regs.besviscal, mga_mmio_base + BESVISCAL);
|
|
307 writel( regs.besv1srclst, mga_mmio_base + BESV1SRCLST);
|
|
308 writel( regs.besv1wght, mga_mmio_base + BESV1WGHT);
|
|
309
|
|
310 //update the registers somewhere between 1 and 2 frames from now.
|
|
311 writel( regs.besglobctl + ((readl(mga_mmio_base + VCOUNT)+2)<<16),
|
|
312 mga_mmio_base + BESGLOBCTL);
|
|
313
|
|
314 printk("mga_vid: wrote BES registers\n");
|
|
315 printk("mga_vid: BESCTL = 0x%08x\n",
|
|
316 readl(mga_mmio_base + BESCTL));
|
|
317 printk("mga_vid: BESGLOBCTL = 0x%08x\n",
|
|
318 readl(mga_mmio_base + BESGLOBCTL));
|
|
319 printk("mga_vid: BESSTATUS= 0x%08x\n",
|
|
320 readl(mga_mmio_base + BESSTATUS));
|
|
321 }
|
|
322
|
|
323 static int mga_vid_set_config(mga_vid_config_t *config)
|
|
324 {
|
|
325 int x, y, sw, sh, dw, dh;
|
|
326 int besleft, bestop, ifactor, ofsleft, ofstop, baseadrofs, weight, weights;
|
|
327 int frame_size;
|
|
328 x = config->x_org;
|
|
329 y = config->y_org;
|
|
330 sw = config->src_width;
|
|
331 sh = config->src_height;
|
|
332 dw = config->dest_width;
|
|
333 dh = config->dest_height;
|
|
334
|
|
335 printk("mga_vid: Setting up a %dx%d+%d+%d video window (src %dx%d) format %X\n",
|
|
336 dw, dh, x, y, sw, sh, config->format);
|
|
337
|
|
338 //FIXME check that window is valid and inside desktop
|
|
339
|
|
340 //FIXME figure out a better way to allocate memory on card
|
|
341 //allocate 2 megs
|
|
342 //mga_src_base = mga_mem_base + (MGA_VIDMEM_SIZE-2) * 0x100000;
|
|
343 mga_src_base = (MGA_VIDMEM_SIZE-2) * 0x100000;
|
|
344
|
|
345
|
|
346 //Setup the BES registers for a three plane 4:2:0 video source
|
|
347
|
|
348 switch(config->format){
|
|
349 case MGA_VID_FORMAT_YV12:
|
|
350 regs.besctl = 1 // BES enabled
|
|
351 + (0<<6) // even start polarity
|
|
352 + (1<<10) // x filtering enabled
|
|
353 + (1<<11) // y filtering enabled
|
|
354 + (1<<16) // chroma upsampling
|
|
355 + (1<<17) // 4:2:0 mode
|
|
356 + (1<<18); // dither enabled
|
|
357
|
|
358 if(is_g400)
|
|
359 {
|
|
360 //zoom disabled, zoom filter disabled, 420 3 plane format, proc amp
|
|
361 //disabled, rgb mode disabled
|
|
362 regs.besglobctl = (1<<5);
|
|
363 }
|
|
364 else
|
|
365 {
|
|
366 //zoom disabled, zoom filter disabled, Cb samples in 0246, Cr
|
|
367 //in 1357, BES register update on besvcnt
|
|
368 regs.besglobctl = 0;
|
|
369 }
|
|
370 break;
|
|
371
|
|
372 case MGA_VID_FORMAT_YUY2:
|
|
373 regs.besctl = 1 // BES enabled
|
|
374 + (0<<6) // even start polarity
|
|
375 + (1<<10) // x filtering enabled
|
|
376 + (1<<11) // y filtering enabled
|
|
377 + (1<<16) // chroma upsampling
|
|
378 + (0<<17) // 4:2:2 mode
|
|
379 + (1<<18); // dither enabled
|
|
380
|
|
381 regs.besglobctl = 0; // YUY2 format selected
|
|
382 break;
|
|
383 default:
|
|
384 return -1;
|
|
385 }
|
|
386
|
|
387
|
|
388 //Disable contrast and brightness control
|
|
389 regs.besglobctl = (1<<5) + (1<<7);
|
|
390 regs.beslumactl = (0x7f << 16) + (0x80<<0);
|
|
391 regs.beslumactl = 0x80<<0;
|
|
392
|
|
393 //Setup destination window boundaries
|
|
394 besleft = x > 0 ? x : 0;
|
|
395 bestop = y > 0 ? y : 0;
|
|
396 regs.beshcoord = (besleft<<16) + (x + dw-1);
|
|
397 regs.besvcoord = (bestop<<16) + (y + dh-1);
|
|
398
|
|
399 //Setup source dimensions
|
|
400 regs.beshsrclst = (sw - 1) << 16;
|
|
401 regs.bespitch = (sw + 31) & ~31 ;
|
|
402
|
|
403 //Setup horizontal scaling
|
|
404 ifactor = ((sw-1)<<14)/(dw-1);
|
|
405 ofsleft = besleft - x;
|
|
406
|
|
407 regs.beshiscal = ifactor<<2;
|
|
408 regs.beshsrcst = (ofsleft*ifactor)<<2;
|
|
409 regs.beshsrcend = regs.beshsrcst + (((dw - ofsleft - 1) * ifactor) << 2);
|
|
410
|
|
411 //Setup vertical scaling
|
|
412 ifactor = ((sh-1)<<14)/(dh-1);
|
|
413 ofstop = bestop - y;
|
|
414
|
|
415 regs.besviscal = ifactor<<2;
|
|
416
|
|
417 baseadrofs = ((ofstop*regs.besviscal)>>16)*regs.bespitch;
|
|
418 frame_size = ((sw + 31) & ~31) * sh + (((sw + 31) & ~31) * sh) / 2;
|
|
419 regs.besa1org = (uint32_t) mga_src_base + baseadrofs;
|
|
420 regs.besb1org = (uint32_t) mga_src_base + baseadrofs + frame_size;
|
|
421
|
|
422 if (is_g400)
|
|
423 baseadrofs = (((ofstop*regs.besviscal)/4)>>16)*regs.bespitch;
|
|
424 else
|
|
425 baseadrofs = (((ofstop*regs.besviscal)/2)>>16)*regs.bespitch;
|
|
426
|
|
427 regs.besa1corg = (uint32_t) mga_src_base + baseadrofs + regs.bespitch * sh ;
|
|
428 regs.besb1corg = (uint32_t) mga_src_base + baseadrofs + frame_size + regs.bespitch * sh;
|
|
429 regs.besa1c3org = regs.besa1corg + ((regs.bespitch * sh) / 4);
|
|
430 regs.besb1c3org = regs.besb1corg + ((regs.bespitch * sh) / 4);
|
|
431
|
|
432 weight = ofstop * (regs.besviscal >> 2);
|
|
433 weights = weight < 0 ? 1 : 0;
|
|
434 regs.besv1wght = (weights << 16) + ((weight & 0x3FFF) << 2);
|
|
435 regs.besv1srclst = sh - 1 - (((ofstop * regs.besviscal) >> 16) & 0x03FF);
|
|
436
|
|
437 mga_vid_write_regs();
|
|
438 return 0;
|
|
439 }
|
|
440
|
|
441
|
|
442 static int mga_vid_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
|
|
443 {
|
|
444 int frame;
|
|
445
|
|
446 switch(cmd)
|
|
447 {
|
|
448 case MGA_VID_CONFIG:
|
|
449 //FIXME remove
|
|
450 printk("vcount = %d\n",readl(mga_mmio_base + VCOUNT));
|
|
451 printk("mga_mmio_base = %p\n",mga_mmio_base);
|
|
452 printk("mga_mem_base = %08lx\n",mga_mem_base);
|
|
453 //FIXME remove
|
|
454
|
|
455 printk("mga_vid: Received configuration\n");
|
|
456
|
|
457 if(copy_from_user(&mga_config,(mga_vid_config_t*) arg,sizeof(mga_vid_config_t)))
|
|
458 {
|
|
459 printk("mga_vid: failed copy from userspace\n");
|
|
460 return(-EFAULT);
|
|
461 }
|
|
462 if (is_g400)
|
|
463 mga_config.card_type = MGA_G400;
|
|
464 else
|
|
465 mga_config.card_type = MGA_G200;
|
|
466
|
|
467 mga_config.ram_size = mga_ram_size;
|
|
468
|
|
469 if (copy_to_user((mga_vid_config_t *) arg, &mga_config, sizeof(mga_vid_config_t)))
|
|
470 {
|
|
471 printk("mga_vid: failed copy to userspace\n");
|
|
472 return(-EFAULT);
|
|
473 }
|
|
474 return mga_vid_set_config(&mga_config);
|
|
475 break;
|
|
476
|
|
477 case MGA_VID_ON:
|
|
478 printk("mga_vid: Video ON\n");
|
|
479 vid_src_ready = 1;
|
|
480 if(vid_overlay_on)
|
|
481 {
|
|
482 regs.besctl |= 1;
|
|
483 mga_vid_write_regs();
|
|
484 }
|
|
485 break;
|
|
486
|
|
487 case MGA_VID_OFF:
|
|
488 printk("mga_vid: Video OFF\n");
|
|
489 vid_src_ready = 0;
|
|
490 regs.besctl &= ~1;
|
|
491 mga_vid_write_regs();
|
|
492 break;
|
|
493
|
|
494 case MGA_VID_FSEL:
|
|
495 if(copy_from_user(&frame,(int *) arg,sizeof(int)))
|
|
496 {
|
|
497 printk("mga_vid: FSEL failed copy from userspace\n");
|
|
498 return(-EFAULT);
|
|
499 }
|
|
500
|
|
501 mga_vid_frame_sel(frame);
|
|
502 break;
|
|
503
|
|
504 default:
|
|
505 printk("mga_vid: Invalid ioctl\n");
|
|
506 return (-EINVAL);
|
|
507 }
|
|
508
|
|
509 return 0;
|
|
510 }
|
|
511
|
|
512
|
|
513 static int mga_vid_find_card(void)
|
|
514 {
|
|
515 struct pci_dev *dev = NULL;
|
|
516 unsigned int card_option, temp;
|
|
517
|
|
518 if((dev = pci_find_device(PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G400, NULL)))
|
|
519 {
|
|
520 is_g400 = 1;
|
|
521 printk("mga_vid: Found MGA G400\n");
|
|
522 }
|
|
523 else if((dev = pci_find_device(PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, NULL)))
|
|
524 {
|
|
525 is_g400 = 0;
|
|
526 printk("mga_vid: Found MGA G200 AGP\n");
|
|
527 }
|
|
528 else if((dev = pci_find_device(PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_PCI, NULL)))
|
|
529 {
|
|
530 is_g400 = 0;
|
|
531 printk("mga_vid: Found MGA G200 PCI\n");
|
|
532 }
|
|
533 else
|
|
534 {
|
|
535 printk("mga_vid: No supported cards found\n");
|
|
536 return FALSE;
|
|
537 }
|
|
538
|
|
539 pci_dev = dev;
|
|
540
|
|
541 #if LINUX_VERSION_CODE >= 0x020300
|
|
542 mga_mmio_base = ioremap_nocache(dev->resource[1].start,0x4000);
|
|
543 mga_mem_base = dev->resource[0].start;
|
|
544 #else
|
|
545 mga_mmio_base = ioremap_nocache(dev->base_address[1] & PCI_BASE_ADDRESS_MEM_MASK,0x4000);
|
|
546 mga_mem_base = dev->base_address[0] & PCI_BASE_ADDRESS_MEM_MASK;
|
|
547 #endif
|
|
548 printk("mga_vid: MMIO at 0x%p\n", mga_mmio_base);
|
|
549 printk("mga_vid: Frame Buffer at 0x%08lX\n", mga_mem_base);
|
|
550
|
|
551 pci_read_config_dword(dev, 0x40, &card_option);
|
|
552 printk("OPTION word: 0x%08x\n", card_option);
|
|
553
|
|
554 temp = (card_option >> 10) & 0x17;
|
|
555
|
|
556 if (is_g400)
|
|
557 {
|
|
558 switch(temp)
|
|
559 {
|
|
560 default:
|
|
561 mga_ram_size = 16;
|
|
562 }
|
|
563 }
|
|
564 else
|
|
565 {
|
|
566 // a g200
|
|
567 switch(temp)
|
|
568 {
|
|
569 default:
|
|
570 mga_ram_size = 8;
|
|
571 }
|
|
572 }
|
|
573
|
|
574 printk("mga_vid: RAMSIZE seems to be %d MB\n", (unsigned int) mga_ram_size);
|
|
575
|
|
576 return TRUE;
|
|
577 }
|
|
578
|
|
579
|
|
580 static ssize_t mga_vid_read(struct file *file, char *buf, size_t count, loff_t *ppos)
|
|
581 {
|
|
582 return -EINVAL;
|
|
583 }
|
|
584
|
|
585 static ssize_t mga_vid_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
|
|
586 {
|
|
587 return -EINVAL;
|
|
588 }
|
|
589
|
|
590 static int mga_vid_mmap(struct file *file, struct vm_area_struct *vma)
|
|
591 {
|
|
592
|
|
593 printk("mga_vid: mapping video memory into userspace\n");
|
|
594 if(remap_page_range(vma->vm_start, mga_mem_base + (MGA_VIDMEM_SIZE-2) * 0x100000,
|
|
595 vma->vm_end - vma->vm_start, vma->vm_page_prot))
|
|
596 {
|
|
597 printk("mga_vid: error mapping video memory\n");
|
|
598 return(-EAGAIN);
|
|
599 }
|
|
600
|
|
601 return(0);
|
|
602 }
|
|
603
|
|
604 static int mga_vid_release(struct inode *inode, struct file *file)
|
|
605 {
|
|
606 //Close the window just in case
|
|
607 vid_src_ready = 0;
|
|
608 regs.besctl &= ~1;
|
|
609 mga_vid_write_regs();
|
|
610 mga_vid_in_use = 0;
|
|
611
|
|
612 //FIXME put back in!
|
|
613 //MOD_DEC_USE_COUNT;
|
|
614 return 0;
|
|
615 }
|
|
616
|
|
617 static long long mga_vid_lseek(struct file *file, long long offset, int origin)
|
|
618 {
|
|
619 return -ESPIPE;
|
|
620 }
|
|
621
|
|
622 static int mga_vid_open(struct inode *inode, struct file *file)
|
|
623 {
|
|
624 int minor = MINOR(inode->i_rdev);
|
|
625
|
|
626 if(minor != 0)
|
|
627 return(-ENXIO);
|
|
628
|
|
629 if(mga_vid_in_use == 1)
|
|
630 return(-EBUSY);
|
|
631
|
|
632 mga_vid_in_use = 1;
|
|
633 //FIXME turn me back on!
|
|
634 //MOD_INC_USE_COUNT;
|
|
635 return(0);
|
|
636 }
|
|
637
|
|
638 #if LINUX_VERSION_CODE >= 0x020400
|
|
639 static struct file_operations mga_vid_fops =
|
|
640 {
|
|
641 llseek: mga_vid_lseek,
|
|
642 read: mga_vid_read,
|
|
643 write: mga_vid_write,
|
|
644 ioctl: mga_vid_ioctl,
|
|
645 mmap: mga_vid_mmap,
|
|
646 open: mga_vid_open,
|
|
647 release: mga_vid_release
|
|
648 };
|
|
649 #else
|
|
650 static struct file_operations mga_vid_fops =
|
|
651 {
|
|
652 mga_vid_lseek,
|
|
653 mga_vid_read,
|
|
654 mga_vid_write,
|
|
655 NULL,
|
|
656 NULL,
|
|
657 mga_vid_ioctl,
|
|
658 mga_vid_mmap,
|
|
659 mga_vid_open,
|
|
660 NULL,
|
|
661 mga_vid_release
|
|
662 };
|
|
663 #endif
|
|
664
|
|
665 static long mga_v4l_read(struct video_device *v, char *buf, unsigned long count,
|
|
666 int noblock)
|
|
667 {
|
|
668 return -EINVAL;
|
|
669 }
|
|
670
|
|
671 static long mga_v4l_write(struct video_device *v, const char *buf, unsigned long count, int noblock)
|
|
672 {
|
|
673 return -EINVAL;
|
|
674 }
|
|
675
|
|
676 static int mga_v4l_open(struct video_device *dev, int mode)
|
|
677 {
|
|
678 MOD_INC_USE_COUNT;
|
|
679 return 0;
|
|
680 }
|
|
681
|
|
682 static void mga_v4l_close(struct video_device *dev)
|
|
683 {
|
|
684 regs.besctl &= ~1;
|
|
685 mga_vid_write_regs();
|
|
686 vid_overlay_on = 0;
|
|
687 MOD_DEC_USE_COUNT;
|
|
688 return;
|
|
689 }
|
|
690
|
|
691 static int mga_v4l_init_done(struct video_device *dev)
|
|
692 {
|
|
693 return 0;
|
|
694 }
|
|
695
|
|
696 static int mga_v4l_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
|
|
697 {
|
|
698 switch(cmd)
|
|
699 {
|
|
700 case VIDIOCGCAP:
|
|
701 {
|
|
702 struct video_capability b;
|
|
703 strcpy(b.name, "Matrox G200/400");
|
|
704 b.type = VID_TYPE_SCALES|VID_TYPE_OVERLAY|VID_TYPE_CHROMAKEY;
|
|
705 b.channels = 0;
|
|
706 b.audios = 0;
|
|
707 b.maxwidth = 1024; /* GUESS ?? */
|
|
708 b.maxheight = 768;
|
|
709 b.minwidth = 32;
|
|
710 b.minheight = 16; /* GUESS ?? */
|
|
711 if(copy_to_user(arg,&b,sizeof(b)))
|
|
712 return -EFAULT;
|
|
713 return 0;
|
|
714 }
|
|
715 case VIDIOCGPICT:
|
|
716 {
|
|
717 /*
|
|
718 * Default values.. if we can change this we
|
|
719 * can add the feature later
|
|
720 */
|
|
721 struct video_picture vp;
|
|
722 vp.brightness = 0x8000;
|
|
723 vp.hue = 0x8000;
|
|
724 vp.colour = 0x8000;
|
|
725 vp.whiteness = 0x8000;
|
|
726 vp.depth = 8;
|
|
727 /* Format is a guess */
|
|
728 vp.palette = VIDEO_PALETTE_YUV420P;
|
|
729 if(copy_to_user(arg, &vp, sizeof(vp)))
|
|
730 return -EFAULT;
|
|
731 return 0;
|
|
732 }
|
|
733 case VIDIOCSPICT:
|
|
734 {
|
|
735 return -EINVAL;
|
|
736 }
|
|
737 case VIDIOCSWIN:
|
|
738 {
|
|
739 struct video_window vw;
|
|
740 if(copy_from_user(&vw, arg, sizeof(vw)))
|
|
741 return -EFAULT;
|
|
742 if(vw.x <0 || vw.y <0 || vw.width < 32
|
|
743 || vw.height < 16)
|
|
744 return -EINVAL;
|
|
745 memcpy(&mga_win, &vw, sizeof(mga_win));
|
|
746
|
|
747 mga_config.x_org = vw.x;
|
|
748 mga_config.y_org = vw.y;
|
|
749 mga_config.dest_width = vw.width;
|
|
750 mga_config.dest_height = vw.height;
|
|
751
|
|
752 /*
|
|
753 * May have to add
|
|
754 *
|
|
755 * #define VIDEO_WINDOW_CHROMAKEY 16
|
|
756 *
|
|
757 * to <linux/videodev.h>
|
|
758 */
|
|
759
|
|
760 //add it here for now
|
|
761 #define VIDEO_WINDOW_CHROMAKEY 16
|
|
762
|
|
763 if (vw.flags & VIDEO_WINDOW_CHROMAKEY)
|
|
764 mga_config.colkey_on = 1;
|
|
765 else
|
|
766 mga_config.colkey_on = 0;
|
|
767
|
|
768 mga_config.colkey_red = (vw.chromakey >> 24) & 0xFF;
|
|
769 mga_config.colkey_green = (vw.chromakey >> 16) & 0xFF;
|
|
770 mga_config.colkey_blue = (vw.chromakey >> 8) & 0xFF;
|
|
771 mga_vid_set_config(&mga_config);
|
|
772 return 0;
|
|
773
|
|
774 }
|
|
775 case VIDIOCGWIN:
|
|
776 {
|
|
777 if(copy_to_user(arg, &mga_win, sizeof(mga_win)))
|
|
778 return -EFAULT;
|
|
779 return 0;
|
|
780 }
|
|
781 case VIDIOCCAPTURE:
|
|
782 {
|
|
783 int v;
|
|
784 if(copy_from_user(&v, arg, sizeof(v)))
|
|
785 return -EFAULT;
|
|
786 vid_overlay_on = v;
|
|
787 if(vid_overlay_on && vid_src_ready)
|
|
788 {
|
|
789 regs.besctl |= 1;
|
|
790 mga_vid_write_regs();
|
|
791 }
|
|
792 else
|
|
793 {
|
|
794 regs.besctl &= ~1;
|
|
795 mga_vid_write_regs();
|
|
796 }
|
|
797 return 0;
|
|
798 }
|
|
799 default:
|
|
800 return -ENOIOCTLCMD;
|
|
801 }
|
|
802 }
|
|
803
|
|
804 static struct video_device mga_v4l_dev =
|
|
805 {
|
|
806 "Matrox G200/G400",
|
|
807 VID_TYPE_CAPTURE,
|
|
808 VID_HARDWARE_BT848, /* This is a lie for now */
|
|
809 mga_v4l_open,
|
|
810 mga_v4l_close,
|
|
811 mga_v4l_read,
|
|
812 mga_v4l_write,
|
|
813 NULL,
|
|
814 mga_v4l_ioctl,
|
|
815 NULL,
|
|
816 mga_v4l_init_done,
|
|
817 NULL,
|
|
818 0,
|
|
819 0
|
|
820 };
|
|
821
|
|
822
|
|
823
|
|
824 /*
|
|
825 * Main Initialization Function
|
|
826 */
|
|
827
|
|
828
|
|
829 static int mga_vid_initialize(void)
|
|
830 {
|
|
831 mga_vid_in_use = 0;
|
|
832
|
|
833 printk( "Matrox MGA G200/G400 YUV Video interface v0.01 (c) Aaron Holtzman \n");
|
|
834 if(register_chrdev(MGA_VID_MAJOR, "mga_vid", &mga_vid_fops))
|
|
835 {
|
|
836 printk("mga_vid: unable to get major: %d\n", MGA_VID_MAJOR);
|
|
837 return -EIO;
|
|
838 }
|
|
839
|
|
840 if (!mga_vid_find_card())
|
|
841 {
|
|
842 printk("mga_vid: no supported devices found\n");
|
|
843 unregister_chrdev(MGA_VID_MAJOR, "mga_vid");
|
|
844 return -EINVAL;
|
|
845 }
|
|
846
|
|
847 #if 0
|
|
848 if (video_register_device(&mga_v4l_dev, VFL_TYPE_GRABBER)<0)
|
|
849 {
|
|
850 printk("mga_vid: unable to register.\n");
|
|
851 unregister_chrdev(MGA_VID_MAJOR, "mga_vid");
|
|
852 if(mga_mmio_base)
|
|
853 iounmap(mga_mmio_base);
|
|
854 mga_mmio_base = 0;
|
|
855 return -EINVAL;
|
|
856 }
|
|
857 #endif
|
|
858
|
|
859 return(0);
|
|
860 }
|
|
861
|
|
862 int init_module(void)
|
|
863 {
|
|
864 return mga_vid_initialize();
|
|
865 }
|
|
866
|
|
867 void cleanup_module(void)
|
|
868 {
|
|
869 // video_unregister_device(&mga_v4l_dev);
|
|
870 if(mga_mmio_base)
|
|
871 iounmap(mga_mmio_base);
|
|
872
|
|
873 //FIXME turn off BES
|
|
874 printk("mga_vid: Cleaning up module\n");
|
|
875 unregister_chrdev(MGA_VID_MAJOR, "mga_vid");
|
|
876 }
|
|
877
|