setup.c 3.7 KB

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