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