[XFS] Fix merge failures
[pandora-kernel.git] / arch / sh / cchips / hd6446x / hd64461.c
1 /*
2  *      Copyright (C) 2000 YAEGASHI Takeshi
3  *      Hitachi HD64461 companion chip support
4  */
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 <linux/io.h>
14 #include <asm/irq.h>
15 #include <asm/hd64461.h>
16
17 /* This belongs in cpu specific */
18 #define INTC_ICR1 0xA4140010UL
19
20 static void hd64461_mask_irq(unsigned int irq)
21 {
22         unsigned short nimr;
23         unsigned short mask = 1 << (irq - HD64461_IRQBASE);
24
25         nimr = __raw_readw(HD64461_NIMR);
26         nimr |= mask;
27         __raw_writew(nimr, HD64461_NIMR);
28 }
29
30 static void hd64461_unmask_irq(unsigned int irq)
31 {
32         unsigned short nimr;
33         unsigned short mask = 1 << (irq - HD64461_IRQBASE);
34
35         nimr = __raw_readw(HD64461_NIMR);
36         nimr &= ~mask;
37         __raw_writew(nimr, HD64461_NIMR);
38 }
39
40 static void hd64461_mask_and_ack_irq(unsigned int irq)
41 {
42         hd64461_mask_irq(irq);
43 #ifdef CONFIG_HD64461_ENABLER
44         if (irq == HD64461_IRQBASE + 13)
45                 __raw_writeb(0x00, HD64461_PCC1CSCR);
46 #endif
47 }
48
49 static struct irq_chip hd64461_irq_chip = {
50         .name           = "HD64461-IRQ",
51         .mask           = hd64461_mask_irq,
52         .mask_ack       = hd64461_mask_and_ack_irq,
53         .unmask         = hd64461_unmask_irq,
54 };
55
56 int hd64461_irq_demux(int irq)
57 {
58         if (irq == CONFIG_HD64461_IRQ) {
59                 unsigned short bit;
60                 unsigned short nirr = inw(HD64461_NIRR);
61                 unsigned short nimr = inw(HD64461_NIMR);
62                 int i;
63
64                 nirr &= ~nimr;
65                 for (bit = 1, i = 0; i < 16; bit <<= 1, i++)
66                         if (nirr & bit)
67                                 break;
68                 irq = HD64461_IRQBASE + i;
69         }
70         return irq;
71 }
72
73 int __init setup_hd64461(void)
74 {
75         int i;
76
77         if (!MACH_HD64461)
78                 return 0;
79
80         printk(KERN_INFO
81                "HD64461 configured at 0x%x on irq %d(mapped into %d to %d)\n",
82                CONFIG_HD64461_IOBASE, CONFIG_HD64461_IRQ, HD64461_IRQBASE,
83                HD64461_IRQBASE + 15);
84
85 /* Should be at processor specific part.. */
86 #if defined(CONFIG_CPU_SUBTYPE_SH7709)
87         __raw_writew(0x2240, INTC_ICR1);
88 #endif
89         __raw_writew(0xffff, HD64461_NIMR);
90
91         /*  IRQ 80 -> 95 belongs to HD64461  */
92         for (i = HD64461_IRQBASE; i < HD64461_IRQBASE + 16; i++)
93                 set_irq_chip_and_handler(i, &hd64461_irq_chip,
94                                          handle_level_irq);
95
96 #ifdef CONFIG_HD64461_ENABLER
97         printk(KERN_INFO "HD64461: enabling PCMCIA devices\n");
98         __raw_writeb(0x4c, HD64461_PCC1CSCIER);
99         __raw_writeb(0x00, HD64461_PCC1CSCR);
100 #endif
101
102         return 0;
103 }
104
105 module_init(setup_hd64461);