]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - arch/m32r/kernel/io_mappi2.c
Merge branch 'master'
[mirror_ubuntu-zesty-kernel.git] / arch / m32r / kernel / io_mappi2.c
1 /*
2 * linux/arch/m32r/kernel/io_mappi2.c
3 *
4 * Typical I/O routines for Mappi2 board.
5 *
6 * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata,
7 * Hitoshi Yamamoto, Mamoru Sakugawa
8 */
9
10 #include <linux/config.h>
11 #include <asm/m32r.h>
12 #include <asm/page.h>
13 #include <asm/io.h>
14 #include <asm/byteorder.h>
15
16 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
17 #include <linux/types.h>
18
19 #define M32R_PCC_IOMAP_SIZE 0x1000
20
21 #define M32R_PCC_IOSTART0 0x1000
22 #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
23
24 extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
25 extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
26 extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
27 extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
28 #endif /* CONFIG_PCMCIA && CONFIG_M32R_CFC */
29
30 #define PORT2ADDR(port) _port2addr(port)
31 #define PORT2ADDR_NE(port) _port2addr_ne(port)
32 #define PORT2ADDR_USB(port) _port2addr_usb(port)
33
34 static inline void *_port2addr(unsigned long port)
35 {
36 return (void *)(port | (NONCACHE_OFFSET));
37 }
38
39 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
40 static inline void *__port2addr_ata(unsigned long port)
41 {
42 static int dummy_reg;
43
44 switch (port) {
45 case 0x1f0: return (void *)0xac002000;
46 case 0x1f1: return (void *)0xac012800;
47 case 0x1f2: return (void *)0xac012002;
48 case 0x1f3: return (void *)0xac012802;
49 case 0x1f4: return (void *)0xac012004;
50 case 0x1f5: return (void *)0xac012804;
51 case 0x1f6: return (void *)0xac012006;
52 case 0x1f7: return (void *)0xac012806;
53 case 0x3f6: return (void *)0xac01200e;
54 default: return (void *)&dummy_reg;
55 }
56 }
57 #endif
58
59 #define LAN_IOSTART 0xa0000300
60 #define LAN_IOEND 0xa0000320
61 #ifdef CONFIG_CHIP_OPSP
62 static inline void *_port2addr_ne(unsigned long port)
63 {
64 return (void *)(port + 0x10000000);
65 }
66 #else
67 static inline void *_port2addr_ne(unsigned long port)
68 {
69 return (void *)(port + 0x04000000);
70 }
71 #endif
72 static inline void *_port2addr_usb(unsigned long port)
73 {
74 return (void *)(port + NONCACHE_OFFSET + 0x14000000);
75 }
76 static inline void delay(void)
77 {
78 __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
79 }
80
81 /*
82 * NIC I/O function
83 */
84
85 static inline unsigned char _ne_inb(void *portp)
86 {
87 return (unsigned char) *(volatile unsigned char *)portp;
88 }
89
90 static inline unsigned short _ne_inw(void *portp)
91 {
92 return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp);
93 }
94
95 static inline void _ne_insb(void *portp, void * addr, unsigned long count)
96 {
97 unsigned char *buf = addr;
98
99 while (count--)
100 *buf++ = *(volatile unsigned char *)portp;
101 }
102
103 static inline void _ne_outb(unsigned char b, void *portp)
104 {
105 *(volatile unsigned char *)portp = (unsigned char)b;
106 }
107
108 static inline void _ne_outw(unsigned short w, void *portp)
109 {
110 *(volatile unsigned short *)portp = cpu_to_le16(w);
111 }
112
113 unsigned char _inb(unsigned long port)
114 {
115 if (port >= LAN_IOSTART && port < LAN_IOEND)
116 return _ne_inb(PORT2ADDR_NE(port));
117 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
118 else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
119 return *(volatile unsigned char *)__port2addr_ata(port);
120 }
121 #endif
122 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
123 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
124 unsigned char b;
125 pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
126 return b;
127 } else
128 #endif
129
130 return *(volatile unsigned char *)PORT2ADDR(port);
131 }
132
133 unsigned short _inw(unsigned long port)
134 {
135 if (port >= LAN_IOSTART && port < LAN_IOEND)
136 return _ne_inw(PORT2ADDR_NE(port));
137 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
138 else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
139 return *(volatile unsigned short *)__port2addr_ata(port);
140 }
141 #endif
142 #if defined(CONFIG_USB)
143 else if (port >= 0x340 && port < 0x3a0)
144 return *(volatile unsigned short *)PORT2ADDR_USB(port);
145 #endif
146
147 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
148 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
149 unsigned short w;
150 pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
151 return w;
152 } else
153 #endif
154 return *(volatile unsigned short *)PORT2ADDR(port);
155 }
156
157 unsigned long _inl(unsigned long port)
158 {
159 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
160 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
161 unsigned long l;
162 pcc_ioread_word(0, port, &l, sizeof(l), 1, 0);
163 return l;
164 } else
165 #endif
166 return *(volatile unsigned long *)PORT2ADDR(port);
167 }
168
169 unsigned char _inb_p(unsigned long port)
170 {
171 unsigned char v = _inb(port);
172 delay();
173 return (v);
174 }
175
176 unsigned short _inw_p(unsigned long port)
177 {
178 unsigned short v = _inw(port);
179 delay();
180 return (v);
181 }
182
183 unsigned long _inl_p(unsigned long port)
184 {
185 unsigned long v = _inl(port);
186 delay();
187 return (v);
188 }
189
190 void _outb(unsigned char b, unsigned long port)
191 {
192 if (port >= LAN_IOSTART && port < LAN_IOEND)
193 _ne_outb(b, PORT2ADDR_NE(port));
194 else
195 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
196 if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
197 *(volatile unsigned char *)__port2addr_ata(port) = b;
198 } else
199 #endif
200 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
201 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
202 pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
203 } else
204 #endif
205 *(volatile unsigned char *)PORT2ADDR(port) = b;
206 }
207
208 void _outw(unsigned short w, unsigned long port)
209 {
210 if (port >= LAN_IOSTART && port < LAN_IOEND)
211 _ne_outw(w, PORT2ADDR_NE(port));
212 else
213 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
214 if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
215 *(volatile unsigned short *)__port2addr_ata(port) = w;
216 } else
217 #endif
218 #if defined(CONFIG_USB)
219 if (port >= 0x340 && port < 0x3a0)
220 *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
221 else
222 #endif
223 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
224 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
225 pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
226 } else
227 #endif
228 *(volatile unsigned short *)PORT2ADDR(port) = w;
229 }
230
231 void _outl(unsigned long l, unsigned long port)
232 {
233 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
234 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
235 pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
236 } else
237 #endif
238 *(volatile unsigned long *)PORT2ADDR(port) = l;
239 }
240
241 void _outb_p(unsigned char b, unsigned long port)
242 {
243 _outb(b, port);
244 delay();
245 }
246
247 void _outw_p(unsigned short w, unsigned long port)
248 {
249 _outw(w, port);
250 delay();
251 }
252
253 void _outl_p(unsigned long l, unsigned long port)
254 {
255 _outl(l, port);
256 delay();
257 }
258
259 void _insb(unsigned int port, void * addr, unsigned long count)
260 {
261 if (port >= LAN_IOSTART && port < LAN_IOEND)
262 _ne_insb(PORT2ADDR_NE(port), addr, count);
263 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
264 else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
265 unsigned char *buf = addr;
266 unsigned char *portp = __port2addr_ata(port);
267 while (count--)
268 *buf++ = *(volatile unsigned char *)portp;
269 }
270 #endif
271 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
272 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
273 pcc_ioread_byte(0, port, (void *)addr, sizeof(unsigned char),
274 count, 1);
275 }
276 #endif
277 else {
278 unsigned char *buf = addr;
279 unsigned char *portp = PORT2ADDR(port);
280 while (count--)
281 *buf++ = *(volatile unsigned char *)portp;
282 }
283 }
284
285 void _insw(unsigned int port, void * addr, unsigned long count)
286 {
287 unsigned short *buf = addr;
288 unsigned short *portp;
289
290 if (port >= LAN_IOSTART && port < LAN_IOEND) {
291 portp = PORT2ADDR_NE(port);
292 while (count--)
293 *buf++ = *(volatile unsigned short *)portp;
294 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
295 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
296 pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short),
297 count, 1);
298 #endif
299 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
300 } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
301 portp = __port2addr_ata(port);
302 while (count--)
303 *buf++ = *(volatile unsigned short *)portp;
304 #endif
305 } else {
306 portp = PORT2ADDR(port);
307 while (count--)
308 *buf++ = *(volatile unsigned short *)portp;
309 }
310 }
311
312 void _insl(unsigned int port, void * addr, unsigned long count)
313 {
314 unsigned long *buf = addr;
315 unsigned long *portp;
316
317 portp = PORT2ADDR(port);
318 while (count--)
319 *buf++ = *(volatile unsigned long *)portp;
320 }
321
322 void _outsb(unsigned int port, const void * addr, unsigned long count)
323 {
324 const unsigned char *buf = addr;
325 unsigned char *portp;
326
327 if (port >= LAN_IOSTART && port < LAN_IOEND) {
328 portp = PORT2ADDR_NE(port);
329 while (count--)
330 _ne_outb(*buf++, portp);
331 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
332 } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
333 portp = __port2addr_ata(port);
334 while (count--)
335 *(volatile unsigned char *)portp = *buf++;
336 #endif
337 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
338 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
339 pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char),
340 count, 1);
341 #endif
342 } else {
343 portp = PORT2ADDR(port);
344 while (count--)
345 *(volatile unsigned char *)portp = *buf++;
346 }
347 }
348
349 void _outsw(unsigned int port, const void * addr, unsigned long count)
350 {
351 const unsigned short *buf = addr;
352 unsigned short *portp;
353
354 if (port >= LAN_IOSTART && port < LAN_IOEND) {
355 portp = PORT2ADDR_NE(port);
356 while (count--)
357 *(volatile unsigned short *)portp = *buf++;
358 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
359 } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
360 portp = __port2addr_ata(port);
361 while (count--)
362 *(volatile unsigned short *)portp = *buf++;
363 #endif
364 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
365 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
366 pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short),
367 count, 1);
368 #endif
369 } else {
370 portp = PORT2ADDR(port);
371 while (count--)
372 *(volatile unsigned short *)portp = *buf++;
373 }
374 }
375
376 void _outsl(unsigned int port, const void * addr, unsigned long count)
377 {
378 const unsigned long *buf = addr;
379 unsigned char *portp;
380
381 portp = PORT2ADDR(port);
382 while (count--)
383 *(volatile unsigned long *)portp = *buf++;
384 }