1 // SPDX-License-Identifier: GPL-2.0
3 * linux/arch/arm/mach-ebsa110/isamem.c
5 * Copyright (C) 2001 Russell King
7 * Perform "ISA" memory and IO accesses. The EBSA110 has some "peculiarities"
8 * in the way it handles accesses to odd IO ports on 16-bit devices. These
9 * devices have their D0-D15 lines connected to the processors D0-D15 lines.
10 * Since they expect all byte IO operations to be performed on D0-D7, and the
11 * StrongARM expects to transfer the byte to these odd addresses on D8-D15,
12 * we must use a trick to get the required behaviour.
14 * The trick employed here is to use long word stores to odd address -1. The
15 * glue logic picks this up as a "trick" access, and asserts the LSB of the
16 * peripherals address bus, thereby accessing the odd IO port. Meanwhile, the
17 * StrongARM transfers its data on D0-D7 as expected.
19 * Things get more interesting on the pass-1 EBSA110 - the PCMCIA controller
20 * wiring was screwed in such a way that it had limited memory space access.
21 * Luckily, the work-around for this is not too horrible. See
22 * __isamem_convert_addr for the details.
24 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/types.h>
29 #include <mach/hardware.h>
32 static void __iomem
*__isamem_convert_addr(const volatile void __iomem
*addr
)
34 u32 ret
, a
= (u32 __force
) addr
;
37 * The PCMCIA controller is wired up as follows:
38 * +---------+---------+---------+---------+---------+---------+
39 * PCMCIA | 2 2 2 2 | 1 1 1 1 | 1 1 1 1 | 1 1 | | |
40 * | 3 2 1 0 | 9 8 7 6 | 5 4 3 2 | 1 0 9 8 | 7 6 5 4 | 3 2 1 0 |
41 * +---------+---------+---------+---------+---------+---------+
42 * CPU | 2 2 2 2 | 2 1 1 1 | 1 1 1 1 | 1 1 1 | | |
43 * | 4 3 2 1 | 0 9 9 8 | 7 6 5 4 | 3 2 0 9 | 8 7 6 5 | 4 3 2 x |
44 * +---------+---------+---------+---------+---------+---------+
46 * This means that we can access PCMCIA regions as follows:
47 * 0x*10000 -> 0x*1ffff
48 * 0x*70000 -> 0x*7ffff
49 * 0x*90000 -> 0x*9ffff
50 * 0x*f0000 -> 0x*fffff
52 ret
= (a
& 0xf803fe) << 1;
53 ret
|= (a
& 0x03fc00) << 2;
57 if ((a
& 0x20000) == (a
& 0x40000) >> 1)
58 return (void __iomem
*)ret
;
65 * read[bwl] and write[bwl]
67 u8
__readb(const volatile void __iomem
*addr
)
69 void __iomem
*a
= __isamem_convert_addr(addr
);
72 if ((unsigned long)addr
& 1)
79 u16
__readw(const volatile void __iomem
*addr
)
81 void __iomem
*a
= __isamem_convert_addr(addr
);
83 if ((unsigned long)addr
& 1)
86 return __raw_readw(a
);
89 u32
__readl(const volatile void __iomem
*addr
)
91 void __iomem
*a
= __isamem_convert_addr(addr
);
94 if ((unsigned long)addr
& 3)
98 ret
|= __raw_readw(a
+ 4) << 16;
102 EXPORT_SYMBOL(__readb
);
103 EXPORT_SYMBOL(__readw
);
104 EXPORT_SYMBOL(__readl
);
106 void readsw(const volatile void __iomem
*addr
, void *data
, int len
)
108 void __iomem
*a
= __isamem_convert_addr(addr
);
110 BUG_ON((unsigned long)addr
& 1);
112 __raw_readsw(a
, data
, len
);
114 EXPORT_SYMBOL(readsw
);
116 void readsl(const volatile void __iomem
*addr
, void *data
, int len
)
118 void __iomem
*a
= __isamem_convert_addr(addr
);
120 BUG_ON((unsigned long)addr
& 3);
122 __raw_readsl(a
, data
, len
);
124 EXPORT_SYMBOL(readsl
);
126 void __writeb(u8 val
, volatile void __iomem
*addr
)
128 void __iomem
*a
= __isamem_convert_addr(addr
);
130 if ((unsigned long)addr
& 1)
131 __raw_writel(val
, a
);
133 __raw_writeb(val
, a
);
136 void __writew(u16 val
, volatile void __iomem
*addr
)
138 void __iomem
*a
= __isamem_convert_addr(addr
);
140 if ((unsigned long)addr
& 1)
143 __raw_writew(val
, a
);
146 void __writel(u32 val
, volatile void __iomem
*addr
)
148 void __iomem
*a
= __isamem_convert_addr(addr
);
150 if ((unsigned long)addr
& 3)
153 __raw_writew(val
, a
);
154 __raw_writew(val
>> 16, a
+ 4);
157 EXPORT_SYMBOL(__writeb
);
158 EXPORT_SYMBOL(__writew
);
159 EXPORT_SYMBOL(__writel
);
161 void writesw(volatile void __iomem
*addr
, const void *data
, int len
)
163 void __iomem
*a
= __isamem_convert_addr(addr
);
165 BUG_ON((unsigned long)addr
& 1);
167 __raw_writesw(a
, data
, len
);
169 EXPORT_SYMBOL(writesw
);
171 void writesl(volatile void __iomem
*addr
, const void *data
, int len
)
173 void __iomem
*a
= __isamem_convert_addr(addr
);
175 BUG_ON((unsigned long)addr
& 3);
177 __raw_writesl(a
, data
, len
);
179 EXPORT_SYMBOL(writesl
);
182 * The EBSA110 has a weird "ISA IO" region:
184 * Region 0 (addr = 0xf0000000 + io << 2)
185 * --------------------------------------------------------
186 * Physical region IO region
187 * f0000fe0 - f0000ffc 3f8 - 3ff ttyS0
188 * f0000e60 - f0000e64 398 - 399
189 * f0000de0 - f0000dfc 378 - 37f lp0
190 * f0000be0 - f0000bfc 2f8 - 2ff ttyS1
192 * Region 1 (addr = 0xf0000000 + (io & ~1) << 1 + (io & 1))
193 * --------------------------------------------------------
194 * Physical region IO region
195 * f00014f1 a79 pnp write data
196 * f00007c0 - f00007c1 3e0 - 3e1 pcmcia
197 * f00004f1 279 pnp address
198 * f0000440 - f000046c 220 - 236 eth0
199 * f0000405 203 pnp read data
201 #define SUPERIO_PORT(p) \
202 (((p) >> 3) == (0x3f8 >> 3) || \
203 ((p) >> 3) == (0x2f8 >> 3) || \
204 ((p) >> 3) == (0x378 >> 3))
207 * We're addressing an 8 or 16-bit peripheral which tranfers
208 * odd addresses on the low ISA byte lane.
210 u8
__inb8(unsigned int port
)
215 * The SuperIO registers use sane addressing techniques...
217 if (SUPERIO_PORT(port
))
218 ret
= __raw_readb((void __iomem
*)ISAIO_BASE
+ (port
<< 2));
220 void __iomem
*a
= (void __iomem
*)ISAIO_BASE
+ ((port
& ~1) << 1);
223 * Shame nothing else does
226 ret
= __raw_readl(a
);
228 ret
= __raw_readb(a
);
234 * We're addressing a 16-bit peripheral which transfers odd
235 * addresses on the high ISA byte lane.
237 u8
__inb16(unsigned int port
)
242 * The SuperIO registers use sane addressing techniques...
244 if (SUPERIO_PORT(port
))
247 offset
= (port
& ~1) << 1 | (port
& 1);
249 return __raw_readb((void __iomem
*)ISAIO_BASE
+ offset
);
252 u16
__inw(unsigned int port
)
257 * The SuperIO registers use sane addressing techniques...
259 if (SUPERIO_PORT(port
))
265 return __raw_readw((void __iomem
*)ISAIO_BASE
+ offset
);
269 * Fake a 32-bit read with two 16-bit reads. Needed for 3c589.
271 u32
__inl(unsigned int port
)
275 if (SUPERIO_PORT(port
) || port
& 3)
278 a
= (void __iomem
*)ISAIO_BASE
+ ((port
& ~1) << 1);
280 return __raw_readw(a
) | __raw_readw(a
+ 4) << 16;
283 EXPORT_SYMBOL(__inb8
);
284 EXPORT_SYMBOL(__inb16
);
285 EXPORT_SYMBOL(__inw
);
286 EXPORT_SYMBOL(__inl
);
288 void __outb8(u8 val
, unsigned int port
)
291 * The SuperIO registers use sane addressing techniques...
293 if (SUPERIO_PORT(port
))
294 __raw_writeb(val
, (void __iomem
*)ISAIO_BASE
+ (port
<< 2));
296 void __iomem
*a
= (void __iomem
*)ISAIO_BASE
+ ((port
& ~1) << 1);
299 * Shame nothing else does
302 __raw_writel(val
, a
);
304 __raw_writeb(val
, a
);
308 void __outb16(u8 val
, unsigned int port
)
313 * The SuperIO registers use sane addressing techniques...
315 if (SUPERIO_PORT(port
))
318 offset
= (port
& ~1) << 1 | (port
& 1);
320 __raw_writeb(val
, (void __iomem
*)ISAIO_BASE
+ offset
);
323 void __outw(u16 val
, unsigned int port
)
328 * The SuperIO registers use sane addressing techniques...
330 if (SUPERIO_PORT(port
))
336 __raw_writew(val
, (void __iomem
*)ISAIO_BASE
+ offset
);
339 void __outl(u32 val
, unsigned int port
)
344 EXPORT_SYMBOL(__outb8
);
345 EXPORT_SYMBOL(__outb16
);
346 EXPORT_SYMBOL(__outw
);
347 EXPORT_SYMBOL(__outl
);
349 void outsb(unsigned int port
, const void *from
, int len
)
353 if (SUPERIO_PORT(port
))
356 off
= (port
& ~1) << 1;
361 __raw_writesb((void __iomem
*)ISAIO_BASE
+ off
, from
, len
);
364 void insb(unsigned int port
, void *from
, int len
)
368 if (SUPERIO_PORT(port
))
371 off
= (port
& ~1) << 1;
376 __raw_readsb((void __iomem
*)ISAIO_BASE
+ off
, from
, len
);
379 EXPORT_SYMBOL(outsb
);
382 void outsw(unsigned int port
, const void *from
, int len
)
386 if (SUPERIO_PORT(port
))
389 off
= (port
& ~1) << 1;
394 __raw_writesw((void __iomem
*)ISAIO_BASE
+ off
, from
, len
);
397 void insw(unsigned int port
, void *from
, int len
)
401 if (SUPERIO_PORT(port
))
404 off
= (port
& ~1) << 1;
409 __raw_readsw((void __iomem
*)ISAIO_BASE
+ off
, from
, len
);
412 EXPORT_SYMBOL(outsw
);
416 * We implement these as 16-bit insw/outsw, mainly for
419 void outsl(unsigned int port
, const void *from
, int len
)
423 if (SUPERIO_PORT(port
) || port
& 3)
426 __raw_writesw((void __iomem
*)ISAIO_BASE
+ off
, from
, len
<< 1);
429 void insl(unsigned int port
, void *from
, int len
)
433 if (SUPERIO_PORT(port
) || port
& 3)
436 __raw_readsw((void __iomem
*)ISAIO_BASE
+ off
, from
, len
<< 1);
439 EXPORT_SYMBOL(outsl
);