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
12 #include <linux/config.h>
17 #define PORT2ADDR(port) _port2addr(port)
19 static __inline__
void *_port2addr(unsigned long port
)
21 return (void *)(port
+ NONCACHE_OFFSET
);
24 static __inline__
void *_port2addr_ne(unsigned long port
)
26 return (void *)((port
<<1) + NONCACHE_OFFSET
+ 0x02000000);
29 static __inline__
void delay(void)
31 __asm__
__volatile__ ("push r0; \n\t pop r0;" : : :"memory");
38 #define PORT2ADDR_NE(port) _port2addr_ne(port)
40 static __inline__
unsigned char _ne_inb(void *portp
)
42 return *(volatile unsigned char *)(portp
+1);
45 static __inline__
unsigned short _ne_inw(void *portp
)
49 tmp
= *(unsigned short *)(portp
) & 0xff;
50 tmp
|= *(unsigned short *)(portp
+2) << 8;
54 static __inline__
void _ne_insb(void *portp
, void * addr
, unsigned long count
)
56 unsigned char *buf
= addr
;
57 while (count
--) *buf
++ = *(volatile unsigned char *)(portp
+1);
60 static __inline__
void _ne_outb(unsigned char b
, void *portp
)
62 *(volatile unsigned char *)(portp
+1) = b
;
65 static __inline__
void _ne_outw(unsigned short w
, void *portp
)
67 *(volatile unsigned short *)portp
= (w
>> 8);
68 *(volatile unsigned short *)(portp
+2) = (w
& 0xff);
71 unsigned char _inb(unsigned long port
)
73 if (port
>= 0x300 && port
< 0x320)
74 return _ne_inb(PORT2ADDR_NE(port
));
76 return *(volatile unsigned char *)PORT2ADDR(port
);
79 unsigned short _inw(unsigned long port
)
81 if (port
>= 0x300 && port
< 0x320)
82 return _ne_inw(PORT2ADDR_NE(port
));
84 return *(volatile unsigned short *)PORT2ADDR(port
);
87 unsigned long _inl(unsigned long port
)
89 return *(volatile unsigned long *)PORT2ADDR(port
);
92 unsigned char _inb_p(unsigned long port
)
96 if (port
>= 0x300 && port
< 0x320)
97 v
= _ne_inb(PORT2ADDR_NE(port
));
99 v
= *(volatile unsigned char *)PORT2ADDR(port
);
105 unsigned short _inw_p(unsigned long port
)
109 if (port
>= 0x300 && port
< 0x320)
110 v
= _ne_inw(PORT2ADDR_NE(port
));
112 v
= *(volatile unsigned short *)PORT2ADDR(port
);
118 unsigned long _inl_p(unsigned long port
)
122 v
= *(volatile unsigned long *)PORT2ADDR(port
);
127 void _outb(unsigned char b
, unsigned long port
)
129 if (port
>= 0x300 && port
< 0x320)
130 _ne_outb(b
, PORT2ADDR_NE(port
));
132 *(volatile unsigned char *)PORT2ADDR(port
) = b
;
135 void _outw(unsigned short w
, unsigned long port
)
137 if (port
>= 0x300 && port
< 0x320)
138 _ne_outw(w
, PORT2ADDR_NE(port
));
140 *(volatile unsigned short *)PORT2ADDR(port
) = w
;
143 void _outl(unsigned long l
, unsigned long port
)
145 *(volatile unsigned long *)PORT2ADDR(port
) = l
;
148 void _outb_p(unsigned char b
, unsigned long port
)
150 if (port
>= 0x300 && port
< 0x320)
151 _ne_outb(b
, PORT2ADDR_NE(port
));
153 *(volatile unsigned char *)PORT2ADDR(port
) = b
;
158 void _outw_p(unsigned short w
, unsigned long port
)
160 if (port
>= 0x300 && port
< 0x320)
161 _ne_outw(w
, PORT2ADDR_NE(port
));
163 *(volatile unsigned short *)PORT2ADDR(port
) = w
;
168 void _outl_p(unsigned long l
, unsigned long port
)
170 *(volatile unsigned long *)PORT2ADDR(port
) = l
;
174 void _insb(unsigned int port
, void * addr
, unsigned long count
)
176 if (port
>= 0x300 && port
< 0x320)
177 _ne_insb(PORT2ADDR_NE(port
), addr
, count
);
179 unsigned char *buf
= addr
;
180 unsigned char *portp
= PORT2ADDR(port
);
181 while(count
--) *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
);
192 while (count
--) *buf
++ = _ne_inw(portp
);
194 portp
= PORT2ADDR(port
);
195 while (count
--) *buf
++ = *(volatile unsigned short *)portp
;
199 void _insl(unsigned int port
, void * addr
, unsigned long count
)
201 unsigned long *buf
= addr
;
202 unsigned long *portp
;
204 portp
= PORT2ADDR(port
);
205 while (count
--) *buf
++ = *(volatile unsigned long *)portp
;
208 void _outsb(unsigned int port
, const void * addr
, unsigned long count
)
210 const unsigned char *buf
= addr
;
211 unsigned char *portp
;
213 if (port
>= 0x300 && port
< 0x320) {
214 portp
= PORT2ADDR_NE(port
);
215 while (count
--) _ne_outb(*buf
++, portp
);
217 portp
= PORT2ADDR(port
);
218 while(count
--) *(volatile unsigned char *)portp
= *buf
++;
222 void _outsw(unsigned int port
, const void * addr
, unsigned long count
)
224 const unsigned short *buf
= addr
;
225 unsigned short *portp
;
227 if (port
>= 0x300 && port
< 0x320) {
228 portp
= PORT2ADDR_NE(port
);
229 while (count
--) _ne_outw(*buf
++, portp
);
231 portp
= PORT2ADDR(port
);
232 while(count
--) *(volatile unsigned short *)portp
= *buf
++;
236 void _outsl(unsigned int port
, const void * addr
, unsigned long count
)
238 const unsigned long *buf
= addr
;
239 unsigned char *portp
;
241 portp
= PORT2ADDR(port
);
242 while(count
--) *(volatile unsigned long *)portp
= *buf
++;