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/hardware.h>
31 static void __iomem *__isamem_convert_addr(void __iomem *addr)
33 u32 ret, a = (u32 __force) addr;
36 * The PCMCIA controller is wired up as follows:
37 * +---------+---------+---------+---------+---------+---------+
38 * PCMCIA | 2 2 2 2 | 1 1 1 1 | 1 1 1 1 | 1 1 | | |
39 * | 3 2 1 0 | 9 8 7 6 | 5 4 3 2 | 1 0 9 8 | 7 6 5 4 | 3 2 1 0 |
40 * +---------+---------+---------+---------+---------+---------+
41 * CPU | 2 2 2 2 | 2 1 1 1 | 1 1 1 1 | 1 1 1 | | |
42 * | 4 3 2 1 | 0 9 9 8 | 7 6 5 4 | 3 2 0 9 | 8 7 6 5 | 4 3 2 x |
43 * +---------+---------+---------+---------+---------+---------+
45 * This means that we can access PCMCIA regions as follows:
46 * 0x*10000 -> 0x*1ffff
47 * 0x*70000 -> 0x*7ffff
48 * 0x*90000 -> 0x*9ffff
49 * 0x*f0000 -> 0x*fffff
51 ret = (a & 0xf803fe) << 1;
52 ret |= (a & 0x03fc00) << 2;
56 if ((a & 0x20000) == (a & 0x40000) >> 1)
57 return (void __iomem *)ret;
64 * read[bwl] and write[bwl]
66 u8 __readb(void __iomem *addr)
68 void __iomem *a = __isamem_convert_addr(addr);
71 if ((unsigned long)addr & 1)
78 u16 __readw(void __iomem *addr)
80 void __iomem *a = __isamem_convert_addr(addr);
82 if ((unsigned long)addr & 1)
85 return __raw_readw(a);
88 u32 __readl(void __iomem *addr)
90 void __iomem *a = __isamem_convert_addr(addr);
93 if ((unsigned long)addr & 3)
97 ret |= __raw_readw(a + 4) << 16;
101 EXPORT_SYMBOL(__readb);
102 EXPORT_SYMBOL(__readw);
103 EXPORT_SYMBOL(__readl);
105 void __writeb(u8 val, void __iomem *addr)
107 void __iomem *a = __isamem_convert_addr(addr);
109 if ((unsigned long)addr & 1)
110 __raw_writel(val, a);
112 __raw_writeb(val, a);
115 void __writew(u16 val, void __iomem *addr)
117 void __iomem *a = __isamem_convert_addr(addr);
119 if ((unsigned long)addr & 1)
122 __raw_writew(val, a);
125 void __writel(u32 val, void __iomem *addr)
127 void __iomem *a = __isamem_convert_addr(addr);
129 if ((unsigned long)addr & 3)
132 __raw_writew(val, a);
133 __raw_writew(val >> 16, a + 4);
136 EXPORT_SYMBOL(__writeb);
137 EXPORT_SYMBOL(__writew);
138 EXPORT_SYMBOL(__writel);
140 #define SUPERIO_PORT(p) \
141 (((p) >> 3) == (0x3f8 >> 3) || \
142 ((p) >> 3) == (0x2f8 >> 3) || \
143 ((p) >> 3) == (0x378 >> 3))
146 * We're addressing an 8 or 16-bit peripheral which tranfers
147 * odd addresses on the low ISA byte lane.
149 u8 __inb8(unsigned int port)
154 * The SuperIO registers use sane addressing techniques...
156 if (SUPERIO_PORT(port))
157 ret = __raw_readb((void __iomem *)ISAIO_BASE + (port << 2));
159 void __iomem *a = (void __iomem *)ISAIO_BASE + ((port & ~1) << 1);
162 * Shame nothing else does
165 ret = __raw_readl(a);
167 ret = __raw_readb(a);
173 * We're addressing a 16-bit peripheral which transfers odd
174 * addresses on the high ISA byte lane.
176 u8 __inb16(unsigned int port)
181 * The SuperIO registers use sane addressing techniques...
183 if (SUPERIO_PORT(port))
186 offset = (port & ~1) << 1 | (port & 1);
188 return __raw_readb((void __iomem *)ISAIO_BASE + offset);
191 u16 __inw(unsigned int port)
196 * The SuperIO registers use sane addressing techniques...
198 if (SUPERIO_PORT(port))
204 return __raw_readw((void __iomem *)ISAIO_BASE + offset);
208 * Fake a 32-bit read with two 16-bit reads. Needed for 3c589.
210 u32 __inl(unsigned int port)
214 if (SUPERIO_PORT(port) || port & 3)
217 a = (void __iomem *)ISAIO_BASE + ((port & ~1) << 1);
219 return __raw_readw(a) | __raw_readw(a + 4) << 16;
222 EXPORT_SYMBOL(__inb8);
223 EXPORT_SYMBOL(__inb16);
224 EXPORT_SYMBOL(__inw);
225 EXPORT_SYMBOL(__inl);
227 void __outb8(u8 val, unsigned int port)
230 * The SuperIO registers use sane addressing techniques...
232 if (SUPERIO_PORT(port))
233 __raw_writeb(val, (void __iomem *)ISAIO_BASE + (port << 2));
235 void __iomem *a = (void __iomem *)ISAIO_BASE + ((port & ~1) << 1);
238 * Shame nothing else does
241 __raw_writel(val, a);
243 __raw_writeb(val, a);
247 void __outb16(u8 val, unsigned int port)
252 * The SuperIO registers use sane addressing techniques...
254 if (SUPERIO_PORT(port))
257 offset = (port & ~1) << 1 | (port & 1);
259 __raw_writeb(val, (void __iomem *)ISAIO_BASE + offset);
262 void __outw(u16 val, unsigned int port)
267 * The SuperIO registers use sane addressing techniques...
269 if (SUPERIO_PORT(port))
275 __raw_writew(val, (void __iomem *)ISAIO_BASE + offset);
278 void __outl(u32 val, unsigned int port)
283 EXPORT_SYMBOL(__outb8);
284 EXPORT_SYMBOL(__outb16);
285 EXPORT_SYMBOL(__outw);
286 EXPORT_SYMBOL(__outl);
288 void outsb(unsigned int port, const void *from, int len)
292 if (SUPERIO_PORT(port))
295 off = (port & ~1) << 1;
300 __raw_writesb((void __iomem *)ISAIO_BASE + off, from, len);
303 void insb(unsigned int port, void *from, int len)
307 if (SUPERIO_PORT(port))
310 off = (port & ~1) << 1;
315 __raw_readsb((void __iomem *)ISAIO_BASE + off, from, len);
318 EXPORT_SYMBOL(outsb);
321 void outsw(unsigned int port, const void *from, int len)
325 if (SUPERIO_PORT(port))
328 off = (port & ~1) << 1;
333 __raw_writesw((void __iomem *)ISAIO_BASE + off, from, len);
336 void insw(unsigned int port, void *from, int len)
340 if (SUPERIO_PORT(port))
343 off = (port & ~1) << 1;
348 __raw_readsw((void __iomem *)ISAIO_BASE + off, from, len);
351 EXPORT_SYMBOL(outsw);
355 * We implement these as 16-bit insw/outsw, mainly for
358 void outsl(unsigned int port, const void *from, int len)
362 if (SUPERIO_PORT(port) || port & 3)
365 __raw_writesw((void __iomem *)ISAIO_BASE + off, from, len << 1);
368 void insl(unsigned int port, void *from, int len)
372 if (SUPERIO_PORT(port) || port & 3)
375 __raw_readsw((void __iomem *)ISAIO_BASE + off, from, len << 1);
378 EXPORT_SYMBOL(outsl);