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