This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / m32r / kernel / io_mappi.c
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 /* $Id: io_mappi.c,v 1.9 2003/12/02 07:18:08 fujiwara Exp $ */
11
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>
17
18 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
19 #include <linux/types.h>
20
21 #define M32R_PCC_IOMAP_SIZE 0x1000
22
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)
27
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 */
31
32 #define PORT2ADDR(port)  _port2addr(port)
33
34 static __inline__ void *_port2addr(unsigned long port)
35 {
36         return (void *)(port + NONCACHE_OFFSET);
37 }
38
39 static __inline__ void *_port2addr_ne(unsigned long port)
40 {
41         return (void *)((port<<1) + NONCACHE_OFFSET + 0x0C000000);
42 }
43
44 static __inline__ void delay(void)
45 {
46         __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
47 }
48
49 /*
50  * NIC I/O function
51  */
52
53 #define PORT2ADDR_NE(port)  _port2addr_ne(port)
54
55 static __inline__ unsigned char _ne_inb(void *portp)
56 {
57         return (unsigned char) *(volatile unsigned short *)portp;
58 }
59
60 static __inline__ unsigned short _ne_inw(void *portp)
61 {
62         unsigned short tmp;
63
64         tmp = *(volatile unsigned short *)portp;
65         return le16_to_cpu(tmp);
66 }
67
68 static __inline__ void _ne_outb(unsigned char b, void *portp)
69 {
70         *(volatile unsigned short *)portp = (unsigned short)b;
71 }
72
73 static __inline__ void _ne_outw(unsigned short w, void *portp)
74 {
75         *(volatile unsigned short *)portp = cpu_to_le16(w);
76 }
77
78 unsigned char _inb(unsigned long port)
79 {
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
94
95         return *(volatile unsigned char *)PORT2ADDR(port);
96 }
97
98 unsigned short _inw(unsigned long port)
99 {
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);
115 }
116
117 unsigned long _inl(unsigned long port)
118 {
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);
131 }
132
133 unsigned char _inb_p(unsigned long port)
134 {
135         unsigned char  v;
136
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);
152
153         delay();
154         return (v);
155 }
156
157 unsigned short _inw_p(unsigned long port)
158 {
159         unsigned short  v;
160
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);
176
177         delay();
178         return (v);
179 }
180
181 unsigned long _inl_p(unsigned long port)
182 {
183         unsigned long  v;
184
185         v = *(volatile unsigned long *)PORT2ADDR(port);
186         delay();
187         return (v);
188 }
189
190 void _outb(unsigned char b, unsigned long port)
191 {
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;
203 }
204
205 void _outw(unsigned short w, unsigned long port)
206 {
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;
218 }
219
220 void _outl(unsigned long l, unsigned long port)
221 {
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;
230 }
231
232 void _outb_p(unsigned char b, unsigned long port)
233 {
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;
245
246         delay();
247 }
248
249 void _outw_p(unsigned short w, unsigned long port)
250 {
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;
262
263         delay();
264 }
265
266 void _outl_p(unsigned long l, unsigned long port)
267 {
268         *(volatile unsigned long *)PORT2ADDR(port) = l;
269         delay();
270 }
271
272 void _insb(unsigned int port, void * addr, unsigned long count)
273 {
274         unsigned short *buf = addr;
275         unsigned short *portp;
276
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;
289         }
290 }
291
292 void _insw(unsigned int port, void * addr, unsigned long count)
293 {
294         unsigned short *buf = addr;
295         unsigned short *portp;
296
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;
309         }
310 }
311
312 void _insl(unsigned int port, void * addr, unsigned long count)
313 {
314         unsigned long *buf = addr;
315         unsigned long *portp;
316
317         portp = PORT2ADDR(port);
318         while (count--) *buf++ = *(volatile unsigned long *)portp;
319 }
320
321 void _outsb(unsigned int port, const void * addr, unsigned long count)
322 {
323         const unsigned char *buf = addr;
324         unsigned char *portp;
325
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++;
338         }
339 }
340
341 void _outsw(unsigned int port, const void * addr, unsigned long count)
342 {
343         const unsigned short *buf = addr;
344         unsigned short *portp;
345
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++;
358         }
359 }
360
361 void _outsl(unsigned int port, const void * addr, unsigned long count)
362 {
363         const unsigned long *buf = addr;
364         unsigned char *portp;
365
366         portp = PORT2ADDR(port);
367         while(count--) *(volatile unsigned long *)portp = *buf++;
368 }