generic: ar8216: use switch_dev->ports in for loops
[openwrt.git] / target / linux / mpc83xx / patches-2.6.36 / 010-sysdev_rb_iomap.patch
1 --- /dev/null
2 +++ b/arch/powerpc/sysdev/rb_iomap.c
3 @@ -0,0 +1,223 @@
4 +#include <linux/init.h>
5 +#include <linux/pci.h>
6 +#include <linux/mm.h>
7 +#include <asm/io.h>
8 +
9 +#define LOCALBUS_START 0x40000000
10 +#define LOCALBUS_MASK 0x007fffff
11 +#define LOCALBUS_REGMASK 0x001fffff
12 +
13 +static void __iomem *localbus_base;
14 +
15 +static inline int is_localbus(void __iomem *addr)
16 +{
17 + return ((unsigned) addr & ~LOCALBUS_MASK) == LOCALBUS_START;
18 +}
19 +
20 +static inline unsigned localbus_regoff(unsigned reg) {
21 + return (reg << 16) | (((reg ^ 8) & 8) << 17);
22 +}
23 +
24 +static inline void __iomem *localbus_addr(void __iomem *addr)
25 +{
26 + return localbus_base
27 + + ((unsigned) addr & LOCALBUS_MASK & ~LOCALBUS_REGMASK)
28 + + localbus_regoff((unsigned) addr & LOCALBUS_REGMASK);
29 +}
30 +
31 +unsigned int ioread8(void __iomem *addr)
32 +{
33 + if (is_localbus(addr))
34 + return in_be16(localbus_addr(addr)) >> 8;
35 + return readb(addr);
36 +}
37 +EXPORT_SYMBOL(ioread8);
38 +
39 +unsigned int ioread16(void __iomem *addr)
40 +{
41 + if (is_localbus(addr))
42 + return le16_to_cpu(in_be16(localbus_addr(addr)));
43 + return readw(addr);
44 +}
45 +EXPORT_SYMBOL(ioread16);
46 +
47 +unsigned int ioread16be(void __iomem *addr)
48 +{
49 + return in_be16(addr);
50 +}
51 +EXPORT_SYMBOL(ioread16be);
52 +
53 +unsigned int ioread32(void __iomem *addr)
54 +{
55 + return readl(addr);
56 +}
57 +EXPORT_SYMBOL(ioread32);
58 +
59 +unsigned int ioread32be(void __iomem *addr)
60 +{
61 + return in_be32(addr);
62 +}
63 +EXPORT_SYMBOL(ioread32be);
64 +
65 +void iowrite8(u8 val, void __iomem *addr)
66 +{
67 + if (is_localbus(addr))
68 + out_be16(localbus_addr(addr), ((u16) val) << 8);
69 + else
70 + writeb(val, addr);
71 +}
72 +EXPORT_SYMBOL(iowrite8);
73 +
74 +void iowrite16(u16 val, void __iomem *addr)
75 +{
76 + if (is_localbus(addr))
77 + out_be16(localbus_addr(addr), cpu_to_le16(val));
78 + else
79 + writew(val, addr);
80 +}
81 +EXPORT_SYMBOL(iowrite16);
82 +
83 +void iowrite16be(u16 val, void __iomem *addr)
84 +{
85 + out_be16(addr, val);
86 +}
87 +EXPORT_SYMBOL(iowrite16be);
88 +
89 +void iowrite32(u32 val, void __iomem *addr)
90 +{
91 + writel(val, addr);
92 +}
93 +EXPORT_SYMBOL(iowrite32);
94 +
95 +void iowrite32be(u32 val, void __iomem *addr)
96 +{
97 + out_be32(addr, val);
98 +}
99 +EXPORT_SYMBOL(iowrite32be);
100 +
101 +void ioread8_rep(void __iomem *addr, void *dst, unsigned long count)
102 +{
103 + if (is_localbus(addr)) {
104 + unsigned i;
105 + void *laddr = localbus_addr(addr);
106 + u8 *buf = dst;
107 +
108 + for (i = 0; i < count; ++i) {
109 + *buf++ = in_be16(laddr) >> 8;
110 + }
111 + } else {
112 + _insb((u8 __iomem *) addr, dst, count);
113 + }
114 +}
115 +EXPORT_SYMBOL(ioread8_rep);
116 +
117 +void ioread16_rep(void __iomem *addr, void *dst, unsigned long count)
118 +{
119 + if (is_localbus(addr)) {
120 + unsigned i;
121 + void *laddr = localbus_addr(addr);
122 + u16 *buf = dst;
123 +
124 + for (i = 0; i < count; ++i) {
125 + *buf++ = in_be16(laddr);
126 + }
127 + } else {
128 + _insw_ns((u16 __iomem *) addr, dst, count);
129 + }
130 +}
131 +EXPORT_SYMBOL(ioread16_rep);
132 +
133 +void ioread32_rep(void __iomem *addr, void *dst, unsigned long count)
134 +{
135 + _insl_ns((u32 __iomem *) addr, dst, count);
136 +}
137 +EXPORT_SYMBOL(ioread32_rep);
138 +
139 +void iowrite8_rep(void __iomem *addr, const void *src, unsigned long count)
140 +{
141 + if (is_localbus(addr)) {
142 + unsigned i;
143 + void *laddr = localbus_addr(addr);
144 + const u8 *buf = src;
145 +
146 + for (i = 0; i < count; ++i) {
147 + out_be16(laddr, ((u16) *buf++) << 8);
148 + }
149 + } else {
150 + _outsb((u8 __iomem *) addr, src, count);
151 + }
152 +}
153 +EXPORT_SYMBOL(iowrite8_rep);
154 +
155 +void iowrite16_rep(void __iomem *addr, const void *src, unsigned long count)
156 +{
157 + if (is_localbus(addr)) {
158 + unsigned i;
159 + void *laddr = localbus_addr(addr);
160 + const u16 *buf = src;
161 +
162 + for (i = 0; i < count; ++i) {
163 + out_be16(laddr, *buf++);
164 + }
165 + } else {
166 + _outsw_ns((u16 __iomem *) addr, src, count);
167 + }
168 +}
169 +EXPORT_SYMBOL(iowrite16_rep);
170 +
171 +void iowrite32_rep(void __iomem *addr, const void *src, unsigned long count)
172 +{
173 + _outsl_ns((u32 __iomem *) addr, src, count);
174 +}
175 +EXPORT_SYMBOL(iowrite32_rep);
176 +
177 +void __iomem *ioport_map(unsigned long port, unsigned int len)
178 +{
179 + return (void __iomem *) (port + _IO_BASE);
180 +}
181 +EXPORT_SYMBOL(ioport_unmap);
182 +
183 +void ioport_unmap(void __iomem *addr)
184 +{
185 + /* Nothing to do */
186 +}
187 +EXPORT_SYMBOL(ioport_map);
188 +
189 +void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max)
190 +{
191 + unsigned long start = pci_resource_start(dev, bar);
192 + unsigned long len = pci_resource_len(dev, bar);
193 + unsigned long flags = pci_resource_flags(dev, bar);
194 +
195 + if (!len)
196 + return NULL;
197 + if (max && len > max)
198 + len = max;
199 + if (flags & IORESOURCE_IO)
200 + return ioport_map(start, len);
201 + if (flags & IORESOURCE_MEM)
202 + return ioremap(start, len);
203 + /* What? */
204 + return NULL;
205 +}
206 +EXPORT_SYMBOL(pci_iomap);
207 +
208 +void pci_iounmap(struct pci_dev *dev, void __iomem *addr)
209 +{
210 + /* Nothing to do */
211 +}
212 +EXPORT_SYMBOL(pci_iounmap);
213 +
214 +void __iomem *localbus_map(unsigned long addr, unsigned int len)
215 +{
216 + if (!localbus_base)
217 + localbus_base = ioremap(addr & ~LOCALBUS_MASK,
218 + LOCALBUS_MASK + 1);
219 + return (void *) (LOCALBUS_START + (addr & LOCALBUS_MASK));
220 +}
221 +EXPORT_SYMBOL(localbus_map);
222 +
223 +void localbus_unmap(void __iomem *addr)
224 +{
225 +}
226 +EXPORT_SYMBOL(localbus_unmap);
This page took 0.052797 seconds and 5 git commands to generate.