ip22-eisa.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. #include <linux/eisa.h>
  22. #include <linux/types.h>
  23. #include <linux/init.h>
  24. #include <linux/irq.h>
  25. #include <linux/kernel_stat.h>
  26. #include <linux/signal.h>
  27. #include <linux/sched.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/delay.h>
  30. #include <asm/io.h>
  31. #include <asm/irq.h>
  32. #include <asm/mipsregs.h>
  33. #include <asm/addrspace.h>
  34. #include <asm/processor.h>
  35. #include <asm/sgi/ioc.h>
  36. #include <asm/sgi/mc.h>
  37. #include <asm/sgi/ip22.h>
  38. /* I2 has four EISA slots. */
  39. #define IP22_EISA_MAX_SLOTS 4
  40. #define EISA_MAX_IRQ 16
  41. #define EIU_MODE_REG 0x0001ffc0
  42. #define EIU_STAT_REG 0x0001ffc4
  43. #define EIU_PREMPT_REG 0x0001ffc8
  44. #define EIU_QUIET_REG 0x0001ffcc
  45. #define EIU_INTRPT_ACK 0x00010004
  46. static char __init *decode_eisa_sig(unsigned long addr)
  47. {
  48. static char sig_str[EISA_SIG_LEN];
  49. u8 sig[4];
  50. u16 rev;
  51. int i;
  52. for (i = 0; i < 4; i++) {
  53. sig[i] = inb (addr + i);
  54. if (!i && (sig[0] & 0x80))
  55. return NULL;
  56. }
  57. sig_str[0] = ((sig[0] >> 2) & 0x1f) + ('A' - 1);
  58. sig_str[1] = (((sig[0] & 3) << 3) | (sig[1] >> 5)) + ('A' - 1);
  59. sig_str[2] = (sig[1] & 0x1f) + ('A' - 1);
  60. rev = (sig[2] << 8) | sig[3];
  61. sprintf(sig_str + 3, "%04X", rev);
  62. return sig_str;
  63. }
  64. static irqreturn_t ip22_eisa_intr(int irq, void *dev_id, struct pt_regs *regs)
  65. {
  66. u8 eisa_irq;
  67. u8 dma1, dma2;
  68. eisa_irq = inb(EIU_INTRPT_ACK);
  69. dma1 = inb(EISA_DMA1_STATUS);
  70. dma2 = inb(EISA_DMA2_STATUS);
  71. if (eisa_irq < EISA_MAX_IRQ) {
  72. do_IRQ(eisa_irq, regs);
  73. return IRQ_HANDLED;
  74. }
  75. /* Oops, Bad Stuff Happened... */
  76. printk(KERN_ERR "eisa_irq %d out of bound\n", eisa_irq);
  77. outb(0x20, EISA_INT2_CTRL);
  78. outb(0x20, EISA_INT1_CTRL);
  79. return IRQ_NONE;
  80. }
  81. static void enable_eisa1_irq(unsigned int irq)
  82. {
  83. unsigned long flags;
  84. u8 mask;
  85. local_irq_save(flags);
  86. mask = inb(EISA_INT1_MASK);
  87. mask &= ~((u8) (1 << irq));
  88. outb(mask, EISA_INT1_MASK);
  89. local_irq_restore(flags);
  90. }
  91. static unsigned int startup_eisa1_irq(unsigned int irq)
  92. {
  93. u8 edge;
  94. /* Only use edge interrupts for EISA */
  95. edge = inb(EISA_INT1_EDGE_LEVEL);
  96. edge &= ~((u8) (1 << irq));
  97. outb(edge, EISA_INT1_EDGE_LEVEL);
  98. enable_eisa1_irq(irq);
  99. return 0;
  100. }
  101. static void disable_eisa1_irq(unsigned int irq)
  102. {
  103. u8 mask;
  104. mask = inb(EISA_INT1_MASK);
  105. mask |= ((u8) (1 << irq));
  106. outb(mask, EISA_INT1_MASK);
  107. }
  108. #define shutdown_eisa1_irq disable_eisa1_irq
  109. static void mask_and_ack_eisa1_irq(unsigned int irq)
  110. {
  111. disable_eisa1_irq(irq);
  112. outb(0x20, EISA_INT1_CTRL);
  113. }
  114. static void end_eisa1_irq(unsigned int irq)
  115. {
  116. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
  117. enable_eisa1_irq(irq);
  118. }
  119. static struct irq_chip ip22_eisa1_irq_type = {
  120. .typename = "IP22 EISA",
  121. .startup = startup_eisa1_irq,
  122. .shutdown = shutdown_eisa1_irq,
  123. .enable = enable_eisa1_irq,
  124. .disable = disable_eisa1_irq,
  125. .ack = mask_and_ack_eisa1_irq,
  126. .end = end_eisa1_irq,
  127. };
  128. static void enable_eisa2_irq(unsigned int irq)
  129. {
  130. unsigned long flags;
  131. u8 mask;
  132. local_irq_save(flags);
  133. mask = inb(EISA_INT2_MASK);
  134. mask &= ~((u8) (1 << (irq - 8)));
  135. outb(mask, EISA_INT2_MASK);
  136. local_irq_restore(flags);
  137. }
  138. static unsigned int startup_eisa2_irq(unsigned int irq)
  139. {
  140. u8 edge;
  141. /* Only use edge interrupts for EISA */
  142. edge = inb(EISA_INT2_EDGE_LEVEL);
  143. edge &= ~((u8) (1 << (irq - 8)));
  144. outb(edge, EISA_INT2_EDGE_LEVEL);
  145. enable_eisa2_irq(irq);
  146. return 0;
  147. }
  148. static void disable_eisa2_irq(unsigned int irq)
  149. {
  150. u8 mask;
  151. mask = inb(EISA_INT2_MASK);
  152. mask |= ((u8) (1 << (irq - 8)));
  153. outb(mask, EISA_INT2_MASK);
  154. }
  155. #define shutdown_eisa2_irq disable_eisa2_irq
  156. static void mask_and_ack_eisa2_irq(unsigned int irq)
  157. {
  158. disable_eisa2_irq(irq);
  159. outb(0x20, EISA_INT2_CTRL);
  160. }
  161. static void end_eisa2_irq(unsigned int irq)
  162. {
  163. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
  164. enable_eisa2_irq(irq);
  165. }
  166. static struct irq_chip ip22_eisa2_irq_type = {
  167. .typename = "IP22 EISA",
  168. .startup = startup_eisa2_irq,
  169. .shutdown = shutdown_eisa2_irq,
  170. .enable = enable_eisa2_irq,
  171. .disable = disable_eisa2_irq,
  172. .ack = mask_and_ack_eisa2_irq,
  173. .end = end_eisa2_irq,
  174. };
  175. static struct irqaction eisa_action = {
  176. .handler = ip22_eisa_intr,
  177. .name = "EISA",
  178. };
  179. static struct irqaction cascade_action = {
  180. .handler = no_action,
  181. .name = "EISA cascade",
  182. };
  183. int __init ip22_eisa_init(void)
  184. {
  185. int i, c;
  186. char *str;
  187. if (!(sgimc->systemid & SGIMC_SYSID_EPRESENT)) {
  188. printk(KERN_INFO "EISA: bus not present.\n");
  189. return 1;
  190. }
  191. printk(KERN_INFO "EISA: Probing bus...\n");
  192. for (c = 0, i = 1; i <= IP22_EISA_MAX_SLOTS; i++) {
  193. if ((str = decode_eisa_sig(0x1000 * i + EISA_VENDOR_ID_OFFSET))) {
  194. printk(KERN_INFO "EISA: slot %d : %s detected.\n",
  195. i, str);
  196. c++;
  197. }
  198. }
  199. printk(KERN_INFO "EISA: Detected %d card%s.\n", c, c < 2 ? "" : "s");
  200. #ifdef CONFIG_ISA
  201. printk(KERN_INFO "ISA support compiled in.\n");
  202. #endif
  203. /* Warning : BlackMagicAhead(tm).
  204. Please wave your favorite dead chicken over the busses */
  205. /* First say hello to the EIU */
  206. outl(0x0000FFFF, EIU_PREMPT_REG);
  207. outl(1, EIU_QUIET_REG);
  208. outl(0x40f3c07F, EIU_MODE_REG);
  209. /* Now be nice to the EISA chipset */
  210. outb(1, EISA_EXT_NMI_RESET_CTRL);
  211. udelay(50); /* Wait long enough for the dust to settle */
  212. outb(0, EISA_EXT_NMI_RESET_CTRL);
  213. outb(0x11, EISA_INT1_CTRL);
  214. outb(0x11, EISA_INT2_CTRL);
  215. outb(0, EISA_INT1_MASK);
  216. outb(8, EISA_INT2_MASK);
  217. outb(4, EISA_INT1_MASK);
  218. outb(2, EISA_INT2_MASK);
  219. outb(1, EISA_INT1_MASK);
  220. outb(1, EISA_INT2_MASK);
  221. outb(0xfb, EISA_INT1_MASK);
  222. outb(0xff, EISA_INT2_MASK);
  223. outb(0, EISA_DMA2_WRITE_SINGLE);
  224. for (i = SGINT_EISA; i < (SGINT_EISA + EISA_MAX_IRQ); i++) {
  225. irq_desc[i].status = IRQ_DISABLED;
  226. irq_desc[i].action = 0;
  227. irq_desc[i].depth = 1;
  228. if (i < (SGINT_EISA + 8))
  229. irq_desc[i].chip = &ip22_eisa1_irq_type;
  230. else
  231. irq_desc[i].chip = &ip22_eisa2_irq_type;
  232. }
  233. /* Cannot use request_irq because of kmalloc not being ready at such
  234. * an early stage. Yes, I've been bitten... */
  235. setup_irq(SGI_EISA_IRQ, &eisa_action);
  236. setup_irq(SGINT_EISA + 2, &cascade_action);
  237. EISA_bus = 1;
  238. return 0;
  239. }