|
|
1.1 root 1: #include "u.h"
2: #include "../port/lib.h"
3: #include "mem.h"
4: #include "dat.h"
5: #include "fns.h"
6: #include "io.h"
7:
8: /*
9: * safari nsx20 specific routines
10: */
11:
12: /*
13: * intel power management unit (i80c51)
14: */
15: enum {
16: /*
17: * power management unit ports
18: */
19: Pmudata= 0x198,
20:
21: Pmucsr= 0x199,
22: Busy= 0x1,
23:
24: /*
25: * configuration port
26: */
27: Pconfig= 0x3F3,
28: };
29:
30: /*
31: * return when pmu ready
32: */
33: static int
34: pmuready(void)
35: {
36: int tries;
37:
38: for(tries = 0; (inb(Pmucsr) & Busy); tries++)
39: if(tries > 1000)
40: return -1;
41: return 0;
42: }
43:
44: /*
45: * return when pmu busy
46: */
47: static int
48: pmubusy(void)
49: {
50: int tries;
51:
52: for(tries = 0; !(inb(Pmucsr) & Busy); tries++)
53: if(tries > 1000)
54: return -1;
55: return 0;
56: }
57:
58: /*
59: * set a bit in the PMU
60: */
61: static Lock pmulock;
62: static int
63: pmuwrbit(int index, int bit, int pos)
64: {
65: lock(&pmulock);
66: outb(Pmucsr, 0x02); /* next is command request */
67: if(pmuready() < 0){
68: unlock(&pmulock);
69: return -1;
70: }
71: outb(Pmudata, (2<<4) | index); /* send write bit command */
72: outb(Pmucsr, 0x01); /* send available */
73: if(pmubusy() < 0){
74: unlock(&pmulock);
75: return -1;
76: }
77: outb(Pmucsr, 0x01); /* next is data */
78: if(pmuready() < 0){
79: unlock(&pmulock);
80: return -1;
81: }
82: outb(Pmudata, (bit<<3) | pos); /* send bit to write */
83: outb(Pmucsr, 0x01); /* send available */
84: if(pmubusy() < 0){
85: unlock(&pmulock);
86: return -1;
87: }
88: unlock(&pmulock);
89: return 0;
90: }
91:
92: /*
93: * power to serial port
94: * onoff == 1 means on
95: * onoff == 0 means off
96: */
97: static int
98: nsx20serialpower(int onoff)
99: {
100: return pmuwrbit(1, 1^onoff, 6);
101: }
102:
103: /*
104: * power to modem
105: * onoff == 1 means on
106: * onoff == 0 means off
107: */
108: static int
109: nsx20modempower(int onoff)
110: {
111: if(pmuwrbit(1, 1^onoff, 0)<0) /* modem speaker */
112: return -1;
113: return pmuwrbit(1, onoff, 5); /* modem power */
114: }
115:
116: /*
117: * set cpu speed
118: * 0 == low speed
119: * 1 == high speed
120: */
121: static int
122: nsx20cpuspeed(int speed)
123: {
124: return pmuwrbit(0, speed, 0);
125: }
126:
127: /*
128: * f == frequency in Hz
129: * d == duration in ms
130: */
131: static void
132: nsx20buzz(int f, int d)
133: {
134: static QLock bl;
135: static Rendez br;
136:
137: USED(f);
138: qlock(&bl);
139: pmuwrbit(0, 0, 6);
140: tsleep(&br, return0, 0, d);
141: pmuwrbit(0, 1, 6);
142: qunlock(&bl);
143: }
144:
145: /*
146: * 1 == owl eye
147: * 2 == mail icon
148: */
149: static void
150: nsx20lights(int val)
151: {
152: pmuwrbit(0, (val&1), 4); /* owl */
153: pmuwrbit(0, ((val>>1)&1), 1); /* mail */
154: }
155:
156: /*
157: * headland system controller (ht21)
158: */
159: enum
160: {
161: /*
162: * system control port
163: */
164: Head= 0x92, /* control port */
165: Reset= (1<<0), /* reset the 386 */
166: A20ena= (1<<1), /* enable address line 20 */
167: };
168:
169: /*
170: * reset machine
171: */
172: static void
173: headreset(void)
174: {
175: outb(Head, Reset);
176: }
177:
178: PCArch nsx20 =
179: {
180: "AT&TNSX",
181: headreset,
182: nsx20cpuspeed,
183: nsx20buzz,
184: nsx20lights,
185: nsx20serialpower,
186: nsx20modempower,
187: 0,
188: 0,
189: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.