hd64461.c 3.5 KB

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