Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid
[sfrench/cifs-2.6.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
18 #ifdef CONFIG_CPU_SH3
19 /* SH3 has a PCMCIA bug that needs a dummy read from area 6 for a
20  * workaround. */
21 /* I'm not sure SH7709 has this kind of bug */
22 #define dummy_read()    __raw_readb(0xba000000)
23 #else
24 #define dummy_read()
25 #endif
26
27 unsigned long generic_io_base;
28
29 u8 generic_inb(unsigned long port)
30 {
31         return __raw_readb(__ioport_map(port, 1));
32 }
33
34 u16 generic_inw(unsigned long port)
35 {
36         return __raw_readw(__ioport_map(port, 2));
37 }
38
39 u32 generic_inl(unsigned long port)
40 {
41         return __raw_readl(__ioport_map(port, 4));
42 }
43
44 u8 generic_inb_p(unsigned long port)
45 {
46         unsigned long v = generic_inb(port);
47
48         ctrl_delay();
49         return v;
50 }
51
52 u16 generic_inw_p(unsigned long port)
53 {
54         unsigned long v = generic_inw(port);
55
56         ctrl_delay();
57         return v;
58 }
59
60 u32 generic_inl_p(unsigned long port)
61 {
62         unsigned long v = generic_inl(port);
63
64         ctrl_delay();
65         return v;
66 }
67
68 /*
69  * insb/w/l all read a series of bytes/words/longs from a fixed port
70  * address. However as the port address doesn't change we only need to
71  * convert the port address to real address once.
72  */
73
74 void generic_insb(unsigned long port, void *dst, unsigned long count)
75 {
76         volatile u8 *port_addr;
77         u8 *buf = dst;
78
79         port_addr = (volatile u8 __force *)__ioport_map(port, 1);
80         while (count--)
81                 *buf++ = *port_addr;
82 }
83
84 void generic_insw(unsigned long port, void *dst, unsigned long count)
85 {
86         volatile u16 *port_addr;
87         u16 *buf = dst;
88
89         port_addr = (volatile u16 __force *)__ioport_map(port, 2);
90         while (count--)
91                 *buf++ = *port_addr;
92
93         dummy_read();
94 }
95
96 void generic_insl(unsigned long port, void *dst, unsigned long count)
97 {
98         volatile u32 *port_addr;
99         u32 *buf = dst;
100
101         port_addr = (volatile u32 __force *)__ioport_map(port, 4);
102         while (count--)
103                 *buf++ = *port_addr;
104
105         dummy_read();
106 }
107
108 void generic_outb(u8 b, unsigned long port)
109 {
110         __raw_writeb(b, __ioport_map(port, 1));
111 }
112
113 void generic_outw(u16 b, unsigned long port)
114 {
115         __raw_writew(b, __ioport_map(port, 2));
116 }
117
118 void generic_outl(u32 b, unsigned long port)
119 {
120         __raw_writel(b, __ioport_map(port, 4));
121 }
122
123 void generic_outb_p(u8 b, unsigned long port)
124 {
125         generic_outb(b, port);
126         ctrl_delay();
127 }
128
129 void generic_outw_p(u16 b, unsigned long port)
130 {
131         generic_outw(b, port);
132         ctrl_delay();
133 }
134
135 void generic_outl_p(u32 b, unsigned long port)
136 {
137         generic_outl(b, port);
138         ctrl_delay();
139 }
140
141 /*
142  * outsb/w/l all write a series of bytes/words/longs to a fixed port
143  * address. However as the port address doesn't change we only need to
144  * convert the port address to real address once.
145  */
146 void generic_outsb(unsigned long port, const void *src, unsigned long count)
147 {
148         volatile u8 *port_addr;
149         const u8 *buf = src;
150
151         port_addr = (volatile u8 __force *)__ioport_map(port, 1);
152
153         while (count--)
154                 *port_addr = *buf++;
155 }
156
157 void generic_outsw(unsigned long port, const void *src, unsigned long count)
158 {
159         volatile u16 *port_addr;
160         const u16 *buf = src;
161
162         port_addr = (volatile u16 __force *)__ioport_map(port, 2);
163
164         while (count--)
165                 *port_addr = *buf++;
166
167         dummy_read();
168 }
169
170 void generic_outsl(unsigned long port, const void *src, unsigned long count)
171 {
172         volatile u32 *port_addr;
173         const u32 *buf = src;
174
175         port_addr = (volatile u32 __force *)__ioport_map(port, 4);
176         while (count--)
177                 *port_addr = *buf++;
178
179         dummy_read();
180 }
181
182 void __iomem *generic_ioport_map(unsigned long addr, unsigned int size)
183 {
184         return (void __iomem *)(addr + generic_io_base);
185 }
186
187 void generic_ioport_unmap(void __iomem *addr)
188 {
189 }