1 // SPDX-License-Identifier: GPL-2.0
3 * linux/arch/m32r/platforms/mappi2/io.c
5 * Typical I/O routines for Mappi2 board.
7 * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata,
8 * Hitoshi Yamamoto, Mamoru Sakugawa
14 #include <asm/byteorder.h>
16 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
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)
24 extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
25 extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
26 extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
27 extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
28 #endif /* CONFIG_PCMCIA && CONFIG_M32R_CFC */
30 #define PORT2ADDR(port) _port2addr(port)
31 #define PORT2ADDR_NE(port) _port2addr_ne(port)
32 #define PORT2ADDR_USB(port) _port2addr_usb(port)
34 static inline void *_port2addr(unsigned long port
)
36 return (void *)(port
| NONCACHE_OFFSET
);
39 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
40 static inline void *__port2addr_ata(unsigned long port
)
45 case 0x1f0: return (void *)(0x0c002000 | NONCACHE_OFFSET
);
46 case 0x1f1: return (void *)(0x0c012800 | NONCACHE_OFFSET
);
47 case 0x1f2: return (void *)(0x0c012002 | NONCACHE_OFFSET
);
48 case 0x1f3: return (void *)(0x0c012802 | NONCACHE_OFFSET
);
49 case 0x1f4: return (void *)(0x0c012004 | NONCACHE_OFFSET
);
50 case 0x1f5: return (void *)(0x0c012804 | NONCACHE_OFFSET
);
51 case 0x1f6: return (void *)(0x0c012006 | NONCACHE_OFFSET
);
52 case 0x1f7: return (void *)(0x0c012806 | NONCACHE_OFFSET
);
53 case 0x3f6: return (void *)(0x0c01200e | NONCACHE_OFFSET
);
54 default: return (void *)&dummy_reg
;
59 #define LAN_IOSTART (0x300 | NONCACHE_OFFSET)
60 #define LAN_IOEND (0x320 | NONCACHE_OFFSET)
61 #ifdef CONFIG_CHIP_OPSP
62 static inline void *_port2addr_ne(unsigned long port
)
64 return (void *)(port
+ 0x10000000);
67 static inline void *_port2addr_ne(unsigned long port
)
69 return (void *)(port
+ 0x04000000);
72 static inline void *_port2addr_usb(unsigned long port
)
74 return (void *)(port
+ NONCACHE_OFFSET
+ 0x14000000);
76 static inline void delay(void)
78 __asm__
__volatile__ ("push r0; \n\t pop r0;" : : :"memory");
85 static inline unsigned char _ne_inb(void *portp
)
87 return (unsigned char) *(volatile unsigned char *)portp
;
90 static inline unsigned short _ne_inw(void *portp
)
92 return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp
);
95 static inline void _ne_insb(void *portp
, void * addr
, unsigned long count
)
97 unsigned char *buf
= addr
;
100 *buf
++ = *(volatile unsigned char *)portp
;
103 static inline void _ne_outb(unsigned char b
, void *portp
)
105 *(volatile unsigned char *)portp
= (unsigned char)b
;
108 static inline void _ne_outw(unsigned short w
, void *portp
)
110 *(volatile unsigned short *)portp
= cpu_to_le16(w
);
113 unsigned char _inb(unsigned long port
)
115 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
116 return _ne_inb(PORT2ADDR_NE(port
));
117 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
118 else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
119 return *(volatile unsigned char *)__port2addr_ata(port
);
122 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
123 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
125 pcc_ioread_byte(0, port
, &b
, sizeof(b
), 1, 0);
130 return *(volatile unsigned char *)PORT2ADDR(port
);
133 unsigned short _inw(unsigned long port
)
135 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
136 return _ne_inw(PORT2ADDR_NE(port
));
137 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
138 else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
139 return *(volatile unsigned short *)__port2addr_ata(port
);
142 #if defined(CONFIG_USB)
143 else if (port
>= 0x340 && port
< 0x3a0)
144 return *(volatile unsigned short *)PORT2ADDR_USB(port
);
147 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
148 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
150 pcc_ioread_word(0, port
, &w
, sizeof(w
), 1, 0);
154 return *(volatile unsigned short *)PORT2ADDR(port
);
157 unsigned long _inl(unsigned long port
)
159 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
160 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
162 pcc_ioread_word(0, port
, &l
, sizeof(l
), 1, 0);
166 return *(volatile unsigned long *)PORT2ADDR(port
);
169 unsigned char _inb_p(unsigned long port
)
171 unsigned char v
= _inb(port
);
176 unsigned short _inw_p(unsigned long port
)
178 unsigned short v
= _inw(port
);
183 unsigned long _inl_p(unsigned long port
)
185 unsigned long v
= _inl(port
);
190 void _outb(unsigned char b
, unsigned long port
)
192 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
193 _ne_outb(b
, PORT2ADDR_NE(port
));
195 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
196 if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
197 *(volatile unsigned char *)__port2addr_ata(port
) = b
;
200 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
201 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
202 pcc_iowrite_byte(0, port
, &b
, sizeof(b
), 1, 0);
205 *(volatile unsigned char *)PORT2ADDR(port
) = b
;
208 void _outw(unsigned short w
, unsigned long port
)
210 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
211 _ne_outw(w
, PORT2ADDR_NE(port
));
213 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
214 if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
215 *(volatile unsigned short *)__port2addr_ata(port
) = w
;
218 #if defined(CONFIG_USB)
219 if (port
>= 0x340 && port
< 0x3a0)
220 *(volatile unsigned short *)PORT2ADDR_USB(port
) = w
;
223 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
224 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
225 pcc_iowrite_word(0, port
, &w
, sizeof(w
), 1, 0);
228 *(volatile unsigned short *)PORT2ADDR(port
) = w
;
231 void _outl(unsigned long l
, unsigned long port
)
233 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
234 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
235 pcc_iowrite_word(0, port
, &l
, sizeof(l
), 1, 0);
238 *(volatile unsigned long *)PORT2ADDR(port
) = l
;
241 void _outb_p(unsigned char b
, unsigned long port
)
247 void _outw_p(unsigned short w
, unsigned long port
)
253 void _outl_p(unsigned long l
, unsigned long port
)
259 void _insb(unsigned int port
, void * addr
, unsigned long count
)
261 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
262 _ne_insb(PORT2ADDR_NE(port
), addr
, count
);
263 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
264 else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
265 unsigned char *buf
= addr
;
266 unsigned char *portp
= __port2addr_ata(port
);
268 *buf
++ = *(volatile unsigned char *)portp
;
271 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
272 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
273 pcc_ioread_byte(0, port
, (void *)addr
, sizeof(unsigned char),
278 unsigned char *buf
= addr
;
279 unsigned char *portp
= PORT2ADDR(port
);
281 *buf
++ = *(volatile unsigned char *)portp
;
285 void _insw(unsigned int port
, void * addr
, unsigned long count
)
287 unsigned short *buf
= addr
;
288 unsigned short *portp
;
290 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
291 portp
= PORT2ADDR_NE(port
);
293 *buf
++ = *(volatile unsigned short *)portp
;
294 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
295 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
296 pcc_ioread_word(9, port
, (void *)addr
, sizeof(unsigned short),
299 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
300 } else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
301 portp
= __port2addr_ata(port
);
303 *buf
++ = *(volatile unsigned short *)portp
;
306 portp
= PORT2ADDR(port
);
308 *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
);
319 *buf
++ = *(volatile unsigned long *)portp
;
322 void _outsb(unsigned int port
, const void * addr
, unsigned long count
)
324 const unsigned char *buf
= addr
;
325 unsigned char *portp
;
327 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
328 portp
= PORT2ADDR_NE(port
);
330 _ne_outb(*buf
++, portp
);
331 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
332 } else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
333 portp
= __port2addr_ata(port
);
335 *(volatile unsigned char *)portp
= *buf
++;
337 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
338 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
339 pcc_iowrite_byte(0, port
, (void *)addr
, sizeof(unsigned char),
343 portp
= PORT2ADDR(port
);
345 *(volatile unsigned char *)portp
= *buf
++;
349 void _outsw(unsigned int port
, const void * addr
, unsigned long count
)
351 const unsigned short *buf
= addr
;
352 unsigned short *portp
;
354 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
355 portp
= PORT2ADDR_NE(port
);
357 *(volatile unsigned short *)portp
= *buf
++;
358 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
359 } else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
360 portp
= __port2addr_ata(port
);
362 *(volatile unsigned short *)portp
= *buf
++;
364 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
365 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
366 pcc_iowrite_word(9, 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
++;