blob: 3454dacc2af8b7c5d0c283d0ca700300a20d6e13 [file] [log] [blame]
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001/*
2 * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
3 * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
4 * Copyright (c) 2007-2008 Luis Rodriguez <mcgrof@winlab.rutgers.edu>
5 * Copyright (c) 2007-2008 Pavel Roskin <proski@gnu.org>
6 * Copyright (c) 2007-2008 Jiri Slaby <jirislaby@gmail.com>
7 *
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 *
20 */
21
22#define _ATH5K_RESET
23
24/*****************************\
25 Reset functions and helpers
26\*****************************/
27
Luis R. Rodriguezbcd8f542009-09-09 22:43:17 -070028#include <asm/unaligned.h>
29
Nick Kossifidise8f055f2009-02-09 06:12:58 +020030#include <linux/pci.h> /* To determine if a card is pci-e */
Forrest Zhanga54be5d2009-05-13 11:14:39 -040031#include <linux/log2.h>
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030032#include "ath5k.h"
33#include "reg.h"
34#include "base.h"
35#include "debug.h"
36
37/**
38 * ath5k_hw_write_ofdm_timings - set OFDM timings on AR5212
39 *
40 * @ah: the &struct ath5k_hw
41 * @channel: the currently set channel upon reset
42 *
Nick Kossifidise8f055f2009-02-09 06:12:58 +020043 * Write the delta slope coefficient (used on pilot tracking ?) for OFDM
44 * operation on the AR5212 upon reset. This is a helper for ath5k_hw_reset().
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030045 *
Nick Kossifidise8f055f2009-02-09 06:12:58 +020046 * Since delta slope is floating point we split it on its exponent and
47 * mantissa and provide these values on hw.
48 *
49 * For more infos i think this patent is related
50 * http://www.freepatentsonline.com/7184495.html
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030051 */
52static inline int ath5k_hw_write_ofdm_timings(struct ath5k_hw *ah,
53 struct ieee80211_channel *channel)
54{
55 /* Get exponent and mantissa and set it */
56 u32 coef_scaled, coef_exp, coef_man,
57 ds_coef_exp, ds_coef_man, clock;
58
Alexander Beregalov0ee904c2009-04-11 14:50:23 +000059 BUG_ON(!(ah->ah_version == AR5K_AR5212) ||
60 !(channel->hw_value & CHANNEL_OFDM));
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030061
Nick Kossifidise8f055f2009-02-09 06:12:58 +020062 /* Get coefficient
63 * ALGO: coef = (5 * clock * carrier_freq) / 2)
64 * we scale coef by shifting clock value by 24 for
65 * better precision since we use integers */
66 /* TODO: Half/quarter rate */
67 clock = ath5k_hw_htoclock(1, channel->hw_value & CHANNEL_TURBO);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030068
Nick Kossifidise8f055f2009-02-09 06:12:58 +020069 coef_scaled = ((5 * (clock << 24)) / 2) / channel->center_freq;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030070
Nick Kossifidise8f055f2009-02-09 06:12:58 +020071 /* Get exponent
72 * ALGO: coef_exp = 14 - highest set bit position */
Forrest Zhanga54be5d2009-05-13 11:14:39 -040073 coef_exp = ilog2(coef_scaled);
Nick Kossifidise8f055f2009-02-09 06:12:58 +020074
75 /* Doesn't make sense if it's zero*/
Forrest Zhanga54be5d2009-05-13 11:14:39 -040076 if (!coef_scaled || !coef_exp)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030077 return -EINVAL;
78
Nick Kossifidise8f055f2009-02-09 06:12:58 +020079 /* Note: we've shifted coef_scaled by 24 */
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030080 coef_exp = 14 - (coef_exp - 24);
Nick Kossifidise8f055f2009-02-09 06:12:58 +020081
82
83 /* Get mantissa (significant digits)
84 * ALGO: coef_mant = floor(coef_scaled* 2^coef_exp+0.5) */
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030085 coef_man = coef_scaled +
86 (1 << (24 - coef_exp - 1));
Nick Kossifidise8f055f2009-02-09 06:12:58 +020087
88 /* Calculate delta slope coefficient exponent
89 * and mantissa (remove scaling) and set them on hw */
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030090 ds_coef_man = coef_man >> (24 - coef_exp);
91 ds_coef_exp = coef_exp - 16;
92
93 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
94 AR5K_PHY_TIMING_3_DSC_MAN, ds_coef_man);
95 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
96 AR5K_PHY_TIMING_3_DSC_EXP, ds_coef_exp);
97
98 return 0;
99}
100
101
102/*
103 * index into rates for control rates, we can set it up like this because
104 * this is only used for AR5212 and we know it supports G mode
105 */
Jiri Slaby2c91108c2009-03-07 10:26:41 +0100106static const unsigned int control_rates[] =
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300107 { 0, 1, 1, 1, 4, 4, 6, 6, 8, 8, 8, 8 };
108
109/**
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200110 * ath5k_hw_write_rate_duration - fill rate code to duration table
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300111 *
112 * @ah: the &struct ath5k_hw
113 * @mode: one of enum ath5k_driver_mode
114 *
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200115 * Write the rate code to duration table upon hw reset. This is a helper for
116 * ath5k_hw_reset(). It seems all this is doing is setting an ACK timeout on
117 * the hardware, based on current mode, for each rate. The rates which are
118 * capable of short preamble (802.11b rates 2Mbps, 5.5Mbps, and 11Mbps) have
119 * different rate code so we write their value twice (one for long preample
120 * and one for short).
121 *
122 * Note: Band doesn't matter here, if we set the values for OFDM it works
123 * on both a and g modes. So all we have to do is set values for all g rates
124 * that include all OFDM and CCK rates. If we operate in turbo or xr/half/
125 * quarter rate mode, we need to use another set of bitrates (that's why we
126 * need the mode parameter) but we don't handle these proprietary modes yet.
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300127 */
128static inline void ath5k_hw_write_rate_duration(struct ath5k_hw *ah,
129 unsigned int mode)
130{
131 struct ath5k_softc *sc = ah->ah_sc;
132 struct ieee80211_rate *rate;
133 unsigned int i;
134
135 /* Write rate duration table */
136 for (i = 0; i < sc->sbands[IEEE80211_BAND_2GHZ].n_bitrates; i++) {
137 u32 reg;
138 u16 tx_time;
139
140 rate = &sc->sbands[IEEE80211_BAND_2GHZ].bitrates[control_rates[i]];
141
142 /* Set ACK timeout */
143 reg = AR5K_RATE_DUR(rate->hw_value);
144
145 /* An ACK frame consists of 10 bytes. If you add the FCS,
146 * which ieee80211_generic_frame_duration() adds,
147 * its 14 bytes. Note we use the control rate and not the
148 * actual rate for this rate. See mac80211 tx.c
149 * ieee80211_duration() for a brief description of
150 * what rate we should choose to TX ACKs. */
151 tx_time = le16_to_cpu(ieee80211_generic_frame_duration(sc->hw,
152 sc->vif, 10, rate));
153
154 ath5k_hw_reg_write(ah, tx_time, reg);
155
156 if (!(rate->flags & IEEE80211_RATE_SHORT_PREAMBLE))
157 continue;
158
159 /*
160 * We're not distinguishing short preamble here,
161 * This is true, all we'll get is a longer value here
162 * which is not necessarilly bad. We could use
163 * export ieee80211_frame_duration() but that needs to be
164 * fixed first to be properly used by mac802111 drivers:
165 *
166 * - remove erp stuff and let the routine figure ofdm
167 * erp rates
168 * - remove passing argument ieee80211_local as
169 * drivers don't have access to it
170 * - move drivers using ieee80211_generic_frame_duration()
171 * to this
172 */
173 ath5k_hw_reg_write(ah, tx_time,
174 reg + (AR5K_SET_SHORT_PREAMBLE << 2));
175 }
176}
177
178/*
179 * Reset chipset
180 */
181static int ath5k_hw_nic_reset(struct ath5k_hw *ah, u32 val)
182{
183 int ret;
184 u32 mask = val ? val : ~0U;
185
186 ATH5K_TRACE(ah->ah_sc);
187
188 /* Read-and-clear RX Descriptor Pointer*/
189 ath5k_hw_reg_read(ah, AR5K_RXDP);
190
191 /*
192 * Reset the device and wait until success
193 */
194 ath5k_hw_reg_write(ah, val, AR5K_RESET_CTL);
195
196 /* Wait at least 128 PCI clocks */
197 udelay(15);
198
199 if (ah->ah_version == AR5K_AR5210) {
Nick Kossifidis84e463f2008-09-17 03:33:19 +0300200 val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_DMA
201 | AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_PHY;
202 mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_DMA
203 | AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_PHY;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300204 } else {
205 val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
206 mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
207 }
208
209 ret = ath5k_hw_register_timeout(ah, AR5K_RESET_CTL, mask, val, false);
210
211 /*
212 * Reset configuration register (for hw byte-swap). Note that this
213 * is only set for big endian. We do the necessary magic in
214 * AR5K_INIT_CFG.
215 */
216 if ((val & AR5K_RESET_CTL_PCU) == 0)
217 ath5k_hw_reg_write(ah, AR5K_INIT_CFG, AR5K_CFG);
218
219 return ret;
220}
221
222/*
223 * Sleep control
224 */
225int ath5k_hw_set_power(struct ath5k_hw *ah, enum ath5k_power_mode mode,
226 bool set_chip, u16 sleep_duration)
227{
228 unsigned int i;
229 u32 staid, data;
230
231 ATH5K_TRACE(ah->ah_sc);
232 staid = ath5k_hw_reg_read(ah, AR5K_STA_ID1);
233
234 switch (mode) {
235 case AR5K_PM_AUTO:
236 staid &= ~AR5K_STA_ID1_DEFAULT_ANTENNA;
237 /* fallthrough */
238 case AR5K_PM_NETWORK_SLEEP:
239 if (set_chip)
240 ath5k_hw_reg_write(ah,
241 AR5K_SLEEP_CTL_SLE_ALLOW |
242 sleep_duration,
243 AR5K_SLEEP_CTL);
244
245 staid |= AR5K_STA_ID1_PWR_SV;
246 break;
247
248 case AR5K_PM_FULL_SLEEP:
249 if (set_chip)
250 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_SLP,
251 AR5K_SLEEP_CTL);
252
253 staid |= AR5K_STA_ID1_PWR_SV;
254 break;
255
256 case AR5K_PM_AWAKE:
257
258 staid &= ~AR5K_STA_ID1_PWR_SV;
259
260 if (!set_chip)
261 goto commit;
262
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300263 data = ath5k_hw_reg_read(ah, AR5K_SLEEP_CTL);
Nick Kossifidisedd7fc72009-08-10 03:29:02 +0300264
265 /* If card is down we 'll get 0xffff... so we
266 * need to clean this up before we write the register
267 */
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300268 if (data & 0xffc00000)
269 data = 0;
270 else
Nick Kossifidisedd7fc72009-08-10 03:29:02 +0300271 /* Preserve sleep duration etc */
272 data = data & ~AR5K_SLEEP_CTL_SLE;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300273
Nick Kossifidisedd7fc72009-08-10 03:29:02 +0300274 ath5k_hw_reg_write(ah, data | AR5K_SLEEP_CTL_SLE_WAKE,
275 AR5K_SLEEP_CTL);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300276 udelay(15);
277
Nick Kossifidisedd7fc72009-08-10 03:29:02 +0300278 for (i = 200; i > 0; i--) {
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300279 /* Check if the chip did wake up */
280 if ((ath5k_hw_reg_read(ah, AR5K_PCICFG) &
281 AR5K_PCICFG_SPWR_DN) == 0)
282 break;
283
284 /* Wait a bit and retry */
Nick Kossifidisedd7fc72009-08-10 03:29:02 +0300285 udelay(50);
286 ath5k_hw_reg_write(ah, data | AR5K_SLEEP_CTL_SLE_WAKE,
287 AR5K_SLEEP_CTL);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300288 }
289
290 /* Fail if the chip didn't wake up */
Nick Kossifidisedd7fc72009-08-10 03:29:02 +0300291 if (i == 0)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300292 return -EIO;
293
294 break;
295
296 default:
297 return -EINVAL;
298 }
299
300commit:
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300301 ath5k_hw_reg_write(ah, staid, AR5K_STA_ID1);
302
303 return 0;
304}
305
306/*
Nick Kossifidisedd7fc72009-08-10 03:29:02 +0300307 * Put device on hold
308 *
309 * Put MAC and Baseband on warm reset and
310 * keep that state (don't clean sleep control
311 * register). After this MAC and Baseband are
312 * disabled and a full reset is needed to come
313 * back. This way we save as much power as possible
314 * without puting the card on full sleep.
315 */
316int ath5k_hw_on_hold(struct ath5k_hw *ah)
317{
318 struct pci_dev *pdev = ah->ah_sc->pdev;
319 u32 bus_flags;
320 int ret;
321
322 /* Make sure device is awake */
323 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
324 if (ret) {
325 ATH5K_ERR(ah->ah_sc, "failed to wakeup the MAC Chip\n");
326 return ret;
327 }
328
329 /*
330 * Put chipset on warm reset...
331 *
332 * Note: puting PCI core on warm reset on PCI-E cards
333 * results card to hang and always return 0xffff... so
334 * we ingore that flag for PCI-E cards. On PCI cards
335 * this flag gets cleared after 64 PCI clocks.
336 */
337 bus_flags = (pdev->is_pcie) ? 0 : AR5K_RESET_CTL_PCI;
338
339 if (ah->ah_version == AR5K_AR5210) {
340 ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
341 AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_DMA |
342 AR5K_RESET_CTL_PHY | AR5K_RESET_CTL_PCI);
343 mdelay(2);
344 } else {
345 ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
346 AR5K_RESET_CTL_BASEBAND | bus_flags);
347 }
348
349 if (ret) {
350 ATH5K_ERR(ah->ah_sc, "failed to put device on warm reset\n");
351 return -EIO;
352 }
353
354 /* ...wakeup again!*/
355 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
356 if (ret) {
357 ATH5K_ERR(ah->ah_sc, "failed to put device on hold\n");
358 return ret;
359 }
360
361 return ret;
362}
363
364/*
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200365 * Bring up MAC + PHY Chips and program PLL
366 * TODO: Half/Quarter rate support
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300367 */
368int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
369{
370 struct pci_dev *pdev = ah->ah_sc->pdev;
371 u32 turbo, mode, clock, bus_flags;
372 int ret;
373
374 turbo = 0;
375 mode = 0;
376 clock = 0;
377
378 ATH5K_TRACE(ah->ah_sc);
379
380 /* Wakeup the device */
381 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
382 if (ret) {
383 ATH5K_ERR(ah->ah_sc, "failed to wakeup the MAC Chip\n");
384 return ret;
385 }
386
Nick Kossifidisedd7fc72009-08-10 03:29:02 +0300387 /*
388 * Put chipset on warm reset...
389 *
390 * Note: puting PCI core on warm reset on PCI-E cards
391 * results card to hang and always return 0xffff... so
392 * we ingore that flag for PCI-E cards. On PCI cards
393 * this flag gets cleared after 64 PCI clocks.
394 */
395 bus_flags = (pdev->is_pcie) ? 0 : AR5K_RESET_CTL_PCI;
396
397 if (ah->ah_version == AR5K_AR5210) {
398 ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
399 AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_DMA |
400 AR5K_RESET_CTL_PHY | AR5K_RESET_CTL_PCI);
401 mdelay(2);
402 } else {
403 ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
404 AR5K_RESET_CTL_BASEBAND | bus_flags);
405 }
406
407 if (ret) {
408 ATH5K_ERR(ah->ah_sc, "failed to reset the MAC Chip\n");
409 return -EIO;
410 }
411
412 /* ...wakeup again!...*/
413 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
414 if (ret) {
415 ATH5K_ERR(ah->ah_sc, "failed to resume the MAC Chip\n");
416 return ret;
417 }
418
419 /* ...clear reset control register and pull device out of
420 * warm reset */
421 if (ath5k_hw_nic_reset(ah, 0)) {
422 ATH5K_ERR(ah->ah_sc, "failed to warm reset the MAC Chip\n");
423 return -EIO;
424 }
425
426 /* On initialization skip PLL programming since we don't have
427 * a channel / mode set yet */
428 if (initial)
429 return 0;
430
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300431 if (ah->ah_version != AR5K_AR5210) {
432 /*
433 * Get channel mode flags
434 */
435
436 if (ah->ah_radio >= AR5K_RF5112) {
437 mode = AR5K_PHY_MODE_RAD_RF5112;
438 clock = AR5K_PHY_PLL_RF5112;
439 } else {
440 mode = AR5K_PHY_MODE_RAD_RF5111; /*Zero*/
441 clock = AR5K_PHY_PLL_RF5111; /*Zero*/
442 }
443
444 if (flags & CHANNEL_2GHZ) {
445 mode |= AR5K_PHY_MODE_FREQ_2GHZ;
446 clock |= AR5K_PHY_PLL_44MHZ;
447
448 if (flags & CHANNEL_CCK) {
449 mode |= AR5K_PHY_MODE_MOD_CCK;
450 } else if (flags & CHANNEL_OFDM) {
451 /* XXX Dynamic OFDM/CCK is not supported by the
452 * AR5211 so we set MOD_OFDM for plain g (no
453 * CCK headers) operation. We need to test
454 * this, 5211 might support ofdm-only g after
455 * all, there are also initial register values
456 * in the code for g mode (see initvals.c). */
457 if (ah->ah_version == AR5K_AR5211)
458 mode |= AR5K_PHY_MODE_MOD_OFDM;
459 else
460 mode |= AR5K_PHY_MODE_MOD_DYN;
461 } else {
462 ATH5K_ERR(ah->ah_sc,
463 "invalid radio modulation mode\n");
464 return -EINVAL;
465 }
466 } else if (flags & CHANNEL_5GHZ) {
467 mode |= AR5K_PHY_MODE_FREQ_5GHZ;
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200468
469 if (ah->ah_radio == AR5K_RF5413)
Pavel Roskin807e3732009-03-27 17:47:27 -0400470 clock = AR5K_PHY_PLL_40MHZ_5413;
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200471 else
472 clock |= AR5K_PHY_PLL_40MHZ;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300473
474 if (flags & CHANNEL_OFDM)
475 mode |= AR5K_PHY_MODE_MOD_OFDM;
476 else {
477 ATH5K_ERR(ah->ah_sc,
478 "invalid radio modulation mode\n");
479 return -EINVAL;
480 }
481 } else {
482 ATH5K_ERR(ah->ah_sc, "invalid radio frequency mode\n");
483 return -EINVAL;
484 }
485
486 if (flags & CHANNEL_TURBO)
487 turbo = AR5K_PHY_TURBO_MODE | AR5K_PHY_TURBO_SHORT;
488 } else { /* Reset the device */
489
490 /* ...enable Atheros turbo mode if requested */
491 if (flags & CHANNEL_TURBO)
492 ath5k_hw_reg_write(ah, AR5K_PHY_TURBO_MODE,
493 AR5K_PHY_TURBO);
494 }
495
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300496 if (ah->ah_version != AR5K_AR5210) {
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300497
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200498 /* ...update PLL if needed */
499 if (ath5k_hw_reg_read(ah, AR5K_PHY_PLL) != clock) {
500 ath5k_hw_reg_write(ah, clock, AR5K_PHY_PLL);
501 udelay(300);
502 }
503
504 /* ...set the PHY operating mode */
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300505 ath5k_hw_reg_write(ah, mode, AR5K_PHY_MODE);
506 ath5k_hw_reg_write(ah, turbo, AR5K_PHY_TURBO);
507 }
508
509 return 0;
510}
511
512/*
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200513 * If there is an external 32KHz crystal available, use it
514 * as ref. clock instead of 32/40MHz clock and baseband clocks
515 * to save power during sleep or restore normal 32/40MHz
516 * operation.
517 *
518 * XXX: When operating on 32KHz certain PHY registers (27 - 31,
519 * 123 - 127) require delay on access.
520 */
521static void ath5k_hw_set_sleep_clock(struct ath5k_hw *ah, bool enable)
522{
523 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
524 u32 scal, spending, usec32;
525
526 /* Only set 32KHz settings if we have an external
527 * 32KHz crystal present */
528 if ((AR5K_EEPROM_HAS32KHZCRYSTAL(ee->ee_misc1) ||
529 AR5K_EEPROM_HAS32KHZCRYSTAL_OLD(ee->ee_misc1)) &&
530 enable) {
531
532 /* 1 usec/cycle */
533 AR5K_REG_WRITE_BITS(ah, AR5K_USEC_5211, AR5K_USEC_32, 1);
534 /* Set up tsf increment on each cycle */
535 AR5K_REG_WRITE_BITS(ah, AR5K_TSF_PARM, AR5K_TSF_PARM_INC, 61);
536
537 /* Set baseband sleep control registers
538 * and sleep control rate */
539 ath5k_hw_reg_write(ah, 0x1f, AR5K_PHY_SCR);
540
541 if ((ah->ah_radio == AR5K_RF5112) ||
542 (ah->ah_radio == AR5K_RF5413) ||
543 (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4)))
544 spending = 0x14;
545 else
546 spending = 0x18;
547 ath5k_hw_reg_write(ah, spending, AR5K_PHY_SPENDING);
548
549 if ((ah->ah_radio == AR5K_RF5112) ||
550 (ah->ah_radio == AR5K_RF5413) ||
551 (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))) {
552 ath5k_hw_reg_write(ah, 0x26, AR5K_PHY_SLMT);
553 ath5k_hw_reg_write(ah, 0x0d, AR5K_PHY_SCAL);
554 ath5k_hw_reg_write(ah, 0x07, AR5K_PHY_SCLOCK);
555 ath5k_hw_reg_write(ah, 0x3f, AR5K_PHY_SDELAY);
556 AR5K_REG_WRITE_BITS(ah, AR5K_PCICFG,
557 AR5K_PCICFG_SLEEP_CLOCK_RATE, 0x02);
558 } else {
559 ath5k_hw_reg_write(ah, 0x0a, AR5K_PHY_SLMT);
560 ath5k_hw_reg_write(ah, 0x0c, AR5K_PHY_SCAL);
561 ath5k_hw_reg_write(ah, 0x03, AR5K_PHY_SCLOCK);
562 ath5k_hw_reg_write(ah, 0x20, AR5K_PHY_SDELAY);
563 AR5K_REG_WRITE_BITS(ah, AR5K_PCICFG,
564 AR5K_PCICFG_SLEEP_CLOCK_RATE, 0x03);
565 }
566
567 /* Enable sleep clock operation */
568 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG,
569 AR5K_PCICFG_SLEEP_CLOCK_EN);
570
571 } else {
572
573 /* Disable sleep clock operation and
574 * restore default parameters */
575 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG,
576 AR5K_PCICFG_SLEEP_CLOCK_EN);
577
578 AR5K_REG_WRITE_BITS(ah, AR5K_PCICFG,
579 AR5K_PCICFG_SLEEP_CLOCK_RATE, 0);
580
581 ath5k_hw_reg_write(ah, 0x1f, AR5K_PHY_SCR);
582 ath5k_hw_reg_write(ah, AR5K_PHY_SLMT_32MHZ, AR5K_PHY_SLMT);
583
584 if (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))
585 scal = AR5K_PHY_SCAL_32MHZ_2417;
Nick Kossifidis1889ba02009-04-30 15:55:46 -0400586 else if (ee->ee_is_hb63)
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200587 scal = AR5K_PHY_SCAL_32MHZ_HB63;
588 else
589 scal = AR5K_PHY_SCAL_32MHZ;
590 ath5k_hw_reg_write(ah, scal, AR5K_PHY_SCAL);
591
592 ath5k_hw_reg_write(ah, AR5K_PHY_SCLOCK_32MHZ, AR5K_PHY_SCLOCK);
593 ath5k_hw_reg_write(ah, AR5K_PHY_SDELAY_32MHZ, AR5K_PHY_SDELAY);
594
595 if ((ah->ah_radio == AR5K_RF5112) ||
596 (ah->ah_radio == AR5K_RF5413) ||
597 (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4)))
598 spending = 0x14;
599 else
600 spending = 0x18;
601 ath5k_hw_reg_write(ah, spending, AR5K_PHY_SPENDING);
602
603 if ((ah->ah_radio == AR5K_RF5112) ||
604 (ah->ah_radio == AR5K_RF5413))
605 usec32 = 39;
606 else
607 usec32 = 31;
608 AR5K_REG_WRITE_BITS(ah, AR5K_USEC_5211, AR5K_USEC_32, usec32);
609
610 AR5K_REG_WRITE_BITS(ah, AR5K_TSF_PARM, AR5K_TSF_PARM_INC, 1);
611 }
612 return;
613}
614
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200615/* TODO: Half/Quarter rate */
616static void ath5k_hw_tweak_initval_settings(struct ath5k_hw *ah,
617 struct ieee80211_channel *channel)
618{
619 if (ah->ah_version == AR5K_AR5212 &&
620 ah->ah_phy_revision >= AR5K_SREV_PHY_5212A) {
621
622 /* Setup ADC control */
623 ath5k_hw_reg_write(ah,
624 (AR5K_REG_SM(2,
625 AR5K_PHY_ADC_CTL_INBUFGAIN_OFF) |
626 AR5K_REG_SM(2,
627 AR5K_PHY_ADC_CTL_INBUFGAIN_ON) |
628 AR5K_PHY_ADC_CTL_PWD_DAC_OFF |
629 AR5K_PHY_ADC_CTL_PWD_ADC_OFF),
630 AR5K_PHY_ADC_CTL);
631
632
633
634 /* Disable barker RSSI threshold */
635 AR5K_REG_DISABLE_BITS(ah, AR5K_PHY_DAG_CCK_CTL,
636 AR5K_PHY_DAG_CCK_CTL_EN_RSSI_THR);
637
638 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DAG_CCK_CTL,
639 AR5K_PHY_DAG_CCK_CTL_RSSI_THR, 2);
640
641 /* Set the mute mask */
642 ath5k_hw_reg_write(ah, 0x0000000f, AR5K_SEQ_MASK);
643 }
644
645 /* Clear PHY_BLUETOOTH to allow RX_CLEAR line debug */
646 if (ah->ah_phy_revision >= AR5K_SREV_PHY_5212B)
647 ath5k_hw_reg_write(ah, 0, AR5K_PHY_BLUETOOTH);
648
649 /* Enable DCU double buffering */
650 if (ah->ah_phy_revision > AR5K_SREV_PHY_5212B)
651 AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
652 AR5K_TXCFG_DCU_DBL_BUF_DIS);
653
654 /* Set DAC/ADC delays */
655 if (ah->ah_version == AR5K_AR5212) {
656 u32 scal;
Nick Kossifidis1889ba02009-04-30 15:55:46 -0400657 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200658 if (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))
659 scal = AR5K_PHY_SCAL_32MHZ_2417;
Nick Kossifidis1889ba02009-04-30 15:55:46 -0400660 else if (ee->ee_is_hb63)
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200661 scal = AR5K_PHY_SCAL_32MHZ_HB63;
662 else
663 scal = AR5K_PHY_SCAL_32MHZ;
664 ath5k_hw_reg_write(ah, scal, AR5K_PHY_SCAL);
665 }
666
667 /* Set fast ADC */
668 if ((ah->ah_radio == AR5K_RF5413) ||
669 (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))) {
670 u32 fast_adc = true;
671
672 if (channel->center_freq == 2462 ||
673 channel->center_freq == 2467)
674 fast_adc = 0;
675
676 /* Only update if needed */
677 if (ath5k_hw_reg_read(ah, AR5K_PHY_FAST_ADC) != fast_adc)
678 ath5k_hw_reg_write(ah, fast_adc,
679 AR5K_PHY_FAST_ADC);
680 }
681
682 /* Fix for first revision of the RF5112 RF chipset */
683 if (ah->ah_radio == AR5K_RF5112 &&
684 ah->ah_radio_5ghz_revision <
685 AR5K_SREV_RAD_5112A) {
686 u32 data;
687 ath5k_hw_reg_write(ah, AR5K_PHY_CCKTXCTL_WORLD,
688 AR5K_PHY_CCKTXCTL);
689 if (channel->hw_value & CHANNEL_5GHZ)
690 data = 0xffb81020;
691 else
692 data = 0xffb80d20;
693 ath5k_hw_reg_write(ah, data, AR5K_PHY_FRAME_CTL);
694 }
695
696 if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
697 u32 usec_reg;
698 /* 5311 has different tx/rx latency masks
699 * from 5211, since we deal 5311 the same
700 * as 5211 when setting initvals, shift
701 * values here to their proper locations */
702 usec_reg = ath5k_hw_reg_read(ah, AR5K_USEC_5211);
703 ath5k_hw_reg_write(ah, usec_reg & (AR5K_USEC_1 |
704 AR5K_USEC_32 |
705 AR5K_USEC_TX_LATENCY_5211 |
706 AR5K_REG_SM(29,
707 AR5K_USEC_RX_LATENCY_5210)),
708 AR5K_USEC_5211);
709 /* Clear QCU/DCU clock gating register */
710 ath5k_hw_reg_write(ah, 0, AR5K_QCUDCU_CLKGT);
711 /* Set DAC/ADC delays */
712 ath5k_hw_reg_write(ah, 0x08, AR5K_PHY_SCAL);
713 /* Enable PCU FIFO corruption ECO */
714 AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW_5211,
715 AR5K_DIAG_SW_ECO_ENABLE);
716 }
717}
718
719static void ath5k_hw_commit_eeprom_settings(struct ath5k_hw *ah,
720 struct ieee80211_channel *channel, u8 *ant, u8 ee_mode)
721{
722 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
Nick Kossifidis8f655dd2009-03-15 22:20:35 +0200723 s16 cck_ofdm_pwr_delta;
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200724
Nick Kossifidis8f655dd2009-03-15 22:20:35 +0200725 /* Adjust power delta for channel 14 */
726 if (channel->center_freq == 2484)
727 cck_ofdm_pwr_delta =
728 ((ee->ee_cck_ofdm_power_delta -
729 ee->ee_scaled_cck_delta) * 2) / 10;
730 else
731 cck_ofdm_pwr_delta =
732 (ee->ee_cck_ofdm_power_delta * 2) / 10;
733
734 /* Set CCK to OFDM power delta on tx power
735 * adjustment register */
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200736 if (ah->ah_phy_revision >= AR5K_SREV_PHY_5212A) {
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200737 if (channel->hw_value == CHANNEL_G)
738 ath5k_hw_reg_write(ah,
Nick Kossifidis8f655dd2009-03-15 22:20:35 +0200739 AR5K_REG_SM((ee->ee_cck_ofdm_gain_delta * -1),
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200740 AR5K_PHY_TX_PWR_ADJ_CCK_GAIN_DELTA) |
741 AR5K_REG_SM((cck_ofdm_pwr_delta * -1),
742 AR5K_PHY_TX_PWR_ADJ_CCK_PCDAC_INDEX),
743 AR5K_PHY_TX_PWR_ADJ);
744 else
745 ath5k_hw_reg_write(ah, 0, AR5K_PHY_TX_PWR_ADJ);
Nick Kossifidis8f655dd2009-03-15 22:20:35 +0200746 } else {
747 /* For older revs we scale power on sw during tx power
748 * setup */
749 ah->ah_txpower.txp_cck_ofdm_pwr_delta = cck_ofdm_pwr_delta;
750 ah->ah_txpower.txp_cck_ofdm_gainf_delta =
751 ee->ee_cck_ofdm_gain_delta;
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200752 }
753
754 /* Set antenna idle switch table */
755 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_ANT_CTL,
756 AR5K_PHY_ANT_CTL_SWTABLE_IDLE,
Nick Kossifidis2bed03e2009-04-30 15:55:49 -0400757 (ah->ah_ant_ctl[ee_mode][0] |
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200758 AR5K_PHY_ANT_CTL_TXRX_EN));
759
Nick Kossifidis2bed03e2009-04-30 15:55:49 -0400760 /* Set antenna switch tables */
761 ath5k_hw_reg_write(ah, ah->ah_ant_ctl[ee_mode][ant[0]],
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200762 AR5K_PHY_ANT_SWITCH_TABLE_0);
Nick Kossifidis2bed03e2009-04-30 15:55:49 -0400763 ath5k_hw_reg_write(ah, ah->ah_ant_ctl[ee_mode][ant[1]],
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200764 AR5K_PHY_ANT_SWITCH_TABLE_1);
765
766 /* Noise floor threshold */
767 ath5k_hw_reg_write(ah,
768 AR5K_PHY_NF_SVAL(ee->ee_noise_floor_thr[ee_mode]),
769 AR5K_PHY_NFTHRES);
770
771 if ((channel->hw_value & CHANNEL_TURBO) &&
772 (ah->ah_ee_version >= AR5K_EEPROM_VERSION_5_0)) {
773 /* Switch settling time (Turbo) */
774 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_SETTLING,
775 AR5K_PHY_SETTLING_SWITCH,
776 ee->ee_switch_settling_turbo[ee_mode]);
777
778 /* Tx/Rx attenuation (Turbo) */
779 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN,
780 AR5K_PHY_GAIN_TXRX_ATTEN,
781 ee->ee_atn_tx_rx_turbo[ee_mode]);
782
783 /* ADC/PGA desired size (Turbo) */
784 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
785 AR5K_PHY_DESIRED_SIZE_ADC,
786 ee->ee_adc_desired_size_turbo[ee_mode]);
787
788 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
789 AR5K_PHY_DESIRED_SIZE_PGA,
790 ee->ee_pga_desired_size_turbo[ee_mode]);
791
792 /* Tx/Rx margin (Turbo) */
793 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
794 AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
795 ee->ee_margin_tx_rx_turbo[ee_mode]);
796
797 } else {
798 /* Switch settling time */
799 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_SETTLING,
800 AR5K_PHY_SETTLING_SWITCH,
801 ee->ee_switch_settling[ee_mode]);
802
803 /* Tx/Rx attenuation */
804 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN,
805 AR5K_PHY_GAIN_TXRX_ATTEN,
806 ee->ee_atn_tx_rx[ee_mode]);
807
808 /* ADC/PGA desired size */
809 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
810 AR5K_PHY_DESIRED_SIZE_ADC,
811 ee->ee_adc_desired_size[ee_mode]);
812
813 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
814 AR5K_PHY_DESIRED_SIZE_PGA,
815 ee->ee_pga_desired_size[ee_mode]);
816
817 /* Tx/Rx margin */
818 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
819 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
820 AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
821 ee->ee_margin_tx_rx[ee_mode]);
822 }
823
824 /* XPA delays */
825 ath5k_hw_reg_write(ah,
826 (ee->ee_tx_end2xpa_disable[ee_mode] << 24) |
827 (ee->ee_tx_end2xpa_disable[ee_mode] << 16) |
828 (ee->ee_tx_frm2xpa_enable[ee_mode] << 8) |
829 (ee->ee_tx_frm2xpa_enable[ee_mode]), AR5K_PHY_RF_CTL4);
830
831 /* XLNA delay */
832 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_RF_CTL3,
833 AR5K_PHY_RF_CTL3_TXE2XLNA_ON,
834 ee->ee_tx_end2xlna_enable[ee_mode]);
835
836 /* Thresh64 (ANI) */
837 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_NF,
838 AR5K_PHY_NF_THRESH62,
839 ee->ee_thr_62[ee_mode]);
840
841
842 /* False detect backoff for channels
843 * that have spur noise. Write the new
844 * cyclic power RSSI threshold. */
845 if (ath5k_hw_chan_has_spur_noise(ah, channel))
846 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_OFDM_SELFCORR,
847 AR5K_PHY_OFDM_SELFCORR_CYPWR_THR1,
848 AR5K_INIT_CYCRSSI_THR1 +
849 ee->ee_false_detect[ee_mode]);
850 else
851 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_OFDM_SELFCORR,
852 AR5K_PHY_OFDM_SELFCORR_CYPWR_THR1,
853 AR5K_INIT_CYCRSSI_THR1);
854
855 /* I/Q correction
856 * TODO: Per channel i/q infos ? */
857 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
858 AR5K_PHY_IQ_CORR_ENABLE |
859 (ee->ee_i_cal[ee_mode] << AR5K_PHY_IQ_CORR_Q_I_COFF_S) |
860 ee->ee_q_cal[ee_mode]);
861
862 /* Heavy clipping -disable for now */
863 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_5_1)
864 ath5k_hw_reg_write(ah, 0, AR5K_PHY_HEAVY_CLIP_ENABLE);
865
866 return;
867}
868
869/*
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300870 * Main reset function
871 */
Johannes Berg05c914f2008-09-11 00:01:58 +0200872int ath5k_hw_reset(struct ath5k_hw *ah, enum nl80211_iftype op_mode,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300873 struct ieee80211_channel *channel, bool change_channel)
874{
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200875 u32 s_seq[10], s_ant, s_led[3], staid1_flags, tsf_up, tsf_lo;
876 u32 phy_tst1;
877 u8 mode, freq, ee_mode, ant[2];
878 int i, ret;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300879
880 ATH5K_TRACE(ah->ah_sc);
881
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300882 s_ant = 0;
883 ee_mode = 0;
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200884 staid1_flags = 0;
885 tsf_up = 0;
886 tsf_lo = 0;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300887 freq = 0;
888 mode = 0;
889
890 /*
891 * Save some registers before a reset
892 */
893 /*DCU/Antenna selection not available on 5210*/
894 if (ah->ah_version != AR5K_AR5210) {
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300895
896 switch (channel->hw_value & CHANNEL_MODES) {
897 case CHANNEL_A:
898 mode = AR5K_MODE_11A;
899 freq = AR5K_INI_RFGAIN_5GHZ;
900 ee_mode = AR5K_EEPROM_MODE_11A;
901 break;
902 case CHANNEL_G:
903 mode = AR5K_MODE_11G;
904 freq = AR5K_INI_RFGAIN_2GHZ;
905 ee_mode = AR5K_EEPROM_MODE_11G;
906 break;
907 case CHANNEL_B:
908 mode = AR5K_MODE_11B;
909 freq = AR5K_INI_RFGAIN_2GHZ;
910 ee_mode = AR5K_EEPROM_MODE_11B;
911 break;
912 case CHANNEL_T:
913 mode = AR5K_MODE_11A_TURBO;
914 freq = AR5K_INI_RFGAIN_5GHZ;
915 ee_mode = AR5K_EEPROM_MODE_11A;
916 break;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300917 case CHANNEL_TG:
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200918 if (ah->ah_version == AR5K_AR5211) {
919 ATH5K_ERR(ah->ah_sc,
920 "TurboG mode not available on 5211");
921 return -EINVAL;
922 }
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300923 mode = AR5K_MODE_11G_TURBO;
924 freq = AR5K_INI_RFGAIN_2GHZ;
925 ee_mode = AR5K_EEPROM_MODE_11G;
926 break;
927 case CHANNEL_XR:
928 if (ah->ah_version == AR5K_AR5211) {
929 ATH5K_ERR(ah->ah_sc,
930 "XR mode not available on 5211");
931 return -EINVAL;
932 }
933 mode = AR5K_MODE_XR;
934 freq = AR5K_INI_RFGAIN_5GHZ;
935 ee_mode = AR5K_EEPROM_MODE_11A;
936 break;
937 default:
938 ATH5K_ERR(ah->ah_sc,
939 "invalid channel: %d\n", channel->center_freq);
940 return -EINVAL;
941 }
942
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200943 if (change_channel) {
944 /*
945 * Save frame sequence count
946 * For revs. after Oahu, only save
947 * seq num for DCU 0 (Global seq num)
948 */
949 if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
950
951 for (i = 0; i < 10; i++)
952 s_seq[i] = ath5k_hw_reg_read(ah,
953 AR5K_QUEUE_DCU_SEQNUM(i));
954
955 } else {
956 s_seq[0] = ath5k_hw_reg_read(ah,
957 AR5K_QUEUE_DCU_SEQNUM(0));
958 }
959
960 /* TSF accelerates on AR5211 durring reset
961 * As a workaround save it here and restore
962 * it later so that it's back in time after
963 * reset. This way it'll get re-synced on the
964 * next beacon without breaking ad-hoc.
965 *
966 * On AR5212 TSF is almost preserved across a
967 * reset so it stays back in time anyway and
968 * we don't have to save/restore it.
969 *
970 * XXX: Since this breaks power saving we have
971 * to disable power saving until we receive the
972 * next beacon, so we can resync beacon timers */
973 if (ah->ah_version == AR5K_AR5211) {
974 tsf_up = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
975 tsf_lo = ath5k_hw_reg_read(ah, AR5K_TSF_L32);
976 }
977 }
978
979 /* Save default antenna */
980 s_ant = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
981
982 if (ah->ah_version == AR5K_AR5212) {
983 /* Restore normal 32/40MHz clock operation
984 * to avoid register access delay on certain
985 * PHY registers */
986 ath5k_hw_set_sleep_clock(ah, false);
987
988 /* Since we are going to write rf buffer
989 * check if we have any pending gain_F
990 * optimization settings */
991 if (change_channel && ah->ah_rf_banks != NULL)
992 ath5k_hw_gainf_calibrate(ah);
993 }
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300994 }
995
Nick Kossifidise8f055f2009-02-09 06:12:58 +0200996 /*GPIOs*/
997 s_led[0] = ath5k_hw_reg_read(ah, AR5K_PCICFG) &
998 AR5K_PCICFG_LEDSTATE;
999 s_led[1] = ath5k_hw_reg_read(ah, AR5K_GPIOCR);
1000 s_led[2] = ath5k_hw_reg_read(ah, AR5K_GPIODO);
Nick Kossifidisa406c132009-02-09 06:08:51 +02001001
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001002 /* AR5K_STA_ID1 flags, only preserve antenna
1003 * settings and ack/cts rate mode */
1004 staid1_flags = ath5k_hw_reg_read(ah, AR5K_STA_ID1) &
1005 (AR5K_STA_ID1_DEFAULT_ANTENNA |
1006 AR5K_STA_ID1_DESC_ANTENNA |
1007 AR5K_STA_ID1_RTS_DEF_ANTENNA |
1008 AR5K_STA_ID1_ACKCTS_6MB |
1009 AR5K_STA_ID1_BASE_RATE_11B |
1010 AR5K_STA_ID1_SELFGEN_DEF_ANT);
1011
1012 /* Wakeup the device */
1013 ret = ath5k_hw_nic_wakeup(ah, channel->hw_value, false);
1014 if (ret)
1015 return ret;
1016
1017 /*
1018 * Initialize operating mode
1019 */
1020 ah->ah_op_mode = op_mode;
1021
1022 /* PHY access enable */
1023 if (ah->ah_mac_srev >= AR5K_SREV_AR5211)
1024 ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
1025 else
1026 ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ | 0x40,
1027 AR5K_PHY(0));
1028
1029 /* Write initial settings */
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001030 ret = ath5k_hw_write_initvals(ah, mode, change_channel);
1031 if (ret)
1032 return ret;
1033
1034 /*
1035 * 5211/5212 Specific
1036 */
1037 if (ah->ah_version != AR5K_AR5210) {
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001038
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001039 /*
1040 * Write initial RF gain settings
1041 * This should work for both 5111/5112
1042 */
Nick Kossifidis6f3b4142009-02-09 06:03:41 +02001043 ret = ath5k_hw_rfgain_init(ah, freq);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001044 if (ret)
1045 return ret;
1046
1047 mdelay(1);
1048
1049 /*
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001050 * Tweak initval settings for revised
1051 * chipsets and add some more config
1052 * bits
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001053 */
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001054 ath5k_hw_tweak_initval_settings(ah, channel);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001055
1056 /*
Nick Kossifidis57e6c562009-04-30 15:55:50 -04001057 * Set TX power
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001058 */
Nick Kossifidis8f655dd2009-03-15 22:20:35 +02001059 ret = ath5k_hw_txpower(ah, channel, ee_mode,
Nick Kossifidisa0823812009-04-30 15:55:44 -04001060 ah->ah_txpower.txp_max_pwr / 2);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001061 if (ret)
1062 return ret;
1063
1064 /* Write rate duration table only on AR5212 and if
1065 * virtual interface has already been brought up
1066 * XXX: rethink this after new mode changes to
1067 * mac80211 are integrated */
1068 if (ah->ah_version == AR5K_AR5212 &&
1069 ah->ah_sc->vif != NULL)
1070 ath5k_hw_write_rate_duration(ah, mode);
1071
1072 /*
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001073 * Write RF buffer
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001074 */
Nick Kossifidis8892e4e2009-02-09 06:06:34 +02001075 ret = ath5k_hw_rfregs_init(ah, channel, mode);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001076 if (ret)
1077 return ret;
1078
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001079
1080 /* Write OFDM timings on 5212*/
1081 if (ah->ah_version == AR5K_AR5212 &&
1082 channel->hw_value & CHANNEL_OFDM) {
Nick Kossifidis57e6c562009-04-30 15:55:50 -04001083 struct ath5k_eeprom_info *ee =
1084 &ah->ah_capabilities.cap_eeprom;
1085
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001086 ret = ath5k_hw_write_ofdm_timings(ah, channel);
1087 if (ret)
1088 return ret;
Nick Kossifidis57e6c562009-04-30 15:55:50 -04001089
1090 /* Note: According to docs we can have a newer
1091 * EEPROM on old hardware, so we need to verify
1092 * that our hardware is new enough to have spur
1093 * mitigation registers (delta phase etc) */
1094 if (ah->ah_mac_srev >= AR5K_SREV_AR5424 ||
1095 (ah->ah_mac_srev >= AR5K_SREV_AR5424 &&
1096 ee->ee_version >= AR5K_EEPROM_VERSION_5_3))
1097 ath5k_hw_set_spur_mitigation_filter(ah,
1098 channel);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001099 }
1100
1101 /*Enable/disable 802.11b mode on 5111
1102 (enable 2111 frequency converter + CCK)*/
1103 if (ah->ah_radio == AR5K_RF5111) {
1104 if (mode == AR5K_MODE_11B)
1105 AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG,
1106 AR5K_TXCFG_B_MODE);
1107 else
1108 AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
1109 AR5K_TXCFG_B_MODE);
1110 }
1111
1112 /*
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001113 * In case a fixed antenna was set as default
Nick Kossifidis2bed03e2009-04-30 15:55:49 -04001114 * use the same switch table twice.
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001115 */
Nick Kossifidis2bed03e2009-04-30 15:55:49 -04001116 if (ah->ah_ant_mode == AR5K_ANTMODE_FIXED_A)
1117 ant[0] = ant[1] = AR5K_ANT_SWTABLE_A;
1118 else if (ah->ah_ant_mode == AR5K_ANTMODE_FIXED_B)
1119 ant[0] = ant[1] = AR5K_ANT_SWTABLE_B;
1120 else {
1121 ant[0] = AR5K_ANT_SWTABLE_A;
1122 ant[1] = AR5K_ANT_SWTABLE_B;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001123 }
1124
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001125 /* Commit values from EEPROM */
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001126 ath5k_hw_commit_eeprom_settings(ah, channel, ant, ee_mode);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001127
1128 } else {
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001129 /*
1130 * For 5210 we do all initialization using
1131 * initvals, so we don't have to modify
1132 * any settings (5210 also only supports
1133 * a/aturbo modes)
1134 */
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001135 mdelay(1);
1136 /* Disable phy and wait */
1137 ath5k_hw_reg_write(ah, AR5K_PHY_ACT_DISABLE, AR5K_PHY_ACT);
1138 mdelay(1);
1139 }
1140
1141 /*
1142 * Restore saved values
1143 */
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001144
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001145 /*DCU/Antenna selection not available on 5210*/
1146 if (ah->ah_version != AR5K_AR5210) {
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001147
1148 if (change_channel) {
1149 if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
1150 for (i = 0; i < 10; i++)
1151 ath5k_hw_reg_write(ah, s_seq[i],
1152 AR5K_QUEUE_DCU_SEQNUM(i));
1153 } else {
1154 ath5k_hw_reg_write(ah, s_seq[0],
1155 AR5K_QUEUE_DCU_SEQNUM(0));
1156 }
1157
1158
1159 if (ah->ah_version == AR5K_AR5211) {
1160 ath5k_hw_reg_write(ah, tsf_up, AR5K_TSF_U32);
1161 ath5k_hw_reg_write(ah, tsf_lo, AR5K_TSF_L32);
1162 }
1163 }
1164
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001165 ath5k_hw_reg_write(ah, s_ant, AR5K_DEFAULT_ANTENNA);
1166 }
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001167
1168 /* Ledstate */
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001169 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, s_led[0]);
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001170
1171 /* Gpio settings */
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001172 ath5k_hw_reg_write(ah, s_led[1], AR5K_GPIOCR);
1173 ath5k_hw_reg_write(ah, s_led[2], AR5K_GPIODO);
1174
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001175 /* Restore sta_id flags and preserve our mac address*/
Luis R. Rodriguezbcd8f542009-09-09 22:43:17 -07001176 ath5k_hw_reg_write(ah, get_unaligned_le32(ah->ah_sta_id),
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001177 AR5K_STA_ID0);
Luis R. Rodriguezbcd8f542009-09-09 22:43:17 -07001178 ath5k_hw_reg_write(ah, staid1_flags | get_unaligned_le16(ah->ah_sta_id),
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001179 AR5K_STA_ID1);
1180
1181
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001182 /*
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001183 * Configure PCU
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001184 */
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001185
1186 /* Restore bssid and bssid mask */
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001187 /* XXX: add ah->aid once mac80211 gives this to us */
1188 ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
1189
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001190 /* Set PCU config */
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001191 ath5k_hw_set_opmode(ah);
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001192
1193 /* Clear any pending interrupts
1194 * PISR/SISR Not available on 5210 */
1195 if (ah->ah_version != AR5K_AR5210)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001196 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_PISR);
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001197
1198 /* Set RSSI/BRSSI thresholds
1199 *
1200 * Note: If we decide to set this value
1201 * dynamicaly, have in mind that when AR5K_RSSI_THR
1202 * register is read it might return 0x40 if we haven't
1203 * wrote anything to it plus BMISS RSSI threshold is zeroed.
1204 * So doing a save/restore procedure here isn't the right
1205 * choice. Instead store it on ath5k_hw */
1206 ath5k_hw_reg_write(ah, (AR5K_TUNE_RSSI_THRES |
1207 AR5K_TUNE_BMISS_THRES <<
1208 AR5K_RSSI_THR_BMISS_S),
1209 AR5K_RSSI_THR);
1210
1211 /* MIC QoS support */
1212 if (ah->ah_mac_srev >= AR5K_SREV_AR2413) {
1213 ath5k_hw_reg_write(ah, 0x000100aa, AR5K_MIC_QOS_CTL);
1214 ath5k_hw_reg_write(ah, 0x00003210, AR5K_MIC_QOS_SEL);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001215 }
1216
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001217 /* QoS NOACK Policy */
1218 if (ah->ah_version == AR5K_AR5212) {
1219 ath5k_hw_reg_write(ah,
1220 AR5K_REG_SM(2, AR5K_QOS_NOACK_2BIT_VALUES) |
1221 AR5K_REG_SM(5, AR5K_QOS_NOACK_BIT_OFFSET) |
1222 AR5K_REG_SM(0, AR5K_QOS_NOACK_BYTE_OFFSET),
1223 AR5K_QOS_NOACK);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001224 }
1225
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001226
1227 /*
1228 * Configure PHY
1229 */
1230
1231 /* Set channel on PHY */
1232 ret = ath5k_hw_channel(ah, channel);
1233 if (ret)
1234 return ret;
1235
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001236 /*
1237 * Enable the PHY and wait until completion
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001238 * This includes BaseBand and Synthesizer
1239 * activation.
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001240 */
1241 ath5k_hw_reg_write(ah, AR5K_PHY_ACT_ENABLE, AR5K_PHY_ACT);
1242
1243 /*
1244 * On 5211+ read activation -> rx delay
1245 * and use it.
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001246 *
1247 * TODO: Half/quarter rate support
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001248 */
1249 if (ah->ah_version != AR5K_AR5210) {
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001250 u32 delay;
1251 delay = ath5k_hw_reg_read(ah, AR5K_PHY_RX_DELAY) &
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001252 AR5K_PHY_RX_DELAY_M;
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001253 delay = (channel->hw_value & CHANNEL_CCK) ?
1254 ((delay << 2) / 22) : (delay / 10);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001255
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001256 udelay(100 + (2 * delay));
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001257 } else {
1258 mdelay(1);
1259 }
1260
1261 /*
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001262 * Perform ADC test to see if baseband is ready
1263 * Set tx hold and check adc test register
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001264 */
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001265 phy_tst1 = ath5k_hw_reg_read(ah, AR5K_PHY_TST1);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001266 ath5k_hw_reg_write(ah, AR5K_PHY_TST1_TXHOLD, AR5K_PHY_TST1);
1267 for (i = 0; i <= 20; i++) {
1268 if (!(ath5k_hw_reg_read(ah, AR5K_PHY_ADC_TEST) & 0x10))
1269 break;
1270 udelay(200);
1271 }
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001272 ath5k_hw_reg_write(ah, phy_tst1, AR5K_PHY_TST1);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001273
1274 /*
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001275 * Start automatic gain control calibration
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001276 *
1277 * During AGC calibration RX path is re-routed to
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001278 * a power detector so we don't receive anything.
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001279 *
1280 * This method is used to calibrate some static offsets
1281 * used together with on-the fly I/Q calibration (the
1282 * one performed via ath5k_hw_phy_calibrate), that doesn't
1283 * interrupt rx path.
1284 *
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001285 * While rx path is re-routed to the power detector we also
1286 * start a noise floor calibration, to measure the
1287 * card's noise floor (the noise we measure when we are not
1288 * transmiting or receiving anything).
1289 *
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001290 * If we are in a noisy environment AGC calibration may time
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001291 * out and/or noise floor calibration might timeout.
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001292 */
1293 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
1294 AR5K_PHY_AGCCTL_CAL);
1295
1296 /* At the same time start I/Q calibration for QAM constellation
1297 * -no need for CCK- */
1298 ah->ah_calibration = false;
1299 if (!(mode == AR5K_MODE_11B)) {
1300 ah->ah_calibration = true;
1301 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ,
1302 AR5K_PHY_IQ_CAL_NUM_LOG_MAX, 15);
1303 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
1304 AR5K_PHY_IQ_RUN);
1305 }
1306
1307 /* Wait for gain calibration to finish (we check for I/Q calibration
1308 * during ath5k_phy_calibrate) */
1309 if (ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
1310 AR5K_PHY_AGCCTL_CAL, 0, false)) {
1311 ATH5K_ERR(ah->ah_sc, "gain calibration timeout (%uMHz)\n",
1312 channel->center_freq);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001313 }
1314
1315 /*
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001316 * If we run NF calibration before AGC, it always times out.
1317 * Binary HAL starts NF and AGC calibration at the same time
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001318 * and only waits for AGC to finish. Also if AGC or NF cal.
1319 * times out, reset doesn't fail on binary HAL. I believe
1320 * that's wrong because since rx path is routed to a detector,
1321 * if cal. doesn't finish we won't have RX. Sam's HAL for AR5210/5211
1322 * enables noise floor calibration after offset calibration and if noise
1323 * floor calibration fails, reset fails. I believe that's
1324 * a better approach, we just need to find a polling interval
1325 * that suits best, even if reset continues we need to make
1326 * sure that rx path is ready.
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001327 */
Felix Fietkau8b0162a2008-11-03 11:27:38 +01001328 ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001329
Nick Kossifidis2bed03e2009-04-30 15:55:49 -04001330 /* Restore antenna mode */
1331 ath5k_hw_set_antenna_mode(ah, ah->ah_ant_mode);
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001332
1333 /*
1334 * Configure QCUs/DCUs
1335 */
1336
1337 /* TODO: HW Compression support for data queues */
1338 /* TODO: Burst prefetch for data queues */
1339
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001340 /*
1341 * Reset queues and start beacon timers at the end of the reset routine
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001342 * This also sets QCU mask on each DCU for 1:1 qcu to dcu mapping
1343 * Note: If we want we can assign multiple qcus on one dcu.
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001344 */
1345 for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++) {
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001346 ret = ath5k_hw_reset_tx_queue(ah, i);
1347 if (ret) {
1348 ATH5K_ERR(ah->ah_sc,
1349 "failed to reset TX queue #%d\n", i);
1350 return ret;
1351 }
1352 }
1353
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001354
1355 /*
1356 * Configure DMA/Interrupts
1357 */
1358
1359 /*
1360 * Set Rx/Tx DMA Configuration
1361 *
1362 * Set standard DMA size (128). Note that
1363 * a DMA size of 512 causes rx overruns and tx errors
1364 * on pci-e cards (tested on 5424 but since rx overruns
1365 * also occur on 5416/5418 with madwifi we set 128
1366 * for all PCI-E cards to be safe).
1367 *
1368 * XXX: need to check 5210 for this
1369 * TODO: Check out tx triger level, it's always 64 on dumps but I
1370 * guess we can tweak it and see how it goes ;-)
1371 */
1372 if (ah->ah_version != AR5K_AR5210) {
1373 AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
1374 AR5K_TXCFG_SDMAMR, AR5K_DMASIZE_128B);
1375 AR5K_REG_WRITE_BITS(ah, AR5K_RXCFG,
1376 AR5K_RXCFG_SDMAMW, AR5K_DMASIZE_128B);
1377 }
1378
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001379 /* Pre-enable interrupts on 5211/5212*/
1380 if (ah->ah_version != AR5K_AR5210)
Nick Kossifidis4c674c62008-10-26 20:40:25 +02001381 ath5k_hw_set_imr(ah, ah->ah_imr);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001382
Nick Kossifidise8f055f2009-02-09 06:12:58 +02001383 /* Enable 32KHz clock function for AR5212+ chips
1384 * Set clocks to 32KHz operation and use an
1385 * external 32KHz crystal when sleeping if one
1386 * exists */
1387 if (ah->ah_version == AR5K_AR5212)
1388 ath5k_hw_set_sleep_clock(ah, true);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001389
1390 /*
1391 * Disable beacons and reset the register
1392 */
1393 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE |
1394 AR5K_BEACON_RESET_TSF);
1395
1396 return 0;
1397}
1398
1399#undef _ATH5K_RESET