patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / include / asm-h8300 / io.h
index 662ca86..ceef520 100644 (file)
  * swap functions are sometimes needed to interface little-endian hardware
  */
 
-/*
- * CHANGES
- * 
- * 020325   Added some #define's for the COBRA5272 board
- *          (hede)
- */
-
 static inline unsigned short _swapw(volatile unsigned short v)
 {
-    return ((v << 8) | (v >> 8));
+       unsigned short r,t;
+       __asm__("mov.b %w2,%x1\n\t"
+               "mov.b %x2,%w1\n\t"
+               "mov.w %1,%0"
+               :"=r"(r),"=r"(t)
+               :"r"(v));
+       return r;
 }
 
 static inline unsigned int _swapl(volatile unsigned long v)
 {
-    return ((v << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8) | (v >> 24));
+       unsigned int r,t;
+       __asm__("mov.b %w2,%x1\n\t"
+               "mov.b %x2,%w1\n\t"
+               "mov.w %f1,%e0\n\t"
+               "mov.w %e2,%f1\n\t"
+               "mov.b %w1,%x0\n\t"
+               "mov.b %x1,%w0"
+               :"=r"(r),"=r"(t)
+               :"r"(v));
+       return r;
 }
 
 #define readb(addr) \
@@ -76,7 +84,7 @@ static inline int h8300_buswidth(unsigned int addr)
        return (*(volatile unsigned char *)ABWCR & (1 << ((addr >> 21) & 7))) == 0;
 }
 
-static inline void io_outsb(unsigned int addr, void *buf, int len)
+static inline void io_outsb(unsigned int addr, const void *buf, int len)
 {
        volatile unsigned char  *ap_b = (volatile unsigned char *) addr;
        volatile unsigned short *ap_w = (volatile unsigned short *) addr;
@@ -91,33 +99,37 @@ static inline void io_outsb(unsigned int addr, void *buf, int len)
        }
 }
 
-static inline void io_outsw(unsigned int addr, void *buf, int len)
+static inline void io_outsw(unsigned int addr, const void *buf, int len)
 {
        volatile unsigned short *ap = (volatile unsigned short *) addr;
        unsigned short *bp = (unsigned short *) buf;
        while (len--)
-               *ap = *bp++;
+               *ap = _swapw(*bp++);
 }
 
-static inline void io_outsl(unsigned int addr, void *buf, int len)
+static inline void io_outsl(unsigned int addr, const void *buf, int len)
 {
        volatile unsigned int *ap = (volatile unsigned int *) addr;
-       unsigned int *bp = (unsigned int *) buf;
+       unsigned long *bp = (unsigned long *) buf;
        while (len--)
-               *ap = *bp++;
+               *ap = _swapl(*bp++);
 }
 
 static inline void io_insb(unsigned int addr, void *buf, int len)
 {
-       volatile unsigned char  *ap;
+       volatile unsigned char  *ap_b;
+       volatile unsigned short *ap_w;
        unsigned char *bp = (unsigned char *) buf;
 
-       if(h8300_buswidth(addr))
-               ap = (volatile unsigned char *)(addr ^ 1);
-       else
-               ap = (volatile unsigned char *)addr;
-       while (len--)
-               *bp++ = *ap;
+       if(h8300_buswidth(addr)) {
+               ap_w = (volatile unsigned short *)(addr & ~1);
+               while (len--)
+                       *bp++ = *ap_w & 0xff;
+       } else {
+               ap_b = (volatile unsigned char *)addr;
+               while (len--)
+                       *bp++ = *ap_b;
+       }
 }
 
 static inline void io_insw(unsigned int addr, void *buf, int len)
@@ -125,15 +137,15 @@ static inline void io_insw(unsigned int addr, void *buf, int len)
        volatile unsigned short *ap = (volatile unsigned short *) addr;
        unsigned short *bp = (unsigned short *) buf;
        while (len--)
-               *bp++ = *ap;
+               *bp++ = _swapw(*ap);
 }
 
 static inline void io_insl(unsigned int addr, void *buf, int len)
 {
        volatile unsigned int *ap = (volatile unsigned int *) addr;
-       unsigned int *bp = (unsigned int *) buf;
+       unsigned long *bp = (unsigned long *) buf;
        while (len--)
-               *bp++ = *ap;
+               *bp++ = _swapl(*ap);
 }
 
 /*
@@ -145,10 +157,10 @@ static inline void io_insl(unsigned int addr, void *buf, int len)
 #define memcpy_fromio(a,b,c)   memcpy((a),(void *)(b),(c))
 #define memcpy_toio(a,b,c)     memcpy((void *)(a),(b),(c))
 
-#define inb(addr)    ((h8300_buswidth(addr))?readb((addr) ^ 1) & 0xff:readb(addr))
+#define inb(addr)    ((h8300_buswidth(addr))?readw((addr) & ~1) & 0xff:readb(addr))
 #define inw(addr)    _swapw(readw(addr))
 #define inl(addr)    _swapl(readl(addr))
-#define outb(x,addr) ((void)((h8300_buswidth(addr) && ((addr) & 1))?writew(x,addr):writeb(x,addr)))
+#define outb(x,addr) ((void)((h8300_buswidth(addr) && ((addr) & 1))?writew(x,(addr) & ~1):writeb(x,addr)))
 #define outw(x,addr) ((void) writew(_swapw(x),addr))
 #define outl(x,addr) ((void) writel(_swapl(x),addr))