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