2 * Copyright (C) 2000 YAEGASHI Takeshi
3 * Hitachi HD64461 companion chip support
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>
15 #include <asm/hd64461.h>
17 static void disable_hd64461_irq(unsigned int irq)
20 unsigned short mask = 1 << (irq - HD64461_IRQBASE);
22 nimr = inw(HD64461_NIMR);
24 outw(nimr, HD64461_NIMR);
27 static void enable_hd64461_irq(unsigned int irq)
30 unsigned short mask = 1 << (irq - HD64461_IRQBASE);
32 nimr = inw(HD64461_NIMR);
34 outw(nimr, HD64461_NIMR);
37 static void mask_and_ack_hd64461(unsigned int irq)
39 disable_hd64461_irq(irq);
40 #ifdef CONFIG_HD64461_ENABLER
41 if (irq == HD64461_IRQBASE + 13)
42 outb(0x00, HD64461_PCC1CSCR);
46 static void end_hd64461_irq(unsigned int irq)
48 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
49 enable_hd64461_irq(irq);
52 static unsigned int startup_hd64461_irq(unsigned int irq)
54 enable_hd64461_irq(irq);
58 static void shutdown_hd64461_irq(unsigned int irq)
60 disable_hd64461_irq(irq);
63 static struct hw_interrupt_type hd64461_irq_type = {
64 .typename = "HD64461-IRQ",
65 .startup = startup_hd64461_irq,
66 .shutdown = shutdown_hd64461_irq,
67 .enable = enable_hd64461_irq,
68 .disable = disable_hd64461_irq,
69 .ack = mask_and_ack_hd64461,
70 .end = end_hd64461_irq,
73 static irqreturn_t hd64461_interrupt(int irq, void *dev_id)
76 "HD64461: spurious interrupt, nirr: 0x%x nimr: 0x%x\n",
77 inw(HD64461_NIRR), inw(HD64461_NIMR));
83 int (*func) (int, void *);
85 } hd64461_demux[HD64461_IRQ_NUM];
87 void hd64461_register_irq_demux(int irq,
88 int (*demux) (int irq, void *dev), void *dev)
90 hd64461_demux[irq - HD64461_IRQBASE].func = demux;
91 hd64461_demux[irq - HD64461_IRQBASE].dev = dev;
94 EXPORT_SYMBOL(hd64461_register_irq_demux);
96 void hd64461_unregister_irq_demux(int irq)
98 hd64461_demux[irq - HD64461_IRQBASE].func = 0;
101 EXPORT_SYMBOL(hd64461_unregister_irq_demux);
103 int hd64461_irq_demux(int irq)
105 if (irq == CONFIG_HD64461_IRQ) {
107 unsigned short nirr = inw(HD64461_NIRR);
108 unsigned short nimr = inw(HD64461_NIMR);
112 for (bit = 1, i = 0; i < 16; bit <<= 1, i++)
116 irq = CONFIG_HD64461_IRQ;
118 irq = HD64461_IRQBASE + i;
119 if (hd64461_demux[i].func != 0) {
120 irq = hd64461_demux[i].func(irq, hd64461_demux[i].dev);
124 return __irq_demux(irq);
127 static struct irqaction irq0 = { hd64461_interrupt, IRQF_DISABLED, CPU_MASK_NONE, "HD64461", NULL, NULL };
129 int __init setup_hd64461(void)
137 "HD64461 configured at 0x%x on irq %d(mapped into %d to %d)\n",
138 CONFIG_HD64461_IOBASE, CONFIG_HD64461_IRQ, HD64461_IRQBASE,
139 HD64461_IRQBASE + 15);
141 #if defined(CONFIG_CPU_SUBTYPE_SH7709) /* Should be at processor specific part.. */
142 outw(0x2240, INTC_ICR1);
144 outw(0xffff, HD64461_NIMR);
146 for (i = HD64461_IRQBASE; i < HD64461_IRQBASE + 16; i++) {
147 irq_desc[i].chip = &hd64461_irq_type;
150 setup_irq(CONFIG_HD64461_IRQ, &irq0);
152 #ifdef CONFIG_HD64461_ENABLER
153 printk(KERN_INFO "HD64461: enabling PCMCIA devices\n");
154 outb(0x4c, HD64461_PCC1CSCIER);
155 outb(0x00, HD64461_PCC1CSCR);
161 module_init(setup_hd64461);