Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Basic EISA bus support for the SGI Indigo-2. | |
3 | * | |
4 | * (C) 2002 Pascal Dameme <netinet@freesurf.fr> | |
5 | * and Marc Zyngier <mzyngier@freesurf.fr> | |
6 | * | |
7 | * This code is released under both the GPL version 2 and BSD | |
8 | * licenses. Either license may be used. | |
9 | * | |
10 | * This code offers a very basic support for this EISA bus present in | |
11 | * the SGI Indigo-2. It currently only supports PIO (forget about DMA | |
12 | * for the time being). This is enough for a low-end ethernet card, | |
13 | * but forget about your favorite SCSI card... | |
14 | * | |
15 | * TODO : | |
16 | * - Fix bugs... | |
17 | * - Add ISA support | |
18 | * - Add DMA (yeah, right...). | |
19 | * - Fix more bugs. | |
20 | */ | |
21 | ||
1da177e4 LT |
22 | #include <linux/eisa.h> |
23 | #include <linux/types.h> | |
24 | #include <linux/init.h> | |
25 | #include <linux/irq.h> | |
26 | #include <linux/kernel_stat.h> | |
27 | #include <linux/signal.h> | |
28 | #include <linux/sched.h> | |
29 | #include <linux/interrupt.h> | |
30 | #include <linux/delay.h> | |
37c8c642 | 31 | #include <asm/io.h> |
1da177e4 LT |
32 | #include <asm/irq.h> |
33 | #include <asm/mipsregs.h> | |
34 | #include <asm/addrspace.h> | |
35 | #include <asm/processor.h> | |
36 | #include <asm/sgi/ioc.h> | |
37 | #include <asm/sgi/mc.h> | |
38 | #include <asm/sgi/ip22.h> | |
68de4803 | 39 | #include <asm/i8259.h> |
1da177e4 | 40 | |
37c8c642 TS |
41 | /* I2 has four EISA slots. */ |
42 | #define IP22_EISA_MAX_SLOTS 4 | |
1da177e4 LT |
43 | #define EISA_MAX_IRQ 16 |
44 | ||
37c8c642 TS |
45 | #define EIU_MODE_REG 0x0001ffc0 |
46 | #define EIU_STAT_REG 0x0001ffc4 | |
47 | #define EIU_PREMPT_REG 0x0001ffc8 | |
48 | #define EIU_QUIET_REG 0x0001ffcc | |
49 | #define EIU_INTRPT_ACK 0x00010004 | |
50 | ||
51 | static char __init *decode_eisa_sig(unsigned long addr) | |
1da177e4 | 52 | { |
599a8945 | 53 | static char sig_str[EISA_SIG_LEN] __initdata; |
37c8c642 | 54 | u8 sig[4]; |
599a8945 | 55 | u16 rev; |
37c8c642 TS |
56 | int i; |
57 | ||
58 | for (i = 0; i < 4; i++) { | |
49a89efb | 59 | sig[i] = inb(addr + i); |
1da177e4 | 60 | |
37c8c642 TS |
61 | if (!i && (sig[0] & 0x80)) |
62 | return NULL; | |
63 | } | |
1da177e4 LT |
64 | |
65 | sig_str[0] = ((sig[0] >> 2) & 0x1f) + ('A' - 1); | |
66 | sig_str[1] = (((sig[0] & 3) << 3) | (sig[1] >> 5)) + ('A' - 1); | |
67 | sig_str[2] = (sig[1] & 0x1f) + ('A' - 1); | |
68 | rev = (sig[2] << 8) | sig[3]; | |
69 | sprintf(sig_str + 3, "%04X", rev); | |
70 | ||
71 | return sig_str; | |
72 | } | |
73 | ||
937a8015 | 74 | static irqreturn_t ip22_eisa_intr(int irq, void *dev_id) |
1da177e4 LT |
75 | { |
76 | u8 eisa_irq; | |
77 | u8 dma1, dma2; | |
78 | ||
37c8c642 TS |
79 | eisa_irq = inb(EIU_INTRPT_ACK); |
80 | dma1 = inb(EISA_DMA1_STATUS); | |
81 | dma2 = inb(EISA_DMA2_STATUS); | |
1da177e4 | 82 | |
37c8c642 | 83 | if (eisa_irq < EISA_MAX_IRQ) { |
937a8015 | 84 | do_IRQ(eisa_irq); |
37c8c642 TS |
85 | return IRQ_HANDLED; |
86 | } | |
87 | ||
88 | /* Oops, Bad Stuff Happened... */ | |
89 | printk(KERN_ERR "eisa_irq %d out of bound\n", eisa_irq); | |
90 | ||
91 | outb(0x20, EISA_INT2_CTRL); | |
92 | outb(0x20, EISA_INT1_CTRL); | |
937a8015 | 93 | |
37c8c642 | 94 | return IRQ_NONE; |
1da177e4 LT |
95 | } |
96 | ||
1da177e4 LT |
97 | static struct irqaction eisa_action = { |
98 | .handler = ip22_eisa_intr, | |
99 | .name = "EISA", | |
100 | }; | |
101 | ||
1da177e4 LT |
102 | int __init ip22_eisa_init(void) |
103 | { | |
104 | int i, c; | |
105 | char *str; | |
42a3b4f2 | 106 | |
1da177e4 LT |
107 | if (!(sgimc->systemid & SGIMC_SYSID_EPRESENT)) { |
108 | printk(KERN_INFO "EISA: bus not present.\n"); | |
109 | return 1; | |
110 | } | |
111 | ||
112 | printk(KERN_INFO "EISA: Probing bus...\n"); | |
37c8c642 TS |
113 | for (c = 0, i = 1; i <= IP22_EISA_MAX_SLOTS; i++) { |
114 | if ((str = decode_eisa_sig(0x1000 * i + EISA_VENDOR_ID_OFFSET))) { | |
1da177e4 LT |
115 | printk(KERN_INFO "EISA: slot %d : %s detected.\n", |
116 | i, str); | |
117 | c++; | |
118 | } | |
119 | } | |
120 | printk(KERN_INFO "EISA: Detected %d card%s.\n", c, c < 2 ? "" : "s"); | |
121 | #ifdef CONFIG_ISA | |
122 | printk(KERN_INFO "ISA support compiled in.\n"); | |
123 | #endif | |
124 | ||
125 | /* Warning : BlackMagicAhead(tm). | |
126 | Please wave your favorite dead chicken over the busses */ | |
127 | ||
128 | /* First say hello to the EIU */ | |
37c8c642 TS |
129 | outl(0x0000FFFF, EIU_PREMPT_REG); |
130 | outl(1, EIU_QUIET_REG); | |
131 | outl(0x40f3c07F, EIU_MODE_REG); | |
1da177e4 LT |
132 | |
133 | /* Now be nice to the EISA chipset */ | |
37c8c642 TS |
134 | outb(1, EISA_EXT_NMI_RESET_CTRL); |
135 | udelay(50); /* Wait long enough for the dust to settle */ | |
136 | outb(0, EISA_EXT_NMI_RESET_CTRL); | |
37c8c642 | 137 | outb(0, EISA_DMA2_WRITE_SINGLE); |
1da177e4 | 138 | |
68de4803 | 139 | init_i8259_irqs(); |
1da177e4 LT |
140 | |
141 | /* Cannot use request_irq because of kmalloc not being ready at such | |
142 | * an early stage. Yes, I've been bitten... */ | |
143 | setup_irq(SGI_EISA_IRQ, &eisa_action); | |
1da177e4 LT |
144 | |
145 | EISA_bus = 1; | |
146 | return 0; | |
147 | } |