2 * linux/arch/m32r/platforms/mappi2/io.c
4 * Typical I/O routines for Mappi2 board.
6 * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata,
7 * Hitoshi Yamamoto, Mamoru Sakugawa
13 #include <asm/byteorder.h>
15 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
16 #include <linux/types.h>
18 #define M32R_PCC_IOMAP_SIZE 0x1000
20 #define M32R_PCC_IOSTART0 0x1000
21 #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
23 extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
24 extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
25 extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
26 extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
27 #endif /* CONFIG_PCMCIA && CONFIG_M32R_CFC */
29 #define PORT2ADDR(port) _port2addr(port)
30 #define PORT2ADDR_NE(port) _port2addr_ne(port)
31 #define PORT2ADDR_USB(port) _port2addr_usb(port)
33 static inline void *_port2addr(unsigned long port
)
35 return (void *)(port
| NONCACHE_OFFSET
);
38 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
39 static inline void *__port2addr_ata(unsigned long port
)
44 case 0x1f0: return (void *)(0x0c002000 | NONCACHE_OFFSET
);
45 case 0x1f1: return (void *)(0x0c012800 | NONCACHE_OFFSET
);
46 case 0x1f2: return (void *)(0x0c012002 | NONCACHE_OFFSET
);
47 case 0x1f3: return (void *)(0x0c012802 | NONCACHE_OFFSET
);
48 case 0x1f4: return (void *)(0x0c012004 | NONCACHE_OFFSET
);
49 case 0x1f5: return (void *)(0x0c012804 | NONCACHE_OFFSET
);
50 case 0x1f6: return (void *)(0x0c012006 | NONCACHE_OFFSET
);
51 case 0x1f7: return (void *)(0x0c012806 | NONCACHE_OFFSET
);
52 case 0x3f6: return (void *)(0x0c01200e | NONCACHE_OFFSET
);
53 default: return (void *)&dummy_reg
;
58 #define LAN_IOSTART (0x300 | NONCACHE_OFFSET)
59 #define LAN_IOEND (0x320 | NONCACHE_OFFSET)
60 #ifdef CONFIG_CHIP_OPSP
61 static inline void *_port2addr_ne(unsigned long port
)
63 return (void *)(port
+ 0x10000000);
66 static inline void *_port2addr_ne(unsigned long port
)
68 return (void *)(port
+ 0x04000000);
71 static inline void *_port2addr_usb(unsigned long port
)
73 return (void *)(port
+ NONCACHE_OFFSET
+ 0x14000000);
75 static inline void delay(void)
77 __asm__
__volatile__ ("push r0; \n\t pop r0;" : : :"memory");
84 static inline unsigned char _ne_inb(void *portp
)
86 return (unsigned char) *(volatile unsigned char *)portp
;
89 static inline unsigned short _ne_inw(void *portp
)
91 return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp
);
94 static inline void _ne_insb(void *portp
, void * addr
, unsigned long count
)
96 unsigned char *buf
= addr
;
99 *buf
++ = *(volatile unsigned char *)portp
;
102 static inline void _ne_outb(unsigned char b
, void *portp
)
104 *(volatile unsigned char *)portp
= (unsigned char)b
;
107 static inline void _ne_outw(unsigned short w
, void *portp
)
109 *(volatile unsigned short *)portp
= cpu_to_le16(w
);
112 unsigned char _inb(unsigned long port
)
114 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
115 return _ne_inb(PORT2ADDR_NE(port
));
116 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
117 else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
118 return *(volatile unsigned char *)__port2addr_ata(port
);
121 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
122 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
124 pcc_ioread_byte(0, port
, &b
, sizeof(b
), 1, 0);
129 return *(volatile unsigned char *)PORT2ADDR(port
);
132 unsigned short _inw(unsigned long port
)
134 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
135 return _ne_inw(PORT2ADDR_NE(port
));
136 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
137 else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
138 return *(volatile unsigned short *)__port2addr_ata(port
);
141 #if defined(CONFIG_USB)
142 else if (port
>= 0x340 && port
< 0x3a0)
143 return *(volatile unsigned short *)PORT2ADDR_USB(port
);
146 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
147 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
149 pcc_ioread_word(0, port
, &w
, sizeof(w
), 1, 0);
153 return *(volatile unsigned short *)PORT2ADDR(port
);
156 unsigned long _inl(unsigned long port
)
158 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
159 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
161 pcc_ioread_word(0, port
, &l
, sizeof(l
), 1, 0);
165 return *(volatile unsigned long *)PORT2ADDR(port
);
168 unsigned char _inb_p(unsigned long port
)
170 unsigned char v
= _inb(port
);
175 unsigned short _inw_p(unsigned long port
)
177 unsigned short v
= _inw(port
);
182 unsigned long _inl_p(unsigned long port
)
184 unsigned long v
= _inl(port
);
189 void _outb(unsigned char b
, unsigned long port
)
191 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
192 _ne_outb(b
, PORT2ADDR_NE(port
));
194 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
195 if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
196 *(volatile unsigned char *)__port2addr_ata(port
) = b
;
199 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
200 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
201 pcc_iowrite_byte(0, port
, &b
, sizeof(b
), 1, 0);
204 *(volatile unsigned char *)PORT2ADDR(port
) = b
;
207 void _outw(unsigned short w
, unsigned long port
)
209 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
210 _ne_outw(w
, PORT2ADDR_NE(port
));
212 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
213 if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
214 *(volatile unsigned short *)__port2addr_ata(port
) = w
;
217 #if defined(CONFIG_USB)
218 if (port
>= 0x340 && port
< 0x3a0)
219 *(volatile unsigned short *)PORT2ADDR_USB(port
) = w
;
222 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
223 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
224 pcc_iowrite_word(0, port
, &w
, sizeof(w
), 1, 0);
227 *(volatile unsigned short *)PORT2ADDR(port
) = w
;
230 void _outl(unsigned long l
, unsigned long port
)
232 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
233 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
234 pcc_iowrite_word(0, port
, &l
, sizeof(l
), 1, 0);
237 *(volatile unsigned long *)PORT2ADDR(port
) = l
;
240 void _outb_p(unsigned char b
, unsigned long port
)
246 void _outw_p(unsigned short w
, unsigned long port
)
252 void _outl_p(unsigned long l
, unsigned long port
)
258 void _insb(unsigned int port
, void * addr
, unsigned long count
)
260 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
261 _ne_insb(PORT2ADDR_NE(port
), addr
, count
);
262 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
263 else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
264 unsigned char *buf
= addr
;
265 unsigned char *portp
= __port2addr_ata(port
);
267 *buf
++ = *(volatile unsigned char *)portp
;
270 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
271 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
272 pcc_ioread_byte(0, port
, (void *)addr
, sizeof(unsigned char),
277 unsigned char *buf
= addr
;
278 unsigned char *portp
= PORT2ADDR(port
);
280 *buf
++ = *(volatile unsigned char *)portp
;
284 void _insw(unsigned int port
, void * addr
, unsigned long count
)
286 unsigned short *buf
= addr
;
287 unsigned short *portp
;
289 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
290 portp
= PORT2ADDR_NE(port
);
292 *buf
++ = *(volatile unsigned short *)portp
;
293 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
294 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
295 pcc_ioread_word(9, port
, (void *)addr
, sizeof(unsigned short),
298 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
299 } else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
300 portp
= __port2addr_ata(port
);
302 *buf
++ = *(volatile unsigned short *)portp
;
305 portp
= PORT2ADDR(port
);
307 *buf
++ = *(volatile unsigned short *)portp
;
311 void _insl(unsigned int port
, void * addr
, unsigned long count
)
313 unsigned long *buf
= addr
;
314 unsigned long *portp
;
316 portp
= PORT2ADDR(port
);
318 *buf
++ = *(volatile unsigned long *)portp
;
321 void _outsb(unsigned int port
, const void * addr
, unsigned long count
)
323 const unsigned char *buf
= addr
;
324 unsigned char *portp
;
326 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
327 portp
= PORT2ADDR_NE(port
);
329 _ne_outb(*buf
++, portp
);
330 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
331 } else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
332 portp
= __port2addr_ata(port
);
334 *(volatile unsigned char *)portp
= *buf
++;
336 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
337 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
338 pcc_iowrite_byte(0, port
, (void *)addr
, sizeof(unsigned char),
342 portp
= PORT2ADDR(port
);
344 *(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
) {
354 portp
= PORT2ADDR_NE(port
);
356 *(volatile unsigned short *)portp
= *buf
++;
357 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
358 } else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
359 portp
= __port2addr_ata(port
);
361 *(volatile unsigned short *)portp
= *buf
++;
363 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
364 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
365 pcc_iowrite_word(9, port
, (void *)addr
, sizeof(unsigned short),
369 portp
= PORT2ADDR(port
);
371 *(volatile unsigned short *)portp
= *buf
++;
375 void _outsl(unsigned int port
, const void * addr
, unsigned long count
)
377 const unsigned long *buf
= addr
;
378 unsigned char *portp
;
380 portp
= PORT2ADDR(port
);
382 *(volatile unsigned long *)portp
= *buf
++;