2 Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 Abstract: rt2x00 generic register information.
33 ANTENNA_SW_DIVERSITY = 0,
36 ANTENNA_HW_DIVERSITY = 3,
44 LED_MODE_TXRX_ACTIVITY = 1,
45 LED_MODE_SIGNAL_STRENGTH = 2,
69 * Additional device states, these values are
70 * not strict since they are not directly passed
77 STATE_RADIO_RX_ON_LINK,
78 STATE_RADIO_RX_OFF_LINK,
94 * Cipher types for hardware encryption
103 * The following fields were added by rt61pci and rt73usb.
107 CIPHER_TKIP_NO_MIC = 7,
112 * We store the position of a register field inside a field structure,
113 * This will simplify the process of setting and reading a certain field
114 * inside the register while making sure the process remains byte order safe.
116 struct rt2x00_field8 {
121 struct rt2x00_field16 {
126 struct rt2x00_field32 {
132 * Power of two check, this will check
133 * if the mask that has been given contains and contiguous set of bits.
134 * Note that we cannot use the is_power_of_2() function since this
135 * check must be done at compile-time.
137 #define is_power_of_two(x) ( !((x) & ((x)-1)) )
138 #define low_bit_mask(x) ( ((x)-1) & ~(x) )
139 #define is_valid_mask(x) is_power_of_two(1 + (x) + low_bit_mask(x))
142 * Macro's to find first set bit in a variable.
143 * These macro's behaves the same as the __ffs() function with
144 * the most important difference that this is done during
145 * compile-time rather then run-time.
147 #define compile_ffs2(__x) \
148 __builtin_choose_expr(((__x) & 0x1), 0, 1)
150 #define compile_ffs4(__x) \
151 __builtin_choose_expr(((__x) & 0x3), \
152 (compile_ffs2((__x))), \
153 (compile_ffs2((__x) >> 2) + 2))
155 #define compile_ffs8(__x) \
156 __builtin_choose_expr(((__x) & 0xf), \
157 (compile_ffs4((__x))), \
158 (compile_ffs4((__x) >> 4) + 4))
160 #define compile_ffs16(__x) \
161 __builtin_choose_expr(((__x) & 0xff), \
162 (compile_ffs8((__x))), \
163 (compile_ffs8((__x) >> 8) + 8))
165 #define compile_ffs32(__x) \
166 __builtin_choose_expr(((__x) & 0xffff), \
167 (compile_ffs16((__x))), \
168 (compile_ffs16((__x) >> 16) + 16))
171 * This macro will check the requirements for the FIELD{8,16,32} macros
172 * The mask should be a constant non-zero contiguous set of bits which
173 * does not exceed the given typelimit.
175 #define FIELD_CHECK(__mask, __type) \
176 BUILD_BUG_ON(!__builtin_constant_p(__mask) || \
178 !is_valid_mask(__mask) || \
179 (__mask) != (__type)(__mask)) \
181 #define FIELD8(__mask) \
183 FIELD_CHECK(__mask, u8); \
184 (struct rt2x00_field8) { \
185 compile_ffs8(__mask), (__mask) \
189 #define FIELD16(__mask) \
191 FIELD_CHECK(__mask, u16); \
192 (struct rt2x00_field16) { \
193 compile_ffs16(__mask), (__mask) \
197 #define FIELD32(__mask) \
199 FIELD_CHECK(__mask, u32); \
200 (struct rt2x00_field32) { \
201 compile_ffs32(__mask), (__mask) \
205 #define SET_FIELD(__reg, __type, __field, __value)\
207 typecheck(__type, __field); \
208 *(__reg) &= ~((__field).bit_mask); \
209 *(__reg) |= ((__value) << \
210 ((__field).bit_offset)) & \
211 ((__field).bit_mask); \
214 #define GET_FIELD(__reg, __type, __field) \
216 typecheck(__type, __field); \
217 ((__reg) & ((__field).bit_mask)) >> \
218 ((__field).bit_offset); \
221 #define rt2x00_set_field32(__reg, __field, __value) \
222 SET_FIELD(__reg, struct rt2x00_field32, __field, __value)
223 #define rt2x00_get_field32(__reg, __field) \
224 GET_FIELD(__reg, struct rt2x00_field32, __field)
226 #define rt2x00_set_field16(__reg, __field, __value) \
227 SET_FIELD(__reg, struct rt2x00_field16, __field, __value)
228 #define rt2x00_get_field16(__reg, __field) \
229 GET_FIELD(__reg, struct rt2x00_field16, __field)
231 #define rt2x00_set_field8(__reg, __field, __value) \
232 SET_FIELD(__reg, struct rt2x00_field8, __field, __value)
233 #define rt2x00_get_field8(__reg, __field) \
234 GET_FIELD(__reg, struct rt2x00_field8, __field)
236 #endif /* RT2X00REG_H */