setup.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * $Id: setup.c,v 1.4 2003/08/03 03:05:10 lethal Exp $
  3. *
  4. * Setup and IRQ handling code for the HD64465 companion chip.
  5. * by Greg Banks <gbanks@pocketpenguins.com>
  6. * Copyright (c) 2000 PocketPenguins Inc
  7. *
  8. * Derived from setup_hd64461.c which bore the message:
  9. * Copyright (C) 2000 YAEGASHI Takeshi
  10. */
  11. #include <linux/sched.h>
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/param.h>
  15. #include <linux/ioport.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/init.h>
  18. #include <linux/irq.h>
  19. #include <asm/io.h>
  20. #include <asm/irq.h>
  21. #include <asm/hd64465/hd64465.h>
  22. static void disable_hd64465_irq(unsigned int irq)
  23. {
  24. unsigned short nimr;
  25. unsigned short mask = 1 << (irq - HD64465_IRQ_BASE);
  26. pr_debug("disable_hd64465_irq(%d): mask=%x\n", irq, mask);
  27. nimr = inw(HD64465_REG_NIMR);
  28. nimr |= mask;
  29. outw(nimr, HD64465_REG_NIMR);
  30. }
  31. static void enable_hd64465_irq(unsigned int irq)
  32. {
  33. unsigned short nimr;
  34. unsigned short mask = 1 << (irq - HD64465_IRQ_BASE);
  35. pr_debug("enable_hd64465_irq(%d): mask=%x\n", irq, mask);
  36. nimr = inw(HD64465_REG_NIMR);
  37. nimr &= ~mask;
  38. outw(nimr, HD64465_REG_NIMR);
  39. }
  40. static void mask_and_ack_hd64465(unsigned int irq)
  41. {
  42. disable_hd64465_irq(irq);
  43. }
  44. static void end_hd64465_irq(unsigned int irq)
  45. {
  46. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  47. enable_hd64465_irq(irq);
  48. }
  49. static unsigned int startup_hd64465_irq(unsigned int irq)
  50. {
  51. enable_hd64465_irq(irq);
  52. return 0;
  53. }
  54. static void shutdown_hd64465_irq(unsigned int irq)
  55. {
  56. disable_hd64465_irq(irq);
  57. }
  58. static struct hw_interrupt_type hd64465_irq_type = {
  59. .typename = "HD64465-IRQ",
  60. .startup = startup_hd64465_irq,
  61. .shutdown = shutdown_hd64465_irq,
  62. .enable = enable_hd64465_irq,
  63. .disable = disable_hd64465_irq,
  64. .ack = mask_and_ack_hd64465,
  65. .end = end_hd64465_irq,
  66. };
  67. static irqreturn_t hd64465_interrupt(int irq, void *dev_id)
  68. {
  69. printk(KERN_INFO
  70. "HD64465: spurious interrupt, nirr: 0x%x nimr: 0x%x\n",
  71. inw(HD64465_REG_NIRR), inw(HD64465_REG_NIMR));
  72. return IRQ_NONE;
  73. }
  74. /*====================================================*/
  75. /*
  76. * Support for a secondary IRQ demux step. This is necessary
  77. * because the HD64465 presents a very thin interface to the
  78. * PCMCIA bus; a lot of features (such as remapping interrupts)
  79. * normally done in hardware by other PCMCIA host bridges is
  80. * instead done in software.
  81. */
  82. static struct
  83. {
  84. int (*func)(int, void *);
  85. void *dev;
  86. } hd64465_demux[HD64465_IRQ_NUM];
  87. void hd64465_register_irq_demux(int irq,
  88. int (*demux)(int irq, void *dev), void *dev)
  89. {
  90. hd64465_demux[irq - HD64465_IRQ_BASE].func = demux;
  91. hd64465_demux[irq - HD64465_IRQ_BASE].dev = dev;
  92. }
  93. EXPORT_SYMBOL(hd64465_register_irq_demux);
  94. void hd64465_unregister_irq_demux(int irq)
  95. {
  96. hd64465_demux[irq - HD64465_IRQ_BASE].func = 0;
  97. }
  98. EXPORT_SYMBOL(hd64465_unregister_irq_demux);
  99. int hd64465_irq_demux(int irq)
  100. {
  101. if (irq == CONFIG_HD64465_IRQ) {
  102. unsigned short i, bit;
  103. unsigned short nirr = inw(HD64465_REG_NIRR);
  104. unsigned short nimr = inw(HD64465_REG_NIMR);
  105. pr_debug("hd64465_irq_demux, nirr=%04x, nimr=%04x\n", nirr, nimr);
  106. nirr &= ~nimr;
  107. for (bit = 1, i = 0 ; i < HD64465_IRQ_NUM ; bit <<= 1, i++)
  108. if (nirr & bit)
  109. break;
  110. if (i < HD64465_IRQ_NUM) {
  111. irq = HD64465_IRQ_BASE + i;
  112. if (hd64465_demux[i].func != 0)
  113. irq = hd64465_demux[i].func(irq, hd64465_demux[i].dev);
  114. }
  115. }
  116. return irq;
  117. }
  118. static struct irqaction irq0 = { hd64465_interrupt, IRQF_DISABLED, CPU_MASK_NONE, "HD64465", NULL, NULL};
  119. static int __init setup_hd64465(void)
  120. {
  121. int i;
  122. unsigned short rev;
  123. unsigned short smscr;
  124. if (!MACH_HD64465)
  125. return 0;
  126. printk(KERN_INFO "HD64465 configured at 0x%x on irq %d(mapped into %d to %d)\n",
  127. CONFIG_HD64465_IOBASE,
  128. CONFIG_HD64465_IRQ,
  129. HD64465_IRQ_BASE,
  130. HD64465_IRQ_BASE+HD64465_IRQ_NUM-1);
  131. if (inw(HD64465_REG_SDID) != HD64465_SDID) {
  132. printk(KERN_ERR "HD64465 device ID not found, check base address\n");
  133. }
  134. rev = inw(HD64465_REG_SRR);
  135. printk(KERN_INFO "HD64465 hardware revision %d.%d\n", (rev >> 8) & 0xff, rev & 0xff);
  136. outw(0xffff, HD64465_REG_NIMR); /* mask all interrupts */
  137. for (i = 0; i < HD64465_IRQ_NUM ; i++) {
  138. irq_desc[HD64465_IRQ_BASE + i].chip = &hd64465_irq_type;
  139. }
  140. setup_irq(CONFIG_HD64465_IRQ, &irq0);
  141. #ifdef CONFIG_SERIAL
  142. /* wake up the UART from STANDBY at this point */
  143. smscr = inw(HD64465_REG_SMSCR);
  144. outw(smscr & (~HD64465_SMSCR_UARTST), HD64465_REG_SMSCR);
  145. /* remap IO ports for first ISA serial port to HD64465 UART */
  146. hd64465_port_map(0x3f8, 8, CONFIG_HD64465_IOBASE + 0x8000, 1);
  147. #endif
  148. return 0;
  149. }
  150. module_init(setup_hd64465);