2 * linux/arch/m32r/kernel/io_mappi.c
4 * Typical I/O routines for Mappi board.
6 * Copyright (c) 2001, 2002 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
)
135 if (port
>= 0x300 && port
< 0x320)
136 v
= _ne_inb(PORT2ADDR_NE(port
));
138 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
139 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
141 pcc_ioread(0, port
, &b
, sizeof(b
), 1, 0);
143 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
145 pcc_ioread(1, port
, &b
, sizeof(b
), 1, 0);
149 v
= *(volatile unsigned char *)PORT2ADDR(port
);
155 unsigned short _inw_p(unsigned long port
)
159 if (port
>= 0x300 && port
< 0x320)
160 v
= _ne_inw(PORT2ADDR_NE(port
));
162 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
163 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
165 pcc_ioread(0, port
, &w
, sizeof(w
), 1, 0);
167 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
169 pcc_ioread(1, port
, &w
, sizeof(w
), 1, 0);
173 v
= *(volatile unsigned short *)PORT2ADDR(port
);
179 unsigned long _inl_p(unsigned long port
)
183 v
= *(volatile unsigned long *)PORT2ADDR(port
);
188 void _outb(unsigned char b
, unsigned long port
)
190 if (port
>= 0x300 && port
< 0x320)
191 _ne_outb(b
, PORT2ADDR_NE(port
));
193 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
194 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
195 pcc_iowrite(0, port
, &b
, sizeof(b
), 1, 0);
196 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
197 pcc_iowrite(1, port
, &b
, sizeof(b
), 1, 0);
200 *(volatile unsigned char *)PORT2ADDR(port
) = b
;
203 void _outw(unsigned short w
, unsigned long port
)
205 if (port
>= 0x300 && port
< 0x320)
206 _ne_outw(w
, PORT2ADDR_NE(port
));
208 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
209 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
210 pcc_iowrite(0, port
, &w
, sizeof(w
), 1, 0);
211 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
212 pcc_iowrite(1, port
, &w
, sizeof(w
), 1, 0);
215 *(volatile unsigned short *)PORT2ADDR(port
) = w
;
218 void _outl(unsigned long l
, unsigned long port
)
220 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
221 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
222 pcc_iowrite(0, port
, &l
, sizeof(l
), 1, 0);
223 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
224 pcc_iowrite(1, port
, &l
, sizeof(l
), 1, 0);
227 *(volatile unsigned long *)PORT2ADDR(port
) = l
;
230 void _outb_p(unsigned char b
, unsigned long port
)
232 if (port
>= 0x300 && port
< 0x320)
233 _ne_outb(b
, PORT2ADDR_NE(port
));
235 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
236 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
237 pcc_iowrite(0, port
, &b
, sizeof(b
), 1, 0);
238 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
239 pcc_iowrite(1, port
, &b
, sizeof(b
), 1, 0);
242 *(volatile unsigned char *)PORT2ADDR(port
) = b
;
247 void _outw_p(unsigned short w
, unsigned long port
)
249 if (port
>= 0x300 && port
< 0x320)
250 _ne_outw(w
, PORT2ADDR_NE(port
));
252 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
253 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
254 pcc_iowrite(0, port
, &w
, sizeof(w
), 1, 0);
255 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
256 pcc_iowrite(1, port
, &w
, sizeof(w
), 1, 0);
259 *(volatile unsigned short *)PORT2ADDR(port
) = w
;
264 void _outl_p(unsigned long l
, unsigned long port
)
266 *(volatile unsigned long *)PORT2ADDR(port
) = l
;
270 void _insb(unsigned int port
, void *addr
, unsigned long count
)
272 unsigned short *buf
= addr
;
273 unsigned short *portp
;
275 if (port
>= 0x300 && port
< 0x320){
276 portp
= PORT2ADDR_NE(port
);
278 *buf
++ = *(volatile unsigned char *)portp
;
279 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
280 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
281 pcc_ioread(0, port
, (void *)addr
, sizeof(unsigned char),
283 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
284 pcc_ioread(1, port
, (void *)addr
, sizeof(unsigned char),
288 portp
= PORT2ADDR(port
);
290 *buf
++ = *(volatile unsigned char *)portp
;
294 void _insw(unsigned int port
, void *addr
, unsigned long count
)
296 unsigned short *buf
= addr
;
297 unsigned short *portp
;
299 if (port
>= 0x300 && port
< 0x320) {
300 portp
= PORT2ADDR_NE(port
);
302 *buf
++ = _ne_inw(portp
);
303 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
304 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
305 pcc_ioread(0, port
, (void *)addr
, sizeof(unsigned short),
307 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
308 pcc_ioread(1, port
, (void *)addr
, sizeof(unsigned short),
312 portp
= PORT2ADDR(port
);
314 *buf
++ = *(volatile unsigned short *)portp
;
318 void _insl(unsigned int port
, void *addr
, unsigned long count
)
320 unsigned long *buf
= addr
;
321 unsigned long *portp
;
323 portp
= PORT2ADDR(port
);
325 *buf
++ = *(volatile unsigned long *)portp
;
328 void _outsb(unsigned int port
, const void *addr
, unsigned long count
)
330 const unsigned char *buf
= addr
;
331 unsigned char *portp
;
333 if (port
>= 0x300 && port
< 0x320) {
334 portp
= PORT2ADDR_NE(port
);
336 _ne_outb(*buf
++, portp
);
337 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
338 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
339 pcc_iowrite(0, port
, (void *)addr
, sizeof(unsigned char),
341 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
342 pcc_iowrite(1, port
, (void *)addr
, sizeof(unsigned char),
346 portp
= PORT2ADDR(port
);
348 *(volatile unsigned char *)portp
= *buf
++;
352 void _outsw(unsigned int port
, const void *addr
, unsigned long count
)
354 const unsigned short *buf
= addr
;
355 unsigned short *portp
;
357 if (port
>= 0x300 && port
< 0x320) {
358 portp
= PORT2ADDR_NE(port
);
360 _ne_outw(*buf
++, portp
);
361 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
362 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
363 pcc_iowrite(0, port
, (void *)addr
, sizeof(unsigned short),
365 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
366 pcc_iowrite(1, port
, (void *)addr
, sizeof(unsigned short),
370 portp
= PORT2ADDR(port
);
372 *(volatile unsigned short *)portp
= *buf
++;
376 void _outsl(unsigned int port
, const void *addr
, unsigned long count
)
378 const unsigned long *buf
= addr
;
379 unsigned char *portp
;
381 portp
= PORT2ADDR(port
);
383 *(volatile unsigned long *)portp
= *buf
++;