]> git.sur5r.net Git - u-boot/commitdiff
Blackfin: sync MMR read/write helpers with Linux
authorMike Frysinger <vapier@gentoo.org>
Sat, 14 May 2011 14:20:25 +0000 (10:20 -0400)
committerMike Frysinger <vapier@gentoo.org>
Tue, 12 Jul 2011 06:17:45 +0000 (02:17 -0400)
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
arch/blackfin/include/asm/blackfin_local.h

index 48f793a4ce6199343084291a23a7269b698d7636..27034d3d06bd935518771df2a494fd916a60b92c 100644 (file)
@@ -93,65 +93,61 @@ extern void blackfin_dcache_flush_invalidate_range(const void *, const void *);
 # define NOP_PAD_ANOMALY_05000198
 #endif
 
-#define bfin_read8(addr) ({ \
-       uint8_t __v; \
+#define _bfin_readX(addr, size, asm_size, asm_ext) ({ \
+       u32 __v; \
        __asm__ __volatile__( \
                NOP_PAD_ANOMALY_05000198 \
-               "%0 = b[%1] (z);" \
+               "%0 = " #asm_size "[%1]" #asm_ext ";" \
                : "=d" (__v) \
                : "a" (addr) \
        ); \
        __v; })
-
-#define bfin_read16(addr) ({ \
-       uint16_t __v; \
-       __asm__ __volatile__( \
-               NOP_PAD_ANOMALY_05000198 \
-               "%0 = w[%1] (z);" \
-               : "=d" (__v) \
-               : "a" (addr) \
-       ); \
-       __v; })
-
-#define bfin_read32(addr) ({ \
-       uint32_t __v; \
+#define _bfin_writeX(addr, val, size, asm_size) \
        __asm__ __volatile__( \
                NOP_PAD_ANOMALY_05000198 \
-               "%0 = [%1];" \
-               : "=d" (__v) \
-               : "a" (addr) \
-       ); \
-       __v; })
-
-#define bfin_readPTR(addr) bfin_read32(addr)
-
-#define bfin_write8(addr, val) \
-       __asm__ __volatile__( \
-               NOP_PAD_ANOMALY_05000198 \
-               "b[%0] = %1;" \
-               : \
-               : "a" (addr), "d" (val) \
-               : "memory" \
-       )
-
-#define bfin_write16(addr, val) \
-       __asm__ __volatile__( \
-               NOP_PAD_ANOMALY_05000198 \
-               "w[%0] = %1;" \
+               #asm_size "[%0] = %1;" \
                : \
-               : "a" (addr), "d" (val) \
+               : "a" (addr), "d" ((u##size)(val)) \
                : "memory" \
        )
 
-#define bfin_write32(addr, val) \
-       __asm__ __volatile__( \
-               NOP_PAD_ANOMALY_05000198 \
-               "[%0] = %1;" \
-               : \
-               : "a" (addr), "d" (val) \
-               : "memory" \
-       )
+#define bfin_read8(addr)  _bfin_readX(addr,  8, b, (z))
+#define bfin_read16(addr) _bfin_readX(addr, 16, w, (z))
+#define bfin_read32(addr) _bfin_readX(addr, 32,  ,    )
+#define bfin_write8(addr, val)  _bfin_writeX(addr, val,  8, b)
+#define bfin_write16(addr, val) _bfin_writeX(addr, val, 16, w)
+#define bfin_write32(addr, val) _bfin_writeX(addr, val, 32,  )
+
+#define bfin_read(addr) \
+({ \
+       sizeof(*(addr)) == 1 ? bfin_read8(addr)  : \
+       sizeof(*(addr)) == 2 ? bfin_read16(addr) : \
+       sizeof(*(addr)) == 4 ? bfin_read32(addr) : \
+       ({ BUG(); 0; }); \
+})
+#define bfin_write(addr, val) \
+do { \
+       switch (sizeof(*(addr))) { \
+       case 1: bfin_write8(addr, val);  break; \
+       case 2: bfin_write16(addr, val); break; \
+       case 4: bfin_write32(addr, val); break; \
+       default: BUG(); \
+       } \
+} while (0)
+
+#define bfin_write_or(addr, bits) \
+do { \
+       typeof(addr) __addr = (addr); \
+       bfin_write(__addr, bfin_read(__addr) | (bits)); \
+} while (0)
+
+#define bfin_write_and(addr, bits) \
+do { \
+       typeof(addr) __addr = (addr); \
+       bfin_write(__addr, bfin_read(__addr) & (bits)); \
+} while (0)
 
+#define bfin_readPTR(addr) bfin_read32(addr)
 #define bfin_writePTR(addr, val) bfin_write32(addr, val)
 
 /* SSYNC implementation for C file */