]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - arch/m32r/kernel/io_m32700ut.c
Merge branch 'fixes.b8' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/bird
[mirror_ubuntu-zesty-kernel.git] / arch / m32r / kernel / io_m32700ut.c
1 /*
2 * linux/arch/m32r/kernel/io_m32700ut.c
3 *
4 * Typical I/O routines for M32700UT 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 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
43 static inline void *__port2addr_ata(unsigned long port)
44 {
45 static int dummy_reg;
46
47 switch (port) {
48 case 0x1f0: return (void *)(0x0c002000 | NONCACHE_OFFSET);
49 case 0x1f1: return (void *)(0x0c012800 | NONCACHE_OFFSET);
50 case 0x1f2: return (void *)(0x0c012002 | NONCACHE_OFFSET);
51 case 0x1f3: return (void *)(0x0c012802 | NONCACHE_OFFSET);
52 case 0x1f4: return (void *)(0x0c012004 | NONCACHE_OFFSET);
53 case 0x1f5: return (void *)(0x0c012804 | NONCACHE_OFFSET);
54 case 0x1f6: return (void *)(0x0c012006 | NONCACHE_OFFSET);
55 case 0x1f7: return (void *)(0x0c012806 | NONCACHE_OFFSET);
56 case 0x3f6: return (void *)(0x0c01200e | NONCACHE_OFFSET);
57 default: return (void *)&dummy_reg;
58 }
59 }
60 #endif
61
62 /*
63 * M32700UT-LAN is located in the extended bus space
64 * from 0x10000000 to 0x13ffffff on physical address.
65 * The base address of LAN controller(LAN91C111) is 0x300.
66 */
67 #define LAN_IOSTART (0x300 | NONCACHE_OFFSET)
68 #define LAN_IOEND (0x320 | NONCACHE_OFFSET)
69 static inline void *_port2addr_ne(unsigned long port)
70 {
71 return (void *)(port + 0x10000000);
72 }
73 static inline void *_port2addr_usb(unsigned long port)
74 {
75 return (void *)((port & 0x0f) + NONCACHE_OFFSET + 0x10303000);
76 }
77
78 static inline void delay(void)
79 {
80 __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
81 }
82
83 /*
84 * NIC I/O function
85 */
86
87 #define PORT2ADDR_NE(port) _port2addr_ne(port)
88
89 static inline unsigned char _ne_inb(void *portp)
90 {
91 return *(volatile unsigned char *)portp;
92 }
93
94 static inline unsigned short _ne_inw(void *portp)
95 {
96 return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp);
97 }
98
99 static inline void _ne_insb(void *portp, void *addr, unsigned long count)
100 {
101 unsigned char *buf = (unsigned char *)addr;
102
103 while (count--)
104 *buf++ = _ne_inb(portp);
105 }
106
107 static inline void _ne_outb(unsigned char b, void *portp)
108 {
109 *(volatile unsigned char *)portp = b;
110 }
111
112 static inline void _ne_outw(unsigned short w, void *portp)
113 {
114 *(volatile unsigned short *)portp = cpu_to_le16(w);
115 }
116
117 unsigned char _inb(unsigned long port)
118 {
119 if (port >= LAN_IOSTART && port < LAN_IOEND)
120 return _ne_inb(PORT2ADDR_NE(port));
121
122 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
123 else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
124 return *(volatile unsigned char *)__port2addr_ata(port);
125 }
126 #endif
127 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
128 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
129 unsigned char b;
130 pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
131 return b;
132 } else
133 #endif
134
135 return *(volatile unsigned char *)PORT2ADDR(port);
136 }
137
138 unsigned short _inw(unsigned long port)
139 {
140 if (port >= LAN_IOSTART && port < LAN_IOEND)
141 return _ne_inw(PORT2ADDR_NE(port));
142 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
143 else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
144 return *(volatile unsigned short *)__port2addr_ata(port);
145 }
146 #endif
147 #if defined(CONFIG_USB)
148 else if(port >= 0x340 && port < 0x3a0)
149 return *(volatile unsigned short *)PORT2ADDR_USB(port);
150 #endif
151 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
152 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
153 unsigned short w;
154 pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
155 return w;
156 } else
157 #endif
158 return *(volatile unsigned short *)PORT2ADDR(port);
159 }
160
161 unsigned long _inl(unsigned long port)
162 {
163 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
164 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
165 unsigned long l;
166 pcc_ioread_word(0, port, &l, sizeof(l), 1, 0);
167 return l;
168 } else
169 #endif
170 return *(volatile unsigned long *)PORT2ADDR(port);
171 }
172
173 unsigned char _inb_p(unsigned long port)
174 {
175 unsigned char v = _inb(port);
176 delay();
177 return (v);
178 }
179
180 unsigned short _inw_p(unsigned long port)
181 {
182 unsigned short v = _inw(port);
183 delay();
184 return (v);
185 }
186
187 unsigned long _inl_p(unsigned long port)
188 {
189 unsigned long v = _inl(port);
190 delay();
191 return (v);
192 }
193
194 void _outb(unsigned char b, unsigned long port)
195 {
196 if (port >= LAN_IOSTART && port < LAN_IOEND)
197 _ne_outb(b, PORT2ADDR_NE(port));
198 else
199 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
200 if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
201 *(volatile unsigned char *)__port2addr_ata(port) = b;
202 } else
203 #endif
204 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
205 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
206 pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
207 } else
208 #endif
209 *(volatile unsigned char *)PORT2ADDR(port) = b;
210 }
211
212 void _outw(unsigned short w, unsigned long port)
213 {
214 if (port >= LAN_IOSTART && port < LAN_IOEND)
215 _ne_outw(w, PORT2ADDR_NE(port));
216 else
217 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
218 if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
219 *(volatile unsigned short *)__port2addr_ata(port) = w;
220 } else
221 #endif
222 #if defined(CONFIG_USB)
223 if(port >= 0x340 && port < 0x3a0)
224 *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
225 else
226 #endif
227 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
228 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
229 pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
230 } else
231 #endif
232 *(volatile unsigned short *)PORT2ADDR(port) = w;
233 }
234
235 void _outl(unsigned long l, unsigned long port)
236 {
237 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
238 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
239 pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
240 } else
241 #endif
242 *(volatile unsigned long *)PORT2ADDR(port) = l;
243 }
244
245 void _outb_p(unsigned char b, unsigned long port)
246 {
247 _outb(b, port);
248 delay();
249 }
250
251 void _outw_p(unsigned short w, unsigned long port)
252 {
253 _outw(w, port);
254 delay();
255 }
256
257 void _outl_p(unsigned long l, unsigned long port)
258 {
259 _outl(l, port);
260 delay();
261 }
262
263 void _insb(unsigned int port, void *addr, unsigned long count)
264 {
265 if (port >= LAN_IOSTART && port < LAN_IOEND)
266 _ne_insb(PORT2ADDR_NE(port), addr, count);
267 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
268 else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
269 unsigned char *buf = addr;
270 unsigned char *portp = __port2addr_ata(port);
271 while (count--)
272 *buf++ = *(volatile unsigned char *)portp;
273 }
274 #endif
275 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
276 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
277 pcc_ioread_byte(0, port, (void *)addr, sizeof(unsigned char),
278 count, 1);
279 }
280 #endif
281 else {
282 unsigned char *buf = addr;
283 unsigned char *portp = PORT2ADDR(port);
284 while (count--)
285 *buf++ = *(volatile unsigned char *)portp;
286 }
287 }
288
289 void _insw(unsigned int port, void *addr, unsigned long count)
290 {
291 unsigned short *buf = addr;
292 unsigned short *portp;
293
294 if (port >= LAN_IOSTART && port < LAN_IOEND) {
295 /*
296 * This portion is only used by smc91111.c to read data
297 * from the DATA_REG. Do not swap the data.
298 */
299 portp = PORT2ADDR_NE(port);
300 while (count--)
301 *buf++ = *(volatile unsigned short *)portp;
302 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
303 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
304 pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short),
305 count, 1);
306 #endif
307 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
308 } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
309 portp = __port2addr_ata(port);
310 while (count--)
311 *buf++ = *(volatile unsigned short *)portp;
312 #endif
313 } else {
314 portp = PORT2ADDR(port);
315 while (count--)
316 *buf++ = *(volatile unsigned short *)portp;
317 }
318 }
319
320 void _insl(unsigned int port, void *addr, unsigned long count)
321 {
322 unsigned long *buf = addr;
323 unsigned long *portp;
324
325 portp = PORT2ADDR(port);
326 while (count--)
327 *buf++ = *(volatile unsigned long *)portp;
328 }
329
330 void _outsb(unsigned int port, const void *addr, unsigned long count)
331 {
332 const unsigned char *buf = addr;
333 unsigned char *portp;
334
335 if (port >= LAN_IOSTART && port < LAN_IOEND) {
336 portp = PORT2ADDR_NE(port);
337 while (count--)
338 _ne_outb(*buf++, portp);
339 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
340 } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
341 portp = __port2addr_ata(port);
342 while (count--)
343 *(volatile unsigned char *)portp = *buf++;
344 #endif
345 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
346 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
347 pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char),
348 count, 1);
349 #endif
350 } else {
351 portp = PORT2ADDR(port);
352 while (count--)
353 *(volatile unsigned char *)portp = *buf++;
354 }
355 }
356
357 void _outsw(unsigned int port, const void *addr, unsigned long count)
358 {
359 const unsigned short *buf = addr;
360 unsigned short *portp;
361
362 if (port >= LAN_IOSTART && port < LAN_IOEND) {
363 /*
364 * This portion is only used by smc91111.c to write data
365 * into the DATA_REG. Do not swap the data.
366 */
367 portp = PORT2ADDR_NE(port);
368 while (count--)
369 *(volatile unsigned short *)portp = *buf++;
370 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
371 } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
372 portp = __port2addr_ata(port);
373 while (count--)
374 *(volatile unsigned short *)portp = *buf++;
375 #endif
376 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
377 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
378 pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short),
379 count, 1);
380 #endif
381 } else {
382 portp = PORT2ADDR(port);
383 while (count--)
384 *(volatile unsigned short *)portp = *buf++;
385 }
386 }
387
388 void _outsl(unsigned int port, const void *addr, unsigned long count)
389 {
390 const unsigned long *buf = addr;
391 unsigned char *portp;
392
393 portp = PORT2ADDR(port);
394 while (count--)
395 *(volatile unsigned long *)portp = *buf++;
396 }