1
2
3
4
5
6
7
8
9#include <linux/interrupt.h>
10#include <linux/kernel.h>
11#include <asm/dma.h>
12#include <asm/dmabrg.h>
13#include <asm/io.h>
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56#define DMARSRA 0xfe090000
57#define DMAOR 0xffa00040
58#define DMACHCR0 0xffa0000c
59#define DMABRGCR 0xfe3c0000
60
61#define DMAOR_BRG 0x0000c000
62#define DMAOR_DMEN 0x00000001
63
64#define DMABRGI0 68
65#define DMABRGI1 69
66#define DMABRGI2 70
67
68struct dmabrg_handler {
69 void (*handler)(void *);
70 void *data;
71} *dmabrg_handlers;
72
73static inline void dmabrg_call_handler(int i)
74{
75 dmabrg_handlers[i].handler(dmabrg_handlers[i].data);
76}
77
78
79
80
81
82
83
84static irqreturn_t dmabrg_irq(int irq, void *data)
85{
86 unsigned long dcr;
87 unsigned int i;
88
89 dcr = ctrl_inl(DMABRGCR);
90 ctrl_outl(dcr & ~0x00ff0003, DMABRGCR);
91 dcr &= dcr >> 8;
92
93
94 if (dcr & 1)
95 dmabrg_call_handler(DMABRGIRQ_USBDMA);
96 if (dcr & 2)
97 dmabrg_call_handler(DMABRGIRQ_USBDMAERR);
98
99
100 dcr >>= 16;
101 while (dcr) {
102 i = __ffs(dcr);
103 dcr &= dcr - 1;
104 dmabrg_call_handler(i + DMABRGIRQ_A0TXF);
105 }
106 return IRQ_HANDLED;
107}
108
109static void dmabrg_disable_irq(unsigned int dmairq)
110{
111 unsigned long dcr;
112 dcr = ctrl_inl(DMABRGCR);
113 dcr &= ~(1 << ((dmairq > 1) ? dmairq + 22 : dmairq + 8));
114 ctrl_outl(dcr, DMABRGCR);
115}
116
117static void dmabrg_enable_irq(unsigned int dmairq)
118{
119 unsigned long dcr;
120 dcr = ctrl_inl(DMABRGCR);
121 dcr |= (1 << ((dmairq > 1) ? dmairq + 22 : dmairq + 8));
122 ctrl_outl(dcr, DMABRGCR);
123}
124
125int dmabrg_request_irq(unsigned int dmairq, void(*handler)(void*),
126 void *data)
127{
128 if ((dmairq > 9) || !handler)
129 return -ENOENT;
130 if (dmabrg_handlers[dmairq].handler)
131 return -EBUSY;
132
133 dmabrg_handlers[dmairq].handler = handler;
134 dmabrg_handlers[dmairq].data = data;
135
136 dmabrg_enable_irq(dmairq);
137 return 0;
138}
139EXPORT_SYMBOL_GPL(dmabrg_request_irq);
140
141void dmabrg_free_irq(unsigned int dmairq)
142{
143 if (likely(dmairq < 10)) {
144 dmabrg_disable_irq(dmairq);
145 dmabrg_handlers[dmairq].handler = NULL;
146 dmabrg_handlers[dmairq].data = NULL;
147 }
148}
149EXPORT_SYMBOL_GPL(dmabrg_free_irq);
150
151static int __init dmabrg_init(void)
152{
153 unsigned long or;
154 int ret;
155
156 dmabrg_handlers = kzalloc(10 * sizeof(struct dmabrg_handler),
157 GFP_KERNEL);
158 if (!dmabrg_handlers)
159 return -ENOMEM;
160
161#ifdef CONFIG_SH_DMA
162
163 ret = request_dma(0, "DMAC 0 (DMABRG)");
164 if (ret < 0)
165 printk(KERN_INFO "DMABRG: DMAC ch0 not reserved!\n");
166#endif
167
168 ctrl_outl(0, DMABRGCR);
169 ctrl_outl(0, DMACHCR0);
170 ctrl_outl(0x94000000, DMARSRA);
171
172
173 or = ctrl_inl(DMAOR);
174 ctrl_outl(or | DMAOR_BRG | DMAOR_DMEN, DMAOR);
175
176 ret = request_irq(DMABRGI0, dmabrg_irq, IRQF_DISABLED,
177 "DMABRG USB address error", NULL);
178 if (ret)
179 goto out0;
180
181 ret = request_irq(DMABRGI1, dmabrg_irq, IRQF_DISABLED,
182 "DMABRG Transfer End", NULL);
183 if (ret)
184 goto out1;
185
186 ret = request_irq(DMABRGI2, dmabrg_irq, IRQF_DISABLED,
187 "DMABRG Transfer Half", NULL);
188 if (ret == 0)
189 return ret;
190
191 free_irq(DMABRGI1, 0);
192out1: free_irq(DMABRGI0, 0);
193out0: kfree(dmabrg_handlers);
194 return ret;
195}
196subsys_initcall(dmabrg_init);
197