]>
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)
40 static inline void *__port2addr_ata(unsigned long port
)
46 case 0x1f0: return (void *)0xb4002000;
47 case 0x1f1: return (void *)0xb4012800;
48 case 0x1f2: return (void *)0xb4012002;
49 case 0x1f3: return (void *)0xb4012802;
50 case 0x1f4: return (void *)0xb4012004;
51 case 0x1f5: return (void *)0xb4012804;
52 case 0x1f6: return (void *)0xb4012006;
53 case 0x1f7: return (void *)0xb4012806;
54 case 0x3f6: return (void *)0xb401200e;
56 case 0x170: return (void *)0xb4810000; /* Data 16bit */
57 case 0x171: return (void *)0xb4810002; /* Features / Error */
58 case 0x172: return (void *)0xb4810004; /* Sector count */
59 case 0x173: return (void *)0xb4810006; /* Sector number */
60 case 0x174: return (void *)0xb4810008; /* Cylinder low */
61 case 0x175: return (void *)0xb481000a; /* Cylinder high */
62 case 0x176: return (void *)0xb481000c; /* Device head */
63 case 0x177: return (void *)0xb481000e; /* Command */
64 case 0x376: return (void *)0xb480800c; /* Device control / Alt status */
66 default: return (void *)&dummy_reg
;
71 #define LAN_IOSTART 0xa0000300
72 #define LAN_IOEND 0xa0000320
73 static inline void *_port2addr_ne(unsigned long port
)
75 return (void *)(port
+ 0x10000000);
78 static inline void *_port2addr_usb(unsigned long port
)
80 return (void *)(port
+ NONCACHE_OFFSET
+ 0x12000000);
82 static inline void delay(void)
84 __asm__
__volatile__ ("push r0; \n\t pop r0;" : : :"memory");
91 static inline unsigned char _ne_inb(void *portp
)
93 return (unsigned char) *(volatile unsigned char *)portp
;
96 static inline unsigned short _ne_inw(void *portp
)
98 return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp
);
101 static inline void _ne_insb(void *portp
, void * addr
, unsigned long count
)
103 unsigned char *buf
= addr
;
106 *buf
++ = *(volatile unsigned char *)portp
;
109 static inline void _ne_outb(unsigned char b
, void *portp
)
111 *(volatile unsigned char *)portp
= (unsigned char)b
;
114 static inline void _ne_outw(unsigned short w
, void *portp
)
116 *(volatile unsigned short *)portp
= cpu_to_le16(w
);
119 unsigned char _inb(unsigned long port
)
121 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
122 return _ne_inb(PORT2ADDR_NE(port
));
123 #if defined(CONFIG_IDE)
124 else if ( ((port
>= 0x170 && port
<=0x177) || port
== 0x376) ||
125 ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) ){
126 return *(volatile unsigned char *)__port2addr_ata(port
);
129 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
130 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
132 pcc_ioread_byte(0, port
, &b
, sizeof(b
), 1, 0);
136 return *(volatile unsigned char *)PORT2ADDR(port
);
139 unsigned short _inw(unsigned long port
)
141 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
142 return _ne_inw(PORT2ADDR_NE(port
));
143 #if defined(CONFIG_IDE)
144 else if ( ((port
>= 0x170 && port
<=0x177) || port
== 0x376) ||
145 ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) ){
146 return *(volatile unsigned short *)__port2addr_ata(port
);
149 #if defined(CONFIG_USB)
150 else if (port
>= 0x340 && port
< 0x3a0)
151 return *(volatile unsigned short *)PORT2ADDR_USB(port
);
154 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
155 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
157 pcc_ioread_word(0, port
, &w
, sizeof(w
), 1, 0);
161 return *(volatile unsigned short *)PORT2ADDR(port
);
164 unsigned long _inl(unsigned long port
)
166 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
167 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
169 pcc_ioread_word(0, port
, &l
, sizeof(l
), 1, 0);
173 return *(volatile unsigned long *)PORT2ADDR(port
);
176 unsigned char _inb_p(unsigned long port
)
178 unsigned char v
= _inb(port
);
183 unsigned short _inw_p(unsigned long port
)
185 unsigned short v
= _inw(port
);
190 unsigned long _inl_p(unsigned long port
)
192 unsigned long v
= _inl(port
);
197 void _outb(unsigned char b
, unsigned long port
)
199 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
200 _ne_outb(b
, PORT2ADDR_NE(port
));
202 #if defined(CONFIG_IDE)
203 if ( ((port
>= 0x170 && port
<=0x177) || port
== 0x376) ||
204 ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) ){
205 *(volatile unsigned char *)__port2addr_ata(port
) = b
;
208 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
209 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
210 pcc_iowrite_byte(0, port
, &b
, sizeof(b
), 1, 0);
213 *(volatile unsigned char *)PORT2ADDR(port
) = b
;
216 void _outw(unsigned short w
, unsigned long port
)
218 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
219 _ne_outw(w
, PORT2ADDR_NE(port
));
221 #if defined(CONFIG_IDE)
222 if ( ((port
>= 0x170 && port
<=0x177) || port
== 0x376) ||
223 ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) ){
224 *(volatile unsigned short *)__port2addr_ata(port
) = w
;
227 #if defined(CONFIG_USB)
228 if (port
>= 0x340 && port
< 0x3a0)
229 *(volatile unsigned short *)PORT2ADDR_USB(port
) = w
;
232 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
233 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
234 pcc_iowrite_word(0, port
, &w
, sizeof(w
), 1, 0);
237 *(volatile unsigned short *)PORT2ADDR(port
) = w
;
240 void _outl(unsigned long l
, unsigned long port
)
242 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
243 if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
244 pcc_iowrite_word(0, port
, &l
, sizeof(l
), 1, 0);
247 *(volatile unsigned long *)PORT2ADDR(port
) = l
;
250 void _outb_p(unsigned char b
, unsigned long port
)
256 void _outw_p(unsigned short w
, unsigned long port
)
262 void _outl_p(unsigned long l
, unsigned long port
)
268 void _insb(unsigned int port
, void * addr
, unsigned long count
)
270 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
)
271 _ne_insb(PORT2ADDR_NE(port
), addr
, count
);
272 #if defined(CONFIG_IDE)
273 else if ( ((port
>= 0x170 && port
<=0x177) || port
== 0x376) ||
274 ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) ){
275 unsigned char *buf
= addr
;
276 unsigned char *portp
= __port2addr_ata(port
);
278 *buf
++ = *(volatile unsigned char *)portp
;
281 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
282 else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
283 pcc_ioread_byte(0, port
, (void *)addr
, sizeof(unsigned char),
288 unsigned char *buf
= addr
;
289 unsigned char *portp
= PORT2ADDR(port
);
291 *buf
++ = *(volatile unsigned char *)portp
;
295 void _insw(unsigned int port
, void * addr
, unsigned long count
)
297 unsigned short *buf
= addr
;
298 unsigned short *portp
;
300 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
301 portp
= PORT2ADDR_NE(port
);
303 *buf
++ = *(volatile unsigned short *)portp
;
304 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
305 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
306 pcc_ioread_word(9, port
, (void *)addr
, sizeof(unsigned short),
309 #if defined(CONFIG_IDE)
310 } else if ( ((port
>= 0x170 && port
<=0x177) || port
== 0x376) ||
311 ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) ){
312 portp
= __port2addr_ata(port
);
314 *buf
++ = *(volatile unsigned short *)portp
;
317 portp
= PORT2ADDR(port
);
319 *buf
++ = *(volatile unsigned short *)portp
;
323 void _insl(unsigned int port
, void * addr
, unsigned long count
)
325 unsigned long *buf
= addr
;
326 unsigned long *portp
;
328 portp
= PORT2ADDR(port
);
330 *buf
++ = *(volatile unsigned long *)portp
;
333 void _outsb(unsigned int port
, const void * addr
, unsigned long count
)
335 const unsigned char *buf
= addr
;
336 unsigned char *portp
;
338 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
339 portp
= PORT2ADDR_NE(port
);
341 _ne_outb(*buf
++, portp
);
342 #if defined(CONFIG_IDE)
343 } else if ( ((port
>= 0x170 && port
<=0x177) || port
== 0x376) ||
344 ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) ){
345 portp
= __port2addr_ata(port
);
347 *(volatile unsigned char *)portp
= *buf
++;
349 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
350 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
351 pcc_iowrite_byte(0, port
, (void *)addr
, sizeof(unsigned char),
355 portp
= PORT2ADDR(port
);
357 *(volatile unsigned char *)portp
= *buf
++;
361 void _outsw(unsigned int port
, const void * addr
, unsigned long count
)
363 const unsigned short *buf
= addr
;
364 unsigned short *portp
;
366 if (port
>= LAN_IOSTART
&& port
< LAN_IOEND
) {
367 portp
= PORT2ADDR_NE(port
);
369 *(volatile unsigned short *)portp
= *buf
++;
370 #if defined(CONFIG_IDE)
371 } else if ( ((port
>= 0x170 && port
<=0x177) || port
== 0x376) ||
372 ((port
>= 0x1f0 && port
<=0x1f7) || port
== 0x3f6) ){
373 portp
= __port2addr_ata(port
);
375 *(volatile unsigned short *)portp
= *buf
++;
377 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
378 } else if (port
>= M32R_PCC_IOSTART0
&& port
<= M32R_PCC_IOEND0
) {
379 pcc_iowrite_word(9, port
, (void *)addr
, sizeof(unsigned short),
383 portp
= PORT2ADDR(port
);
385 *(volatile unsigned short *)portp
= *buf
++;
389 void _outsl(unsigned int port
, const void * addr
, unsigned long count
)
391 const unsigned long *buf
= addr
;
392 unsigned char *portp
;
394 portp
= PORT2ADDR(port
);
396 *(volatile unsigned long *)portp
= *buf
++;