Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / m32r / kernel / io_mappi2.c
blob4182cd4f97c8a77a60ca636de368677059cbf792
1 /*
2 * linux/arch/m32r/kernel/io_mappi2.c
4 * Typical I/O routines for Mappi2 board.
6 * Copyright (c) 2001-2003 Hiroyuki Kondo, Hirokazu Takata,
7 * Hitoshi Yamamoto, Mamoru Sakugawa
8 */
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>
16 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
17 #include <linux/types.h>
19 #define M32R_PCC_IOMAP_SIZE 0x1000
21 #define M32R_PCC_IOSTART0 0x1000
22 #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
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_MAPPI2_CFC */
30 #define PORT2ADDR(port) _port2addr(port)
31 #define PORT2ADDR_NE(port) _port2addr_ne(port)
32 #define PORT2ADDR_USB(port) _port2addr_usb(port)
34 static inline void *_port2addr(unsigned long port)
36 return (void *)(port + NONCACHE_OFFSET);
39 #define LAN_IOSTART 0x300
40 #define LAN_IOEND 0x320
42 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
43 static inline void *__port2addr_ata(unsigned long port)
45 static int dummy_reg;
47 switch (port) {
48 case 0x1f0: return (void *)0xac002000;
49 case 0x1f1: return (void *)0xac012800;
50 case 0x1f2: return (void *)0xac012002;
51 case 0x1f3: return (void *)0xac012802;
52 case 0x1f4: return (void *)0xac012004;
53 case 0x1f5: return (void *)0xac012804;
54 case 0x1f6: return (void *)0xac012006;
55 case 0x1f7: return (void *)0xac012806;
56 case 0x3f6: return (void *)0xac01200e;
57 default: return (void *)&dummy_reg;
60 #endif
62 #ifdef CONFIG_CHIP_OPSP
63 static inline void *_port2addr_ne(unsigned long port)
65 return (void *)(port + NONCACHE_OFFSET + 0x10000000);
67 #else
68 static inline void *_port2addr_ne(unsigned long port)
70 return (void *)(port + NONCACHE_OFFSET + 0x04000000);
72 #endif
73 static inline void *_port2addr_usb(unsigned long port)
75 return (void *)(port + NONCACHE_OFFSET + 0x14000000);
77 static inline void delay(void)
79 __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
83 * NIC I/O function
86 static inline unsigned char _ne_inb(void *portp)
88 return (unsigned char) *(volatile unsigned char *)portp;
91 static inline unsigned short _ne_inw(void *portp)
93 return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp);
96 static inline void _ne_insb(void *portp, void * addr, unsigned long count)
98 unsigned char *buf = addr;
100 while (count--)
101 *buf++ = *(volatile unsigned char *)portp;
104 static inline void _ne_outb(unsigned char b, void *portp)
106 *(volatile unsigned char *)portp = (unsigned char)b;
109 static inline void _ne_outw(unsigned short w, void *portp)
111 *(volatile unsigned short *)portp = cpu_to_le16(w);
114 unsigned char _inb(unsigned long port)
116 if (port >= LAN_IOSTART && port < LAN_IOEND)
117 return _ne_inb(PORT2ADDR_NE(port));
118 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
119 else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
120 return *(volatile unsigned char *)__port2addr_ata(port);
122 #endif
123 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
124 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
125 unsigned char b;
126 pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
127 return b;
128 } else
129 #endif
131 return *(volatile unsigned char *)PORT2ADDR(port);
134 unsigned short _inw(unsigned long port)
136 if (port >= LAN_IOSTART && port < LAN_IOEND)
137 return _ne_inw(PORT2ADDR_NE(port));
138 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
139 else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
140 return *(volatile unsigned short *)__port2addr_ata(port);
142 #endif
143 #if defined(CONFIG_USB)
144 else if (port >= 0x340 && port < 0x3a0)
145 return *(volatile unsigned short *)PORT2ADDR_USB(port);
146 #endif
148 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
149 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
150 unsigned short w;
151 pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
152 return w;
153 } else
154 #endif
155 return *(volatile unsigned short *)PORT2ADDR(port);
158 unsigned long _inl(unsigned long port)
160 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
161 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
162 unsigned long l;
163 pcc_ioread_word(0, port, &l, sizeof(l), 1, 0);
164 return l;
165 } else
166 #endif
167 return *(volatile unsigned long *)PORT2ADDR(port);
170 unsigned char _inb_p(unsigned long port)
172 unsigned char v;
174 if (port >= LAN_IOSTART && port < LAN_IOEND)
175 v = _ne_inb(PORT2ADDR_NE(port));
176 else
177 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
178 if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
179 return *(volatile unsigned char *)__port2addr_ata(port);
180 } else
181 #endif
182 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
183 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
184 unsigned char b;
185 pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
186 return b;
187 } else
188 #endif
189 v = *(volatile unsigned char *)PORT2ADDR(port);
191 delay();
192 return (v);
195 unsigned short _inw_p(unsigned long port)
197 unsigned short v;
199 if (port >= LAN_IOSTART && port < LAN_IOEND)
200 v = _ne_inw(PORT2ADDR_NE(port));
201 else
202 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
203 if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
204 return *(volatile unsigned short *)__port2addr_ata(port);
205 } else
206 #endif
207 #if defined(CONFIG_USB)
208 if (port >= 0x340 && port < 0x3a0)
209 v = *(volatile unsigned short *)PORT2ADDR_USB(port);
210 else
211 #endif
212 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
213 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
214 unsigned short w;
215 pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
216 return w;
217 } else
218 #endif
219 v = *(volatile unsigned short *)PORT2ADDR(port);
221 delay();
222 return (v);
225 unsigned long _inl_p(unsigned long port)
227 unsigned long v;
229 v = *(volatile unsigned long *)PORT2ADDR(port);
230 delay();
231 return (v);
234 void _outb(unsigned char b, unsigned long port)
236 if (port >= LAN_IOSTART && port < LAN_IOEND)
237 _ne_outb(b, PORT2ADDR_NE(port));
238 else
239 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
240 if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
241 *(volatile unsigned char *)__port2addr_ata(port) = b;
242 } else
243 #endif
244 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
245 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
246 pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
247 } else
248 #endif
249 *(volatile unsigned char *)PORT2ADDR(port) = b;
252 void _outw(unsigned short w, unsigned long port)
254 if (port >= LAN_IOSTART && port < LAN_IOEND)
255 _ne_outw(w, PORT2ADDR_NE(port));
256 else
257 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
258 if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
259 *(volatile unsigned short *)__port2addr_ata(port) = w;
260 } else
261 #endif
262 #if defined(CONFIG_USB)
263 if (port >= 0x340 && port < 0x3a0)
264 *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
265 else
266 #endif
267 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
268 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
269 pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
270 } else
271 #endif
272 *(volatile unsigned short *)PORT2ADDR(port) = w;
275 void _outl(unsigned long l, unsigned long port)
277 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
278 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
279 pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
280 } else
281 #endif
282 *(volatile unsigned long *)PORT2ADDR(port) = l;
285 void _outb_p(unsigned char b, unsigned long port)
287 if (port >= LAN_IOSTART && port < LAN_IOEND)
288 _ne_outb(b, PORT2ADDR_NE(port));
289 else
290 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
291 if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
292 *(volatile unsigned char *)__port2addr_ata(port) = b;
293 } else
294 #endif
295 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
296 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
297 pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
298 } else
299 #endif
300 *(volatile unsigned char *)PORT2ADDR(port) = b;
302 delay();
305 void _outw_p(unsigned short w, unsigned long port)
307 if (port >= LAN_IOSTART && port < LAN_IOEND)
308 _ne_outw(w, PORT2ADDR_NE(port));
309 else
310 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
311 if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
312 *(volatile unsigned short *)__port2addr_ata(port) = w;
313 } else
314 #endif
315 #if defined(CONFIG_USB)
316 if (port >= 0x340 && port < 0x3a0)
317 *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
318 else
319 #endif
320 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
321 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
322 pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
323 } else
324 #endif
325 *(volatile unsigned short *)PORT2ADDR(port) = w;
327 delay();
330 void _outl_p(unsigned long l, unsigned long port)
332 *(volatile unsigned long *)PORT2ADDR(port) = l;
333 delay();
336 void _insb(unsigned int port, void * addr, unsigned long count)
338 if (port >= LAN_IOSTART && port < LAN_IOEND)
339 _ne_insb(PORT2ADDR_NE(port), addr, count);
340 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
341 else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
342 unsigned char *buf = addr;
343 unsigned char *portp = __port2addr_ata(port);
344 while (count--)
345 *buf++ = *(volatile unsigned char *)portp;
347 #endif
348 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
349 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
350 pcc_ioread_byte(0, port, (void *)addr, sizeof(unsigned char),
351 count, 1);
353 #endif
354 else {
355 unsigned char *buf = addr;
356 unsigned char *portp = PORT2ADDR(port);
357 while (count--)
358 *buf++ = *(volatile unsigned char *)portp;
362 void _insw(unsigned int port, void * addr, unsigned long count)
364 unsigned short *buf = addr;
365 unsigned short *portp;
367 if (port >= LAN_IOSTART && port < LAN_IOEND) {
368 portp = PORT2ADDR_NE(port);
369 while (count--)
370 *buf++ = *(volatile unsigned short *)portp;
371 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
372 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
373 pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short),
374 count, 1);
375 #endif
376 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
377 } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
378 portp = __port2addr_ata(port);
379 while (count--)
380 *buf++ = *(volatile unsigned short *)portp;
381 #endif
382 } else {
383 portp = PORT2ADDR(port);
384 while (count--)
385 *buf++ = *(volatile unsigned short *)portp;
389 void _insl(unsigned int port, void * addr, unsigned long count)
391 unsigned long *buf = addr;
392 unsigned long *portp;
394 portp = PORT2ADDR(port);
395 while (count--)
396 *buf++ = *(volatile unsigned long *)portp;
399 void _outsb(unsigned int port, const void * addr, unsigned long count)
401 const unsigned char *buf = addr;
402 unsigned char *portp;
404 if (port >= LAN_IOSTART && port < LAN_IOEND) {
405 portp = PORT2ADDR_NE(port);
406 while (count--)
407 _ne_outb(*buf++, portp);
408 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
409 } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
410 portp = __port2addr_ata(port);
411 while (count--)
412 *(volatile unsigned char *)portp = *buf++;
413 #endif
414 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
415 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
416 pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char),
417 count, 1);
418 #endif
419 } else {
420 portp = PORT2ADDR(port);
421 while (count--)
422 *(volatile unsigned char *)portp = *buf++;
426 void _outsw(unsigned int port, const void * addr, unsigned long count)
428 const unsigned short *buf = addr;
429 unsigned short *portp;
431 if (port >= LAN_IOSTART && port < LAN_IOEND) {
432 portp = PORT2ADDR_NE(port);
433 while (count--)
434 *(volatile unsigned short *)portp = *buf++;
435 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
436 } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
437 portp = __port2addr_ata(port);
438 while (count--)
439 *(volatile unsigned short *)portp = *buf++;
440 #endif
441 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
442 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
443 pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short),
444 count, 1);
445 #endif
446 } else {
447 portp = PORT2ADDR(port);
448 while (count--)
449 *(volatile unsigned short *)portp = *buf++;
453 void _outsl(unsigned int port, const void * addr, unsigned long count)
455 const unsigned long *buf = addr;
456 unsigned char *portp;
458 portp = PORT2ADDR(port);
459 while (count--)
460 *(volatile unsigned long *)portp = *buf++;