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 <linux/moduleparam.h> 188c2ecf20Sopenharmony_ci#include "hw.h" 198c2ecf20Sopenharmony_ci#include "ar5008_initvals.h" 208c2ecf20Sopenharmony_ci#include "ar9001_initvals.h" 218c2ecf20Sopenharmony_ci#include "ar9002_initvals.h" 228c2ecf20Sopenharmony_ci#include "ar9002_phy.h" 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/* General hardware code for the A5008/AR9001/AR9002 hadware families */ 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_cistatic int ar9002_hw_init_mode_regs(struct ath_hw *ah) 278c2ecf20Sopenharmony_ci{ 288c2ecf20Sopenharmony_ci if (AR_SREV_9271(ah)) { 298c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271); 308c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271); 318c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModes_9271_ANI_reg, ar9271Modes_9271_ANI_reg); 328c2ecf20Sopenharmony_ci return 0; 338c2ecf20Sopenharmony_ci } 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniPcieSerdes, 368c2ecf20Sopenharmony_ci ar9280PciePhy_clkreq_always_on_L1_9280); 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci if (AR_SREV_9287_11_OR_LATER(ah)) { 398c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1); 408c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1); 418c2ecf20Sopenharmony_ci } else if (AR_SREV_9285_12_OR_LATER(ah)) { 428c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2); 438c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2); 448c2ecf20Sopenharmony_ci } else if (AR_SREV_9280_20_OR_LATER(ah)) { 458c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2); 468c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2); 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModesFastClock, 498c2ecf20Sopenharmony_ci ar9280Modes_fast_clock_9280_2); 508c2ecf20Sopenharmony_ci } else if (AR_SREV_9160_10_OR_LATER(ah)) { 518c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160); 528c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160); 538c2ecf20Sopenharmony_ci if (AR_SREV_9160_11(ah)) { 548c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniAddac, 558c2ecf20Sopenharmony_ci ar5416Addac_9160_1_1); 568c2ecf20Sopenharmony_ci } else { 578c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160); 588c2ecf20Sopenharmony_ci } 598c2ecf20Sopenharmony_ci } else if (AR_SREV_9100_OR_LATER(ah)) { 608c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100); 618c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100); 628c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100); 638c2ecf20Sopenharmony_ci } else { 648c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModes, ar5416Modes); 658c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniCommon, ar5416Common); 668c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac); 678c2ecf20Sopenharmony_ci } 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci if (!AR_SREV_9280_20_OR_LATER(ah)) { 708c2ecf20Sopenharmony_ci /* Common for AR5416, AR913x, AR9160 */ 718c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain); 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci /* Common for AR913x, AR9160 */ 748c2ecf20Sopenharmony_ci if (!AR_SREV_5416(ah)) 758c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6TPC_9100); 768c2ecf20Sopenharmony_ci else 778c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6TPC); 788c2ecf20Sopenharmony_ci } 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci /* iniAddac needs to be modified for these chips */ 818c2ecf20Sopenharmony_ci if (AR_SREV_9160(ah) || !AR_SREV_5416_22_OR_LATER(ah)) { 828c2ecf20Sopenharmony_ci struct ar5416IniArray *addac = &ah->iniAddac; 838c2ecf20Sopenharmony_ci u32 size = sizeof(u32) * addac->ia_rows * addac->ia_columns; 848c2ecf20Sopenharmony_ci u32 *data; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci data = devm_kzalloc(ah->dev, size, GFP_KERNEL); 878c2ecf20Sopenharmony_ci if (!data) 888c2ecf20Sopenharmony_ci return -ENOMEM; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci memcpy(data, addac->ia_array, size); 918c2ecf20Sopenharmony_ci addac->ia_array = data; 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci if (!AR_SREV_5416_22_OR_LATER(ah)) { 948c2ecf20Sopenharmony_ci /* override CLKDRV value */ 958c2ecf20Sopenharmony_ci INI_RA(addac, 31,1) = 0; 968c2ecf20Sopenharmony_ci } 978c2ecf20Sopenharmony_ci } 988c2ecf20Sopenharmony_ci if (AR_SREV_9287_11_OR_LATER(ah)) { 998c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniCckfirNormal, 1008c2ecf20Sopenharmony_ci ar9287Common_normal_cck_fir_coeff_9287_1_1); 1018c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniCckfirJapan2484, 1028c2ecf20Sopenharmony_ci ar9287Common_japan_2484_cck_fir_coeff_9287_1_1); 1038c2ecf20Sopenharmony_ci } 1048c2ecf20Sopenharmony_ci return 0; 1058c2ecf20Sopenharmony_ci} 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_cistatic void ar9280_20_hw_init_rxgain_ini(struct ath_hw *ah) 1088c2ecf20Sopenharmony_ci{ 1098c2ecf20Sopenharmony_ci u32 rxgain_type; 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci if (ah->eep_ops->get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_17) { 1128c2ecf20Sopenharmony_ci rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE); 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF) 1158c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModesRxGain, 1168c2ecf20Sopenharmony_ci ar9280Modes_backoff_13db_rxgain_9280_2); 1178c2ecf20Sopenharmony_ci else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF) 1188c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModesRxGain, 1198c2ecf20Sopenharmony_ci ar9280Modes_backoff_23db_rxgain_9280_2); 1208c2ecf20Sopenharmony_ci else 1218c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModesRxGain, 1228c2ecf20Sopenharmony_ci ar9280Modes_original_rxgain_9280_2); 1238c2ecf20Sopenharmony_ci } else { 1248c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModesRxGain, 1258c2ecf20Sopenharmony_ci ar9280Modes_original_rxgain_9280_2); 1268c2ecf20Sopenharmony_ci } 1278c2ecf20Sopenharmony_ci} 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_cistatic void ar9280_20_hw_init_txgain_ini(struct ath_hw *ah, u32 txgain_type) 1308c2ecf20Sopenharmony_ci{ 1318c2ecf20Sopenharmony_ci if (ah->eep_ops->get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_19) { 1328c2ecf20Sopenharmony_ci if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) 1338c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModesTxGain, 1348c2ecf20Sopenharmony_ci ar9280Modes_high_power_tx_gain_9280_2); 1358c2ecf20Sopenharmony_ci else 1368c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModesTxGain, 1378c2ecf20Sopenharmony_ci ar9280Modes_original_tx_gain_9280_2); 1388c2ecf20Sopenharmony_ci } else { 1398c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModesTxGain, 1408c2ecf20Sopenharmony_ci ar9280Modes_original_tx_gain_9280_2); 1418c2ecf20Sopenharmony_ci } 1428c2ecf20Sopenharmony_ci} 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_cistatic void ar9271_hw_init_txgain_ini(struct ath_hw *ah, u32 txgain_type) 1458c2ecf20Sopenharmony_ci{ 1468c2ecf20Sopenharmony_ci if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) 1478c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModesTxGain, 1488c2ecf20Sopenharmony_ci ar9271Modes_high_power_tx_gain_9271); 1498c2ecf20Sopenharmony_ci else 1508c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModesTxGain, 1518c2ecf20Sopenharmony_ci ar9271Modes_normal_power_tx_gain_9271); 1528c2ecf20Sopenharmony_ci} 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_cistatic void ar9002_hw_init_mode_gain_regs(struct ath_hw *ah) 1558c2ecf20Sopenharmony_ci{ 1568c2ecf20Sopenharmony_ci u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE); 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci if (AR_SREV_9287_11_OR_LATER(ah)) 1598c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModesRxGain, 1608c2ecf20Sopenharmony_ci ar9287Modes_rx_gain_9287_1_1); 1618c2ecf20Sopenharmony_ci else if (AR_SREV_9280_20(ah)) 1628c2ecf20Sopenharmony_ci ar9280_20_hw_init_rxgain_ini(ah); 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci if (AR_SREV_9271(ah)) { 1658c2ecf20Sopenharmony_ci ar9271_hw_init_txgain_ini(ah, txgain_type); 1668c2ecf20Sopenharmony_ci } else if (AR_SREV_9287_11_OR_LATER(ah)) { 1678c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModesTxGain, 1688c2ecf20Sopenharmony_ci ar9287Modes_tx_gain_9287_1_1); 1698c2ecf20Sopenharmony_ci } else if (AR_SREV_9280_20(ah)) { 1708c2ecf20Sopenharmony_ci ar9280_20_hw_init_txgain_ini(ah, txgain_type); 1718c2ecf20Sopenharmony_ci } else if (AR_SREV_9285_12_OR_LATER(ah)) { 1728c2ecf20Sopenharmony_ci /* txgain table */ 1738c2ecf20Sopenharmony_ci if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) { 1748c2ecf20Sopenharmony_ci if (AR_SREV_9285E_20(ah)) { 1758c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModesTxGain, 1768c2ecf20Sopenharmony_ci ar9285Modes_XE2_0_high_power); 1778c2ecf20Sopenharmony_ci } else { 1788c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModesTxGain, 1798c2ecf20Sopenharmony_ci ar9285Modes_high_power_tx_gain_9285_1_2); 1808c2ecf20Sopenharmony_ci } 1818c2ecf20Sopenharmony_ci } else { 1828c2ecf20Sopenharmony_ci if (AR_SREV_9285E_20(ah)) { 1838c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModesTxGain, 1848c2ecf20Sopenharmony_ci ar9285Modes_XE2_0_normal_power); 1858c2ecf20Sopenharmony_ci } else { 1868c2ecf20Sopenharmony_ci INIT_INI_ARRAY(&ah->iniModesTxGain, 1878c2ecf20Sopenharmony_ci ar9285Modes_original_tx_gain_9285_1_2); 1888c2ecf20Sopenharmony_ci } 1898c2ecf20Sopenharmony_ci } 1908c2ecf20Sopenharmony_ci } 1918c2ecf20Sopenharmony_ci} 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci/* 1948c2ecf20Sopenharmony_ci * Helper for ASPM support. 1958c2ecf20Sopenharmony_ci * 1968c2ecf20Sopenharmony_ci * Disable PLL when in L0s as well as receiver clock when in L1. 1978c2ecf20Sopenharmony_ci * This power saving option must be enabled through the SerDes. 1988c2ecf20Sopenharmony_ci * 1998c2ecf20Sopenharmony_ci * Programming the SerDes must go through the same 288 bit serial shift 2008c2ecf20Sopenharmony_ci * register as the other analog registers. Hence the 9 writes. 2018c2ecf20Sopenharmony_ci */ 2028c2ecf20Sopenharmony_cistatic void ar9002_hw_configpcipowersave(struct ath_hw *ah, 2038c2ecf20Sopenharmony_ci bool power_off) 2048c2ecf20Sopenharmony_ci{ 2058c2ecf20Sopenharmony_ci u8 i; 2068c2ecf20Sopenharmony_ci u32 val; 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci /* Nothing to do on restore for 11N */ 2098c2ecf20Sopenharmony_ci if (!power_off /* !restore */) { 2108c2ecf20Sopenharmony_ci if (AR_SREV_9280_20_OR_LATER(ah)) { 2118c2ecf20Sopenharmony_ci /* 2128c2ecf20Sopenharmony_ci * AR9280 2.0 or later chips use SerDes values from the 2138c2ecf20Sopenharmony_ci * initvals.h initialized depending on chipset during 2148c2ecf20Sopenharmony_ci * __ath9k_hw_init() 2158c2ecf20Sopenharmony_ci */ 2168c2ecf20Sopenharmony_ci for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) { 2178c2ecf20Sopenharmony_ci REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0), 2188c2ecf20Sopenharmony_ci INI_RA(&ah->iniPcieSerdes, i, 1)); 2198c2ecf20Sopenharmony_ci } 2208c2ecf20Sopenharmony_ci } else { 2218c2ecf20Sopenharmony_ci ENABLE_REGWRITE_BUFFER(ah); 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00); 2248c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924); 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci /* RX shut off when elecidle is asserted */ 2278c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039); 2288c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824); 2298c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579); 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci /* 2328c2ecf20Sopenharmony_ci * Ignore ah->ah_config.pcie_clock_req setting for 2338c2ecf20Sopenharmony_ci * pre-AR9280 11n 2348c2ecf20Sopenharmony_ci */ 2358c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff); 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40); 2388c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554); 2398c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007); 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci /* Load the new settings */ 2428c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000); 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci REGWRITE_BUFFER_FLUSH(ah); 2458c2ecf20Sopenharmony_ci } 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci udelay(1000); 2488c2ecf20Sopenharmony_ci } 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci if (power_off) { 2518c2ecf20Sopenharmony_ci /* clear bit 19 to disable L1 */ 2528c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA); 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci val = REG_READ(ah, AR_WA); 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci /* 2578c2ecf20Sopenharmony_ci * Set PCIe workaround bits 2588c2ecf20Sopenharmony_ci * In AR9280 and AR9285, bit 14 in WA register (disable L1) 2598c2ecf20Sopenharmony_ci * should only be set when device enters D3 and be 2608c2ecf20Sopenharmony_ci * cleared when device comes back to D0. 2618c2ecf20Sopenharmony_ci */ 2628c2ecf20Sopenharmony_ci if (ah->config.pcie_waen) { 2638c2ecf20Sopenharmony_ci if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE) 2648c2ecf20Sopenharmony_ci val |= AR_WA_D3_L1_DISABLE; 2658c2ecf20Sopenharmony_ci } else { 2668c2ecf20Sopenharmony_ci if (AR_SREV_9285(ah) || AR_SREV_9271(ah) || AR_SREV_9287(ah)) { 2678c2ecf20Sopenharmony_ci if (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE) 2688c2ecf20Sopenharmony_ci val |= AR_WA_D3_L1_DISABLE; 2698c2ecf20Sopenharmony_ci } else if (AR_SREV_9280(ah)) { 2708c2ecf20Sopenharmony_ci if (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE) 2718c2ecf20Sopenharmony_ci val |= AR_WA_D3_L1_DISABLE; 2728c2ecf20Sopenharmony_ci } 2738c2ecf20Sopenharmony_ci } 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ci if (AR_SREV_9280(ah) || AR_SREV_9285(ah) || AR_SREV_9287(ah)) { 2768c2ecf20Sopenharmony_ci /* 2778c2ecf20Sopenharmony_ci * Disable bit 6 and 7 before entering D3 to 2788c2ecf20Sopenharmony_ci * prevent system hang. 2798c2ecf20Sopenharmony_ci */ 2808c2ecf20Sopenharmony_ci val &= ~(AR_WA_BIT6 | AR_WA_BIT7); 2818c2ecf20Sopenharmony_ci } 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_ci if (AR_SREV_9280(ah)) 2848c2ecf20Sopenharmony_ci val |= AR_WA_BIT22; 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci if (AR_SREV_9285E_20(ah)) 2878c2ecf20Sopenharmony_ci val |= AR_WA_BIT23; 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_WA, val); 2908c2ecf20Sopenharmony_ci } else { 2918c2ecf20Sopenharmony_ci if (ah->config.pcie_waen) { 2928c2ecf20Sopenharmony_ci val = ah->config.pcie_waen; 2938c2ecf20Sopenharmony_ci val &= (~AR_WA_D3_L1_DISABLE); 2948c2ecf20Sopenharmony_ci } else { 2958c2ecf20Sopenharmony_ci if (AR_SREV_9285(ah) || AR_SREV_9271(ah) || AR_SREV_9287(ah)) { 2968c2ecf20Sopenharmony_ci val = AR9285_WA_DEFAULT; 2978c2ecf20Sopenharmony_ci val &= (~AR_WA_D3_L1_DISABLE); 2988c2ecf20Sopenharmony_ci } else if (AR_SREV_9280(ah)) { 2998c2ecf20Sopenharmony_ci /* 3008c2ecf20Sopenharmony_ci * For AR9280 chips, bit 22 of 0x4004 3018c2ecf20Sopenharmony_ci * needs to be set. 3028c2ecf20Sopenharmony_ci */ 3038c2ecf20Sopenharmony_ci val = AR9280_WA_DEFAULT; 3048c2ecf20Sopenharmony_ci val &= (~AR_WA_D3_L1_DISABLE); 3058c2ecf20Sopenharmony_ci } else { 3068c2ecf20Sopenharmony_ci val = AR_WA_DEFAULT; 3078c2ecf20Sopenharmony_ci } 3088c2ecf20Sopenharmony_ci } 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_ci /* WAR for ASPM system hang */ 3118c2ecf20Sopenharmony_ci if (AR_SREV_9285(ah) || AR_SREV_9287(ah)) 3128c2ecf20Sopenharmony_ci val |= (AR_WA_BIT6 | AR_WA_BIT7); 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_ci if (AR_SREV_9285E_20(ah)) 3158c2ecf20Sopenharmony_ci val |= AR_WA_BIT23; 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_WA, val); 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_ci /* set bit 19 to allow forcing of pcie core into L1 state */ 3208c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA); 3218c2ecf20Sopenharmony_ci } 3228c2ecf20Sopenharmony_ci} 3238c2ecf20Sopenharmony_ci 3248c2ecf20Sopenharmony_cistatic int ar9002_hw_get_radiorev(struct ath_hw *ah) 3258c2ecf20Sopenharmony_ci{ 3268c2ecf20Sopenharmony_ci u32 val; 3278c2ecf20Sopenharmony_ci int i; 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_ci ENABLE_REGWRITE_BUFFER(ah); 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY(0x36), 0x00007058); 3328c2ecf20Sopenharmony_ci for (i = 0; i < 8; i++) 3338c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY(0x20), 0x00010000); 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci REGWRITE_BUFFER_FLUSH(ah); 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_ci val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff; 3388c2ecf20Sopenharmony_ci val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4); 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci return ath9k_hw_reverse_bits(val, 8); 3418c2ecf20Sopenharmony_ci} 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ciint ar9002_hw_rf_claim(struct ath_hw *ah) 3448c2ecf20Sopenharmony_ci{ 3458c2ecf20Sopenharmony_ci u32 val; 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY(0), 0x00000007); 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_ci val = ar9002_hw_get_radiorev(ah); 3508c2ecf20Sopenharmony_ci switch (val & AR_RADIO_SREV_MAJOR) { 3518c2ecf20Sopenharmony_ci case 0: 3528c2ecf20Sopenharmony_ci val = AR_RAD5133_SREV_MAJOR; 3538c2ecf20Sopenharmony_ci break; 3548c2ecf20Sopenharmony_ci case AR_RAD5133_SREV_MAJOR: 3558c2ecf20Sopenharmony_ci case AR_RAD5122_SREV_MAJOR: 3568c2ecf20Sopenharmony_ci case AR_RAD2133_SREV_MAJOR: 3578c2ecf20Sopenharmony_ci case AR_RAD2122_SREV_MAJOR: 3588c2ecf20Sopenharmony_ci break; 3598c2ecf20Sopenharmony_ci default: 3608c2ecf20Sopenharmony_ci ath_err(ath9k_hw_common(ah), 3618c2ecf20Sopenharmony_ci "Radio Chip Rev 0x%02X not supported\n", 3628c2ecf20Sopenharmony_ci val & AR_RADIO_SREV_MAJOR); 3638c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 3648c2ecf20Sopenharmony_ci } 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ci ah->hw_version.analog5GhzRev = val; 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci return 0; 3698c2ecf20Sopenharmony_ci} 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_civoid ar9002_hw_enable_async_fifo(struct ath_hw *ah) 3728c2ecf20Sopenharmony_ci{ 3738c2ecf20Sopenharmony_ci if (AR_SREV_9287_13_OR_LATER(ah)) { 3748c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3, 3758c2ecf20Sopenharmony_ci AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL); 3768c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO); 3778c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3, 3788c2ecf20Sopenharmony_ci AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET); 3798c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3, 3808c2ecf20Sopenharmony_ci AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET); 3818c2ecf20Sopenharmony_ci } 3828c2ecf20Sopenharmony_ci} 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_cistatic void ar9002_hw_init_hang_checks(struct ath_hw *ah) 3858c2ecf20Sopenharmony_ci{ 3868c2ecf20Sopenharmony_ci if (AR_SREV_9100(ah) || AR_SREV_9160(ah)) { 3878c2ecf20Sopenharmony_ci ah->config.hw_hang_checks |= HW_BB_RIFS_HANG; 3888c2ecf20Sopenharmony_ci ah->config.hw_hang_checks |= HW_BB_DFS_HANG; 3898c2ecf20Sopenharmony_ci } 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci if (AR_SREV_9280(ah)) 3928c2ecf20Sopenharmony_ci ah->config.hw_hang_checks |= HW_BB_RX_CLEAR_STUCK_HANG; 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_ci if (AR_SREV_5416(ah) || AR_SREV_9100(ah) || AR_SREV_9160(ah)) 3958c2ecf20Sopenharmony_ci ah->config.hw_hang_checks |= HW_MAC_HANG; 3968c2ecf20Sopenharmony_ci} 3978c2ecf20Sopenharmony_ci 3988c2ecf20Sopenharmony_ci/* Sets up the AR5008/AR9001/AR9002 hardware familiy callbacks */ 3998c2ecf20Sopenharmony_ciint ar9002_hw_attach_ops(struct ath_hw *ah) 4008c2ecf20Sopenharmony_ci{ 4018c2ecf20Sopenharmony_ci struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah); 4028c2ecf20Sopenharmony_ci struct ath_hw_ops *ops = ath9k_hw_ops(ah); 4038c2ecf20Sopenharmony_ci int ret; 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ci ret = ar9002_hw_init_mode_regs(ah); 4068c2ecf20Sopenharmony_ci if (ret) 4078c2ecf20Sopenharmony_ci return ret; 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_ci priv_ops->init_mode_gain_regs = ar9002_hw_init_mode_gain_regs; 4108c2ecf20Sopenharmony_ci priv_ops->init_hang_checks = ar9002_hw_init_hang_checks; 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ci ops->config_pci_powersave = ar9002_hw_configpcipowersave; 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_ci ret = ar5008_hw_attach_phy_ops(ah); 4158c2ecf20Sopenharmony_ci if (ret) 4168c2ecf20Sopenharmony_ci return ret; 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_ci if (AR_SREV_9280_20_OR_LATER(ah)) 4198c2ecf20Sopenharmony_ci ar9002_hw_attach_phy_ops(ah); 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci ar9002_hw_attach_calib_ops(ah); 4228c2ecf20Sopenharmony_ci ar9002_hw_attach_mac_ops(ah); 4238c2ecf20Sopenharmony_ci return 0; 4248c2ecf20Sopenharmony_ci} 4258c2ecf20Sopenharmony_ci 4268c2ecf20Sopenharmony_civoid ar9002_hw_load_ani_reg(struct ath_hw *ah, struct ath9k_channel *chan) 4278c2ecf20Sopenharmony_ci{ 4288c2ecf20Sopenharmony_ci u32 modesIndex; 4298c2ecf20Sopenharmony_ci int i; 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci if (IS_CHAN_5GHZ(chan)) 4328c2ecf20Sopenharmony_ci modesIndex = IS_CHAN_HT40(chan) ? 2 : 1; 4338c2ecf20Sopenharmony_ci else 4348c2ecf20Sopenharmony_ci modesIndex = IS_CHAN_HT40(chan) ? 3 : 4; 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ci ENABLE_REGWRITE_BUFFER(ah); 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ci for (i = 0; i < ah->iniModes_9271_ANI_reg.ia_rows; i++) { 4398c2ecf20Sopenharmony_ci u32 reg = INI_RA(&ah->iniModes_9271_ANI_reg, i, 0); 4408c2ecf20Sopenharmony_ci u32 val = INI_RA(&ah->iniModes_9271_ANI_reg, i, modesIndex); 4418c2ecf20Sopenharmony_ci u32 val_orig; 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci if (reg == AR_PHY_CCK_DETECT) { 4448c2ecf20Sopenharmony_ci val_orig = REG_READ(ah, reg); 4458c2ecf20Sopenharmony_ci val &= AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK; 4468c2ecf20Sopenharmony_ci val_orig &= ~AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK; 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci REG_WRITE(ah, reg, val|val_orig); 4498c2ecf20Sopenharmony_ci } else 4508c2ecf20Sopenharmony_ci REG_WRITE(ah, reg, val); 4518c2ecf20Sopenharmony_ci } 4528c2ecf20Sopenharmony_ci 4538c2ecf20Sopenharmony_ci REGWRITE_BUFFER_FLUSH(ah); 4548c2ecf20Sopenharmony_ci} 455