1 /*
2  * ramdac.c:
3  *
4  * This file contains RAMDAC definitions of type DacMethods for
5  * various DACs.
6  *
7  * Note that the restoreState function is the only function that
8  * should program the DAC registers; the initializeState function
9  * should merely define the values that will be written in a
10  * subsequent call of the restore funtion.
11  */
12 
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include "libvga.h"
16 
17 #include "timing.h"
18 #include "vgaregs.h"
19 #include "driver.h"		/* for __svgalib_driver_report */
20 #include "ramdac.h"
21 
22 /*
23  * The following function probes the DACs in daclist, which must be
24  * terminated by NULL. It returns the detected DAC if successful, NULL
25  * otherwise. The detected DAC is also initialized.
26  */
27 
__svgalib_probeDacs(DacMethods ** dacs_to_probe)28 DacMethods *__svgalib_probeDacs(DacMethods ** dacs_to_probe)
29 {
30     /* Probe for a RAMDAC. */
31     for (;;) {
32 	DacMethods *dac;
33 	dac = *dacs_to_probe;
34 	if (dac == NULL)
35 	    /* None found. */
36 	    return NULL;
37 	if (dac->probe()) {
38 	    dac->initialize();
39 	    return dac;
40 	}
41 	dacs_to_probe++;
42     }
43 }
44 
__svgalib_setDacSpeed(int dacspeed,int defspeed)45 int __svgalib_setDacSpeed(int dacspeed, int defspeed)
46 {
47     if (!dacspeed) {
48 	if (__svgalib_driver_report)
49 	    printf("svgalib: Assuming %dMHz DAC.\n", defspeed / 1000);
50 	dacspeed = defspeed;
51     } else {
52 	if (__svgalib_driver_report)
53 	    printf("svgalib: DAC speed set to %dMHz.\n", dacspeed / 1000);
54     }
55     return dacspeed;
56 }
57 
58 #ifndef __OPTIMIZE__	/* otherwise inlined from ramdac.h */
_ramdac_dactocomm(void)59 void _ramdac_dactocomm(void)
60 {
61     inb(PEL_IW);
62     inb(PEL_MSK);
63     inb(PEL_MSK);
64     inb(PEL_MSK);
65     inb(PEL_MSK);
66 }
67 
_ramdac_dactopel(void)68 void _ramdac_dactopel(void)
69 {
70     inb(PEL_IW);
71 }
72 
_ramdac_setcomm(unsigned char data)73 unsigned char _ramdac_setcomm(unsigned char data)
74 {
75     _ramdac_dactocomm();
76     outb(PEL_MSK, data);
77     _ramdac_dactocomm();
78     return inb(PEL_MSK);
79 }
80 #endif
81 
82 /*
83  * List of all DACs.
84  */
85 
86 DacMethods *__svgalib_all_dacs[] =
87 {
88 #ifdef INCLUDE_NORMAL_DAC
89     &__svgalib_normal_dac_methods,
90 #endif
91 #ifdef INCLUDE_S3_SDAC_DAC
92     &__svgalib_S3_SDAC_methods,
93 #endif
94 #ifdef INCLUDE_S3_GENDAC_DAC
95     &__svgalib_S3_GENDAC_methods,
96 #endif
97 #ifdef INCLUDE_S3_TRIO64_DAC
98     &__svgalib_Trio64_methods,
99 #endif
100 #ifdef INCLUDE_SIERRA_DAC
101     &__svgalib_Sierra_32K_methods,
102 #endif
103 #ifdef INCLUDE_SC15025_DAC
104     &__svgalib_SC15025_methods,
105 #endif
106 #ifdef INCLUDE_ATT20C490_DAC
107     &__svgalib_ATT20C490_methods,
108 #endif
109 #ifdef INCLUDE_ATT20C498_DAC
110     &__svgalib_ATT20C498_methods,
111 #endif
112 #ifdef INCLUDE_ICW_DAC
113     &__svgalib_ICW_methods,
114 #endif
115 #ifdef INCLUDE_SC1148X_DAC
116     &__svgalib_SC1148X_methods,
117 #endif
118     NULL
119 };
120