This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / sh / boards / se / 7300 / io.c
1 /*
2  * linux/arch/sh/boards/se/7300/io.c
3  *
4  * Copyright (C) 2003 YOSHII Takashi <yoshii-takashi@hitachi-ul.co.jp>
5  */
6
7 #include <linux/config.h>
8 #include <linux/kernel.h>
9 #include <asm/se7300/se7300.h>
10 #include <asm/io.h>
11
12 #define badio(fn, a) panic("bad i/o operation %s for %08lx.", #fn, a)
13
14 struct iop {
15         unsigned long start, end;
16         unsigned long base;
17         struct iop *(*check) (struct iop * p, unsigned long port);
18         unsigned char (*inb) (struct iop * p, unsigned long port);
19         unsigned short (*inw) (struct iop * p, unsigned long port);
20         void (*outb) (struct iop * p, unsigned char value, unsigned long port);
21         void (*outw) (struct iop * p, unsigned short value, unsigned long port);
22 };
23
24 struct iop *
25 simple_check(struct iop *p, unsigned long port)
26 {
27         if ((p->start <= port) && (port <= p->end))
28                 return p;
29         else
30                 badio(check, port);
31 }
32
33 struct iop *
34 ide_check(struct iop *p, unsigned long port)
35 {
36         if (((0x1f0 <= port) && (port <= 0x1f7)) || (port == 0x3f7))
37                 return p;
38         return NULL;
39 }
40
41 unsigned char
42 simple_inb(struct iop *p, unsigned long port)
43 {
44         return *(unsigned char *) (p->base + port);
45 }
46
47 unsigned short
48 simple_inw(struct iop *p, unsigned long port)
49 {
50         return *(unsigned short *) (p->base + port);
51 }
52
53 void
54 simple_outb(struct iop *p, unsigned char value, unsigned long port)
55 {
56         *(unsigned char *) (p->base + port) = value;
57 }
58
59 void
60 simple_outw(struct iop *p, unsigned short value, unsigned long port)
61 {
62         *(unsigned short *) (p->base + port) = value;
63 }
64
65 unsigned char
66 pcc_inb(struct iop *p, unsigned long port)
67 {
68         unsigned long addr = p->base + port + 0x40000;
69         unsigned long v;
70
71         if (port & 1)
72                 addr += 0x00400000;
73         v = *(volatile unsigned char *) addr;
74         return v;
75 }
76
77 void
78 pcc_outb(struct iop *p, unsigned char value, unsigned long port)
79 {
80         unsigned long addr = p->base + port + 0x40000;
81
82         if (port & 1)
83                 addr += 0x00400000;
84         *(volatile unsigned char *) addr = value;
85 }
86
87 unsigned char
88 bad_inb(struct iop *p, unsigned long port)
89 {
90         badio(inb, port);
91 }
92
93 void
94 bad_outb(struct iop *p, unsigned char value, unsigned long port)
95 {
96         badio(inw, port);
97 }
98
99 /* MSTLANEX01 LAN at 0xb400:0000 */
100 static struct iop laniop = {
101         .start = 0x300,
102         .end = 0x30f,
103         .base = 0xb4000000,
104         .check = simple_check,
105         .inb = simple_inb,
106         .inw = simple_inw,
107         .outb = simple_outb,
108         .outw = simple_outw,
109 };
110
111 /* NE2000 pc card NIC */
112 static struct iop neiop = {
113         .start = 0x280,
114         .end = 0x29f,
115         .base = 0xb0600000 + 0x80,      /* soft 0x280 -> hard 0x300 */
116         .check = simple_check,
117         .inb = pcc_inb,
118         .inw = simple_inw,
119         .outb = pcc_outb,
120         .outw = simple_outw,
121 };
122
123 /* CF in CF slot */
124 static struct iop cfiop = {
125         .base = 0xb0600000,
126         .check = ide_check,
127         .inb = pcc_inb,
128         .inw = simple_inw,
129         .outb = pcc_outb,
130         .outw = simple_outw,
131 };
132
133 static __inline__ struct iop *
134 port2iop(unsigned long port)
135 {
136         if (0) ;
137 #if defined(CONFIG_SMC91111)
138         else if (laniop.check(&laniop, port))
139                 return &laniop;
140 #endif
141 #if defined(CONFIG_NE2000)
142         else if (neiop.check(&neiop, port))
143                 return &neiop;
144 #endif
145 #if defined(CONFIG_IDE)
146         else if (cfiop.check(&cfiop, port))
147                 return &cfiop;
148 #endif
149         else
150                 return &neiop;  /* fallback */
151 }
152
153 static inline void
154 delay(void)
155 {
156         ctrl_inw(0xac000000);
157         ctrl_inw(0xac000000);
158 }
159
160 unsigned char
161 sh7300se_inb(unsigned long port)
162 {
163         struct iop *p = port2iop(port);
164         return (p->inb) (p, port);
165 }
166
167 unsigned char
168 sh7300se_inb_p(unsigned long port)
169 {
170         unsigned char v = sh7300se_inb(port);
171         delay();
172         return v;
173 }
174
175 unsigned short
176 sh7300se_inw(unsigned long port)
177 {
178         struct iop *p = port2iop(port);
179         return (p->inw) (p, port);
180 }
181
182 unsigned int
183 sh7300se_inl(unsigned long port)
184 {
185         badio(inl, port);
186 }
187
188 void
189 sh7300se_outb(unsigned char value, unsigned long port)
190 {
191         struct iop *p = port2iop(port);
192         (p->outb) (p, value, port);
193 }
194
195 void
196 sh7300se_outb_p(unsigned char value, unsigned long port)
197 {
198         sh7300se_outb(value, port);
199         delay();
200 }
201
202 void
203 sh7300se_outw(unsigned short value, unsigned long port)
204 {
205         struct iop *p = port2iop(port);
206         (p->outw) (p, value, port);
207 }
208
209 void
210 sh7300se_outl(unsigned int value, unsigned long port)
211 {
212         badio(outl, port);
213 }
214
215 void
216 sh7300se_insb(unsigned long port, void *addr, unsigned long count)
217 {
218         unsigned char *a = addr;
219         struct iop *p = port2iop(port);
220         while (count--)
221                 *a++ = (p->inb) (p, port);
222 }
223
224 void
225 sh7300se_insw(unsigned long port, void *addr, unsigned long count)
226 {
227         unsigned short *a = addr;
228         struct iop *p = port2iop(port);
229         while (count--)
230                 *a++ = (p->inw) (p, port);
231 }
232
233 void
234 sh7300se_insl(unsigned long port, void *addr, unsigned long count)
235 {
236         badio(insl, port);
237 }
238
239 void
240 sh7300se_outsb(unsigned long port, const void *addr, unsigned long count)
241 {
242         unsigned char *a = (unsigned char *) addr;
243         struct iop *p = port2iop(port);
244         while (count--)
245                 (p->outb) (p, *a++, port);
246 }
247
248 void
249 sh7300se_outsw(unsigned long port, const void *addr, unsigned long count)
250 {
251         unsigned short *a = (unsigned short *) addr;
252         struct iop *p = port2iop(port);
253         while (count--)
254                 (p->outw) (p, *a++, port);
255 }
256
257 void
258 sh7300se_outsl(unsigned long port, const void *addr, unsigned long count)
259 {
260         badio(outsw, port);
261 }