ip22-eisa.c 7.5 KB

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