setup.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * $Id: setup.c,v 1.5 2004/03/16 00:07:50 lethal Exp $
  3. * Copyright (C) 2000 YAEGASHI Takeshi
  4. * Hitachi HD64461 companion chip support
  5. */
  6. #include <linux/config.h>
  7. #include <linux/sched.h>
  8. #include <linux/module.h>
  9. #include <linux/kernel.h>
  10. #include <linux/param.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/init.h>
  13. #include <linux/irq.h>
  14. #include <asm/io.h>
  15. #include <asm/irq.h>
  16. #include <asm/hd64461/hd64461.h>
  17. static void disable_hd64461_irq(unsigned int irq)
  18. {
  19. unsigned long flags;
  20. unsigned short nimr;
  21. unsigned short mask = 1 << (irq - HD64461_IRQBASE);
  22. local_irq_save(flags);
  23. nimr = inw(HD64461_NIMR);
  24. nimr |= mask;
  25. outw(nimr, HD64461_NIMR);
  26. local_irq_restore(flags);
  27. }
  28. static void enable_hd64461_irq(unsigned int irq)
  29. {
  30. unsigned long flags;
  31. unsigned short nimr;
  32. unsigned short mask = 1 << (irq - HD64461_IRQBASE);
  33. local_irq_save(flags);
  34. nimr = inw(HD64461_NIMR);
  35. nimr &= ~mask;
  36. outw(nimr, HD64461_NIMR);
  37. local_irq_restore(flags);
  38. }
  39. static void mask_and_ack_hd64461(unsigned int irq)
  40. {
  41. disable_hd64461_irq(irq);
  42. #ifdef CONFIG_HD64461_ENABLER
  43. if (irq == HD64461_IRQBASE + 13)
  44. outb(0x00, HD64461_PCC1CSCR);
  45. #endif
  46. }
  47. static void end_hd64461_irq(unsigned int irq)
  48. {
  49. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  50. enable_hd64461_irq(irq);
  51. }
  52. static unsigned int startup_hd64461_irq(unsigned int irq)
  53. {
  54. enable_hd64461_irq(irq);
  55. return 0;
  56. }
  57. static void shutdown_hd64461_irq(unsigned int irq)
  58. {
  59. disable_hd64461_irq(irq);
  60. }
  61. static struct hw_interrupt_type hd64461_irq_type = {
  62. .typename = "HD64461-IRQ",
  63. .startup = startup_hd64461_irq,
  64. .shutdown = shutdown_hd64461_irq,
  65. .enable = enable_hd64461_irq,
  66. .disable = disable_hd64461_irq,
  67. .ack = mask_and_ack_hd64461,
  68. .end = end_hd64461_irq,
  69. };
  70. static irqreturn_t hd64461_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  71. {
  72. printk(KERN_INFO
  73. "HD64461: spurious interrupt, nirr: 0x%x nimr: 0x%x\n",
  74. inw(HD64461_NIRR), inw(HD64461_NIMR));
  75. return IRQ_NONE;
  76. }
  77. static struct {
  78. int (*func) (int, void *);
  79. void *dev;
  80. } hd64461_demux[HD64461_IRQ_NUM];
  81. void hd64461_register_irq_demux(int irq,
  82. int (*demux) (int irq, void *dev), void *dev)
  83. {
  84. hd64461_demux[irq - HD64461_IRQBASE].func = demux;
  85. hd64461_demux[irq - HD64461_IRQBASE].dev = dev;
  86. }
  87. EXPORT_SYMBOL(hd64461_register_irq_demux);
  88. void hd64461_unregister_irq_demux(int irq)
  89. {
  90. hd64461_demux[irq - HD64461_IRQBASE].func = 0;
  91. }
  92. EXPORT_SYMBOL(hd64461_unregister_irq_demux);
  93. int hd64461_irq_demux(int irq)
  94. {
  95. if (irq == CONFIG_HD64461_IRQ) {
  96. unsigned short bit;
  97. unsigned short nirr = inw(HD64461_NIRR);
  98. unsigned short nimr = inw(HD64461_NIMR);
  99. int i;
  100. nirr &= ~nimr;
  101. for (bit = 1, i = 0; i < 16; bit <<= 1, i++)
  102. if (nirr & bit)
  103. break;
  104. if (i == 16)
  105. irq = CONFIG_HD64461_IRQ;
  106. else {
  107. irq = HD64461_IRQBASE + i;
  108. if (hd64461_demux[i].func != 0) {
  109. irq = hd64461_demux[i].func(irq, hd64461_demux[i].dev);
  110. }
  111. }
  112. }
  113. return __irq_demux(irq);
  114. }
  115. static struct irqaction irq0 = { hd64461_interrupt, SA_INTERRUPT, CPU_MASK_NONE, "HD64461", NULL, NULL };
  116. int __init setup_hd64461(void)
  117. {
  118. int i;
  119. if (!MACH_HD64461)
  120. return 0;
  121. printk(KERN_INFO
  122. "HD64461 configured at 0x%x on irq %d(mapped into %d to %d)\n",
  123. CONFIG_HD64461_IOBASE, CONFIG_HD64461_IRQ, HD64461_IRQBASE,
  124. HD64461_IRQBASE + 15);
  125. #if defined(CONFIG_CPU_SUBTYPE_SH7709) /* Should be at processor specific part.. */
  126. outw(0x2240, INTC_ICR1);
  127. #endif
  128. outw(0xffff, HD64461_NIMR);
  129. for (i = HD64461_IRQBASE; i < HD64461_IRQBASE + 16; i++) {
  130. irq_desc[i].handler = &hd64461_irq_type;
  131. }
  132. setup_irq(CONFIG_HD64461_IRQ, &irq0);
  133. #ifdef CONFIG_HD64461_ENABLER
  134. printk(KERN_INFO "HD64461: enabling PCMCIA devices\n");
  135. outb(0x4c, HD64461_PCC1CSCIER);
  136. outb(0x00, HD64461_PCC1CSCR);
  137. #endif
  138. return 0;
  139. }
  140. module_init(setup_hd64461);