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>
30 static u32 __isamem_convert_addr(void *addr)
32 u32 ret, a = (u32) 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;
55 if ((a & 0x20000) == (a & 0x40000) >> 1)
63 * read[bwl] and write[bwl]
65 u8 __readb(void *addr)
67 u32 ret, a = __isamem_convert_addr(addr);
76 u16 __readw(void *addr)
78 u32 a = __isamem_convert_addr(addr);
83 return __raw_readw(a);
86 u32 __readl(void *addr)
88 u32 ret, a = __isamem_convert_addr(addr);
94 ret |= __raw_readw(a + 4) << 16;
98 EXPORT_SYMBOL(__readb);
99 EXPORT_SYMBOL(__readw);
100 EXPORT_SYMBOL(__readl);
102 void __writeb(u8 val, void *addr)
104 u32 a = __isamem_convert_addr(addr);
107 __raw_writel(val, a);
109 __raw_writeb(val, a);
112 void __writew(u16 val, void *addr)
114 u32 a = __isamem_convert_addr(addr);
119 __raw_writew(val, a);
122 void __writel(u32 val, void *addr)
124 u32 a = __isamem_convert_addr(addr);
129 __raw_writew(val, a);
130 __raw_writew(val >> 16, a + 4);
133 EXPORT_SYMBOL(__writeb);
134 EXPORT_SYMBOL(__writew);
135 EXPORT_SYMBOL(__writel);
137 #define SUPERIO_PORT(p) \
138 (((p) >> 3) == (0x3f8 >> 3) || \
139 ((p) >> 3) == (0x2f8 >> 3) || \
140 ((p) >> 3) == (0x378 >> 3))
143 * We're addressing an 8 or 16-bit peripheral which tranfers
144 * odd addresses on the low ISA byte lane.
146 u8 __inb8(unsigned int port)
151 * The SuperIO registers use sane addressing techniques...
153 if (SUPERIO_PORT(port))
154 ret = __raw_readb(ISAIO_BASE + (port << 2));
156 u32 a = ISAIO_BASE + ((port & ~1) << 1);
159 * Shame nothing else does
162 ret = __raw_readl(a);
164 ret = __raw_readb(a);
170 * We're addressing a 16-bit peripheral which transfers odd
171 * addresses on the high ISA byte lane.
173 u8 __inb16(unsigned int port)
178 * The SuperIO registers use sane addressing techniques...
180 if (SUPERIO_PORT(port))
181 ret = __raw_readb(ISAIO_BASE + (port << 2));
183 u32 a = ISAIO_BASE + ((port & ~1) << 1);
186 * Shame nothing else does
188 ret = __raw_readb(a + (port & 1));
193 u16 __inw(unsigned int port)
198 * The SuperIO registers use sane addressing techniques...
200 if (SUPERIO_PORT(port))
201 ret = __raw_readw(ISAIO_BASE + (port << 2));
203 u32 a = ISAIO_BASE + ((port & ~1) << 1);
206 * Shame nothing else does
211 ret = __raw_readw(a);
217 * Fake a 32-bit read with two 16-bit reads. Needed for 3c589.
219 u32 __inl(unsigned int port)
223 if (SUPERIO_PORT(port) || port & 3)
226 a = ISAIO_BASE + (port << 1);
228 return __raw_readw(a) | __raw_readw(a + 4) << 16;
231 EXPORT_SYMBOL(__inb8);
232 EXPORT_SYMBOL(__inb16);
233 EXPORT_SYMBOL(__inw);
234 EXPORT_SYMBOL(__inl);
236 void __outb8(u8 val, unsigned int port)
239 * The SuperIO registers use sane addressing techniques...
241 if (SUPERIO_PORT(port))
242 __raw_writeb(val, ISAIO_BASE + (port << 2));
244 u32 a = ISAIO_BASE + ((port & ~1) << 1);
247 * Shame nothing else does
250 __raw_writel(val, a);
252 __raw_writeb(val, a);
256 void __outb16(u8 val, unsigned int port)
259 * The SuperIO registers use sane addressing techniques...
261 if (SUPERIO_PORT(port))
262 __raw_writeb(val, ISAIO_BASE + (port << 2));
264 u32 a = ISAIO_BASE + ((port & ~1) << 1);
267 * Shame nothing else does
269 __raw_writeb(val, a + (port & 1));
273 void __outw(u16 val, unsigned int port)
278 * The SuperIO registers use sane addressing techniques...
280 if (SUPERIO_PORT(port))
288 __raw_writew(val, ISAIO_BASE + off);
291 void __outl(u32 val, unsigned int port)
296 EXPORT_SYMBOL(__outb8);
297 EXPORT_SYMBOL(__outb16);
298 EXPORT_SYMBOL(__outw);
299 EXPORT_SYMBOL(__outl);
301 extern void __arch_writesb(unsigned long virt, const void *from, int len);
302 extern void __arch_writesw(unsigned long virt, const void *from, int len);
303 extern void __arch_writesl(unsigned long virt, const void *from, int len);
304 extern void __arch_readsb(unsigned long virt, void *from, int len);
305 extern void __arch_readsw(unsigned long virt, void *from, int len);
306 extern void __arch_readsl(unsigned long virt, void *from, int len);
308 void outsb(unsigned int port, const void *from, int len)
312 if (SUPERIO_PORT(port))
315 off = (port & ~1) << 1;
320 __raw_writesb(ISAIO_BASE + off, from, len);
323 void insb(unsigned int port, void *from, int len)
327 if (SUPERIO_PORT(port))
330 off = (port & ~1) << 1;
335 __raw_readsb(ISAIO_BASE + off, from, len);
338 EXPORT_SYMBOL(outsb);
341 void outsw(unsigned int port, const void *from, int len)
345 if (SUPERIO_PORT(port))
348 off = (port & ~1) << 1;
353 __raw_writesw(ISAIO_BASE + off, from, len);
356 void insw(unsigned int port, void *from, int len)
360 if (SUPERIO_PORT(port))
363 off = (port & ~1) << 1;
368 __raw_readsw(ISAIO_BASE + off, from, len);
371 EXPORT_SYMBOL(outsw);
375 * We implement these as 16-bit insw/outsw, mainly for
378 void outsl(unsigned int port, const void *from, int len)
382 if (SUPERIO_PORT(port) || port & 3)
385 __raw_writesw(ISAIO_BASE + off, from, len << 1);
388 void insl(unsigned int port, void *from, int len)
392 if (SUPERIO_PORT(port) || port & 3)
395 __raw_readsw(ISAIO_BASE + off, from, len << 1);
398 EXPORT_SYMBOL(outsl);