Linux 3.17-rc2
[linux/fpc-iii.git] / arch / m32r / platforms / usrv / io.c
blobf5e50d37badbe2666b238dd6c74e037f505b5f86
1 /*
2 * linux/arch/m32r/platforms/usrv/io.c
4 * Typical I/O routines for uServer 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.
15 #include <asm/m32r.h>
16 #include <asm/page.h>
17 #include <asm/io.h>
19 #include <linux/types.h>
20 #include "../../../../drivers/pcmcia/m32r_cfc.h"
22 extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
23 extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
24 extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
25 extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
26 #define CFC_IOSTART CFC_IOPORT_BASE
27 #define CFC_IOEND (CFC_IOSTART + (M32R_PCC_MAPSIZE * M32R_MAX_PCC) - 1)
29 #if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE)
30 #define UART0_REGSTART 0x04c20000
31 #define UART1_REGSTART 0x04c20100
32 #define UART_IOMAP_SIZE 8
33 #define UART0_IOSTART 0x3f8
34 #define UART0_IOEND (UART0_IOSTART + UART_IOMAP_SIZE - 1)
35 #define UART1_IOSTART 0x2f8
36 #define UART1_IOEND (UART1_IOSTART + UART_IOMAP_SIZE - 1)
37 #endif /* CONFIG_SERIAL_8250 || CONFIG_SERIAL_8250_MODULE */
39 #define PORT2ADDR(port) _port2addr(port)
41 static inline void *_port2addr(unsigned long port)
43 #if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE)
44 if (port >= UART0_IOSTART && port <= UART0_IOEND)
45 port = ((port - UART0_IOSTART) << 1) + UART0_REGSTART;
46 else if (port >= UART1_IOSTART && port <= UART1_IOEND)
47 port = ((port - UART1_IOSTART) << 1) + UART1_REGSTART;
48 #endif /* CONFIG_SERIAL_8250 || CONFIG_SERIAL_8250_MODULE */
49 return (void *)(port | (NONCACHE_OFFSET));
52 static inline void delay(void)
54 __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
57 unsigned char _inb(unsigned long port)
59 if (port >= CFC_IOSTART && port <= CFC_IOEND) {
60 unsigned char b;
61 pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
62 return b;
63 } else
64 return *(volatile unsigned char *)PORT2ADDR(port);
67 unsigned short _inw(unsigned long port)
69 if (port >= CFC_IOSTART && port <= CFC_IOEND) {
70 unsigned short w;
71 pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
72 return w;
73 } else
74 return *(volatile unsigned short *)PORT2ADDR(port);
77 unsigned long _inl(unsigned long port)
79 if (port >= CFC_IOSTART && port <= CFC_IOEND) {
80 unsigned long l;
81 pcc_ioread_word(0, port, &l, sizeof(l), 1, 0);
82 return l;
83 } else
84 return *(volatile unsigned long *)PORT2ADDR(port);
87 unsigned char _inb_p(unsigned long port)
89 unsigned char v = _inb(port);
90 delay();
91 return v;
94 unsigned short _inw_p(unsigned long port)
96 unsigned short v = _inw(port);
97 delay();
98 return v;
101 unsigned long _inl_p(unsigned long port)
103 unsigned long v = _inl(port);
104 delay();
105 return v;
108 void _outb(unsigned char b, unsigned long port)
110 if (port >= CFC_IOSTART && port <= CFC_IOEND)
111 pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
112 else
113 *(volatile unsigned char *)PORT2ADDR(port) = b;
116 void _outw(unsigned short w, unsigned long port)
118 if (port >= CFC_IOSTART && port <= CFC_IOEND)
119 pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
120 else
121 *(volatile unsigned short *)PORT2ADDR(port) = w;
124 void _outl(unsigned long l, unsigned long port)
126 if (port >= CFC_IOSTART && port <= CFC_IOEND)
127 pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
128 else
129 *(volatile unsigned long *)PORT2ADDR(port) = l;
132 void _outb_p(unsigned char b, unsigned long port)
134 _outb(b, port);
135 delay();
138 void _outw_p(unsigned short w, unsigned long port)
140 _outw(w, port);
141 delay();
144 void _outl_p(unsigned long l, unsigned long port)
146 _outl(l, port);
147 delay();
150 void _insb(unsigned int port, void * addr, unsigned long count)
152 if (port >= CFC_IOSTART && port <= CFC_IOEND)
153 pcc_ioread_byte(0, port, addr, sizeof(unsigned char), count, 1);
154 else {
155 unsigned char *buf = addr;
156 unsigned char *portp = PORT2ADDR(port);
157 while (count--)
158 *buf++ = *(volatile unsigned char *)portp;
162 void _insw(unsigned int port, void * addr, unsigned long count)
164 unsigned short *buf = addr;
165 unsigned short *portp;
167 if (port >= CFC_IOSTART && port <= CFC_IOEND)
168 pcc_ioread_word(0, port, addr, sizeof(unsigned short), count,
170 else {
171 portp = PORT2ADDR(port);
172 while (count--)
173 *buf++ = *(volatile unsigned short *)portp;
177 void _insl(unsigned int port, void * addr, unsigned long count)
179 unsigned long *buf = addr;
180 unsigned long *portp;
182 portp = PORT2ADDR(port);
183 while (count--)
184 *buf++ = *(volatile unsigned long *)portp;
187 void _outsb(unsigned int port, const void * addr, unsigned long count)
189 const unsigned char *buf = addr;
190 unsigned char *portp;
192 if (port >= CFC_IOSTART && port <= CFC_IOEND)
193 pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char),
194 count, 1);
195 else {
196 portp = PORT2ADDR(port);
197 while (count--)
198 *(volatile unsigned char *)portp = *buf++;
202 void _outsw(unsigned int port, const void * addr, unsigned long count)
204 const unsigned short *buf = addr;
205 unsigned short *portp;
207 if (port >= CFC_IOSTART && port <= CFC_IOEND)
208 pcc_iowrite_word(0, port, (void *)addr, sizeof(unsigned short),
209 count, 1);
210 else {
211 portp = PORT2ADDR(port);
212 while (count--)
213 *(volatile unsigned short *)portp = *buf++;
217 void _outsl(unsigned int port, const void * addr, unsigned long count)
219 const unsigned long *buf = addr;
220 unsigned char *portp;
222 portp = PORT2ADDR(port);
223 while (count--)
224 *(volatile unsigned long *)portp = *buf++;