MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / arch / m32r / kernel / io_mappi2.c
blob7705fb0bb9a04eff7ce156998ca86f4489564a6e
1 /*
2 * linux/arch/m32r/kernel/io_mappi2.c
4 * Typical I/O routines for Mappi2 board.
6 * Copyright (c) 2001-2003 Hiroyuki Kondo, Hirokazu Takata,
7 * Hitoshi Yamamoto, Mamoru Sakugawa
8 */
10 /* $Id:$ */
12 #include <linux/config.h>
13 #include <asm/m32r.h>
14 #include <asm/page.h>
15 #include <asm/io.h>
17 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
18 #include <linux/types.h>
20 #define M32R_PCC_IOMAP_SIZE 0x1000
22 #define M32R_PCC_IOSTART0 0x1000
23 #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
25 extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
26 extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
27 extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
28 extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
29 #endif /* CONFIG_PCMCIA && CONFIG_MAPPI2_CFC */
31 #define PORT2ADDR(port) _port2addr(port)
32 #define PORT2ADDR_NE(port) _port2addr_ne(port)
33 #define PORT2ADDR_USB(port) _port2addr_usb(port)
35 static __inline__ void *_port2addr(unsigned long port)
37 return (void *)(port + NONCACHE_OFFSET);
40 #define LAN_IOSTART 0x300
41 #define LAN_IOEND 0x320
42 #ifdef CONFIG_CHIP_OPSP
43 static __inline__ void *_port2addr_ne(unsigned long port)
45 return (void *)(port + NONCACHE_OFFSET + 0x10000000);
47 #else
48 static __inline__ void *_port2addr_ne(unsigned long port)
50 return (void *)(port + NONCACHE_OFFSET + 0x04000000);
52 #endif
53 static __inline__ void *_port2addr_usb(unsigned long port)
55 return (void *)(port + NONCACHE_OFFSET + 0x14000000);
57 static __inline__ void delay(void)
59 __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
63 * NIC I/O function
66 static __inline__ unsigned char _ne_inb(void *portp)
68 return (unsigned char) *(volatile unsigned char *)portp;
71 static __inline__ unsigned short _ne_inw(void *portp)
73 #if 1 /* byte swap */
74 unsigned short tmp,tmp2;
75 tmp = *(volatile unsigned short *)portp;
76 tmp2 = (tmp>>8|tmp<<8);
77 return tmp2;
78 #else
79 return *(volatile unsigned short *)portp;
80 #endif
83 static __inline__ void _ne_insb(void *portp, void * addr, unsigned long count)
85 unsigned short tmp;
86 unsigned char *buf = addr;
88 tmp = *(volatile unsigned char *)portp;
89 while (count--) *buf++ = *(volatile unsigned char *)portp;
92 static __inline__ void _ne_outb(unsigned char b, void *portp)
94 *(volatile unsigned char *)portp = (unsigned char)b;
97 static __inline__ void _ne_outw(unsigned short w, void *portp)
99 *(volatile unsigned short *)portp = (w>>8|w<<8);
102 unsigned char _inb(unsigned long port)
104 if (port >= LAN_IOSTART && port < LAN_IOEND)
105 return _ne_inb(PORT2ADDR_NE(port));
106 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
107 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
108 unsigned char b;
109 pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
110 return b;
111 } else
112 #endif
114 return *(volatile unsigned char *)PORT2ADDR(port);
117 unsigned short _inw(unsigned long port)
119 if (port >= LAN_IOSTART && port < LAN_IOEND)
120 return _ne_inw(PORT2ADDR_NE(port));
121 #if defined(CONFIG_USB)
122 else if (port >= 0x340 && port < 0x3a0)
123 return *(volatile unsigned short *)PORT2ADDR_USB(port);
124 #endif
126 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
127 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
128 unsigned short w;
129 pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
130 return w;
131 } else
132 #endif
133 return *(volatile unsigned short *)PORT2ADDR(port);
136 unsigned long _inl(unsigned long port)
138 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
139 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
140 unsigned long l;
141 pcc_ioread_word(0, port, &l, sizeof(l), 1, 0);
142 return l;
143 } else
144 #endif
145 return *(volatile unsigned long *)PORT2ADDR(port);
148 unsigned char _inb_p(unsigned long port)
150 unsigned char v;
152 if (port >= 0x300 && port < 0x320)
153 v = _ne_inb(PORT2ADDR_NE(port));
154 else
155 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
156 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
157 unsigned char b;
158 pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
159 return b;
160 } else
161 #endif
162 v = *(volatile unsigned char *)PORT2ADDR(port);
164 delay();
165 return (v);
168 unsigned short _inw_p(unsigned long port)
170 unsigned short v;
172 if (port >= 0x300 && port < 0x320)
173 v = _ne_inw(PORT2ADDR_NE(port));
174 else
175 #if defined(CONFIG_USB)
176 if (port >= 0x340 && port < 0x3a0)
177 v = *(volatile unsigned short *)PORT2ADDR_USB(port);
178 else
179 #endif
180 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
181 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
182 unsigned short w;
183 pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
184 return w;
185 } else
186 #endif
187 v = *(volatile unsigned short *)PORT2ADDR(port);
189 delay();
190 return (v);
193 unsigned long _inl_p(unsigned long port)
195 unsigned long v;
197 v = *(volatile unsigned long *)PORT2ADDR(port);
198 delay();
199 return (v);
202 void _outb(unsigned char b, unsigned long port)
204 if (port >= LAN_IOSTART && port < LAN_IOEND)
205 _ne_outb(b, PORT2ADDR_NE(port));
206 else
207 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
208 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
209 pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
210 } else
211 #endif
212 *(volatile unsigned char *)PORT2ADDR(port) = b;
215 void _outw(unsigned short w, unsigned long port)
217 if (port >= LAN_IOSTART && port < LAN_IOEND)
218 _ne_outw(w, PORT2ADDR_NE(port));
219 else
220 #if defined(CONFIG_USB)
221 if (port >= 0x340 && port < 0x3a0)
222 *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
223 else
224 #endif
225 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
226 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
227 pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
228 } else
229 #endif
230 *(volatile unsigned short *)PORT2ADDR(port) = w;
233 void _outl(unsigned long l, unsigned long port)
235 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
236 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
237 pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
238 } else
239 #endif
240 *(volatile unsigned long *)PORT2ADDR(port) = l;
243 void _outb_p(unsigned char b, unsigned long port)
245 if (port >= LAN_IOSTART && port < LAN_IOEND)
246 _ne_outb(b, PORT2ADDR_NE(port));
247 else
248 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
249 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
250 pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
251 } else
252 #endif
253 *(volatile unsigned char *)PORT2ADDR(port) = b;
255 delay();
258 void _outw_p(unsigned short w, unsigned long port)
260 if (port >= LAN_IOSTART && port < LAN_IOEND)
261 _ne_outw(w, PORT2ADDR_NE(port));
262 else
263 #if defined(CONFIG_USB)
264 if (port >= 0x340 && port < 0x3a0)
265 *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
266 else
267 #endif
268 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
269 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
270 pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
271 } else
272 #endif
273 *(volatile unsigned short *)PORT2ADDR(port) = w;
275 delay();
278 void _outl_p(unsigned long l, unsigned long port)
280 *(volatile unsigned long *)PORT2ADDR(port) = l;
281 delay();
284 void _insb(unsigned int port, void * addr, unsigned long count)
286 if (port >= LAN_IOSTART && port < LAN_IOEND)
287 _ne_insb(PORT2ADDR_NE(port), addr, count);
288 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
289 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
290 pcc_ioread_byte(0, port, (void *)addr, sizeof(unsigned char), count, 1);
292 #endif
293 else {
294 unsigned char *buf = addr;
295 unsigned char *portp = PORT2ADDR(port);
296 while(count--) *buf++ = *(volatile unsigned char *)portp;
300 void _insw(unsigned int port, void * addr, unsigned long count)
302 unsigned short *buf = addr;
303 unsigned short *portp;
305 if (port >= LAN_IOSTART && port < LAN_IOEND)
306 portp = PORT2ADDR_NE(port);
307 while (count--) *buf++ = *(volatile unsigned short *)portp;
308 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
309 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
310 pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short), count, 1);
311 #endif
312 } else {
313 portp = PORT2ADDR(port);
314 while (count--) *buf++ = *(volatile unsigned short *)portp;
318 void _insl(unsigned int port, void * addr, unsigned long count)
320 unsigned long *buf = addr;
321 unsigned long *portp;
323 portp = PORT2ADDR(port);
324 while (count--) *buf++ = *(volatile unsigned long *)portp;
327 void _outsb(unsigned int port, const void * addr, unsigned long count)
329 const unsigned char *buf = addr;
330 unsigned char *portp;
332 if (port >= LAN_IOSTART && port < LAN_IOEND)
333 portp = PORT2ADDR_NE(port);
334 while (count--) _ne_outb(*buf++, portp);
335 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
336 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
337 pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char), count, 1);
338 #endif
339 } else {
340 portp = PORT2ADDR(port);
341 while(count--) *(volatile unsigned char *)portp = *buf++;
345 void _outsw(unsigned int port, const void * addr, unsigned long count)
347 const unsigned short *buf = addr;
348 unsigned short *portp;
350 if (port >= LAN_IOSTART && port < LAN_IOEND)
351 portp = PORT2ADDR_NE(port);
352 while (count--) *(volatile unsigned short *)portp = *buf++;
353 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
354 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
355 pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short), count, 1);
356 #endif
357 } else {
358 portp = PORT2ADDR(port);
359 while(count--) *(volatile unsigned short *)portp = *buf++;
363 void _outsl(unsigned int port, const void * addr, unsigned long count)
365 const unsigned long *buf = addr;
366 unsigned char *portp;
368 portp = PORT2ADDR(port);
369 while(count--) *(volatile unsigned long *)portp = *buf++;