Linux-2.6.12-rc2
[linux-flexiantxendom0-natty.git] / arch / m32r / kernel / io_opsput.c
1 /*
2  *  linux/arch/m32r/kernel/io_mappi.c
3  *
4  *  Typical I/O routines for OPSPUT 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 #include <linux/config.h>
15 #include <asm/m32r.h>
16 #include <asm/page.h>
17 #include <asm/io.h>
18 #include <asm/byteorder.h>
19
20 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
21 #include <linux/types.h>
22
23 #define M32R_PCC_IOMAP_SIZE 0x1000
24
25 #define M32R_PCC_IOSTART0 0x1000
26 #define M32R_PCC_IOEND0   (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
27
28 extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
29 extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
30 extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
31 extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
32 #endif /* CONFIG_PCMCIA && CONFIG_M32R_CFC */
33
34 #define PORT2ADDR(port)  _port2addr(port)
35 #define PORT2ADDR_USB(port) _port2addr_usb(port)
36
37 static inline void *_port2addr(unsigned long port)
38 {
39         return (void *)(port + NONCACHE_OFFSET);
40 }
41
42 /*
43  * OPSPUT-LAN is located in the extended bus space
44  * from 0x10000000 to 0x13ffffff on physical address.
45  * The base address of LAN controller(LAN91C111) is 0x300.
46  */
47 #define LAN_IOSTART     0x300
48 #define LAN_IOEND       0x320
49 static inline void *_port2addr_ne(unsigned long port)
50 {
51         return (void *)(port + NONCACHE_OFFSET + 0x10000000);
52 }
53 static inline void *_port2addr_usb(unsigned long port)
54 {
55         return (void *)((port & 0x0f) + NONCACHE_OFFSET + 0x10303000);
56 }
57
58 static inline void delay(void)
59 {
60         __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
61 }
62
63 /*
64  * NIC I/O function
65  */
66
67 #define PORT2ADDR_NE(port)  _port2addr_ne(port)
68
69 static inline unsigned char _ne_inb(void *portp)
70 {
71         return *(volatile unsigned char *)portp;
72 }
73
74 static inline unsigned short _ne_inw(void *portp)
75 {
76         return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp);
77 }
78
79 static inline void _ne_insb(void *portp, void *addr, unsigned long count)
80 {
81         unsigned char *buf = (unsigned char *)addr;
82
83         while (count--)
84                 *buf++ = _ne_inb(portp);
85 }
86
87 static inline void _ne_outb(unsigned char b, void *portp)
88 {
89         *(volatile unsigned char *)portp = b;
90 }
91
92 static inline void _ne_outw(unsigned short w, void *portp)
93 {
94         *(volatile unsigned short *)portp = cpu_to_le16(w);
95 }
96
97 unsigned char _inb(unsigned long port)
98 {
99         if (port >= LAN_IOSTART && port < LAN_IOEND)
100                 return _ne_inb(PORT2ADDR_NE(port));
101
102 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
103         else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
104                 unsigned char b;
105                 pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
106                 return b;
107         } else
108 #endif
109
110         return *(volatile unsigned char *)PORT2ADDR(port);
111 }
112
113 unsigned short _inw(unsigned long port)
114 {
115         if (port >= LAN_IOSTART && port < LAN_IOEND)
116                 return _ne_inw(PORT2ADDR_NE(port));
117 #if defined(CONFIG_USB)
118         else if(port >= 0x340 && port < 0x3a0)
119                 return *(volatile unsigned short *)PORT2ADDR_USB(port);
120 #endif
121
122 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
123         else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
124                 unsigned short w;
125                 pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
126                 return w;
127         } else
128 #endif
129         return *(volatile unsigned short *)PORT2ADDR(port);
130 }
131
132 unsigned long _inl(unsigned long port)
133 {
134 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
135         if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
136                 unsigned long l;
137                 pcc_ioread_word(0, port, &l, sizeof(l), 1, 0);
138                 return l;
139         } else
140 #endif
141         return *(volatile unsigned long *)PORT2ADDR(port);
142 }
143
144 unsigned char _inb_p(unsigned long port)
145 {
146         unsigned char  v;
147
148         if (port >= LAN_IOSTART && port < LAN_IOEND)
149                 v = _ne_inb(PORT2ADDR_NE(port));
150         else
151 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
152         if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
153                 unsigned char b;
154                 pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
155                 return b;
156         } else
157 #endif
158                 v = *(volatile unsigned char *)PORT2ADDR(port);
159
160         delay();
161         return (v);
162 }
163
164 unsigned short _inw_p(unsigned long port)
165 {
166         unsigned short  v;
167
168         if (port >= LAN_IOSTART && port < LAN_IOEND)
169                 v = _ne_inw(PORT2ADDR_NE(port));
170         else
171 #if defined(CONFIG_USB)
172         if(port >= 0x340 && port < 0x3a0)
173                 return *(volatile unsigned short *)PORT2ADDR_USB(port);
174         else
175 #endif
176
177 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
178         if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
179                 unsigned short w;
180                 pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
181                 return w;
182         } else
183 #endif
184                 v = *(volatile unsigned short *)PORT2ADDR(port);
185
186         delay();
187         return (v);
188 }
189
190 unsigned long _inl_p(unsigned long port)
191 {
192         unsigned long  v;
193
194         v = *(volatile unsigned long *)PORT2ADDR(port);
195         delay();
196         return (v);
197 }
198
199 void _outb(unsigned char b, unsigned long port)
200 {
201         if (port >= LAN_IOSTART && port < LAN_IOEND)
202                 _ne_outb(b, PORT2ADDR_NE(port));
203         else
204 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
205         if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
206                 pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
207         } else
208 #endif
209                 *(volatile unsigned char *)PORT2ADDR(port) = b;
210 }
211
212 void _outw(unsigned short w, unsigned long port)
213 {
214         if (port >= LAN_IOSTART && port < LAN_IOEND)
215                 _ne_outw(w, PORT2ADDR_NE(port));
216         else
217 #if defined(CONFIG_USB)
218         if(port >= 0x340 && port < 0x3a0)
219                 *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
220         else
221 #endif
222
223 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
224         if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
225                 pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
226         } else
227 #endif
228                 *(volatile unsigned short *)PORT2ADDR(port) = w;
229 }
230
231 void _outl(unsigned long l, unsigned long port)
232 {
233 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
234         if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
235                 pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
236         } else
237 #endif
238         *(volatile unsigned long *)PORT2ADDR(port) = l;
239 }
240
241 void _outb_p(unsigned char b, unsigned long port)
242 {
243         if (port >= LAN_IOSTART && port < LAN_IOEND)
244                 _ne_outb(b, PORT2ADDR_NE(port));
245         else
246 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
247         if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
248                 pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
249         } else
250 #endif
251                 *(volatile unsigned char *)PORT2ADDR(port) = b;
252
253         delay();
254 }
255
256 void _outw_p(unsigned short w, unsigned long port)
257 {
258         if (port >= LAN_IOSTART && port < LAN_IOEND)
259                 _ne_outw(w, PORT2ADDR_NE(port));
260         else
261 #if defined(CONFIG_USB)
262         if(port >= 0x340 && port < 0x3a0)
263                 *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
264         else
265 #endif
266
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         delay();
275 }
276
277 void _outl_p(unsigned long l, unsigned long port)
278 {
279         *(volatile unsigned long *)PORT2ADDR(port) = l;
280         delay();
281 }
282
283 void _insb(unsigned int port, void *addr, unsigned long count)
284 {
285         if (port >= LAN_IOSTART && port < LAN_IOEND)
286                 _ne_insb(PORT2ADDR_NE(port), addr, count);
287 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
288         else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
289                 pcc_ioread_byte(0, port, (void *)addr, sizeof(unsigned char),
290                                 count, 1);
291         }
292 #endif
293         else {
294                 unsigned char *buf = addr;
295                 unsigned char *portp = PORT2ADDR(port);
296                 while (count--)
297                         *buf++ = *(volatile unsigned char *)portp;
298         }
299 }
300
301 void _insw(unsigned int port, void *addr, unsigned long count)
302 {
303         unsigned short *buf = addr;
304         unsigned short *portp;
305
306         if (port >= LAN_IOSTART && port < LAN_IOEND) {
307                 /*
308                  * This portion is only used by smc91111.c to read data
309                  * from the DATA_REG. Do not swap the data.
310                  */
311                 portp = PORT2ADDR_NE(port);
312                 while (count--)
313                         *buf++ = *(volatile unsigned short *)portp;
314 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
315         } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
316                 pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short),
317                                 count, 1);
318 #endif
319         } else {
320                 portp = PORT2ADDR(port);
321                 while (count--)
322                         *buf++ = *(volatile unsigned short *)portp;
323         }
324 }
325
326 void _insl(unsigned int port, void *addr, unsigned long count)
327 {
328         unsigned long *buf = addr;
329         unsigned long *portp;
330
331         portp = PORT2ADDR(port);
332         while (count--)
333                 *buf++ = *(volatile unsigned long *)portp;
334 }
335
336 void _outsb(unsigned int port, const void *addr, unsigned long count)
337 {
338         const unsigned char *buf = addr;
339         unsigned char *portp;
340
341         if (port >= LAN_IOSTART && port < LAN_IOEND) {
342                 portp = PORT2ADDR_NE(port);
343                 while (count--)
344                         _ne_outb(*buf++, portp);
345 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
346         } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
347                 pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char),
348                                  count, 1);
349 #endif
350         } else {
351                 portp = PORT2ADDR(port);
352                 while (count--)
353                         *(volatile unsigned char *)portp = *buf++;
354         }
355 }
356
357 void _outsw(unsigned int port, const void *addr, unsigned long count)
358 {
359         const unsigned short *buf = addr;
360         unsigned short *portp;
361
362         if (port >= LAN_IOSTART && port < LAN_IOEND) {
363                 /*
364                  * This portion is only used by smc91111.c to write data
365                  * into the DATA_REG. Do not swap the data.
366                  */
367                 portp = PORT2ADDR_NE(port);
368                 while (count--)
369                         *(volatile unsigned short *)portp = *buf++;
370 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
371         } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
372                 pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short),
373                                  count, 1);
374 #endif
375         } else {
376                 portp = PORT2ADDR(port);
377                 while (count--)
378                         *(volatile unsigned short *)portp = *buf++;
379         }
380 }
381
382 void _outsl(unsigned int port, const void *addr, unsigned long count)
383 {
384         const unsigned long *buf = addr;
385         unsigned char *portp;
386
387         portp = PORT2ADDR(port);
388         while (count--)
389                 *(volatile unsigned long *)portp = *buf++;
390 }