aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/rt2x00/rt2800usb.c
diff options
context:
space:
mode:
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2009-11-04 12:36:24 -0500
committerJohn W. Linville <linville@tuxdriver.com>2009-11-06 16:48:58 -0500
commit89297425c2104b187c25d6260a41345c491c8f18 (patch)
tree7a66b13c5a555af7d1adfd20fbda06e37dbf3ef0 /drivers/net/wireless/rt2x00/rt2800usb.c
parent4d6f8b9f17626da48d6badc6ba259fbacc1413c3 (diff)
rt2800: add rt2800lib (part one)
Code unification. Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> Acked-by: Ivo van Doorn <IvDoorn@gmail.com> Acked-by: Gertjan van Wingerde <gwingerde@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/rt2x00/rt2800usb.c')
-rw-r--r--drivers/net/wireless/rt2x00/rt2800usb.c223
1 files changed, 0 insertions, 223 deletions
diff --git a/drivers/net/wireless/rt2x00/rt2800usb.c b/drivers/net/wireless/rt2x00/rt2800usb.c
index 9aee3ab6589e..6bd646a979af 100644
--- a/drivers/net/wireless/rt2x00/rt2800usb.c
+++ b/drivers/net/wireless/rt2x00/rt2800usb.c
@@ -45,229 +45,6 @@ static int modparam_nohwcrypt = 1;
45module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO); 45module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
46MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption."); 46MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
47 47
48/*
49 * Register access.
50 * All access to the CSR registers will go through the methods
51 * rt2800_register_read and rt2800_register_write.
52 * BBP and RF register require indirect register access,
53 * and use the CSR registers BBPCSR and RFCSR to achieve this.
54 * These indirect registers work with busy bits,
55 * and we will try maximal REGISTER_BUSY_COUNT times to access
56 * the register while taking a REGISTER_BUSY_DELAY us delay
57 * between each attampt. When the busy bit is still set at that time,
58 * the access attempt is considered to have failed,
59 * and we will print an error.
60 * The _lock versions must be used if you already hold the csr_mutex
61 */
62#define WAIT_FOR_BBP(__dev, __reg) \
63 rt2800_regbusy_read((__dev), BBP_CSR_CFG, BBP_CSR_CFG_BUSY, (__reg))
64#define WAIT_FOR_RFCSR(__dev, __reg) \
65 rt2800_regbusy_read((__dev), RF_CSR_CFG, RF_CSR_CFG_BUSY, (__reg))
66#define WAIT_FOR_RF(__dev, __reg) \
67 rt2800_regbusy_read((__dev), RF_CSR_CFG0, RF_CSR_CFG0_BUSY, (__reg))
68#define WAIT_FOR_MCU(__dev, __reg) \
69 rt2800_regbusy_read((__dev), H2M_MAILBOX_CSR, \
70 H2M_MAILBOX_CSR_OWNER, (__reg))
71
72static void rt2800usb_bbp_write(struct rt2x00_dev *rt2x00dev,
73 const unsigned int word, const u8 value)
74{
75 u32 reg;
76
77 mutex_lock(&rt2x00dev->csr_mutex);
78
79 /*
80 * Wait until the BBP becomes available, afterwards we
81 * can safely write the new data into the register.
82 */
83 if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
84 reg = 0;
85 rt2x00_set_field32(&reg, BBP_CSR_CFG_VALUE, value);
86 rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
87 rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
88 rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 0);
89
90 rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
91 }
92
93 mutex_unlock(&rt2x00dev->csr_mutex);
94}
95
96static void rt2800usb_bbp_read(struct rt2x00_dev *rt2x00dev,
97 const unsigned int word, u8 *value)
98{
99 u32 reg;
100
101 mutex_lock(&rt2x00dev->csr_mutex);
102
103 /*
104 * Wait until the BBP becomes available, afterwards we
105 * can safely write the read request into the register.
106 * After the data has been written, we wait until hardware
107 * returns the correct value, if at any time the register
108 * doesn't become available in time, reg will be 0xffffffff
109 * which means we return 0xff to the caller.
110 */
111 if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
112 reg = 0;
113 rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
114 rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
115 rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 1);
116
117 rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
118
119 WAIT_FOR_BBP(rt2x00dev, &reg);
120 }
121
122 *value = rt2x00_get_field32(reg, BBP_CSR_CFG_VALUE);
123
124 mutex_unlock(&rt2x00dev->csr_mutex);
125}
126
127static inline void rt2800_bbp_write(struct rt2x00_dev *rt2x00dev,
128 const unsigned int word, const u8 value)
129{
130 rt2800usb_bbp_write(rt2x00dev, word, value);
131}
132
133static inline void rt2800_bbp_read(struct rt2x00_dev *rt2x00dev,
134 const unsigned int word, u8 *value)
135{
136 rt2800usb_bbp_read(rt2x00dev, word, value);
137}
138
139static void rt2800usb_rfcsr_write(struct rt2x00_dev *rt2x00dev,
140 const unsigned int word, const u8 value)
141{
142 u32 reg;
143
144 mutex_lock(&rt2x00dev->csr_mutex);
145
146 /*
147 * Wait until the RFCSR becomes available, afterwards we
148 * can safely write the new data into the register.
149 */
150 if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
151 reg = 0;
152 rt2x00_set_field32(&reg, RF_CSR_CFG_DATA, value);
153 rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
154 rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 1);
155 rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
156
157 rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
158 }
159
160 mutex_unlock(&rt2x00dev->csr_mutex);
161}
162
163static void rt2800usb_rfcsr_read(struct rt2x00_dev *rt2x00dev,
164 const unsigned int word, u8 *value)
165{
166 u32 reg;
167
168 mutex_lock(&rt2x00dev->csr_mutex);
169
170 /*
171 * Wait until the RFCSR becomes available, afterwards we
172 * can safely write the read request into the register.
173 * After the data has been written, we wait until hardware
174 * returns the correct value, if at any time the register
175 * doesn't become available in time, reg will be 0xffffffff
176 * which means we return 0xff to the caller.
177 */
178 if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
179 reg = 0;
180 rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
181 rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 0);
182 rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
183
184 rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
185
186 WAIT_FOR_RFCSR(rt2x00dev, &reg);
187 }
188
189 *value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA);
190
191 mutex_unlock(&rt2x00dev->csr_mutex);
192}
193
194static inline void rt2800_rfcsr_write(struct rt2x00_dev *rt2x00dev,
195 const unsigned int word, const u8 value)
196{
197 rt2800usb_rfcsr_write(rt2x00dev, word, value);
198}
199
200static inline void rt2800_rfcsr_read(struct rt2x00_dev *rt2x00dev,
201 const unsigned int word, u8 *value)
202{
203 rt2800usb_rfcsr_read(rt2x00dev, word, value);
204}
205
206static void rt2800usb_rf_write(struct rt2x00_dev *rt2x00dev,
207 const unsigned int word, const u32 value)
208{
209 u32 reg;
210
211 mutex_lock(&rt2x00dev->csr_mutex);
212
213 /*
214 * Wait until the RF becomes available, afterwards we
215 * can safely write the new data into the register.
216 */
217 if (WAIT_FOR_RF(rt2x00dev, &reg)) {
218 reg = 0;
219 rt2x00_set_field32(&reg, RF_CSR_CFG0_REG_VALUE_BW, value);
220 rt2x00_set_field32(&reg, RF_CSR_CFG0_STANDBYMODE, 0);
221 rt2x00_set_field32(&reg, RF_CSR_CFG0_SEL, 0);
222 rt2x00_set_field32(&reg, RF_CSR_CFG0_BUSY, 1);
223
224 rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG0, reg);
225 rt2x00_rf_write(rt2x00dev, word, value);
226 }
227
228 mutex_unlock(&rt2x00dev->csr_mutex);
229}
230
231static inline void rt2800_rf_write(struct rt2x00_dev *rt2x00dev,
232 const unsigned int word, const u32 value)
233{
234 rt2800usb_rf_write(rt2x00dev, word, value);
235}
236
237static void rt2800usb_mcu_request(struct rt2x00_dev *rt2x00dev,
238 const u8 command, const u8 token,
239 const u8 arg0, const u8 arg1)
240{
241 u32 reg;
242
243 mutex_lock(&rt2x00dev->csr_mutex);
244
245 /*
246 * Wait until the MCU becomes available, afterwards we
247 * can safely write the new data into the register.
248 */
249 if (WAIT_FOR_MCU(rt2x00dev, &reg)) {
250 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_OWNER, 1);
251 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_CMD_TOKEN, token);
252 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG0, arg0);
253 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG1, arg1);
254 rt2800_register_write_lock(rt2x00dev, H2M_MAILBOX_CSR, reg);
255
256 reg = 0;
257 rt2x00_set_field32(&reg, HOST_CMD_CSR_HOST_COMMAND, command);
258 rt2800_register_write_lock(rt2x00dev, HOST_CMD_CSR, reg);
259 }
260
261 mutex_unlock(&rt2x00dev->csr_mutex);
262}
263
264static inline void rt2800_mcu_request(struct rt2x00_dev *rt2x00dev,
265 const u8 command, const u8 token,
266 const u8 arg0, const u8 arg1)
267{
268 rt2800usb_mcu_request(rt2x00dev, command, token, arg0, arg1);
269}
270
271#ifdef CONFIG_RT2X00_LIB_DEBUGFS 48#ifdef CONFIG_RT2X00_LIB_DEBUGFS
272static const struct rt2x00debug rt2800usb_rt2x00debug = { 49static const struct rt2x00debug rt2800usb_rt2x00debug = {
273 .owner = THIS_MODULE, 50 .owner = THIS_MODULE,