setup.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 long flags;
  25. unsigned short nimr;
  26. unsigned short mask = 1 << (irq - HD64465_IRQ_BASE);
  27. pr_debug("disable_hd64465_irq(%d): mask=%x\n", irq, mask);
  28. local_irq_save(flags);
  29. nimr = inw(HD64465_REG_NIMR);
  30. nimr |= mask;
  31. outw(nimr, HD64465_REG_NIMR);
  32. local_irq_restore(flags);
  33. }
  34. static void enable_hd64465_irq(unsigned int irq)
  35. {
  36. unsigned long flags;
  37. unsigned short nimr;
  38. unsigned short mask = 1 << (irq - HD64465_IRQ_BASE);
  39. pr_debug("enable_hd64465_irq(%d): mask=%x\n", irq, mask);
  40. local_irq_save(flags);
  41. nimr = inw(HD64465_REG_NIMR);
  42. nimr &= ~mask;
  43. outw(nimr, HD64465_REG_NIMR);
  44. local_irq_restore(flags);
  45. }
  46. static void mask_and_ack_hd64465(unsigned int irq)
  47. {
  48. disable_hd64465_irq(irq);
  49. }
  50. static void end_hd64465_irq(unsigned int irq)
  51. {
  52. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  53. enable_hd64465_irq(irq);
  54. }
  55. static unsigned int startup_hd64465_irq(unsigned int irq)
  56. {
  57. enable_hd64465_irq(irq);
  58. return 0;
  59. }
  60. static void shutdown_hd64465_irq(unsigned int irq)
  61. {
  62. disable_hd64465_irq(irq);
  63. }
  64. static struct hw_interrupt_type hd64465_irq_type = {
  65. .typename = "HD64465-IRQ",
  66. .startup = startup_hd64465_irq,
  67. .shutdown = shutdown_hd64465_irq,
  68. .enable = enable_hd64465_irq,
  69. .disable = disable_hd64465_irq,
  70. .ack = mask_and_ack_hd64465,
  71. .end = end_hd64465_irq,
  72. };
  73. static irqreturn_t hd64465_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  74. {
  75. printk(KERN_INFO
  76. "HD64465: spurious interrupt, nirr: 0x%x nimr: 0x%x\n",
  77. inw(HD64465_REG_NIRR), inw(HD64465_REG_NIMR));
  78. return IRQ_NONE;
  79. }
  80. /*====================================================*/
  81. /*
  82. * Support for a secondary IRQ demux step. This is necessary
  83. * because the HD64465 presents a very thin interface to the
  84. * PCMCIA bus; a lot of features (such as remapping interrupts)
  85. * normally done in hardware by other PCMCIA host bridges is
  86. * instead done in software.
  87. */
  88. static struct
  89. {
  90. int (*func)(int, void *);
  91. void *dev;
  92. } hd64465_demux[HD64465_IRQ_NUM];
  93. void hd64465_register_irq_demux(int irq,
  94. int (*demux)(int irq, void *dev), void *dev)
  95. {
  96. hd64465_demux[irq - HD64465_IRQ_BASE].func = demux;
  97. hd64465_demux[irq - HD64465_IRQ_BASE].dev = dev;
  98. }
  99. EXPORT_SYMBOL(hd64465_register_irq_demux);
  100. void hd64465_unregister_irq_demux(int irq)
  101. {
  102. hd64465_demux[irq - HD64465_IRQ_BASE].func = 0;
  103. }
  104. EXPORT_SYMBOL(hd64465_unregister_irq_demux);
  105. int hd64465_irq_demux(int irq)
  106. {
  107. if (irq == CONFIG_HD64465_IRQ) {
  108. unsigned short i, bit;
  109. unsigned short nirr = inw(HD64465_REG_NIRR);
  110. unsigned short nimr = inw(HD64465_REG_NIMR);
  111. pr_debug("hd64465_irq_demux, nirr=%04x, nimr=%04x\n", nirr, nimr);
  112. nirr &= ~nimr;
  113. for (bit = 1, i = 0 ; i < HD64465_IRQ_NUM ; bit <<= 1, i++)
  114. if (nirr & bit)
  115. break;
  116. if (i < HD64465_IRQ_NUM) {
  117. irq = HD64465_IRQ_BASE + i;
  118. if (hd64465_demux[i].func != 0)
  119. irq = hd64465_demux[i].func(irq, hd64465_demux[i].dev);
  120. }
  121. }
  122. return irq;
  123. }
  124. static struct irqaction irq0 = { hd64465_interrupt, IRQF_DISABLED, CPU_MASK_NONE, "HD64465", NULL, NULL};
  125. static int __init setup_hd64465(void)
  126. {
  127. int i;
  128. unsigned short rev;
  129. unsigned short smscr;
  130. if (!MACH_HD64465)
  131. return 0;
  132. printk(KERN_INFO "HD64465 configured at 0x%x on irq %d(mapped into %d to %d)\n",
  133. CONFIG_HD64465_IOBASE,
  134. CONFIG_HD64465_IRQ,
  135. HD64465_IRQ_BASE,
  136. HD64465_IRQ_BASE+HD64465_IRQ_NUM-1);
  137. if (inw(HD64465_REG_SDID) != HD64465_SDID) {
  138. printk(KERN_ERR "HD64465 device ID not found, check base address\n");
  139. }
  140. rev = inw(HD64465_REG_SRR);
  141. printk(KERN_INFO "HD64465 hardware revision %d.%d\n", (rev >> 8) & 0xff, rev & 0xff);
  142. outw(0xffff, HD64465_REG_NIMR); /* mask all interrupts */
  143. for (i = 0; i < HD64465_IRQ_NUM ; i++) {
  144. irq_desc[HD64465_IRQ_BASE + i].chip = &hd64465_irq_type;
  145. }
  146. setup_irq(CONFIG_HD64465_IRQ, &irq0);
  147. #ifdef CONFIG_SERIAL
  148. /* wake up the UART from STANDBY at this point */
  149. smscr = inw(HD64465_REG_SMSCR);
  150. outw(smscr & (~HD64465_SMSCR_UARTST), HD64465_REG_SMSCR);
  151. /* remap IO ports for first ISA serial port to HD64465 UART */
  152. hd64465_port_map(0x3f8, 8, CONFIG_HD64465_IOBASE + 0x8000, 1);
  153. #endif
  154. return 0;
  155. }
  156. module_init(setup_hd64465);