2 * linux/arch/m32r/kernel/io_mappi2.c
4 * Typical I/O routines for Mappi2 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 *)0xac002000;
49 case 0x1f1: return (void *)0xac012800;
50 case 0x1f2: return (void *)0xac012002;
51 case 0x1f3: return (void *)0xac012802;
52 case 0x1f4: return (void *)0xac012004;
53 case 0x1f5: return (void *)0xac012804;
54 case 0x1f6: return (void *)0xac012006;
55 case 0x1f7: return (void *)0xac012806;
56 case 0x3f6: return (void *)0xac01200e;
57 default: return (void *)&dummy_reg
;
62 #ifdef CONFIG_CHIP_OPSP
63 static inline void *_port2addr_ne(unsigned long port
)
65 return (void *)(port
+ NONCACHE_OFFSET
+ 0x10000000);
68 static inline void *_port2addr_ne(unsigned long port
)
70 return (void *)(port
+ NONCACHE_OFFSET
+ 0x04000000);
73 static inline void *_port2addr_usb(unsigned long port
)
75 return (void *)(port
+ NONCACHE_OFFSET
+ 0x14000000);
77 static inline void delay(void)
79 __asm__
__volatile__ ("push r0; \n\t pop r0;" : : :"memory");
86 static inline unsigned char _ne_inb(void *portp
)
88 return (unsigned char) *(volatile unsigned char *)portp
;
91 static inline unsigned short _ne_inw(void *portp
)
93 return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp
);
96 static inline void _ne_insb(void *portp
, void * addr
, unsigned long count
)
98 unsigned char *buf
= addr
;
101 *buf
++ = *(volatile unsigned char *)portp
;
104 static inline void _ne_outb(unsigned char b
, void *portp
)
106 *(volatile unsigned char *)portp
= (unsigned char)b
;
109 static inline void _ne_outw(unsigned short w
, void *portp
)
111 *(volatile unsigned short *)portp
= cpu_to_le16(w
);
114 unsigned char _inb(unsigned long port
)
116 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
117 return _ne_inb(PORT2ADDR_NE(port
));
118 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
119 else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
120 return *(volatile unsigned char *)__port2addr_ata(port
);
123 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
124 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
126 pcc_ioread_byte(0, port
, &b
, sizeof(b
), 1, 0);
131 return *(volatile unsigned char *)PORT2ADDR(port
);
134 unsigned short _inw(unsigned long port
)
136 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
137 return _ne_inw(PORT2ADDR_NE(port
));
138 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
139 else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
140 return *(volatile unsigned short *)__port2addr_ata(port
);
143 #if defined(CONFIG_USB)
144 else if (port
>= 0x340 && port
< 0x3a0)
145 return *(volatile unsigned short *)PORT2ADDR_USB(port
);
148 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
149 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
151 pcc_ioread_word(0, port
, &w
, sizeof(w
), 1, 0);
155 return *(volatile unsigned short *)PORT2ADDR(port
);
158 unsigned long _inl(unsigned long port
)
160 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
161 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
163 pcc_ioread_word(0, port
, &l
, sizeof(l
), 1, 0);
167 return *(volatile unsigned long *)PORT2ADDR(port
);
170 unsigned char _inb_p(unsigned long port
)
172 unsigned char v
= _inb(port
);
177 unsigned short _inw_p(unsigned long port
)
179 unsigned short v
= _inw(port
);
184 unsigned long _inl_p(unsigned long port
)
186 unsigned long v
= _inl(port
);
191 void _outb(unsigned char b
, unsigned long port
)
193 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
194 _ne_outb(b
, PORT2ADDR_NE(port
));
196 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
197 if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
198 *(volatile unsigned char *)__port2addr_ata(port
) = b
;
201 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
202 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
203 pcc_iowrite_byte(0, port
, &b
, sizeof(b
), 1, 0);
206 *(volatile unsigned char *)PORT2ADDR(port
) = b
;
209 void _outw(unsigned short w
, unsigned long port
)
211 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
212 _ne_outw(w
, PORT2ADDR_NE(port
));
214 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
215 if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
216 *(volatile unsigned short *)__port2addr_ata(port
) = w
;
219 #if defined(CONFIG_USB)
220 if (port
>= 0x340 && port
< 0x3a0)
221 *(volatile unsigned short *)PORT2ADDR_USB(port
) = w
;
224 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
225 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
226 pcc_iowrite_word(0, port
, &w
, sizeof(w
), 1, 0);
229 *(volatile unsigned short *)PORT2ADDR(port
) = w
;
232 void _outl(unsigned long l
, unsigned long port
)
234 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
235 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
236 pcc_iowrite_word(0, port
, &l
, sizeof(l
), 1, 0);
239 *(volatile unsigned long *)PORT2ADDR(port
) = l
;
242 void _outb_p(unsigned char b
, unsigned long port
)
248 void _outw_p(unsigned short w
, unsigned long port
)
254 void _outl_p(unsigned long l
, unsigned long port
)
260 void _insb(unsigned int port
, void * addr
, unsigned long count
)
262 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
263 _ne_insb(PORT2ADDR_NE(port
), addr
, count
);
264 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
265 else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
266 unsigned char *buf
= addr
;
267 unsigned char *portp
= __port2addr_ata(port
);
269 *buf
++ = *(volatile unsigned char *)portp
;
272 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
273 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
274 pcc_ioread_byte(0, port
, (void *)addr
, sizeof(unsigned char),
279 unsigned char *buf
= addr
;
280 unsigned char *portp
= PORT2ADDR(port
);
282 *buf
++ = *(volatile unsigned char *)portp
;
286 void _insw(unsigned int port
, void * addr
, unsigned long count
)
288 unsigned short *buf
= addr
;
289 unsigned short *portp
;
291 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
292 portp
= PORT2ADDR_NE(port
);
294 *buf
++ = *(volatile unsigned short *)portp
;
295 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
296 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
297 pcc_ioread_word(9, port
, (void *)addr
, sizeof(unsigned short),
300 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
301 } else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
302 portp
= __port2addr_ata(port
);
304 *buf
++ = *(volatile unsigned short *)portp
;
307 portp
= PORT2ADDR(port
);
309 *buf
++ = *(volatile unsigned short *)portp
;
313 void _insl(unsigned int port
, void * addr
, unsigned long count
)
315 unsigned long *buf
= addr
;
316 unsigned long *portp
;
318 portp
= PORT2ADDR(port
);
320 *buf
++ = *(volatile unsigned long *)portp
;
323 void _outsb(unsigned int port
, const void * addr
, unsigned long count
)
325 const unsigned char *buf
= addr
;
326 unsigned char *portp
;
328 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
329 portp
= PORT2ADDR_NE(port
);
331 _ne_outb(*buf
++, portp
);
332 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
333 } else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
334 portp
= __port2addr_ata(port
);
336 *(volatile unsigned char *)portp
= *buf
++;
338 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
339 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
340 pcc_iowrite_byte(0, port
, (void *)addr
, sizeof(unsigned char),
344 portp
= PORT2ADDR(port
);
346 *(volatile unsigned char *)portp
= *buf
++;
350 void _outsw(unsigned int port
, const void * addr
, unsigned long count
)
352 const unsigned short *buf
= addr
;
353 unsigned short *portp
;
355 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
356 portp
= PORT2ADDR_NE(port
);
358 *(volatile unsigned short *)portp
= *buf
++;
359 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
360 } else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
361 portp
= __port2addr_ata(port
);
363 *(volatile unsigned short *)portp
= *buf
++;
365 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
366 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
367 pcc_iowrite_word(9, port
, (void *)addr
, sizeof(unsigned short),
371 portp
= PORT2ADDR(port
);
373 *(volatile unsigned short *)portp
= *buf
++;
377 void _outsl(unsigned int port
, const void * addr
, unsigned long count
)
379 const unsigned long *buf
= addr
;
380 unsigned char *portp
;
382 portp
= PORT2ADDR(port
);
384 *(volatile unsigned long *)portp
= *buf
++;