]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - arch/m32r/kernel/io_mappi3.c
2 * linux/arch/m32r/kernel/io_mappi3.c
4 * Typical I/O routines for Mappi3 board.
6 * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata,
7 * Hitoshi Yamamoto, Mamoru Sakugawa
10 #include <linux/config.h>
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 *)0xb4002000;
46 case 0x1f1: return (void *)0xb4012800;
47 case 0x1f2: return (void *)0xb4012002;
48 case 0x1f3: return (void *)0xb4012802;
49 case 0x1f4: return (void *)0xb4012004;
50 case 0x1f5: return (void *)0xb4012804;
51 case 0x1f6: return (void *)0xb4012006;
52 case 0x1f7: return (void *)0xb4012806;
53 case 0x3f6: return (void *)0xb401200e;
54 default: return (void *)&dummy_reg
;
59 #define LAN_IOSTART 0xa0000300
60 #define LAN_IOEND 0xa0000320
61 static inline void *_port2addr_ne(unsigned long port
)
63 return (void *)(port
+ 0x10000000);
66 static inline void *_port2addr_usb(unsigned long port
)
68 return (void *)(port
+ NONCACHE_OFFSET
+ 0x12000000);
70 static inline void delay(void)
72 __asm__
__volatile__ ("push r0; \n\t pop r0;" : : :"memory");
79 static inline unsigned char _ne_inb(void *portp
)
81 return (unsigned char) *(volatile unsigned char *)portp
;
84 static inline unsigned short _ne_inw(void *portp
)
86 return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp
);
89 static inline void _ne_insb(void *portp
, void * addr
, unsigned long count
)
91 unsigned char *buf
= addr
;
94 *buf
++ = *(volatile unsigned char *)portp
;
97 static inline void _ne_outb(unsigned char b
, void *portp
)
99 *(volatile unsigned char *)portp
= (unsigned char)b
;
102 static inline void _ne_outw(unsigned short w
, void *portp
)
104 *(volatile unsigned short *)portp
= cpu_to_le16(w
);
107 unsigned char _inb(unsigned long port
)
109 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
110 return _ne_inb(PORT2ADDR_NE(port
));
111 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
112 else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
113 return *(volatile unsigned char *)__port2addr_ata(port
);
116 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
117 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
119 pcc_ioread_byte(0, port
, &b
, sizeof(b
), 1, 0);
123 return *(volatile unsigned char *)PORT2ADDR(port
);
126 unsigned short _inw(unsigned long port
)
128 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
129 return _ne_inw(PORT2ADDR_NE(port
));
130 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
131 else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
132 return *(volatile unsigned short *)__port2addr_ata(port
);
135 #if defined(CONFIG_USB)
136 else if (port
>= 0x340 && port
< 0x3a0)
137 return *(volatile unsigned short *)PORT2ADDR_USB(port
);
140 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
141 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
143 pcc_ioread_word(0, port
, &w
, sizeof(w
), 1, 0);
147 return *(volatile unsigned short *)PORT2ADDR(port
);
150 unsigned long _inl(unsigned long port
)
152 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
153 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
155 pcc_ioread_word(0, port
, &l
, sizeof(l
), 1, 0);
159 return *(volatile unsigned long *)PORT2ADDR(port
);
162 unsigned char _inb_p(unsigned long port
)
164 unsigned char v
= _inb(port
);
169 unsigned short _inw_p(unsigned long port
)
171 unsigned short v
= _inw(port
);
176 unsigned long _inl_p(unsigned long port
)
178 unsigned long v
= _inl(port
);
183 void _outb(unsigned char b
, unsigned long port
)
185 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
186 _ne_outb(b
, PORT2ADDR_NE(port
));
188 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
189 if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
190 *(volatile unsigned char *)__port2addr_ata(port
) = b
;
193 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
194 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
195 pcc_iowrite_byte(0, port
, &b
, sizeof(b
), 1, 0);
198 *(volatile unsigned char *)PORT2ADDR(port
) = b
;
201 void _outw(unsigned short w
, unsigned long port
)
203 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
204 _ne_outw(w
, PORT2ADDR_NE(port
));
206 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
207 if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
208 *(volatile unsigned short *)__port2addr_ata(port
) = w
;
211 #if defined(CONFIG_USB)
212 if (port
>= 0x340 && port
< 0x3a0)
213 *(volatile unsigned short *)PORT2ADDR_USB(port
) = w
;
216 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
217 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
218 pcc_iowrite_word(0, port
, &w
, sizeof(w
), 1, 0);
221 *(volatile unsigned short *)PORT2ADDR(port
) = w
;
224 void _outl(unsigned long l
, unsigned long port
)
226 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
227 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
228 pcc_iowrite_word(0, port
, &l
, sizeof(l
), 1, 0);
231 *(volatile unsigned long *)PORT2ADDR(port
) = l
;
234 void _outb_p(unsigned char b
, unsigned long port
)
240 void _outw_p(unsigned short w
, unsigned long port
)
246 void _outl_p(unsigned long l
, unsigned long port
)
252 void _insb(unsigned int port
, void * addr
, unsigned long count
)
254 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
255 _ne_insb(PORT2ADDR_NE(port
), addr
, count
);
256 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
257 else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
258 unsigned char *buf
= addr
;
259 unsigned char *portp
= __port2addr_ata(port
);
261 *buf
++ = *(volatile unsigned char *)portp
;
264 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
265 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
266 pcc_ioread_byte(0, port
, (void *)addr
, sizeof(unsigned char),
271 unsigned char *buf
= addr
;
272 unsigned char *portp
= PORT2ADDR(port
);
274 *buf
++ = *(volatile unsigned char *)portp
;
278 void _insw(unsigned int port
, void * addr
, unsigned long count
)
280 unsigned short *buf
= addr
;
281 unsigned short *portp
;
283 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
284 portp
= PORT2ADDR_NE(port
);
286 *buf
++ = *(volatile unsigned short *)portp
;
287 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
288 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
289 pcc_ioread_word(9, port
, (void *)addr
, sizeof(unsigned short),
292 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
293 } else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
294 portp
= __port2addr_ata(port
);
296 *buf
++ = *(volatile unsigned short *)portp
;
299 portp
= PORT2ADDR(port
);
301 *buf
++ = *(volatile unsigned short *)portp
;
305 void _insl(unsigned int port
, void * addr
, unsigned long count
)
307 unsigned long *buf
= addr
;
308 unsigned long *portp
;
310 portp
= PORT2ADDR(port
);
312 *buf
++ = *(volatile unsigned long *)portp
;
315 void _outsb(unsigned int port
, const void * addr
, unsigned long count
)
317 const unsigned char *buf
= addr
;
318 unsigned char *portp
;
320 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
321 portp
= PORT2ADDR_NE(port
);
323 _ne_outb(*buf
++, portp
);
324 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
325 } else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
326 portp
= __port2addr_ata(port
);
328 *(volatile unsigned char *)portp
= *buf
++;
330 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
331 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
332 pcc_iowrite_byte(0, port
, (void *)addr
, sizeof(unsigned char),
336 portp
= PORT2ADDR(port
);
338 *(volatile unsigned char *)portp
= *buf
++;
342 void _outsw(unsigned int port
, const void * addr
, unsigned long count
)
344 const unsigned short *buf
= addr
;
345 unsigned short *portp
;
347 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
348 portp
= PORT2ADDR_NE(port
);
350 *(volatile unsigned short *)portp
= *buf
++;
351 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
352 } else if ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) {
353 portp
= __port2addr_ata(port
);
355 *(volatile unsigned short *)portp
= *buf
++;
357 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
358 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
359 pcc_iowrite_word(9, port
, (void *)addr
, sizeof(unsigned short),
363 portp
= PORT2ADDR(port
);
365 *(volatile unsigned short *)portp
= *buf
++;
369 void _outsl(unsigned int port
, const void * addr
, unsigned long count
)
371 const unsigned long *buf
= addr
;
372 unsigned char *portp
;
374 portp
= PORT2ADDR(port
);
376 *(volatile unsigned long *)portp
= *buf
++;