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