2 * linux/arch/m32r/kernel/io_mappi.c
4 * Typical I/O routines for OPSPUT board.
6 * Copyright (c) 2001, 2002 Hiroyuki Kondo, Hirokazu Takata,
7 * Hitoshi Yamamoto, Takeo Takahashi
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.
15 #include <linux/config.h>
19 #include <asm/byteorder.h>
21 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
22 #include <linux/types.h>
24 #define M32R_PCC_IOMAP_SIZE 0x1000
26 #define M32R_PCC_IOSTART0 0x1000
27 #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
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 */
35 #define PORT2ADDR(port) _port2addr(port)
36 #define PORT2ADDR_USB(port) _port2addr_usb(port)
38 static __inline__ void *_port2addr(unsigned long port)
40 return (void *)(port + NONCACHE_OFFSET);
44 * OPSPUT-LAN is located in the extended bus space
45 * from 0x10000000 to 0x13ffffff on physical address.
46 * The base address of LAN controller(LAN91C111) is 0x300.
48 #define LAN_IOSTART 0x300
49 #define LAN_IOEND 0x320
50 static __inline__ void *_port2addr_ne(unsigned long port)
52 return (void *)(port + NONCACHE_OFFSET + 0x10000000);
54 static __inline__ void *_port2addr_usb(unsigned long port)
56 return (void *)((port & 0x0f) + NONCACHE_OFFSET + 0x10303000);
59 static __inline__ void delay(void)
61 __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
68 #define PORT2ADDR_NE(port) _port2addr_ne(port)
70 static __inline__ unsigned char _ne_inb(void *portp)
72 return *(volatile unsigned char *)portp;
75 static __inline__ unsigned short _ne_inw(void *portp)
77 return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp);
80 static __inline__ void _ne_insb(void *portp, void * addr, unsigned long count)
82 unsigned char *buf = (unsigned char *)addr;
84 while (count--) *buf++ = _ne_inb(portp);
87 static __inline__ void _ne_outb(unsigned char b, void *portp)
89 *(volatile unsigned char *)portp = b;
92 static __inline__ void _ne_outw(unsigned short w, void *portp)
94 *(volatile unsigned short *)portp = cpu_to_le16(w);
97 unsigned char _inb(unsigned long port)
99 if (port >= LAN_IOSTART && port < LAN_IOEND)
100 return _ne_inb(PORT2ADDR_NE(port));
102 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
103 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
105 pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
110 return *(volatile unsigned char *)PORT2ADDR(port);
113 unsigned short _inw(unsigned long port)
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);
122 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
123 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
125 pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
129 return *(volatile unsigned short *)PORT2ADDR(port);
132 unsigned long _inl(unsigned long port)
134 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
135 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
137 pcc_ioread_word(0, port, &l, sizeof(l), 1, 0);
141 return *(volatile unsigned long *)PORT2ADDR(port);
144 unsigned char _inb_p(unsigned long port)
148 if (port >= LAN_IOSTART && port < LAN_IOEND)
149 v = _ne_inb(PORT2ADDR_NE(port));
151 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
152 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
154 pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
158 v = *(volatile unsigned char *)PORT2ADDR(port);
164 unsigned short _inw_p(unsigned long port)
168 if (port >= LAN_IOSTART && port < LAN_IOEND)
169 v = _ne_inw(PORT2ADDR_NE(port));
171 #if defined(CONFIG_USB)
172 if(port >= 0x340 && port < 0x3a0)
173 return *(volatile unsigned short *)PORT2ADDR_USB(port);
177 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
178 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
180 pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
184 v = *(volatile unsigned short *)PORT2ADDR(port);
190 unsigned long _inl_p(unsigned long port)
194 v = *(volatile unsigned long *)PORT2ADDR(port);
199 void _outb(unsigned char b, unsigned long port)
201 if (port >= LAN_IOSTART && port < LAN_IOEND)
202 _ne_outb(b, PORT2ADDR_NE(port));
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);
209 *(volatile unsigned char *)PORT2ADDR(port) = b;
212 void _outw(unsigned short w, unsigned long port)
214 if (port >= LAN_IOSTART && port < LAN_IOEND)
215 _ne_outw(w, PORT2ADDR_NE(port));
217 #if defined(CONFIG_USB)
218 if(port >= 0x340 && port < 0x3a0)
219 *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
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);
228 *(volatile unsigned short *)PORT2ADDR(port) = w;
231 void _outl(unsigned long l, unsigned long port)
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);
238 *(volatile unsigned long *)PORT2ADDR(port) = l;
241 void _outb_p(unsigned char b, unsigned long port)
243 if (port >= LAN_IOSTART && port < LAN_IOEND)
244 _ne_outb(b, PORT2ADDR_NE(port));
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);
251 *(volatile unsigned char *)PORT2ADDR(port) = b;
256 void _outw_p(unsigned short w, unsigned long port)
258 if (port >= LAN_IOSTART && port < LAN_IOEND)
259 _ne_outw(w, PORT2ADDR_NE(port));
261 #if defined(CONFIG_USB)
262 if(port >= 0x340 && port < 0x3a0)
263 *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
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);
272 *(volatile unsigned short *)PORT2ADDR(port) = w;
277 void _outl_p(unsigned long l, unsigned long port)
279 *(volatile unsigned long *)PORT2ADDR(port) = l;
283 void _insb(unsigned int port, void * addr, unsigned long count)
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), count, 1);
293 unsigned char *buf = addr;
294 unsigned char *portp = PORT2ADDR(port);
295 while(count--) *buf++ = *(volatile unsigned char *)portp;
299 void _insw(unsigned int port, void * addr, unsigned long count)
301 unsigned short *buf = addr;
302 unsigned short *portp;
304 if (port >= LAN_IOSTART && port < LAN_IOEND) {
306 * This portion is only used by smc91111.c to read data
307 * from the DATA_REG. Do not swap the data.
309 portp = PORT2ADDR_NE(port);
310 while (count--) *buf++ = *(volatile unsigned short *)portp;
311 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
312 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
313 pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short), count, 1);
316 portp = PORT2ADDR(port);
317 while (count--) *buf++ = *(volatile unsigned short *)portp;
321 void _insl(unsigned int port, void * addr, unsigned long count)
323 unsigned long *buf = addr;
324 unsigned long *portp;
326 portp = PORT2ADDR(port);
327 while (count--) *buf++ = *(volatile unsigned long *)portp;
330 void _outsb(unsigned int port, const void * addr, unsigned long count)
332 const unsigned char *buf = addr;
333 unsigned char *portp;
335 if (port >= LAN_IOSTART && port < LAN_IOEND) {
336 portp = PORT2ADDR_NE(port);
337 while (count--) _ne_outb(*buf++, portp);
338 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
339 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
340 pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char), count, 1);
343 portp = PORT2ADDR(port);
344 while(count--) *(volatile unsigned char *)portp = *buf++;
348 void _outsw(unsigned int port, const void * addr, unsigned long count)
350 const unsigned short *buf = addr;
351 unsigned short *portp;
353 if (port >= LAN_IOSTART && port < LAN_IOEND) {
355 * This portion is only used by smc91111.c to write data
356 * into the DATA_REG. Do not swap the data.
358 portp = PORT2ADDR_NE(port);
359 while(count--) *(volatile unsigned short *)portp = *buf++;
360 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
361 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
362 pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short), count, 1);
365 portp = PORT2ADDR(port);
366 while(count--) *(volatile unsigned short *)portp = *buf++;
370 void _outsl(unsigned int port, const void * addr, unsigned long count)
372 const unsigned long *buf = addr;
373 unsigned char *portp;
375 portp = PORT2ADDR(port);
376 while(count--) *(volatile unsigned long *)portp = *buf++;