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