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