Mercurial > mplayer.hg
annotate drivers/mga_vid.c @ 2861:bdc625b8048a
fix typos
author | nexus |
---|---|
date | Tue, 13 Nov 2001 09:12:20 +0000 |
parents | 9acd3e75be48 |
children | d62aa0b7fd68 |
rev | line source |
---|---|
2345 | 1 //#define CRTC2 |
2 | |
1 | 3 // YUY2 support (see config.format) added by A'rpi/ESP-team |
57 | 4 // double buffering added by A'rpi/ESP-team |
5 | |
6 // Set this value, if autodetection fails! (video ram size in megabytes) | |
91 | 7 // #define MGA_MEMORY_SIZE 16 |
1 | 8 |
68 | 9 //#define MGA_ALLOW_IRQ |
10 | |
11 #define MGA_VSYNC_POS 2 | |
12 | |
1 | 13 /* |
14 * | |
15 * mga_vid.c | |
16 * | |
17 * Copyright (C) 1999 Aaron Holtzman | |
18 * | |
19 * Module skeleton based on gutted agpgart module by Jeff Hartmann | |
20 * <slicer@ionet.net> | |
21 * | |
22 * Matrox MGA G200/G400 YUV Video Interface module Version 0.1.0 | |
23 * | |
24 * BES == Back End Scaler | |
25 * | |
26 * This software has been released under the terms of the GNU Public | |
27 * license. See http://www.gnu.org/copyleft/gpl.html for details. | |
28 */ | |
29 | |
30 //It's entirely possible this major conflicts with something else | |
31 /* mknod /dev/mga_vid c 178 0 */ | |
32 | |
33 #include <linux/config.h> | |
34 #include <linux/version.h> | |
35 #include <linux/module.h> | |
36 #include <linux/types.h> | |
37 #include <linux/kernel.h> | |
38 #include <linux/sched.h> | |
39 #include <linux/mm.h> | |
40 #include <linux/string.h> | |
41 #include <linux/errno.h> | |
42 #include <linux/malloc.h> | |
43 #include <linux/pci.h> | |
63 | 44 #include <linux/ioport.h> |
1 | 45 #include <linux/init.h> |
46 | |
47 #include "mga_vid.h" | |
48 | |
49 #ifdef CONFIG_MTRR | |
50 #include <asm/mtrr.h> | |
51 #endif | |
52 | |
53 #include <asm/uaccess.h> | |
54 #include <asm/system.h> | |
55 #include <asm/io.h> | |
56 | |
57 #define TRUE 1 | |
58 #define FALSE 0 | |
59 | |
60 #define MGA_VID_MAJOR 178 | |
61 | |
57 | 62 //#define MGA_VIDMEM_SIZE mga_ram_size |
1 | 63 |
64 #ifndef PCI_DEVICE_ID_MATROX_G200_PCI | |
65 #define PCI_DEVICE_ID_MATROX_G200_PCI 0x0520 | |
66 #endif | |
67 | |
68 #ifndef PCI_DEVICE_ID_MATROX_G200_AGP | |
69 #define PCI_DEVICE_ID_MATROX_G200_AGP 0x0521 | |
70 #endif | |
71 | |
72 #ifndef PCI_DEVICE_ID_MATROX_G400 | |
73 #define PCI_DEVICE_ID_MATROX_G400 0x0525 | |
74 #endif | |
75 | |
1989 | 76 #ifndef PCI_DEVICE_ID_MATROX_G550 |
77 #define PCI_DEVICE_ID_MATROX_G550 0x2527 | |
78 #endif | |
79 | |
1 | 80 MODULE_AUTHOR("Aaron Holtzman <aholtzma@engr.uvic.ca>"); |
2262 | 81 #ifdef MODULE_LICENSE |
82 MODULE_LICENSE("GPL"); | |
83 #endif | |
1 | 84 |
85 typedef struct bes_registers_s | |
86 { | |
87 //BES Control | |
88 uint32_t besctl; | |
89 //BES Global control | |
90 uint32_t besglobctl; | |
91 //Luma control (brightness and contrast) | |
92 uint32_t beslumactl; | |
93 //Line pitch | |
94 uint32_t bespitch; | |
95 | |
96 //Buffer A-1 Chroma 3 plane org | |
97 uint32_t besa1c3org; | |
98 //Buffer A-1 Chroma org | |
99 uint32_t besa1corg; | |
100 //Buffer A-1 Luma org | |
101 uint32_t besa1org; | |
102 | |
103 //Buffer A-2 Chroma 3 plane org | |
104 uint32_t besa2c3org; | |
105 //Buffer A-2 Chroma org | |
106 uint32_t besa2corg; | |
107 //Buffer A-2 Luma org | |
108 uint32_t besa2org; | |
109 | |
110 //Buffer B-1 Chroma 3 plane org | |
111 uint32_t besb1c3org; | |
112 //Buffer B-1 Chroma org | |
113 uint32_t besb1corg; | |
114 //Buffer B-1 Luma org | |
115 uint32_t besb1org; | |
116 | |
117 //Buffer B-2 Chroma 3 plane org | |
118 uint32_t besb2c3org; | |
119 //Buffer B-2 Chroma org | |
120 uint32_t besb2corg; | |
121 //Buffer B-2 Luma org | |
122 uint32_t besb2org; | |
123 | |
124 //BES Horizontal coord | |
125 uint32_t beshcoord; | |
126 //BES Horizontal inverse scaling [5.14] | |
127 uint32_t beshiscal; | |
128 //BES Horizontal source start [10.14] (for scaling) | |
129 uint32_t beshsrcst; | |
130 //BES Horizontal source ending [10.14] (for scaling) | |
131 uint32_t beshsrcend; | |
132 //BES Horizontal source last | |
133 uint32_t beshsrclst; | |
134 | |
135 | |
136 //BES Vertical coord | |
137 uint32_t besvcoord; | |
138 //BES Vertical inverse scaling [5.14] | |
139 uint32_t besviscal; | |
140 //BES Field 1 vertical source last position | |
141 uint32_t besv1srclst; | |
142 //BES Field 1 weight start | |
143 uint32_t besv1wght; | |
144 //BES Field 2 vertical source last position | |
145 uint32_t besv2srclst; | |
146 //BES Field 2 weight start | |
147 uint32_t besv2wght; | |
148 | |
149 } bes_registers_t; | |
150 | |
151 static bes_registers_t regs; | |
2344 | 152 #ifdef CRTC2 |
153 typedef struct crtc2_registers_s | |
154 { | |
155 uint32_t c2ctl; | |
156 uint32_t c2datactl; | |
157 uint32_t c2misc; | |
158 uint32_t c2hparam; | |
159 uint32_t c2hsync; | |
160 uint32_t c2offset; | |
161 uint32_t c2pl2startadd0; | |
162 uint32_t c2pl2startadd1; | |
163 uint32_t c2pl3startadd0; | |
164 uint32_t c2pl3startadd1; | |
165 uint32_t c2preload; | |
166 uint32_t c2spicstartadd0; | |
167 uint32_t c2spicstartadd1; | |
168 uint32_t c2startadd0; | |
169 uint32_t c2startadd1; | |
170 uint32_t c2subpiclut; | |
171 uint32_t c2vcount; | |
172 uint32_t c2vparam; | |
173 uint32_t c2vsync; | |
174 } crtc2_registers_t; | |
175 static crtc2_registers_t cregs; | |
176 #endif | |
1 | 177 static uint32_t mga_vid_in_use = 0; |
178 static uint32_t is_g400 = 0; | |
179 static uint32_t vid_src_ready = 0; | |
180 static uint32_t vid_overlay_on = 0; | |
181 | |
182 static uint8_t *mga_mmio_base = 0; | |
183 static uint32_t mga_mem_base = 0; | |
184 | |
57 | 185 static int mga_src_base = 0; // YUV buffer position in video memory |
186 | |
187 static uint32_t mga_ram_size = 0; // how much megabytes videoram we have | |
1 | 188 |
95 | 189 //static int mga_force_memsize = 0; |
90 | 190 |
95 | 191 MODULE_PARM(mga_ram_size, "i"); |
90 | 192 |
1 | 193 static struct pci_dev *pci_dev; |
194 | |
195 static mga_vid_config_t mga_config; | |
196 | |
2086 | 197 static int colkey_saved=0; |
198 static int colkey_on=0; | |
199 static unsigned char colkey_color[4]; | |
200 static unsigned char colkey_mask[4]; | |
201 | |
48 | 202 static int mga_irq = -1; |
1 | 203 |
204 //All register offsets are converted to word aligned offsets (32 bit) | |
205 //because we want all our register accesses to be 32 bits | |
206 #define VCOUNT 0x1e20 | |
207 | |
208 #define PALWTADD 0x3c00 // Index register for X_DATAREG port | |
209 #define X_DATAREG 0x3c0a | |
210 | |
211 #define XMULCTRL 0x19 | |
212 #define BPP_8 0x00 | |
213 #define BPP_15 0x01 | |
214 #define BPP_16 0x02 | |
215 #define BPP_24 0x03 | |
216 #define BPP_32_DIR 0x04 | |
217 #define BPP_32_PAL 0x07 | |
218 | |
219 #define XCOLMSK 0x40 | |
220 #define X_COLKEY 0x42 | |
221 #define XKEYOPMODE 0x51 | |
222 #define XCOLMSK0RED 0x52 | |
223 #define XCOLMSK0GREEN 0x53 | |
224 #define XCOLMSK0BLUE 0x54 | |
225 #define XCOLKEY0RED 0x55 | |
226 #define XCOLKEY0GREEN 0x56 | |
227 #define XCOLKEY0BLUE 0x57 | |
228 | |
2344 | 229 #ifdef CRTC2 |
230 | |
231 /*CRTC2 registers*/ | |
232 #define XMISCCTRL 0x1e | |
233 #define C2CTL 0x3c10 | |
234 #define C2DATACTL 0x3c4c | |
235 #define C2MISC 0x3c44 | |
236 #define C2HPARAM 0x3c14 | |
237 #define C2HSYNC 0x3c18 | |
238 #define C2OFFSET 0x3c40 | |
239 #define C2PL2STARTADD0 0x3c30 // like BESA1CORG | |
240 #define C2PL2STARTADD1 0x3c34 // like BESA2CORG | |
241 #define C2PL3STARTADD0 0x3c38 // like BESA1C3ORG | |
242 #define C2PL3STARTADD1 0x3c3c // like BESA2C3ORG | |
243 #define C2PRELOAD 0x3c24 | |
244 #define C2SPICSTARTADD0 0x3c54 | |
245 #define C2SPICSTARTADD1 0x3c58 | |
246 #define C2STARTADD0 0x3c28 // like BESA1ORG | |
247 #define C2STARTADD1 0x3c2c // like BESA2ORG | |
248 #define C2SUBPICLUT 0x3c50 | |
249 #define C2VCOUNT 0x3c48 | |
250 #define C2VPARAM 0x3c1c | |
251 #define C2VSYNC 0x3c20 | |
252 | |
253 #endif | |
254 | |
1 | 255 // Backend Scaler registers |
256 #define BESCTL 0x3d20 | |
257 #define BESGLOBCTL 0x3dc0 | |
258 #define BESLUMACTL 0x3d40 | |
259 #define BESPITCH 0x3d24 | |
48 | 260 |
1 | 261 #define BESA1C3ORG 0x3d60 |
262 #define BESA1CORG 0x3d10 | |
263 #define BESA1ORG 0x3d00 | |
48 | 264 |
1 | 265 #define BESA2C3ORG 0x3d64 |
266 #define BESA2CORG 0x3d14 | |
267 #define BESA2ORG 0x3d04 | |
48 | 268 |
1 | 269 #define BESB1C3ORG 0x3d68 |
270 #define BESB1CORG 0x3d18 | |
271 #define BESB1ORG 0x3d08 | |
48 | 272 |
1 | 273 #define BESB2C3ORG 0x3d6C |
274 #define BESB2CORG 0x3d1C | |
275 #define BESB2ORG 0x3d0C | |
48 | 276 |
1 | 277 #define BESHCOORD 0x3d28 |
278 #define BESHISCAL 0x3d30 | |
279 #define BESHSRCEND 0x3d3C | |
280 #define BESHSRCLST 0x3d50 | |
281 #define BESHSRCST 0x3d38 | |
282 #define BESV1WGHT 0x3d48 | |
283 #define BESV2WGHT 0x3d4c | |
284 #define BESV1SRCLST 0x3d54 | |
285 #define BESV2SRCLST 0x3d58 | |
286 #define BESVISCAL 0x3d34 | |
287 #define BESVCOORD 0x3d2c | |
288 #define BESSTATUS 0x3dc4 | |
289 | |
48 | 290 #define CRTCX 0x1fd4 |
291 #define CRTCD 0x1fd5 | |
292 #define IEN 0x1e1c | |
293 #define ICLEAR 0x1e18 | |
294 #define STATUS 0x1e14 | |
295 | |
296 static int mga_next_frame=0; | |
1 | 297 |
2344 | 298 #ifdef CRTC2 |
299 static void crtc2_frame_sel(int frame) | |
300 { | |
301 switch(frame) { | |
302 case 0: | |
303 cregs.c2pl2startadd0=regs.besa1corg; | |
304 cregs.c2pl3startadd0=regs.besa1c3org; | |
305 cregs.c2startadd0=regs.besa1org; | |
306 break; | |
307 case 1: | |
308 cregs.c2pl2startadd0=regs.besa2corg; | |
309 cregs.c2pl3startadd0=regs.besa2c3org; | |
310 cregs.c2startadd0=regs.besa2org; | |
311 break; | |
312 case 2: | |
313 cregs.c2pl2startadd0=regs.besb1corg; | |
314 cregs.c2pl3startadd0=regs.besb1c3org; | |
315 cregs.c2startadd0=regs.besb1org; | |
316 break; | |
317 case 3: | |
318 cregs.c2pl2startadd0=regs.besb2corg; | |
319 cregs.c2pl3startadd0=regs.besb2c3org; | |
320 cregs.c2startadd0=regs.besb2org; | |
321 break; | |
322 } | |
323 writel(cregs.c2startadd0, mga_mmio_base + C2STARTADD0); | |
324 writel(cregs.c2pl2startadd0, mga_mmio_base + C2PL2STARTADD0); | |
325 writel(cregs.c2pl3startadd0, mga_mmio_base + C2PL3STARTADD0); | |
326 } | |
327 #endif | |
328 | |
1 | 329 static void mga_vid_frame_sel(int frame) |
330 { | |
48 | 331 if ( mga_irq != -1 ) { |
332 mga_next_frame=frame; | |
333 } else { | |
334 | |
1 | 335 //we don't need the vcount protection as we're only hitting |
336 //one register (and it doesn't seem to be double buffered) | |
337 regs.besctl = (regs.besctl & ~0x07000000) + (frame << 25); | |
338 writel( regs.besctl, mga_mmio_base + BESCTL ); | |
68 | 339 |
340 // writel( regs.besglobctl + ((readl(mga_mmio_base + VCOUNT)+2)<<16), | |
341 writel( regs.besglobctl + (MGA_VSYNC_POS<<16), | |
342 mga_mmio_base + BESGLOBCTL); | |
2344 | 343 #ifdef CRTC2 |
344 crtc2_frame_sel(frame); | |
345 #endif | |
68 | 346 |
48 | 347 } |
1 | 348 } |
349 | |
350 | |
2086 | 351 static void mga_vid_write_regs(int restore) |
1 | 352 { |
353 //Make sure internal registers don't get updated until we're done | |
354 writel( (readl(mga_mmio_base + VCOUNT)-1)<<16, | |
355 mga_mmio_base + BESGLOBCTL); | |
356 | |
357 // color or coordinate keying | |
2086 | 358 |
359 if(restore && colkey_saved){ | |
360 // restore it | |
361 colkey_saved=0; | |
362 | |
363 printk("mga_vid: Restoring colorkey (ON: %d %02X:%02X:%02X)\n", | |
364 colkey_on,colkey_color[0],colkey_color[1],colkey_color[2]); | |
365 | |
366 // Set color key registers: | |
367 writeb( XKEYOPMODE, mga_mmio_base + PALWTADD); | |
368 writeb( colkey_on, mga_mmio_base + X_DATAREG); | |
369 | |
370 writeb( XCOLKEY0RED, mga_mmio_base + PALWTADD); | |
371 writeb( colkey_color[0], mga_mmio_base + X_DATAREG); | |
372 writeb( XCOLKEY0GREEN, mga_mmio_base + PALWTADD); | |
373 writeb( colkey_color[1], mga_mmio_base + X_DATAREG); | |
374 writeb( XCOLKEY0BLUE, mga_mmio_base + PALWTADD); | |
375 writeb( colkey_color[2], mga_mmio_base + X_DATAREG); | |
376 writeb( X_COLKEY, mga_mmio_base + PALWTADD); | |
377 writeb( colkey_color[3], mga_mmio_base + X_DATAREG); | |
378 | |
379 writeb( XCOLMSK0RED, mga_mmio_base + PALWTADD); | |
380 writeb( colkey_mask[0], mga_mmio_base + X_DATAREG); | |
381 writeb( XCOLMSK0GREEN, mga_mmio_base + PALWTADD); | |
382 writeb( colkey_mask[1], mga_mmio_base + X_DATAREG); | |
383 writeb( XCOLMSK0BLUE, mga_mmio_base + PALWTADD); | |
384 writeb( colkey_mask[2], mga_mmio_base + X_DATAREG); | |
385 writeb( XCOLMSK, mga_mmio_base + PALWTADD); | |
386 writeb( colkey_mask[3], mga_mmio_base + X_DATAREG); | |
387 | |
388 } else if(!colkey_saved){ | |
389 // save it | |
390 colkey_saved=1; | |
391 // Get color key registers: | |
392 writeb( XKEYOPMODE, mga_mmio_base + PALWTADD); | |
393 colkey_on=(unsigned char)readb(mga_mmio_base + X_DATAREG) & 1; | |
394 | |
395 writeb( XCOLKEY0RED, mga_mmio_base + PALWTADD); | |
396 colkey_color[0]=(unsigned char)readb(mga_mmio_base + X_DATAREG); | |
397 writeb( XCOLKEY0GREEN, mga_mmio_base + PALWTADD); | |
398 colkey_color[1]=(unsigned char)readb(mga_mmio_base + X_DATAREG); | |
399 writeb( XCOLKEY0BLUE, mga_mmio_base + PALWTADD); | |
400 colkey_color[2]=(unsigned char)readb(mga_mmio_base + X_DATAREG); | |
401 writeb( X_COLKEY, mga_mmio_base + PALWTADD); | |
402 colkey_color[3]=(unsigned char)readb(mga_mmio_base + X_DATAREG); | |
403 | |
404 writeb( XCOLMSK0RED, mga_mmio_base + PALWTADD); | |
405 colkey_mask[0]=(unsigned char)readb(mga_mmio_base + X_DATAREG); | |
406 writeb( XCOLMSK0GREEN, mga_mmio_base + PALWTADD); | |
407 colkey_mask[1]=(unsigned char)readb(mga_mmio_base + X_DATAREG); | |
408 writeb( XCOLMSK0BLUE, mga_mmio_base + PALWTADD); | |
409 colkey_mask[2]=(unsigned char)readb(mga_mmio_base + X_DATAREG); | |
410 writeb( XCOLMSK, mga_mmio_base + PALWTADD); | |
411 colkey_mask[3]=(unsigned char)readb(mga_mmio_base + X_DATAREG); | |
412 | |
413 printk("mga_vid: Saved colorkey (ON: %d %02X:%02X:%02X)\n", | |
414 colkey_on,colkey_color[0],colkey_color[1],colkey_color[2]); | |
415 | |
416 } | |
417 | |
418 if(!restore){ | |
1 | 419 writeb( XKEYOPMODE, mga_mmio_base + PALWTADD); |
420 writeb( mga_config.colkey_on, mga_mmio_base + X_DATAREG); | |
421 if ( mga_config.colkey_on ) | |
422 { | |
423 uint32_t r=0, g=0, b=0; | |
424 | |
425 writeb( XMULCTRL, mga_mmio_base + PALWTADD); | |
426 switch (readb (mga_mmio_base + X_DATAREG)) | |
427 { | |
428 case BPP_8: | |
429 /* Need to look up the color index, just using | |
430 color 0 for now. */ | |
431 break; | |
432 | |
433 case BPP_15: | |
434 r = mga_config.colkey_red >> 3; | |
435 g = mga_config.colkey_green >> 3; | |
436 b = mga_config.colkey_blue >> 3; | |
437 break; | |
438 | |
439 case BPP_16: | |
440 r = mga_config.colkey_red >> 3; | |
441 g = mga_config.colkey_green >> 2; | |
442 b = mga_config.colkey_blue >> 3; | |
443 break; | |
444 | |
445 case BPP_24: | |
446 case BPP_32_DIR: | |
447 case BPP_32_PAL: | |
448 r = mga_config.colkey_red; | |
449 g = mga_config.colkey_green; | |
450 b = mga_config.colkey_blue; | |
451 break; | |
452 } | |
453 | |
454 // Disable color keying on alpha channel | |
455 writeb( XCOLMSK, mga_mmio_base + PALWTADD); | |
456 writeb( 0x00, mga_mmio_base + X_DATAREG); | |
457 writeb( X_COLKEY, mga_mmio_base + PALWTADD); | |
458 writeb( 0x00, mga_mmio_base + X_DATAREG); | |
459 | |
2086 | 460 |
1 | 461 // Set up color key registers |
462 writeb( XCOLKEY0RED, mga_mmio_base + PALWTADD); | |
463 writeb( r, mga_mmio_base + X_DATAREG); | |
464 writeb( XCOLKEY0GREEN, mga_mmio_base + PALWTADD); | |
465 writeb( g, mga_mmio_base + X_DATAREG); | |
466 writeb( XCOLKEY0BLUE, mga_mmio_base + PALWTADD); | |
467 writeb( b, mga_mmio_base + X_DATAREG); | |
468 | |
469 // Set up color key mask registers | |
470 writeb( XCOLMSK0RED, mga_mmio_base + PALWTADD); | |
471 writeb( 0xff, mga_mmio_base + X_DATAREG); | |
472 writeb( XCOLMSK0GREEN, mga_mmio_base + PALWTADD); | |
473 writeb( 0xff, mga_mmio_base + X_DATAREG); | |
474 writeb( XCOLMSK0BLUE, mga_mmio_base + PALWTADD); | |
475 writeb( 0xff, mga_mmio_base + X_DATAREG); | |
476 } | |
477 | |
2086 | 478 } |
479 | |
1 | 480 // Backend Scaler |
481 writel( regs.besctl, mga_mmio_base + BESCTL); | |
482 if(is_g400) | |
483 writel( regs.beslumactl, mga_mmio_base + BESLUMACTL); | |
484 writel( regs.bespitch, mga_mmio_base + BESPITCH); | |
485 | |
486 writel( regs.besa1org, mga_mmio_base + BESA1ORG); | |
487 writel( regs.besa1corg, mga_mmio_base + BESA1CORG); | |
48 | 488 writel( regs.besa2org, mga_mmio_base + BESA2ORG); |
489 writel( regs.besa2corg, mga_mmio_base + BESA2CORG); | |
1 | 490 writel( regs.besb1org, mga_mmio_base + BESB1ORG); |
491 writel( regs.besb1corg, mga_mmio_base + BESB1CORG); | |
48 | 492 writel( regs.besb2org, mga_mmio_base + BESB2ORG); |
493 writel( regs.besb2corg, mga_mmio_base + BESB2CORG); | |
1 | 494 if(is_g400) |
495 { | |
496 writel( regs.besa1c3org, mga_mmio_base + BESA1C3ORG); | |
48 | 497 writel( regs.besa2c3org, mga_mmio_base + BESA2C3ORG); |
1 | 498 writel( regs.besb1c3org, mga_mmio_base + BESB1C3ORG); |
48 | 499 writel( regs.besb2c3org, mga_mmio_base + BESB2C3ORG); |
1 | 500 } |
501 | |
502 writel( regs.beshcoord, mga_mmio_base + BESHCOORD); | |
503 writel( regs.beshiscal, mga_mmio_base + BESHISCAL); | |
504 writel( regs.beshsrcst, mga_mmio_base + BESHSRCST); | |
505 writel( regs.beshsrcend, mga_mmio_base + BESHSRCEND); | |
506 writel( regs.beshsrclst, mga_mmio_base + BESHSRCLST); | |
507 | |
508 writel( regs.besvcoord, mga_mmio_base + BESVCOORD); | |
509 writel( regs.besviscal, mga_mmio_base + BESVISCAL); | |
48 | 510 |
1 | 511 writel( regs.besv1srclst, mga_mmio_base + BESV1SRCLST); |
512 writel( regs.besv1wght, mga_mmio_base + BESV1WGHT); | |
48 | 513 writel( regs.besv2srclst, mga_mmio_base + BESV2SRCLST); |
514 writel( regs.besv2wght, mga_mmio_base + BESV2WGHT); | |
1 | 515 |
516 //update the registers somewhere between 1 and 2 frames from now. | |
517 writel( regs.besglobctl + ((readl(mga_mmio_base + VCOUNT)+2)<<16), | |
518 mga_mmio_base + BESGLOBCTL); | |
519 | |
77 | 520 #if 0 |
61 | 521 printk(KERN_DEBUG "mga_vid: wrote BES registers\n"); |
522 printk(KERN_DEBUG "mga_vid: BESCTL = 0x%08x\n", | |
1 | 523 readl(mga_mmio_base + BESCTL)); |
61 | 524 printk(KERN_DEBUG "mga_vid: BESGLOBCTL = 0x%08x\n", |
1 | 525 readl(mga_mmio_base + BESGLOBCTL)); |
61 | 526 printk(KERN_DEBUG "mga_vid: BESSTATUS= 0x%08x\n", |
1 | 527 readl(mga_mmio_base + BESSTATUS)); |
77 | 528 #endif |
2344 | 529 #ifdef CRTC2 |
530 // printk("c2ctl:0x%08x c2datactl:0x%08x\n",readl(mga_mmio_base + C2CTL),readl(mga_mmio_base + C2DATACTL)); | |
531 // printk("c2misc:0x%08x\n",readl(mga_mmio_base + C2MISC)); | |
532 // printk("c2ctl:0x%08x c2datactl:0x%08x\n",cregs.c2ctl,cregs.c2datactl); | |
533 | |
534 // writel(cregs.c2ctl, mga_mmio_base + C2CTL); | |
535 | |
536 writel(((readl(mga_mmio_base + C2CTL) & ~0x03e00000) + (cregs.c2ctl & 0x03e00000)), mga_mmio_base + C2CTL); | |
537 writel(((readl(mga_mmio_base + C2DATACTL) & ~0x000000ff) + (cregs.c2datactl & 0x000000ff)), mga_mmio_base + C2DATACTL); | |
538 // ctrc2 | |
539 // disable CRTC2 acording to specs | |
540 // writel(cregs.c2ctl & 0xfffffff0, mga_mmio_base + C2CTL); | |
541 // je to treba ??? | |
542 // writeb((readb(mga_mmio_base + XMISCCTRL) & 0x19) | 0xa2, mga_mmio_base + XMISCCTRL); // MAFC - mfcsel & vdoutsel | |
543 // writeb((readb(mga_mmio_base + XMISCCTRL) & 0x19) | 0x92, mga_mmio_base + XMISCCTRL); | |
544 // writeb((readb(mga_mmio_base + XMISCCTRL) & ~0xe9) + 0xa2, mga_mmio_base + XMISCCTRL); | |
545 // writel(cregs.c2datactl, mga_mmio_base + C2DATACTL); | |
546 // writel(cregs.c2hparam, mga_mmio_base + C2HPARAM); | |
547 // writel(cregs.c2hsync, mga_mmio_base + C2HSYNC); | |
548 // writel(cregs.c2vparam, mga_mmio_base + C2VPARAM); | |
549 // writel(cregs.c2vsync, mga_mmio_base + C2VSYNC); | |
550 writel(cregs.c2misc, mga_mmio_base + C2MISC); | |
551 | |
552 printk("c2offset = %d\n",cregs.c2offset); | |
553 | |
554 writel(cregs.c2offset, mga_mmio_base + C2OFFSET); | |
555 writel(cregs.c2startadd0, mga_mmio_base + C2STARTADD0); | |
556 // writel(cregs.c2startadd1, mga_mmio_base + C2STARTADD1); | |
557 writel(cregs.c2pl2startadd0, mga_mmio_base + C2PL2STARTADD0); | |
558 // writel(cregs.c2pl2startadd1, mga_mmio_base + C2PL2STARTADD1); | |
559 writel(cregs.c2pl3startadd0, mga_mmio_base + C2PL3STARTADD0); | |
560 // writel(cregs.c2pl3startadd1, mga_mmio_base + C2PL3STARTADD1); | |
561 writel(cregs.c2spicstartadd0, mga_mmio_base + C2SPICSTARTADD0); | |
562 // writel(cregs.c2spicstartadd1, mga_mmio_base + C2SPICSTARTADD1); | |
563 // writel(cregs.c2subpiclut, mga_mmio_base + C2SUBPICLUT); | |
564 // writel(cregs.c2preload, mga_mmio_base + C2PRELOAD); | |
565 // finaly enable everything | |
566 // writel(cregs.c2ctl, mga_mmio_base + C2CTL); | |
567 // printk("c2ctl:0x%08x c2datactl:0x%08x\n",readl(mga_mmio_base + C2CTL),readl(mga_mmio_base + C2DATACTL)); | |
568 // printk("c2misc:0x%08x\n", readl(mga_mmio_base + C2MISC)); | |
569 #endif | |
1 | 570 } |
571 | |
572 static int mga_vid_set_config(mga_vid_config_t *config) | |
573 { | |
574 int x, y, sw, sh, dw, dh; | |
575 int besleft, bestop, ifactor, ofsleft, ofstop, baseadrofs, weight, weights; | |
57 | 576 int frame_size=config->frame_size; |
2344 | 577 #ifdef CRTC2 |
578 #define right_margin 0 | |
579 #define left_margin 18 | |
580 #define hsync_len 46 | |
581 #define lower_margin 10 | |
582 #define vsync_len 4 | |
583 #define upper_margin 39 | |
584 | |
585 unsigned int hdispend = (config->src_width + 31) & ~31; | |
586 unsigned int hsyncstart = hdispend + (right_margin & ~7); | |
587 unsigned int hsyncend = hsyncstart + (hsync_len & ~7); | |
588 unsigned int htotal = hsyncend + (left_margin & ~7); | |
589 unsigned int vdispend = config->src_height; | |
590 unsigned int vsyncstart = vdispend + lower_margin; | |
591 unsigned int vsyncend = vsyncstart + vsync_len; | |
592 unsigned int vtotal = vsyncend + upper_margin; | |
593 #endif | |
1 | 594 x = config->x_org; |
595 y = config->y_org; | |
596 sw = config->src_width; | |
597 sh = config->src_height; | |
598 dw = config->dest_width; | |
599 dh = config->dest_height; | |
600 | |
61 | 601 printk(KERN_DEBUG "mga_vid: Setting up a %dx%d+%d+%d video window (src %dx%d) format %X\n", |
1 | 602 dw, dh, x, y, sw, sh, config->format); |
603 | |
604 //FIXME check that window is valid and inside desktop | |
605 | |
606 //FIXME figure out a better way to allocate memory on card | |
607 //allocate 2 megs | |
608 //mga_src_base = mga_mem_base + (MGA_VIDMEM_SIZE-2) * 0x100000; | |
57 | 609 //mga_src_base = (MGA_VIDMEM_SIZE-3) * 0x100000; |
1 | 610 |
611 | |
612 //Setup the BES registers for a three plane 4:2:0 video source | |
613 | |
466 | 614 regs.besglobctl = 0; |
615 | |
1 | 616 switch(config->format){ |
617 case MGA_VID_FORMAT_YV12: | |
470 | 618 case MGA_VID_FORMAT_I420: |
619 case MGA_VID_FORMAT_IYUV: | |
1 | 620 regs.besctl = 1 // BES enabled |
621 + (0<<6) // even start polarity | |
622 + (1<<10) // x filtering enabled | |
623 + (1<<11) // y filtering enabled | |
624 + (1<<16) // chroma upsampling | |
625 + (1<<17) // 4:2:0 mode | |
626 + (1<<18); // dither enabled | |
466 | 627 #if 0 |
1 | 628 if(is_g400) |
629 { | |
630 //zoom disabled, zoom filter disabled, 420 3 plane format, proc amp | |
631 //disabled, rgb mode disabled | |
632 regs.besglobctl = (1<<5); | |
633 } | |
634 else | |
635 { | |
636 //zoom disabled, zoom filter disabled, Cb samples in 0246, Cr | |
637 //in 1357, BES register update on besvcnt | |
466 | 638 regs.besglobctl = 0; |
1 | 639 } |
466 | 640 #endif |
1 | 641 break; |
642 | |
643 case MGA_VID_FORMAT_YUY2: | |
644 regs.besctl = 1 // BES enabled | |
645 + (0<<6) // even start polarity | |
646 + (1<<10) // x filtering enabled | |
647 + (1<<11) // y filtering enabled | |
648 + (1<<16) // chroma upsampling | |
649 + (0<<17) // 4:2:2 mode | |
650 + (1<<18); // dither enabled | |
651 | |
652 regs.besglobctl = 0; // YUY2 format selected | |
653 break; | |
466 | 654 |
655 case MGA_VID_FORMAT_UYVY: | |
656 regs.besctl = 1 // BES enabled | |
657 + (0<<6) // even start polarity | |
658 + (1<<10) // x filtering enabled | |
659 + (1<<11) // y filtering enabled | |
660 + (1<<16) // chroma upsampling | |
661 + (0<<17) // 4:2:2 mode | |
662 + (1<<18); // dither enabled | |
663 | |
664 regs.besglobctl = 1<<6; // UYVY format selected | |
665 break; | |
666 | |
1 | 667 default: |
61 | 668 printk(KERN_ERR "mga_vid: Unsupported pixel format: 0x%X\n",config->format); |
1 | 669 return -1; |
670 } | |
671 | |
672 | |
673 //Disable contrast and brightness control | |
466 | 674 regs.besglobctl |= (1<<5) + (1<<7); |
1 | 675 regs.beslumactl = (0x7f << 16) + (0x80<<0); |
676 regs.beslumactl = 0x80<<0; | |
677 | |
678 //Setup destination window boundaries | |
679 besleft = x > 0 ? x : 0; | |
680 bestop = y > 0 ? y : 0; | |
681 regs.beshcoord = (besleft<<16) + (x + dw-1); | |
682 regs.besvcoord = (bestop<<16) + (y + dh-1); | |
683 | |
684 //Setup source dimensions | |
685 regs.beshsrclst = (sw - 1) << 16; | |
686 regs.bespitch = (sw + 31) & ~31 ; | |
687 | |
688 //Setup horizontal scaling | |
689 ifactor = ((sw-1)<<14)/(dw-1); | |
690 ofsleft = besleft - x; | |
691 | |
692 regs.beshiscal = ifactor<<2; | |
693 regs.beshsrcst = (ofsleft*ifactor)<<2; | |
694 regs.beshsrcend = regs.beshsrcst + (((dw - ofsleft - 1) * ifactor) << 2); | |
695 | |
696 //Setup vertical scaling | |
697 ifactor = ((sh-1)<<14)/(dh-1); | |
698 ofstop = bestop - y; | |
699 | |
700 regs.besviscal = ifactor<<2; | |
701 | |
702 baseadrofs = ((ofstop*regs.besviscal)>>16)*regs.bespitch; | |
57 | 703 //frame_size = ((sw + 31) & ~31) * sh + (((sw + 31) & ~31) * sh) / 2; |
1 | 704 regs.besa1org = (uint32_t) mga_src_base + baseadrofs; |
48 | 705 regs.besa2org = (uint32_t) mga_src_base + baseadrofs + 1*frame_size; |
706 regs.besb1org = (uint32_t) mga_src_base + baseadrofs + 2*frame_size; | |
707 regs.besb2org = (uint32_t) mga_src_base + baseadrofs + 3*frame_size; | |
1 | 708 |
470 | 709 if(config->format==MGA_VID_FORMAT_YV12 |
710 ||config->format==MGA_VID_FORMAT_IYUV | |
711 ||config->format==MGA_VID_FORMAT_I420 | |
712 ){ | |
57 | 713 // planar YUV frames: |
1 | 714 if (is_g400) |
715 baseadrofs = (((ofstop*regs.besviscal)/4)>>16)*regs.bespitch; | |
716 else | |
717 baseadrofs = (((ofstop*regs.besviscal)/2)>>16)*regs.bespitch; | |
718 | |
470 | 719 if(config->format==MGA_VID_FORMAT_YV12){ |
1 | 720 regs.besa1corg = (uint32_t) mga_src_base + baseadrofs + regs.bespitch * sh ; |
48 | 721 regs.besa2corg = (uint32_t) mga_src_base + baseadrofs + 1*frame_size + regs.bespitch * sh; |
722 regs.besb1corg = (uint32_t) mga_src_base + baseadrofs + 2*frame_size + regs.bespitch * sh; | |
723 regs.besb2corg = (uint32_t) mga_src_base + baseadrofs + 3*frame_size + regs.bespitch * sh; | |
1 | 724 regs.besa1c3org = regs.besa1corg + ((regs.bespitch * sh) / 4); |
48 | 725 regs.besa2c3org = regs.besa2corg + ((regs.bespitch * sh) / 4); |
1 | 726 regs.besb1c3org = regs.besb1corg + ((regs.bespitch * sh) / 4); |
48 | 727 regs.besb2c3org = regs.besb2corg + ((regs.bespitch * sh) / 4); |
470 | 728 } else { |
729 regs.besa1c3org = (uint32_t) mga_src_base + baseadrofs + regs.bespitch * sh ; | |
730 regs.besa2c3org = (uint32_t) mga_src_base + baseadrofs + 1*frame_size + regs.bespitch * sh; | |
731 regs.besb1c3org = (uint32_t) mga_src_base + baseadrofs + 2*frame_size + regs.bespitch * sh; | |
732 regs.besb2c3org = (uint32_t) mga_src_base + baseadrofs + 3*frame_size + regs.bespitch * sh; | |
733 regs.besa1corg = regs.besa1c3org + ((regs.bespitch * sh) / 4); | |
734 regs.besa2corg = regs.besa2c3org + ((regs.bespitch * sh) / 4); | |
735 regs.besb1corg = regs.besb1c3org + ((regs.bespitch * sh) / 4); | |
736 regs.besb2corg = regs.besb2c3org + ((regs.bespitch * sh) / 4); | |
737 } | |
738 | |
57 | 739 } |
1 | 740 |
741 weight = ofstop * (regs.besviscal >> 2); | |
742 weights = weight < 0 ? 1 : 0; | |
48 | 743 regs.besv2wght = regs.besv1wght = (weights << 16) + ((weight & 0x3FFF) << 2); |
744 regs.besv2srclst = regs.besv1srclst = sh - 1 - (((ofstop * regs.besviscal) >> 16) & 0x03FF); | |
1 | 745 |
2344 | 746 #ifdef CRTC2 |
747 // pridat hlavni registry - tj. casovani ... | |
748 | |
749 | |
750 switch(config->format){ | |
751 case MGA_VID_FORMAT_YV12: | |
752 case MGA_VID_FORMAT_I420: | |
753 case MGA_VID_FORMAT_IYUV: | |
754 cregs.c2ctl = 1 // CRTC2 enabled | |
755 + (1<<1) // external clock | |
756 + (0<<2) // external clock | |
757 + (1<<3) // pixel clock enable - not needed ??? | |
758 + (0<<4) // high prioryty req | |
759 + (1<<5) // high prioryty req | |
760 + (0<<6) // high prioryty req | |
761 + (1<<8) // high prioryty req max | |
762 + (0<<9) // high prioryty req max | |
763 + (0<<10) // high prioryty req max | |
764 + (0<<20) // CRTC1 to DAC | |
765 + (1<<21) // 420 mode | |
766 + (1<<22) // 420 mode | |
767 + (1<<23) // 420 mode | |
768 + (0<<24) // single chroma line for 420 mode - need to be corrected | |
769 + (0<<25) /*/ interlace mode - need to be corrected*/ | |
770 + (0<<26) // field legth polariry | |
771 + (0<<27) // field identification polariry | |
772 + (1<<28) // VIDRST detection mode | |
773 + (0<<29) // VIDRST detection mode | |
774 + (1<<30) // Horizontal counter preload | |
775 + (1<<31) // Vertical counter preload | |
776 ; | |
777 cregs.c2datactl = 1 // disable dither - propably not needed, we are already in YUV mode | |
778 + (1<<1) // Y filter enable | |
779 + (1<<2) // CbCr filter enable | |
780 + (0<<3) // subpicture enable (disabled) | |
781 + (0<<4) // NTSC enable (disabled - PAL) | |
782 + (0<<5) // C2 static subpicture enable (disabled) | |
783 + (0<<6) // C2 subpicture offset division (disabled) | |
784 + (0<<7) // 422 subformat selection ! | |
785 /* + (0<<8) // 15 bpp high alpha | |
786 + (0<<9) // 15 bpp high alpha | |
787 + (0<<10) // 15 bpp high alpha | |
788 + (0<<11) // 15 bpp high alpha | |
789 + (0<<12) // 15 bpp high alpha | |
790 + (0<<13) // 15 bpp high alpha | |
791 + (0<<14) // 15 bpp high alpha | |
792 + (0<<15) // 15 bpp high alpha | |
793 + (0<<16) // 15 bpp low alpha | |
794 + (0<<17) // 15 bpp low alpha | |
795 + (0<<18) // 15 bpp low alpha | |
796 + (0<<19) // 15 bpp low alpha | |
797 + (0<<20) // 15 bpp low alpha | |
798 + (0<<21) // 15 bpp low alpha | |
799 + (0<<22) // 15 bpp low alpha | |
800 + (0<<23) // 15 bpp low alpha | |
801 + (0<<24) // static subpicture key | |
802 + (0<<25) // static subpicture key | |
803 + (0<<26) // static subpicture key | |
804 + (0<<27) // static subpicture key | |
805 + (0<<28) // static subpicture key | |
806 */ ; | |
807 break; | |
808 | |
809 case MGA_VID_FORMAT_YUY2: | |
810 cregs.c2ctl = 1 // CRTC2 enabled | |
811 + (1<<1) // external clock | |
812 + (0<<2) // external clock | |
813 + (1<<3) // pixel clock enable - not needed ??? | |
814 + (0<<4) // high prioryty req - acc to spec | |
815 + (1<<5) // high prioryty req | |
816 + (0<<6) // high prioryty req | |
817 // 7 reserved | |
818 + (1<<8) // high prioryty req max | |
819 + (0<<9) // high prioryty req max | |
820 + (0<<10) // high prioryty req max | |
821 // 11-19 reserved | |
822 + (0<<20) // CRTC1 to DAC | |
823 + (1<<21) // 422 mode | |
824 + (0<<22) // 422 mode | |
825 + (1<<23) // 422 mode | |
826 + (0<<24) // single chroma line for 420 mode - need to be corrected | |
827 + (0<<25) /*/ interlace mode - need to be corrected*/ | |
828 + (0<<26) // field legth polariry | |
829 + (0<<27) // field identification polariry | |
830 + (1<<28) // VIDRST detection mode | |
831 + (0<<29) // VIDRST detection mode | |
832 + (1<<30) // Horizontal counter preload | |
833 + (1<<31) // Vertical counter preload | |
834 ; | |
835 cregs.c2datactl = 1 // disable dither - propably not needed, we are already in YUV mode | |
836 + (1<<1) // Y filter enable | |
837 + (1<<2) // CbCr filter enable | |
838 + (0<<3) // subpicture enable (disabled) | |
839 + (0<<4) // NTSC enable (disabled - PAL) | |
840 + (0<<5) // C2 static subpicture enable (disabled) | |
841 + (0<<6) // C2 subpicture offset division (disabled) | |
842 + (0<<7) // 422 subformat selection ! | |
843 /* + (0<<8) // 15 bpp high alpha | |
844 + (0<<9) // 15 bpp high alpha | |
845 + (0<<10) // 15 bpp high alpha | |
846 + (0<<11) // 15 bpp high alpha | |
847 + (0<<12) // 15 bpp high alpha | |
848 + (0<<13) // 15 bpp high alpha | |
849 + (0<<14) // 15 bpp high alpha | |
850 + (0<<15) // 15 bpp high alpha | |
851 + (0<<16) // 15 bpp low alpha | |
852 + (0<<17) // 15 bpp low alpha | |
853 + (0<<18) // 15 bpp low alpha | |
854 + (0<<19) // 15 bpp low alpha | |
855 + (0<<20) // 15 bpp low alpha | |
856 + (0<<21) // 15 bpp low alpha | |
857 + (0<<22) // 15 bpp low alpha | |
858 + (0<<23) // 15 bpp low alpha | |
859 + (0<<24) // static subpicture key | |
860 + (0<<25) // static subpicture key | |
861 + (0<<26) // static subpicture key | |
862 + (0<<27) // static subpicture key | |
863 + (0<<28) // static subpicture key | |
864 */ ; | |
865 break; | |
866 | |
867 case MGA_VID_FORMAT_UYVY: | |
868 cregs.c2ctl = 1 // CRTC2 enabled | |
869 + (1<<1) // external clock | |
870 + (0<<2) // external clock | |
871 + (1<<3) // pixel clock enable - not needed ??? | |
872 + (0<<4) // high prioryty req | |
873 + (1<<5) // high prioryty req | |
874 + (0<<6) // high prioryty req | |
875 + (1<<8) // high prioryty req max | |
876 + (0<<9) // high prioryty req max | |
877 + (0<<10) // high prioryty req max | |
878 + (0<<20) // CRTC1 to DAC | |
879 + (1<<21) // 422 mode | |
880 + (0<<22) // 422 mode | |
881 + (1<<23) // 422 mode | |
882 + (1<<24) // single chroma line for 420 mode - need to be corrected | |
883 + (1<<25) /*/ interlace mode - need to be corrected*/ | |
884 + (0<<26) // field legth polariry | |
885 + (0<<27) // field identification polariry | |
886 + (1<<28) // VIDRST detection mode | |
887 + (0<<29) // VIDRST detection mode | |
888 + (1<<30) // Horizontal counter preload | |
889 + (1<<31) // Vertical counter preload | |
890 ; | |
891 cregs.c2datactl = 0 // enable dither - propably not needed, we are already in YUV mode | |
892 + (1<<1) // Y filter enable | |
893 + (1<<2) // CbCr filter enable | |
894 + (0<<3) // subpicture enable (disabled) | |
895 + (0<<4) // NTSC enable (disabled - PAL) | |
896 + (0<<5) // C2 static subpicture enable (disabled) | |
897 + (0<<6) // C2 subpicture offset division (disabled) | |
898 + (1<<7) // 422 subformat selection ! | |
899 /* + (0<<8) // 15 bpp high alpha | |
900 + (0<<9) // 15 bpp high alpha | |
901 + (0<<10) // 15 bpp high alpha | |
902 + (0<<11) // 15 bpp high alpha | |
903 + (0<<12) // 15 bpp high alpha | |
904 + (0<<13) // 15 bpp high alpha | |
905 + (0<<14) // 15 bpp high alpha | |
906 + (0<<15) // 15 bpp high alpha | |
907 + (0<<16) // 15 bpp low alpha | |
908 + (0<<17) // 15 bpp low alpha | |
909 + (0<<18) // 15 bpp low alpha | |
910 + (0<<19) // 15 bpp low alpha | |
911 + (0<<20) // 15 bpp low alpha | |
912 + (0<<21) // 15 bpp low alpha | |
913 + (0<<22) // 15 bpp low alpha | |
914 + (0<<23) // 15 bpp low alpha | |
915 + (0<<24) // static subpicture key | |
916 + (0<<25) // static subpicture key | |
917 + (0<<26) // static subpicture key | |
918 + (0<<27) // static subpicture key | |
919 + (0<<28) // static subpicture key | |
920 */ ; | |
921 break; | |
922 | |
923 default: | |
924 printk(KERN_ERR "mga_vid: Unsupported pixel format: 0x%X\n",config->format); | |
925 return -1; | |
926 } | |
927 | |
928 cregs.c2hparam=((hdispend - 8) << 16) | (htotal - 8); | |
929 cregs.c2hsync=((hsyncend - 8) << 16) | (hsyncstart - 8); | |
930 | |
931 cregs.c2misc=0 // CRTCV2 656 togg f0 | |
932 +(0<<1) // CRTCV2 656 togg f0 | |
933 +(0<<2) // CRTCV2 656 togg f0 | |
934 +(0<<4) // CRTCV2 656 togg f1 | |
935 +(0<<5) // CRTCV2 656 togg f1 | |
936 +(0<<6) // CRTCV2 656 togg f1 | |
937 +(0<<8) // Hsync active high | |
938 +(0<<9) // Vsync active high | |
939 // 16-27 c2vlinecomp - nevim co tam dat | |
940 ; | |
941 cregs.c2offset=(regs.bespitch << 1); | |
942 | |
943 cregs.c2pl2startadd0=regs.besa1corg; | |
944 // cregs.c2pl2startadd1=regs.besa2corg; | |
945 cregs.c2pl3startadd0=regs.besa1c3org; | |
946 // cregs.c2pl3startadd1=regs.besa2c3org; | |
947 | |
948 cregs.c2preload=(vsyncstart << 16) | (hsyncstart); // from | |
949 | |
950 cregs.c2spicstartadd0=0; // not used | |
951 // cregs.c2spicstartadd1=0; // not used | |
952 | |
953 cregs.c2startadd0=regs.besa1org; | |
954 // cregs.c2startadd1=regs.besa2org; | |
955 | |
956 cregs.c2subpiclut=0; //not used | |
957 | |
958 cregs.c2vparam=((vdispend - 1) << 16) | (vtotal - 1); | |
959 cregs.c2vsync=((vsyncend - 1) << 16) | (vsyncstart - 1); | |
960 | |
961 | |
962 #endif | |
963 | |
2086 | 964 mga_vid_write_regs(0); |
1 | 965 return 0; |
966 } | |
967 | |
68 | 968 #ifdef MGA_ALLOW_IRQ |
969 | |
48 | 970 static void enable_irq(){ |
971 long int cc; | |
972 | |
973 cc = readl(mga_mmio_base + IEN); | |
63 | 974 // printk(KERN_ALERT "*** !!! IRQREG = %d\n", (int)(cc&0xff)); |
48 | 975 |
976 writeb( 0x11, mga_mmio_base + CRTCX); | |
977 | |
978 writeb(0x20, mga_mmio_base + CRTCD ); /* clear 0, enable off */ | |
979 writeb(0x00, mga_mmio_base + CRTCD ); /* enable on */ | |
980 writeb(0x10, mga_mmio_base + CRTCD ); /* clear = 1 */ | |
981 | |
982 writel( regs.besglobctl , mga_mmio_base + BESGLOBCTL); | |
983 | |
984 } | |
985 | |
986 static void disable_irq(){ | |
987 | |
988 writeb( 0x11, mga_mmio_base + CRTCX); | |
989 writeb(0x20, mga_mmio_base + CRTCD ); /* clear 0, enable off */ | |
990 | |
991 } | |
992 | |
993 void mga_handle_irq(int irq, void *dev_id, struct pt_regs *pregs) { | |
994 // static int frame=0; | |
854
76ca00724e12
gcc warnings fixed - patch by Aelius aelius@wish.net
arpi_esp
parents:
662
diff
changeset
|
995 // static int counter=0; |
48 | 996 long int cc; |
997 // if ( ! mga_enabled_flag ) return; | |
998 | |
68 | 999 // printk(KERN_DEBUG "vcount = %d\n",readl(mga_mmio_base + VCOUNT)); |
1000 | |
48 | 1001 //printk("mga_interrupt #%d\n", irq); |
1002 | |
1003 if ( irq != -1 ) { | |
1004 | |
1005 cc = readl(mga_mmio_base + STATUS); | |
1006 if ( ! (cc & 0x10) ) return; /* vsyncpen */ | |
1007 // debug_irqcnt++; | |
1008 } | |
1009 | |
1010 // if ( debug_irqignore ) { | |
1011 // debug_irqignore = 0; | |
1012 | |
1013 | |
1014 /* | |
1015 if ( mga_conf_deinterlace ) { | |
1016 if ( mga_first_field ) { | |
1017 // printk("mga_interrupt first field\n"); | |
1018 if ( syncfb_interrupt() ) | |
1019 mga_first_field = 0; | |
1020 } else { | |
1021 // printk("mga_interrupt second field\n"); | |
1022 mga_select_buffer( mga_current_field | 2 ); | |
1023 mga_first_field = 1; | |
1024 } | |
1025 } else { | |
1026 syncfb_interrupt(); | |
1027 } | |
1028 */ | |
1029 | |
1030 // frame=(frame+1)&1; | |
1031 regs.besctl = (regs.besctl & ~0x07000000) + (mga_next_frame << 25); | |
1032 writel( regs.besctl, mga_mmio_base + BESCTL ); | |
2344 | 1033 |
1034 #ifdef CRTC2 | |
1035 // sem pridat vyber obrazku !!!! | |
1036 crtc2_frame_sel(mga_next_frame); | |
1037 #endif | |
48 | 1038 |
1039 #if 0 | |
1040 ++counter; | |
1041 if(!(counter&63)){ | |
1042 printk("mga irq counter = %d\n",counter); | |
1043 } | |
1044 #endif | |
1045 | |
1046 // } else { | |
1047 // debug_irqignore = 1; | |
1048 // } | |
1049 | |
1050 if ( irq != -1 ) { | |
1051 writeb( 0x11, mga_mmio_base + CRTCX); | |
1052 writeb( 0, mga_mmio_base + CRTCD ); | |
1053 writeb( 0x10, mga_mmio_base + CRTCD ); | |
1054 } | |
1055 | |
1056 // writel( regs.besglobctl, mga_mmio_base + BESGLOBCTL); | |
1057 | |
1058 | |
1059 return; | |
1060 | |
1061 } | |
1062 | |
68 | 1063 #endif |
1 | 1064 |
1065 static int mga_vid_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) | |
1066 { | |
1067 int frame; | |
1068 | |
1069 switch(cmd) | |
1070 { | |
1071 case MGA_VID_CONFIG: | |
1072 //FIXME remove | |
68 | 1073 // printk(KERN_DEBUG "vcount = %d\n",readl(mga_mmio_base + VCOUNT)); |
61 | 1074 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
|
1075 printk(KERN_DEBUG "mga_mem_base = %08x\n",mga_mem_base); |
1 | 1076 //FIXME remove |
1077 | |
61 | 1078 printk(KERN_DEBUG "mga_vid: Received configuration\n"); |
1 | 1079 |
1080 if(copy_from_user(&mga_config,(mga_vid_config_t*) arg,sizeof(mga_vid_config_t))) | |
1081 { | |
61 | 1082 printk(KERN_ERR "mga_vid: failed copy from userspace\n"); |
1 | 1083 return(-EFAULT); |
1084 } | |
57 | 1085 if(mga_config.version != MGA_VID_VERSION){ |
61 | 1086 printk(KERN_ERR "mga_vid: incompatible version! driver: %X requested: %X\n",MGA_VID_VERSION,mga_config.version); |
57 | 1087 return(-EFAULT); |
1088 } | |
1089 | |
1090 if(mga_config.frame_size==0 || mga_config.frame_size>1024*768*2){ | |
61 | 1091 printk(KERN_ERR "mga_vid: illegal frame_size: %d\n",mga_config.frame_size); |
57 | 1092 return(-EFAULT); |
1093 } | |
1094 | |
1095 if(mga_config.num_frames<1 || mga_config.num_frames>4){ | |
61 | 1096 printk(KERN_ERR "mga_vid: illegal num_frames: %d\n",mga_config.num_frames); |
57 | 1097 return(-EFAULT); |
1098 } | |
1099 | |
1100 mga_src_base = (mga_ram_size*0x100000-mga_config.num_frames*mga_config.frame_size); | |
1101 if(mga_src_base<0){ | |
61 | 1102 printk(KERN_ERR "mga_vid: not enough memory for frames!\n"); |
57 | 1103 return(-EFAULT); |
1104 } | |
1105 mga_src_base &= (~0xFFFF); // 64k boundary | |
61 | 1106 printk(KERN_DEBUG "mga YUV buffer base: 0x%X\n", mga_src_base); |
57 | 1107 |
1 | 1108 if (is_g400) |
1109 mga_config.card_type = MGA_G400; | |
1110 else | |
1111 mga_config.card_type = MGA_G200; | |
1112 | |
1113 mga_config.ram_size = mga_ram_size; | |
1114 | |
1115 if (copy_to_user((mga_vid_config_t *) arg, &mga_config, sizeof(mga_vid_config_t))) | |
1116 { | |
61 | 1117 printk(KERN_ERR "mga_vid: failed copy to userspace\n"); |
1 | 1118 return(-EFAULT); |
1119 } | |
1120 return mga_vid_set_config(&mga_config); | |
1121 break; | |
1122 | |
1123 case MGA_VID_ON: | |
61 | 1124 printk(KERN_DEBUG "mga_vid: Video ON\n"); |
1 | 1125 vid_src_ready = 1; |
1126 if(vid_overlay_on) | |
1127 { | |
1128 regs.besctl |= 1; | |
2086 | 1129 mga_vid_write_regs(0); |
1 | 1130 } |
68 | 1131 #ifdef MGA_ALLOW_IRQ |
48 | 1132 if ( mga_irq != -1 ) enable_irq(); |
68 | 1133 #endif |
48 | 1134 mga_next_frame=0; |
1 | 1135 break; |
1136 | |
1137 case MGA_VID_OFF: | |
94
fbd99740af99
printk() message for video off when releasing mga without ioctl()
lgb
parents:
93
diff
changeset
|
1138 printk(KERN_DEBUG "mga_vid: Video OFF (ioctl)\n"); |
1 | 1139 vid_src_ready = 0; |
68 | 1140 #ifdef MGA_ALLOW_IRQ |
48 | 1141 if ( mga_irq != -1 ) disable_irq(); |
68 | 1142 #endif |
1 | 1143 regs.besctl &= ~1; |
466 | 1144 regs.besglobctl &= ~(1<<6); // UYVY format selected |
2086 | 1145 mga_vid_write_regs(0); |
1 | 1146 break; |
1147 | |
1148 case MGA_VID_FSEL: | |
1149 if(copy_from_user(&frame,(int *) arg,sizeof(int))) | |
1150 { | |
61 | 1151 printk(KERN_ERR "mga_vid: FSEL failed copy from userspace\n"); |
1 | 1152 return(-EFAULT); |
1153 } | |
1154 | |
1155 mga_vid_frame_sel(frame); | |
1156 break; | |
1157 | |
1158 default: | |
61 | 1159 printk(KERN_ERR "mga_vid: Invalid ioctl\n"); |
1 | 1160 return (-EINVAL); |
1161 } | |
1162 | |
1163 return 0; | |
1164 } | |
1165 | |
1166 | |
1167 static int mga_vid_find_card(void) | |
1168 { | |
1169 struct pci_dev *dev = NULL; | |
854
76ca00724e12
gcc warnings fixed - patch by Aelius aelius@wish.net
arpi_esp
parents:
662
diff
changeset
|
1170 unsigned int card_option; |
1 | 1171 |
1989 | 1172 if((dev = pci_find_device(PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G550, NULL))) |
1173 { | |
1174 is_g400 = 1; | |
1175 printk(KERN_INFO "mga_vid: Found MGA G550\n"); | |
1176 } | |
1177 else if((dev = pci_find_device(PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G400, NULL))) | |
1 | 1178 { |
1179 is_g400 = 1; | |
77 | 1180 printk(KERN_INFO "mga_vid: Found MGA G400/G450\n"); |
1 | 1181 } |
1182 else if((dev = pci_find_device(PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, NULL))) | |
1183 { | |
1184 is_g400 = 0; | |
63 | 1185 printk(KERN_INFO "mga_vid: Found MGA G200 AGP\n"); |
1 | 1186 } |
1187 else if((dev = pci_find_device(PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_PCI, NULL))) | |
1188 { | |
1189 is_g400 = 0; | |
63 | 1190 printk(KERN_INFO "mga_vid: Found MGA G200 PCI\n"); |
1 | 1191 } |
1192 else | |
1193 { | |
61 | 1194 printk(KERN_ERR "mga_vid: No supported cards found\n"); |
1 | 1195 return FALSE; |
1196 } | |
1197 | |
1198 pci_dev = dev; | |
48 | 1199 |
1200 mga_irq = pci_dev->irq; | |
1 | 1201 |
1202 #if LINUX_VERSION_CODE >= 0x020300 | |
1203 mga_mmio_base = ioremap_nocache(dev->resource[1].start,0x4000); | |
1204 mga_mem_base = dev->resource[0].start; | |
1205 #else | |
1206 mga_mmio_base = ioremap_nocache(dev->base_address[1] & PCI_BASE_ADDRESS_MEM_MASK,0x4000); | |
1207 mga_mem_base = dev->base_address[0] & PCI_BASE_ADDRESS_MEM_MASK; | |
1208 #endif | |
854
76ca00724e12
gcc warnings fixed - patch by Aelius aelius@wish.net
arpi_esp
parents:
662
diff
changeset
|
1209 printk(KERN_INFO "mga_vid: MMIO at 0x%p IRQ: %d framebuffer: 0x%08X\n", mga_mmio_base, mga_irq, mga_mem_base); |
1 | 1210 |
1211 pci_read_config_dword(dev, 0x40, &card_option); | |
77 | 1212 printk(KERN_INFO "mga_vid: OPTION word: 0x%08X mem: 0x%02X %s\n", card_option, |
1213 (card_option>>10)&0x17, ((card_option>>14)&1)?"SGRAM":"SDRAM"); | |
1 | 1214 |
57 | 1215 // temp = (card_option >> 10) & 0x17; |
1216 | |
95 | 1217 if (mga_ram_size) { |
1218 printk(KERN_INFO "mga_vid: RAMSIZE forced to %d MB\n", mga_ram_size); | |
91 | 1219 } else { |
90 | 1220 |
101
7fe6855f19cd
mga_ram_size=x works with hard-coded ramsize too (szabi)
arpi_esp
parents:
95
diff
changeset
|
1221 #ifdef MGA_MEMORY_SIZE |
7fe6855f19cd
mga_ram_size=x works with hard-coded ramsize too (szabi)
arpi_esp
parents:
95
diff
changeset
|
1222 mga_ram_size = MGA_MEMORY_SIZE; |
7fe6855f19cd
mga_ram_size=x works with hard-coded ramsize too (szabi)
arpi_esp
parents:
95
diff
changeset
|
1223 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
|
1224 |
7fe6855f19cd
mga_ram_size=x works with hard-coded ramsize too (szabi)
arpi_esp
parents:
95
diff
changeset
|
1225 #else |
7fe6855f19cd
mga_ram_size=x works with hard-coded ramsize too (szabi)
arpi_esp
parents:
95
diff
changeset
|
1226 |
95 | 1227 if (is_g400){ |
75 | 1228 switch((card_option>>10)&0x17){ |
1229 // SDRAM: | |
1230 case 0x00: | |
1231 case 0x04: mga_ram_size = 16; break; | |
105 | 1232 case 0x03: mga_ram_size = 32; break; |
75 | 1233 // SGRAM: |
1234 case 0x10: | |
1235 case 0x14: mga_ram_size = 32; break; | |
1236 case 0x11: | |
1237 case 0x12: mga_ram_size = 16; break; | |
1238 default: | |
1239 mga_ram_size = 16; | |
1240 printk(KERN_INFO "mga_vid: Couldn't detect RAMSIZE, assuming 16MB!"); | |
1241 } | |
95 | 1242 }else{ |
662
4a959b73d51e
G200 ramsize detection disabled, using 8M by default
arpi_esp
parents:
470
diff
changeset
|
1243 switch((card_option>>10)&0x17){ |
4a959b73d51e
G200 ramsize detection disabled, using 8M by default
arpi_esp
parents:
470
diff
changeset
|
1244 // case 0x10: |
4a959b73d51e
G200 ramsize detection disabled, using 8M by default
arpi_esp
parents:
470
diff
changeset
|
1245 // case 0x13: mga_ram_size = 8; break; |
4a959b73d51e
G200 ramsize detection disabled, using 8M by default
arpi_esp
parents:
470
diff
changeset
|
1246 default: mga_ram_size = 8; |
64 | 1247 } |
95 | 1248 } |
64 | 1249 #if 0 |
95 | 1250 // printk("List resources -----------\n"); |
1251 for(temp=0;temp<DEVICE_COUNT_RESOURCE;temp++){ | |
1252 struct resource *res=&pci_dev->resource[temp]; | |
1253 if(res->flags){ | |
1254 int size=(1+res->end-res->start)>>20; | |
1255 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); | |
1256 if(res->flags&(IORESOURCE_MEM|IORESOURCE_PREFETCH)){ | |
1257 if(size>mga_ram_size && size<=64) mga_ram_size=size; | |
1258 } | |
1259 } | |
57 | 1260 } |
64 | 1261 #endif |
95 | 1262 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
|
1263 #endif |
95 | 1264 } |
57 | 1265 |
48 | 1266 |
68 | 1267 #ifdef MGA_ALLOW_IRQ |
48 | 1268 if ( mga_irq != -1 ) { |
1269 int tmp = request_irq(mga_irq, mga_handle_irq, SA_INTERRUPT | SA_SHIRQ, "Syncfb Time Base", &mga_irq); | |
1270 if ( tmp ) { | |
61 | 1271 printk(KERN_INFO "syncfb (mga): cannot register irq %d (Err: %d)\n", mga_irq, tmp); |
48 | 1272 mga_irq=-1; |
1273 } else { | |
61 | 1274 printk(KERN_DEBUG "syncfb (mga): registered irq %d\n", mga_irq); |
48 | 1275 } |
1276 } else { | |
61 | 1277 printk(KERN_INFO "syncfb (mga): No valid irq was found\n"); |
48 | 1278 mga_irq=-1; |
1279 } | |
68 | 1280 #else |
1281 printk(KERN_INFO "syncfb (mga): IRQ disabled in mga_vid.c\n"); | |
1282 mga_irq=-1; | |
1283 #endif | |
48 | 1284 |
1 | 1285 return TRUE; |
1286 } | |
1287 | |
1288 | |
1289 static ssize_t mga_vid_read(struct file *file, char *buf, size_t count, loff_t *ppos) | |
1290 { | |
1291 return -EINVAL; | |
1292 } | |
1293 | |
1294 static ssize_t mga_vid_write(struct file *file, const char *buf, size_t count, loff_t *ppos) | |
1295 { | |
1296 return -EINVAL; | |
1297 } | |
1298 | |
1299 static int mga_vid_mmap(struct file *file, struct vm_area_struct *vma) | |
1300 { | |
1301 | |
61 | 1302 printk(KERN_DEBUG "mga_vid: mapping video memory into userspace\n"); |
57 | 1303 if(remap_page_range(vma->vm_start, mga_mem_base + mga_src_base, |
1 | 1304 vma->vm_end - vma->vm_start, vma->vm_page_prot)) |
1305 { | |
63 | 1306 printk(KERN_ERR "mga_vid: error mapping video memory\n"); |
1 | 1307 return(-EAGAIN); |
1308 } | |
1309 | |
1310 return(0); | |
1311 } | |
1312 | |
1313 static int mga_vid_release(struct inode *inode, struct file *file) | |
1314 { | |
1315 //Close the window just in case | |
94
fbd99740af99
printk() message for video off when releasing mga without ioctl()
lgb
parents:
93
diff
changeset
|
1316 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
|
1317 |
1 | 1318 vid_src_ready = 0; |
1319 regs.besctl &= ~1; | |
466 | 1320 regs.besglobctl &= ~(1<<6); // UYVY format selected |
2086 | 1321 // mga_config.colkey_on=0; //!!! |
1322 mga_vid_write_regs(1); | |
1 | 1323 mga_vid_in_use = 0; |
1324 | |
93 | 1325 MOD_DEC_USE_COUNT; |
1 | 1326 return 0; |
1327 } | |
1328 | |
1329 static long long mga_vid_lseek(struct file *file, long long offset, int origin) | |
1330 { | |
1331 return -ESPIPE; | |
1332 } | |
1333 | |
1334 static int mga_vid_open(struct inode *inode, struct file *file) | |
1335 { | |
1336 int minor = MINOR(inode->i_rdev); | |
1337 | |
1338 if(minor != 0) | |
1339 return(-ENXIO); | |
1340 | |
1341 if(mga_vid_in_use == 1) | |
1342 return(-EBUSY); | |
1343 | |
1344 mga_vid_in_use = 1; | |
93 | 1345 MOD_INC_USE_COUNT; |
1 | 1346 return(0); |
1347 } | |
1348 | |
1349 #if LINUX_VERSION_CODE >= 0x020400 | |
1350 static struct file_operations mga_vid_fops = | |
1351 { | |
1352 llseek: mga_vid_lseek, | |
1353 read: mga_vid_read, | |
1354 write: mga_vid_write, | |
1355 ioctl: mga_vid_ioctl, | |
1356 mmap: mga_vid_mmap, | |
1357 open: mga_vid_open, | |
1358 release: mga_vid_release | |
1359 }; | |
1360 #else | |
1361 static struct file_operations mga_vid_fops = | |
1362 { | |
1363 mga_vid_lseek, | |
1364 mga_vid_read, | |
1365 mga_vid_write, | |
1366 NULL, | |
1367 NULL, | |
1368 mga_vid_ioctl, | |
1369 mga_vid_mmap, | |
1370 mga_vid_open, | |
1371 NULL, | |
1372 mga_vid_release | |
1373 }; | |
1374 #endif | |
1375 | |
1376 | |
1377 /* | |
1378 * Main Initialization Function | |
1379 */ | |
1380 | |
1381 static int mga_vid_initialize(void) | |
1382 { | |
1383 mga_vid_in_use = 0; | |
1384 | |
77 | 1385 // printk(KERN_INFO "Matrox MGA G200/G400 YUV Video interface v0.01 (c) Aaron Holtzman \n"); |
1386 printk(KERN_INFO "Matrox MGA G200/G400/G450 YUV Video interface v2.01 (c) Aaron Holtzman & A'rpi\n"); | |
90 | 1387 |
95 | 1388 if (mga_ram_size) { |
1389 if (mga_ram_size<4 || mga_ram_size>64) { | |
1390 printk(KERN_ERR "mga_vid: invalid RAMSIZE: %d MB\n", mga_ram_size); | |
90 | 1391 return -EINVAL; |
1392 } | |
1393 } | |
1394 | |
1 | 1395 if(register_chrdev(MGA_VID_MAJOR, "mga_vid", &mga_vid_fops)) |
1396 { | |
61 | 1397 printk(KERN_ERR "mga_vid: unable to get major: %d\n", MGA_VID_MAJOR); |
1 | 1398 return -EIO; |
1399 } | |
1400 | |
1401 if (!mga_vid_find_card()) | |
1402 { | |
61 | 1403 printk(KERN_ERR "mga_vid: no supported devices found\n"); |
1 | 1404 unregister_chrdev(MGA_VID_MAJOR, "mga_vid"); |
1405 return -EINVAL; | |
1406 } | |
1407 | |
1408 return(0); | |
1409 } | |
1410 | |
1411 int init_module(void) | |
1412 { | |
1413 return mga_vid_initialize(); | |
1414 } | |
1415 | |
1416 void cleanup_module(void) | |
1417 { | |
48 | 1418 |
68 | 1419 #ifdef MGA_ALLOW_IRQ |
48 | 1420 if ( mga_irq != -1) |
1421 free_irq(mga_irq, &mga_irq); | |
68 | 1422 #endif |
48 | 1423 |
1 | 1424 if(mga_mmio_base) |
1425 iounmap(mga_mmio_base); | |
1426 | |
1427 //FIXME turn off BES | |
63 | 1428 printk(KERN_INFO "mga_vid: Cleaning up module\n"); |
1 | 1429 unregister_chrdev(MGA_VID_MAJOR, "mga_vid"); |
1430 } | |
1431 |