diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/m32r/kernel/io_mappi2.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'arch/m32r/kernel/io_mappi2.c')
-rw-r--r-- | arch/m32r/kernel/io_mappi2.c | 461 |
1 files changed, 461 insertions, 0 deletions
diff --git a/arch/m32r/kernel/io_mappi2.c b/arch/m32r/kernel/io_mappi2.c new file mode 100644 index 000000000000..4182cd4f97c8 --- /dev/null +++ b/arch/m32r/kernel/io_mappi2.c | |||
@@ -0,0 +1,461 @@ | |||
1 | /* | ||
2 | * linux/arch/m32r/kernel/io_mappi2.c | ||
3 | * | ||
4 | * Typical I/O routines for Mappi2 board. | ||
5 | * | ||
6 | * Copyright (c) 2001-2003 Hiroyuki Kondo, Hirokazu Takata, | ||
7 | * Hitoshi Yamamoto, Mamoru Sakugawa | ||
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_CFC) | ||
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 | |||
24 | extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int); | ||
25 | extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int); | ||
26 | extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int); | ||
27 | extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int); | ||
28 | #endif /* CONFIG_PCMCIA && CONFIG_MAPPI2_CFC */ | ||
29 | |||
30 | #define PORT2ADDR(port) _port2addr(port) | ||
31 | #define PORT2ADDR_NE(port) _port2addr_ne(port) | ||
32 | #define PORT2ADDR_USB(port) _port2addr_usb(port) | ||
33 | |||
34 | static inline void *_port2addr(unsigned long port) | ||
35 | { | ||
36 | return (void *)(port + NONCACHE_OFFSET); | ||
37 | } | ||
38 | |||
39 | #define LAN_IOSTART 0x300 | ||
40 | #define LAN_IOEND 0x320 | ||
41 | |||
42 | #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC) | ||
43 | static inline void *__port2addr_ata(unsigned long port) | ||
44 | { | ||
45 | static int dummy_reg; | ||
46 | |||
47 | switch (port) { | ||
48 | case 0x1f0: return (void *)0xac002000; | ||
49 | case 0x1f1: return (void *)0xac012800; | ||
50 | case 0x1f2: return (void *)0xac012002; | ||
51 | case 0x1f3: return (void *)0xac012802; | ||
52 | case 0x1f4: return (void *)0xac012004; | ||
53 | case 0x1f5: return (void *)0xac012804; | ||
54 | case 0x1f6: return (void *)0xac012006; | ||
55 | case 0x1f7: return (void *)0xac012806; | ||
56 | case 0x3f6: return (void *)0xac01200e; | ||
57 | default: return (void *)&dummy_reg; | ||
58 | } | ||
59 | } | ||
60 | #endif | ||
61 | |||
62 | #ifdef CONFIG_CHIP_OPSP | ||
63 | static inline void *_port2addr_ne(unsigned long port) | ||
64 | { | ||
65 | return (void *)(port + NONCACHE_OFFSET + 0x10000000); | ||
66 | } | ||
67 | #else | ||
68 | static inline void *_port2addr_ne(unsigned long port) | ||
69 | { | ||
70 | return (void *)(port + NONCACHE_OFFSET + 0x04000000); | ||
71 | } | ||
72 | #endif | ||
73 | static inline void *_port2addr_usb(unsigned long port) | ||
74 | { | ||
75 | return (void *)(port + NONCACHE_OFFSET + 0x14000000); | ||
76 | } | ||
77 | static inline void delay(void) | ||
78 | { | ||
79 | __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory"); | ||
80 | } | ||
81 | |||
82 | /* | ||
83 | * NIC I/O function | ||
84 | */ | ||
85 | |||
86 | static inline unsigned char _ne_inb(void *portp) | ||
87 | { | ||
88 | return (unsigned char) *(volatile unsigned char *)portp; | ||
89 | } | ||
90 | |||
91 | static inline unsigned short _ne_inw(void *portp) | ||
92 | { | ||
93 | return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp); | ||
94 | } | ||
95 | |||
96 | static inline void _ne_insb(void *portp, void * addr, unsigned long count) | ||
97 | { | ||
98 | unsigned char *buf = addr; | ||
99 | |||
100 | while (count--) | ||
101 | *buf++ = *(volatile unsigned char *)portp; | ||
102 | } | ||
103 | |||
104 | static inline void _ne_outb(unsigned char b, void *portp) | ||
105 | { | ||
106 | *(volatile unsigned char *)portp = (unsigned char)b; | ||
107 | } | ||
108 | |||
109 | static inline void _ne_outw(unsigned short w, void *portp) | ||
110 | { | ||
111 | *(volatile unsigned short *)portp = cpu_to_le16(w); | ||
112 | } | ||
113 | |||
114 | unsigned char _inb(unsigned long port) | ||
115 | { | ||
116 | if (port >= LAN_IOSTART && port < LAN_IOEND) | ||
117 | return _ne_inb(PORT2ADDR_NE(port)); | ||
118 | #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC) | ||
119 | else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) { | ||
120 | return *(volatile unsigned char *)__port2addr_ata(port); | ||
121 | } | ||
122 | #endif | ||
123 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) | ||
124 | else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
125 | unsigned char b; | ||
126 | pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0); | ||
127 | return b; | ||
128 | } else | ||
129 | #endif | ||
130 | |||
131 | return *(volatile unsigned char *)PORT2ADDR(port); | ||
132 | } | ||
133 | |||
134 | unsigned short _inw(unsigned long port) | ||
135 | { | ||
136 | if (port >= LAN_IOSTART && port < LAN_IOEND) | ||
137 | return _ne_inw(PORT2ADDR_NE(port)); | ||
138 | #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC) | ||
139 | else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) { | ||
140 | return *(volatile unsigned short *)__port2addr_ata(port); | ||
141 | } | ||
142 | #endif | ||
143 | #if defined(CONFIG_USB) | ||
144 | else if (port >= 0x340 && port < 0x3a0) | ||
145 | return *(volatile unsigned short *)PORT2ADDR_USB(port); | ||
146 | #endif | ||
147 | |||
148 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) | ||
149 | else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
150 | unsigned short w; | ||
151 | pcc_ioread_word(0, port, &w, sizeof(w), 1, 0); | ||
152 | return w; | ||
153 | } else | ||
154 | #endif | ||
155 | return *(volatile unsigned short *)PORT2ADDR(port); | ||
156 | } | ||
157 | |||
158 | unsigned long _inl(unsigned long port) | ||
159 | { | ||
160 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) | ||
161 | if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
162 | unsigned long l; | ||
163 | pcc_ioread_word(0, port, &l, sizeof(l), 1, 0); | ||
164 | return l; | ||
165 | } else | ||
166 | #endif | ||
167 | return *(volatile unsigned long *)PORT2ADDR(port); | ||
168 | } | ||
169 | |||
170 | unsigned char _inb_p(unsigned long port) | ||
171 | { | ||
172 | unsigned char v; | ||
173 | |||
174 | if (port >= LAN_IOSTART && port < LAN_IOEND) | ||
175 | v = _ne_inb(PORT2ADDR_NE(port)); | ||
176 | else | ||
177 | #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC) | ||
178 | if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) { | ||
179 | return *(volatile unsigned char *)__port2addr_ata(port); | ||
180 | } else | ||
181 | #endif | ||
182 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) | ||
183 | if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
184 | unsigned char b; | ||
185 | pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0); | ||
186 | return b; | ||
187 | } else | ||
188 | #endif | ||
189 | v = *(volatile unsigned char *)PORT2ADDR(port); | ||
190 | |||
191 | delay(); | ||
192 | return (v); | ||
193 | } | ||
194 | |||
195 | unsigned short _inw_p(unsigned long port) | ||
196 | { | ||
197 | unsigned short v; | ||
198 | |||
199 | if (port >= LAN_IOSTART && port < LAN_IOEND) | ||
200 | v = _ne_inw(PORT2ADDR_NE(port)); | ||
201 | else | ||
202 | #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC) | ||
203 | if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) { | ||
204 | return *(volatile unsigned short *)__port2addr_ata(port); | ||
205 | } else | ||
206 | #endif | ||
207 | #if defined(CONFIG_USB) | ||
208 | if (port >= 0x340 && port < 0x3a0) | ||
209 | v = *(volatile unsigned short *)PORT2ADDR_USB(port); | ||
210 | else | ||
211 | #endif | ||
212 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) | ||
213 | if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
214 | unsigned short w; | ||
215 | pcc_ioread_word(0, port, &w, sizeof(w), 1, 0); | ||
216 | return w; | ||
217 | } else | ||
218 | #endif | ||
219 | v = *(volatile unsigned short *)PORT2ADDR(port); | ||
220 | |||
221 | delay(); | ||
222 | return (v); | ||
223 | } | ||
224 | |||
225 | unsigned long _inl_p(unsigned long port) | ||
226 | { | ||
227 | unsigned long v; | ||
228 | |||
229 | v = *(volatile unsigned long *)PORT2ADDR(port); | ||
230 | delay(); | ||
231 | return (v); | ||
232 | } | ||
233 | |||
234 | void _outb(unsigned char b, unsigned long port) | ||
235 | { | ||
236 | if (port >= LAN_IOSTART && port < LAN_IOEND) | ||
237 | _ne_outb(b, PORT2ADDR_NE(port)); | ||
238 | else | ||
239 | #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC) | ||
240 | if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) { | ||
241 | *(volatile unsigned char *)__port2addr_ata(port) = b; | ||
242 | } else | ||
243 | #endif | ||
244 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) | ||
245 | if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
246 | pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0); | ||
247 | } else | ||
248 | #endif | ||
249 | *(volatile unsigned char *)PORT2ADDR(port) = b; | ||
250 | } | ||
251 | |||
252 | void _outw(unsigned short w, unsigned long port) | ||
253 | { | ||
254 | if (port >= LAN_IOSTART && port < LAN_IOEND) | ||
255 | _ne_outw(w, PORT2ADDR_NE(port)); | ||
256 | else | ||
257 | #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC) | ||
258 | if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) { | ||
259 | *(volatile unsigned short *)__port2addr_ata(port) = w; | ||
260 | } else | ||
261 | #endif | ||
262 | #if defined(CONFIG_USB) | ||
263 | if (port >= 0x340 && port < 0x3a0) | ||
264 | *(volatile unsigned short *)PORT2ADDR_USB(port) = w; | ||
265 | else | ||
266 | #endif | ||
267 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) | ||
268 | if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
269 | pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0); | ||
270 | } else | ||
271 | #endif | ||
272 | *(volatile unsigned short *)PORT2ADDR(port) = w; | ||
273 | } | ||
274 | |||
275 | void _outl(unsigned long l, unsigned long port) | ||
276 | { | ||
277 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) | ||
278 | if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
279 | pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0); | ||
280 | } else | ||
281 | #endif | ||
282 | *(volatile unsigned long *)PORT2ADDR(port) = l; | ||
283 | } | ||
284 | |||
285 | void _outb_p(unsigned char b, unsigned long port) | ||
286 | { | ||
287 | if (port >= LAN_IOSTART && port < LAN_IOEND) | ||
288 | _ne_outb(b, PORT2ADDR_NE(port)); | ||
289 | else | ||
290 | #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC) | ||
291 | if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) { | ||
292 | *(volatile unsigned char *)__port2addr_ata(port) = b; | ||
293 | } else | ||
294 | #endif | ||
295 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) | ||
296 | if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
297 | pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0); | ||
298 | } else | ||
299 | #endif | ||
300 | *(volatile unsigned char *)PORT2ADDR(port) = b; | ||
301 | |||
302 | delay(); | ||
303 | } | ||
304 | |||
305 | void _outw_p(unsigned short w, unsigned long port) | ||
306 | { | ||
307 | if (port >= LAN_IOSTART && port < LAN_IOEND) | ||
308 | _ne_outw(w, PORT2ADDR_NE(port)); | ||
309 | else | ||
310 | #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC) | ||
311 | if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) { | ||
312 | *(volatile unsigned short *)__port2addr_ata(port) = w; | ||
313 | } else | ||
314 | #endif | ||
315 | #if defined(CONFIG_USB) | ||
316 | if (port >= 0x340 && port < 0x3a0) | ||
317 | *(volatile unsigned short *)PORT2ADDR_USB(port) = w; | ||
318 | else | ||
319 | #endif | ||
320 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) | ||
321 | if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
322 | pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0); | ||
323 | } else | ||
324 | #endif | ||
325 | *(volatile unsigned short *)PORT2ADDR(port) = w; | ||
326 | |||
327 | delay(); | ||
328 | } | ||
329 | |||
330 | void _outl_p(unsigned long l, unsigned long port) | ||
331 | { | ||
332 | *(volatile unsigned long *)PORT2ADDR(port) = l; | ||
333 | delay(); | ||
334 | } | ||
335 | |||
336 | void _insb(unsigned int port, void * addr, unsigned long count) | ||
337 | { | ||
338 | if (port >= LAN_IOSTART && port < LAN_IOEND) | ||
339 | _ne_insb(PORT2ADDR_NE(port), addr, count); | ||
340 | #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC) | ||
341 | else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) { | ||
342 | unsigned char *buf = addr; | ||
343 | unsigned char *portp = __port2addr_ata(port); | ||
344 | while (count--) | ||
345 | *buf++ = *(volatile unsigned char *)portp; | ||
346 | } | ||
347 | #endif | ||
348 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) | ||
349 | else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
350 | pcc_ioread_byte(0, port, (void *)addr, sizeof(unsigned char), | ||
351 | count, 1); | ||
352 | } | ||
353 | #endif | ||
354 | else { | ||
355 | unsigned char *buf = addr; | ||
356 | unsigned char *portp = PORT2ADDR(port); | ||
357 | while (count--) | ||
358 | *buf++ = *(volatile unsigned char *)portp; | ||
359 | } | ||
360 | } | ||
361 | |||
362 | void _insw(unsigned int port, void * addr, unsigned long count) | ||
363 | { | ||
364 | unsigned short *buf = addr; | ||
365 | unsigned short *portp; | ||
366 | |||
367 | if (port >= LAN_IOSTART && port < LAN_IOEND) { | ||
368 | portp = PORT2ADDR_NE(port); | ||
369 | while (count--) | ||
370 | *buf++ = *(volatile unsigned short *)portp; | ||
371 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) | ||
372 | } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
373 | pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short), | ||
374 | count, 1); | ||
375 | #endif | ||
376 | #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC) | ||
377 | } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) { | ||
378 | portp = __port2addr_ata(port); | ||
379 | while (count--) | ||
380 | *buf++ = *(volatile unsigned short *)portp; | ||
381 | #endif | ||
382 | } else { | ||
383 | portp = PORT2ADDR(port); | ||
384 | while (count--) | ||
385 | *buf++ = *(volatile unsigned short *)portp; | ||
386 | } | ||
387 | } | ||
388 | |||
389 | void _insl(unsigned int port, void * addr, unsigned long count) | ||
390 | { | ||
391 | unsigned long *buf = addr; | ||
392 | unsigned long *portp; | ||
393 | |||
394 | portp = PORT2ADDR(port); | ||
395 | while (count--) | ||
396 | *buf++ = *(volatile unsigned long *)portp; | ||
397 | } | ||
398 | |||
399 | void _outsb(unsigned int port, const void * addr, unsigned long count) | ||
400 | { | ||
401 | const unsigned char *buf = addr; | ||
402 | unsigned char *portp; | ||
403 | |||
404 | if (port >= LAN_IOSTART && port < LAN_IOEND) { | ||
405 | portp = PORT2ADDR_NE(port); | ||
406 | while (count--) | ||
407 | _ne_outb(*buf++, portp); | ||
408 | #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC) | ||
409 | } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) { | ||
410 | portp = __port2addr_ata(port); | ||
411 | while (count--) | ||
412 | *(volatile unsigned char *)portp = *buf++; | ||
413 | #endif | ||
414 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) | ||
415 | } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
416 | pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char), | ||
417 | count, 1); | ||
418 | #endif | ||
419 | } else { | ||
420 | portp = PORT2ADDR(port); | ||
421 | while (count--) | ||
422 | *(volatile unsigned char *)portp = *buf++; | ||
423 | } | ||
424 | } | ||
425 | |||
426 | void _outsw(unsigned int port, const void * addr, unsigned long count) | ||
427 | { | ||
428 | const unsigned short *buf = addr; | ||
429 | unsigned short *portp; | ||
430 | |||
431 | if (port >= LAN_IOSTART && port < LAN_IOEND) { | ||
432 | portp = PORT2ADDR_NE(port); | ||
433 | while (count--) | ||
434 | *(volatile unsigned short *)portp = *buf++; | ||
435 | #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC) | ||
436 | } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) { | ||
437 | portp = __port2addr_ata(port); | ||
438 | while (count--) | ||
439 | *(volatile unsigned short *)portp = *buf++; | ||
440 | #endif | ||
441 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) | ||
442 | } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { | ||
443 | pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short), | ||
444 | count, 1); | ||
445 | #endif | ||
446 | } else { | ||
447 | portp = PORT2ADDR(port); | ||
448 | while (count--) | ||
449 | *(volatile unsigned short *)portp = *buf++; | ||
450 | } | ||
451 | } | ||
452 | |||
453 | void _outsl(unsigned int port, const void * addr, unsigned long count) | ||
454 | { | ||
455 | const unsigned long *buf = addr; | ||
456 | unsigned char *portp; | ||
457 | |||
458 | portp = PORT2ADDR(port); | ||
459 | while (count--) | ||
460 | *(volatile unsigned long *)portp = *buf++; | ||
461 | } | ||