1 /*
2 * sierra.c:
3 *
4 * RAMDAC definition for basic Sierra, SC15025 and SC1148x.
5 */
6
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include "libvga.h"
10
11 #include "timing.h"
12 #include "vgaregs.h"
13 #include "driver.h" /* for __svgalib_driver_report */
14 #include "ramdac.h"
15
16 /*
17 * RAMDAC definition for basic Sierra-type DAC
18 * that can do 32K (5-5-5) color mode (16bpp) with doubled VCLK.
19 * A value of 0x80 is written to the Hidden DAC register for this mode.
20 */
21
22 #ifdef INCLUDE_SIERRA_DAC_TEST
Sierra_32K_probe(void)23 static int Sierra_32K_probe(void)
24 {
25 /* Should return 1 for any Sierra-type DAC. */
26 return 0;
27 }
28 #else
29 #define Sierra_32K_probe 0
30 #endif
31
32 #ifdef INCLUDE_SIERRA_DAC
Sierra_32K_init(void)33 static void Sierra_32K_init(void)
34 {
35 /* Should probe the exact DAC type. */
36 if (__svgalib_driver_report)
37 printf("svgalib: Using Sierra 32K DAC.\n");
38 }
39
Sierra_32K_map_clock(int bpp,int pixelclock)40 static int Sierra_32K_map_clock(int bpp, int pixelclock)
41 {
42 if (bpp == 16)
43 return pixelclock * 2;
44 return pixelclock;
45 }
46
Sierra_32K_map_horizontal_crtc(int bpp,int pixelclock,int htiming)47 static int Sierra_32K_map_horizontal_crtc(int bpp, int pixelclock, int htiming)
48 {
49 if (bpp == 16)
50 return htiming * 2;
51 return htiming;
52 }
53 #endif
54
55 #if defined(INCLUDE_SIERRA_DAC) || defined(INCLUDE_ICW_DAC) || \
56 defined(INCLUDE_ATT20C490_DAC) || defined(INCLUDE_ATT20C498_DAC)
__svgalib_Sierra_32K_savestate(unsigned char * regs)57 void __svgalib_Sierra_32K_savestate(unsigned char *regs)
58 {
59 _ramdac_dactocomm();
60 regs[0] = inb(PEL_MSK);
61 }
62
__svgalib_Sierra_32K_restorestate(const unsigned char * regs)63 void __svgalib_Sierra_32K_restorestate(const unsigned char *regs)
64 {
65 _ramdac_dactocomm();
66 outb(PEL_MSK, regs[0]);
67 }
68
69 #endif
70
71 #ifdef INCLUDE_SIERRA_DAC
Sierra_32K_initializestate(unsigned char * regs,int bpp,int colormode,int pixelclock)72 static void Sierra_32K_initializestate(unsigned char *regs, int bpp, int colormode,
73 int pixelclock)
74 {
75 regs[0] = 0;
76 if (colormode == RGB16_555)
77 regs[0] = 0x80;
78 }
79
Sierra_32K_qualify_cardspecs(CardSpecs * cardspecs,int dacspeed)80 static void Sierra_32K_qualify_cardspecs(CardSpecs * cardspecs, int dacspeed)
81 {
82 dacspeed = __svgalib_setDacSpeed(dacspeed, 80000);
83 cardspecs->maxPixelClock4bpp = dacspeed;
84 cardspecs->maxPixelClock8bpp = dacspeed;
85 cardspecs->maxPixelClock16bpp = dacspeed / 2;
86 cardspecs->maxPixelClock24bpp = 0;
87 cardspecs->maxPixelClock32bpp = 0;
88 cardspecs->mapClock = Sierra_32K_map_clock;
89 cardspecs->mapHorizontalCrtc = Sierra_32K_map_horizontal_crtc;
90 cardspecs->flags |= NO_RGB16_565;
91 }
92
93 DacMethods __svgalib_Sierra_32K_methods =
94 {
95 SIERRA_32K,
96 "Sierra 32K colors VGA DAC",
97 0,
98 Sierra_32K_probe,
99 Sierra_32K_init,
100 Sierra_32K_qualify_cardspecs,
101 __svgalib_Sierra_32K_savestate,
102 __svgalib_Sierra_32K_restorestate,
103 Sierra_32K_initializestate,
104 1 /* State size. */
105 };
106 #endif
107
108
109 /*
110 * RAMDAC definition for Sierra 15025/26
111 */
112
113 #ifdef INCLUDE_SC15025_DAC_TEST
114 static unsigned char SC15025_Rev;
115
SC15025_probe(void)116 static int SC15025_probe(void)
117 {
118 unsigned char c, id[4];
119 int i, flag = 0;
120
121 _ramdac_dactocomm();
122 c = inb(PEL_MSK);
123 _ramdac_setcomm(c | 0x10);
124 for (i = 0; i < 4; i++) {
125 outb(PEL_IR, 0x9 + i);
126 id[i] = inb(PEL_IW);
127 }
128 _ramdac_setcomm(c);
129 _ramdac_dactopel();
130 if (id[0] == 'S' && /* Sierra */
131 ((id[1] << 8) | id[2]) == 15025) { /* unique for the SC 15025/26 */
132 flag = 1;
133 SC15025_Rev = id[3];
134 }
135 return flag;
136 }
137 #else
138 #define SC15025_probe 0
139 #define SC15025_Rev ' '
140 #endif
141
142 #ifdef INCLUDE_SC15025_DAC
SC15025_init(void)143 static void SC15025_init(void)
144 {
145 if (__svgalib_driver_report)
146 printf("svgalib: Using Sierra 15025/26%c truecolor DAC.\n", SC15025_Rev);
147 }
148
SC15025_initializestate(unsigned char * regs,int bpp,int colormode,int pixelclock)149 static void SC15025_initializestate(unsigned char *regs, int bpp, int colormode,
150 int pixelclock)
151 {
152 regs[0] = 0;
153 regs[1] = 0;
154 regs[2] = 0;
155 if (colormode == RGB16_555) {
156 regs[0] = 0x80;
157 regs[1] = 1;
158 } else if (colormode == RGB16_565) {
159 regs[0] = 0xC0;
160 regs[1] = 1;
161 } else if (colormode == RGB32_888_B) {
162 regs[0] = 0x40;
163 regs[1] = 1;
164 regs[2] = 1;
165 }
166 /* ARI: FIXME: regs[1] should be 1 for CLUT8_8 */
167 /* also: OR 8 to regs[0] to enable gamma correction */
168 }
169
SC15025_savestate(unsigned char * regs)170 static void SC15025_savestate(unsigned char *regs)
171 {
172 _ramdac_dactocomm();
173 regs[0] = inb(PEL_MSK);
174 _ramdac_setcomm(regs[0] | 0x10);
175 _ramdac_dactocomm();
176 outb(PEL_IR, 8);
177 regs[1] = inb(PEL_IW); /* Aux control */
178 outb(PEL_IR, 16);
179 regs[2] = inb(PEL_IW); /* Pixel Repack */
180 _ramdac_setcomm(regs[0]);
181 }
182
SC15025_restorestate(const unsigned char * regs)183 static void SC15025_restorestate(const unsigned char *regs)
184 {
185 unsigned char c;
186
187 _ramdac_dactocomm();
188 c = inb(PEL_MSK);
189 _ramdac_setcomm(c | 0x10);
190 _ramdac_dactocomm();
191 outb(PEL_IR, 8);
192 outb(PEL_IW, regs[1]); /* Aux control */
193 outb(PEL_IR, 16);
194 outb(PEL_IW, regs[2]); /* Pixel Repack */
195 _ramdac_setcomm(c);
196 _ramdac_setcomm(regs[0]);
197 }
198
SC15025_map_clock(int bpp,int pixelclock)199 static int SC15025_map_clock(int bpp, int pixelclock)
200 {
201 if (bpp == 32)
202 return pixelclock * 2;
203 return pixelclock;
204 }
205
SC15025_map_horizontal_crtc(int bpp,int pixelclock,int htiming)206 static int SC15025_map_horizontal_crtc(int bpp, int pixelclock, int htiming)
207 {
208 if (bpp == 16)
209 return htiming * 2;
210 if (bpp == 32)
211 return htiming * 4;
212 return htiming;
213 }
214
SC15025_qualify_cardspecs(CardSpecs * cardspecs,int dacspeed)215 static void SC15025_qualify_cardspecs(CardSpecs * cardspecs, int dacspeed)
216 {
217 dacspeed = __svgalib_setDacSpeed(dacspeed, 110000);
218 cardspecs->maxPixelClock4bpp = dacspeed;
219 cardspecs->maxPixelClock8bpp = dacspeed;
220 cardspecs->maxPixelClock16bpp = dacspeed / 2;
221 cardspecs->maxPixelClock24bpp = 0;
222 cardspecs->maxPixelClock32bpp = dacspeed / 3;
223 cardspecs->mapClock = SC15025_map_clock;
224 cardspecs->mapHorizontalCrtc = SC15025_map_horizontal_crtc;
225 }
226
227 DacMethods __svgalib_SC15025_methods =
228 {
229 SIERRA_15025,
230 "Sierra SC15025/6 DAC",
231 0,
232 SC15025_probe,
233 SC15025_init,
234 SC15025_qualify_cardspecs,
235 SC15025_savestate,
236 SC15025_restorestate,
237 SC15025_initializestate,
238 3 /* State size. */
239 };
240 #endif
241
242 /*
243 * RAMDAC definition for Sierra 1148x Series.
244 * 11482, 83, and 84 (Mark 2) can do 32K (5-5-5) color mode (16bpp).
245 * 11485, 87, and 89 (Mark 3) additionally can do 64K (5-6-5) color mode,
246 * but are not autodetected since they cannot be distinguished from Mark 2.
247 * 11486 really is a Sierra 32K dac, and should have been set by user.
248 *
249 * Note that these dacs are different from 'Sierra 32K', since they can be
250 * detected as such, while there are clones that work compatible to the
251 * Sierra dacs, but cannot be autodetected. To avoid such dacs to fail
252 * the type 'Sierra 32K' still refers to them, while this new type
253 * 'SC1148x Series' refers to original Sierra dacs.
254 *
255 * ATTENTION: THIS TEST MUST BE LAST IN CHAIN, SINCE MANY BETTER DACS
256 * IMPLEMENT 32K MODES COMPATIBLE TO THIS ONE AND WOULD BE DETECTED AS
257 * SIERRA!
258 *
259 */
260
261 #ifdef INCLUDE_SC1148X_DAC_TEST
SC1148X_probe(void)262 static int SC1148X_probe(void)
263 {
264 unsigned char oc, op, tmp, tmp2;
265 int flag = 0;
266
267 _ramdac_dactopel();
268 tmp = inb(PEL_MSK);
269 do {
270 tmp2 = tmp;
271 tmp = inb(PEL_MSK);
272 } while (tmp2 != tmp);
273 inb(PEL_IW);
274 inb(PEL_MSK);
275 inb(PEL_MSK);
276 inb(PEL_MSK);
277 for (tmp2 = 9; tmp != 0x8E && tmp2 > 0; tmp2--)
278 tmp = inb(PEL_MSK);
279 if (tmp != 0x8E) {
280 _ramdac_dactocomm();
281 oc = inb(PEL_MSK);
282 _ramdac_dactopel();
283 op = inb(PEL_MSK);
284 tmp = oc ^ 0xFF;
285 outb(PEL_MSK, tmp);
286 _ramdac_dactocomm();
287 tmp2 = inb(PEL_MSK);
288 if (tmp2 != tmp) {
289 tmp = _ramdac_setcomm(tmp = oc ^ 0x60);
290 if ((tmp & 0xe0) == (tmp2 & 0xe0)) {
291 tmp = inb(PEL_MSK);
292 _ramdac_dactopel();
293 if (tmp != inb(PEL_MSK))
294 flag = 1; /* Sierra Mark 2 or 3 */
295 } else {
296 /* We have a Sierra SC11486 */
297 #ifdef INCLUDE_SIERRA_DAC
298 flag = 1;
299 /* We do some ugly trickery here to patch SC1148X Series
300 descriptor with values from Sierra 32K descriptor, since
301 this is what whe really have detected! */
302 __svgalib_SC1148X_methods.id = SIERRA_32K;
303 __svgalib_SC1148X_methods.name = __svgalib_Sierra_32K_methods.name;
304 __svgalib_SC1148X_methods.initialize = __svgalib_Sierra_32K_methods.initialize;
305 __svgalib_SC1148X_methods.qualifyCardSpecs = __svgalib_Sierra_32K_methods.qualifyCardSpecs ;
306 __svgalib_SC1148X_methods.initializeState = __svgalib_Sierra_32K_methods.initializeState ;
307 #endif
308 }
309 _ramdac_dactocomm();
310 outb(PEL_MSK, oc);
311 }
312 _ramdac_dactopel();
313 outb(PEL_MSK, op);
314 } else {
315 _ramdac_dactopel();
316 /* Diamond SS2410 */
317 }
318 return flag;
319 }
320 #else
321 #define SC1148x_probe 0
322 #endif
323
324 #ifdef INCLUDE_SC1148X_DAC
SC1148X_init(void)325 static void SC1148X_init(void)
326 {
327 if (__svgalib_driver_report)
328 printf("svgalib: Using Sierra 1148x series 32K DAC.\n");
329 }
330
SC1148X_initializestate(unsigned char * regs,int bpp,int colormode,int pixelclock)331 static void SC1148X_initializestate(unsigned char *regs, int bpp, int colormode,
332 int pixelclock)
333 {
334 regs[0] = 0;
335 if (colormode == RGB16_555)
336 regs[0] = 0xA0;
337 /* Mark 3 (not autodetected) */
338 else if (colormode == RGB16_565)
339 regs[0] = 0xE0;
340 }
341
SC1148X_qualify_cardspecs(CardSpecs * cardspecs,int dacspeed)342 static void SC1148X_qualify_cardspecs(CardSpecs * cardspecs, int dacspeed)
343 {
344 dacspeed = __svgalib_setDacSpeed(dacspeed, 110000);
345 cardspecs->maxPixelClock4bpp = dacspeed;
346 cardspecs->maxPixelClock8bpp = dacspeed;
347 cardspecs->maxPixelClock16bpp = dacspeed / 2;
348 cardspecs->maxPixelClock24bpp = 0;
349 cardspecs->maxPixelClock32bpp = 0;
350 cardspecs->mapClock = Sierra_32K_map_clock;
351 cardspecs->mapHorizontalCrtc = Sierra_32K_map_horizontal_crtc;
352 cardspecs->flags |= NO_RGB16_565; /* Mark 3 (11485,87, and higher) can */
353 }
354
355 DacMethods __svgalib_SC1148X_methods =
356 {
357 SIERRA_1148X,
358 "Sierra SC1148x series 32K colors VGA DAC",
359 0,
360 SC1148X_probe,
361 SC1148X_init,
362 SC1148X_qualify_cardspecs,
363 __svgalib_Sierra_32K_savestate,
364 __svgalib_Sierra_32K_restorestate,
365 SC1148X_initializestate,
366 1 /* State size. */
367 };
368 #endif
369