2 * linux/arch/m32r/platforms/opsput/io.c
4 * Typical I/O routines for OPSPUT board.
6 * Copyright (c) 2001-2005 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.
17 #include <asm/byteorder.h>
19 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
20 #include <linux/types.h>
22 #define M32R_PCC_IOMAP_SIZE 0x1000
24 #define M32R_PCC_IOSTART0 0x1000
25 #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
27 extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
28 extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
29 extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
30 extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
31 #endif /* CONFIG_PCMCIA && CONFIG_M32R_CFC */
33 #define PORT2ADDR(port) _port2addr(port)
34 #define PORT2ADDR_USB(port) _port2addr_usb(port)
36 static inline void *_port2addr(unsigned long port)
38 return (void *)(port | NONCACHE_OFFSET);
41 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
42 static inline void *__port2addr_ata(unsigned long port)
47 case 0x1f0: return (void *)(0x0c002000 | NONCACHE_OFFSET);
48 case 0x1f1: return (void *)(0x0c012800 | NONCACHE_OFFSET);
49 case 0x1f2: return (void *)(0x0c012002 | NONCACHE_OFFSET);
50 case 0x1f3: return (void *)(0x0c012802 | NONCACHE_OFFSET);
51 case 0x1f4: return (void *)(0x0c012004 | NONCACHE_OFFSET);
52 case 0x1f5: return (void *)(0x0c012804 | NONCACHE_OFFSET);
53 case 0x1f6: return (void *)(0x0c012006 | NONCACHE_OFFSET);
54 case 0x1f7: return (void *)(0x0c012806 | NONCACHE_OFFSET);
55 case 0x3f6: return (void *)(0x0c01200e | NONCACHE_OFFSET);
56 default: return (void *)&dummy_reg;
62 * OPSPUT-LAN is located in the extended bus space
63 * from 0x10000000 to 0x13ffffff on physical address.
64 * The base address of LAN controller(LAN91C111) is 0x300.
66 #define LAN_IOSTART (0x300 | NONCACHE_OFFSET)
67 #define LAN_IOEND (0x320 | NONCACHE_OFFSET)
68 static inline void *_port2addr_ne(unsigned long port)
70 return (void *)(port + 0x10000000);
72 static inline void *_port2addr_usb(unsigned long port)
74 return (void *)((port & 0x0f) + NONCACHE_OFFSET + 0x10303000);
77 static inline void delay(void)
79 __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
86 #define PORT2ADDR_NE(port) _port2addr_ne(port)
88 static inline unsigned char _ne_inb(void *portp)
90 return *(volatile unsigned char *)portp;
93 static inline unsigned short _ne_inw(void *portp)
95 return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp);
98 static inline void _ne_insb(void *portp, void *addr, unsigned long count)
100 unsigned char *buf = (unsigned char *)addr;
103 *buf++ = _ne_inb(portp);
106 static inline void _ne_outb(unsigned char b, void *portp)
108 *(volatile unsigned char *)portp = b;
111 static inline void _ne_outw(unsigned short w, void *portp)
113 *(volatile unsigned short *)portp = cpu_to_le16(w);
116 unsigned char _inb(unsigned long port)
118 if (port >= LAN_IOSTART && port < LAN_IOEND)
119 return _ne_inb(PORT2ADDR_NE(port));
121 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
122 else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
123 return *(volatile unsigned char *)__port2addr_ata(port);
126 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
127 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
129 pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
134 return *(volatile unsigned char *)PORT2ADDR(port);
137 unsigned short _inw(unsigned long port)
139 if (port >= LAN_IOSTART && port < LAN_IOEND)
140 return _ne_inw(PORT2ADDR_NE(port));
141 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
142 else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
143 return *(volatile unsigned short *)__port2addr_ata(port);
146 #if defined(CONFIG_USB)
147 else if(port >= 0x340 && port < 0x3a0)
148 return *(volatile unsigned short *)PORT2ADDR_USB(port);
150 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
151 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
153 pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
157 return *(volatile unsigned short *)PORT2ADDR(port);
160 unsigned long _inl(unsigned long port)
162 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
163 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
165 pcc_ioread_word(0, port, &l, sizeof(l), 1, 0);
169 return *(volatile unsigned long *)PORT2ADDR(port);
172 unsigned char _inb_p(unsigned long port)
174 unsigned char v = _inb(port);
179 unsigned short _inw_p(unsigned long port)
181 unsigned short v = _inw(port);
186 unsigned long _inl_p(unsigned long port)
188 unsigned long v = _inl(port);
193 void _outb(unsigned char b, unsigned long port)
195 if (port >= LAN_IOSTART && port < LAN_IOEND)
196 _ne_outb(b, PORT2ADDR_NE(port));
198 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
199 if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
200 *(volatile unsigned char *)__port2addr_ata(port) = b;
203 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
204 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
205 pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
208 *(volatile unsigned char *)PORT2ADDR(port) = b;
211 void _outw(unsigned short w, unsigned long port)
213 if (port >= LAN_IOSTART && port < LAN_IOEND)
214 _ne_outw(w, PORT2ADDR_NE(port));
216 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
217 if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
218 *(volatile unsigned short *)__port2addr_ata(port) = w;
221 #if defined(CONFIG_USB)
222 if(port >= 0x340 && port < 0x3a0)
223 *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
226 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
227 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
228 pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
231 *(volatile unsigned short *)PORT2ADDR(port) = w;
234 void _outl(unsigned long l, unsigned long port)
236 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
237 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
238 pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
241 *(volatile unsigned long *)PORT2ADDR(port) = l;
244 void _outb_p(unsigned char b, unsigned long port)
250 void _outw_p(unsigned short w, unsigned long port)
256 void _outl_p(unsigned long l, unsigned long port)
262 void _insb(unsigned int port, void *addr, unsigned long count)
264 if (port >= LAN_IOSTART && port < LAN_IOEND)
265 _ne_insb(PORT2ADDR_NE(port), addr, count);
266 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
267 else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
268 unsigned char *buf = addr;
269 unsigned char *portp = __port2addr_ata(port);
271 *buf++ = *(volatile unsigned char *)portp;
274 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
275 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
276 pcc_ioread_byte(0, port, (void *)addr, sizeof(unsigned char),
281 unsigned char *buf = addr;
282 unsigned char *portp = PORT2ADDR(port);
284 *buf++ = *(volatile unsigned char *)portp;
288 void _insw(unsigned int port, void *addr, unsigned long count)
290 unsigned short *buf = addr;
291 unsigned short *portp;
293 if (port >= LAN_IOSTART && port < LAN_IOEND) {
295 * This portion is only used by smc91111.c to read data
296 * from the DATA_REG. Do not swap the data.
298 portp = PORT2ADDR_NE(port);
300 *buf++ = *(volatile unsigned short *)portp;
301 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
302 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
303 pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short),
306 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
307 } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
308 portp = __port2addr_ata(port);
310 *buf++ = *(volatile unsigned short *)portp;
313 portp = PORT2ADDR(port);
315 *buf++ = *(volatile unsigned short *)portp;
319 void _insl(unsigned int port, void *addr, unsigned long count)
321 unsigned long *buf = addr;
322 unsigned long *portp;
324 portp = PORT2ADDR(port);
326 *buf++ = *(volatile unsigned long *)portp;
329 void _outsb(unsigned int port, const void *addr, unsigned long count)
331 const unsigned char *buf = addr;
332 unsigned char *portp;
334 if (port >= LAN_IOSTART && port < LAN_IOEND) {
335 portp = PORT2ADDR_NE(port);
337 _ne_outb(*buf++, portp);
338 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
339 } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
340 portp = __port2addr_ata(port);
342 *(volatile unsigned char *)portp = *buf++;
344 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
345 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
346 pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char),
350 portp = PORT2ADDR(port);
352 *(volatile unsigned char *)portp = *buf++;
356 void _outsw(unsigned int port, const void *addr, unsigned long count)
358 const unsigned short *buf = addr;
359 unsigned short *portp;
361 if (port >= LAN_IOSTART && port < LAN_IOEND) {
363 * This portion is only used by smc91111.c to write data
364 * into the DATA_REG. Do not swap the data.
366 portp = PORT2ADDR_NE(port);
368 *(volatile unsigned short *)portp = *buf++;
369 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
370 } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
371 portp = __port2addr_ata(port);
373 *(volatile unsigned short *)portp = *buf++;
375 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
376 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
377 pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short),
381 portp = PORT2ADDR(port);
383 *(volatile unsigned short *)portp = *buf++;
387 void _outsl(unsigned int port, const void *addr, unsigned long count)
389 const unsigned long *buf = addr;
390 unsigned char *portp;
392 portp = PORT2ADDR(port);
394 *(volatile unsigned long *)portp = *buf++;