2 * linux/arch/m32r/kernel/io_oaks32r.c
4 * Typical I/O routines for OAKS32R board.
6 * Copyright (c) 2001-2004 Hiroyuki Kondo, Hirokazu Takata,
7 * Hitoshi Yamamoto, Mamoru Sakugawa
10 #include <linux/config.h>
15 #define PORT2ADDR(port) _port2addr(port)
17 static inline void *_port2addr(unsigned long port
)
19 return (void *)(port
+ NONCACHE_OFFSET
);
22 static inline void *_port2addr_ne(unsigned long port
)
24 return (void *)((port
<<1) + NONCACHE_OFFSET
+ 0x02000000);
27 static inline void delay(void)
29 __asm__
__volatile__ ("push r0; \n\t pop r0;" : : :"memory");
36 #define PORT2ADDR_NE(port) _port2addr_ne(port)
38 static inline unsigned char _ne_inb(void *portp
)
40 return *(volatile unsigned char *)(portp
+1);
43 static inline unsigned short _ne_inw(void *portp
)
47 tmp
= *(unsigned short *)(portp
) & 0xff;
48 tmp
|= *(unsigned short *)(portp
+2) << 8;
52 static inline void _ne_insb(void *portp
, void *addr
, unsigned long count
)
54 unsigned char *buf
= addr
;
56 *buf
++ = *(volatile unsigned char *)(portp
+1);
59 static inline void _ne_outb(unsigned char b
, void *portp
)
61 *(volatile unsigned char *)(portp
+1) = b
;
64 static inline void _ne_outw(unsigned short w
, void *portp
)
66 *(volatile unsigned short *)portp
= (w
>> 8);
67 *(volatile unsigned short *)(portp
+2) = (w
& 0xff);
70 unsigned char _inb(unsigned long port
)
72 if (port
>= 0x300 && port
< 0x320)
73 return _ne_inb(PORT2ADDR_NE(port
));
75 return *(volatile unsigned char *)PORT2ADDR(port
);
78 unsigned short _inw(unsigned long port
)
80 if (port
>= 0x300 && port
< 0x320)
81 return _ne_inw(PORT2ADDR_NE(port
));
83 return *(volatile unsigned short *)PORT2ADDR(port
);
86 unsigned long _inl(unsigned long port
)
88 return *(volatile unsigned long *)PORT2ADDR(port
);
91 unsigned char _inb_p(unsigned long port
)
95 if (port
>= 0x300 && port
< 0x320)
96 v
= _ne_inb(PORT2ADDR_NE(port
));
98 v
= *(volatile unsigned char *)PORT2ADDR(port
);
104 unsigned short _inw_p(unsigned long port
)
108 if (port
>= 0x300 && port
< 0x320)
109 v
= _ne_inw(PORT2ADDR_NE(port
));
111 v
= *(volatile unsigned short *)PORT2ADDR(port
);
117 unsigned long _inl_p(unsigned long port
)
121 v
= *(volatile unsigned long *)PORT2ADDR(port
);
126 void _outb(unsigned char b
, unsigned long port
)
128 if (port
>= 0x300 && port
< 0x320)
129 _ne_outb(b
, PORT2ADDR_NE(port
));
131 *(volatile unsigned char *)PORT2ADDR(port
) = b
;
134 void _outw(unsigned short w
, unsigned long port
)
136 if (port
>= 0x300 && port
< 0x320)
137 _ne_outw(w
, PORT2ADDR_NE(port
));
139 *(volatile unsigned short *)PORT2ADDR(port
) = w
;
142 void _outl(unsigned long l
, unsigned long port
)
144 *(volatile unsigned long *)PORT2ADDR(port
) = l
;
147 void _outb_p(unsigned char b
, unsigned long port
)
149 if (port
>= 0x300 && port
< 0x320)
150 _ne_outb(b
, PORT2ADDR_NE(port
));
152 *(volatile unsigned char *)PORT2ADDR(port
) = b
;
157 void _outw_p(unsigned short w
, unsigned long port
)
159 if (port
>= 0x300 && port
< 0x320)
160 _ne_outw(w
, PORT2ADDR_NE(port
));
162 *(volatile unsigned short *)PORT2ADDR(port
) = w
;
167 void _outl_p(unsigned long l
, unsigned long port
)
169 *(volatile unsigned long *)PORT2ADDR(port
) = l
;
173 void _insb(unsigned int port
, void *addr
, unsigned long count
)
175 if (port
>= 0x300 && port
< 0x320)
176 _ne_insb(PORT2ADDR_NE(port
), addr
, count
);
178 unsigned char *buf
= addr
;
179 unsigned char *portp
= PORT2ADDR(port
);
181 *buf
++ = *(volatile unsigned char *)portp
;
185 void _insw(unsigned int port
, void *addr
, unsigned long count
)
187 unsigned short *buf
= addr
;
188 unsigned short *portp
;
190 if (port
>= 0x300 && port
< 0x320) {
191 portp
= PORT2ADDR_NE(port
);
193 *buf
++ = _ne_inw(portp
);
195 portp
= PORT2ADDR(port
);
197 *buf
++ = *(volatile unsigned short *)portp
;
201 void _insl(unsigned int port
, void *addr
, unsigned long count
)
203 unsigned long *buf
= addr
;
204 unsigned long *portp
;
206 portp
= PORT2ADDR(port
);
208 *buf
++ = *(volatile unsigned long *)portp
;
211 void _outsb(unsigned int port
, const void *addr
, unsigned long count
)
213 const unsigned char *buf
= addr
;
214 unsigned char *portp
;
216 if (port
>= 0x300 && port
< 0x320) {
217 portp
= PORT2ADDR_NE(port
);
219 _ne_outb(*buf
++, portp
);
221 portp
= PORT2ADDR(port
);
223 *(volatile unsigned char *)portp
= *buf
++;
227 void _outsw(unsigned int port
, const void *addr
, unsigned long count
)
229 const unsigned short *buf
= addr
;
230 unsigned short *portp
;
232 if (port
>= 0x300 && port
< 0x320) {
233 portp
= PORT2ADDR_NE(port
);
235 _ne_outw(*buf
++, portp
);
237 portp
= PORT2ADDR(port
);
239 *(volatile unsigned short *)portp
= *buf
++;
243 void _outsl(unsigned int port
, const void *addr
, unsigned long count
)
245 const unsigned long *buf
= addr
;
246 unsigned char *portp
;
248 portp
= PORT2ADDR(port
);
250 *(volatile unsigned long *)portp
= *buf
++;