initial commit with v2.6.9
[linux-2.6.9-moxart.git] / arch / m32r / kernel / io_mappi.c
blob74aeca6362399efc62a168e342d4a1023d1dfde8
1 /*
2 * linux/arch/m32r/kernel/io_mappi.c
4 * Typical I/O routines for Mappi board.
6 * Copyright (c) 2001, 2002 Hiroyuki Kondo, Hirokazu Takata,
7 * Hitoshi Yamamoto
8 */
10 /* $Id: io_mappi.c,v 1.9 2003/12/02 07:18:08 fujiwara Exp $ */
12 #include <linux/config.h>
13 #include <asm/m32r.h>
14 #include <asm/page.h>
15 #include <asm/io.h>
16 #include <asm/byteorder.h>
18 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
19 #include <linux/types.h>
21 #define M32R_PCC_IOMAP_SIZE 0x1000
23 #define M32R_PCC_IOSTART0 0x1000
24 #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
25 #define M32R_PCC_IOSTART1 0x2000
26 #define M32R_PCC_IOEND1 (M32R_PCC_IOSTART1 + M32R_PCC_IOMAP_SIZE - 1)
28 extern void pcc_ioread(int, unsigned long, void *, size_t, size_t, int);
29 extern void pcc_iowrite(int, unsigned long, void *, size_t, size_t, int);
30 #endif /* CONFIG_PCMCIA && CONFIG_M32RPCC */
32 #define PORT2ADDR(port) _port2addr(port)
34 static __inline__ void *_port2addr(unsigned long port)
36 return (void *)(port + NONCACHE_OFFSET);
39 static __inline__ void *_port2addr_ne(unsigned long port)
41 return (void *)((port<<1) + NONCACHE_OFFSET + 0x0C000000);
44 static __inline__ void delay(void)
46 __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
50 * NIC I/O function
53 #define PORT2ADDR_NE(port) _port2addr_ne(port)
55 static __inline__ unsigned char _ne_inb(void *portp)
57 return (unsigned char) *(volatile unsigned short *)portp;
60 static __inline__ unsigned short _ne_inw(void *portp)
62 unsigned short tmp;
64 tmp = *(volatile unsigned short *)portp;
65 return le16_to_cpu(tmp);
68 static __inline__ void _ne_outb(unsigned char b, void *portp)
70 *(volatile unsigned short *)portp = (unsigned short)b;
73 static __inline__ void _ne_outw(unsigned short w, void *portp)
75 *(volatile unsigned short *)portp = cpu_to_le16(w);
78 unsigned char _inb(unsigned long port)
80 if (port >= 0x300 && port < 0x320)
81 return _ne_inb(PORT2ADDR_NE(port));
82 else
83 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
84 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
85 unsigned char b;
86 pcc_ioread(0, port, &b, sizeof(b), 1, 0);
87 return b;
88 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
89 unsigned char b;
90 pcc_ioread(1, port, &b, sizeof(b), 1, 0);
91 return b;
92 } else
93 #endif
95 return *(volatile unsigned char *)PORT2ADDR(port);
98 unsigned short _inw(unsigned long port)
100 if (port >= 0x300 && port < 0x320)
101 return _ne_inw(PORT2ADDR_NE(port));
102 else
103 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
104 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
105 unsigned short w;
106 pcc_ioread(0, port, &w, sizeof(w), 1, 0);
107 return w;
108 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
109 unsigned short w;
110 pcc_ioread(1, port, &w, sizeof(w), 1, 0);
111 return w;
112 } else
113 #endif
114 return *(volatile unsigned short *)PORT2ADDR(port);
117 unsigned long _inl(unsigned long port)
119 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
120 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
121 unsigned long l;
122 pcc_ioread(0, port, &l, sizeof(l), 1, 0);
123 return l;
124 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
125 unsigned short l;
126 pcc_ioread(1, port, &l, sizeof(l), 1, 0);
127 return l;
128 } else
129 #endif
130 return *(volatile unsigned long *)PORT2ADDR(port);
133 unsigned char _inb_p(unsigned long port)
135 unsigned char v;
137 if (port >= 0x300 && port < 0x320)
138 v = _ne_inb(PORT2ADDR_NE(port));
139 else
140 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
141 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
142 unsigned char b;
143 pcc_ioread(0, port, &b, sizeof(b), 1, 0);
144 return b;
145 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
146 unsigned char b;
147 pcc_ioread(1, port, &b, sizeof(b), 1, 0);
148 return b;
149 } else
150 #endif
151 v = *(volatile unsigned char *)PORT2ADDR(port);
153 delay();
154 return (v);
157 unsigned short _inw_p(unsigned long port)
159 unsigned short v;
161 if (port >= 0x300 && port < 0x320)
162 v = _ne_inw(PORT2ADDR_NE(port));
163 else
164 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
165 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
166 unsigned short w;
167 pcc_ioread(0, port, &w, sizeof(w), 1, 0);
168 return w;
169 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
170 unsigned short w;
171 pcc_ioread(1, port, &w, sizeof(w), 1, 0);
172 return w;
173 } else
174 #endif
175 v = *(volatile unsigned short *)PORT2ADDR(port);
177 delay();
178 return (v);
181 unsigned long _inl_p(unsigned long port)
183 unsigned long v;
185 v = *(volatile unsigned long *)PORT2ADDR(port);
186 delay();
187 return (v);
190 void _outb(unsigned char b, unsigned long port)
192 if (port >= 0x300 && port < 0x320)
193 _ne_outb(b, PORT2ADDR_NE(port));
194 else
195 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
196 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
197 pcc_iowrite(0, port, &b, sizeof(b), 1, 0);
198 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
199 pcc_iowrite(1, port, &b, sizeof(b), 1, 0);
200 } else
201 #endif
202 *(volatile unsigned char *)PORT2ADDR(port) = b;
205 void _outw(unsigned short w, unsigned long port)
207 if (port >= 0x300 && port < 0x320)
208 _ne_outw(w, PORT2ADDR_NE(port));
209 else
210 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
211 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
212 pcc_iowrite(0, port, &w, sizeof(w), 1, 0);
213 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
214 pcc_iowrite(1, port, &w, sizeof(w), 1, 0);
215 } else
216 #endif
217 *(volatile unsigned short *)PORT2ADDR(port) = w;
220 void _outl(unsigned long l, unsigned long port)
222 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
223 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
224 pcc_iowrite(0, port, &l, sizeof(l), 1, 0);
225 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
226 pcc_iowrite(1, port, &l, sizeof(l), 1, 0);
227 } else
228 #endif
229 *(volatile unsigned long *)PORT2ADDR(port) = l;
232 void _outb_p(unsigned char b, unsigned long port)
234 if (port >= 0x300 && port < 0x320)
235 _ne_outb(b, PORT2ADDR_NE(port));
236 else
237 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
238 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
239 pcc_iowrite(0, port, &b, sizeof(b), 1, 0);
240 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
241 pcc_iowrite(1, port, &b, sizeof(b), 1, 0);
242 } else
243 #endif
244 *(volatile unsigned char *)PORT2ADDR(port) = b;
246 delay();
249 void _outw_p(unsigned short w, unsigned long port)
251 if (port >= 0x300 && port < 0x320)
252 _ne_outw(w, PORT2ADDR_NE(port));
253 else
254 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
255 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
256 pcc_iowrite(0, port, &w, sizeof(w), 1, 0);
257 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
258 pcc_iowrite(1, port, &w, sizeof(w), 1, 0);
259 } else
260 #endif
261 *(volatile unsigned short *)PORT2ADDR(port) = w;
263 delay();
266 void _outl_p(unsigned long l, unsigned long port)
268 *(volatile unsigned long *)PORT2ADDR(port) = l;
269 delay();
272 void _insb(unsigned int port, void * addr, unsigned long count)
274 unsigned short *buf = addr;
275 unsigned short *portp;
277 if (port >= 0x300 && port < 0x320){
278 portp = PORT2ADDR_NE(port);
279 while(count--) *buf++ = *(volatile unsigned char *)portp;
280 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
281 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
282 pcc_ioread(0, port, (void *)addr, sizeof(unsigned char), count, 1);
283 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
284 pcc_ioread(1, port, (void *)addr, sizeof(unsigned char), count, 1);
285 #endif
286 } else {
287 portp = PORT2ADDR(port);
288 while(count--) *buf++ = *(volatile unsigned char *)portp;
292 void _insw(unsigned int port, void * addr, unsigned long count)
294 unsigned short *buf = addr;
295 unsigned short *portp;
297 if (port >= 0x300 && port < 0x320) {
298 portp = PORT2ADDR_NE(port);
299 while (count--) *buf++ = _ne_inw(portp);
300 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
301 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
302 pcc_ioread(0, port, (void *)addr, sizeof(unsigned short), count, 1);
303 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
304 pcc_ioread(1, port, (void *)addr, sizeof(unsigned short), count, 1);
305 #endif
306 } else {
307 portp = PORT2ADDR(port);
308 while (count--) *buf++ = *(volatile unsigned short *)portp;
312 void _insl(unsigned int port, void * addr, unsigned long count)
314 unsigned long *buf = addr;
315 unsigned long *portp;
317 portp = PORT2ADDR(port);
318 while (count--) *buf++ = *(volatile unsigned long *)portp;
321 void _outsb(unsigned int port, const void * addr, unsigned long count)
323 const unsigned char *buf = addr;
324 unsigned char *portp;
326 if (port >= 0x300 && port < 0x320) {
327 portp = PORT2ADDR_NE(port);
328 while (count--) _ne_outb(*buf++, portp);
329 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
330 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
331 pcc_iowrite(0, port, (void *)addr, sizeof(unsigned char), count, 1);
332 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
333 pcc_iowrite(1, port, (void *)addr, sizeof(unsigned char), count, 1);
334 #endif
335 } else {
336 portp = PORT2ADDR(port);
337 while(count--) *(volatile unsigned char *)portp = *buf++;
341 void _outsw(unsigned int port, const void * addr, unsigned long count)
343 const unsigned short *buf = addr;
344 unsigned short *portp;
346 if (port >= 0x300 && port < 0x320) {
347 portp = PORT2ADDR_NE(port);
348 while (count--) _ne_outw(*buf++, portp);
349 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
350 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
351 pcc_iowrite(0, port, (void *)addr, sizeof(unsigned short), count, 1);
352 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
353 pcc_iowrite(1, port, (void *)addr, sizeof(unsigned short), count, 1);
354 #endif
355 } else {
356 portp = PORT2ADDR(port);
357 while(count--) *(volatile unsigned short *)portp = *buf++;
361 void _outsl(unsigned int port, const void * addr, unsigned long count)
363 const unsigned long *buf = addr;
364 unsigned char *portp;
366 portp = PORT2ADDR(port);
367 while(count--) *(volatile unsigned long *)portp = *buf++;