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