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