]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - arch/m32r/kernel/io_opsput.c
Merge branch 'upstream-fixes' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik...
[mirror_ubuntu-zesty-kernel.git] / arch / m32r / kernel / io_opsput.c
1 /*
2 * linux/arch/m32r/kernel/io_opsput.c
3 *
4 * Typical I/O routines for OPSPUT board.
5 *
6 * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata,
7 * Hitoshi Yamamoto, Takeo Takahashi
8 *
9 * This file is subject to the terms and conditions of the GNU General
10 * Public License. See the file "COPYING" in the main directory of this
11 * archive for more details.
12 */
13
14 #include <linux/config.h>
15 #include <asm/m32r.h>
16 #include <asm/page.h>
17 #include <asm/io.h>
18 #include <asm/byteorder.h>
19
20 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
21 #include <linux/types.h>
22
23 #define M32R_PCC_IOMAP_SIZE 0x1000
24
25 #define M32R_PCC_IOSTART0 0x1000
26 #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
27
28 extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
29 extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
30 extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
31 extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
32 #endif /* CONFIG_PCMCIA && CONFIG_M32R_CFC */
33
34 #define PORT2ADDR(port) _port2addr(port)
35 #define PORT2ADDR_USB(port) _port2addr_usb(port)
36
37 static inline void *_port2addr(unsigned long port)
38 {
39 return (void *)(port | NONCACHE_OFFSET);
40 }
41
42 /*
43 * OPSPUT-LAN is located in the extended bus space
44 * from 0x10000000 to 0x13ffffff on physical address.
45 * The base address of LAN controller(LAN91C111) is 0x300.
46 */
47 #define LAN_IOSTART (0x300 | NONCACHE_OFFSET)
48 #define LAN_IOEND (0x320 | NONCACHE_OFFSET)
49 static inline void *_port2addr_ne(unsigned long port)
50 {
51 return (void *)(port + 0x10000000);
52 }
53 static inline void *_port2addr_usb(unsigned long port)
54 {
55 return (void *)((port & 0x0f) + NONCACHE_OFFSET + 0x10303000);
56 }
57
58 static inline void delay(void)
59 {
60 __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
61 }
62
63 /*
64 * NIC I/O function
65 */
66
67 #define PORT2ADDR_NE(port) _port2addr_ne(port)
68
69 static inline unsigned char _ne_inb(void *portp)
70 {
71 return *(volatile unsigned char *)portp;
72 }
73
74 static inline unsigned short _ne_inw(void *portp)
75 {
76 return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp);
77 }
78
79 static inline void _ne_insb(void *portp, void *addr, unsigned long count)
80 {
81 unsigned char *buf = (unsigned char *)addr;
82
83 while (count--)
84 *buf++ = _ne_inb(portp);
85 }
86
87 static inline void _ne_outb(unsigned char b, void *portp)
88 {
89 *(volatile unsigned char *)portp = b;
90 }
91
92 static inline void _ne_outw(unsigned short w, void *portp)
93 {
94 *(volatile unsigned short *)portp = cpu_to_le16(w);
95 }
96
97 unsigned char _inb(unsigned long port)
98 {
99 if (port >= LAN_IOSTART && port < LAN_IOEND)
100 return _ne_inb(PORT2ADDR_NE(port));
101 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
102 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
103 unsigned char b;
104 pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
105 return b;
106 } else
107 #endif
108
109 return *(volatile unsigned char *)PORT2ADDR(port);
110 }
111
112 unsigned short _inw(unsigned long port)
113 {
114 if (port >= LAN_IOSTART && port < LAN_IOEND)
115 return _ne_inw(PORT2ADDR_NE(port));
116 #if defined(CONFIG_USB)
117 else if(port >= 0x340 && port < 0x3a0)
118 return *(volatile unsigned short *)PORT2ADDR_USB(port);
119 #endif
120 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
121 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
122 unsigned short w;
123 pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
124 return w;
125 } else
126 #endif
127 return *(volatile unsigned short *)PORT2ADDR(port);
128 }
129
130 unsigned long _inl(unsigned long port)
131 {
132 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
133 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
134 unsigned long l;
135 pcc_ioread_word(0, port, &l, sizeof(l), 1, 0);
136 return l;
137 } else
138 #endif
139 return *(volatile unsigned long *)PORT2ADDR(port);
140 }
141
142 unsigned char _inb_p(unsigned long port)
143 {
144 unsigned char v = _inb(port);
145 delay();
146 return (v);
147 }
148
149 unsigned short _inw_p(unsigned long port)
150 {
151 unsigned short v = _inw(port);
152 delay();
153 return (v);
154 }
155
156 unsigned long _inl_p(unsigned long port)
157 {
158 unsigned long v = _inl(port);
159 delay();
160 return (v);
161 }
162
163 void _outb(unsigned char b, unsigned long port)
164 {
165 if (port >= LAN_IOSTART && port < LAN_IOEND)
166 _ne_outb(b, PORT2ADDR_NE(port));
167 else
168 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
169 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
170 pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
171 } else
172 #endif
173 *(volatile unsigned char *)PORT2ADDR(port) = b;
174 }
175
176 void _outw(unsigned short w, unsigned long port)
177 {
178 if (port >= LAN_IOSTART && port < LAN_IOEND)
179 _ne_outw(w, PORT2ADDR_NE(port));
180 else
181 #if defined(CONFIG_USB)
182 if(port >= 0x340 && port < 0x3a0)
183 *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
184 else
185 #endif
186 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
187 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
188 pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
189 } else
190 #endif
191 *(volatile unsigned short *)PORT2ADDR(port) = w;
192 }
193
194 void _outl(unsigned long l, unsigned long port)
195 {
196 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
197 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
198 pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
199 } else
200 #endif
201 *(volatile unsigned long *)PORT2ADDR(port) = l;
202 }
203
204 void _outb_p(unsigned char b, unsigned long port)
205 {
206 _outb(b, port);
207 delay();
208 }
209
210 void _outw_p(unsigned short w, unsigned long port)
211 {
212 _outw(w, port);
213 delay();
214 }
215
216 void _outl_p(unsigned long l, unsigned long port)
217 {
218 _outl(l, port);
219 delay();
220 }
221
222 void _insb(unsigned int port, void *addr, unsigned long count)
223 {
224 if (port >= LAN_IOSTART && port < LAN_IOEND)
225 _ne_insb(PORT2ADDR_NE(port), addr, count);
226 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
227 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
228 pcc_ioread_byte(0, port, (void *)addr, sizeof(unsigned char),
229 count, 1);
230 }
231 #endif
232 else {
233 unsigned char *buf = addr;
234 unsigned char *portp = PORT2ADDR(port);
235 while (count--)
236 *buf++ = *(volatile unsigned char *)portp;
237 }
238 }
239
240 void _insw(unsigned int port, void *addr, unsigned long count)
241 {
242 unsigned short *buf = addr;
243 unsigned short *portp;
244
245 if (port >= LAN_IOSTART && port < LAN_IOEND) {
246 /*
247 * This portion is only used by smc91111.c to read data
248 * from the DATA_REG. Do not swap the data.
249 */
250 portp = PORT2ADDR_NE(port);
251 while (count--)
252 *buf++ = *(volatile unsigned short *)portp;
253 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
254 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
255 pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short),
256 count, 1);
257 #endif
258 } else {
259 portp = PORT2ADDR(port);
260 while (count--)
261 *buf++ = *(volatile unsigned short *)portp;
262 }
263 }
264
265 void _insl(unsigned int port, void *addr, unsigned long count)
266 {
267 unsigned long *buf = addr;
268 unsigned long *portp;
269
270 portp = PORT2ADDR(port);
271 while (count--)
272 *buf++ = *(volatile unsigned long *)portp;
273 }
274
275 void _outsb(unsigned int port, const void *addr, unsigned long count)
276 {
277 const unsigned char *buf = addr;
278 unsigned char *portp;
279
280 if (port >= LAN_IOSTART && port < LAN_IOEND) {
281 portp = PORT2ADDR_NE(port);
282 while (count--)
283 _ne_outb(*buf++, portp);
284 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
285 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
286 pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char),
287 count, 1);
288 #endif
289 } else {
290 portp = PORT2ADDR(port);
291 while (count--)
292 *(volatile unsigned char *)portp = *buf++;
293 }
294 }
295
296 void _outsw(unsigned int port, const void *addr, unsigned long count)
297 {
298 const unsigned short *buf = addr;
299 unsigned short *portp;
300
301 if (port >= LAN_IOSTART && port < LAN_IOEND) {
302 /*
303 * This portion is only used by smc91111.c to write data
304 * into the DATA_REG. Do not swap the data.
305 */
306 portp = PORT2ADDR_NE(port);
307 while (count--)
308 *(volatile unsigned short *)portp = *buf++;
309 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
310 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
311 pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short),
312 count, 1);
313 #endif
314 } else {
315 portp = PORT2ADDR(port);
316 while (count--)
317 *(volatile unsigned short *)portp = *buf++;
318 }
319 }
320
321 void _outsl(unsigned int port, const void *addr, unsigned long count)
322 {
323 const unsigned long *buf = addr;
324 unsigned char *portp;
325
326 portp = PORT2ADDR(port);
327 while (count--)
328 *(volatile unsigned long *)portp = *buf++;
329 }