This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / m32r / kernel / io_m32700ut.c
1 /*
2  *  linux/arch/m32r/kernel/io_mappi.c
3  *
4  *  Typical I/O routines for M32700UT board.
5  *
6  *  Copyright (c) 2001, 2002  Hiroyuki Kondo, Hirokazu Takata,
7  *                            Hitoshi Yamamoto, Takeo Takahashi
8  *
9  *  This file is subject to the terms and conditions of the GNU General
10  *  Public License.  See the file "COPYING" in the main directory of this
11  *  archive for more details.
12  *
13  */
14
15 #include <linux/config.h>
16 #include <asm/m32r.h>
17 #include <asm/page.h>
18 #include <asm/io.h>
19 #include <asm/byteorder.h>
20
21 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
22 #include <linux/types.h>
23
24 #define M32R_PCC_IOMAP_SIZE 0x1000
25
26 #define M32R_PCC_IOSTART0 0x1000
27 #define M32R_PCC_IOEND0   (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
28
29 extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
30 extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
31 extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
32 extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
33 #endif /* CONFIG_PCMCIA && CONFIG_M32R_CFC */
34
35 #define PORT2ADDR(port)  _port2addr(port)
36 #define PORT2ADDR_USB(port) _port2addr_usb(port)
37
38 static __inline__ void *_port2addr(unsigned long port)
39 {
40         return (void *)(port + NONCACHE_OFFSET);
41 }
42
43 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
44 static __inline__ void *__port2addr_ata(unsigned long port)
45 {
46         static int      dummy_reg;
47
48         switch (port) {
49         case 0x1f0:     return (void *)0xac002000;
50         case 0x1f1:     return (void *)0xac012800;
51         case 0x1f2:     return (void *)0xac012002;
52         case 0x1f3:     return (void *)0xac012802;
53         case 0x1f4:     return (void *)0xac012004;
54         case 0x1f5:     return (void *)0xac012804;
55         case 0x1f6:     return (void *)0xac012006;
56         case 0x1f7:     return (void *)0xac012806;
57         case 0x3f6:     return (void *)0xac01200e;
58         default:        return (void *)&dummy_reg;
59         }
60 }
61 #endif
62
63 /*
64  * M32700UT-LAN is located in the extended bus space
65  * from 0x10000000 to 0x13ffffff on physical address.
66  * The base address of LAN controller(LAN91C111) is 0x300.
67  */
68 #define LAN_IOSTART     0x300
69 #define LAN_IOEND       0x320
70 static __inline__ void *_port2addr_ne(unsigned long port)
71 {
72         return (void *)(port + NONCACHE_OFFSET + 0x10000000);
73 }
74 static __inline__ void *_port2addr_usb(unsigned long port)
75 {
76   return (void *)((port & 0x0f) + NONCACHE_OFFSET + 0x10303000);
77 }
78
79 static __inline__ void delay(void)
80 {
81         __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
82 }
83
84 /*
85  * NIC I/O function
86  */
87
88 #define PORT2ADDR_NE(port)  _port2addr_ne(port)
89
90 static __inline__ unsigned char _ne_inb(void *portp)
91 {
92         return *(volatile unsigned char *)portp;
93 }
94
95 static __inline__ unsigned short _ne_inw(void *portp)
96 {
97         return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp);
98 }
99
100 static __inline__ void _ne_insb(void *portp, void * addr, unsigned long count)
101 {
102         unsigned char *buf = (unsigned char *)addr;
103
104         while (count--) *buf++ = _ne_inb(portp);
105 }
106
107 static __inline__ void _ne_outb(unsigned char b, void *portp)
108 {
109         *(volatile unsigned char *)portp = b;
110 }
111
112 static __inline__ void _ne_outw(unsigned short w, void *portp)
113 {
114         *(volatile unsigned short *)portp = cpu_to_le16(w);
115 }
116
117 unsigned char _inb(unsigned long port)
118 {
119         if (port >= LAN_IOSTART && port < LAN_IOEND)
120                 return _ne_inb(PORT2ADDR_NE(port));
121
122 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
123         else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
124                 return *(volatile unsigned char *)__port2addr_ata(port);
125         }
126 #endif
127 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
128         else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
129            unsigned char b;
130            pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
131            return b;
132         } else
133 #endif
134
135         return *(volatile unsigned char *)PORT2ADDR(port);
136 }
137
138 unsigned short _inw(unsigned long port)
139 {
140         if (port >= LAN_IOSTART && port < LAN_IOEND)
141                 return _ne_inw(PORT2ADDR_NE(port));
142 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
143         else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
144                 return *(volatile unsigned short *)__port2addr_ata(port);
145         }
146 #endif
147 #if defined(CONFIG_USB)
148         else if(port >= 0x340 && port < 0x3a0)
149           return *(volatile unsigned short *)PORT2ADDR_USB(port);
150 #endif
151 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
152         else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
153            unsigned short w;
154            pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
155            return w;
156         } else
157 #endif
158         return *(volatile unsigned short *)PORT2ADDR(port);
159 }
160
161 unsigned long _inl(unsigned long port)
162 {
163 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
164         if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
165            unsigned long l;
166            pcc_ioread_word(0, port, &l, sizeof(l), 1, 0);
167            return l;
168         } else
169 #endif
170         return *(volatile unsigned long *)PORT2ADDR(port);
171 }
172
173 unsigned char _inb_p(unsigned long port)
174 {
175         unsigned char  v;
176
177         if (port >= LAN_IOSTART && port < LAN_IOEND)
178                 v = _ne_inb(PORT2ADDR_NE(port));
179         else
180 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
181         if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
182                 return *(volatile unsigned char *)__port2addr_ata(port);
183         } else
184 #endif
185 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
186         if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
187            unsigned char b;
188            pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
189            return b;
190         } else
191 #endif
192                 v = *(volatile unsigned char *)PORT2ADDR(port);
193
194         delay();
195         return (v);
196 }
197
198 unsigned short _inw_p(unsigned long port)
199 {
200         unsigned short  v;
201
202         if (port >= LAN_IOSTART && port < LAN_IOEND)
203                 v = _ne_inw(PORT2ADDR_NE(port));
204         else
205 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
206         if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
207                 return *(volatile unsigned short *)__port2addr_ata(port);
208         } else
209 #endif
210 #if defined(CONFIG_USB)
211           if(port >= 0x340 && port < 0x3a0)
212             return *(volatile unsigned short *)PORT2ADDR_USB(port);
213         else
214 #endif
215 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
216         if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
217            unsigned short w;
218            pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
219            return w;
220         } else
221 #endif
222                 v = *(volatile unsigned short *)PORT2ADDR(port);
223
224         delay();
225         return (v);
226 }
227
228 unsigned long _inl_p(unsigned long port)
229 {
230         unsigned long  v;
231
232         v = *(volatile unsigned long *)PORT2ADDR(port);
233         delay();
234         return (v);
235 }
236
237 void _outb(unsigned char b, unsigned long port)
238 {
239         if (port >= LAN_IOSTART && port < LAN_IOEND)
240                 _ne_outb(b, PORT2ADDR_NE(port));
241         else
242 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
243         if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
244                 *(volatile unsigned char *)__port2addr_ata(port) = b;
245         } else
246 #endif
247 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
248         if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
249            pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
250         } else
251 #endif
252                 *(volatile unsigned char *)PORT2ADDR(port) = b;
253 }
254
255 void _outw(unsigned short w, unsigned long port)
256 {
257         if (port >= LAN_IOSTART && port < LAN_IOEND)
258                 _ne_outw(w, PORT2ADDR_NE(port));
259         else
260 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
261         if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
262                 *(volatile unsigned short *)__port2addr_ata(port) = w;
263         } else
264 #endif
265 #if defined(CONFIG_USB)
266         if(port >= 0x340 && port < 0x3a0)
267           *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
268         else
269 #endif
270 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
271         if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
272            pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
273         } else
274 #endif
275                 *(volatile unsigned short *)PORT2ADDR(port) = w;
276 }
277
278 void _outl(unsigned long l, unsigned long port)
279 {
280 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
281         if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
282            pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
283         } else
284 #endif
285         *(volatile unsigned long *)PORT2ADDR(port) = l;
286 }
287
288 void _outb_p(unsigned char b, unsigned long port)
289 {
290         if (port >= LAN_IOSTART && port < LAN_IOEND)
291                 _ne_outb(b, PORT2ADDR_NE(port));
292         else
293 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
294         if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
295                 *(volatile unsigned char *)__port2addr_ata(port) = b;
296         } else
297 #endif
298 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
299         if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
300            pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
301         } else
302 #endif
303                 *(volatile unsigned char *)PORT2ADDR(port) = b;
304
305         delay();
306 }
307
308 void _outw_p(unsigned short w, unsigned long port)
309 {
310         if (port >= LAN_IOSTART && port < LAN_IOEND)
311                 _ne_outw(w, PORT2ADDR_NE(port));
312         else
313 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
314         if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
315                 *(volatile unsigned short *)__port2addr_ata(port) = w;
316         } else
317 #endif
318 #if defined(CONFIG_USB)
319           if(port >= 0x340 && port < 0x3a0)
320             *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
321         else
322 #endif
323 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
324         if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
325            pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
326         } else
327 #endif
328                 *(volatile unsigned short *)PORT2ADDR(port) = w;
329
330         delay();
331 }
332
333 void _outl_p(unsigned long l, unsigned long port)
334 {
335         *(volatile unsigned long *)PORT2ADDR(port) = l;
336         delay();
337 }
338
339 void _insb(unsigned int port, void * addr, unsigned long count)
340 {
341         if (port >= LAN_IOSTART && port < LAN_IOEND)
342                 _ne_insb(PORT2ADDR_NE(port), addr, count);
343 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
344         else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
345                 unsigned char *buf = addr;
346                 unsigned char *portp = __port2addr_ata(port);
347                 while(count--) *buf++ = *(volatile unsigned char *)portp;
348         }
349 #endif
350 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
351           else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
352            pcc_ioread_byte(0, port, (void *)addr, sizeof(unsigned char), count, 1);
353         }
354 #endif
355         else {
356                 unsigned char *buf = addr;
357                 unsigned char *portp = PORT2ADDR(port);
358                 while(count--) *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                 /*
369                  * This portion is only used by smc91111.c to read data
370                  * from the DATA_REG. Do not swap the data.
371                  */
372                 portp = PORT2ADDR_NE(port);
373                 while (count--) *buf++ = *(volatile unsigned short *)portp;
374 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
375         } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
376            pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short), count, 1);
377 #endif
378 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
379         } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
380                 portp = __port2addr_ata(port);
381                 while (count--) *buf++ = *(volatile unsigned short *)portp;
382 #endif
383         } else {
384                 portp = PORT2ADDR(port);
385                 while (count--) *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--) *buf++ = *(volatile unsigned long *)portp;
396 }
397
398 void _outsb(unsigned int port, const void * addr, unsigned long count)
399 {
400         const unsigned char *buf = addr;
401         unsigned char *portp;
402
403         if (port >= LAN_IOSTART && port < LAN_IOEND) {
404                 portp = PORT2ADDR_NE(port);
405                 while (count--) _ne_outb(*buf++, portp);
406 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
407         } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
408                 portp = __port2addr_ata(port);
409                 while(count--) *(volatile unsigned char *)portp = *buf++;
410 #endif
411 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
412         } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
413            pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char), count, 1);
414 #endif
415         } else {
416                 portp = PORT2ADDR(port);
417                 while(count--) *(volatile unsigned char *)portp = *buf++;
418         }
419 }
420
421 void _outsw(unsigned int port, const void * addr, unsigned long count)
422 {
423         const unsigned short *buf = addr;
424         unsigned short *portp;
425
426         if (port >= LAN_IOSTART && port < LAN_IOEND) {
427                 /*
428                  * This portion is only used by smc91111.c to write data
429                  * into the DATA_REG. Do not swap the data.
430                  */
431                 portp = PORT2ADDR_NE(port);
432                 while(count--) *(volatile unsigned short *)portp = *buf++;
433 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
434         } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
435                 portp = __port2addr_ata(port);
436                 while(count--) *(volatile unsigned short *)portp = *buf++;
437 #endif
438 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
439         } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
440            pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short), count, 1);
441 #endif
442         } else {
443                 portp = PORT2ADDR(port);
444                 while(count--) *(volatile unsigned short *)portp = *buf++;
445         }
446 }
447
448 void _outsl(unsigned int port, const void * addr, unsigned long count)
449 {
450         const unsigned long *buf = addr;
451         unsigned char *portp;
452
453         portp = PORT2ADDR(port);
454         while(count--) *(volatile unsigned long *)portp = *buf++;
455 }