1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <config.h>
17
18#include <common.h>
19#include <asm/io.h>
20#include <ali512x.h>
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41static void ali_write(u8 index, u8 value)
42{
43
44 outb(index, ALI_INDEX);
45 outb(value, ALI_DATA);
46}
47
48#if 0
49static int ali_read(u8 index)
50{
51 outb(index, ALI_INDEX);
52 return inb(ALI_DATA);
53}
54#endif
55
56#define ALI_OPEN() \
57 outb(0x51, ALI_INDEX); \
58 outb(0x23, ALI_INDEX)
59
60
61#define ALI_CLOSE() \
62 outb(0xbb, ALI_INDEX)
63
64
65#define ALI_SELDEV(dev) \
66 ali_write(0x07, dev)
67
68
69void ali512x_init(void)
70{
71 ALI_OPEN();
72
73 ali_write(0x02, 0x01);
74 ali_write(0x03, 0x03);
75 ali_write(0x22, 0x00);
76 ali_write(0x23, 0x00);
77 ali_write(0x24, 0x00);
78
79 ALI_CLOSE();
80}
81
82void ali512x_set_fdc(int enabled, u16 io, u8 irq, u8 dma_channel)
83{
84 ALI_OPEN();
85 ALI_SELDEV(0);
86
87 ali_write(0x30, enabled?1:0);
88 if (enabled) {
89 ali_write(0x60, io >> 8);
90 ali_write(0x61, io & 0xff);
91 ali_write(0x70, irq);
92 ali_write(0x74, dma_channel);
93
94
95 ali_write(0xf0, 0x08);
96 ali_write(0xf1, 0x00);
97 ali_write(0xf2, 0xff);
98 ali_write(0xf4, 0x00);
99 }
100 ALI_CLOSE();
101}
102
103
104void ali512x_set_pp(int enabled, u16 io, u8 irq, u8 dma_channel)
105{
106 ALI_OPEN();
107 ALI_SELDEV(3);
108
109 ali_write(0x30, enabled?1:0);
110 if (enabled) {
111 ali_write(0x60, io >> 8);
112 ali_write(0x61, io & 0xff);
113 ali_write(0x70, irq);
114 ali_write(0x74, dma_channel);
115
116
117 ali_write(0xf0, 0xbc);
118
119 ali_write(0xf1, 0x05);
120 }
121 ALI_CLOSE();
122
123}
124
125void ali512x_set_uart(int enabled, int index, u16 io, u8 irq)
126{
127 ALI_OPEN();
128 ALI_SELDEV(index?5:4);
129
130 ali_write(0x30, enabled?1:0);
131 if (enabled) {
132 ali_write(0x60, io >> 8);
133 ali_write(0x61, io & 0xff);
134 ali_write(0x70, irq);
135
136 ali_write(0xf0, 0x00);
137 ali_write(0xf1, 0x00);
138
139
140
141
142 if (index) {
143 ali_write(0xf2, 0x00);
144 }
145 ali_write(0xf2, 0x0c);
146 }
147 ALI_CLOSE();
148
149}
150
151void ali512x_set_uart2_irda(int enabled)
152{
153 ALI_OPEN();
154 ALI_SELDEV(5);
155
156 ali_write(0xf1, enabled?0x48:0x00);
157 ALI_CLOSE();
158
159}
160
161void ali512x_set_rtc(int enabled, u16 io, u8 irq)
162{
163 ALI_OPEN();
164 ALI_SELDEV(6);
165
166 ali_write(0x30, enabled?1:0);
167 if (enabled) {
168 ali_write(0x60, io >> 8);
169 ali_write(0x61, io & 0xff);
170 ali_write(0x70, irq);
171
172 ali_write(0xf0, 0x00);
173 }
174 ALI_CLOSE();
175}
176
177void ali512x_set_kbc(int enabled, u8 kbc_irq, u8 mouse_irq)
178{
179 ALI_OPEN();
180 ALI_SELDEV(7);
181
182 ali_write(0x30, enabled?1:0);
183 if (enabled) {
184 ali_write(0x70, kbc_irq);
185 ali_write(0x72, mouse_irq);
186
187 ali_write(0xf0, 0x00);
188 }
189 ALI_CLOSE();
190}
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
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#define ALI_CIO_PORT_SEL 0x83
296#define ALI_CIO_INDEX 0xea
297#define ALI_CIO_DATA 0xeb
298
299void ali512x_set_cio(int enabled)
300{
301 int i;
302
303 ALI_OPEN();
304
305 if (enabled) {
306 ali_write(0x3, ALI_CIO_PORT_SEL);
307 } else {
308 ali_write(0x3, ALI_CIO_PORT_SEL & ~0x80);
309 }
310
311 ALI_SELDEV(8);
312
313 ali_write(0x30, enabled?1:0);
314
315
316 for (i=0xe0;i<0xee;i++) {
317 ali_write(i, 1);
318 }
319
320 for (i=0xf5;i<0xfe;i++) {
321 ali_write(i, 1);
322 }
323
324 ALI_CLOSE();
325}
326
327
328void ali512x_cio_function(int pin, int special, int inv, int input)
329{
330 u8 data;
331 u8 addr;
332
333
334 if (pin >= 10 && pin <= 17) {
335 addr = 0xe0+(pin&7);
336 } else if (pin >= 20 && pin <= 25) {
337 addr = 0xe8+(pin&7);
338 } else if (pin >= 30 && pin <= 37) {
339 addr = 0xf5+(pin&7);
340 } else {
341 return;
342 }
343
344 ALI_OPEN();
345
346 ALI_SELDEV(8);
347
348
349 data=0xf4;
350 if (special) {
351 data |= 0x08;
352 } else {
353 if (inv) {
354 data |= 0x02;
355 }
356 if (input) {
357 data |= 0x01;
358 }
359 }
360
361 ali_write(addr, data);
362
363 ALI_CLOSE();
364}
365
366void ali512x_cio_out(int pin, int value)
367{
368 u8 reg;
369 u8 data;
370 u8 bit;
371
372 reg = pin/10;
373 bit = 1 << (pin%10);
374
375
376 outb(reg, ALI_CIO_INDEX);
377 data = inb(ALI_CIO_DATA);
378 if (value) {
379 data |= bit;
380 } else {
381 data &= ~bit;
382 }
383 outb(data, ALI_CIO_DATA);
384}
385
386int ali512x_cio_in(int pin)
387{
388 u8 reg;
389 u8 data;
390 u8 bit;
391
392
393 reg = pin/10;
394 bit = 1 << (pin%10);
395
396
397 outb(reg, ALI_CIO_INDEX);
398 data = inb(ALI_CIO_DATA);
399
400 return data & bit;
401}
402