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