hd64461.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. /* This belongs in cpu specific */
  16. #define INTC_ICR1 0xA4140010UL
  17. static void disable_hd64461_irq(unsigned int irq)
  18. {
  19. unsigned short nimr;
  20. unsigned short mask = 1 << (irq - HD64461_IRQBASE);
  21. nimr = inw(HD64461_NIMR);
  22. nimr |= mask;
  23. outw(nimr, HD64461_NIMR);
  24. }
  25. static void enable_hd64461_irq(unsigned int irq)
  26. {
  27. unsigned short nimr;
  28. unsigned short mask = 1 << (irq - HD64461_IRQBASE);
  29. nimr = inw(HD64461_NIMR);
  30. nimr &= ~mask;
  31. outw(nimr, HD64461_NIMR);
  32. }
  33. static void mask_and_ack_hd64461(unsigned int irq)
  34. {
  35. disable_hd64461_irq(irq);
  36. #ifdef CONFIG_HD64461_ENABLER
  37. if (irq == HD64461_IRQBASE + 13)
  38. outb(0x00, HD64461_PCC1CSCR);
  39. #endif
  40. }
  41. static void end_hd64461_irq(unsigned int irq)
  42. {
  43. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  44. enable_hd64461_irq(irq);
  45. }
  46. static unsigned int startup_hd64461_irq(unsigned int irq)
  47. {
  48. enable_hd64461_irq(irq);
  49. return 0;
  50. }
  51. static void shutdown_hd64461_irq(unsigned int irq)
  52. {
  53. disable_hd64461_irq(irq);
  54. }
  55. static struct hw_interrupt_type hd64461_irq_type = {
  56. .typename = "HD64461-IRQ",
  57. .startup = startup_hd64461_irq,
  58. .shutdown = shutdown_hd64461_irq,
  59. .enable = enable_hd64461_irq,
  60. .disable = disable_hd64461_irq,
  61. .ack = mask_and_ack_hd64461,
  62. .end = end_hd64461_irq,
  63. };
  64. static irqreturn_t hd64461_interrupt(int irq, void *dev_id)
  65. {
  66. printk(KERN_INFO
  67. "HD64461: spurious interrupt, nirr: 0x%x nimr: 0x%x\n",
  68. inw(HD64461_NIRR), inw(HD64461_NIMR));
  69. return IRQ_NONE;
  70. }
  71. static struct {
  72. int (*func) (int, void *);
  73. void *dev;
  74. } hd64461_demux[HD64461_IRQ_NUM];
  75. void hd64461_register_irq_demux(int irq,
  76. int (*demux) (int irq, void *dev), void *dev)
  77. {
  78. hd64461_demux[irq - HD64461_IRQBASE].func = demux;
  79. hd64461_demux[irq - HD64461_IRQBASE].dev = dev;
  80. }
  81. EXPORT_SYMBOL(hd64461_register_irq_demux);
  82. void hd64461_unregister_irq_demux(int irq)
  83. {
  84. hd64461_demux[irq - HD64461_IRQBASE].func = 0;
  85. }
  86. EXPORT_SYMBOL(hd64461_unregister_irq_demux);
  87. int hd64461_irq_demux(int irq)
  88. {
  89. if (irq == CONFIG_HD64461_IRQ) {
  90. unsigned short bit;
  91. unsigned short nirr = inw(HD64461_NIRR);
  92. unsigned short nimr = inw(HD64461_NIMR);
  93. int i;
  94. nirr &= ~nimr;
  95. for (bit = 1, i = 0; i < 16; bit <<= 1, i++)
  96. if (nirr & bit)
  97. break;
  98. if (i == 16)
  99. irq = CONFIG_HD64461_IRQ;
  100. else {
  101. irq = HD64461_IRQBASE + i;
  102. if (hd64461_demux[i].func != 0) {
  103. irq = hd64461_demux[i].func(irq, hd64461_demux[i].dev);
  104. }
  105. }
  106. }
  107. return irq;
  108. }
  109. static struct irqaction irq0 = {
  110. .handler = hd64461_interrupt,
  111. .flags = IRQF_DISABLED,
  112. .mask = CPU_MASK_NONE,
  113. .name = "HD64461",
  114. };
  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. /* IRQ 80 -> 95 belongs to HD64461 */
  129. for (i = HD64461_IRQBASE; i < HD64461_IRQBASE + 16; i++) {
  130. irq_desc[i].chip = &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);