]> git.karo-electronics.de Git - mv-sheeva.git/blob - arch/sh/cchips/hd6446x/hd64461/io.c
sh: Move hd64461.h to a more sensible location.
[mv-sheeva.git] / arch / sh / cchips / hd6446x / hd64461 / io.c
1 /*
2  *      Copyright (C) 2000 YAEGASHI Takeshi
3  *      Typical I/O routines for HD64461 system.
4  */
5
6 #include <asm/io.h>
7 #include <asm/hd64461.h>
8
9 #define MEM_BASE (CONFIG_HD64461_IOBASE - HD64461_STBCR)
10
11 static __inline__ unsigned long PORT2ADDR(unsigned long port)
12 {
13         /* 16550A: HD64461 internal */
14         if (0x3f8<=port && port<=0x3ff)
15                 return CONFIG_HD64461_IOBASE + 0x8000 + ((port-0x3f8)<<1);
16         if (0x2f8<=port && port<=0x2ff)
17                 return CONFIG_HD64461_IOBASE + 0x7000 + ((port-0x2f8)<<1);
18
19 #ifdef CONFIG_HD64461_ENABLER
20         /* NE2000: HD64461 PCMCIA channel 0 (I/O) */
21         if (0x300<=port && port<=0x31f)
22                 return 0xba000000 + port;
23
24         /* ide0: HD64461 PCMCIA channel 1 (memory) */
25         /* On HP690, CF in slot 1 is configured as a memory card
26            device.  See CF+ and CompactFlash Specification for the
27            detail of CF's memory mapped addressing. */
28         if (0x1f0<=port && port<=0x1f7) return 0xb5000000 + port;
29         if (port == 0x3f6) return 0xb50001fe;
30         if (port == 0x3f7) return 0xb50001ff;
31
32         /* ide1 */
33         if (0x170<=port && port<=0x177) return 0xba000000 + port;
34         if (port == 0x376) return 0xba000376;
35         if (port == 0x377) return 0xba000377;
36 #endif
37
38         /* ??? */
39         if (port < 0xf000) return 0xa0000000 + port;
40         /* PCMCIA channel 0, I/O (0xba000000) */
41         if (port < 0x10000) return 0xba000000 + port - 0xf000;
42
43         /* HD64461 internal devices (0xb0000000) */
44         if (port < 0x20000) return CONFIG_HD64461_IOBASE + port - 0x10000;
45
46         /* PCMCIA channel 0, I/O (0xba000000) */
47         if (port < 0x30000) return 0xba000000 + port - 0x20000;
48
49         /* PCMCIA channel 1, memory (0xb5000000) */
50         if (port < 0x40000) return 0xb5000000 + port - 0x30000;
51
52         /* Whole physical address space (0xa0000000) */
53         return 0xa0000000 + (port & 0x1fffffff);
54 }
55
56 static inline void delay(void)
57 {
58         ctrl_inw(0xa0000000);
59 }
60
61 unsigned char hd64461_inb(unsigned long port)
62 {
63         return *(volatile unsigned char*)PORT2ADDR(port);
64 }
65
66 unsigned char hd64461_inb_p(unsigned long port)
67 {
68         unsigned long v = *(volatile unsigned char*)PORT2ADDR(port);
69         delay();
70         return v;
71 }
72
73 unsigned short hd64461_inw(unsigned long port)
74 {
75         return *(volatile unsigned short*)PORT2ADDR(port);
76 }
77
78 unsigned int hd64461_inl(unsigned long port)
79 {
80         return *(volatile unsigned long*)PORT2ADDR(port);
81 }
82
83 void hd64461_outb(unsigned char b, unsigned long port)
84 {
85         *(volatile unsigned char*)PORT2ADDR(port) = b;
86 }
87
88 void hd64461_outb_p(unsigned char b, unsigned long port)
89 {
90         *(volatile unsigned char*)PORT2ADDR(port) = b;
91         delay();
92 }
93
94 void hd64461_outw(unsigned short b, unsigned long port)
95 {
96         *(volatile unsigned short*)PORT2ADDR(port) = b;
97 }
98
99 void hd64461_outl(unsigned int b, unsigned long port)
100 {
101         *(volatile unsigned long*)PORT2ADDR(port) = b;
102 }
103
104 void hd64461_insb(unsigned long port, void *buffer, unsigned long count)
105 {
106         volatile unsigned char* addr=(volatile unsigned char*)PORT2ADDR(port);
107         unsigned char *buf=buffer;
108         while(count--) *buf++=*addr;
109 }
110
111 void hd64461_insw(unsigned long port, void *buffer, unsigned long count)
112 {
113         volatile unsigned short* addr=(volatile unsigned short*)PORT2ADDR(port);
114         unsigned short *buf=buffer;
115         while(count--) *buf++=*addr;
116 }
117
118 void hd64461_insl(unsigned long port, void *buffer, unsigned long count)
119 {
120         volatile unsigned long* addr=(volatile unsigned long*)PORT2ADDR(port);
121         unsigned long *buf=buffer;
122         while(count--) *buf++=*addr;
123 }
124
125 void hd64461_outsb(unsigned long port, const void *buffer, unsigned long count)
126 {
127         volatile unsigned char* addr=(volatile unsigned char*)PORT2ADDR(port);
128         const unsigned char *buf=buffer;
129         while(count--) *addr=*buf++;
130 }
131
132 void hd64461_outsw(unsigned long port, const void *buffer, unsigned long count)
133 {
134         volatile unsigned short* addr=(volatile unsigned short*)PORT2ADDR(port);
135         const unsigned short *buf=buffer;
136         while(count--) *addr=*buf++;
137 }
138
139 void hd64461_outsl(unsigned long port, const void *buffer, unsigned long count)
140 {
141         volatile unsigned long* addr=(volatile unsigned long*)PORT2ADDR(port);
142         const unsigned long *buf=buffer;
143         while(count--) *addr=*buf++;
144 }
145
146 unsigned short hd64461_readw(void __iomem *addr)
147 {
148         return ctrl_inw(MEM_BASE+(unsigned long __force)addr);
149 }
150
151 void hd64461_writew(unsigned short b, void __iomem *addr)
152 {
153         ctrl_outw(b, MEM_BASE+(unsigned long __force)addr);
154 }
155