18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2009-2011 Atheros Communications Inc. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any 58c2ecf20Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above 68c2ecf20Sopenharmony_ci * copyright notice and this permission notice appear in all copies. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 98c2ecf20Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 108c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 118c2ecf20Sopenharmony_ci * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 128c2ecf20Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 138c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 148c2ecf20Sopenharmony_ci * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <linux/export.h> 188c2ecf20Sopenharmony_ci#include <linux/types.h> 198c2ecf20Sopenharmony_ci#include <linux/ath9k_platform.h> 208c2ecf20Sopenharmony_ci#include "hw.h" 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_cienum ath_bt_mode { 238c2ecf20Sopenharmony_ci ATH_BT_COEX_MODE_LEGACY, /* legacy rx_clear mode */ 248c2ecf20Sopenharmony_ci ATH_BT_COEX_MODE_UNSLOTTED, /* untimed/unslotted mode */ 258c2ecf20Sopenharmony_ci ATH_BT_COEX_MODE_SLOTTED, /* slotted mode */ 268c2ecf20Sopenharmony_ci ATH_BT_COEX_MODE_DISABLED, /* coexistence disabled */ 278c2ecf20Sopenharmony_ci}; 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cistruct ath_btcoex_config { 308c2ecf20Sopenharmony_ci u8 bt_time_extend; 318c2ecf20Sopenharmony_ci bool bt_txstate_extend; 328c2ecf20Sopenharmony_ci bool bt_txframe_extend; 338c2ecf20Sopenharmony_ci enum ath_bt_mode bt_mode; /* coexistence mode */ 348c2ecf20Sopenharmony_ci bool bt_quiet_collision; 358c2ecf20Sopenharmony_ci bool bt_rxclear_polarity; /* invert rx_clear as WLAN_ACTIVE*/ 368c2ecf20Sopenharmony_ci u8 bt_priority_time; 378c2ecf20Sopenharmony_ci u8 bt_first_slot_time; 388c2ecf20Sopenharmony_ci bool bt_hold_rx_clear; 398c2ecf20Sopenharmony_ci u8 wl_active_time; 408c2ecf20Sopenharmony_ci u8 wl_qc_time; 418c2ecf20Sopenharmony_ci}; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_cistatic const u32 ar9003_wlan_weights[ATH_BTCOEX_STOMP_MAX] 448c2ecf20Sopenharmony_ci [AR9300_NUM_WLAN_WEIGHTS] = { 458c2ecf20Sopenharmony_ci { 0xfffffff0, 0xfffffff0, 0xfffffff0, 0xfffffff0 }, /* STOMP_ALL */ 468c2ecf20Sopenharmony_ci { 0x88888880, 0x88888880, 0x88888880, 0x88888880 }, /* STOMP_LOW */ 478c2ecf20Sopenharmony_ci { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, /* STOMP_NONE */ 488c2ecf20Sopenharmony_ci}; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cistatic const u32 mci_wlan_weights[ATH_BTCOEX_STOMP_MAX] 518c2ecf20Sopenharmony_ci [AR9300_NUM_WLAN_WEIGHTS] = { 528c2ecf20Sopenharmony_ci { 0x01017d01, 0x41414101, 0x41414101, 0x41414141 }, /* STOMP_ALL */ 538c2ecf20Sopenharmony_ci { 0x01017d01, 0x3b3b3b01, 0x3b3b3b01, 0x3b3b3b3b }, /* STOMP_LOW */ 548c2ecf20Sopenharmony_ci { 0x01017d01, 0x01010101, 0x01010101, 0x01010101 }, /* STOMP_NONE */ 558c2ecf20Sopenharmony_ci { 0x01017d01, 0x013b0101, 0x3b3b0101, 0x3b3b013b }, /* STOMP_LOW_FTP */ 568c2ecf20Sopenharmony_ci { 0xffffff01, 0xffffffff, 0xffffff01, 0xffffffff }, /* STOMP_AUDIO */ 578c2ecf20Sopenharmony_ci}; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_civoid ath9k_hw_init_btcoex_hw(struct ath_hw *ah, int qnum) 608c2ecf20Sopenharmony_ci{ 618c2ecf20Sopenharmony_ci struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; 628c2ecf20Sopenharmony_ci const struct ath_btcoex_config ath_bt_config = { 638c2ecf20Sopenharmony_ci .bt_time_extend = 0, 648c2ecf20Sopenharmony_ci .bt_txstate_extend = true, 658c2ecf20Sopenharmony_ci .bt_txframe_extend = true, 668c2ecf20Sopenharmony_ci .bt_mode = ATH_BT_COEX_MODE_SLOTTED, 678c2ecf20Sopenharmony_ci .bt_quiet_collision = true, 688c2ecf20Sopenharmony_ci .bt_rxclear_polarity = true, 698c2ecf20Sopenharmony_ci .bt_priority_time = 2, 708c2ecf20Sopenharmony_ci .bt_first_slot_time = 5, 718c2ecf20Sopenharmony_ci .bt_hold_rx_clear = true, 728c2ecf20Sopenharmony_ci .wl_active_time = 0x20, 738c2ecf20Sopenharmony_ci .wl_qc_time = 0x20, 748c2ecf20Sopenharmony_ci }; 758c2ecf20Sopenharmony_ci bool rxclear_polarity = ath_bt_config.bt_rxclear_polarity; 768c2ecf20Sopenharmony_ci u8 time_extend = ath_bt_config.bt_time_extend; 778c2ecf20Sopenharmony_ci u8 first_slot_time = ath_bt_config.bt_first_slot_time; 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci if (AR_SREV_9300_20_OR_LATER(ah)) 808c2ecf20Sopenharmony_ci rxclear_polarity = !ath_bt_config.bt_rxclear_polarity; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci if (AR_SREV_SOC(ah)) { 838c2ecf20Sopenharmony_ci first_slot_time = 0x1d; 848c2ecf20Sopenharmony_ci time_extend = 0xa; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci btcoex_hw->bt_coex_mode3 = 878c2ecf20Sopenharmony_ci SM(ath_bt_config.wl_active_time, AR_BT_WL_ACTIVE_TIME) | 888c2ecf20Sopenharmony_ci SM(ath_bt_config.wl_qc_time, AR_BT_WL_QC_TIME); 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci btcoex_hw->bt_coex_mode2 = 918c2ecf20Sopenharmony_ci AR_BT_PROTECT_BT_AFTER_WAKEUP | 928c2ecf20Sopenharmony_ci AR_BT_PHY_ERR_BT_COLL_ENABLE; 938c2ecf20Sopenharmony_ci } 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci btcoex_hw->bt_coex_mode = 968c2ecf20Sopenharmony_ci (btcoex_hw->bt_coex_mode & AR_BT_QCU_THRESH) | 978c2ecf20Sopenharmony_ci SM(time_extend, AR_BT_TIME_EXTEND) | 988c2ecf20Sopenharmony_ci SM(ath_bt_config.bt_txstate_extend, AR_BT_TXSTATE_EXTEND) | 998c2ecf20Sopenharmony_ci SM(ath_bt_config.bt_txframe_extend, AR_BT_TX_FRAME_EXTEND) | 1008c2ecf20Sopenharmony_ci SM(ath_bt_config.bt_mode, AR_BT_MODE) | 1018c2ecf20Sopenharmony_ci SM(ath_bt_config.bt_quiet_collision, AR_BT_QUIET) | 1028c2ecf20Sopenharmony_ci SM(rxclear_polarity, AR_BT_RX_CLEAR_POLARITY) | 1038c2ecf20Sopenharmony_ci SM(ath_bt_config.bt_priority_time, AR_BT_PRIORITY_TIME) | 1048c2ecf20Sopenharmony_ci SM(first_slot_time, AR_BT_FIRST_SLOT_TIME) | 1058c2ecf20Sopenharmony_ci SM(qnum, AR_BT_QCU_THRESH); 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci btcoex_hw->bt_coex_mode2 |= 1088c2ecf20Sopenharmony_ci SM(ath_bt_config.bt_hold_rx_clear, AR_BT_HOLD_RX_CLEAR) | 1098c2ecf20Sopenharmony_ci SM(ATH_BTCOEX_BMISS_THRESH, AR_BT_BCN_MISS_THRESH) | 1108c2ecf20Sopenharmony_ci AR_BT_DISABLE_BT_ANT; 1118c2ecf20Sopenharmony_ci} 1128c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_init_btcoex_hw); 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_cistatic void ath9k_hw_btcoex_pin_init(struct ath_hw *ah, u8 wlanactive_gpio, 1158c2ecf20Sopenharmony_ci u8 btactive_gpio, u8 btpriority_gpio) 1168c2ecf20Sopenharmony_ci{ 1178c2ecf20Sopenharmony_ci struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; 1188c2ecf20Sopenharmony_ci struct ath9k_platform_data *pdata = ah->dev->platform_data; 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci if (btcoex_hw->scheme != ATH_BTCOEX_CFG_2WIRE && 1218c2ecf20Sopenharmony_ci btcoex_hw->scheme != ATH_BTCOEX_CFG_3WIRE) 1228c2ecf20Sopenharmony_ci return; 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci /* bt priority GPIO will be ignored by 2 wire scheme */ 1258c2ecf20Sopenharmony_ci if (pdata && (pdata->bt_active_pin || pdata->bt_priority_pin || 1268c2ecf20Sopenharmony_ci pdata->wlan_active_pin)) { 1278c2ecf20Sopenharmony_ci btcoex_hw->btactive_gpio = pdata->bt_active_pin; 1288c2ecf20Sopenharmony_ci btcoex_hw->wlanactive_gpio = pdata->wlan_active_pin; 1298c2ecf20Sopenharmony_ci btcoex_hw->btpriority_gpio = pdata->bt_priority_pin; 1308c2ecf20Sopenharmony_ci } else { 1318c2ecf20Sopenharmony_ci btcoex_hw->btactive_gpio = btactive_gpio; 1328c2ecf20Sopenharmony_ci btcoex_hw->wlanactive_gpio = wlanactive_gpio; 1338c2ecf20Sopenharmony_ci btcoex_hw->btpriority_gpio = btpriority_gpio; 1348c2ecf20Sopenharmony_ci } 1358c2ecf20Sopenharmony_ci} 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_civoid ath9k_hw_btcoex_init_scheme(struct ath_hw *ah) 1388c2ecf20Sopenharmony_ci{ 1398c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 1408c2ecf20Sopenharmony_ci struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci /* 1438c2ecf20Sopenharmony_ci * Check if BTCOEX is globally disabled. 1448c2ecf20Sopenharmony_ci */ 1458c2ecf20Sopenharmony_ci if (!common->btcoex_enabled) { 1468c2ecf20Sopenharmony_ci btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE; 1478c2ecf20Sopenharmony_ci return; 1488c2ecf20Sopenharmony_ci } 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI) { 1518c2ecf20Sopenharmony_ci btcoex_hw->scheme = ATH_BTCOEX_CFG_MCI; 1528c2ecf20Sopenharmony_ci } else if (AR_SREV_9300_20_OR_LATER(ah)) { 1538c2ecf20Sopenharmony_ci btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE; 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci ath9k_hw_btcoex_pin_init(ah, ATH_WLANACTIVE_GPIO_9300, 1568c2ecf20Sopenharmony_ci ATH_BTACTIVE_GPIO_9300, 1578c2ecf20Sopenharmony_ci ATH_BTPRIORITY_GPIO_9300); 1588c2ecf20Sopenharmony_ci } else if (AR_SREV_9280_20_OR_LATER(ah)) { 1598c2ecf20Sopenharmony_ci if (AR_SREV_9285(ah)) 1608c2ecf20Sopenharmony_ci btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE; 1618c2ecf20Sopenharmony_ci else 1628c2ecf20Sopenharmony_ci btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE; 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci ath9k_hw_btcoex_pin_init(ah, ATH_WLANACTIVE_GPIO_9280, 1658c2ecf20Sopenharmony_ci ATH_BTACTIVE_GPIO_9280, 1668c2ecf20Sopenharmony_ci ATH_BTPRIORITY_GPIO_9285); 1678c2ecf20Sopenharmony_ci } 1688c2ecf20Sopenharmony_ci} 1698c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_btcoex_init_scheme); 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_civoid ath9k_hw_btcoex_init_2wire(struct ath_hw *ah) 1728c2ecf20Sopenharmony_ci{ 1738c2ecf20Sopenharmony_ci struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci /* connect bt_active to baseband */ 1768c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_GPIO_INPUT_EN_VAL, 1778c2ecf20Sopenharmony_ci (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_DEF | 1788c2ecf20Sopenharmony_ci AR_GPIO_INPUT_EN_VAL_BT_FREQUENCY_DEF)); 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, 1818c2ecf20Sopenharmony_ci AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB); 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci /* Set input mux for bt_active to gpio pin */ 1848c2ecf20Sopenharmony_ci if (!AR_SREV_SOC(ah)) 1858c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1, 1868c2ecf20Sopenharmony_ci AR_GPIO_INPUT_MUX1_BT_ACTIVE, 1878c2ecf20Sopenharmony_ci btcoex_hw->btactive_gpio); 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci /* Configure the desired gpio port for input */ 1908c2ecf20Sopenharmony_ci ath9k_hw_gpio_request_in(ah, btcoex_hw->btactive_gpio, 1918c2ecf20Sopenharmony_ci "ath9k-btactive"); 1928c2ecf20Sopenharmony_ci} 1938c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_btcoex_init_2wire); 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_civoid ath9k_hw_btcoex_init_3wire(struct ath_hw *ah) 1968c2ecf20Sopenharmony_ci{ 1978c2ecf20Sopenharmony_ci struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci /* btcoex 3-wire */ 2008c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, 2018c2ecf20Sopenharmony_ci (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_BB | 2028c2ecf20Sopenharmony_ci AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB)); 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci /* Set input mux for bt_prority_async and 2058c2ecf20Sopenharmony_ci * bt_active_async to GPIO pins */ 2068c2ecf20Sopenharmony_ci if (!AR_SREV_SOC(ah)) { 2078c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1, 2088c2ecf20Sopenharmony_ci AR_GPIO_INPUT_MUX1_BT_ACTIVE, 2098c2ecf20Sopenharmony_ci btcoex_hw->btactive_gpio); 2108c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1, 2118c2ecf20Sopenharmony_ci AR_GPIO_INPUT_MUX1_BT_PRIORITY, 2128c2ecf20Sopenharmony_ci btcoex_hw->btpriority_gpio); 2138c2ecf20Sopenharmony_ci } 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci /* Configure the desired GPIO ports for input */ 2168c2ecf20Sopenharmony_ci ath9k_hw_gpio_request_in(ah, btcoex_hw->btactive_gpio, 2178c2ecf20Sopenharmony_ci "ath9k-btactive"); 2188c2ecf20Sopenharmony_ci ath9k_hw_gpio_request_in(ah, btcoex_hw->btpriority_gpio, 2198c2ecf20Sopenharmony_ci "ath9k-btpriority"); 2208c2ecf20Sopenharmony_ci} 2218c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_btcoex_init_3wire); 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_civoid ath9k_hw_btcoex_deinit(struct ath_hw *ah) 2248c2ecf20Sopenharmony_ci{ 2258c2ecf20Sopenharmony_ci struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci ath9k_hw_gpio_free(ah, btcoex_hw->btactive_gpio); 2288c2ecf20Sopenharmony_ci ath9k_hw_gpio_free(ah, btcoex_hw->btpriority_gpio); 2298c2ecf20Sopenharmony_ci ath9k_hw_gpio_free(ah, btcoex_hw->wlanactive_gpio); 2308c2ecf20Sopenharmony_ci} 2318c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_btcoex_deinit); 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_civoid ath9k_hw_btcoex_init_mci(struct ath_hw *ah) 2348c2ecf20Sopenharmony_ci{ 2358c2ecf20Sopenharmony_ci ah->btcoex_hw.mci.ready = false; 2368c2ecf20Sopenharmony_ci ah->btcoex_hw.mci.bt_state = 0; 2378c2ecf20Sopenharmony_ci ah->btcoex_hw.mci.bt_ver_major = 3; 2388c2ecf20Sopenharmony_ci ah->btcoex_hw.mci.bt_ver_minor = 0; 2398c2ecf20Sopenharmony_ci ah->btcoex_hw.mci.bt_version_known = false; 2408c2ecf20Sopenharmony_ci ah->btcoex_hw.mci.update_2g5g = true; 2418c2ecf20Sopenharmony_ci ah->btcoex_hw.mci.is_2g = true; 2428c2ecf20Sopenharmony_ci ah->btcoex_hw.mci.wlan_channels_update = false; 2438c2ecf20Sopenharmony_ci ah->btcoex_hw.mci.wlan_channels[0] = 0x00000000; 2448c2ecf20Sopenharmony_ci ah->btcoex_hw.mci.wlan_channels[1] = 0xffffffff; 2458c2ecf20Sopenharmony_ci ah->btcoex_hw.mci.wlan_channels[2] = 0xffffffff; 2468c2ecf20Sopenharmony_ci ah->btcoex_hw.mci.wlan_channels[3] = 0x7fffffff; 2478c2ecf20Sopenharmony_ci ah->btcoex_hw.mci.query_bt = true; 2488c2ecf20Sopenharmony_ci ah->btcoex_hw.mci.unhalt_bt_gpm = true; 2498c2ecf20Sopenharmony_ci ah->btcoex_hw.mci.halted_bt_gpm = false; 2508c2ecf20Sopenharmony_ci ah->btcoex_hw.mci.need_flush_btinfo = false; 2518c2ecf20Sopenharmony_ci ah->btcoex_hw.mci.wlan_cal_seq = 0; 2528c2ecf20Sopenharmony_ci ah->btcoex_hw.mci.wlan_cal_done = 0; 2538c2ecf20Sopenharmony_ci ah->btcoex_hw.mci.config = (AR_SREV_9462(ah)) ? 0x2201 : 0xa4c1; 2548c2ecf20Sopenharmony_ci} 2558c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_btcoex_init_mci); 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_cistatic void ath9k_hw_btcoex_enable_2wire(struct ath_hw *ah) 2588c2ecf20Sopenharmony_ci{ 2598c2ecf20Sopenharmony_ci struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_ci /* Configure the desired GPIO port for TX_FRAME output */ 2628c2ecf20Sopenharmony_ci ath9k_hw_gpio_request_out(ah, btcoex_hw->wlanactive_gpio, 2638c2ecf20Sopenharmony_ci "ath9k-wlanactive", 2648c2ecf20Sopenharmony_ci AR_GPIO_OUTPUT_MUX_AS_TX_FRAME); 2658c2ecf20Sopenharmony_ci} 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci/* 2688c2ecf20Sopenharmony_ci * For AR9002, bt_weight/wlan_weight are used. 2698c2ecf20Sopenharmony_ci * For AR9003 and above, stomp_type is used. 2708c2ecf20Sopenharmony_ci */ 2718c2ecf20Sopenharmony_civoid ath9k_hw_btcoex_set_weight(struct ath_hw *ah, 2728c2ecf20Sopenharmony_ci u32 bt_weight, 2738c2ecf20Sopenharmony_ci u32 wlan_weight, 2748c2ecf20Sopenharmony_ci enum ath_stomp_type stomp_type) 2758c2ecf20Sopenharmony_ci{ 2768c2ecf20Sopenharmony_ci struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; 2778c2ecf20Sopenharmony_ci struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci; 2788c2ecf20Sopenharmony_ci u8 txprio_shift[] = { 24, 16, 16, 0 }; /* tx priority weight */ 2798c2ecf20Sopenharmony_ci bool concur_tx = (mci_hw->concur_tx && btcoex_hw->tx_prio[stomp_type]); 2808c2ecf20Sopenharmony_ci const u32 *weight = ar9003_wlan_weights[stomp_type]; 2818c2ecf20Sopenharmony_ci int i; 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_ci if (!AR_SREV_9300_20_OR_LATER(ah)) { 2848c2ecf20Sopenharmony_ci btcoex_hw->bt_coex_weights = 2858c2ecf20Sopenharmony_ci SM(bt_weight, AR_BTCOEX_BT_WGHT) | 2868c2ecf20Sopenharmony_ci SM(wlan_weight, AR_BTCOEX_WL_WGHT); 2878c2ecf20Sopenharmony_ci return; 2888c2ecf20Sopenharmony_ci } 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_ci if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) { 2918c2ecf20Sopenharmony_ci enum ath_stomp_type stype = 2928c2ecf20Sopenharmony_ci ((stomp_type == ATH_BTCOEX_STOMP_LOW) && 2938c2ecf20Sopenharmony_ci btcoex_hw->mci.stomp_ftp) ? 2948c2ecf20Sopenharmony_ci ATH_BTCOEX_STOMP_LOW_FTP : stomp_type; 2958c2ecf20Sopenharmony_ci weight = mci_wlan_weights[stype]; 2968c2ecf20Sopenharmony_ci } 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci for (i = 0; i < AR9300_NUM_WLAN_WEIGHTS; i++) { 2998c2ecf20Sopenharmony_ci btcoex_hw->bt_weight[i] = AR9300_BT_WGHT; 3008c2ecf20Sopenharmony_ci btcoex_hw->wlan_weight[i] = weight[i]; 3018c2ecf20Sopenharmony_ci if (concur_tx && i) { 3028c2ecf20Sopenharmony_ci btcoex_hw->wlan_weight[i] &= 3038c2ecf20Sopenharmony_ci ~(0xff << txprio_shift[i-1]); 3048c2ecf20Sopenharmony_ci btcoex_hw->wlan_weight[i] |= 3058c2ecf20Sopenharmony_ci (btcoex_hw->tx_prio[stomp_type] << 3068c2ecf20Sopenharmony_ci txprio_shift[i-1]); 3078c2ecf20Sopenharmony_ci } 3088c2ecf20Sopenharmony_ci } 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_ci /* Last WLAN weight has to be adjusted wrt tx priority */ 3118c2ecf20Sopenharmony_ci if (concur_tx) { 3128c2ecf20Sopenharmony_ci btcoex_hw->wlan_weight[i-1] &= ~(0xff << txprio_shift[i-1]); 3138c2ecf20Sopenharmony_ci btcoex_hw->wlan_weight[i-1] |= (btcoex_hw->tx_prio[stomp_type] 3148c2ecf20Sopenharmony_ci << txprio_shift[i-1]); 3158c2ecf20Sopenharmony_ci } 3168c2ecf20Sopenharmony_ci} 3178c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_btcoex_set_weight); 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_cistatic void ath9k_hw_btcoex_enable_3wire(struct ath_hw *ah) 3218c2ecf20Sopenharmony_ci{ 3228c2ecf20Sopenharmony_ci struct ath_btcoex_hw *btcoex = &ah->btcoex_hw; 3238c2ecf20Sopenharmony_ci u32 val; 3248c2ecf20Sopenharmony_ci int i; 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci /* 3278c2ecf20Sopenharmony_ci * Program coex mode and weight registers to 3288c2ecf20Sopenharmony_ci * enable coex 3-wire 3298c2ecf20Sopenharmony_ci */ 3308c2ecf20Sopenharmony_ci if (AR_SREV_SOC(ah)) 3318c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_BT_COEX_MODE2, AR_BT_PHY_ERR_BT_COLL_ENABLE); 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_BT_COEX_MODE, btcoex->bt_coex_mode); 3348c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_BT_COEX_MODE2, btcoex->bt_coex_mode2); 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci if (AR_SREV_SOC(ah)) 3378c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_BT_COEX_MODE3, btcoex->bt_coex_mode3); 3388c2ecf20Sopenharmony_ci 3398c2ecf20Sopenharmony_ci if (AR_SREV_9300_20_OR_LATER(ah)) { 3408c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_BT_COEX_WL_WEIGHTS0, btcoex->wlan_weight[0]); 3418c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_BT_COEX_WL_WEIGHTS1, btcoex->wlan_weight[1]); 3428c2ecf20Sopenharmony_ci for (i = 0; i < AR9300_NUM_BT_WEIGHTS; i++) 3438c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_BT_COEX_BT_WEIGHTS(i), 3448c2ecf20Sopenharmony_ci btcoex->bt_weight[i]); 3458c2ecf20Sopenharmony_ci } else 3468c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_BT_COEX_WEIGHT, btcoex->bt_coex_weights); 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci if (AR_SREV_9271(ah)) { 3498c2ecf20Sopenharmony_ci val = REG_READ(ah, 0x50040); 3508c2ecf20Sopenharmony_ci val &= 0xFFFFFEFF; 3518c2ecf20Sopenharmony_ci REG_WRITE(ah, 0x50040, val); 3528c2ecf20Sopenharmony_ci } 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_QUIET1, AR_QUIET1_QUIET_ACK_CTS_ENABLE, 1); 3558c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_PCU_MISC, AR_PCU_BT_ANT_PREVENT_RX, 0); 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci ath9k_hw_gpio_request_out(ah, btcoex->wlanactive_gpio, 3588c2ecf20Sopenharmony_ci "ath9k-wlanactive", 3598c2ecf20Sopenharmony_ci AR_GPIO_OUTPUT_MUX_AS_RX_CLEAR_EXTERNAL); 3608c2ecf20Sopenharmony_ci} 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_cistatic void ath9k_hw_btcoex_enable_mci(struct ath_hw *ah) 3638c2ecf20Sopenharmony_ci{ 3648c2ecf20Sopenharmony_ci struct ath_btcoex_hw *btcoex = &ah->btcoex_hw; 3658c2ecf20Sopenharmony_ci int i; 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci for (i = 0; i < AR9300_NUM_BT_WEIGHTS; i++) 3688c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_MCI_COEX_WL_WEIGHTS(i), 3698c2ecf20Sopenharmony_ci btcoex->wlan_weight[i]); 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_QUIET1, AR_QUIET1_QUIET_ACK_CTS_ENABLE, 1); 3728c2ecf20Sopenharmony_ci btcoex->enabled = true; 3738c2ecf20Sopenharmony_ci} 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_cistatic void ath9k_hw_btcoex_disable_mci(struct ath_hw *ah) 3768c2ecf20Sopenharmony_ci{ 3778c2ecf20Sopenharmony_ci struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; 3788c2ecf20Sopenharmony_ci int i; 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_NONE); 3818c2ecf20Sopenharmony_ci 3828c2ecf20Sopenharmony_ci for (i = 0; i < AR9300_NUM_BT_WEIGHTS; i++) 3838c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_MCI_COEX_WL_WEIGHTS(i), 3848c2ecf20Sopenharmony_ci btcoex_hw->wlan_weight[i]); 3858c2ecf20Sopenharmony_ci} 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_civoid ath9k_hw_btcoex_enable(struct ath_hw *ah) 3888c2ecf20Sopenharmony_ci{ 3898c2ecf20Sopenharmony_ci struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci switch (ath9k_hw_get_btcoex_scheme(ah)) { 3928c2ecf20Sopenharmony_ci case ATH_BTCOEX_CFG_NONE: 3938c2ecf20Sopenharmony_ci return; 3948c2ecf20Sopenharmony_ci case ATH_BTCOEX_CFG_2WIRE: 3958c2ecf20Sopenharmony_ci ath9k_hw_btcoex_enable_2wire(ah); 3968c2ecf20Sopenharmony_ci break; 3978c2ecf20Sopenharmony_ci case ATH_BTCOEX_CFG_3WIRE: 3988c2ecf20Sopenharmony_ci ath9k_hw_btcoex_enable_3wire(ah); 3998c2ecf20Sopenharmony_ci break; 4008c2ecf20Sopenharmony_ci case ATH_BTCOEX_CFG_MCI: 4018c2ecf20Sopenharmony_ci ath9k_hw_btcoex_enable_mci(ah); 4028c2ecf20Sopenharmony_ci break; 4038c2ecf20Sopenharmony_ci } 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ci if (ath9k_hw_get_btcoex_scheme(ah) != ATH_BTCOEX_CFG_MCI && 4068c2ecf20Sopenharmony_ci !AR_SREV_SOC(ah)) { 4078c2ecf20Sopenharmony_ci REG_RMW(ah, AR_GPIO_PDPU, 4088c2ecf20Sopenharmony_ci (0x2 << (btcoex_hw->btactive_gpio * 2)), 4098c2ecf20Sopenharmony_ci (0x3 << (btcoex_hw->btactive_gpio * 2))); 4108c2ecf20Sopenharmony_ci } 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ci ah->btcoex_hw.enabled = true; 4138c2ecf20Sopenharmony_ci} 4148c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_btcoex_enable); 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_civoid ath9k_hw_btcoex_disable(struct ath_hw *ah) 4178c2ecf20Sopenharmony_ci{ 4188c2ecf20Sopenharmony_ci struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; 4198c2ecf20Sopenharmony_ci int i; 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci btcoex_hw->enabled = false; 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ci if (ath9k_hw_get_btcoex_scheme(ah) == ATH_BTCOEX_CFG_MCI) { 4248c2ecf20Sopenharmony_ci ath9k_hw_btcoex_disable_mci(ah); 4258c2ecf20Sopenharmony_ci return; 4268c2ecf20Sopenharmony_ci } 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ci if (!AR_SREV_9300_20_OR_LATER(ah)) 4298c2ecf20Sopenharmony_ci ath9k_hw_set_gpio(ah, btcoex_hw->wlanactive_gpio, 0); 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci ath9k_hw_gpio_request_out(ah, btcoex_hw->wlanactive_gpio, 4328c2ecf20Sopenharmony_ci NULL, AR_GPIO_OUTPUT_MUX_AS_OUTPUT); 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ci if (btcoex_hw->scheme == ATH_BTCOEX_CFG_3WIRE) { 4358c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_BT_COEX_MODE, AR_BT_QUIET | AR_BT_MODE); 4368c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_BT_COEX_MODE2, 0); 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ci if (AR_SREV_9300_20_OR_LATER(ah)) { 4398c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_BT_COEX_WL_WEIGHTS0, 0); 4408c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_BT_COEX_WL_WEIGHTS1, 0); 4418c2ecf20Sopenharmony_ci for (i = 0; i < AR9300_NUM_BT_WEIGHTS; i++) 4428c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_BT_COEX_BT_WEIGHTS(i), 0); 4438c2ecf20Sopenharmony_ci } else 4448c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_BT_COEX_WEIGHT, 0); 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ci } 4478c2ecf20Sopenharmony_ci} 4488c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_btcoex_disable); 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci/* 4518c2ecf20Sopenharmony_ci * Configures appropriate weight based on stomp type. 4528c2ecf20Sopenharmony_ci */ 4538c2ecf20Sopenharmony_civoid ath9k_hw_btcoex_bt_stomp(struct ath_hw *ah, 4548c2ecf20Sopenharmony_ci enum ath_stomp_type stomp_type) 4558c2ecf20Sopenharmony_ci{ 4568c2ecf20Sopenharmony_ci if (AR_SREV_9300_20_OR_LATER(ah)) { 4578c2ecf20Sopenharmony_ci ath9k_hw_btcoex_set_weight(ah, 0, 0, stomp_type); 4588c2ecf20Sopenharmony_ci return; 4598c2ecf20Sopenharmony_ci } 4608c2ecf20Sopenharmony_ci 4618c2ecf20Sopenharmony_ci switch (stomp_type) { 4628c2ecf20Sopenharmony_ci case ATH_BTCOEX_STOMP_ALL: 4638c2ecf20Sopenharmony_ci ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT, 4648c2ecf20Sopenharmony_ci AR_STOMP_ALL_WLAN_WGHT, 0); 4658c2ecf20Sopenharmony_ci break; 4668c2ecf20Sopenharmony_ci case ATH_BTCOEX_STOMP_LOW: 4678c2ecf20Sopenharmony_ci ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT, 4688c2ecf20Sopenharmony_ci AR_STOMP_LOW_WLAN_WGHT, 0); 4698c2ecf20Sopenharmony_ci break; 4708c2ecf20Sopenharmony_ci case ATH_BTCOEX_STOMP_NONE: 4718c2ecf20Sopenharmony_ci ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT, 4728c2ecf20Sopenharmony_ci AR_STOMP_NONE_WLAN_WGHT, 0); 4738c2ecf20Sopenharmony_ci break; 4748c2ecf20Sopenharmony_ci default: 4758c2ecf20Sopenharmony_ci ath_dbg(ath9k_hw_common(ah), BTCOEX, "Invalid Stomptype\n"); 4768c2ecf20Sopenharmony_ci break; 4778c2ecf20Sopenharmony_ci } 4788c2ecf20Sopenharmony_ci} 4798c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_btcoex_bt_stomp); 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_civoid ath9k_hw_btcoex_set_concur_txprio(struct ath_hw *ah, u8 *stomp_txprio) 4828c2ecf20Sopenharmony_ci{ 4838c2ecf20Sopenharmony_ci struct ath_btcoex_hw *btcoex = &ah->btcoex_hw; 4848c2ecf20Sopenharmony_ci int i; 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ci for (i = 0; i < ATH_BTCOEX_STOMP_MAX; i++) 4878c2ecf20Sopenharmony_ci btcoex->tx_prio[i] = stomp_txprio[i]; 4888c2ecf20Sopenharmony_ci} 4898c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_btcoex_set_concur_txprio); 490