18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2008-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 "hw.h" 188c2ecf20Sopenharmony_ci#include "hw-ops.h" 198c2ecf20Sopenharmony_ci#include "../regd.h" 208c2ecf20Sopenharmony_ci#include "ar9002_phy.h" 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* All code below is for AR5008, AR9001, AR9002 */ 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#define AR5008_OFDM_RATES 8 258c2ecf20Sopenharmony_ci#define AR5008_HT_SS_RATES 8 268c2ecf20Sopenharmony_ci#define AR5008_HT_DS_RATES 8 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#define AR5008_HT20_SHIFT 16 298c2ecf20Sopenharmony_ci#define AR5008_HT40_SHIFT 24 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#define AR5008_11NA_OFDM_SHIFT 0 328c2ecf20Sopenharmony_ci#define AR5008_11NA_HT_SS_SHIFT 8 338c2ecf20Sopenharmony_ci#define AR5008_11NA_HT_DS_SHIFT 16 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#define AR5008_11NG_OFDM_SHIFT 4 368c2ecf20Sopenharmony_ci#define AR5008_11NG_HT_SS_SHIFT 12 378c2ecf20Sopenharmony_ci#define AR5008_11NG_HT_DS_SHIFT 20 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci/* 408c2ecf20Sopenharmony_ci * register values to turn OFDM weak signal detection OFF 418c2ecf20Sopenharmony_ci */ 428c2ecf20Sopenharmony_cistatic const int m1ThreshLow_off = 127; 438c2ecf20Sopenharmony_cistatic const int m2ThreshLow_off = 127; 448c2ecf20Sopenharmony_cistatic const int m1Thresh_off = 127; 458c2ecf20Sopenharmony_cistatic const int m2Thresh_off = 127; 468c2ecf20Sopenharmony_cistatic const int m2CountThr_off = 31; 478c2ecf20Sopenharmony_cistatic const int m2CountThrLow_off = 63; 488c2ecf20Sopenharmony_cistatic const int m1ThreshLowExt_off = 127; 498c2ecf20Sopenharmony_cistatic const int m2ThreshLowExt_off = 127; 508c2ecf20Sopenharmony_cistatic const int m1ThreshExt_off = 127; 518c2ecf20Sopenharmony_cistatic const int m2ThreshExt_off = 127; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_cistatic const u32 ar5416Bank0[][2] = { 548c2ecf20Sopenharmony_ci /* Addr allmodes */ 558c2ecf20Sopenharmony_ci {0x000098b0, 0x1e5795e5}, 568c2ecf20Sopenharmony_ci {0x000098e0, 0x02008020}, 578c2ecf20Sopenharmony_ci}; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_cistatic const u32 ar5416Bank1[][2] = { 608c2ecf20Sopenharmony_ci /* Addr allmodes */ 618c2ecf20Sopenharmony_ci {0x000098b0, 0x02108421}, 628c2ecf20Sopenharmony_ci {0x000098ec, 0x00000008}, 638c2ecf20Sopenharmony_ci}; 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_cistatic const u32 ar5416Bank2[][2] = { 668c2ecf20Sopenharmony_ci /* Addr allmodes */ 678c2ecf20Sopenharmony_ci {0x000098b0, 0x0e73ff17}, 688c2ecf20Sopenharmony_ci {0x000098e0, 0x00000420}, 698c2ecf20Sopenharmony_ci}; 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_cistatic const u32 ar5416Bank3[][3] = { 728c2ecf20Sopenharmony_ci /* Addr 5G 2G */ 738c2ecf20Sopenharmony_ci {0x000098f0, 0x01400018, 0x01c00018}, 748c2ecf20Sopenharmony_ci}; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_cistatic const u32 ar5416Bank7[][2] = { 778c2ecf20Sopenharmony_ci /* Addr allmodes */ 788c2ecf20Sopenharmony_ci {0x0000989c, 0x00000500}, 798c2ecf20Sopenharmony_ci {0x0000989c, 0x00000800}, 808c2ecf20Sopenharmony_ci {0x000098cc, 0x0000000e}, 818c2ecf20Sopenharmony_ci}; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_cistatic const struct ar5416IniArray bank0 = STATIC_INI_ARRAY(ar5416Bank0); 848c2ecf20Sopenharmony_cistatic const struct ar5416IniArray bank1 = STATIC_INI_ARRAY(ar5416Bank1); 858c2ecf20Sopenharmony_cistatic const struct ar5416IniArray bank2 = STATIC_INI_ARRAY(ar5416Bank2); 868c2ecf20Sopenharmony_cistatic const struct ar5416IniArray bank3 = STATIC_INI_ARRAY(ar5416Bank3); 878c2ecf20Sopenharmony_cistatic const struct ar5416IniArray bank7 = STATIC_INI_ARRAY(ar5416Bank7); 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_cistatic void ar5008_write_bank6(struct ath_hw *ah, unsigned int *writecnt) 908c2ecf20Sopenharmony_ci{ 918c2ecf20Sopenharmony_ci struct ar5416IniArray *array = &ah->iniBank6; 928c2ecf20Sopenharmony_ci u32 *data = ah->analogBank6Data; 938c2ecf20Sopenharmony_ci int r; 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci ENABLE_REGWRITE_BUFFER(ah); 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci for (r = 0; r < array->ia_rows; r++) { 988c2ecf20Sopenharmony_ci REG_WRITE(ah, INI_RA(array, r, 0), data[r]); 998c2ecf20Sopenharmony_ci DO_DELAY(*writecnt); 1008c2ecf20Sopenharmony_ci } 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci REGWRITE_BUFFER_FLUSH(ah); 1038c2ecf20Sopenharmony_ci} 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci/** 1068c2ecf20Sopenharmony_ci * ar5008_hw_phy_modify_rx_buffer() - perform analog swizzling of parameters 1078c2ecf20Sopenharmony_ci * @rfbuf: 1088c2ecf20Sopenharmony_ci * @reg32: 1098c2ecf20Sopenharmony_ci * @numBits: 1108c2ecf20Sopenharmony_ci * @firstBit: 1118c2ecf20Sopenharmony_ci * @column: 1128c2ecf20Sopenharmony_ci * 1138c2ecf20Sopenharmony_ci * Performs analog "swizzling" of parameters into their location. 1148c2ecf20Sopenharmony_ci * Used on external AR2133/AR5133 radios. 1158c2ecf20Sopenharmony_ci */ 1168c2ecf20Sopenharmony_cistatic void ar5008_hw_phy_modify_rx_buffer(u32 *rfBuf, u32 reg32, 1178c2ecf20Sopenharmony_ci u32 numBits, u32 firstBit, 1188c2ecf20Sopenharmony_ci u32 column) 1198c2ecf20Sopenharmony_ci{ 1208c2ecf20Sopenharmony_ci u32 tmp32, mask, arrayEntry, lastBit; 1218c2ecf20Sopenharmony_ci int32_t bitPosition, bitsLeft; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci tmp32 = ath9k_hw_reverse_bits(reg32, numBits); 1248c2ecf20Sopenharmony_ci arrayEntry = (firstBit - 1) / 8; 1258c2ecf20Sopenharmony_ci bitPosition = (firstBit - 1) % 8; 1268c2ecf20Sopenharmony_ci bitsLeft = numBits; 1278c2ecf20Sopenharmony_ci while (bitsLeft > 0) { 1288c2ecf20Sopenharmony_ci lastBit = (bitPosition + bitsLeft > 8) ? 1298c2ecf20Sopenharmony_ci 8 : bitPosition + bitsLeft; 1308c2ecf20Sopenharmony_ci mask = (((1 << lastBit) - 1) ^ ((1 << bitPosition) - 1)) << 1318c2ecf20Sopenharmony_ci (column * 8); 1328c2ecf20Sopenharmony_ci rfBuf[arrayEntry] &= ~mask; 1338c2ecf20Sopenharmony_ci rfBuf[arrayEntry] |= ((tmp32 << bitPosition) << 1348c2ecf20Sopenharmony_ci (column * 8)) & mask; 1358c2ecf20Sopenharmony_ci bitsLeft -= 8 - bitPosition; 1368c2ecf20Sopenharmony_ci tmp32 = tmp32 >> (8 - bitPosition); 1378c2ecf20Sopenharmony_ci bitPosition = 0; 1388c2ecf20Sopenharmony_ci arrayEntry++; 1398c2ecf20Sopenharmony_ci } 1408c2ecf20Sopenharmony_ci} 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci/* 1438c2ecf20Sopenharmony_ci * Fix on 2.4 GHz band for orientation sensitivity issue by increasing 1448c2ecf20Sopenharmony_ci * rf_pwd_icsyndiv. 1458c2ecf20Sopenharmony_ci * 1468c2ecf20Sopenharmony_ci * Theoretical Rules: 1478c2ecf20Sopenharmony_ci * if 2 GHz band 1488c2ecf20Sopenharmony_ci * if forceBiasAuto 1498c2ecf20Sopenharmony_ci * if synth_freq < 2412 1508c2ecf20Sopenharmony_ci * bias = 0 1518c2ecf20Sopenharmony_ci * else if 2412 <= synth_freq <= 2422 1528c2ecf20Sopenharmony_ci * bias = 1 1538c2ecf20Sopenharmony_ci * else // synth_freq > 2422 1548c2ecf20Sopenharmony_ci * bias = 2 1558c2ecf20Sopenharmony_ci * else if forceBias > 0 1568c2ecf20Sopenharmony_ci * bias = forceBias & 7 1578c2ecf20Sopenharmony_ci * else 1588c2ecf20Sopenharmony_ci * no change, use value from ini file 1598c2ecf20Sopenharmony_ci * else 1608c2ecf20Sopenharmony_ci * no change, invalid band 1618c2ecf20Sopenharmony_ci * 1628c2ecf20Sopenharmony_ci * 1st Mod: 1638c2ecf20Sopenharmony_ci * 2422 also uses value of 2 1648c2ecf20Sopenharmony_ci * <approved> 1658c2ecf20Sopenharmony_ci * 1668c2ecf20Sopenharmony_ci * 2nd Mod: 1678c2ecf20Sopenharmony_ci * Less than 2412 uses value of 0, 2412 and above uses value of 2 1688c2ecf20Sopenharmony_ci */ 1698c2ecf20Sopenharmony_cistatic void ar5008_hw_force_bias(struct ath_hw *ah, u16 synth_freq) 1708c2ecf20Sopenharmony_ci{ 1718c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 1728c2ecf20Sopenharmony_ci u32 tmp_reg; 1738c2ecf20Sopenharmony_ci int reg_writes = 0; 1748c2ecf20Sopenharmony_ci u32 new_bias = 0; 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci if (!AR_SREV_5416(ah) || synth_freq >= 3000) 1778c2ecf20Sopenharmony_ci return; 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci BUG_ON(AR_SREV_9280_20_OR_LATER(ah)); 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci if (synth_freq < 2412) 1828c2ecf20Sopenharmony_ci new_bias = 0; 1838c2ecf20Sopenharmony_ci else if (synth_freq < 2422) 1848c2ecf20Sopenharmony_ci new_bias = 1; 1858c2ecf20Sopenharmony_ci else 1868c2ecf20Sopenharmony_ci new_bias = 2; 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci /* pre-reverse this field */ 1898c2ecf20Sopenharmony_ci tmp_reg = ath9k_hw_reverse_bits(new_bias, 3); 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci ath_dbg(common, CONFIG, "Force rf_pwd_icsyndiv to %1d on %4d\n", 1928c2ecf20Sopenharmony_ci new_bias, synth_freq); 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci /* swizzle rf_pwd_icsyndiv */ 1958c2ecf20Sopenharmony_ci ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data, tmp_reg, 3, 181, 3); 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci /* write Bank 6 with new params */ 1988c2ecf20Sopenharmony_ci ar5008_write_bank6(ah, ®_writes); 1998c2ecf20Sopenharmony_ci} 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci/** 2028c2ecf20Sopenharmony_ci * ar5008_hw_set_channel - tune to a channel on the external AR2133/AR5133 radios 2038c2ecf20Sopenharmony_ci * @ah: atheros hardware structure 2048c2ecf20Sopenharmony_ci * @chan: 2058c2ecf20Sopenharmony_ci * 2068c2ecf20Sopenharmony_ci * For the external AR2133/AR5133 radios, takes the MHz channel value and set 2078c2ecf20Sopenharmony_ci * the channel value. Assumes writes enabled to analog bus and bank6 register 2088c2ecf20Sopenharmony_ci * cache in ah->analogBank6Data. 2098c2ecf20Sopenharmony_ci */ 2108c2ecf20Sopenharmony_cistatic int ar5008_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan) 2118c2ecf20Sopenharmony_ci{ 2128c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 2138c2ecf20Sopenharmony_ci u32 channelSel = 0; 2148c2ecf20Sopenharmony_ci u32 bModeSynth = 0; 2158c2ecf20Sopenharmony_ci u32 aModeRefSel = 0; 2168c2ecf20Sopenharmony_ci u32 reg32 = 0; 2178c2ecf20Sopenharmony_ci u16 freq; 2188c2ecf20Sopenharmony_ci struct chan_centers centers; 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci ath9k_hw_get_channel_centers(ah, chan, ¢ers); 2218c2ecf20Sopenharmony_ci freq = centers.synth_center; 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci if (freq < 4800) { 2248c2ecf20Sopenharmony_ci u32 txctl; 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci if (((freq - 2192) % 5) == 0) { 2278c2ecf20Sopenharmony_ci channelSel = ((freq - 672) * 2 - 3040) / 10; 2288c2ecf20Sopenharmony_ci bModeSynth = 0; 2298c2ecf20Sopenharmony_ci } else if (((freq - 2224) % 5) == 0) { 2308c2ecf20Sopenharmony_ci channelSel = ((freq - 704) * 2 - 3040) / 10; 2318c2ecf20Sopenharmony_ci bModeSynth = 1; 2328c2ecf20Sopenharmony_ci } else { 2338c2ecf20Sopenharmony_ci ath_err(common, "Invalid channel %u MHz\n", freq); 2348c2ecf20Sopenharmony_ci return -EINVAL; 2358c2ecf20Sopenharmony_ci } 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci channelSel = (channelSel << 2) & 0xff; 2388c2ecf20Sopenharmony_ci channelSel = ath9k_hw_reverse_bits(channelSel, 8); 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci txctl = REG_READ(ah, AR_PHY_CCK_TX_CTRL); 2418c2ecf20Sopenharmony_ci if (freq == 2484) { 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_CCK_TX_CTRL, 2448c2ecf20Sopenharmony_ci txctl | AR_PHY_CCK_TX_CTRL_JAPAN); 2458c2ecf20Sopenharmony_ci } else { 2468c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_CCK_TX_CTRL, 2478c2ecf20Sopenharmony_ci txctl & ~AR_PHY_CCK_TX_CTRL_JAPAN); 2488c2ecf20Sopenharmony_ci } 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci } else if ((freq % 20) == 0 && freq >= 5120) { 2518c2ecf20Sopenharmony_ci channelSel = 2528c2ecf20Sopenharmony_ci ath9k_hw_reverse_bits(((freq - 4800) / 20 << 2), 8); 2538c2ecf20Sopenharmony_ci aModeRefSel = ath9k_hw_reverse_bits(1, 2); 2548c2ecf20Sopenharmony_ci } else if ((freq % 10) == 0) { 2558c2ecf20Sopenharmony_ci channelSel = 2568c2ecf20Sopenharmony_ci ath9k_hw_reverse_bits(((freq - 4800) / 10 << 1), 8); 2578c2ecf20Sopenharmony_ci if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah)) 2588c2ecf20Sopenharmony_ci aModeRefSel = ath9k_hw_reverse_bits(2, 2); 2598c2ecf20Sopenharmony_ci else 2608c2ecf20Sopenharmony_ci aModeRefSel = ath9k_hw_reverse_bits(1, 2); 2618c2ecf20Sopenharmony_ci } else if ((freq % 5) == 0) { 2628c2ecf20Sopenharmony_ci channelSel = ath9k_hw_reverse_bits((freq - 4800) / 5, 8); 2638c2ecf20Sopenharmony_ci aModeRefSel = ath9k_hw_reverse_bits(1, 2); 2648c2ecf20Sopenharmony_ci } else { 2658c2ecf20Sopenharmony_ci ath_err(common, "Invalid channel %u MHz\n", freq); 2668c2ecf20Sopenharmony_ci return -EINVAL; 2678c2ecf20Sopenharmony_ci } 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci ar5008_hw_force_bias(ah, freq); 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci reg32 = 2728c2ecf20Sopenharmony_ci (channelSel << 8) | (aModeRefSel << 2) | (bModeSynth << 1) | 2738c2ecf20Sopenharmony_ci (1 << 5) | 0x1; 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY(0x37), reg32); 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci ah->curchan = chan; 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci return 0; 2808c2ecf20Sopenharmony_ci} 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_civoid ar5008_hw_cmn_spur_mitigate(struct ath_hw *ah, 2838c2ecf20Sopenharmony_ci struct ath9k_channel *chan, int bin) 2848c2ecf20Sopenharmony_ci{ 2858c2ecf20Sopenharmony_ci int cur_bin; 2868c2ecf20Sopenharmony_ci int upper, lower, cur_vit_mask; 2878c2ecf20Sopenharmony_ci int i; 2888c2ecf20Sopenharmony_ci int8_t mask_m[123] = {0}; 2898c2ecf20Sopenharmony_ci int8_t mask_p[123] = {0}; 2908c2ecf20Sopenharmony_ci int8_t mask_amt; 2918c2ecf20Sopenharmony_ci int tmp_mask; 2928c2ecf20Sopenharmony_ci static const int pilot_mask_reg[4] = { 2938c2ecf20Sopenharmony_ci AR_PHY_TIMING7, AR_PHY_TIMING8, 2948c2ecf20Sopenharmony_ci AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60 2958c2ecf20Sopenharmony_ci }; 2968c2ecf20Sopenharmony_ci static const int chan_mask_reg[4] = { 2978c2ecf20Sopenharmony_ci AR_PHY_TIMING9, AR_PHY_TIMING10, 2988c2ecf20Sopenharmony_ci AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60 2998c2ecf20Sopenharmony_ci }; 3008c2ecf20Sopenharmony_ci static const int inc[4] = { 0, 100, 0, 0 }; 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_ci cur_bin = -6000; 3038c2ecf20Sopenharmony_ci upper = bin + 100; 3048c2ecf20Sopenharmony_ci lower = bin - 100; 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci for (i = 0; i < 4; i++) { 3078c2ecf20Sopenharmony_ci int pilot_mask = 0; 3088c2ecf20Sopenharmony_ci int chan_mask = 0; 3098c2ecf20Sopenharmony_ci int bp = 0; 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci for (bp = 0; bp < 30; bp++) { 3128c2ecf20Sopenharmony_ci if ((cur_bin > lower) && (cur_bin < upper)) { 3138c2ecf20Sopenharmony_ci pilot_mask = pilot_mask | 0x1 << bp; 3148c2ecf20Sopenharmony_ci chan_mask = chan_mask | 0x1 << bp; 3158c2ecf20Sopenharmony_ci } 3168c2ecf20Sopenharmony_ci cur_bin += 100; 3178c2ecf20Sopenharmony_ci } 3188c2ecf20Sopenharmony_ci cur_bin += inc[i]; 3198c2ecf20Sopenharmony_ci REG_WRITE(ah, pilot_mask_reg[i], pilot_mask); 3208c2ecf20Sopenharmony_ci REG_WRITE(ah, chan_mask_reg[i], chan_mask); 3218c2ecf20Sopenharmony_ci } 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_ci cur_vit_mask = 6100; 3248c2ecf20Sopenharmony_ci upper = bin + 120; 3258c2ecf20Sopenharmony_ci lower = bin - 120; 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(mask_m); i++) { 3288c2ecf20Sopenharmony_ci if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) { 3298c2ecf20Sopenharmony_ci /* workaround for gcc bug #37014 */ 3308c2ecf20Sopenharmony_ci volatile int tmp_v = abs(cur_vit_mask - bin); 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci if (tmp_v < 75) 3338c2ecf20Sopenharmony_ci mask_amt = 1; 3348c2ecf20Sopenharmony_ci else 3358c2ecf20Sopenharmony_ci mask_amt = 0; 3368c2ecf20Sopenharmony_ci if (cur_vit_mask < 0) 3378c2ecf20Sopenharmony_ci mask_m[abs(cur_vit_mask / 100)] = mask_amt; 3388c2ecf20Sopenharmony_ci else 3398c2ecf20Sopenharmony_ci mask_p[cur_vit_mask / 100] = mask_amt; 3408c2ecf20Sopenharmony_ci } 3418c2ecf20Sopenharmony_ci cur_vit_mask -= 100; 3428c2ecf20Sopenharmony_ci } 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_ci tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28) 3458c2ecf20Sopenharmony_ci | (mask_m[48] << 26) | (mask_m[49] << 24) 3468c2ecf20Sopenharmony_ci | (mask_m[50] << 22) | (mask_m[51] << 20) 3478c2ecf20Sopenharmony_ci | (mask_m[52] << 18) | (mask_m[53] << 16) 3488c2ecf20Sopenharmony_ci | (mask_m[54] << 14) | (mask_m[55] << 12) 3498c2ecf20Sopenharmony_ci | (mask_m[56] << 10) | (mask_m[57] << 8) 3508c2ecf20Sopenharmony_ci | (mask_m[58] << 6) | (mask_m[59] << 4) 3518c2ecf20Sopenharmony_ci | (mask_m[60] << 2) | (mask_m[61] << 0); 3528c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask); 3538c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask); 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_ci tmp_mask = (mask_m[31] << 28) 3568c2ecf20Sopenharmony_ci | (mask_m[32] << 26) | (mask_m[33] << 24) 3578c2ecf20Sopenharmony_ci | (mask_m[34] << 22) | (mask_m[35] << 20) 3588c2ecf20Sopenharmony_ci | (mask_m[36] << 18) | (mask_m[37] << 16) 3598c2ecf20Sopenharmony_ci | (mask_m[48] << 14) | (mask_m[39] << 12) 3608c2ecf20Sopenharmony_ci | (mask_m[40] << 10) | (mask_m[41] << 8) 3618c2ecf20Sopenharmony_ci | (mask_m[42] << 6) | (mask_m[43] << 4) 3628c2ecf20Sopenharmony_ci | (mask_m[44] << 2) | (mask_m[45] << 0); 3638c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask); 3648c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask); 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ci tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28) 3678c2ecf20Sopenharmony_ci | (mask_m[18] << 26) | (mask_m[18] << 24) 3688c2ecf20Sopenharmony_ci | (mask_m[20] << 22) | (mask_m[20] << 20) 3698c2ecf20Sopenharmony_ci | (mask_m[22] << 18) | (mask_m[22] << 16) 3708c2ecf20Sopenharmony_ci | (mask_m[24] << 14) | (mask_m[24] << 12) 3718c2ecf20Sopenharmony_ci | (mask_m[25] << 10) | (mask_m[26] << 8) 3728c2ecf20Sopenharmony_ci | (mask_m[27] << 6) | (mask_m[28] << 4) 3738c2ecf20Sopenharmony_ci | (mask_m[29] << 2) | (mask_m[30] << 0); 3748c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask); 3758c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask); 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_ci tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28) 3788c2ecf20Sopenharmony_ci | (mask_m[2] << 26) | (mask_m[3] << 24) 3798c2ecf20Sopenharmony_ci | (mask_m[4] << 22) | (mask_m[5] << 20) 3808c2ecf20Sopenharmony_ci | (mask_m[6] << 18) | (mask_m[7] << 16) 3818c2ecf20Sopenharmony_ci | (mask_m[8] << 14) | (mask_m[9] << 12) 3828c2ecf20Sopenharmony_ci | (mask_m[10] << 10) | (mask_m[11] << 8) 3838c2ecf20Sopenharmony_ci | (mask_m[12] << 6) | (mask_m[13] << 4) 3848c2ecf20Sopenharmony_ci | (mask_m[14] << 2) | (mask_m[15] << 0); 3858c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask); 3868c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask); 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci tmp_mask = (mask_p[15] << 28) 3898c2ecf20Sopenharmony_ci | (mask_p[14] << 26) | (mask_p[13] << 24) 3908c2ecf20Sopenharmony_ci | (mask_p[12] << 22) | (mask_p[11] << 20) 3918c2ecf20Sopenharmony_ci | (mask_p[10] << 18) | (mask_p[9] << 16) 3928c2ecf20Sopenharmony_ci | (mask_p[8] << 14) | (mask_p[7] << 12) 3938c2ecf20Sopenharmony_ci | (mask_p[6] << 10) | (mask_p[5] << 8) 3948c2ecf20Sopenharmony_ci | (mask_p[4] << 6) | (mask_p[3] << 4) 3958c2ecf20Sopenharmony_ci | (mask_p[2] << 2) | (mask_p[1] << 0); 3968c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask); 3978c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask); 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ci tmp_mask = (mask_p[30] << 28) 4008c2ecf20Sopenharmony_ci | (mask_p[29] << 26) | (mask_p[28] << 24) 4018c2ecf20Sopenharmony_ci | (mask_p[27] << 22) | (mask_p[26] << 20) 4028c2ecf20Sopenharmony_ci | (mask_p[25] << 18) | (mask_p[24] << 16) 4038c2ecf20Sopenharmony_ci | (mask_p[23] << 14) | (mask_p[22] << 12) 4048c2ecf20Sopenharmony_ci | (mask_p[21] << 10) | (mask_p[20] << 8) 4058c2ecf20Sopenharmony_ci | (mask_p[19] << 6) | (mask_p[18] << 4) 4068c2ecf20Sopenharmony_ci | (mask_p[17] << 2) | (mask_p[16] << 0); 4078c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask); 4088c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask); 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_ci tmp_mask = (mask_p[45] << 28) 4118c2ecf20Sopenharmony_ci | (mask_p[44] << 26) | (mask_p[43] << 24) 4128c2ecf20Sopenharmony_ci | (mask_p[42] << 22) | (mask_p[41] << 20) 4138c2ecf20Sopenharmony_ci | (mask_p[40] << 18) | (mask_p[39] << 16) 4148c2ecf20Sopenharmony_ci | (mask_p[38] << 14) | (mask_p[37] << 12) 4158c2ecf20Sopenharmony_ci | (mask_p[36] << 10) | (mask_p[35] << 8) 4168c2ecf20Sopenharmony_ci | (mask_p[34] << 6) | (mask_p[33] << 4) 4178c2ecf20Sopenharmony_ci | (mask_p[32] << 2) | (mask_p[31] << 0); 4188c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask); 4198c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask); 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28) 4228c2ecf20Sopenharmony_ci | (mask_p[59] << 26) | (mask_p[58] << 24) 4238c2ecf20Sopenharmony_ci | (mask_p[57] << 22) | (mask_p[56] << 20) 4248c2ecf20Sopenharmony_ci | (mask_p[55] << 18) | (mask_p[54] << 16) 4258c2ecf20Sopenharmony_ci | (mask_p[53] << 14) | (mask_p[52] << 12) 4268c2ecf20Sopenharmony_ci | (mask_p[51] << 10) | (mask_p[50] << 8) 4278c2ecf20Sopenharmony_ci | (mask_p[49] << 6) | (mask_p[48] << 4) 4288c2ecf20Sopenharmony_ci | (mask_p[47] << 2) | (mask_p[46] << 0); 4298c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask); 4308c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask); 4318c2ecf20Sopenharmony_ci} 4328c2ecf20Sopenharmony_ci 4338c2ecf20Sopenharmony_ci/** 4348c2ecf20Sopenharmony_ci * ar5008_hw_spur_mitigate - convert baseband spur frequency for external radios 4358c2ecf20Sopenharmony_ci * @ah: atheros hardware structure 4368c2ecf20Sopenharmony_ci * @chan: 4378c2ecf20Sopenharmony_ci * 4388c2ecf20Sopenharmony_ci * For non single-chip solutions. Converts to baseband spur frequency given the 4398c2ecf20Sopenharmony_ci * input channel frequency and compute register settings below. 4408c2ecf20Sopenharmony_ci */ 4418c2ecf20Sopenharmony_cistatic void ar5008_hw_spur_mitigate(struct ath_hw *ah, 4428c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 4438c2ecf20Sopenharmony_ci{ 4448c2ecf20Sopenharmony_ci int bb_spur = AR_NO_SPUR; 4458c2ecf20Sopenharmony_ci int bin; 4468c2ecf20Sopenharmony_ci int spur_freq_sd; 4478c2ecf20Sopenharmony_ci int spur_delta_phase; 4488c2ecf20Sopenharmony_ci int denominator; 4498c2ecf20Sopenharmony_ci int tmp, new; 4508c2ecf20Sopenharmony_ci int i; 4518c2ecf20Sopenharmony_ci 4528c2ecf20Sopenharmony_ci int cur_bb_spur; 4538c2ecf20Sopenharmony_ci bool is2GHz = IS_CHAN_2GHZ(chan); 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_ci for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) { 4568c2ecf20Sopenharmony_ci cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz); 4578c2ecf20Sopenharmony_ci if (AR_NO_SPUR == cur_bb_spur) 4588c2ecf20Sopenharmony_ci break; 4598c2ecf20Sopenharmony_ci cur_bb_spur = cur_bb_spur - (chan->channel * 10); 4608c2ecf20Sopenharmony_ci if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) { 4618c2ecf20Sopenharmony_ci bb_spur = cur_bb_spur; 4628c2ecf20Sopenharmony_ci break; 4638c2ecf20Sopenharmony_ci } 4648c2ecf20Sopenharmony_ci } 4658c2ecf20Sopenharmony_ci 4668c2ecf20Sopenharmony_ci if (AR_NO_SPUR == bb_spur) 4678c2ecf20Sopenharmony_ci return; 4688c2ecf20Sopenharmony_ci 4698c2ecf20Sopenharmony_ci bin = bb_spur * 32; 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ci tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0)); 4728c2ecf20Sopenharmony_ci new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI | 4738c2ecf20Sopenharmony_ci AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER | 4748c2ecf20Sopenharmony_ci AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK | 4758c2ecf20Sopenharmony_ci AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK); 4768c2ecf20Sopenharmony_ci 4778c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new); 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_ci new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL | 4808c2ecf20Sopenharmony_ci AR_PHY_SPUR_REG_ENABLE_MASK_PPM | 4818c2ecf20Sopenharmony_ci AR_PHY_SPUR_REG_MASK_RATE_SELECT | 4828c2ecf20Sopenharmony_ci AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI | 4838c2ecf20Sopenharmony_ci SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH)); 4848c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_SPUR_REG, new); 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ci spur_delta_phase = ((bb_spur * 524288) / 100) & 4878c2ecf20Sopenharmony_ci AR_PHY_TIMING11_SPUR_DELTA_PHASE; 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_ci denominator = IS_CHAN_2GHZ(chan) ? 440 : 400; 4908c2ecf20Sopenharmony_ci spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff; 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_ci new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC | 4938c2ecf20Sopenharmony_ci SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) | 4948c2ecf20Sopenharmony_ci SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE)); 4958c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_TIMING11, new); 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci ar5008_hw_cmn_spur_mitigate(ah, chan, bin); 4988c2ecf20Sopenharmony_ci} 4998c2ecf20Sopenharmony_ci 5008c2ecf20Sopenharmony_ci/** 5018c2ecf20Sopenharmony_ci * ar5008_hw_rf_alloc_ext_banks - allocates banks for external radio programming 5028c2ecf20Sopenharmony_ci * @ah: atheros hardware structure 5038c2ecf20Sopenharmony_ci * 5048c2ecf20Sopenharmony_ci * Only required for older devices with external AR2133/AR5133 radios. 5058c2ecf20Sopenharmony_ci */ 5068c2ecf20Sopenharmony_cistatic int ar5008_hw_rf_alloc_ext_banks(struct ath_hw *ah) 5078c2ecf20Sopenharmony_ci{ 5088c2ecf20Sopenharmony_ci int size = ah->iniBank6.ia_rows * sizeof(u32); 5098c2ecf20Sopenharmony_ci 5108c2ecf20Sopenharmony_ci if (AR_SREV_9280_20_OR_LATER(ah)) 5118c2ecf20Sopenharmony_ci return 0; 5128c2ecf20Sopenharmony_ci 5138c2ecf20Sopenharmony_ci ah->analogBank6Data = devm_kzalloc(ah->dev, size, GFP_KERNEL); 5148c2ecf20Sopenharmony_ci if (!ah->analogBank6Data) 5158c2ecf20Sopenharmony_ci return -ENOMEM; 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci return 0; 5188c2ecf20Sopenharmony_ci} 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_ci 5218c2ecf20Sopenharmony_ci/* * 5228c2ecf20Sopenharmony_ci * ar5008_hw_set_rf_regs - programs rf registers based on EEPROM 5238c2ecf20Sopenharmony_ci * @ah: atheros hardware structure 5248c2ecf20Sopenharmony_ci * @chan: 5258c2ecf20Sopenharmony_ci * @modesIndex: 5268c2ecf20Sopenharmony_ci * 5278c2ecf20Sopenharmony_ci * Used for the external AR2133/AR5133 radios. 5288c2ecf20Sopenharmony_ci * 5298c2ecf20Sopenharmony_ci * Reads the EEPROM header info from the device structure and programs 5308c2ecf20Sopenharmony_ci * all rf registers. This routine requires access to the analog 5318c2ecf20Sopenharmony_ci * rf device. This is not required for single-chip devices. 5328c2ecf20Sopenharmony_ci */ 5338c2ecf20Sopenharmony_cistatic bool ar5008_hw_set_rf_regs(struct ath_hw *ah, 5348c2ecf20Sopenharmony_ci struct ath9k_channel *chan, 5358c2ecf20Sopenharmony_ci u16 modesIndex) 5368c2ecf20Sopenharmony_ci{ 5378c2ecf20Sopenharmony_ci u32 eepMinorRev; 5388c2ecf20Sopenharmony_ci u32 ob5GHz = 0, db5GHz = 0; 5398c2ecf20Sopenharmony_ci u32 ob2GHz = 0, db2GHz = 0; 5408c2ecf20Sopenharmony_ci int regWrites = 0; 5418c2ecf20Sopenharmony_ci int i; 5428c2ecf20Sopenharmony_ci 5438c2ecf20Sopenharmony_ci /* 5448c2ecf20Sopenharmony_ci * Software does not need to program bank data 5458c2ecf20Sopenharmony_ci * for single chip devices, that is AR9280 or anything 5468c2ecf20Sopenharmony_ci * after that. 5478c2ecf20Sopenharmony_ci */ 5488c2ecf20Sopenharmony_ci if (AR_SREV_9280_20_OR_LATER(ah)) 5498c2ecf20Sopenharmony_ci return true; 5508c2ecf20Sopenharmony_ci 5518c2ecf20Sopenharmony_ci /* Setup rf parameters */ 5528c2ecf20Sopenharmony_ci eepMinorRev = ah->eep_ops->get_eeprom_rev(ah); 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_ci for (i = 0; i < ah->iniBank6.ia_rows; i++) 5558c2ecf20Sopenharmony_ci ah->analogBank6Data[i] = INI_RA(&ah->iniBank6, i, modesIndex); 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_ci /* Only the 5 or 2 GHz OB/DB need to be set for a mode */ 5588c2ecf20Sopenharmony_ci if (eepMinorRev >= 2) { 5598c2ecf20Sopenharmony_ci if (IS_CHAN_2GHZ(chan)) { 5608c2ecf20Sopenharmony_ci ob2GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_2); 5618c2ecf20Sopenharmony_ci db2GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_2); 5628c2ecf20Sopenharmony_ci ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data, 5638c2ecf20Sopenharmony_ci ob2GHz, 3, 197, 0); 5648c2ecf20Sopenharmony_ci ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data, 5658c2ecf20Sopenharmony_ci db2GHz, 3, 194, 0); 5668c2ecf20Sopenharmony_ci } else { 5678c2ecf20Sopenharmony_ci ob5GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_5); 5688c2ecf20Sopenharmony_ci db5GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_5); 5698c2ecf20Sopenharmony_ci ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data, 5708c2ecf20Sopenharmony_ci ob5GHz, 3, 203, 0); 5718c2ecf20Sopenharmony_ci ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data, 5728c2ecf20Sopenharmony_ci db5GHz, 3, 200, 0); 5738c2ecf20Sopenharmony_ci } 5748c2ecf20Sopenharmony_ci } 5758c2ecf20Sopenharmony_ci 5768c2ecf20Sopenharmony_ci /* Write Analog registers */ 5778c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&bank0, 1, regWrites); 5788c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&bank1, 1, regWrites); 5798c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&bank2, 1, regWrites); 5808c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&bank3, modesIndex, regWrites); 5818c2ecf20Sopenharmony_ci ar5008_write_bank6(ah, ®Writes); 5828c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&bank7, 1, regWrites); 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ci return true; 5858c2ecf20Sopenharmony_ci} 5868c2ecf20Sopenharmony_ci 5878c2ecf20Sopenharmony_cistatic void ar5008_hw_init_bb(struct ath_hw *ah, 5888c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 5898c2ecf20Sopenharmony_ci{ 5908c2ecf20Sopenharmony_ci u32 synthDelay; 5918c2ecf20Sopenharmony_ci 5928c2ecf20Sopenharmony_ci synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY; 5938c2ecf20Sopenharmony_ci 5948c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN); 5958c2ecf20Sopenharmony_ci 5968c2ecf20Sopenharmony_ci ath9k_hw_synth_delay(ah, chan, synthDelay); 5978c2ecf20Sopenharmony_ci} 5988c2ecf20Sopenharmony_ci 5998c2ecf20Sopenharmony_cistatic void ar5008_hw_init_chain_masks(struct ath_hw *ah) 6008c2ecf20Sopenharmony_ci{ 6018c2ecf20Sopenharmony_ci int rx_chainmask, tx_chainmask; 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_ci rx_chainmask = ah->rxchainmask; 6048c2ecf20Sopenharmony_ci tx_chainmask = ah->txchainmask; 6058c2ecf20Sopenharmony_ci 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_ci switch (rx_chainmask) { 6088c2ecf20Sopenharmony_ci case 0x5: 6098c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP, 6108c2ecf20Sopenharmony_ci AR_PHY_SWAP_ALT_CHAIN); 6118c2ecf20Sopenharmony_ci fallthrough; 6128c2ecf20Sopenharmony_ci case 0x3: 6138c2ecf20Sopenharmony_ci if (ah->hw_version.macVersion == AR_SREV_REVISION_5416_10) { 6148c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7); 6158c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7); 6168c2ecf20Sopenharmony_ci break; 6178c2ecf20Sopenharmony_ci } 6188c2ecf20Sopenharmony_ci fallthrough; 6198c2ecf20Sopenharmony_ci case 0x1: 6208c2ecf20Sopenharmony_ci case 0x2: 6218c2ecf20Sopenharmony_ci case 0x7: 6228c2ecf20Sopenharmony_ci ENABLE_REGWRITE_BUFFER(ah); 6238c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask); 6248c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask); 6258c2ecf20Sopenharmony_ci break; 6268c2ecf20Sopenharmony_ci default: 6278c2ecf20Sopenharmony_ci ENABLE_REGWRITE_BUFFER(ah); 6288c2ecf20Sopenharmony_ci break; 6298c2ecf20Sopenharmony_ci } 6308c2ecf20Sopenharmony_ci 6318c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask); 6328c2ecf20Sopenharmony_ci 6338c2ecf20Sopenharmony_ci REGWRITE_BUFFER_FLUSH(ah); 6348c2ecf20Sopenharmony_ci 6358c2ecf20Sopenharmony_ci if (tx_chainmask == 0x5) { 6368c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP, 6378c2ecf20Sopenharmony_ci AR_PHY_SWAP_ALT_CHAIN); 6388c2ecf20Sopenharmony_ci } 6398c2ecf20Sopenharmony_ci if (AR_SREV_9100(ah)) 6408c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_ANALOG_SWAP, 6418c2ecf20Sopenharmony_ci REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001); 6428c2ecf20Sopenharmony_ci} 6438c2ecf20Sopenharmony_ci 6448c2ecf20Sopenharmony_cistatic void ar5008_hw_override_ini(struct ath_hw *ah, 6458c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 6468c2ecf20Sopenharmony_ci{ 6478c2ecf20Sopenharmony_ci u32 val; 6488c2ecf20Sopenharmony_ci 6498c2ecf20Sopenharmony_ci /* 6508c2ecf20Sopenharmony_ci * Set the RX_ABORT and RX_DIS and clear if off only after 6518c2ecf20Sopenharmony_ci * RXE is set for MAC. This prevents frames with corrupted 6528c2ecf20Sopenharmony_ci * descriptor status. 6538c2ecf20Sopenharmony_ci */ 6548c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT)); 6558c2ecf20Sopenharmony_ci 6568c2ecf20Sopenharmony_ci if (AR_SREV_9280_20_OR_LATER(ah)) { 6578c2ecf20Sopenharmony_ci /* 6588c2ecf20Sopenharmony_ci * For AR9280 and above, there is a new feature that allows 6598c2ecf20Sopenharmony_ci * Multicast search based on both MAC Address and Key ID. 6608c2ecf20Sopenharmony_ci * By default, this feature is enabled. But since the driver 6618c2ecf20Sopenharmony_ci * is not using this feature, we switch it off; otherwise 6628c2ecf20Sopenharmony_ci * multicast search based on MAC addr only will fail. 6638c2ecf20Sopenharmony_ci */ 6648c2ecf20Sopenharmony_ci val = REG_READ(ah, AR_PCU_MISC_MODE2) & 6658c2ecf20Sopenharmony_ci (~AR_ADHOC_MCAST_KEYID_ENABLE); 6668c2ecf20Sopenharmony_ci 6678c2ecf20Sopenharmony_ci if (!AR_SREV_9271(ah)) 6688c2ecf20Sopenharmony_ci val &= ~AR_PCU_MISC_MODE2_HWWAR1; 6698c2ecf20Sopenharmony_ci 6708c2ecf20Sopenharmony_ci if (AR_SREV_9287_11_OR_LATER(ah)) 6718c2ecf20Sopenharmony_ci val = val & (~AR_PCU_MISC_MODE2_HWWAR2); 6728c2ecf20Sopenharmony_ci 6738c2ecf20Sopenharmony_ci val |= AR_PCU_MISC_MODE2_CFP_IGNORE; 6748c2ecf20Sopenharmony_ci 6758c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PCU_MISC_MODE2, val); 6768c2ecf20Sopenharmony_ci } 6778c2ecf20Sopenharmony_ci 6788c2ecf20Sopenharmony_ci if (AR_SREV_9280_20_OR_LATER(ah)) 6798c2ecf20Sopenharmony_ci return; 6808c2ecf20Sopenharmony_ci /* 6818c2ecf20Sopenharmony_ci * Disable BB clock gating 6828c2ecf20Sopenharmony_ci * Necessary to avoid issues on AR5416 2.0 6838c2ecf20Sopenharmony_ci */ 6848c2ecf20Sopenharmony_ci REG_WRITE(ah, 0x9800 + (651 << 2), 0x11); 6858c2ecf20Sopenharmony_ci 6868c2ecf20Sopenharmony_ci /* 6878c2ecf20Sopenharmony_ci * Disable RIFS search on some chips to avoid baseband 6888c2ecf20Sopenharmony_ci * hang issues. 6898c2ecf20Sopenharmony_ci */ 6908c2ecf20Sopenharmony_ci if (AR_SREV_9100(ah) || AR_SREV_9160(ah)) { 6918c2ecf20Sopenharmony_ci val = REG_READ(ah, AR_PHY_HEAVY_CLIP_FACTOR_RIFS); 6928c2ecf20Sopenharmony_ci val &= ~AR_PHY_RIFS_INIT_DELAY; 6938c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_HEAVY_CLIP_FACTOR_RIFS, val); 6948c2ecf20Sopenharmony_ci } 6958c2ecf20Sopenharmony_ci} 6968c2ecf20Sopenharmony_ci 6978c2ecf20Sopenharmony_cistatic void ar5008_hw_set_channel_regs(struct ath_hw *ah, 6988c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 6998c2ecf20Sopenharmony_ci{ 7008c2ecf20Sopenharmony_ci u32 phymode; 7018c2ecf20Sopenharmony_ci u32 enableDacFifo = 0; 7028c2ecf20Sopenharmony_ci 7038c2ecf20Sopenharmony_ci if (AR_SREV_9285_12_OR_LATER(ah)) 7048c2ecf20Sopenharmony_ci enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) & 7058c2ecf20Sopenharmony_ci AR_PHY_FC_ENABLE_DAC_FIFO); 7068c2ecf20Sopenharmony_ci 7078c2ecf20Sopenharmony_ci phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40 7088c2ecf20Sopenharmony_ci | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo; 7098c2ecf20Sopenharmony_ci 7108c2ecf20Sopenharmony_ci if (IS_CHAN_HT40(chan)) { 7118c2ecf20Sopenharmony_ci phymode |= AR_PHY_FC_DYN2040_EN; 7128c2ecf20Sopenharmony_ci 7138c2ecf20Sopenharmony_ci if (IS_CHAN_HT40PLUS(chan)) 7148c2ecf20Sopenharmony_ci phymode |= AR_PHY_FC_DYN2040_PRI_CH; 7158c2ecf20Sopenharmony_ci 7168c2ecf20Sopenharmony_ci } 7178c2ecf20Sopenharmony_ci ENABLE_REGWRITE_BUFFER(ah); 7188c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_TURBO, phymode); 7198c2ecf20Sopenharmony_ci 7208c2ecf20Sopenharmony_ci /* This function do only REG_WRITE, so 7218c2ecf20Sopenharmony_ci * we can include it to REGWRITE_BUFFER. */ 7228c2ecf20Sopenharmony_ci ath9k_hw_set11nmac2040(ah, chan); 7238c2ecf20Sopenharmony_ci 7248c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S); 7258c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S); 7268c2ecf20Sopenharmony_ci 7278c2ecf20Sopenharmony_ci REGWRITE_BUFFER_FLUSH(ah); 7288c2ecf20Sopenharmony_ci} 7298c2ecf20Sopenharmony_ci 7308c2ecf20Sopenharmony_ci 7318c2ecf20Sopenharmony_cistatic int ar5008_hw_process_ini(struct ath_hw *ah, 7328c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 7338c2ecf20Sopenharmony_ci{ 7348c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 7358c2ecf20Sopenharmony_ci int i, regWrites = 0; 7368c2ecf20Sopenharmony_ci u32 modesIndex, freqIndex; 7378c2ecf20Sopenharmony_ci 7388c2ecf20Sopenharmony_ci if (IS_CHAN_5GHZ(chan)) { 7398c2ecf20Sopenharmony_ci freqIndex = 1; 7408c2ecf20Sopenharmony_ci modesIndex = IS_CHAN_HT40(chan) ? 2 : 1; 7418c2ecf20Sopenharmony_ci } else { 7428c2ecf20Sopenharmony_ci freqIndex = 2; 7438c2ecf20Sopenharmony_ci modesIndex = IS_CHAN_HT40(chan) ? 3 : 4; 7448c2ecf20Sopenharmony_ci } 7458c2ecf20Sopenharmony_ci 7468c2ecf20Sopenharmony_ci /* 7478c2ecf20Sopenharmony_ci * Set correct baseband to analog shift setting to 7488c2ecf20Sopenharmony_ci * access analog chips. 7498c2ecf20Sopenharmony_ci */ 7508c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY(0), 0x00000007); 7518c2ecf20Sopenharmony_ci 7528c2ecf20Sopenharmony_ci /* Write ADDAC shifts */ 7538c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO); 7548c2ecf20Sopenharmony_ci if (ah->eep_ops->set_addac) 7558c2ecf20Sopenharmony_ci ah->eep_ops->set_addac(ah, chan); 7568c2ecf20Sopenharmony_ci 7578c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites); 7588c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC); 7598c2ecf20Sopenharmony_ci 7608c2ecf20Sopenharmony_ci ENABLE_REGWRITE_BUFFER(ah); 7618c2ecf20Sopenharmony_ci 7628c2ecf20Sopenharmony_ci for (i = 0; i < ah->iniModes.ia_rows; i++) { 7638c2ecf20Sopenharmony_ci u32 reg = INI_RA(&ah->iniModes, i, 0); 7648c2ecf20Sopenharmony_ci u32 val = INI_RA(&ah->iniModes, i, modesIndex); 7658c2ecf20Sopenharmony_ci 7668c2ecf20Sopenharmony_ci if (reg == AR_AN_TOP2 && ah->need_an_top2_fixup) 7678c2ecf20Sopenharmony_ci val &= ~AR_AN_TOP2_PWDCLKIND; 7688c2ecf20Sopenharmony_ci 7698c2ecf20Sopenharmony_ci REG_WRITE(ah, reg, val); 7708c2ecf20Sopenharmony_ci 7718c2ecf20Sopenharmony_ci if (reg >= 0x7800 && reg < 0x78a0 7728c2ecf20Sopenharmony_ci && ah->config.analog_shiftreg 7738c2ecf20Sopenharmony_ci && (common->bus_ops->ath_bus_type != ATH_USB)) { 7748c2ecf20Sopenharmony_ci udelay(100); 7758c2ecf20Sopenharmony_ci } 7768c2ecf20Sopenharmony_ci 7778c2ecf20Sopenharmony_ci DO_DELAY(regWrites); 7788c2ecf20Sopenharmony_ci } 7798c2ecf20Sopenharmony_ci 7808c2ecf20Sopenharmony_ci REGWRITE_BUFFER_FLUSH(ah); 7818c2ecf20Sopenharmony_ci 7828c2ecf20Sopenharmony_ci if (AR_SREV_9280(ah) || AR_SREV_9287_11_OR_LATER(ah)) 7838c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites); 7848c2ecf20Sopenharmony_ci 7858c2ecf20Sopenharmony_ci if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) || 7868c2ecf20Sopenharmony_ci AR_SREV_9287_11_OR_LATER(ah)) 7878c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites); 7888c2ecf20Sopenharmony_ci 7898c2ecf20Sopenharmony_ci if (AR_SREV_9271_10(ah)) { 7908c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN, AR_PHY_SPECTRAL_SCAN_ENA); 7918c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_ADC_ON, 0xa); 7928c2ecf20Sopenharmony_ci } 7938c2ecf20Sopenharmony_ci 7948c2ecf20Sopenharmony_ci ENABLE_REGWRITE_BUFFER(ah); 7958c2ecf20Sopenharmony_ci 7968c2ecf20Sopenharmony_ci /* Write common array parameters */ 7978c2ecf20Sopenharmony_ci for (i = 0; i < ah->iniCommon.ia_rows; i++) { 7988c2ecf20Sopenharmony_ci u32 reg = INI_RA(&ah->iniCommon, i, 0); 7998c2ecf20Sopenharmony_ci u32 val = INI_RA(&ah->iniCommon, i, 1); 8008c2ecf20Sopenharmony_ci 8018c2ecf20Sopenharmony_ci REG_WRITE(ah, reg, val); 8028c2ecf20Sopenharmony_ci 8038c2ecf20Sopenharmony_ci if (reg >= 0x7800 && reg < 0x78a0 8048c2ecf20Sopenharmony_ci && ah->config.analog_shiftreg 8058c2ecf20Sopenharmony_ci && (common->bus_ops->ath_bus_type != ATH_USB)) { 8068c2ecf20Sopenharmony_ci udelay(100); 8078c2ecf20Sopenharmony_ci } 8088c2ecf20Sopenharmony_ci 8098c2ecf20Sopenharmony_ci DO_DELAY(regWrites); 8108c2ecf20Sopenharmony_ci } 8118c2ecf20Sopenharmony_ci 8128c2ecf20Sopenharmony_ci REGWRITE_BUFFER_FLUSH(ah); 8138c2ecf20Sopenharmony_ci 8148c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&ah->iniBB_RfGain, freqIndex, regWrites); 8158c2ecf20Sopenharmony_ci 8168c2ecf20Sopenharmony_ci if (IS_CHAN_A_FAST_CLOCK(ah, chan)) 8178c2ecf20Sopenharmony_ci REG_WRITE_ARRAY(&ah->iniModesFastClock, modesIndex, 8188c2ecf20Sopenharmony_ci regWrites); 8198c2ecf20Sopenharmony_ci 8208c2ecf20Sopenharmony_ci ar5008_hw_override_ini(ah, chan); 8218c2ecf20Sopenharmony_ci ar5008_hw_set_channel_regs(ah, chan); 8228c2ecf20Sopenharmony_ci ar5008_hw_init_chain_masks(ah); 8238c2ecf20Sopenharmony_ci ath9k_olc_init(ah); 8248c2ecf20Sopenharmony_ci ath9k_hw_apply_txpower(ah, chan, false); 8258c2ecf20Sopenharmony_ci 8268c2ecf20Sopenharmony_ci /* Write analog registers */ 8278c2ecf20Sopenharmony_ci if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) { 8288c2ecf20Sopenharmony_ci ath_err(ath9k_hw_common(ah), "ar5416SetRfRegs failed\n"); 8298c2ecf20Sopenharmony_ci return -EIO; 8308c2ecf20Sopenharmony_ci } 8318c2ecf20Sopenharmony_ci 8328c2ecf20Sopenharmony_ci return 0; 8338c2ecf20Sopenharmony_ci} 8348c2ecf20Sopenharmony_ci 8358c2ecf20Sopenharmony_cistatic void ar5008_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan) 8368c2ecf20Sopenharmony_ci{ 8378c2ecf20Sopenharmony_ci u32 rfMode = 0; 8388c2ecf20Sopenharmony_ci 8398c2ecf20Sopenharmony_ci if (chan == NULL) 8408c2ecf20Sopenharmony_ci return; 8418c2ecf20Sopenharmony_ci 8428c2ecf20Sopenharmony_ci if (IS_CHAN_2GHZ(chan)) 8438c2ecf20Sopenharmony_ci rfMode |= AR_PHY_MODE_DYNAMIC; 8448c2ecf20Sopenharmony_ci else 8458c2ecf20Sopenharmony_ci rfMode |= AR_PHY_MODE_OFDM; 8468c2ecf20Sopenharmony_ci 8478c2ecf20Sopenharmony_ci if (!AR_SREV_9280_20_OR_LATER(ah)) 8488c2ecf20Sopenharmony_ci rfMode |= (IS_CHAN_5GHZ(chan)) ? 8498c2ecf20Sopenharmony_ci AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ; 8508c2ecf20Sopenharmony_ci 8518c2ecf20Sopenharmony_ci if (IS_CHAN_A_FAST_CLOCK(ah, chan)) 8528c2ecf20Sopenharmony_ci rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE); 8538c2ecf20Sopenharmony_ci 8548c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_MODE, rfMode); 8558c2ecf20Sopenharmony_ci} 8568c2ecf20Sopenharmony_ci 8578c2ecf20Sopenharmony_cistatic void ar5008_hw_mark_phy_inactive(struct ath_hw *ah) 8588c2ecf20Sopenharmony_ci{ 8598c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS); 8608c2ecf20Sopenharmony_ci} 8618c2ecf20Sopenharmony_ci 8628c2ecf20Sopenharmony_cistatic void ar5008_hw_set_delta_slope(struct ath_hw *ah, 8638c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 8648c2ecf20Sopenharmony_ci{ 8658c2ecf20Sopenharmony_ci u32 coef_scaled, ds_coef_exp, ds_coef_man; 8668c2ecf20Sopenharmony_ci u32 clockMhzScaled = 0x64000000; 8678c2ecf20Sopenharmony_ci struct chan_centers centers; 8688c2ecf20Sopenharmony_ci 8698c2ecf20Sopenharmony_ci if (IS_CHAN_HALF_RATE(chan)) 8708c2ecf20Sopenharmony_ci clockMhzScaled = clockMhzScaled >> 1; 8718c2ecf20Sopenharmony_ci else if (IS_CHAN_QUARTER_RATE(chan)) 8728c2ecf20Sopenharmony_ci clockMhzScaled = clockMhzScaled >> 2; 8738c2ecf20Sopenharmony_ci 8748c2ecf20Sopenharmony_ci ath9k_hw_get_channel_centers(ah, chan, ¢ers); 8758c2ecf20Sopenharmony_ci coef_scaled = clockMhzScaled / centers.synth_center; 8768c2ecf20Sopenharmony_ci 8778c2ecf20Sopenharmony_ci ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man, 8788c2ecf20Sopenharmony_ci &ds_coef_exp); 8798c2ecf20Sopenharmony_ci 8808c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TIMING3, 8818c2ecf20Sopenharmony_ci AR_PHY_TIMING3_DSC_MAN, ds_coef_man); 8828c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TIMING3, 8838c2ecf20Sopenharmony_ci AR_PHY_TIMING3_DSC_EXP, ds_coef_exp); 8848c2ecf20Sopenharmony_ci 8858c2ecf20Sopenharmony_ci coef_scaled = (9 * coef_scaled) / 10; 8868c2ecf20Sopenharmony_ci 8878c2ecf20Sopenharmony_ci ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man, 8888c2ecf20Sopenharmony_ci &ds_coef_exp); 8898c2ecf20Sopenharmony_ci 8908c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_HALFGI, 8918c2ecf20Sopenharmony_ci AR_PHY_HALFGI_DSC_MAN, ds_coef_man); 8928c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_HALFGI, 8938c2ecf20Sopenharmony_ci AR_PHY_HALFGI_DSC_EXP, ds_coef_exp); 8948c2ecf20Sopenharmony_ci} 8958c2ecf20Sopenharmony_ci 8968c2ecf20Sopenharmony_cistatic bool ar5008_hw_rfbus_req(struct ath_hw *ah) 8978c2ecf20Sopenharmony_ci{ 8988c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN); 8998c2ecf20Sopenharmony_ci return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN, 9008c2ecf20Sopenharmony_ci AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT); 9018c2ecf20Sopenharmony_ci} 9028c2ecf20Sopenharmony_ci 9038c2ecf20Sopenharmony_cistatic void ar5008_hw_rfbus_done(struct ath_hw *ah) 9048c2ecf20Sopenharmony_ci{ 9058c2ecf20Sopenharmony_ci u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY; 9068c2ecf20Sopenharmony_ci 9078c2ecf20Sopenharmony_ci ath9k_hw_synth_delay(ah, ah->curchan, synthDelay); 9088c2ecf20Sopenharmony_ci 9098c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0); 9108c2ecf20Sopenharmony_ci} 9118c2ecf20Sopenharmony_ci 9128c2ecf20Sopenharmony_cistatic void ar5008_restore_chainmask(struct ath_hw *ah) 9138c2ecf20Sopenharmony_ci{ 9148c2ecf20Sopenharmony_ci int rx_chainmask = ah->rxchainmask; 9158c2ecf20Sopenharmony_ci 9168c2ecf20Sopenharmony_ci if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) { 9178c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask); 9188c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask); 9198c2ecf20Sopenharmony_ci } 9208c2ecf20Sopenharmony_ci} 9218c2ecf20Sopenharmony_ci 9228c2ecf20Sopenharmony_cistatic u32 ar9160_hw_compute_pll_control(struct ath_hw *ah, 9238c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 9248c2ecf20Sopenharmony_ci{ 9258c2ecf20Sopenharmony_ci u32 pll; 9268c2ecf20Sopenharmony_ci 9278c2ecf20Sopenharmony_ci pll = SM(0x5, AR_RTC_9160_PLL_REFDIV); 9288c2ecf20Sopenharmony_ci 9298c2ecf20Sopenharmony_ci if (chan && IS_CHAN_HALF_RATE(chan)) 9308c2ecf20Sopenharmony_ci pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL); 9318c2ecf20Sopenharmony_ci else if (chan && IS_CHAN_QUARTER_RATE(chan)) 9328c2ecf20Sopenharmony_ci pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL); 9338c2ecf20Sopenharmony_ci 9348c2ecf20Sopenharmony_ci if (chan && IS_CHAN_5GHZ(chan)) 9358c2ecf20Sopenharmony_ci pll |= SM(0x50, AR_RTC_9160_PLL_DIV); 9368c2ecf20Sopenharmony_ci else 9378c2ecf20Sopenharmony_ci pll |= SM(0x58, AR_RTC_9160_PLL_DIV); 9388c2ecf20Sopenharmony_ci 9398c2ecf20Sopenharmony_ci return pll; 9408c2ecf20Sopenharmony_ci} 9418c2ecf20Sopenharmony_ci 9428c2ecf20Sopenharmony_cistatic u32 ar5008_hw_compute_pll_control(struct ath_hw *ah, 9438c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 9448c2ecf20Sopenharmony_ci{ 9458c2ecf20Sopenharmony_ci u32 pll; 9468c2ecf20Sopenharmony_ci 9478c2ecf20Sopenharmony_ci pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2; 9488c2ecf20Sopenharmony_ci 9498c2ecf20Sopenharmony_ci if (chan && IS_CHAN_HALF_RATE(chan)) 9508c2ecf20Sopenharmony_ci pll |= SM(0x1, AR_RTC_PLL_CLKSEL); 9518c2ecf20Sopenharmony_ci else if (chan && IS_CHAN_QUARTER_RATE(chan)) 9528c2ecf20Sopenharmony_ci pll |= SM(0x2, AR_RTC_PLL_CLKSEL); 9538c2ecf20Sopenharmony_ci 9548c2ecf20Sopenharmony_ci if (chan && IS_CHAN_5GHZ(chan)) 9558c2ecf20Sopenharmony_ci pll |= SM(0xa, AR_RTC_PLL_DIV); 9568c2ecf20Sopenharmony_ci else 9578c2ecf20Sopenharmony_ci pll |= SM(0xb, AR_RTC_PLL_DIV); 9588c2ecf20Sopenharmony_ci 9598c2ecf20Sopenharmony_ci return pll; 9608c2ecf20Sopenharmony_ci} 9618c2ecf20Sopenharmony_ci 9628c2ecf20Sopenharmony_cistatic bool ar5008_hw_ani_control_new(struct ath_hw *ah, 9638c2ecf20Sopenharmony_ci enum ath9k_ani_cmd cmd, 9648c2ecf20Sopenharmony_ci int param) 9658c2ecf20Sopenharmony_ci{ 9668c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 9678c2ecf20Sopenharmony_ci struct ath9k_channel *chan = ah->curchan; 9688c2ecf20Sopenharmony_ci struct ar5416AniState *aniState = &ah->ani; 9698c2ecf20Sopenharmony_ci s32 value; 9708c2ecf20Sopenharmony_ci 9718c2ecf20Sopenharmony_ci switch (cmd & ah->ani_function) { 9728c2ecf20Sopenharmony_ci case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{ 9738c2ecf20Sopenharmony_ci /* 9748c2ecf20Sopenharmony_ci * on == 1 means ofdm weak signal detection is ON 9758c2ecf20Sopenharmony_ci * on == 1 is the default, for less noise immunity 9768c2ecf20Sopenharmony_ci * 9778c2ecf20Sopenharmony_ci * on == 0 means ofdm weak signal detection is OFF 9788c2ecf20Sopenharmony_ci * on == 0 means more noise imm 9798c2ecf20Sopenharmony_ci */ 9808c2ecf20Sopenharmony_ci u32 on = param ? 1 : 0; 9818c2ecf20Sopenharmony_ci /* 9828c2ecf20Sopenharmony_ci * make register setting for default 9838c2ecf20Sopenharmony_ci * (weak sig detect ON) come from INI file 9848c2ecf20Sopenharmony_ci */ 9858c2ecf20Sopenharmony_ci int m1ThreshLow = on ? 9868c2ecf20Sopenharmony_ci aniState->iniDef.m1ThreshLow : m1ThreshLow_off; 9878c2ecf20Sopenharmony_ci int m2ThreshLow = on ? 9888c2ecf20Sopenharmony_ci aniState->iniDef.m2ThreshLow : m2ThreshLow_off; 9898c2ecf20Sopenharmony_ci int m1Thresh = on ? 9908c2ecf20Sopenharmony_ci aniState->iniDef.m1Thresh : m1Thresh_off; 9918c2ecf20Sopenharmony_ci int m2Thresh = on ? 9928c2ecf20Sopenharmony_ci aniState->iniDef.m2Thresh : m2Thresh_off; 9938c2ecf20Sopenharmony_ci int m2CountThr = on ? 9948c2ecf20Sopenharmony_ci aniState->iniDef.m2CountThr : m2CountThr_off; 9958c2ecf20Sopenharmony_ci int m2CountThrLow = on ? 9968c2ecf20Sopenharmony_ci aniState->iniDef.m2CountThrLow : m2CountThrLow_off; 9978c2ecf20Sopenharmony_ci int m1ThreshLowExt = on ? 9988c2ecf20Sopenharmony_ci aniState->iniDef.m1ThreshLowExt : m1ThreshLowExt_off; 9998c2ecf20Sopenharmony_ci int m2ThreshLowExt = on ? 10008c2ecf20Sopenharmony_ci aniState->iniDef.m2ThreshLowExt : m2ThreshLowExt_off; 10018c2ecf20Sopenharmony_ci int m1ThreshExt = on ? 10028c2ecf20Sopenharmony_ci aniState->iniDef.m1ThreshExt : m1ThreshExt_off; 10038c2ecf20Sopenharmony_ci int m2ThreshExt = on ? 10048c2ecf20Sopenharmony_ci aniState->iniDef.m2ThreshExt : m2ThreshExt_off; 10058c2ecf20Sopenharmony_ci 10068c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW, 10078c2ecf20Sopenharmony_ci AR_PHY_SFCORR_LOW_M1_THRESH_LOW, 10088c2ecf20Sopenharmony_ci m1ThreshLow); 10098c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW, 10108c2ecf20Sopenharmony_ci AR_PHY_SFCORR_LOW_M2_THRESH_LOW, 10118c2ecf20Sopenharmony_ci m2ThreshLow); 10128c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SFCORR, 10138c2ecf20Sopenharmony_ci AR_PHY_SFCORR_M1_THRESH, m1Thresh); 10148c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SFCORR, 10158c2ecf20Sopenharmony_ci AR_PHY_SFCORR_M2_THRESH, m2Thresh); 10168c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SFCORR, 10178c2ecf20Sopenharmony_ci AR_PHY_SFCORR_M2COUNT_THR, m2CountThr); 10188c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW, 10198c2ecf20Sopenharmony_ci AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW, 10208c2ecf20Sopenharmony_ci m2CountThrLow); 10218c2ecf20Sopenharmony_ci 10228c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT, 10238c2ecf20Sopenharmony_ci AR_PHY_SFCORR_EXT_M1_THRESH_LOW, m1ThreshLowExt); 10248c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT, 10258c2ecf20Sopenharmony_ci AR_PHY_SFCORR_EXT_M2_THRESH_LOW, m2ThreshLowExt); 10268c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT, 10278c2ecf20Sopenharmony_ci AR_PHY_SFCORR_EXT_M1_THRESH, m1ThreshExt); 10288c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT, 10298c2ecf20Sopenharmony_ci AR_PHY_SFCORR_EXT_M2_THRESH, m2ThreshExt); 10308c2ecf20Sopenharmony_ci 10318c2ecf20Sopenharmony_ci if (on) 10328c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_SFCORR_LOW, 10338c2ecf20Sopenharmony_ci AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW); 10348c2ecf20Sopenharmony_ci else 10358c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW, 10368c2ecf20Sopenharmony_ci AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW); 10378c2ecf20Sopenharmony_ci 10388c2ecf20Sopenharmony_ci if (on != aniState->ofdmWeakSigDetect) { 10398c2ecf20Sopenharmony_ci ath_dbg(common, ANI, 10408c2ecf20Sopenharmony_ci "** ch %d: ofdm weak signal: %s=>%s\n", 10418c2ecf20Sopenharmony_ci chan->channel, 10428c2ecf20Sopenharmony_ci aniState->ofdmWeakSigDetect ? 10438c2ecf20Sopenharmony_ci "on" : "off", 10448c2ecf20Sopenharmony_ci on ? "on" : "off"); 10458c2ecf20Sopenharmony_ci if (on) 10468c2ecf20Sopenharmony_ci ah->stats.ast_ani_ofdmon++; 10478c2ecf20Sopenharmony_ci else 10488c2ecf20Sopenharmony_ci ah->stats.ast_ani_ofdmoff++; 10498c2ecf20Sopenharmony_ci aniState->ofdmWeakSigDetect = on; 10508c2ecf20Sopenharmony_ci } 10518c2ecf20Sopenharmony_ci break; 10528c2ecf20Sopenharmony_ci } 10538c2ecf20Sopenharmony_ci case ATH9K_ANI_FIRSTEP_LEVEL:{ 10548c2ecf20Sopenharmony_ci u32 level = param; 10558c2ecf20Sopenharmony_ci 10568c2ecf20Sopenharmony_ci value = level * 2; 10578c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_FIND_SIG, 10588c2ecf20Sopenharmony_ci AR_PHY_FIND_SIG_FIRSTEP, value); 10598c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW, 10608c2ecf20Sopenharmony_ci AR_PHY_FIND_SIG_FIRSTEP_LOW, value); 10618c2ecf20Sopenharmony_ci 10628c2ecf20Sopenharmony_ci if (level != aniState->firstepLevel) { 10638c2ecf20Sopenharmony_ci ath_dbg(common, ANI, 10648c2ecf20Sopenharmony_ci "** ch %d: level %d=>%d[def:%d] firstep[level]=%d ini=%d\n", 10658c2ecf20Sopenharmony_ci chan->channel, 10668c2ecf20Sopenharmony_ci aniState->firstepLevel, 10678c2ecf20Sopenharmony_ci level, 10688c2ecf20Sopenharmony_ci ATH9K_ANI_FIRSTEP_LVL, 10698c2ecf20Sopenharmony_ci value, 10708c2ecf20Sopenharmony_ci aniState->iniDef.firstep); 10718c2ecf20Sopenharmony_ci ath_dbg(common, ANI, 10728c2ecf20Sopenharmony_ci "** ch %d: level %d=>%d[def:%d] firstep_low[level]=%d ini=%d\n", 10738c2ecf20Sopenharmony_ci chan->channel, 10748c2ecf20Sopenharmony_ci aniState->firstepLevel, 10758c2ecf20Sopenharmony_ci level, 10768c2ecf20Sopenharmony_ci ATH9K_ANI_FIRSTEP_LVL, 10778c2ecf20Sopenharmony_ci value, 10788c2ecf20Sopenharmony_ci aniState->iniDef.firstepLow); 10798c2ecf20Sopenharmony_ci if (level > aniState->firstepLevel) 10808c2ecf20Sopenharmony_ci ah->stats.ast_ani_stepup++; 10818c2ecf20Sopenharmony_ci else if (level < aniState->firstepLevel) 10828c2ecf20Sopenharmony_ci ah->stats.ast_ani_stepdown++; 10838c2ecf20Sopenharmony_ci aniState->firstepLevel = level; 10848c2ecf20Sopenharmony_ci } 10858c2ecf20Sopenharmony_ci break; 10868c2ecf20Sopenharmony_ci } 10878c2ecf20Sopenharmony_ci case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{ 10888c2ecf20Sopenharmony_ci u32 level = param; 10898c2ecf20Sopenharmony_ci 10908c2ecf20Sopenharmony_ci value = (level + 1) * 2; 10918c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TIMING5, 10928c2ecf20Sopenharmony_ci AR_PHY_TIMING5_CYCPWR_THR1, value); 10938c2ecf20Sopenharmony_ci 10948c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_EXT_CCA, 10958c2ecf20Sopenharmony_ci AR_PHY_EXT_TIMING5_CYCPWR_THR1, value - 1); 10968c2ecf20Sopenharmony_ci 10978c2ecf20Sopenharmony_ci if (level != aniState->spurImmunityLevel) { 10988c2ecf20Sopenharmony_ci ath_dbg(common, ANI, 10998c2ecf20Sopenharmony_ci "** ch %d: level %d=>%d[def:%d] cycpwrThr1[level]=%d ini=%d\n", 11008c2ecf20Sopenharmony_ci chan->channel, 11018c2ecf20Sopenharmony_ci aniState->spurImmunityLevel, 11028c2ecf20Sopenharmony_ci level, 11038c2ecf20Sopenharmony_ci ATH9K_ANI_SPUR_IMMUNE_LVL, 11048c2ecf20Sopenharmony_ci value, 11058c2ecf20Sopenharmony_ci aniState->iniDef.cycpwrThr1); 11068c2ecf20Sopenharmony_ci ath_dbg(common, ANI, 11078c2ecf20Sopenharmony_ci "** ch %d: level %d=>%d[def:%d] cycpwrThr1Ext[level]=%d ini=%d\n", 11088c2ecf20Sopenharmony_ci chan->channel, 11098c2ecf20Sopenharmony_ci aniState->spurImmunityLevel, 11108c2ecf20Sopenharmony_ci level, 11118c2ecf20Sopenharmony_ci ATH9K_ANI_SPUR_IMMUNE_LVL, 11128c2ecf20Sopenharmony_ci value, 11138c2ecf20Sopenharmony_ci aniState->iniDef.cycpwrThr1Ext); 11148c2ecf20Sopenharmony_ci if (level > aniState->spurImmunityLevel) 11158c2ecf20Sopenharmony_ci ah->stats.ast_ani_spurup++; 11168c2ecf20Sopenharmony_ci else if (level < aniState->spurImmunityLevel) 11178c2ecf20Sopenharmony_ci ah->stats.ast_ani_spurdown++; 11188c2ecf20Sopenharmony_ci aniState->spurImmunityLevel = level; 11198c2ecf20Sopenharmony_ci } 11208c2ecf20Sopenharmony_ci break; 11218c2ecf20Sopenharmony_ci } 11228c2ecf20Sopenharmony_ci case ATH9K_ANI_MRC_CCK: 11238c2ecf20Sopenharmony_ci /* 11248c2ecf20Sopenharmony_ci * You should not see this as AR5008, AR9001, AR9002 11258c2ecf20Sopenharmony_ci * does not have hardware support for MRC CCK. 11268c2ecf20Sopenharmony_ci */ 11278c2ecf20Sopenharmony_ci WARN_ON(1); 11288c2ecf20Sopenharmony_ci break; 11298c2ecf20Sopenharmony_ci default: 11308c2ecf20Sopenharmony_ci ath_dbg(common, ANI, "invalid cmd %u\n", cmd); 11318c2ecf20Sopenharmony_ci return false; 11328c2ecf20Sopenharmony_ci } 11338c2ecf20Sopenharmony_ci 11348c2ecf20Sopenharmony_ci ath_dbg(common, ANI, 11358c2ecf20Sopenharmony_ci "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n", 11368c2ecf20Sopenharmony_ci aniState->spurImmunityLevel, 11378c2ecf20Sopenharmony_ci aniState->ofdmWeakSigDetect ? "on" : "off", 11388c2ecf20Sopenharmony_ci aniState->firstepLevel, 11398c2ecf20Sopenharmony_ci aniState->mrcCCK ? "on" : "off", 11408c2ecf20Sopenharmony_ci aniState->listenTime, 11418c2ecf20Sopenharmony_ci aniState->ofdmPhyErrCount, 11428c2ecf20Sopenharmony_ci aniState->cckPhyErrCount); 11438c2ecf20Sopenharmony_ci return true; 11448c2ecf20Sopenharmony_ci} 11458c2ecf20Sopenharmony_ci 11468c2ecf20Sopenharmony_cistatic void ar5008_hw_do_getnf(struct ath_hw *ah, 11478c2ecf20Sopenharmony_ci int16_t nfarray[NUM_NF_READINGS]) 11488c2ecf20Sopenharmony_ci{ 11498c2ecf20Sopenharmony_ci int16_t nf; 11508c2ecf20Sopenharmony_ci 11518c2ecf20Sopenharmony_ci nf = MS(REG_READ(ah, AR_PHY_CCA), AR_PHY_MINCCA_PWR); 11528c2ecf20Sopenharmony_ci nfarray[0] = sign_extend32(nf, 8); 11538c2ecf20Sopenharmony_ci 11548c2ecf20Sopenharmony_ci nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR_PHY_CH1_MINCCA_PWR); 11558c2ecf20Sopenharmony_ci nfarray[1] = sign_extend32(nf, 8); 11568c2ecf20Sopenharmony_ci 11578c2ecf20Sopenharmony_ci nf = MS(REG_READ(ah, AR_PHY_CH2_CCA), AR_PHY_CH2_MINCCA_PWR); 11588c2ecf20Sopenharmony_ci nfarray[2] = sign_extend32(nf, 8); 11598c2ecf20Sopenharmony_ci 11608c2ecf20Sopenharmony_ci if (!IS_CHAN_HT40(ah->curchan)) 11618c2ecf20Sopenharmony_ci return; 11628c2ecf20Sopenharmony_ci 11638c2ecf20Sopenharmony_ci nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR); 11648c2ecf20Sopenharmony_ci nfarray[3] = sign_extend32(nf, 8); 11658c2ecf20Sopenharmony_ci 11668c2ecf20Sopenharmony_ci nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), AR_PHY_CH1_EXT_MINCCA_PWR); 11678c2ecf20Sopenharmony_ci nfarray[4] = sign_extend32(nf, 8); 11688c2ecf20Sopenharmony_ci 11698c2ecf20Sopenharmony_ci nf = MS(REG_READ(ah, AR_PHY_CH2_EXT_CCA), AR_PHY_CH2_EXT_MINCCA_PWR); 11708c2ecf20Sopenharmony_ci nfarray[5] = sign_extend32(nf, 8); 11718c2ecf20Sopenharmony_ci} 11728c2ecf20Sopenharmony_ci 11738c2ecf20Sopenharmony_ci/* 11748c2ecf20Sopenharmony_ci * Initialize the ANI register values with default (ini) values. 11758c2ecf20Sopenharmony_ci * This routine is called during a (full) hardware reset after 11768c2ecf20Sopenharmony_ci * all the registers are initialised from the INI. 11778c2ecf20Sopenharmony_ci */ 11788c2ecf20Sopenharmony_cistatic void ar5008_hw_ani_cache_ini_regs(struct ath_hw *ah) 11798c2ecf20Sopenharmony_ci{ 11808c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 11818c2ecf20Sopenharmony_ci struct ath9k_channel *chan = ah->curchan; 11828c2ecf20Sopenharmony_ci struct ar5416AniState *aniState = &ah->ani; 11838c2ecf20Sopenharmony_ci struct ath9k_ani_default *iniDef; 11848c2ecf20Sopenharmony_ci u32 val; 11858c2ecf20Sopenharmony_ci 11868c2ecf20Sopenharmony_ci iniDef = &aniState->iniDef; 11878c2ecf20Sopenharmony_ci 11888c2ecf20Sopenharmony_ci ath_dbg(common, ANI, "ver %d.%d opmode %u chan %d Mhz\n", 11898c2ecf20Sopenharmony_ci ah->hw_version.macVersion, 11908c2ecf20Sopenharmony_ci ah->hw_version.macRev, 11918c2ecf20Sopenharmony_ci ah->opmode, 11928c2ecf20Sopenharmony_ci chan->channel); 11938c2ecf20Sopenharmony_ci 11948c2ecf20Sopenharmony_ci val = REG_READ(ah, AR_PHY_SFCORR); 11958c2ecf20Sopenharmony_ci iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH); 11968c2ecf20Sopenharmony_ci iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH); 11978c2ecf20Sopenharmony_ci iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR); 11988c2ecf20Sopenharmony_ci 11998c2ecf20Sopenharmony_ci val = REG_READ(ah, AR_PHY_SFCORR_LOW); 12008c2ecf20Sopenharmony_ci iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW); 12018c2ecf20Sopenharmony_ci iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW); 12028c2ecf20Sopenharmony_ci iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW); 12038c2ecf20Sopenharmony_ci 12048c2ecf20Sopenharmony_ci val = REG_READ(ah, AR_PHY_SFCORR_EXT); 12058c2ecf20Sopenharmony_ci iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH); 12068c2ecf20Sopenharmony_ci iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH); 12078c2ecf20Sopenharmony_ci iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW); 12088c2ecf20Sopenharmony_ci iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW); 12098c2ecf20Sopenharmony_ci iniDef->firstep = REG_READ_FIELD(ah, 12108c2ecf20Sopenharmony_ci AR_PHY_FIND_SIG, 12118c2ecf20Sopenharmony_ci AR_PHY_FIND_SIG_FIRSTEP); 12128c2ecf20Sopenharmony_ci iniDef->firstepLow = REG_READ_FIELD(ah, 12138c2ecf20Sopenharmony_ci AR_PHY_FIND_SIG_LOW, 12148c2ecf20Sopenharmony_ci AR_PHY_FIND_SIG_FIRSTEP_LOW); 12158c2ecf20Sopenharmony_ci iniDef->cycpwrThr1 = REG_READ_FIELD(ah, 12168c2ecf20Sopenharmony_ci AR_PHY_TIMING5, 12178c2ecf20Sopenharmony_ci AR_PHY_TIMING5_CYCPWR_THR1); 12188c2ecf20Sopenharmony_ci iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah, 12198c2ecf20Sopenharmony_ci AR_PHY_EXT_CCA, 12208c2ecf20Sopenharmony_ci AR_PHY_EXT_TIMING5_CYCPWR_THR1); 12218c2ecf20Sopenharmony_ci 12228c2ecf20Sopenharmony_ci /* these levels just got reset to defaults by the INI */ 12238c2ecf20Sopenharmony_ci aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL; 12248c2ecf20Sopenharmony_ci aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL; 12258c2ecf20Sopenharmony_ci aniState->ofdmWeakSigDetect = true; 12268c2ecf20Sopenharmony_ci aniState->mrcCCK = false; /* not available on pre AR9003 */ 12278c2ecf20Sopenharmony_ci} 12288c2ecf20Sopenharmony_ci 12298c2ecf20Sopenharmony_cistatic void ar5008_hw_set_nf_limits(struct ath_hw *ah) 12308c2ecf20Sopenharmony_ci{ 12318c2ecf20Sopenharmony_ci ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_5416_2GHZ; 12328c2ecf20Sopenharmony_ci ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_5416_2GHZ; 12338c2ecf20Sopenharmony_ci ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_5416_2GHZ; 12348c2ecf20Sopenharmony_ci ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_5416_5GHZ; 12358c2ecf20Sopenharmony_ci ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_5416_5GHZ; 12368c2ecf20Sopenharmony_ci ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_5416_5GHZ; 12378c2ecf20Sopenharmony_ci} 12388c2ecf20Sopenharmony_ci 12398c2ecf20Sopenharmony_cistatic void ar5008_hw_set_radar_params(struct ath_hw *ah, 12408c2ecf20Sopenharmony_ci struct ath_hw_radar_conf *conf) 12418c2ecf20Sopenharmony_ci{ 12428c2ecf20Sopenharmony_ci u32 radar_0 = 0, radar_1; 12438c2ecf20Sopenharmony_ci 12448c2ecf20Sopenharmony_ci if (!conf) { 12458c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA); 12468c2ecf20Sopenharmony_ci return; 12478c2ecf20Sopenharmony_ci } 12488c2ecf20Sopenharmony_ci 12498c2ecf20Sopenharmony_ci radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA; 12508c2ecf20Sopenharmony_ci radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR); 12518c2ecf20Sopenharmony_ci radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI); 12528c2ecf20Sopenharmony_ci radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT); 12538c2ecf20Sopenharmony_ci radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI); 12548c2ecf20Sopenharmony_ci radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND); 12558c2ecf20Sopenharmony_ci 12568c2ecf20Sopenharmony_ci radar_1 = REG_READ(ah, AR_PHY_RADAR_1); 12578c2ecf20Sopenharmony_ci radar_1 &= ~(AR_PHY_RADAR_1_MAXLEN | AR_PHY_RADAR_1_RELSTEP_THRESH | 12588c2ecf20Sopenharmony_ci AR_PHY_RADAR_1_RELPWR_THRESH); 12598c2ecf20Sopenharmony_ci radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI; 12608c2ecf20Sopenharmony_ci radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK; 12618c2ecf20Sopenharmony_ci radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN); 12628c2ecf20Sopenharmony_ci radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH); 12638c2ecf20Sopenharmony_ci radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH); 12648c2ecf20Sopenharmony_ci 12658c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_RADAR_0, radar_0); 12668c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_RADAR_1, radar_1); 12678c2ecf20Sopenharmony_ci if (conf->ext_channel) 12688c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA); 12698c2ecf20Sopenharmony_ci else 12708c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA); 12718c2ecf20Sopenharmony_ci} 12728c2ecf20Sopenharmony_ci 12738c2ecf20Sopenharmony_cistatic void ar5008_hw_set_radar_conf(struct ath_hw *ah) 12748c2ecf20Sopenharmony_ci{ 12758c2ecf20Sopenharmony_ci struct ath_hw_radar_conf *conf = &ah->radar_conf; 12768c2ecf20Sopenharmony_ci 12778c2ecf20Sopenharmony_ci conf->fir_power = -33; 12788c2ecf20Sopenharmony_ci conf->radar_rssi = 20; 12798c2ecf20Sopenharmony_ci conf->pulse_height = 10; 12808c2ecf20Sopenharmony_ci conf->pulse_rssi = 15; 12818c2ecf20Sopenharmony_ci conf->pulse_inband = 15; 12828c2ecf20Sopenharmony_ci conf->pulse_maxlen = 255; 12838c2ecf20Sopenharmony_ci conf->pulse_inband_step = 12; 12848c2ecf20Sopenharmony_ci conf->radar_inband = 8; 12858c2ecf20Sopenharmony_ci} 12868c2ecf20Sopenharmony_ci 12878c2ecf20Sopenharmony_cistatic void ar5008_hw_init_txpower_cck(struct ath_hw *ah, int16_t *rate_array) 12888c2ecf20Sopenharmony_ci{ 12898c2ecf20Sopenharmony_ci#define CCK_DELTA(x) ((OLC_FOR_AR9280_20_LATER) ? max((x) - 2, 0) : (x)) 12908c2ecf20Sopenharmony_ci ah->tx_power[0] = CCK_DELTA(rate_array[rate1l]); 12918c2ecf20Sopenharmony_ci ah->tx_power[1] = CCK_DELTA(min(rate_array[rate2l], 12928c2ecf20Sopenharmony_ci rate_array[rate2s])); 12938c2ecf20Sopenharmony_ci ah->tx_power[2] = CCK_DELTA(min(rate_array[rate5_5l], 12948c2ecf20Sopenharmony_ci rate_array[rate5_5s])); 12958c2ecf20Sopenharmony_ci ah->tx_power[3] = CCK_DELTA(min(rate_array[rate11l], 12968c2ecf20Sopenharmony_ci rate_array[rate11s])); 12978c2ecf20Sopenharmony_ci#undef CCK_DELTA 12988c2ecf20Sopenharmony_ci} 12998c2ecf20Sopenharmony_ci 13008c2ecf20Sopenharmony_cistatic void ar5008_hw_init_txpower_ofdm(struct ath_hw *ah, int16_t *rate_array, 13018c2ecf20Sopenharmony_ci int offset) 13028c2ecf20Sopenharmony_ci{ 13038c2ecf20Sopenharmony_ci int i, idx = 0; 13048c2ecf20Sopenharmony_ci 13058c2ecf20Sopenharmony_ci for (i = offset; i < offset + AR5008_OFDM_RATES; i++) { 13068c2ecf20Sopenharmony_ci ah->tx_power[i] = rate_array[idx]; 13078c2ecf20Sopenharmony_ci idx++; 13088c2ecf20Sopenharmony_ci } 13098c2ecf20Sopenharmony_ci} 13108c2ecf20Sopenharmony_ci 13118c2ecf20Sopenharmony_cistatic void ar5008_hw_init_txpower_ht(struct ath_hw *ah, int16_t *rate_array, 13128c2ecf20Sopenharmony_ci int ss_offset, int ds_offset, 13138c2ecf20Sopenharmony_ci bool is_40, int ht40_delta) 13148c2ecf20Sopenharmony_ci{ 13158c2ecf20Sopenharmony_ci int i, mcs_idx = (is_40) ? AR5008_HT40_SHIFT : AR5008_HT20_SHIFT; 13168c2ecf20Sopenharmony_ci 13178c2ecf20Sopenharmony_ci for (i = ss_offset; i < ss_offset + AR5008_HT_SS_RATES; i++) { 13188c2ecf20Sopenharmony_ci ah->tx_power[i] = rate_array[mcs_idx] + ht40_delta; 13198c2ecf20Sopenharmony_ci mcs_idx++; 13208c2ecf20Sopenharmony_ci } 13218c2ecf20Sopenharmony_ci memcpy(&ah->tx_power[ds_offset], &ah->tx_power[ss_offset], 13228c2ecf20Sopenharmony_ci AR5008_HT_SS_RATES); 13238c2ecf20Sopenharmony_ci} 13248c2ecf20Sopenharmony_ci 13258c2ecf20Sopenharmony_civoid ar5008_hw_init_rate_txpower(struct ath_hw *ah, int16_t *rate_array, 13268c2ecf20Sopenharmony_ci struct ath9k_channel *chan, int ht40_delta) 13278c2ecf20Sopenharmony_ci{ 13288c2ecf20Sopenharmony_ci if (IS_CHAN_5GHZ(chan)) { 13298c2ecf20Sopenharmony_ci ar5008_hw_init_txpower_ofdm(ah, rate_array, 13308c2ecf20Sopenharmony_ci AR5008_11NA_OFDM_SHIFT); 13318c2ecf20Sopenharmony_ci if (IS_CHAN_HT20(chan) || IS_CHAN_HT40(chan)) { 13328c2ecf20Sopenharmony_ci ar5008_hw_init_txpower_ht(ah, rate_array, 13338c2ecf20Sopenharmony_ci AR5008_11NA_HT_SS_SHIFT, 13348c2ecf20Sopenharmony_ci AR5008_11NA_HT_DS_SHIFT, 13358c2ecf20Sopenharmony_ci IS_CHAN_HT40(chan), 13368c2ecf20Sopenharmony_ci ht40_delta); 13378c2ecf20Sopenharmony_ci } 13388c2ecf20Sopenharmony_ci } else { 13398c2ecf20Sopenharmony_ci ar5008_hw_init_txpower_cck(ah, rate_array); 13408c2ecf20Sopenharmony_ci ar5008_hw_init_txpower_ofdm(ah, rate_array, 13418c2ecf20Sopenharmony_ci AR5008_11NG_OFDM_SHIFT); 13428c2ecf20Sopenharmony_ci if (IS_CHAN_HT20(chan) || IS_CHAN_HT40(chan)) { 13438c2ecf20Sopenharmony_ci ar5008_hw_init_txpower_ht(ah, rate_array, 13448c2ecf20Sopenharmony_ci AR5008_11NG_HT_SS_SHIFT, 13458c2ecf20Sopenharmony_ci AR5008_11NG_HT_DS_SHIFT, 13468c2ecf20Sopenharmony_ci IS_CHAN_HT40(chan), 13478c2ecf20Sopenharmony_ci ht40_delta); 13488c2ecf20Sopenharmony_ci } 13498c2ecf20Sopenharmony_ci } 13508c2ecf20Sopenharmony_ci} 13518c2ecf20Sopenharmony_ci 13528c2ecf20Sopenharmony_ciint ar5008_hw_attach_phy_ops(struct ath_hw *ah) 13538c2ecf20Sopenharmony_ci{ 13548c2ecf20Sopenharmony_ci struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah); 13558c2ecf20Sopenharmony_ci static const u32 ar5416_cca_regs[6] = { 13568c2ecf20Sopenharmony_ci AR_PHY_CCA, 13578c2ecf20Sopenharmony_ci AR_PHY_CH1_CCA, 13588c2ecf20Sopenharmony_ci AR_PHY_CH2_CCA, 13598c2ecf20Sopenharmony_ci AR_PHY_EXT_CCA, 13608c2ecf20Sopenharmony_ci AR_PHY_CH1_EXT_CCA, 13618c2ecf20Sopenharmony_ci AR_PHY_CH2_EXT_CCA 13628c2ecf20Sopenharmony_ci }; 13638c2ecf20Sopenharmony_ci int ret; 13648c2ecf20Sopenharmony_ci 13658c2ecf20Sopenharmony_ci ret = ar5008_hw_rf_alloc_ext_banks(ah); 13668c2ecf20Sopenharmony_ci if (ret) 13678c2ecf20Sopenharmony_ci return ret; 13688c2ecf20Sopenharmony_ci 13698c2ecf20Sopenharmony_ci priv_ops->rf_set_freq = ar5008_hw_set_channel; 13708c2ecf20Sopenharmony_ci priv_ops->spur_mitigate_freq = ar5008_hw_spur_mitigate; 13718c2ecf20Sopenharmony_ci 13728c2ecf20Sopenharmony_ci priv_ops->set_rf_regs = ar5008_hw_set_rf_regs; 13738c2ecf20Sopenharmony_ci priv_ops->set_channel_regs = ar5008_hw_set_channel_regs; 13748c2ecf20Sopenharmony_ci priv_ops->init_bb = ar5008_hw_init_bb; 13758c2ecf20Sopenharmony_ci priv_ops->process_ini = ar5008_hw_process_ini; 13768c2ecf20Sopenharmony_ci priv_ops->set_rfmode = ar5008_hw_set_rfmode; 13778c2ecf20Sopenharmony_ci priv_ops->mark_phy_inactive = ar5008_hw_mark_phy_inactive; 13788c2ecf20Sopenharmony_ci priv_ops->set_delta_slope = ar5008_hw_set_delta_slope; 13798c2ecf20Sopenharmony_ci priv_ops->rfbus_req = ar5008_hw_rfbus_req; 13808c2ecf20Sopenharmony_ci priv_ops->rfbus_done = ar5008_hw_rfbus_done; 13818c2ecf20Sopenharmony_ci priv_ops->restore_chainmask = ar5008_restore_chainmask; 13828c2ecf20Sopenharmony_ci priv_ops->do_getnf = ar5008_hw_do_getnf; 13838c2ecf20Sopenharmony_ci priv_ops->set_radar_params = ar5008_hw_set_radar_params; 13848c2ecf20Sopenharmony_ci 13858c2ecf20Sopenharmony_ci priv_ops->ani_control = ar5008_hw_ani_control_new; 13868c2ecf20Sopenharmony_ci priv_ops->ani_cache_ini_regs = ar5008_hw_ani_cache_ini_regs; 13878c2ecf20Sopenharmony_ci 13888c2ecf20Sopenharmony_ci if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah)) 13898c2ecf20Sopenharmony_ci priv_ops->compute_pll_control = ar9160_hw_compute_pll_control; 13908c2ecf20Sopenharmony_ci else 13918c2ecf20Sopenharmony_ci priv_ops->compute_pll_control = ar5008_hw_compute_pll_control; 13928c2ecf20Sopenharmony_ci 13938c2ecf20Sopenharmony_ci ar5008_hw_set_nf_limits(ah); 13948c2ecf20Sopenharmony_ci ar5008_hw_set_radar_conf(ah); 13958c2ecf20Sopenharmony_ci memcpy(ah->nf_regs, ar5416_cca_regs, sizeof(ah->nf_regs)); 13968c2ecf20Sopenharmony_ci return 0; 13978c2ecf20Sopenharmony_ci} 1398