1 #include <u.h>
2 #include <libc.h>
3 #include <bio.h>
4
5 #include "pci.h"
6 #include "vga.h"
7
8 /*
9 * ATT21C498 16-Bit Interface RAMDAC
10 * PrecisionDAC Technology
11 */
12 enum {
13 Cr0 = 0x00, /* Control register 0 */
14 Midr = 0x01, /* Manufacturer's identification register */
15 Didr = 0x02, /* Device identification register */
16 Rtest = 0x03, /* Red signature analysis register */
17 Gtest = 0x04, /* Green signature analysis register */
18 Btest = 0x05, /* Blue signature analysis register */
19
20 Nir = 0x06, /* number of indirect registers */
21 };
22
23 static void
attdacio(uchar reg)24 attdacio(uchar reg)
25 {
26 int i;
27
28 /*
29 * Access to the indirect registers is accomplished by reading
30 * Pixmask 4 times, then subsequent reads cycle through the
31 * indirect registers. Any I/O write to a direct register resets
32 * the sequence.
33 */
34 inportb(PaddrW);
35 for(i = 0; i < 4+reg; i++)
36 inportb(Pixmask);
37 }
38
39 uchar
attdaci(uchar reg)40 attdaci(uchar reg)
41 {
42 uchar r;
43
44 attdacio(reg);
45 r = inportb(Pixmask);
46
47 inportb(PaddrW);
48 return r;
49 }
50
51 void
attdaco(uchar reg,uchar data)52 attdaco(uchar reg, uchar data)
53 {
54 attdacio(reg);
55 outportb(Pixmask, data);
56 inportb(PaddrW);
57 }
58
59 static void
options(Vga *,Ctlr * ctlr)60 options(Vga*, Ctlr* ctlr)
61 {
62 ctlr->flag |= Hpclk2x8|Foptions;
63 }
64
65 static void
init(Vga * vga,Ctlr * ctlr)66 init(Vga* vga, Ctlr* ctlr)
67 {
68 ulong grade, pclk;
69 char *p;
70
71 /*
72 * Part comes in -170, -130 and -110MHz speed-grades.
73 * In 8-bit mode the max. PCLK is 80MHz for the -110 part
74 * and 110MHz for the others. In 2x8-bit mode, the max.
75 * PCLK is the speed-grade, using the 2x doubler.
76 * We can use mode 2 (2x8-bit, internal clock doubler)
77 * if connected to a suitable graphics chip, e.g. the
78 * S3 Vision864.
79 * Work out the part speed-grade from name. Name can have,
80 * e.g. '-135' on the end for 135MHz part.
81 */
82 grade = 110000000;
83 if(p = strrchr(ctlr->name, '-'))
84 grade = strtoul(p+1, 0, 0) * 1000000;
85
86 if(vga->ctlr && ((vga->ctlr->flag & Hpclk2x8) && vga->mode->z == 8))
87 pclk = grade;
88 else{
89 if(grade == 110000000)
90 pclk = 80000000;
91 else
92 pclk = 110000000;
93 }
94
95 /*
96 * If we don't already have a desired pclk,
97 * take it from the mode.
98 * Check it's within range.
99 */
100 if(vga->f[0] == 0)
101 vga->f[0] = vga->mode->frequency;
102
103 /*
104 * Determine whether to use 2x8-bit mode or not.
105 * If yes and the clock has already been initialised,
106 * initialise it again.
107 */
108 if(vga->ctlr && (vga->ctlr->flag & Hpclk2x8) && vga->mode->z == 8 && vga->f[0] > 80000000){
109 vga->f[0] /= 2;
110 resyncinit(vga, ctlr, Upclk2x8, 0);
111 }
112 if(vga->f[0] > pclk)
113 error("%s: invalid pclk - %ld\n", ctlr->name, vga->f[0]);
114
115 ctlr->flag |= Finit;
116 }
117
118 static void
load(Vga * vga,Ctlr * ctlr)119 load(Vga* vga, Ctlr* ctlr)
120 {
121 uchar mode, x;
122
123 /*
124 * Put the chip to sleep.
125 */
126 x = attdaci(Cr0);
127 attdaco(Cr0, x|0x04);
128
129 mode = 0x00;
130 if(ctlr->flag & Upclk2x8)
131 mode = 0x20;
132
133 /*
134 * Set the mode in the RAMDAC, setting 6/8-bit colour
135 * as appropriate and waking the chip back up.
136 */
137 if(vga->mode->z == 8 && 0)
138 mode |= 0x02;
139 attdaco(Cr0, mode);
140
141 ctlr->flag |= Fload;
142 }
143
144 static void
dump(Vga *,Ctlr * ctlr)145 dump(Vga*, Ctlr* ctlr)
146 {
147 int i;
148
149 printitem(ctlr->name, "");
150 for(i = 0; i < Nir; i++)
151 printreg(attdaci(i));
152 }
153
154 Ctlr att21c498 = {
155 "att21c498", /* name */
156 0, /* snarf */
157 options, /* options */
158 init, /* init */
159 load, /* load */
160 dump, /* dump */
161 };
162