[PATCH] orinoco: Annotate endianess of variables and structure members.
[linux/fpc-iii.git] / arch / arm / mach-ebsa110 / io.c
blobef7eb5dc91bd9560a80251fa33ddc338b46e8710
1 /*
2 * linux/arch/arm/mach-ebsa110/isamem.c
4 * Copyright (C) 2001 Russell King
6 * Perform "ISA" memory and IO accesses. The EBSA110 has some "peculiarities"
7 * in the way it handles accesses to odd IO ports on 16-bit devices. These
8 * devices have their D0-D15 lines connected to the processors D0-D15 lines.
9 * Since they expect all byte IO operations to be performed on D0-D7, and the
10 * StrongARM expects to transfer the byte to these odd addresses on D8-D15,
11 * we must use a trick to get the required behaviour.
13 * The trick employed here is to use long word stores to odd address -1. The
14 * glue logic picks this up as a "trick" access, and asserts the LSB of the
15 * peripherals address bus, thereby accessing the odd IO port. Meanwhile, the
16 * StrongARM transfers its data on D0-D7 as expected.
18 * Things get more interesting on the pass-1 EBSA110 - the PCMCIA controller
19 * wiring was screwed in such a way that it had limited memory space access.
20 * Luckily, the work-around for this is not too horrible. See
21 * __isamem_convert_addr for the details.
23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/types.h>
27 #include <asm/io.h>
28 #include <asm/page.h>
30 static void __iomem *__isamem_convert_addr(void __iomem *addr)
32 u32 ret, a = (u32 __force) addr;
35 * The PCMCIA controller is wired up as follows:
36 * +---------+---------+---------+---------+---------+---------+
37 * PCMCIA | 2 2 2 2 | 1 1 1 1 | 1 1 1 1 | 1 1 | | |
38 * | 3 2 1 0 | 9 8 7 6 | 5 4 3 2 | 1 0 9 8 | 7 6 5 4 | 3 2 1 0 |
39 * +---------+---------+---------+---------+---------+---------+
40 * CPU | 2 2 2 2 | 2 1 1 1 | 1 1 1 1 | 1 1 1 | | |
41 * | 4 3 2 1 | 0 9 9 8 | 7 6 5 4 | 3 2 0 9 | 8 7 6 5 | 4 3 2 x |
42 * +---------+---------+---------+---------+---------+---------+
44 * This means that we can access PCMCIA regions as follows:
45 * 0x*10000 -> 0x*1ffff
46 * 0x*70000 -> 0x*7ffff
47 * 0x*90000 -> 0x*9ffff
48 * 0x*f0000 -> 0x*fffff
50 ret = (a & 0xf803fe) << 1;
51 ret |= (a & 0x03fc00) << 2;
53 ret += 0xe8000000;
55 if ((a & 0x20000) == (a & 0x40000) >> 1)
56 return (void __iomem *)ret;
58 BUG();
59 return NULL;
63 * read[bwl] and write[bwl]
65 u8 __readb(void __iomem *addr)
67 void __iomem *a = __isamem_convert_addr(addr);
68 u32 ret;
70 if ((unsigned long)addr & 1)
71 ret = __raw_readl(a);
72 else
73 ret = __raw_readb(a);
74 return ret;
77 u16 __readw(void __iomem *addr)
79 void __iomem *a = __isamem_convert_addr(addr);
81 if ((unsigned long)addr & 1)
82 BUG();
84 return __raw_readw(a);
87 u32 __readl(void __iomem *addr)
89 void __iomem *a = __isamem_convert_addr(addr);
90 u32 ret;
92 if ((unsigned long)addr & 3)
93 BUG();
95 ret = __raw_readw(a);
96 ret |= __raw_readw(a + 4) << 16;
97 return ret;
100 EXPORT_SYMBOL(__readb);
101 EXPORT_SYMBOL(__readw);
102 EXPORT_SYMBOL(__readl);
104 void __writeb(u8 val, void __iomem *addr)
106 void __iomem *a = __isamem_convert_addr(addr);
108 if ((unsigned long)addr & 1)
109 __raw_writel(val, a);
110 else
111 __raw_writeb(val, a);
114 void __writew(u16 val, void __iomem *addr)
116 void __iomem *a = __isamem_convert_addr(addr);
118 if ((unsigned long)addr & 1)
119 BUG();
121 __raw_writew(val, a);
124 void __writel(u32 val, void __iomem *addr)
126 void __iomem *a = __isamem_convert_addr(addr);
128 if ((unsigned long)addr & 3)
129 BUG();
131 __raw_writew(val, a);
132 __raw_writew(val >> 16, a + 4);
135 EXPORT_SYMBOL(__writeb);
136 EXPORT_SYMBOL(__writew);
137 EXPORT_SYMBOL(__writel);
139 #define SUPERIO_PORT(p) \
140 (((p) >> 3) == (0x3f8 >> 3) || \
141 ((p) >> 3) == (0x2f8 >> 3) || \
142 ((p) >> 3) == (0x378 >> 3))
145 * We're addressing an 8 or 16-bit peripheral which tranfers
146 * odd addresses on the low ISA byte lane.
148 u8 __inb8(unsigned int port)
150 u32 ret;
153 * The SuperIO registers use sane addressing techniques...
155 if (SUPERIO_PORT(port))
156 ret = __raw_readb((void __iomem *)ISAIO_BASE + (port << 2));
157 else {
158 void __iomem *a = (void __iomem *)ISAIO_BASE + ((port & ~1) << 1);
161 * Shame nothing else does
163 if (port & 1)
164 ret = __raw_readl(a);
165 else
166 ret = __raw_readb(a);
168 return ret;
172 * We're addressing a 16-bit peripheral which transfers odd
173 * addresses on the high ISA byte lane.
175 u8 __inb16(unsigned int port)
177 unsigned int offset;
180 * The SuperIO registers use sane addressing techniques...
182 if (SUPERIO_PORT(port))
183 offset = port << 2;
184 else
185 offset = (port & ~1) << 1 | (port & 1);
187 return __raw_readb((void __iomem *)ISAIO_BASE + offset);
190 u16 __inw(unsigned int port)
192 unsigned int offset;
195 * The SuperIO registers use sane addressing techniques...
197 if (SUPERIO_PORT(port))
198 offset = port << 2;
199 else {
200 offset = port << 1;
201 BUG_ON(port & 1);
203 return __raw_readw((void __iomem *)ISAIO_BASE + offset);
207 * Fake a 32-bit read with two 16-bit reads. Needed for 3c589.
209 u32 __inl(unsigned int port)
211 void __iomem *a;
213 if (SUPERIO_PORT(port) || port & 3)
214 BUG();
216 a = (void __iomem *)ISAIO_BASE + ((port & ~1) << 1);
218 return __raw_readw(a) | __raw_readw(a + 4) << 16;
221 EXPORT_SYMBOL(__inb8);
222 EXPORT_SYMBOL(__inb16);
223 EXPORT_SYMBOL(__inw);
224 EXPORT_SYMBOL(__inl);
226 void __outb8(u8 val, unsigned int port)
229 * The SuperIO registers use sane addressing techniques...
231 if (SUPERIO_PORT(port))
232 __raw_writeb(val, (void __iomem *)ISAIO_BASE + (port << 2));
233 else {
234 void __iomem *a = (void __iomem *)ISAIO_BASE + ((port & ~1) << 1);
237 * Shame nothing else does
239 if (port & 1)
240 __raw_writel(val, a);
241 else
242 __raw_writeb(val, a);
246 void __outb16(u8 val, unsigned int port)
248 unsigned int offset;
251 * The SuperIO registers use sane addressing techniques...
253 if (SUPERIO_PORT(port))
254 offset = port << 2;
255 else
256 offset = (port & ~1) << 1 | (port & 1);
258 __raw_writeb(val, (void __iomem *)ISAIO_BASE + offset);
261 void __outw(u16 val, unsigned int port)
263 unsigned int offset;
266 * The SuperIO registers use sane addressing techniques...
268 if (SUPERIO_PORT(port))
269 offset = port << 2;
270 else {
271 offset = port << 1;
272 BUG_ON(port & 1);
274 __raw_writew(val, (void __iomem *)ISAIO_BASE + offset);
277 void __outl(u32 val, unsigned int port)
279 BUG();
282 EXPORT_SYMBOL(__outb8);
283 EXPORT_SYMBOL(__outb16);
284 EXPORT_SYMBOL(__outw);
285 EXPORT_SYMBOL(__outl);
287 void outsb(unsigned int port, const void *from, int len)
289 u32 off;
291 if (SUPERIO_PORT(port))
292 off = port << 2;
293 else {
294 off = (port & ~1) << 1;
295 if (port & 1)
296 BUG();
299 __raw_writesb((void __iomem *)ISAIO_BASE + off, from, len);
302 void insb(unsigned int port, void *from, int len)
304 u32 off;
306 if (SUPERIO_PORT(port))
307 off = port << 2;
308 else {
309 off = (port & ~1) << 1;
310 if (port & 1)
311 BUG();
314 __raw_readsb((void __iomem *)ISAIO_BASE + off, from, len);
317 EXPORT_SYMBOL(outsb);
318 EXPORT_SYMBOL(insb);
320 void outsw(unsigned int port, const void *from, int len)
322 u32 off;
324 if (SUPERIO_PORT(port))
325 off = port << 2;
326 else {
327 off = (port & ~1) << 1;
328 if (port & 1)
329 BUG();
332 __raw_writesw((void __iomem *)ISAIO_BASE + off, from, len);
335 void insw(unsigned int port, void *from, int len)
337 u32 off;
339 if (SUPERIO_PORT(port))
340 off = port << 2;
341 else {
342 off = (port & ~1) << 1;
343 if (port & 1)
344 BUG();
347 __raw_readsw((void __iomem *)ISAIO_BASE + off, from, len);
350 EXPORT_SYMBOL(outsw);
351 EXPORT_SYMBOL(insw);
354 * We implement these as 16-bit insw/outsw, mainly for
355 * 3c589 cards.
357 void outsl(unsigned int port, const void *from, int len)
359 u32 off = port << 1;
361 if (SUPERIO_PORT(port) || port & 3)
362 BUG();
364 __raw_writesw((void __iomem *)ISAIO_BASE + off, from, len << 1);
367 void insl(unsigned int port, void *from, int len)
369 u32 off = port << 1;
371 if (SUPERIO_PORT(port) || port & 3)
372 BUG();
374 __raw_readsw((void __iomem *)ISAIO_BASE + off, from, len << 1);
377 EXPORT_SYMBOL(outsl);
378 EXPORT_SYMBOL(insl);