summaryrefslogtreecommitdiff
path: root/sys/src/cmd/aux/vga/tvp3026.c
blob: 2125007956f798f66e2d98fa94f578f2863a524d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include <u.h>
#include <libc.h>
#include <bio.h>

#include "pci.h"
#include "vga.h"

/*
 * Tvp3026 Viewpoint Video Interface Palette.
 * Assumes hooked up to an S3 chip of some kind.
 * Why is register access different from the
 * Tvp302[05]?
 */
enum {
	Index		= 0x00,		/* Index register */
	Data		= 0x0A,		/* Data register */

	Id		= 0x3F,		/* ID Register */
	Tvp3026		= 0x26,
};

static uchar
tvp3026io(uchar reg, uchar data)
{
	uchar crt55;

	crt55 = vgaxi(Crtx, 0x55) & 0xFC;
	vgaxo(Crtx, 0x55, crt55|((reg>>2) & 0x03));
	vgao(dacxreg[reg & 0x03], data);

	return crt55;
}

static uchar
tvp3026i(uchar reg)
{
	uchar crt55, r;

	crt55 = vgaxi(Crtx, 0x55) & 0xFC;
	vgaxo(Crtx, 0x55, crt55|((reg>>2) & 0x03));
	r = vgai(dacxreg[reg & 0x03]);
	vgaxo(Crtx, 0x55, crt55);

	return r;
}

uchar
tvp3026xi(uchar index)
{
	uchar crt55, r;

	crt55 = tvp3026io(Index, index);
	vgaxo(Crtx, 0x55, crt55|((Data>>2) & 0x03));
	r = vgai(dacxreg[Data & 0x03]);
	vgaxo(Crtx, 0x55, crt55);

	return r;
}

static void
tvp3026o(uchar reg, uchar data)
{
	uchar crt55;

	crt55 = tvp3026io(reg, data);
	vgaxo(Crtx, 0x55, crt55);
}

void
tvp3026xo(uchar index, uchar data)
{
	uchar crt55;

	crt55 = tvp3026io(Index, index);
	vgaxo(Crtx, 0x55, crt55|((Data>>2) & 0x03));
	vgao(dacxreg[Data & 0x03], data);
	vgaxo(Crtx, 0x55, crt55);
}

static void
options(Vga*, Ctlr* ctlr)
{
	ctlr->flag |= Hclk2|Hextsid|Henhanced|Foptions;
}

static void
init(Vga* vga, Ctlr* ctlr)
{
	ulong grade;
	char *p;

	/*
	 * Work out the part speed-grade from name. Name can have,
	 * e.g. '-135' on the end  for 135MHz part.
	 */
	grade = 110000000;
	if(p = strrchr(ctlr->name, '-'))
		grade = strtoul(p+1, 0, 0) * 1000000;

	/*
	 * If we don't already have a desired pclk,
	 * take it from the mode.
	 * Check it's within range.
	 */
	if(vga->f[0] == 0)
		vga->f[0] = vga->mode->frequency;
	if(vga->f[0] > grade)
		error("%s: invalid pclk - %ld\n", ctlr->name, vga->f[0]);

	/*
	 * Determine whether to use clock-doubler or not.
	 */
	if((ctlr->flag & Uclk2) == 0 && vga->mode->z == 8 && vga->f[0] > 85000000)
		resyncinit(vga, ctlr, Uclk2, 0);

	ctlr->flag |= Finit;
}

static void
load(Vga* vga, Ctlr* ctlr)
{
	uchar x;

	/*
	 * General Control:
	 *	output sync polarity
	 * It's important to set this properly and to turn off the
	 * VGA controller H and V syncs. Can't be set in VGA mode.
	 */
	x = 0x00;
	if((vga->misc & 0x40) == 0)
		x |= 0x01;
	if((vga->misc & 0x80) == 0)
		x |= 0x02;
	tvp3026xo(0x1D, x);
	vga->misc |= 0xC0;
	vgao(MiscW, vga->misc);

	ctlr->flag |= Fload;
}

static void
dump(Vga*, Ctlr* ctlr)
{
	int i;
	ulong clock[4], f;

	printitem(ctlr->name, "direct");
	for(i = 0; i < 16; i++)
		printreg(tvp3026i(i));

	printitem(ctlr->name, "index");
	for(i = 0; i < 64; i++)
		printreg(tvp3026xi(i));

	printitem(ctlr->name, "PCLK");
	for(i = 0; i < 3; i++){
		tvp3026xo(0x2C, (i<<4)|(i<<2)|i);
		printreg(clock[i] = tvp3026xi(0x2D));
	}
	f = (RefFreq*(65-clock[1]))/(65-(clock[0] & 0x3F));
	f >>= clock[2] & 0x03;
	Bprint(&stdout, "%23ld", f);

	printitem(ctlr->name, "MCLK");
	for(i = 0; i < 3; i++){
		tvp3026xo(0x2C, (i<<4)|(i<<2)|i);
		printreg(clock[i] = tvp3026xi(0x2E));
	}
	f = (RefFreq*(65-clock[1]))/(65-(clock[0] & 0x3F));
	f >>= clock[2] & 0x03;
	Bprint(&stdout, "%23ld", f);

	printitem(ctlr->name, "LCLK");
	for(i = 0; i < 3; i++){
		tvp3026xo(0x2C, (i<<4)|(i<<2)|i);
		printreg(clock[i] = tvp3026xi(0x2F));
	}
	Bprint(&stdout, "\n");
}

Ctlr tvp3026 = {
	"tvp3026",			/* name */
	0,				/* snarf */
	options,			/* options */
	init,				/* init */
	0,				/* load */
	dump,				/* dump */
};