4 * Copyright (c) 2004-2007 Reyk Floeter <reyk@openbsd.org>
5 * Copyright (c) 2006-2009 Nick Kossifidis <mickflemm@gmail.com>
6 * Copyright (c) 2007-2008 Jiri Slaby <jirislaby@gmail.com>
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.
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.
24 #include <linux/delay.h>
33 * Used to modify RF Banks before writing them to AR5K_RF_BUFFER
35 static unsigned int ath5k_hw_rfb_op(struct ath5k_hw *ah,
36 const struct ath5k_rf_reg *rf_regs,
37 u32 val, u8 reg_id, bool set)
39 const struct ath5k_rf_reg *rfreg = NULL;
40 u8 offset, bank, num_bits, col, position;
42 u32 mask, data, last_bit, bits_shifted, first_bit;
48 rfb = ah->ah_rf_banks;
50 for (i = 0; i < ah->ah_rf_regs_count; i++) {
51 if (rf_regs[i].index == reg_id) {
57 if (rfb == NULL || rfreg == NULL) {
58 ATH5K_PRINTF("Rf register not found!\n");
59 /* should not happen */
64 num_bits = rfreg->field.len;
65 first_bit = rfreg->field.pos;
66 col = rfreg->field.col;
68 /* first_bit is an offset from bank's
69 * start. Since we have all banks on
70 * the same array, we use this offset
71 * to mark each bank's start */
72 offset = ah->ah_offset[bank];
75 if (!(col <= 3 && num_bits <= 32 && first_bit + num_bits <= 319)) {
76 ATH5K_PRINTF("invalid values at offset %u\n", offset);
80 entry = ((first_bit - 1) / 8) + offset;
81 position = (first_bit - 1) % 8;
84 data = ath5k_hw_bitswap(val, num_bits);
86 for (bits_shifted = 0, bits_left = num_bits; bits_left > 0;
87 position = 0, entry++) {
89 last_bit = (position + bits_left > 8) ? 8 :
92 mask = (((1 << last_bit) - 1) ^ ((1 << position) - 1)) <<
97 rfb[entry] |= ((data << position) << (col * 8)) & mask;
98 data >>= (8 - position);
100 data |= (((rfb[entry] & mask) >> (col * 8)) >> position)
102 bits_shifted += last_bit - position;
105 bits_left -= 8 - position;
108 data = set ? 1 : ath5k_hw_bitswap(data, num_bits);
113 /**********************\
114 * RF Gain optimization *
115 \**********************/
118 * This code is used to optimize rf gain on different environments
119 * (temprature mostly) based on feedback from a power detector.
121 * It's only used on RF5111 and RF5112, later RF chips seem to have
122 * auto adjustment on hw -notice they have a much smaller BANK 7 and
123 * no gain optimization ladder-.
125 * For more infos check out this patent doc
126 * http://www.freepatentsonline.com/7400691.html
128 * This paper describes power drops as seen on the receiver due to
130 * http://www.cnri.dit.ie/publications/ICT08%20-%20Practical%20Issues
131 * %20of%20Power%20Control.pdf
133 * And this is the MadWiFi bug entry related to the above
134 * http://madwifi-project.org/ticket/1659
135 * with various measurements and diagrams
137 * TODO: Deal with power drops due to probes by setting an apropriate
138 * tx power on the probe packets ! Make this part of the calibration process.
141 /* Initialize ah_gain durring attach */
142 int ath5k_hw_rfgain_opt_init(struct ath5k_hw *ah)
144 /* Initialize the gain optimization values */
145 switch (ah->ah_radio) {
147 ah->ah_gain.g_step_idx = rfgain_opt_5111.go_default;
148 ah->ah_gain.g_low = 20;
149 ah->ah_gain.g_high = 35;
150 ah->ah_gain.g_state = AR5K_RFGAIN_ACTIVE;
153 ah->ah_gain.g_step_idx = rfgain_opt_5112.go_default;
154 ah->ah_gain.g_low = 20;
155 ah->ah_gain.g_high = 85;
156 ah->ah_gain.g_state = AR5K_RFGAIN_ACTIVE;
165 /* Schedule a gain probe check on the next transmited packet.
166 * That means our next packet is going to be sent with lower
167 * tx power and a Peak to Average Power Detector (PAPD) will try
168 * to measure the gain.
170 * TODO: Use propper tx power setting for the probe packet so
171 * that we don't observe a serious power drop on the receiver
173 * XXX: How about forcing a tx packet (bypassing PCU arbitrator etc)
174 * just after we enable the probe so that we don't mess with
175 * standard traffic ? Maybe it's time to use sw interrupts and
176 * a probe tasklet !!!
178 static void ath5k_hw_request_rfgain_probe(struct ath5k_hw *ah)
181 /* Skip if gain calibration is inactive or
182 * we already handle a probe request */
183 if (ah->ah_gain.g_state != AR5K_RFGAIN_ACTIVE)
186 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txpower.txp_max,
187 AR5K_PHY_PAPD_PROBE_TXPOWER) |
188 AR5K_PHY_PAPD_PROBE_TX_NEXT, AR5K_PHY_PAPD_PROBE);
190 ah->ah_gain.g_state = AR5K_RFGAIN_READ_REQUESTED;
194 /* Calculate gain_F measurement correction
195 * based on the current step for RF5112 rev. 2 */
196 static u32 ath5k_hw_rf_gainf_corr(struct ath5k_hw *ah)
200 const struct ath5k_gain_opt *go;
201 const struct ath5k_gain_opt_step *g_step;
202 const struct ath5k_rf_reg *rf_regs;
204 /* Only RF5112 Rev. 2 supports it */
205 if ((ah->ah_radio != AR5K_RF5112) ||
206 (ah->ah_radio_5ghz_revision <= AR5K_SREV_RAD_5112A))
209 go = &rfgain_opt_5112;
210 rf_regs = rf_regs_5112a;
211 ah->ah_rf_regs_count = ARRAY_SIZE(rf_regs_5112a);
213 g_step = &go->go_step[ah->ah_gain.g_step_idx];
215 if (ah->ah_rf_banks == NULL)
218 rf = ah->ah_rf_banks;
219 ah->ah_gain.g_f_corr = 0;
221 /* No VGA (Variable Gain Amplifier) override, skip */
222 if (ath5k_hw_rfb_op(ah, rf_regs, 0, AR5K_RF_MIXVGA_OVR, false) != 1)
225 /* Mix gain stepping */
226 step = ath5k_hw_rfb_op(ah, rf_regs, 0, AR5K_RF_MIXGAIN_STEP, false);
228 /* Mix gain override */
229 mix = g_step->gos_param[0];
233 ah->ah_gain.g_f_corr = step * 2;
236 ah->ah_gain.g_f_corr = (step - 5) * 2;
239 ah->ah_gain.g_f_corr = step;
242 ah->ah_gain.g_f_corr = 0;
246 return ah->ah_gain.g_f_corr;
249 /* Check if current gain_F measurement is in the range of our
250 * power detector windows. If we get a measurement outside range
251 * we know it's not accurate (detectors can't measure anything outside
252 * their detection window) so we must ignore it */
253 static bool ath5k_hw_rf_check_gainf_readback(struct ath5k_hw *ah)
255 const struct ath5k_rf_reg *rf_regs;
256 u32 step, mix_ovr, level[4];
259 if (ah->ah_rf_banks == NULL)
262 rf = ah->ah_rf_banks;
264 if (ah->ah_radio == AR5K_RF5111) {
266 rf_regs = rf_regs_5111;
267 ah->ah_rf_regs_count = ARRAY_SIZE(rf_regs_5111);
269 step = ath5k_hw_rfb_op(ah, rf_regs, 0, AR5K_RF_RFGAIN_STEP,
273 level[1] = (step == 63) ? 50 : step + 4;
274 level[2] = (step != 63) ? 64 : level[0];
275 level[3] = level[2] + 50 ;
277 ah->ah_gain.g_high = level[3] -
278 (step == 63 ? AR5K_GAIN_DYN_ADJUST_HI_MARGIN : -5);
279 ah->ah_gain.g_low = level[0] +
280 (step == 63 ? AR5K_GAIN_DYN_ADJUST_LO_MARGIN : 0);
283 rf_regs = rf_regs_5112;
284 ah->ah_rf_regs_count = ARRAY_SIZE(rf_regs_5112);
286 mix_ovr = ath5k_hw_rfb_op(ah, rf_regs, 0, AR5K_RF_MIXVGA_OVR,
289 level[0] = level[2] = 0;
292 level[1] = level[3] = 83;
294 level[1] = level[3] = 107;
295 ah->ah_gain.g_high = 55;
299 return (ah->ah_gain.g_current >= level[0] &&
300 ah->ah_gain.g_current <= level[1]) ||
301 (ah->ah_gain.g_current >= level[2] &&
302 ah->ah_gain.g_current <= level[3]);
305 /* Perform gain_F adjustment by choosing the right set
306 * of parameters from rf gain optimization ladder */
307 static s8 ath5k_hw_rf_gainf_adjust(struct ath5k_hw *ah)
309 const struct ath5k_gain_opt *go;
310 const struct ath5k_gain_opt_step *g_step;
313 switch (ah->ah_radio) {
315 go = &rfgain_opt_5111;
318 go = &rfgain_opt_5112;
324 g_step = &go->go_step[ah->ah_gain.g_step_idx];
326 if (ah->ah_gain.g_current >= ah->ah_gain.g_high) {
328 /* Reached maximum */
329 if (ah->ah_gain.g_step_idx == 0)
332 for (ah->ah_gain.g_target = ah->ah_gain.g_current;
333 ah->ah_gain.g_target >= ah->ah_gain.g_high &&
334 ah->ah_gain.g_step_idx > 0;
335 g_step = &go->go_step[ah->ah_gain.g_step_idx])
336 ah->ah_gain.g_target -= 2 *
337 (go->go_step[--(ah->ah_gain.g_step_idx)].gos_gain -
344 if (ah->ah_gain.g_current <= ah->ah_gain.g_low) {
346 /* Reached minimum */
347 if (ah->ah_gain.g_step_idx == (go->go_steps_count - 1))
350 for (ah->ah_gain.g_target = ah->ah_gain.g_current;
351 ah->ah_gain.g_target <= ah->ah_gain.g_low &&
352 ah->ah_gain.g_step_idx < go->go_steps_count-1;
353 g_step = &go->go_step[ah->ah_gain.g_step_idx])
354 ah->ah_gain.g_target -= 2 *
355 (go->go_step[++ah->ah_gain.g_step_idx].gos_gain -
363 ATH5K_DBG(ah->ah_sc, ATH5K_DEBUG_CALIBRATE,
364 "ret %d, gain step %u, current gain %u, target gain %u\n",
365 ret, ah->ah_gain.g_step_idx, ah->ah_gain.g_current,
366 ah->ah_gain.g_target);
371 /* Main callback for thermal rf gain calibration engine
372 * Check for a new gain reading and schedule an adjustment
375 * TODO: Use sw interrupt to schedule reset if gain_F needs
377 enum ath5k_rfgain ath5k_hw_gainf_calibrate(struct ath5k_hw *ah)
380 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
382 ATH5K_TRACE(ah->ah_sc);
384 if (ah->ah_rf_banks == NULL ||
385 ah->ah_gain.g_state == AR5K_RFGAIN_INACTIVE)
386 return AR5K_RFGAIN_INACTIVE;
388 /* No check requested, either engine is inactive
389 * or an adjustment is already requested */
390 if (ah->ah_gain.g_state != AR5K_RFGAIN_READ_REQUESTED)
393 /* Read the PAPD (Peak to Average Power Detector)
395 data = ath5k_hw_reg_read(ah, AR5K_PHY_PAPD_PROBE);
397 /* No probe is scheduled, read gain_F measurement */
398 if (!(data & AR5K_PHY_PAPD_PROBE_TX_NEXT)) {
399 ah->ah_gain.g_current = data >> AR5K_PHY_PAPD_PROBE_GAINF_S;
400 type = AR5K_REG_MS(data, AR5K_PHY_PAPD_PROBE_TYPE);
402 /* If tx packet is CCK correct the gain_F measurement
403 * by cck ofdm gain delta */
404 if (type == AR5K_PHY_PAPD_PROBE_TYPE_CCK) {
405 if (ah->ah_radio_5ghz_revision >= AR5K_SREV_RAD_5112A)
406 ah->ah_gain.g_current +=
407 ee->ee_cck_ofdm_gain_delta;
409 ah->ah_gain.g_current +=
410 AR5K_GAIN_CCK_PROBE_CORR;
413 /* Further correct gain_F measurement for
415 if (ah->ah_radio_5ghz_revision >= AR5K_SREV_RAD_5112A) {
416 ath5k_hw_rf_gainf_corr(ah);
417 ah->ah_gain.g_current =
418 ah->ah_gain.g_current >= ah->ah_gain.g_f_corr ?
419 (ah->ah_gain.g_current-ah->ah_gain.g_f_corr) :
423 /* Check if measurement is ok and if we need
424 * to adjust gain, schedule a gain adjustment,
425 * else switch back to the acive state */
426 if (ath5k_hw_rf_check_gainf_readback(ah) &&
427 AR5K_GAIN_CHECK_ADJUST(&ah->ah_gain) &&
428 ath5k_hw_rf_gainf_adjust(ah)) {
429 ah->ah_gain.g_state = AR5K_RFGAIN_NEED_CHANGE;
431 ah->ah_gain.g_state = AR5K_RFGAIN_ACTIVE;
436 return ah->ah_gain.g_state;
439 /* Write initial rf gain table to set the RF sensitivity
440 * this one works on all RF chips and has nothing to do
441 * with gain_F calibration */
442 int ath5k_hw_rfgain_init(struct ath5k_hw *ah, unsigned int freq)
444 const struct ath5k_ini_rfgain *ath5k_rfg;
445 unsigned int i, size;
447 switch (ah->ah_radio) {
449 ath5k_rfg = rfgain_5111;
450 size = ARRAY_SIZE(rfgain_5111);
453 ath5k_rfg = rfgain_5112;
454 size = ARRAY_SIZE(rfgain_5112);
457 ath5k_rfg = rfgain_2413;
458 size = ARRAY_SIZE(rfgain_2413);
461 ath5k_rfg = rfgain_2316;
462 size = ARRAY_SIZE(rfgain_2316);
465 ath5k_rfg = rfgain_5413;
466 size = ARRAY_SIZE(rfgain_5413);
470 ath5k_rfg = rfgain_2425;
471 size = ARRAY_SIZE(rfgain_2425);
478 case AR5K_INI_RFGAIN_2GHZ:
479 case AR5K_INI_RFGAIN_5GHZ:
485 for (i = 0; i < size; i++) {
487 ath5k_hw_reg_write(ah, ath5k_rfg[i].rfg_value[freq],
488 (u32)ath5k_rfg[i].rfg_register);
496 /********************\
497 * RF Registers setup *
498 \********************/
502 * Setup RF registers by writing rf buffer on hw
504 int ath5k_hw_rfregs_init(struct ath5k_hw *ah, struct ieee80211_channel *channel,
507 const struct ath5k_rf_reg *rf_regs;
508 const struct ath5k_ini_rfbuffer *ini_rfb;
509 const struct ath5k_gain_opt *go = NULL;
510 const struct ath5k_gain_opt_step *g_step;
511 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
514 int i, obdb = -1, bank = -1;
516 switch (ah->ah_radio) {
518 rf_regs = rf_regs_5111;
519 ah->ah_rf_regs_count = ARRAY_SIZE(rf_regs_5111);
521 ah->ah_rf_banks_size = ARRAY_SIZE(rfb_5111);
522 go = &rfgain_opt_5111;
525 if (ah->ah_radio_5ghz_revision >= AR5K_SREV_RAD_5112A) {
526 rf_regs = rf_regs_5112a;
527 ah->ah_rf_regs_count = ARRAY_SIZE(rf_regs_5112a);
529 ah->ah_rf_banks_size = ARRAY_SIZE(rfb_5112a);
531 rf_regs = rf_regs_5112;
532 ah->ah_rf_regs_count = ARRAY_SIZE(rf_regs_5112);
534 ah->ah_rf_banks_size = ARRAY_SIZE(rfb_5112);
536 go = &rfgain_opt_5112;
539 rf_regs = rf_regs_2413;
540 ah->ah_rf_regs_count = ARRAY_SIZE(rf_regs_2413);
542 ah->ah_rf_banks_size = ARRAY_SIZE(rfb_2413);
545 rf_regs = rf_regs_2316;
546 ah->ah_rf_regs_count = ARRAY_SIZE(rf_regs_2316);
548 ah->ah_rf_banks_size = ARRAY_SIZE(rfb_2316);
551 rf_regs = rf_regs_5413;
552 ah->ah_rf_regs_count = ARRAY_SIZE(rf_regs_5413);
554 ah->ah_rf_banks_size = ARRAY_SIZE(rfb_5413);
557 rf_regs = rf_regs_2425;
558 ah->ah_rf_regs_count = ARRAY_SIZE(rf_regs_2425);
560 ah->ah_rf_banks_size = ARRAY_SIZE(rfb_2317);
563 rf_regs = rf_regs_2425;
564 ah->ah_rf_regs_count = ARRAY_SIZE(rf_regs_2425);
565 if (ah->ah_mac_srev < AR5K_SREV_AR2417) {
567 ah->ah_rf_banks_size = ARRAY_SIZE(rfb_2425);
570 ah->ah_rf_banks_size = ARRAY_SIZE(rfb_2417);
577 /* If it's the first time we set rf buffer, allocate
578 * ah->ah_rf_banks based on ah->ah_rf_banks_size
580 if (ah->ah_rf_banks == NULL) {
581 ah->ah_rf_banks = kmalloc(sizeof(u32) * ah->ah_rf_banks_size,
583 if (ah->ah_rf_banks == NULL) {
584 ATH5K_ERR(ah->ah_sc, "out of memory\n");
589 /* Copy values to modify them */
590 rfb = ah->ah_rf_banks;
592 for (i = 0; i < ah->ah_rf_banks_size; i++) {
593 if (ini_rfb[i].rfb_bank >= AR5K_MAX_RF_BANKS) {
594 ATH5K_ERR(ah->ah_sc, "invalid bank\n");
598 /* Bank changed, write down the offset */
599 if (bank != ini_rfb[i].rfb_bank) {
600 bank = ini_rfb[i].rfb_bank;
601 ah->ah_offset[bank] = i;
604 rfb[i] = ini_rfb[i].rfb_mode_data[mode];
607 /* Set Output and Driver bias current (OB/DB) */
608 if (channel->hw_value & CHANNEL_2GHZ) {
610 if (channel->hw_value & CHANNEL_CCK)
611 ee_mode = AR5K_EEPROM_MODE_11B;
613 ee_mode = AR5K_EEPROM_MODE_11G;
615 /* For RF511X/RF211X combination we
616 * use b_OB and b_DB parameters stored
617 * in eeprom on ee->ee_ob[ee_mode][0]
619 * For all other chips we use OB/DB for 2Ghz
620 * stored in the b/g modal section just like
621 * 802.11a on ee->ee_ob[ee_mode][1] */
622 if ((ah->ah_radio == AR5K_RF5111) ||
623 (ah->ah_radio == AR5K_RF5112))
628 ath5k_hw_rfb_op(ah, rf_regs, ee->ee_ob[ee_mode][obdb],
629 AR5K_RF_OB_2GHZ, true);
631 ath5k_hw_rfb_op(ah, rf_regs, ee->ee_db[ee_mode][obdb],
632 AR5K_RF_DB_2GHZ, true);
634 /* RF5111 always needs OB/DB for 5GHz, even if we use 2GHz */
635 } else if ((channel->hw_value & CHANNEL_5GHZ) ||
636 (ah->ah_radio == AR5K_RF5111)) {
638 /* For 11a, Turbo and XR we need to choose
639 * OB/DB based on frequency range */
640 ee_mode = AR5K_EEPROM_MODE_11A;
641 obdb = channel->center_freq >= 5725 ? 3 :
642 (channel->center_freq >= 5500 ? 2 :
643 (channel->center_freq >= 5260 ? 1 :
644 (channel->center_freq > 4000 ? 0 : -1)));
649 ath5k_hw_rfb_op(ah, rf_regs, ee->ee_ob[ee_mode][obdb],
650 AR5K_RF_OB_5GHZ, true);
652 ath5k_hw_rfb_op(ah, rf_regs, ee->ee_db[ee_mode][obdb],
653 AR5K_RF_DB_5GHZ, true);
656 g_step = &go->go_step[ah->ah_gain.g_step_idx];
658 /* Bank Modifications (chip-specific) */
659 if (ah->ah_radio == AR5K_RF5111) {
661 /* Set gain_F settings according to current step */
662 if (channel->hw_value & CHANNEL_OFDM) {
664 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_FRAME_CTL,
665 AR5K_PHY_FRAME_CTL_TX_CLIP,
666 g_step->gos_param[0]);
668 ath5k_hw_rfb_op(ah, rf_regs, g_step->gos_param[1],
669 AR5K_RF_PWD_90, true);
671 ath5k_hw_rfb_op(ah, rf_regs, g_step->gos_param[2],
672 AR5K_RF_PWD_84, true);
674 ath5k_hw_rfb_op(ah, rf_regs, g_step->gos_param[3],
675 AR5K_RF_RFGAIN_SEL, true);
677 /* We programmed gain_F parameters, switch back
679 ah->ah_gain.g_state = AR5K_RFGAIN_ACTIVE;
685 ath5k_hw_rfb_op(ah, rf_regs, !ee->ee_xpd[ee_mode],
686 AR5K_RF_PWD_XPD, true);
688 ath5k_hw_rfb_op(ah, rf_regs, ee->ee_x_gain[ee_mode],
689 AR5K_RF_XPD_GAIN, true);
691 ath5k_hw_rfb_op(ah, rf_regs, ee->ee_i_gain[ee_mode],
692 AR5K_RF_GAIN_I, true);
694 ath5k_hw_rfb_op(ah, rf_regs, ee->ee_xpd[ee_mode],
695 AR5K_RF_PLO_SEL, true);
697 /* TODO: Half/quarter channel support */
700 if (ah->ah_radio == AR5K_RF5112) {
702 /* Set gain_F settings according to current step */
703 if (channel->hw_value & CHANNEL_OFDM) {
705 ath5k_hw_rfb_op(ah, rf_regs, g_step->gos_param[0],
706 AR5K_RF_MIXGAIN_OVR, true);
708 ath5k_hw_rfb_op(ah, rf_regs, g_step->gos_param[1],
709 AR5K_RF_PWD_138, true);
711 ath5k_hw_rfb_op(ah, rf_regs, g_step->gos_param[2],
712 AR5K_RF_PWD_137, true);
714 ath5k_hw_rfb_op(ah, rf_regs, g_step->gos_param[3],
715 AR5K_RF_PWD_136, true);
717 ath5k_hw_rfb_op(ah, rf_regs, g_step->gos_param[4],
718 AR5K_RF_PWD_132, true);
720 ath5k_hw_rfb_op(ah, rf_regs, g_step->gos_param[5],
721 AR5K_RF_PWD_131, true);
723 ath5k_hw_rfb_op(ah, rf_regs, g_step->gos_param[6],
724 AR5K_RF_PWD_130, true);
726 /* We programmed gain_F parameters, switch back
728 ah->ah_gain.g_state = AR5K_RFGAIN_ACTIVE;
733 ath5k_hw_rfb_op(ah, rf_regs, ee->ee_xpd[ee_mode],
734 AR5K_RF_XPD_SEL, true);
736 if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5112A) {
737 /* Rev. 1 supports only one xpd */
738 ath5k_hw_rfb_op(ah, rf_regs,
739 ee->ee_x_gain[ee_mode],
740 AR5K_RF_XPD_GAIN, true);
743 /* TODO: Set high and low gain bits */
744 ath5k_hw_rfb_op(ah, rf_regs,
745 ee->ee_x_gain[ee_mode],
746 AR5K_RF_PD_GAIN_LO, true);
747 ath5k_hw_rfb_op(ah, rf_regs,
748 ee->ee_x_gain[ee_mode],
749 AR5K_RF_PD_GAIN_HI, true);
751 /* Lower synth voltage on Rev 2 */
752 ath5k_hw_rfb_op(ah, rf_regs, 2,
753 AR5K_RF_HIGH_VC_CP, true);
755 ath5k_hw_rfb_op(ah, rf_regs, 2,
756 AR5K_RF_MID_VC_CP, true);
758 ath5k_hw_rfb_op(ah, rf_regs, 2,
759 AR5K_RF_LOW_VC_CP, true);
761 ath5k_hw_rfb_op(ah, rf_regs, 2,
762 AR5K_RF_PUSH_UP, true);
764 /* Decrease power consumption on 5213+ BaseBand */
765 if (ah->ah_phy_revision >= AR5K_SREV_PHY_5212A) {
766 ath5k_hw_rfb_op(ah, rf_regs, 1,
767 AR5K_RF_PAD2GND, true);
769 ath5k_hw_rfb_op(ah, rf_regs, 1,
770 AR5K_RF_XB2_LVL, true);
772 ath5k_hw_rfb_op(ah, rf_regs, 1,
773 AR5K_RF_XB5_LVL, true);
775 ath5k_hw_rfb_op(ah, rf_regs, 1,
776 AR5K_RF_PWD_167, true);
778 ath5k_hw_rfb_op(ah, rf_regs, 1,
779 AR5K_RF_PWD_166, true);
783 ath5k_hw_rfb_op(ah, rf_regs, ee->ee_i_gain[ee_mode],
784 AR5K_RF_GAIN_I, true);
786 /* TODO: Half/quarter channel support */
790 if (ah->ah_radio == AR5K_RF5413 &&
791 channel->hw_value & CHANNEL_2GHZ) {
793 ath5k_hw_rfb_op(ah, rf_regs, 1, AR5K_RF_DERBY_CHAN_SEL_MODE,
796 /* Set optimum value for early revisions (on pci-e chips) */
797 if (ah->ah_mac_srev >= AR5K_SREV_AR5424 &&
798 ah->ah_mac_srev < AR5K_SREV_AR5413)
799 ath5k_hw_rfb_op(ah, rf_regs, ath5k_hw_bitswap(6, 3),
800 AR5K_RF_PWD_ICLOBUF_2G, true);
804 /* Write RF banks on hw */
805 for (i = 0; i < ah->ah_rf_banks_size; i++) {
807 ath5k_hw_reg_write(ah, rfb[i], ini_rfb[i].rfb_ctrl_register);
814 /**************************\
815 PHY/RF channel functions
816 \**************************/
819 * Check if a channel is supported
821 bool ath5k_channel_ok(struct ath5k_hw *ah, u16 freq, unsigned int flags)
823 /* Check if the channel is in our supported range */
824 if (flags & CHANNEL_2GHZ) {
825 if ((freq >= ah->ah_capabilities.cap_range.range_2ghz_min) &&
826 (freq <= ah->ah_capabilities.cap_range.range_2ghz_max))
828 } else if (flags & CHANNEL_5GHZ)
829 if ((freq >= ah->ah_capabilities.cap_range.range_5ghz_min) &&
830 (freq <= ah->ah_capabilities.cap_range.range_5ghz_max))
837 * Convertion needed for RF5110
839 static u32 ath5k_hw_rf5110_chan2athchan(struct ieee80211_channel *channel)
844 * Convert IEEE channel/MHz to an internal channel value used
845 * by the AR5210 chipset. This has not been verified with
846 * newer chipsets like the AR5212A who have a completely
847 * different RF/PHY part.
849 athchan = (ath5k_hw_bitswap(
850 (ieee80211_frequency_to_channel(
851 channel->center_freq) - 24) / 2, 5)
852 << 1) | (1 << 6) | 0x1;
857 * Set channel on RF5110
859 static int ath5k_hw_rf5110_channel(struct ath5k_hw *ah,
860 struct ieee80211_channel *channel)
865 * Set the channel and wait
867 data = ath5k_hw_rf5110_chan2athchan(channel);
868 ath5k_hw_reg_write(ah, data, AR5K_RF_BUFFER);
869 ath5k_hw_reg_write(ah, 0, AR5K_RF_BUFFER_CONTROL_0);
876 * Convertion needed for 5111
878 static int ath5k_hw_rf5111_chan2athchan(unsigned int ieee,
879 struct ath5k_athchan_2ghz *athchan)
883 /* Cast this value to catch negative channel numbers (>= -19) */
887 * Map 2GHz IEEE channel to 5GHz Atheros channel
890 athchan->a2_athchan = 115 + channel;
891 athchan->a2_flags = 0x46;
892 } else if (channel == 14) {
893 athchan->a2_athchan = 124;
894 athchan->a2_flags = 0x44;
895 } else if (channel >= 15 && channel <= 26) {
896 athchan->a2_athchan = ((channel - 14) * 4) + 132;
897 athchan->a2_flags = 0x46;
905 * Set channel on 5111
907 static int ath5k_hw_rf5111_channel(struct ath5k_hw *ah,
908 struct ieee80211_channel *channel)
910 struct ath5k_athchan_2ghz ath5k_channel_2ghz;
911 unsigned int ath5k_channel =
912 ieee80211_frequency_to_channel(channel->center_freq);
913 u32 data0, data1, clock;
917 * Set the channel on the RF5111 radio
921 if (channel->hw_value & CHANNEL_2GHZ) {
922 /* Map 2GHz channel to 5GHz Atheros channel ID */
923 ret = ath5k_hw_rf5111_chan2athchan(
924 ieee80211_frequency_to_channel(channel->center_freq),
925 &ath5k_channel_2ghz);
929 ath5k_channel = ath5k_channel_2ghz.a2_athchan;
930 data0 = ((ath5k_hw_bitswap(ath5k_channel_2ghz.a2_flags, 8) & 0xff)
934 if (ath5k_channel < 145 || !(ath5k_channel & 1)) {
936 data1 = ((ath5k_hw_bitswap(ath5k_channel - 24, 8) & 0xff) << 2) |
937 (clock << 1) | (1 << 10) | 1;
940 data1 = ((ath5k_hw_bitswap((ath5k_channel - 24) / 2, 8) & 0xff)
941 << 2) | (clock << 1) | (1 << 10) | 1;
944 ath5k_hw_reg_write(ah, (data1 & 0xff) | ((data0 & 0xff) << 8),
946 ath5k_hw_reg_write(ah, ((data1 >> 8) & 0xff) | (data0 & 0xff00),
947 AR5K_RF_BUFFER_CONTROL_3);
953 * Set channel on 5112 and newer
955 static int ath5k_hw_rf5112_channel(struct ath5k_hw *ah,
956 struct ieee80211_channel *channel)
958 u32 data, data0, data1, data2;
961 data = data0 = data1 = data2 = 0;
962 c = channel->center_freq;
965 if (!((c - 2224) % 5)) {
966 data0 = ((2 * (c - 704)) - 3040) / 10;
968 } else if (!((c - 2192) % 5)) {
969 data0 = ((2 * (c - 672)) - 3040) / 10;
974 data0 = ath5k_hw_bitswap((data0 << 2) & 0xff, 8);
975 } else if ((c - (c % 5)) != 2 || c > 5435) {
976 if (!(c % 20) && c >= 5120) {
977 data0 = ath5k_hw_bitswap(((c - 4800) / 20 << 2), 8);
978 data2 = ath5k_hw_bitswap(3, 2);
979 } else if (!(c % 10)) {
980 data0 = ath5k_hw_bitswap(((c - 4800) / 10 << 1), 8);
981 data2 = ath5k_hw_bitswap(2, 2);
982 } else if (!(c % 5)) {
983 data0 = ath5k_hw_bitswap((c - 4800) / 5, 8);
984 data2 = ath5k_hw_bitswap(1, 2);
988 data0 = ath5k_hw_bitswap((10 * (c - 2) - 4800) / 25 + 1, 8);
989 data2 = ath5k_hw_bitswap(0, 2);
992 data = (data0 << 4) | (data1 << 1) | (data2 << 2) | 0x1001;
994 ath5k_hw_reg_write(ah, data & 0xff, AR5K_RF_BUFFER);
995 ath5k_hw_reg_write(ah, (data >> 8) & 0x7f, AR5K_RF_BUFFER_CONTROL_5);
1001 * Set the channel on the RF2425
1003 static int ath5k_hw_rf2425_channel(struct ath5k_hw *ah,
1004 struct ieee80211_channel *channel)
1006 u32 data, data0, data2;
1009 data = data0 = data2 = 0;
1010 c = channel->center_freq;
1013 data0 = ath5k_hw_bitswap((c - 2272), 8);
1016 } else if ((c - (c % 5)) != 2 || c > 5435) {
1017 if (!(c % 20) && c < 5120)
1018 data0 = ath5k_hw_bitswap(((c - 4800) / 20 << 2), 8);
1020 data0 = ath5k_hw_bitswap(((c - 4800) / 10 << 1), 8);
1022 data0 = ath5k_hw_bitswap((c - 4800) / 5, 8);
1025 data2 = ath5k_hw_bitswap(1, 2);
1027 data0 = ath5k_hw_bitswap((10 * (c - 2) - 4800) / 25 + 1, 8);
1028 data2 = ath5k_hw_bitswap(0, 2);
1031 data = (data0 << 4) | data2 << 2 | 0x1001;
1033 ath5k_hw_reg_write(ah, data & 0xff, AR5K_RF_BUFFER);
1034 ath5k_hw_reg_write(ah, (data >> 8) & 0x7f, AR5K_RF_BUFFER_CONTROL_5);
1040 * Set a channel on the radio chip
1042 int ath5k_hw_channel(struct ath5k_hw *ah, struct ieee80211_channel *channel)
1046 * Check bounds supported by the PHY (we don't care about regultory
1047 * restrictions at this point). Note: hw_value already has the band
1048 * (CHANNEL_2GHZ, or CHANNEL_5GHZ) so we inform ath5k_channel_ok()
1049 * of the band by that */
1050 if (!ath5k_channel_ok(ah, channel->center_freq, channel->hw_value)) {
1051 ATH5K_ERR(ah->ah_sc,
1052 "channel frequency (%u MHz) out of supported "
1054 channel->center_freq);
1059 * Set the channel and wait
1061 switch (ah->ah_radio) {
1063 ret = ath5k_hw_rf5110_channel(ah, channel);
1066 ret = ath5k_hw_rf5111_channel(ah, channel);
1069 ret = ath5k_hw_rf2425_channel(ah, channel);
1072 ret = ath5k_hw_rf5112_channel(ah, channel);
1079 /* Set JAPAN setting for channel 14 */
1080 if (channel->center_freq == 2484) {
1081 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_CCKTXCTL,
1082 AR5K_PHY_CCKTXCTL_JAPAN);
1084 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_CCKTXCTL,
1085 AR5K_PHY_CCKTXCTL_WORLD);
1088 ah->ah_current_channel.center_freq = channel->center_freq;
1089 ah->ah_current_channel.hw_value = channel->hw_value;
1090 ah->ah_turbo = channel->hw_value == CHANNEL_T ? true : false;
1100 * ath5k_hw_noise_floor_calibration - perform PHY noise floor calibration
1102 * @ah: struct ath5k_hw pointer we are operating on
1103 * @freq: the channel frequency, just used for error logging
1105 * This function performs a noise floor calibration of the PHY and waits for
1106 * it to complete. Then the noise floor value is compared to some maximum
1107 * noise floor we consider valid.
1109 * Note that this is different from what the madwifi HAL does: it reads the
1110 * noise floor and afterwards initiates the calibration. Since the noise floor
1111 * calibration can take some time to finish, depending on the current channel
1112 * use, that avoids the occasional timeout warnings we are seeing now.
1114 * See the following link for an Atheros patent on noise floor calibration:
1115 * http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO1&Sect2=HITOFF&d=PALL \
1116 * &p=1&u=%2Fnetahtml%2FPTO%2Fsrchnum.htm&r=1&f=G&l=50&s1=7245893.PN.&OS=PN/7
1118 * XXX: Since during noise floor calibration antennas are detached according to
1119 * the patent, we should stop tx queues here.
1122 ath5k_hw_noise_floor_calibration(struct ath5k_hw *ah, short freq)
1129 * Enable noise floor calibration
1131 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
1132 AR5K_PHY_AGCCTL_NF);
1134 ret = ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
1135 AR5K_PHY_AGCCTL_NF, 0, false);
1137 ATH5K_ERR(ah->ah_sc,
1138 "noise floor calibration timeout (%uMHz)\n", freq);
1142 /* Wait until the noise floor is calibrated and read the value */
1143 for (i = 20; i > 0; i--) {
1145 noise_floor = ath5k_hw_reg_read(ah, AR5K_PHY_NF);
1146 noise_floor = AR5K_PHY_NF_RVAL(noise_floor);
1147 if (noise_floor & AR5K_PHY_NF_ACTIVE) {
1148 noise_floor = AR5K_PHY_NF_AVAL(noise_floor);
1150 if (noise_floor <= AR5K_TUNE_NOISE_FLOOR)
1155 ATH5K_DBG_UNLIMIT(ah->ah_sc, ATH5K_DEBUG_CALIBRATE,
1156 "noise floor %d\n", noise_floor);
1158 if (noise_floor > AR5K_TUNE_NOISE_FLOOR) {
1159 ATH5K_ERR(ah->ah_sc,
1160 "noise floor calibration failed (%uMHz)\n", freq);
1164 ah->ah_noise_floor = noise_floor;
1170 * Perform a PHY calibration on RF5110
1171 * -Fix BPSK/QAM Constellation (I/Q correction)
1172 * -Calculate Noise Floor
1174 static int ath5k_hw_rf5110_calibrate(struct ath5k_hw *ah,
1175 struct ieee80211_channel *channel)
1177 u32 phy_sig, phy_agc, phy_sat, beacon;
1181 * Disable beacons and RX/TX queues, wait
1183 AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW_5210,
1184 AR5K_DIAG_SW_DIS_TX | AR5K_DIAG_SW_DIS_RX_5210);
1185 beacon = ath5k_hw_reg_read(ah, AR5K_BEACON_5210);
1186 ath5k_hw_reg_write(ah, beacon & ~AR5K_BEACON_ENABLE, AR5K_BEACON_5210);
1191 * Set the channel (with AGC turned off)
1193 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGC, AR5K_PHY_AGC_DISABLE);
1195 ret = ath5k_hw_channel(ah, channel);
1198 * Activate PHY and wait
1200 ath5k_hw_reg_write(ah, AR5K_PHY_ACT_ENABLE, AR5K_PHY_ACT);
1203 AR5K_REG_DISABLE_BITS(ah, AR5K_PHY_AGC, AR5K_PHY_AGC_DISABLE);
1209 * Calibrate the radio chip
1212 /* Remember normal state */
1213 phy_sig = ath5k_hw_reg_read(ah, AR5K_PHY_SIG);
1214 phy_agc = ath5k_hw_reg_read(ah, AR5K_PHY_AGCCOARSE);
1215 phy_sat = ath5k_hw_reg_read(ah, AR5K_PHY_ADCSAT);
1217 /* Update radio registers */
1218 ath5k_hw_reg_write(ah, (phy_sig & ~(AR5K_PHY_SIG_FIRPWR)) |
1219 AR5K_REG_SM(-1, AR5K_PHY_SIG_FIRPWR), AR5K_PHY_SIG);
1221 ath5k_hw_reg_write(ah, (phy_agc & ~(AR5K_PHY_AGCCOARSE_HI |
1222 AR5K_PHY_AGCCOARSE_LO)) |
1223 AR5K_REG_SM(-1, AR5K_PHY_AGCCOARSE_HI) |
1224 AR5K_REG_SM(-127, AR5K_PHY_AGCCOARSE_LO), AR5K_PHY_AGCCOARSE);
1226 ath5k_hw_reg_write(ah, (phy_sat & ~(AR5K_PHY_ADCSAT_ICNT |
1227 AR5K_PHY_ADCSAT_THR)) |
1228 AR5K_REG_SM(2, AR5K_PHY_ADCSAT_ICNT) |
1229 AR5K_REG_SM(12, AR5K_PHY_ADCSAT_THR), AR5K_PHY_ADCSAT);
1233 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGC, AR5K_PHY_AGC_DISABLE);
1235 ath5k_hw_reg_write(ah, AR5K_PHY_RFSTG_DISABLE, AR5K_PHY_RFSTG);
1236 AR5K_REG_DISABLE_BITS(ah, AR5K_PHY_AGC, AR5K_PHY_AGC_DISABLE);
1241 * Enable calibration and wait until completion
1243 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL, AR5K_PHY_AGCCTL_CAL);
1245 ret = ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
1246 AR5K_PHY_AGCCTL_CAL, 0, false);
1248 /* Reset to normal state */
1249 ath5k_hw_reg_write(ah, phy_sig, AR5K_PHY_SIG);
1250 ath5k_hw_reg_write(ah, phy_agc, AR5K_PHY_AGCCOARSE);
1251 ath5k_hw_reg_write(ah, phy_sat, AR5K_PHY_ADCSAT);
1254 ATH5K_ERR(ah->ah_sc, "calibration timeout (%uMHz)\n",
1255 channel->center_freq);
1259 ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
1262 * Re-enable RX/TX and beacons
1264 AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW_5210,
1265 AR5K_DIAG_SW_DIS_TX | AR5K_DIAG_SW_DIS_RX_5210);
1266 ath5k_hw_reg_write(ah, beacon, AR5K_BEACON_5210);
1272 * Perform a PHY calibration on RF5111/5112 and newer chips
1274 static int ath5k_hw_rf511x_calibrate(struct ath5k_hw *ah,
1275 struct ieee80211_channel *channel)
1278 s32 iq_corr, i_coff, i_coffd, q_coff, q_coffd;
1280 ATH5K_TRACE(ah->ah_sc);
1282 if (!ah->ah_calibration ||
1283 ath5k_hw_reg_read(ah, AR5K_PHY_IQ) & AR5K_PHY_IQ_RUN)
1286 /* Calibration has finished, get the results and re-run */
1287 for (i = 0; i <= 10; i++) {
1288 iq_corr = ath5k_hw_reg_read(ah, AR5K_PHY_IQRES_CAL_CORR);
1289 i_pwr = ath5k_hw_reg_read(ah, AR5K_PHY_IQRES_CAL_PWR_I);
1290 q_pwr = ath5k_hw_reg_read(ah, AR5K_PHY_IQRES_CAL_PWR_Q);
1293 i_coffd = ((i_pwr >> 1) + (q_pwr >> 1)) >> 7;
1294 q_coffd = q_pwr >> 7;
1297 if (i_coffd == 0 || q_coffd == 0)
1300 i_coff = ((-iq_corr) / i_coffd) & 0x3f;
1302 /* Boundary check */
1308 q_coff = (((s32)i_pwr / q_coffd) - 128) & 0x1f;
1310 /* Boundary check */
1316 /* Commit new I/Q value */
1317 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ, AR5K_PHY_IQ_CORR_ENABLE |
1318 ((u32)q_coff) | ((u32)i_coff << AR5K_PHY_IQ_CORR_Q_I_COFF_S));
1320 /* Re-enable calibration -if we don't we'll commit
1321 * the same values again and again */
1322 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ,
1323 AR5K_PHY_IQ_CAL_NUM_LOG_MAX, 15);
1324 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ, AR5K_PHY_IQ_RUN);
1328 /* TODO: Separate noise floor calibration from I/Q calibration
1329 * since noise floor calibration interrupts rx path while I/Q
1330 * calibration doesn't. We don't need to run noise floor calibration
1331 * as often as I/Q calibration.*/
1332 ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
1334 /* Initiate a gain_F calibration */
1335 ath5k_hw_request_rfgain_probe(ah);
1341 * Perform a PHY calibration
1343 int ath5k_hw_phy_calibrate(struct ath5k_hw *ah,
1344 struct ieee80211_channel *channel)
1348 if (ah->ah_radio == AR5K_RF5110)
1349 ret = ath5k_hw_rf5110_calibrate(ah, channel);
1351 ret = ath5k_hw_rf511x_calibrate(ah, channel);
1356 int ath5k_hw_phy_disable(struct ath5k_hw *ah)
1358 ATH5K_TRACE(ah->ah_sc);
1360 ath5k_hw_reg_write(ah, AR5K_PHY_ACT_DISABLE, AR5K_PHY_ACT);
1365 /********************\
1367 \********************/
1370 * Get the PHY Chip revision
1372 u16 ath5k_hw_radio_revision(struct ath5k_hw *ah, unsigned int chan)
1378 ATH5K_TRACE(ah->ah_sc);
1381 * Set the radio chip access register
1385 ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_2GHZ, AR5K_PHY(0));
1388 ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
1396 /* ...wait until PHY is ready and read the selected radio revision */
1397 ath5k_hw_reg_write(ah, 0x00001c16, AR5K_PHY(0x34));
1399 for (i = 0; i < 8; i++)
1400 ath5k_hw_reg_write(ah, 0x00010000, AR5K_PHY(0x20));
1402 if (ah->ah_version == AR5K_AR5210) {
1403 srev = ath5k_hw_reg_read(ah, AR5K_PHY(256) >> 28) & 0xf;
1404 ret = (u16)ath5k_hw_bitswap(srev, 4) + 1;
1406 srev = (ath5k_hw_reg_read(ah, AR5K_PHY(0x100)) >> 24) & 0xff;
1407 ret = (u16)ath5k_hw_bitswap(((srev & 0xf0) >> 4) |
1408 ((srev & 0x0f) << 4), 8);
1411 /* Reset to the 5GHz mode */
1412 ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
1417 void /*TODO:Boundary check*/
1418 ath5k_hw_set_def_antenna(struct ath5k_hw *ah, unsigned int ant)
1420 ATH5K_TRACE(ah->ah_sc);
1422 if (ah->ah_version != AR5K_AR5210)
1423 ath5k_hw_reg_write(ah, ant, AR5K_DEFAULT_ANTENNA);
1426 unsigned int ath5k_hw_get_def_antenna(struct ath5k_hw *ah)
1428 ATH5K_TRACE(ah->ah_sc);
1430 if (ah->ah_version != AR5K_AR5210)
1431 return ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
1433 return false; /*XXX: What do we return for 5210 ?*/
1441 * Initialize the tx power table (not fully implemented)
1443 static void ath5k_txpower_table(struct ath5k_hw *ah,
1444 struct ieee80211_channel *channel, s16 max_power)
1446 unsigned int i, min, max, n;
1447 u16 txpower, *rates;
1449 rates = ah->ah_txpower.txp_rates;
1451 txpower = AR5K_TUNE_DEFAULT_TXPOWER * 2;
1452 if (max_power > txpower)
1453 txpower = max_power > AR5K_TUNE_MAX_TXPOWER ?
1454 AR5K_TUNE_MAX_TXPOWER : max_power;
1456 for (i = 0; i < AR5K_MAX_RATES; i++)
1459 /* XXX setup target powers by rate */
1461 ah->ah_txpower.txp_min = rates[7];
1462 ah->ah_txpower.txp_max = rates[0];
1463 ah->ah_txpower.txp_ofdm = rates[0];
1465 /* Calculate the power table */
1466 n = ARRAY_SIZE(ah->ah_txpower.txp_pcdac);
1467 min = AR5K_EEPROM_PCDAC_START;
1468 max = AR5K_EEPROM_PCDAC_STOP;
1469 for (i = 0; i < n; i += AR5K_EEPROM_PCDAC_STEP)
1470 ah->ah_txpower.txp_pcdac[i] =
1472 min + ((i * (max - min)) / n);
1479 * Set transmition power
1481 int /*O.K. - txpower_table is unimplemented so this doesn't work*/
1482 ath5k_hw_txpower(struct ath5k_hw *ah, struct ieee80211_channel *channel,
1483 unsigned int txpower)
1485 bool tpc = ah->ah_txpower.txp_tpc;
1488 ATH5K_TRACE(ah->ah_sc);
1489 if (txpower > AR5K_TUNE_MAX_TXPOWER) {
1490 ATH5K_ERR(ah->ah_sc, "invalid tx power: %u\n", txpower);
1495 * RF2413 for some reason can't
1496 * transmit anything if we call
1497 * this funtion, so we skip it
1498 * until we fix txpower.
1500 * XXX: Assume same for RF2425
1503 if ((ah->ah_radio == AR5K_RF2413) || (ah->ah_radio == AR5K_RF2425))
1506 /* Reset TX power values */
1507 memset(&ah->ah_txpower, 0, sizeof(ah->ah_txpower));
1508 ah->ah_txpower.txp_tpc = tpc;
1510 /* Initialize TX power table */
1511 ath5k_txpower_table(ah, channel, txpower);
1514 * Write TX power values
1516 for (i = 0; i < (AR5K_EEPROM_POWER_TABLE_SIZE / 2); i++) {
1517 ath5k_hw_reg_write(ah,
1518 ((((ah->ah_txpower.txp_pcdac[(i << 1) + 1] << 8) | 0xff) & 0xffff) << 16) |
1519 (((ah->ah_txpower.txp_pcdac[(i << 1) ] << 8) | 0xff) & 0xffff),
1520 AR5K_PHY_PCDAC_TXPOWER(i));
1523 ath5k_hw_reg_write(ah, AR5K_TXPOWER_OFDM(3, 24) |
1524 AR5K_TXPOWER_OFDM(2, 16) | AR5K_TXPOWER_OFDM(1, 8) |
1525 AR5K_TXPOWER_OFDM(0, 0), AR5K_PHY_TXPOWER_RATE1);
1527 ath5k_hw_reg_write(ah, AR5K_TXPOWER_OFDM(7, 24) |
1528 AR5K_TXPOWER_OFDM(6, 16) | AR5K_TXPOWER_OFDM(5, 8) |
1529 AR5K_TXPOWER_OFDM(4, 0), AR5K_PHY_TXPOWER_RATE2);
1531 ath5k_hw_reg_write(ah, AR5K_TXPOWER_CCK(10, 24) |
1532 AR5K_TXPOWER_CCK(9, 16) | AR5K_TXPOWER_CCK(15, 8) |
1533 AR5K_TXPOWER_CCK(8, 0), AR5K_PHY_TXPOWER_RATE3);
1535 ath5k_hw_reg_write(ah, AR5K_TXPOWER_CCK(14, 24) |
1536 AR5K_TXPOWER_CCK(13, 16) | AR5K_TXPOWER_CCK(12, 8) |
1537 AR5K_TXPOWER_CCK(11, 0), AR5K_PHY_TXPOWER_RATE4);
1539 if (ah->ah_txpower.txp_tpc)
1540 ath5k_hw_reg_write(ah, AR5K_PHY_TXPOWER_RATE_MAX_TPC_ENABLE |
1541 AR5K_TUNE_MAX_TXPOWER, AR5K_PHY_TXPOWER_RATE_MAX);
1543 ath5k_hw_reg_write(ah, AR5K_PHY_TXPOWER_RATE_MAX |
1544 AR5K_TUNE_MAX_TXPOWER, AR5K_PHY_TXPOWER_RATE_MAX);
1549 int ath5k_hw_set_txpower_limit(struct ath5k_hw *ah, unsigned int power)
1552 struct ieee80211_channel *channel = &ah->ah_current_channel;
1554 ATH5K_TRACE(ah->ah_sc);
1555 ATH5K_DBG(ah->ah_sc, ATH5K_DEBUG_TXPOWER,
1556 "changing txpower to %d\n", power);
1558 return ath5k_hw_txpower(ah, channel, power);