Merge master.kernel.org:/pub/scm/linux/kernel/git/sfrench/cifs-2.6
[pandora-kernel.git] / arch / sh / kernel / io_generic.c
1 /*
2  * arch/sh/kernel/io_generic.c
3  *
4  * Copyright (C) 2000  Niibe Yutaka
5  * Copyright (C) 2005 - 2007 Paul Mundt
6  *
7  * Generic I/O routine. These can be used where a machine specific version
8  * is not required.
9  *
10  * This file is subject to the terms and conditions of the GNU General Public
11  * License.  See the file "COPYING" in the main directory of this archive
12  * for more details.
13  */
14 #include <linux/module.h>
15 #include <linux/io.h>
16 #include <asm/machvec.h>
17 #include <asm/cacheflush.h>
18
19 #ifdef CONFIG_CPU_SH3
20 /* SH3 has a PCMCIA bug that needs a dummy read from area 6 for a
21  * workaround. */
22 /* I'm not sure SH7709 has this kind of bug */
23 #define dummy_read()    ctrl_inb(0xba000000)
24 #else
25 #define dummy_read()
26 #endif
27
28 unsigned long generic_io_base;
29
30 static inline void delay(void)
31 {
32         ctrl_inw(0xa0000000);
33 }
34
35 u8 generic_inb(unsigned long port)
36 {
37         return ctrl_inb((unsigned long __force)ioport_map(port, 1));
38 }
39
40 u16 generic_inw(unsigned long port)
41 {
42         return ctrl_inw((unsigned long __force)ioport_map(port, 2));
43 }
44
45 u32 generic_inl(unsigned long port)
46 {
47         return ctrl_inl((unsigned long __force)ioport_map(port, 4));
48 }
49
50 u8 generic_inb_p(unsigned long port)
51 {
52         unsigned long v = generic_inb(port);
53
54         delay();
55         return v;
56 }
57
58 u16 generic_inw_p(unsigned long port)
59 {
60         unsigned long v = generic_inw(port);
61
62         delay();
63         return v;
64 }
65
66 u32 generic_inl_p(unsigned long port)
67 {
68         unsigned long v = generic_inl(port);
69
70         delay();
71         return v;
72 }
73
74 /*
75  * insb/w/l all read a series of bytes/words/longs from a fixed port
76  * address. However as the port address doesn't change we only need to
77  * convert the port address to real address once.
78  */
79
80 void generic_insb(unsigned long port, void *dst, unsigned long count)
81 {
82         volatile u8 *port_addr;
83         u8 *buf = dst;
84
85         port_addr = (volatile u8 *)ioport_map(port, 1);
86         while (count--)
87                 *buf++ = *port_addr;
88 }
89
90 void generic_insw(unsigned long port, void *dst, unsigned long count)
91 {
92         volatile u16 *port_addr;
93         u16 *buf = dst;
94
95         port_addr = (volatile u16 *)ioport_map(port, 2);
96         while (count--)
97                 *buf++ = *port_addr;
98
99         flush_dcache_all();
100         dummy_read();
101 }
102
103 void generic_insl(unsigned long port, void *dst, unsigned long count)
104 {
105         volatile u32 *port_addr;
106         u32 *buf = dst;
107
108         port_addr = (volatile u32 *)ioport_map(port, 4);
109         while (count--)
110                 *buf++ = *port_addr;
111
112         dummy_read();
113 }
114
115 void generic_outb(u8 b, unsigned long port)
116 {
117         ctrl_outb(b, (unsigned long __force)ioport_map(port, 1));
118 }
119
120 void generic_outw(u16 b, unsigned long port)
121 {
122         ctrl_outw(b, (unsigned long __force)ioport_map(port, 2));
123 }
124
125 void generic_outl(u32 b, unsigned long port)
126 {
127         ctrl_outl(b, (unsigned long __force)ioport_map(port, 4));
128 }
129
130 void generic_outb_p(u8 b, unsigned long port)
131 {
132         generic_outb(b, port);
133         delay();
134 }
135
136 void generic_outw_p(u16 b, unsigned long port)
137 {
138         generic_outw(b, port);
139         delay();
140 }
141
142 void generic_outl_p(u32 b, unsigned long port)
143 {
144         generic_outl(b, port);
145         delay();
146 }
147
148 /*
149  * outsb/w/l all write a series of bytes/words/longs to a fixed port
150  * address. However as the port address doesn't change we only need to
151  * convert the port address to real address once.
152  */
153 void generic_outsb(unsigned long port, const void *src, unsigned long count)
154 {
155         volatile u8 *port_addr;
156         const u8 *buf = src;
157
158         port_addr = (volatile u8 __force *)ioport_map(port, 1);
159
160         while (count--)
161                 *port_addr = *buf++;
162 }
163
164 void generic_outsw(unsigned long port, const void *src, unsigned long count)
165 {
166         volatile u16 *port_addr;
167         const u16 *buf = src;
168
169         port_addr = (volatile u16 __force *)ioport_map(port, 2);
170
171         while (count--)
172                 *port_addr = *buf++;
173
174         flush_dcache_all();
175         dummy_read();
176 }
177
178 void generic_outsl(unsigned long port, const void *src, unsigned long count)
179 {
180         volatile u32 *port_addr;
181         const u32 *buf = src;
182
183         port_addr = (volatile u32 __force *)ioport_map(port, 4);
184         while (count--)
185                 *port_addr = *buf++;
186
187         dummy_read();
188 }
189
190 u8 generic_readb(void __iomem *addr)
191 {
192         return ctrl_inb((unsigned long __force)addr);
193 }
194
195 u16 generic_readw(void __iomem *addr)
196 {
197         return ctrl_inw((unsigned long __force)addr);
198 }
199
200 u32 generic_readl(void __iomem *addr)
201 {
202         return ctrl_inl((unsigned long __force)addr);
203 }
204
205 void generic_writeb(u8 b, void __iomem *addr)
206 {
207         ctrl_outb(b, (unsigned long __force)addr);
208 }
209
210 void generic_writew(u16 b, void __iomem *addr)
211 {
212         ctrl_outw(b, (unsigned long __force)addr);
213 }
214
215 void generic_writel(u32 b, void __iomem *addr)
216 {
217         ctrl_outl(b, (unsigned long __force)addr);
218 }
219
220 void __iomem *generic_ioport_map(unsigned long addr, unsigned int size)
221 {
222         return (void __iomem *)(addr + generic_io_base);
223 }
224
225 void generic_ioport_unmap(void __iomem *addr)
226 {
227 }