xref: /plan9/sys/src/cmd/aux/vga/sc15025.c (revision 9a747e4fd48b9f4522c70c07e8f882a15030f964)
1 #include <u.h>
2 #include <libc.h>
3 #include <bio.h>
4 
5 #include "pci.h"
6 #include "vga.h"
7 
8 /*
9  * Sierra SC1502[56] HiCOLOR-24 Palette.
10  */
11 static void
pixmask(void)12 pixmask(void)
13 {
14 	inportb(PaddrW);
15 }
16 
17 static void
commandrw(void)18 commandrw(void)
19 {
20 	int i;
21 
22 	pixmask();
23 	for(i = 0; i < 4; i++)
24 		inportb(Pixmask);
25 }
26 
27 static uchar
commandr(void)28 commandr(void)
29 {
30 	uchar command;
31 
32 	commandrw();
33 	command = inportb(Pixmask);
34 	pixmask();
35 
36 	return command;
37 }
38 
39 static void
commandw(uchar command)40 commandw(uchar command)
41 {
42 	commandrw();
43 	outportb(Pixmask, command);
44 	pixmask();
45 }
46 
47 static void
options(Vga *,Ctlr * ctlr)48 options(Vga*, Ctlr* ctlr)
49 {
50 	ctlr->flag |= Foptions;
51 }
52 
53 static void
init(Vga * vga,Ctlr * ctlr)54 init(Vga* vga, Ctlr* ctlr)
55 {
56 	ulong pclk;
57 	char *p;
58 
59 	/*
60 	 * Part comes in -125, -110, -80, and -66MHz speed-grades.
61 	 * Work out the part speed-grade from name.  Name can have,
62 	 * e.g. '-110' on the end  for 100MHz part.
63 	 */
64 	pclk = 66000000;
65 	if(p = strrchr(ctlr->name, '-'))
66 		pclk = strtoul(p+1, 0, 0) * 1000000;
67 
68 	/*
69 	 * If we don't already have a desired pclk,
70 	 * take it from the mode.
71 	 * Check it's within range.
72 	 */
73 	if(vga->f[0] == 0)
74 		vga->f[0] = vga->mode->frequency;
75 	if(vga->f[0] > pclk)
76 		error("%s: invalid pclk - %ld\n", ctlr->name, vga->f[0]);
77 }
78 
79 static void
load(Vga *,Ctlr *)80 load(Vga*, Ctlr*)
81 {
82 	uchar aux, command;
83 
84 	aux = 0x00;
85 	/*
86 	if(vga->mode->z == 8)
87 		aux = 0x01;
88 	 */
89 	commandrw();
90 	command = inportb(Pixmask);
91 	outportb(Pixmask, command|0x18);
92 	outportb(PaddrR, 0x08);
93 	outportb(PaddrW, aux);
94 	commandw(command);
95 }
96 
97 static void
dump(Vga *,Ctlr * ctlr)98 dump(Vga*, Ctlr* ctlr)
99 {
100 	int i;
101 	uchar command;
102 
103 	printitem(ctlr->name, "command");
104 	command = commandr();
105 	printreg(command);
106 
107 	printitem(ctlr->name, "index08");
108 	commandw(command|0x10);
109 	for(i = 0x08; i < 0x11; i++){
110 		outportb(PaddrR, i);
111 		printreg(inportb(PaddrW));
112 	}
113 	commandw(command);
114 }
115 
116 Ctlr sc15025 = {
117 	"sc15025",			/* name */
118 	0,				/* snarf */
119 	options,			/* options */
120 	init,				/* init */
121 	load,				/* load */
122 	dump,				/* dump */
123 };
124