2 * linux/arch/m32r/kernel/io_opsput.c
4 * Typical I/O routines for OPSPUT board.
6 * Copyright (c) 2001-2005 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.
17 #include <asm/byteorder.h>
19 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
20 #include <linux/types.h>
22 #define M32R_PCC_IOMAP_SIZE 0x1000
24 #define M32R_PCC_IOSTART0 0x1000
25 #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
27 extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
28 extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
29 extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
30 extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
31 #endif /* CONFIG_PCMCIA && CONFIG_M32R_CFC */
33 #define PORT2ADDR(port) _port2addr(port)
34 #define PORT2ADDR_USB(port) _port2addr_usb(port)
36 static inline void *_port2addr(unsigned long port
)
38 return (void *)(port
| NONCACHE_OFFSET
);
42 * OPSPUT-LAN is located in the extended bus space
43 * from 0x10000000 to 0x13ffffff on physical address.
44 * The base address of LAN controller(LAN91C111) is 0x300.
46 #define LAN_IOSTART (0x300 | NONCACHE_OFFSET)
47 #define LAN_IOEND (0x320 | NONCACHE_OFFSET)
48 static inline void *_port2addr_ne(unsigned long port
)
50 return (void *)(port
+ 0x10000000);
52 static inline void *_port2addr_usb(unsigned long port
)
54 return (void *)((port
& 0x0f) + NONCACHE_OFFSET
+ 0x10303000);
57 static inline void delay(void)
59 __asm__
__volatile__ ("push r0; \n\t pop r0;" : : :"memory");
66 #define PORT2ADDR_NE(port) _port2addr_ne(port)
68 static inline unsigned char _ne_inb(void *portp
)
70 return *(volatile unsigned char *)portp
;
73 static inline unsigned short _ne_inw(void *portp
)
75 return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp
);
78 static inline void _ne_insb(void *portp
, void *addr
, unsigned long count
)
80 unsigned char *buf
= (unsigned char *)addr
;
83 *buf
++ = _ne_inb(portp
);
86 static inline void _ne_outb(unsigned char b
, void *portp
)
88 *(volatile unsigned char *)portp
= b
;
91 static inline void _ne_outw(unsigned short w
, void *portp
)
93 *(volatile unsigned short *)portp
= cpu_to_le16(w
);
96 unsigned char _inb(unsigned long port
)
98 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
99 return _ne_inb(PORT2ADDR_NE(port
));
100 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
101 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
103 pcc_ioread_byte(0, port
, &b
, sizeof(b
), 1, 0);
108 return *(volatile unsigned char *)PORT2ADDR(port
);
111 unsigned short _inw(unsigned long port
)
113 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
114 return _ne_inw(PORT2ADDR_NE(port
));
115 #if defined(CONFIG_USB)
116 else if(port
>= 0x340 && port
< 0x3a0)
117 return *(volatile unsigned short *)PORT2ADDR_USB(port
);
119 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
120 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
122 pcc_ioread_word(0, port
, &w
, sizeof(w
), 1, 0);
126 return *(volatile unsigned short *)PORT2ADDR(port
);
129 unsigned long _inl(unsigned long port
)
131 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
132 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
134 pcc_ioread_word(0, port
, &l
, sizeof(l
), 1, 0);
138 return *(volatile unsigned long *)PORT2ADDR(port
);
141 unsigned char _inb_p(unsigned long port
)
143 unsigned char v
= _inb(port
);
148 unsigned short _inw_p(unsigned long port
)
150 unsigned short v
= _inw(port
);
155 unsigned long _inl_p(unsigned long port
)
157 unsigned long v
= _inl(port
);
162 void _outb(unsigned char b
, unsigned long port
)
164 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
165 _ne_outb(b
, PORT2ADDR_NE(port
));
167 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
168 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
169 pcc_iowrite_byte(0, port
, &b
, sizeof(b
), 1, 0);
172 *(volatile unsigned char *)PORT2ADDR(port
) = b
;
175 void _outw(unsigned short w
, unsigned long port
)
177 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
178 _ne_outw(w
, PORT2ADDR_NE(port
));
180 #if defined(CONFIG_USB)
181 if(port
>= 0x340 && port
< 0x3a0)
182 *(volatile unsigned short *)PORT2ADDR_USB(port
) = w
;
185 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
186 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
187 pcc_iowrite_word(0, port
, &w
, sizeof(w
), 1, 0);
190 *(volatile unsigned short *)PORT2ADDR(port
) = w
;
193 void _outl(unsigned long l
, unsigned long port
)
195 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
196 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
197 pcc_iowrite_word(0, port
, &l
, sizeof(l
), 1, 0);
200 *(volatile unsigned long *)PORT2ADDR(port
) = l
;
203 void _outb_p(unsigned char b
, unsigned long port
)
209 void _outw_p(unsigned short w
, unsigned long port
)
215 void _outl_p(unsigned long l
, unsigned long port
)
221 void _insb(unsigned int port
, void *addr
, unsigned long count
)
223 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
224 _ne_insb(PORT2ADDR_NE(port
), addr
, count
);
225 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
226 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
227 pcc_ioread_byte(0, port
, (void *)addr
, sizeof(unsigned char),
232 unsigned char *buf
= addr
;
233 unsigned char *portp
= PORT2ADDR(port
);
235 *buf
++ = *(volatile unsigned char *)portp
;
239 void _insw(unsigned int port
, void *addr
, unsigned long count
)
241 unsigned short *buf
= addr
;
242 unsigned short *portp
;
244 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
246 * This portion is only used by smc91111.c to read data
247 * from the DATA_REG. Do not swap the data.
249 portp
= PORT2ADDR_NE(port
);
251 *buf
++ = *(volatile unsigned short *)portp
;
252 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
253 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
254 pcc_ioread_word(9, port
, (void *)addr
, sizeof(unsigned short),
258 portp
= PORT2ADDR(port
);
260 *buf
++ = *(volatile unsigned short *)portp
;
264 void _insl(unsigned int port
, void *addr
, unsigned long count
)
266 unsigned long *buf
= addr
;
267 unsigned long *portp
;
269 portp
= PORT2ADDR(port
);
271 *buf
++ = *(volatile unsigned long *)portp
;
274 void _outsb(unsigned int port
, const void *addr
, unsigned long count
)
276 const unsigned char *buf
= addr
;
277 unsigned char *portp
;
279 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
280 portp
= PORT2ADDR_NE(port
);
282 _ne_outb(*buf
++, portp
);
283 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
284 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
285 pcc_iowrite_byte(0, port
, (void *)addr
, sizeof(unsigned char),
289 portp
= PORT2ADDR(port
);
291 *(volatile unsigned char *)portp
= *buf
++;
295 void _outsw(unsigned int port
, const void *addr
, unsigned long count
)
297 const unsigned short *buf
= addr
;
298 unsigned short *portp
;
300 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
302 * This portion is only used by smc91111.c to write data
303 * into the DATA_REG. Do not swap the data.
305 portp
= PORT2ADDR_NE(port
);
307 *(volatile unsigned short *)portp
= *buf
++;
308 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
309 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
310 pcc_iowrite_word(9, port
, (void *)addr
, sizeof(unsigned short),
314 portp
= PORT2ADDR(port
);
316 *(volatile unsigned short *)portp
= *buf
++;
320 void _outsl(unsigned int port
, const void *addr
, unsigned long count
)
322 const unsigned long *buf
= addr
;
323 unsigned char *portp
;
325 portp
= PORT2ADDR(port
);
327 *(volatile unsigned long *)portp
= *buf
++;