2 * linux/arch/m32r/kernel/io_mappi.c
4 * Typical I/O routines for Mappi board.
6 * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata,
10 #include <linux/config.h>
14 #include <asm/byteorder.h>
16 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
17 #include <linux/types.h>
19 #define M32R_PCC_IOMAP_SIZE 0x1000
21 #define M32R_PCC_IOSTART0 0x1000
22 #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
23 #define M32R_PCC_IOSTART1 0x2000
24 #define M32R_PCC_IOEND1 (M32R_PCC_IOSTART1 + M32R_PCC_IOMAP_SIZE - 1)
26 extern void pcc_ioread(int, unsigned long, void *, size_t, size_t, int);
27 extern void pcc_iowrite(int, unsigned long, void *, size_t, size_t, int);
28 #endif /* CONFIG_PCMCIA && CONFIG_M32R_PCC */
30 #define PORT2ADDR(port) _port2addr(port)
32 static inline void *_port2addr(unsigned long port)
34 return (void *)(port + NONCACHE_OFFSET);
37 static inline void *_port2addr_ne(unsigned long port)
39 return (void *)((port<<1) + NONCACHE_OFFSET + 0x0C000000);
42 static inline void delay(void)
44 __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
51 #define PORT2ADDR_NE(port) _port2addr_ne(port)
53 static inline unsigned char _ne_inb(void *portp)
55 return (unsigned char) *(volatile unsigned short *)portp;
58 static inline unsigned short _ne_inw(void *portp)
62 tmp = *(volatile unsigned short *)portp;
63 return le16_to_cpu(tmp);
66 static inline void _ne_outb(unsigned char b, void *portp)
68 *(volatile unsigned short *)portp = (unsigned short)b;
71 static inline void _ne_outw(unsigned short w, void *portp)
73 *(volatile unsigned short *)portp = cpu_to_le16(w);
76 unsigned char _inb(unsigned long port)
78 if (port >= 0x300 && port < 0x320)
79 return _ne_inb(PORT2ADDR_NE(port));
81 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
82 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
84 pcc_ioread(0, port, &b, sizeof(b), 1, 0);
86 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
88 pcc_ioread(1, port, &b, sizeof(b), 1, 0);
93 return *(volatile unsigned char *)PORT2ADDR(port);
96 unsigned short _inw(unsigned long port)
98 if (port >= 0x300 && port < 0x320)
99 return _ne_inw(PORT2ADDR_NE(port));
101 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
102 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
104 pcc_ioread(0, port, &w, sizeof(w), 1, 0);
106 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
108 pcc_ioread(1, port, &w, sizeof(w), 1, 0);
112 return *(volatile unsigned short *)PORT2ADDR(port);
115 unsigned long _inl(unsigned long port)
117 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
118 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
120 pcc_ioread(0, port, &l, sizeof(l), 1, 0);
122 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
124 pcc_ioread(1, port, &l, sizeof(l), 1, 0);
128 return *(volatile unsigned long *)PORT2ADDR(port);
131 unsigned char _inb_p(unsigned long port)
133 unsigned char v = _inb(port);
138 unsigned short _inw_p(unsigned long port)
140 unsigned short v = _inw(port);
145 unsigned long _inl_p(unsigned long port)
147 unsigned long v = _inl(port);
152 void _outb(unsigned char b, unsigned long port)
154 if (port >= 0x300 && port < 0x320)
155 _ne_outb(b, PORT2ADDR_NE(port));
157 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
158 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
159 pcc_iowrite(0, port, &b, sizeof(b), 1, 0);
160 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
161 pcc_iowrite(1, port, &b, sizeof(b), 1, 0);
164 *(volatile unsigned char *)PORT2ADDR(port) = b;
167 void _outw(unsigned short w, unsigned long port)
169 if (port >= 0x300 && port < 0x320)
170 _ne_outw(w, PORT2ADDR_NE(port));
172 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
173 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
174 pcc_iowrite(0, port, &w, sizeof(w), 1, 0);
175 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
176 pcc_iowrite(1, port, &w, sizeof(w), 1, 0);
179 *(volatile unsigned short *)PORT2ADDR(port) = w;
182 void _outl(unsigned long l, unsigned long port)
184 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
185 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
186 pcc_iowrite(0, port, &l, sizeof(l), 1, 0);
187 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
188 pcc_iowrite(1, port, &l, sizeof(l), 1, 0);
191 *(volatile unsigned long *)PORT2ADDR(port) = l;
194 void _outb_p(unsigned char b, unsigned long port)
200 void _outw_p(unsigned short w, unsigned long port)
206 void _outl_p(unsigned long l, unsigned long port)
212 void _insb(unsigned int port, void *addr, unsigned long count)
214 unsigned short *buf = addr;
215 unsigned short *portp;
217 if (port >= 0x300 && port < 0x320){
218 portp = PORT2ADDR_NE(port);
220 *buf++ = *(volatile unsigned char *)portp;
221 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
222 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
223 pcc_ioread(0, port, (void *)addr, sizeof(unsigned char),
225 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
226 pcc_ioread(1, port, (void *)addr, sizeof(unsigned char),
230 portp = PORT2ADDR(port);
232 *buf++ = *(volatile unsigned char *)portp;
236 void _insw(unsigned int port, void *addr, unsigned long count)
238 unsigned short *buf = addr;
239 unsigned short *portp;
241 if (port >= 0x300 && port < 0x320) {
242 portp = PORT2ADDR_NE(port);
244 *buf++ = _ne_inw(portp);
245 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
246 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
247 pcc_ioread(0, port, (void *)addr, sizeof(unsigned short),
249 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
250 pcc_ioread(1, port, (void *)addr, sizeof(unsigned short),
254 portp = PORT2ADDR(port);
256 *buf++ = *(volatile unsigned short *)portp;
260 void _insl(unsigned int port, void *addr, unsigned long count)
262 unsigned long *buf = addr;
263 unsigned long *portp;
265 portp = PORT2ADDR(port);
267 *buf++ = *(volatile unsigned long *)portp;
270 void _outsb(unsigned int port, const void *addr, unsigned long count)
272 const unsigned char *buf = addr;
273 unsigned char *portp;
275 if (port >= 0x300 && port < 0x320) {
276 portp = PORT2ADDR_NE(port);
278 _ne_outb(*buf++, portp);
279 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
280 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
281 pcc_iowrite(0, port, (void *)addr, sizeof(unsigned char),
283 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
284 pcc_iowrite(1, port, (void *)addr, sizeof(unsigned char),
288 portp = PORT2ADDR(port);
290 *(volatile unsigned char *)portp = *buf++;
294 void _outsw(unsigned int port, const void *addr, unsigned long count)
296 const unsigned short *buf = addr;
297 unsigned short *portp;
299 if (port >= 0x300 && port < 0x320) {
300 portp = PORT2ADDR_NE(port);
302 _ne_outw(*buf++, portp);
303 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
304 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
305 pcc_iowrite(0, port, (void *)addr, sizeof(unsigned short),
307 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
308 pcc_iowrite(1, port, (void *)addr, sizeof(unsigned short),
312 portp = PORT2ADDR(port);
314 *(volatile unsigned short *)portp = *buf++;
318 void _outsl(unsigned int port, const void *addr, unsigned long count)
320 const unsigned long *buf = addr;
321 unsigned char *portp;
323 portp = PORT2ADDR(port);
325 *(volatile unsigned long *)portp = *buf++;