ip22-eisa.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. #include <asm/i8259.h>
  39. /* I2 has four EISA slots. */
  40. #define IP22_EISA_MAX_SLOTS 4
  41. #define EISA_MAX_IRQ 16
  42. #define EIU_MODE_REG 0x0001ffc0
  43. #define EIU_STAT_REG 0x0001ffc4
  44. #define EIU_PREMPT_REG 0x0001ffc8
  45. #define EIU_QUIET_REG 0x0001ffcc
  46. #define EIU_INTRPT_ACK 0x00010004
  47. static char __init *decode_eisa_sig(unsigned long addr)
  48. {
  49. static char sig_str[EISA_SIG_LEN] __initdata;
  50. u8 sig[4];
  51. u16 rev;
  52. int i;
  53. for (i = 0; i < 4; i++) {
  54. sig[i] = inb(addr + i);
  55. if (!i && (sig[0] & 0x80))
  56. return NULL;
  57. }
  58. sig_str[0] = ((sig[0] >> 2) & 0x1f) + ('A' - 1);
  59. sig_str[1] = (((sig[0] & 3) << 3) | (sig[1] >> 5)) + ('A' - 1);
  60. sig_str[2] = (sig[1] & 0x1f) + ('A' - 1);
  61. rev = (sig[2] << 8) | sig[3];
  62. sprintf(sig_str + 3, "%04X", rev);
  63. return sig_str;
  64. }
  65. static irqreturn_t ip22_eisa_intr(int irq, void *dev_id)
  66. {
  67. u8 eisa_irq = inb(EIU_INTRPT_ACK);
  68. inb(EISA_DMA1_STATUS);
  69. inb(EISA_DMA2_STATUS);
  70. if (eisa_irq < EISA_MAX_IRQ) {
  71. do_IRQ(eisa_irq);
  72. return IRQ_HANDLED;
  73. }
  74. /* Oops, Bad Stuff Happened... */
  75. printk(KERN_ERR "eisa_irq %d out of bound\n", eisa_irq);
  76. outb(0x20, EISA_INT2_CTRL);
  77. outb(0x20, EISA_INT1_CTRL);
  78. return IRQ_NONE;
  79. }
  80. static struct irqaction eisa_action = {
  81. .handler = ip22_eisa_intr,
  82. .name = "EISA",
  83. };
  84. int __init ip22_eisa_init(void)
  85. {
  86. int i, c;
  87. char *str;
  88. if (!(sgimc->systemid & SGIMC_SYSID_EPRESENT)) {
  89. printk(KERN_INFO "EISA: bus not present.\n");
  90. return 1;
  91. }
  92. printk(KERN_INFO "EISA: Probing bus...\n");
  93. for (c = 0, i = 1; i <= IP22_EISA_MAX_SLOTS; i++) {
  94. if ((str = decode_eisa_sig(0x1000 * i + EISA_VENDOR_ID_OFFSET))) {
  95. printk(KERN_INFO "EISA: slot %d : %s detected.\n",
  96. i, str);
  97. c++;
  98. }
  99. }
  100. printk(KERN_INFO "EISA: Detected %d card%s.\n", c, c < 2 ? "" : "s");
  101. #ifdef CONFIG_ISA
  102. printk(KERN_INFO "ISA support compiled in.\n");
  103. #endif
  104. /* Warning : BlackMagicAhead(tm).
  105. Please wave your favorite dead chicken over the busses */
  106. /* First say hello to the EIU */
  107. outl(0x0000FFFF, EIU_PREMPT_REG);
  108. outl(1, EIU_QUIET_REG);
  109. outl(0x40f3c07F, EIU_MODE_REG);
  110. /* Now be nice to the EISA chipset */
  111. outb(1, EISA_EXT_NMI_RESET_CTRL);
  112. udelay(50); /* Wait long enough for the dust to settle */
  113. outb(0, EISA_EXT_NMI_RESET_CTRL);
  114. outb(0, EISA_DMA2_WRITE_SINGLE);
  115. init_i8259_irqs();
  116. /* Cannot use request_irq because of kmalloc not being ready at such
  117. * an early stage. Yes, I've been bitten... */
  118. setup_irq(SGI_EISA_IRQ, &eisa_action);
  119. EISA_bus = 1;
  120. return 0;
  121. }