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#include <common.h>
28#include <asm/processor.h>
29#include <stdio_dev.h>
30#include "isa.h"
31#include "piix4_pci.h"
32#include "kbd.h"
33#include "video.h"
34
35
36#undef ISA_DEBUG
37
38#ifdef ISA_DEBUG
39#define PRINTF(fmt,args...) printf (fmt ,##args)
40#else
41#define PRINTF(fmt,args...)
42#endif
43
44#ifndef TRUE
45#define TRUE 1
46#endif
47#ifndef FALSE
48#define FALSE 0
49#endif
50
51#if defined(CONFIG_PIP405)
52
53extern int drv_isa_kbd_init (void);
54
55
56const SIO_LOGDEV_TABLE sio_fdc[] = {
57 {0x60, 3},
58 {0x61, 0xF0},
59 {0x70, 06},
60 {0x74, 02},
61 {0xF0, 0x05},
62 {0xF1, 0x00},
63 {0x30, 1},
64 {0xFF, 0}
65};
66
67const SIO_LOGDEV_TABLE sio_pport[] = {
68 {0x60, 3},
69 {0x61, 0x78},
70 {0x70, 07},
71 {0xF1, 00},
72 {0x30, 1},
73 {0xFF, 0}
74};
75
76const SIO_LOGDEV_TABLE sio_pport_fdc[] = {
77 {0x60, 3},
78 {0x61, 0x78},
79 {0x70, 07},
80 {0xF1, 02},
81 {0x30, 1},
82 {0xFF, 0}
83};
84
85const SIO_LOGDEV_TABLE sio_com1[] = {
86 {0x60, 3},
87 {0x61, 0xF8},
88 {0x70, 04},
89 {0x30, 1},
90 {0xFF, 0}
91};
92
93const SIO_LOGDEV_TABLE sio_com2[] = {
94 {0x60, 2},
95 {0x61, 0xF8},
96 {0x70, 03},
97 {0x30, 1},
98 {0xFF, 0}
99};
100
101
102const SIO_LOGDEV_TABLE sio_keyboard[] = {
103 {0x70, 1},
104 {0x72, 12},
105 {0xF0, 0},
106 {0x30, 1},
107 {0xFF, 0}
108};
109
110
111
112
113
114unsigned char open_cfg_super_IO(int address)
115{
116 out8(CONFIG_SYS_ISA_IO_BASE_ADDRESS | address,0x55);
117 out8(CONFIG_SYS_ISA_IO_BASE_ADDRESS | address,0x20);
118 if(in8(CONFIG_SYS_ISA_IO_BASE_ADDRESS | address | 0x1)==0x40)
119 return TRUE;
120 else
121 return FALSE;
122}
123
124void close_cfg_super_IO(int address)
125{
126 out8(CONFIG_SYS_ISA_IO_BASE_ADDRESS | address,0xAA);
127}
128
129
130unsigned char read_cfg_super_IO(int address, unsigned char function, unsigned char regaddr)
131{
132
133 out8(CONFIG_SYS_ISA_IO_BASE_ADDRESS | address,0x7);
134 out8(CONFIG_SYS_ISA_IO_BASE_ADDRESS | address | 1,function);
135 out8(CONFIG_SYS_ISA_IO_BASE_ADDRESS | address,regaddr);
136 return in8(CONFIG_SYS_ISA_IO_BASE_ADDRESS | address | 1);
137}
138
139void write_cfg_super_IO(int address, unsigned char function, unsigned char regaddr, unsigned char data)
140{
141
142 out8(CONFIG_SYS_ISA_IO_BASE_ADDRESS | address,0x7);
143 out8(CONFIG_SYS_ISA_IO_BASE_ADDRESS | address | 1,function);
144 out8(CONFIG_SYS_ISA_IO_BASE_ADDRESS | address,regaddr);
145 out8(CONFIG_SYS_ISA_IO_BASE_ADDRESS | address | 1,data);
146}
147
148void isa_write_table(SIO_LOGDEV_TABLE *ldt,unsigned char ldev)
149{
150 while (ldt->index != 0xFF) {
151 write_cfg_super_IO(SIO_CFG_PORT, ldev, ldt->index, ldt->val);
152 ldt++;
153 }
154}
155
156void isa_sio_loadtable(void)
157{
158 char *s = getenv("floppy");
159
160 isa_write_table((SIO_LOGDEV_TABLE *)&sio_fdc,0);
161
162 if(s && !strncmp(s, "lpt", 3)) {
163 printf("SIO: Floppy assigned to LPT\n");
164
165 isa_write_table((SIO_LOGDEV_TABLE *)&sio_pport_fdc,3);
166 }
167 else {
168
169 isa_write_table((SIO_LOGDEV_TABLE *)&sio_pport,3);
170 }
171
172 isa_write_table((SIO_LOGDEV_TABLE *)&sio_com1,4);
173
174 isa_write_table((SIO_LOGDEV_TABLE *)&sio_com2,5);
175
176 isa_write_table((SIO_LOGDEV_TABLE *)&sio_keyboard,7);
177}
178
179
180void isa_sio_setup(void)
181{
182 if(open_cfg_super_IO(SIO_CFG_PORT)==TRUE)
183 {
184 isa_sio_loadtable();
185 close_cfg_super_IO(0x3F0);
186 }
187}
188#endif
189
190
191
192
193
194
195struct isa_irq_action {
196 interrupt_handler_t *handler;
197 void *arg;
198 int count;
199};
200
201static struct isa_irq_action isa_irqs[16];
202
203
204
205
206
207static unsigned int cached_irq_mask = 0xfff9;
208
209#define cached_imr1 (unsigned char)cached_irq_mask
210#define cached_imr2 (unsigned char)(cached_irq_mask>>8)
211#define IMR_1 CONFIG_SYS_ISA_IO_BASE_ADDRESS + PIIX4_ISA_INT1_OCW1
212#define IMR_2 CONFIG_SYS_ISA_IO_BASE_ADDRESS + PIIX4_ISA_INT2_OCW1
213#define ICW1_1 CONFIG_SYS_ISA_IO_BASE_ADDRESS + PIIX4_ISA_INT1_ICW1
214#define ICW1_2 CONFIG_SYS_ISA_IO_BASE_ADDRESS + PIIX4_ISA_INT2_ICW1
215#define ICW2_1 CONFIG_SYS_ISA_IO_BASE_ADDRESS + PIIX4_ISA_INT1_ICW2
216#define ICW2_2 CONFIG_SYS_ISA_IO_BASE_ADDRESS + PIIX4_ISA_INT2_ICW2
217#define ICW3_1 ICW2_1
218#define ICW3_2 ICW2_2
219#define ICW4_1 ICW2_1
220#define ICW4_2 ICW2_2
221#define ISR_1 ICW1_1
222#define ISR_2 ICW1_2
223
224
225void disable_8259A_irq(unsigned int irq)
226{
227 unsigned int mask = 1 << irq;
228
229 cached_irq_mask |= mask;
230 if (irq & 8)
231 out8(IMR_2,cached_imr2);
232 else
233 out8(IMR_1,cached_imr1);
234}
235
236void enable_8259A_irq(unsigned int irq)
237{
238 unsigned int mask = ~(1 << irq);
239
240 cached_irq_mask &= mask;
241 if (irq & 8)
242 out8(IMR_2,cached_imr2);
243 else
244 out8(IMR_1,cached_imr1);
245}
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266int i8259A_irq_real(unsigned int irq)
267{
268 int value;
269 int irqmask = 1<<irq;
270
271 if (irq < 8) {
272 out8(ISR_1,0x0B);
273 value = in8(ISR_1) & irqmask;
274 out8(ISR_1,0x0A);
275 return value;
276 }
277 out8(ISR_2,0x0B);
278 value = in8(ISR_2) & (irqmask >> 8);
279 out8(ISR_2,0x0A);
280 return value;
281}
282
283
284
285
286
287
288
289void mask_and_ack_8259A(unsigned int irq)
290{
291 unsigned int irqmask = 1 << irq;
292 unsigned int temp_irqmask = cached_irq_mask;
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308 if (temp_irqmask & irqmask)
309 goto spurious_8259A_irq;
310 temp_irqmask |= irqmask;
311
312handle_real_irq:
313 if (irq & 8) {
314 in8(IMR_2);
315 out8(IMR_2,(unsigned char)(temp_irqmask>>8));
316 out8(ISR_2,0x60+(irq&7));
317 out8(ISR_1,0x62);
318 out8(IMR_2,cached_imr2);
319 } else {
320 in8(IMR_1);
321 out8(IMR_1,(unsigned char)temp_irqmask);
322 out8(ISR_1,0x60+irq);
323 out8(IMR_1,cached_imr1);
324 }
325
326 return;
327
328spurious_8259A_irq:
329
330
331
332 if (i8259A_irq_real(irq))
333
334
335
336
337 goto handle_real_irq;
338
339 {
340 static int spurious_irq_mask;
341
342
343
344
345 if (!(spurious_irq_mask & irqmask)) {
346 PRINTF("spurious 8259A interrupt: IRQ%d.\n", irq);
347 spurious_irq_mask |= irqmask;
348 }
349
350
351
352
353
354
355 goto handle_real_irq;
356 }
357}
358
359void init_8259A(void)
360{
361 out8(IMR_1,0xff);
362 out8(IMR_2,0xff);
363
364 out8(ICW1_1,0x11);
365 out8(ICW2_1,0x20 + 0);
366 out8(ICW3_1,0x04);
367 out8(ICW4_1,0x01);
368 out8(ICW1_2,0x11);
369 out8(ICW2_2,0x20 + 8);
370 out8(ICW3_2,0x02);
371 out8(ICW4_2,0x01);
372
373 udelay(10000);
374 out8(IMR_1,cached_imr1);
375 udelay(10000);
376 out8(IMR_2,cached_imr2);
377}
378
379
380#define PCI_INT_ACK_ADDR 0xEED00000
381
382int handle_isa_int(void)
383{
384 unsigned long irqack;
385 unsigned char isr1,isr2,irq;
386
387 irqack=in32(PCI_INT_ACK_ADDR);
388
389 isr2=in8(ISR_2);
390 isr1=in8(ISR_1);
391 irq=(unsigned char)irqack;
392 irq-=32;
393
394
395
396
397
398 {
399
400 isa_irqs[irq].count++;
401 if(irq!=2) {
402 if (isa_irqs[irq].handler != NULL)
403 (*isa_irqs[irq].handler)(isa_irqs[irq].arg);
404 else {
405 PRINTF ("bogus interrupt vector 0x%x\n", irq);
406 }
407 }
408 }
409
410 mask_and_ack_8259A(irq);
411 return 0;
412}
413
414
415
416
417
418
419void isa_irq_install_handler(int vec, interrupt_handler_t *handler, void *arg)
420{
421 if (isa_irqs[vec].handler != NULL) {
422 printf ("ISA Interrupt vector %d: handler 0x%x replacing 0x%x\n",
423 vec, (uint)handler, (uint)isa_irqs[vec].handler);
424 }
425 isa_irqs[vec].handler = handler;
426 isa_irqs[vec].arg = arg;
427 enable_8259A_irq(vec);
428 PRINTF ("Install ISA IRQ %d ==> %p, @ %p mask=%04x\n", vec, handler, &isa_irqs[vec].handler,cached_irq_mask);
429
430}
431
432void isa_irq_free_handler(int vec)
433{
434 disable_8259A_irq(vec);
435 isa_irqs[vec].handler = NULL;
436 isa_irqs[vec].arg = NULL;
437 PRINTF ("Free ISA IRQ %d mask=%04x\n", vec, cached_irq_mask);
438
439}
440
441
442void isa_init_irq_contr(void)
443{
444 int i;
445
446
447 for(i=0;i<16;i++)
448 {
449 isa_irqs[i].handler=NULL;
450 isa_irqs[i].arg=NULL;
451 isa_irqs[i].count=0;
452 }
453 init_8259A();
454 out8(IMR_2,0xFF);
455}
456
457
458void isa_show_irq(void)
459{
460 int vec;
461
462 printf ("\nISA Interrupt-Information:\n");
463 printf ("Nr Routine Arg Count\n");
464
465 for (vec=0; vec<16; vec++) {
466 if (isa_irqs[vec].handler != NULL) {
467 printf ("%02d %08lx %08lx %d\n",
468 vec,
469 (ulong)isa_irqs[vec].handler,
470 (ulong)isa_irqs[vec].arg,
471 isa_irqs[vec].count);
472 }
473 }
474}
475
476int isa_irq_get_count(int vec)
477{
478 return(isa_irqs[vec].count);
479}
480
481
482
483
484
485#if defined(CONFIG_PIP405)
486
487int isa_init(void)
488{
489 isa_sio_setup();
490 isa_init_irq_contr();
491 drv_isa_kbd_init();
492 return 0;
493}
494#endif
495