Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux...
[pandora-kernel.git] / arch / sh / cchips / hd6446x / hd64461 / setup.c
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
7 #include <linux/sched.h>
8 #include <linux/module.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/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         local_irq_save(flags);
27         nimr = inw(HD64461_NIMR);
28         nimr |= mask;
29         outw(nimr, HD64461_NIMR);
30         local_irq_restore(flags);
31 }
32
33 static void enable_hd64461_irq(unsigned int irq)
34 {
35         unsigned long flags;
36         unsigned short nimr;
37         unsigned short mask = 1 << (irq - HD64461_IRQBASE);
38
39         local_irq_save(flags);
40         nimr = inw(HD64461_NIMR);
41         nimr &= ~mask;
42         outw(nimr, HD64461_NIMR);
43         local_irq_restore(flags);
44 }
45
46 static void mask_and_ack_hd64461(unsigned int irq)
47 {
48         disable_hd64461_irq(irq);
49 #ifdef CONFIG_HD64461_ENABLER
50         if (irq == HD64461_IRQBASE + 13)
51                 outb(0x00, HD64461_PCC1CSCR);
52 #endif
53 }
54
55 static void end_hd64461_irq(unsigned int irq)
56 {
57         if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
58                 enable_hd64461_irq(irq);
59 }
60
61 static unsigned int startup_hd64461_irq(unsigned int irq)
62 {
63         enable_hd64461_irq(irq);
64         return 0;
65 }
66
67 static void shutdown_hd64461_irq(unsigned int irq)
68 {
69         disable_hd64461_irq(irq);
70 }
71
72 static struct hw_interrupt_type hd64461_irq_type = {
73         .typename       = "HD64461-IRQ",
74         .startup        = startup_hd64461_irq,
75         .shutdown       = shutdown_hd64461_irq,
76         .enable         = enable_hd64461_irq,
77         .disable        = disable_hd64461_irq,
78         .ack            = mask_and_ack_hd64461,
79         .end            = end_hd64461_irq,
80 };
81
82 static irqreturn_t hd64461_interrupt(int irq, void *dev_id, struct pt_regs *regs)
83 {
84         printk(KERN_INFO
85                "HD64461: spurious interrupt, nirr: 0x%x nimr: 0x%x\n",
86                inw(HD64461_NIRR), inw(HD64461_NIMR));
87
88         return IRQ_NONE;
89 }
90
91 static struct {
92         int (*func) (int, void *);
93         void *dev;
94 } hd64461_demux[HD64461_IRQ_NUM];
95
96 void hd64461_register_irq_demux(int irq,
97                                 int (*demux) (int irq, void *dev), void *dev)
98 {
99         hd64461_demux[irq - HD64461_IRQBASE].func = demux;
100         hd64461_demux[irq - HD64461_IRQBASE].dev = dev;
101 }
102
103 EXPORT_SYMBOL(hd64461_register_irq_demux);
104
105 void hd64461_unregister_irq_demux(int irq)
106 {
107         hd64461_demux[irq - HD64461_IRQBASE].func = 0;
108 }
109
110 EXPORT_SYMBOL(hd64461_unregister_irq_demux);
111
112 int hd64461_irq_demux(int irq)
113 {
114         if (irq == CONFIG_HD64461_IRQ) {
115                 unsigned short bit;
116                 unsigned short nirr = inw(HD64461_NIRR);
117                 unsigned short nimr = inw(HD64461_NIMR);
118                 int i;
119
120                 nirr &= ~nimr;
121                 for (bit = 1, i = 0; i < 16; bit <<= 1, i++)
122                         if (nirr & bit)
123                                 break;
124                 if (i == 16)
125                         irq = CONFIG_HD64461_IRQ;
126                 else {
127                         irq = HD64461_IRQBASE + i;
128                         if (hd64461_demux[i].func != 0) {
129                                 irq = hd64461_demux[i].func(irq, hd64461_demux[i].dev);
130                         }
131                 }
132         }
133         return __irq_demux(irq);
134 }
135
136 static struct irqaction irq0 = { hd64461_interrupt, IRQF_DISABLED, CPU_MASK_NONE, "HD64461", NULL, NULL };
137
138 int __init setup_hd64461(void)
139 {
140         int i;
141
142         if (!MACH_HD64461)
143                 return 0;
144
145         printk(KERN_INFO
146                "HD64461 configured at 0x%x on irq %d(mapped into %d to %d)\n",
147                CONFIG_HD64461_IOBASE, CONFIG_HD64461_IRQ, HD64461_IRQBASE,
148                HD64461_IRQBASE + 15);
149
150 #if defined(CONFIG_CPU_SUBTYPE_SH7709)  /* Should be at processor specific part.. */
151         outw(0x2240, INTC_ICR1);
152 #endif
153         outw(0xffff, HD64461_NIMR);
154
155         for (i = HD64461_IRQBASE; i < HD64461_IRQBASE + 16; i++) {
156                 irq_desc[i].chip = &hd64461_irq_type;
157         }
158
159         setup_irq(CONFIG_HD64461_IRQ, &irq0);
160
161 #ifdef CONFIG_HD64461_ENABLER
162         printk(KERN_INFO "HD64461: enabling PCMCIA devices\n");
163         outb(0x4c, HD64461_PCC1CSCIER);
164         outb(0x00, HD64461_PCC1CSCR);
165 #endif
166
167         return 0;
168 }
169
170 module_init(setup_hd64461);