2 * $Id: io.c,v 1.6 2004/03/16 00:07:50 lethal Exp $
3 * Copyright (C) 2000 YAEGASHI Takeshi
4 * Typical I/O routines for HD64461 system.
7 #include <linux/config.h>
9 #include <asm/hd64461/hd64461.h>
11 #define MEM_BASE (CONFIG_HD64461_IOBASE - HD64461_STBCR)
13 static __inline__
unsigned long PORT2ADDR(unsigned long port
)
15 /* 16550A: HD64461 internal */
16 if (0x3f8<=port
&& port
<=0x3ff)
17 return CONFIG_HD64461_IOBASE
+ 0x8000 + ((port
-0x3f8)<<1);
18 if (0x2f8<=port
&& port
<=0x2ff)
19 return CONFIG_HD64461_IOBASE
+ 0x7000 + ((port
-0x2f8)<<1);
21 #ifdef CONFIG_HD64461_ENABLER
22 /* NE2000: HD64461 PCMCIA channel 0 (I/O) */
23 if (0x300<=port
&& port
<=0x31f)
24 return 0xba000000 + port
;
26 /* ide0: HD64461 PCMCIA channel 1 (memory) */
27 /* On HP690, CF in slot 1 is configured as a memory card
28 device. See CF+ and CompactFlash Specification for the
29 detail of CF's memory mapped addressing. */
30 if (0x1f0<=port
&& port
<=0x1f7) return 0xb5000000 + port
;
31 if (port
== 0x3f6) return 0xb50001fe;
32 if (port
== 0x3f7) return 0xb50001ff;
35 if (0x170<=port
&& port
<=0x177) return 0xba000000 + port
;
36 if (port
== 0x376) return 0xba000376;
37 if (port
== 0x377) return 0xba000377;
41 if (port
< 0xf000) return 0xa0000000 + port
;
42 /* PCMCIA channel 0, I/O (0xba000000) */
43 if (port
< 0x10000) return 0xba000000 + port
- 0xf000;
45 /* HD64461 internal devices (0xb0000000) */
46 if (port
< 0x20000) return CONFIG_HD64461_IOBASE
+ port
- 0x10000;
48 /* PCMCIA channel 0, I/O (0xba000000) */
49 if (port
< 0x30000) return 0xba000000 + port
- 0x20000;
51 /* PCMCIA channel 1, memory (0xb5000000) */
52 if (port
< 0x40000) return 0xb5000000 + port
- 0x30000;
54 /* Whole physical address space (0xa0000000) */
55 return 0xa0000000 + (port
& 0x1fffffff);
58 static inline void delay(void)
63 unsigned char hd64461_inb(unsigned long port
)
65 return *(volatile unsigned char*)PORT2ADDR(port
);
68 unsigned char hd64461_inb_p(unsigned long port
)
70 unsigned long v
= *(volatile unsigned char*)PORT2ADDR(port
);
75 unsigned short hd64461_inw(unsigned long port
)
77 return *(volatile unsigned short*)PORT2ADDR(port
);
80 unsigned int hd64461_inl(unsigned long port
)
82 return *(volatile unsigned long*)PORT2ADDR(port
);
85 void hd64461_outb(unsigned char b
, unsigned long port
)
87 *(volatile unsigned char*)PORT2ADDR(port
) = b
;
90 void hd64461_outb_p(unsigned char b
, unsigned long port
)
92 *(volatile unsigned char*)PORT2ADDR(port
) = b
;
96 void hd64461_outw(unsigned short b
, unsigned long port
)
98 *(volatile unsigned short*)PORT2ADDR(port
) = b
;
101 void hd64461_outl(unsigned int b
, unsigned long port
)
103 *(volatile unsigned long*)PORT2ADDR(port
) = b
;
106 void hd64461_insb(unsigned long port
, void *buffer
, unsigned long count
)
108 volatile unsigned char* addr
=(volatile unsigned char*)PORT2ADDR(port
);
109 unsigned char *buf
=buffer
;
110 while(count
--) *buf
++=*addr
;
113 void hd64461_insw(unsigned long port
, void *buffer
, unsigned long count
)
115 volatile unsigned short* addr
=(volatile unsigned short*)PORT2ADDR(port
);
116 unsigned short *buf
=buffer
;
117 while(count
--) *buf
++=*addr
;
120 void hd64461_insl(unsigned long port
, void *buffer
, unsigned long count
)
122 volatile unsigned long* addr
=(volatile unsigned long*)PORT2ADDR(port
);
123 unsigned long *buf
=buffer
;
124 while(count
--) *buf
++=*addr
;
127 void hd64461_outsb(unsigned long port
, const void *buffer
, unsigned long count
)
129 volatile unsigned char* addr
=(volatile unsigned char*)PORT2ADDR(port
);
130 const unsigned char *buf
=buffer
;
131 while(count
--) *addr
=*buf
++;
134 void hd64461_outsw(unsigned long port
, const void *buffer
, unsigned long count
)
136 volatile unsigned short* addr
=(volatile unsigned short*)PORT2ADDR(port
);
137 const unsigned short *buf
=buffer
;
138 while(count
--) *addr
=*buf
++;
141 void hd64461_outsl(unsigned long port
, const void *buffer
, unsigned long count
)
143 volatile unsigned long* addr
=(volatile unsigned long*)PORT2ADDR(port
);
144 const unsigned long *buf
=buffer
;
145 while(count
--) *addr
=*buf
++;
148 unsigned short hd64461_readw(unsigned long addr
)
150 return *(volatile unsigned short*)(MEM_BASE
+addr
);
153 void hd64461_writew(unsigned short b
, unsigned long addr
)
155 *(volatile unsigned short*)(MEM_BASE
+addr
) = b
;