setup.c 3.6 KB

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