2 * linux/arch/m32r/kernel/io_mappi3.c
4 * Typical I/O routines for Mappi3 board.
6 * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata,
7 * Hitoshi Yamamoto, Mamoru Sakugawa
10 #include <linux/config.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_M32R_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 #if defined(CONFIG_IDE)
40 static inline void *__port2addr_ata(unsigned long port)
46 case 0x1f0: return (void *)(0x14002000 | NONCACHE_OFFSET);
47 case 0x1f1: return (void *)(0x14012800 | NONCACHE_OFFSET);
48 case 0x1f2: return (void *)(0x14012002 | NONCACHE_OFFSET);
49 case 0x1f3: return (void *)(0x14012802 | NONCACHE_OFFSET);
50 case 0x1f4: return (void *)(0x14012004 | NONCACHE_OFFSET);
51 case 0x1f5: return (void *)(0x14012804 | NONCACHE_OFFSET);
52 case 0x1f6: return (void *)(0x14012006 | NONCACHE_OFFSET);
53 case 0x1f7: return (void *)(0x14012806 | NONCACHE_OFFSET);
54 case 0x3f6: return (void *)(0x1401200e | NONCACHE_OFFSET);
56 case 0x170: /* Data 16bit */
57 return (void *)(0x14810000 | NONCACHE_OFFSET);
58 case 0x171: /* Features / Error */
59 return (void *)(0x14810002 | NONCACHE_OFFSET);
60 case 0x172: /* Sector count */
61 return (void *)(0x14810004 | NONCACHE_OFFSET);
62 case 0x173: /* Sector number */
63 return (void *)(0x14810006 | NONCACHE_OFFSET);
64 case 0x174: /* Cylinder low */
65 return (void *)(0x14810008 | NONCACHE_OFFSET);
66 case 0x175: /* Cylinder high */
67 return (void *)(0x1481000a | NONCACHE_OFFSET);
68 case 0x176: /* Device head */
69 return (void *)(0x1481000c | NONCACHE_OFFSET);
70 case 0x177: /* Command */
71 return (void *)(0x1481000e | NONCACHE_OFFSET);
72 case 0x376: /* Device control / Alt status */
73 return (void *)(0x1480800c | NONCACHE_OFFSET);
75 default: return (void *)&dummy_reg;
80 #define LAN_IOSTART (0x300 | NONCACHE_OFFSET)
81 #define LAN_IOEND (0x320 | NONCACHE_OFFSET)
82 static inline void *_port2addr_ne(unsigned long port)
84 return (void *)(port + 0x10000000);
87 static inline void *_port2addr_usb(unsigned long port)
89 return (void *)(port + NONCACHE_OFFSET + 0x12000000);
91 static inline void delay(void)
93 __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
100 static inline unsigned char _ne_inb(void *portp)
102 return (unsigned char) *(volatile unsigned char *)portp;
105 static inline unsigned short _ne_inw(void *portp)
107 return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp);
110 static inline void _ne_insb(void *portp, void * addr, unsigned long count)
112 unsigned char *buf = addr;
115 *buf++ = *(volatile unsigned char *)portp;
118 static inline void _ne_outb(unsigned char b, void *portp)
120 *(volatile unsigned char *)portp = (unsigned char)b;
123 static inline void _ne_outw(unsigned short w, void *portp)
125 *(volatile unsigned short *)portp = cpu_to_le16(w);
128 unsigned char _inb(unsigned long port)
130 if (port >= LAN_IOSTART && port < LAN_IOEND)
131 return _ne_inb(PORT2ADDR_NE(port));
132 #if defined(CONFIG_IDE)
133 else if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
134 ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
135 return *(volatile unsigned char *)__port2addr_ata(port);
138 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
139 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
141 pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
145 return *(volatile unsigned char *)PORT2ADDR(port);
148 unsigned short _inw(unsigned long port)
150 if (port >= LAN_IOSTART && port < LAN_IOEND)
151 return _ne_inw(PORT2ADDR_NE(port));
152 #if defined(CONFIG_IDE)
153 else if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
154 ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
155 return *(volatile unsigned short *)__port2addr_ata(port);
158 #if defined(CONFIG_USB)
159 else if (port >= 0x340 && port < 0x3a0)
160 return *(volatile unsigned short *)PORT2ADDR_USB(port);
163 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
164 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
166 pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
170 return *(volatile unsigned short *)PORT2ADDR(port);
173 unsigned long _inl(unsigned long port)
175 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
176 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
178 pcc_ioread_word(0, port, &l, sizeof(l), 1, 0);
182 return *(volatile unsigned long *)PORT2ADDR(port);
185 unsigned char _inb_p(unsigned long port)
187 unsigned char v = _inb(port);
192 unsigned short _inw_p(unsigned long port)
194 unsigned short v = _inw(port);
199 unsigned long _inl_p(unsigned long port)
201 unsigned long v = _inl(port);
206 void _outb(unsigned char b, unsigned long port)
208 if (port >= LAN_IOSTART && port < LAN_IOEND)
209 _ne_outb(b, PORT2ADDR_NE(port));
211 #if defined(CONFIG_IDE)
212 if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
213 ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
214 *(volatile unsigned char *)__port2addr_ata(port) = b;
217 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
218 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
219 pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
222 *(volatile unsigned char *)PORT2ADDR(port) = b;
225 void _outw(unsigned short w, unsigned long port)
227 if (port >= LAN_IOSTART && port < LAN_IOEND)
228 _ne_outw(w, PORT2ADDR_NE(port));
230 #if defined(CONFIG_IDE)
231 if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
232 ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
233 *(volatile unsigned short *)__port2addr_ata(port) = w;
236 #if defined(CONFIG_USB)
237 if (port >= 0x340 && port < 0x3a0)
238 *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
241 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
242 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
243 pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
246 *(volatile unsigned short *)PORT2ADDR(port) = w;
249 void _outl(unsigned long l, unsigned long port)
251 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
252 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
253 pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
256 *(volatile unsigned long *)PORT2ADDR(port) = l;
259 void _outb_p(unsigned char b, unsigned long port)
265 void _outw_p(unsigned short w, unsigned long port)
271 void _outl_p(unsigned long l, unsigned long port)
277 void _insb(unsigned int port, void * addr, unsigned long count)
279 if (port >= LAN_IOSTART && port < LAN_IOEND)
280 _ne_insb(PORT2ADDR_NE(port), addr, count);
281 #if defined(CONFIG_IDE)
282 else if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
283 ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
284 unsigned char *buf = addr;
285 unsigned char *portp = __port2addr_ata(port);
287 *buf++ = *(volatile unsigned char *)portp;
290 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
291 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
292 pcc_ioread_byte(0, port, (void *)addr, sizeof(unsigned char),
297 unsigned char *buf = addr;
298 unsigned char *portp = PORT2ADDR(port);
300 *buf++ = *(volatile unsigned char *)portp;
304 void _insw(unsigned int port, void * addr, unsigned long count)
306 unsigned short *buf = addr;
307 unsigned short *portp;
309 if (port >= LAN_IOSTART && port < LAN_IOEND) {
310 portp = PORT2ADDR_NE(port);
312 *buf++ = *(volatile unsigned short *)portp;
313 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
314 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
315 pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short),
318 #if defined(CONFIG_IDE)
319 } else if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
320 ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
321 portp = __port2addr_ata(port);
323 *buf++ = *(volatile unsigned short *)portp;
326 portp = PORT2ADDR(port);
328 *buf++ = *(volatile unsigned short *)portp;
332 void _insl(unsigned int port, void * addr, unsigned long count)
334 unsigned long *buf = addr;
335 unsigned long *portp;
337 portp = PORT2ADDR(port);
339 *buf++ = *(volatile unsigned long *)portp;
342 void _outsb(unsigned int port, const void * addr, unsigned long count)
344 const unsigned char *buf = addr;
345 unsigned char *portp;
347 if (port >= LAN_IOSTART && port < LAN_IOEND) {
348 portp = PORT2ADDR_NE(port);
350 _ne_outb(*buf++, portp);
351 #if defined(CONFIG_IDE)
352 } else if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
353 ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
354 portp = __port2addr_ata(port);
356 *(volatile unsigned char *)portp = *buf++;
358 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
359 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
360 pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char),
364 portp = PORT2ADDR(port);
366 *(volatile unsigned char *)portp = *buf++;
370 void _outsw(unsigned int port, const void * addr, unsigned long count)
372 const unsigned short *buf = addr;
373 unsigned short *portp;
375 if (port >= LAN_IOSTART && port < LAN_IOEND) {
376 portp = PORT2ADDR_NE(port);
378 *(volatile unsigned short *)portp = *buf++;
379 #if defined(CONFIG_IDE)
380 } else if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
381 ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
382 portp = __port2addr_ata(port);
384 *(volatile unsigned short *)portp = *buf++;
386 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
387 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
388 pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short),
392 portp = PORT2ADDR(port);
394 *(volatile unsigned short *)portp = *buf++;
398 void _outsl(unsigned int port, const void * addr, unsigned long count)
400 const unsigned long *buf = addr;
401 unsigned char *portp;
403 portp = PORT2ADDR(port);
405 *(volatile unsigned long *)portp = *buf++;