2 * linux/arch/m32r/platforms/mappi3/io.c
4 * Typical I/O routines for Mappi3 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)
39 static inline void *__port2addr_ata(unsigned long port
)
45 case 0x1f0: return (void *)(0x14002000 | NONCACHE_OFFSET
);
46 case 0x1f1: return (void *)(0x14012800 | NONCACHE_OFFSET
);
47 case 0x1f2: return (void *)(0x14012002 | NONCACHE_OFFSET
);
48 case 0x1f3: return (void *)(0x14012802 | NONCACHE_OFFSET
);
49 case 0x1f4: return (void *)(0x14012004 | NONCACHE_OFFSET
);
50 case 0x1f5: return (void *)(0x14012804 | NONCACHE_OFFSET
);
51 case 0x1f6: return (void *)(0x14012006 | NONCACHE_OFFSET
);
52 case 0x1f7: return (void *)(0x14012806 | NONCACHE_OFFSET
);
53 case 0x3f6: return (void *)(0x1401200e | NONCACHE_OFFSET
);
55 case 0x170: /* Data 16bit */
56 return (void *)(0x14810000 | NONCACHE_OFFSET
);
57 case 0x171: /* Features / Error */
58 return (void *)(0x14810002 | NONCACHE_OFFSET
);
59 case 0x172: /* Sector count */
60 return (void *)(0x14810004 | NONCACHE_OFFSET
);
61 case 0x173: /* Sector number */
62 return (void *)(0x14810006 | NONCACHE_OFFSET
);
63 case 0x174: /* Cylinder low */
64 return (void *)(0x14810008 | NONCACHE_OFFSET
);
65 case 0x175: /* Cylinder high */
66 return (void *)(0x1481000a | NONCACHE_OFFSET
);
67 case 0x176: /* Device head */
68 return (void *)(0x1481000c | NONCACHE_OFFSET
);
69 case 0x177: /* Command */
70 return (void *)(0x1481000e | NONCACHE_OFFSET
);
71 case 0x376: /* Device control / Alt status */
72 return (void *)(0x1480800c | NONCACHE_OFFSET
);
74 default: return (void *)&dummy_reg
;
79 #define LAN_IOSTART (0x300 | NONCACHE_OFFSET)
80 #define LAN_IOEND (0x320 | NONCACHE_OFFSET)
81 static inline void *_port2addr_ne(unsigned long port
)
83 return (void *)(port
+ 0x10000000);
86 static inline void *_port2addr_usb(unsigned long port
)
88 return (void *)(port
+ NONCACHE_OFFSET
+ 0x12000000);
90 static inline void delay(void)
92 __asm__
__volatile__ ("push r0; \n\t pop r0;" : : :"memory");
99 static inline unsigned char _ne_inb(void *portp
)
101 return (unsigned char) *(volatile unsigned char *)portp
;
104 static inline unsigned short _ne_inw(void *portp
)
106 return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp
);
109 static inline void _ne_insb(void *portp
, void * addr
, unsigned long count
)
111 unsigned char *buf
= addr
;
114 *buf
++ = *(volatile unsigned char *)portp
;
117 static inline void _ne_outb(unsigned char b
, void *portp
)
119 *(volatile unsigned char *)portp
= (unsigned char)b
;
122 static inline void _ne_outw(unsigned short w
, void *portp
)
124 *(volatile unsigned short *)portp
= cpu_to_le16(w
);
127 unsigned char _inb(unsigned long port
)
129 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
130 return _ne_inb(PORT2ADDR_NE(port
));
131 #if defined(CONFIG_IDE)
132 else if ( ((port
>= 0x170 && port
<=0x177) || port
== 0x376) ||
133 ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) ){
134 return *(volatile unsigned char *)__port2addr_ata(port
);
137 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
138 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
140 pcc_ioread_byte(0, port
, &b
, sizeof(b
), 1, 0);
144 return *(volatile unsigned char *)PORT2ADDR(port
);
147 unsigned short _inw(unsigned long port
)
149 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
150 return _ne_inw(PORT2ADDR_NE(port
));
151 #if defined(CONFIG_IDE)
152 else if ( ((port
>= 0x170 && port
<=0x177) || port
== 0x376) ||
153 ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) ){
154 return *(volatile unsigned short *)__port2addr_ata(port
);
157 #if defined(CONFIG_USB)
158 else if (port
>= 0x340 && port
< 0x3a0)
159 return *(volatile unsigned short *)PORT2ADDR_USB(port
);
162 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
163 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
165 pcc_ioread_word(0, port
, &w
, sizeof(w
), 1, 0);
169 return *(volatile unsigned short *)PORT2ADDR(port
);
172 unsigned long _inl(unsigned long port
)
174 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
175 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
177 pcc_ioread_word(0, port
, &l
, sizeof(l
), 1, 0);
181 return *(volatile unsigned long *)PORT2ADDR(port
);
184 unsigned char _inb_p(unsigned long port
)
186 unsigned char v
= _inb(port
);
191 unsigned short _inw_p(unsigned long port
)
193 unsigned short v
= _inw(port
);
198 unsigned long _inl_p(unsigned long port
)
200 unsigned long v
= _inl(port
);
205 void _outb(unsigned char b
, unsigned long port
)
207 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
208 _ne_outb(b
, PORT2ADDR_NE(port
));
210 #if defined(CONFIG_IDE)
211 if ( ((port
>= 0x170 && port
<=0x177) || port
== 0x376) ||
212 ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) ){
213 *(volatile unsigned char *)__port2addr_ata(port
) = b
;
216 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
217 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
218 pcc_iowrite_byte(0, port
, &b
, sizeof(b
), 1, 0);
221 *(volatile unsigned char *)PORT2ADDR(port
) = b
;
224 void _outw(unsigned short w
, unsigned long port
)
226 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
227 _ne_outw(w
, PORT2ADDR_NE(port
));
229 #if defined(CONFIG_IDE)
230 if ( ((port
>= 0x170 && port
<=0x177) || port
== 0x376) ||
231 ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) ){
232 *(volatile unsigned short *)__port2addr_ata(port
) = w
;
235 #if defined(CONFIG_USB)
236 if (port
>= 0x340 && port
< 0x3a0)
237 *(volatile unsigned short *)PORT2ADDR_USB(port
) = w
;
240 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
241 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
242 pcc_iowrite_word(0, port
, &w
, sizeof(w
), 1, 0);
245 *(volatile unsigned short *)PORT2ADDR(port
) = w
;
248 void _outl(unsigned long l
, unsigned long port
)
250 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
251 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
252 pcc_iowrite_word(0, port
, &l
, sizeof(l
), 1, 0);
255 *(volatile unsigned long *)PORT2ADDR(port
) = l
;
258 void _outb_p(unsigned char b
, unsigned long port
)
264 void _outw_p(unsigned short w
, unsigned long port
)
270 void _outl_p(unsigned long l
, unsigned long port
)
276 void _insb(unsigned int port
, void * addr
, unsigned long count
)
278 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
279 _ne_insb(PORT2ADDR_NE(port
), addr
, count
);
280 #if defined(CONFIG_IDE)
281 else if ( ((port
>= 0x170 && port
<=0x177) || port
== 0x376) ||
282 ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) ){
283 unsigned char *buf
= addr
;
284 unsigned char *portp
= __port2addr_ata(port
);
286 *buf
++ = *(volatile unsigned char *)portp
;
289 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
290 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
291 pcc_ioread_byte(0, port
, (void *)addr
, sizeof(unsigned char),
296 unsigned char *buf
= addr
;
297 unsigned char *portp
= PORT2ADDR(port
);
299 *buf
++ = *(volatile unsigned char *)portp
;
303 void _insw(unsigned int port
, void * addr
, unsigned long count
)
305 unsigned short *buf
= addr
;
306 unsigned short *portp
;
308 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
309 portp
= PORT2ADDR_NE(port
);
311 *buf
++ = *(volatile unsigned short *)portp
;
312 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
313 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
314 pcc_ioread_word(9, port
, (void *)addr
, sizeof(unsigned short),
317 #if defined(CONFIG_IDE)
318 } else if ( ((port
>= 0x170 && port
<=0x177) || port
== 0x376) ||
319 ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) ){
320 portp
= __port2addr_ata(port
);
322 *buf
++ = *(volatile unsigned short *)portp
;
325 portp
= PORT2ADDR(port
);
327 *buf
++ = *(volatile unsigned short *)portp
;
331 void _insl(unsigned int port
, void * addr
, unsigned long count
)
333 unsigned long *buf
= addr
;
334 unsigned long *portp
;
336 portp
= PORT2ADDR(port
);
338 *buf
++ = *(volatile unsigned long *)portp
;
341 void _outsb(unsigned int port
, const void * addr
, unsigned long count
)
343 const unsigned char *buf
= addr
;
344 unsigned char *portp
;
346 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
347 portp
= PORT2ADDR_NE(port
);
349 _ne_outb(*buf
++, portp
);
350 #if defined(CONFIG_IDE)
351 } else if ( ((port
>= 0x170 && port
<=0x177) || port
== 0x376) ||
352 ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) ){
353 portp
= __port2addr_ata(port
);
355 *(volatile unsigned char *)portp
= *buf
++;
357 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
358 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
359 pcc_iowrite_byte(0, port
, (void *)addr
, sizeof(unsigned char),
363 portp
= PORT2ADDR(port
);
365 *(volatile unsigned char *)portp
= *buf
++;
369 void _outsw(unsigned int port
, const void * addr
, unsigned long count
)
371 const unsigned short *buf
= addr
;
372 unsigned short *portp
;
374 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
375 portp
= PORT2ADDR_NE(port
);
377 *(volatile unsigned short *)portp
= *buf
++;
378 #if defined(CONFIG_IDE)
379 } else if ( ((port
>= 0x170 && port
<=0x177) || port
== 0x376) ||
380 ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) ){
381 portp
= __port2addr_ata(port
);
383 *(volatile unsigned short *)portp
= *buf
++;
385 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
386 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
387 pcc_iowrite_word(9, port
, (void *)addr
, sizeof(unsigned short),
391 portp
= PORT2ADDR(port
);
393 *(volatile unsigned short *)portp
= *buf
++;
397 void _outsl(unsigned int port
, const void * addr
, unsigned long count
)
399 const unsigned long *buf
= addr
;
400 unsigned char *portp
;
402 portp
= PORT2ADDR(port
);
404 *(volatile unsigned long *)portp
= *buf
++;