2 * linux/arch/m32r/kernel/io_mappi2.c
4 * Typical I/O routines for Mappi2 board.
6 * Copyright (c) 2001-2003 Hiroyuki Kondo, Hirokazu Takata,
7 * Hitoshi Yamamoto, Mamoru Sakugawa
12 #include <linux/config.h>
17 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
18 #include <linux/types.h>
20 #define M32R_PCC_IOMAP_SIZE 0x1000
22 #define M32R_PCC_IOSTART0 0x1000
23 #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
25 extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
26 extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
27 extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
28 extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
29 #endif /* CONFIG_PCMCIA && CONFIG_MAPPI2_CFC */
31 #define PORT2ADDR(port) _port2addr(port)
32 #define PORT2ADDR_NE(port) _port2addr_ne(port)
33 #define PORT2ADDR_USB(port) _port2addr_usb(port)
35 static __inline__
void *_port2addr(unsigned long port
)
37 return (void *)(port
+ NONCACHE_OFFSET
);
40 #define LAN_IOSTART 0x300
41 #define LAN_IOEND 0x320
42 #ifdef CONFIG_CHIP_OPSP
43 static __inline__
void *_port2addr_ne(unsigned long port
)
45 return (void *)(port
+ NONCACHE_OFFSET
+ 0x10000000);
48 static __inline__
void *_port2addr_ne(unsigned long port
)
50 return (void *)(port
+ NONCACHE_OFFSET
+ 0x04000000);
53 static __inline__
void *_port2addr_usb(unsigned long port
)
55 return (void *)(port
+ NONCACHE_OFFSET
+ 0x14000000);
57 static __inline__
void delay(void)
59 __asm__
__volatile__ ("push r0; \n\t pop r0;" : : :"memory");
66 static __inline__
unsigned char _ne_inb(void *portp
)
68 return (unsigned char) *(volatile unsigned char *)portp
;
71 static __inline__
unsigned short _ne_inw(void *portp
)
74 unsigned short tmp
,tmp2
;
75 tmp
= *(volatile unsigned short *)portp
;
76 tmp2
= (tmp
>>8|tmp
<<8);
79 return *(volatile unsigned short *)portp
;
83 static __inline__
void _ne_insb(void *portp
, void * addr
, unsigned long count
)
86 unsigned char *buf
= addr
;
88 tmp
= *(volatile unsigned char *)portp
;
89 while (count
--) *buf
++ = *(volatile unsigned char *)portp
;
92 static __inline__
void _ne_outb(unsigned char b
, void *portp
)
94 *(volatile unsigned char *)portp
= (unsigned char)b
;
97 static __inline__
void _ne_outw(unsigned short w
, void *portp
)
99 *(volatile unsigned short *)portp
= (w
>>8|w
<<8);
102 unsigned char _inb(unsigned long port
)
104 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
105 return _ne_inb(PORT2ADDR_NE(port
));
106 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
107 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
109 pcc_ioread_byte(0, port
, &b
, sizeof(b
), 1, 0);
114 return *(volatile unsigned char *)PORT2ADDR(port
);
117 unsigned short _inw(unsigned long port
)
119 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
120 return _ne_inw(PORT2ADDR_NE(port
));
121 #if defined(CONFIG_USB)
122 else if (port
>= 0x340 && port
< 0x3a0)
123 return *(volatile unsigned short *)PORT2ADDR_USB(port
);
126 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
127 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
129 pcc_ioread_word(0, port
, &w
, sizeof(w
), 1, 0);
133 return *(volatile unsigned short *)PORT2ADDR(port
);
136 unsigned long _inl(unsigned long port
)
138 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
139 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
141 pcc_ioread_word(0, port
, &l
, sizeof(l
), 1, 0);
145 return *(volatile unsigned long *)PORT2ADDR(port
);
148 unsigned char _inb_p(unsigned long port
)
152 if (port
>= 0x300 && port
< 0x320)
153 v
= _ne_inb(PORT2ADDR_NE(port
));
155 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
156 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
158 pcc_ioread_byte(0, port
, &b
, sizeof(b
), 1, 0);
162 v
= *(volatile unsigned char *)PORT2ADDR(port
);
168 unsigned short _inw_p(unsigned long port
)
172 if (port
>= 0x300 && port
< 0x320)
173 v
= _ne_inw(PORT2ADDR_NE(port
));
175 #if defined(CONFIG_USB)
176 if (port
>= 0x340 && port
< 0x3a0)
177 v
= *(volatile unsigned short *)PORT2ADDR_USB(port
);
180 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
181 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
183 pcc_ioread_word(0, port
, &w
, sizeof(w
), 1, 0);
187 v
= *(volatile unsigned short *)PORT2ADDR(port
);
193 unsigned long _inl_p(unsigned long port
)
197 v
= *(volatile unsigned long *)PORT2ADDR(port
);
202 void _outb(unsigned char b
, unsigned long port
)
204 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
205 _ne_outb(b
, PORT2ADDR_NE(port
));
207 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
208 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
209 pcc_iowrite_byte(0, port
, &b
, sizeof(b
), 1, 0);
212 *(volatile unsigned char *)PORT2ADDR(port
) = b
;
215 void _outw(unsigned short w
, unsigned long port
)
217 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
218 _ne_outw(w
, PORT2ADDR_NE(port
));
220 #if defined(CONFIG_USB)
221 if (port
>= 0x340 && port
< 0x3a0)
222 *(volatile unsigned short *)PORT2ADDR_USB(port
) = w
;
225 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
226 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
227 pcc_iowrite_word(0, port
, &w
, sizeof(w
), 1, 0);
230 *(volatile unsigned short *)PORT2ADDR(port
) = w
;
233 void _outl(unsigned long l
, unsigned long port
)
235 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
236 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
237 pcc_iowrite_word(0, port
, &l
, sizeof(l
), 1, 0);
240 *(volatile unsigned long *)PORT2ADDR(port
) = l
;
243 void _outb_p(unsigned char b
, unsigned long port
)
245 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
246 _ne_outb(b
, PORT2ADDR_NE(port
));
248 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
249 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
250 pcc_iowrite_byte(0, port
, &b
, sizeof(b
), 1, 0);
253 *(volatile unsigned char *)PORT2ADDR(port
) = b
;
258 void _outw_p(unsigned short w
, unsigned long port
)
260 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
261 _ne_outw(w
, PORT2ADDR_NE(port
));
263 #if defined(CONFIG_USB)
264 if (port
>= 0x340 && port
< 0x3a0)
265 *(volatile unsigned short *)PORT2ADDR_USB(port
) = w
;
268 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
269 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
270 pcc_iowrite_word(0, port
, &w
, sizeof(w
), 1, 0);
273 *(volatile unsigned short *)PORT2ADDR(port
) = w
;
278 void _outl_p(unsigned long l
, unsigned long port
)
280 *(volatile unsigned long *)PORT2ADDR(port
) = l
;
284 void _insb(unsigned int port
, void * addr
, unsigned long count
)
286 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
287 _ne_insb(PORT2ADDR_NE(port
), addr
, count
);
288 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
289 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
290 pcc_ioread_byte(0, port
, (void *)addr
, sizeof(unsigned char), count
, 1);
294 unsigned char *buf
= addr
;
295 unsigned char *portp
= PORT2ADDR(port
);
296 while(count
--) *buf
++ = *(volatile unsigned char *)portp
;
300 void _insw(unsigned int port
, void * addr
, unsigned long count
)
302 unsigned short *buf
= addr
;
303 unsigned short *portp
;
305 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
306 portp
= PORT2ADDR_NE(port
);
307 while (count
--) *buf
++ = *(volatile unsigned short *)portp
;
308 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
309 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
310 pcc_ioread_word(9, port
, (void *)addr
, sizeof(unsigned short), count
, 1);
313 portp
= PORT2ADDR(port
);
314 while (count
--) *buf
++ = *(volatile unsigned short *)portp
;
318 void _insl(unsigned int port
, void * addr
, unsigned long count
)
320 unsigned long *buf
= addr
;
321 unsigned long *portp
;
323 portp
= PORT2ADDR(port
);
324 while (count
--) *buf
++ = *(volatile unsigned long *)portp
;
327 void _outsb(unsigned int port
, const void * addr
, unsigned long count
)
329 const unsigned char *buf
= addr
;
330 unsigned char *portp
;
332 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
333 portp
= PORT2ADDR_NE(port
);
334 while (count
--) _ne_outb(*buf
++, portp
);
335 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
336 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
337 pcc_iowrite_byte(0, port
, (void *)addr
, sizeof(unsigned char), count
, 1);
340 portp
= PORT2ADDR(port
);
341 while(count
--) *(volatile unsigned char *)portp
= *buf
++;
345 void _outsw(unsigned int port
, const void * addr
, unsigned long count
)
347 const unsigned short *buf
= addr
;
348 unsigned short *portp
;
350 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
351 portp
= PORT2ADDR_NE(port
);
352 while (count
--) *(volatile unsigned short *)portp
= *buf
++;
353 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
354 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
355 pcc_iowrite_word(9, port
, (void *)addr
, sizeof(unsigned short), count
, 1);
358 portp
= PORT2ADDR(port
);
359 while(count
--) *(volatile unsigned short *)portp
= *buf
++;
363 void _outsl(unsigned int port
, const void * addr
, unsigned long count
)
365 const unsigned long *buf
= addr
;
366 unsigned char *portp
;
368 portp
= PORT2ADDR(port
);
369 while(count
--) *(volatile unsigned long *)portp
= *buf
++;