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
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_MAPPI2_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
)
174 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
175 v
= _ne_inb(PORT2ADDR_NE(port
));
177 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
178 if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
179 return *(volatile unsigned char *)__port2addr_ata(port
);
182 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
183 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
185 pcc_ioread_byte(0, port
, &b
, sizeof(b
), 1, 0);
189 v
= *(volatile unsigned char *)PORT2ADDR(port
);
195 unsigned short _inw_p(unsigned long port
)
199 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
200 v
= _ne_inw(PORT2ADDR_NE(port
));
202 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
203 if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
204 return *(volatile unsigned short *)__port2addr_ata(port
);
207 #if defined(CONFIG_USB)
208 if (port
>= 0x340 && port
< 0x3a0)
209 v
= *(volatile unsigned short *)PORT2ADDR_USB(port
);
212 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
213 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
215 pcc_ioread_word(0, port
, &w
, sizeof(w
), 1, 0);
219 v
= *(volatile unsigned short *)PORT2ADDR(port
);
225 unsigned long _inl_p(unsigned long port
)
229 v
= *(volatile unsigned long *)PORT2ADDR(port
);
234 void _outb(unsigned char b
, unsigned long port
)
236 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
237 _ne_outb(b
, PORT2ADDR_NE(port
));
239 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
240 if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
241 *(volatile unsigned char *)__port2addr_ata(port
) = b
;
244 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
245 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
246 pcc_iowrite_byte(0, port
, &b
, sizeof(b
), 1, 0);
249 *(volatile unsigned char *)PORT2ADDR(port
) = b
;
252 void _outw(unsigned short w
, unsigned long port
)
254 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
255 _ne_outw(w
, PORT2ADDR_NE(port
));
257 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
258 if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
259 *(volatile unsigned short *)__port2addr_ata(port
) = w
;
262 #if defined(CONFIG_USB)
263 if (port
>= 0x340 && port
< 0x3a0)
264 *(volatile unsigned short *)PORT2ADDR_USB(port
) = w
;
267 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
268 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
269 pcc_iowrite_word(0, port
, &w
, sizeof(w
), 1, 0);
272 *(volatile unsigned short *)PORT2ADDR(port
) = w
;
275 void _outl(unsigned long l
, unsigned long port
)
277 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
278 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
279 pcc_iowrite_word(0, port
, &l
, sizeof(l
), 1, 0);
282 *(volatile unsigned long *)PORT2ADDR(port
) = l
;
285 void _outb_p(unsigned char b
, unsigned long port
)
287 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
288 _ne_outb(b
, PORT2ADDR_NE(port
));
290 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
291 if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
292 *(volatile unsigned char *)__port2addr_ata(port
) = b
;
295 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
296 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
297 pcc_iowrite_byte(0, port
, &b
, sizeof(b
), 1, 0);
300 *(volatile unsigned char *)PORT2ADDR(port
) = b
;
305 void _outw_p(unsigned short w
, unsigned long port
)
307 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
308 _ne_outw(w
, PORT2ADDR_NE(port
));
310 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
311 if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
312 *(volatile unsigned short *)__port2addr_ata(port
) = w
;
315 #if defined(CONFIG_USB)
316 if (port
>= 0x340 && port
< 0x3a0)
317 *(volatile unsigned short *)PORT2ADDR_USB(port
) = w
;
320 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
321 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
322 pcc_iowrite_word(0, port
, &w
, sizeof(w
), 1, 0);
325 *(volatile unsigned short *)PORT2ADDR(port
) = w
;
330 void _outl_p(unsigned long l
, unsigned long port
)
332 *(volatile unsigned long *)PORT2ADDR(port
) = l
;
336 void _insb(unsigned int port
, void * addr
, unsigned long count
)
338 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
339 _ne_insb(PORT2ADDR_NE(port
), addr
, count
);
340 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
341 else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
342 unsigned char *buf
= addr
;
343 unsigned char *portp
= __port2addr_ata(port
);
345 *buf
++ = *(volatile unsigned char *)portp
;
348 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
349 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
350 pcc_ioread_byte(0, port
, (void *)addr
, sizeof(unsigned char),
355 unsigned char *buf
= addr
;
356 unsigned char *portp
= PORT2ADDR(port
);
358 *buf
++ = *(volatile unsigned char *)portp
;
362 void _insw(unsigned int port
, void * addr
, unsigned long count
)
364 unsigned short *buf
= addr
;
365 unsigned short *portp
;
367 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
368 portp
= PORT2ADDR_NE(port
);
370 *buf
++ = *(volatile unsigned short *)portp
;
371 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
372 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
373 pcc_ioread_word(9, port
, (void *)addr
, sizeof(unsigned short),
376 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
377 } else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
378 portp
= __port2addr_ata(port
);
380 *buf
++ = *(volatile unsigned short *)portp
;
383 portp
= PORT2ADDR(port
);
385 *buf
++ = *(volatile unsigned short *)portp
;
389 void _insl(unsigned int port
, void * addr
, unsigned long count
)
391 unsigned long *buf
= addr
;
392 unsigned long *portp
;
394 portp
= PORT2ADDR(port
);
396 *buf
++ = *(volatile unsigned long *)portp
;
399 void _outsb(unsigned int port
, const void * addr
, unsigned long count
)
401 const unsigned char *buf
= addr
;
402 unsigned char *portp
;
404 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
405 portp
= PORT2ADDR_NE(port
);
407 _ne_outb(*buf
++, portp
);
408 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
409 } else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
410 portp
= __port2addr_ata(port
);
412 *(volatile unsigned char *)portp
= *buf
++;
414 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
415 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
416 pcc_iowrite_byte(0, port
, (void *)addr
, sizeof(unsigned char),
420 portp
= PORT2ADDR(port
);
422 *(volatile unsigned char *)portp
= *buf
++;
426 void _outsw(unsigned int port
, const void * addr
, unsigned long count
)
428 const unsigned short *buf
= addr
;
429 unsigned short *portp
;
431 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
432 portp
= PORT2ADDR_NE(port
);
434 *(volatile unsigned short *)portp
= *buf
++;
435 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
436 } else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
437 portp
= __port2addr_ata(port
);
439 *(volatile unsigned short *)portp
= *buf
++;
441 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
442 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
443 pcc_iowrite_word(9, port
, (void *)addr
, sizeof(unsigned short),
447 portp
= PORT2ADDR(port
);
449 *(volatile unsigned short *)portp
= *buf
++;
453 void _outsl(unsigned int port
, const void * addr
, unsigned long count
)
455 const unsigned long *buf
= addr
;
456 unsigned char *portp
;
458 portp
= PORT2ADDR(port
);
460 *(volatile unsigned long *)portp
= *buf
++;