18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2015 Qualcomm Atheros 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 "ar9003_mci.h" 208c2ecf20Sopenharmony_ci#include "ar9003_aic.h" 218c2ecf20Sopenharmony_ci#include "ar9003_phy.h" 228c2ecf20Sopenharmony_ci#include "reg_aic.h" 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_cistatic const u8 com_att_db_table[ATH_AIC_MAX_COM_ATT_DB_TABLE] = { 258c2ecf20Sopenharmony_ci 0, 3, 9, 15, 21, 27 268c2ecf20Sopenharmony_ci}; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_cistatic const u16 aic_lin_table[ATH_AIC_MAX_AIC_LIN_TABLE] = { 298c2ecf20Sopenharmony_ci 8191, 7300, 6506, 5799, 5168, 4606, 4105, 3659, 308c2ecf20Sopenharmony_ci 3261, 2906, 2590, 2309, 2057, 1834, 1634, 1457, 318c2ecf20Sopenharmony_ci 1298, 1157, 1031, 919, 819, 730, 651, 580, 328c2ecf20Sopenharmony_ci 517, 461, 411, 366, 326, 291, 259, 231, 338c2ecf20Sopenharmony_ci 206, 183, 163, 146, 130, 116, 103, 92, 348c2ecf20Sopenharmony_ci 82, 73, 65, 58, 52, 46, 41, 37, 358c2ecf20Sopenharmony_ci 33, 29, 26, 23, 21, 18, 16, 15, 368c2ecf20Sopenharmony_ci 13, 12, 10, 9, 8, 7, 7, 6, 378c2ecf20Sopenharmony_ci 5, 5, 4, 4, 3 388c2ecf20Sopenharmony_ci}; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cistatic bool ar9003_hw_is_aic_enabled(struct ath_hw *ah) 418c2ecf20Sopenharmony_ci{ 428c2ecf20Sopenharmony_ci struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci /* 458c2ecf20Sopenharmony_ci * Disable AIC for now, until we have all the 468c2ecf20Sopenharmony_ci * HW code and the driver-layer support ready. 478c2ecf20Sopenharmony_ci */ 488c2ecf20Sopenharmony_ci return false; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci if (mci_hw->config & ATH_MCI_CONFIG_DISABLE_AIC) 518c2ecf20Sopenharmony_ci return false; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci return true; 548c2ecf20Sopenharmony_ci} 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_cistatic int16_t ar9003_aic_find_valid(bool *cal_sram_valid, 578c2ecf20Sopenharmony_ci bool dir, u8 index) 588c2ecf20Sopenharmony_ci{ 598c2ecf20Sopenharmony_ci int16_t i; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci if (dir) { 628c2ecf20Sopenharmony_ci for (i = index + 1; i < ATH_AIC_MAX_BT_CHANNEL; i++) { 638c2ecf20Sopenharmony_ci if (cal_sram_valid[i]) 648c2ecf20Sopenharmony_ci break; 658c2ecf20Sopenharmony_ci } 668c2ecf20Sopenharmony_ci } else { 678c2ecf20Sopenharmony_ci for (i = index - 1; i >= 0; i--) { 688c2ecf20Sopenharmony_ci if (cal_sram_valid[i]) 698c2ecf20Sopenharmony_ci break; 708c2ecf20Sopenharmony_ci } 718c2ecf20Sopenharmony_ci } 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci if ((i >= ATH_AIC_MAX_BT_CHANNEL) || (i < 0)) 748c2ecf20Sopenharmony_ci i = -1; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci return i; 778c2ecf20Sopenharmony_ci} 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci/* 808c2ecf20Sopenharmony_ci * type 0: aic_lin_table, 1: com_att_db_table 818c2ecf20Sopenharmony_ci */ 828c2ecf20Sopenharmony_cistatic int16_t ar9003_aic_find_index(u8 type, int16_t value) 838c2ecf20Sopenharmony_ci{ 848c2ecf20Sopenharmony_ci int16_t i = -1; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci if (type == 0) { 878c2ecf20Sopenharmony_ci for (i = ATH_AIC_MAX_AIC_LIN_TABLE - 1; i >= 0; i--) { 888c2ecf20Sopenharmony_ci if (aic_lin_table[i] >= value) 898c2ecf20Sopenharmony_ci break; 908c2ecf20Sopenharmony_ci } 918c2ecf20Sopenharmony_ci } else if (type == 1) { 928c2ecf20Sopenharmony_ci for (i = 0; i < ATH_AIC_MAX_COM_ATT_DB_TABLE; i++) { 938c2ecf20Sopenharmony_ci if (com_att_db_table[i] > value) { 948c2ecf20Sopenharmony_ci i--; 958c2ecf20Sopenharmony_ci break; 968c2ecf20Sopenharmony_ci } 978c2ecf20Sopenharmony_ci } 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci if (i >= ATH_AIC_MAX_COM_ATT_DB_TABLE) 1008c2ecf20Sopenharmony_ci i = -1; 1018c2ecf20Sopenharmony_ci } 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci return i; 1048c2ecf20Sopenharmony_ci} 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_cistatic void ar9003_aic_gain_table(struct ath_hw *ah) 1078c2ecf20Sopenharmony_ci{ 1088c2ecf20Sopenharmony_ci u32 aic_atten_word[19], i; 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci /* Config LNA gain difference */ 1118c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_BT_COEX_4, 0x2c200a00); 1128c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_BT_COEX_5, 0x5c4e4438); 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci /* Program gain table */ 1158c2ecf20Sopenharmony_ci aic_atten_word[0] = (0x1 & 0xf) << 14 | (0x1f & 0x1f) << 9 | (0x0 & 0xf) << 5 | 1168c2ecf20Sopenharmony_ci (0x1f & 0x1f); /* -01 dB: 4'd1, 5'd31, 00 dB: 4'd0, 5'd31 */ 1178c2ecf20Sopenharmony_ci aic_atten_word[1] = (0x3 & 0xf) << 14 | (0x1f & 0x1f) << 9 | (0x2 & 0xf) << 5 | 1188c2ecf20Sopenharmony_ci (0x1f & 0x1f); /* -03 dB: 4'd3, 5'd31, -02 dB: 4'd2, 5'd31 */ 1198c2ecf20Sopenharmony_ci aic_atten_word[2] = (0x5 & 0xf) << 14 | (0x1f & 0x1f) << 9 | (0x4 & 0xf) << 5 | 1208c2ecf20Sopenharmony_ci (0x1f & 0x1f); /* -05 dB: 4'd5, 5'd31, -04 dB: 4'd4, 5'd31 */ 1218c2ecf20Sopenharmony_ci aic_atten_word[3] = (0x1 & 0xf) << 14 | (0x1e & 0x1f) << 9 | (0x0 & 0xf) << 5 | 1228c2ecf20Sopenharmony_ci (0x1e & 0x1f); /* -07 dB: 4'd1, 5'd30, -06 dB: 4'd0, 5'd30 */ 1238c2ecf20Sopenharmony_ci aic_atten_word[4] = (0x3 & 0xf) << 14 | (0x1e & 0x1f) << 9 | (0x2 & 0xf) << 5 | 1248c2ecf20Sopenharmony_ci (0x1e & 0x1f); /* -09 dB: 4'd3, 5'd30, -08 dB: 4'd2, 5'd30 */ 1258c2ecf20Sopenharmony_ci aic_atten_word[5] = (0x5 & 0xf) << 14 | (0x1e & 0x1f) << 9 | (0x4 & 0xf) << 5 | 1268c2ecf20Sopenharmony_ci (0x1e & 0x1f); /* -11 dB: 4'd5, 5'd30, -10 dB: 4'd4, 5'd30 */ 1278c2ecf20Sopenharmony_ci aic_atten_word[6] = (0x1 & 0xf) << 14 | (0xf & 0x1f) << 9 | (0x0 & 0xf) << 5 | 1288c2ecf20Sopenharmony_ci (0xf & 0x1f); /* -13 dB: 4'd1, 5'd15, -12 dB: 4'd0, 5'd15 */ 1298c2ecf20Sopenharmony_ci aic_atten_word[7] = (0x3 & 0xf) << 14 | (0xf & 0x1f) << 9 | (0x2 & 0xf) << 5 | 1308c2ecf20Sopenharmony_ci (0xf & 0x1f); /* -15 dB: 4'd3, 5'd15, -14 dB: 4'd2, 5'd15 */ 1318c2ecf20Sopenharmony_ci aic_atten_word[8] = (0x5 & 0xf) << 14 | (0xf & 0x1f) << 9 | (0x4 & 0xf) << 5 | 1328c2ecf20Sopenharmony_ci (0xf & 0x1f); /* -17 dB: 4'd5, 5'd15, -16 dB: 4'd4, 5'd15 */ 1338c2ecf20Sopenharmony_ci aic_atten_word[9] = (0x1 & 0xf) << 14 | (0x7 & 0x1f) << 9 | (0x0 & 0xf) << 5 | 1348c2ecf20Sopenharmony_ci (0x7 & 0x1f); /* -19 dB: 4'd1, 5'd07, -18 dB: 4'd0, 5'd07 */ 1358c2ecf20Sopenharmony_ci aic_atten_word[10] = (0x3 & 0xf) << 14 | (0x7 & 0x1f) << 9 | (0x2 & 0xf) << 5 | 1368c2ecf20Sopenharmony_ci (0x7 & 0x1f); /* -21 dB: 4'd3, 5'd07, -20 dB: 4'd2, 5'd07 */ 1378c2ecf20Sopenharmony_ci aic_atten_word[11] = (0x5 & 0xf) << 14 | (0x7 & 0x1f) << 9 | (0x4 & 0xf) << 5 | 1388c2ecf20Sopenharmony_ci (0x7 & 0x1f); /* -23 dB: 4'd5, 5'd07, -22 dB: 4'd4, 5'd07 */ 1398c2ecf20Sopenharmony_ci aic_atten_word[12] = (0x7 & 0xf) << 14 | (0x7 & 0x1f) << 9 | (0x6 & 0xf) << 5 | 1408c2ecf20Sopenharmony_ci (0x7 & 0x1f); /* -25 dB: 4'd7, 5'd07, -24 dB: 4'd6, 5'd07 */ 1418c2ecf20Sopenharmony_ci aic_atten_word[13] = (0x3 & 0xf) << 14 | (0x3 & 0x1f) << 9 | (0x2 & 0xf) << 5 | 1428c2ecf20Sopenharmony_ci (0x3 & 0x1f); /* -27 dB: 4'd3, 5'd03, -26 dB: 4'd2, 5'd03 */ 1438c2ecf20Sopenharmony_ci aic_atten_word[14] = (0x5 & 0xf) << 14 | (0x3 & 0x1f) << 9 | (0x4 & 0xf) << 5 | 1448c2ecf20Sopenharmony_ci (0x3 & 0x1f); /* -29 dB: 4'd5, 5'd03, -28 dB: 4'd4, 5'd03 */ 1458c2ecf20Sopenharmony_ci aic_atten_word[15] = (0x1 & 0xf) << 14 | (0x1 & 0x1f) << 9 | (0x0 & 0xf) << 5 | 1468c2ecf20Sopenharmony_ci (0x1 & 0x1f); /* -31 dB: 4'd1, 5'd01, -30 dB: 4'd0, 5'd01 */ 1478c2ecf20Sopenharmony_ci aic_atten_word[16] = (0x3 & 0xf) << 14 | (0x1 & 0x1f) << 9 | (0x2 & 0xf) << 5 | 1488c2ecf20Sopenharmony_ci (0x1 & 0x1f); /* -33 dB: 4'd3, 5'd01, -32 dB: 4'd2, 5'd01 */ 1498c2ecf20Sopenharmony_ci aic_atten_word[17] = (0x5 & 0xf) << 14 | (0x1 & 0x1f) << 9 | (0x4 & 0xf) << 5 | 1508c2ecf20Sopenharmony_ci (0x1 & 0x1f); /* -35 dB: 4'd5, 5'd01, -34 dB: 4'd4, 5'd01 */ 1518c2ecf20Sopenharmony_ci aic_atten_word[18] = (0x7 & 0xf) << 14 | (0x1 & 0x1f) << 9 | (0x6 & 0xf) << 5 | 1528c2ecf20Sopenharmony_ci (0x1 & 0x1f); /* -37 dB: 4'd7, 5'd01, -36 dB: 4'd6, 5'd01 */ 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci /* Write to Gain table with auto increment enabled. */ 1558c2ecf20Sopenharmony_ci REG_WRITE(ah, (AR_PHY_AIC_SRAM_ADDR_B0 + 0x3000), 1568c2ecf20Sopenharmony_ci (ATH_AIC_SRAM_AUTO_INCREMENT | 1578c2ecf20Sopenharmony_ci ATH_AIC_SRAM_GAIN_TABLE_OFFSET)); 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci for (i = 0; i < 19; i++) { 1608c2ecf20Sopenharmony_ci REG_WRITE(ah, (AR_PHY_AIC_SRAM_DATA_B0 + 0x3000), 1618c2ecf20Sopenharmony_ci aic_atten_word[i]); 1628c2ecf20Sopenharmony_ci } 1638c2ecf20Sopenharmony_ci} 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_cistatic u8 ar9003_aic_cal_start(struct ath_hw *ah, u8 min_valid_count) 1668c2ecf20Sopenharmony_ci{ 1678c2ecf20Sopenharmony_ci struct ath9k_hw_aic *aic = &ah->btcoex_hw.aic; 1688c2ecf20Sopenharmony_ci int i; 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci /* Write to Gain table with auto increment enabled. */ 1718c2ecf20Sopenharmony_ci REG_WRITE(ah, (AR_PHY_AIC_SRAM_ADDR_B0 + 0x3000), 1728c2ecf20Sopenharmony_ci (ATH_AIC_SRAM_AUTO_INCREMENT | 1738c2ecf20Sopenharmony_ci ATH_AIC_SRAM_CAL_OFFSET)); 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci for (i = 0; i < ATH_AIC_MAX_BT_CHANNEL; i++) { 1768c2ecf20Sopenharmony_ci REG_WRITE(ah, (AR_PHY_AIC_SRAM_DATA_B0 + 0x3000), 0); 1778c2ecf20Sopenharmony_ci aic->aic_sram[i] = 0; 1788c2ecf20Sopenharmony_ci } 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_AIC_CTRL_0_B0, 1818c2ecf20Sopenharmony_ci (SM(0, AR_PHY_AIC_MON_ENABLE) | 1828c2ecf20Sopenharmony_ci SM(127, AR_PHY_AIC_CAL_MAX_HOP_COUNT) | 1838c2ecf20Sopenharmony_ci SM(min_valid_count, AR_PHY_AIC_CAL_MIN_VALID_COUNT) | 1848c2ecf20Sopenharmony_ci SM(37, AR_PHY_AIC_F_WLAN) | 1858c2ecf20Sopenharmony_ci SM(1, AR_PHY_AIC_CAL_CH_VALID_RESET) | 1868c2ecf20Sopenharmony_ci SM(0, AR_PHY_AIC_CAL_ENABLE) | 1878c2ecf20Sopenharmony_ci SM(0x40, AR_PHY_AIC_BTTX_PWR_THR) | 1888c2ecf20Sopenharmony_ci SM(0, AR_PHY_AIC_ENABLE))); 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_AIC_CTRL_0_B1, 1918c2ecf20Sopenharmony_ci (SM(0, AR_PHY_AIC_MON_ENABLE) | 1928c2ecf20Sopenharmony_ci SM(1, AR_PHY_AIC_CAL_CH_VALID_RESET) | 1938c2ecf20Sopenharmony_ci SM(0, AR_PHY_AIC_CAL_ENABLE) | 1948c2ecf20Sopenharmony_ci SM(0x40, AR_PHY_AIC_BTTX_PWR_THR) | 1958c2ecf20Sopenharmony_ci SM(0, AR_PHY_AIC_ENABLE))); 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_AIC_CTRL_1_B0, 1988c2ecf20Sopenharmony_ci (SM(8, AR_PHY_AIC_CAL_BT_REF_DELAY) | 1998c2ecf20Sopenharmony_ci SM(0, AR_PHY_AIC_BT_IDLE_CFG) | 2008c2ecf20Sopenharmony_ci SM(1, AR_PHY_AIC_STDBY_COND) | 2018c2ecf20Sopenharmony_ci SM(37, AR_PHY_AIC_STDBY_ROT_ATT_DB) | 2028c2ecf20Sopenharmony_ci SM(5, AR_PHY_AIC_STDBY_COM_ATT_DB) | 2038c2ecf20Sopenharmony_ci SM(15, AR_PHY_AIC_RSSI_MAX) | 2048c2ecf20Sopenharmony_ci SM(0, AR_PHY_AIC_RSSI_MIN))); 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_AIC_CTRL_1_B1, 2078c2ecf20Sopenharmony_ci (SM(15, AR_PHY_AIC_RSSI_MAX) | 2088c2ecf20Sopenharmony_ci SM(0, AR_PHY_AIC_RSSI_MIN))); 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_AIC_CTRL_2_B0, 2118c2ecf20Sopenharmony_ci (SM(44, AR_PHY_AIC_RADIO_DELAY) | 2128c2ecf20Sopenharmony_ci SM(8, AR_PHY_AIC_CAL_STEP_SIZE_CORR) | 2138c2ecf20Sopenharmony_ci SM(12, AR_PHY_AIC_CAL_ROT_IDX_CORR) | 2148c2ecf20Sopenharmony_ci SM(2, AR_PHY_AIC_CAL_CONV_CHECK_FACTOR) | 2158c2ecf20Sopenharmony_ci SM(5, AR_PHY_AIC_ROT_IDX_COUNT_MAX) | 2168c2ecf20Sopenharmony_ci SM(0, AR_PHY_AIC_CAL_SYNTH_TOGGLE) | 2178c2ecf20Sopenharmony_ci SM(0, AR_PHY_AIC_CAL_SYNTH_AFTER_BTRX) | 2188c2ecf20Sopenharmony_ci SM(200, AR_PHY_AIC_CAL_SYNTH_SETTLING))); 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_AIC_CTRL_3_B0, 2218c2ecf20Sopenharmony_ci (SM(2, AR_PHY_AIC_MON_MAX_HOP_COUNT) | 2228c2ecf20Sopenharmony_ci SM(1, AR_PHY_AIC_MON_MIN_STALE_COUNT) | 2238c2ecf20Sopenharmony_ci SM(1, AR_PHY_AIC_MON_PWR_EST_LONG) | 2248c2ecf20Sopenharmony_ci SM(2, AR_PHY_AIC_MON_PD_TALLY_SCALING) | 2258c2ecf20Sopenharmony_ci SM(10, AR_PHY_AIC_MON_PERF_THR) | 2268c2ecf20Sopenharmony_ci SM(2, AR_PHY_AIC_CAL_TARGET_MAG_SETTING) | 2278c2ecf20Sopenharmony_ci SM(1, AR_PHY_AIC_CAL_PERF_CHECK_FACTOR) | 2288c2ecf20Sopenharmony_ci SM(1, AR_PHY_AIC_CAL_PWR_EST_LONG))); 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_AIC_CTRL_4_B0, 2318c2ecf20Sopenharmony_ci (SM(2, AR_PHY_AIC_CAL_ROT_ATT_DB_EST_ISO) | 2328c2ecf20Sopenharmony_ci SM(3, AR_PHY_AIC_CAL_COM_ATT_DB_EST_ISO) | 2338c2ecf20Sopenharmony_ci SM(0, AR_PHY_AIC_CAL_ISO_EST_INIT_SETTING) | 2348c2ecf20Sopenharmony_ci SM(2, AR_PHY_AIC_CAL_COM_ATT_DB_BACKOFF) | 2358c2ecf20Sopenharmony_ci SM(1, AR_PHY_AIC_CAL_COM_ATT_DB_FIXED))); 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_AIC_CTRL_4_B1, 2388c2ecf20Sopenharmony_ci (SM(2, AR_PHY_AIC_CAL_ROT_ATT_DB_EST_ISO) | 2398c2ecf20Sopenharmony_ci SM(3, AR_PHY_AIC_CAL_COM_ATT_DB_EST_ISO) | 2408c2ecf20Sopenharmony_ci SM(0, AR_PHY_AIC_CAL_ISO_EST_INIT_SETTING) | 2418c2ecf20Sopenharmony_ci SM(2, AR_PHY_AIC_CAL_COM_ATT_DB_BACKOFF) | 2428c2ecf20Sopenharmony_ci SM(1, AR_PHY_AIC_CAL_COM_ATT_DB_FIXED))); 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci ar9003_aic_gain_table(ah); 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_ci /* Need to enable AIC reference signal in BT modem. */ 2478c2ecf20Sopenharmony_ci REG_WRITE(ah, ATH_AIC_BT_JUPITER_CTRL, 2488c2ecf20Sopenharmony_ci (REG_READ(ah, ATH_AIC_BT_JUPITER_CTRL) | 2498c2ecf20Sopenharmony_ci ATH_AIC_BT_AIC_ENABLE)); 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci aic->aic_cal_start_time = REG_READ(ah, AR_TSF_L32); 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci /* Start calibration */ 2548c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_PHY_AIC_CTRL_0_B1, AR_PHY_AIC_CAL_ENABLE); 2558c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_AIC_CTRL_0_B1, AR_PHY_AIC_CAL_CH_VALID_RESET); 2568c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_AIC_CTRL_0_B1, AR_PHY_AIC_CAL_ENABLE); 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci aic->aic_caled_chan = 0; 2598c2ecf20Sopenharmony_ci aic->aic_cal_state = AIC_CAL_STATE_STARTED; 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_ci return aic->aic_cal_state; 2628c2ecf20Sopenharmony_ci} 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_cistatic bool ar9003_aic_cal_post_process(struct ath_hw *ah) 2658c2ecf20Sopenharmony_ci{ 2668c2ecf20Sopenharmony_ci struct ath9k_hw_aic *aic = &ah->btcoex_hw.aic; 2678c2ecf20Sopenharmony_ci bool cal_sram_valid[ATH_AIC_MAX_BT_CHANNEL]; 2688c2ecf20Sopenharmony_ci struct ath_aic_out_info aic_sram[ATH_AIC_MAX_BT_CHANNEL]; 2698c2ecf20Sopenharmony_ci u32 dir_path_gain_idx, quad_path_gain_idx, value; 2708c2ecf20Sopenharmony_ci u32 fixed_com_att_db; 2718c2ecf20Sopenharmony_ci int8_t dir_path_sign, quad_path_sign; 2728c2ecf20Sopenharmony_ci int16_t i; 2738c2ecf20Sopenharmony_ci bool ret = true; 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ci memset(&cal_sram_valid, 0, sizeof(cal_sram_valid)); 2768c2ecf20Sopenharmony_ci memset(&aic_sram, 0, sizeof(aic_sram)); 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci for (i = 0; i < ATH_AIC_MAX_BT_CHANNEL; i++) { 2798c2ecf20Sopenharmony_ci struct ath_aic_sram_info sram; 2808c2ecf20Sopenharmony_ci value = aic->aic_sram[i]; 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci cal_sram_valid[i] = sram.valid = 2838c2ecf20Sopenharmony_ci MS(value, AR_PHY_AIC_SRAM_VALID); 2848c2ecf20Sopenharmony_ci sram.rot_quad_att_db = 2858c2ecf20Sopenharmony_ci MS(value, AR_PHY_AIC_SRAM_ROT_QUAD_ATT_DB); 2868c2ecf20Sopenharmony_ci sram.vga_quad_sign = 2878c2ecf20Sopenharmony_ci MS(value, AR_PHY_AIC_SRAM_VGA_QUAD_SIGN); 2888c2ecf20Sopenharmony_ci sram.rot_dir_att_db = 2898c2ecf20Sopenharmony_ci MS(value, AR_PHY_AIC_SRAM_ROT_DIR_ATT_DB); 2908c2ecf20Sopenharmony_ci sram.vga_dir_sign = 2918c2ecf20Sopenharmony_ci MS(value, AR_PHY_AIC_SRAM_VGA_DIR_SIGN); 2928c2ecf20Sopenharmony_ci sram.com_att_6db = 2938c2ecf20Sopenharmony_ci MS(value, AR_PHY_AIC_SRAM_COM_ATT_6DB); 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci if (sram.valid) { 2968c2ecf20Sopenharmony_ci dir_path_gain_idx = sram.rot_dir_att_db + 2978c2ecf20Sopenharmony_ci com_att_db_table[sram.com_att_6db]; 2988c2ecf20Sopenharmony_ci quad_path_gain_idx = sram.rot_quad_att_db + 2998c2ecf20Sopenharmony_ci com_att_db_table[sram.com_att_6db]; 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_ci dir_path_sign = (sram.vga_dir_sign) ? 1 : -1; 3028c2ecf20Sopenharmony_ci quad_path_sign = (sram.vga_quad_sign) ? 1 : -1; 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci aic_sram[i].dir_path_gain_lin = dir_path_sign * 3058c2ecf20Sopenharmony_ci aic_lin_table[dir_path_gain_idx]; 3068c2ecf20Sopenharmony_ci aic_sram[i].quad_path_gain_lin = quad_path_sign * 3078c2ecf20Sopenharmony_ci aic_lin_table[quad_path_gain_idx]; 3088c2ecf20Sopenharmony_ci } 3098c2ecf20Sopenharmony_ci } 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci for (i = 0; i < ATH_AIC_MAX_BT_CHANNEL; i++) { 3128c2ecf20Sopenharmony_ci int16_t start_idx, end_idx; 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_ci if (cal_sram_valid[i]) 3158c2ecf20Sopenharmony_ci continue; 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_ci start_idx = ar9003_aic_find_valid(cal_sram_valid, 0, i); 3188c2ecf20Sopenharmony_ci end_idx = ar9003_aic_find_valid(cal_sram_valid, 1, i); 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ci if (start_idx < 0) { 3218c2ecf20Sopenharmony_ci /* extrapolation */ 3228c2ecf20Sopenharmony_ci start_idx = end_idx; 3238c2ecf20Sopenharmony_ci end_idx = ar9003_aic_find_valid(cal_sram_valid, 1, start_idx); 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci if (end_idx < 0) { 3268c2ecf20Sopenharmony_ci ret = false; 3278c2ecf20Sopenharmony_ci break; 3288c2ecf20Sopenharmony_ci } 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci aic_sram[i].dir_path_gain_lin = 3318c2ecf20Sopenharmony_ci ((aic_sram[start_idx].dir_path_gain_lin - 3328c2ecf20Sopenharmony_ci aic_sram[end_idx].dir_path_gain_lin) * 3338c2ecf20Sopenharmony_ci (start_idx - i) + ((end_idx - i) >> 1)) / 3348c2ecf20Sopenharmony_ci (end_idx - i) + 3358c2ecf20Sopenharmony_ci aic_sram[start_idx].dir_path_gain_lin; 3368c2ecf20Sopenharmony_ci aic_sram[i].quad_path_gain_lin = 3378c2ecf20Sopenharmony_ci ((aic_sram[start_idx].quad_path_gain_lin - 3388c2ecf20Sopenharmony_ci aic_sram[end_idx].quad_path_gain_lin) * 3398c2ecf20Sopenharmony_ci (start_idx - i) + ((end_idx - i) >> 1)) / 3408c2ecf20Sopenharmony_ci (end_idx - i) + 3418c2ecf20Sopenharmony_ci aic_sram[start_idx].quad_path_gain_lin; 3428c2ecf20Sopenharmony_ci } 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_ci if (end_idx < 0) { 3458c2ecf20Sopenharmony_ci /* extrapolation */ 3468c2ecf20Sopenharmony_ci end_idx = ar9003_aic_find_valid(cal_sram_valid, 0, start_idx); 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci if (end_idx < 0) { 3498c2ecf20Sopenharmony_ci ret = false; 3508c2ecf20Sopenharmony_ci break; 3518c2ecf20Sopenharmony_ci } 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci aic_sram[i].dir_path_gain_lin = 3548c2ecf20Sopenharmony_ci ((aic_sram[start_idx].dir_path_gain_lin - 3558c2ecf20Sopenharmony_ci aic_sram[end_idx].dir_path_gain_lin) * 3568c2ecf20Sopenharmony_ci (i - start_idx) + ((start_idx - end_idx) >> 1)) / 3578c2ecf20Sopenharmony_ci (start_idx - end_idx) + 3588c2ecf20Sopenharmony_ci aic_sram[start_idx].dir_path_gain_lin; 3598c2ecf20Sopenharmony_ci aic_sram[i].quad_path_gain_lin = 3608c2ecf20Sopenharmony_ci ((aic_sram[start_idx].quad_path_gain_lin - 3618c2ecf20Sopenharmony_ci aic_sram[end_idx].quad_path_gain_lin) * 3628c2ecf20Sopenharmony_ci (i - start_idx) + ((start_idx - end_idx) >> 1)) / 3638c2ecf20Sopenharmony_ci (start_idx - end_idx) + 3648c2ecf20Sopenharmony_ci aic_sram[start_idx].quad_path_gain_lin; 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ci } else if (start_idx >= 0){ 3678c2ecf20Sopenharmony_ci /* interpolation */ 3688c2ecf20Sopenharmony_ci aic_sram[i].dir_path_gain_lin = 3698c2ecf20Sopenharmony_ci (((end_idx - i) * aic_sram[start_idx].dir_path_gain_lin) + 3708c2ecf20Sopenharmony_ci ((i - start_idx) * aic_sram[end_idx].dir_path_gain_lin) + 3718c2ecf20Sopenharmony_ci ((end_idx - start_idx) >> 1)) / 3728c2ecf20Sopenharmony_ci (end_idx - start_idx); 3738c2ecf20Sopenharmony_ci aic_sram[i].quad_path_gain_lin = 3748c2ecf20Sopenharmony_ci (((end_idx - i) * aic_sram[start_idx].quad_path_gain_lin) + 3758c2ecf20Sopenharmony_ci ((i - start_idx) * aic_sram[end_idx].quad_path_gain_lin) + 3768c2ecf20Sopenharmony_ci ((end_idx - start_idx) >> 1))/ 3778c2ecf20Sopenharmony_ci (end_idx - start_idx); 3788c2ecf20Sopenharmony_ci } 3798c2ecf20Sopenharmony_ci } 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ci /* From dir/quad_path_gain_lin to sram. */ 3828c2ecf20Sopenharmony_ci i = ar9003_aic_find_valid(cal_sram_valid, 1, 0); 3838c2ecf20Sopenharmony_ci if (i < 0) { 3848c2ecf20Sopenharmony_ci i = 0; 3858c2ecf20Sopenharmony_ci ret = false; 3868c2ecf20Sopenharmony_ci } 3878c2ecf20Sopenharmony_ci fixed_com_att_db = com_att_db_table[MS(aic->aic_sram[i], 3888c2ecf20Sopenharmony_ci AR_PHY_AIC_SRAM_COM_ATT_6DB)]; 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci for (i = 0; i < ATH_AIC_MAX_BT_CHANNEL; i++) { 3918c2ecf20Sopenharmony_ci int16_t rot_dir_path_att_db, rot_quad_path_att_db; 3928c2ecf20Sopenharmony_ci struct ath_aic_sram_info sram; 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_ci sram.vga_dir_sign = 3958c2ecf20Sopenharmony_ci (aic_sram[i].dir_path_gain_lin >= 0) ? 1 : 0; 3968c2ecf20Sopenharmony_ci sram.vga_quad_sign = 3978c2ecf20Sopenharmony_ci (aic_sram[i].quad_path_gain_lin >= 0) ? 1 : 0; 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ci rot_dir_path_att_db = 4008c2ecf20Sopenharmony_ci ar9003_aic_find_index(0, abs(aic_sram[i].dir_path_gain_lin)) - 4018c2ecf20Sopenharmony_ci fixed_com_att_db; 4028c2ecf20Sopenharmony_ci rot_quad_path_att_db = 4038c2ecf20Sopenharmony_ci ar9003_aic_find_index(0, abs(aic_sram[i].quad_path_gain_lin)) - 4048c2ecf20Sopenharmony_ci fixed_com_att_db; 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci sram.com_att_6db = 4078c2ecf20Sopenharmony_ci ar9003_aic_find_index(1, fixed_com_att_db); 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_ci sram.valid = true; 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_ci sram.rot_dir_att_db = 4128c2ecf20Sopenharmony_ci min(max(rot_dir_path_att_db, 4138c2ecf20Sopenharmony_ci (int16_t)ATH_AIC_MIN_ROT_DIR_ATT_DB), 4148c2ecf20Sopenharmony_ci ATH_AIC_MAX_ROT_DIR_ATT_DB); 4158c2ecf20Sopenharmony_ci sram.rot_quad_att_db = 4168c2ecf20Sopenharmony_ci min(max(rot_quad_path_att_db, 4178c2ecf20Sopenharmony_ci (int16_t)ATH_AIC_MIN_ROT_QUAD_ATT_DB), 4188c2ecf20Sopenharmony_ci ATH_AIC_MAX_ROT_QUAD_ATT_DB); 4198c2ecf20Sopenharmony_ci 4208c2ecf20Sopenharmony_ci aic->aic_sram[i] = (SM(sram.vga_dir_sign, 4218c2ecf20Sopenharmony_ci AR_PHY_AIC_SRAM_VGA_DIR_SIGN) | 4228c2ecf20Sopenharmony_ci SM(sram.vga_quad_sign, 4238c2ecf20Sopenharmony_ci AR_PHY_AIC_SRAM_VGA_QUAD_SIGN) | 4248c2ecf20Sopenharmony_ci SM(sram.com_att_6db, 4258c2ecf20Sopenharmony_ci AR_PHY_AIC_SRAM_COM_ATT_6DB) | 4268c2ecf20Sopenharmony_ci SM(sram.valid, 4278c2ecf20Sopenharmony_ci AR_PHY_AIC_SRAM_VALID) | 4288c2ecf20Sopenharmony_ci SM(sram.rot_dir_att_db, 4298c2ecf20Sopenharmony_ci AR_PHY_AIC_SRAM_ROT_DIR_ATT_DB) | 4308c2ecf20Sopenharmony_ci SM(sram.rot_quad_att_db, 4318c2ecf20Sopenharmony_ci AR_PHY_AIC_SRAM_ROT_QUAD_ATT_DB)); 4328c2ecf20Sopenharmony_ci } 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ci return ret; 4358c2ecf20Sopenharmony_ci} 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_cistatic void ar9003_aic_cal_done(struct ath_hw *ah) 4388c2ecf20Sopenharmony_ci{ 4398c2ecf20Sopenharmony_ci struct ath9k_hw_aic *aic = &ah->btcoex_hw.aic; 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ci /* Disable AIC reference signal in BT modem. */ 4428c2ecf20Sopenharmony_ci REG_WRITE(ah, ATH_AIC_BT_JUPITER_CTRL, 4438c2ecf20Sopenharmony_ci (REG_READ(ah, ATH_AIC_BT_JUPITER_CTRL) & 4448c2ecf20Sopenharmony_ci ~ATH_AIC_BT_AIC_ENABLE)); 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ci if (ar9003_aic_cal_post_process(ah)) 4478c2ecf20Sopenharmony_ci aic->aic_cal_state = AIC_CAL_STATE_DONE; 4488c2ecf20Sopenharmony_ci else 4498c2ecf20Sopenharmony_ci aic->aic_cal_state = AIC_CAL_STATE_ERROR; 4508c2ecf20Sopenharmony_ci} 4518c2ecf20Sopenharmony_ci 4528c2ecf20Sopenharmony_cistatic u8 ar9003_aic_cal_continue(struct ath_hw *ah, bool cal_once) 4538c2ecf20Sopenharmony_ci{ 4548c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 4558c2ecf20Sopenharmony_ci struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci; 4568c2ecf20Sopenharmony_ci struct ath9k_hw_aic *aic = &ah->btcoex_hw.aic; 4578c2ecf20Sopenharmony_ci int i, num_chan; 4588c2ecf20Sopenharmony_ci 4598c2ecf20Sopenharmony_ci num_chan = MS(mci_hw->config, ATH_MCI_CONFIG_AIC_CAL_NUM_CHAN); 4608c2ecf20Sopenharmony_ci 4618c2ecf20Sopenharmony_ci if (!num_chan) { 4628c2ecf20Sopenharmony_ci aic->aic_cal_state = AIC_CAL_STATE_ERROR; 4638c2ecf20Sopenharmony_ci return aic->aic_cal_state; 4648c2ecf20Sopenharmony_ci } 4658c2ecf20Sopenharmony_ci 4668c2ecf20Sopenharmony_ci if (cal_once) { 4678c2ecf20Sopenharmony_ci for (i = 0; i < 10000; i++) { 4688c2ecf20Sopenharmony_ci if ((REG_READ(ah, AR_PHY_AIC_CTRL_0_B1) & 4698c2ecf20Sopenharmony_ci AR_PHY_AIC_CAL_ENABLE) == 0) 4708c2ecf20Sopenharmony_ci break; 4718c2ecf20Sopenharmony_ci 4728c2ecf20Sopenharmony_ci udelay(100); 4738c2ecf20Sopenharmony_ci } 4748c2ecf20Sopenharmony_ci } 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ci /* 4778c2ecf20Sopenharmony_ci * Use AR_PHY_AIC_CAL_ENABLE bit instead of AR_PHY_AIC_CAL_DONE. 4788c2ecf20Sopenharmony_ci * Sometimes CAL_DONE bit is not asserted. 4798c2ecf20Sopenharmony_ci */ 4808c2ecf20Sopenharmony_ci if ((REG_READ(ah, AR_PHY_AIC_CTRL_0_B1) & 4818c2ecf20Sopenharmony_ci AR_PHY_AIC_CAL_ENABLE) != 0) { 4828c2ecf20Sopenharmony_ci ath_dbg(common, MCI, "AIC cal is not done after 40ms"); 4838c2ecf20Sopenharmony_ci goto exit; 4848c2ecf20Sopenharmony_ci } 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_AIC_SRAM_ADDR_B1, 4878c2ecf20Sopenharmony_ci (ATH_AIC_SRAM_CAL_OFFSET | ATH_AIC_SRAM_AUTO_INCREMENT)); 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_ci for (i = 0; i < ATH_AIC_MAX_BT_CHANNEL; i++) { 4908c2ecf20Sopenharmony_ci u32 value; 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_ci value = REG_READ(ah, AR_PHY_AIC_SRAM_DATA_B1); 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_ci if (value & 0x01) { 4958c2ecf20Sopenharmony_ci if (aic->aic_sram[i] == 0) 4968c2ecf20Sopenharmony_ci aic->aic_caled_chan++; 4978c2ecf20Sopenharmony_ci 4988c2ecf20Sopenharmony_ci aic->aic_sram[i] = value; 4998c2ecf20Sopenharmony_ci 5008c2ecf20Sopenharmony_ci if (!cal_once) 5018c2ecf20Sopenharmony_ci break; 5028c2ecf20Sopenharmony_ci } 5038c2ecf20Sopenharmony_ci } 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ci if ((aic->aic_caled_chan >= num_chan) || cal_once) { 5068c2ecf20Sopenharmony_ci ar9003_aic_cal_done(ah); 5078c2ecf20Sopenharmony_ci } else { 5088c2ecf20Sopenharmony_ci /* Start calibration */ 5098c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_PHY_AIC_CTRL_0_B1, AR_PHY_AIC_CAL_ENABLE); 5108c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_AIC_CTRL_0_B1, 5118c2ecf20Sopenharmony_ci AR_PHY_AIC_CAL_CH_VALID_RESET); 5128c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PHY_AIC_CTRL_0_B1, AR_PHY_AIC_CAL_ENABLE); 5138c2ecf20Sopenharmony_ci } 5148c2ecf20Sopenharmony_ciexit: 5158c2ecf20Sopenharmony_ci return aic->aic_cal_state; 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci} 5188c2ecf20Sopenharmony_ci 5198c2ecf20Sopenharmony_ciu8 ar9003_aic_calibration(struct ath_hw *ah) 5208c2ecf20Sopenharmony_ci{ 5218c2ecf20Sopenharmony_ci struct ath9k_hw_aic *aic = &ah->btcoex_hw.aic; 5228c2ecf20Sopenharmony_ci u8 cal_ret = AIC_CAL_STATE_ERROR; 5238c2ecf20Sopenharmony_ci 5248c2ecf20Sopenharmony_ci switch (aic->aic_cal_state) { 5258c2ecf20Sopenharmony_ci case AIC_CAL_STATE_IDLE: 5268c2ecf20Sopenharmony_ci cal_ret = ar9003_aic_cal_start(ah, 1); 5278c2ecf20Sopenharmony_ci break; 5288c2ecf20Sopenharmony_ci case AIC_CAL_STATE_STARTED: 5298c2ecf20Sopenharmony_ci cal_ret = ar9003_aic_cal_continue(ah, false); 5308c2ecf20Sopenharmony_ci break; 5318c2ecf20Sopenharmony_ci case AIC_CAL_STATE_DONE: 5328c2ecf20Sopenharmony_ci cal_ret = AIC_CAL_STATE_DONE; 5338c2ecf20Sopenharmony_ci break; 5348c2ecf20Sopenharmony_ci default: 5358c2ecf20Sopenharmony_ci break; 5368c2ecf20Sopenharmony_ci } 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_ci return cal_ret; 5398c2ecf20Sopenharmony_ci} 5408c2ecf20Sopenharmony_ci 5418c2ecf20Sopenharmony_ciu8 ar9003_aic_start_normal(struct ath_hw *ah) 5428c2ecf20Sopenharmony_ci{ 5438c2ecf20Sopenharmony_ci struct ath9k_hw_aic *aic = &ah->btcoex_hw.aic; 5448c2ecf20Sopenharmony_ci int16_t i; 5458c2ecf20Sopenharmony_ci 5468c2ecf20Sopenharmony_ci if (aic->aic_cal_state != AIC_CAL_STATE_DONE) 5478c2ecf20Sopenharmony_ci return 1; 5488c2ecf20Sopenharmony_ci 5498c2ecf20Sopenharmony_ci ar9003_aic_gain_table(ah); 5508c2ecf20Sopenharmony_ci 5518c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_AIC_SRAM_ADDR_B1, ATH_AIC_SRAM_AUTO_INCREMENT); 5528c2ecf20Sopenharmony_ci 5538c2ecf20Sopenharmony_ci for (i = 0; i < ATH_AIC_MAX_BT_CHANNEL; i++) { 5548c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_AIC_SRAM_DATA_B1, aic->aic_sram[i]); 5558c2ecf20Sopenharmony_ci } 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_ci /* FIXME: Replace these with proper register names */ 5588c2ecf20Sopenharmony_ci REG_WRITE(ah, 0xa6b0, 0x80); 5598c2ecf20Sopenharmony_ci REG_WRITE(ah, 0xa6b4, 0x5b2df0); 5608c2ecf20Sopenharmony_ci REG_WRITE(ah, 0xa6b8, 0x10762cc8); 5618c2ecf20Sopenharmony_ci REG_WRITE(ah, 0xa6bc, 0x1219a4b); 5628c2ecf20Sopenharmony_ci REG_WRITE(ah, 0xa6c0, 0x1e01); 5638c2ecf20Sopenharmony_ci REG_WRITE(ah, 0xb6b4, 0xf0); 5648c2ecf20Sopenharmony_ci REG_WRITE(ah, 0xb6c0, 0x1e01); 5658c2ecf20Sopenharmony_ci REG_WRITE(ah, 0xb6b0, 0x81); 5668c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PHY_65NM_CH1_RXTX4, 0x40000000); 5678c2ecf20Sopenharmony_ci 5688c2ecf20Sopenharmony_ci aic->aic_enabled = true; 5698c2ecf20Sopenharmony_ci 5708c2ecf20Sopenharmony_ci return 0; 5718c2ecf20Sopenharmony_ci} 5728c2ecf20Sopenharmony_ci 5738c2ecf20Sopenharmony_ciu8 ar9003_aic_cal_reset(struct ath_hw *ah) 5748c2ecf20Sopenharmony_ci{ 5758c2ecf20Sopenharmony_ci struct ath9k_hw_aic *aic = &ah->btcoex_hw.aic; 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_ci aic->aic_cal_state = AIC_CAL_STATE_IDLE; 5788c2ecf20Sopenharmony_ci return aic->aic_cal_state; 5798c2ecf20Sopenharmony_ci} 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_ciu8 ar9003_aic_calibration_single(struct ath_hw *ah) 5828c2ecf20Sopenharmony_ci{ 5838c2ecf20Sopenharmony_ci struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci; 5848c2ecf20Sopenharmony_ci u8 cal_ret; 5858c2ecf20Sopenharmony_ci int num_chan; 5868c2ecf20Sopenharmony_ci 5878c2ecf20Sopenharmony_ci num_chan = MS(mci_hw->config, ATH_MCI_CONFIG_AIC_CAL_NUM_CHAN); 5888c2ecf20Sopenharmony_ci 5898c2ecf20Sopenharmony_ci (void) ar9003_aic_cal_start(ah, num_chan); 5908c2ecf20Sopenharmony_ci cal_ret = ar9003_aic_cal_continue(ah, true); 5918c2ecf20Sopenharmony_ci 5928c2ecf20Sopenharmony_ci return cal_ret; 5938c2ecf20Sopenharmony_ci} 5948c2ecf20Sopenharmony_ci 5958c2ecf20Sopenharmony_civoid ar9003_hw_attach_aic_ops(struct ath_hw *ah) 5968c2ecf20Sopenharmony_ci{ 5978c2ecf20Sopenharmony_ci struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah); 5988c2ecf20Sopenharmony_ci 5998c2ecf20Sopenharmony_ci priv_ops->is_aic_enabled = ar9003_hw_is_aic_enabled; 6008c2ecf20Sopenharmony_ci} 601