1 #include "config.h"
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <unistd.h>
7 #include <fcntl.h>
8 #include <inttypes.h>
9 #include <sys/ioctl.h>
10 #include <sys/mman.h>
11
12 #include <asm/page.h> /* PAGE_SIZE */
13 #include <linux/fb.h>
14
15 #include "byteswap.h"
16
17 #include "fbtools.h"
18 #include "matrox.h"
19
20 /* ---------------------------------------------------------------------- */
21 /* generic */
22
23 void (*gfx_scaler_on)(int offscreen, int pitch, int width, int height,
24 int left, int right, int top, int bottom);
25 void (*gfx_scaler_off)(void);
26
27 static unsigned char *bmmio;
28 static uint32_t *mmio;
29
30 static void
31 wrio4(int adr, unsigned long val)
32 {
33 #if BYTE_ORDER == LITTLE_ENDIAN
34 mmio[adr] = val;
35 #else
36 mmio[adr] = SWAP4(val);
37 #endif
38 /* usleep(10); */
39 }
40
41 /* ---------------------------------------------------------------------- */
42 /* Matrox G200/G400 */
43
44 #define BES_BASE 0x3d00
45 #define BESA1ORG ((BES_BASE+0x00)>>2)
46 #define BESA2ORG ((BES_BASE+0x04)>>2)
47 #define BESB1ORG ((BES_BASE+0x08)>>2)
48 #define BESB2ORG ((BES_BASE+0x0c)>>2)
49 #define BESA1CORG ((BES_BASE+0x10)>>2)
50 #define BESA2CORG ((BES_BASE+0x14)>>2)
51 #define BESB1CORG ((BES_BASE+0x18)>>2)
52 #define BESB2CORG ((BES_BASE+0x1c)>>2)
53 #define BESCTL ((BES_BASE+0x20)>>2)
54 #define BESPITCH ((BES_BASE+0x24)>>2)
55 #define BESHCOORD ((BES_BASE+0x28)>>2)
56 #define BESVCOORD ((BES_BASE+0x2c)>>2)
57 #define BESHISCAL ((BES_BASE+0x30)>>2)
58 #define BESVISCAL ((BES_BASE+0x34)>>2)
59 #define BESHSRCST ((BES_BASE+0x38)>>2)
60 #define BESHSRCEND ((BES_BASE+0x3c)>>2)
61
62 #define BESV1WGHT ((BES_BASE+0x48)>>2)
63 #define BESV2WGHT ((BES_BASE+0x4c)>>2)
64 #define BESHSRCLST ((BES_BASE+0x50)>>2)
65 #define BESV1SRCLST ((BES_BASE+0x54)>>2)
66 #define BESV2SRCLST ((BES_BASE+0x58)>>2)
67 #define BESGLOBCTL ((BES_BASE+0xc0)>>2)
68 #define BESSTATUS ((BES_BASE+0xc4)>>2)
69
70 #define PALWTADD 0x3c00
71 #define X_DATAREG 0x3c0a
72 #define XKEYOPMODE 0x51
73
74 static void
75 matrox_scaler_on(int offscreen, int pitch, int width, int height,
76 int left, int right, int top, int bottom)
77 {
78 /* color keying (turn it off) */
79 bmmio[PALWTADD] = XKEYOPMODE;
80 bmmio[X_DATAREG] = 0;
81
82 /* src */
83 wrio4(BESA1ORG, offscreen);
84 wrio4(BESA2ORG, offscreen);
85 wrio4(BESB1ORG, offscreen);
86 wrio4(BESB2ORG, offscreen);
87 wrio4(BESPITCH, pitch/2);
88
89 /* dest */
90 wrio4(BESHCOORD, (left << 16) | right);
91 wrio4(BESVCOORD, (top << 16) | bottom);
92
93 /* scale horiz */
94 wrio4(BESHISCAL, width*65536/(right-left) & 0x001ffffc);
95 wrio4(BESHSRCST, 0 << 16);
96 wrio4(BESHSRCEND, width << 16);
97 wrio4(BESHSRCLST, (width-1) << 16);
98
99 /* scale vert */
100 wrio4(BESVISCAL, height*65536/(bottom-top) & 0x001ffffc);
101 wrio4(BESV1WGHT, 0);
102 wrio4(BESV2WGHT, 0);
103 wrio4(BESV1SRCLST, height-1);
104 wrio4(BESV2SRCLST, height-1);
105
106 /* turn on (enable, horizontal+vertical interpolation filters */
107 wrio4(BESCTL, (1 << 0) | (1 << 10) | (1 << 11));
108 wrio4(BESGLOBCTL, 0);
109 }
110
111 static void
112 matrox_scaler_off(void)
113 {
114 /* turn off */
115 wrio4(BESCTL, 0);
116 }
117
118 /* ---------------------------------------------------------------------- */
119 /* ATI Mach64 VT+GT */
120
121 #define OVERLAY_X_Y_START 0x0000
122 #define OVERLAY_X_Y_END 0x0001
123 #define OVERLAY_VIDEO_KEY_CLR 0x0002
124 #define OVERLAY_VIDEO_KEY_MSK 0x0003
125 #define OVERLAY_GRAPHICS_KEY_CLR 0x0004
126 #define OVERLAY_GRAPHICS_KEY_MSK 0x0005
127 #define OVERLAY_KEY_CNTL 0x0006
128
129 #define OVERLAY_SCALE_INC 0x0008
130 #define OVERLAY_SCALE_CNTL 0x0009
131 #define SCALER_HEIGHT_WIDTH 0x000a
132 #define SCALER_TEST 0x000b
133 #define SCALER_BUF0_OFFSET 0x000d
134 #define SCALER_BUF1_OFFSET 0x000e
135 #define SCALER_BUF_PITCH 0x000f
136
137 #define VIDEO_FORMAT 0x0012
138 #define CAPTURE_CONFIG 0x0014
139
140 #define SCALER_COLOR_CNTL 0x0054
141 #define SCALER_H_COEFF0 0x0055
142 #define SCALER_H_COEFF1 0x0056
143 #define SCALER_H_COEFF2 0x0057
144 #define SCALER_H_COEFF3 0x0058
145 #define SCALER_H_COEFF4 0x0059
146
147 /* does'nt work for all color depth yet... */
148 static void
149 mach64_scaler_on(int offscreen, int pitch, int width, int height,
150 int left, int right, int top, int bottom)
151 {
152 int v,h;
153
154 v = (height << 12) / (bottom-top);
155 h = (width << 12) / (right-left);
156
157 wrio4(OVERLAY_SCALE_CNTL, 0);
158 wrio4(OVERLAY_SCALE_INC, (h << 16) | v);
159 wrio4(VIDEO_FORMAT, (12 << 16));
160 wrio4(SCALER_BUF0_OFFSET, offscreen);
161 wrio4(SCALER_BUF1_OFFSET, offscreen);
162 wrio4(SCALER_BUF_PITCH, pitch/2);
163 wrio4(SCALER_HEIGHT_WIDTH, (width << 16) | height);
164 wrio4(CAPTURE_CONFIG, 0);
165
166 #if 1
167 /* from gatos, don't know what this does, have no specs :-( */
168 wrio4(SCALER_COLOR_CNTL, 0x00101000);
169 wrio4(SCALER_H_COEFF0, 0x00002000);
170 wrio4(SCALER_H_COEFF1, 0x0D06200D);
171 wrio4(SCALER_H_COEFF2, 0x0D0A1C0D);
172 wrio4(SCALER_H_COEFF3, 0x0C0E1A0C);
173 wrio4(SCALER_H_COEFF4, 0x0C14140C);
174 #endif
175
176 wrio4(OVERLAY_X_Y_START, (left << 16) | top);
177 wrio4(OVERLAY_X_Y_END, ((right-1) << 16) | (bottom-1));
178 wrio4(OVERLAY_VIDEO_KEY_MSK, 0);
179 wrio4(OVERLAY_VIDEO_KEY_CLR, 0);
180 wrio4(OVERLAY_KEY_CNTL, 1);
181
182 wrio4(SCALER_TEST, 0); /* 2 == test mode */
183 wrio4(OVERLAY_SCALE_CNTL, (1<<31) | (1<<30));
184 }
185
186 static void
187 mach64_scaler_off(void)
188 {
189 /* off */
190 wrio4(OVERLAY_SCALE_CNTL, 0);
191 }
192
193 /* ---------------------------------------------------------------------- */
194 /* generic */
195
196 int
197 gfx_init(int fd)
198 {
199 int off;
200
201 switch (fb_fix.accel) {
202 case FB_ACCEL_MATROX_MGAG200:
203 #ifdef FB_ACCEL_MATROX_MGAG400
204 case FB_ACCEL_MATROX_MGAG400:
205 #endif
206 gfx_scaler_on = matrox_scaler_on;
207 gfx_scaler_off = matrox_scaler_off;
208 break;
209 case FB_ACCEL_ATI_MACH64VT:
210 case FB_ACCEL_ATI_MACH64GT:
211 gfx_scaler_on = mach64_scaler_on;
212 gfx_scaler_off = mach64_scaler_off;
213 break;
214 default:
215 return -1;
216 }
217 fb_var.accel_flags = 0;
218 if (0 != ioctl(fd,FBIOPUT_VSCREENINFO,&fb_var)) {
219 perror("FBIOPUT_VSCREENINFO");
220 return -1;
221 }
222 bmmio = mmap(NULL, fb_fix.mmio_len, PROT_READ | PROT_WRITE,
223 MAP_SHARED, fd, fb_fix.smem_len);
224 if ((void*)-1 == bmmio) {
225 perror("mmap");
226 return -1;
227 }
228 off = (unsigned long)fb_fix.mmio_start -
229 ((unsigned long)fb_fix.mmio_start & ~(PAGE_SIZE-1));
230 bmmio += off;
231 mmio = (uint32_t*)bmmio;
232 return 0;
233 }
234
|
This page was automatically generated by the
LXR engine.
|