From 7349dc6de42b696619d7632fb6a016f848d63bca Mon Sep 17 00:00:00 2001 From: Josh Boyer Date: Tue, 16 May 2006 05:39:27 -0500 Subject: Consolidate the swab macros into one location Signed-off-by: Josh Boyer --- include/mtd_swab.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 include/mtd_swab.h (limited to 'include/mtd_swab.h') diff --git a/include/mtd_swab.h b/include/mtd_swab.h new file mode 100644 index 0000000..05732a9 --- /dev/null +++ b/include/mtd_swab.h @@ -0,0 +1,33 @@ +#ifndef MTD_SWAB_H +#define MTD_SWAB_H + +#include + +#define swab16(x) \ + ((__u16)( \ + (((__u16)(x) & (__u16)0x00ffU) << 8) | \ + (((__u16)(x) & (__u16)0xff00U) >> 8) )) +#define swab32(x) \ + ((__u32)( \ + (((__u32)(x) & (__u32)0x000000ffUL) << 24) | \ + (((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \ + (((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \ + (((__u32)(x) & (__u32)0xff000000UL) >> 24) )) + +#if __BYTE_ORDER == __BIG_ENDIAN +#define cpu_to_le16(x) ({ __u16 _x = x; swab16(_x); }) +#define cpu_to_le32(x) ({ __u32 _x = x; swab32(_x); }) +#define cpu_to_be16(x) (x) +#define cpu_to_be32(x) (x) +#else +#define cpu_to_le16(x) (x) +#define cpu_to_le32(x) (x) +#define cpu_to_be16(x) ({ __u16 _x = x; swab16(_x); }) +#define cpu_to_be32(x) ({ __u32 _x = x; swab32(_x); }) +#endif +#define le16_to_cpu(x) cpu_to_le16(x) +#define be16_to_cpu(x) cpu_to_be16(x) +#define le32_to_cpu(x) cpu_to_le32(x) +#define be32_to_cpu(x) cpu_to_be32(x) + +#endif -- cgit v1.2.3