diff options
Diffstat (limited to 'arch/m32r/kernel/io_mappi.c')
-rw-r--r-- | arch/m32r/kernel/io_mappi.c | 384 |
1 files changed, 384 insertions, 0 deletions
diff --git a/arch/m32r/kernel/io_mappi.c b/arch/m32r/kernel/io_mappi.c new file mode 100644 index 000000000000..85688ffb52f9 --- /dev/null +++ b/arch/m32r/kernel/io_mappi.c | |||
@@ -0,0 +1,384 @@ | |||
1 | /* | ||
2 | * linux/arch/m32r/kernel/io_mappi.c | ||
3 | * | ||
4 | * Typical I/O routines for Mappi board. | ||
5 | * | ||
6 | * Copyright (c) 2001, 2002 Hiroyuki Kondo, Hirokazu Takata, | ||
7 | * Hitoshi Yamamoto | ||
8 | */ | ||
9 | |||
10 | #include <linux/config.h> | ||
11 | #include <asm/m32r.h> | ||
12 | #include <asm/page.h> | ||
13 | #include <asm/io.h> | ||
14 | #include <asm/byteorder.h> | ||
15 | |||
16 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC) | ||
17 | #include <linux/types.h> | ||
18 | |||
19 | #define M32R_PCC_IOMAP_SIZE 0x1000 | ||
20 | |||
21 | #define M32R_PCC_IOSTART0 0x1000 | ||
22 | #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1) | ||
23 | #define M32R_PCC_IOSTART1 0x2000 | ||
24 | #define M32R_PCC_IOEND1 (M32R_PCC_IOSTART1 + M32R_PCC_IOMAP_SIZE - 1) | ||
25 | |||
26 | extern void pcc_ioread(int, unsigned long, void *, size_t, size_t, int); | ||
27 | extern void pcc_iowrite(int, unsigned long, void *, size_t, size_t, int); | ||
28 | #endif /* CONFIG_PCMCIA && CONFIG_M32R_PCC */ | ||
29 | |||
30 | #define PORT2ADDR(port) _port2addr(port) | ||
31 | |||
32 | static inline void *_port2addr(unsigned long port) | ||
33 | { | ||
34 | return (void *)(port + NONCACHE_OFFSET); | ||
35 | } | ||
36 | |||
37 | static inline void *_port2addr_ne(unsigned long port) | ||
38 | { | ||
39 | return (void *)((port<<1) + NONCACHE_OFFSET + 0x0C000000); | ||
40 | } | ||
41 | |||
42 | static inline void delay(void) | ||
43 | { | ||
44 | __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory"); | ||
45 | } | ||
46 | |||
47 | /* | ||
48 | * NIC I/O function | ||
49 | */ | ||
50 | |||
51 | #define PORT2ADDR_NE(port) _port2addr_ne(port) | ||
52 | |||
53 | static inline unsigned char _ne_inb(void *portp) | ||
54 | { | ||
55 | return (unsigned char) *(volatile unsigned short *)portp; | ||
56 | } | ||
57 | |||
58 | static inline unsigned short _ne_inw(void *portp) | ||
59 | { | ||
60 | unsigned short tmp; | ||
61 | |||
62 | tmp = *(volatile unsigned short *)portp; | ||
63 | return le16_to_cpu(tmp); | ||
64 | } | ||
65 | |||
66 | static inline void _ne_outb(unsigned char b, void *portp) | ||
67 | { | ||
68 | *(volatile unsigned short *)portp = (unsigned short)b; | ||
69 | } | ||
70 | |||
71 | static inline void _ne_outw(unsigned short w, void *portp) | ||
72 | { | ||
73 | *(volatile unsigned short *)portp = cpu_to_le16(w); | ||
74 | } | ||
75 | |||
76 | unsigned char _inb(unsigned long port) | ||
77 | { | ||
78 | if (port >= 0x300 && port < 0x320) | ||
79 | return _ne_inb(PORT2ADDR_NE(port)); | ||
80 | else | ||
81 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC) | ||
82 | if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
83 | unsigned char b; | ||
84 | pcc_ioread(0, port, &b, sizeof(b), 1, 0); | ||
85 | return b; | ||
86 | } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) { | ||
87 | unsigned char b; | ||
88 | pcc_ioread(1, port, &b, sizeof(b), 1, 0); | ||
89 | return b; | ||
90 | } else | ||
91 | #endif | ||
92 | |||
93 | return *(volatile unsigned char *)PORT2ADDR(port); | ||
94 | } | ||
95 | |||
96 | unsigned short _inw(unsigned long port) | ||
97 | { | ||
98 | if (port >= 0x300 && port < 0x320) | ||
99 | return _ne_inw(PORT2ADDR_NE(port)); | ||
100 | else | ||
101 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC) | ||
102 | if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
103 | unsigned short w; | ||
104 | pcc_ioread(0, port, &w, sizeof(w), 1, 0); | ||
105 | return w; | ||
106 | } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) { | ||
107 | unsigned short w; | ||
108 | pcc_ioread(1, port, &w, sizeof(w), 1, 0); | ||
109 | return w; | ||
110 | } else | ||
111 | #endif | ||
112 | return *(volatile unsigned short *)PORT2ADDR(port); | ||
113 | } | ||
114 | |||
115 | unsigned long _inl(unsigned long port) | ||
116 | { | ||
117 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC) | ||
118 | if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
119 | unsigned long l; | ||
120 | pcc_ioread(0, port, &l, sizeof(l), 1, 0); | ||
121 | return l; | ||
122 | } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) { | ||
123 | unsigned short l; | ||
124 | pcc_ioread(1, port, &l, sizeof(l), 1, 0); | ||
125 | return l; | ||
126 | } else | ||
127 | #endif | ||
128 | return *(volatile unsigned long *)PORT2ADDR(port); | ||
129 | } | ||
130 | |||
131 | unsigned char _inb_p(unsigned long port) | ||
132 | { | ||
133 | unsigned char v; | ||
134 | |||
135 | if (port >= 0x300 && port < 0x320) | ||
136 | v = _ne_inb(PORT2ADDR_NE(port)); | ||
137 | else | ||
138 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC) | ||
139 | if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
140 | unsigned char b; | ||
141 | pcc_ioread(0, port, &b, sizeof(b), 1, 0); | ||
142 | return b; | ||
143 | } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) { | ||
144 | unsigned char b; | ||
145 | pcc_ioread(1, port, &b, sizeof(b), 1, 0); | ||
146 | return b; | ||
147 | } else | ||
148 | #endif | ||
149 | v = *(volatile unsigned char *)PORT2ADDR(port); | ||
150 | |||
151 | delay(); | ||
152 | return (v); | ||
153 | } | ||
154 | |||
155 | unsigned short _inw_p(unsigned long port) | ||
156 | { | ||
157 | unsigned short v; | ||
158 | |||
159 | if (port >= 0x300 && port < 0x320) | ||
160 | v = _ne_inw(PORT2ADDR_NE(port)); | ||
161 | else | ||
162 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC) | ||
163 | if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
164 | unsigned short w; | ||
165 | pcc_ioread(0, port, &w, sizeof(w), 1, 0); | ||
166 | return w; | ||
167 | } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) { | ||
168 | unsigned short w; | ||
169 | pcc_ioread(1, port, &w, sizeof(w), 1, 0); | ||
170 | return w; | ||
171 | } else | ||
172 | #endif | ||
173 | v = *(volatile unsigned short *)PORT2ADDR(port); | ||
174 | |||
175 | delay(); | ||
176 | return (v); | ||
177 | } | ||
178 | |||
179 | unsigned long _inl_p(unsigned long port) | ||
180 | { | ||
181 | unsigned long v; | ||
182 | |||
183 | v = *(volatile unsigned long *)PORT2ADDR(port); | ||
184 | delay(); | ||
185 | return (v); | ||
186 | } | ||
187 | |||
188 | void _outb(unsigned char b, unsigned long port) | ||
189 | { | ||
190 | if (port >= 0x300 && port < 0x320) | ||
191 | _ne_outb(b, PORT2ADDR_NE(port)); | ||
192 | else | ||
193 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC) | ||
194 | if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
195 | pcc_iowrite(0, port, &b, sizeof(b), 1, 0); | ||
196 | } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) { | ||
197 | pcc_iowrite(1, port, &b, sizeof(b), 1, 0); | ||
198 | } else | ||
199 | #endif | ||
200 | *(volatile unsigned char *)PORT2ADDR(port) = b; | ||
201 | } | ||
202 | |||
203 | void _outw(unsigned short w, unsigned long port) | ||
204 | { | ||
205 | if (port >= 0x300 && port < 0x320) | ||
206 | _ne_outw(w, PORT2ADDR_NE(port)); | ||
207 | else | ||
208 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC) | ||
209 | if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
210 | pcc_iowrite(0, port, &w, sizeof(w), 1, 0); | ||
211 | } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) { | ||
212 | pcc_iowrite(1, port, &w, sizeof(w), 1, 0); | ||
213 | } else | ||
214 | #endif | ||
215 | *(volatile unsigned short *)PORT2ADDR(port) = w; | ||
216 | } | ||
217 | |||
218 | void _outl(unsigned long l, unsigned long port) | ||
219 | { | ||
220 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC) | ||
221 | if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
222 | pcc_iowrite(0, port, &l, sizeof(l), 1, 0); | ||
223 | } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) { | ||
224 | pcc_iowrite(1, port, &l, sizeof(l), 1, 0); | ||
225 | } else | ||
226 | #endif | ||
227 | *(volatile unsigned long *)PORT2ADDR(port) = l; | ||
228 | } | ||
229 | |||
230 | void _outb_p(unsigned char b, unsigned long port) | ||
231 | { | ||
232 | if (port >= 0x300 && port < 0x320) | ||
233 | _ne_outb(b, PORT2ADDR_NE(port)); | ||
234 | else | ||
235 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC) | ||
236 | if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
237 | pcc_iowrite(0, port, &b, sizeof(b), 1, 0); | ||
238 | } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) { | ||
239 | pcc_iowrite(1, port, &b, sizeof(b), 1, 0); | ||
240 | } else | ||
241 | #endif | ||
242 | *(volatile unsigned char *)PORT2ADDR(port) = b; | ||
243 | |||
244 | delay(); | ||
245 | } | ||
246 | |||
247 | void _outw_p(unsigned short w, unsigned long port) | ||
248 | { | ||
249 | if (port >= 0x300 && port < 0x320) | ||
250 | _ne_outw(w, PORT2ADDR_NE(port)); | ||
251 | else | ||
252 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC) | ||
253 | if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
254 | pcc_iowrite(0, port, &w, sizeof(w), 1, 0); | ||
255 | } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) { | ||
256 | pcc_iowrite(1, port, &w, sizeof(w), 1, 0); | ||
257 | } else | ||
258 | #endif | ||
259 | *(volatile unsigned short *)PORT2ADDR(port) = w; | ||
260 | |||
261 | delay(); | ||
262 | } | ||
263 | |||
264 | void _outl_p(unsigned long l, unsigned long port) | ||
265 | { | ||
266 | *(volatile unsigned long *)PORT2ADDR(port) = l; | ||
267 | delay(); | ||
268 | } | ||
269 | |||
270 | void _insb(unsigned int port, void *addr, unsigned long count) | ||
271 | { | ||
272 | unsigned short *buf = addr; | ||
273 | unsigned short *portp; | ||
274 | |||
275 | if (port >= 0x300 && port < 0x320){ | ||
276 | portp = PORT2ADDR_NE(port); | ||
277 | while (count--) | ||
278 | *buf++ = *(volatile unsigned char *)portp; | ||
279 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC) | ||
280 | } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
281 | pcc_ioread(0, port, (void *)addr, sizeof(unsigned char), | ||
282 | count, 1); | ||
283 | } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) { | ||
284 | pcc_ioread(1, port, (void *)addr, sizeof(unsigned char), | ||
285 | count, 1); | ||
286 | #endif | ||
287 | } else { | ||
288 | portp = PORT2ADDR(port); | ||
289 | while (count--) | ||
290 | *buf++ = *(volatile unsigned char *)portp; | ||
291 | } | ||
292 | } | ||
293 | |||
294 | void _insw(unsigned int port, void *addr, unsigned long count) | ||
295 | { | ||
296 | unsigned short *buf = addr; | ||
297 | unsigned short *portp; | ||
298 | |||
299 | if (port >= 0x300 && port < 0x320) { | ||
300 | portp = PORT2ADDR_NE(port); | ||
301 | while (count--) | ||
302 | *buf++ = _ne_inw(portp); | ||
303 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC) | ||
304 | } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
305 | pcc_ioread(0, port, (void *)addr, sizeof(unsigned short), | ||
306 | count, 1); | ||
307 | } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) { | ||
308 | pcc_ioread(1, port, (void *)addr, sizeof(unsigned short), | ||
309 | count, 1); | ||
310 | #endif | ||
311 | } else { | ||
312 | portp = PORT2ADDR(port); | ||
313 | while (count--) | ||
314 | *buf++ = *(volatile unsigned short *)portp; | ||
315 | } | ||
316 | } | ||
317 | |||
318 | void _insl(unsigned int port, void *addr, unsigned long count) | ||
319 | { | ||
320 | unsigned long *buf = addr; | ||
321 | unsigned long *portp; | ||
322 | |||
323 | portp = PORT2ADDR(port); | ||
324 | while (count--) | ||
325 | *buf++ = *(volatile unsigned long *)portp; | ||
326 | } | ||
327 | |||
328 | void _outsb(unsigned int port, const void *addr, unsigned long count) | ||
329 | { | ||
330 | const unsigned char *buf = addr; | ||
331 | unsigned char *portp; | ||
332 | |||
333 | if (port >= 0x300 && port < 0x320) { | ||
334 | portp = PORT2ADDR_NE(port); | ||
335 | while (count--) | ||
336 | _ne_outb(*buf++, portp); | ||
337 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC) | ||
338 | } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
339 | pcc_iowrite(0, port, (void *)addr, sizeof(unsigned char), | ||
340 | count, 1); | ||
341 | } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) { | ||
342 | pcc_iowrite(1, port, (void *)addr, sizeof(unsigned char), | ||
343 | count, 1); | ||
344 | #endif | ||
345 | } else { | ||
346 | portp = PORT2ADDR(port); | ||
347 | while (count--) | ||
348 | *(volatile unsigned char *)portp = *buf++; | ||
349 | } | ||
350 | } | ||
351 | |||
352 | void _outsw(unsigned int port, const void *addr, unsigned long count) | ||
353 | { | ||
354 | const unsigned short *buf = addr; | ||
355 | unsigned short *portp; | ||
356 | |||
357 | if (port >= 0x300 && port < 0x320) { | ||
358 | portp = PORT2ADDR_NE(port); | ||
359 | while (count--) | ||
360 | _ne_outw(*buf++, portp); | ||
361 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC) | ||
362 | } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
363 | pcc_iowrite(0, port, (void *)addr, sizeof(unsigned short), | ||
364 | count, 1); | ||
365 | } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) { | ||
366 | pcc_iowrite(1, port, (void *)addr, sizeof(unsigned short), | ||
367 | count, 1); | ||
368 | #endif | ||
369 | } else { | ||
370 | portp = PORT2ADDR(port); | ||
371 | while (count--) | ||
372 | *(volatile unsigned short *)portp = *buf++; | ||
373 | } | ||
374 | } | ||
375 | |||
376 | void _outsl(unsigned int port, const void *addr, unsigned long count) | ||
377 | { | ||
378 | const unsigned long *buf = addr; | ||
379 | unsigned char *portp; | ||
380 | |||
381 | portp = PORT2ADDR(port); | ||
382 | while (count--) | ||
383 | *(volatile unsigned long *)portp = *buf++; | ||
384 | } | ||