Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Basic EISA bus support for the SGI Indigo-2. |
| 3 | * |
| 4 | * (C) 2002 Pascal Dameme <netinet@freesurf.fr> |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 5 | * and Marc Zyngier <mzyngier@freesurf.fr> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Thiemo Seufer | 37c8c64 | 2005-08-31 15:55:16 +0000 | [diff] [blame] | 31 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Thomas Bogendoerfer | 68de480 | 2007-11-23 20:34:16 +0100 | [diff] [blame] | 39 | #include <asm/i8259.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Thiemo Seufer | 37c8c64 | 2005-08-31 15:55:16 +0000 | [diff] [blame] | 41 | /* I2 has four EISA slots. */ |
| 42 | #define IP22_EISA_MAX_SLOTS 4 |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 43 | #define EISA_MAX_IRQ 16 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Thiemo Seufer | 37c8c64 | 2005-08-31 15:55:16 +0000 | [diff] [blame] | 51 | static char __init *decode_eisa_sig(unsigned long addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
Dmitri Vorobiev | 599a894 | 2009-11-23 13:53:37 +0200 | [diff] [blame] | 53 | static char sig_str[EISA_SIG_LEN] __initdata; |
Thiemo Seufer | 37c8c64 | 2005-08-31 15:55:16 +0000 | [diff] [blame] | 54 | u8 sig[4]; |
Dmitri Vorobiev | 599a894 | 2009-11-23 13:53:37 +0200 | [diff] [blame] | 55 | u16 rev; |
Thiemo Seufer | 37c8c64 | 2005-08-31 15:55:16 +0000 | [diff] [blame] | 56 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Thiemo Seufer | 37c8c64 | 2005-08-31 15:55:16 +0000 | [diff] [blame] | 58 | for (i = 0; i < 4; i++) { |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 59 | sig[i] = inb(addr + i); |
Thiemo Seufer | 37c8c64 | 2005-08-31 15:55:16 +0000 | [diff] [blame] | 60 | |
| 61 | if (!i && (sig[0] & 0x80)) |
| 62 | return NULL; |
| 63 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 74 | static irqreturn_t ip22_eisa_intr(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | { |
Ralf Baechle | b2f711d | 2012-09-06 10:02:40 +0200 | [diff] [blame] | 76 | u8 eisa_irq = inb(EIU_INTRPT_ACK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Ralf Baechle | b2f711d | 2012-09-06 10:02:40 +0200 | [diff] [blame] | 78 | inb(EISA_DMA1_STATUS); |
| 79 | inb(EISA_DMA2_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Thiemo Seufer | 37c8c64 | 2005-08-31 15:55:16 +0000 | [diff] [blame] | 81 | if (eisa_irq < EISA_MAX_IRQ) { |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 82 | do_IRQ(eisa_irq); |
Thiemo Seufer | 37c8c64 | 2005-08-31 15:55:16 +0000 | [diff] [blame] | 83 | return IRQ_HANDLED; |
| 84 | } |
| 85 | |
| 86 | /* Oops, Bad Stuff Happened... */ |
| 87 | printk(KERN_ERR "eisa_irq %d out of bound\n", eisa_irq); |
| 88 | |
| 89 | outb(0x20, EISA_INT2_CTRL); |
| 90 | outb(0x20, EISA_INT1_CTRL); |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 91 | |
Thiemo Seufer | 37c8c64 | 2005-08-31 15:55:16 +0000 | [diff] [blame] | 92 | return IRQ_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | static struct irqaction eisa_action = { |
| 96 | .handler = ip22_eisa_intr, |
| 97 | .name = "EISA", |
| 98 | }; |
| 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | int __init ip22_eisa_init(void) |
| 101 | { |
| 102 | int i, c; |
| 103 | char *str; |
Ralf Baechle | 42a3b4f | 2005-09-03 15:56:17 -0700 | [diff] [blame] | 104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | if (!(sgimc->systemid & SGIMC_SYSID_EPRESENT)) { |
| 106 | printk(KERN_INFO "EISA: bus not present.\n"); |
| 107 | return 1; |
| 108 | } |
| 109 | |
| 110 | printk(KERN_INFO "EISA: Probing bus...\n"); |
Thiemo Seufer | 37c8c64 | 2005-08-31 15:55:16 +0000 | [diff] [blame] | 111 | for (c = 0, i = 1; i <= IP22_EISA_MAX_SLOTS; i++) { |
| 112 | if ((str = decode_eisa_sig(0x1000 * i + EISA_VENDOR_ID_OFFSET))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | printk(KERN_INFO "EISA: slot %d : %s detected.\n", |
| 114 | i, str); |
| 115 | c++; |
| 116 | } |
| 117 | } |
| 118 | printk(KERN_INFO "EISA: Detected %d card%s.\n", c, c < 2 ? "" : "s"); |
| 119 | #ifdef CONFIG_ISA |
| 120 | printk(KERN_INFO "ISA support compiled in.\n"); |
| 121 | #endif |
| 122 | |
| 123 | /* Warning : BlackMagicAhead(tm). |
| 124 | Please wave your favorite dead chicken over the busses */ |
| 125 | |
| 126 | /* First say hello to the EIU */ |
Thiemo Seufer | 37c8c64 | 2005-08-31 15:55:16 +0000 | [diff] [blame] | 127 | outl(0x0000FFFF, EIU_PREMPT_REG); |
| 128 | outl(1, EIU_QUIET_REG); |
| 129 | outl(0x40f3c07F, EIU_MODE_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | /* Now be nice to the EISA chipset */ |
Thiemo Seufer | 37c8c64 | 2005-08-31 15:55:16 +0000 | [diff] [blame] | 132 | outb(1, EISA_EXT_NMI_RESET_CTRL); |
| 133 | udelay(50); /* Wait long enough for the dust to settle */ |
| 134 | outb(0, EISA_EXT_NMI_RESET_CTRL); |
Thiemo Seufer | 37c8c64 | 2005-08-31 15:55:16 +0000 | [diff] [blame] | 135 | outb(0, EISA_DMA2_WRITE_SINGLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
Thomas Bogendoerfer | 68de480 | 2007-11-23 20:34:16 +0100 | [diff] [blame] | 137 | init_i8259_irqs(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
| 139 | /* Cannot use request_irq because of kmalloc not being ready at such |
| 140 | * an early stage. Yes, I've been bitten... */ |
| 141 | setup_irq(SGI_EISA_IRQ, &eisa_action); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
| 143 | EISA_bus = 1; |
| 144 | return 0; |
| 145 | } |