common.c: change MODULE_LICENSE
[acx-mac80211.git] / acx_util.h
blob12083bf70aec474cb1bc3b496619c99f2f9ca24c
1 #ifndef _ACX_UTIL_H_
2 #define _ACX_UTIL_H_
4 /*
5 * acx_util.h: define some utilities used all along the code.
7 * Copyright (c) 2008 Francis Galiegue <fgaliegue@gmail.com> for the ACX10
8 * driver project.
10 * This file is licensed under the GPLv2.
13 #include <asm/io.h>
15 #include "acx_config.h" /* Needed for ACX_IO_WIDTH */
16 #include "acx_struct.h"
19 * I/O routines
21 * Basically, make LE/BE safe versions of the OS routines.
23 * Declare them all static. They are ultra short operations anyway, and the
24 * header is reentrant, so no worries there.
26 * FIXME: some devices use ssb_*, whatever that turns out to be. Maybe this
27 * could be used instead of using self-constructed offsets?
29 * FIXME, 2: use smp_[rw]mb() after each read/write?
32 #define acx_readl(val) le32_to_cpu(readl((val)))
33 #define acx_readw(val) le16_to_cpu(readw((val)))
35 #define acx_writew(val, port) writew(le16_to_cpu((val)), port)
36 #define acx_writel(val, port) writel(le32_to_cpu((val)), port)
38 static inline u32 read_reg32(acx_device_t * adev, unsigned int offset)
40 #if ACX_IO_WIDTH == 32
41 return acx_readl((u8 *) adev->iobase + adev->io[offset]);
42 #else
43 return acx_readw((u8 *) adev->iobase + adev->io[offset])
44 + (acx_readw((u8 *) adev->iobase + adev->io[offset] + 2) << 16);
45 #endif
48 static inline u16 read_reg16(acx_device_t * adev, unsigned int offset)
50 return acx_readw((u8 *) adev->iobase + adev->io[offset]);
53 static inline u8 read_reg8(acx_device_t * adev, unsigned int offset)
55 return readb((u8 *) adev->iobase + adev->io[offset]);
58 static inline void write_reg32(acx_device_t * adev, unsigned int offset, u32 val)
60 #if ACX_IO_WIDTH == 32
61 acx_writel(val, (u8 *) adev->iobase + adev->io[offset]);
62 #else
63 acx_writew(val & 0xffff, (u8 *) adev->iobase + adev->io[offset]);
64 acx_writew(val >> 16, (u8 *) adev->iobase + adev->io[offset] + 2);
65 #endif
68 static inline void write_reg16(acx_device_t * adev, unsigned int offset, u16 val)
70 acx_writew(val, (u8 *) adev->iobase + adev->io[offset]);
73 static inline void write_reg8(acx_device_t * adev, unsigned int offset, u8 val)
75 writeb(val, (u8 *) adev->iobase + adev->io[offset]);
78 #endif /* _ACX_UTIL_H_ */