17 #include <linux/export.h>
21 static const int firstep_table[] =
23 { -4, -2, 0, 2, 4, 6, 8, 10, 12 };
25 static const int cycpwrThr1_table[] =
27 { -6, -4, -2, 0, 2, 4, 6, 8 };
32 static const int m1ThreshLow_off = 127;
33 static const int m2ThreshLow_off = 127;
34 static const int m1Thresh_off = 127;
35 static const int m2Thresh_off = 127;
36 static const int m2CountThr_off = 31;
37 static const int m2CountThrLow_off = 63;
38 static const int m1ThreshLowExt_off = 127;
39 static const int m2ThreshLowExt_off = 127;
40 static const int m1ThreshExt_off = 127;
41 static const int m2ThreshExt_off = 127;
70 u16 bMode, fracMode = 0, aModeRefSel = 0;
71 u32 freq, channelSel = 0, reg32 = 0;
76 freq = centers.synth_center;
88 channelSel = (freq * 4) / div;
89 chan_frac = (((freq * 4) % div) * 0x20000) / div;
90 channelSel = (channelSel << 17) | chan_frac;
99 channelSel = (freq * 4) / 120;
100 chan_frac = (((freq * 4) % 120) * 0x20000) / 120;
101 channelSel = (channelSel << 17) | chan_frac;
106 channelSel = (freq * 2) / 75;
107 chan_frac = (((freq * 2) % 75) * 0x20000) / 75;
108 channelSel = (channelSel << 17) | chan_frac;
120 channelSel = freq / 75;
121 chan_frac = ((freq % 75) * 0x20000) / 75;
122 channelSel = (channelSel << 17) | chan_frac;
135 loadSynthChannel = 0;
137 reg32 = (bMode << 29);
145 reg32 = (channelSel << 2) | (fracMode << 30) |
146 (aModeRefSel << 28) | (loadSynthChannel << 31);
150 loadSynthChannel = 1;
151 reg32 = (channelSel << 2) | (fracMode << 30) |
152 (aModeRefSel << 28) | (loadSynthChannel << 31);
170 static void ar9003_hw_spur_mitigate_mrc_cck(
struct ath_hw *ah,
173 static const u32 spur_freq[4] = { 2420, 2440, 2464, 2480 };
174 int cur_bb_spur, negative = 0, cck_spur_freq;
176 int range, max_spur_cnts, synth_freq;
186 if (spur_fbin_ptr[0] == 0)
193 synth_freq = chan->
channel + 10;
195 synth_freq = chan->
channel - 10;
206 for (i = 0; i < max_spur_cnts; i++) {
213 cur_bb_spur = ath9k_hw_fbin2freq(spur_fbin_ptr[i],
216 cur_bb_spur = spur_freq[
i];
218 cur_bb_spur -= synth_freq;
219 if (cur_bb_spur < 0) {
221 cur_bb_spur = -cur_bb_spur;
223 if (cur_bb_spur < range) {
224 cck_spur_freq = (
int)((cur_bb_spur << 19) / 11);
227 cck_spur_freq = -cck_spur_freq;
229 cck_spur_freq = cck_spur_freq & 0xfffff;
258 static void ar9003_hw_spur_ofdm_clear(
struct ath_hw *ah)
301 static void ar9003_hw_spur_ofdm(
struct ath_hw *ah,
304 int spur_delta_phase,
305 int spur_subchannel_sd,
323 if (!(
AR_SREV_9565(ah) && range == 10 && synth_freq == 2437))
339 mask_index = (freq_offset << 4) / 5;
341 mask_index = mask_index - 1;
343 mask_index = mask_index & 0x7f;
367 static void ar9003_hw_spur_ofdm_9565(
struct ath_hw *ah,
372 mask_index = (freq_offset << 4) / 5;
374 mask_index = mask_index - 1;
376 mask_index = mask_index & 0x7f;
400 static void ar9003_hw_spur_ofdm_work(
struct ath_hw *ah,
406 int spur_freq_sd = 0;
407 int spur_subchannel_sd = 0;
408 int spur_delta_phase = 0;
411 if (freq_offset < 0) {
414 spur_subchannel_sd = 1;
416 spur_subchannel_sd = 0;
418 spur_freq_sd = ((freq_offset + 10) << 9) / 11;
423 spur_subchannel_sd = 0;
425 spur_subchannel_sd = 1;
427 spur_freq_sd = ((freq_offset - 10) << 9) / 11;
431 spur_delta_phase = (freq_offset << 17) / 5;
434 spur_subchannel_sd = 0;
435 spur_freq_sd = (freq_offset << 9) /11;
436 spur_delta_phase = (freq_offset << 18) / 5;
439 spur_freq_sd = spur_freq_sd & 0x3ff;
440 spur_delta_phase = spur_delta_phase & 0xfffff;
442 ar9003_hw_spur_ofdm(ah,
451 static void ar9003_hw_spur_mitigate_ofdm(
struct ath_hw *ah,
471 if (spurChansPtr[0] == 0)
478 synth_freq = chan->
channel - 10;
480 synth_freq = chan->
channel + 10;
486 ar9003_hw_spur_ofdm_clear(ah);
489 freq_offset = ath9k_hw_fbin2freq(spurChansPtr[i], mode);
490 freq_offset -= synth_freq;
491 if (
abs(freq_offset) < range) {
492 ar9003_hw_spur_ofdm_work(ah, chan, freq_offset,
496 freq_offset = ath9k_hw_fbin2freq(spurChansPtr[i + 1],
498 freq_offset -= synth_freq;
499 if (
abs(freq_offset) < range)
500 ar9003_hw_spur_ofdm_9565(ah, freq_offset);
508 static void ar9003_hw_spur_mitigate(
struct ath_hw *ah,
512 ar9003_hw_spur_mitigate_mrc_cck(ah, chan);
513 ar9003_hw_spur_mitigate_ofdm(ah, chan);
516 static u32 ar9003_hw_compute_pll_control(
struct ath_hw *ah,
533 static void ar9003_hw_set_channel_regs(
struct ath_hw *ah,
537 u32 enableDacFifo = 0;
572 static void ar9003_hw_init_bb(
struct ath_hw *ah,
589 static void ar9003_hw_set_chain_masks(
struct ath_hw *ah,
u8 rx,
u8 tx)
620 static void ar9003_hw_override_ini(
struct ath_hw *ah)
646 static void ar9003_hw_prog_ini(
struct ath_hw *ah,
650 unsigned int i, regWrites = 0;
664 for (i = 0; i < iniArr->
ia_rows; i++) {
674 static int ar9550_hw_get_modes_txgain_index(
struct ath_hw *ah,
718 static int ar9003_hw_process_ini(
struct ath_hw *ah,
721 unsigned int regWrites = 0,
i;
748 ar9003_hw_prog_ini(ah, &ah->
iniSOC[i], modesIndex);
749 ar9003_hw_prog_ini(ah, &ah->
iniMac[i], modesIndex);
750 ar9003_hw_prog_ini(ah, &ah->
iniBB[i], modesIndex);
751 ar9003_hw_prog_ini(ah, &ah->
iniRadio[i], modesIndex);
753 ar9003_hw_prog_ini(ah,
764 int modes_txgain_index;
766 modes_txgain_index = ar9550_hw_get_modes_txgain_index(ah, chan);
767 if (modes_txgain_index < 0)
782 modesIndex, regWrites);
794 ar9003_hw_override_ini(ah);
795 ar9003_hw_set_channel_regs(ah, chan);
815 static void ar9003_hw_set_rfmode(
struct ath_hw *ah,
840 static void ar9003_hw_mark_phy_inactive(
struct ath_hw *ah)
845 static void ar9003_hw_set_delta_slope(
struct ath_hw *ah,
848 u32 coef_scaled, ds_coef_exp, ds_coef_man;
849 u32 clockMhzScaled = 0x64000000;
857 clockMhzScaled = clockMhzScaled >> 1;
859 clockMhzScaled = clockMhzScaled >> 2;
866 coef_scaled = clockMhzScaled / centers.synth_center;
880 coef_scaled = (9 * coef_scaled) / 10;
892 static bool ar9003_hw_rfbus_req(
struct ath_hw *ah)
903 static void ar9003_hw_rfbus_done(
struct ath_hw *ah)
912 static bool ar9003_hw_ani_control(
struct ath_hw *ah,
929 u32 on = param ? 1 : 0;
940 "** ch %d: ofdm weak signal: %s=>%s\n",
946 ah->
stats.ast_ani_ofdmon++;
948 ah->
stats.ast_ani_ofdmoff++;
958 "ATH9K_ANI_FIRSTEP_LEVEL: level out of range (%u > %zu)\n",
967 value = firstep_table[
level] -
982 value2 = firstep_table[
level] -
984 aniState->
iniDef.firstepLow;
995 "** ch %d: level %d=>%d[def:%d] firstep[level]=%d ini=%d\n",
1001 aniState->
iniDef.firstep);
1003 "** ch %d: level %d=>%d[def:%d] firstep_low[level]=%d ini=%d\n",
1009 aniState->
iniDef.firstepLow);
1011 ah->
stats.ast_ani_stepup++;
1013 ah->
stats.ast_ani_stepdown++;
1023 "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level out of range (%u > %zu)\n",
1031 value = cycpwrThr1_table[
level] -
1033 aniState->
iniDef.cycpwrThr1;
1047 value2 = cycpwrThr1_table[
level] -
1049 aniState->
iniDef.cycpwrThr1Ext;
1059 "** ch %d: level %d=>%d[def:%d] cycpwrThr1[level]=%d ini=%d\n",
1065 aniState->
iniDef.cycpwrThr1);
1067 "** ch %d: level %d=>%d[def:%d] cycpwrThr1Ext[level]=%d ini=%d\n",
1073 aniState->
iniDef.cycpwrThr1Ext);
1075 ah->
stats.ast_ani_spurup++;
1077 ah->
stats.ast_ani_spurdown++;
1087 bool is_on = param ? 1 : 0;
1092 if (is_on != aniState->
mrcCCK) {
1093 ath_dbg(common, ANI,
"** ch %d: MRC CCK: %s=>%s\n",
1095 aniState->
mrcCCK ?
"on" :
"off",
1096 is_on ?
"on" :
"off");
1098 ah->
stats.ast_ani_ccklow++;
1100 ah->
stats.ast_ani_cckhigh++;
1101 aniState->
mrcCCK = is_on;
1108 ath_dbg(common, ANI,
"invalid cmd %u\n", cmd);
1113 "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n",
1117 aniState->
mrcCCK ?
"on" :
"off",
1124 static void ar9003_hw_do_getnf(
struct ath_hw *ah,
1127 #define AR_PHY_CH_MINCCA_PWR 0x1FF00000
1128 #define AR_PHY_CH_MINCCA_PWR_S 20
1129 #define AR_PHY_CH_EXT_MINCCA_PWR 0x01FF0000
1130 #define AR_PHY_CH_EXT_MINCCA_PWR_S 16
1138 AR_PHY_CH_MINCCA_PWR);
1139 nfarray[
i] = sign_extend32(nf, 8);
1142 u8 ext_idx = AR9300_MAX_CHAINS +
i;
1145 AR_PHY_CH_EXT_MINCCA_PWR);
1146 nfarray[ext_idx] = sign_extend32(nf, 8);
1152 static void ar9003_hw_set_nf_limits(
struct ath_hw *ah)
1177 static void ar9003_hw_ani_cache_ini_regs(
struct ath_hw *ah)
1180 struct ath_common *common = ath9k_hw_common(ah);
1186 iniDef = &aniState->
iniDef;
1188 ath_dbg(common, ANI,
"ver %d.%d opmode %u chan %d Mhz/0x%x\n",
1230 static void ar9003_hw_set_radar_params(
struct ath_hw *ah,
1233 u32 radar_0 = 0, radar_1 = 0;
1261 static void ar9003_hw_set_radar_conf(
struct ath_hw *ah)
1275 static void ar9003_hw_antdiv_comb_conf_get(
struct ath_hw *ah,
1303 static void ar9003_hw_antdiv_comb_conf_set(
struct ath_hw *ah,
1328 static void ar9003_hw_antctrl_shared_chain_lnadiv(
struct ath_hw *ah,
1387 static int ar9003_hw_fast_chan_change(
struct ath_hw *ah,
1391 unsigned int regWrites = 0;
1418 *ini_reloaded =
false;
1446 *ini_reloaded =
true;
1449 ar9003_hw_set_rfmode(ah, chan);
1457 static const u32 ar9300_cca_regs[6] = {
1470 priv_ops->
init_bb = ar9003_hw_init_bb;
1475 priv_ops->
rfbus_req = ar9003_hw_rfbus_req;
1478 priv_ops->
do_getnf = ar9003_hw_do_getnf;
1487 ar9003_hw_set_nf_limits(ah);
1488 ar9003_hw_set_radar_conf(ah);
1494 struct ath_common *common = ath9k_hw_common(ah);
1522 if (idle_tmo_ms > 10000)
1523 idle_tmo_ms = 10000;
1534 idle_count = (100 * idle_tmo_ms) / 74;
1536 idle_count = (100 * idle_tmo_ms) / 37;
1547 ath_dbg(common,
RESET,
"Enabled BB Watchdog timeout (%u ms)\n",
1569 struct ath_common *common = ath9k_hw_common(ah);
1577 "\n==== BB update: BB status=0x%08x ====\n", status);
1579 "** BB state: wd=%u det=%u rdar=%u rOFDM=%d rCCK=%u tOFDM=%u tCCK=%u agc=%u src=%u **\n",
1590 ath_dbg(common,
RESET,
"** BB WD cntl: cntl1=0x%08x cntl2=0x%08x **\n",
1593 ath_dbg(common,
RESET,
"** BB mode: BB_gen_controls=0x%08x **\n",
1596 #define PCT(_field) (common->cc_survey._field * 100 / common->cc_survey.cycles)
1599 "** BB busy times: rx_clear=%d%%, rx_frame=%d%%, tx_frame=%d%% **\n",
1602 ath_dbg(common,
RESET,
"==== BB update: done ====\n\n");