26096
|
1 /*
|
|
2 * VIDIX driver for S3 chipsets.
|
|
3 * Copyright (C) 2004 Reza Jelveh
|
|
4 *
|
|
5 * This file is part of MPlayer.
|
|
6 *
|
|
7 * MPlayer is free software; you can redistribute it and/or modify
|
|
8 * it under the terms of the GNU General Public License as published by
|
|
9 * the Free Software Foundation; either version 2 of the License, or
|
|
10 * (at your option) any later version.
|
|
11 *
|
|
12 * MPlayer is distributed in the hope that it will be useful,
|
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 * GNU General Public License for more details.
|
|
16 *
|
|
17 * You should have received a copy of the GNU General Public License
|
|
18 * along with MPlayer; if not, write to the Free Software
|
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
20 *
|
|
21 * Thanks to Alex Deucher for Support
|
|
22 *
|
|
23 * Trio/Virge support by Michael Kostylev
|
|
24 *
|
|
25 */
|
|
26
|
|
27 #include <errno.h>
|
|
28 #include <stdio.h>
|
|
29 #include <stdlib.h>
|
|
30 #include <string.h>
|
|
31 #include <inttypes.h>
|
|
32 #include <unistd.h>
|
|
33 #include <math.h>
|
|
34
|
|
35 #include "vidix.h"
|
|
36 #include "vidixlib.h"
|
|
37 #include "fourcc.h"
|
|
38 #include "dha.h"
|
|
39 #include "pci_ids.h"
|
|
40 #include "pci_names.h"
|
|
41 #include "config.h"
|
|
42
|
|
43 #include "s3_regs.h"
|
|
44
|
|
45 static void S3SetColorKeyOld (void);
|
|
46 static void S3SetColorKeyNew (void);
|
|
47 static void S3SetColorKey2000 (void);
|
|
48 static void (*S3SetColorKey) (void) = NULL;
|
|
49
|
|
50 static void S3SetColorOld (void);
|
|
51 static void S3SetColorNew (void);
|
|
52 static void S3SetColor2000 (void);
|
|
53 static void (*S3SetColor) (void) = NULL;
|
|
54
|
|
55 static void S3DisplayVideoOld (void);
|
|
56 static void S3DisplayVideoNew (void);
|
|
57 static void S3DisplayVideo2000 (void);
|
|
58 static void (*S3DisplayVideo) (void) = NULL;
|
|
59
|
|
60 static void S3InitStreamsOld (void);
|
|
61 static void S3InitStreamsNew (void);
|
|
62 static void S3InitStreams2000 (void);
|
|
63 static void (*S3InitStreams) (void) = NULL;
|
|
64
|
|
65 pciinfo_t pci_info;
|
|
66
|
|
67 struct s3_chip
|
|
68 {
|
|
69 int arch;
|
|
70 unsigned long fbsize;
|
|
71 void (*lock) (struct s3_chip *, int);
|
|
72 };
|
|
73 typedef struct s3_chip s3_chip;
|
|
74
|
|
75 struct s3_info
|
|
76 {
|
|
77 vidix_video_eq_t eq;
|
|
78 unsigned int use_colorkey;
|
|
79 unsigned int colorkey;
|
|
80 unsigned int vidixcolorkey;
|
|
81 unsigned int depth;
|
|
82 unsigned int bpp;
|
|
83 unsigned int format;
|
|
84 unsigned int pitch;
|
|
85 unsigned int blendBase;
|
|
86 unsigned int displayWidth, displayHeight;
|
|
87 unsigned int src_w, src_h;
|
|
88 unsigned int drw_w, drw_h;
|
|
89 unsigned int wx, wy;
|
|
90 unsigned int screen_x;
|
|
91 unsigned int screen_y;
|
|
92 unsigned long frame_size;
|
|
93 struct s3_chip chip;
|
|
94 void *video_base;
|
|
95 void *control_base;
|
|
96 unsigned long picture_base;
|
|
97 unsigned long picture_offset;
|
|
98 unsigned int num_frames;
|
|
99 int bps;
|
|
100 };
|
|
101 typedef struct s3_info s3_info;
|
|
102
|
|
103 static s3_info *info;
|
|
104
|
|
105 static vidix_capability_t s3_cap = {
|
|
106 "S3 BES",
|
|
107 "Reza Jelveh, Michael Kostylev",
|
|
108 TYPE_OUTPUT,
|
|
109 {0, 0, 0, 0},
|
|
110 4096,
|
|
111 4096,
|
|
112 4,
|
|
113 4,
|
|
114 -1,
|
|
115 FLAG_UPSCALER | FLAG_DOWNSCALER,
|
|
116 VENDOR_S3_INC,
|
|
117 -1,
|
|
118 {0, 0, 0, 0}
|
|
119 };
|
|
120
|
|
121 struct s3_cards
|
|
122 {
|
|
123 unsigned short chip_id;
|
|
124 unsigned short arch;
|
|
125 };
|
|
126
|
|
127 static struct s3_cards s3_card_ids[] = {
|
|
128 /* Trio64V */
|
|
129 {DEVICE_S3_INC_86C764_765_TRIO32_64_64V, S3_TRIO64V},
|
|
130 {DEVICE_S3_INC_86C767_TRIO_64UV, S3_TRIO64V},
|
|
131 {DEVICE_S3_INC_86C755_TRIO_64V2_DX, S3_TRIO64V},
|
|
132 {DEVICE_S3_INC_86C775_86C785_TRIO_64V2_DX, S3_TRIO64V},
|
|
133 {DEVICE_S3_INC_TRIO_64V_FAMILY, S3_TRIO64V},
|
|
134 {DEVICE_S3_INC_TRIO_64V_FAMILY2, S3_TRIO64V},
|
|
135 {DEVICE_S3_INC_TRIO_64V_FAMILY3, S3_TRIO64V},
|
|
136 {DEVICE_S3_INC_TRIO_64V_FAMILY4, S3_TRIO64V},
|
|
137 {DEVICE_S3_INC_TRIO_64V_FAMILY5, S3_TRIO64V},
|
|
138 {DEVICE_S3_INC_TRIO_64V_FAMILY6, S3_TRIO64V},
|
|
139 {DEVICE_S3_INC_TRIO_64V_FAMILY7, S3_TRIO64V},
|
|
140 {DEVICE_S3_INC_TRIO_64V_FAMILY8, S3_TRIO64V},
|
|
141 {DEVICE_S3_INC_TRIO_64V_FAMILY9, S3_TRIO64V},
|
|
142 {DEVICE_S3_INC_TRIO_64V_FAMILY10, S3_TRIO64V},
|
|
143 {DEVICE_S3_INC_TRIO_64V_FAMILY11, S3_TRIO64V},
|
|
144 /* Virge */
|
|
145 {DEVICE_S3_INC_86C325_VIRGE, S3_VIRGE},
|
|
146 {DEVICE_S3_INC_86C988_VIRGE_VX, S3_VIRGE},
|
|
147 {DEVICE_S3_INC_VIRGE_DX_OR_GX, S3_VIRGE},
|
|
148 {DEVICE_S3_INC_VIRGE_GX2, S3_VIRGE},
|
|
149 {DEVICE_S3_INC_VIRGE_M3, S3_VIRGE},
|
|
150 {DEVICE_S3_INC_VIRGE_MX, S3_VIRGE},
|
|
151 {DEVICE_S3_INC_VIRGE_MX2, S3_VIRGE},
|
|
152 {DEVICE_S3_INC_VIRGE_MX_MV, S3_VIRGE},
|
|
153 /* Savage3D */
|
|
154 {DEVICE_S3_INC_86C794_SAVAGE_3D, S3_SAVAGE3D},
|
|
155 {DEVICE_S3_INC_86C390_SAVAGE_3D_MV, S3_SAVAGE3D},
|
|
156 /* Savage4 */
|
|
157 {DEVICE_S3_INC_SAVAGE_4, S3_SAVAGE4},
|
|
158 {DEVICE_S3_INC_SAVAGE_42, S3_SAVAGE4},
|
|
159 /* SavageMX */
|
|
160 {DEVICE_S3_INC_86C270_294_SAVAGE_MX_MV, S3_SAVAGE_MX},
|
|
161 {DEVICE_S3_INC_82C270_294_SAVAGE_MX, S3_SAVAGE_MX},
|
|
162 {DEVICE_S3_INC_86C270_294_SAVAGE_IX_MV, S3_SAVAGE_MX},
|
|
163 /* SuperSavage */
|
|
164 {DEVICE_S3_INC_SUPERSAVAGE_MX_128, S3_SUPERSAVAGE},
|
|
165 {DEVICE_S3_INC_SUPERSAVAGE_MX_64, S3_SUPERSAVAGE},
|
|
166 {DEVICE_S3_INC_SUPERSAVAGE_MX_64C, S3_SUPERSAVAGE},
|
|
167 {DEVICE_S3_INC_SUPERSAVAGE_IX_128_SDR, S3_SUPERSAVAGE},
|
|
168 {DEVICE_S3_INC_SUPERSAVAGE_IX_128_DDR, S3_SUPERSAVAGE},
|
|
169 {DEVICE_S3_INC_SUPERSAVAGE_IX_64_SDR, S3_SUPERSAVAGE},
|
|
170 {DEVICE_S3_INC_SUPERSAVAGE_IX_64_DDR, S3_SUPERSAVAGE},
|
|
171 {DEVICE_S3_INC_SUPERSAVAGE_IX_C_SDR, S3_SUPERSAVAGE},
|
|
172 {DEVICE_S3_INC_SUPERSAVAGE_IX_C_DDR, S3_SUPERSAVAGE},
|
|
173 /* ProSavage */
|
|
174 {DEVICE_S3_INC_PROSAVAGE_PM133, S3_PROSAVAGE},
|
|
175 {DEVICE_S3_INC_PROSAVAGE_KM133, S3_PROSAVAGE},
|
|
176 {DEVICE_S3_INC_86C380_PROSAVAGEDDR_K4M266, S3_PROSAVAGE},
|
|
177 {DEVICE_S3_INC_VT8636A_PROSAVAGE_KN133, S3_PROSAVAGE},
|
|
178 {DEVICE_S3_INC_VT8751_PROSAVAGEDDR_P4M266, S3_PROSAVAGE},
|
|
179 {DEVICE_S3_INC_VT8375_PROSAVAGE8_KM266_KL266, S3_PROSAVAGE},
|
|
180 /* Savage2000 */
|
|
181 {DEVICE_S3_INC_86C410_SAVAGE_2000, S3_SAVAGE2000}
|
|
182 };
|
|
183
|
|
184 static unsigned int GetBlendForFourCC (int id)
|
|
185 {
|
|
186 switch (id)
|
|
187 {
|
|
188 case IMGFMT_UYVY:
|
|
189 return 0;
|
|
190 case IMGFMT_YUY2:
|
|
191 return 1;
|
|
192 case IMGFMT_Y211:
|
|
193 return 4;
|
|
194 case IMGFMT_BGR15:
|
|
195 return 3;
|
|
196 case IMGFMT_BGR16:
|
|
197 return 5;
|
|
198 case IMGFMT_BGR24:
|
|
199 return 6;
|
|
200 case IMGFMT_BGR32:
|
|
201 return 7;
|
|
202 default:
|
|
203 return 1;
|
|
204 }
|
|
205 }
|
|
206
|
|
207 static void S3SetColorOld (void)
|
|
208 {
|
|
209 char sat = (info->eq.saturation + 1000) * 15 / 2000;
|
|
210 double hue = info->eq.hue * 3.1415926 / 1000.0;
|
|
211 char hsx = ((char) (sat * cos (hue))) & 0x1f;
|
|
212 char hsy = ((char) (sat * sin (hue))) & 0x1f;
|
|
213
|
|
214 OUTREG (COLOR_ADJUSTMENT_REG, 0x80008000 | hsy << 24 | hsx << 16 |
|
|
215 ((info->eq.contrast + 1000) * 31 / 2000) << 8 |
|
|
216 (info->eq.brightness + 1000) * 255 / 2000);
|
|
217 }
|
|
218
|
|
219 static void S3SetColorNew (void)
|
|
220 {
|
|
221 /* not yet */
|
|
222 }
|
|
223
|
|
224 static void S3SetColor2000 (void)
|
|
225 {
|
|
226 /* not yet */
|
|
227 }
|
|
228
|
|
229 static void S3SetColorKeyOld (void)
|
|
230 {
|
|
231 int red, green, blue;
|
|
232
|
|
233 /* Here, we reset the colorkey and all the controls */
|
|
234
|
|
235 red = (info->vidixcolorkey & 0x00FF0000) >> 16;
|
|
236 green = (info->vidixcolorkey & 0x0000FF00) >> 8;
|
|
237 blue = info->vidixcolorkey & 0x000000FF;
|
|
238
|
|
239 if (!info->vidixcolorkey)
|
|
240 {
|
|
241 OUTREG (COL_CHROMA_KEY_CONTROL_REG, 0);
|
|
242 OUTREG (CHROMA_KEY_UPPER_BOUND_REG, 0);
|
|
243 OUTREG (BLEND_CONTROL_REG, 0);
|
|
244 }
|
|
245 else
|
|
246 {
|
|
247 switch (info->depth)
|
|
248 {
|
|
249 // FIXME: isnt fixed yet
|
|
250 case 8:
|
|
251 OUTREG (COL_CHROMA_KEY_CONTROL_REG, 0x37000000 | (info->vidixcolorkey & 0xFF));
|
|
252 OUTREG (CHROMA_KEY_UPPER_BOUND_REG, 0x00000000 | (info->vidixcolorkey & 0xFF));
|
|
253 break;
|
|
254 case 15:
|
|
255 /* 15 bpp 555 */
|
|
256 red &= 0x1f;
|
|
257 green &= 0x1f;
|
|
258 blue &= 0x1f;
|
|
259 OUTREG (COL_CHROMA_KEY_CONTROL_REG, 0x05000000 | (red << 19) | (green << 11) | (blue << 3));
|
|
260 OUTREG (CHROMA_KEY_UPPER_BOUND_REG, 0x00000000 | (red << 19) | (green << 11) | (blue << 3));
|
|
261 break;
|
|
262 case 16:
|
|
263 /* 16 bpp 565 */
|
|
264 red &= 0x1f;
|
|
265 green &= 0x3f;
|
|
266 blue &= 0x1f;
|
|
267 OUTREG (COL_CHROMA_KEY_CONTROL_REG, 0x16000000 | (red << 19) | (green << 10) | (blue << 3));
|
|
268 OUTREG (CHROMA_KEY_UPPER_BOUND_REG, 0x00020002 | (red << 19) | (green << 10) | (blue << 3));
|
|
269 break;
|
|
270 case 24:
|
|
271 /* 24 bpp 888 */
|
|
272 OUTREG (COL_CHROMA_KEY_CONTROL_REG, 0x17000000 | (red << 16) | (green << 8) | (blue));
|
|
273 OUTREG (CHROMA_KEY_UPPER_BOUND_REG, 0x00000000 | (red << 16) | (green << 8) | (blue));
|
|
274 break;
|
|
275 }
|
|
276
|
|
277 /* We use destination colorkey */
|
|
278 OUTREG (BLEND_CONTROL_REG, 0x05000000);
|
|
279 }
|
|
280 }
|
|
281
|
|
282 static void S3SetColorKeyNew (void)
|
|
283 {
|
|
284 /* not yet */
|
|
285 }
|
|
286
|
|
287 static void S3SetColorKey2000 (void)
|
|
288 {
|
|
289 /* not yet */
|
|
290 }
|
|
291
|
|
292 static void S3DisplayVideoOld (void)
|
|
293 {
|
|
294 unsigned int ssControl;
|
|
295 int cr92;
|
|
296
|
|
297 /* Set surface location and stride */
|
|
298 OUTREG (SSTREAM_FBADDR0_REG, info->picture_offset);
|
|
299 OUTREG (SSTREAM_FBADDR1_REG, 0);
|
|
300 OUTREG (SSTREAM_STRIDE_REG, info->pitch);
|
|
301 /* Set window parameters */
|
|
302 OUTREG (SSTREAM_WINDOW_START_REG, OS_XY (info->wx, info->wy));
|
|
303 OUTREG (SSTREAM_WINDOW_SIZE_REG, OS_WH (info->drw_w, info->drw_h));
|
|
304
|
|
305 /* Set surface format and adjust scaling */
|
|
306 if (info->chip.arch <= S3_VIRGE)
|
|
307 {
|
|
308 ssControl = ((info->src_w - 1) << 1) - ((info->drw_w - 1) & 0xffff);
|
|
309 ssControl |= GetBlendForFourCC (info->format) << 24;
|
|
310 if (info->src_w != info->drw_w)
|
|
311 ssControl |= 2 << 28;
|
|
312
|
|
313 OUTREG (SSTREAM_CONTROL_REG, ssControl);
|
|
314 OUTREG (SSTREAM_STRETCH_REG, (((info->src_w - info->drw_w) & 0x7ff) << 16) | (info->src_w - 1));
|
|
315 /* Calculate vertical scale factor */
|
|
316 OUTREG (K1_VSCALE_REG, info->src_h - 1);
|
|
317 OUTREG (K2_VSCALE_REG, (info->src_h - info->drw_h) & 0x7ff);
|
|
318 OUTREG (DDA_VERT_REG, (1 - info->drw_h) & 0xfff);
|
|
319 }
|
|
320 else
|
|
321 {
|
|
322 ssControl = GetBlendForFourCC (info->format) << 24 | info->src_w;
|
|
323 if (info->src_w > (info->drw_w << 1))
|
|
324 {
|
|
325 /* BUGBUG shouldn't this be >=? */
|
|
326 if (info->src_w <= (info->drw_w << 2))
|
|
327 ssControl |= HDSCALE_4;
|
|
328 else if (info->src_w > (info->drw_w << 3))
|
|
329 ssControl |= HDSCALE_8;
|
|
330 else if (info->src_w > (info->drw_w << 4))
|
|
331 ssControl |= HDSCALE_16;
|
|
332 else if (info->src_w > (info->drw_w << 5))
|
|
333 ssControl |= HDSCALE_32;
|
|
334 else if (info->src_w > (info->drw_w << 6))
|
|
335 ssControl |= HDSCALE_64;
|
|
336 }
|
|
337
|
|
338 OUTREG (SSTREAM_CONTROL_REG, ssControl);
|
|
339 OUTREG (SSTREAM_STRETCH_REG, (info->src_w << 15) / info->drw_w);
|
|
340 OUTREG (SSTREAM_LINES_REG, info->src_h);
|
|
341 /* Calculate vertical scale factor. */
|
|
342 OUTREG (SSTREAM_VSCALE_REG, VSCALING (info->src_h, info->drw_h));
|
|
343 }
|
|
344
|
|
345 if (info->chip.arch == S3_TRIO64V)
|
|
346 OUTREG (STREAMS_FIFO_REG, (6 << 10) | (14 << 5) | 16);
|
|
347 else
|
|
348 {
|
|
349 // FIXME: this should actually be enabled
|
|
350 info->pitch = (info->pitch + 7) / 8;
|
|
351 VGAOUT8 (vgaCRIndex, 0x92);
|
|
352 cr92 = VGAIN8 (vgaCRReg);
|
|
353 VGAOUT8 (vgaCRReg, (cr92 & 0x40) | (info->pitch >> 8) | 0x80);
|
|
354 VGAOUT8 (vgaCRIndex, 0x93);
|
|
355 VGAOUT8 (vgaCRReg, info->pitch);
|
|
356 OUTREG (STREAMS_FIFO_REG, 2 | 25 << 5 | 32 << 11);
|
|
357 }
|
|
358 }
|
|
359
|
|
360 static void S3DisplayVideoNew (void)
|
|
361 {
|
|
362 /* not yet */
|
|
363 }
|
|
364
|
|
365 static void S3DisplayVideo2000 (void)
|
|
366 {
|
|
367 /* not yet */
|
|
368 }
|
|
369
|
|
370 static void S3InitStreamsOld (void)
|
|
371 {
|
|
372 /*unsigned long jDelta; */
|
|
373 unsigned long format = 0;
|
|
374
|
|
375 /*jDelta = pScrn->displayWidth * (pScrn->bitsPerPixel + 7) / 8; */
|
|
376 switch (info->depth)
|
|
377 {
|
|
378 case 8:
|
|
379 format = 0 << 24;
|
|
380 break;
|
|
381 case 15:
|
|
382 format = 3 << 24;
|
|
383 break;
|
|
384 case 16:
|
|
385 format = 5 << 24;
|
|
386 break;
|
|
387 case 24:
|
|
388 format = 7 << 24;
|
|
389 break;
|
|
390 }
|
|
391 //#warning enable this again
|
|
392 OUTREG (PSTREAM_FBSIZE_REG, info->screen_y * info->screen_x * (info->bpp >> 3));
|
|
393 OUTREG (PSTREAM_WINDOW_START_REG, OS_XY (0, 0));
|
|
394 OUTREG (PSTREAM_WINDOW_SIZE_REG, OS_WH (info->screen_x, info->screen_y));
|
|
395 OUTREG (PSTREAM_FBADDR1_REG, 0);
|
|
396 /*OUTREG( PSTREAM_STRIDE_REG, jDelta ); */
|
|
397 OUTREG (PSTREAM_CONTROL_REG, format);
|
|
398 OUTREG (PSTREAM_FBADDR0_REG, 0);
|
|
399
|
|
400 OUTREG (COL_CHROMA_KEY_CONTROL_REG, 0);
|
|
401 OUTREG (SSTREAM_CONTROL_REG, 0);
|
|
402 OUTREG (CHROMA_KEY_UPPER_BOUND_REG, 0);
|
|
403 OUTREG (SSTREAM_STRETCH_REG, 0);
|
|
404 OUTREG (COLOR_ADJUSTMENT_REG, 0);
|
|
405 OUTREG (BLEND_CONTROL_REG, 1 << 24);
|
|
406 OUTREG (DOUBLE_BUFFER_REG, 0);
|
|
407 OUTREG (SSTREAM_FBADDR0_REG, 0);
|
|
408 OUTREG (SSTREAM_FBADDR1_REG, 0);
|
|
409 OUTREG (SSTREAM_FBADDR2_REG, 0);
|
|
410 OUTREG (SSTREAM_FBSIZE_REG, 0);
|
|
411 OUTREG (SSTREAM_STRIDE_REG, 0);
|
|
412 OUTREG (SSTREAM_VSCALE_REG, 0);
|
|
413 OUTREG (SSTREAM_LINES_REG, 0);
|
|
414 OUTREG (SSTREAM_VINITIAL_REG, 0);
|
|
415 }
|
|
416
|
|
417 static void S3InitStreamsNew (void)
|
|
418 {
|
|
419 /* not yet */
|
|
420 }
|
|
421
|
|
422 static void S3InitStreams2000 (void)
|
|
423 {
|
|
424 /* not yet */
|
|
425 }
|
|
426
|
|
427 static void S3StreamsOn (void)
|
|
428 {
|
|
429 unsigned char jStreamsControl;
|
|
430
|
|
431 VGAOUT8 (vgaCRIndex, EXT_MISC_CTRL2);
|
|
432
|
|
433 if (S3_SAVAGE_MOBILE_SERIES (info->chip.arch))
|
|
434 {
|
|
435 jStreamsControl = VGAIN8 (vgaCRReg) | ENABLE_STREAM1;
|
|
436 VerticalRetraceWait ();
|
|
437 VGAOUT16 (vgaCRIndex, (jStreamsControl << 8) | EXT_MISC_CTRL2);
|
|
438
|
|
439 S3InitStreams = S3InitStreamsNew;
|
|
440 S3SetColor = S3SetColorNew;
|
|
441 S3SetColorKey = S3SetColorKeyNew;
|
|
442 S3DisplayVideo = S3DisplayVideoNew;
|
|
443 }
|
|
444 else if (info->chip.arch == S3_SAVAGE2000)
|
|
445 {
|
|
446 jStreamsControl = VGAIN8 (vgaCRReg) | ENABLE_STREAM1;
|
|
447 VerticalRetraceWait ();
|
|
448 VGAOUT16 (vgaCRIndex, (jStreamsControl << 8) | EXT_MISC_CTRL2);
|
|
449
|
|
450 S3InitStreams = S3InitStreams2000;
|
|
451 S3SetColor = S3SetColor2000;
|
|
452 S3SetColorKey = S3SetColorKey2000;
|
|
453 S3DisplayVideo = S3DisplayVideo2000;
|
|
454 }
|
|
455 else
|
|
456 {
|
|
457 jStreamsControl = VGAIN8 (vgaCRReg) | ENABLE_STREAMS_OLD;
|
|
458 VerticalRetraceWait ();
|
|
459 VGAOUT16 (vgaCRIndex, (jStreamsControl << 8) | EXT_MISC_CTRL2);
|
|
460
|
|
461 S3InitStreams = S3InitStreamsOld;
|
|
462 S3SetColor = S3SetColorOld;
|
|
463 S3SetColorKey = S3SetColorKeyOld;
|
|
464 S3DisplayVideo = S3DisplayVideoOld;
|
|
465 }
|
|
466
|
|
467 S3InitStreams ();
|
|
468
|
|
469 VerticalRetraceWait ();
|
|
470 /* Turn on secondary stream TV flicker filter, once we support TV. */
|
|
471 /* SR70 |= 0x10 */
|
|
472 }
|
|
473
|
|
474 static void S3GetScrProp (struct s3_info *info)
|
|
475 {
|
|
476 unsigned char bpp = 0;
|
|
477
|
|
478 VGAOUT8 (vgaCRIndex, EXT_MISC_CTRL2);
|
|
479 bpp = VGAIN8 (vgaCRReg);
|
|
480
|
|
481 switch (bpp & 0xf0)
|
|
482 {
|
|
483 case 0x00:
|
|
484 case 0x10:
|
|
485 info->depth = 8;
|
|
486 info->bpp = 8;
|
|
487 break;
|
|
488 case 0x20:
|
|
489 case 0x30:
|
|
490 info->depth = 15;
|
|
491 info->bpp = 16;
|
|
492 break;
|
|
493 case 0x40:
|
|
494 case 0x50:
|
|
495 info->depth = 16;
|
|
496 info->bpp = 16;
|
|
497 break;
|
|
498 case 0x70:
|
|
499 case 0xd0:
|
|
500 info->depth = 24;
|
|
501 info->bpp = 32;
|
|
502 break;
|
|
503 }
|
|
504
|
|
505 VGAOUT8 (vgaCRIndex, 0x1);
|
|
506 info->screen_x = (1 + VGAIN8 (vgaCRReg)) << 3;
|
|
507 VGAOUT8 (vgaCRIndex, 0x12);
|
|
508 info->screen_y = VGAIN8 (vgaCRReg);
|
|
509 VGAOUT8 (vgaCRIndex, 0x07);
|
|
510 info->screen_y |= (VGAIN8 (vgaCRReg) & 0x02) << 7;
|
|
511 info->screen_y |= (VGAIN8 (vgaCRReg) & 0x40) << 3;
|
|
512 ++info->screen_y;
|
|
513
|
|
514 printf ("[s3_vid] x = %d, y = %d, bpp = %d\n", info->screen_x, info->screen_y, info->bpp);
|
|
515 }
|
|
516
|
|
517 static void S3StreamsOff (void)
|
|
518 {
|
|
519 unsigned char jStreamsControl;
|
|
520
|
|
521 if (info->chip.arch == S3_TRIO64V)
|
|
522 OUTREG (STREAMS_FIFO_REG, (20 << 10));
|
|
523
|
|
524 VGAOUT8 (vgaCRIndex, EXT_MISC_CTRL2);
|
|
525 if (S3_SAVAGE_MOBILE_SERIES (info->chip.arch) ||
|
|
526 (info->chip.arch == S3_SUPERSAVAGE) || (info->chip.arch == S3_SAVAGE2000))
|
|
527 jStreamsControl = VGAIN8 (vgaCRReg) & NO_STREAMS;
|
|
528 else
|
|
529 jStreamsControl = VGAIN8 (vgaCRReg) & NO_STREAMS_OLD;
|
|
530
|
|
531 VerticalRetraceWait ();
|
|
532 VGAOUT16 (vgaCRIndex, (jStreamsControl << 8) | EXT_MISC_CTRL2);
|
|
533
|
|
534 if (S3_SAVAGE_SERIES (info->chip.arch))
|
|
535 {
|
|
536 VGAOUT16 (vgaCRIndex, 0x0093);
|
|
537 VGAOUT8 (vgaCRIndex, 0x92);
|
|
538 VGAOUT8 (vgaCRReg, VGAIN8 (vgaCRReg) & 0x40);
|
|
539 }
|
|
540 }
|
|
541
|
|
542 static int find_chip (unsigned chip_id)
|
|
543 {
|
|
544 unsigned i;
|
|
545
|
|
546 for (i = 0; i < sizeof (s3_card_ids) / sizeof (struct s3_cards); i++)
|
|
547 if (chip_id == s3_card_ids[i].chip_id)
|
|
548 return i;
|
|
549 return -1;
|
|
550 }
|
|
551
|
|
552 static int s3_probe (int verbose, int force)
|
|
553 {
|
|
554 pciinfo_t lst[MAX_PCI_DEVICES];
|
|
555 unsigned i, num_pci;
|
|
556 int err;
|
|
557
|
|
558 if (force)
|
|
559 printf ("[s3_vid] Warning: forcing not supported yet!\n");
|
|
560 err = pci_scan (lst, &num_pci);
|
|
561 if (err)
|
|
562 {
|
|
563 printf ("[s3_vid] Error occurred during pci scan: %s\n", strerror (err));
|
|
564 return err;
|
|
565 }
|
|
566 else
|
|
567 {
|
|
568 err = ENXIO;
|
|
569 for (i = 0; i < num_pci; i++)
|
|
570 {
|
|
571 if (lst[i].vendor == VENDOR_S3_INC)
|
|
572 {
|
|
573 int idx;
|
|
574 const char *dname;
|
|
575 idx = find_chip (lst[i].device);
|
|
576 if (idx == -1)
|
|
577 continue;
|
|
578 dname = pci_device_name (lst[i].vendor, lst[i].device);
|
|
579 dname = dname ? dname : "Unknown chip";
|
|
580 printf ("[s3_vid] Found chip: %s\n", dname);
|
|
581 // FIXME: whats wrong here?
|
|
582 if ((lst[i].command & PCI_COMMAND_IO) == 0)
|
|
583 {
|
|
584 printf ("[s3_vid] Device is disabled, ignoring\n");
|
|
585 continue;
|
|
586 }
|
|
587 s3_cap.device_id = lst[i].device;
|
|
588 err = 0;
|
|
589 memcpy (&pci_info, &lst[i], sizeof (pciinfo_t));
|
|
590 break;
|
|
591 }
|
|
592 }
|
|
593 }
|
|
594 if (err && verbose)
|
|
595 printf ("[s3_vid] Can't find chip\n");
|
|
596 return err;
|
|
597 }
|
|
598
|
26099
|
599 static int s3_init (void)
|
26096
|
600 {
|
|
601 unsigned char cr36;
|
|
602 int mtrr, videoRam;
|
|
603 static unsigned char RamTrioVirge[] = { 4, 0, 3, 8, 2, 6, 1, 0 };
|
|
604 static unsigned char RamSavage3D[] = { 8, 4, 4, 2 };
|
|
605 static unsigned char RamSavage4[] = { 2, 4, 8, 12, 16, 32, 64, 32 };
|
|
606 static unsigned char RamSavageMX[] = { 2, 8, 4, 16, 8, 16, 4, 16 };
|
|
607 static unsigned char RamSavageNB[] = { 0, 2, 4, 8, 16, 32, 16, 2 };
|
|
608
|
|
609 enable_app_io ();
|
|
610
|
|
611 info = calloc (1, sizeof (s3_info));
|
|
612
|
|
613 info->chip.arch = s3_card_ids[find_chip (pci_info.device)].arch;
|
|
614
|
|
615 /* Switch to vga registers */
|
|
616 OUTPORT8 (0x3c3, INPORT8 (0x3c3) | 0x01);
|
|
617 OUTPORT8 (0x3c2, INPORT8 (0x3cc) | 0x01);
|
|
618 /* Unlock extended registers */
|
|
619 OUTPORT8 (vgaCRIndex, 0x38);
|
|
620 OUTPORT8 (vgaCRReg, 0x48);
|
|
621 OUTPORT8 (vgaCRIndex, 0x39);
|
|
622 OUTPORT8 (vgaCRReg, 0xa0);
|
|
623
|
|
624 if (info->chip.arch <= S3_VIRGE)
|
|
625 {
|
|
626 /* TODO: Improve detecting code */
|
|
627
|
|
628 /* Enable LFB */
|
|
629 OUTPORT8 (vgaCRIndex, LIN_ADDR_CTRL);
|
|
630 OUTPORT8 (vgaCRReg, INPORT8 (vgaCRReg) | ENABLE_LFB);
|
|
631 /* Enable NewMMIO */
|
|
632 OUTPORT8 (vgaCRIndex, EXT_MEM_CTRL1);
|
|
633 OUTPORT8 (vgaCRReg, INPORT8 (vgaCRReg) | ENABLE_NEWMMIO);
|
|
634 }
|
|
635
|
|
636 if (info->chip.arch < S3_SAVAGE3D)
|
|
637 info->control_base = map_phys_mem (pci_info.base0 + S3_NEWMMIO_REGBASE, S3_NEWMMIO_REGSIZE);
|
|
638 else if (info->chip.arch == S3_SAVAGE3D)
|
|
639 info->control_base = map_phys_mem (pci_info.base0 + S3_NEWMMIO_REGBASE, S3_NEWMMIO_REGSIZE_SAVAGE);
|
|
640 else
|
|
641 info->control_base = map_phys_mem (pci_info.base0, S3_NEWMMIO_REGSIZE_SAVAGE);
|
|
642
|
|
643 /* Unlock CRTC[0-7] */
|
|
644 VGAOUT8 (vgaCRIndex, 0x11);
|
|
645 VGAOUT8 (vgaCRReg, VGAIN8 (vgaCRReg) & 0x7f);
|
|
646 /* Unlock sequencer */
|
|
647 VGAOUT16 (0x3c4, 0x0608);
|
|
648 /* Detect amount of installed ram */
|
|
649 VGAOUT8 (vgaCRIndex, 0x36);
|
|
650 cr36 = VGAIN8 (vgaCRReg);
|
|
651
|
|
652 switch (info->chip.arch)
|
|
653 {
|
|
654 case S3_TRIO64V:
|
|
655 case S3_VIRGE:
|
|
656 videoRam = RamTrioVirge[(cr36 & 0xE0) >> 5] * 1024;
|
|
657 break;
|
|
658
|
|
659 case S3_SAVAGE3D:
|
|
660 videoRam = RamSavage3D[(cr36 & 0xC0) >> 6] * 1024;
|
|
661 break;
|
|
662
|
|
663 case S3_SAVAGE4:
|
|
664 /*
|
|
665 * The Savage4 has one ugly special case to consider. On
|
|
666 * systems with 4 banks of 2Mx32 SDRAM, the BIOS says 4MB
|
|
667 * when it really means 8MB. Why do it the same when you
|
|
668 * can do it different...
|
|
669 */
|
|
670 VGAOUT8 (vgaCRIndex, 0x68);
|
|
671 if ((VGAIN8 (vgaCRReg) & 0xC0) == (0x01 << 6))
|
|
672 RamSavage4[1] = 8;
|
|
673
|
|
674 case S3_SAVAGE2000:
|
|
675 videoRam = RamSavage4[(cr36 & 0xE0) >> 5] * 1024;
|
|
676 break;
|
|
677
|
|
678 case S3_SAVAGE_MX:
|
|
679 videoRam = RamSavageMX[(cr36 & 0x0E) >> 1] * 1024;
|
|
680 break;
|
|
681
|
|
682 case S3_PROSAVAGE:
|
|
683 videoRam = RamSavageNB[(cr36 & 0xE0) >> 5] * 1024;
|
|
684 break;
|
|
685
|
|
686 default:
|
|
687 /* How did we get here? */
|
|
688 videoRam = 0;
|
|
689 break;
|
|
690 }
|
|
691
|
|
692 printf ("[s3_vid] VideoRam = %d\n", videoRam);
|
|
693 info->chip.fbsize = videoRam * 1024;
|
|
694
|
|
695 if (info->chip.arch <= S3_SAVAGE3D)
|
|
696 mtrr = mtrr_set_type (pci_info.base0, info->chip.fbsize, MTRR_TYPE_WRCOMB);
|
|
697 else
|
|
698 mtrr = mtrr_set_type (pci_info.base1, info->chip.fbsize, MTRR_TYPE_WRCOMB);
|
|
699
|
|
700 if (mtrr != 0)
|
|
701 printf ("[s3_vid] Unable to setup MTRR: %s\n", strerror (mtrr));
|
|
702 else
|
|
703 printf ("[s3_vid] MTRR set up\n");
|
|
704
|
|
705 S3GetScrProp (info);
|
|
706 S3StreamsOn ();
|
|
707
|
|
708 return 0;
|
|
709 }
|
|
710
|
|
711 static void s3_destroy (void)
|
|
712 {
|
|
713 unmap_phys_mem (info->video_base, info->chip.fbsize);
|
|
714 if (S3_SAVAGE_SERIES (info->chip.arch))
|
|
715 unmap_phys_mem (info->control_base, S3_NEWMMIO_REGSIZE_SAVAGE);
|
|
716 else
|
|
717 unmap_phys_mem (info->control_base, S3_NEWMMIO_REGSIZE);
|
|
718
|
|
719 free (info);
|
|
720 }
|
|
721
|
|
722 static int s3_get_caps (vidix_capability_t * to)
|
|
723 {
|
|
724 memcpy (to, &s3_cap, sizeof (vidix_capability_t));
|
|
725 return 0;
|
|
726 }
|
|
727
|
|
728 static int is_supported_fourcc (uint32_t fourcc)
|
|
729 {
|
|
730 switch (fourcc)
|
|
731 {
|
|
732 //FIXME: Burst Command Interface should be used
|
|
733 // for planar to packed conversion
|
|
734 // case IMGFMT_YV12:
|
|
735 // case IMGFMT_I420:
|
|
736 case IMGFMT_UYVY:
|
|
737 case IMGFMT_YUY2:
|
|
738 case IMGFMT_Y211:
|
|
739 case IMGFMT_BGR15:
|
|
740 case IMGFMT_BGR16:
|
|
741 case IMGFMT_BGR24:
|
|
742 case IMGFMT_BGR32:
|
|
743 return 1;
|
|
744 default:
|
|
745 return 0;
|
|
746 }
|
|
747 }
|
|
748
|
|
749 static int s3_query_fourcc (vidix_fourcc_t * to)
|
|
750 {
|
|
751 if (is_supported_fourcc (to->fourcc))
|
|
752 {
|
|
753 to->depth = VID_DEPTH_ALL;
|
|
754 to->flags = VID_CAP_EXPAND | VID_CAP_SHRINK | VID_CAP_COLORKEY;
|
|
755 return 0;
|
|
756 }
|
|
757 else
|
|
758 to->depth = to->flags = 0;
|
|
759
|
|
760 return ENOSYS;
|
|
761 }
|
|
762
|
|
763 #if 0
|
|
764 static int s3_get_gkeys (vidix_grkey_t * grkey)
|
|
765 {
|
|
766 return 0;
|
|
767 }
|
|
768 #endif
|
|
769
|
|
770 static int s3_set_gkeys (const vidix_grkey_t * grkey)
|
|
771 {
|
|
772 if (grkey->ckey.op == CKEY_FALSE)
|
|
773 {
|
|
774 info->use_colorkey = 0;
|
|
775 info->vidixcolorkey = 0;
|
|
776 printf ("[s3_vid] Colorkeying disabled\n");
|
|
777 }
|
|
778 else
|
|
779 {
|
|
780 info->use_colorkey = 1;
|
|
781 info->vidixcolorkey = ((grkey->ckey.red << 16) | (grkey->ckey.green << 8) | grkey->ckey.blue);
|
|
782 printf ("[s3_vid] Set colorkey 0x%x\n", info->vidixcolorkey);
|
|
783 }
|
|
784 if (S3SetColorKey)
|
|
785 S3SetColorKey ();
|
|
786 return 0;
|
|
787 }
|
|
788
|
|
789 static int s3_get_eq (vidix_video_eq_t * eq)
|
|
790 {
|
|
791 memcpy (eq, &(info->eq), sizeof (vidix_video_eq_t));
|
|
792 return 0;
|
|
793 }
|
|
794
|
|
795 static int s3_set_eq (const vidix_video_eq_t * eq)
|
|
796 {
|
|
797 if (eq->cap & VEQ_CAP_BRIGHTNESS)
|
|
798 info->eq.brightness = eq->brightness;
|
|
799 if (eq->cap & VEQ_CAP_CONTRAST)
|
|
800 info->eq.contrast = eq->contrast;
|
|
801 if (eq->cap & VEQ_CAP_SATURATION)
|
|
802 info->eq.saturation = eq->saturation;
|
|
803 if (eq->cap & VEQ_CAP_HUE)
|
|
804 info->eq.hue = eq->hue;
|
|
805 if (S3SetColor)
|
|
806 S3SetColor ();
|
|
807 return 0;
|
|
808 }
|
|
809
|
|
810 static int s3_config_playback (vidix_playback_t * vinfo)
|
|
811 {
|
|
812 unsigned int i, bpp;
|
|
813
|
|
814 if (!is_supported_fourcc (vinfo->fourcc))
|
|
815 return -1;
|
|
816
|
|
817 info->src_w = vinfo->src.w;
|
|
818 info->src_h = vinfo->src.h;
|
|
819
|
|
820 info->drw_w = vinfo->dest.w;
|
|
821 info->drw_h = vinfo->dest.h;
|
|
822
|
|
823 info->wx = vinfo->dest.x;
|
|
824 info->wy = vinfo->dest.y;
|
|
825 info->format = vinfo->fourcc;
|
|
826
|
|
827 info->eq.cap = VEQ_CAP_BRIGHTNESS | VEQ_CAP_CONTRAST |
|
|
828 VEQ_CAP_SATURATION | VEQ_CAP_HUE;
|
|
829 info->eq.brightness = 0;
|
|
830 info->eq.contrast = 0;
|
|
831 info->eq.saturation = 0;
|
|
832 info->eq.hue = 0;
|
|
833
|
|
834 vinfo->offset.y = 0;
|
|
835 vinfo->offset.v = 0;
|
|
836 vinfo->offset.u = 0;
|
|
837
|
|
838 vinfo->dest.pitch.y = 32;
|
|
839 vinfo->dest.pitch.u = 32;
|
|
840 vinfo->dest.pitch.v = 32;
|
|
841
|
|
842 switch (vinfo->fourcc)
|
|
843 {
|
|
844 case IMGFMT_Y211:
|
|
845 bpp = 1;
|
|
846 break;
|
|
847 case IMGFMT_BGR24:
|
|
848 bpp = 3;
|
|
849 break;
|
|
850 case IMGFMT_BGR32:
|
|
851 bpp = 4;
|
|
852 break;
|
|
853 default:
|
|
854 bpp = 2;
|
|
855 break;
|
|
856 }
|
|
857
|
|
858 info->pitch = ((info->src_w * bpp) + 15) & ~15;
|
|
859 info->pitch |= ((info->pitch / bpp) << 16);
|
|
860
|
|
861 vinfo->frame_size = (info->pitch & 0xffff) * info->src_h;
|
|
862 info->frame_size = vinfo->frame_size;
|
|
863
|
|
864 info->picture_offset = info->screen_x * info->screen_y * (info->bpp >> 3);
|
|
865 if (info->picture_offset > (info->chip.fbsize - vinfo->frame_size))
|
|
866 {
|
|
867 printf ("[s3_vid] Not enough memory for overlay\n");
|
|
868 return -1;
|
|
869 }
|
|
870
|
|
871 if (info->chip.arch <= S3_SAVAGE3D)
|
|
872 info->video_base = map_phys_mem (pci_info.base0, info->chip.fbsize);
|
|
873 else
|
|
874 info->video_base = map_phys_mem (pci_info.base1, info->chip.fbsize);
|
|
875
|
|
876 if (info->video_base == NULL)
|
|
877 {
|
|
878 printf ("[s3_vid] errno = %s\n", strerror (errno));
|
|
879 return -1;
|
|
880 }
|
|
881
|
|
882 info->picture_base = (uint32_t) info->video_base + info->picture_offset;
|
|
883
|
|
884 vinfo->dga_addr = (void *) (info->picture_base);
|
|
885
|
|
886 vinfo->num_frames = (info->chip.fbsize - info->picture_offset) / vinfo->frame_size;
|
|
887 if (vinfo->num_frames > VID_PLAY_MAXFRAMES)
|
|
888 vinfo->num_frames = VID_PLAY_MAXFRAMES;
|
|
889
|
|
890 for (i = 0; i < vinfo->num_frames; i++)
|
|
891 vinfo->offsets[i] = vinfo->frame_size * i;
|
|
892
|
|
893 return 0;
|
|
894 }
|
|
895
|
|
896 static int s3_playback_on (void)
|
|
897 {
|
|
898 S3DisplayVideo ();
|
|
899 return 0;
|
|
900 }
|
|
901
|
|
902 static int s3_playback_off (void)
|
|
903 {
|
|
904 S3StreamsOff ();
|
|
905 return 0;
|
|
906 }
|
|
907
|
|
908 static int s3_frame_sel (unsigned int frame)
|
|
909 {
|
|
910 OUTREG (SSTREAM_FBADDR0_REG, info->picture_offset + (info->frame_size * frame));
|
|
911 return 0;
|
|
912 }
|
|
913
|
|
914 VDXDriver s3_drv = {
|
|
915 "s3",
|
|
916 NULL,
|
|
917 .probe = s3_probe,
|
|
918 .get_caps = s3_get_caps,
|
|
919 .query_fourcc = s3_query_fourcc,
|
|
920 .init = s3_init,
|
|
921 .destroy = s3_destroy,
|
|
922 .config_playback = s3_config_playback,
|
|
923 .playback_on = s3_playback_on,
|
|
924 .playback_off = s3_playback_off,
|
|
925 .frame_sel = s3_frame_sel,
|
|
926 .get_eq = s3_get_eq,
|
|
927 .set_eq = s3_set_eq,
|
|
928 .set_gkey = s3_set_gkeys,
|
|
929 };
|