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 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;
55 if ((a & 0x20000) == (a & 0x40000) >> 1)
56 return (void __iomem *)ret;
63 * read[bwl] and write[bwl]
65 u8 __readb(void __iomem *addr)
67 void __iomem *a = __isamem_convert_addr(addr);
70 if ((unsigned long)addr & 1)
77 u16 __readw(void __iomem *addr)
79 void __iomem *a = __isamem_convert_addr(addr);
81 if ((unsigned long)addr & 1)
84 return __raw_readw(a);
87 u32 __readl(void __iomem *addr)
89 void __iomem *a = __isamem_convert_addr(addr);
92 if ((unsigned long)addr & 3)
96 ret |= __raw_readw(a + 4) << 16;
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);
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)
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)
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)
153 * The SuperIO registers use sane addressing techniques...
155 if (SUPERIO_PORT(port))
156 ret = __raw_readb((void __iomem *)ISAIO_BASE + (port << 2));
158 void __iomem *a = (void __iomem *)ISAIO_BASE + ((port & ~1) << 1);
161 * Shame nothing else does
164 ret = __raw_readl(a);
166 ret = __raw_readb(a);
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)
180 * The SuperIO registers use sane addressing techniques...
182 if (SUPERIO_PORT(port))
185 offset = (port & ~1) << 1 | (port & 1);
187 return __raw_readb((void __iomem *)ISAIO_BASE + offset);
190 u16 __inw(unsigned int port)
195 * The SuperIO registers use sane addressing techniques...
197 if (SUPERIO_PORT(port))
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)
213 if (SUPERIO_PORT(port) || port & 3)
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));
234 void __iomem *a = (void __iomem *)ISAIO_BASE + ((port & ~1) << 1);
237 * Shame nothing else does
240 __raw_writel(val, a);
242 __raw_writeb(val, a);
246 void __outb16(u8 val, unsigned int port)
251 * The SuperIO registers use sane addressing techniques...
253 if (SUPERIO_PORT(port))
256 offset = (port & ~1) << 1 | (port & 1);
258 __raw_writeb(val, (void __iomem *)ISAIO_BASE + offset);
261 void __outw(u16 val, unsigned int port)
266 * The SuperIO registers use sane addressing techniques...
268 if (SUPERIO_PORT(port))
274 __raw_writew(val, (void __iomem *)ISAIO_BASE + offset);
277 void __outl(u32 val, unsigned int port)
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)
291 if (SUPERIO_PORT(port))
294 off = (port & ~1) << 1;
299 __raw_writesb((void __iomem *)ISAIO_BASE + off, from, len);
302 void insb(unsigned int port, void *from, int len)
306 if (SUPERIO_PORT(port))
309 off = (port & ~1) << 1;
314 __raw_readsb((void __iomem *)ISAIO_BASE + off, from, len);
317 EXPORT_SYMBOL(outsb);
320 void outsw(unsigned int port, const void *from, int len)
324 if (SUPERIO_PORT(port))
327 off = (port & ~1) << 1;
332 __raw_writesw((void __iomem *)ISAIO_BASE + off, from, len);
335 void insw(unsigned int port, void *from, int len)
339 if (SUPERIO_PORT(port))
342 off = (port & ~1) << 1;
347 __raw_readsw((void __iomem *)ISAIO_BASE + off, from, len);
350 EXPORT_SYMBOL(outsw);
354 * We implement these as 16-bit insw/outsw, mainly for
357 void outsl(unsigned int port, const void *from, int len)
361 if (SUPERIO_PORT(port) || port & 3)
364 __raw_writesw((void __iomem *)ISAIO_BASE + off, from, len << 1);
367 void insl(unsigned int port, void *from, int len)
371 if (SUPERIO_PORT(port) || port & 3)
374 __raw_readsw((void __iomem *)ISAIO_BASE + off, from, len << 1);
377 EXPORT_SYMBOL(outsl);