18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2010-2011 Atheros Communications Inc. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any 58c2ecf20Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above 68c2ecf20Sopenharmony_ci * copyright notice and this permission notice appear in all copies. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 98c2ecf20Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 108c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 118c2ecf20Sopenharmony_ci * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 128c2ecf20Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 138c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 148c2ecf20Sopenharmony_ci * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <linux/export.h> 188c2ecf20Sopenharmony_ci#include "hw.h" 198c2ecf20Sopenharmony_ci#include "ar9003_phy.h" 208c2ecf20Sopenharmony_ci#include "ar9003_eeprom.h" 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#define AR9300_OFDM_RATES 8 238c2ecf20Sopenharmony_ci#define AR9300_HT_SS_RATES 8 248c2ecf20Sopenharmony_ci#define AR9300_HT_DS_RATES 8 258c2ecf20Sopenharmony_ci#define AR9300_HT_TS_RATES 8 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#define AR9300_11NA_OFDM_SHIFT 0 288c2ecf20Sopenharmony_ci#define AR9300_11NA_HT_SS_SHIFT 8 298c2ecf20Sopenharmony_ci#define AR9300_11NA_HT_DS_SHIFT 16 308c2ecf20Sopenharmony_ci#define AR9300_11NA_HT_TS_SHIFT 24 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#define AR9300_11NG_OFDM_SHIFT 4 338c2ecf20Sopenharmony_ci#define AR9300_11NG_HT_SS_SHIFT 12 348c2ecf20Sopenharmony_ci#define AR9300_11NG_HT_DS_SHIFT 20 358c2ecf20Sopenharmony_ci#define AR9300_11NG_HT_TS_SHIFT 28 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistatic const int firstep_table[] = 388c2ecf20Sopenharmony_ci/* level: 0 1 2 3 4 5 6 7 8 */ 398c2ecf20Sopenharmony_ci { -4, -2, 0, 2, 4, 6, 8, 10, 12 }; /* lvl 0-8, default 2 */ 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_cistatic const int cycpwrThr1_table[] = 428c2ecf20Sopenharmony_ci/* level: 0 1 2 3 4 5 6 7 8 */ 438c2ecf20Sopenharmony_ci { -6, -4, -2, 0, 2, 4, 6, 8 }; /* lvl 0-7, default 3 */ 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci/* 468c2ecf20Sopenharmony_ci * register values to turn OFDM weak signal detection OFF 478c2ecf20Sopenharmony_ci */ 488c2ecf20Sopenharmony_cistatic const int m1ThreshLow_off = 127; 498c2ecf20Sopenharmony_cistatic const int m2ThreshLow_off = 127; 508c2ecf20Sopenharmony_cistatic const int m1Thresh_off = 127; 518c2ecf20Sopenharmony_cistatic const int m2Thresh_off = 127; 528c2ecf20Sopenharmony_cistatic const int m2CountThr_off = 31; 538c2ecf20Sopenharmony_cistatic const int m2CountThrLow_off = 63; 548c2ecf20Sopenharmony_cistatic const int m1ThreshLowExt_off = 127; 558c2ecf20Sopenharmony_cistatic const int m2ThreshLowExt_off = 127; 568c2ecf20Sopenharmony_cistatic const int m1ThreshExt_off = 127; 578c2ecf20Sopenharmony_cistatic const int m2ThreshExt_off = 127; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_cistatic const u8 ofdm2pwr[] = { 608c2ecf20Sopenharmony_ci ALL_TARGET_LEGACY_6_24, 618c2ecf20Sopenharmony_ci ALL_TARGET_LEGACY_6_24, 628c2ecf20Sopenharmony_ci ALL_TARGET_LEGACY_6_24, 638c2ecf20Sopenharmony_ci ALL_TARGET_LEGACY_6_24, 648c2ecf20Sopenharmony_ci ALL_TARGET_LEGACY_6_24, 658c2ecf20Sopenharmony_ci ALL_TARGET_LEGACY_36, 668c2ecf20Sopenharmony_ci ALL_TARGET_LEGACY_48, 678c2ecf20Sopenharmony_ci ALL_TARGET_LEGACY_54 688c2ecf20Sopenharmony_ci}; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_cistatic const u8 mcs2pwr_ht20[] = { 718c2ecf20Sopenharmony_ci ALL_TARGET_HT20_0_8_16, 728c2ecf20Sopenharmony_ci ALL_TARGET_HT20_1_3_9_11_17_19, 738c2ecf20Sopenharmony_ci ALL_TARGET_HT20_1_3_9_11_17_19, 748c2ecf20Sopenharmony_ci ALL_TARGET_HT20_1_3_9_11_17_19, 758c2ecf20Sopenharmony_ci ALL_TARGET_HT20_4, 768c2ecf20Sopenharmony_ci ALL_TARGET_HT20_5, 778c2ecf20Sopenharmony_ci ALL_TARGET_HT20_6, 788c2ecf20Sopenharmony_ci ALL_TARGET_HT20_7, 798c2ecf20Sopenharmony_ci ALL_TARGET_HT20_0_8_16, 808c2ecf20Sopenharmony_ci ALL_TARGET_HT20_1_3_9_11_17_19, 818c2ecf20Sopenharmony_ci ALL_TARGET_HT20_1_3_9_11_17_19, 828c2ecf20Sopenharmony_ci ALL_TARGET_HT20_1_3_9_11_17_19, 838c2ecf20Sopenharmony_ci ALL_TARGET_HT20_12, 848c2ecf20Sopenharmony_ci ALL_TARGET_HT20_13, 858c2ecf20Sopenharmony_ci ALL_TARGET_HT20_14, 868c2ecf20Sopenharmony_ci ALL_TARGET_HT20_15, 878c2ecf20Sopenharmony_ci ALL_TARGET_HT20_0_8_16, 888c2ecf20Sopenharmony_ci ALL_TARGET_HT20_1_3_9_11_17_19, 898c2ecf20Sopenharmony_ci ALL_TARGET_HT20_1_3_9_11_17_19, 908c2ecf20Sopenharmony_ci ALL_TARGET_HT20_1_3_9_11_17_19, 918c2ecf20Sopenharmony_ci ALL_TARGET_HT20_20, 928c2ecf20Sopenharmony_ci ALL_TARGET_HT20_21, 938c2ecf20Sopenharmony_ci ALL_TARGET_HT20_22, 948c2ecf20Sopenharmony_ci ALL_TARGET_HT20_23 958c2ecf20Sopenharmony_ci}; 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_cistatic const u8 mcs2pwr_ht40[] = { 988c2ecf20Sopenharmony_ci ALL_TARGET_HT40_0_8_16, 998c2ecf20Sopenharmony_ci ALL_TARGET_HT40_1_3_9_11_17_19, 1008c2ecf20Sopenharmony_ci ALL_TARGET_HT40_1_3_9_11_17_19, 1018c2ecf20Sopenharmony_ci ALL_TARGET_HT40_1_3_9_11_17_19, 1028c2ecf20Sopenharmony_ci ALL_TARGET_HT40_4, 1038c2ecf20Sopenharmony_ci ALL_TARGET_HT40_5, 1048c2ecf20Sopenharmony_ci ALL_TARGET_HT40_6, 1058c2ecf20Sopenharmony_ci ALL_TARGET_HT40_7, 1068c2ecf20Sopenharmony_ci ALL_TARGET_HT40_0_8_16, 1078c2ecf20Sopenharmony_ci ALL_TARGET_HT40_1_3_9_11_17_19, 1088c2ecf20Sopenharmony_ci ALL_TARGET_HT40_1_3_9_11_17_19, 1098c2ecf20Sopenharmony_ci ALL_TARGET_HT40_1_3_9_11_17_19, 1108c2ecf20Sopenharmony_ci ALL_TARGET_HT40_12, 1118c2ecf20Sopenharmony_ci ALL_TARGET_HT40_13, 1128c2ecf20Sopenharmony_ci ALL_TARGET_HT40_14, 1138c2ecf20Sopenharmony_ci ALL_TARGET_HT40_15, 1148c2ecf20Sopenharmony_ci ALL_TARGET_HT40_0_8_16, 1158c2ecf20Sopenharmony_ci ALL_TARGET_HT40_1_3_9_11_17_19, 1168c2ecf20Sopenharmony_ci ALL_TARGET_HT40_1_3_9_11_17_19, 1178c2ecf20Sopenharmony_ci ALL_TARGET_HT40_1_3_9_11_17_19, 1188c2ecf20Sopenharmony_ci ALL_TARGET_HT40_20, 1198c2ecf20Sopenharmony_ci ALL_TARGET_HT40_21, 1208c2ecf20Sopenharmony_ci ALL_TARGET_HT40_22, 1218c2ecf20Sopenharmony_ci ALL_TARGET_HT40_23, 1228c2ecf20Sopenharmony_ci}; 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci/** 1258c2ecf20Sopenharmony_ci * ar9003_hw_set_channel - set channel on single-chip device 1268c2ecf20Sopenharmony_ci * @ah: atheros hardware structure 1278c2ecf20Sopenharmony_ci * @chan: 1288c2ecf20Sopenharmony_ci * 1298c2ecf20Sopenharmony_ci * This is the function to change channel on single-chip devices, that is 1308c2ecf20Sopenharmony_ci * for AR9300 family of chipsets. 1318c2ecf20Sopenharmony_ci * 1328c2ecf20Sopenharmony_ci * This function takes the channel value in MHz and sets 1338c2ecf20Sopenharmony_ci * hardware channel value. Assumes writes have been enabled to analog bus. 1348c2ecf20Sopenharmony_ci * 1358c2ecf20Sopenharmony_ci * Actual Expression, 1368c2ecf20Sopenharmony_ci * 1378c2ecf20Sopenharmony_ci * For 2GHz channel, 1388c2ecf20Sopenharmony_ci * Channel Frequency = (3/4) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17) 1398c2ecf20Sopenharmony_ci * (freq_ref = 40MHz) 1408c2ecf20Sopenharmony_ci * 1418c2ecf20Sopenharmony_ci * For 5GHz channel, 1428c2ecf20Sopenharmony_ci * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^10) 1438c2ecf20Sopenharmony_ci * (freq_ref = 40MHz/(24>>amodeRefSel)) 1448c2ecf20Sopenharmony_ci * 1458c2ecf20Sopenharmony_ci * For 5GHz channels which are 5MHz spaced, 1468c2ecf20Sopenharmony_ci * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17) 1478c2ecf20Sopenharmony_ci * (freq_ref = 40MHz) 1488c2ecf20Sopenharmony_ci */ 1498c2ecf20Sopenharmony_cistatic int ar9003_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan) 1508c2ecf20Sopenharmony_ci{ 1518c2ecf20Sopenharmony_ci u16 bMode, fracMode = 0, aModeRefSel = 0; 1528c2ecf20Sopenharmony_ci u32 freq, chan_frac, div, channelSel = 0, reg32 = 0; 1538c2ecf20Sopenharmony_ci struct chan_centers centers; 1548c2ecf20Sopenharmony_ci int loadSynthChannel; 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci ath9k_hw_get_channel_centers(ah, chan, ¢ers); 1578c2ecf20Sopenharmony_ci freq = centers.synth_center; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci if (freq < 4800) { /* 2 GHz, fractional mode */ 1608c2ecf20Sopenharmony_ci if (AR_SREV_9330(ah) || AR_SREV_9485(ah) || 1618c2ecf20Sopenharmony_ci AR_SREV_9531(ah) || AR_SREV_9550(ah) || 1628c2ecf20Sopenharmony_ci AR_SREV_9561(ah) || AR_SREV_9565(ah)) { 1638c2ecf20Sopenharmony_ci if (ah->is_clk_25mhz) 1648c2ecf20Sopenharmony_ci div = 75; 1658c2ecf20Sopenharmony_ci else 1668c2ecf20Sopenharmony_ci div = 120; 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci channelSel = (freq * 4) / div; 1698c2ecf20Sopenharmony_ci chan_frac = (((freq * 4) % div) * 0x20000) / div; 1708c2ecf20Sopenharmony_ci channelSel = (channelSel << 17) | chan_frac; 1718c2ecf20Sopenharmony_ci } else if (AR_SREV_9340(ah)) { 1728c2ecf20Sopenharmony_ci if (ah->is_clk_25mhz) { 1738c2ecf20Sopenharmony_ci channelSel = (freq * 2) / 75; 1748c2ecf20Sopenharmony_ci chan_frac = (((freq * 2) % 75) * 0x20000) / 75; 1758c2ecf20Sopenharmony_ci channelSel = (channelSel << 17) | chan_frac; 1768c2ecf20Sopenharmony_ci } else { 1778c2ecf20Sopenharmony_ci channelSel = CHANSEL_2G(freq) >> 1; 1788c2ecf20Sopenharmony_ci } 1798c2ecf20Sopenharmony_ci } else { 1808c2ecf20Sopenharmony_ci channelSel = CHANSEL_2G(freq); 1818c2ecf20Sopenharmony_ci } 1828c2ecf20Sopenharmony_ci /* Set to 2G mode */ 1838c2ecf20Sopenharmony_ci bMode = 1; 1848c2ecf20Sopenharmony_ci } else { 1858c2ecf20Sopenharmony_ci if ((AR_SREV_9340(ah) || AR_SREV_9550(ah) || 1868c2ecf20Sopenharmony_ci AR_SREV_9531(ah) || AR_SREV_9561(ah)) && 1878c2ecf20Sopenharmony_ci ah->is_clk_25mhz) { 1888c2ecf20Sopenharmony_ci channelSel = freq / 75; 1898c2ecf20Sopenharmony_ci chan_frac = ((freq % 75) * 0x20000) / 75; 1908c2ecf20Sopenharmony_ci channelSel = (channelSel << 17) | chan_frac; 1918c2ecf20Sopenharmony_ci } else { 1928c2ecf20Sopenharmony_ci channelSel = CHANSEL_5G(freq); 1938c2ecf20Sopenharmony_ci /* Doubler is ON, so, divide channelSel by 2. */ 1948c2ecf20Sopenharmony_ci channelSel >>= 1; 1958c2ecf20Sopenharmony_ci } 1968c2ecf20Sopenharmony_ci /* Set to 5G mode */ 1978c2ecf20Sopenharmony_ci bMode = 0; 1988c2ecf20Sopenharmony_ci } 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci /* Enable fractional mode for all channels */ 2018c2ecf20Sopenharmony_ci fracMode = 1; 2028c2ecf20Sopenharmony_ci aModeRefSel = 0; 2038c2ecf20Sopenharmony_ci loadSynthChannel = 0; 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci reg32 = (bMode << 29); 2068c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32); 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci /* Enable Long shift Select for Synthesizer */ 2098c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_SYNTH4, 2108c2ecf20Sopenharmony_ci AR_PHY_SYNTH4_LONG_SHIFT_SELECT, 1); 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci /* Program Synth. setting */ 2138c2ecf20Sopenharmony_ci reg32 = (channelSel << 2) | (fracMode << 30) | 2148c2ecf20Sopenharmony_ci (aModeRefSel << 28) | (loadSynthChannel << 31); 2158c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32); 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci /* Toggle Load Synth channel bit */ 2188c2ecf20Sopenharmony_ci loadSynthChannel = 1; 2198c2ecf20Sopenharmony_ci reg32 = (channelSel << 2) | (fracMode << 30) | 2208c2ecf20Sopenharmony_ci (aModeRefSel << 28) | (loadSynthChannel << 31); 2218c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32); 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci ah->curchan = chan; 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci return 0; 2268c2ecf20Sopenharmony_ci} 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci/** 2298c2ecf20Sopenharmony_ci * ar9003_hw_spur_mitigate_mrc_cck - convert baseband spur frequency 2308c2ecf20Sopenharmony_ci * @ah: atheros hardware structure 2318c2ecf20Sopenharmony_ci * @chan: 2328c2ecf20Sopenharmony_ci * 2338c2ecf20Sopenharmony_ci * For single-chip solutions. Converts to baseband spur frequency given the 2348c2ecf20Sopenharmony_ci * input channel frequency and compute register settings below. 2358c2ecf20Sopenharmony_ci * 2368c2ecf20Sopenharmony_ci * Spur mitigation for MRC CCK 2378c2ecf20Sopenharmony_ci */ 2388c2ecf20Sopenharmony_cistatic void ar9003_hw_spur_mitigate_mrc_cck(struct ath_hw *ah, 2398c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 2408c2ecf20Sopenharmony_ci{ 2418c2ecf20Sopenharmony_ci static const u32 spur_freq[4] = { 2420, 2440, 2464, 2480 }; 2428c2ecf20Sopenharmony_ci int cur_bb_spur, negative = 0, cck_spur_freq; 2438c2ecf20Sopenharmony_ci int i; 2448c2ecf20Sopenharmony_ci int range, max_spur_cnts, synth_freq; 2458c2ecf20Sopenharmony_ci u8 *spur_fbin_ptr = ar9003_get_spur_chan_ptr(ah, IS_CHAN_2GHZ(chan)); 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci /* 2488c2ecf20Sopenharmony_ci * Need to verify range +/- 10 MHz in control channel, otherwise spur 2498c2ecf20Sopenharmony_ci * is out-of-band and can be ignored. 2508c2ecf20Sopenharmony_ci */ 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah) || 2538c2ecf20Sopenharmony_ci AR_SREV_9550(ah) || AR_SREV_9561(ah)) { 2548c2ecf20Sopenharmony_ci if (spur_fbin_ptr[0] == 0) /* No spur */ 2558c2ecf20Sopenharmony_ci return; 2568c2ecf20Sopenharmony_ci max_spur_cnts = 5; 2578c2ecf20Sopenharmony_ci if (IS_CHAN_HT40(chan)) { 2588c2ecf20Sopenharmony_ci range = 19; 2598c2ecf20Sopenharmony_ci if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL, 2608c2ecf20Sopenharmony_ci AR_PHY_GC_DYN2040_PRI_CH) == 0) 2618c2ecf20Sopenharmony_ci synth_freq = chan->channel + 10; 2628c2ecf20Sopenharmony_ci else 2638c2ecf20Sopenharmony_ci synth_freq = chan->channel - 10; 2648c2ecf20Sopenharmony_ci } else { 2658c2ecf20Sopenharmony_ci range = 10; 2668c2ecf20Sopenharmony_ci synth_freq = chan->channel; 2678c2ecf20Sopenharmony_ci } 2688c2ecf20Sopenharmony_ci } else { 2698c2ecf20Sopenharmony_ci range = AR_SREV_9462(ah) ? 5 : 10; 2708c2ecf20Sopenharmony_ci max_spur_cnts = 4; 2718c2ecf20Sopenharmony_ci synth_freq = chan->channel; 2728c2ecf20Sopenharmony_ci } 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci for (i = 0; i < max_spur_cnts; i++) { 2758c2ecf20Sopenharmony_ci if (AR_SREV_9462(ah) && (i == 0 || i == 3)) 2768c2ecf20Sopenharmony_ci continue; 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci negative = 0; 2798c2ecf20Sopenharmony_ci if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah) || 2808c2ecf20Sopenharmony_ci AR_SREV_9550(ah) || AR_SREV_9561(ah)) 2818c2ecf20Sopenharmony_ci cur_bb_spur = ath9k_hw_fbin2freq(spur_fbin_ptr[i], 2828c2ecf20Sopenharmony_ci IS_CHAN_2GHZ(chan)); 2838c2ecf20Sopenharmony_ci else 2848c2ecf20Sopenharmony_ci cur_bb_spur = spur_freq[i]; 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci cur_bb_spur -= synth_freq; 2878c2ecf20Sopenharmony_ci if (cur_bb_spur < 0) { 2888c2ecf20Sopenharmony_ci negative = 1; 2898c2ecf20Sopenharmony_ci cur_bb_spur = -cur_bb_spur; 2908c2ecf20Sopenharmony_ci } 2918c2ecf20Sopenharmony_ci if (cur_bb_spur < range) { 2928c2ecf20Sopenharmony_ci cck_spur_freq = (int)((cur_bb_spur << 19) / 11); 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_ci if (negative == 1) 2958c2ecf20Sopenharmony_ci cck_spur_freq = -cck_spur_freq; 2968c2ecf20Sopenharmony_ci 2978c2ecf20Sopenharmony_ci cck_spur_freq = cck_spur_freq & 0xfffff; 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL, 3008c2ecf20Sopenharmony_ci AR_PHY_AGC_CONTROL_YCOK_MAX, 0x7); 3018c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT, 3028c2ecf20Sopenharmony_ci AR_PHY_CCK_SPUR_MIT_SPUR_RSSI_THR, 0x7f); 3038c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT, 3048c2ecf20Sopenharmony_ci AR_PHY_CCK_SPUR_MIT_SPUR_FILTER_TYPE, 3058c2ecf20Sopenharmony_ci 0x2); 3068c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT, 3078c2ecf20Sopenharmony_ci AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT, 3088c2ecf20Sopenharmony_ci 0x1); 3098c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT, 3108c2ecf20Sopenharmony_ci AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ, 3118c2ecf20Sopenharmony_ci cck_spur_freq); 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci return; 3148c2ecf20Sopenharmony_ci } 3158c2ecf20Sopenharmony_ci } 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL, 3188c2ecf20Sopenharmony_ci AR_PHY_AGC_CONTROL_YCOK_MAX, 0x5); 3198c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT, 3208c2ecf20Sopenharmony_ci AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT, 0x0); 3218c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT, 3228c2ecf20Sopenharmony_ci AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ, 0x0); 3238c2ecf20Sopenharmony_ci} 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci/* Clean all spur register fields */ 3268c2ecf20Sopenharmony_cistatic void ar9003_hw_spur_ofdm_clear(struct ath_hw *ah) 3278c2ecf20Sopenharmony_ci{ 3288c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TIMING4, 3298c2ecf20Sopenharmony_ci AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0); 3308c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TIMING11, 3318c2ecf20Sopenharmony_ci AR_PHY_TIMING11_SPUR_FREQ_SD, 0); 3328c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TIMING11, 3338c2ecf20Sopenharmony_ci AR_PHY_TIMING11_SPUR_DELTA_PHASE, 0); 3348c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT, 3358c2ecf20Sopenharmony_ci AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, 0); 3368c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TIMING11, 3378c2ecf20Sopenharmony_ci AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0); 3388c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TIMING11, 3398c2ecf20Sopenharmony_ci AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0); 3408c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TIMING4, 3418c2ecf20Sopenharmony_ci AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0); 3428c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SPUR_REG, 3438c2ecf20Sopenharmony_ci AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 0); 3448c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SPUR_REG, 3458c2ecf20Sopenharmony_ci AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 0); 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SPUR_REG, 3488c2ecf20Sopenharmony_ci AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0); 3498c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TIMING4, 3508c2ecf20Sopenharmony_ci AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0); 3518c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TIMING4, 3528c2ecf20Sopenharmony_ci AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0); 3538c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK, 3548c2ecf20Sopenharmony_ci AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, 0); 3558c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A, 3568c2ecf20Sopenharmony_ci AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, 0); 3578c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK, 3588c2ecf20Sopenharmony_ci AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, 0); 3598c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK, 3608c2ecf20Sopenharmony_ci AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0); 3618c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK, 3628c2ecf20Sopenharmony_ci AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0); 3638c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A, 3648c2ecf20Sopenharmony_ci AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0); 3658c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SPUR_REG, 3668c2ecf20Sopenharmony_ci AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0); 3678c2ecf20Sopenharmony_ci} 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_cistatic void ar9003_hw_spur_ofdm(struct ath_hw *ah, 3708c2ecf20Sopenharmony_ci int freq_offset, 3718c2ecf20Sopenharmony_ci int spur_freq_sd, 3728c2ecf20Sopenharmony_ci int spur_delta_phase, 3738c2ecf20Sopenharmony_ci int spur_subchannel_sd, 3748c2ecf20Sopenharmony_ci int range, 3758c2ecf20Sopenharmony_ci int synth_freq) 3768c2ecf20Sopenharmony_ci{ 3778c2ecf20Sopenharmony_ci int mask_index = 0; 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_ci /* OFDM Spur mitigation */ 3808c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TIMING4, 3818c2ecf20Sopenharmony_ci AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0x1); 3828c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TIMING11, 3838c2ecf20Sopenharmony_ci AR_PHY_TIMING11_SPUR_FREQ_SD, spur_freq_sd); 3848c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TIMING11, 3858c2ecf20Sopenharmony_ci AR_PHY_TIMING11_SPUR_DELTA_PHASE, spur_delta_phase); 3868c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT, 3878c2ecf20Sopenharmony_ci AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, spur_subchannel_sd); 3888c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TIMING11, 3898c2ecf20Sopenharmony_ci AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0x1); 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci if (!(AR_SREV_9565(ah) && range == 10 && synth_freq == 2437)) 3928c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TIMING11, 3938c2ecf20Sopenharmony_ci AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0x1); 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TIMING4, 3968c2ecf20Sopenharmony_ci AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0x1); 3978c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SPUR_REG, 3988c2ecf20Sopenharmony_ci AR_PHY_SPUR_REG_SPUR_RSSI_THRESH, 34); 3998c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SPUR_REG, 4008c2ecf20Sopenharmony_ci AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 1); 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_ci if (!AR_SREV_9340(ah) && 4038c2ecf20Sopenharmony_ci REG_READ_FIELD(ah, AR_PHY_MODE, 4048c2ecf20Sopenharmony_ci AR_PHY_MODE_DYNAMIC) == 0x1) 4058c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SPUR_REG, 4068c2ecf20Sopenharmony_ci AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 1); 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_ci mask_index = (freq_offset << 4) / 5; 4098c2ecf20Sopenharmony_ci if (mask_index < 0) 4108c2ecf20Sopenharmony_ci mask_index = mask_index - 1; 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ci mask_index = mask_index & 0x7f; 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SPUR_REG, 4158c2ecf20Sopenharmony_ci AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0x1); 4168c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TIMING4, 4178c2ecf20Sopenharmony_ci AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0x1); 4188c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TIMING4, 4198c2ecf20Sopenharmony_ci AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0x1); 4208c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK, 4218c2ecf20Sopenharmony_ci AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, mask_index); 4228c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A, 4238c2ecf20Sopenharmony_ci AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, mask_index); 4248c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK, 4258c2ecf20Sopenharmony_ci AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, mask_index); 4268c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK, 4278c2ecf20Sopenharmony_ci AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0xc); 4288c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK, 4298c2ecf20Sopenharmony_ci AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0xc); 4308c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A, 4318c2ecf20Sopenharmony_ci AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0xa0); 4328c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SPUR_REG, 4338c2ecf20Sopenharmony_ci AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0xff); 4348c2ecf20Sopenharmony_ci} 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_cistatic void ar9003_hw_spur_ofdm_9565(struct ath_hw *ah, 4378c2ecf20Sopenharmony_ci int freq_offset) 4388c2ecf20Sopenharmony_ci{ 4398c2ecf20Sopenharmony_ci int mask_index = 0; 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ci mask_index = (freq_offset << 4) / 5; 4428c2ecf20Sopenharmony_ci if (mask_index < 0) 4438c2ecf20Sopenharmony_ci mask_index = mask_index - 1; 4448c2ecf20Sopenharmony_ci 4458c2ecf20Sopenharmony_ci mask_index = mask_index & 0x7f; 4468c2ecf20Sopenharmony_ci 4478c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK, 4488c2ecf20Sopenharmony_ci AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_B, 4498c2ecf20Sopenharmony_ci mask_index); 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_ci /* A == B */ 4528c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_B, 4538c2ecf20Sopenharmony_ci AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, 4548c2ecf20Sopenharmony_ci mask_index); 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK, 4578c2ecf20Sopenharmony_ci AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_B, 4588c2ecf20Sopenharmony_ci mask_index); 4598c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK, 4608c2ecf20Sopenharmony_ci AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_B, 0xe); 4618c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK, 4628c2ecf20Sopenharmony_ci AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_B, 0xe); 4638c2ecf20Sopenharmony_ci 4648c2ecf20Sopenharmony_ci /* A == B */ 4658c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_B, 4668c2ecf20Sopenharmony_ci AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0xa0); 4678c2ecf20Sopenharmony_ci} 4688c2ecf20Sopenharmony_ci 4698c2ecf20Sopenharmony_cistatic void ar9003_hw_spur_ofdm_work(struct ath_hw *ah, 4708c2ecf20Sopenharmony_ci struct ath9k_channel *chan, 4718c2ecf20Sopenharmony_ci int freq_offset, 4728c2ecf20Sopenharmony_ci int range, 4738c2ecf20Sopenharmony_ci int synth_freq) 4748c2ecf20Sopenharmony_ci{ 4758c2ecf20Sopenharmony_ci int spur_freq_sd = 0; 4768c2ecf20Sopenharmony_ci int spur_subchannel_sd = 0; 4778c2ecf20Sopenharmony_ci int spur_delta_phase = 0; 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_ci if (IS_CHAN_HT40(chan)) { 4808c2ecf20Sopenharmony_ci if (freq_offset < 0) { 4818c2ecf20Sopenharmony_ci if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL, 4828c2ecf20Sopenharmony_ci AR_PHY_GC_DYN2040_PRI_CH) == 0x0) 4838c2ecf20Sopenharmony_ci spur_subchannel_sd = 1; 4848c2ecf20Sopenharmony_ci else 4858c2ecf20Sopenharmony_ci spur_subchannel_sd = 0; 4868c2ecf20Sopenharmony_ci 4878c2ecf20Sopenharmony_ci spur_freq_sd = ((freq_offset + 10) << 9) / 11; 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_ci } else { 4908c2ecf20Sopenharmony_ci if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL, 4918c2ecf20Sopenharmony_ci AR_PHY_GC_DYN2040_PRI_CH) == 0x0) 4928c2ecf20Sopenharmony_ci spur_subchannel_sd = 0; 4938c2ecf20Sopenharmony_ci else 4948c2ecf20Sopenharmony_ci spur_subchannel_sd = 1; 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_ci spur_freq_sd = ((freq_offset - 10) << 9) / 11; 4978c2ecf20Sopenharmony_ci 4988c2ecf20Sopenharmony_ci } 4998c2ecf20Sopenharmony_ci 5008c2ecf20Sopenharmony_ci spur_delta_phase = (freq_offset << 17) / 5; 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_ci } else { 5038c2ecf20Sopenharmony_ci spur_subchannel_sd = 0; 5048c2ecf20Sopenharmony_ci spur_freq_sd = (freq_offset << 9) /11; 5058c2ecf20Sopenharmony_ci spur_delta_phase = (freq_offset << 18) / 5; 5068c2ecf20Sopenharmony_ci } 5078c2ecf20Sopenharmony_ci 5088c2ecf20Sopenharmony_ci spur_freq_sd = spur_freq_sd & 0x3ff; 5098c2ecf20Sopenharmony_ci spur_delta_phase = spur_delta_phase & 0xfffff; 5108c2ecf20Sopenharmony_ci 5118c2ecf20Sopenharmony_ci ar9003_hw_spur_ofdm(ah, 5128c2ecf20Sopenharmony_ci freq_offset, 5138c2ecf20Sopenharmony_ci spur_freq_sd, 5148c2ecf20Sopenharmony_ci spur_delta_phase, 5158c2ecf20Sopenharmony_ci spur_subchannel_sd, 5168c2ecf20Sopenharmony_ci range, synth_freq); 5178c2ecf20Sopenharmony_ci} 5188c2ecf20Sopenharmony_ci 5198c2ecf20Sopenharmony_ci/* Spur mitigation for OFDM */ 5208c2ecf20Sopenharmony_cistatic void ar9003_hw_spur_mitigate_ofdm(struct ath_hw *ah, 5218c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 5228c2ecf20Sopenharmony_ci{ 5238c2ecf20Sopenharmony_ci int synth_freq; 5248c2ecf20Sopenharmony_ci int range = 10; 5258c2ecf20Sopenharmony_ci int freq_offset = 0; 5268c2ecf20Sopenharmony_ci int mode; 5278c2ecf20Sopenharmony_ci u8* spurChansPtr; 5288c2ecf20Sopenharmony_ci unsigned int i; 5298c2ecf20Sopenharmony_ci struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep; 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_ci if (IS_CHAN_5GHZ(chan)) { 5328c2ecf20Sopenharmony_ci spurChansPtr = &(eep->modalHeader5G.spurChans[0]); 5338c2ecf20Sopenharmony_ci mode = 0; 5348c2ecf20Sopenharmony_ci } 5358c2ecf20Sopenharmony_ci else { 5368c2ecf20Sopenharmony_ci spurChansPtr = &(eep->modalHeader2G.spurChans[0]); 5378c2ecf20Sopenharmony_ci mode = 1; 5388c2ecf20Sopenharmony_ci } 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_ci if (spurChansPtr[0] == 0) 5418c2ecf20Sopenharmony_ci return; /* No spur in the mode */ 5428c2ecf20Sopenharmony_ci 5438c2ecf20Sopenharmony_ci if (IS_CHAN_HT40(chan)) { 5448c2ecf20Sopenharmony_ci range = 19; 5458c2ecf20Sopenharmony_ci if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL, 5468c2ecf20Sopenharmony_ci AR_PHY_GC_DYN2040_PRI_CH) == 0x0) 5478c2ecf20Sopenharmony_ci synth_freq = chan->channel - 10; 5488c2ecf20Sopenharmony_ci else 5498c2ecf20Sopenharmony_ci synth_freq = chan->channel + 10; 5508c2ecf20Sopenharmony_ci } else { 5518c2ecf20Sopenharmony_ci range = 10; 5528c2ecf20Sopenharmony_ci synth_freq = chan->channel; 5538c2ecf20Sopenharmony_ci } 5548c2ecf20Sopenharmony_ci 5558c2ecf20Sopenharmony_ci ar9003_hw_spur_ofdm_clear(ah); 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_ci for (i = 0; i < AR_EEPROM_MODAL_SPURS && spurChansPtr[i]; i++) { 5588c2ecf20Sopenharmony_ci freq_offset = ath9k_hw_fbin2freq(spurChansPtr[i], mode); 5598c2ecf20Sopenharmony_ci freq_offset -= synth_freq; 5608c2ecf20Sopenharmony_ci if (abs(freq_offset) < range) { 5618c2ecf20Sopenharmony_ci ar9003_hw_spur_ofdm_work(ah, chan, freq_offset, 5628c2ecf20Sopenharmony_ci range, synth_freq); 5638c2ecf20Sopenharmony_ci 5648c2ecf20Sopenharmony_ci if (AR_SREV_9565(ah) && (i < 4)) { 5658c2ecf20Sopenharmony_ci freq_offset = ath9k_hw_fbin2freq(spurChansPtr[i + 1], 5668c2ecf20Sopenharmony_ci mode); 5678c2ecf20Sopenharmony_ci freq_offset -= synth_freq; 5688c2ecf20Sopenharmony_ci if (abs(freq_offset) < range) 5698c2ecf20Sopenharmony_ci ar9003_hw_spur_ofdm_9565(ah, freq_offset); 5708c2ecf20Sopenharmony_ci } 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ci break; 5738c2ecf20Sopenharmony_ci } 5748c2ecf20Sopenharmony_ci } 5758c2ecf20Sopenharmony_ci} 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_cistatic void ar9003_hw_spur_mitigate(struct ath_hw *ah, 5788c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 5798c2ecf20Sopenharmony_ci{ 5808c2ecf20Sopenharmony_ci if (!AR_SREV_9565(ah)) 5818c2ecf20Sopenharmony_ci ar9003_hw_spur_mitigate_mrc_cck(ah, chan); 5828c2ecf20Sopenharmony_ci ar9003_hw_spur_mitigate_ofdm(ah, chan); 5838c2ecf20Sopenharmony_ci} 5848c2ecf20Sopenharmony_ci 5858c2ecf20Sopenharmony_cistatic u32 ar9003_hw_compute_pll_control_soc(struct ath_hw *ah, 5868c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 5878c2ecf20Sopenharmony_ci{ 5888c2ecf20Sopenharmony_ci u32 pll; 5898c2ecf20Sopenharmony_ci 5908c2ecf20Sopenharmony_ci pll = SM(0x5, AR_RTC_9300_SOC_PLL_REFDIV); 5918c2ecf20Sopenharmony_ci 5928c2ecf20Sopenharmony_ci if (chan && IS_CHAN_HALF_RATE(chan)) 5938c2ecf20Sopenharmony_ci pll |= SM(0x1, AR_RTC_9300_SOC_PLL_CLKSEL); 5948c2ecf20Sopenharmony_ci else if (chan && IS_CHAN_QUARTER_RATE(chan)) 5958c2ecf20Sopenharmony_ci pll |= SM(0x2, AR_RTC_9300_SOC_PLL_CLKSEL); 5968c2ecf20Sopenharmony_ci 5978c2ecf20Sopenharmony_ci pll |= SM(0x2c, AR_RTC_9300_SOC_PLL_DIV_INT); 5988c2ecf20Sopenharmony_ci 5998c2ecf20Sopenharmony_ci return pll; 6008c2ecf20Sopenharmony_ci} 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_cistatic u32 ar9003_hw_compute_pll_control(struct ath_hw *ah, 6038c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 6048c2ecf20Sopenharmony_ci{ 6058c2ecf20Sopenharmony_ci u32 pll; 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_ci pll = SM(0x5, AR_RTC_9300_PLL_REFDIV); 6088c2ecf20Sopenharmony_ci 6098c2ecf20Sopenharmony_ci if (chan && IS_CHAN_HALF_RATE(chan)) 6108c2ecf20Sopenharmony_ci pll |= SM(0x1, AR_RTC_9300_PLL_CLKSEL); 6118c2ecf20Sopenharmony_ci else if (chan && IS_CHAN_QUARTER_RATE(chan)) 6128c2ecf20Sopenharmony_ci pll |= SM(0x2, AR_RTC_9300_PLL_CLKSEL); 6138c2ecf20Sopenharmony_ci 6148c2ecf20Sopenharmony_ci pll |= SM(0x2c, AR_RTC_9300_PLL_DIV); 6158c2ecf20Sopenharmony_ci 6168c2ecf20Sopenharmony_ci return pll; 6178c2ecf20Sopenharmony_ci} 6188c2ecf20Sopenharmony_ci 6198c2ecf20Sopenharmony_cistatic void ar9003_hw_set_channel_regs(struct ath_hw *ah, 6208c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 6218c2ecf20Sopenharmony_ci{ 6228c2ecf20Sopenharmony_ci u32 phymode; 6238c2ecf20Sopenharmony_ci u32 enableDacFifo = 0; 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_ci enableDacFifo = 6268c2ecf20Sopenharmony_ci (REG_READ(ah, AR_PHY_GEN_CTRL) & AR_PHY_GC_ENABLE_DAC_FIFO); 6278c2ecf20Sopenharmony_ci 6288c2ecf20Sopenharmony_ci /* Enable 11n HT, 20 MHz */ 6298c2ecf20Sopenharmony_ci phymode = AR_PHY_GC_HT_EN | AR_PHY_GC_SHORT_GI_40 | enableDacFifo; 6308c2ecf20Sopenharmony_ci 6318c2ecf20Sopenharmony_ci if (!AR_SREV_9561(ah)) 6328c2ecf20Sopenharmony_ci phymode |= AR_PHY_GC_SINGLE_HT_LTF1; 6338c2ecf20Sopenharmony_ci 6348c2ecf20Sopenharmony_ci /* Configure baseband for dynamic 20/40 operation */ 6358c2ecf20Sopenharmony_ci if (IS_CHAN_HT40(chan)) { 6368c2ecf20Sopenharmony_ci phymode |= AR_PHY_GC_DYN2040_EN; 6378c2ecf20Sopenharmony_ci /* Configure control (primary) channel at +-10MHz */ 6388c2ecf20Sopenharmony_ci if (IS_CHAN_HT40PLUS(chan)) 6398c2ecf20Sopenharmony_ci phymode |= AR_PHY_GC_DYN2040_PRI_CH; 6408c2ecf20Sopenharmony_ci 6418c2ecf20Sopenharmony_ci } 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_ci /* make sure we preserve INI settings */ 6448c2ecf20Sopenharmony_ci phymode |= REG_READ(ah, AR_PHY_GEN_CTRL); 6458c2ecf20Sopenharmony_ci /* turn off Green Field detection for STA for now */ 6468c2ecf20Sopenharmony_ci phymode &= ~AR_PHY_GC_GF_DETECT_EN; 6478c2ecf20Sopenharmony_ci 6488c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_GEN_CTRL, phymode); 6498c2ecf20Sopenharmony_ci 6508c2ecf20Sopenharmony_ci /* Configure MAC for 20/40 operation */ 6518c2ecf20Sopenharmony_ci ath9k_hw_set11nmac2040(ah, chan); 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ci /* global transmit timeout (25 TUs default)*/ 6548c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S); 6558c2ecf20Sopenharmony_ci /* carrier sense timeout */ 6568c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S); 6578c2ecf20Sopenharmony_ci} 6588c2ecf20Sopenharmony_ci 6598c2ecf20Sopenharmony_cistatic void ar9003_hw_init_bb(struct ath_hw *ah, 6608c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 6618c2ecf20Sopenharmony_ci{ 6628c2ecf20Sopenharmony_ci u32 synthDelay; 6638c2ecf20Sopenharmony_ci 6648c2ecf20Sopenharmony_ci /* 6658c2ecf20Sopenharmony_ci * Wait for the frequency synth to settle (synth goes on 6668c2ecf20Sopenharmony_ci * via AR_PHY_ACTIVE_EN). Read the phy active delay register. 6678c2ecf20Sopenharmony_ci * Value is in 100ns increments. 6688c2ecf20Sopenharmony_ci */ 6698c2ecf20Sopenharmony_ci synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY; 6708c2ecf20Sopenharmony_ci 6718c2ecf20Sopenharmony_ci /* Activate the PHY (includes baseband activate + synthesizer on) */ 6728c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN); 6738c2ecf20Sopenharmony_ci ath9k_hw_synth_delay(ah, chan, synthDelay); 6748c2ecf20Sopenharmony_ci} 6758c2ecf20Sopenharmony_ci 6768c2ecf20Sopenharmony_civoid ar9003_hw_set_chain_masks(struct ath_hw *ah, u8 rx, u8 tx) 6778c2ecf20Sopenharmony_ci{ 6788c2ecf20Sopenharmony_ci if (ah->caps.tx_chainmask == 5 || ah->caps.rx_chainmask == 5) 6798c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP, 6808c2ecf20Sopenharmony_ci AR_PHY_SWAP_ALT_CHAIN); 6818c2ecf20Sopenharmony_ci 6828c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx); 6838c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx); 6848c2ecf20Sopenharmony_ci 6858c2ecf20Sopenharmony_ci if ((ah->caps.hw_caps & ATH9K_HW_CAP_APM) && (tx == 0x7)) 6868c2ecf20Sopenharmony_ci tx = 3; 6878c2ecf20Sopenharmony_ci 6888c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_SELFGEN_MASK, tx); 6898c2ecf20Sopenharmony_ci} 6908c2ecf20Sopenharmony_ci 6918c2ecf20Sopenharmony_ci/* 6928c2ecf20Sopenharmony_ci * Override INI values with chip specific configuration. 6938c2ecf20Sopenharmony_ci */ 6948c2ecf20Sopenharmony_cistatic void ar9003_hw_override_ini(struct ath_hw *ah) 6958c2ecf20Sopenharmony_ci{ 6968c2ecf20Sopenharmony_ci u32 val; 6978c2ecf20Sopenharmony_ci 6988c2ecf20Sopenharmony_ci /* 6998c2ecf20Sopenharmony_ci * Set the RX_ABORT and RX_DIS and clear it only after 7008c2ecf20Sopenharmony_ci * RXE is set for MAC. This prevents frames with 7018c2ecf20Sopenharmony_ci * corrupted descriptor status. 7028c2ecf20Sopenharmony_ci */ 7038c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT)); 7048c2ecf20Sopenharmony_ci 7058c2ecf20Sopenharmony_ci /* 7068c2ecf20Sopenharmony_ci * For AR9280 and above, there is a new feature that allows 7078c2ecf20Sopenharmony_ci * Multicast search based on both MAC Address and Key ID. By default, 7088c2ecf20Sopenharmony_ci * this feature is enabled. But since the driver is not using this 7098c2ecf20Sopenharmony_ci * feature, we switch it off; otherwise multicast search based on 7108c2ecf20Sopenharmony_ci * MAC addr only will fail. 7118c2ecf20Sopenharmony_ci */ 7128c2ecf20Sopenharmony_ci val = REG_READ(ah, AR_PCU_MISC_MODE2) & (~AR_ADHOC_MCAST_KEYID_ENABLE); 7138c2ecf20Sopenharmony_ci val |= AR_AGG_WEP_ENABLE_FIX | 7148c2ecf20Sopenharmony_ci AR_AGG_WEP_ENABLE | 7158c2ecf20Sopenharmony_ci AR_PCU_MISC_MODE2_CFP_IGNORE; 7168c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PCU_MISC_MODE2, val); 7178c2ecf20Sopenharmony_ci 7188c2ecf20Sopenharmony_ci if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) { 7198c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_GLB_SWREG_DISCONT_MODE, 7208c2ecf20Sopenharmony_ci AR_GLB_SWREG_DISCONT_EN_BT_WLAN); 7218c2ecf20Sopenharmony_ci 7228c2ecf20Sopenharmony_ci if (REG_READ_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_0, 7238c2ecf20Sopenharmony_ci AR_PHY_TX_IQCAL_CONTROL_0_ENABLE_TXIQ_CAL)) 7248c2ecf20Sopenharmony_ci ah->enabled_cals |= TX_IQ_CAL; 7258c2ecf20Sopenharmony_ci else 7268c2ecf20Sopenharmony_ci ah->enabled_cals &= ~TX_IQ_CAL; 7278c2ecf20Sopenharmony_ci 7288c2ecf20Sopenharmony_ci } 7298c2ecf20Sopenharmony_ci 7308c2ecf20Sopenharmony_ci if (REG_READ(ah, AR_PHY_CL_CAL_CTL) & AR_PHY_CL_CAL_ENABLE) 7318c2ecf20Sopenharmony_ci ah->enabled_cals |= TX_CL_CAL; 7328c2ecf20Sopenharmony_ci else 7338c2ecf20Sopenharmony_ci ah->enabled_cals &= ~TX_CL_CAL; 7348c2ecf20Sopenharmony_ci 7358c2ecf20Sopenharmony_ci if (AR_SREV_9340(ah) || AR_SREV_9531(ah) || AR_SREV_9550(ah) || 7368c2ecf20Sopenharmony_ci AR_SREV_9561(ah)) { 7378c2ecf20Sopenharmony_ci if (ah->is_clk_25mhz) { 7388c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x17c << 1); 7398c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_SLP32_MODE, 0x0010f3d7); 7408c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_SLP32_INC, 0x0001e7ae); 7418c2ecf20Sopenharmony_ci } else { 7428c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x261 << 1); 7438c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_SLP32_MODE, 0x0010f400); 7448c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_SLP32_INC, 0x0001e800); 7458c2ecf20Sopenharmony_ci } 7468c2ecf20Sopenharmony_ci udelay(100); 7478c2ecf20Sopenharmony_ci } 7488c2ecf20Sopenharmony_ci} 7498c2ecf20Sopenharmony_ci 7508c2ecf20Sopenharmony_cistatic void ar9003_hw_prog_ini(struct ath_hw *ah, 7518c2ecf20Sopenharmony_ci struct ar5416IniArray *iniArr, 7528c2ecf20Sopenharmony_ci int column) 7538c2ecf20Sopenharmony_ci{ 7548c2ecf20Sopenharmony_ci unsigned int i, regWrites = 0; 7558c2ecf20Sopenharmony_ci 7568c2ecf20Sopenharmony_ci /* New INI format: Array may be undefined (pre, core, post arrays) */ 7578c2ecf20Sopenharmony_ci if (!iniArr->ia_array) 7588c2ecf20Sopenharmony_ci return; 7598c2ecf20Sopenharmony_ci 7608c2ecf20Sopenharmony_ci /* 7618c2ecf20Sopenharmony_ci * New INI format: Pre, core, and post arrays for a given subsystem 7628c2ecf20Sopenharmony_ci * may be modal (> 2 columns) or non-modal (2 columns). Determine if 7638c2ecf20Sopenharmony_ci * the array is non-modal and force the column to 1. 7648c2ecf20Sopenharmony_ci */ 7658c2ecf20Sopenharmony_ci if (column >= iniArr->ia_columns) 7668c2ecf20Sopenharmony_ci column = 1; 7678c2ecf20Sopenharmony_ci 7688c2ecf20Sopenharmony_ci for (i = 0; i < iniArr->ia_rows; i++) { 7698c2ecf20Sopenharmony_ci u32 reg = INI_RA(iniArr, i, 0); 7708c2ecf20Sopenharmony_ci u32 val = INI_RA(iniArr, i, column); 7718c2ecf20Sopenharmony_ci 7728c2ecf20Sopenharmony_ci REG_WRITE(ah, reg, val); 7738c2ecf20Sopenharmony_ci 7748c2ecf20Sopenharmony_ci DO_DELAY(regWrites); 7758c2ecf20Sopenharmony_ci } 7768c2ecf20Sopenharmony_ci} 7778c2ecf20Sopenharmony_ci 7788c2ecf20Sopenharmony_cistatic int ar9550_hw_get_modes_txgain_index(struct ath_hw *ah, 7798c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 7808c2ecf20Sopenharmony_ci{ 7818c2ecf20Sopenharmony_ci int ret; 7828c2ecf20Sopenharmony_ci 7838c2ecf20Sopenharmony_ci if (IS_CHAN_2GHZ(chan)) { 7848c2ecf20Sopenharmony_ci if (IS_CHAN_HT40(chan)) 7858c2ecf20Sopenharmony_ci return 7; 7868c2ecf20Sopenharmony_ci else 7878c2ecf20Sopenharmony_ci return 8; 7888c2ecf20Sopenharmony_ci } 7898c2ecf20Sopenharmony_ci 7908c2ecf20Sopenharmony_ci if (chan->channel <= 5350) 7918c2ecf20Sopenharmony_ci ret = 1; 7928c2ecf20Sopenharmony_ci else if ((chan->channel > 5350) && (chan->channel <= 5600)) 7938c2ecf20Sopenharmony_ci ret = 3; 7948c2ecf20Sopenharmony_ci else 7958c2ecf20Sopenharmony_ci ret = 5; 7968c2ecf20Sopenharmony_ci 7978c2ecf20Sopenharmony_ci if (IS_CHAN_HT40(chan)) 7988c2ecf20Sopenharmony_ci ret++; 7998c2ecf20Sopenharmony_ci 8008c2ecf20Sopenharmony_ci return ret; 8018c2ecf20Sopenharmony_ci} 8028c2ecf20Sopenharmony_ci 8038c2ecf20Sopenharmony_cistatic int ar9561_hw_get_modes_txgain_index(struct ath_hw *ah, 8048c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 8058c2ecf20Sopenharmony_ci{ 8068c2ecf20Sopenharmony_ci if (IS_CHAN_2GHZ(chan)) { 8078c2ecf20Sopenharmony_ci if (IS_CHAN_HT40(chan)) 8088c2ecf20Sopenharmony_ci return 1; 8098c2ecf20Sopenharmony_ci else 8108c2ecf20Sopenharmony_ci return 2; 8118c2ecf20Sopenharmony_ci } 8128c2ecf20Sopenharmony_ci 8138c2ecf20Sopenharmony_ci return 0; 8148c2ecf20Sopenharmony_ci} 8158c2ecf20Sopenharmony_ci 8168c2ecf20Sopenharmony_cistatic void ar9003_doubler_fix(struct ath_hw *ah) 8178c2ecf20Sopenharmony_ci{ 8188c2ecf20Sopenharmony_ci if (AR_SREV_9300(ah) || AR_SREV_9580(ah) || AR_SREV_9550(ah)) { 8198c2ecf20Sopenharmony_ci REG_RMW(ah, AR_PHY_65NM_CH0_RXTX2, 8208c2ecf20Sopenharmony_ci 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S | 8218c2ecf20Sopenharmony_ci 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S, 0); 8228c2ecf20Sopenharmony_ci REG_RMW(ah, AR_PHY_65NM_CH1_RXTX2, 8238c2ecf20Sopenharmony_ci 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S | 8248c2ecf20Sopenharmony_ci 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S, 0); 8258c2ecf20Sopenharmony_ci REG_RMW(ah, AR_PHY_65NM_CH2_RXTX2, 8268c2ecf20Sopenharmony_ci 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S | 8278c2ecf20Sopenharmony_ci 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S, 0); 8288c2ecf20Sopenharmony_ci 8298c2ecf20Sopenharmony_ci udelay(200); 8308c2ecf20Sopenharmony_ci 8318c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_PHY_65NM_CH0_RXTX2, 8328c2ecf20Sopenharmony_ci AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK); 8338c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_PHY_65NM_CH1_RXTX2, 8348c2ecf20Sopenharmony_ci AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK); 8358c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_PHY_65NM_CH2_RXTX2, 8368c2ecf20Sopenharmony_ci AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK); 8378c2ecf20Sopenharmony_ci 8388c2ecf20Sopenharmony_ci udelay(1); 8398c2ecf20Sopenharmony_ci 8408c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_RXTX2, 8418c2ecf20Sopenharmony_ci AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK, 1); 8428c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_65NM_CH1_RXTX2, 8438c2ecf20Sopenharmony_ci AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK, 1); 8448c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX2, 8458c2ecf20Sopenharmony_ci AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK, 1); 8468c2ecf20Sopenharmony_ci 8478c2ecf20Sopenharmony_ci udelay(200); 8488c2ecf20Sopenharmony_ci 8498c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_SYNTH12, 8508c2ecf20Sopenharmony_ci AR_PHY_65NM_CH0_SYNTH12_VREFMUL3, 0xf); 8518c2ecf20Sopenharmony_ci 8528c2ecf20Sopenharmony_ci REG_RMW(ah, AR_PHY_65NM_CH0_RXTX2, 0, 8538c2ecf20Sopenharmony_ci 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S | 8548c2ecf20Sopenharmony_ci 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S); 8558c2ecf20Sopenharmony_ci REG_RMW(ah, AR_PHY_65NM_CH1_RXTX2, 0, 8568c2ecf20Sopenharmony_ci 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S | 8578c2ecf20Sopenharmony_ci 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S); 8588c2ecf20Sopenharmony_ci REG_RMW(ah, AR_PHY_65NM_CH2_RXTX2, 0, 8598c2ecf20Sopenharmony_ci 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S | 8608c2ecf20Sopenharmony_ci 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S); 8618c2ecf20Sopenharmony_ci } 8628c2ecf20Sopenharmony_ci} 8638c2ecf20Sopenharmony_ci 8648c2ecf20Sopenharmony_cistatic int ar9003_hw_process_ini(struct ath_hw *ah, 8658c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 8668c2ecf20Sopenharmony_ci{ 8678c2ecf20Sopenharmony_ci unsigned int regWrites = 0, i; 8688c2ecf20Sopenharmony_ci u32 modesIndex; 8698c2ecf20Sopenharmony_ci 8708c2ecf20Sopenharmony_ci if (IS_CHAN_5GHZ(chan)) 8718c2ecf20Sopenharmony_ci modesIndex = IS_CHAN_HT40(chan) ? 2 : 1; 8728c2ecf20Sopenharmony_ci else 8738c2ecf20Sopenharmony_ci modesIndex = IS_CHAN_HT40(chan) ? 3 : 4; 8748c2ecf20Sopenharmony_ci 8758c2ecf20Sopenharmony_ci /* 8768c2ecf20Sopenharmony_ci * SOC, MAC, BB, RADIO initvals. 8778c2ecf20Sopenharmony_ci */ 8788c2ecf20Sopenharmony_ci for (i = 0; i < ATH_INI_NUM_SPLIT; i++) { 8798c2ecf20Sopenharmony_ci ar9003_hw_prog_ini(ah, &ah->iniSOC[i], modesIndex); 8808c2ecf20Sopenharmony_ci ar9003_hw_prog_ini(ah, &ah->iniMac[i], modesIndex); 8818c2ecf20Sopenharmony_ci ar9003_hw_prog_ini(ah, &ah->iniBB[i], modesIndex); 8828c2ecf20Sopenharmony_ci ar9003_hw_prog_ini(ah, &ah->iniRadio[i], modesIndex); 8838c2ecf20Sopenharmony_ci if (i == ATH_INI_POST && AR_SREV_9462_20_OR_LATER(ah)) 8848c2ecf20Sopenharmony_ci ar9003_hw_prog_ini(ah, 8858c2ecf20Sopenharmony_ci &ah->ini_radio_post_sys2ant, 8868c2ecf20Sopenharmony_ci modesIndex); 8878c2ecf20Sopenharmony_ci } 8888c2ecf20Sopenharmony_ci 8898c2ecf20Sopenharmony_ci ar9003_doubler_fix(ah); 8908c2ecf20Sopenharmony_ci 8918c2ecf20Sopenharmony_ci /* 8928c2ecf20Sopenharmony_ci * RXGAIN initvals. 8938c2ecf20Sopenharmony_ci */ 8948c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&ah->iniModesRxGain, 1, regWrites); 8958c2ecf20Sopenharmony_ci 8968c2ecf20Sopenharmony_ci if (AR_SREV_9462_20_OR_LATER(ah)) { 8978c2ecf20Sopenharmony_ci /* 8988c2ecf20Sopenharmony_ci * CUS217 mix LNA mode. 8998c2ecf20Sopenharmony_ci */ 9008c2ecf20Sopenharmony_ci if (ar9003_hw_get_rx_gain_idx(ah) == 2) { 9018c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&ah->ini_modes_rxgain_bb_core, 9028c2ecf20Sopenharmony_ci 1, regWrites); 9038c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&ah->ini_modes_rxgain_bb_postamble, 9048c2ecf20Sopenharmony_ci modesIndex, regWrites); 9058c2ecf20Sopenharmony_ci } 9068c2ecf20Sopenharmony_ci 9078c2ecf20Sopenharmony_ci /* 9088c2ecf20Sopenharmony_ci * 5G-XLNA 9098c2ecf20Sopenharmony_ci */ 9108c2ecf20Sopenharmony_ci if ((ar9003_hw_get_rx_gain_idx(ah) == 2) || 9118c2ecf20Sopenharmony_ci (ar9003_hw_get_rx_gain_idx(ah) == 3)) { 9128c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&ah->ini_modes_rxgain_xlna, 9138c2ecf20Sopenharmony_ci modesIndex, regWrites); 9148c2ecf20Sopenharmony_ci } 9158c2ecf20Sopenharmony_ci } 9168c2ecf20Sopenharmony_ci 9178c2ecf20Sopenharmony_ci if (AR_SREV_9550(ah) || AR_SREV_9561(ah)) 9188c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&ah->ini_modes_rx_gain_bounds, modesIndex, 9198c2ecf20Sopenharmony_ci regWrites); 9208c2ecf20Sopenharmony_ci 9218c2ecf20Sopenharmony_ci if (AR_SREV_9561(ah) && (ar9003_hw_get_rx_gain_idx(ah) == 0)) 9228c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&ah->ini_modes_rxgain_xlna, 9238c2ecf20Sopenharmony_ci modesIndex, regWrites); 9248c2ecf20Sopenharmony_ci /* 9258c2ecf20Sopenharmony_ci * TXGAIN initvals. 9268c2ecf20Sopenharmony_ci */ 9278c2ecf20Sopenharmony_ci if (AR_SREV_9550(ah) || AR_SREV_9531(ah) || AR_SREV_9561(ah)) { 9288c2ecf20Sopenharmony_ci int modes_txgain_index = 1; 9298c2ecf20Sopenharmony_ci 9308c2ecf20Sopenharmony_ci if (AR_SREV_9550(ah)) 9318c2ecf20Sopenharmony_ci modes_txgain_index = ar9550_hw_get_modes_txgain_index(ah, chan); 9328c2ecf20Sopenharmony_ci 9338c2ecf20Sopenharmony_ci if (AR_SREV_9561(ah)) 9348c2ecf20Sopenharmony_ci modes_txgain_index = 9358c2ecf20Sopenharmony_ci ar9561_hw_get_modes_txgain_index(ah, chan); 9368c2ecf20Sopenharmony_ci 9378c2ecf20Sopenharmony_ci if (modes_txgain_index < 0) 9388c2ecf20Sopenharmony_ci return -EINVAL; 9398c2ecf20Sopenharmony_ci 9408c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&ah->iniModesTxGain, modes_txgain_index, 9418c2ecf20Sopenharmony_ci regWrites); 9428c2ecf20Sopenharmony_ci } else { 9438c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites); 9448c2ecf20Sopenharmony_ci } 9458c2ecf20Sopenharmony_ci 9468c2ecf20Sopenharmony_ci /* 9478c2ecf20Sopenharmony_ci * For 5GHz channels requiring Fast Clock, apply 9488c2ecf20Sopenharmony_ci * different modal values. 9498c2ecf20Sopenharmony_ci */ 9508c2ecf20Sopenharmony_ci if (IS_CHAN_A_FAST_CLOCK(ah, chan)) 9518c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&ah->iniModesFastClock, 9528c2ecf20Sopenharmony_ci modesIndex, regWrites); 9538c2ecf20Sopenharmony_ci 9548c2ecf20Sopenharmony_ci /* 9558c2ecf20Sopenharmony_ci * Clock frequency initvals. 9568c2ecf20Sopenharmony_ci */ 9578c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&ah->iniAdditional, 1, regWrites); 9588c2ecf20Sopenharmony_ci 9598c2ecf20Sopenharmony_ci /* 9608c2ecf20Sopenharmony_ci * JAPAN regulatory. 9618c2ecf20Sopenharmony_ci */ 9628c2ecf20Sopenharmony_ci if (chan->channel == 2484) { 9638c2ecf20Sopenharmony_ci ar9003_hw_prog_ini(ah, &ah->iniCckfirJapan2484, 1); 9648c2ecf20Sopenharmony_ci 9658c2ecf20Sopenharmony_ci if (AR_SREV_9531(ah)) 9668c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_FCAL_2_0, 9678c2ecf20Sopenharmony_ci AR_PHY_FLC_PWR_THRESH, 0); 9688c2ecf20Sopenharmony_ci } 9698c2ecf20Sopenharmony_ci 9708c2ecf20Sopenharmony_ci ah->modes_index = modesIndex; 9718c2ecf20Sopenharmony_ci ar9003_hw_override_ini(ah); 9728c2ecf20Sopenharmony_ci ar9003_hw_set_channel_regs(ah, chan); 9738c2ecf20Sopenharmony_ci ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask); 9748c2ecf20Sopenharmony_ci ath9k_hw_apply_txpower(ah, chan, false); 9758c2ecf20Sopenharmony_ci 9768c2ecf20Sopenharmony_ci return 0; 9778c2ecf20Sopenharmony_ci} 9788c2ecf20Sopenharmony_ci 9798c2ecf20Sopenharmony_cistatic void ar9003_hw_set_rfmode(struct ath_hw *ah, 9808c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 9818c2ecf20Sopenharmony_ci{ 9828c2ecf20Sopenharmony_ci u32 rfMode = 0; 9838c2ecf20Sopenharmony_ci 9848c2ecf20Sopenharmony_ci if (chan == NULL) 9858c2ecf20Sopenharmony_ci return; 9868c2ecf20Sopenharmony_ci 9878c2ecf20Sopenharmony_ci if (IS_CHAN_2GHZ(chan)) 9888c2ecf20Sopenharmony_ci rfMode |= AR_PHY_MODE_DYNAMIC; 9898c2ecf20Sopenharmony_ci else 9908c2ecf20Sopenharmony_ci rfMode |= AR_PHY_MODE_OFDM; 9918c2ecf20Sopenharmony_ci 9928c2ecf20Sopenharmony_ci if (IS_CHAN_A_FAST_CLOCK(ah, chan)) 9938c2ecf20Sopenharmony_ci rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE); 9948c2ecf20Sopenharmony_ci 9958c2ecf20Sopenharmony_ci if (IS_CHAN_HALF_RATE(chan) || IS_CHAN_QUARTER_RATE(chan)) 9968c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL, 9978c2ecf20Sopenharmony_ci AR_PHY_FRAME_CTL_CF_OVERLAP_WINDOW, 3); 9988c2ecf20Sopenharmony_ci 9998c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_MODE, rfMode); 10008c2ecf20Sopenharmony_ci} 10018c2ecf20Sopenharmony_ci 10028c2ecf20Sopenharmony_cistatic void ar9003_hw_mark_phy_inactive(struct ath_hw *ah) 10038c2ecf20Sopenharmony_ci{ 10048c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS); 10058c2ecf20Sopenharmony_ci} 10068c2ecf20Sopenharmony_ci 10078c2ecf20Sopenharmony_cistatic void ar9003_hw_set_delta_slope(struct ath_hw *ah, 10088c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 10098c2ecf20Sopenharmony_ci{ 10108c2ecf20Sopenharmony_ci u32 coef_scaled, ds_coef_exp, ds_coef_man; 10118c2ecf20Sopenharmony_ci u32 clockMhzScaled = 0x64000000; 10128c2ecf20Sopenharmony_ci struct chan_centers centers; 10138c2ecf20Sopenharmony_ci 10148c2ecf20Sopenharmony_ci /* 10158c2ecf20Sopenharmony_ci * half and quarter rate can divide the scaled clock by 2 or 4 10168c2ecf20Sopenharmony_ci * scale for selected channel bandwidth 10178c2ecf20Sopenharmony_ci */ 10188c2ecf20Sopenharmony_ci if (IS_CHAN_HALF_RATE(chan)) 10198c2ecf20Sopenharmony_ci clockMhzScaled = clockMhzScaled >> 1; 10208c2ecf20Sopenharmony_ci else if (IS_CHAN_QUARTER_RATE(chan)) 10218c2ecf20Sopenharmony_ci clockMhzScaled = clockMhzScaled >> 2; 10228c2ecf20Sopenharmony_ci 10238c2ecf20Sopenharmony_ci /* 10248c2ecf20Sopenharmony_ci * ALGO -> coef = 1e8/fcarrier*fclock/40; 10258c2ecf20Sopenharmony_ci * scaled coef to provide precision for this floating calculation 10268c2ecf20Sopenharmony_ci */ 10278c2ecf20Sopenharmony_ci ath9k_hw_get_channel_centers(ah, chan, ¢ers); 10288c2ecf20Sopenharmony_ci coef_scaled = clockMhzScaled / centers.synth_center; 10298c2ecf20Sopenharmony_ci 10308c2ecf20Sopenharmony_ci ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man, 10318c2ecf20Sopenharmony_ci &ds_coef_exp); 10328c2ecf20Sopenharmony_ci 10338c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TIMING3, 10348c2ecf20Sopenharmony_ci AR_PHY_TIMING3_DSC_MAN, ds_coef_man); 10358c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TIMING3, 10368c2ecf20Sopenharmony_ci AR_PHY_TIMING3_DSC_EXP, ds_coef_exp); 10378c2ecf20Sopenharmony_ci 10388c2ecf20Sopenharmony_ci /* 10398c2ecf20Sopenharmony_ci * For Short GI, 10408c2ecf20Sopenharmony_ci * scaled coeff is 9/10 that of normal coeff 10418c2ecf20Sopenharmony_ci */ 10428c2ecf20Sopenharmony_ci coef_scaled = (9 * coef_scaled) / 10; 10438c2ecf20Sopenharmony_ci 10448c2ecf20Sopenharmony_ci ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man, 10458c2ecf20Sopenharmony_ci &ds_coef_exp); 10468c2ecf20Sopenharmony_ci 10478c2ecf20Sopenharmony_ci /* for short gi */ 10488c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA, 10498c2ecf20Sopenharmony_ci AR_PHY_SGI_DSC_MAN, ds_coef_man); 10508c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA, 10518c2ecf20Sopenharmony_ci AR_PHY_SGI_DSC_EXP, ds_coef_exp); 10528c2ecf20Sopenharmony_ci} 10538c2ecf20Sopenharmony_ci 10548c2ecf20Sopenharmony_cistatic bool ar9003_hw_rfbus_req(struct ath_hw *ah) 10558c2ecf20Sopenharmony_ci{ 10568c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN); 10578c2ecf20Sopenharmony_ci return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN, 10588c2ecf20Sopenharmony_ci AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT); 10598c2ecf20Sopenharmony_ci} 10608c2ecf20Sopenharmony_ci 10618c2ecf20Sopenharmony_ci/* 10628c2ecf20Sopenharmony_ci * Wait for the frequency synth to settle (synth goes on via PHY_ACTIVE_EN). 10638c2ecf20Sopenharmony_ci * Read the phy active delay register. Value is in 100ns increments. 10648c2ecf20Sopenharmony_ci */ 10658c2ecf20Sopenharmony_cistatic void ar9003_hw_rfbus_done(struct ath_hw *ah) 10668c2ecf20Sopenharmony_ci{ 10678c2ecf20Sopenharmony_ci u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY; 10688c2ecf20Sopenharmony_ci 10698c2ecf20Sopenharmony_ci ath9k_hw_synth_delay(ah, ah->curchan, synthDelay); 10708c2ecf20Sopenharmony_ci 10718c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0); 10728c2ecf20Sopenharmony_ci} 10738c2ecf20Sopenharmony_ci 10748c2ecf20Sopenharmony_cistatic bool ar9003_hw_ani_control(struct ath_hw *ah, 10758c2ecf20Sopenharmony_ci enum ath9k_ani_cmd cmd, int param) 10768c2ecf20Sopenharmony_ci{ 10778c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 10788c2ecf20Sopenharmony_ci struct ath9k_channel *chan = ah->curchan; 10798c2ecf20Sopenharmony_ci struct ar5416AniState *aniState = &ah->ani; 10808c2ecf20Sopenharmony_ci int m1ThreshLow, m2ThreshLow; 10818c2ecf20Sopenharmony_ci int m1Thresh, m2Thresh; 10828c2ecf20Sopenharmony_ci int m2CountThr, m2CountThrLow; 10838c2ecf20Sopenharmony_ci int m1ThreshLowExt, m2ThreshLowExt; 10848c2ecf20Sopenharmony_ci int m1ThreshExt, m2ThreshExt; 10858c2ecf20Sopenharmony_ci s32 value, value2; 10868c2ecf20Sopenharmony_ci 10878c2ecf20Sopenharmony_ci switch (cmd & ah->ani_function) { 10888c2ecf20Sopenharmony_ci case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{ 10898c2ecf20Sopenharmony_ci /* 10908c2ecf20Sopenharmony_ci * on == 1 means ofdm weak signal detection is ON 10918c2ecf20Sopenharmony_ci * on == 1 is the default, for less noise immunity 10928c2ecf20Sopenharmony_ci * 10938c2ecf20Sopenharmony_ci * on == 0 means ofdm weak signal detection is OFF 10948c2ecf20Sopenharmony_ci * on == 0 means more noise imm 10958c2ecf20Sopenharmony_ci */ 10968c2ecf20Sopenharmony_ci u32 on = param ? 1 : 0; 10978c2ecf20Sopenharmony_ci 10988c2ecf20Sopenharmony_ci if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) 10998c2ecf20Sopenharmony_ci goto skip_ws_det; 11008c2ecf20Sopenharmony_ci 11018c2ecf20Sopenharmony_ci m1ThreshLow = on ? 11028c2ecf20Sopenharmony_ci aniState->iniDef.m1ThreshLow : m1ThreshLow_off; 11038c2ecf20Sopenharmony_ci m2ThreshLow = on ? 11048c2ecf20Sopenharmony_ci aniState->iniDef.m2ThreshLow : m2ThreshLow_off; 11058c2ecf20Sopenharmony_ci m1Thresh = on ? 11068c2ecf20Sopenharmony_ci aniState->iniDef.m1Thresh : m1Thresh_off; 11078c2ecf20Sopenharmony_ci m2Thresh = on ? 11088c2ecf20Sopenharmony_ci aniState->iniDef.m2Thresh : m2Thresh_off; 11098c2ecf20Sopenharmony_ci m2CountThr = on ? 11108c2ecf20Sopenharmony_ci aniState->iniDef.m2CountThr : m2CountThr_off; 11118c2ecf20Sopenharmony_ci m2CountThrLow = on ? 11128c2ecf20Sopenharmony_ci aniState->iniDef.m2CountThrLow : m2CountThrLow_off; 11138c2ecf20Sopenharmony_ci m1ThreshLowExt = on ? 11148c2ecf20Sopenharmony_ci aniState->iniDef.m1ThreshLowExt : m1ThreshLowExt_off; 11158c2ecf20Sopenharmony_ci m2ThreshLowExt = on ? 11168c2ecf20Sopenharmony_ci aniState->iniDef.m2ThreshLowExt : m2ThreshLowExt_off; 11178c2ecf20Sopenharmony_ci m1ThreshExt = on ? 11188c2ecf20Sopenharmony_ci aniState->iniDef.m1ThreshExt : m1ThreshExt_off; 11198c2ecf20Sopenharmony_ci m2ThreshExt = on ? 11208c2ecf20Sopenharmony_ci aniState->iniDef.m2ThreshExt : m2ThreshExt_off; 11218c2ecf20Sopenharmony_ci 11228c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW, 11238c2ecf20Sopenharmony_ci AR_PHY_SFCORR_LOW_M1_THRESH_LOW, 11248c2ecf20Sopenharmony_ci m1ThreshLow); 11258c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW, 11268c2ecf20Sopenharmony_ci AR_PHY_SFCORR_LOW_M2_THRESH_LOW, 11278c2ecf20Sopenharmony_ci m2ThreshLow); 11288c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SFCORR, 11298c2ecf20Sopenharmony_ci AR_PHY_SFCORR_M1_THRESH, 11308c2ecf20Sopenharmony_ci m1Thresh); 11318c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SFCORR, 11328c2ecf20Sopenharmony_ci AR_PHY_SFCORR_M2_THRESH, 11338c2ecf20Sopenharmony_ci m2Thresh); 11348c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SFCORR, 11358c2ecf20Sopenharmony_ci AR_PHY_SFCORR_M2COUNT_THR, 11368c2ecf20Sopenharmony_ci m2CountThr); 11378c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW, 11388c2ecf20Sopenharmony_ci AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW, 11398c2ecf20Sopenharmony_ci m2CountThrLow); 11408c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT, 11418c2ecf20Sopenharmony_ci AR_PHY_SFCORR_EXT_M1_THRESH_LOW, 11428c2ecf20Sopenharmony_ci m1ThreshLowExt); 11438c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT, 11448c2ecf20Sopenharmony_ci AR_PHY_SFCORR_EXT_M2_THRESH_LOW, 11458c2ecf20Sopenharmony_ci m2ThreshLowExt); 11468c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT, 11478c2ecf20Sopenharmony_ci AR_PHY_SFCORR_EXT_M1_THRESH, 11488c2ecf20Sopenharmony_ci m1ThreshExt); 11498c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT, 11508c2ecf20Sopenharmony_ci AR_PHY_SFCORR_EXT_M2_THRESH, 11518c2ecf20Sopenharmony_ci m2ThreshExt); 11528c2ecf20Sopenharmony_ciskip_ws_det: 11538c2ecf20Sopenharmony_ci if (on) 11548c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_SFCORR_LOW, 11558c2ecf20Sopenharmony_ci AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW); 11568c2ecf20Sopenharmony_ci else 11578c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW, 11588c2ecf20Sopenharmony_ci AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW); 11598c2ecf20Sopenharmony_ci 11608c2ecf20Sopenharmony_ci if (on != aniState->ofdmWeakSigDetect) { 11618c2ecf20Sopenharmony_ci ath_dbg(common, ANI, 11628c2ecf20Sopenharmony_ci "** ch %d: ofdm weak signal: %s=>%s\n", 11638c2ecf20Sopenharmony_ci chan->channel, 11648c2ecf20Sopenharmony_ci aniState->ofdmWeakSigDetect ? 11658c2ecf20Sopenharmony_ci "on" : "off", 11668c2ecf20Sopenharmony_ci on ? "on" : "off"); 11678c2ecf20Sopenharmony_ci if (on) 11688c2ecf20Sopenharmony_ci ah->stats.ast_ani_ofdmon++; 11698c2ecf20Sopenharmony_ci else 11708c2ecf20Sopenharmony_ci ah->stats.ast_ani_ofdmoff++; 11718c2ecf20Sopenharmony_ci aniState->ofdmWeakSigDetect = on; 11728c2ecf20Sopenharmony_ci } 11738c2ecf20Sopenharmony_ci break; 11748c2ecf20Sopenharmony_ci } 11758c2ecf20Sopenharmony_ci case ATH9K_ANI_FIRSTEP_LEVEL:{ 11768c2ecf20Sopenharmony_ci u32 level = param; 11778c2ecf20Sopenharmony_ci 11788c2ecf20Sopenharmony_ci if (level >= ARRAY_SIZE(firstep_table)) { 11798c2ecf20Sopenharmony_ci ath_dbg(common, ANI, 11808c2ecf20Sopenharmony_ci "ATH9K_ANI_FIRSTEP_LEVEL: level out of range (%u > %zu)\n", 11818c2ecf20Sopenharmony_ci level, ARRAY_SIZE(firstep_table)); 11828c2ecf20Sopenharmony_ci return false; 11838c2ecf20Sopenharmony_ci } 11848c2ecf20Sopenharmony_ci 11858c2ecf20Sopenharmony_ci /* 11868c2ecf20Sopenharmony_ci * make register setting relative to default 11878c2ecf20Sopenharmony_ci * from INI file & cap value 11888c2ecf20Sopenharmony_ci */ 11898c2ecf20Sopenharmony_ci value = firstep_table[level] - 11908c2ecf20Sopenharmony_ci firstep_table[ATH9K_ANI_FIRSTEP_LVL] + 11918c2ecf20Sopenharmony_ci aniState->iniDef.firstep; 11928c2ecf20Sopenharmony_ci if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN) 11938c2ecf20Sopenharmony_ci value = ATH9K_SIG_FIRSTEP_SETTING_MIN; 11948c2ecf20Sopenharmony_ci if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX) 11958c2ecf20Sopenharmony_ci value = ATH9K_SIG_FIRSTEP_SETTING_MAX; 11968c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_FIND_SIG, 11978c2ecf20Sopenharmony_ci AR_PHY_FIND_SIG_FIRSTEP, 11988c2ecf20Sopenharmony_ci value); 11998c2ecf20Sopenharmony_ci /* 12008c2ecf20Sopenharmony_ci * we need to set first step low register too 12018c2ecf20Sopenharmony_ci * make register setting relative to default 12028c2ecf20Sopenharmony_ci * from INI file & cap value 12038c2ecf20Sopenharmony_ci */ 12048c2ecf20Sopenharmony_ci value2 = firstep_table[level] - 12058c2ecf20Sopenharmony_ci firstep_table[ATH9K_ANI_FIRSTEP_LVL] + 12068c2ecf20Sopenharmony_ci aniState->iniDef.firstepLow; 12078c2ecf20Sopenharmony_ci if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN) 12088c2ecf20Sopenharmony_ci value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN; 12098c2ecf20Sopenharmony_ci if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX) 12108c2ecf20Sopenharmony_ci value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX; 12118c2ecf20Sopenharmony_ci 12128c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW, 12138c2ecf20Sopenharmony_ci AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW, value2); 12148c2ecf20Sopenharmony_ci 12158c2ecf20Sopenharmony_ci if (level != aniState->firstepLevel) { 12168c2ecf20Sopenharmony_ci ath_dbg(common, ANI, 12178c2ecf20Sopenharmony_ci "** ch %d: level %d=>%d[def:%d] firstep[level]=%d ini=%d\n", 12188c2ecf20Sopenharmony_ci chan->channel, 12198c2ecf20Sopenharmony_ci aniState->firstepLevel, 12208c2ecf20Sopenharmony_ci level, 12218c2ecf20Sopenharmony_ci ATH9K_ANI_FIRSTEP_LVL, 12228c2ecf20Sopenharmony_ci value, 12238c2ecf20Sopenharmony_ci aniState->iniDef.firstep); 12248c2ecf20Sopenharmony_ci ath_dbg(common, ANI, 12258c2ecf20Sopenharmony_ci "** ch %d: level %d=>%d[def:%d] firstep_low[level]=%d ini=%d\n", 12268c2ecf20Sopenharmony_ci chan->channel, 12278c2ecf20Sopenharmony_ci aniState->firstepLevel, 12288c2ecf20Sopenharmony_ci level, 12298c2ecf20Sopenharmony_ci ATH9K_ANI_FIRSTEP_LVL, 12308c2ecf20Sopenharmony_ci value2, 12318c2ecf20Sopenharmony_ci aniState->iniDef.firstepLow); 12328c2ecf20Sopenharmony_ci if (level > aniState->firstepLevel) 12338c2ecf20Sopenharmony_ci ah->stats.ast_ani_stepup++; 12348c2ecf20Sopenharmony_ci else if (level < aniState->firstepLevel) 12358c2ecf20Sopenharmony_ci ah->stats.ast_ani_stepdown++; 12368c2ecf20Sopenharmony_ci aniState->firstepLevel = level; 12378c2ecf20Sopenharmony_ci } 12388c2ecf20Sopenharmony_ci break; 12398c2ecf20Sopenharmony_ci } 12408c2ecf20Sopenharmony_ci case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{ 12418c2ecf20Sopenharmony_ci u32 level = param; 12428c2ecf20Sopenharmony_ci 12438c2ecf20Sopenharmony_ci if (level >= ARRAY_SIZE(cycpwrThr1_table)) { 12448c2ecf20Sopenharmony_ci ath_dbg(common, ANI, 12458c2ecf20Sopenharmony_ci "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level out of range (%u > %zu)\n", 12468c2ecf20Sopenharmony_ci level, ARRAY_SIZE(cycpwrThr1_table)); 12478c2ecf20Sopenharmony_ci return false; 12488c2ecf20Sopenharmony_ci } 12498c2ecf20Sopenharmony_ci /* 12508c2ecf20Sopenharmony_ci * make register setting relative to default 12518c2ecf20Sopenharmony_ci * from INI file & cap value 12528c2ecf20Sopenharmony_ci */ 12538c2ecf20Sopenharmony_ci value = cycpwrThr1_table[level] - 12548c2ecf20Sopenharmony_ci cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] + 12558c2ecf20Sopenharmony_ci aniState->iniDef.cycpwrThr1; 12568c2ecf20Sopenharmony_ci if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN) 12578c2ecf20Sopenharmony_ci value = ATH9K_SIG_SPUR_IMM_SETTING_MIN; 12588c2ecf20Sopenharmony_ci if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX) 12598c2ecf20Sopenharmony_ci value = ATH9K_SIG_SPUR_IMM_SETTING_MAX; 12608c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TIMING5, 12618c2ecf20Sopenharmony_ci AR_PHY_TIMING5_CYCPWR_THR1, 12628c2ecf20Sopenharmony_ci value); 12638c2ecf20Sopenharmony_ci 12648c2ecf20Sopenharmony_ci /* 12658c2ecf20Sopenharmony_ci * set AR_PHY_EXT_CCA for extension channel 12668c2ecf20Sopenharmony_ci * make register setting relative to default 12678c2ecf20Sopenharmony_ci * from INI file & cap value 12688c2ecf20Sopenharmony_ci */ 12698c2ecf20Sopenharmony_ci value2 = cycpwrThr1_table[level] - 12708c2ecf20Sopenharmony_ci cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] + 12718c2ecf20Sopenharmony_ci aniState->iniDef.cycpwrThr1Ext; 12728c2ecf20Sopenharmony_ci if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN) 12738c2ecf20Sopenharmony_ci value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN; 12748c2ecf20Sopenharmony_ci if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX) 12758c2ecf20Sopenharmony_ci value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX; 12768c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_EXT_CCA, 12778c2ecf20Sopenharmony_ci AR_PHY_EXT_CYCPWR_THR1, value2); 12788c2ecf20Sopenharmony_ci 12798c2ecf20Sopenharmony_ci if (level != aniState->spurImmunityLevel) { 12808c2ecf20Sopenharmony_ci ath_dbg(common, ANI, 12818c2ecf20Sopenharmony_ci "** ch %d: level %d=>%d[def:%d] cycpwrThr1[level]=%d ini=%d\n", 12828c2ecf20Sopenharmony_ci chan->channel, 12838c2ecf20Sopenharmony_ci aniState->spurImmunityLevel, 12848c2ecf20Sopenharmony_ci level, 12858c2ecf20Sopenharmony_ci ATH9K_ANI_SPUR_IMMUNE_LVL, 12868c2ecf20Sopenharmony_ci value, 12878c2ecf20Sopenharmony_ci aniState->iniDef.cycpwrThr1); 12888c2ecf20Sopenharmony_ci ath_dbg(common, ANI, 12898c2ecf20Sopenharmony_ci "** ch %d: level %d=>%d[def:%d] cycpwrThr1Ext[level]=%d ini=%d\n", 12908c2ecf20Sopenharmony_ci chan->channel, 12918c2ecf20Sopenharmony_ci aniState->spurImmunityLevel, 12928c2ecf20Sopenharmony_ci level, 12938c2ecf20Sopenharmony_ci ATH9K_ANI_SPUR_IMMUNE_LVL, 12948c2ecf20Sopenharmony_ci value2, 12958c2ecf20Sopenharmony_ci aniState->iniDef.cycpwrThr1Ext); 12968c2ecf20Sopenharmony_ci if (level > aniState->spurImmunityLevel) 12978c2ecf20Sopenharmony_ci ah->stats.ast_ani_spurup++; 12988c2ecf20Sopenharmony_ci else if (level < aniState->spurImmunityLevel) 12998c2ecf20Sopenharmony_ci ah->stats.ast_ani_spurdown++; 13008c2ecf20Sopenharmony_ci aniState->spurImmunityLevel = level; 13018c2ecf20Sopenharmony_ci } 13028c2ecf20Sopenharmony_ci break; 13038c2ecf20Sopenharmony_ci } 13048c2ecf20Sopenharmony_ci case ATH9K_ANI_MRC_CCK:{ 13058c2ecf20Sopenharmony_ci /* 13068c2ecf20Sopenharmony_ci * is_on == 1 means MRC CCK ON (default, less noise imm) 13078c2ecf20Sopenharmony_ci * is_on == 0 means MRC CCK is OFF (more noise imm) 13088c2ecf20Sopenharmony_ci */ 13098c2ecf20Sopenharmony_ci bool is_on = param ? 1 : 0; 13108c2ecf20Sopenharmony_ci 13118c2ecf20Sopenharmony_ci if (ah->caps.rx_chainmask == 1) 13128c2ecf20Sopenharmony_ci break; 13138c2ecf20Sopenharmony_ci 13148c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL, 13158c2ecf20Sopenharmony_ci AR_PHY_MRC_CCK_ENABLE, is_on); 13168c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL, 13178c2ecf20Sopenharmony_ci AR_PHY_MRC_CCK_MUX_REG, is_on); 13188c2ecf20Sopenharmony_ci if (is_on != aniState->mrcCCK) { 13198c2ecf20Sopenharmony_ci ath_dbg(common, ANI, "** ch %d: MRC CCK: %s=>%s\n", 13208c2ecf20Sopenharmony_ci chan->channel, 13218c2ecf20Sopenharmony_ci aniState->mrcCCK ? "on" : "off", 13228c2ecf20Sopenharmony_ci is_on ? "on" : "off"); 13238c2ecf20Sopenharmony_ci if (is_on) 13248c2ecf20Sopenharmony_ci ah->stats.ast_ani_ccklow++; 13258c2ecf20Sopenharmony_ci else 13268c2ecf20Sopenharmony_ci ah->stats.ast_ani_cckhigh++; 13278c2ecf20Sopenharmony_ci aniState->mrcCCK = is_on; 13288c2ecf20Sopenharmony_ci } 13298c2ecf20Sopenharmony_ci break; 13308c2ecf20Sopenharmony_ci } 13318c2ecf20Sopenharmony_ci default: 13328c2ecf20Sopenharmony_ci ath_dbg(common, ANI, "invalid cmd %u\n", cmd); 13338c2ecf20Sopenharmony_ci return false; 13348c2ecf20Sopenharmony_ci } 13358c2ecf20Sopenharmony_ci 13368c2ecf20Sopenharmony_ci ath_dbg(common, ANI, 13378c2ecf20Sopenharmony_ci "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n", 13388c2ecf20Sopenharmony_ci aniState->spurImmunityLevel, 13398c2ecf20Sopenharmony_ci aniState->ofdmWeakSigDetect ? "on" : "off", 13408c2ecf20Sopenharmony_ci aniState->firstepLevel, 13418c2ecf20Sopenharmony_ci aniState->mrcCCK ? "on" : "off", 13428c2ecf20Sopenharmony_ci aniState->listenTime, 13438c2ecf20Sopenharmony_ci aniState->ofdmPhyErrCount, 13448c2ecf20Sopenharmony_ci aniState->cckPhyErrCount); 13458c2ecf20Sopenharmony_ci return true; 13468c2ecf20Sopenharmony_ci} 13478c2ecf20Sopenharmony_ci 13488c2ecf20Sopenharmony_cistatic void ar9003_hw_do_getnf(struct ath_hw *ah, 13498c2ecf20Sopenharmony_ci int16_t nfarray[NUM_NF_READINGS]) 13508c2ecf20Sopenharmony_ci{ 13518c2ecf20Sopenharmony_ci#define AR_PHY_CH_MINCCA_PWR 0x1FF00000 13528c2ecf20Sopenharmony_ci#define AR_PHY_CH_MINCCA_PWR_S 20 13538c2ecf20Sopenharmony_ci#define AR_PHY_CH_EXT_MINCCA_PWR 0x01FF0000 13548c2ecf20Sopenharmony_ci#define AR_PHY_CH_EXT_MINCCA_PWR_S 16 13558c2ecf20Sopenharmony_ci 13568c2ecf20Sopenharmony_ci int16_t nf; 13578c2ecf20Sopenharmony_ci int i; 13588c2ecf20Sopenharmony_ci 13598c2ecf20Sopenharmony_ci for (i = 0; i < AR9300_MAX_CHAINS; i++) { 13608c2ecf20Sopenharmony_ci if (ah->rxchainmask & BIT(i)) { 13618c2ecf20Sopenharmony_ci nf = MS(REG_READ(ah, ah->nf_regs[i]), 13628c2ecf20Sopenharmony_ci AR_PHY_CH_MINCCA_PWR); 13638c2ecf20Sopenharmony_ci nfarray[i] = sign_extend32(nf, 8); 13648c2ecf20Sopenharmony_ci 13658c2ecf20Sopenharmony_ci if (IS_CHAN_HT40(ah->curchan)) { 13668c2ecf20Sopenharmony_ci u8 ext_idx = AR9300_MAX_CHAINS + i; 13678c2ecf20Sopenharmony_ci 13688c2ecf20Sopenharmony_ci nf = MS(REG_READ(ah, ah->nf_regs[ext_idx]), 13698c2ecf20Sopenharmony_ci AR_PHY_CH_EXT_MINCCA_PWR); 13708c2ecf20Sopenharmony_ci nfarray[ext_idx] = sign_extend32(nf, 8); 13718c2ecf20Sopenharmony_ci } 13728c2ecf20Sopenharmony_ci } 13738c2ecf20Sopenharmony_ci } 13748c2ecf20Sopenharmony_ci} 13758c2ecf20Sopenharmony_ci 13768c2ecf20Sopenharmony_cistatic void ar9003_hw_set_nf_limits(struct ath_hw *ah) 13778c2ecf20Sopenharmony_ci{ 13788c2ecf20Sopenharmony_ci ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_2GHZ; 13798c2ecf20Sopenharmony_ci ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_2GHZ; 13808c2ecf20Sopenharmony_ci ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9300_2GHZ; 13818c2ecf20Sopenharmony_ci ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_5GHZ; 13828c2ecf20Sopenharmony_ci ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_5GHZ; 13838c2ecf20Sopenharmony_ci ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9300_5GHZ; 13848c2ecf20Sopenharmony_ci 13858c2ecf20Sopenharmony_ci if (AR_SREV_9330(ah)) 13868c2ecf20Sopenharmony_ci ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9330_2GHZ; 13878c2ecf20Sopenharmony_ci 13888c2ecf20Sopenharmony_ci if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) { 13898c2ecf20Sopenharmony_ci ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9462_2GHZ; 13908c2ecf20Sopenharmony_ci ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9462_2GHZ; 13918c2ecf20Sopenharmony_ci ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9462_5GHZ; 13928c2ecf20Sopenharmony_ci ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9462_5GHZ; 13938c2ecf20Sopenharmony_ci } 13948c2ecf20Sopenharmony_ci} 13958c2ecf20Sopenharmony_ci 13968c2ecf20Sopenharmony_ci/* 13978c2ecf20Sopenharmony_ci * Initialize the ANI register values with default (ini) values. 13988c2ecf20Sopenharmony_ci * This routine is called during a (full) hardware reset after 13998c2ecf20Sopenharmony_ci * all the registers are initialised from the INI. 14008c2ecf20Sopenharmony_ci */ 14018c2ecf20Sopenharmony_cistatic void ar9003_hw_ani_cache_ini_regs(struct ath_hw *ah) 14028c2ecf20Sopenharmony_ci{ 14038c2ecf20Sopenharmony_ci struct ar5416AniState *aniState; 14048c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 14058c2ecf20Sopenharmony_ci struct ath9k_channel *chan = ah->curchan; 14068c2ecf20Sopenharmony_ci struct ath9k_ani_default *iniDef; 14078c2ecf20Sopenharmony_ci u32 val; 14088c2ecf20Sopenharmony_ci 14098c2ecf20Sopenharmony_ci aniState = &ah->ani; 14108c2ecf20Sopenharmony_ci iniDef = &aniState->iniDef; 14118c2ecf20Sopenharmony_ci 14128c2ecf20Sopenharmony_ci ath_dbg(common, ANI, "ver %d.%d opmode %u chan %d Mhz\n", 14138c2ecf20Sopenharmony_ci ah->hw_version.macVersion, 14148c2ecf20Sopenharmony_ci ah->hw_version.macRev, 14158c2ecf20Sopenharmony_ci ah->opmode, 14168c2ecf20Sopenharmony_ci chan->channel); 14178c2ecf20Sopenharmony_ci 14188c2ecf20Sopenharmony_ci val = REG_READ(ah, AR_PHY_SFCORR); 14198c2ecf20Sopenharmony_ci iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH); 14208c2ecf20Sopenharmony_ci iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH); 14218c2ecf20Sopenharmony_ci iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR); 14228c2ecf20Sopenharmony_ci 14238c2ecf20Sopenharmony_ci val = REG_READ(ah, AR_PHY_SFCORR_LOW); 14248c2ecf20Sopenharmony_ci iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW); 14258c2ecf20Sopenharmony_ci iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW); 14268c2ecf20Sopenharmony_ci iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW); 14278c2ecf20Sopenharmony_ci 14288c2ecf20Sopenharmony_ci val = REG_READ(ah, AR_PHY_SFCORR_EXT); 14298c2ecf20Sopenharmony_ci iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH); 14308c2ecf20Sopenharmony_ci iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH); 14318c2ecf20Sopenharmony_ci iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW); 14328c2ecf20Sopenharmony_ci iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW); 14338c2ecf20Sopenharmony_ci iniDef->firstep = REG_READ_FIELD(ah, 14348c2ecf20Sopenharmony_ci AR_PHY_FIND_SIG, 14358c2ecf20Sopenharmony_ci AR_PHY_FIND_SIG_FIRSTEP); 14368c2ecf20Sopenharmony_ci iniDef->firstepLow = REG_READ_FIELD(ah, 14378c2ecf20Sopenharmony_ci AR_PHY_FIND_SIG_LOW, 14388c2ecf20Sopenharmony_ci AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW); 14398c2ecf20Sopenharmony_ci iniDef->cycpwrThr1 = REG_READ_FIELD(ah, 14408c2ecf20Sopenharmony_ci AR_PHY_TIMING5, 14418c2ecf20Sopenharmony_ci AR_PHY_TIMING5_CYCPWR_THR1); 14428c2ecf20Sopenharmony_ci iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah, 14438c2ecf20Sopenharmony_ci AR_PHY_EXT_CCA, 14448c2ecf20Sopenharmony_ci AR_PHY_EXT_CYCPWR_THR1); 14458c2ecf20Sopenharmony_ci 14468c2ecf20Sopenharmony_ci /* these levels just got reset to defaults by the INI */ 14478c2ecf20Sopenharmony_ci aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL; 14488c2ecf20Sopenharmony_ci aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL; 14498c2ecf20Sopenharmony_ci aniState->ofdmWeakSigDetect = true; 14508c2ecf20Sopenharmony_ci aniState->mrcCCK = true; 14518c2ecf20Sopenharmony_ci} 14528c2ecf20Sopenharmony_ci 14538c2ecf20Sopenharmony_cistatic void ar9003_hw_set_radar_params(struct ath_hw *ah, 14548c2ecf20Sopenharmony_ci struct ath_hw_radar_conf *conf) 14558c2ecf20Sopenharmony_ci{ 14568c2ecf20Sopenharmony_ci unsigned int regWrites = 0; 14578c2ecf20Sopenharmony_ci u32 radar_0 = 0, radar_1; 14588c2ecf20Sopenharmony_ci 14598c2ecf20Sopenharmony_ci if (!conf) { 14608c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA); 14618c2ecf20Sopenharmony_ci return; 14628c2ecf20Sopenharmony_ci } 14638c2ecf20Sopenharmony_ci 14648c2ecf20Sopenharmony_ci radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA; 14658c2ecf20Sopenharmony_ci radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR); 14668c2ecf20Sopenharmony_ci radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI); 14678c2ecf20Sopenharmony_ci radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT); 14688c2ecf20Sopenharmony_ci radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI); 14698c2ecf20Sopenharmony_ci radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND); 14708c2ecf20Sopenharmony_ci 14718c2ecf20Sopenharmony_ci radar_1 = REG_READ(ah, AR_PHY_RADAR_1); 14728c2ecf20Sopenharmony_ci radar_1 &= ~(AR_PHY_RADAR_1_MAXLEN | AR_PHY_RADAR_1_RELSTEP_THRESH | 14738c2ecf20Sopenharmony_ci AR_PHY_RADAR_1_RELPWR_THRESH); 14748c2ecf20Sopenharmony_ci radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI; 14758c2ecf20Sopenharmony_ci radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK; 14768c2ecf20Sopenharmony_ci radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN); 14778c2ecf20Sopenharmony_ci radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH); 14788c2ecf20Sopenharmony_ci radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH); 14798c2ecf20Sopenharmony_ci 14808c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_RADAR_0, radar_0); 14818c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_RADAR_1, radar_1); 14828c2ecf20Sopenharmony_ci if (conf->ext_channel) 14838c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA); 14848c2ecf20Sopenharmony_ci else 14858c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA); 14868c2ecf20Sopenharmony_ci 14878c2ecf20Sopenharmony_ci if (AR_SREV_9300(ah) || AR_SREV_9340(ah) || AR_SREV_9580(ah)) { 14888c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&ah->ini_dfs, 14898c2ecf20Sopenharmony_ci IS_CHAN_HT40(ah->curchan) ? 2 : 1, regWrites); 14908c2ecf20Sopenharmony_ci } 14918c2ecf20Sopenharmony_ci} 14928c2ecf20Sopenharmony_ci 14938c2ecf20Sopenharmony_cistatic void ar9003_hw_set_radar_conf(struct ath_hw *ah) 14948c2ecf20Sopenharmony_ci{ 14958c2ecf20Sopenharmony_ci struct ath_hw_radar_conf *conf = &ah->radar_conf; 14968c2ecf20Sopenharmony_ci 14978c2ecf20Sopenharmony_ci conf->fir_power = -28; 14988c2ecf20Sopenharmony_ci conf->radar_rssi = 0; 14998c2ecf20Sopenharmony_ci conf->pulse_height = 10; 15008c2ecf20Sopenharmony_ci conf->pulse_rssi = 15; 15018c2ecf20Sopenharmony_ci conf->pulse_inband = 8; 15028c2ecf20Sopenharmony_ci conf->pulse_maxlen = 255; 15038c2ecf20Sopenharmony_ci conf->pulse_inband_step = 12; 15048c2ecf20Sopenharmony_ci conf->radar_inband = 8; 15058c2ecf20Sopenharmony_ci} 15068c2ecf20Sopenharmony_ci 15078c2ecf20Sopenharmony_cistatic void ar9003_hw_antdiv_comb_conf_get(struct ath_hw *ah, 15088c2ecf20Sopenharmony_ci struct ath_hw_antcomb_conf *antconf) 15098c2ecf20Sopenharmony_ci{ 15108c2ecf20Sopenharmony_ci u32 regval; 15118c2ecf20Sopenharmony_ci 15128c2ecf20Sopenharmony_ci regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL); 15138c2ecf20Sopenharmony_ci antconf->main_lna_conf = (regval & AR_PHY_ANT_DIV_MAIN_LNACONF) >> 15148c2ecf20Sopenharmony_ci AR_PHY_ANT_DIV_MAIN_LNACONF_S; 15158c2ecf20Sopenharmony_ci antconf->alt_lna_conf = (regval & AR_PHY_ANT_DIV_ALT_LNACONF) >> 15168c2ecf20Sopenharmony_ci AR_PHY_ANT_DIV_ALT_LNACONF_S; 15178c2ecf20Sopenharmony_ci antconf->fast_div_bias = (regval & AR_PHY_ANT_FAST_DIV_BIAS) >> 15188c2ecf20Sopenharmony_ci AR_PHY_ANT_FAST_DIV_BIAS_S; 15198c2ecf20Sopenharmony_ci 15208c2ecf20Sopenharmony_ci if (AR_SREV_9330_11(ah)) { 15218c2ecf20Sopenharmony_ci antconf->lna1_lna2_switch_delta = -1; 15228c2ecf20Sopenharmony_ci antconf->lna1_lna2_delta = -9; 15238c2ecf20Sopenharmony_ci antconf->div_group = 1; 15248c2ecf20Sopenharmony_ci } else if (AR_SREV_9485(ah)) { 15258c2ecf20Sopenharmony_ci antconf->lna1_lna2_switch_delta = -1; 15268c2ecf20Sopenharmony_ci antconf->lna1_lna2_delta = -9; 15278c2ecf20Sopenharmony_ci antconf->div_group = 2; 15288c2ecf20Sopenharmony_ci } else if (AR_SREV_9565(ah)) { 15298c2ecf20Sopenharmony_ci antconf->lna1_lna2_switch_delta = 3; 15308c2ecf20Sopenharmony_ci antconf->lna1_lna2_delta = -9; 15318c2ecf20Sopenharmony_ci antconf->div_group = 3; 15328c2ecf20Sopenharmony_ci } else { 15338c2ecf20Sopenharmony_ci antconf->lna1_lna2_switch_delta = -1; 15348c2ecf20Sopenharmony_ci antconf->lna1_lna2_delta = -3; 15358c2ecf20Sopenharmony_ci antconf->div_group = 0; 15368c2ecf20Sopenharmony_ci } 15378c2ecf20Sopenharmony_ci} 15388c2ecf20Sopenharmony_ci 15398c2ecf20Sopenharmony_cistatic void ar9003_hw_antdiv_comb_conf_set(struct ath_hw *ah, 15408c2ecf20Sopenharmony_ci struct ath_hw_antcomb_conf *antconf) 15418c2ecf20Sopenharmony_ci{ 15428c2ecf20Sopenharmony_ci u32 regval; 15438c2ecf20Sopenharmony_ci 15448c2ecf20Sopenharmony_ci regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL); 15458c2ecf20Sopenharmony_ci regval &= ~(AR_PHY_ANT_DIV_MAIN_LNACONF | 15468c2ecf20Sopenharmony_ci AR_PHY_ANT_DIV_ALT_LNACONF | 15478c2ecf20Sopenharmony_ci AR_PHY_ANT_FAST_DIV_BIAS | 15488c2ecf20Sopenharmony_ci AR_PHY_ANT_DIV_MAIN_GAINTB | 15498c2ecf20Sopenharmony_ci AR_PHY_ANT_DIV_ALT_GAINTB); 15508c2ecf20Sopenharmony_ci regval |= ((antconf->main_lna_conf << AR_PHY_ANT_DIV_MAIN_LNACONF_S) 15518c2ecf20Sopenharmony_ci & AR_PHY_ANT_DIV_MAIN_LNACONF); 15528c2ecf20Sopenharmony_ci regval |= ((antconf->alt_lna_conf << AR_PHY_ANT_DIV_ALT_LNACONF_S) 15538c2ecf20Sopenharmony_ci & AR_PHY_ANT_DIV_ALT_LNACONF); 15548c2ecf20Sopenharmony_ci regval |= ((antconf->fast_div_bias << AR_PHY_ANT_FAST_DIV_BIAS_S) 15558c2ecf20Sopenharmony_ci & AR_PHY_ANT_FAST_DIV_BIAS); 15568c2ecf20Sopenharmony_ci regval |= ((antconf->main_gaintb << AR_PHY_ANT_DIV_MAIN_GAINTB_S) 15578c2ecf20Sopenharmony_ci & AR_PHY_ANT_DIV_MAIN_GAINTB); 15588c2ecf20Sopenharmony_ci regval |= ((antconf->alt_gaintb << AR_PHY_ANT_DIV_ALT_GAINTB_S) 15598c2ecf20Sopenharmony_ci & AR_PHY_ANT_DIV_ALT_GAINTB); 15608c2ecf20Sopenharmony_ci 15618c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval); 15628c2ecf20Sopenharmony_ci} 15638c2ecf20Sopenharmony_ci 15648c2ecf20Sopenharmony_ci#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT 15658c2ecf20Sopenharmony_ci 15668c2ecf20Sopenharmony_cistatic void ar9003_hw_set_bt_ant_diversity(struct ath_hw *ah, bool enable) 15678c2ecf20Sopenharmony_ci{ 15688c2ecf20Sopenharmony_ci struct ath9k_hw_capabilities *pCap = &ah->caps; 15698c2ecf20Sopenharmony_ci u8 ant_div_ctl1; 15708c2ecf20Sopenharmony_ci u32 regval; 15718c2ecf20Sopenharmony_ci 15728c2ecf20Sopenharmony_ci if (!AR_SREV_9485(ah) && !AR_SREV_9565(ah)) 15738c2ecf20Sopenharmony_ci return; 15748c2ecf20Sopenharmony_ci 15758c2ecf20Sopenharmony_ci if (AR_SREV_9485(ah)) { 15768c2ecf20Sopenharmony_ci regval = ar9003_hw_ant_ctrl_common_2_get(ah, 15778c2ecf20Sopenharmony_ci IS_CHAN_2GHZ(ah->curchan)); 15788c2ecf20Sopenharmony_ci if (enable) { 15798c2ecf20Sopenharmony_ci regval &= ~AR_SWITCH_TABLE_COM2_ALL; 15808c2ecf20Sopenharmony_ci regval |= ah->config.ant_ctrl_comm2g_switch_enable; 15818c2ecf20Sopenharmony_ci } 15828c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM_2, 15838c2ecf20Sopenharmony_ci AR_SWITCH_TABLE_COM2_ALL, regval); 15848c2ecf20Sopenharmony_ci } 15858c2ecf20Sopenharmony_ci 15868c2ecf20Sopenharmony_ci ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1); 15878c2ecf20Sopenharmony_ci 15888c2ecf20Sopenharmony_ci /* 15898c2ecf20Sopenharmony_ci * Set MAIN/ALT LNA conf. 15908c2ecf20Sopenharmony_ci * Set MAIN/ALT gain_tb. 15918c2ecf20Sopenharmony_ci */ 15928c2ecf20Sopenharmony_ci regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL); 15938c2ecf20Sopenharmony_ci regval &= (~AR_ANT_DIV_CTRL_ALL); 15948c2ecf20Sopenharmony_ci regval |= (ant_div_ctl1 & 0x3f) << AR_ANT_DIV_CTRL_ALL_S; 15958c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval); 15968c2ecf20Sopenharmony_ci 15978c2ecf20Sopenharmony_ci if (AR_SREV_9485_11_OR_LATER(ah)) { 15988c2ecf20Sopenharmony_ci /* 15998c2ecf20Sopenharmony_ci * Enable LNA diversity. 16008c2ecf20Sopenharmony_ci */ 16018c2ecf20Sopenharmony_ci regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL); 16028c2ecf20Sopenharmony_ci regval &= ~AR_PHY_ANT_DIV_LNADIV; 16038c2ecf20Sopenharmony_ci regval |= ((ant_div_ctl1 >> 6) & 0x1) << AR_PHY_ANT_DIV_LNADIV_S; 16048c2ecf20Sopenharmony_ci if (enable) 16058c2ecf20Sopenharmony_ci regval |= AR_ANT_DIV_ENABLE; 16068c2ecf20Sopenharmony_ci 16078c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval); 16088c2ecf20Sopenharmony_ci 16098c2ecf20Sopenharmony_ci /* 16108c2ecf20Sopenharmony_ci * Enable fast antenna diversity. 16118c2ecf20Sopenharmony_ci */ 16128c2ecf20Sopenharmony_ci regval = REG_READ(ah, AR_PHY_CCK_DETECT); 16138c2ecf20Sopenharmony_ci regval &= ~AR_FAST_DIV_ENABLE; 16148c2ecf20Sopenharmony_ci regval |= ((ant_div_ctl1 >> 7) & 0x1) << AR_FAST_DIV_ENABLE_S; 16158c2ecf20Sopenharmony_ci if (enable) 16168c2ecf20Sopenharmony_ci regval |= AR_FAST_DIV_ENABLE; 16178c2ecf20Sopenharmony_ci 16188c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_CCK_DETECT, regval); 16198c2ecf20Sopenharmony_ci 16208c2ecf20Sopenharmony_ci if (pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) { 16218c2ecf20Sopenharmony_ci regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL); 16228c2ecf20Sopenharmony_ci regval &= (~(AR_PHY_ANT_DIV_MAIN_LNACONF | 16238c2ecf20Sopenharmony_ci AR_PHY_ANT_DIV_ALT_LNACONF | 16248c2ecf20Sopenharmony_ci AR_PHY_ANT_DIV_ALT_GAINTB | 16258c2ecf20Sopenharmony_ci AR_PHY_ANT_DIV_MAIN_GAINTB)); 16268c2ecf20Sopenharmony_ci /* 16278c2ecf20Sopenharmony_ci * Set MAIN to LNA1 and ALT to LNA2 at the 16288c2ecf20Sopenharmony_ci * beginning. 16298c2ecf20Sopenharmony_ci */ 16308c2ecf20Sopenharmony_ci regval |= (ATH_ANT_DIV_COMB_LNA1 << 16318c2ecf20Sopenharmony_ci AR_PHY_ANT_DIV_MAIN_LNACONF_S); 16328c2ecf20Sopenharmony_ci regval |= (ATH_ANT_DIV_COMB_LNA2 << 16338c2ecf20Sopenharmony_ci AR_PHY_ANT_DIV_ALT_LNACONF_S); 16348c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval); 16358c2ecf20Sopenharmony_ci } 16368c2ecf20Sopenharmony_ci } else if (AR_SREV_9565(ah)) { 16378c2ecf20Sopenharmony_ci if (enable) { 16388c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_MC_GAIN_CTRL, 16398c2ecf20Sopenharmony_ci AR_ANT_DIV_ENABLE); 16408c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_MC_GAIN_CTRL, 16418c2ecf20Sopenharmony_ci (1 << AR_PHY_ANT_SW_RX_PROT_S)); 16428c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_CCK_DETECT, 16438c2ecf20Sopenharmony_ci AR_FAST_DIV_ENABLE); 16448c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_RESTART, 16458c2ecf20Sopenharmony_ci AR_PHY_RESTART_ENABLE_DIV_M2FLAG); 16468c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV, 16478c2ecf20Sopenharmony_ci AR_BTCOEX_WL_LNADIV_FORCE_ON); 16488c2ecf20Sopenharmony_ci } else { 16498c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL, 16508c2ecf20Sopenharmony_ci AR_ANT_DIV_ENABLE); 16518c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL, 16528c2ecf20Sopenharmony_ci (1 << AR_PHY_ANT_SW_RX_PROT_S)); 16538c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_PHY_CCK_DETECT, 16548c2ecf20Sopenharmony_ci AR_FAST_DIV_ENABLE); 16558c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_PHY_RESTART, 16568c2ecf20Sopenharmony_ci AR_PHY_RESTART_ENABLE_DIV_M2FLAG); 16578c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_BTCOEX_WL_LNADIV, 16588c2ecf20Sopenharmony_ci AR_BTCOEX_WL_LNADIV_FORCE_ON); 16598c2ecf20Sopenharmony_ci 16608c2ecf20Sopenharmony_ci regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL); 16618c2ecf20Sopenharmony_ci regval &= ~(AR_PHY_ANT_DIV_MAIN_LNACONF | 16628c2ecf20Sopenharmony_ci AR_PHY_ANT_DIV_ALT_LNACONF | 16638c2ecf20Sopenharmony_ci AR_PHY_ANT_DIV_MAIN_GAINTB | 16648c2ecf20Sopenharmony_ci AR_PHY_ANT_DIV_ALT_GAINTB); 16658c2ecf20Sopenharmony_ci regval |= (ATH_ANT_DIV_COMB_LNA1 << 16668c2ecf20Sopenharmony_ci AR_PHY_ANT_DIV_MAIN_LNACONF_S); 16678c2ecf20Sopenharmony_ci regval |= (ATH_ANT_DIV_COMB_LNA2 << 16688c2ecf20Sopenharmony_ci AR_PHY_ANT_DIV_ALT_LNACONF_S); 16698c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval); 16708c2ecf20Sopenharmony_ci } 16718c2ecf20Sopenharmony_ci } 16728c2ecf20Sopenharmony_ci} 16738c2ecf20Sopenharmony_ci 16748c2ecf20Sopenharmony_ci#endif 16758c2ecf20Sopenharmony_ci 16768c2ecf20Sopenharmony_cistatic int ar9003_hw_fast_chan_change(struct ath_hw *ah, 16778c2ecf20Sopenharmony_ci struct ath9k_channel *chan, 16788c2ecf20Sopenharmony_ci u8 *ini_reloaded) 16798c2ecf20Sopenharmony_ci{ 16808c2ecf20Sopenharmony_ci unsigned int regWrites = 0; 16818c2ecf20Sopenharmony_ci u32 modesIndex, txgain_index; 16828c2ecf20Sopenharmony_ci 16838c2ecf20Sopenharmony_ci if (IS_CHAN_5GHZ(chan)) 16848c2ecf20Sopenharmony_ci modesIndex = IS_CHAN_HT40(chan) ? 2 : 1; 16858c2ecf20Sopenharmony_ci else 16868c2ecf20Sopenharmony_ci modesIndex = IS_CHAN_HT40(chan) ? 3 : 4; 16878c2ecf20Sopenharmony_ci 16888c2ecf20Sopenharmony_ci txgain_index = AR_SREV_9531(ah) ? 1 : modesIndex; 16898c2ecf20Sopenharmony_ci 16908c2ecf20Sopenharmony_ci if (modesIndex == ah->modes_index) { 16918c2ecf20Sopenharmony_ci *ini_reloaded = false; 16928c2ecf20Sopenharmony_ci goto set_rfmode; 16938c2ecf20Sopenharmony_ci } 16948c2ecf20Sopenharmony_ci 16958c2ecf20Sopenharmony_ci ar9003_hw_prog_ini(ah, &ah->iniSOC[ATH_INI_POST], modesIndex); 16968c2ecf20Sopenharmony_ci ar9003_hw_prog_ini(ah, &ah->iniMac[ATH_INI_POST], modesIndex); 16978c2ecf20Sopenharmony_ci ar9003_hw_prog_ini(ah, &ah->iniBB[ATH_INI_POST], modesIndex); 16988c2ecf20Sopenharmony_ci ar9003_hw_prog_ini(ah, &ah->iniRadio[ATH_INI_POST], modesIndex); 16998c2ecf20Sopenharmony_ci 17008c2ecf20Sopenharmony_ci if (AR_SREV_9462_20_OR_LATER(ah)) 17018c2ecf20Sopenharmony_ci ar9003_hw_prog_ini(ah, &ah->ini_radio_post_sys2ant, 17028c2ecf20Sopenharmony_ci modesIndex); 17038c2ecf20Sopenharmony_ci 17048c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&ah->iniModesTxGain, txgain_index, regWrites); 17058c2ecf20Sopenharmony_ci 17068c2ecf20Sopenharmony_ci if (AR_SREV_9462_20_OR_LATER(ah)) { 17078c2ecf20Sopenharmony_ci /* 17088c2ecf20Sopenharmony_ci * CUS217 mix LNA mode. 17098c2ecf20Sopenharmony_ci */ 17108c2ecf20Sopenharmony_ci if (ar9003_hw_get_rx_gain_idx(ah) == 2) { 17118c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&ah->ini_modes_rxgain_bb_core, 17128c2ecf20Sopenharmony_ci 1, regWrites); 17138c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&ah->ini_modes_rxgain_bb_postamble, 17148c2ecf20Sopenharmony_ci modesIndex, regWrites); 17158c2ecf20Sopenharmony_ci } 17168c2ecf20Sopenharmony_ci } 17178c2ecf20Sopenharmony_ci 17188c2ecf20Sopenharmony_ci /* 17198c2ecf20Sopenharmony_ci * For 5GHz channels requiring Fast Clock, apply 17208c2ecf20Sopenharmony_ci * different modal values. 17218c2ecf20Sopenharmony_ci */ 17228c2ecf20Sopenharmony_ci if (IS_CHAN_A_FAST_CLOCK(ah, chan)) 17238c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&ah->iniModesFastClock, modesIndex, regWrites); 17248c2ecf20Sopenharmony_ci 17258c2ecf20Sopenharmony_ci if (AR_SREV_9565(ah)) 17268c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&ah->iniModesFastClock, 1, regWrites); 17278c2ecf20Sopenharmony_ci 17288c2ecf20Sopenharmony_ci /* 17298c2ecf20Sopenharmony_ci * JAPAN regulatory. 17308c2ecf20Sopenharmony_ci */ 17318c2ecf20Sopenharmony_ci if (chan->channel == 2484) 17328c2ecf20Sopenharmony_ci ar9003_hw_prog_ini(ah, &ah->iniCckfirJapan2484, 1); 17338c2ecf20Sopenharmony_ci 17348c2ecf20Sopenharmony_ci ah->modes_index = modesIndex; 17358c2ecf20Sopenharmony_ci *ini_reloaded = true; 17368c2ecf20Sopenharmony_ci 17378c2ecf20Sopenharmony_ciset_rfmode: 17388c2ecf20Sopenharmony_ci ar9003_hw_set_rfmode(ah, chan); 17398c2ecf20Sopenharmony_ci return 0; 17408c2ecf20Sopenharmony_ci} 17418c2ecf20Sopenharmony_ci 17428c2ecf20Sopenharmony_cistatic void ar9003_hw_spectral_scan_config(struct ath_hw *ah, 17438c2ecf20Sopenharmony_ci struct ath_spec_scan *param) 17448c2ecf20Sopenharmony_ci{ 17458c2ecf20Sopenharmony_ci u8 count; 17468c2ecf20Sopenharmony_ci 17478c2ecf20Sopenharmony_ci if (!param->enabled) { 17488c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_PHY_SPECTRAL_SCAN, 17498c2ecf20Sopenharmony_ci AR_PHY_SPECTRAL_SCAN_ENABLE); 17508c2ecf20Sopenharmony_ci return; 17518c2ecf20Sopenharmony_ci } 17528c2ecf20Sopenharmony_ci 17538c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_FFT_ENA); 17548c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN, AR_PHY_SPECTRAL_SCAN_ENABLE); 17558c2ecf20Sopenharmony_ci 17568c2ecf20Sopenharmony_ci /* on AR93xx and newer, count = 0 will make the the chip send 17578c2ecf20Sopenharmony_ci * spectral samples endlessly. Check if this really was intended, 17588c2ecf20Sopenharmony_ci * and fix otherwise. 17598c2ecf20Sopenharmony_ci */ 17608c2ecf20Sopenharmony_ci count = param->count; 17618c2ecf20Sopenharmony_ci if (param->endless) 17628c2ecf20Sopenharmony_ci count = 0; 17638c2ecf20Sopenharmony_ci else if (param->count == 0) 17648c2ecf20Sopenharmony_ci count = 1; 17658c2ecf20Sopenharmony_ci 17668c2ecf20Sopenharmony_ci if (param->short_repeat) 17678c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN, 17688c2ecf20Sopenharmony_ci AR_PHY_SPECTRAL_SCAN_SHORT_REPEAT); 17698c2ecf20Sopenharmony_ci else 17708c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_PHY_SPECTRAL_SCAN, 17718c2ecf20Sopenharmony_ci AR_PHY_SPECTRAL_SCAN_SHORT_REPEAT); 17728c2ecf20Sopenharmony_ci 17738c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN, 17748c2ecf20Sopenharmony_ci AR_PHY_SPECTRAL_SCAN_COUNT, count); 17758c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN, 17768c2ecf20Sopenharmony_ci AR_PHY_SPECTRAL_SCAN_PERIOD, param->period); 17778c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN, 17788c2ecf20Sopenharmony_ci AR_PHY_SPECTRAL_SCAN_FFT_PERIOD, param->fft_period); 17798c2ecf20Sopenharmony_ci 17808c2ecf20Sopenharmony_ci return; 17818c2ecf20Sopenharmony_ci} 17828c2ecf20Sopenharmony_ci 17838c2ecf20Sopenharmony_cistatic void ar9003_hw_spectral_scan_trigger(struct ath_hw *ah) 17848c2ecf20Sopenharmony_ci{ 17858c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN, 17868c2ecf20Sopenharmony_ci AR_PHY_SPECTRAL_SCAN_ENABLE); 17878c2ecf20Sopenharmony_ci /* Activate spectral scan */ 17888c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN, 17898c2ecf20Sopenharmony_ci AR_PHY_SPECTRAL_SCAN_ACTIVE); 17908c2ecf20Sopenharmony_ci} 17918c2ecf20Sopenharmony_ci 17928c2ecf20Sopenharmony_cistatic void ar9003_hw_spectral_scan_wait(struct ath_hw *ah) 17938c2ecf20Sopenharmony_ci{ 17948c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 17958c2ecf20Sopenharmony_ci 17968c2ecf20Sopenharmony_ci /* Poll for spectral scan complete */ 17978c2ecf20Sopenharmony_ci if (!ath9k_hw_wait(ah, AR_PHY_SPECTRAL_SCAN, 17988c2ecf20Sopenharmony_ci AR_PHY_SPECTRAL_SCAN_ACTIVE, 17998c2ecf20Sopenharmony_ci 0, AH_WAIT_TIMEOUT)) { 18008c2ecf20Sopenharmony_ci ath_err(common, "spectral scan wait failed\n"); 18018c2ecf20Sopenharmony_ci return; 18028c2ecf20Sopenharmony_ci } 18038c2ecf20Sopenharmony_ci} 18048c2ecf20Sopenharmony_ci 18058c2ecf20Sopenharmony_cistatic void ar9003_hw_tx99_start(struct ath_hw *ah, u32 qnum) 18068c2ecf20Sopenharmony_ci{ 18078c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_TEST, PHY_AGC_CLR); 18088c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS); 18098c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_CR, AR_CR_RXD); 18108c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_DLCL_IFS(qnum), 0); 18118c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_D_GBL_IFS_SIFS, 20); /* 50 OK */ 18128c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_D_GBL_IFS_EIFS, 20); 18138c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_TIME_OUT, 0x00000400); 18148c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_DRETRY_LIMIT(qnum), 0xffffffff); 18158c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_QMISC(qnum), AR_Q_MISC_DCU_EARLY_TERM_REQ); 18168c2ecf20Sopenharmony_ci} 18178c2ecf20Sopenharmony_ci 18188c2ecf20Sopenharmony_cistatic void ar9003_hw_tx99_stop(struct ath_hw *ah) 18198c2ecf20Sopenharmony_ci{ 18208c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_PHY_TEST, PHY_AGC_CLR); 18218c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS); 18228c2ecf20Sopenharmony_ci} 18238c2ecf20Sopenharmony_ci 18248c2ecf20Sopenharmony_cistatic void ar9003_hw_tx99_set_txpower(struct ath_hw *ah, u8 txpower) 18258c2ecf20Sopenharmony_ci{ 18268c2ecf20Sopenharmony_ci static u8 p_pwr_array[ar9300RateSize] = { 0 }; 18278c2ecf20Sopenharmony_ci unsigned int i; 18288c2ecf20Sopenharmony_ci 18298c2ecf20Sopenharmony_ci txpower = txpower <= MAX_RATE_POWER ? txpower : MAX_RATE_POWER; 18308c2ecf20Sopenharmony_ci for (i = 0; i < ar9300RateSize; i++) 18318c2ecf20Sopenharmony_ci p_pwr_array[i] = txpower; 18328c2ecf20Sopenharmony_ci 18338c2ecf20Sopenharmony_ci ar9003_hw_tx_power_regwrite(ah, p_pwr_array); 18348c2ecf20Sopenharmony_ci} 18358c2ecf20Sopenharmony_ci 18368c2ecf20Sopenharmony_cistatic void ar9003_hw_init_txpower_cck(struct ath_hw *ah, u8 *rate_array) 18378c2ecf20Sopenharmony_ci{ 18388c2ecf20Sopenharmony_ci ah->tx_power[0] = rate_array[ALL_TARGET_LEGACY_1L_5L]; 18398c2ecf20Sopenharmony_ci ah->tx_power[1] = rate_array[ALL_TARGET_LEGACY_1L_5L]; 18408c2ecf20Sopenharmony_ci ah->tx_power[2] = min(rate_array[ALL_TARGET_LEGACY_1L_5L], 18418c2ecf20Sopenharmony_ci rate_array[ALL_TARGET_LEGACY_5S]); 18428c2ecf20Sopenharmony_ci ah->tx_power[3] = min(rate_array[ALL_TARGET_LEGACY_11L], 18438c2ecf20Sopenharmony_ci rate_array[ALL_TARGET_LEGACY_11S]); 18448c2ecf20Sopenharmony_ci} 18458c2ecf20Sopenharmony_ci 18468c2ecf20Sopenharmony_cistatic void ar9003_hw_init_txpower_ofdm(struct ath_hw *ah, u8 *rate_array, 18478c2ecf20Sopenharmony_ci int offset) 18488c2ecf20Sopenharmony_ci{ 18498c2ecf20Sopenharmony_ci int i, j; 18508c2ecf20Sopenharmony_ci 18518c2ecf20Sopenharmony_ci for (i = offset; i < offset + AR9300_OFDM_RATES; i++) { 18528c2ecf20Sopenharmony_ci /* OFDM rate to power table idx */ 18538c2ecf20Sopenharmony_ci j = ofdm2pwr[i - offset]; 18548c2ecf20Sopenharmony_ci ah->tx_power[i] = rate_array[j]; 18558c2ecf20Sopenharmony_ci } 18568c2ecf20Sopenharmony_ci} 18578c2ecf20Sopenharmony_ci 18588c2ecf20Sopenharmony_cistatic void ar9003_hw_init_txpower_ht(struct ath_hw *ah, u8 *rate_array, 18598c2ecf20Sopenharmony_ci int ss_offset, int ds_offset, 18608c2ecf20Sopenharmony_ci int ts_offset, bool is_40) 18618c2ecf20Sopenharmony_ci{ 18628c2ecf20Sopenharmony_ci int i, j, mcs_idx = 0; 18638c2ecf20Sopenharmony_ci const u8 *mcs2pwr = (is_40) ? mcs2pwr_ht40 : mcs2pwr_ht20; 18648c2ecf20Sopenharmony_ci 18658c2ecf20Sopenharmony_ci for (i = ss_offset; i < ss_offset + AR9300_HT_SS_RATES; i++) { 18668c2ecf20Sopenharmony_ci j = mcs2pwr[mcs_idx]; 18678c2ecf20Sopenharmony_ci ah->tx_power[i] = rate_array[j]; 18688c2ecf20Sopenharmony_ci mcs_idx++; 18698c2ecf20Sopenharmony_ci } 18708c2ecf20Sopenharmony_ci 18718c2ecf20Sopenharmony_ci for (i = ds_offset; i < ds_offset + AR9300_HT_DS_RATES; i++) { 18728c2ecf20Sopenharmony_ci j = mcs2pwr[mcs_idx]; 18738c2ecf20Sopenharmony_ci ah->tx_power[i] = rate_array[j]; 18748c2ecf20Sopenharmony_ci mcs_idx++; 18758c2ecf20Sopenharmony_ci } 18768c2ecf20Sopenharmony_ci 18778c2ecf20Sopenharmony_ci for (i = ts_offset; i < ts_offset + AR9300_HT_TS_RATES; i++) { 18788c2ecf20Sopenharmony_ci j = mcs2pwr[mcs_idx]; 18798c2ecf20Sopenharmony_ci ah->tx_power[i] = rate_array[j]; 18808c2ecf20Sopenharmony_ci mcs_idx++; 18818c2ecf20Sopenharmony_ci } 18828c2ecf20Sopenharmony_ci} 18838c2ecf20Sopenharmony_ci 18848c2ecf20Sopenharmony_cistatic void ar9003_hw_init_txpower_stbc(struct ath_hw *ah, int ss_offset, 18858c2ecf20Sopenharmony_ci int ds_offset, int ts_offset) 18868c2ecf20Sopenharmony_ci{ 18878c2ecf20Sopenharmony_ci memcpy(&ah->tx_power_stbc[ss_offset], &ah->tx_power[ss_offset], 18888c2ecf20Sopenharmony_ci AR9300_HT_SS_RATES); 18898c2ecf20Sopenharmony_ci memcpy(&ah->tx_power_stbc[ds_offset], &ah->tx_power[ds_offset], 18908c2ecf20Sopenharmony_ci AR9300_HT_DS_RATES); 18918c2ecf20Sopenharmony_ci memcpy(&ah->tx_power_stbc[ts_offset], &ah->tx_power[ts_offset], 18928c2ecf20Sopenharmony_ci AR9300_HT_TS_RATES); 18938c2ecf20Sopenharmony_ci} 18948c2ecf20Sopenharmony_ci 18958c2ecf20Sopenharmony_civoid ar9003_hw_init_rate_txpower(struct ath_hw *ah, u8 *rate_array, 18968c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 18978c2ecf20Sopenharmony_ci{ 18988c2ecf20Sopenharmony_ci if (IS_CHAN_5GHZ(chan)) { 18998c2ecf20Sopenharmony_ci ar9003_hw_init_txpower_ofdm(ah, rate_array, 19008c2ecf20Sopenharmony_ci AR9300_11NA_OFDM_SHIFT); 19018c2ecf20Sopenharmony_ci if (IS_CHAN_HT20(chan) || IS_CHAN_HT40(chan)) { 19028c2ecf20Sopenharmony_ci ar9003_hw_init_txpower_ht(ah, rate_array, 19038c2ecf20Sopenharmony_ci AR9300_11NA_HT_SS_SHIFT, 19048c2ecf20Sopenharmony_ci AR9300_11NA_HT_DS_SHIFT, 19058c2ecf20Sopenharmony_ci AR9300_11NA_HT_TS_SHIFT, 19068c2ecf20Sopenharmony_ci IS_CHAN_HT40(chan)); 19078c2ecf20Sopenharmony_ci ar9003_hw_init_txpower_stbc(ah, 19088c2ecf20Sopenharmony_ci AR9300_11NA_HT_SS_SHIFT, 19098c2ecf20Sopenharmony_ci AR9300_11NA_HT_DS_SHIFT, 19108c2ecf20Sopenharmony_ci AR9300_11NA_HT_TS_SHIFT); 19118c2ecf20Sopenharmony_ci } 19128c2ecf20Sopenharmony_ci } else { 19138c2ecf20Sopenharmony_ci ar9003_hw_init_txpower_cck(ah, rate_array); 19148c2ecf20Sopenharmony_ci ar9003_hw_init_txpower_ofdm(ah, rate_array, 19158c2ecf20Sopenharmony_ci AR9300_11NG_OFDM_SHIFT); 19168c2ecf20Sopenharmony_ci if (IS_CHAN_HT20(chan) || IS_CHAN_HT40(chan)) { 19178c2ecf20Sopenharmony_ci ar9003_hw_init_txpower_ht(ah, rate_array, 19188c2ecf20Sopenharmony_ci AR9300_11NG_HT_SS_SHIFT, 19198c2ecf20Sopenharmony_ci AR9300_11NG_HT_DS_SHIFT, 19208c2ecf20Sopenharmony_ci AR9300_11NG_HT_TS_SHIFT, 19218c2ecf20Sopenharmony_ci IS_CHAN_HT40(chan)); 19228c2ecf20Sopenharmony_ci ar9003_hw_init_txpower_stbc(ah, 19238c2ecf20Sopenharmony_ci AR9300_11NG_HT_SS_SHIFT, 19248c2ecf20Sopenharmony_ci AR9300_11NG_HT_DS_SHIFT, 19258c2ecf20Sopenharmony_ci AR9300_11NG_HT_TS_SHIFT); 19268c2ecf20Sopenharmony_ci } 19278c2ecf20Sopenharmony_ci } 19288c2ecf20Sopenharmony_ci} 19298c2ecf20Sopenharmony_ci 19308c2ecf20Sopenharmony_civoid ar9003_hw_attach_phy_ops(struct ath_hw *ah) 19318c2ecf20Sopenharmony_ci{ 19328c2ecf20Sopenharmony_ci struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah); 19338c2ecf20Sopenharmony_ci struct ath_hw_ops *ops = ath9k_hw_ops(ah); 19348c2ecf20Sopenharmony_ci static const u32 ar9300_cca_regs[6] = { 19358c2ecf20Sopenharmony_ci AR_PHY_CCA_0, 19368c2ecf20Sopenharmony_ci AR_PHY_CCA_1, 19378c2ecf20Sopenharmony_ci AR_PHY_CCA_2, 19388c2ecf20Sopenharmony_ci AR_PHY_EXT_CCA, 19398c2ecf20Sopenharmony_ci AR_PHY_EXT_CCA_1, 19408c2ecf20Sopenharmony_ci AR_PHY_EXT_CCA_2, 19418c2ecf20Sopenharmony_ci }; 19428c2ecf20Sopenharmony_ci 19438c2ecf20Sopenharmony_ci priv_ops->rf_set_freq = ar9003_hw_set_channel; 19448c2ecf20Sopenharmony_ci priv_ops->spur_mitigate_freq = ar9003_hw_spur_mitigate; 19458c2ecf20Sopenharmony_ci 19468c2ecf20Sopenharmony_ci if (AR_SREV_9340(ah) || AR_SREV_9550(ah) || AR_SREV_9531(ah) || 19478c2ecf20Sopenharmony_ci AR_SREV_9561(ah)) 19488c2ecf20Sopenharmony_ci priv_ops->compute_pll_control = ar9003_hw_compute_pll_control_soc; 19498c2ecf20Sopenharmony_ci else 19508c2ecf20Sopenharmony_ci priv_ops->compute_pll_control = ar9003_hw_compute_pll_control; 19518c2ecf20Sopenharmony_ci 19528c2ecf20Sopenharmony_ci priv_ops->set_channel_regs = ar9003_hw_set_channel_regs; 19538c2ecf20Sopenharmony_ci priv_ops->init_bb = ar9003_hw_init_bb; 19548c2ecf20Sopenharmony_ci priv_ops->process_ini = ar9003_hw_process_ini; 19558c2ecf20Sopenharmony_ci priv_ops->set_rfmode = ar9003_hw_set_rfmode; 19568c2ecf20Sopenharmony_ci priv_ops->mark_phy_inactive = ar9003_hw_mark_phy_inactive; 19578c2ecf20Sopenharmony_ci priv_ops->set_delta_slope = ar9003_hw_set_delta_slope; 19588c2ecf20Sopenharmony_ci priv_ops->rfbus_req = ar9003_hw_rfbus_req; 19598c2ecf20Sopenharmony_ci priv_ops->rfbus_done = ar9003_hw_rfbus_done; 19608c2ecf20Sopenharmony_ci priv_ops->ani_control = ar9003_hw_ani_control; 19618c2ecf20Sopenharmony_ci priv_ops->do_getnf = ar9003_hw_do_getnf; 19628c2ecf20Sopenharmony_ci priv_ops->ani_cache_ini_regs = ar9003_hw_ani_cache_ini_regs; 19638c2ecf20Sopenharmony_ci priv_ops->set_radar_params = ar9003_hw_set_radar_params; 19648c2ecf20Sopenharmony_ci priv_ops->fast_chan_change = ar9003_hw_fast_chan_change; 19658c2ecf20Sopenharmony_ci 19668c2ecf20Sopenharmony_ci ops->antdiv_comb_conf_get = ar9003_hw_antdiv_comb_conf_get; 19678c2ecf20Sopenharmony_ci ops->antdiv_comb_conf_set = ar9003_hw_antdiv_comb_conf_set; 19688c2ecf20Sopenharmony_ci ops->spectral_scan_config = ar9003_hw_spectral_scan_config; 19698c2ecf20Sopenharmony_ci ops->spectral_scan_trigger = ar9003_hw_spectral_scan_trigger; 19708c2ecf20Sopenharmony_ci ops->spectral_scan_wait = ar9003_hw_spectral_scan_wait; 19718c2ecf20Sopenharmony_ci 19728c2ecf20Sopenharmony_ci#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT 19738c2ecf20Sopenharmony_ci ops->set_bt_ant_diversity = ar9003_hw_set_bt_ant_diversity; 19748c2ecf20Sopenharmony_ci#endif 19758c2ecf20Sopenharmony_ci ops->tx99_start = ar9003_hw_tx99_start; 19768c2ecf20Sopenharmony_ci ops->tx99_stop = ar9003_hw_tx99_stop; 19778c2ecf20Sopenharmony_ci ops->tx99_set_txpower = ar9003_hw_tx99_set_txpower; 19788c2ecf20Sopenharmony_ci 19798c2ecf20Sopenharmony_ci ar9003_hw_set_nf_limits(ah); 19808c2ecf20Sopenharmony_ci ar9003_hw_set_radar_conf(ah); 19818c2ecf20Sopenharmony_ci memcpy(ah->nf_regs, ar9300_cca_regs, sizeof(ah->nf_regs)); 19828c2ecf20Sopenharmony_ci} 19838c2ecf20Sopenharmony_ci 19848c2ecf20Sopenharmony_ci/* 19858c2ecf20Sopenharmony_ci * Baseband Watchdog signatures: 19868c2ecf20Sopenharmony_ci * 19878c2ecf20Sopenharmony_ci * 0x04000539: BB hang when operating in HT40 DFS Channel. 19888c2ecf20Sopenharmony_ci * Full chip reset is not required, but a recovery 19898c2ecf20Sopenharmony_ci * mechanism is needed. 19908c2ecf20Sopenharmony_ci * 19918c2ecf20Sopenharmony_ci * 0x1300000a: Related to CAC deafness. 19928c2ecf20Sopenharmony_ci * Chip reset is not required. 19938c2ecf20Sopenharmony_ci * 19948c2ecf20Sopenharmony_ci * 0x0400000a: Related to CAC deafness. 19958c2ecf20Sopenharmony_ci * Full chip reset is required. 19968c2ecf20Sopenharmony_ci * 19978c2ecf20Sopenharmony_ci * 0x04000b09: RX state machine gets into an illegal state 19988c2ecf20Sopenharmony_ci * when a packet with unsupported rate is received. 19998c2ecf20Sopenharmony_ci * Full chip reset is required and PHY_RESTART has 20008c2ecf20Sopenharmony_ci * to be disabled. 20018c2ecf20Sopenharmony_ci * 20028c2ecf20Sopenharmony_ci * 0x04000409: Packet stuck on receive. 20038c2ecf20Sopenharmony_ci * Full chip reset is required for all chips except 20048c2ecf20Sopenharmony_ci * AR9340, AR9531 and AR9561. 20058c2ecf20Sopenharmony_ci */ 20068c2ecf20Sopenharmony_ci 20078c2ecf20Sopenharmony_ci/* 20088c2ecf20Sopenharmony_ci * ar9003_hw_bb_watchdog_check(): Returns true if a chip reset is required. 20098c2ecf20Sopenharmony_ci */ 20108c2ecf20Sopenharmony_cibool ar9003_hw_bb_watchdog_check(struct ath_hw *ah) 20118c2ecf20Sopenharmony_ci{ 20128c2ecf20Sopenharmony_ci u32 val; 20138c2ecf20Sopenharmony_ci 20148c2ecf20Sopenharmony_ci switch(ah->bb_watchdog_last_status) { 20158c2ecf20Sopenharmony_ci case 0x04000539: 20168c2ecf20Sopenharmony_ci val = REG_READ(ah, AR_PHY_RADAR_0); 20178c2ecf20Sopenharmony_ci val &= (~AR_PHY_RADAR_0_FIRPWR); 20188c2ecf20Sopenharmony_ci val |= SM(0x7f, AR_PHY_RADAR_0_FIRPWR); 20198c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_RADAR_0, val); 20208c2ecf20Sopenharmony_ci udelay(1); 20218c2ecf20Sopenharmony_ci val = REG_READ(ah, AR_PHY_RADAR_0); 20228c2ecf20Sopenharmony_ci val &= ~AR_PHY_RADAR_0_FIRPWR; 20238c2ecf20Sopenharmony_ci val |= SM(AR9300_DFS_FIRPWR, AR_PHY_RADAR_0_FIRPWR); 20248c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_RADAR_0, val); 20258c2ecf20Sopenharmony_ci 20268c2ecf20Sopenharmony_ci return false; 20278c2ecf20Sopenharmony_ci case 0x1300000a: 20288c2ecf20Sopenharmony_ci return false; 20298c2ecf20Sopenharmony_ci case 0x0400000a: 20308c2ecf20Sopenharmony_ci case 0x04000b09: 20318c2ecf20Sopenharmony_ci return true; 20328c2ecf20Sopenharmony_ci case 0x04000409: 20338c2ecf20Sopenharmony_ci if (AR_SREV_9340(ah) || AR_SREV_9531(ah) || AR_SREV_9561(ah)) 20348c2ecf20Sopenharmony_ci return false; 20358c2ecf20Sopenharmony_ci else 20368c2ecf20Sopenharmony_ci return true; 20378c2ecf20Sopenharmony_ci default: 20388c2ecf20Sopenharmony_ci /* 20398c2ecf20Sopenharmony_ci * For any other unknown signatures, do a 20408c2ecf20Sopenharmony_ci * full chip reset. 20418c2ecf20Sopenharmony_ci */ 20428c2ecf20Sopenharmony_ci return true; 20438c2ecf20Sopenharmony_ci } 20448c2ecf20Sopenharmony_ci} 20458c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ar9003_hw_bb_watchdog_check); 20468c2ecf20Sopenharmony_ci 20478c2ecf20Sopenharmony_civoid ar9003_hw_bb_watchdog_config(struct ath_hw *ah) 20488c2ecf20Sopenharmony_ci{ 20498c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 20508c2ecf20Sopenharmony_ci u32 idle_tmo_ms = ah->bb_watchdog_timeout_ms; 20518c2ecf20Sopenharmony_ci u32 val, idle_count; 20528c2ecf20Sopenharmony_ci 20538c2ecf20Sopenharmony_ci if (!idle_tmo_ms) { 20548c2ecf20Sopenharmony_ci /* disable IRQ, disable chip-reset for BB panic */ 20558c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2, 20568c2ecf20Sopenharmony_ci REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) & 20578c2ecf20Sopenharmony_ci ~(AR_PHY_WATCHDOG_RST_ENABLE | 20588c2ecf20Sopenharmony_ci AR_PHY_WATCHDOG_IRQ_ENABLE)); 20598c2ecf20Sopenharmony_ci 20608c2ecf20Sopenharmony_ci /* disable watchdog in non-IDLE mode, disable in IDLE mode */ 20618c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1, 20628c2ecf20Sopenharmony_ci REG_READ(ah, AR_PHY_WATCHDOG_CTL_1) & 20638c2ecf20Sopenharmony_ci ~(AR_PHY_WATCHDOG_NON_IDLE_ENABLE | 20648c2ecf20Sopenharmony_ci AR_PHY_WATCHDOG_IDLE_ENABLE)); 20658c2ecf20Sopenharmony_ci 20668c2ecf20Sopenharmony_ci ath_dbg(common, RESET, "Disabled BB Watchdog\n"); 20678c2ecf20Sopenharmony_ci return; 20688c2ecf20Sopenharmony_ci } 20698c2ecf20Sopenharmony_ci 20708c2ecf20Sopenharmony_ci /* enable IRQ, disable chip-reset for BB watchdog */ 20718c2ecf20Sopenharmony_ci val = REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) & AR_PHY_WATCHDOG_CNTL2_MASK; 20728c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2, 20738c2ecf20Sopenharmony_ci (val | AR_PHY_WATCHDOG_IRQ_ENABLE) & 20748c2ecf20Sopenharmony_ci ~AR_PHY_WATCHDOG_RST_ENABLE); 20758c2ecf20Sopenharmony_ci 20768c2ecf20Sopenharmony_ci /* bound limit to 10 secs */ 20778c2ecf20Sopenharmony_ci if (idle_tmo_ms > 10000) 20788c2ecf20Sopenharmony_ci idle_tmo_ms = 10000; 20798c2ecf20Sopenharmony_ci 20808c2ecf20Sopenharmony_ci /* 20818c2ecf20Sopenharmony_ci * The time unit for watchdog event is 2^15 44/88MHz cycles. 20828c2ecf20Sopenharmony_ci * 20838c2ecf20Sopenharmony_ci * For HT20 we have a time unit of 2^15/44 MHz = .74 ms per tick 20848c2ecf20Sopenharmony_ci * For HT40 we have a time unit of 2^15/88 MHz = .37 ms per tick 20858c2ecf20Sopenharmony_ci * 20868c2ecf20Sopenharmony_ci * Given we use fast clock now in 5 GHz, these time units should 20878c2ecf20Sopenharmony_ci * be common for both 2 GHz and 5 GHz. 20888c2ecf20Sopenharmony_ci */ 20898c2ecf20Sopenharmony_ci idle_count = (100 * idle_tmo_ms) / 74; 20908c2ecf20Sopenharmony_ci if (ah->curchan && IS_CHAN_HT40(ah->curchan)) 20918c2ecf20Sopenharmony_ci idle_count = (100 * idle_tmo_ms) / 37; 20928c2ecf20Sopenharmony_ci 20938c2ecf20Sopenharmony_ci /* 20948c2ecf20Sopenharmony_ci * enable watchdog in non-IDLE mode, disable in IDLE mode, 20958c2ecf20Sopenharmony_ci * set idle time-out. 20968c2ecf20Sopenharmony_ci */ 20978c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1, 20988c2ecf20Sopenharmony_ci AR_PHY_WATCHDOG_NON_IDLE_ENABLE | 20998c2ecf20Sopenharmony_ci AR_PHY_WATCHDOG_IDLE_MASK | 21008c2ecf20Sopenharmony_ci (AR_PHY_WATCHDOG_NON_IDLE_MASK & (idle_count << 2))); 21018c2ecf20Sopenharmony_ci 21028c2ecf20Sopenharmony_ci ath_dbg(common, RESET, "Enabled BB Watchdog timeout (%u ms)\n", 21038c2ecf20Sopenharmony_ci idle_tmo_ms); 21048c2ecf20Sopenharmony_ci} 21058c2ecf20Sopenharmony_ci 21068c2ecf20Sopenharmony_civoid ar9003_hw_bb_watchdog_read(struct ath_hw *ah) 21078c2ecf20Sopenharmony_ci{ 21088c2ecf20Sopenharmony_ci /* 21098c2ecf20Sopenharmony_ci * we want to avoid printing in ISR context so we save the 21108c2ecf20Sopenharmony_ci * watchdog status to be printed later in bottom half context. 21118c2ecf20Sopenharmony_ci */ 21128c2ecf20Sopenharmony_ci ah->bb_watchdog_last_status = REG_READ(ah, AR_PHY_WATCHDOG_STATUS); 21138c2ecf20Sopenharmony_ci 21148c2ecf20Sopenharmony_ci /* 21158c2ecf20Sopenharmony_ci * the watchdog timer should reset on status read but to be sure 21168c2ecf20Sopenharmony_ci * sure we write 0 to the watchdog status bit. 21178c2ecf20Sopenharmony_ci */ 21188c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_WATCHDOG_STATUS, 21198c2ecf20Sopenharmony_ci ah->bb_watchdog_last_status & ~AR_PHY_WATCHDOG_STATUS_CLR); 21208c2ecf20Sopenharmony_ci} 21218c2ecf20Sopenharmony_ci 21228c2ecf20Sopenharmony_civoid ar9003_hw_bb_watchdog_dbg_info(struct ath_hw *ah) 21238c2ecf20Sopenharmony_ci{ 21248c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 21258c2ecf20Sopenharmony_ci u32 status; 21268c2ecf20Sopenharmony_ci 21278c2ecf20Sopenharmony_ci if (likely(!(common->debug_mask & ATH_DBG_RESET))) 21288c2ecf20Sopenharmony_ci return; 21298c2ecf20Sopenharmony_ci 21308c2ecf20Sopenharmony_ci status = ah->bb_watchdog_last_status; 21318c2ecf20Sopenharmony_ci ath_dbg(common, RESET, 21328c2ecf20Sopenharmony_ci "\n==== BB update: BB status=0x%08x ====\n", status); 21338c2ecf20Sopenharmony_ci ath_dbg(common, RESET, 21348c2ecf20Sopenharmony_ci "** BB state: wd=%u det=%u rdar=%u rOFDM=%d rCCK=%u tOFDM=%u tCCK=%u agc=%u src=%u **\n", 21358c2ecf20Sopenharmony_ci MS(status, AR_PHY_WATCHDOG_INFO), 21368c2ecf20Sopenharmony_ci MS(status, AR_PHY_WATCHDOG_DET_HANG), 21378c2ecf20Sopenharmony_ci MS(status, AR_PHY_WATCHDOG_RADAR_SM), 21388c2ecf20Sopenharmony_ci MS(status, AR_PHY_WATCHDOG_RX_OFDM_SM), 21398c2ecf20Sopenharmony_ci MS(status, AR_PHY_WATCHDOG_RX_CCK_SM), 21408c2ecf20Sopenharmony_ci MS(status, AR_PHY_WATCHDOG_TX_OFDM_SM), 21418c2ecf20Sopenharmony_ci MS(status, AR_PHY_WATCHDOG_TX_CCK_SM), 21428c2ecf20Sopenharmony_ci MS(status, AR_PHY_WATCHDOG_AGC_SM), 21438c2ecf20Sopenharmony_ci MS(status, AR_PHY_WATCHDOG_SRCH_SM)); 21448c2ecf20Sopenharmony_ci 21458c2ecf20Sopenharmony_ci ath_dbg(common, RESET, "** BB WD cntl: cntl1=0x%08x cntl2=0x%08x **\n", 21468c2ecf20Sopenharmony_ci REG_READ(ah, AR_PHY_WATCHDOG_CTL_1), 21478c2ecf20Sopenharmony_ci REG_READ(ah, AR_PHY_WATCHDOG_CTL_2)); 21488c2ecf20Sopenharmony_ci ath_dbg(common, RESET, "** BB mode: BB_gen_controls=0x%08x **\n", 21498c2ecf20Sopenharmony_ci REG_READ(ah, AR_PHY_GEN_CTRL)); 21508c2ecf20Sopenharmony_ci 21518c2ecf20Sopenharmony_ci#define PCT(_field) (common->cc_survey._field * 100 / common->cc_survey.cycles) 21528c2ecf20Sopenharmony_ci if (common->cc_survey.cycles) 21538c2ecf20Sopenharmony_ci ath_dbg(common, RESET, 21548c2ecf20Sopenharmony_ci "** BB busy times: rx_clear=%d%%, rx_frame=%d%%, tx_frame=%d%% **\n", 21558c2ecf20Sopenharmony_ci PCT(rx_busy), PCT(rx_frame), PCT(tx_frame)); 21568c2ecf20Sopenharmony_ci 21578c2ecf20Sopenharmony_ci ath_dbg(common, RESET, "==== BB update: done ====\n\n"); 21588c2ecf20Sopenharmony_ci} 21598c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ar9003_hw_bb_watchdog_dbg_info); 21608c2ecf20Sopenharmony_ci 21618c2ecf20Sopenharmony_civoid ar9003_hw_disable_phy_restart(struct ath_hw *ah) 21628c2ecf20Sopenharmony_ci{ 21638c2ecf20Sopenharmony_ci u8 result; 21648c2ecf20Sopenharmony_ci u32 val; 21658c2ecf20Sopenharmony_ci 21668c2ecf20Sopenharmony_ci /* While receiving unsupported rate frame rx state machine 21678c2ecf20Sopenharmony_ci * gets into a state 0xb and if phy_restart happens in that 21688c2ecf20Sopenharmony_ci * state, BB would go hang. If RXSM is in 0xb state after 21698c2ecf20Sopenharmony_ci * first bb panic, ensure to disable the phy_restart. 21708c2ecf20Sopenharmony_ci */ 21718c2ecf20Sopenharmony_ci result = MS(ah->bb_watchdog_last_status, AR_PHY_WATCHDOG_RX_OFDM_SM); 21728c2ecf20Sopenharmony_ci 21738c2ecf20Sopenharmony_ci if ((result == 0xb) || ah->bb_hang_rx_ofdm) { 21748c2ecf20Sopenharmony_ci ah->bb_hang_rx_ofdm = true; 21758c2ecf20Sopenharmony_ci val = REG_READ(ah, AR_PHY_RESTART); 21768c2ecf20Sopenharmony_ci val &= ~AR_PHY_RESTART_ENA; 21778c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_RESTART, val); 21788c2ecf20Sopenharmony_ci } 21798c2ecf20Sopenharmony_ci} 21808c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ar9003_hw_disable_phy_restart); 2181