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 <asm/unaligned.h> 188c2ecf20Sopenharmony_ci#include "hw.h" 198c2ecf20Sopenharmony_ci#include "ar9002_phy.h" 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_cistatic int ath9k_hw_4k_get_eeprom_ver(struct ath_hw *ah) 228c2ecf20Sopenharmony_ci{ 238c2ecf20Sopenharmony_ci u16 version = le16_to_cpu(ah->eeprom.map4k.baseEepHeader.version); 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci return (version & AR5416_EEP_VER_MAJOR_MASK) >> 268c2ecf20Sopenharmony_ci AR5416_EEP_VER_MAJOR_SHIFT; 278c2ecf20Sopenharmony_ci} 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cistatic int ath9k_hw_4k_get_eeprom_rev(struct ath_hw *ah) 308c2ecf20Sopenharmony_ci{ 318c2ecf20Sopenharmony_ci u16 version = le16_to_cpu(ah->eeprom.map4k.baseEepHeader.version); 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci return version & AR5416_EEP_VER_MINOR_MASK; 348c2ecf20Sopenharmony_ci} 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define SIZE_EEPROM_4K (sizeof(struct ar5416_eeprom_4k) / sizeof(u16)) 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_cistatic bool __ath9k_hw_4k_fill_eeprom(struct ath_hw *ah) 398c2ecf20Sopenharmony_ci{ 408c2ecf20Sopenharmony_ci u16 *eep_data = (u16 *)&ah->eeprom.map4k; 418c2ecf20Sopenharmony_ci int addr, eep_start_loc = 64; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci for (addr = 0; addr < SIZE_EEPROM_4K; addr++) { 448c2ecf20Sopenharmony_ci if (!ath9k_hw_nvram_read(ah, addr + eep_start_loc, eep_data)) 458c2ecf20Sopenharmony_ci return false; 468c2ecf20Sopenharmony_ci eep_data++; 478c2ecf20Sopenharmony_ci } 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci return true; 508c2ecf20Sopenharmony_ci} 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistatic bool __ath9k_hw_usb_4k_fill_eeprom(struct ath_hw *ah) 538c2ecf20Sopenharmony_ci{ 548c2ecf20Sopenharmony_ci u16 *eep_data = (u16 *)&ah->eeprom.map4k; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci ath9k_hw_usb_gen_fill_eeprom(ah, eep_data, 64, SIZE_EEPROM_4K); 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci return true; 598c2ecf20Sopenharmony_ci} 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_cistatic bool ath9k_hw_4k_fill_eeprom(struct ath_hw *ah) 628c2ecf20Sopenharmony_ci{ 638c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci if (!ath9k_hw_use_flash(ah)) { 668c2ecf20Sopenharmony_ci ath_dbg(common, EEPROM, "Reading from EEPROM, not flash\n"); 678c2ecf20Sopenharmony_ci } 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci if (common->bus_ops->ath_bus_type == ATH_USB) 708c2ecf20Sopenharmony_ci return __ath9k_hw_usb_4k_fill_eeprom(ah); 718c2ecf20Sopenharmony_ci else 728c2ecf20Sopenharmony_ci return __ath9k_hw_4k_fill_eeprom(ah); 738c2ecf20Sopenharmony_ci} 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci#ifdef CONFIG_ATH9K_COMMON_DEBUG 768c2ecf20Sopenharmony_cistatic u32 ath9k_dump_4k_modal_eeprom(char *buf, u32 len, u32 size, 778c2ecf20Sopenharmony_ci struct modal_eep_4k_header *modal_hdr) 788c2ecf20Sopenharmony_ci{ 798c2ecf20Sopenharmony_ci PR_EEP("Chain0 Ant. Control", le16_to_cpu(modal_hdr->antCtrlChain[0])); 808c2ecf20Sopenharmony_ci PR_EEP("Ant. Common Control", le32_to_cpu(modal_hdr->antCtrlCommon)); 818c2ecf20Sopenharmony_ci PR_EEP("Chain0 Ant. Gain", modal_hdr->antennaGainCh[0]); 828c2ecf20Sopenharmony_ci PR_EEP("Switch Settle", modal_hdr->switchSettling); 838c2ecf20Sopenharmony_ci PR_EEP("Chain0 TxRxAtten", modal_hdr->txRxAttenCh[0]); 848c2ecf20Sopenharmony_ci PR_EEP("Chain0 RxTxMargin", modal_hdr->rxTxMarginCh[0]); 858c2ecf20Sopenharmony_ci PR_EEP("ADC Desired size", modal_hdr->adcDesiredSize); 868c2ecf20Sopenharmony_ci PR_EEP("PGA Desired size", modal_hdr->pgaDesiredSize); 878c2ecf20Sopenharmony_ci PR_EEP("Chain0 xlna Gain", modal_hdr->xlnaGainCh[0]); 888c2ecf20Sopenharmony_ci PR_EEP("txEndToXpaOff", modal_hdr->txEndToXpaOff); 898c2ecf20Sopenharmony_ci PR_EEP("txEndToRxOn", modal_hdr->txEndToRxOn); 908c2ecf20Sopenharmony_ci PR_EEP("txFrameToXpaOn", modal_hdr->txFrameToXpaOn); 918c2ecf20Sopenharmony_ci PR_EEP("CCA Threshold)", modal_hdr->thresh62); 928c2ecf20Sopenharmony_ci PR_EEP("Chain0 NF Threshold", modal_hdr->noiseFloorThreshCh[0]); 938c2ecf20Sopenharmony_ci PR_EEP("xpdGain", modal_hdr->xpdGain); 948c2ecf20Sopenharmony_ci PR_EEP("External PD", modal_hdr->xpd); 958c2ecf20Sopenharmony_ci PR_EEP("Chain0 I Coefficient", modal_hdr->iqCalICh[0]); 968c2ecf20Sopenharmony_ci PR_EEP("Chain0 Q Coefficient", modal_hdr->iqCalQCh[0]); 978c2ecf20Sopenharmony_ci PR_EEP("pdGainOverlap", modal_hdr->pdGainOverlap); 988c2ecf20Sopenharmony_ci PR_EEP("O/D Bias Version", modal_hdr->version); 998c2ecf20Sopenharmony_ci PR_EEP("CCK OutputBias", modal_hdr->ob_0); 1008c2ecf20Sopenharmony_ci PR_EEP("BPSK OutputBias", modal_hdr->ob_1); 1018c2ecf20Sopenharmony_ci PR_EEP("QPSK OutputBias", modal_hdr->ob_2); 1028c2ecf20Sopenharmony_ci PR_EEP("16QAM OutputBias", modal_hdr->ob_3); 1038c2ecf20Sopenharmony_ci PR_EEP("64QAM OutputBias", modal_hdr->ob_4); 1048c2ecf20Sopenharmony_ci PR_EEP("CCK Driver1_Bias", modal_hdr->db1_0); 1058c2ecf20Sopenharmony_ci PR_EEP("BPSK Driver1_Bias", modal_hdr->db1_1); 1068c2ecf20Sopenharmony_ci PR_EEP("QPSK Driver1_Bias", modal_hdr->db1_2); 1078c2ecf20Sopenharmony_ci PR_EEP("16QAM Driver1_Bias", modal_hdr->db1_3); 1088c2ecf20Sopenharmony_ci PR_EEP("64QAM Driver1_Bias", modal_hdr->db1_4); 1098c2ecf20Sopenharmony_ci PR_EEP("CCK Driver2_Bias", modal_hdr->db2_0); 1108c2ecf20Sopenharmony_ci PR_EEP("BPSK Driver2_Bias", modal_hdr->db2_1); 1118c2ecf20Sopenharmony_ci PR_EEP("QPSK Driver2_Bias", modal_hdr->db2_2); 1128c2ecf20Sopenharmony_ci PR_EEP("16QAM Driver2_Bias", modal_hdr->db2_3); 1138c2ecf20Sopenharmony_ci PR_EEP("64QAM Driver2_Bias", modal_hdr->db2_4); 1148c2ecf20Sopenharmony_ci PR_EEP("xPA Bias Level", modal_hdr->xpaBiasLvl); 1158c2ecf20Sopenharmony_ci PR_EEP("txFrameToDataStart", modal_hdr->txFrameToDataStart); 1168c2ecf20Sopenharmony_ci PR_EEP("txFrameToPaOn", modal_hdr->txFrameToPaOn); 1178c2ecf20Sopenharmony_ci PR_EEP("HT40 Power Inc.", modal_hdr->ht40PowerIncForPdadc); 1188c2ecf20Sopenharmony_ci PR_EEP("Chain0 bswAtten", modal_hdr->bswAtten[0]); 1198c2ecf20Sopenharmony_ci PR_EEP("Chain0 bswMargin", modal_hdr->bswMargin[0]); 1208c2ecf20Sopenharmony_ci PR_EEP("HT40 Switch Settle", modal_hdr->swSettleHt40); 1218c2ecf20Sopenharmony_ci PR_EEP("Chain0 xatten2Db", modal_hdr->xatten2Db[0]); 1228c2ecf20Sopenharmony_ci PR_EEP("Chain0 xatten2Margin", modal_hdr->xatten2Margin[0]); 1238c2ecf20Sopenharmony_ci PR_EEP("Ant. Diversity ctl1", modal_hdr->antdiv_ctl1); 1248c2ecf20Sopenharmony_ci PR_EEP("Ant. Diversity ctl2", modal_hdr->antdiv_ctl2); 1258c2ecf20Sopenharmony_ci PR_EEP("TX Diversity", modal_hdr->tx_diversity); 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci return len; 1288c2ecf20Sopenharmony_ci} 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_cistatic u32 ath9k_hw_4k_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr, 1318c2ecf20Sopenharmony_ci u8 *buf, u32 len, u32 size) 1328c2ecf20Sopenharmony_ci{ 1338c2ecf20Sopenharmony_ci struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k; 1348c2ecf20Sopenharmony_ci struct base_eep_header_4k *pBase = &eep->baseEepHeader; 1358c2ecf20Sopenharmony_ci u32 binBuildNumber = le32_to_cpu(pBase->binBuildNumber); 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci if (!dump_base_hdr) { 1388c2ecf20Sopenharmony_ci len += scnprintf(buf + len, size - len, 1398c2ecf20Sopenharmony_ci "%20s :\n", "2GHz modal Header"); 1408c2ecf20Sopenharmony_ci len = ath9k_dump_4k_modal_eeprom(buf, len, size, 1418c2ecf20Sopenharmony_ci &eep->modalHeader); 1428c2ecf20Sopenharmony_ci goto out; 1438c2ecf20Sopenharmony_ci } 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci PR_EEP("Major Version", ath9k_hw_4k_get_eeprom_ver(ah)); 1468c2ecf20Sopenharmony_ci PR_EEP("Minor Version", ath9k_hw_4k_get_eeprom_rev(ah)); 1478c2ecf20Sopenharmony_ci PR_EEP("Checksum", le16_to_cpu(pBase->checksum)); 1488c2ecf20Sopenharmony_ci PR_EEP("Length", le16_to_cpu(pBase->length)); 1498c2ecf20Sopenharmony_ci PR_EEP("RegDomain1", le16_to_cpu(pBase->regDmn[0])); 1508c2ecf20Sopenharmony_ci PR_EEP("RegDomain2", le16_to_cpu(pBase->regDmn[1])); 1518c2ecf20Sopenharmony_ci PR_EEP("TX Mask", pBase->txMask); 1528c2ecf20Sopenharmony_ci PR_EEP("RX Mask", pBase->rxMask); 1538c2ecf20Sopenharmony_ci PR_EEP("Allow 5GHz", !!(pBase->opCapFlags & AR5416_OPFLAGS_11A)); 1548c2ecf20Sopenharmony_ci PR_EEP("Allow 2GHz", !!(pBase->opCapFlags & AR5416_OPFLAGS_11G)); 1558c2ecf20Sopenharmony_ci PR_EEP("Disable 2GHz HT20", !!(pBase->opCapFlags & 1568c2ecf20Sopenharmony_ci AR5416_OPFLAGS_N_2G_HT20)); 1578c2ecf20Sopenharmony_ci PR_EEP("Disable 2GHz HT40", !!(pBase->opCapFlags & 1588c2ecf20Sopenharmony_ci AR5416_OPFLAGS_N_2G_HT40)); 1598c2ecf20Sopenharmony_ci PR_EEP("Disable 5Ghz HT20", !!(pBase->opCapFlags & 1608c2ecf20Sopenharmony_ci AR5416_OPFLAGS_N_5G_HT20)); 1618c2ecf20Sopenharmony_ci PR_EEP("Disable 5Ghz HT40", !!(pBase->opCapFlags & 1628c2ecf20Sopenharmony_ci AR5416_OPFLAGS_N_5G_HT40)); 1638c2ecf20Sopenharmony_ci PR_EEP("Big Endian", !!(pBase->eepMisc & AR5416_EEPMISC_BIG_ENDIAN)); 1648c2ecf20Sopenharmony_ci PR_EEP("Cal Bin Major Ver", (binBuildNumber >> 24) & 0xFF); 1658c2ecf20Sopenharmony_ci PR_EEP("Cal Bin Minor Ver", (binBuildNumber >> 16) & 0xFF); 1668c2ecf20Sopenharmony_ci PR_EEP("Cal Bin Build", (binBuildNumber >> 8) & 0xFF); 1678c2ecf20Sopenharmony_ci PR_EEP("TX Gain type", pBase->txGainType); 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci len += scnprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress", 1708c2ecf20Sopenharmony_ci pBase->macAddr); 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ciout: 1738c2ecf20Sopenharmony_ci if (len > size) 1748c2ecf20Sopenharmony_ci len = size; 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci return len; 1778c2ecf20Sopenharmony_ci} 1788c2ecf20Sopenharmony_ci#else 1798c2ecf20Sopenharmony_cistatic u32 ath9k_hw_4k_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr, 1808c2ecf20Sopenharmony_ci u8 *buf, u32 len, u32 size) 1818c2ecf20Sopenharmony_ci{ 1828c2ecf20Sopenharmony_ci return 0; 1838c2ecf20Sopenharmony_ci} 1848c2ecf20Sopenharmony_ci#endif 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_cistatic int ath9k_hw_4k_check_eeprom(struct ath_hw *ah) 1878c2ecf20Sopenharmony_ci{ 1888c2ecf20Sopenharmony_ci struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k; 1898c2ecf20Sopenharmony_ci u32 el; 1908c2ecf20Sopenharmony_ci bool need_swap; 1918c2ecf20Sopenharmony_ci int i, err; 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci err = ath9k_hw_nvram_swap_data(ah, &need_swap, SIZE_EEPROM_4K); 1948c2ecf20Sopenharmony_ci if (err) 1958c2ecf20Sopenharmony_ci return err; 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci if (need_swap) 1988c2ecf20Sopenharmony_ci el = swab16((__force u16)eep->baseEepHeader.length); 1998c2ecf20Sopenharmony_ci else 2008c2ecf20Sopenharmony_ci el = le16_to_cpu(eep->baseEepHeader.length); 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci el = min(el / sizeof(u16), SIZE_EEPROM_4K); 2038c2ecf20Sopenharmony_ci if (!ath9k_hw_nvram_validate_checksum(ah, el)) 2048c2ecf20Sopenharmony_ci return -EINVAL; 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci if (need_swap) { 2078c2ecf20Sopenharmony_ci EEPROM_FIELD_SWAB16(eep->baseEepHeader.length); 2088c2ecf20Sopenharmony_ci EEPROM_FIELD_SWAB16(eep->baseEepHeader.checksum); 2098c2ecf20Sopenharmony_ci EEPROM_FIELD_SWAB16(eep->baseEepHeader.version); 2108c2ecf20Sopenharmony_ci EEPROM_FIELD_SWAB16(eep->baseEepHeader.regDmn[0]); 2118c2ecf20Sopenharmony_ci EEPROM_FIELD_SWAB16(eep->baseEepHeader.regDmn[1]); 2128c2ecf20Sopenharmony_ci EEPROM_FIELD_SWAB16(eep->baseEepHeader.rfSilent); 2138c2ecf20Sopenharmony_ci EEPROM_FIELD_SWAB16(eep->baseEepHeader.blueToothOptions); 2148c2ecf20Sopenharmony_ci EEPROM_FIELD_SWAB16(eep->baseEepHeader.deviceCap); 2158c2ecf20Sopenharmony_ci EEPROM_FIELD_SWAB32(eep->modalHeader.antCtrlCommon); 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) 2188c2ecf20Sopenharmony_ci EEPROM_FIELD_SWAB32(eep->modalHeader.antCtrlChain[i]); 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) 2218c2ecf20Sopenharmony_ci EEPROM_FIELD_SWAB16( 2228c2ecf20Sopenharmony_ci eep->modalHeader.spurChans[i].spurChan); 2238c2ecf20Sopenharmony_ci } 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci if (!ath9k_hw_nvram_check_version(ah, AR5416_EEP_VER, 2268c2ecf20Sopenharmony_ci AR5416_EEP_NO_BACK_VER)) 2278c2ecf20Sopenharmony_ci return -EINVAL; 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci return 0; 2308c2ecf20Sopenharmony_ci} 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_ci#undef SIZE_EEPROM_4K 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_cistatic u32 ath9k_hw_4k_get_eeprom(struct ath_hw *ah, 2358c2ecf20Sopenharmony_ci enum eeprom_param param) 2368c2ecf20Sopenharmony_ci{ 2378c2ecf20Sopenharmony_ci struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k; 2388c2ecf20Sopenharmony_ci struct modal_eep_4k_header *pModal = &eep->modalHeader; 2398c2ecf20Sopenharmony_ci struct base_eep_header_4k *pBase = &eep->baseEepHeader; 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci switch (param) { 2428c2ecf20Sopenharmony_ci case EEP_NFTHRESH_2: 2438c2ecf20Sopenharmony_ci return pModal->noiseFloorThreshCh[0]; 2448c2ecf20Sopenharmony_ci case EEP_MAC_LSW: 2458c2ecf20Sopenharmony_ci return get_unaligned_be16(pBase->macAddr); 2468c2ecf20Sopenharmony_ci case EEP_MAC_MID: 2478c2ecf20Sopenharmony_ci return get_unaligned_be16(pBase->macAddr + 2); 2488c2ecf20Sopenharmony_ci case EEP_MAC_MSW: 2498c2ecf20Sopenharmony_ci return get_unaligned_be16(pBase->macAddr + 4); 2508c2ecf20Sopenharmony_ci case EEP_REG_0: 2518c2ecf20Sopenharmony_ci return le16_to_cpu(pBase->regDmn[0]); 2528c2ecf20Sopenharmony_ci case EEP_OP_CAP: 2538c2ecf20Sopenharmony_ci return le16_to_cpu(pBase->deviceCap); 2548c2ecf20Sopenharmony_ci case EEP_OP_MODE: 2558c2ecf20Sopenharmony_ci return pBase->opCapFlags; 2568c2ecf20Sopenharmony_ci case EEP_RF_SILENT: 2578c2ecf20Sopenharmony_ci return le16_to_cpu(pBase->rfSilent); 2588c2ecf20Sopenharmony_ci case EEP_OB_2: 2598c2ecf20Sopenharmony_ci return pModal->ob_0; 2608c2ecf20Sopenharmony_ci case EEP_DB_2: 2618c2ecf20Sopenharmony_ci return pModal->db1_1; 2628c2ecf20Sopenharmony_ci case EEP_TX_MASK: 2638c2ecf20Sopenharmony_ci return pBase->txMask; 2648c2ecf20Sopenharmony_ci case EEP_RX_MASK: 2658c2ecf20Sopenharmony_ci return pBase->rxMask; 2668c2ecf20Sopenharmony_ci case EEP_FRAC_N_5G: 2678c2ecf20Sopenharmony_ci return 0; 2688c2ecf20Sopenharmony_ci case EEP_PWR_TABLE_OFFSET: 2698c2ecf20Sopenharmony_ci return AR5416_PWR_TABLE_OFFSET_DB; 2708c2ecf20Sopenharmony_ci case EEP_MODAL_VER: 2718c2ecf20Sopenharmony_ci return pModal->version; 2728c2ecf20Sopenharmony_ci case EEP_ANT_DIV_CTL1: 2738c2ecf20Sopenharmony_ci return pModal->antdiv_ctl1; 2748c2ecf20Sopenharmony_ci case EEP_TXGAIN_TYPE: 2758c2ecf20Sopenharmony_ci return pBase->txGainType; 2768c2ecf20Sopenharmony_ci case EEP_ANTENNA_GAIN_2G: 2778c2ecf20Sopenharmony_ci return pModal->antennaGainCh[0]; 2788c2ecf20Sopenharmony_ci default: 2798c2ecf20Sopenharmony_ci return 0; 2808c2ecf20Sopenharmony_ci } 2818c2ecf20Sopenharmony_ci} 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_cistatic void ath9k_hw_set_4k_power_cal_table(struct ath_hw *ah, 2848c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 2858c2ecf20Sopenharmony_ci{ 2868c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 2878c2ecf20Sopenharmony_ci struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k; 2888c2ecf20Sopenharmony_ci struct cal_data_per_freq_4k *pRawDataset; 2898c2ecf20Sopenharmony_ci u8 *pCalBChans = NULL; 2908c2ecf20Sopenharmony_ci u16 pdGainOverlap_t2; 2918c2ecf20Sopenharmony_ci static u8 pdadcValues[AR5416_NUM_PDADC_VALUES]; 2928c2ecf20Sopenharmony_ci u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK]; 2938c2ecf20Sopenharmony_ci u16 numPiers, i, j; 2948c2ecf20Sopenharmony_ci u16 numXpdGain, xpdMask; 2958c2ecf20Sopenharmony_ci u16 xpdGainValues[AR5416_EEP4K_NUM_PD_GAINS] = { 0, 0 }; 2968c2ecf20Sopenharmony_ci u32 reg32, regOffset, regChainOffset; 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci xpdMask = pEepData->modalHeader.xpdGain; 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci if (ath9k_hw_4k_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_2) 3018c2ecf20Sopenharmony_ci pdGainOverlap_t2 = 3028c2ecf20Sopenharmony_ci pEepData->modalHeader.pdGainOverlap; 3038c2ecf20Sopenharmony_ci else 3048c2ecf20Sopenharmony_ci pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5), 3058c2ecf20Sopenharmony_ci AR_PHY_TPCRG5_PD_GAIN_OVERLAP)); 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_ci pCalBChans = pEepData->calFreqPier2G; 3088c2ecf20Sopenharmony_ci numPiers = AR5416_EEP4K_NUM_2G_CAL_PIERS; 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_ci numXpdGain = 0; 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_ci for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) { 3138c2ecf20Sopenharmony_ci if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) { 3148c2ecf20Sopenharmony_ci if (numXpdGain >= AR5416_EEP4K_NUM_PD_GAINS) 3158c2ecf20Sopenharmony_ci break; 3168c2ecf20Sopenharmony_ci xpdGainValues[numXpdGain] = 3178c2ecf20Sopenharmony_ci (u16)(AR5416_PD_GAINS_IN_MASK - i); 3188c2ecf20Sopenharmony_ci numXpdGain++; 3198c2ecf20Sopenharmony_ci } 3208c2ecf20Sopenharmony_ci } 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci ENABLE_REG_RMW_BUFFER(ah); 3238c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN, 3248c2ecf20Sopenharmony_ci (numXpdGain - 1) & 0x3); 3258c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1, 3268c2ecf20Sopenharmony_ci xpdGainValues[0]); 3278c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2, 3288c2ecf20Sopenharmony_ci xpdGainValues[1]); 3298c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3, 0); 3308c2ecf20Sopenharmony_ci REG_RMW_BUFFER_FLUSH(ah); 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) { 3338c2ecf20Sopenharmony_ci regChainOffset = i * 0x1000; 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci if (pEepData->baseEepHeader.txMask & (1 << i)) { 3368c2ecf20Sopenharmony_ci pRawDataset = pEepData->calPierData2G[i]; 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci ath9k_hw_get_gain_boundaries_pdadcs(ah, chan, 3398c2ecf20Sopenharmony_ci pRawDataset, pCalBChans, 3408c2ecf20Sopenharmony_ci numPiers, pdGainOverlap_t2, 3418c2ecf20Sopenharmony_ci gainBoundaries, 3428c2ecf20Sopenharmony_ci pdadcValues, numXpdGain); 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_ci ENABLE_REGWRITE_BUFFER(ah); 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_TPCRG5 + regChainOffset, 3478c2ecf20Sopenharmony_ci SM(pdGainOverlap_t2, 3488c2ecf20Sopenharmony_ci AR_PHY_TPCRG5_PD_GAIN_OVERLAP) 3498c2ecf20Sopenharmony_ci | SM(gainBoundaries[0], 3508c2ecf20Sopenharmony_ci AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1) 3518c2ecf20Sopenharmony_ci | SM(gainBoundaries[1], 3528c2ecf20Sopenharmony_ci AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2) 3538c2ecf20Sopenharmony_ci | SM(gainBoundaries[2], 3548c2ecf20Sopenharmony_ci AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3) 3558c2ecf20Sopenharmony_ci | SM(gainBoundaries[3], 3568c2ecf20Sopenharmony_ci AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4)); 3578c2ecf20Sopenharmony_ci 3588c2ecf20Sopenharmony_ci regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset; 3598c2ecf20Sopenharmony_ci for (j = 0; j < 32; j++) { 3608c2ecf20Sopenharmony_ci reg32 = get_unaligned_le32(&pdadcValues[4 * j]); 3618c2ecf20Sopenharmony_ci REG_WRITE(ah, regOffset, reg32); 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ci ath_dbg(common, EEPROM, 3648c2ecf20Sopenharmony_ci "PDADC (%d,%4x): %4.4x %8.8x\n", 3658c2ecf20Sopenharmony_ci i, regChainOffset, regOffset, 3668c2ecf20Sopenharmony_ci reg32); 3678c2ecf20Sopenharmony_ci ath_dbg(common, EEPROM, 3688c2ecf20Sopenharmony_ci "PDADC: Chain %d | " 3698c2ecf20Sopenharmony_ci "PDADC %3d Value %3d | " 3708c2ecf20Sopenharmony_ci "PDADC %3d Value %3d | " 3718c2ecf20Sopenharmony_ci "PDADC %3d Value %3d | " 3728c2ecf20Sopenharmony_ci "PDADC %3d Value %3d |\n", 3738c2ecf20Sopenharmony_ci i, 4 * j, pdadcValues[4 * j], 3748c2ecf20Sopenharmony_ci 4 * j + 1, pdadcValues[4 * j + 1], 3758c2ecf20Sopenharmony_ci 4 * j + 2, pdadcValues[4 * j + 2], 3768c2ecf20Sopenharmony_ci 4 * j + 3, pdadcValues[4 * j + 3]); 3778c2ecf20Sopenharmony_ci 3788c2ecf20Sopenharmony_ci regOffset += 4; 3798c2ecf20Sopenharmony_ci } 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ci REGWRITE_BUFFER_FLUSH(ah); 3828c2ecf20Sopenharmony_ci } 3838c2ecf20Sopenharmony_ci } 3848c2ecf20Sopenharmony_ci} 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_cistatic void ath9k_hw_set_4k_power_per_rate_table(struct ath_hw *ah, 3878c2ecf20Sopenharmony_ci struct ath9k_channel *chan, 3888c2ecf20Sopenharmony_ci int16_t *ratesArray, 3898c2ecf20Sopenharmony_ci u16 cfgCtl, 3908c2ecf20Sopenharmony_ci u16 antenna_reduction, 3918c2ecf20Sopenharmony_ci u16 powerLimit) 3928c2ecf20Sopenharmony_ci{ 3938c2ecf20Sopenharmony_ci#define CMP_TEST_GRP \ 3948c2ecf20Sopenharmony_ci (((cfgCtl & ~CTL_MODE_M)| (pCtlMode[ctlMode] & CTL_MODE_M)) == \ 3958c2ecf20Sopenharmony_ci pEepData->ctlIndex[i]) \ 3968c2ecf20Sopenharmony_ci || (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \ 3978c2ecf20Sopenharmony_ci ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL)) 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ci int i; 4008c2ecf20Sopenharmony_ci u16 twiceMinEdgePower; 4018c2ecf20Sopenharmony_ci u16 twiceMaxEdgePower; 4028c2ecf20Sopenharmony_ci u16 scaledPower = 0, minCtlPower; 4038c2ecf20Sopenharmony_ci u16 numCtlModes; 4048c2ecf20Sopenharmony_ci const u16 *pCtlMode; 4058c2ecf20Sopenharmony_ci u16 ctlMode, freq; 4068c2ecf20Sopenharmony_ci struct chan_centers centers; 4078c2ecf20Sopenharmony_ci struct cal_ctl_data_4k *rep; 4088c2ecf20Sopenharmony_ci struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k; 4098c2ecf20Sopenharmony_ci struct cal_target_power_leg targetPowerOfdm, targetPowerCck = { 4108c2ecf20Sopenharmony_ci 0, { 0, 0, 0, 0} 4118c2ecf20Sopenharmony_ci }; 4128c2ecf20Sopenharmony_ci struct cal_target_power_leg targetPowerOfdmExt = { 4138c2ecf20Sopenharmony_ci 0, { 0, 0, 0, 0} }, targetPowerCckExt = { 4148c2ecf20Sopenharmony_ci 0, { 0, 0, 0, 0 } 4158c2ecf20Sopenharmony_ci }; 4168c2ecf20Sopenharmony_ci struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = { 4178c2ecf20Sopenharmony_ci 0, {0, 0, 0, 0} 4188c2ecf20Sopenharmony_ci }; 4198c2ecf20Sopenharmony_ci static const u16 ctlModesFor11g[] = { 4208c2ecf20Sopenharmony_ci CTL_11B, CTL_11G, CTL_2GHT20, 4218c2ecf20Sopenharmony_ci CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40 4228c2ecf20Sopenharmony_ci }; 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_ci ath9k_hw_get_channel_centers(ah, chan, ¢ers); 4258c2ecf20Sopenharmony_ci 4268c2ecf20Sopenharmony_ci scaledPower = powerLimit - antenna_reduction; 4278c2ecf20Sopenharmony_ci scaledPower = min_t(u16, scaledPower, MAX_RATE_POWER); 4288c2ecf20Sopenharmony_ci numCtlModes = ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40; 4298c2ecf20Sopenharmony_ci pCtlMode = ctlModesFor11g; 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci ath9k_hw_get_legacy_target_powers(ah, chan, 4328c2ecf20Sopenharmony_ci pEepData->calTargetPowerCck, 4338c2ecf20Sopenharmony_ci AR5416_NUM_2G_CCK_TARGET_POWERS, 4348c2ecf20Sopenharmony_ci &targetPowerCck, 4, false); 4358c2ecf20Sopenharmony_ci ath9k_hw_get_legacy_target_powers(ah, chan, 4368c2ecf20Sopenharmony_ci pEepData->calTargetPower2G, 4378c2ecf20Sopenharmony_ci AR5416_NUM_2G_20_TARGET_POWERS, 4388c2ecf20Sopenharmony_ci &targetPowerOfdm, 4, false); 4398c2ecf20Sopenharmony_ci ath9k_hw_get_target_powers(ah, chan, 4408c2ecf20Sopenharmony_ci pEepData->calTargetPower2GHT20, 4418c2ecf20Sopenharmony_ci AR5416_NUM_2G_20_TARGET_POWERS, 4428c2ecf20Sopenharmony_ci &targetPowerHt20, 8, false); 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ci if (IS_CHAN_HT40(chan)) { 4458c2ecf20Sopenharmony_ci numCtlModes = ARRAY_SIZE(ctlModesFor11g); 4468c2ecf20Sopenharmony_ci ath9k_hw_get_target_powers(ah, chan, 4478c2ecf20Sopenharmony_ci pEepData->calTargetPower2GHT40, 4488c2ecf20Sopenharmony_ci AR5416_NUM_2G_40_TARGET_POWERS, 4498c2ecf20Sopenharmony_ci &targetPowerHt40, 8, true); 4508c2ecf20Sopenharmony_ci ath9k_hw_get_legacy_target_powers(ah, chan, 4518c2ecf20Sopenharmony_ci pEepData->calTargetPowerCck, 4528c2ecf20Sopenharmony_ci AR5416_NUM_2G_CCK_TARGET_POWERS, 4538c2ecf20Sopenharmony_ci &targetPowerCckExt, 4, true); 4548c2ecf20Sopenharmony_ci ath9k_hw_get_legacy_target_powers(ah, chan, 4558c2ecf20Sopenharmony_ci pEepData->calTargetPower2G, 4568c2ecf20Sopenharmony_ci AR5416_NUM_2G_20_TARGET_POWERS, 4578c2ecf20Sopenharmony_ci &targetPowerOfdmExt, 4, true); 4588c2ecf20Sopenharmony_ci } 4598c2ecf20Sopenharmony_ci 4608c2ecf20Sopenharmony_ci for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) { 4618c2ecf20Sopenharmony_ci bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) || 4628c2ecf20Sopenharmony_ci (pCtlMode[ctlMode] == CTL_2GHT40); 4638c2ecf20Sopenharmony_ci 4648c2ecf20Sopenharmony_ci if (isHt40CtlMode) 4658c2ecf20Sopenharmony_ci freq = centers.synth_center; 4668c2ecf20Sopenharmony_ci else if (pCtlMode[ctlMode] & EXT_ADDITIVE) 4678c2ecf20Sopenharmony_ci freq = centers.ext_center; 4688c2ecf20Sopenharmony_ci else 4698c2ecf20Sopenharmony_ci freq = centers.ctl_center; 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ci twiceMaxEdgePower = MAX_RATE_POWER; 4728c2ecf20Sopenharmony_ci 4738c2ecf20Sopenharmony_ci for (i = 0; (i < AR5416_EEP4K_NUM_CTLS) && 4748c2ecf20Sopenharmony_ci pEepData->ctlIndex[i]; i++) { 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ci if (CMP_TEST_GRP) { 4778c2ecf20Sopenharmony_ci rep = &(pEepData->ctlData[i]); 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_ci twiceMinEdgePower = ath9k_hw_get_max_edge_power( 4808c2ecf20Sopenharmony_ci freq, 4818c2ecf20Sopenharmony_ci rep->ctlEdges[ 4828c2ecf20Sopenharmony_ci ar5416_get_ntxchains(ah->txchainmask) - 1], 4838c2ecf20Sopenharmony_ci IS_CHAN_2GHZ(chan), 4848c2ecf20Sopenharmony_ci AR5416_EEP4K_NUM_BAND_EDGES); 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ci if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) { 4878c2ecf20Sopenharmony_ci twiceMaxEdgePower = 4888c2ecf20Sopenharmony_ci min(twiceMaxEdgePower, 4898c2ecf20Sopenharmony_ci twiceMinEdgePower); 4908c2ecf20Sopenharmony_ci } else { 4918c2ecf20Sopenharmony_ci twiceMaxEdgePower = twiceMinEdgePower; 4928c2ecf20Sopenharmony_ci break; 4938c2ecf20Sopenharmony_ci } 4948c2ecf20Sopenharmony_ci } 4958c2ecf20Sopenharmony_ci } 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower); 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci switch (pCtlMode[ctlMode]) { 5008c2ecf20Sopenharmony_ci case CTL_11B: 5018c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) { 5028c2ecf20Sopenharmony_ci targetPowerCck.tPow2x[i] = 5038c2ecf20Sopenharmony_ci min((u16)targetPowerCck.tPow2x[i], 5048c2ecf20Sopenharmony_ci minCtlPower); 5058c2ecf20Sopenharmony_ci } 5068c2ecf20Sopenharmony_ci break; 5078c2ecf20Sopenharmony_ci case CTL_11G: 5088c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) { 5098c2ecf20Sopenharmony_ci targetPowerOfdm.tPow2x[i] = 5108c2ecf20Sopenharmony_ci min((u16)targetPowerOfdm.tPow2x[i], 5118c2ecf20Sopenharmony_ci minCtlPower); 5128c2ecf20Sopenharmony_ci } 5138c2ecf20Sopenharmony_ci break; 5148c2ecf20Sopenharmony_ci case CTL_2GHT20: 5158c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) { 5168c2ecf20Sopenharmony_ci targetPowerHt20.tPow2x[i] = 5178c2ecf20Sopenharmony_ci min((u16)targetPowerHt20.tPow2x[i], 5188c2ecf20Sopenharmony_ci minCtlPower); 5198c2ecf20Sopenharmony_ci } 5208c2ecf20Sopenharmony_ci break; 5218c2ecf20Sopenharmony_ci case CTL_11B_EXT: 5228c2ecf20Sopenharmony_ci targetPowerCckExt.tPow2x[0] = 5238c2ecf20Sopenharmony_ci min((u16)targetPowerCckExt.tPow2x[0], 5248c2ecf20Sopenharmony_ci minCtlPower); 5258c2ecf20Sopenharmony_ci break; 5268c2ecf20Sopenharmony_ci case CTL_11G_EXT: 5278c2ecf20Sopenharmony_ci targetPowerOfdmExt.tPow2x[0] = 5288c2ecf20Sopenharmony_ci min((u16)targetPowerOfdmExt.tPow2x[0], 5298c2ecf20Sopenharmony_ci minCtlPower); 5308c2ecf20Sopenharmony_ci break; 5318c2ecf20Sopenharmony_ci case CTL_2GHT40: 5328c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) { 5338c2ecf20Sopenharmony_ci targetPowerHt40.tPow2x[i] = 5348c2ecf20Sopenharmony_ci min((u16)targetPowerHt40.tPow2x[i], 5358c2ecf20Sopenharmony_ci minCtlPower); 5368c2ecf20Sopenharmony_ci } 5378c2ecf20Sopenharmony_ci break; 5388c2ecf20Sopenharmony_ci default: 5398c2ecf20Sopenharmony_ci break; 5408c2ecf20Sopenharmony_ci } 5418c2ecf20Sopenharmony_ci } 5428c2ecf20Sopenharmony_ci 5438c2ecf20Sopenharmony_ci ratesArray[rate6mb] = 5448c2ecf20Sopenharmony_ci ratesArray[rate9mb] = 5458c2ecf20Sopenharmony_ci ratesArray[rate12mb] = 5468c2ecf20Sopenharmony_ci ratesArray[rate18mb] = 5478c2ecf20Sopenharmony_ci ratesArray[rate24mb] = 5488c2ecf20Sopenharmony_ci targetPowerOfdm.tPow2x[0]; 5498c2ecf20Sopenharmony_ci 5508c2ecf20Sopenharmony_ci ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1]; 5518c2ecf20Sopenharmony_ci ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2]; 5528c2ecf20Sopenharmony_ci ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3]; 5538c2ecf20Sopenharmony_ci ratesArray[rateXr] = targetPowerOfdm.tPow2x[0]; 5548c2ecf20Sopenharmony_ci 5558c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) 5568c2ecf20Sopenharmony_ci ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i]; 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_ci ratesArray[rate1l] = targetPowerCck.tPow2x[0]; 5598c2ecf20Sopenharmony_ci ratesArray[rate2s] = ratesArray[rate2l] = targetPowerCck.tPow2x[1]; 5608c2ecf20Sopenharmony_ci ratesArray[rate5_5s] = ratesArray[rate5_5l] = targetPowerCck.tPow2x[2]; 5618c2ecf20Sopenharmony_ci ratesArray[rate11s] = ratesArray[rate11l] = targetPowerCck.tPow2x[3]; 5628c2ecf20Sopenharmony_ci 5638c2ecf20Sopenharmony_ci if (IS_CHAN_HT40(chan)) { 5648c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) { 5658c2ecf20Sopenharmony_ci ratesArray[rateHt40_0 + i] = 5668c2ecf20Sopenharmony_ci targetPowerHt40.tPow2x[i]; 5678c2ecf20Sopenharmony_ci } 5688c2ecf20Sopenharmony_ci ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0]; 5698c2ecf20Sopenharmony_ci ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0]; 5708c2ecf20Sopenharmony_ci ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0]; 5718c2ecf20Sopenharmony_ci ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0]; 5728c2ecf20Sopenharmony_ci } 5738c2ecf20Sopenharmony_ci 5748c2ecf20Sopenharmony_ci#undef CMP_TEST_GRP 5758c2ecf20Sopenharmony_ci} 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_cistatic void ath9k_hw_4k_set_txpower(struct ath_hw *ah, 5788c2ecf20Sopenharmony_ci struct ath9k_channel *chan, 5798c2ecf20Sopenharmony_ci u16 cfgCtl, 5808c2ecf20Sopenharmony_ci u8 twiceAntennaReduction, 5818c2ecf20Sopenharmony_ci u8 powerLimit, bool test) 5828c2ecf20Sopenharmony_ci{ 5838c2ecf20Sopenharmony_ci struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); 5848c2ecf20Sopenharmony_ci struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k; 5858c2ecf20Sopenharmony_ci struct modal_eep_4k_header *pModal = &pEepData->modalHeader; 5868c2ecf20Sopenharmony_ci int16_t ratesArray[Ar5416RateSize]; 5878c2ecf20Sopenharmony_ci u8 ht40PowerIncForPdadc = 2; 5888c2ecf20Sopenharmony_ci int i; 5898c2ecf20Sopenharmony_ci 5908c2ecf20Sopenharmony_ci memset(ratesArray, 0, sizeof(ratesArray)); 5918c2ecf20Sopenharmony_ci 5928c2ecf20Sopenharmony_ci if (ath9k_hw_4k_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_2) 5938c2ecf20Sopenharmony_ci ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc; 5948c2ecf20Sopenharmony_ci 5958c2ecf20Sopenharmony_ci ath9k_hw_set_4k_power_per_rate_table(ah, chan, 5968c2ecf20Sopenharmony_ci &ratesArray[0], cfgCtl, 5978c2ecf20Sopenharmony_ci twiceAntennaReduction, 5988c2ecf20Sopenharmony_ci powerLimit); 5998c2ecf20Sopenharmony_ci 6008c2ecf20Sopenharmony_ci ath9k_hw_set_4k_power_cal_table(ah, chan); 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_ci regulatory->max_power_level = 0; 6038c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(ratesArray); i++) { 6048c2ecf20Sopenharmony_ci if (ratesArray[i] > MAX_RATE_POWER) 6058c2ecf20Sopenharmony_ci ratesArray[i] = MAX_RATE_POWER; 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_ci if (ratesArray[i] > regulatory->max_power_level) 6088c2ecf20Sopenharmony_ci regulatory->max_power_level = ratesArray[i]; 6098c2ecf20Sopenharmony_ci } 6108c2ecf20Sopenharmony_ci 6118c2ecf20Sopenharmony_ci if (test) 6128c2ecf20Sopenharmony_ci return; 6138c2ecf20Sopenharmony_ci 6148c2ecf20Sopenharmony_ci for (i = 0; i < Ar5416RateSize; i++) 6158c2ecf20Sopenharmony_ci ratesArray[i] -= AR5416_PWR_TABLE_OFFSET_DB * 2; 6168c2ecf20Sopenharmony_ci 6178c2ecf20Sopenharmony_ci ENABLE_REGWRITE_BUFFER(ah); 6188c2ecf20Sopenharmony_ci 6198c2ecf20Sopenharmony_ci /* OFDM power per rate */ 6208c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_POWER_TX_RATE1, 6218c2ecf20Sopenharmony_ci ATH9K_POW_SM(ratesArray[rate18mb], 24) 6228c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rate12mb], 16) 6238c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rate9mb], 8) 6248c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rate6mb], 0)); 6258c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_POWER_TX_RATE2, 6268c2ecf20Sopenharmony_ci ATH9K_POW_SM(ratesArray[rate54mb], 24) 6278c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rate48mb], 16) 6288c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rate36mb], 8) 6298c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rate24mb], 0)); 6308c2ecf20Sopenharmony_ci 6318c2ecf20Sopenharmony_ci /* CCK power per rate */ 6328c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_POWER_TX_RATE3, 6338c2ecf20Sopenharmony_ci ATH9K_POW_SM(ratesArray[rate2s], 24) 6348c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rate2l], 16) 6358c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rateXr], 8) 6368c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rate1l], 0)); 6378c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_POWER_TX_RATE4, 6388c2ecf20Sopenharmony_ci ATH9K_POW_SM(ratesArray[rate11s], 24) 6398c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rate11l], 16) 6408c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rate5_5s], 8) 6418c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rate5_5l], 0)); 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_ci /* HT20 power per rate */ 6448c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_POWER_TX_RATE5, 6458c2ecf20Sopenharmony_ci ATH9K_POW_SM(ratesArray[rateHt20_3], 24) 6468c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rateHt20_2], 16) 6478c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rateHt20_1], 8) 6488c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rateHt20_0], 0)); 6498c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_POWER_TX_RATE6, 6508c2ecf20Sopenharmony_ci ATH9K_POW_SM(ratesArray[rateHt20_7], 24) 6518c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rateHt20_6], 16) 6528c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rateHt20_5], 8) 6538c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rateHt20_4], 0)); 6548c2ecf20Sopenharmony_ci 6558c2ecf20Sopenharmony_ci /* HT40 power per rate */ 6568c2ecf20Sopenharmony_ci if (IS_CHAN_HT40(chan)) { 6578c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_POWER_TX_RATE7, 6588c2ecf20Sopenharmony_ci ATH9K_POW_SM(ratesArray[rateHt40_3] + 6598c2ecf20Sopenharmony_ci ht40PowerIncForPdadc, 24) 6608c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rateHt40_2] + 6618c2ecf20Sopenharmony_ci ht40PowerIncForPdadc, 16) 6628c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rateHt40_1] + 6638c2ecf20Sopenharmony_ci ht40PowerIncForPdadc, 8) 6648c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rateHt40_0] + 6658c2ecf20Sopenharmony_ci ht40PowerIncForPdadc, 0)); 6668c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_POWER_TX_RATE8, 6678c2ecf20Sopenharmony_ci ATH9K_POW_SM(ratesArray[rateHt40_7] + 6688c2ecf20Sopenharmony_ci ht40PowerIncForPdadc, 24) 6698c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rateHt40_6] + 6708c2ecf20Sopenharmony_ci ht40PowerIncForPdadc, 16) 6718c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rateHt40_5] + 6728c2ecf20Sopenharmony_ci ht40PowerIncForPdadc, 8) 6738c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rateHt40_4] + 6748c2ecf20Sopenharmony_ci ht40PowerIncForPdadc, 0)); 6758c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_POWER_TX_RATE9, 6768c2ecf20Sopenharmony_ci ATH9K_POW_SM(ratesArray[rateExtOfdm], 24) 6778c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rateExtCck], 16) 6788c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8) 6798c2ecf20Sopenharmony_ci | ATH9K_POW_SM(ratesArray[rateDupCck], 0)); 6808c2ecf20Sopenharmony_ci } 6818c2ecf20Sopenharmony_ci 6828c2ecf20Sopenharmony_ci /* TPC initializations */ 6838c2ecf20Sopenharmony_ci if (ah->tpc_enabled) { 6848c2ecf20Sopenharmony_ci int ht40_delta; 6858c2ecf20Sopenharmony_ci 6868c2ecf20Sopenharmony_ci ht40_delta = (IS_CHAN_HT40(chan)) ? ht40PowerIncForPdadc : 0; 6878c2ecf20Sopenharmony_ci ar5008_hw_init_rate_txpower(ah, ratesArray, chan, ht40_delta); 6888c2ecf20Sopenharmony_ci /* Enable TPC */ 6898c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_POWER_TX_RATE_MAX, 6908c2ecf20Sopenharmony_ci MAX_RATE_POWER | AR_PHY_POWER_TX_RATE_MAX_TPC_ENABLE); 6918c2ecf20Sopenharmony_ci } else { 6928c2ecf20Sopenharmony_ci /* Disable TPC */ 6938c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_POWER_TX_RATE_MAX, MAX_RATE_POWER); 6948c2ecf20Sopenharmony_ci } 6958c2ecf20Sopenharmony_ci 6968c2ecf20Sopenharmony_ci REGWRITE_BUFFER_FLUSH(ah); 6978c2ecf20Sopenharmony_ci} 6988c2ecf20Sopenharmony_ci 6998c2ecf20Sopenharmony_cistatic void ath9k_hw_4k_set_gain(struct ath_hw *ah, 7008c2ecf20Sopenharmony_ci struct modal_eep_4k_header *pModal, 7018c2ecf20Sopenharmony_ci struct ar5416_eeprom_4k *eep, 7028c2ecf20Sopenharmony_ci u8 txRxAttenLocal) 7038c2ecf20Sopenharmony_ci{ 7048c2ecf20Sopenharmony_ci ENABLE_REG_RMW_BUFFER(ah); 7058c2ecf20Sopenharmony_ci REG_RMW(ah, AR_PHY_SWITCH_CHAIN_0, 7068c2ecf20Sopenharmony_ci le32_to_cpu(pModal->antCtrlChain[0]), 0); 7078c2ecf20Sopenharmony_ci 7088c2ecf20Sopenharmony_ci REG_RMW(ah, AR_PHY_TIMING_CTRL4(0), 7098c2ecf20Sopenharmony_ci SM(pModal->iqCalICh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) | 7108c2ecf20Sopenharmony_ci SM(pModal->iqCalQCh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF), 7118c2ecf20Sopenharmony_ci AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF | AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF); 7128c2ecf20Sopenharmony_ci 7138c2ecf20Sopenharmony_ci if (ath9k_hw_4k_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_3) { 7148c2ecf20Sopenharmony_ci txRxAttenLocal = pModal->txRxAttenCh[0]; 7158c2ecf20Sopenharmony_ci 7168c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ, 7178c2ecf20Sopenharmony_ci AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN, pModal->bswMargin[0]); 7188c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ, 7198c2ecf20Sopenharmony_ci AR_PHY_GAIN_2GHZ_XATTEN1_DB, pModal->bswAtten[0]); 7208c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ, 7218c2ecf20Sopenharmony_ci AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN, 7228c2ecf20Sopenharmony_ci pModal->xatten2Margin[0]); 7238c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ, 7248c2ecf20Sopenharmony_ci AR_PHY_GAIN_2GHZ_XATTEN2_DB, pModal->xatten2Db[0]); 7258c2ecf20Sopenharmony_ci 7268c2ecf20Sopenharmony_ci /* Set the block 1 value to block 0 value */ 7278c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000, 7288c2ecf20Sopenharmony_ci AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN, 7298c2ecf20Sopenharmony_ci pModal->bswMargin[0]); 7308c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000, 7318c2ecf20Sopenharmony_ci AR_PHY_GAIN_2GHZ_XATTEN1_DB, pModal->bswAtten[0]); 7328c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000, 7338c2ecf20Sopenharmony_ci AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN, 7348c2ecf20Sopenharmony_ci pModal->xatten2Margin[0]); 7358c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000, 7368c2ecf20Sopenharmony_ci AR_PHY_GAIN_2GHZ_XATTEN2_DB, 7378c2ecf20Sopenharmony_ci pModal->xatten2Db[0]); 7388c2ecf20Sopenharmony_ci } 7398c2ecf20Sopenharmony_ci 7408c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_RXGAIN, 7418c2ecf20Sopenharmony_ci AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal); 7428c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_RXGAIN, 7438c2ecf20Sopenharmony_ci AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[0]); 7448c2ecf20Sopenharmony_ci 7458c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_RXGAIN + 0x1000, 7468c2ecf20Sopenharmony_ci AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal); 7478c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_RXGAIN + 0x1000, 7488c2ecf20Sopenharmony_ci AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[0]); 7498c2ecf20Sopenharmony_ci REG_RMW_BUFFER_FLUSH(ah); 7508c2ecf20Sopenharmony_ci} 7518c2ecf20Sopenharmony_ci 7528c2ecf20Sopenharmony_ci/* 7538c2ecf20Sopenharmony_ci * Read EEPROM header info and program the device for correct operation 7548c2ecf20Sopenharmony_ci * given the channel value. 7558c2ecf20Sopenharmony_ci */ 7568c2ecf20Sopenharmony_cistatic void ath9k_hw_4k_set_board_values(struct ath_hw *ah, 7578c2ecf20Sopenharmony_ci struct ath9k_channel *chan) 7588c2ecf20Sopenharmony_ci{ 7598c2ecf20Sopenharmony_ci struct ath9k_hw_capabilities *pCap = &ah->caps; 7608c2ecf20Sopenharmony_ci struct modal_eep_4k_header *pModal; 7618c2ecf20Sopenharmony_ci struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k; 7628c2ecf20Sopenharmony_ci struct base_eep_header_4k *pBase = &eep->baseEepHeader; 7638c2ecf20Sopenharmony_ci u8 txRxAttenLocal; 7648c2ecf20Sopenharmony_ci u8 ob[5], db1[5], db2[5]; 7658c2ecf20Sopenharmony_ci u8 ant_div_control1, ant_div_control2; 7668c2ecf20Sopenharmony_ci u8 bb_desired_scale; 7678c2ecf20Sopenharmony_ci u32 regVal; 7688c2ecf20Sopenharmony_ci 7698c2ecf20Sopenharmony_ci pModal = &eep->modalHeader; 7708c2ecf20Sopenharmony_ci txRxAttenLocal = 23; 7718c2ecf20Sopenharmony_ci 7728c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_SWITCH_COM, le32_to_cpu(pModal->antCtrlCommon)); 7738c2ecf20Sopenharmony_ci 7748c2ecf20Sopenharmony_ci /* Single chain for 4K EEPROM*/ 7758c2ecf20Sopenharmony_ci ath9k_hw_4k_set_gain(ah, pModal, eep, txRxAttenLocal); 7768c2ecf20Sopenharmony_ci 7778c2ecf20Sopenharmony_ci /* Initialize Ant Diversity settings from EEPROM */ 7788c2ecf20Sopenharmony_ci if (pModal->version >= 3) { 7798c2ecf20Sopenharmony_ci ant_div_control1 = pModal->antdiv_ctl1; 7808c2ecf20Sopenharmony_ci ant_div_control2 = pModal->antdiv_ctl2; 7818c2ecf20Sopenharmony_ci 7828c2ecf20Sopenharmony_ci regVal = REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL); 7838c2ecf20Sopenharmony_ci regVal &= (~(AR_PHY_9285_ANT_DIV_CTL_ALL)); 7848c2ecf20Sopenharmony_ci 7858c2ecf20Sopenharmony_ci regVal |= SM(ant_div_control1, 7868c2ecf20Sopenharmony_ci AR_PHY_9285_ANT_DIV_CTL); 7878c2ecf20Sopenharmony_ci regVal |= SM(ant_div_control2, 7888c2ecf20Sopenharmony_ci AR_PHY_9285_ANT_DIV_ALT_LNACONF); 7898c2ecf20Sopenharmony_ci regVal |= SM((ant_div_control2 >> 2), 7908c2ecf20Sopenharmony_ci AR_PHY_9285_ANT_DIV_MAIN_LNACONF); 7918c2ecf20Sopenharmony_ci regVal |= SM((ant_div_control1 >> 1), 7928c2ecf20Sopenharmony_ci AR_PHY_9285_ANT_DIV_ALT_GAINTB); 7938c2ecf20Sopenharmony_ci regVal |= SM((ant_div_control1 >> 2), 7948c2ecf20Sopenharmony_ci AR_PHY_9285_ANT_DIV_MAIN_GAINTB); 7958c2ecf20Sopenharmony_ci 7968c2ecf20Sopenharmony_ci 7978c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_MULTICHAIN_GAIN_CTL, regVal); 7988c2ecf20Sopenharmony_ci regVal = REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL); 7998c2ecf20Sopenharmony_ci regVal = REG_READ(ah, AR_PHY_CCK_DETECT); 8008c2ecf20Sopenharmony_ci regVal &= (~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV); 8018c2ecf20Sopenharmony_ci regVal |= SM((ant_div_control1 >> 3), 8028c2ecf20Sopenharmony_ci AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV); 8038c2ecf20Sopenharmony_ci 8048c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_CCK_DETECT, regVal); 8058c2ecf20Sopenharmony_ci regVal = REG_READ(ah, AR_PHY_CCK_DETECT); 8068c2ecf20Sopenharmony_ci 8078c2ecf20Sopenharmony_ci if (pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) { 8088c2ecf20Sopenharmony_ci /* 8098c2ecf20Sopenharmony_ci * If diversity combining is enabled, 8108c2ecf20Sopenharmony_ci * set MAIN to LNA1 and ALT to LNA2 initially. 8118c2ecf20Sopenharmony_ci */ 8128c2ecf20Sopenharmony_ci regVal = REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL); 8138c2ecf20Sopenharmony_ci regVal &= (~(AR_PHY_9285_ANT_DIV_MAIN_LNACONF | 8148c2ecf20Sopenharmony_ci AR_PHY_9285_ANT_DIV_ALT_LNACONF)); 8158c2ecf20Sopenharmony_ci 8168c2ecf20Sopenharmony_ci regVal |= (ATH_ANT_DIV_COMB_LNA1 << 8178c2ecf20Sopenharmony_ci AR_PHY_9285_ANT_DIV_MAIN_LNACONF_S); 8188c2ecf20Sopenharmony_ci regVal |= (ATH_ANT_DIV_COMB_LNA2 << 8198c2ecf20Sopenharmony_ci AR_PHY_9285_ANT_DIV_ALT_LNACONF_S); 8208c2ecf20Sopenharmony_ci regVal &= (~(AR_PHY_9285_FAST_DIV_BIAS)); 8218c2ecf20Sopenharmony_ci regVal |= (0 << AR_PHY_9285_FAST_DIV_BIAS_S); 8228c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_MULTICHAIN_GAIN_CTL, regVal); 8238c2ecf20Sopenharmony_ci } 8248c2ecf20Sopenharmony_ci } 8258c2ecf20Sopenharmony_ci 8268c2ecf20Sopenharmony_ci if (pModal->version >= 2) { 8278c2ecf20Sopenharmony_ci ob[0] = pModal->ob_0; 8288c2ecf20Sopenharmony_ci ob[1] = pModal->ob_1; 8298c2ecf20Sopenharmony_ci ob[2] = pModal->ob_2; 8308c2ecf20Sopenharmony_ci ob[3] = pModal->ob_3; 8318c2ecf20Sopenharmony_ci ob[4] = pModal->ob_4; 8328c2ecf20Sopenharmony_ci 8338c2ecf20Sopenharmony_ci db1[0] = pModal->db1_0; 8348c2ecf20Sopenharmony_ci db1[1] = pModal->db1_1; 8358c2ecf20Sopenharmony_ci db1[2] = pModal->db1_2; 8368c2ecf20Sopenharmony_ci db1[3] = pModal->db1_3; 8378c2ecf20Sopenharmony_ci db1[4] = pModal->db1_4; 8388c2ecf20Sopenharmony_ci 8398c2ecf20Sopenharmony_ci db2[0] = pModal->db2_0; 8408c2ecf20Sopenharmony_ci db2[1] = pModal->db2_1; 8418c2ecf20Sopenharmony_ci db2[2] = pModal->db2_2; 8428c2ecf20Sopenharmony_ci db2[3] = pModal->db2_3; 8438c2ecf20Sopenharmony_ci db2[4] = pModal->db2_4; 8448c2ecf20Sopenharmony_ci } else if (pModal->version == 1) { 8458c2ecf20Sopenharmony_ci ob[0] = pModal->ob_0; 8468c2ecf20Sopenharmony_ci ob[1] = ob[2] = ob[3] = ob[4] = pModal->ob_1; 8478c2ecf20Sopenharmony_ci db1[0] = pModal->db1_0; 8488c2ecf20Sopenharmony_ci db1[1] = db1[2] = db1[3] = db1[4] = pModal->db1_1; 8498c2ecf20Sopenharmony_ci db2[0] = pModal->db2_0; 8508c2ecf20Sopenharmony_ci db2[1] = db2[2] = db2[3] = db2[4] = pModal->db2_1; 8518c2ecf20Sopenharmony_ci } else { 8528c2ecf20Sopenharmony_ci int i; 8538c2ecf20Sopenharmony_ci 8548c2ecf20Sopenharmony_ci for (i = 0; i < 5; i++) { 8558c2ecf20Sopenharmony_ci ob[i] = pModal->ob_0; 8568c2ecf20Sopenharmony_ci db1[i] = pModal->db1_0; 8578c2ecf20Sopenharmony_ci db2[i] = pModal->db1_0; 8588c2ecf20Sopenharmony_ci } 8598c2ecf20Sopenharmony_ci } 8608c2ecf20Sopenharmony_ci 8618c2ecf20Sopenharmony_ci ENABLE_REG_RMW_BUFFER(ah); 8628c2ecf20Sopenharmony_ci if (AR_SREV_9271(ah)) { 8638c2ecf20Sopenharmony_ci ath9k_hw_analog_shift_rmw(ah, 8648c2ecf20Sopenharmony_ci AR9285_AN_RF2G3, 8658c2ecf20Sopenharmony_ci AR9271_AN_RF2G3_OB_cck, 8668c2ecf20Sopenharmony_ci AR9271_AN_RF2G3_OB_cck_S, 8678c2ecf20Sopenharmony_ci ob[0]); 8688c2ecf20Sopenharmony_ci ath9k_hw_analog_shift_rmw(ah, 8698c2ecf20Sopenharmony_ci AR9285_AN_RF2G3, 8708c2ecf20Sopenharmony_ci AR9271_AN_RF2G3_OB_psk, 8718c2ecf20Sopenharmony_ci AR9271_AN_RF2G3_OB_psk_S, 8728c2ecf20Sopenharmony_ci ob[1]); 8738c2ecf20Sopenharmony_ci ath9k_hw_analog_shift_rmw(ah, 8748c2ecf20Sopenharmony_ci AR9285_AN_RF2G3, 8758c2ecf20Sopenharmony_ci AR9271_AN_RF2G3_OB_qam, 8768c2ecf20Sopenharmony_ci AR9271_AN_RF2G3_OB_qam_S, 8778c2ecf20Sopenharmony_ci ob[2]); 8788c2ecf20Sopenharmony_ci ath9k_hw_analog_shift_rmw(ah, 8798c2ecf20Sopenharmony_ci AR9285_AN_RF2G3, 8808c2ecf20Sopenharmony_ci AR9271_AN_RF2G3_DB_1, 8818c2ecf20Sopenharmony_ci AR9271_AN_RF2G3_DB_1_S, 8828c2ecf20Sopenharmony_ci db1[0]); 8838c2ecf20Sopenharmony_ci ath9k_hw_analog_shift_rmw(ah, 8848c2ecf20Sopenharmony_ci AR9285_AN_RF2G4, 8858c2ecf20Sopenharmony_ci AR9271_AN_RF2G4_DB_2, 8868c2ecf20Sopenharmony_ci AR9271_AN_RF2G4_DB_2_S, 8878c2ecf20Sopenharmony_ci db2[0]); 8888c2ecf20Sopenharmony_ci } else { 8898c2ecf20Sopenharmony_ci ath9k_hw_analog_shift_rmw(ah, 8908c2ecf20Sopenharmony_ci AR9285_AN_RF2G3, 8918c2ecf20Sopenharmony_ci AR9285_AN_RF2G3_OB_0, 8928c2ecf20Sopenharmony_ci AR9285_AN_RF2G3_OB_0_S, 8938c2ecf20Sopenharmony_ci ob[0]); 8948c2ecf20Sopenharmony_ci ath9k_hw_analog_shift_rmw(ah, 8958c2ecf20Sopenharmony_ci AR9285_AN_RF2G3, 8968c2ecf20Sopenharmony_ci AR9285_AN_RF2G3_OB_1, 8978c2ecf20Sopenharmony_ci AR9285_AN_RF2G3_OB_1_S, 8988c2ecf20Sopenharmony_ci ob[1]); 8998c2ecf20Sopenharmony_ci ath9k_hw_analog_shift_rmw(ah, 9008c2ecf20Sopenharmony_ci AR9285_AN_RF2G3, 9018c2ecf20Sopenharmony_ci AR9285_AN_RF2G3_OB_2, 9028c2ecf20Sopenharmony_ci AR9285_AN_RF2G3_OB_2_S, 9038c2ecf20Sopenharmony_ci ob[2]); 9048c2ecf20Sopenharmony_ci ath9k_hw_analog_shift_rmw(ah, 9058c2ecf20Sopenharmony_ci AR9285_AN_RF2G3, 9068c2ecf20Sopenharmony_ci AR9285_AN_RF2G3_OB_3, 9078c2ecf20Sopenharmony_ci AR9285_AN_RF2G3_OB_3_S, 9088c2ecf20Sopenharmony_ci ob[3]); 9098c2ecf20Sopenharmony_ci ath9k_hw_analog_shift_rmw(ah, 9108c2ecf20Sopenharmony_ci AR9285_AN_RF2G3, 9118c2ecf20Sopenharmony_ci AR9285_AN_RF2G3_OB_4, 9128c2ecf20Sopenharmony_ci AR9285_AN_RF2G3_OB_4_S, 9138c2ecf20Sopenharmony_ci ob[4]); 9148c2ecf20Sopenharmony_ci 9158c2ecf20Sopenharmony_ci ath9k_hw_analog_shift_rmw(ah, 9168c2ecf20Sopenharmony_ci AR9285_AN_RF2G3, 9178c2ecf20Sopenharmony_ci AR9285_AN_RF2G3_DB1_0, 9188c2ecf20Sopenharmony_ci AR9285_AN_RF2G3_DB1_0_S, 9198c2ecf20Sopenharmony_ci db1[0]); 9208c2ecf20Sopenharmony_ci ath9k_hw_analog_shift_rmw(ah, 9218c2ecf20Sopenharmony_ci AR9285_AN_RF2G3, 9228c2ecf20Sopenharmony_ci AR9285_AN_RF2G3_DB1_1, 9238c2ecf20Sopenharmony_ci AR9285_AN_RF2G3_DB1_1_S, 9248c2ecf20Sopenharmony_ci db1[1]); 9258c2ecf20Sopenharmony_ci ath9k_hw_analog_shift_rmw(ah, 9268c2ecf20Sopenharmony_ci AR9285_AN_RF2G3, 9278c2ecf20Sopenharmony_ci AR9285_AN_RF2G3_DB1_2, 9288c2ecf20Sopenharmony_ci AR9285_AN_RF2G3_DB1_2_S, 9298c2ecf20Sopenharmony_ci db1[2]); 9308c2ecf20Sopenharmony_ci ath9k_hw_analog_shift_rmw(ah, 9318c2ecf20Sopenharmony_ci AR9285_AN_RF2G4, 9328c2ecf20Sopenharmony_ci AR9285_AN_RF2G4_DB1_3, 9338c2ecf20Sopenharmony_ci AR9285_AN_RF2G4_DB1_3_S, 9348c2ecf20Sopenharmony_ci db1[3]); 9358c2ecf20Sopenharmony_ci ath9k_hw_analog_shift_rmw(ah, 9368c2ecf20Sopenharmony_ci AR9285_AN_RF2G4, 9378c2ecf20Sopenharmony_ci AR9285_AN_RF2G4_DB1_4, 9388c2ecf20Sopenharmony_ci AR9285_AN_RF2G4_DB1_4_S, db1[4]); 9398c2ecf20Sopenharmony_ci 9408c2ecf20Sopenharmony_ci ath9k_hw_analog_shift_rmw(ah, 9418c2ecf20Sopenharmony_ci AR9285_AN_RF2G4, 9428c2ecf20Sopenharmony_ci AR9285_AN_RF2G4_DB2_0, 9438c2ecf20Sopenharmony_ci AR9285_AN_RF2G4_DB2_0_S, 9448c2ecf20Sopenharmony_ci db2[0]); 9458c2ecf20Sopenharmony_ci ath9k_hw_analog_shift_rmw(ah, 9468c2ecf20Sopenharmony_ci AR9285_AN_RF2G4, 9478c2ecf20Sopenharmony_ci AR9285_AN_RF2G4_DB2_1, 9488c2ecf20Sopenharmony_ci AR9285_AN_RF2G4_DB2_1_S, 9498c2ecf20Sopenharmony_ci db2[1]); 9508c2ecf20Sopenharmony_ci ath9k_hw_analog_shift_rmw(ah, 9518c2ecf20Sopenharmony_ci AR9285_AN_RF2G4, 9528c2ecf20Sopenharmony_ci AR9285_AN_RF2G4_DB2_2, 9538c2ecf20Sopenharmony_ci AR9285_AN_RF2G4_DB2_2_S, 9548c2ecf20Sopenharmony_ci db2[2]); 9558c2ecf20Sopenharmony_ci ath9k_hw_analog_shift_rmw(ah, 9568c2ecf20Sopenharmony_ci AR9285_AN_RF2G4, 9578c2ecf20Sopenharmony_ci AR9285_AN_RF2G4_DB2_3, 9588c2ecf20Sopenharmony_ci AR9285_AN_RF2G4_DB2_3_S, 9598c2ecf20Sopenharmony_ci db2[3]); 9608c2ecf20Sopenharmony_ci ath9k_hw_analog_shift_rmw(ah, 9618c2ecf20Sopenharmony_ci AR9285_AN_RF2G4, 9628c2ecf20Sopenharmony_ci AR9285_AN_RF2G4_DB2_4, 9638c2ecf20Sopenharmony_ci AR9285_AN_RF2G4_DB2_4_S, 9648c2ecf20Sopenharmony_ci db2[4]); 9658c2ecf20Sopenharmony_ci } 9668c2ecf20Sopenharmony_ci REG_RMW_BUFFER_FLUSH(ah); 9678c2ecf20Sopenharmony_ci 9688c2ecf20Sopenharmony_ci ENABLE_REG_RMW_BUFFER(ah); 9698c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH, 9708c2ecf20Sopenharmony_ci pModal->switchSettling); 9718c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC, 9728c2ecf20Sopenharmony_ci pModal->adcDesiredSize); 9738c2ecf20Sopenharmony_ci 9748c2ecf20Sopenharmony_ci REG_RMW(ah, AR_PHY_RF_CTL4, 9758c2ecf20Sopenharmony_ci SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF) | 9768c2ecf20Sopenharmony_ci SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF) | 9778c2ecf20Sopenharmony_ci SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON) | 9788c2ecf20Sopenharmony_ci SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON), 0); 9798c2ecf20Sopenharmony_ci 9808c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON, 9818c2ecf20Sopenharmony_ci pModal->txEndToRxOn); 9828c2ecf20Sopenharmony_ci 9838c2ecf20Sopenharmony_ci if (AR_SREV_9271_10(ah)) 9848c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON, 9858c2ecf20Sopenharmony_ci pModal->txEndToRxOn); 9868c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62, 9878c2ecf20Sopenharmony_ci pModal->thresh62); 9888c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0, AR_PHY_EXT_CCA0_THRESH62, 9898c2ecf20Sopenharmony_ci pModal->thresh62); 9908c2ecf20Sopenharmony_ci 9918c2ecf20Sopenharmony_ci if (ath9k_hw_4k_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_2) { 9928c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_DATA_START, 9938c2ecf20Sopenharmony_ci pModal->txFrameToDataStart); 9948c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON, 9958c2ecf20Sopenharmony_ci pModal->txFrameToPaOn); 9968c2ecf20Sopenharmony_ci } 9978c2ecf20Sopenharmony_ci 9988c2ecf20Sopenharmony_ci if (ath9k_hw_4k_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_3) { 9998c2ecf20Sopenharmony_ci if (IS_CHAN_HT40(chan)) 10008c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PHY_SETTLING, 10018c2ecf20Sopenharmony_ci AR_PHY_SETTLING_SWITCH, 10028c2ecf20Sopenharmony_ci pModal->swSettleHt40); 10038c2ecf20Sopenharmony_ci } 10048c2ecf20Sopenharmony_ci 10058c2ecf20Sopenharmony_ci REG_RMW_BUFFER_FLUSH(ah); 10068c2ecf20Sopenharmony_ci 10078c2ecf20Sopenharmony_ci bb_desired_scale = (pModal->bb_scale_smrt_antenna & 10088c2ecf20Sopenharmony_ci EEP_4K_BB_DESIRED_SCALE_MASK); 10098c2ecf20Sopenharmony_ci if ((pBase->txGainType == 0) && (bb_desired_scale != 0)) { 10108c2ecf20Sopenharmony_ci u32 pwrctrl, mask, clr; 10118c2ecf20Sopenharmony_ci 10128c2ecf20Sopenharmony_ci mask = BIT(0)|BIT(5)|BIT(10)|BIT(15)|BIT(20)|BIT(25); 10138c2ecf20Sopenharmony_ci pwrctrl = mask * bb_desired_scale; 10148c2ecf20Sopenharmony_ci clr = mask * 0x1f; 10158c2ecf20Sopenharmony_ci ENABLE_REG_RMW_BUFFER(ah); 10168c2ecf20Sopenharmony_ci REG_RMW(ah, AR_PHY_TX_PWRCTRL8, pwrctrl, clr); 10178c2ecf20Sopenharmony_ci REG_RMW(ah, AR_PHY_TX_PWRCTRL10, pwrctrl, clr); 10188c2ecf20Sopenharmony_ci REG_RMW(ah, AR_PHY_CH0_TX_PWRCTRL12, pwrctrl, clr); 10198c2ecf20Sopenharmony_ci 10208c2ecf20Sopenharmony_ci mask = BIT(0)|BIT(5)|BIT(15); 10218c2ecf20Sopenharmony_ci pwrctrl = mask * bb_desired_scale; 10228c2ecf20Sopenharmony_ci clr = mask * 0x1f; 10238c2ecf20Sopenharmony_ci REG_RMW(ah, AR_PHY_TX_PWRCTRL9, pwrctrl, clr); 10248c2ecf20Sopenharmony_ci 10258c2ecf20Sopenharmony_ci mask = BIT(0)|BIT(5); 10268c2ecf20Sopenharmony_ci pwrctrl = mask * bb_desired_scale; 10278c2ecf20Sopenharmony_ci clr = mask * 0x1f; 10288c2ecf20Sopenharmony_ci REG_RMW(ah, AR_PHY_CH0_TX_PWRCTRL11, pwrctrl, clr); 10298c2ecf20Sopenharmony_ci REG_RMW(ah, AR_PHY_CH0_TX_PWRCTRL13, pwrctrl, clr); 10308c2ecf20Sopenharmony_ci REG_RMW_BUFFER_FLUSH(ah); 10318c2ecf20Sopenharmony_ci } 10328c2ecf20Sopenharmony_ci} 10338c2ecf20Sopenharmony_ci 10348c2ecf20Sopenharmony_cistatic u16 ath9k_hw_4k_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz) 10358c2ecf20Sopenharmony_ci{ 10368c2ecf20Sopenharmony_ci return le16_to_cpu(ah->eeprom.map4k.modalHeader.spurChans[i].spurChan); 10378c2ecf20Sopenharmony_ci} 10388c2ecf20Sopenharmony_ci 10398c2ecf20Sopenharmony_cistatic u8 ath9k_hw_4k_get_eepmisc(struct ath_hw *ah) 10408c2ecf20Sopenharmony_ci{ 10418c2ecf20Sopenharmony_ci return ah->eeprom.map4k.baseEepHeader.eepMisc; 10428c2ecf20Sopenharmony_ci} 10438c2ecf20Sopenharmony_ci 10448c2ecf20Sopenharmony_ciconst struct eeprom_ops eep_4k_ops = { 10458c2ecf20Sopenharmony_ci .check_eeprom = ath9k_hw_4k_check_eeprom, 10468c2ecf20Sopenharmony_ci .get_eeprom = ath9k_hw_4k_get_eeprom, 10478c2ecf20Sopenharmony_ci .fill_eeprom = ath9k_hw_4k_fill_eeprom, 10488c2ecf20Sopenharmony_ci .dump_eeprom = ath9k_hw_4k_dump_eeprom, 10498c2ecf20Sopenharmony_ci .get_eeprom_ver = ath9k_hw_4k_get_eeprom_ver, 10508c2ecf20Sopenharmony_ci .get_eeprom_rev = ath9k_hw_4k_get_eeprom_rev, 10518c2ecf20Sopenharmony_ci .set_board_values = ath9k_hw_4k_set_board_values, 10528c2ecf20Sopenharmony_ci .set_txpower = ath9k_hw_4k_set_txpower, 10538c2ecf20Sopenharmony_ci .get_spur_channel = ath9k_hw_4k_get_spur_channel, 10548c2ecf20Sopenharmony_ci .get_eepmisc = ath9k_hw_4k_get_eepmisc 10558c2ecf20Sopenharmony_ci}; 1056