setup.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. * Support for a secondary IRQ demux step. This is necessary
  76. * because the HD64465 presents a very thin interface to the
  77. * PCMCIA bus; a lot of features (such as remapping interrupts)
  78. * normally done in hardware by other PCMCIA host bridges is
  79. * instead done in software.
  80. */
  81. static struct {
  82. int (*func)(int, void *);
  83. void *dev;
  84. } hd64465_demux[HD64465_IRQ_NUM];
  85. void hd64465_register_irq_demux(int irq,
  86. int (*demux)(int irq, void *dev), void *dev)
  87. {
  88. hd64465_demux[irq - HD64465_IRQ_BASE].func = demux;
  89. hd64465_demux[irq - HD64465_IRQ_BASE].dev = dev;
  90. }
  91. EXPORT_SYMBOL(hd64465_register_irq_demux);
  92. void hd64465_unregister_irq_demux(int irq)
  93. {
  94. hd64465_demux[irq - HD64465_IRQ_BASE].func = 0;
  95. }
  96. EXPORT_SYMBOL(hd64465_unregister_irq_demux);
  97. int hd64465_irq_demux(int irq)
  98. {
  99. if (irq == CONFIG_HD64465_IRQ) {
  100. unsigned short i, bit;
  101. unsigned short nirr = inw(HD64465_REG_NIRR);
  102. unsigned short nimr = inw(HD64465_REG_NIMR);
  103. pr_debug("hd64465_irq_demux, nirr=%04x, nimr=%04x\n", nirr, nimr);
  104. nirr &= ~nimr;
  105. for (bit = 1, i = 0 ; i < HD64465_IRQ_NUM ; bit <<= 1, i++)
  106. if (nirr & bit)
  107. break;
  108. if (i < HD64465_IRQ_NUM) {
  109. irq = HD64465_IRQ_BASE + i;
  110. if (hd64465_demux[i].func != 0)
  111. irq = hd64465_demux[i].func(irq, hd64465_demux[i].dev);
  112. }
  113. }
  114. return irq;
  115. }
  116. static struct irqaction irq0 = {
  117. .handler = hd64465_interrupt,
  118. .flags = IRQF_DISABLED,
  119. .mask = CPU_MASK_NONE,
  120. .name = "HD64465",
  121. };
  122. static int __init setup_hd64465(void)
  123. {
  124. int i;
  125. unsigned short rev;
  126. unsigned short smscr;
  127. if (!MACH_HD64465)
  128. return 0;
  129. printk(KERN_INFO "HD64465 configured at 0x%x on irq %d(mapped into %d to %d)\n",
  130. CONFIG_HD64465_IOBASE,
  131. CONFIG_HD64465_IRQ,
  132. HD64465_IRQ_BASE,
  133. HD64465_IRQ_BASE+HD64465_IRQ_NUM-1);
  134. if (inw(HD64465_REG_SDID) != HD64465_SDID) {
  135. printk(KERN_ERR "HD64465 device ID not found, check base address\n");
  136. }
  137. rev = inw(HD64465_REG_SRR);
  138. printk(KERN_INFO "HD64465 hardware revision %d.%d\n", (rev >> 8) & 0xff, rev & 0xff);
  139. outw(0xffff, HD64465_REG_NIMR); /* mask all interrupts */
  140. for (i = 0; i < HD64465_IRQ_NUM ; i++) {
  141. irq_desc[HD64465_IRQ_BASE + i].chip = &hd64465_irq_type;
  142. }
  143. setup_irq(CONFIG_HD64465_IRQ, &irq0);
  144. /* wake up the UART from STANDBY at this point */
  145. smscr = inw(HD64465_REG_SMSCR);
  146. outw(smscr & (~HD64465_SMSCR_UARTST), HD64465_REG_SMSCR);
  147. /* remap IO ports for first ISA serial port to HD64465 UART */
  148. hd64465_port_map(0x3f8, 8, CONFIG_HD64465_IOBASE + 0x8000, 1);
  149. return 0;
  150. }
  151. module_init(setup_hd64465);