2 * linux/arch/m32r/kernel/io_m32104ut.c
4 * Typical I/O routines for M32104UT board.
6 * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata,
7 * Hitoshi Yamamoto, Mamoru Sakugawa,
8 * Naoto Sugai, Hayato Fujiwara
11 #include <linux/config.h>
15 #include <asm/byteorder.h>
17 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
18 #include <linux/types.h>
20 #define M32R_PCC_IOMAP_SIZE 0x1000
22 #define M32R_PCC_IOSTART0 0x1000
23 #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
25 extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
26 extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
27 extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
28 extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
29 #endif /* CONFIG_PCMCIA && CONFIG_M32R_CFC */
31 #define PORT2ADDR(port) _port2addr(port)
33 static inline void *_port2addr(unsigned long port)
35 return (void *)(port | NONCACHE_OFFSET);
38 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
39 static inline void *__port2addr_ata(unsigned long port)
44 case 0x1f0: return (void *)(0x0c002000 | NONCACHE_OFFSET);
45 case 0x1f1: return (void *)(0x0c012800 | NONCACHE_OFFSET);
46 case 0x1f2: return (void *)(0x0c012002 | NONCACHE_OFFSET);
47 case 0x1f3: return (void *)(0x0c012802 | NONCACHE_OFFSET);
48 case 0x1f4: return (void *)(0x0c012004 | NONCACHE_OFFSET);
49 case 0x1f5: return (void *)(0x0c012804 | NONCACHE_OFFSET);
50 case 0x1f6: return (void *)(0x0c012006 | NONCACHE_OFFSET);
51 case 0x1f7: return (void *)(0x0c012806 | NONCACHE_OFFSET);
52 case 0x3f6: return (void *)(0x0c01200e | NONCACHE_OFFSET);
53 default: return (void *)&dummy_reg;
59 * M32104T-LAN is located in the extended bus space
60 * from 0x01000000 to 0x01ffffff on physical address.
61 * The base address of LAN controller(LAN91C111) is 0x300.
63 #define LAN_IOSTART (0x300 | NONCACHE_OFFSET)
64 #define LAN_IOEND (0x320 | NONCACHE_OFFSET)
65 static inline void *_port2addr_ne(unsigned long port)
67 return (void *)(port + NONCACHE_OFFSET + 0x01000000);
70 static inline void delay(void)
72 __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
79 #define PORT2ADDR_NE(port) _port2addr_ne(port)
81 static inline unsigned char _ne_inb(void *portp)
83 return *(volatile unsigned char *)portp;
86 static inline unsigned short _ne_inw(void *portp)
88 return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp);
91 static inline void _ne_insb(void *portp, void *addr, unsigned long count)
93 unsigned char *buf = (unsigned char *)addr;
96 *buf++ = _ne_inb(portp);
99 static inline void _ne_outb(unsigned char b, void *portp)
101 *(volatile unsigned char *)portp = b;
104 static inline void _ne_outw(unsigned short w, void *portp)
106 *(volatile unsigned short *)portp = cpu_to_le16(w);
109 unsigned char _inb(unsigned long port)
111 if (port >= LAN_IOSTART && port < LAN_IOEND)
112 return _ne_inb(PORT2ADDR_NE(port));
114 return *(volatile unsigned char *)PORT2ADDR(port);
117 unsigned short _inw(unsigned long port)
119 if (port >= LAN_IOSTART && port < LAN_IOEND)
120 return _ne_inw(PORT2ADDR_NE(port));
122 return *(volatile unsigned short *)PORT2ADDR(port);
125 unsigned long _inl(unsigned long port)
127 return *(volatile unsigned long *)PORT2ADDR(port);
130 unsigned char _inb_p(unsigned long port)
132 unsigned char v = _inb(port);
137 unsigned short _inw_p(unsigned long port)
139 unsigned short v = _inw(port);
144 unsigned long _inl_p(unsigned long port)
146 unsigned long v = _inl(port);
151 void _outb(unsigned char b, unsigned long port)
153 if (port >= LAN_IOSTART && port < LAN_IOEND)
154 _ne_outb(b, PORT2ADDR_NE(port));
156 *(volatile unsigned char *)PORT2ADDR(port) = b;
159 void _outw(unsigned short w, unsigned long port)
161 if (port >= LAN_IOSTART && port < LAN_IOEND)
162 _ne_outw(w, PORT2ADDR_NE(port));
164 *(volatile unsigned short *)PORT2ADDR(port) = w;
167 void _outl(unsigned long l, unsigned long port)
169 *(volatile unsigned long *)PORT2ADDR(port) = l;
172 void _outb_p(unsigned char b, unsigned long port)
178 void _outw_p(unsigned short w, unsigned long port)
184 void _outl_p(unsigned long l, unsigned long port)
190 void _insb(unsigned int port, void *addr, unsigned long count)
192 if (port >= LAN_IOSTART && port < LAN_IOEND)
193 _ne_insb(PORT2ADDR_NE(port), addr, count);
195 unsigned char *buf = addr;
196 unsigned char *portp = PORT2ADDR(port);
198 *buf++ = *(volatile unsigned char *)portp;
202 void _insw(unsigned int port, void *addr, unsigned long count)
204 unsigned short *buf = addr;
205 unsigned short *portp;
207 if (port >= LAN_IOSTART && port < LAN_IOEND) {
209 * This portion is only used by smc91111.c to read data
210 * from the DATA_REG. Do not swap the data.
212 portp = PORT2ADDR_NE(port);
214 *buf++ = *(volatile unsigned short *)portp;
215 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
216 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
217 pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short),
220 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
221 } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
222 portp = __port2addr_ata(port);
224 *buf++ = *(volatile unsigned short *)portp;
227 portp = PORT2ADDR(port);
229 *buf++ = *(volatile unsigned short *)portp;
233 void _insl(unsigned int port, void *addr, unsigned long count)
235 unsigned long *buf = addr;
236 unsigned long *portp;
238 portp = PORT2ADDR(port);
240 *buf++ = *(volatile unsigned long *)portp;
243 void _outsb(unsigned int port, const void *addr, unsigned long count)
245 const unsigned char *buf = addr;
246 unsigned char *portp;
248 if (port >= LAN_IOSTART && port < LAN_IOEND) {
249 portp = PORT2ADDR_NE(port);
251 _ne_outb(*buf++, portp);
253 portp = PORT2ADDR(port);
255 *(volatile unsigned char *)portp = *buf++;
259 void _outsw(unsigned int port, const void *addr, unsigned long count)
261 const unsigned short *buf = addr;
262 unsigned short *portp;
264 if (port >= LAN_IOSTART && port < LAN_IOEND) {
266 * This portion is only used by smc91111.c to write data
267 * into the DATA_REG. Do not swap the data.
269 portp = PORT2ADDR_NE(port);
271 *(volatile unsigned short *)portp = *buf++;
272 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
273 } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
274 portp = __port2addr_ata(port);
276 *(volatile unsigned short *)portp = *buf++;
278 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
279 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
280 pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short),
284 portp = PORT2ADDR(port);
286 *(volatile unsigned short *)portp = *buf++;
290 void _outsl(unsigned int port, const void *addr, unsigned long count)
292 const unsigned long *buf = addr;
293 unsigned char *portp;
295 portp = PORT2ADDR(port);
297 *(volatile unsigned long *)portp = *buf++;