2 * linux/arch/m32r/kernel/io_m32700ut.c
4 * Typical I/O routines for M32700UT board.
6 * Copyright (c) 2001, 2002 Hiroyuki Kondo, Hirokazu Takata,
7 * Hitoshi Yamamoto, Takeo Takahashi
9 * This file is subject to the terms and conditions of the GNU General
10 * Public License. See the file "COPYING" in the main directory of this
11 * archive for more details.
14 #include <linux/config.h>
18 #include <asm/byteorder.h>
20 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
21 #include <linux/types.h>
23 #define M32R_PCC_IOMAP_SIZE 0x1000
25 #define M32R_PCC_IOSTART0 0x1000
26 #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
28 extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
29 extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
30 extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
31 extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
32 #endif /* CONFIG_PCMCIA && CONFIG_M32R_CFC */
34 #define PORT2ADDR(port) _port2addr(port)
35 #define PORT2ADDR_USB(port) _port2addr_usb(port)
37 static inline void *_port2addr(unsigned long port
)
39 return (void *)(port
+ NONCACHE_OFFSET
);
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
;
63 * M32700UT-LAN is located in the extended bus space
64 * from 0x10000000 to 0x13ffffff on physical address.
65 * The base address of LAN controller(LAN91C111) is 0x300.
67 #define LAN_IOSTART 0x300
68 #define LAN_IOEND 0x320
69 static inline void *_port2addr_ne(unsigned long port
)
71 return (void *)(port
+ NONCACHE_OFFSET
+ 0x10000000);
73 static inline void *_port2addr_usb(unsigned long port
)
75 return (void *)((port
& 0x0f) + NONCACHE_OFFSET
+ 0x10303000);
78 static inline void delay(void)
80 __asm__
__volatile__ ("push r0; \n\t pop r0;" : : :"memory");
87 #define PORT2ADDR_NE(port) _port2addr_ne(port)
89 static inline unsigned char _ne_inb(void *portp
)
91 return *(volatile unsigned char *)portp
;
94 static inline unsigned short _ne_inw(void *portp
)
96 return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp
);
99 static inline void _ne_insb(void *portp
, void *addr
, unsigned long count
)
101 unsigned char *buf
= (unsigned char *)addr
;
104 *buf
++ = _ne_inb(portp
);
107 static inline void _ne_outb(unsigned char b
, void *portp
)
109 *(volatile unsigned char *)portp
= b
;
112 static inline void _ne_outw(unsigned short w
, void *portp
)
114 *(volatile unsigned short *)portp
= cpu_to_le16(w
);
117 unsigned char _inb(unsigned long port
)
119 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
120 return _ne_inb(PORT2ADDR_NE(port
));
122 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
123 else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
124 return *(volatile unsigned char *)__port2addr_ata(port
);
127 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
128 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
130 pcc_ioread_byte(0, port
, &b
, sizeof(b
), 1, 0);
135 return *(volatile unsigned char *)PORT2ADDR(port
);
138 unsigned short _inw(unsigned long port
)
140 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
141 return _ne_inw(PORT2ADDR_NE(port
));
142 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
143 else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
144 return *(volatile unsigned short *)__port2addr_ata(port
);
147 #if defined(CONFIG_USB)
148 else if(port
>= 0x340 && port
< 0x3a0)
149 return *(volatile unsigned short *)PORT2ADDR_USB(port
);
151 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
152 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
154 pcc_ioread_word(0, port
, &w
, sizeof(w
), 1, 0);
158 return *(volatile unsigned short *)PORT2ADDR(port
);
161 unsigned long _inl(unsigned long port
)
163 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
164 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
166 pcc_ioread_word(0, port
, &l
, sizeof(l
), 1, 0);
170 return *(volatile unsigned long *)PORT2ADDR(port
);
173 unsigned char _inb_p(unsigned long port
)
177 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
178 v
= _ne_inb(PORT2ADDR_NE(port
));
180 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
181 if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
182 return *(volatile unsigned char *)__port2addr_ata(port
);
185 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
186 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
188 pcc_ioread_byte(0, port
, &b
, sizeof(b
), 1, 0);
192 v
= *(volatile unsigned char *)PORT2ADDR(port
);
198 unsigned short _inw_p(unsigned long port
)
202 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
203 v
= _ne_inw(PORT2ADDR_NE(port
));
205 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
206 if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
207 return *(volatile unsigned short *)__port2addr_ata(port
);
210 #if defined(CONFIG_USB)
211 if(port
>= 0x340 && port
< 0x3a0)
212 return *(volatile unsigned short *)PORT2ADDR_USB(port
);
215 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
216 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
218 pcc_ioread_word(0, port
, &w
, sizeof(w
), 1, 0);
222 v
= *(volatile unsigned short *)PORT2ADDR(port
);
228 unsigned long _inl_p(unsigned long port
)
232 v
= *(volatile unsigned long *)PORT2ADDR(port
);
237 void _outb(unsigned char b
, unsigned long port
)
239 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
240 _ne_outb(b
, PORT2ADDR_NE(port
));
242 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
243 if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
244 *(volatile unsigned char *)__port2addr_ata(port
) = b
;
247 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
248 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
249 pcc_iowrite_byte(0, port
, &b
, sizeof(b
), 1, 0);
252 *(volatile unsigned char *)PORT2ADDR(port
) = b
;
255 void _outw(unsigned short w
, unsigned long port
)
257 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
258 _ne_outw(w
, PORT2ADDR_NE(port
));
260 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
261 if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
262 *(volatile unsigned short *)__port2addr_ata(port
) = w
;
265 #if defined(CONFIG_USB)
266 if(port
>= 0x340 && port
< 0x3a0)
267 *(volatile unsigned short *)PORT2ADDR_USB(port
) = w
;
270 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
271 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
272 pcc_iowrite_word(0, port
, &w
, sizeof(w
), 1, 0);
275 *(volatile unsigned short *)PORT2ADDR(port
) = w
;
278 void _outl(unsigned long l
, unsigned long port
)
280 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
281 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
282 pcc_iowrite_word(0, port
, &l
, sizeof(l
), 1, 0);
285 *(volatile unsigned long *)PORT2ADDR(port
) = l
;
288 void _outb_p(unsigned char b
, unsigned long port
)
290 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
291 _ne_outb(b
, PORT2ADDR_NE(port
));
293 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
294 if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
295 *(volatile unsigned char *)__port2addr_ata(port
) = b
;
298 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
299 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
300 pcc_iowrite_byte(0, port
, &b
, sizeof(b
), 1, 0);
303 *(volatile unsigned char *)PORT2ADDR(port
) = b
;
308 void _outw_p(unsigned short w
, unsigned long port
)
310 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
311 _ne_outw(w
, PORT2ADDR_NE(port
));
313 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
314 if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
315 *(volatile unsigned short *)__port2addr_ata(port
) = w
;
318 #if defined(CONFIG_USB)
319 if(port
>= 0x340 && port
< 0x3a0)
320 *(volatile unsigned short *)PORT2ADDR_USB(port
) = w
;
323 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
324 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
325 pcc_iowrite_word(0, port
, &w
, sizeof(w
), 1, 0);
328 *(volatile unsigned short *)PORT2ADDR(port
) = w
;
333 void _outl_p(unsigned long l
, unsigned long port
)
335 *(volatile unsigned long *)PORT2ADDR(port
) = l
;
339 void _insb(unsigned int port
, void *addr
, unsigned long count
)
341 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
342 _ne_insb(PORT2ADDR_NE(port
), addr
, count
);
343 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
344 else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
345 unsigned char *buf
= addr
;
346 unsigned char *portp
= __port2addr_ata(port
);
348 *buf
++ = *(volatile unsigned char *)portp
;
351 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
352 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
353 pcc_ioread_byte(0, port
, (void *)addr
, sizeof(unsigned char),
358 unsigned char *buf
= addr
;
359 unsigned char *portp
= PORT2ADDR(port
);
361 *buf
++ = *(volatile unsigned char *)portp
;
365 void _insw(unsigned int port
, void *addr
, unsigned long count
)
367 unsigned short *buf
= addr
;
368 unsigned short *portp
;
370 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
372 * This portion is only used by smc91111.c to read data
373 * from the DATA_REG. Do not swap the data.
375 portp
= PORT2ADDR_NE(port
);
377 *buf
++ = *(volatile unsigned short *)portp
;
378 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
379 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
380 pcc_ioread_word(9, port
, (void *)addr
, sizeof(unsigned short),
383 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
384 } else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
385 portp
= __port2addr_ata(port
);
387 *buf
++ = *(volatile unsigned short *)portp
;
390 portp
= PORT2ADDR(port
);
392 *buf
++ = *(volatile unsigned short *)portp
;
396 void _insl(unsigned int port
, void *addr
, unsigned long count
)
398 unsigned long *buf
= addr
;
399 unsigned long *portp
;
401 portp
= PORT2ADDR(port
);
403 *buf
++ = *(volatile unsigned long *)portp
;
406 void _outsb(unsigned int port
, const void *addr
, unsigned long count
)
408 const unsigned char *buf
= addr
;
409 unsigned char *portp
;
411 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
412 portp
= PORT2ADDR_NE(port
);
414 _ne_outb(*buf
++, portp
);
415 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
416 } else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
417 portp
= __port2addr_ata(port
);
419 *(volatile unsigned char *)portp
= *buf
++;
421 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
422 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
423 pcc_iowrite_byte(0, port
, (void *)addr
, sizeof(unsigned char),
427 portp
= PORT2ADDR(port
);
429 *(volatile unsigned char *)portp
= *buf
++;
433 void _outsw(unsigned int port
, const void *addr
, unsigned long count
)
435 const unsigned short *buf
= addr
;
436 unsigned short *portp
;
438 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
440 * This portion is only used by smc91111.c to write data
441 * into the DATA_REG. Do not swap the data.
443 portp
= PORT2ADDR_NE(port
);
445 *(volatile unsigned short *)portp
= *buf
++;
446 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
447 } else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
448 portp
= __port2addr_ata(port
);
450 *(volatile unsigned short *)portp
= *buf
++;
452 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
453 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
454 pcc_iowrite_word(9, port
, (void *)addr
, sizeof(unsigned short),
458 portp
= PORT2ADDR(port
);
460 *(volatile unsigned short *)portp
= *buf
++;
464 void _outsl(unsigned int port
, const void *addr
, unsigned long count
)
466 const unsigned long *buf
= addr
;
467 unsigned char *portp
;
469 portp
= PORT2ADDR(port
);
471 *(volatile unsigned long *)portp
= *buf
++;