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#include <config.h>
34
35#include <common.h>
36#include <asm/io.h>
37#include <ali512x.h>
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58static void ali_write(u8 index, u8 value)
59{
60
61 outb(index, ALI_INDEX);
62 outb(value, ALI_DATA);
63}
64
65#if 0
66static int ali_read(u8 index)
67{
68 outb(index, ALI_INDEX);
69 return inb(ALI_DATA);
70}
71#endif
72
73#define ALI_OPEN() \
74 outb(0x51, ALI_INDEX); \
75 outb(0x23, ALI_INDEX)
76
77
78#define ALI_CLOSE() \
79 outb(0xbb, ALI_INDEX)
80
81
82#define ALI_SELDEV(dev) \
83 ali_write(0x07, dev)
84
85
86void ali512x_init(void)
87{
88 ALI_OPEN();
89
90 ali_write(0x02, 0x01);
91 ali_write(0x03, 0x03);
92 ali_write(0x22, 0x00);
93 ali_write(0x23, 0x00);
94 ali_write(0x24, 0x00);
95
96 ALI_CLOSE();
97}
98
99void ali512x_set_fdc(int enabled, u16 io, u8 irq, u8 dma_channel)
100{
101 ALI_OPEN();
102 ALI_SELDEV(0);
103
104 ali_write(0x30, enabled?1:0);
105 if (enabled) {
106 ali_write(0x60, io >> 8);
107 ali_write(0x61, io & 0xff);
108 ali_write(0x70, irq);
109 ali_write(0x74, dma_channel);
110
111
112 ali_write(0xf0, 0x08);
113 ali_write(0xf1, 0x00);
114 ali_write(0xf2, 0xff);
115 ali_write(0xf4, 0x00);
116 }
117 ALI_CLOSE();
118}
119
120
121void ali512x_set_pp(int enabled, u16 io, u8 irq, u8 dma_channel)
122{
123 ALI_OPEN();
124 ALI_SELDEV(3);
125
126 ali_write(0x30, enabled?1:0);
127 if (enabled) {
128 ali_write(0x60, io >> 8);
129 ali_write(0x61, io & 0xff);
130 ali_write(0x70, irq);
131 ali_write(0x74, dma_channel);
132
133
134 ali_write(0xf0, 0xbc);
135
136 ali_write(0xf1, 0x05);
137 }
138 ALI_CLOSE();
139
140}
141
142void ali512x_set_uart(int enabled, int index, u16 io, u8 irq)
143{
144 ALI_OPEN();
145 ALI_SELDEV(index?5:4);
146
147 ali_write(0x30, enabled?1:0);
148 if (enabled) {
149 ali_write(0x60, io >> 8);
150 ali_write(0x61, io & 0xff);
151 ali_write(0x70, irq);
152
153 ali_write(0xf0, 0x00);
154 ali_write(0xf1, 0x00);
155
156
157
158
159 if (index) {
160 ali_write(0xf2, 0x00);
161 }
162 ali_write(0xf2, 0x0c);
163 }
164 ALI_CLOSE();
165
166}
167
168void ali512x_set_uart2_irda(int enabled)
169{
170 ALI_OPEN();
171 ALI_SELDEV(5);
172
173 ali_write(0xf1, enabled?0x48:0x00);
174 ALI_CLOSE();
175
176}
177
178void ali512x_set_rtc(int enabled, u16 io, u8 irq)
179{
180 ALI_OPEN();
181 ALI_SELDEV(6);
182
183 ali_write(0x30, enabled?1:0);
184 if (enabled) {
185 ali_write(0x60, io >> 8);
186 ali_write(0x61, io & 0xff);
187 ali_write(0x70, irq);
188
189 ali_write(0xf0, 0x00);
190 }
191 ALI_CLOSE();
192}
193
194void ali512x_set_kbc(int enabled, u8 kbc_irq, u8 mouse_irq)
195{
196 ALI_OPEN();
197 ALI_SELDEV(7);
198
199 ali_write(0x30, enabled?1:0);
200 if (enabled) {
201 ali_write(0x70, kbc_irq);
202 ali_write(0x72, mouse_irq);
203
204 ali_write(0xf0, 0x00);
205 }
206 ALI_CLOSE();
207}
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312#define ALI_CIO_PORT_SEL 0x83
313#define ALI_CIO_INDEX 0xea
314#define ALI_CIO_DATA 0xeb
315
316void ali512x_set_cio(int enabled)
317{
318 int i;
319
320 ALI_OPEN();
321
322 if (enabled) {
323 ali_write(0x3, ALI_CIO_PORT_SEL);
324 } else {
325 ali_write(0x3, ALI_CIO_PORT_SEL & ~0x80);
326 }
327
328 ALI_SELDEV(8);
329
330 ali_write(0x30, enabled?1:0);
331
332
333 for (i=0xe0;i<0xee;i++) {
334 ali_write(i, 1);
335 }
336
337 for (i=0xf5;i<0xfe;i++) {
338 ali_write(i, 1);
339 }
340
341 ALI_CLOSE();
342}
343
344
345void ali512x_cio_function(int pin, int special, int inv, int input)
346{
347 u8 data;
348 u8 addr;
349
350
351 if (pin >= 10 && pin <= 17) {
352 addr = 0xe0+(pin&7);
353 } else if (pin >= 20 && pin <= 25) {
354 addr = 0xe8+(pin&7);
355 } else if (pin >= 30 && pin <= 37) {
356 addr = 0xf5+(pin&7);
357 } else {
358 return;
359 }
360
361 ALI_OPEN();
362
363 ALI_SELDEV(8);
364
365
366 data=0xf4;
367 if (special) {
368 data |= 0x08;
369 } else {
370 if (inv) {
371 data |= 0x02;
372 }
373 if (input) {
374 data |= 0x01;
375 }
376 }
377
378 ali_write(addr, data);
379
380 ALI_CLOSE();
381}
382
383void ali512x_cio_out(int pin, int value)
384{
385 u8 reg;
386 u8 data;
387 u8 bit;
388
389 reg = pin/10;
390 bit = 1 << (pin%10);
391
392
393 outb(reg, ALI_CIO_INDEX);
394 data = inb(ALI_CIO_DATA);
395 if (value) {
396 data |= bit;
397 } else {
398 data &= ~bit;
399 }
400 outb(data, ALI_CIO_DATA);
401}
402
403int ali512x_cio_in(int pin)
404{
405 u8 reg;
406 u8 data;
407 u8 bit;
408
409
410 reg = pin/10;
411 bit = 1 << (pin%10);
412
413
414 outb(reg, ALI_CIO_INDEX);
415 data = inb(ALI_CIO_DATA);
416
417 return data & bit;
418}
419