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 /* $Id: io_mappi.c,v 1.9 2003/12/02 07:18:08 fujiwara Exp $ */
12 #include <linux/config.h>
16 #include <asm/byteorder.h>
18 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
19 #include <linux/types.h>
21 #define M32R_PCC_IOMAP_SIZE 0x1000
23 #define M32R_PCC_IOSTART0 0x1000
24 #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
25 #define M32R_PCC_IOSTART1 0x2000
26 #define M32R_PCC_IOEND1 (M32R_PCC_IOSTART1 + M32R_PCC_IOMAP_SIZE - 1)
28 extern void pcc_ioread(int, unsigned long, void *, size_t, size_t, int);
29 extern void pcc_iowrite(int, unsigned long, void *, size_t, size_t, int);
30 #endif /* CONFIG_PCMCIA && CONFIG_M32RPCC */
32 #define PORT2ADDR(port) _port2addr(port)
34 static __inline__
void *_port2addr(unsigned long port
)
36 return (void *)(port
+ NONCACHE_OFFSET
);
39 static __inline__
void *_port2addr_ne(unsigned long port
)
41 return (void *)((port
<<1) + NONCACHE_OFFSET
+ 0x0C000000);
44 static __inline__
void delay(void)
46 __asm__
__volatile__ ("push r0; \n\t pop r0;" : : :"memory");
53 #define PORT2ADDR_NE(port) _port2addr_ne(port)
55 static __inline__
unsigned char _ne_inb(void *portp
)
57 return (unsigned char) *(volatile unsigned short *)portp
;
60 static __inline__
unsigned short _ne_inw(void *portp
)
64 tmp
= *(volatile unsigned short *)portp
;
65 return le16_to_cpu(tmp
);
68 static __inline__
void _ne_outb(unsigned char b
, void *portp
)
70 *(volatile unsigned short *)portp
= (unsigned short)b
;
73 static __inline__
void _ne_outw(unsigned short w
, void *portp
)
75 *(volatile unsigned short *)portp
= cpu_to_le16(w
);
78 unsigned char _inb(unsigned long port
)
80 if (port
>= 0x300 && port
< 0x320)
81 return _ne_inb(PORT2ADDR_NE(port
));
83 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
84 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
86 pcc_ioread(0, port
, &b
, sizeof(b
), 1, 0);
88 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
90 pcc_ioread(1, port
, &b
, sizeof(b
), 1, 0);
95 return *(volatile unsigned char *)PORT2ADDR(port
);
98 unsigned short _inw(unsigned long port
)
100 if (port
>= 0x300 && port
< 0x320)
101 return _ne_inw(PORT2ADDR_NE(port
));
103 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
104 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
106 pcc_ioread(0, port
, &w
, sizeof(w
), 1, 0);
108 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
110 pcc_ioread(1, port
, &w
, sizeof(w
), 1, 0);
114 return *(volatile unsigned short *)PORT2ADDR(port
);
117 unsigned long _inl(unsigned long port
)
119 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
120 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
122 pcc_ioread(0, port
, &l
, sizeof(l
), 1, 0);
124 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
126 pcc_ioread(1, port
, &l
, sizeof(l
), 1, 0);
130 return *(volatile unsigned long *)PORT2ADDR(port
);
133 unsigned char _inb_p(unsigned long port
)
137 if (port
>= 0x300 && port
< 0x320)
138 v
= _ne_inb(PORT2ADDR_NE(port
));
140 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
141 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
143 pcc_ioread(0, port
, &b
, sizeof(b
), 1, 0);
145 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
147 pcc_ioread(1, port
, &b
, sizeof(b
), 1, 0);
151 v
= *(volatile unsigned char *)PORT2ADDR(port
);
157 unsigned short _inw_p(unsigned long port
)
161 if (port
>= 0x300 && port
< 0x320)
162 v
= _ne_inw(PORT2ADDR_NE(port
));
164 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
165 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
167 pcc_ioread(0, port
, &w
, sizeof(w
), 1, 0);
169 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
171 pcc_ioread(1, port
, &w
, sizeof(w
), 1, 0);
175 v
= *(volatile unsigned short *)PORT2ADDR(port
);
181 unsigned long _inl_p(unsigned long port
)
185 v
= *(volatile unsigned long *)PORT2ADDR(port
);
190 void _outb(unsigned char b
, unsigned long port
)
192 if (port
>= 0x300 && port
< 0x320)
193 _ne_outb(b
, PORT2ADDR_NE(port
));
195 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
196 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
197 pcc_iowrite(0, port
, &b
, sizeof(b
), 1, 0);
198 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
199 pcc_iowrite(1, port
, &b
, sizeof(b
), 1, 0);
202 *(volatile unsigned char *)PORT2ADDR(port
) = b
;
205 void _outw(unsigned short w
, unsigned long port
)
207 if (port
>= 0x300 && port
< 0x320)
208 _ne_outw(w
, PORT2ADDR_NE(port
));
210 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
211 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
212 pcc_iowrite(0, port
, &w
, sizeof(w
), 1, 0);
213 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
214 pcc_iowrite(1, port
, &w
, sizeof(w
), 1, 0);
217 *(volatile unsigned short *)PORT2ADDR(port
) = w
;
220 void _outl(unsigned long l
, unsigned long port
)
222 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
223 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
224 pcc_iowrite(0, port
, &l
, sizeof(l
), 1, 0);
225 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
226 pcc_iowrite(1, port
, &l
, sizeof(l
), 1, 0);
229 *(volatile unsigned long *)PORT2ADDR(port
) = l
;
232 void _outb_p(unsigned char b
, unsigned long port
)
234 if (port
>= 0x300 && port
< 0x320)
235 _ne_outb(b
, PORT2ADDR_NE(port
));
237 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
238 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
239 pcc_iowrite(0, port
, &b
, sizeof(b
), 1, 0);
240 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
241 pcc_iowrite(1, port
, &b
, sizeof(b
), 1, 0);
244 *(volatile unsigned char *)PORT2ADDR(port
) = b
;
249 void _outw_p(unsigned short w
, unsigned long port
)
251 if (port
>= 0x300 && port
< 0x320)
252 _ne_outw(w
, PORT2ADDR_NE(port
));
254 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
255 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
256 pcc_iowrite(0, port
, &w
, sizeof(w
), 1, 0);
257 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
258 pcc_iowrite(1, port
, &w
, sizeof(w
), 1, 0);
261 *(volatile unsigned short *)PORT2ADDR(port
) = w
;
266 void _outl_p(unsigned long l
, unsigned long port
)
268 *(volatile unsigned long *)PORT2ADDR(port
) = l
;
272 void _insb(unsigned int port
, void * addr
, unsigned long count
)
274 unsigned short *buf
= addr
;
275 unsigned short *portp
;
277 if (port
>= 0x300 && port
< 0x320){
278 portp
= PORT2ADDR_NE(port
);
279 while(count
--) *buf
++ = *(volatile unsigned char *)portp
;
280 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
281 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
282 pcc_ioread(0, port
, (void *)addr
, sizeof(unsigned char), count
, 1);
283 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
284 pcc_ioread(1, port
, (void *)addr
, sizeof(unsigned char), count
, 1);
287 portp
= PORT2ADDR(port
);
288 while(count
--) *buf
++ = *(volatile unsigned char *)portp
;
292 void _insw(unsigned int port
, void * addr
, unsigned long count
)
294 unsigned short *buf
= addr
;
295 unsigned short *portp
;
297 if (port
>= 0x300 && port
< 0x320) {
298 portp
= PORT2ADDR_NE(port
);
299 while (count
--) *buf
++ = _ne_inw(portp
);
300 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
301 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
302 pcc_ioread(0, port
, (void *)addr
, sizeof(unsigned short), count
, 1);
303 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
304 pcc_ioread(1, port
, (void *)addr
, sizeof(unsigned short), count
, 1);
307 portp
= PORT2ADDR(port
);
308 while (count
--) *buf
++ = *(volatile unsigned short *)portp
;
312 void _insl(unsigned int port
, void * addr
, unsigned long count
)
314 unsigned long *buf
= addr
;
315 unsigned long *portp
;
317 portp
= PORT2ADDR(port
);
318 while (count
--) *buf
++ = *(volatile unsigned long *)portp
;
321 void _outsb(unsigned int port
, const void * addr
, unsigned long count
)
323 const unsigned char *buf
= addr
;
324 unsigned char *portp
;
326 if (port
>= 0x300 && port
< 0x320) {
327 portp
= PORT2ADDR_NE(port
);
328 while (count
--) _ne_outb(*buf
++, portp
);
329 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
330 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
331 pcc_iowrite(0, port
, (void *)addr
, sizeof(unsigned char), count
, 1);
332 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
333 pcc_iowrite(1, port
, (void *)addr
, sizeof(unsigned char), count
, 1);
336 portp
= PORT2ADDR(port
);
337 while(count
--) *(volatile unsigned char *)portp
= *buf
++;
341 void _outsw(unsigned int port
, const void * addr
, unsigned long count
)
343 const unsigned short *buf
= addr
;
344 unsigned short *portp
;
346 if (port
>= 0x300 && port
< 0x320) {
347 portp
= PORT2ADDR_NE(port
);
348 while (count
--) _ne_outw(*buf
++, portp
);
349 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32RPCC)
350 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
351 pcc_iowrite(0, port
, (void *)addr
, sizeof(unsigned short), count
, 1);
352 } else if (port
>= M32R_PCC_IOSTART1
&& port
<= M32R_PCC_IOEND1
) {
353 pcc_iowrite(1, port
, (void *)addr
, sizeof(unsigned short), count
, 1);
356 portp
= PORT2ADDR(port
);
357 while(count
--) *(volatile unsigned short *)portp
= *buf
++;
361 void _outsl(unsigned int port
, const void * addr
, unsigned long count
)
363 const unsigned long *buf
= addr
;
364 unsigned char *portp
;
366 portp
= PORT2ADDR(port
);
367 while(count
--) *(volatile unsigned long *)portp
= *buf
++;