2 * linux/arch/m32r/kernel/io_mappi3.c
4 * Typical I/O routines for Mappi3 board.
6 * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata,
7 * Hitoshi Yamamoto, Mamoru Sakugawa
10 #include <linux/config.h>
14 #include <asm/byteorder.h>
16 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
17 #include <linux/types.h>
19 #define M32R_PCC_IOMAP_SIZE 0x1000
21 #define M32R_PCC_IOSTART0 0x1000
22 #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
24 extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
25 extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
26 extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
27 extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
28 #endif /* CONFIG_PCMCIA && CONFIG_M32R_CFC */
30 #define PORT2ADDR(port) _port2addr(port)
31 #define PORT2ADDR_NE(port) _port2addr_ne(port)
32 #define PORT2ADDR_USB(port) _port2addr_usb(port)
34 static inline void *_port2addr(unsigned long port
)
36 return (void *)(port
+ NONCACHE_OFFSET
);
39 #define LAN_IOSTART 0x300
40 #define LAN_IOEND 0x320
42 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
43 static inline void *__port2addr_ata(unsigned long port
)
48 case 0x1f0: return (void *)0xb4002000;
49 case 0x1f1: return (void *)0xb4012800;
50 case 0x1f2: return (void *)0xb4012002;
51 case 0x1f3: return (void *)0xb4012802;
52 case 0x1f4: return (void *)0xb4012004;
53 case 0x1f5: return (void *)0xb4012804;
54 case 0x1f6: return (void *)0xb4012006;
55 case 0x1f7: return (void *)0xb4012806;
56 case 0x3f6: return (void *)0xb401200e;
57 default: return (void *)&dummy_reg
;
62 static inline void *_port2addr_ne(unsigned long port
)
64 return (void *)(port
+ NONCACHE_OFFSET
+ 0x10000000);
67 static inline void *_port2addr_usb(unsigned long port
)
69 return (void *)(port
+ NONCACHE_OFFSET
+ 0x12000000);
71 static inline void delay(void)
73 __asm__
__volatile__ ("push r0; \n\t pop r0;" : : :"memory");
80 static inline unsigned char _ne_inb(void *portp
)
82 return (unsigned char) *(volatile unsigned char *)portp
;
85 static inline unsigned short _ne_inw(void *portp
)
87 return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp
);
90 static inline void _ne_insb(void *portp
, void * addr
, unsigned long count
)
92 unsigned char *buf
= addr
;
95 *buf
++ = *(volatile unsigned char *)portp
;
98 static inline void _ne_outb(unsigned char b
, void *portp
)
100 *(volatile unsigned char *)portp
= (unsigned char)b
;
103 static inline void _ne_outw(unsigned short w
, void *portp
)
105 *(volatile unsigned short *)portp
= cpu_to_le16(w
);
108 unsigned char _inb(unsigned long port
)
110 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
111 return _ne_inb(PORT2ADDR_NE(port
));
112 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
113 else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
114 return *(volatile unsigned char *)__port2addr_ata(port
);
117 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
118 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
120 pcc_ioread_byte(0, port
, &b
, sizeof(b
), 1, 0);
124 return *(volatile unsigned char *)PORT2ADDR(port
);
127 unsigned short _inw(unsigned long port
)
129 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
130 return _ne_inw(PORT2ADDR_NE(port
));
131 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
132 else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
133 return *(volatile unsigned short *)__port2addr_ata(port
);
136 #if defined(CONFIG_USB)
137 else if (port
>= 0x340 && port
< 0x3a0)
138 return *(volatile unsigned short *)PORT2ADDR_USB(port
);
141 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
142 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
144 pcc_ioread_word(0, port
, &w
, sizeof(w
), 1, 0);
148 return *(volatile unsigned short *)PORT2ADDR(port
);
151 unsigned long _inl(unsigned long port
)
153 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
154 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
156 pcc_ioread_word(0, port
, &l
, sizeof(l
), 1, 0);
160 return *(volatile unsigned long *)PORT2ADDR(port
);
163 unsigned char _inb_p(unsigned long port
)
165 unsigned char v
= _inb(port
);
170 unsigned short _inw_p(unsigned long port
)
172 unsigned short v
= _inw(port
);
177 unsigned long _inl_p(unsigned long port
)
179 unsigned long v
= _inl(port
);
184 void _outb(unsigned char b
, unsigned long port
)
186 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
187 _ne_outb(b
, PORT2ADDR_NE(port
));
189 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
190 if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
191 *(volatile unsigned char *)__port2addr_ata(port
) = b
;
194 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
195 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
196 pcc_iowrite_byte(0, port
, &b
, sizeof(b
), 1, 0);
199 *(volatile unsigned char *)PORT2ADDR(port
) = b
;
202 void _outw(unsigned short w
, unsigned long port
)
204 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
205 _ne_outw(w
, PORT2ADDR_NE(port
));
207 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
208 if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
209 *(volatile unsigned short *)__port2addr_ata(port
) = w
;
212 #if defined(CONFIG_USB)
213 if (port
>= 0x340 && port
< 0x3a0)
214 *(volatile unsigned short *)PORT2ADDR_USB(port
) = w
;
217 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
218 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
219 pcc_iowrite_word(0, port
, &w
, sizeof(w
), 1, 0);
222 *(volatile unsigned short *)PORT2ADDR(port
) = w
;
225 void _outl(unsigned long l
, unsigned long port
)
227 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
228 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
229 pcc_iowrite_word(0, port
, &l
, sizeof(l
), 1, 0);
232 *(volatile unsigned long *)PORT2ADDR(port
) = l
;
235 void _outb_p(unsigned char b
, unsigned long port
)
241 void _outw_p(unsigned short w
, unsigned long port
)
247 void _outl_p(unsigned long l
, unsigned long port
)
253 void _insb(unsigned int port
, void * addr
, unsigned long count
)
255 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
256 _ne_insb(PORT2ADDR_NE(port
), addr
, count
);
257 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
258 else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
259 unsigned char *buf
= addr
;
260 unsigned char *portp
= __port2addr_ata(port
);
262 *buf
++ = *(volatile unsigned char *)portp
;
265 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
266 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
267 pcc_ioread_byte(0, port
, (void *)addr
, sizeof(unsigned char),
272 unsigned char *buf
= addr
;
273 unsigned char *portp
= PORT2ADDR(port
);
275 *buf
++ = *(volatile unsigned char *)portp
;
279 void _insw(unsigned int port
, void * addr
, unsigned long count
)
281 unsigned short *buf
= addr
;
282 unsigned short *portp
;
284 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
285 portp
= PORT2ADDR_NE(port
);
287 *buf
++ = *(volatile unsigned short *)portp
;
288 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
289 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
290 pcc_ioread_word(9, port
, (void *)addr
, sizeof(unsigned short),
293 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
294 } else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
295 portp
= __port2addr_ata(port
);
297 *buf
++ = *(volatile unsigned short *)portp
;
300 portp
= PORT2ADDR(port
);
302 *buf
++ = *(volatile unsigned short *)portp
;
306 void _insl(unsigned int port
, void * addr
, unsigned long count
)
308 unsigned long *buf
= addr
;
309 unsigned long *portp
;
311 portp
= PORT2ADDR(port
);
313 *buf
++ = *(volatile unsigned long *)portp
;
316 void _outsb(unsigned int port
, const void * addr
, unsigned long count
)
318 const unsigned char *buf
= addr
;
319 unsigned char *portp
;
321 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
322 portp
= PORT2ADDR_NE(port
);
324 _ne_outb(*buf
++, portp
);
325 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
326 } else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
327 portp
= __port2addr_ata(port
);
329 *(volatile unsigned char *)portp
= *buf
++;
331 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
332 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
333 pcc_iowrite_byte(0, port
, (void *)addr
, sizeof(unsigned char),
337 portp
= PORT2ADDR(port
);
339 *(volatile unsigned char *)portp
= *buf
++;
343 void _outsw(unsigned int port
, const void * addr
, unsigned long count
)
345 const unsigned short *buf
= addr
;
346 unsigned short *portp
;
348 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
349 portp
= PORT2ADDR_NE(port
);
351 *(volatile unsigned short *)portp
= *buf
++;
352 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
353 } else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
354 portp
= __port2addr_ata(port
);
356 *(volatile unsigned short *)portp
= *buf
++;
358 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
359 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
360 pcc_iowrite_word(9, port
, (void *)addr
, sizeof(unsigned short),
364 portp
= PORT2ADDR(port
);
366 *(volatile unsigned short *)portp
= *buf
++;
370 void _outsl(unsigned int port
, const void * addr
, unsigned long count
)
372 const unsigned long *buf
= addr
;
373 unsigned char *portp
;
375 portp
= PORT2ADDR(port
);
377 *(volatile unsigned long *)portp
= *buf
++;