| 1 |
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause |
| 2 |
/* Copyright(c) 2019-2022 Realtek Corporation |
| 3 |
*/ |
| 4 |
|
| 5 |
#include "chan.h" |
| 6 |
#include "coex.h" |
| 7 |
#include "debug.h" |
| 8 |
#include "fw.h" |
| 9 |
#include "mac.h" |
| 10 |
#include "phy.h" |
| 11 |
#include "reg.h" |
| 12 |
#include "rtw8852c.h" |
| 13 |
#include "rtw8852c_rfk.h" |
| 14 |
#include "rtw8852c_table.h" |
| 15 |
#include "sar.h" |
| 16 |
#include "util.h" |
| 17 |
|
| 18 |
#define RTW8852C_FW_FORMAT_MAX 2 |
| 19 |
#define RTW8852C_FW_BASENAME "rtw89/rtw8852c_fw" |
| 20 |
#define RTW8852C_MODULE_FIRMWARE \ |
| 21 |
RTW8852C_FW_BASENAME "-" __stringify(RTW8852C_FW_FORMAT_MAX) ".bin" |
| 22 |
|
| 23 |
static const struct rtw89_hfc_ch_cfg rtw8852c_hfc_chcfg_pcie[] = { |
| 24 |
{13, 1614, grp_0}, /* ACH 0 */ |
| 25 |
{13, 1614, grp_0}, /* ACH 1 */ |
| 26 |
{13, 1614, grp_0}, /* ACH 2 */ |
| 27 |
{13, 1614, grp_0}, /* ACH 3 */ |
| 28 |
{13, 1614, grp_1}, /* ACH 4 */ |
| 29 |
{13, 1614, grp_1}, /* ACH 5 */ |
| 30 |
{13, 1614, grp_1}, /* ACH 6 */ |
| 31 |
{13, 1614, grp_1}, /* ACH 7 */ |
| 32 |
{13, 1614, grp_0}, /* B0MGQ */ |
| 33 |
{13, 1614, grp_0}, /* B0HIQ */ |
| 34 |
{13, 1614, grp_1}, /* B1MGQ */ |
| 35 |
{13, 1614, grp_1}, /* B1HIQ */ |
| 36 |
{40, 0, 0} /* FWCMDQ */ |
| 37 |
}; |
| 38 |
|
| 39 |
static const struct rtw89_hfc_pub_cfg rtw8852c_hfc_pubcfg_pcie = { |
| 40 |
1614, /* Group 0 */ |
| 41 |
1614, /* Group 1 */ |
| 42 |
3228, /* Public Max */ |
| 43 |
0 /* WP threshold */ |
| 44 |
}; |
| 45 |
|
| 46 |
static const struct rtw89_hfc_param_ini rtw8852c_hfc_param_ini_pcie[] = { |
| 47 |
[RTW89_QTA_SCC] = {rtw8852c_hfc_chcfg_pcie, &rtw8852c_hfc_pubcfg_pcie, |
| 48 |
&rtw89_mac_size.hfc_preccfg_pcie, RTW89_HCIFC_POH}, |
| 49 |
[RTW89_QTA_DLFW] = {NULL, NULL, &rtw89_mac_size.hfc_preccfg_pcie, |
| 50 |
RTW89_HCIFC_POH}, |
| 51 |
[RTW89_QTA_INVALID] = {NULL}, |
| 52 |
}; |
| 53 |
|
| 54 |
static const struct rtw89_hfc_ch_cfg rtw8852c_hfc_chcfg_usb[] = { |
| 55 |
{18, 344, grp_0}, /* ACH 0 */ |
| 56 |
{0, 0, grp_0}, /* ACH 1 */ |
| 57 |
{18, 344, grp_0}, /* ACH 2 */ |
| 58 |
{0, 0, grp_0}, /* ACH 3 */ |
| 59 |
{18, 344, grp_0}, /* ACH 4 */ |
| 60 |
{0, 0, grp_0}, /* ACH 5 */ |
| 61 |
{18, 344, grp_0}, /* ACH 6 */ |
| 62 |
{0, 0, grp_0}, /* ACH 7 */ |
| 63 |
{18, 344, grp_0}, /* B0MGQ */ |
| 64 |
{0, 0, grp_0}, /* B0HIQ */ |
| 65 |
{18, 344, grp_0}, /* B1MGQ */ |
| 66 |
{0, 0, grp_0}, /* B1HIQ */ |
| 67 |
{0, 0, 0} /* FWCMDQ */ |
| 68 |
}; |
| 69 |
|
| 70 |
static const struct rtw89_hfc_pub_cfg rtw8852c_hfc_pubcfg_usb = { |
| 71 |
344, /* Group 0 */ |
| 72 |
0, /* Group 1 */ |
| 73 |
344, /* Public Max */ |
| 74 |
0 /* WP threshold */ |
| 75 |
}; |
| 76 |
|
| 77 |
static const struct rtw89_hfc_prec_cfg rtw8852c_hfc_preccfg_usb = { |
| 78 |
9, /* CH 0-11 pre-cost */ |
| 79 |
32, /* H2C pre-cost */ |
| 80 |
146, /* WP CH 0-7 pre-cost */ |
| 81 |
146, /* WP CH 8-11 pre-cost */ |
| 82 |
1, /* CH 0-11 full condition */ |
| 83 |
1, /* H2C full condition */ |
| 84 |
1, /* WP CH 0-7 full condition */ |
| 85 |
1, /* WP CH 8-11 full condition */ |
| 86 |
}; |
| 87 |
|
| 88 |
static const struct rtw89_hfc_param_ini rtw8852c_hfc_param_ini_usb[] = { |
| 89 |
[RTW89_QTA_SCC] = {rtw8852c_hfc_chcfg_usb, &rtw8852c_hfc_pubcfg_usb, |
| 90 |
&rtw8852c_hfc_preccfg_usb, RTW89_HCIFC_STF}, |
| 91 |
[RTW89_QTA_DLFW] = {NULL, NULL, |
| 92 |
&rtw8852c_hfc_preccfg_usb, RTW89_HCIFC_STF}, |
| 93 |
[RTW89_QTA_INVALID] = {NULL}, |
| 94 |
}; |
| 95 |
|
| 96 |
static const struct rtw89_dle_mem rtw8852c_dle_mem_pcie[] = { |
| 97 |
[RTW89_QTA_SCC] = {RTW89_QTA_SCC, &rtw89_mac_size.wde_size19, |
| 98 |
&rtw89_mac_size.ple_size19, &rtw89_mac_size.wde_qt18, |
| 99 |
&rtw89_mac_size.wde_qt18, &rtw89_mac_size.ple_qt46, |
| 100 |
&rtw89_mac_size.ple_qt47}, |
| 101 |
[RTW89_QTA_DLFW] = {RTW89_QTA_DLFW, &rtw89_mac_size.wde_size18, |
| 102 |
&rtw89_mac_size.ple_size18, &rtw89_mac_size.wde_qt17, |
| 103 |
&rtw89_mac_size.wde_qt17, &rtw89_mac_size.ple_qt44, |
| 104 |
&rtw89_mac_size.ple_qt45}, |
| 105 |
[RTW89_QTA_INVALID] = {RTW89_QTA_INVALID, NULL, NULL, NULL, NULL, NULL, |
| 106 |
NULL}, |
| 107 |
}; |
| 108 |
|
| 109 |
static const struct rtw89_dle_mem rtw8852c_dle_mem_usb2[] = { |
| 110 |
[RTW89_QTA_SCC] = {RTW89_QTA_SCC, &rtw89_mac_size.wde_size31, |
| 111 |
&rtw89_mac_size.ple_size34, &rtw89_mac_size.wde_qt31, |
| 112 |
&rtw89_mac_size.wde_qt31, &rtw89_mac_size.ple_qt78, |
| 113 |
&rtw89_mac_size.ple_qt79}, |
| 114 |
[RTW89_QTA_DLFW] = {RTW89_QTA_DLFW, &rtw89_mac_size.wde_size18, |
| 115 |
&rtw89_mac_size.ple_size18, &rtw89_mac_size.wde_qt17, |
| 116 |
&rtw89_mac_size.wde_qt17, &rtw89_mac_size.ple_qt44, |
| 117 |
&rtw89_mac_size.ple_qt45}, |
| 118 |
[RTW89_QTA_INVALID] = {RTW89_QTA_INVALID, NULL, NULL, NULL, NULL, NULL, |
| 119 |
NULL}, |
| 120 |
}; |
| 121 |
|
| 122 |
static const struct rtw89_dle_mem rtw8852c_dle_mem_usb3[] = { |
| 123 |
[RTW89_QTA_SCC] = {RTW89_QTA_SCC, &rtw89_mac_size.wde_size17, |
| 124 |
&rtw89_mac_size.ple_size17, &rtw89_mac_size.wde_qt16, |
| 125 |
&rtw89_mac_size.wde_qt16, &rtw89_mac_size.ple_qt42, |
| 126 |
&rtw89_mac_size.ple_qt43}, |
| 127 |
[RTW89_QTA_DLFW] = {RTW89_QTA_DLFW, &rtw89_mac_size.wde_size18, |
| 128 |
&rtw89_mac_size.ple_size18, &rtw89_mac_size.wde_qt17, |
| 129 |
&rtw89_mac_size.wde_qt17, &rtw89_mac_size.ple_qt44, |
| 130 |
&rtw89_mac_size.ple_qt45}, |
| 131 |
[RTW89_QTA_INVALID] = {RTW89_QTA_INVALID, NULL, NULL, NULL, NULL, NULL, |
| 132 |
NULL}, |
| 133 |
}; |
| 134 |
|
| 135 |
static const u32 rtw8852c_h2c_regs[RTW89_H2CREG_MAX] = { |
| 136 |
R_AX_H2CREG_DATA0_V1, R_AX_H2CREG_DATA1_V1, R_AX_H2CREG_DATA2_V1, |
| 137 |
R_AX_H2CREG_DATA3_V1 |
| 138 |
}; |
| 139 |
|
| 140 |
static const u32 rtw8852c_c2h_regs[RTW89_H2CREG_MAX] = { |
| 141 |
R_AX_C2HREG_DATA0_V1, R_AX_C2HREG_DATA1_V1, R_AX_C2HREG_DATA2_V1, |
| 142 |
R_AX_C2HREG_DATA3_V1 |
| 143 |
}; |
| 144 |
|
| 145 |
static const u32 rtw8852c_wow_wakeup_regs[RTW89_WOW_REASON_NUM] = { |
| 146 |
R_AX_C2HREG_DATA3_V1 + 3, R_AX_DBG_WOW, |
| 147 |
}; |
| 148 |
|
| 149 |
static const struct rtw89_page_regs rtw8852c_page_regs = { |
| 150 |
.hci_fc_ctrl = R_AX_HCI_FC_CTRL_V1, |
| 151 |
.ch_page_ctrl = R_AX_CH_PAGE_CTRL_V1, |
| 152 |
.ach_page_ctrl = R_AX_ACH0_PAGE_CTRL_V1, |
| 153 |
.ach_page_info = R_AX_ACH0_PAGE_INFO_V1, |
| 154 |
.pub_page_info3 = R_AX_PUB_PAGE_INFO3_V1, |
| 155 |
.pub_page_ctrl1 = R_AX_PUB_PAGE_CTRL1_V1, |
| 156 |
.pub_page_ctrl2 = R_AX_PUB_PAGE_CTRL2_V1, |
| 157 |
.pub_page_info1 = R_AX_PUB_PAGE_INFO1_V1, |
| 158 |
.pub_page_info2 = R_AX_PUB_PAGE_INFO2_V1, |
| 159 |
.wp_page_ctrl1 = R_AX_WP_PAGE_CTRL1_V1, |
| 160 |
.wp_page_ctrl2 = R_AX_WP_PAGE_CTRL2_V1, |
| 161 |
.wp_page_info1 = R_AX_WP_PAGE_INFO1_V1, |
| 162 |
}; |
| 163 |
|
| 164 |
static const struct rtw89_reg_def rtw8852c_dcfo_comp = { |
| 165 |
R_DCFO_COMP_S0_V1, B_DCFO_COMP_S0_V1_MSK |
| 166 |
}; |
| 167 |
|
| 168 |
static const struct rtw89_imr_info rtw8852c_imr_info = { |
| 169 |
.wdrls_imr_set = B_AX_WDRLS_IMR_SET_V1, |
| 170 |
.wsec_imr_reg = R_AX_SEC_ERROR_FLAG_IMR, |
| 171 |
.wsec_imr_set = B_AX_TX_HANG_IMR | B_AX_RX_HANG_IMR, |
| 172 |
.mpdu_tx_imr_set = B_AX_MPDU_TX_IMR_SET_V1, |
| 173 |
.mpdu_rx_imr_set = B_AX_MPDU_RX_IMR_SET_V1, |
| 174 |
.sta_sch_imr_set = B_AX_STA_SCHEDULER_IMR_SET, |
| 175 |
.txpktctl_imr_b0_reg = R_AX_TXPKTCTL_B0_ERRFLAG_IMR, |
| 176 |
.txpktctl_imr_b0_clr = B_AX_TXPKTCTL_IMR_B0_CLR_V1, |
| 177 |
.txpktctl_imr_b0_set = B_AX_TXPKTCTL_IMR_B0_SET_V1, |
| 178 |
.txpktctl_imr_b1_reg = R_AX_TXPKTCTL_B1_ERRFLAG_IMR, |
| 179 |
.txpktctl_imr_b1_clr = B_AX_TXPKTCTL_IMR_B1_CLR_V1, |
| 180 |
.txpktctl_imr_b1_set = B_AX_TXPKTCTL_IMR_B1_SET_V1, |
| 181 |
.wde_imr_clr = B_AX_WDE_IMR_CLR_V1, |
| 182 |
.wde_imr_set = B_AX_WDE_IMR_SET_V1, |
| 183 |
.ple_imr_clr = B_AX_PLE_IMR_CLR_V1, |
| 184 |
.ple_imr_set = B_AX_PLE_IMR_SET_V1, |
| 185 |
.host_disp_imr_clr = B_AX_HOST_DISP_IMR_CLR_V1, |
| 186 |
.host_disp_imr_set = B_AX_HOST_DISP_IMR_SET_V1, |
| 187 |
.cpu_disp_imr_clr = B_AX_CPU_DISP_IMR_CLR_V1, |
| 188 |
.cpu_disp_imr_set = B_AX_CPU_DISP_IMR_SET_V1, |
| 189 |
.other_disp_imr_clr = B_AX_OTHER_DISP_IMR_CLR_V1, |
| 190 |
.other_disp_imr_set = B_AX_OTHER_DISP_IMR_SET_V1, |
| 191 |
.bbrpt_com_err_imr_reg = R_AX_BBRPT_COM_ERR_IMR, |
| 192 |
.bbrpt_chinfo_err_imr_reg = R_AX_BBRPT_CHINFO_ERR_IMR, |
| 193 |
.bbrpt_err_imr_set = R_AX_BBRPT_CHINFO_IMR_SET_V1, |
| 194 |
.bbrpt_dfs_err_imr_reg = R_AX_BBRPT_DFS_ERR_IMR, |
| 195 |
.ptcl_imr_clr = B_AX_PTCL_IMR_CLR_V1, |
| 196 |
.ptcl_imr_set = B_AX_PTCL_IMR_SET_V1, |
| 197 |
.cdma_imr_0_reg = R_AX_RX_ERR_FLAG_IMR, |
| 198 |
.cdma_imr_0_clr = B_AX_RX_ERR_IMR_CLR_V1, |
| 199 |
.cdma_imr_0_set = B_AX_RX_ERR_IMR_SET_V1, |
| 200 |
.cdma_imr_1_reg = R_AX_TX_ERR_FLAG_IMR, |
| 201 |
.cdma_imr_1_clr = B_AX_TX_ERR_IMR_CLR_V1, |
| 202 |
.cdma_imr_1_set = B_AX_TX_ERR_IMR_SET_V1, |
| 203 |
.phy_intf_imr_reg = R_AX_PHYINFO_ERR_IMR_V1, |
| 204 |
.phy_intf_imr_clr = B_AX_PHYINFO_IMR_CLR_V1, |
| 205 |
.phy_intf_imr_set = B_AX_PHYINFO_IMR_SET_V1, |
| 206 |
.rmac_imr_reg = R_AX_RX_ERR_IMR, |
| 207 |
.rmac_imr_clr = B_AX_RMAC_IMR_CLR_V1, |
| 208 |
.rmac_imr_set = B_AX_RMAC_IMR_SET_V1, |
| 209 |
.tmac_imr_reg = R_AX_TRXPTCL_ERROR_INDICA_MASK, |
| 210 |
.tmac_imr_clr = B_AX_TMAC_IMR_CLR_V1, |
| 211 |
.tmac_imr_set = B_AX_TMAC_IMR_SET_V1, |
| 212 |
}; |
| 213 |
|
| 214 |
static const struct rtw89_rrsr_cfgs rtw8852c_rrsr_cfgs = { |
| 215 |
.ref_rate = {R_AX_TRXPTCL_RRSR_CTL_0, B_AX_WMAC_RESP_REF_RATE_SEL, 0}, |
| 216 |
.rsc = {R_AX_PTCL_RRSR1, B_AX_RSC_MASK, 2}, |
| 217 |
}; |
| 218 |
|
| 219 |
static const struct rtw89_rfkill_regs rtw8852c_rfkill_regs = { |
| 220 |
.pinmux = {R_AX_GPIO8_15_FUNC_SEL, |
| 221 |
B_AX_PINMUX_GPIO9_FUNC_SEL_MASK, |
| 222 |
0xf}, |
| 223 |
.mode = {R_AX_GPIO_EXT_CTRL + 2, |
| 224 |
(B_AX_GPIO_MOD_9 | B_AX_GPIO_IO_SEL_9) >> 16, |
| 225 |
0x0}, |
| 226 |
}; |
| 227 |
|
| 228 |
static const struct rtw89_dig_regs rtw8852c_dig_regs = { |
| 229 |
.seg0_pd_reg = R_SEG0R_PD, |
| 230 |
.pd_lower_bound_mask = B_SEG0R_PD_LOWER_BOUND_MSK, |
| 231 |
.pd_spatial_reuse_en = B_SEG0R_PD_SPATIAL_REUSE_EN_MSK, |
| 232 |
.bmode_pd_reg = R_BMODE_PDTH_EN_V1, |
| 233 |
.bmode_cca_rssi_limit_en = B_BMODE_PDTH_LIMIT_EN_MSK_V1, |
| 234 |
.bmode_pd_lower_bound_reg = R_BMODE_PDTH_V1, |
| 235 |
.bmode_rssi_nocca_low_th_mask = B_BMODE_PDTH_LOWER_BOUND_MSK_V1, |
| 236 |
.p0_lna_init = {R_PATH0_LNA_INIT_V1, B_PATH0_LNA_INIT_IDX_MSK}, |
| 237 |
.p1_lna_init = {R_PATH1_LNA_INIT_V1, B_PATH1_LNA_INIT_IDX_MSK}, |
| 238 |
.p0_tia_init = {R_PATH0_TIA_INIT_V1, B_PATH0_TIA_INIT_IDX_MSK_V1}, |
| 239 |
.p1_tia_init = {R_PATH1_TIA_INIT_V1, B_PATH1_TIA_INIT_IDX_MSK_V1}, |
| 240 |
.p0_rxb_init = {R_PATH0_RXB_INIT_V1, B_PATH0_RXB_INIT_IDX_MSK_V1}, |
| 241 |
.p1_rxb_init = {R_PATH1_RXB_INIT_V1, B_PATH1_RXB_INIT_IDX_MSK_V1}, |
| 242 |
.p0_p20_pagcugc_en = {R_PATH0_P20_FOLLOW_BY_PAGCUGC_V1, |
| 243 |
B_PATH0_P20_FOLLOW_BY_PAGCUGC_EN_MSK}, |
| 244 |
.p0_s20_pagcugc_en = {R_PATH0_S20_FOLLOW_BY_PAGCUGC_V1, |
| 245 |
B_PATH0_S20_FOLLOW_BY_PAGCUGC_EN_MSK}, |
| 246 |
.p1_p20_pagcugc_en = {R_PATH1_P20_FOLLOW_BY_PAGCUGC_V1, |
| 247 |
B_PATH1_P20_FOLLOW_BY_PAGCUGC_EN_MSK}, |
| 248 |
.p1_s20_pagcugc_en = {R_PATH1_S20_FOLLOW_BY_PAGCUGC_V1, |
| 249 |
B_PATH1_S20_FOLLOW_BY_PAGCUGC_EN_MSK}, |
| 250 |
}; |
| 251 |
|
| 252 |
static const struct rtw89_edcca_regs rtw8852c_edcca_regs = { |
| 253 |
.edcca_level = R_SEG0R_EDCCA_LVL, |
| 254 |
.edcca_mask = B_EDCCA_LVL_MSK0, |
| 255 |
.edcca_p_mask = B_EDCCA_LVL_MSK1, |
| 256 |
.ppdu_level = R_SEG0R_EDCCA_LVL, |
| 257 |
.ppdu_mask = B_EDCCA_LVL_MSK3, |
| 258 |
.p = {{ |
| 259 |
.rpt_a = R_EDCCA_RPT_A, |
| 260 |
.rpt_b = R_EDCCA_RPT_B, |
| 261 |
.rpt_sel = R_EDCCA_RPT_SEL, |
| 262 |
.rpt_sel_mask = B_EDCCA_RPT_SEL_MSK, |
| 263 |
}, { |
| 264 |
.rpt_a = R_EDCCA_RPT_P1_A, |
| 265 |
.rpt_b = R_EDCCA_RPT_P1_B, |
| 266 |
.rpt_sel = R_EDCCA_RPT_SEL, |
| 267 |
.rpt_sel_mask = B_EDCCA_RPT_SEL_P1_MSK, |
| 268 |
}}, |
| 269 |
.tx_collision_t2r_st = R_TX_COLLISION_T2R_ST, |
| 270 |
.tx_collision_t2r_st_mask = B_TX_COLLISION_T2R_ST_M, |
| 271 |
}; |
| 272 |
|
| 273 |
static void rtw8852c_ctrl_btg_bt_rx(struct rtw89_dev *rtwdev, bool en, |
| 274 |
enum rtw89_phy_idx phy_idx); |
| 275 |
|
| 276 |
static void rtw8852c_ctrl_tx_path_tmac(struct rtw89_dev *rtwdev, u8 tx_path, |
| 277 |
enum rtw89_mac_idx mac_idx); |
| 278 |
|
| 279 |
static int rtw8852c_pwr_on_func(struct rtw89_dev *rtwdev) |
| 280 |
{ |
| 281 |
u32 val32; |
| 282 |
int ret; |
| 283 |
|
| 284 |
val32 = rtw89_read32_mask(rtwdev, R_AX_SYS_STATUS1, B_AX_PAD_HCI_SEL_V2_MASK); |
| 285 |
if (val32 == MAC_AX_HCI_SEL_PCIE_USB || |
| 286 |
rtwdev->hci.type == RTW89_HCI_TYPE_USB) |
| 287 |
rtw89_write32_set(rtwdev, R_AX_LDO_AON_CTRL0, B_AX_PD_REGU_L); |
| 288 |
|
| 289 |
rtw89_write32_clr(rtwdev, R_AX_SYS_PW_CTRL, B_AX_AFSM_WLSUS_EN | |
| 290 |
B_AX_AFSM_PCIE_SUS_EN); |
| 291 |
rtw89_write32_set(rtwdev, R_AX_SYS_PW_CTRL, B_AX_DIS_WLBT_PDNSUSEN_SOPC); |
| 292 |
rtw89_write32_set(rtwdev, R_AX_WLLPS_CTRL, B_AX_DIS_WLBT_LPSEN_LOPC); |
| 293 |
rtw89_write32_clr(rtwdev, R_AX_SYS_PW_CTRL, B_AX_APDM_HPDN); |
| 294 |
rtw89_write32_clr(rtwdev, R_AX_SYS_PW_CTRL, B_AX_APFM_SWLPS); |
| 295 |
|
| 296 |
rtw89_write32_mask(rtwdev, R_AX_SPS_DIG_ON_CTRL0, |
| 297 |
B_AX_OCP_L1_MASK, 0x7); |
| 298 |
|
| 299 |
ret = read_poll_timeout(rtw89_read32, val32, val32 & B_AX_RDY_SYSPWR, |
| 300 |
1000, 20000, false, rtwdev, R_AX_SYS_PW_CTRL); |
| 301 |
if (ret) |
| 302 |
return ret; |
| 303 |
|
| 304 |
rtw89_write32_set(rtwdev, R_AX_SYS_PW_CTRL, B_AX_EN_WLON); |
| 305 |
rtw89_write32_set(rtwdev, R_AX_SYS_PW_CTRL, B_AX_APFN_ONMAC); |
| 306 |
|
| 307 |
ret = read_poll_timeout(rtw89_read32, val32, !(val32 & B_AX_APFN_ONMAC), |
| 308 |
1000, 20000, false, rtwdev, R_AX_SYS_PW_CTRL); |
| 309 |
if (ret) |
| 310 |
return ret; |
| 311 |
|
| 312 |
rtw89_write8_set(rtwdev, R_AX_PLATFORM_ENABLE, B_AX_PLATFORM_EN); |
| 313 |
rtw89_write8_clr(rtwdev, R_AX_PLATFORM_ENABLE, B_AX_PLATFORM_EN); |
| 314 |
rtw89_write8_set(rtwdev, R_AX_PLATFORM_ENABLE, B_AX_PLATFORM_EN); |
| 315 |
rtw89_write8_clr(rtwdev, R_AX_PLATFORM_ENABLE, B_AX_PLATFORM_EN); |
| 316 |
|
| 317 |
rtw89_write8_set(rtwdev, R_AX_PLATFORM_ENABLE, B_AX_PLATFORM_EN); |
| 318 |
|
| 319 |
if (rtwdev->hci.type == RTW89_HCI_TYPE_PCIE) |
| 320 |
rtw89_write32_clr(rtwdev, R_AX_SYS_SDIO_CTRL, B_AX_PCIE_CALIB_EN_V1); |
| 321 |
|
| 322 |
rtw89_write32_clr(rtwdev, R_AX_SYS_ISO_CTRL_EXTEND, B_AX_CMAC1_FEN); |
| 323 |
rtw89_write32_set(rtwdev, R_AX_SYS_ISO_CTRL_EXTEND, B_AX_R_SYM_ISO_CMAC12PP); |
| 324 |
rtw89_write32_clr(rtwdev, R_AX_AFE_CTRL1, B_AX_R_SYM_WLCMAC1_P4_PC_EN | |
| 325 |
B_AX_R_SYM_WLCMAC1_P3_PC_EN | |
| 326 |
B_AX_R_SYM_WLCMAC1_P2_PC_EN | |
| 327 |
B_AX_R_SYM_WLCMAC1_P1_PC_EN | |
| 328 |
B_AX_R_SYM_WLCMAC1_PC_EN); |
| 329 |
rtw89_write32_set(rtwdev, R_AX_SYS_ADIE_PAD_PWR_CTRL, B_AX_SYM_PADPDN_WL_PTA_1P3); |
| 330 |
|
| 331 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, |
| 332 |
XTAL_SI_GND_SHDN_WL, XTAL_SI_GND_SHDN_WL); |
| 333 |
if (ret) |
| 334 |
return ret; |
| 335 |
|
| 336 |
rtw89_write32_set(rtwdev, R_AX_SYS_ADIE_PAD_PWR_CTRL, B_AX_SYM_PADPDN_WL_RFC_1P3); |
| 337 |
|
| 338 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, |
| 339 |
XTAL_SI_SHDN_WL, XTAL_SI_SHDN_WL); |
| 340 |
if (ret) |
| 341 |
return ret; |
| 342 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, XTAL_SI_OFF_WEI, |
| 343 |
XTAL_SI_OFF_WEI); |
| 344 |
if (ret) |
| 345 |
return ret; |
| 346 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, XTAL_SI_OFF_EI, |
| 347 |
XTAL_SI_OFF_EI); |
| 348 |
if (ret) |
| 349 |
return ret; |
| 350 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_RFC2RF); |
| 351 |
if (ret) |
| 352 |
return ret; |
| 353 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, XTAL_SI_PON_WEI, |
| 354 |
XTAL_SI_PON_WEI); |
| 355 |
if (ret) |
| 356 |
return ret; |
| 357 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, XTAL_SI_PON_EI, |
| 358 |
XTAL_SI_PON_EI); |
| 359 |
if (ret) |
| 360 |
return ret; |
| 361 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_SRAM2RFC); |
| 362 |
if (ret) |
| 363 |
return ret; |
| 364 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_XTAL_XMD_2, 0x10, XTAL_SI_LDO_LPS); |
| 365 |
if (ret) |
| 366 |
return ret; |
| 367 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_XTAL_XMD_4, 0, XTAL_SI_LPS_CAP); |
| 368 |
if (ret) |
| 369 |
return ret; |
| 370 |
|
| 371 |
rtw89_write32_set(rtwdev, R_AX_PMC_DBG_CTRL2, B_AX_SYSON_DIS_PMCR_AX_WRMSK); |
| 372 |
rtw89_write32_set(rtwdev, R_AX_SYS_ISO_CTRL, B_AX_ISO_EB2CORE); |
| 373 |
rtw89_write32_clr(rtwdev, R_AX_SYS_ISO_CTRL, B_AX_PWC_EV2EF_B15); |
| 374 |
|
| 375 |
fsleep(1000); |
| 376 |
|
| 377 |
rtw89_write32_clr(rtwdev, R_AX_SYS_ISO_CTRL, B_AX_PWC_EV2EF_B14); |
| 378 |
rtw89_write32_clr(rtwdev, R_AX_PMC_DBG_CTRL2, B_AX_SYSON_DIS_PMCR_AX_WRMSK); |
| 379 |
|
| 380 |
if (rtwdev->hci.type == RTW89_HCI_TYPE_PCIE) |
| 381 |
rtw89_write32_set(rtwdev, R_AX_GPIO0_15_EECS_EESK_LED1_PULL_LOW_EN, |
| 382 |
B_AX_EECS_PULL_LOW_EN | B_AX_EESK_PULL_LOW_EN | |
| 383 |
B_AX_LED1_PULL_LOW_EN); |
| 384 |
|
| 385 |
rtw89_write32_set(rtwdev, R_AX_DMAC_FUNC_EN, |
| 386 |
B_AX_MAC_FUNC_EN | B_AX_DMAC_FUNC_EN | B_AX_MPDU_PROC_EN | |
| 387 |
B_AX_WD_RLS_EN | B_AX_DLE_WDE_EN | B_AX_TXPKT_CTRL_EN | |
| 388 |
B_AX_STA_SCH_EN | B_AX_DLE_PLE_EN | B_AX_PKT_BUF_EN | |
| 389 |
B_AX_DMAC_TBL_EN | B_AX_PKT_IN_EN | B_AX_DLE_CPUIO_EN | |
| 390 |
B_AX_DISPATCHER_EN | B_AX_BBRPT_EN | B_AX_MAC_SEC_EN | |
| 391 |
B_AX_MAC_UN_EN | B_AX_H_AXIDMA_EN); |
| 392 |
|
| 393 |
rtw89_write32_set(rtwdev, R_AX_CMAC_FUNC_EN, |
| 394 |
B_AX_CMAC_EN | B_AX_CMAC_TXEN | B_AX_CMAC_RXEN | |
| 395 |
B_AX_FORCE_CMACREG_GCKEN | B_AX_PHYINTF_EN | |
| 396 |
B_AX_CMAC_DMA_EN | B_AX_PTCLTOP_EN | B_AX_SCHEDULER_EN | |
| 397 |
B_AX_TMAC_EN | B_AX_RMAC_EN); |
| 398 |
|
| 399 |
rtw89_write32_mask(rtwdev, R_AX_LED1_FUNC_SEL, B_AX_PINMUX_EESK_FUNC_SEL_V1_MASK, |
| 400 |
PINMUX_EESK_FUNC_SEL_BT_LOG); |
| 401 |
|
| 402 |
return 0; |
| 403 |
} |
| 404 |
|
| 405 |
static int rtw8852c_pwr_off_func(struct rtw89_dev *rtwdev) |
| 406 |
{ |
| 407 |
u32 val32; |
| 408 |
int ret; |
| 409 |
|
| 410 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, XTAL_SI_RFC2RF, |
| 411 |
XTAL_SI_RFC2RF); |
| 412 |
if (ret) |
| 413 |
return ret; |
| 414 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_OFF_EI); |
| 415 |
if (ret) |
| 416 |
return ret; |
| 417 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_OFF_WEI); |
| 418 |
if (ret) |
| 419 |
return ret; |
| 420 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_WL_RFC_S0, 0, XTAL_SI_RF00); |
| 421 |
if (ret) |
| 422 |
return ret; |
| 423 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_WL_RFC_S1, 0, XTAL_SI_RF10); |
| 424 |
if (ret) |
| 425 |
return ret; |
| 426 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, XTAL_SI_SRAM2RFC, |
| 427 |
XTAL_SI_SRAM2RFC); |
| 428 |
if (ret) |
| 429 |
return ret; |
| 430 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_PON_EI); |
| 431 |
if (ret) |
| 432 |
return ret; |
| 433 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_PON_WEI); |
| 434 |
if (ret) |
| 435 |
return ret; |
| 436 |
|
| 437 |
rtw89_write32_set(rtwdev, R_AX_SYS_PW_CTRL, B_AX_EN_WLON); |
| 438 |
rtw89_write32_clr(rtwdev, R_AX_WLRF_CTRL, B_AX_AFC_AFEDIG); |
| 439 |
rtw89_write8_clr(rtwdev, R_AX_SYS_FUNC_EN, B_AX_FEN_BB_GLB_RSTN | B_AX_FEN_BBRSTB); |
| 440 |
rtw89_write32_clr(rtwdev, R_AX_SYS_ISO_CTRL_EXTEND, |
| 441 |
B_AX_R_SYM_FEN_WLBBGLB_1 | B_AX_R_SYM_FEN_WLBBFUN_1); |
| 442 |
rtw89_write32_clr(rtwdev, R_AX_SYS_ADIE_PAD_PWR_CTRL, B_AX_SYM_PADPDN_WL_RFC_1P3); |
| 443 |
|
| 444 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_SHDN_WL); |
| 445 |
if (ret) |
| 446 |
return ret; |
| 447 |
|
| 448 |
rtw89_write32_clr(rtwdev, R_AX_SYS_ADIE_PAD_PWR_CTRL, B_AX_SYM_PADPDN_WL_PTA_1P3); |
| 449 |
|
| 450 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_GND_SHDN_WL); |
| 451 |
if (ret) |
| 452 |
return ret; |
| 453 |
|
| 454 |
rtw89_write32_set(rtwdev, R_AX_SYS_PW_CTRL, B_AX_APFM_OFFMAC); |
| 455 |
|
| 456 |
ret = read_poll_timeout(rtw89_read32, val32, !(val32 & B_AX_APFM_OFFMAC), |
| 457 |
1000, 20000, false, rtwdev, R_AX_SYS_PW_CTRL); |
| 458 |
if (ret) |
| 459 |
return ret; |
| 460 |
|
| 461 |
if (rtwdev->hci.type == RTW89_HCI_TYPE_PCIE) |
| 462 |
rtw89_write32(rtwdev, R_AX_WLLPS_CTRL, SW_LPS_OPTION); |
| 463 |
else if (rtwdev->hci.type == RTW89_HCI_TYPE_USB) |
| 464 |
rtw89_write32_clr(rtwdev, R_AX_SYS_PW_CTRL, B_AX_SOP_EDSWR); |
| 465 |
|
| 466 |
rtw89_write32_set(rtwdev, R_AX_SYS_PW_CTRL, B_AX_XTAL_OFF_A_DIE); |
| 467 |
rtw89_write32_set(rtwdev, R_AX_SYS_SWR_CTRL1, B_AX_SYM_CTRL_SPS_PWMFREQ); |
| 468 |
rtw89_write32_mask(rtwdev, R_AX_SPS_DIG_ON_CTRL0, |
| 469 |
B_AX_REG_ZCDC_H_MASK, 0x3); |
| 470 |
|
| 471 |
if (rtwdev->hci.type == RTW89_HCI_TYPE_PCIE) { |
| 472 |
rtw89_write32_set(rtwdev, R_AX_SYS_PW_CTRL, B_AX_APFM_SWLPS); |
| 473 |
} else if (rtwdev->hci.type == RTW89_HCI_TYPE_USB) { |
| 474 |
val32 = rtw89_read32(rtwdev, R_AX_SYS_PW_CTRL); |
| 475 |
val32 &= ~B_AX_AFSM_PCIE_SUS_EN; |
| 476 |
val32 |= B_AX_AFSM_WLSUS_EN; |
| 477 |
rtw89_write32(rtwdev, R_AX_SYS_PW_CTRL, val32); |
| 478 |
} |
| 479 |
|
| 480 |
return 0; |
| 481 |
} |
| 482 |
|
| 483 |
static void rtw8852c_efuse_parsing_tssi(struct rtw89_dev *rtwdev, |
| 484 |
struct rtw8852c_efuse *map) |
| 485 |
{ |
| 486 |
struct rtw89_tssi_info *tssi = &rtwdev->tssi; |
| 487 |
struct rtw8852c_tssi_offset *ofst[] = {&map->path_a_tssi, &map->path_b_tssi}; |
| 488 |
u8 *bw40_1s_tssi_6g_ofst[] = {map->bw40_1s_tssi_6g_a, map->bw40_1s_tssi_6g_b}; |
| 489 |
u8 i, j; |
| 490 |
|
| 491 |
tssi->thermal[RF_PATH_A] = map->path_a_therm; |
| 492 |
tssi->thermal[RF_PATH_B] = map->path_b_therm; |
| 493 |
|
| 494 |
for (i = 0; i < RF_PATH_NUM_8852C; i++) { |
| 495 |
memcpy(tssi->tssi_cck[i], ofst[i]->cck_tssi, |
| 496 |
sizeof(ofst[i]->cck_tssi)); |
| 497 |
|
| 498 |
for (j = 0; j < TSSI_CCK_CH_GROUP_NUM; j++) |
| 499 |
rtw89_debug(rtwdev, RTW89_DBG_TSSI, |
| 500 |
"[TSSI][EFUSE] path=%d cck[%d]=0x%x\n", |
| 501 |
i, j, tssi->tssi_cck[i][j]); |
| 502 |
|
| 503 |
memcpy(tssi->tssi_mcs[i], ofst[i]->bw40_tssi, |
| 504 |
sizeof(ofst[i]->bw40_tssi)); |
| 505 |
memcpy(tssi->tssi_mcs[i] + TSSI_MCS_2G_CH_GROUP_NUM, |
| 506 |
ofst[i]->bw40_1s_tssi_5g, sizeof(ofst[i]->bw40_1s_tssi_5g)); |
| 507 |
memcpy(tssi->tssi_6g_mcs[i], bw40_1s_tssi_6g_ofst[i], |
| 508 |
sizeof(tssi->tssi_6g_mcs[i])); |
| 509 |
|
| 510 |
for (j = 0; j < TSSI_MCS_CH_GROUP_NUM; j++) |
| 511 |
rtw89_debug(rtwdev, RTW89_DBG_TSSI, |
| 512 |
"[TSSI][EFUSE] path=%d mcs[%d]=0x%x\n", |
| 513 |
i, j, tssi->tssi_mcs[i][j]); |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
static bool _decode_efuse_gain(u8 data, s8 *high, s8 *low) |
| 518 |
{ |
| 519 |
if (high) |
| 520 |
*high = sign_extend32(FIELD_GET(GENMASK(7, 4), data), 3); |
| 521 |
if (low) |
| 522 |
*low = sign_extend32(FIELD_GET(GENMASK(3, 0), data), 3); |
| 523 |
|
| 524 |
return data != 0xff; |
| 525 |
} |
| 526 |
|
| 527 |
static void rtw8852c_efuse_parsing_gain_offset(struct rtw89_dev *rtwdev, |
| 528 |
struct rtw8852c_efuse *map) |
| 529 |
{ |
| 530 |
struct rtw89_phy_efuse_gain *gain = &rtwdev->efuse_gain; |
| 531 |
bool valid = false; |
| 532 |
|
| 533 |
valid |= _decode_efuse_gain(map->rx_gain_2g_cck, |
| 534 |
&gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_2G_CCK], |
| 535 |
&gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_2G_CCK]); |
| 536 |
valid |= _decode_efuse_gain(map->rx_gain_2g_ofdm, |
| 537 |
&gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_2G_OFDM], |
| 538 |
&gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_2G_OFDM]); |
| 539 |
valid |= _decode_efuse_gain(map->rx_gain_5g_low, |
| 540 |
&gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_5G_LOW], |
| 541 |
&gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_5G_LOW]); |
| 542 |
valid |= _decode_efuse_gain(map->rx_gain_5g_mid, |
| 543 |
&gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_5G_MID], |
| 544 |
&gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_5G_MID]); |
| 545 |
valid |= _decode_efuse_gain(map->rx_gain_5g_high, |
| 546 |
&gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_5G_HIGH], |
| 547 |
&gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_5G_HIGH]); |
| 548 |
valid |= _decode_efuse_gain(map->rx_gain_6g_l0, |
| 549 |
&gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_6G_L0], |
| 550 |
&gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_6G_L0]); |
| 551 |
valid |= _decode_efuse_gain(map->rx_gain_6g_l1, |
| 552 |
&gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_6G_L1], |
| 553 |
&gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_6G_L1]); |
| 554 |
valid |= _decode_efuse_gain(map->rx_gain_6g_m0, |
| 555 |
&gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_6G_M0], |
| 556 |
&gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_6G_M0]); |
| 557 |
valid |= _decode_efuse_gain(map->rx_gain_6g_m1, |
| 558 |
&gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_6G_M1], |
| 559 |
&gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_6G_M1]); |
| 560 |
valid |= _decode_efuse_gain(map->rx_gain_6g_h0, |
| 561 |
&gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_6G_H0], |
| 562 |
&gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_6G_H0]); |
| 563 |
valid |= _decode_efuse_gain(map->rx_gain_6g_h1, |
| 564 |
&gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_6G_H1], |
| 565 |
&gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_6G_H1]); |
| 566 |
valid |= _decode_efuse_gain(map->rx_gain_6g_uh0, |
| 567 |
&gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_6G_UH0], |
| 568 |
&gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_6G_UH0]); |
| 569 |
valid |= _decode_efuse_gain(map->rx_gain_6g_uh1, |
| 570 |
&gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_6G_UH1], |
| 571 |
&gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_6G_UH1]); |
| 572 |
|
| 573 |
gain->offset_valid = valid; |
| 574 |
} |
| 575 |
|
| 576 |
static int rtw8852c_read_efuse(struct rtw89_dev *rtwdev, u8 *log_map, |
| 577 |
enum rtw89_efuse_block block) |
| 578 |
{ |
| 579 |
struct rtw89_efuse *efuse = &rtwdev->efuse; |
| 580 |
struct rtw8852c_efuse *map; |
| 581 |
|
| 582 |
map = (struct rtw8852c_efuse *)log_map; |
| 583 |
|
| 584 |
efuse->country_code[0] = map->country_code[0]; |
| 585 |
efuse->country_code[1] = map->country_code[1]; |
| 586 |
rtw8852c_efuse_parsing_tssi(rtwdev, map); |
| 587 |
rtw8852c_efuse_parsing_gain_offset(rtwdev, map); |
| 588 |
|
| 589 |
switch (rtwdev->hci.type) { |
| 590 |
case RTW89_HCI_TYPE_PCIE: |
| 591 |
ether_addr_copy(efuse->addr, map->e.mac_addr); |
| 592 |
break; |
| 593 |
case RTW89_HCI_TYPE_USB: |
| 594 |
ether_addr_copy(efuse->addr, map->u.mac_addr); |
| 595 |
break; |
| 596 |
default: |
| 597 |
return -ENOTSUPP; |
| 598 |
} |
| 599 |
|
| 600 |
efuse->rfe_type = map->rfe_type; |
| 601 |
efuse->xtal_cap = map->xtal_k; |
| 602 |
|
| 603 |
return 0; |
| 604 |
} |
| 605 |
|
| 606 |
static void rtw8852c_phycap_parsing_tssi(struct rtw89_dev *rtwdev, u8 *phycap_map) |
| 607 |
{ |
| 608 |
struct rtw89_tssi_info *tssi = &rtwdev->tssi; |
| 609 |
static const u32 tssi_trim_addr[RF_PATH_NUM_8852C] = {0x5D6, 0x5AB}; |
| 610 |
static const u32 tssi_trim_addr_6g[RF_PATH_NUM_8852C] = {0x5CE, 0x5A3}; |
| 611 |
u32 addr = rtwdev->chip->phycap_addr; |
| 612 |
bool pg = false; |
| 613 |
u32 ofst; |
| 614 |
u8 i, j; |
| 615 |
|
| 616 |
for (i = 0; i < RF_PATH_NUM_8852C; i++) { |
| 617 |
for (j = 0; j < TSSI_TRIM_CH_GROUP_NUM; j++) { |
| 618 |
/* addrs are in decreasing order */ |
| 619 |
ofst = tssi_trim_addr[i] - addr - j; |
| 620 |
tssi->tssi_trim[i][j] = phycap_map[ofst]; |
| 621 |
|
| 622 |
if (phycap_map[ofst] != 0xff) |
| 623 |
pg = true; |
| 624 |
} |
| 625 |
|
| 626 |
for (j = 0; j < TSSI_TRIM_CH_GROUP_NUM_6G; j++) { |
| 627 |
/* addrs are in decreasing order */ |
| 628 |
ofst = tssi_trim_addr_6g[i] - addr - j; |
| 629 |
tssi->tssi_trim_6g[i][j] = phycap_map[ofst]; |
| 630 |
|
| 631 |
if (phycap_map[ofst] != 0xff) |
| 632 |
pg = true; |
| 633 |
} |
| 634 |
} |
| 635 |
|
| 636 |
if (!pg) { |
| 637 |
memset(tssi->tssi_trim, 0, sizeof(tssi->tssi_trim)); |
| 638 |
memset(tssi->tssi_trim_6g, 0, sizeof(tssi->tssi_trim_6g)); |
| 639 |
rtw89_debug(rtwdev, RTW89_DBG_TSSI, |
| 640 |
"[TSSI][TRIM] no PG, set all trim info to 0\n"); |
| 641 |
} |
| 642 |
|
| 643 |
for (i = 0; i < RF_PATH_NUM_8852C; i++) |
| 644 |
for (j = 0; j < TSSI_TRIM_CH_GROUP_NUM; j++) |
| 645 |
rtw89_debug(rtwdev, RTW89_DBG_TSSI, |
| 646 |
"[TSSI] path=%d idx=%d trim=0x%x addr=0x%x\n", |
| 647 |
i, j, tssi->tssi_trim[i][j], |
| 648 |
tssi_trim_addr[i] - j); |
| 649 |
} |
| 650 |
|
| 651 |
static void rtw8852c_phycap_parsing_thermal_trim(struct rtw89_dev *rtwdev, |
| 652 |
u8 *phycap_map) |
| 653 |
{ |
| 654 |
struct rtw89_power_trim_info *info = &rtwdev->pwr_trim; |
| 655 |
static const u32 thm_trim_addr[RF_PATH_NUM_8852C] = {0x5DF, 0x5DC}; |
| 656 |
u32 addr = rtwdev->chip->phycap_addr; |
| 657 |
u8 i; |
| 658 |
|
| 659 |
for (i = 0; i < RF_PATH_NUM_8852C; i++) { |
| 660 |
info->thermal_trim[i] = phycap_map[thm_trim_addr[i] - addr]; |
| 661 |
|
| 662 |
rtw89_debug(rtwdev, RTW89_DBG_RFK, |
| 663 |
"[THERMAL][TRIM] path=%d thermal_trim=0x%x\n", |
| 664 |
i, info->thermal_trim[i]); |
| 665 |
|
| 666 |
if (info->thermal_trim[i] != 0xff) |
| 667 |
info->pg_thermal_trim = true; |
| 668 |
} |
| 669 |
} |
| 670 |
|
| 671 |
#define __THM_MASK_SIGN BIT(0) |
| 672 |
#define __THM_MASK_3BITS GENMASK(3, 1) |
| 673 |
#define __THM_MASK_VAL8 BIT(4) |
| 674 |
|
| 675 |
static void rtw8852c_thermal_trim(struct rtw89_dev *rtwdev) |
| 676 |
{ |
| 677 |
#define __thm_setting(raw) \ |
| 678 |
({ \ |
| 679 |
u8 __v = (raw); \ |
| 680 |
((__v & __THM_MASK_SIGN) << 3) | ((__v & __THM_MASK_3BITS) >> 1); \ |
| 681 |
}) |
| 682 |
struct rtw89_power_trim_info *info = &rtwdev->pwr_trim; |
| 683 |
u8 i, val; |
| 684 |
|
| 685 |
if (!info->pg_thermal_trim) { |
| 686 |
rtw89_debug(rtwdev, RTW89_DBG_RFK, |
| 687 |
"[THERMAL][TRIM] no PG, do nothing\n"); |
| 688 |
|
| 689 |
return; |
| 690 |
} |
| 691 |
|
| 692 |
for (i = 0; i < RF_PATH_NUM_8852C; i++) { |
| 693 |
val = __thm_setting(info->thermal_trim[i]); |
| 694 |
rtw89_write_rf(rtwdev, i, RR_TM2, RR_TM2_OFF, val); |
| 695 |
|
| 696 |
rtw89_debug(rtwdev, RTW89_DBG_RFK, |
| 697 |
"[THERMAL][TRIM] path=%d thermal_setting=0x%x\n", |
| 698 |
i, val); |
| 699 |
} |
| 700 |
#undef __thm_setting |
| 701 |
} |
| 702 |
|
| 703 |
static void rtw8852c_phycap_parsing_pa_bias_trim(struct rtw89_dev *rtwdev, |
| 704 |
u8 *phycap_map) |
| 705 |
{ |
| 706 |
struct rtw89_power_trim_info *info = &rtwdev->pwr_trim; |
| 707 |
static const u32 pabias_trim_addr[RF_PATH_NUM_8852C] = {0x5DE, 0x5DB}; |
| 708 |
u32 addr = rtwdev->chip->phycap_addr; |
| 709 |
u8 i; |
| 710 |
|
| 711 |
for (i = 0; i < RF_PATH_NUM_8852C; i++) { |
| 712 |
info->pa_bias_trim[i] = phycap_map[pabias_trim_addr[i] - addr]; |
| 713 |
|
| 714 |
rtw89_debug(rtwdev, RTW89_DBG_RFK, |
| 715 |
"[PA_BIAS][TRIM] path=%d pa_bias_trim=0x%x\n", |
| 716 |
i, info->pa_bias_trim[i]); |
| 717 |
|
| 718 |
if (info->pa_bias_trim[i] != 0xff) |
| 719 |
info->pg_pa_bias_trim = true; |
| 720 |
} |
| 721 |
} |
| 722 |
|
| 723 |
static void rtw8852c_pa_bias_trim(struct rtw89_dev *rtwdev) |
| 724 |
{ |
| 725 |
struct rtw89_power_trim_info *info = &rtwdev->pwr_trim; |
| 726 |
u8 pabias_2g, pabias_5g; |
| 727 |
u8 i; |
| 728 |
|
| 729 |
if (!info->pg_pa_bias_trim) { |
| 730 |
rtw89_debug(rtwdev, RTW89_DBG_RFK, |
| 731 |
"[PA_BIAS][TRIM] no PG, do nothing\n"); |
| 732 |
|
| 733 |
return; |
| 734 |
} |
| 735 |
|
| 736 |
for (i = 0; i < RF_PATH_NUM_8852C; i++) { |
| 737 |
pabias_2g = FIELD_GET(GENMASK(3, 0), info->pa_bias_trim[i]); |
| 738 |
pabias_5g = FIELD_GET(GENMASK(7, 4), info->pa_bias_trim[i]); |
| 739 |
|
| 740 |
rtw89_debug(rtwdev, RTW89_DBG_RFK, |
| 741 |
"[PA_BIAS][TRIM] path=%d 2G=0x%x 5G=0x%x\n", |
| 742 |
i, pabias_2g, pabias_5g); |
| 743 |
|
| 744 |
rtw89_write_rf(rtwdev, i, RR_BIASA, RR_BIASA_TXG, pabias_2g); |
| 745 |
rtw89_write_rf(rtwdev, i, RR_BIASA, RR_BIASA_TXA, pabias_5g); |
| 746 |
} |
| 747 |
} |
| 748 |
|
| 749 |
static int rtw8852c_read_phycap(struct rtw89_dev *rtwdev, u8 *phycap_map) |
| 750 |
{ |
| 751 |
rtw8852c_phycap_parsing_tssi(rtwdev, phycap_map); |
| 752 |
rtw8852c_phycap_parsing_thermal_trim(rtwdev, phycap_map); |
| 753 |
rtw8852c_phycap_parsing_pa_bias_trim(rtwdev, phycap_map); |
| 754 |
|
| 755 |
return 0; |
| 756 |
} |
| 757 |
|
| 758 |
static void rtw8852c_power_trim(struct rtw89_dev *rtwdev) |
| 759 |
{ |
| 760 |
rtw8852c_thermal_trim(rtwdev); |
| 761 |
rtw8852c_pa_bias_trim(rtwdev); |
| 762 |
} |
| 763 |
|
| 764 |
static void rtw8852c_set_channel_mac(struct rtw89_dev *rtwdev, |
| 765 |
const struct rtw89_chan *chan, |
| 766 |
u8 mac_idx) |
| 767 |
{ |
| 768 |
u32 rf_mod = rtw89_mac_reg_by_idx(rtwdev, R_AX_WMAC_RFMOD, mac_idx); |
| 769 |
u32 sub_carr = rtw89_mac_reg_by_idx(rtwdev, R_AX_TX_SUB_CARRIER_VALUE, mac_idx); |
| 770 |
u32 chk_rate = rtw89_mac_reg_by_idx(rtwdev, R_AX_TXRATE_CHK, mac_idx); |
| 771 |
u8 txsc20 = 0, txsc40 = 0, txsc80 = 0; |
| 772 |
u8 rf_mod_val = 0, chk_rate_mask = 0; |
| 773 |
u32 txsc; |
| 774 |
|
| 775 |
switch (chan->band_width) { |
| 776 |
case RTW89_CHANNEL_WIDTH_160: |
| 777 |
txsc80 = rtw89_phy_get_txsc(rtwdev, chan, |
| 778 |
RTW89_CHANNEL_WIDTH_80); |
| 779 |
fallthrough; |
| 780 |
case RTW89_CHANNEL_WIDTH_80: |
| 781 |
txsc40 = rtw89_phy_get_txsc(rtwdev, chan, |
| 782 |
RTW89_CHANNEL_WIDTH_40); |
| 783 |
fallthrough; |
| 784 |
case RTW89_CHANNEL_WIDTH_40: |
| 785 |
txsc20 = rtw89_phy_get_txsc(rtwdev, chan, |
| 786 |
RTW89_CHANNEL_WIDTH_20); |
| 787 |
break; |
| 788 |
default: |
| 789 |
break; |
| 790 |
} |
| 791 |
|
| 792 |
switch (chan->band_width) { |
| 793 |
case RTW89_CHANNEL_WIDTH_160: |
| 794 |
rf_mod_val = AX_WMAC_RFMOD_160M; |
| 795 |
txsc = FIELD_PREP(B_AX_TXSC_20M_MASK, txsc20) | |
| 796 |
FIELD_PREP(B_AX_TXSC_40M_MASK, txsc40) | |
| 797 |
FIELD_PREP(B_AX_TXSC_80M_MASK, txsc80); |
| 798 |
break; |
| 799 |
case RTW89_CHANNEL_WIDTH_80: |
| 800 |
rf_mod_val = AX_WMAC_RFMOD_80M; |
| 801 |
txsc = FIELD_PREP(B_AX_TXSC_20M_MASK, txsc20) | |
| 802 |
FIELD_PREP(B_AX_TXSC_40M_MASK, txsc40); |
| 803 |
break; |
| 804 |
case RTW89_CHANNEL_WIDTH_40: |
| 805 |
rf_mod_val = AX_WMAC_RFMOD_40M; |
| 806 |
txsc = FIELD_PREP(B_AX_TXSC_20M_MASK, txsc20); |
| 807 |
break; |
| 808 |
case RTW89_CHANNEL_WIDTH_20: |
| 809 |
default: |
| 810 |
rf_mod_val = AX_WMAC_RFMOD_20M; |
| 811 |
txsc = 0; |
| 812 |
break; |
| 813 |
} |
| 814 |
rtw89_write8_mask(rtwdev, rf_mod, B_AX_WMAC_RFMOD_MASK, rf_mod_val); |
| 815 |
rtw89_write32(rtwdev, sub_carr, txsc); |
| 816 |
|
| 817 |
switch (chan->band_type) { |
| 818 |
case RTW89_BAND_2G: |
| 819 |
chk_rate_mask = B_AX_BAND_MODE; |
| 820 |
break; |
| 821 |
case RTW89_BAND_5G: |
| 822 |
case RTW89_BAND_6G: |
| 823 |
chk_rate_mask = B_AX_CHECK_CCK_EN | B_AX_RTS_LIMIT_IN_OFDM6; |
| 824 |
break; |
| 825 |
default: |
| 826 |
rtw89_warn(rtwdev, "Invalid band_type:%d\n", chan->band_type); |
| 827 |
return; |
| 828 |
} |
| 829 |
rtw89_write8_clr(rtwdev, chk_rate, B_AX_BAND_MODE | B_AX_CHECK_CCK_EN | |
| 830 |
B_AX_RTS_LIMIT_IN_OFDM6); |
| 831 |
rtw89_write8_set(rtwdev, chk_rate, chk_rate_mask); |
| 832 |
} |
| 833 |
|
| 834 |
static const u32 rtw8852c_sco_barker_threshold[14] = { |
| 835 |
0x1fe4f, 0x1ff5e, 0x2006c, 0x2017b, 0x2028a, 0x20399, 0x204a8, 0x205b6, |
| 836 |
0x206c5, 0x207d4, 0x208e3, 0x209f2, 0x20b00, 0x20d8a |
| 837 |
}; |
| 838 |
|
| 839 |
static const u32 rtw8852c_sco_cck_threshold[14] = { |
| 840 |
0x2bdac, 0x2bf21, 0x2c095, 0x2c209, 0x2c37e, 0x2c4f2, 0x2c666, 0x2c7db, |
| 841 |
0x2c94f, 0x2cac3, 0x2cc38, 0x2cdac, 0x2cf21, 0x2d29e |
| 842 |
}; |
| 843 |
|
| 844 |
static int rtw8852c_ctrl_sco_cck(struct rtw89_dev *rtwdev, u8 central_ch, |
| 845 |
u8 primary_ch, enum rtw89_bandwidth bw) |
| 846 |
{ |
| 847 |
u8 ch_element; |
| 848 |
|
| 849 |
if (bw == RTW89_CHANNEL_WIDTH_20) { |
| 850 |
ch_element = central_ch - 1; |
| 851 |
} else if (bw == RTW89_CHANNEL_WIDTH_40) { |
| 852 |
if (primary_ch == 1) |
| 853 |
ch_element = central_ch - 1 + 2; |
| 854 |
else |
| 855 |
ch_element = central_ch - 1 - 2; |
| 856 |
} else { |
| 857 |
rtw89_warn(rtwdev, "Invalid BW:%d for CCK\n", bw); |
| 858 |
return -EINVAL; |
| 859 |
} |
| 860 |
rtw89_phy_write32_mask(rtwdev, R_BK_FC0_INV_V1, B_BK_FC0_INV_MSK_V1, |
| 861 |
rtw8852c_sco_barker_threshold[ch_element]); |
| 862 |
rtw89_phy_write32_mask(rtwdev, R_CCK_FC0_INV_V1, B_CCK_FC0_INV_MSK_V1, |
| 863 |
rtw8852c_sco_cck_threshold[ch_element]); |
| 864 |
|
| 865 |
return 0; |
| 866 |
} |
| 867 |
|
| 868 |
struct rtw8852c_bb_gain { |
| 869 |
u32 gain_g[BB_PATH_NUM_8852C]; |
| 870 |
u32 gain_a[BB_PATH_NUM_8852C]; |
| 871 |
u32 gain_mask; |
| 872 |
}; |
| 873 |
|
| 874 |
static const struct rtw8852c_bb_gain bb_gain_lna[LNA_GAIN_NUM] = { |
| 875 |
{ .gain_g = {0x4678, 0x475C}, .gain_a = {0x45DC, 0x4740}, |
| 876 |
.gain_mask = 0x00ff0000 }, |
| 877 |
{ .gain_g = {0x4678, 0x475C}, .gain_a = {0x45DC, 0x4740}, |
| 878 |
.gain_mask = 0xff000000 }, |
| 879 |
{ .gain_g = {0x467C, 0x4760}, .gain_a = {0x4660, 0x4744}, |
| 880 |
.gain_mask = 0x000000ff }, |
| 881 |
{ .gain_g = {0x467C, 0x4760}, .gain_a = {0x4660, 0x4744}, |
| 882 |
.gain_mask = 0x0000ff00 }, |
| 883 |
{ .gain_g = {0x467C, 0x4760}, .gain_a = {0x4660, 0x4744}, |
| 884 |
.gain_mask = 0x00ff0000 }, |
| 885 |
{ .gain_g = {0x467C, 0x4760}, .gain_a = {0x4660, 0x4744}, |
| 886 |
.gain_mask = 0xff000000 }, |
| 887 |
{ .gain_g = {0x4680, 0x4764}, .gain_a = {0x4664, 0x4748}, |
| 888 |
.gain_mask = 0x000000ff }, |
| 889 |
}; |
| 890 |
|
| 891 |
static const struct rtw8852c_bb_gain bb_gain_tia[TIA_GAIN_NUM] = { |
| 892 |
{ .gain_g = {0x4680, 0x4764}, .gain_a = {0x4664, 0x4748}, |
| 893 |
.gain_mask = 0x00ff0000 }, |
| 894 |
{ .gain_g = {0x4680, 0x4764}, .gain_a = {0x4664, 0x4748}, |
| 895 |
.gain_mask = 0xff000000 }, |
| 896 |
}; |
| 897 |
|
| 898 |
struct rtw8852c_bb_gain_bypass { |
| 899 |
u32 gain_g[BB_PATH_NUM_8852C]; |
| 900 |
u32 gain_a[BB_PATH_NUM_8852C]; |
| 901 |
u32 gain_mask_g; |
| 902 |
u32 gain_mask_a; |
| 903 |
}; |
| 904 |
|
| 905 |
static |
| 906 |
const struct rtw8852c_bb_gain_bypass bb_gain_bypass_lna[LNA_GAIN_NUM] = { |
| 907 |
{ .gain_g = {0x4BB8, 0x4C7C}, .gain_a = {0x4BB4, 0x4C78}, |
| 908 |
.gain_mask_g = 0xff000000, .gain_mask_a = 0xff}, |
| 909 |
{ .gain_g = {0x4BBC, 0x4C80}, .gain_a = {0x4BB4, 0x4C78}, |
| 910 |
.gain_mask_g = 0xff, .gain_mask_a = 0xff00}, |
| 911 |
{ .gain_g = {0x4BBC, 0x4C80}, .gain_a = {0x4BB4, 0x4C78}, |
| 912 |
.gain_mask_g = 0xff00, .gain_mask_a = 0xff0000}, |
| 913 |
{ .gain_g = {0x4BBC, 0x4C80}, .gain_a = {0x4BB4, 0x4C78}, |
| 914 |
.gain_mask_g = 0xff0000, .gain_mask_a = 0xff000000}, |
| 915 |
{ .gain_g = {0x4BBC, 0x4C80}, .gain_a = {0x4BB8, 0x4C7C}, |
| 916 |
.gain_mask_g = 0xff000000, .gain_mask_a = 0xff}, |
| 917 |
{ .gain_g = {0x4BC0, 0x4C84}, .gain_a = {0x4BB8, 0x4C7C}, |
| 918 |
.gain_mask_g = 0xff, .gain_mask_a = 0xff00}, |
| 919 |
{ .gain_g = {0x4BC0, 0x4C84}, .gain_a = {0x4BB8, 0x4C7C}, |
| 920 |
.gain_mask_g = 0xff00, .gain_mask_a = 0xff0000}, |
| 921 |
}; |
| 922 |
|
| 923 |
struct rtw8852c_bb_gain_op1db { |
| 924 |
struct { |
| 925 |
u32 lna[BB_PATH_NUM_8852C]; |
| 926 |
u32 tia_lna[BB_PATH_NUM_8852C]; |
| 927 |
u32 mask; |
| 928 |
} reg[LNA_GAIN_NUM]; |
| 929 |
u32 reg_tia0_lna6[BB_PATH_NUM_8852C]; |
| 930 |
u32 mask_tia0_lna6; |
| 931 |
}; |
| 932 |
|
| 933 |
static const struct rtw8852c_bb_gain_op1db bb_gain_op1db_a = { |
| 934 |
.reg = { |
| 935 |
{ .lna = {0x4668, 0x474c}, .tia_lna = {0x4670, 0x4754}, |
| 936 |
.mask = 0xff}, |
| 937 |
{ .lna = {0x4668, 0x474c}, .tia_lna = {0x4670, 0x4754}, |
| 938 |
.mask = 0xff00}, |
| 939 |
{ .lna = {0x4668, 0x474c}, .tia_lna = {0x4670, 0x4754}, |
| 940 |
.mask = 0xff0000}, |
| 941 |
{ .lna = {0x4668, 0x474c}, .tia_lna = {0x4670, 0x4754}, |
| 942 |
.mask = 0xff000000}, |
| 943 |
{ .lna = {0x466c, 0x4750}, .tia_lna = {0x4674, 0x4758}, |
| 944 |
.mask = 0xff}, |
| 945 |
{ .lna = {0x466c, 0x4750}, .tia_lna = {0x4674, 0x4758}, |
| 946 |
.mask = 0xff00}, |
| 947 |
{ .lna = {0x466c, 0x4750}, .tia_lna = {0x4674, 0x4758}, |
| 948 |
.mask = 0xff0000}, |
| 949 |
}, |
| 950 |
.reg_tia0_lna6 = {0x4674, 0x4758}, |
| 951 |
.mask_tia0_lna6 = 0xff000000, |
| 952 |
}; |
| 953 |
|
| 954 |
static void rtw8852c_set_gain_error(struct rtw89_dev *rtwdev, |
| 955 |
enum rtw89_subband subband, |
| 956 |
enum rtw89_rf_path path) |
| 957 |
{ |
| 958 |
const struct rtw89_phy_bb_gain_info *gain = &rtwdev->bb_gain.ax; |
| 959 |
u8 gain_band = rtw89_subband_to_bb_gain_band(subband); |
| 960 |
s32 val; |
| 961 |
u32 reg; |
| 962 |
u32 mask; |
| 963 |
int i; |
| 964 |
|
| 965 |
for (i = 0; i < LNA_GAIN_NUM; i++) { |
| 966 |
if (subband == RTW89_CH_2G) |
| 967 |
reg = bb_gain_lna[i].gain_g[path]; |
| 968 |
else |
| 969 |
reg = bb_gain_lna[i].gain_a[path]; |
| 970 |
|
| 971 |
mask = bb_gain_lna[i].gain_mask; |
| 972 |
val = gain->lna_gain[gain_band][path][i]; |
| 973 |
rtw89_phy_write32_mask(rtwdev, reg, mask, val); |
| 974 |
|
| 975 |
if (subband == RTW89_CH_2G) { |
| 976 |
reg = bb_gain_bypass_lna[i].gain_g[path]; |
| 977 |
mask = bb_gain_bypass_lna[i].gain_mask_g; |
| 978 |
} else { |
| 979 |
reg = bb_gain_bypass_lna[i].gain_a[path]; |
| 980 |
mask = bb_gain_bypass_lna[i].gain_mask_a; |
| 981 |
} |
| 982 |
|
| 983 |
val = gain->lna_gain_bypass[gain_band][path][i]; |
| 984 |
rtw89_phy_write32_mask(rtwdev, reg, mask, val); |
| 985 |
|
| 986 |
if (subband != RTW89_CH_2G) { |
| 987 |
reg = bb_gain_op1db_a.reg[i].lna[path]; |
| 988 |
mask = bb_gain_op1db_a.reg[i].mask; |
| 989 |
val = gain->lna_op1db[gain_band][path][i]; |
| 990 |
rtw89_phy_write32_mask(rtwdev, reg, mask, val); |
| 991 |
|
| 992 |
reg = bb_gain_op1db_a.reg[i].tia_lna[path]; |
| 993 |
mask = bb_gain_op1db_a.reg[i].mask; |
| 994 |
val = gain->tia_lna_op1db[gain_band][path][i]; |
| 995 |
rtw89_phy_write32_mask(rtwdev, reg, mask, val); |
| 996 |
} |
| 997 |
} |
| 998 |
|
| 999 |
if (subband != RTW89_CH_2G) { |
| 1000 |
reg = bb_gain_op1db_a.reg_tia0_lna6[path]; |
| 1001 |
mask = bb_gain_op1db_a.mask_tia0_lna6; |
| 1002 |
val = gain->tia_lna_op1db[gain_band][path][7]; |
| 1003 |
rtw89_phy_write32_mask(rtwdev, reg, mask, val); |
| 1004 |
} |
| 1005 |
|
| 1006 |
for (i = 0; i < TIA_GAIN_NUM; i++) { |
| 1007 |
if (subband == RTW89_CH_2G) |
| 1008 |
reg = bb_gain_tia[i].gain_g[path]; |
| 1009 |
else |
| 1010 |
reg = bb_gain_tia[i].gain_a[path]; |
| 1011 |
|
| 1012 |
mask = bb_gain_tia[i].gain_mask; |
| 1013 |
val = gain->tia_gain[gain_band][path][i]; |
| 1014 |
rtw89_phy_write32_mask(rtwdev, reg, mask, val); |
| 1015 |
} |
| 1016 |
} |
| 1017 |
|
| 1018 |
static void rtw8852c_set_gain_offset(struct rtw89_dev *rtwdev, |
| 1019 |
const struct rtw89_chan *chan, |
| 1020 |
enum rtw89_phy_idx phy_idx, |
| 1021 |
enum rtw89_rf_path path) |
| 1022 |
{ |
| 1023 |
static const u32 rssi_ofst_addr[2] = {R_PATH0_G_TIA0_LNA6_OP1DB_V1, |
| 1024 |
R_PATH1_G_TIA0_LNA6_OP1DB_V1}; |
| 1025 |
static const u32 rpl_mask[2] = {B_RPL_PATHA_MASK, B_RPL_PATHB_MASK}; |
| 1026 |
static const u32 rpl_tb_mask[2] = {B_RSSI_M_PATHA_MASK, B_RSSI_M_PATHB_MASK}; |
| 1027 |
struct rtw89_phy_efuse_gain *efuse_gain = &rtwdev->efuse_gain; |
| 1028 |
enum rtw89_gain_offset gain_band; |
| 1029 |
s32 offset_q0, offset_base_q4; |
| 1030 |
s32 tmp = 0; |
| 1031 |
|
| 1032 |
if (!efuse_gain->offset_valid) |
| 1033 |
return; |
| 1034 |
|
| 1035 |
if (rtwdev->dbcc_en && path == RF_PATH_B) |
| 1036 |
phy_idx = RTW89_PHY_1; |
| 1037 |
|
| 1038 |
if (chan->band_type == RTW89_BAND_2G) { |
| 1039 |
offset_q0 = efuse_gain->offset[path][RTW89_GAIN_OFFSET_2G_CCK]; |
| 1040 |
offset_base_q4 = efuse_gain->offset_base[phy_idx]; |
| 1041 |
|
| 1042 |
tmp = clamp_t(s32, (-offset_q0 << 3) + (offset_base_q4 >> 1), |
| 1043 |
S8_MIN >> 1, S8_MAX >> 1); |
| 1044 |
rtw89_phy_write32_mask(rtwdev, R_RPL_OFST, B_RPL_OFST_MASK, tmp & 0x7f); |
| 1045 |
} |
| 1046 |
|
| 1047 |
gain_band = rtw89_subband_to_gain_offset_band_of_ofdm(chan->subband_type); |
| 1048 |
|
| 1049 |
offset_q0 = -efuse_gain->offset[path][gain_band]; |
| 1050 |
offset_base_q4 = efuse_gain->offset_base[phy_idx]; |
| 1051 |
|
| 1052 |
tmp = (offset_q0 << 2) + (offset_base_q4 >> 2); |
| 1053 |
tmp = clamp_t(s32, -tmp, S8_MIN, S8_MAX); |
| 1054 |
rtw89_phy_write32_mask(rtwdev, rssi_ofst_addr[path], B_PATH0_R_G_OFST_MASK, tmp & 0xff); |
| 1055 |
|
| 1056 |
tmp = clamp_t(s32, offset_q0 << 4, S8_MIN, S8_MAX); |
| 1057 |
rtw89_phy_write32_idx(rtwdev, R_RPL_PATHAB, rpl_mask[path], tmp & 0xff, phy_idx); |
| 1058 |
rtw89_phy_write32_idx(rtwdev, R_RSSI_M_PATHAB, rpl_tb_mask[path], tmp & 0xff, phy_idx); |
| 1059 |
} |
| 1060 |
|
| 1061 |
static void rtw8852c_ctrl_ch(struct rtw89_dev *rtwdev, |
| 1062 |
const struct rtw89_chan *chan, |
| 1063 |
enum rtw89_phy_idx phy_idx) |
| 1064 |
{ |
| 1065 |
u8 sco; |
| 1066 |
u16 central_freq = chan->freq; |
| 1067 |
u8 central_ch = chan->channel; |
| 1068 |
u8 band = chan->band_type; |
| 1069 |
u8 subband = chan->subband_type; |
| 1070 |
bool is_2g = band == RTW89_BAND_2G; |
| 1071 |
u8 chan_idx; |
| 1072 |
|
| 1073 |
if (!central_freq) { |
| 1074 |
rtw89_warn(rtwdev, "Invalid central_freq\n"); |
| 1075 |
return; |
| 1076 |
} |
| 1077 |
|
| 1078 |
if (phy_idx == RTW89_PHY_0) { |
| 1079 |
/* Path A */ |
| 1080 |
rtw8852c_set_gain_error(rtwdev, subband, RF_PATH_A); |
| 1081 |
rtw8852c_set_gain_offset(rtwdev, chan, phy_idx, RF_PATH_A); |
| 1082 |
|
| 1083 |
if (is_2g) |
| 1084 |
rtw89_phy_write32_idx(rtwdev, R_PATH0_BAND_SEL_V1, |
| 1085 |
B_PATH0_BAND_SEL_MSK_V1, 1, |
| 1086 |
phy_idx); |
| 1087 |
else |
| 1088 |
rtw89_phy_write32_idx(rtwdev, R_PATH0_BAND_SEL_V1, |
| 1089 |
B_PATH0_BAND_SEL_MSK_V1, 0, |
| 1090 |
phy_idx); |
| 1091 |
/* Path B */ |
| 1092 |
if (!rtwdev->dbcc_en) { |
| 1093 |
rtw8852c_set_gain_error(rtwdev, subband, RF_PATH_B); |
| 1094 |
rtw8852c_set_gain_offset(rtwdev, chan, phy_idx, RF_PATH_B); |
| 1095 |
|
| 1096 |
if (is_2g) |
| 1097 |
rtw89_phy_write32_idx(rtwdev, |
| 1098 |
R_PATH1_BAND_SEL_V1, |
| 1099 |
B_PATH1_BAND_SEL_MSK_V1, |
| 1100 |
1, phy_idx); |
| 1101 |
else |
| 1102 |
rtw89_phy_write32_idx(rtwdev, |
| 1103 |
R_PATH1_BAND_SEL_V1, |
| 1104 |
B_PATH1_BAND_SEL_MSK_V1, |
| 1105 |
0, phy_idx); |
| 1106 |
rtw89_phy_write32_clr(rtwdev, R_2P4G_BAND, B_2P4G_BAND_SEL); |
| 1107 |
} else { |
| 1108 |
if (is_2g) |
| 1109 |
rtw89_phy_write32_clr(rtwdev, R_2P4G_BAND, B_2P4G_BAND_SEL); |
| 1110 |
else |
| 1111 |
rtw89_phy_write32_set(rtwdev, R_2P4G_BAND, B_2P4G_BAND_SEL); |
| 1112 |
} |
| 1113 |
/* SCO compensate FC setting */ |
| 1114 |
rtw89_phy_write32_idx(rtwdev, R_FC0_V1, B_FC0_MSK_V1, |
| 1115 |
central_freq, phy_idx); |
| 1116 |
/* round_up((1/fc0)*pow(2,18)) */ |
| 1117 |
sco = DIV_ROUND_CLOSEST(1 << 18, central_freq); |
| 1118 |
rtw89_phy_write32_idx(rtwdev, R_FC0_BW, B_FC0_BW_INV, sco, |
| 1119 |
phy_idx); |
| 1120 |
} else { |
| 1121 |
/* Path B */ |
| 1122 |
rtw8852c_set_gain_error(rtwdev, subband, RF_PATH_B); |
| 1123 |
rtw8852c_set_gain_offset(rtwdev, chan, phy_idx, RF_PATH_B); |
| 1124 |
|
| 1125 |
if (is_2g) |
| 1126 |
rtw89_phy_write32_idx(rtwdev, R_PATH1_BAND_SEL_V1, |
| 1127 |
B_PATH1_BAND_SEL_MSK_V1, |
| 1128 |
1, phy_idx); |
| 1129 |
else |
| 1130 |
rtw89_phy_write32_idx(rtwdev, R_PATH1_BAND_SEL_V1, |
| 1131 |
B_PATH1_BAND_SEL_MSK_V1, |
| 1132 |
0, phy_idx); |
| 1133 |
/* SCO compensate FC setting */ |
| 1134 |
rtw89_phy_write32_idx(rtwdev, R_FC0_V1, B_FC0_MSK_V1, |
| 1135 |
central_freq, phy_idx); |
| 1136 |
/* round_up((1/fc0)*pow(2,18)) */ |
| 1137 |
sco = DIV_ROUND_CLOSEST(1 << 18, central_freq); |
| 1138 |
rtw89_phy_write32_idx(rtwdev, R_FC0_BW, B_FC0_BW_INV, sco, |
| 1139 |
phy_idx); |
| 1140 |
} |
| 1141 |
/* CCK parameters */ |
| 1142 |
if (band == RTW89_BAND_2G) { |
| 1143 |
if (central_ch == 14) { |
| 1144 |
rtw89_phy_write32_mask(rtwdev, R_PCOEFF0_V1, |
| 1145 |
B_PCOEFF01_MSK_V1, 0x3b13ff); |
| 1146 |
rtw89_phy_write32_mask(rtwdev, R_PCOEFF2_V1, |
| 1147 |
B_PCOEFF23_MSK_V1, 0x1c42de); |
| 1148 |
rtw89_phy_write32_mask(rtwdev, R_PCOEFF4_V1, |
| 1149 |
B_PCOEFF45_MSK_V1, 0xfdb0ad); |
| 1150 |
rtw89_phy_write32_mask(rtwdev, R_PCOEFF6_V1, |
| 1151 |
B_PCOEFF67_MSK_V1, 0xf60f6e); |
| 1152 |
rtw89_phy_write32_mask(rtwdev, R_PCOEFF8_V1, |
| 1153 |
B_PCOEFF89_MSK_V1, 0xfd8f92); |
| 1154 |
rtw89_phy_write32_mask(rtwdev, R_PCOEFFA_V1, |
| 1155 |
B_PCOEFFAB_MSK_V1, 0x2d011); |
| 1156 |
rtw89_phy_write32_mask(rtwdev, R_PCOEFFC_V1, |
| 1157 |
B_PCOEFFCD_MSK_V1, 0x1c02c); |
| 1158 |
rtw89_phy_write32_mask(rtwdev, R_PCOEFFE_V1, |
| 1159 |
B_PCOEFFEF_MSK_V1, 0xfff00a); |
| 1160 |
} else { |
| 1161 |
rtw89_phy_write32_mask(rtwdev, R_PCOEFF0_V1, |
| 1162 |
B_PCOEFF01_MSK_V1, 0x3d23ff); |
| 1163 |
rtw89_phy_write32_mask(rtwdev, R_PCOEFF2_V1, |
| 1164 |
B_PCOEFF23_MSK_V1, 0x29b354); |
| 1165 |
rtw89_phy_write32_mask(rtwdev, R_PCOEFF4_V1, |
| 1166 |
B_PCOEFF45_MSK_V1, 0xfc1c8); |
| 1167 |
rtw89_phy_write32_mask(rtwdev, R_PCOEFF6_V1, |
| 1168 |
B_PCOEFF67_MSK_V1, 0xfdb053); |
| 1169 |
rtw89_phy_write32_mask(rtwdev, R_PCOEFF8_V1, |
| 1170 |
B_PCOEFF89_MSK_V1, 0xf86f9a); |
| 1171 |
rtw89_phy_write32_mask(rtwdev, R_PCOEFFA_V1, |
| 1172 |
B_PCOEFFAB_MSK_V1, 0xfaef92); |
| 1173 |
rtw89_phy_write32_mask(rtwdev, R_PCOEFFC_V1, |
| 1174 |
B_PCOEFFCD_MSK_V1, 0xfe5fcc); |
| 1175 |
rtw89_phy_write32_mask(rtwdev, R_PCOEFFE_V1, |
| 1176 |
B_PCOEFFEF_MSK_V1, 0xffdff5); |
| 1177 |
} |
| 1178 |
} |
| 1179 |
|
| 1180 |
chan_idx = rtw89_encode_chan_idx(rtwdev, chan->primary_channel, band); |
| 1181 |
rtw89_phy_write32_idx(rtwdev, R_MAC_PIN_SEL, B_CH_IDX_SEG0, chan_idx, phy_idx); |
| 1182 |
} |
| 1183 |
|
| 1184 |
static void rtw8852c_bw_setting(struct rtw89_dev *rtwdev, u8 bw, u8 path) |
| 1185 |
{ |
| 1186 |
static const u32 adc_sel[2] = {0xC0EC, 0xC1EC}; |
| 1187 |
static const u32 wbadc_sel[2] = {0xC0E4, 0xC1E4}; |
| 1188 |
|
| 1189 |
switch (bw) { |
| 1190 |
case RTW89_CHANNEL_WIDTH_5: |
| 1191 |
rtw89_phy_write32_mask(rtwdev, adc_sel[path], 0x6000, 0x1); |
| 1192 |
rtw89_phy_write32_mask(rtwdev, wbadc_sel[path], 0x30, 0x0); |
| 1193 |
break; |
| 1194 |
case RTW89_CHANNEL_WIDTH_10: |
| 1195 |
rtw89_phy_write32_mask(rtwdev, adc_sel[path], 0x6000, 0x2); |
| 1196 |
rtw89_phy_write32_mask(rtwdev, wbadc_sel[path], 0x30, 0x1); |
| 1197 |
break; |
| 1198 |
case RTW89_CHANNEL_WIDTH_20: |
| 1199 |
case RTW89_CHANNEL_WIDTH_40: |
| 1200 |
case RTW89_CHANNEL_WIDTH_80: |
| 1201 |
case RTW89_CHANNEL_WIDTH_160: |
| 1202 |
rtw89_phy_write32_mask(rtwdev, adc_sel[path], 0x6000, 0x0); |
| 1203 |
rtw89_phy_write32_mask(rtwdev, wbadc_sel[path], 0x30, 0x2); |
| 1204 |
break; |
| 1205 |
default: |
| 1206 |
rtw89_warn(rtwdev, "Fail to set ADC\n"); |
| 1207 |
} |
| 1208 |
} |
| 1209 |
|
| 1210 |
static void rtw8852c_edcca_per20_bitmap_sifs(struct rtw89_dev *rtwdev, u8 bw, |
| 1211 |
enum rtw89_phy_idx phy_idx) |
| 1212 |
{ |
| 1213 |
if (bw == RTW89_CHANNEL_WIDTH_20) { |
| 1214 |
rtw89_phy_write32_idx(rtwdev, R_SNDCCA_A1, B_SNDCCA_A1_EN, 0xff, phy_idx); |
| 1215 |
rtw89_phy_write32_idx(rtwdev, R_SNDCCA_A2, B_SNDCCA_A2_VAL, 0, phy_idx); |
| 1216 |
} else { |
| 1217 |
rtw89_phy_write32_idx(rtwdev, R_SNDCCA_A1, B_SNDCCA_A1_EN, 0, phy_idx); |
| 1218 |
rtw89_phy_write32_idx(rtwdev, R_SNDCCA_A2, B_SNDCCA_A2_VAL, 0, phy_idx); |
| 1219 |
} |
| 1220 |
} |
| 1221 |
|
| 1222 |
static void |
| 1223 |
rtw8852c_ctrl_bw(struct rtw89_dev *rtwdev, u8 pri_ch, u8 bw, |
| 1224 |
enum rtw89_phy_idx phy_idx) |
| 1225 |
{ |
| 1226 |
u8 mod_sbw = 0; |
| 1227 |
|
| 1228 |
switch (bw) { |
| 1229 |
case RTW89_CHANNEL_WIDTH_5: |
| 1230 |
case RTW89_CHANNEL_WIDTH_10: |
| 1231 |
case RTW89_CHANNEL_WIDTH_20: |
| 1232 |
if (bw == RTW89_CHANNEL_WIDTH_5) |
| 1233 |
mod_sbw = 0x1; |
| 1234 |
else if (bw == RTW89_CHANNEL_WIDTH_10) |
| 1235 |
mod_sbw = 0x2; |
| 1236 |
else if (bw == RTW89_CHANNEL_WIDTH_20) |
| 1237 |
mod_sbw = 0x0; |
| 1238 |
rtw89_phy_write32_idx(rtwdev, R_FC0_BW, B_FC0_BW_SET, 0x0, |
| 1239 |
phy_idx); |
| 1240 |
rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD, B_CHBW_MOD_SBW, |
| 1241 |
mod_sbw, phy_idx); |
| 1242 |
rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD, B_CHBW_MOD_PRICH, 0x0, |
| 1243 |
phy_idx); |
| 1244 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_SAMPL_DLY_T_V1, |
| 1245 |
B_PATH0_SAMPL_DLY_T_MSK_V1, 0x3); |
| 1246 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_SAMPL_DLY_T_V1, |
| 1247 |
B_PATH1_SAMPL_DLY_T_MSK_V1, 0x3); |
| 1248 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_BW_SEL_V1, |
| 1249 |
B_PATH0_BW_SEL_MSK_V1, 0xf); |
| 1250 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_BW_SEL_V1, |
| 1251 |
B_PATH1_BW_SEL_MSK_V1, 0xf); |
| 1252 |
break; |
| 1253 |
case RTW89_CHANNEL_WIDTH_40: |
| 1254 |
rtw89_phy_write32_idx(rtwdev, R_FC0_BW, B_FC0_BW_SET, 0x1, |
| 1255 |
phy_idx); |
| 1256 |
rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD, B_CHBW_MOD_SBW, 0x0, |
| 1257 |
phy_idx); |
| 1258 |
rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD, B_CHBW_MOD_PRICH, |
| 1259 |
pri_ch, |
| 1260 |
phy_idx); |
| 1261 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_SAMPL_DLY_T_V1, |
| 1262 |
B_PATH0_SAMPL_DLY_T_MSK_V1, 0x3); |
| 1263 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_SAMPL_DLY_T_V1, |
| 1264 |
B_PATH1_SAMPL_DLY_T_MSK_V1, 0x3); |
| 1265 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_BW_SEL_V1, |
| 1266 |
B_PATH0_BW_SEL_MSK_V1, 0xf); |
| 1267 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_BW_SEL_V1, |
| 1268 |
B_PATH1_BW_SEL_MSK_V1, 0xf); |
| 1269 |
break; |
| 1270 |
case RTW89_CHANNEL_WIDTH_80: |
| 1271 |
rtw89_phy_write32_idx(rtwdev, R_FC0_BW, B_FC0_BW_SET, 0x2, |
| 1272 |
phy_idx); |
| 1273 |
rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD, B_CHBW_MOD_SBW, 0x0, |
| 1274 |
phy_idx); |
| 1275 |
rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD, B_CHBW_MOD_PRICH, |
| 1276 |
pri_ch, |
| 1277 |
phy_idx); |
| 1278 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_SAMPL_DLY_T_V1, |
| 1279 |
B_PATH0_SAMPL_DLY_T_MSK_V1, 0x2); |
| 1280 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_SAMPL_DLY_T_V1, |
| 1281 |
B_PATH1_SAMPL_DLY_T_MSK_V1, 0x2); |
| 1282 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_BW_SEL_V1, |
| 1283 |
B_PATH0_BW_SEL_MSK_V1, 0xd); |
| 1284 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_BW_SEL_V1, |
| 1285 |
B_PATH1_BW_SEL_MSK_V1, 0xd); |
| 1286 |
break; |
| 1287 |
case RTW89_CHANNEL_WIDTH_160: |
| 1288 |
rtw89_phy_write32_idx(rtwdev, R_FC0_BW, B_FC0_BW_SET, 0x3, |
| 1289 |
phy_idx); |
| 1290 |
rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD, B_CHBW_MOD_SBW, 0x0, |
| 1291 |
phy_idx); |
| 1292 |
rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD, B_CHBW_MOD_PRICH, |
| 1293 |
pri_ch, |
| 1294 |
phy_idx); |
| 1295 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_SAMPL_DLY_T_V1, |
| 1296 |
B_PATH0_SAMPL_DLY_T_MSK_V1, 0x1); |
| 1297 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_SAMPL_DLY_T_V1, |
| 1298 |
B_PATH1_SAMPL_DLY_T_MSK_V1, 0x1); |
| 1299 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_BW_SEL_V1, |
| 1300 |
B_PATH0_BW_SEL_MSK_V1, 0xb); |
| 1301 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_BW_SEL_V1, |
| 1302 |
B_PATH1_BW_SEL_MSK_V1, 0xb); |
| 1303 |
break; |
| 1304 |
default: |
| 1305 |
rtw89_warn(rtwdev, "Fail to switch bw (bw:%d, pri ch:%d)\n", bw, |
| 1306 |
pri_ch); |
| 1307 |
} |
| 1308 |
|
| 1309 |
if (bw == RTW89_CHANNEL_WIDTH_40) { |
| 1310 |
rtw89_phy_write32_idx(rtwdev, R_RX_BW40_2XFFT_EN_V1, |
| 1311 |
B_RX_BW40_2XFFT_EN_MSK_V1, 0x1, phy_idx); |
| 1312 |
rtw89_phy_write32_idx(rtwdev, R_T2F_GI_COMB, B_T2F_GI_COMB_EN, 1, phy_idx); |
| 1313 |
} else { |
| 1314 |
rtw89_phy_write32_idx(rtwdev, R_RX_BW40_2XFFT_EN_V1, |
| 1315 |
B_RX_BW40_2XFFT_EN_MSK_V1, 0x0, phy_idx); |
| 1316 |
rtw89_phy_write32_idx(rtwdev, R_T2F_GI_COMB, B_T2F_GI_COMB_EN, 0, phy_idx); |
| 1317 |
} |
| 1318 |
|
| 1319 |
if (phy_idx == RTW89_PHY_0) { |
| 1320 |
rtw8852c_bw_setting(rtwdev, bw, RF_PATH_A); |
| 1321 |
if (!rtwdev->dbcc_en) |
| 1322 |
rtw8852c_bw_setting(rtwdev, bw, RF_PATH_B); |
| 1323 |
} else { |
| 1324 |
rtw8852c_bw_setting(rtwdev, bw, RF_PATH_B); |
| 1325 |
} |
| 1326 |
|
| 1327 |
rtw8852c_edcca_per20_bitmap_sifs(rtwdev, bw, phy_idx); |
| 1328 |
} |
| 1329 |
|
| 1330 |
static u32 rtw8852c_spur_freq(struct rtw89_dev *rtwdev, |
| 1331 |
const struct rtw89_chan *chan) |
| 1332 |
{ |
| 1333 |
u8 center_chan = chan->channel; |
| 1334 |
u8 bw = chan->band_width; |
| 1335 |
|
| 1336 |
switch (chan->band_type) { |
| 1337 |
case RTW89_BAND_2G: |
| 1338 |
if (bw == RTW89_CHANNEL_WIDTH_20) { |
| 1339 |
if (center_chan >= 5 && center_chan <= 8) |
| 1340 |
return 2440; |
| 1341 |
if (center_chan == 13) |
| 1342 |
return 2480; |
| 1343 |
} else if (bw == RTW89_CHANNEL_WIDTH_40) { |
| 1344 |
if (center_chan >= 3 && center_chan <= 10) |
| 1345 |
return 2440; |
| 1346 |
} |
| 1347 |
break; |
| 1348 |
case RTW89_BAND_5G: |
| 1349 |
if (center_chan == 151 || center_chan == 153 || |
| 1350 |
center_chan == 155 || center_chan == 163) |
| 1351 |
return 5760; |
| 1352 |
break; |
| 1353 |
case RTW89_BAND_6G: |
| 1354 |
if (center_chan == 195 || center_chan == 197 || |
| 1355 |
center_chan == 199 || center_chan == 207) |
| 1356 |
return 6920; |
| 1357 |
break; |
| 1358 |
default: |
| 1359 |
break; |
| 1360 |
} |
| 1361 |
|
| 1362 |
return 0; |
| 1363 |
} |
| 1364 |
|
| 1365 |
#define CARRIER_SPACING_312_5 312500 /* 312.5 kHz */ |
| 1366 |
#define CARRIER_SPACING_78_125 78125 /* 78.125 kHz */ |
| 1367 |
#define MAX_TONE_NUM 2048 |
| 1368 |
|
| 1369 |
static void rtw8852c_set_csi_tone_idx(struct rtw89_dev *rtwdev, |
| 1370 |
const struct rtw89_chan *chan, |
| 1371 |
enum rtw89_phy_idx phy_idx) |
| 1372 |
{ |
| 1373 |
u32 spur_freq; |
| 1374 |
s32 freq_diff, csi_idx, csi_tone_idx; |
| 1375 |
|
| 1376 |
spur_freq = rtw8852c_spur_freq(rtwdev, chan); |
| 1377 |
if (spur_freq == 0) { |
| 1378 |
rtw89_phy_write32_idx(rtwdev, R_SEG0CSI_EN, B_SEG0CSI_EN, 0, phy_idx); |
| 1379 |
return; |
| 1380 |
} |
| 1381 |
|
| 1382 |
freq_diff = (spur_freq - chan->freq) * 1000000; |
| 1383 |
csi_idx = s32_div_u32_round_closest(freq_diff, CARRIER_SPACING_78_125); |
| 1384 |
s32_div_u32_round_down(csi_idx, MAX_TONE_NUM, &csi_tone_idx); |
| 1385 |
|
| 1386 |
rtw89_phy_write32_idx(rtwdev, R_SEG0CSI, B_SEG0CSI_IDX, csi_tone_idx, phy_idx); |
| 1387 |
rtw89_phy_write32_idx(rtwdev, R_SEG0CSI_EN, B_SEG0CSI_EN, 1, phy_idx); |
| 1388 |
} |
| 1389 |
|
| 1390 |
static const struct rtw89_nbi_reg_def rtw8852c_nbi_reg_def[] = { |
| 1391 |
[RF_PATH_A] = { |
| 1392 |
.notch1_idx = {0x4C14, 0xFF}, |
| 1393 |
.notch1_frac_idx = {0x4C14, 0xC00}, |
| 1394 |
.notch1_en = {0x4C14, 0x1000}, |
| 1395 |
.notch2_idx = {0x4C20, 0xFF}, |
| 1396 |
.notch2_frac_idx = {0x4C20, 0xC00}, |
| 1397 |
.notch2_en = {0x4C20, 0x1000}, |
| 1398 |
}, |
| 1399 |
[RF_PATH_B] = { |
| 1400 |
.notch1_idx = {0x4CD8, 0xFF}, |
| 1401 |
.notch1_frac_idx = {0x4CD8, 0xC00}, |
| 1402 |
.notch1_en = {0x4CD8, 0x1000}, |
| 1403 |
.notch2_idx = {0x4CE4, 0xFF}, |
| 1404 |
.notch2_frac_idx = {0x4CE4, 0xC00}, |
| 1405 |
.notch2_en = {0x4CE4, 0x1000}, |
| 1406 |
}, |
| 1407 |
}; |
| 1408 |
|
| 1409 |
static void rtw8852c_set_nbi_tone_idx(struct rtw89_dev *rtwdev, |
| 1410 |
const struct rtw89_chan *chan, |
| 1411 |
enum rtw89_rf_path path) |
| 1412 |
{ |
| 1413 |
const struct rtw89_nbi_reg_def *nbi = &rtw8852c_nbi_reg_def[path]; |
| 1414 |
u32 spur_freq, fc; |
| 1415 |
s32 freq_diff; |
| 1416 |
s32 nbi_idx, nbi_tone_idx; |
| 1417 |
s32 nbi_frac_idx, nbi_frac_tone_idx; |
| 1418 |
bool notch2_chk = false; |
| 1419 |
|
| 1420 |
spur_freq = rtw8852c_spur_freq(rtwdev, chan); |
| 1421 |
if (spur_freq == 0) { |
| 1422 |
rtw89_phy_write32_mask(rtwdev, nbi->notch1_en.addr, nbi->notch1_en.mask, 0); |
| 1423 |
rtw89_phy_write32_mask(rtwdev, nbi->notch1_en.addr, nbi->notch1_en.mask, 0); |
| 1424 |
return; |
| 1425 |
} |
| 1426 |
|
| 1427 |
fc = chan->freq; |
| 1428 |
if (chan->band_width == RTW89_CHANNEL_WIDTH_160) { |
| 1429 |
fc = (spur_freq > fc) ? fc + 40 : fc - 40; |
| 1430 |
if ((fc > spur_freq && |
| 1431 |
chan->channel < chan->primary_channel) || |
| 1432 |
(fc < spur_freq && |
| 1433 |
chan->channel > chan->primary_channel)) |
| 1434 |
notch2_chk = true; |
| 1435 |
} |
| 1436 |
|
| 1437 |
freq_diff = (spur_freq - fc) * 1000000; |
| 1438 |
nbi_idx = s32_div_u32_round_down(freq_diff, CARRIER_SPACING_312_5, &nbi_frac_idx); |
| 1439 |
|
| 1440 |
if (chan->band_width == RTW89_CHANNEL_WIDTH_20) { |
| 1441 |
s32_div_u32_round_down(nbi_idx + 32, 64, &nbi_tone_idx); |
| 1442 |
} else { |
| 1443 |
u16 tone_para = (chan->band_width == RTW89_CHANNEL_WIDTH_40) ? |
| 1444 |
128 : 256; |
| 1445 |
|
| 1446 |
s32_div_u32_round_down(nbi_idx, tone_para, &nbi_tone_idx); |
| 1447 |
} |
| 1448 |
nbi_frac_tone_idx = s32_div_u32_round_closest(nbi_frac_idx, CARRIER_SPACING_78_125); |
| 1449 |
|
| 1450 |
if (chan->band_width == RTW89_CHANNEL_WIDTH_160 && notch2_chk) { |
| 1451 |
rtw89_phy_write32_mask(rtwdev, nbi->notch2_idx.addr, |
| 1452 |
nbi->notch2_idx.mask, nbi_tone_idx); |
| 1453 |
rtw89_phy_write32_mask(rtwdev, nbi->notch2_frac_idx.addr, |
| 1454 |
nbi->notch2_frac_idx.mask, nbi_frac_tone_idx); |
| 1455 |
rtw89_phy_write32_mask(rtwdev, nbi->notch2_en.addr, nbi->notch2_en.mask, 0); |
| 1456 |
rtw89_phy_write32_mask(rtwdev, nbi->notch2_en.addr, nbi->notch2_en.mask, 1); |
| 1457 |
rtw89_phy_write32_mask(rtwdev, nbi->notch1_en.addr, nbi->notch1_en.mask, 0); |
| 1458 |
} else { |
| 1459 |
rtw89_phy_write32_mask(rtwdev, nbi->notch1_idx.addr, |
| 1460 |
nbi->notch1_idx.mask, nbi_tone_idx); |
| 1461 |
rtw89_phy_write32_mask(rtwdev, nbi->notch1_frac_idx.addr, |
| 1462 |
nbi->notch1_frac_idx.mask, nbi_frac_tone_idx); |
| 1463 |
rtw89_phy_write32_mask(rtwdev, nbi->notch1_en.addr, nbi->notch1_en.mask, 0); |
| 1464 |
rtw89_phy_write32_mask(rtwdev, nbi->notch1_en.addr, nbi->notch1_en.mask, 1); |
| 1465 |
rtw89_phy_write32_mask(rtwdev, nbi->notch2_en.addr, nbi->notch2_en.mask, 0); |
| 1466 |
} |
| 1467 |
} |
| 1468 |
|
| 1469 |
static void rtw8852c_spur_notch(struct rtw89_dev *rtwdev, u32 val, |
| 1470 |
enum rtw89_phy_idx phy_idx) |
| 1471 |
{ |
| 1472 |
u32 notch; |
| 1473 |
u32 notch2; |
| 1474 |
|
| 1475 |
if (phy_idx == RTW89_PHY_0) { |
| 1476 |
notch = R_PATH0_NOTCH; |
| 1477 |
notch2 = R_PATH0_NOTCH2; |
| 1478 |
} else { |
| 1479 |
notch = R_PATH1_NOTCH; |
| 1480 |
notch2 = R_PATH1_NOTCH2; |
| 1481 |
} |
| 1482 |
|
| 1483 |
rtw89_phy_write32_mask(rtwdev, notch, |
| 1484 |
B_PATH0_NOTCH_VAL | B_PATH0_NOTCH_EN, val); |
| 1485 |
rtw89_phy_write32_set(rtwdev, notch, B_PATH0_NOTCH_EN); |
| 1486 |
rtw89_phy_write32_mask(rtwdev, notch2, |
| 1487 |
B_PATH0_NOTCH2_VAL | B_PATH0_NOTCH2_EN, val); |
| 1488 |
rtw89_phy_write32_set(rtwdev, notch2, B_PATH0_NOTCH2_EN); |
| 1489 |
} |
| 1490 |
|
| 1491 |
static void rtw8852c_spur_elimination(struct rtw89_dev *rtwdev, |
| 1492 |
const struct rtw89_chan *chan, |
| 1493 |
u8 pri_ch_idx, |
| 1494 |
enum rtw89_phy_idx phy_idx) |
| 1495 |
{ |
| 1496 |
rtw8852c_set_csi_tone_idx(rtwdev, chan, phy_idx); |
| 1497 |
|
| 1498 |
if (phy_idx == RTW89_PHY_0) { |
| 1499 |
if (chan->band_width == RTW89_CHANNEL_WIDTH_160 && |
| 1500 |
(pri_ch_idx == RTW89_SC_20_LOWER || |
| 1501 |
pri_ch_idx == RTW89_SC_20_UP3X)) { |
| 1502 |
rtw8852c_spur_notch(rtwdev, 0xe7f, RTW89_PHY_0); |
| 1503 |
if (!rtwdev->dbcc_en) |
| 1504 |
rtw8852c_spur_notch(rtwdev, 0xe7f, RTW89_PHY_1); |
| 1505 |
} else if (chan->band_width == RTW89_CHANNEL_WIDTH_160 && |
| 1506 |
(pri_ch_idx == RTW89_SC_20_UPPER || |
| 1507 |
pri_ch_idx == RTW89_SC_20_LOW3X)) { |
| 1508 |
rtw8852c_spur_notch(rtwdev, 0x280, RTW89_PHY_0); |
| 1509 |
if (!rtwdev->dbcc_en) |
| 1510 |
rtw8852c_spur_notch(rtwdev, 0x280, RTW89_PHY_1); |
| 1511 |
} else { |
| 1512 |
rtw8852c_set_nbi_tone_idx(rtwdev, chan, RF_PATH_A); |
| 1513 |
if (!rtwdev->dbcc_en) |
| 1514 |
rtw8852c_set_nbi_tone_idx(rtwdev, chan, |
| 1515 |
RF_PATH_B); |
| 1516 |
} |
| 1517 |
} else { |
| 1518 |
if (chan->band_width == RTW89_CHANNEL_WIDTH_160 && |
| 1519 |
(pri_ch_idx == RTW89_SC_20_LOWER || |
| 1520 |
pri_ch_idx == RTW89_SC_20_UP3X)) { |
| 1521 |
rtw8852c_spur_notch(rtwdev, 0xe7f, RTW89_PHY_1); |
| 1522 |
} else if (chan->band_width == RTW89_CHANNEL_WIDTH_160 && |
| 1523 |
(pri_ch_idx == RTW89_SC_20_UPPER || |
| 1524 |
pri_ch_idx == RTW89_SC_20_LOW3X)) { |
| 1525 |
rtw8852c_spur_notch(rtwdev, 0x280, RTW89_PHY_1); |
| 1526 |
} else { |
| 1527 |
rtw8852c_set_nbi_tone_idx(rtwdev, chan, RF_PATH_B); |
| 1528 |
} |
| 1529 |
} |
| 1530 |
|
| 1531 |
if (pri_ch_idx == RTW89_SC_20_UP3X || pri_ch_idx == RTW89_SC_20_LOW3X) |
| 1532 |
rtw89_phy_write32_idx(rtwdev, R_PD_BOOST_EN, B_PD_BOOST_EN, 0, phy_idx); |
| 1533 |
else |
| 1534 |
rtw89_phy_write32_idx(rtwdev, R_PD_BOOST_EN, B_PD_BOOST_EN, 1, phy_idx); |
| 1535 |
} |
| 1536 |
|
| 1537 |
static void rtw8852c_5m_mask(struct rtw89_dev *rtwdev, |
| 1538 |
const struct rtw89_chan *chan, |
| 1539 |
enum rtw89_phy_idx phy_idx) |
| 1540 |
{ |
| 1541 |
u8 pri_ch = chan->pri_ch_idx; |
| 1542 |
bool mask_5m_low; |
| 1543 |
bool mask_5m_en; |
| 1544 |
|
| 1545 |
switch (chan->band_width) { |
| 1546 |
case RTW89_CHANNEL_WIDTH_40: |
| 1547 |
mask_5m_en = true; |
| 1548 |
mask_5m_low = pri_ch == RTW89_SC_20_LOWER; |
| 1549 |
break; |
| 1550 |
case RTW89_CHANNEL_WIDTH_80: |
| 1551 |
mask_5m_en = pri_ch == RTW89_SC_20_UPMOST || |
| 1552 |
pri_ch == RTW89_SC_20_LOWEST; |
| 1553 |
mask_5m_low = pri_ch == RTW89_SC_20_LOWEST; |
| 1554 |
break; |
| 1555 |
default: |
| 1556 |
mask_5m_en = false; |
| 1557 |
mask_5m_low = false; |
| 1558 |
break; |
| 1559 |
} |
| 1560 |
|
| 1561 |
if (!mask_5m_en) { |
| 1562 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET, B_PATH0_5MDET_EN, 0x0); |
| 1563 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET, B_PATH1_5MDET_EN, 0x0); |
| 1564 |
rtw89_phy_write32_idx(rtwdev, R_ASSIGN_SBD_OPT, |
| 1565 |
B_ASSIGN_SBD_OPT_EN, 0x0, phy_idx); |
| 1566 |
} else { |
| 1567 |
if (mask_5m_low) { |
| 1568 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET, B_PATH0_5MDET_TH, 0x4); |
| 1569 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET, B_PATH0_5MDET_EN, 0x1); |
| 1570 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET, B_PATH0_5MDET_SB2, 0x0); |
| 1571 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET, B_PATH0_5MDET_SB0, 0x1); |
| 1572 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET, B_PATH1_5MDET_TH, 0x4); |
| 1573 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET, B_PATH1_5MDET_EN, 0x1); |
| 1574 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET, B_PATH1_5MDET_SB2, 0x0); |
| 1575 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET, B_PATH1_5MDET_SB0, 0x1); |
| 1576 |
} else { |
| 1577 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET, B_PATH0_5MDET_TH, 0x4); |
| 1578 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET, B_PATH0_5MDET_EN, 0x1); |
| 1579 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET, B_PATH0_5MDET_SB2, 0x1); |
| 1580 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET, B_PATH0_5MDET_SB0, 0x0); |
| 1581 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET, B_PATH1_5MDET_TH, 0x4); |
| 1582 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET, B_PATH1_5MDET_EN, 0x1); |
| 1583 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET, B_PATH1_5MDET_SB2, 0x1); |
| 1584 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET, B_PATH1_5MDET_SB0, 0x0); |
| 1585 |
} |
| 1586 |
rtw89_phy_write32_idx(rtwdev, R_ASSIGN_SBD_OPT, B_ASSIGN_SBD_OPT_EN, 0x1, phy_idx); |
| 1587 |
} |
| 1588 |
} |
| 1589 |
|
| 1590 |
static void rtw8852c_bb_reset_all(struct rtw89_dev *rtwdev, |
| 1591 |
enum rtw89_phy_idx phy_idx) |
| 1592 |
{ |
| 1593 |
/*HW SI reset*/ |
| 1594 |
rtw89_phy_write32_mask(rtwdev, R_S0_HW_SI_DIS, B_S0_HW_SI_DIS_W_R_TRIG, |
| 1595 |
0x7); |
| 1596 |
rtw89_phy_write32_mask(rtwdev, R_S1_HW_SI_DIS, B_S1_HW_SI_DIS_W_R_TRIG, |
| 1597 |
0x7); |
| 1598 |
|
| 1599 |
udelay(1); |
| 1600 |
|
| 1601 |
rtw89_phy_write32_idx(rtwdev, R_RSTB_ASYNC, B_RSTB_ASYNC_ALL, 1, |
| 1602 |
phy_idx); |
| 1603 |
rtw89_phy_write32_idx(rtwdev, R_RSTB_ASYNC, B_RSTB_ASYNC_ALL, 0, |
| 1604 |
phy_idx); |
| 1605 |
/*HW SI reset*/ |
| 1606 |
rtw89_phy_write32_mask(rtwdev, R_S0_HW_SI_DIS, B_S0_HW_SI_DIS_W_R_TRIG, |
| 1607 |
0x0); |
| 1608 |
rtw89_phy_write32_mask(rtwdev, R_S1_HW_SI_DIS, B_S1_HW_SI_DIS_W_R_TRIG, |
| 1609 |
0x0); |
| 1610 |
|
| 1611 |
rtw89_phy_write32_idx(rtwdev, R_RSTB_ASYNC, B_RSTB_ASYNC_ALL, 1, |
| 1612 |
phy_idx); |
| 1613 |
} |
| 1614 |
|
| 1615 |
static void rtw8852c_bb_reset_en(struct rtw89_dev *rtwdev, enum rtw89_band band, |
| 1616 |
enum rtw89_phy_idx phy_idx, bool en) |
| 1617 |
{ |
| 1618 |
if (en) { |
| 1619 |
rtw89_phy_write32_idx(rtwdev, R_S0_HW_SI_DIS, |
| 1620 |
B_S0_HW_SI_DIS_W_R_TRIG, 0x0, phy_idx); |
| 1621 |
rtw89_phy_write32_idx(rtwdev, R_S1_HW_SI_DIS, |
| 1622 |
B_S1_HW_SI_DIS_W_R_TRIG, 0x0, phy_idx); |
| 1623 |
rtw89_phy_write32_idx(rtwdev, R_RSTB_ASYNC, B_RSTB_ASYNC_ALL, 1, |
| 1624 |
phy_idx); |
| 1625 |
if (band == RTW89_BAND_2G) |
| 1626 |
rtw89_phy_write32_mask(rtwdev, R_RXCCA_V1, B_RXCCA_DIS_V1, 0x0); |
| 1627 |
rtw89_phy_write32_mask(rtwdev, R_PD_CTRL, B_PD_HIT_DIS, 0x0); |
| 1628 |
} else { |
| 1629 |
rtw89_phy_write32_mask(rtwdev, R_RXCCA_V1, B_RXCCA_DIS_V1, 0x1); |
| 1630 |
rtw89_phy_write32_mask(rtwdev, R_PD_CTRL, B_PD_HIT_DIS, 0x1); |
| 1631 |
rtw89_phy_write32_idx(rtwdev, R_S0_HW_SI_DIS, |
| 1632 |
B_S0_HW_SI_DIS_W_R_TRIG, 0x7, phy_idx); |
| 1633 |
rtw89_phy_write32_idx(rtwdev, R_S1_HW_SI_DIS, |
| 1634 |
B_S1_HW_SI_DIS_W_R_TRIG, 0x7, phy_idx); |
| 1635 |
fsleep(1); |
| 1636 |
rtw89_phy_write32_idx(rtwdev, R_RSTB_ASYNC, B_RSTB_ASYNC_ALL, 0, |
| 1637 |
phy_idx); |
| 1638 |
} |
| 1639 |
} |
| 1640 |
|
| 1641 |
static void rtw8852c_bb_reset(struct rtw89_dev *rtwdev, |
| 1642 |
enum rtw89_phy_idx phy_idx) |
| 1643 |
{ |
| 1644 |
rtw8852c_bb_reset_all(rtwdev, phy_idx); |
| 1645 |
} |
| 1646 |
|
| 1647 |
static |
| 1648 |
void rtw8852c_bb_gpio_trsw(struct rtw89_dev *rtwdev, enum rtw89_rf_path path, |
| 1649 |
u8 tx_path_en, u8 trsw_tx, |
| 1650 |
u8 trsw_rx, u8 trsw, u8 trsw_b) |
| 1651 |
{ |
| 1652 |
static const u32 path_cr_bases[] = {0x5868, 0x7868}; |
| 1653 |
u32 mask_ofst = 16; |
| 1654 |
u32 cr; |
| 1655 |
u32 val; |
| 1656 |
|
| 1657 |
if (path >= ARRAY_SIZE(path_cr_bases)) |
| 1658 |
return; |
| 1659 |
|
| 1660 |
cr = path_cr_bases[path]; |
| 1661 |
|
| 1662 |
mask_ofst += (tx_path_en * 4 + trsw_tx * 2 + trsw_rx) * 2; |
| 1663 |
val = FIELD_PREP(B_P0_TRSW_A, trsw) | FIELD_PREP(B_P0_TRSW_B, trsw_b); |
| 1664 |
|
| 1665 |
rtw89_phy_write32_mask(rtwdev, cr, (B_P0_TRSW_A | B_P0_TRSW_B) << mask_ofst, val); |
| 1666 |
} |
| 1667 |
|
| 1668 |
enum rtw8852c_rfe_src { |
| 1669 |
PAPE_RFM, |
| 1670 |
TRSW_RFM, |
| 1671 |
LNAON_RFM, |
| 1672 |
}; |
| 1673 |
|
| 1674 |
static |
| 1675 |
void rtw8852c_bb_gpio_rfm(struct rtw89_dev *rtwdev, enum rtw89_rf_path path, |
| 1676 |
enum rtw8852c_rfe_src src, u8 dis_tx_gnt_wl, |
| 1677 |
u8 active_tx_opt, u8 act_bt_en, u8 rfm_output_val) |
| 1678 |
{ |
| 1679 |
static const u32 path_cr_bases[] = {0x5894, 0x7894}; |
| 1680 |
static const u32 masks[] = {0, 8, 16}; |
| 1681 |
u32 mask, mask_ofst; |
| 1682 |
u32 cr; |
| 1683 |
u32 val; |
| 1684 |
|
| 1685 |
if (src >= ARRAY_SIZE(masks) || path >= ARRAY_SIZE(path_cr_bases)) |
| 1686 |
return; |
| 1687 |
|
| 1688 |
mask_ofst = masks[src]; |
| 1689 |
cr = path_cr_bases[path]; |
| 1690 |
|
| 1691 |
val = FIELD_PREP(B_P0_RFM_DIS_WL, dis_tx_gnt_wl) | |
| 1692 |
FIELD_PREP(B_P0_RFM_TX_OPT, active_tx_opt) | |
| 1693 |
FIELD_PREP(B_P0_RFM_BT_EN, act_bt_en) | |
| 1694 |
FIELD_PREP(B_P0_RFM_OUT, rfm_output_val); |
| 1695 |
mask = 0xff << mask_ofst; |
| 1696 |
|
| 1697 |
rtw89_phy_write32_mask(rtwdev, cr, mask, val); |
| 1698 |
} |
| 1699 |
|
| 1700 |
static void rtw8852c_bb_gpio_init(struct rtw89_dev *rtwdev) |
| 1701 |
{ |
| 1702 |
static const u32 cr_bases[] = {0x5800, 0x7800}; |
| 1703 |
u32 addr; |
| 1704 |
u8 i; |
| 1705 |
|
| 1706 |
for (i = 0; i < ARRAY_SIZE(cr_bases); i++) { |
| 1707 |
addr = cr_bases[i]; |
| 1708 |
rtw89_phy_write32_set(rtwdev, (addr | 0x68), B_P0_TRSW_A); |
| 1709 |
rtw89_phy_write32_clr(rtwdev, (addr | 0x68), B_P0_TRSW_X); |
| 1710 |
rtw89_phy_write32_clr(rtwdev, (addr | 0x68), B_P0_TRSW_SO_A2); |
| 1711 |
rtw89_phy_write32(rtwdev, (addr | 0x80), 0x77777777); |
| 1712 |
rtw89_phy_write32(rtwdev, (addr | 0x84), 0x77777777); |
| 1713 |
} |
| 1714 |
|
| 1715 |
rtw89_phy_write32(rtwdev, R_RFE_E_A2, 0xffffffff); |
| 1716 |
rtw89_phy_write32(rtwdev, R_RFE_O_SEL_A2, 0); |
| 1717 |
rtw89_phy_write32(rtwdev, R_RFE_SEL0_A2, 0); |
| 1718 |
rtw89_phy_write32(rtwdev, R_RFE_SEL32_A2, 0); |
| 1719 |
|
| 1720 |
rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_A, 0, 0, 0, 0, 1); |
| 1721 |
rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_A, 0, 0, 1, 1, 0); |
| 1722 |
rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_A, 0, 1, 0, 1, 0); |
| 1723 |
rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_A, 0, 1, 1, 1, 0); |
| 1724 |
rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_A, 1, 0, 0, 0, 1); |
| 1725 |
rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_A, 1, 0, 1, 1, 0); |
| 1726 |
rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_A, 1, 1, 0, 1, 0); |
| 1727 |
rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_A, 1, 1, 1, 1, 0); |
| 1728 |
|
| 1729 |
rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_B, 0, 0, 0, 0, 1); |
| 1730 |
rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_B, 0, 0, 1, 1, 0); |
| 1731 |
rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_B, 0, 1, 0, 1, 0); |
| 1732 |
rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_B, 0, 1, 1, 1, 0); |
| 1733 |
rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_B, 1, 0, 0, 0, 1); |
| 1734 |
rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_B, 1, 0, 1, 1, 0); |
| 1735 |
rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_B, 1, 1, 0, 1, 0); |
| 1736 |
rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_B, 1, 1, 1, 1, 0); |
| 1737 |
|
| 1738 |
rtw8852c_bb_gpio_rfm(rtwdev, RF_PATH_A, PAPE_RFM, 0, 0, 0, 0x0); |
| 1739 |
rtw8852c_bb_gpio_rfm(rtwdev, RF_PATH_A, TRSW_RFM, 0, 0, 0, 0x4); |
| 1740 |
rtw8852c_bb_gpio_rfm(rtwdev, RF_PATH_A, LNAON_RFM, 0, 0, 0, 0x8); |
| 1741 |
|
| 1742 |
rtw8852c_bb_gpio_rfm(rtwdev, RF_PATH_B, PAPE_RFM, 0, 0, 0, 0x0); |
| 1743 |
rtw8852c_bb_gpio_rfm(rtwdev, RF_PATH_B, TRSW_RFM, 0, 0, 0, 0x4); |
| 1744 |
rtw8852c_bb_gpio_rfm(rtwdev, RF_PATH_B, LNAON_RFM, 0, 0, 0, 0x8); |
| 1745 |
} |
| 1746 |
|
| 1747 |
static void rtw8852c_bb_macid_ctrl_init(struct rtw89_dev *rtwdev, |
| 1748 |
enum rtw89_phy_idx phy_idx) |
| 1749 |
{ |
| 1750 |
u32 addr; |
| 1751 |
|
| 1752 |
for (addr = R_AX_PWR_MACID_LMT_TABLE0; |
| 1753 |
addr <= R_AX_PWR_MACID_LMT_TABLE127; addr += 4) |
| 1754 |
rtw89_mac_txpwr_write32(rtwdev, phy_idx, addr, 0); |
| 1755 |
} |
| 1756 |
|
| 1757 |
static void rtw8852c_bb_sethw(struct rtw89_dev *rtwdev) |
| 1758 |
{ |
| 1759 |
struct rtw89_phy_efuse_gain *gain = &rtwdev->efuse_gain; |
| 1760 |
|
| 1761 |
rtw89_phy_write32_set(rtwdev, R_DBCC_80P80_SEL_EVM_RPT, |
| 1762 |
B_DBCC_80P80_SEL_EVM_RPT_EN); |
| 1763 |
rtw89_phy_write32_set(rtwdev, R_DBCC_80P80_SEL_EVM_RPT2, |
| 1764 |
B_DBCC_80P80_SEL_EVM_RPT2_EN); |
| 1765 |
|
| 1766 |
rtw8852c_bb_macid_ctrl_init(rtwdev, RTW89_PHY_0); |
| 1767 |
rtw8852c_bb_gpio_init(rtwdev); |
| 1768 |
|
| 1769 |
/* read these registers after loading BB parameters */ |
| 1770 |
gain->offset_base[RTW89_PHY_0] = |
| 1771 |
rtw89_phy_read32_mask(rtwdev, R_RPL_BIAS_COMP, B_RPL_BIAS_COMP_MASK); |
| 1772 |
gain->offset_base[RTW89_PHY_1] = |
| 1773 |
rtw89_phy_read32_mask(rtwdev, R_RPL_BIAS_COMP1, B_RPL_BIAS_COMP1_MASK); |
| 1774 |
} |
| 1775 |
|
| 1776 |
static void rtw8852c_set_channel_bb(struct rtw89_dev *rtwdev, |
| 1777 |
const struct rtw89_chan *chan, |
| 1778 |
enum rtw89_phy_idx phy_idx) |
| 1779 |
{ |
| 1780 |
static const u32 ru_alloc_msk[2] = {B_P80_AT_HIGH_FREQ_RU_ALLOC_PHY0, |
| 1781 |
B_P80_AT_HIGH_FREQ_RU_ALLOC_PHY1}; |
| 1782 |
struct rtw89_hal *hal = &rtwdev->hal; |
| 1783 |
bool cck_en = chan->band_type == RTW89_BAND_2G; |
| 1784 |
u8 pri_ch_idx = chan->pri_ch_idx; |
| 1785 |
u32 mask, reg; |
| 1786 |
u8 ntx_path; |
| 1787 |
|
| 1788 |
if (chan->band_type == RTW89_BAND_2G) |
| 1789 |
rtw8852c_ctrl_sco_cck(rtwdev, chan->channel, |
| 1790 |
chan->primary_channel, |
| 1791 |
chan->band_width); |
| 1792 |
|
| 1793 |
rtw8852c_ctrl_ch(rtwdev, chan, phy_idx); |
| 1794 |
rtw8852c_ctrl_bw(rtwdev, pri_ch_idx, chan->band_width, phy_idx); |
| 1795 |
if (cck_en) { |
| 1796 |
rtw89_phy_write32_mask(rtwdev, R_UPD_CLK_ADC, B_ENABLE_CCK, 1); |
| 1797 |
rtw89_phy_write32_mask(rtwdev, R_RXCCA_V1, B_RXCCA_DIS_V1, 0); |
| 1798 |
rtw89_phy_write32_idx(rtwdev, R_PD_ARBITER_OFF, |
| 1799 |
B_PD_ARBITER_OFF, 0x0, phy_idx); |
| 1800 |
} else { |
| 1801 |
rtw89_phy_write32_mask(rtwdev, R_UPD_CLK_ADC, B_ENABLE_CCK, 0); |
| 1802 |
rtw89_phy_write32_mask(rtwdev, R_RXCCA_V1, B_RXCCA_DIS_V1, 1); |
| 1803 |
rtw89_phy_write32_idx(rtwdev, R_PD_ARBITER_OFF, |
| 1804 |
B_PD_ARBITER_OFF, 0x1, phy_idx); |
| 1805 |
} |
| 1806 |
|
| 1807 |
rtw8852c_spur_elimination(rtwdev, chan, pri_ch_idx, phy_idx); |
| 1808 |
rtw8852c_ctrl_btg_bt_rx(rtwdev, chan->band_type == RTW89_BAND_2G, |
| 1809 |
RTW89_PHY_0); |
| 1810 |
rtw8852c_5m_mask(rtwdev, chan, phy_idx); |
| 1811 |
|
| 1812 |
if (chan->band_width == RTW89_CHANNEL_WIDTH_160 && |
| 1813 |
rtwdev->hal.cv != CHIP_CAV) { |
| 1814 |
rtw89_phy_write32_idx(rtwdev, R_P80_AT_HIGH_FREQ, |
| 1815 |
B_P80_AT_HIGH_FREQ, 0x0, phy_idx); |
| 1816 |
reg = rtw89_mac_reg_by_idx(rtwdev, R_P80_AT_HIGH_FREQ_BB_WRP, phy_idx); |
| 1817 |
if (chan->primary_channel > chan->channel) { |
| 1818 |
rtw89_phy_write32_mask(rtwdev, |
| 1819 |
R_P80_AT_HIGH_FREQ_RU_ALLOC, |
| 1820 |
ru_alloc_msk[phy_idx], 1); |
| 1821 |
rtw89_write32_mask(rtwdev, reg, |
| 1822 |
B_P80_AT_HIGH_FREQ_BB_WRP, 1); |
| 1823 |
} else { |
| 1824 |
rtw89_phy_write32_mask(rtwdev, |
| 1825 |
R_P80_AT_HIGH_FREQ_RU_ALLOC, |
| 1826 |
ru_alloc_msk[phy_idx], 0); |
| 1827 |
rtw89_write32_mask(rtwdev, reg, |
| 1828 |
B_P80_AT_HIGH_FREQ_BB_WRP, 0); |
| 1829 |
} |
| 1830 |
} |
| 1831 |
|
| 1832 |
if (chan->band_type == RTW89_BAND_6G && |
| 1833 |
chan->band_width == RTW89_CHANNEL_WIDTH_160) |
| 1834 |
rtw89_phy_write32_idx(rtwdev, R_CDD_EVM_CHK_EN, |
| 1835 |
B_CDD_EVM_CHK_EN, 0, phy_idx); |
| 1836 |
else |
| 1837 |
rtw89_phy_write32_idx(rtwdev, R_CDD_EVM_CHK_EN, |
| 1838 |
B_CDD_EVM_CHK_EN, 1, phy_idx); |
| 1839 |
|
| 1840 |
if (!rtwdev->dbcc_en) { |
| 1841 |
mask = B_P0_TXPW_RSTB_TSSI | B_P0_TXPW_RSTB_MANON; |
| 1842 |
rtw89_phy_write32_mask(rtwdev, R_P0_TXPW_RSTB, mask, 0x1); |
| 1843 |
rtw89_phy_write32_mask(rtwdev, R_P0_TXPW_RSTB, mask, 0x3); |
| 1844 |
mask = B_P1_TXPW_RSTB_TSSI | B_P1_TXPW_RSTB_MANON; |
| 1845 |
rtw89_phy_write32_mask(rtwdev, R_P1_TXPW_RSTB, mask, 0x1); |
| 1846 |
rtw89_phy_write32_mask(rtwdev, R_P1_TXPW_RSTB, mask, 0x3); |
| 1847 |
} else { |
| 1848 |
if (phy_idx == RTW89_PHY_0) { |
| 1849 |
mask = B_P0_TXPW_RSTB_TSSI | B_P0_TXPW_RSTB_MANON; |
| 1850 |
rtw89_phy_write32_mask(rtwdev, R_P0_TXPW_RSTB, mask, 0x1); |
| 1851 |
rtw89_phy_write32_mask(rtwdev, R_P0_TXPW_RSTB, mask, 0x3); |
| 1852 |
} else { |
| 1853 |
mask = B_P1_TXPW_RSTB_TSSI | B_P1_TXPW_RSTB_MANON; |
| 1854 |
rtw89_phy_write32_mask(rtwdev, R_P1_TXPW_RSTB, mask, 0x1); |
| 1855 |
rtw89_phy_write32_mask(rtwdev, R_P1_TXPW_RSTB, mask, 0x3); |
| 1856 |
} |
| 1857 |
} |
| 1858 |
|
| 1859 |
if (chan->band_type == RTW89_BAND_6G) |
| 1860 |
rtw89_phy_write32_set(rtwdev, R_MUIC, B_MUIC_EN); |
| 1861 |
else |
| 1862 |
rtw89_phy_write32_clr(rtwdev, R_MUIC, B_MUIC_EN); |
| 1863 |
|
| 1864 |
if (hal->antenna_tx) |
| 1865 |
ntx_path = hal->antenna_tx; |
| 1866 |
else |
| 1867 |
ntx_path = chan->band_type == RTW89_BAND_6G ? RF_B : RF_AB; |
| 1868 |
|
| 1869 |
rtw8852c_ctrl_tx_path_tmac(rtwdev, ntx_path, (enum rtw89_mac_idx)phy_idx); |
| 1870 |
|
| 1871 |
rtw8852c_bb_reset_all(rtwdev, phy_idx); |
| 1872 |
} |
| 1873 |
|
| 1874 |
static void rtw8852c_set_channel(struct rtw89_dev *rtwdev, |
| 1875 |
const struct rtw89_chan *chan, |
| 1876 |
enum rtw89_mac_idx mac_idx, |
| 1877 |
enum rtw89_phy_idx phy_idx) |
| 1878 |
{ |
| 1879 |
rtw8852c_set_channel_mac(rtwdev, chan, mac_idx); |
| 1880 |
rtw8852c_set_channel_bb(rtwdev, chan, phy_idx); |
| 1881 |
rtw8852c_set_channel_rf(rtwdev, chan, phy_idx); |
| 1882 |
} |
| 1883 |
|
| 1884 |
static void rtw8852c_dfs_en(struct rtw89_dev *rtwdev, bool en) |
| 1885 |
{ |
| 1886 |
if (en) |
| 1887 |
rtw89_phy_write32_mask(rtwdev, R_UPD_P0, B_UPD_P0_EN, 1); |
| 1888 |
else |
| 1889 |
rtw89_phy_write32_mask(rtwdev, R_UPD_P0, B_UPD_P0_EN, 0); |
| 1890 |
} |
| 1891 |
|
| 1892 |
static void rtw8852c_adc_en(struct rtw89_dev *rtwdev, bool en) |
| 1893 |
{ |
| 1894 |
if (en) |
| 1895 |
rtw89_phy_write32_mask(rtwdev, R_ADC_FIFO, B_ADC_FIFO_RST, |
| 1896 |
0x0); |
| 1897 |
else |
| 1898 |
rtw89_phy_write32_mask(rtwdev, R_ADC_FIFO, B_ADC_FIFO_RST, |
| 1899 |
0xf); |
| 1900 |
} |
| 1901 |
|
| 1902 |
static void rtw8852c_set_channel_help(struct rtw89_dev *rtwdev, bool enter, |
| 1903 |
struct rtw89_channel_help_params *p, |
| 1904 |
const struct rtw89_chan *chan, |
| 1905 |
enum rtw89_mac_idx mac_idx, |
| 1906 |
enum rtw89_phy_idx phy_idx) |
| 1907 |
{ |
| 1908 |
if (enter) { |
| 1909 |
rtw89_chip_stop_sch_tx(rtwdev, mac_idx, &p->tx_en, |
| 1910 |
RTW89_SCH_TX_SEL_ALL); |
| 1911 |
rtw89_mac_cfg_ppdu_status(rtwdev, mac_idx, false); |
| 1912 |
rtw8852c_dfs_en(rtwdev, false); |
| 1913 |
rtw8852c_tssi_cont_en_phyidx(rtwdev, false, phy_idx, chan); |
| 1914 |
rtw8852c_adc_en(rtwdev, false); |
| 1915 |
fsleep(40); |
| 1916 |
rtw8852c_bb_reset_en(rtwdev, chan->band_type, phy_idx, false); |
| 1917 |
} else { |
| 1918 |
rtw89_mac_cfg_ppdu_status(rtwdev, mac_idx, true); |
| 1919 |
rtw8852c_adc_en(rtwdev, true); |
| 1920 |
rtw8852c_dfs_en(rtwdev, true); |
| 1921 |
rtw8852c_tssi_cont_en_phyidx(rtwdev, true, phy_idx, chan); |
| 1922 |
rtw8852c_bb_reset_en(rtwdev, chan->band_type, phy_idx, true); |
| 1923 |
rtw89_chip_resume_sch_tx(rtwdev, mac_idx, p->tx_en); |
| 1924 |
} |
| 1925 |
} |
| 1926 |
|
| 1927 |
static void rtw8852c_rfk_init(struct rtw89_dev *rtwdev) |
| 1928 |
{ |
| 1929 |
struct rtw89_rfk_mcc_info *rfk_mcc = &rtwdev->rfk_mcc; |
| 1930 |
|
| 1931 |
rtwdev->is_tssi_mode[RF_PATH_A] = false; |
| 1932 |
rtwdev->is_tssi_mode[RF_PATH_B] = false; |
| 1933 |
memset(rfk_mcc, 0, sizeof(*rfk_mcc)); |
| 1934 |
rtw8852c_lck_init(rtwdev); |
| 1935 |
rtw8852c_dpk_init(rtwdev); |
| 1936 |
|
| 1937 |
rtw8852c_rck(rtwdev); |
| 1938 |
rtw8852c_dack(rtwdev, RTW89_CHANCTX_0); |
| 1939 |
rtw8852c_rx_dck(rtwdev, RTW89_PHY_0, false); |
| 1940 |
} |
| 1941 |
|
| 1942 |
static void rtw8852c_rfk_channel(struct rtw89_dev *rtwdev, |
| 1943 |
struct rtw89_vif_link *rtwvif_link) |
| 1944 |
{ |
| 1945 |
enum rtw89_chanctx_idx chanctx_idx = rtwvif_link->chanctx_idx; |
| 1946 |
enum rtw89_phy_idx phy_idx = rtwvif_link->phy_idx; |
| 1947 |
|
| 1948 |
rtw8852c_mcc_get_ch_info(rtwdev, phy_idx); |
| 1949 |
rtw89_btc_ntfy_conn_rfk(rtwdev, true); |
| 1950 |
|
| 1951 |
rtw8852c_rx_dck(rtwdev, phy_idx, false); |
| 1952 |
rtw8852c_iqk(rtwdev, phy_idx, chanctx_idx); |
| 1953 |
rtw89_btc_ntfy_preserve_bt_time(rtwdev, 30); |
| 1954 |
rtw8852c_tssi(rtwdev, phy_idx, chanctx_idx); |
| 1955 |
rtw89_btc_ntfy_preserve_bt_time(rtwdev, 30); |
| 1956 |
rtw8852c_dpk(rtwdev, phy_idx, chanctx_idx); |
| 1957 |
|
| 1958 |
rtw89_btc_ntfy_conn_rfk(rtwdev, false); |
| 1959 |
rtw89_fw_h2c_rf_ntfy_mcc(rtwdev); |
| 1960 |
} |
| 1961 |
|
| 1962 |
static void rtw8852c_rfk_band_changed(struct rtw89_dev *rtwdev, |
| 1963 |
enum rtw89_phy_idx phy_idx, |
| 1964 |
const struct rtw89_chan *chan) |
| 1965 |
{ |
| 1966 |
rtw8852c_tssi_scan(rtwdev, phy_idx, chan); |
| 1967 |
} |
| 1968 |
|
| 1969 |
static void rtw8852c_rfk_scan(struct rtw89_dev *rtwdev, |
| 1970 |
struct rtw89_vif_link *rtwvif_link, |
| 1971 |
bool start) |
| 1972 |
{ |
| 1973 |
rtw8852c_wifi_scan_notify(rtwdev, start, rtwvif_link->phy_idx); |
| 1974 |
} |
| 1975 |
|
| 1976 |
static void rtw8852c_rfk_track(struct rtw89_dev *rtwdev) |
| 1977 |
{ |
| 1978 |
rtw8852c_dpk_track(rtwdev); |
| 1979 |
rtw8852c_lck_track(rtwdev); |
| 1980 |
rtw8852c_rx_dck_track(rtwdev); |
| 1981 |
} |
| 1982 |
|
| 1983 |
static u32 rtw8852c_bb_cal_txpwr_ref(struct rtw89_dev *rtwdev, |
| 1984 |
enum rtw89_phy_idx phy_idx, |
| 1985 |
s16 ref, u16 pwr_ofst_decrease) |
| 1986 |
{ |
| 1987 |
u8 base_cw_0db = 0x27; |
| 1988 |
u16 tssi_16dbm_cw = 0x12c; |
| 1989 |
s16 pwr_s10_3 = 0; |
| 1990 |
s16 rf_pwr_cw = 0; |
| 1991 |
u16 bb_pwr_cw = 0; |
| 1992 |
u32 pwr_cw = 0; |
| 1993 |
u32 tssi_ofst_cw = 0; |
| 1994 |
|
| 1995 |
pwr_s10_3 = (ref << 1) + (s16)(base_cw_0db << 3) - pwr_ofst_decrease; |
| 1996 |
bb_pwr_cw = FIELD_GET(GENMASK(2, 0), pwr_s10_3); |
| 1997 |
rf_pwr_cw = FIELD_GET(GENMASK(8, 3), pwr_s10_3); |
| 1998 |
rf_pwr_cw = clamp_t(s16, rf_pwr_cw, 15, 63); |
| 1999 |
pwr_cw = (rf_pwr_cw << 3) | bb_pwr_cw; |
| 2000 |
|
| 2001 |
tssi_ofst_cw = (u32)((s16)tssi_16dbm_cw + (ref << 1) - (16 << 3)) - |
| 2002 |
pwr_ofst_decrease; |
| 2003 |
rtw89_debug(rtwdev, RTW89_DBG_TXPWR, |
| 2004 |
"[TXPWR] tssi_ofst_cw=%d rf_cw=0x%x bb_cw=0x%x\n", |
| 2005 |
tssi_ofst_cw, rf_pwr_cw, bb_pwr_cw); |
| 2006 |
|
| 2007 |
return (tssi_ofst_cw << 18) | (pwr_cw << 9) | (ref & GENMASK(8, 0)); |
| 2008 |
} |
| 2009 |
|
| 2010 |
static |
| 2011 |
void rtw8852c_set_txpwr_ul_tb_offset(struct rtw89_dev *rtwdev, |
| 2012 |
s8 pw_ofst, enum rtw89_mac_idx mac_idx) |
| 2013 |
{ |
| 2014 |
s8 pw_ofst_2tx; |
| 2015 |
s8 val_1t; |
| 2016 |
s8 val_2t; |
| 2017 |
u32 reg; |
| 2018 |
u8 i; |
| 2019 |
|
| 2020 |
if (pw_ofst < -32 || pw_ofst > 31) { |
| 2021 |
rtw89_warn(rtwdev, "[ULTB] Err pwr_offset=%d\n", pw_ofst); |
| 2022 |
return; |
| 2023 |
} |
| 2024 |
val_1t = pw_ofst << 2; |
| 2025 |
pw_ofst_2tx = max(pw_ofst - 3, -32); |
| 2026 |
val_2t = pw_ofst_2tx << 2; |
| 2027 |
|
| 2028 |
rtw89_debug(rtwdev, RTW89_DBG_TXPWR, "[ULTB] val_1tx=0x%x\n", val_1t); |
| 2029 |
rtw89_debug(rtwdev, RTW89_DBG_TXPWR, "[ULTB] val_2tx=0x%x\n", val_2t); |
| 2030 |
|
| 2031 |
for (i = 0; i < 4; i++) { |
| 2032 |
/* 1TX */ |
| 2033 |
reg = rtw89_mac_reg_by_idx(rtwdev, R_AX_PWR_UL_TB_1T, mac_idx); |
| 2034 |
rtw89_write32_mask(rtwdev, reg, |
| 2035 |
B_AX_PWR_UL_TB_1T_V1_MASK << (8 * i), |
| 2036 |
val_1t); |
| 2037 |
/* 2TX */ |
| 2038 |
reg = rtw89_mac_reg_by_idx(rtwdev, R_AX_PWR_UL_TB_2T, mac_idx); |
| 2039 |
rtw89_write32_mask(rtwdev, reg, |
| 2040 |
B_AX_PWR_UL_TB_2T_V1_MASK << (8 * i), |
| 2041 |
val_2t); |
| 2042 |
} |
| 2043 |
} |
| 2044 |
|
| 2045 |
static void rtw8852c_set_txpwr_ref(struct rtw89_dev *rtwdev, |
| 2046 |
enum rtw89_phy_idx phy_idx, s16 pwr_ofst) |
| 2047 |
{ |
| 2048 |
static const u32 addr[RF_PATH_NUM_8852C] = {0x5800, 0x7800}; |
| 2049 |
u16 ofst_dec[RF_PATH_NUM_8852C]; |
| 2050 |
const u32 mask = 0x7FFFFFF; |
| 2051 |
const u8 ofst_ofdm = 0x4; |
| 2052 |
const u8 ofst_cck = 0x8; |
| 2053 |
s16 ref_ofdm = 0; |
| 2054 |
s16 ref_cck = 0; |
| 2055 |
u32 val; |
| 2056 |
u8 i; |
| 2057 |
|
| 2058 |
rtw89_debug(rtwdev, RTW89_DBG_TXPWR, "[TXPWR] set txpwr reference\n"); |
| 2059 |
|
| 2060 |
rtw89_mac_txpwr_write32_mask(rtwdev, phy_idx, R_AX_PWR_RATE_CTRL, |
| 2061 |
GENMASK(27, 10), 0x0); |
| 2062 |
|
| 2063 |
ofst_dec[RF_PATH_A] = pwr_ofst > 0 ? 0 : abs(pwr_ofst); |
| 2064 |
ofst_dec[RF_PATH_B] = pwr_ofst > 0 ? pwr_ofst : 0; |
| 2065 |
|
| 2066 |
rtw89_debug(rtwdev, RTW89_DBG_TXPWR, "[TXPWR] set bb ofdm txpwr ref\n"); |
| 2067 |
for (i = 0; i < RF_PATH_NUM_8852C; i++) { |
| 2068 |
val = rtw8852c_bb_cal_txpwr_ref(rtwdev, phy_idx, ref_ofdm, ofst_dec[i]); |
| 2069 |
rtw89_phy_write32_idx(rtwdev, addr[i] + ofst_ofdm, mask, val, phy_idx); |
| 2070 |
} |
| 2071 |
|
| 2072 |
rtw89_debug(rtwdev, RTW89_DBG_TXPWR, "[TXPWR] set bb cck txpwr ref\n"); |
| 2073 |
for (i = 0; i < RF_PATH_NUM_8852C; i++) { |
| 2074 |
val = rtw8852c_bb_cal_txpwr_ref(rtwdev, phy_idx, ref_cck, ofst_dec[i]); |
| 2075 |
rtw89_phy_write32_idx(rtwdev, addr[i] + ofst_cck, mask, val, phy_idx); |
| 2076 |
} |
| 2077 |
} |
| 2078 |
|
| 2079 |
static void rtw8852c_bb_set_tx_shape_dfir(struct rtw89_dev *rtwdev, |
| 2080 |
const struct rtw89_chan *chan, |
| 2081 |
u8 tx_shape_idx, |
| 2082 |
enum rtw89_phy_idx phy_idx) |
| 2083 |
{ |
| 2084 |
#define __DFIR_CFG_MASK 0xffffff |
| 2085 |
#define __DFIR_CFG_NR 8 |
| 2086 |
#define __DECL_DFIR_VAR(_prefix, _name, _val...) \ |
| 2087 |
static const u32 _prefix ## _ ## _name[] = {_val}; \ |
| 2088 |
static_assert(ARRAY_SIZE(_prefix ## _ ## _name) == __DFIR_CFG_NR) |
| 2089 |
#define __DECL_DFIR_PARAM(_name, _val...) __DECL_DFIR_VAR(param, _name, _val) |
| 2090 |
#define __DECL_DFIR_ADDR(_name, _val...) __DECL_DFIR_VAR(addr, _name, _val) |
| 2091 |
|
| 2092 |
__DECL_DFIR_PARAM(flat, |
| 2093 |
0x003D23FF, 0x0029B354, 0x000FC1C8, 0x00FDB053, |
| 2094 |
0x00F86F9A, 0x00FAEF92, 0x00FE5FCC, 0x00FFDFF5); |
| 2095 |
__DECL_DFIR_PARAM(sharp, |
| 2096 |
0x003D83FF, 0x002C636A, 0x0013F204, 0x00008090, |
| 2097 |
0x00F87FB0, 0x00F99F83, 0x00FDBFBA, 0x00003FF5); |
| 2098 |
__DECL_DFIR_PARAM(sharp_14, |
| 2099 |
0x003B13FF, 0x001C42DE, 0x00FDB0AD, 0x00F60F6E, |
| 2100 |
0x00FD8F92, 0x0002D011, 0x0001C02C, 0x00FFF00A); |
| 2101 |
__DECL_DFIR_ADDR(filter, |
| 2102 |
0x45BC, 0x45CC, 0x45D0, 0x45D4, 0x45D8, 0x45C0, |
| 2103 |
0x45C4, 0x45C8); |
| 2104 |
u8 ch = chan->channel; |
| 2105 |
const u32 *param; |
| 2106 |
int i; |
| 2107 |
|
| 2108 |
if (ch > 14) { |
| 2109 |
rtw89_warn(rtwdev, |
| 2110 |
"set tx shape dfir by unknown ch: %d on 2G\n", ch); |
| 2111 |
return; |
| 2112 |
} |
| 2113 |
|
| 2114 |
if (ch == 14) |
| 2115 |
param = param_sharp_14; |
| 2116 |
else |
| 2117 |
param = tx_shape_idx == 0 ? param_flat : param_sharp; |
| 2118 |
|
| 2119 |
for (i = 0; i < __DFIR_CFG_NR; i++) { |
| 2120 |
rtw89_debug(rtwdev, RTW89_DBG_TXPWR, |
| 2121 |
"set tx shape dfir: 0x%x: 0x%x\n", addr_filter[i], |
| 2122 |
param[i]); |
| 2123 |
rtw89_phy_write32_idx(rtwdev, addr_filter[i], __DFIR_CFG_MASK, |
| 2124 |
param[i], phy_idx); |
| 2125 |
} |
| 2126 |
|
| 2127 |
#undef __DECL_DFIR_ADDR |
| 2128 |
#undef __DECL_DFIR_PARAM |
| 2129 |
#undef __DECL_DFIR_VAR |
| 2130 |
#undef __DFIR_CFG_NR |
| 2131 |
#undef __DFIR_CFG_MASK |
| 2132 |
} |
| 2133 |
|
| 2134 |
static void rtw8852c_set_tx_shape(struct rtw89_dev *rtwdev, |
| 2135 |
const struct rtw89_chan *chan, |
| 2136 |
enum rtw89_phy_idx phy_idx) |
| 2137 |
{ |
| 2138 |
const struct rtw89_rfe_parms *rfe_parms = rtwdev->rfe_parms; |
| 2139 |
u8 band = chan->band_type; |
| 2140 |
u8 regd = rtw89_regd_get(rtwdev, band); |
| 2141 |
u8 tx_shape_cck = (*rfe_parms->tx_shape.lmt)[band][RTW89_RS_CCK][regd]; |
| 2142 |
u8 tx_shape_ofdm = (*rfe_parms->tx_shape.lmt)[band][RTW89_RS_OFDM][regd]; |
| 2143 |
|
| 2144 |
if (band == RTW89_BAND_2G) |
| 2145 |
rtw8852c_bb_set_tx_shape_dfir(rtwdev, chan, tx_shape_cck, phy_idx); |
| 2146 |
|
| 2147 |
rtw89_phy_tssi_ctrl_set_bandedge_cfg(rtwdev, |
| 2148 |
(enum rtw89_mac_idx)phy_idx, |
| 2149 |
tx_shape_ofdm); |
| 2150 |
|
| 2151 |
rtw89_phy_write32_set(rtwdev, R_P0_DAC_COMP_POST_DPD_EN, |
| 2152 |
B_P0_DAC_COMP_POST_DPD_EN); |
| 2153 |
rtw89_phy_write32_set(rtwdev, R_P1_DAC_COMP_POST_DPD_EN, |
| 2154 |
B_P1_DAC_COMP_POST_DPD_EN); |
| 2155 |
} |
| 2156 |
|
| 2157 |
static void rtw8852c_set_txpwr_diff(struct rtw89_dev *rtwdev, |
| 2158 |
const struct rtw89_chan *chan, |
| 2159 |
enum rtw89_phy_idx phy_idx) |
| 2160 |
{ |
| 2161 |
s16 pwr_ofst; |
| 2162 |
|
| 2163 |
pwr_ofst = rtw89_phy_ant_gain_pwr_offset(rtwdev, chan); |
| 2164 |
rtw8852c_set_txpwr_ref(rtwdev, phy_idx, pwr_ofst); |
| 2165 |
} |
| 2166 |
|
| 2167 |
static void rtw8852c_set_txpwr_sar_diff(struct rtw89_dev *rtwdev, |
| 2168 |
const struct rtw89_chan *chan, |
| 2169 |
enum rtw89_phy_idx phy_idx) |
| 2170 |
{ |
| 2171 |
struct rtw89_sar_parm sar_parm = { |
| 2172 |
.center_freq = chan->freq, |
| 2173 |
.force_path = true, |
| 2174 |
}; |
| 2175 |
s16 sar_rf; |
| 2176 |
s8 sar_mac; |
| 2177 |
|
| 2178 |
if (phy_idx != RTW89_PHY_0) |
| 2179 |
return; |
| 2180 |
|
| 2181 |
sar_parm.path = RF_PATH_A; |
| 2182 |
sar_mac = rtw89_query_sar(rtwdev, &sar_parm); |
| 2183 |
sar_rf = rtw89_phy_txpwr_mac_to_rf(rtwdev, sar_mac); |
| 2184 |
rtw89_phy_write32_mask(rtwdev, R_TXPWRB, B_TXPWRB_MAX, sar_rf); |
| 2185 |
|
| 2186 |
sar_parm.path = RF_PATH_B; |
| 2187 |
sar_mac = rtw89_query_sar(rtwdev, &sar_parm); |
| 2188 |
sar_rf = rtw89_phy_txpwr_mac_to_rf(rtwdev, sar_mac); |
| 2189 |
rtw89_phy_write32_mask(rtwdev, R_P1_TXPWRB, B_TXPWRB_MAX, sar_rf); |
| 2190 |
} |
| 2191 |
|
| 2192 |
static void rtw8852c_set_txpwr(struct rtw89_dev *rtwdev, |
| 2193 |
const struct rtw89_chan *chan, |
| 2194 |
enum rtw89_phy_idx phy_idx) |
| 2195 |
{ |
| 2196 |
rtw89_phy_set_txpwr_byrate(rtwdev, chan, phy_idx); |
| 2197 |
rtw89_phy_set_txpwr_offset(rtwdev, chan, phy_idx); |
| 2198 |
rtw8852c_set_tx_shape(rtwdev, chan, phy_idx); |
| 2199 |
rtw89_phy_set_txpwr_limit(rtwdev, chan, phy_idx); |
| 2200 |
rtw89_phy_set_txpwr_limit_ru(rtwdev, chan, phy_idx); |
| 2201 |
rtw8852c_set_txpwr_diff(rtwdev, chan, phy_idx); |
| 2202 |
rtw8852c_set_txpwr_sar_diff(rtwdev, chan, phy_idx); |
| 2203 |
} |
| 2204 |
|
| 2205 |
static void rtw8852c_set_txpwr_ctrl(struct rtw89_dev *rtwdev, |
| 2206 |
enum rtw89_phy_idx phy_idx) |
| 2207 |
{ |
| 2208 |
rtw8852c_set_txpwr_ref(rtwdev, phy_idx, 0); |
| 2209 |
} |
| 2210 |
|
| 2211 |
static void |
| 2212 |
rtw8852c_init_tssi_ctrl(struct rtw89_dev *rtwdev, enum rtw89_phy_idx phy_idx) |
| 2213 |
{ |
| 2214 |
static const struct rtw89_reg2_def ctrl_ini[] = { |
| 2215 |
{0xD938, 0x00010100}, |
| 2216 |
{0xD93C, 0x0500D500}, |
| 2217 |
{0xD940, 0x00000500}, |
| 2218 |
{0xD944, 0x00000005}, |
| 2219 |
{0xD94C, 0x00220000}, |
| 2220 |
{0xD950, 0x00030000}, |
| 2221 |
}; |
| 2222 |
u32 addr; |
| 2223 |
int i; |
| 2224 |
|
| 2225 |
for (addr = R_AX_TSSI_CTRL_HEAD; addr <= R_AX_TSSI_CTRL_TAIL; addr += 4) |
| 2226 |
rtw89_mac_txpwr_write32(rtwdev, phy_idx, addr, 0); |
| 2227 |
|
| 2228 |
for (i = 0; i < ARRAY_SIZE(ctrl_ini); i++) |
| 2229 |
rtw89_mac_txpwr_write32(rtwdev, phy_idx, ctrl_ini[i].addr, |
| 2230 |
ctrl_ini[i].data); |
| 2231 |
|
| 2232 |
rtw89_phy_tssi_ctrl_set_bandedge_cfg(rtwdev, |
| 2233 |
(enum rtw89_mac_idx)phy_idx, |
| 2234 |
RTW89_TSSI_BANDEDGE_FLAT); |
| 2235 |
} |
| 2236 |
|
| 2237 |
static int |
| 2238 |
rtw8852c_init_txpwr_unit(struct rtw89_dev *rtwdev, enum rtw89_phy_idx phy_idx) |
| 2239 |
{ |
| 2240 |
int ret; |
| 2241 |
|
| 2242 |
ret = rtw89_mac_txpwr_write32(rtwdev, phy_idx, R_AX_PWR_UL_CTRL2, 0x07763333); |
| 2243 |
if (ret) |
| 2244 |
return ret; |
| 2245 |
|
| 2246 |
ret = rtw89_mac_txpwr_write32(rtwdev, phy_idx, R_AX_PWR_COEXT_CTRL, 0x01ebf000); |
| 2247 |
if (ret) |
| 2248 |
return ret; |
| 2249 |
|
| 2250 |
ret = rtw89_mac_txpwr_write32(rtwdev, phy_idx, R_AX_PWR_UL_CTRL0, 0x0002f8ff); |
| 2251 |
if (ret) |
| 2252 |
return ret; |
| 2253 |
|
| 2254 |
rtw8852c_set_txpwr_ul_tb_offset(rtwdev, 0, phy_idx == RTW89_PHY_1 ? |
| 2255 |
RTW89_MAC_1 : |
| 2256 |
RTW89_MAC_0); |
| 2257 |
rtw8852c_init_tssi_ctrl(rtwdev, phy_idx); |
| 2258 |
|
| 2259 |
return 0; |
| 2260 |
} |
| 2261 |
|
| 2262 |
static void rtw8852c_bb_cfg_rx_path(struct rtw89_dev *rtwdev, u8 rx_path) |
| 2263 |
{ |
| 2264 |
const struct rtw89_chan *chan = rtw89_chan_get(rtwdev, RTW89_CHANCTX_0); |
| 2265 |
u8 band = chan->band_type; |
| 2266 |
u32 rst_mask0 = B_P0_TXPW_RSTB_MANON | B_P0_TXPW_RSTB_TSSI; |
| 2267 |
u32 rst_mask1 = B_P1_TXPW_RSTB_MANON | B_P1_TXPW_RSTB_TSSI; |
| 2268 |
|
| 2269 |
if (rtwdev->dbcc_en) { |
| 2270 |
rtw89_phy_write32_mask(rtwdev, R_CHBW_MOD, B_ANT_RX_SEG0, 1); |
| 2271 |
rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD, B_ANT_RX_SEG0, 2, |
| 2272 |
RTW89_PHY_1); |
| 2273 |
|
| 2274 |
rtw89_phy_write32_mask(rtwdev, R_FC0_BW, B_ANT_RX_1RCCA_SEG0, |
| 2275 |
1); |
| 2276 |
rtw89_phy_write32_mask(rtwdev, R_FC0_BW, B_ANT_RX_1RCCA_SEG1, |
| 2277 |
1); |
| 2278 |
rtw89_phy_write32_idx(rtwdev, R_FC0_BW, B_ANT_RX_1RCCA_SEG0, 2, |
| 2279 |
RTW89_PHY_1); |
| 2280 |
rtw89_phy_write32_idx(rtwdev, R_FC0_BW, B_ANT_RX_1RCCA_SEG1, 2, |
| 2281 |
RTW89_PHY_1); |
| 2282 |
|
| 2283 |
rtw89_phy_write32_mask(rtwdev, R_RXHT_MCS_LIMIT, |
| 2284 |
B_RXHT_MCS_LIMIT, 0); |
| 2285 |
rtw89_phy_write32_mask(rtwdev, R_RXVHT_MCS_LIMIT, |
| 2286 |
B_RXVHT_MCS_LIMIT, 0); |
| 2287 |
rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_USER_MAX, 8); |
| 2288 |
rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_MAX_NSS, 0); |
| 2289 |
rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHETB_MAX_NSS, 0); |
| 2290 |
|
| 2291 |
rtw89_phy_write32_idx(rtwdev, R_RXHT_MCS_LIMIT, |
| 2292 |
B_RXHT_MCS_LIMIT, 0, RTW89_PHY_1); |
| 2293 |
rtw89_phy_write32_idx(rtwdev, R_RXVHT_MCS_LIMIT, |
| 2294 |
B_RXVHT_MCS_LIMIT, 0, RTW89_PHY_1); |
| 2295 |
rtw89_phy_write32_idx(rtwdev, R_RXHE, B_RXHE_USER_MAX, 1, |
| 2296 |
RTW89_PHY_1); |
| 2297 |
rtw89_phy_write32_idx(rtwdev, R_RXHE, B_RXHE_MAX_NSS, 0, |
| 2298 |
RTW89_PHY_1); |
| 2299 |
rtw89_phy_write32_idx(rtwdev, R_RXHE, B_RXHETB_MAX_NSS, 0, |
| 2300 |
RTW89_PHY_1); |
| 2301 |
rtw89_phy_write32_mask(rtwdev, R_P0_TXPW_RSTB, rst_mask0, 1); |
| 2302 |
rtw89_phy_write32_mask(rtwdev, R_P0_TXPW_RSTB, rst_mask0, 3); |
| 2303 |
rtw89_phy_write32_mask(rtwdev, R_P1_TXPW_RSTB, rst_mask1, 1); |
| 2304 |
rtw89_phy_write32_mask(rtwdev, R_P1_TXPW_RSTB, rst_mask1, 3); |
| 2305 |
} else { |
| 2306 |
if (rx_path == RF_PATH_A) { |
| 2307 |
rtw89_phy_write32_mask(rtwdev, R_CHBW_MOD, |
| 2308 |
B_ANT_RX_SEG0, 1); |
| 2309 |
rtw89_phy_write32_mask(rtwdev, R_FC0_BW, |
| 2310 |
B_ANT_RX_1RCCA_SEG0, 1); |
| 2311 |
rtw89_phy_write32_mask(rtwdev, R_FC0_BW, |
| 2312 |
B_ANT_RX_1RCCA_SEG1, 1); |
| 2313 |
rtw89_phy_write32_mask(rtwdev, R_RXHT_MCS_LIMIT, |
| 2314 |
B_RXHT_MCS_LIMIT, 0); |
| 2315 |
rtw89_phy_write32_mask(rtwdev, R_RXVHT_MCS_LIMIT, |
| 2316 |
B_RXVHT_MCS_LIMIT, 0); |
| 2317 |
rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_MAX_NSS, |
| 2318 |
0); |
| 2319 |
rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHETB_MAX_NSS, |
| 2320 |
0); |
| 2321 |
rtw89_phy_write32_mask(rtwdev, R_P0_TXPW_RSTB, |
| 2322 |
rst_mask0, 1); |
| 2323 |
rtw89_phy_write32_mask(rtwdev, R_P0_TXPW_RSTB, |
| 2324 |
rst_mask0, 3); |
| 2325 |
} else if (rx_path == RF_PATH_B) { |
| 2326 |
rtw89_phy_write32_mask(rtwdev, R_CHBW_MOD, |
| 2327 |
B_ANT_RX_SEG0, 2); |
| 2328 |
rtw89_phy_write32_mask(rtwdev, R_FC0_BW, |
| 2329 |
B_ANT_RX_1RCCA_SEG0, 2); |
| 2330 |
rtw89_phy_write32_mask(rtwdev, R_FC0_BW, |
| 2331 |
B_ANT_RX_1RCCA_SEG1, 2); |
| 2332 |
rtw89_phy_write32_mask(rtwdev, R_RXHT_MCS_LIMIT, |
| 2333 |
B_RXHT_MCS_LIMIT, 0); |
| 2334 |
rtw89_phy_write32_mask(rtwdev, R_RXVHT_MCS_LIMIT, |
| 2335 |
B_RXVHT_MCS_LIMIT, 0); |
| 2336 |
rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_MAX_NSS, |
| 2337 |
0); |
| 2338 |
rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHETB_MAX_NSS, |
| 2339 |
0); |
| 2340 |
rtw89_phy_write32_mask(rtwdev, R_P1_TXPW_RSTB, |
| 2341 |
rst_mask1, 1); |
| 2342 |
rtw89_phy_write32_mask(rtwdev, R_P1_TXPW_RSTB, |
| 2343 |
rst_mask1, 3); |
| 2344 |
} else { |
| 2345 |
rtw89_phy_write32_mask(rtwdev, R_CHBW_MOD, |
| 2346 |
B_ANT_RX_SEG0, 3); |
| 2347 |
rtw89_phy_write32_mask(rtwdev, R_FC0_BW, |
| 2348 |
B_ANT_RX_1RCCA_SEG0, 3); |
| 2349 |
rtw89_phy_write32_mask(rtwdev, R_FC0_BW, |
| 2350 |
B_ANT_RX_1RCCA_SEG1, 3); |
| 2351 |
rtw89_phy_write32_mask(rtwdev, R_RXHT_MCS_LIMIT, |
| 2352 |
B_RXHT_MCS_LIMIT, 1); |
| 2353 |
rtw89_phy_write32_mask(rtwdev, R_RXVHT_MCS_LIMIT, |
| 2354 |
B_RXVHT_MCS_LIMIT, 1); |
| 2355 |
rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_MAX_NSS, |
| 2356 |
1); |
| 2357 |
rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHETB_MAX_NSS, |
| 2358 |
1); |
| 2359 |
rtw8852c_ctrl_btg_bt_rx(rtwdev, band == RTW89_BAND_2G, |
| 2360 |
RTW89_PHY_0); |
| 2361 |
rtw89_phy_write32_mask(rtwdev, R_P0_TXPW_RSTB, |
| 2362 |
rst_mask0, 1); |
| 2363 |
rtw89_phy_write32_mask(rtwdev, R_P0_TXPW_RSTB, |
| 2364 |
rst_mask0, 3); |
| 2365 |
rtw89_phy_write32_mask(rtwdev, R_P1_TXPW_RSTB, |
| 2366 |
rst_mask1, 1); |
| 2367 |
rtw89_phy_write32_mask(rtwdev, R_P1_TXPW_RSTB, |
| 2368 |
rst_mask1, 3); |
| 2369 |
} |
| 2370 |
rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_USER_MAX, 8); |
| 2371 |
} |
| 2372 |
} |
| 2373 |
|
| 2374 |
static void rtw8852c_ctrl_tx_path_tmac(struct rtw89_dev *rtwdev, u8 tx_path, |
| 2375 |
enum rtw89_mac_idx mac_idx) |
| 2376 |
{ |
| 2377 |
struct rtw89_reg2_def path_com[] = { |
| 2378 |
{R_AX_PATH_COM0, AX_PATH_COM0_DFVAL}, |
| 2379 |
{R_AX_PATH_COM1, AX_PATH_COM1_DFVAL}, |
| 2380 |
{R_AX_PATH_COM2, AX_PATH_COM2_DFVAL}, |
| 2381 |
{R_AX_PATH_COM3, AX_PATH_COM3_DFVAL}, |
| 2382 |
{R_AX_PATH_COM4, AX_PATH_COM4_DFVAL}, |
| 2383 |
{R_AX_PATH_COM5, AX_PATH_COM5_DFVAL}, |
| 2384 |
{R_AX_PATH_COM6, AX_PATH_COM6_DFVAL}, |
| 2385 |
{R_AX_PATH_COM7, AX_PATH_COM7_DFVAL}, |
| 2386 |
{R_AX_PATH_COM8, AX_PATH_COM8_DFVAL}, |
| 2387 |
{R_AX_PATH_COM9, AX_PATH_COM9_DFVAL}, |
| 2388 |
{R_AX_PATH_COM10, AX_PATH_COM10_DFVAL}, |
| 2389 |
{R_AX_PATH_COM11, AX_PATH_COM11_DFVAL}, |
| 2390 |
}; |
| 2391 |
u32 addr; |
| 2392 |
u32 reg; |
| 2393 |
u8 cr_size = ARRAY_SIZE(path_com); |
| 2394 |
u8 i = 0; |
| 2395 |
|
| 2396 |
rtw89_phy_write32_idx(rtwdev, R_MAC_SEL, B_MAC_SEL_MOD, 0, RTW89_PHY_0); |
| 2397 |
rtw89_phy_write32_idx(rtwdev, R_MAC_SEL, B_MAC_SEL_MOD, 0, RTW89_PHY_1); |
| 2398 |
|
| 2399 |
for (addr = R_AX_MACID_ANT_TABLE; |
| 2400 |
addr <= R_AX_MACID_ANT_TABLE_LAST; addr += 4) { |
| 2401 |
reg = rtw89_mac_reg_by_idx(rtwdev, addr, mac_idx); |
| 2402 |
rtw89_write32(rtwdev, reg, 0); |
| 2403 |
} |
| 2404 |
|
| 2405 |
if (tx_path == RF_A) { |
| 2406 |
path_com[0].data = AX_PATH_COM0_PATHA; |
| 2407 |
path_com[1].data = AX_PATH_COM1_PATHA; |
| 2408 |
path_com[2].data = AX_PATH_COM2_PATHA; |
| 2409 |
path_com[7].data = AX_PATH_COM7_PATHA; |
| 2410 |
path_com[8].data = AX_PATH_COM8_PATHA; |
| 2411 |
} else if (tx_path == RF_B) { |
| 2412 |
path_com[0].data = AX_PATH_COM0_PATHB; |
| 2413 |
path_com[1].data = AX_PATH_COM1_PATHB; |
| 2414 |
path_com[2].data = AX_PATH_COM2_PATHB; |
| 2415 |
path_com[7].data = AX_PATH_COM7_PATHB; |
| 2416 |
path_com[8].data = AX_PATH_COM8_PATHB; |
| 2417 |
} else if (tx_path == RF_AB) { |
| 2418 |
path_com[0].data = AX_PATH_COM0_PATHAB; |
| 2419 |
path_com[1].data = AX_PATH_COM1_PATHAB; |
| 2420 |
path_com[2].data = AX_PATH_COM2_PATHAB; |
| 2421 |
path_com[7].data = AX_PATH_COM7_PATHAB; |
| 2422 |
path_com[8].data = AX_PATH_COM8_PATHAB; |
| 2423 |
} else { |
| 2424 |
rtw89_warn(rtwdev, "[Invalid Tx Path]Tx Path: %d\n", tx_path); |
| 2425 |
return; |
| 2426 |
} |
| 2427 |
|
| 2428 |
for (i = 0; i < cr_size; i++) { |
| 2429 |
rtw89_debug(rtwdev, RTW89_DBG_TSSI, "0x%x = 0x%x\n", |
| 2430 |
path_com[i].addr, path_com[i].data); |
| 2431 |
reg = rtw89_mac_reg_by_idx(rtwdev, path_com[i].addr, mac_idx); |
| 2432 |
rtw89_write32(rtwdev, reg, path_com[i].data); |
| 2433 |
} |
| 2434 |
} |
| 2435 |
|
| 2436 |
static void rtw8852c_ctrl_nbtg_bt_tx(struct rtw89_dev *rtwdev, bool en, |
| 2437 |
enum rtw89_phy_idx phy_idx) |
| 2438 |
{ |
| 2439 |
if (en) { |
| 2440 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_FRC_FIR_TYPE_V1, |
| 2441 |
B_PATH0_FRC_FIR_TYPE_MSK_V1, 0x3); |
| 2442 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_FRC_FIR_TYPE_V1, |
| 2443 |
B_PATH1_FRC_FIR_TYPE_MSK_V1, 0x3); |
| 2444 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_RXBB_V1, |
| 2445 |
B_PATH0_RXBB_MSK_V1, 0xf); |
| 2446 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_RXBB_V1, |
| 2447 |
B_PATH1_RXBB_MSK_V1, 0xf); |
| 2448 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_G_LNA6_OP1DB_V1, |
| 2449 |
B_PATH0_G_LNA6_OP1DB_V1, 0x80); |
| 2450 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_G_LNA6_OP1DB_V1, |
| 2451 |
B_PATH1_G_LNA6_OP1DB_V1, 0x80); |
| 2452 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_G_TIA0_LNA6_OP1DB_V1, |
| 2453 |
B_PATH0_G_TIA0_LNA6_OP1DB_V1, 0x80); |
| 2454 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_G_TIA1_LNA6_OP1DB_V1, |
| 2455 |
B_PATH0_G_TIA1_LNA6_OP1DB_V1, 0x80); |
| 2456 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_G_TIA0_LNA6_OP1DB_V1, |
| 2457 |
B_PATH1_G_TIA0_LNA6_OP1DB_V1, 0x80); |
| 2458 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_G_TIA1_LNA6_OP1DB_V1, |
| 2459 |
B_PATH1_G_TIA1_LNA6_OP1DB_V1, 0x80); |
| 2460 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_BT_BACKOFF_V1, |
| 2461 |
B_PATH0_BT_BACKOFF_V1, 0x780D1E); |
| 2462 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_BT_BACKOFF_V1, |
| 2463 |
B_PATH1_BT_BACKOFF_V1, 0x780D1E); |
| 2464 |
rtw89_phy_write32_mask(rtwdev, R_P0_BACKOFF_IBADC_V1, |
| 2465 |
B_P0_BACKOFF_IBADC_V1, 0x34); |
| 2466 |
rtw89_phy_write32_mask(rtwdev, R_P1_BACKOFF_IBADC_V1, |
| 2467 |
B_P1_BACKOFF_IBADC_V1, 0x34); |
| 2468 |
} else { |
| 2469 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_FRC_FIR_TYPE_V1, |
| 2470 |
B_PATH0_FRC_FIR_TYPE_MSK_V1, 0x0); |
| 2471 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_FRC_FIR_TYPE_V1, |
| 2472 |
B_PATH1_FRC_FIR_TYPE_MSK_V1, 0x0); |
| 2473 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_RXBB_V1, |
| 2474 |
B_PATH0_RXBB_MSK_V1, 0x60); |
| 2475 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_RXBB_V1, |
| 2476 |
B_PATH1_RXBB_MSK_V1, 0x60); |
| 2477 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_G_LNA6_OP1DB_V1, |
| 2478 |
B_PATH0_G_LNA6_OP1DB_V1, 0x1a); |
| 2479 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_G_LNA6_OP1DB_V1, |
| 2480 |
B_PATH1_G_LNA6_OP1DB_V1, 0x1a); |
| 2481 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_G_TIA0_LNA6_OP1DB_V1, |
| 2482 |
B_PATH0_G_TIA0_LNA6_OP1DB_V1, 0x2a); |
| 2483 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_G_TIA1_LNA6_OP1DB_V1, |
| 2484 |
B_PATH0_G_TIA1_LNA6_OP1DB_V1, 0x2a); |
| 2485 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_G_TIA0_LNA6_OP1DB_V1, |
| 2486 |
B_PATH1_G_TIA0_LNA6_OP1DB_V1, 0x2a); |
| 2487 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_G_TIA1_LNA6_OP1DB_V1, |
| 2488 |
B_PATH1_G_TIA1_LNA6_OP1DB_V1, 0x2a); |
| 2489 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_BT_BACKOFF_V1, |
| 2490 |
B_PATH0_BT_BACKOFF_V1, 0x79E99E); |
| 2491 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_BT_BACKOFF_V1, |
| 2492 |
B_PATH1_BT_BACKOFF_V1, 0x79E99E); |
| 2493 |
rtw89_phy_write32_mask(rtwdev, R_P0_BACKOFF_IBADC_V1, |
| 2494 |
B_P0_BACKOFF_IBADC_V1, 0x26); |
| 2495 |
rtw89_phy_write32_mask(rtwdev, R_P1_BACKOFF_IBADC_V1, |
| 2496 |
B_P1_BACKOFF_IBADC_V1, 0x26); |
| 2497 |
} |
| 2498 |
} |
| 2499 |
|
| 2500 |
static void rtw8852c_bb_cfg_txrx_path(struct rtw89_dev *rtwdev) |
| 2501 |
{ |
| 2502 |
struct rtw89_hal *hal = &rtwdev->hal; |
| 2503 |
u8 nrx_path = RF_PATH_AB; |
| 2504 |
u8 rx_nss = hal->rx_nss; |
| 2505 |
|
| 2506 |
if (hal->antenna_rx == RF_A) |
| 2507 |
nrx_path = RF_PATH_A; |
| 2508 |
else if (hal->antenna_rx == RF_B) |
| 2509 |
nrx_path = RF_PATH_B; |
| 2510 |
|
| 2511 |
if (nrx_path != RF_PATH_AB) |
| 2512 |
rx_nss = 1; |
| 2513 |
|
| 2514 |
rtw8852c_bb_cfg_rx_path(rtwdev, nrx_path); |
| 2515 |
|
| 2516 |
if (rx_nss == 1) { |
| 2517 |
rtw89_phy_write32_mask(rtwdev, R_RXHT_MCS_LIMIT, B_RXHT_MCS_LIMIT, 0); |
| 2518 |
rtw89_phy_write32_mask(rtwdev, R_RXVHT_MCS_LIMIT, B_RXVHT_MCS_LIMIT, 0); |
| 2519 |
rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_MAX_NSS, 0); |
| 2520 |
rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHETB_MAX_NSS, 0); |
| 2521 |
} else { |
| 2522 |
rtw89_phy_write32_mask(rtwdev, R_RXHT_MCS_LIMIT, B_RXHT_MCS_LIMIT, 1); |
| 2523 |
rtw89_phy_write32_mask(rtwdev, R_RXVHT_MCS_LIMIT, B_RXVHT_MCS_LIMIT, 1); |
| 2524 |
rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_MAX_NSS, 1); |
| 2525 |
rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHETB_MAX_NSS, 1); |
| 2526 |
} |
| 2527 |
} |
| 2528 |
|
| 2529 |
static u8 rtw8852c_get_thermal(struct rtw89_dev *rtwdev, enum rtw89_rf_path rf_path) |
| 2530 |
{ |
| 2531 |
struct rtw89_power_trim_info *info = &rtwdev->pwr_trim; |
| 2532 |
s8 comp = 0; |
| 2533 |
u8 val; |
| 2534 |
|
| 2535 |
rtw89_write_rf(rtwdev, rf_path, RR_TM, RR_TM_TRI, 0x1); |
| 2536 |
rtw89_write_rf(rtwdev, rf_path, RR_TM, RR_TM_TRI, 0x0); |
| 2537 |
rtw89_write_rf(rtwdev, rf_path, RR_TM, RR_TM_TRI, 0x1); |
| 2538 |
|
| 2539 |
fsleep(200); |
| 2540 |
|
| 2541 |
val = rtw89_read_rf(rtwdev, rf_path, RR_TM, RR_TM_VAL); |
| 2542 |
|
| 2543 |
if (info->pg_thermal_trim) { |
| 2544 |
u8 trim = info->thermal_trim[rf_path]; |
| 2545 |
|
| 2546 |
if (trim & __THM_MASK_VAL8) |
| 2547 |
comp = 8 * (trim & __THM_MASK_SIGN ? -1 : 1); |
| 2548 |
} |
| 2549 |
|
| 2550 |
return val + comp; |
| 2551 |
} |
| 2552 |
|
| 2553 |
static void rtw8852c_btc_set_rfe(struct rtw89_dev *rtwdev) |
| 2554 |
{ |
| 2555 |
const struct rtw89_btc_ver *ver = rtwdev->btc.ver; |
| 2556 |
union rtw89_btc_module_info *md = &rtwdev->btc.mdinfo; |
| 2557 |
|
| 2558 |
if (ver->fcxinit == 7) { |
| 2559 |
md->md_v7.rfe_type = rtwdev->efuse.rfe_type; |
| 2560 |
md->md_v7.kt_ver = rtwdev->hal.cv; |
| 2561 |
md->md_v7.bt_solo = 0; |
| 2562 |
md->md_v7.switch_type = BTC_SWITCH_INTERNAL; |
| 2563 |
|
| 2564 |
if (md->md_v7.rfe_type > 0) |
| 2565 |
md->md_v7.ant.num = (md->md_v7.rfe_type % 2 ? 2 : 3); |
| 2566 |
else |
| 2567 |
md->md_v7.ant.num = 2; |
| 2568 |
|
| 2569 |
md->md_v7.ant.diversity = 0; |
| 2570 |
md->md_v7.ant.isolation = 10; |
| 2571 |
|
| 2572 |
if (md->md_v7.ant.num == 3) { |
| 2573 |
md->md_v7.ant.type = BTC_ANT_DEDICATED; |
| 2574 |
md->md_v7.bt_pos = BTC_BT_ALONE; |
| 2575 |
} else { |
| 2576 |
md->md_v7.ant.type = BTC_ANT_SHARED; |
| 2577 |
md->md_v7.bt_pos = BTC_BT_BTG; |
| 2578 |
} |
| 2579 |
rtwdev->btc.btg_pos = md->md_v7.ant.btg_pos; |
| 2580 |
rtwdev->btc.ant_type = md->md_v7.ant.type; |
| 2581 |
} else { |
| 2582 |
md->md.rfe_type = rtwdev->efuse.rfe_type; |
| 2583 |
md->md.cv = rtwdev->hal.cv; |
| 2584 |
md->md.bt_solo = 0; |
| 2585 |
md->md.switch_type = BTC_SWITCH_INTERNAL; |
| 2586 |
|
| 2587 |
if (md->md.rfe_type > 0) |
| 2588 |
md->md.ant.num = (md->md.rfe_type % 2 ? 2 : 3); |
| 2589 |
else |
| 2590 |
md->md.ant.num = 2; |
| 2591 |
|
| 2592 |
md->md.ant.diversity = 0; |
| 2593 |
md->md.ant.isolation = 10; |
| 2594 |
|
| 2595 |
if (md->md.ant.num == 3) { |
| 2596 |
md->md.ant.type = BTC_ANT_DEDICATED; |
| 2597 |
md->md.bt_pos = BTC_BT_ALONE; |
| 2598 |
} else { |
| 2599 |
md->md.ant.type = BTC_ANT_SHARED; |
| 2600 |
md->md.bt_pos = BTC_BT_BTG; |
| 2601 |
} |
| 2602 |
rtwdev->btc.btg_pos = md->md.ant.btg_pos; |
| 2603 |
rtwdev->btc.ant_type = md->md.ant.type; |
| 2604 |
} |
| 2605 |
} |
| 2606 |
|
| 2607 |
static void rtw8852c_ctrl_btg_bt_rx(struct rtw89_dev *rtwdev, bool en, |
| 2608 |
enum rtw89_phy_idx phy_idx) |
| 2609 |
{ |
| 2610 |
if (en) { |
| 2611 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_BT_SHARE_V1, |
| 2612 |
B_PATH0_BT_SHARE_V1, 0x1); |
| 2613 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_BTG_PATH_V1, |
| 2614 |
B_PATH0_BTG_PATH_V1, 0x0); |
| 2615 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_G_LNA6_OP1DB_V1, |
| 2616 |
B_PATH1_G_LNA6_OP1DB_V1, 0x20); |
| 2617 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_G_TIA0_LNA6_OP1DB_V1, |
| 2618 |
B_PATH1_G_TIA0_LNA6_OP1DB_V1, 0x30); |
| 2619 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_BT_SHARE_V1, |
| 2620 |
B_PATH1_BT_SHARE_V1, 0x1); |
| 2621 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_BTG_PATH_V1, |
| 2622 |
B_PATH1_BTG_PATH_V1, 0x1); |
| 2623 |
rtw89_phy_write32_mask(rtwdev, R_PMAC_GNT, B_PMAC_GNT_P1, 0x0); |
| 2624 |
rtw89_phy_write32_mask(rtwdev, R_CHBW_MOD, B_BT_SHARE, 0x1); |
| 2625 |
rtw89_phy_write32_mask(rtwdev, R_FC0_BW, B_ANT_RX_BT_SEG0, 0x2); |
| 2626 |
rtw89_phy_write32_mask(rtwdev, R_BT_DYN_DC_EST_EN, |
| 2627 |
B_BT_DYN_DC_EST_EN_MSK, 0x1); |
| 2628 |
rtw89_phy_write32_mask(rtwdev, R_GNT_BT_WGT_EN, B_GNT_BT_WGT_EN, |
| 2629 |
0x1); |
| 2630 |
} else { |
| 2631 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_BT_SHARE_V1, |
| 2632 |
B_PATH0_BT_SHARE_V1, 0x0); |
| 2633 |
rtw89_phy_write32_mask(rtwdev, R_PATH0_BTG_PATH_V1, |
| 2634 |
B_PATH0_BTG_PATH_V1, 0x0); |
| 2635 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_G_LNA6_OP1DB_V1, |
| 2636 |
B_PATH1_G_LNA6_OP1DB_V1, 0x1a); |
| 2637 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_G_TIA0_LNA6_OP1DB_V1, |
| 2638 |
B_PATH1_G_TIA0_LNA6_OP1DB_V1, 0x2a); |
| 2639 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_BT_SHARE_V1, |
| 2640 |
B_PATH1_BT_SHARE_V1, 0x0); |
| 2641 |
rtw89_phy_write32_mask(rtwdev, R_PATH1_BTG_PATH_V1, |
| 2642 |
B_PATH1_BTG_PATH_V1, 0x0); |
| 2643 |
rtw89_phy_write32_mask(rtwdev, R_PMAC_GNT, B_PMAC_GNT_P1, 0xf); |
| 2644 |
rtw89_phy_write32_mask(rtwdev, R_PMAC_GNT, B_PMAC_GNT_P2, 0x4); |
| 2645 |
rtw89_phy_write32_mask(rtwdev, R_CHBW_MOD, B_BT_SHARE, 0x0); |
| 2646 |
rtw89_phy_write32_mask(rtwdev, R_FC0_BW, B_ANT_RX_BT_SEG0, 0x0); |
| 2647 |
rtw89_phy_write32_mask(rtwdev, R_BT_DYN_DC_EST_EN, |
| 2648 |
B_BT_DYN_DC_EST_EN_MSK, 0x0); |
| 2649 |
rtw89_phy_write32_mask(rtwdev, R_GNT_BT_WGT_EN, B_GNT_BT_WGT_EN, |
| 2650 |
0x0); |
| 2651 |
} |
| 2652 |
} |
| 2653 |
|
| 2654 |
static |
| 2655 |
void rtw8852c_set_trx_mask(struct rtw89_dev *rtwdev, u8 path, u8 group, u32 val) |
| 2656 |
{ |
| 2657 |
rtw89_write_rf(rtwdev, path, RR_LUTWE, RFREG_MASK, 0x20000); |
| 2658 |
rtw89_write_rf(rtwdev, path, RR_LUTWA, RFREG_MASK, group); |
| 2659 |
rtw89_write_rf(rtwdev, path, RR_LUTWD0, RFREG_MASK, val); |
| 2660 |
rtw89_write_rf(rtwdev, path, RR_LUTWE, RFREG_MASK, 0x0); |
| 2661 |
} |
| 2662 |
|
| 2663 |
static void rtw8852c_btc_init_cfg(struct rtw89_dev *rtwdev) |
| 2664 |
{ |
| 2665 |
struct rtw89_btc *btc = &rtwdev->btc; |
| 2666 |
const struct rtw89_chip_info *chip = rtwdev->chip; |
| 2667 |
const struct rtw89_mac_ax_coex coex_params = { |
| 2668 |
.pta_mode = RTW89_MAC_AX_COEX_RTK_MODE, |
| 2669 |
.direction = RTW89_MAC_AX_COEX_INNER, |
| 2670 |
}; |
| 2671 |
|
| 2672 |
/* PTA init */ |
| 2673 |
rtw89_mac_coex_init_v1(rtwdev, &coex_params); |
| 2674 |
|
| 2675 |
/* set WL Tx response = Hi-Pri */ |
| 2676 |
chip->ops->btc_set_wl_pri(rtwdev, BTC_PRI_MASK_TX_RESP, true); |
| 2677 |
chip->ops->btc_set_wl_pri(rtwdev, BTC_PRI_MASK_BEACON, true); |
| 2678 |
|
| 2679 |
/* set rf gnt debug off */ |
| 2680 |
rtw89_write_rf(rtwdev, RF_PATH_A, RR_WLSEL, RFREG_MASK, 0x0); |
| 2681 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_WLSEL, RFREG_MASK, 0x0); |
| 2682 |
|
| 2683 |
/* set WL Tx thru in TRX mask table if GNT_WL = 0 && BT_S1 = ss group */ |
| 2684 |
if (btc->ant_type == BTC_ANT_SHARED) { |
| 2685 |
rtw8852c_set_trx_mask(rtwdev, |
| 2686 |
RF_PATH_A, BTC_BT_SS_GROUP, 0x5ff); |
| 2687 |
rtw8852c_set_trx_mask(rtwdev, |
| 2688 |
RF_PATH_B, BTC_BT_SS_GROUP, 0x5ff); |
| 2689 |
/* set path-A(S0) Tx/Rx no-mask if GNT_WL=0 && BT_S1=tx group */ |
| 2690 |
rtw8852c_set_trx_mask(rtwdev, |
| 2691 |
RF_PATH_A, BTC_BT_TX_GROUP, 0x5ff); |
| 2692 |
} else { /* set WL Tx stb if GNT_WL = 0 && BT_S1 = ss group for 3-ant */ |
| 2693 |
rtw8852c_set_trx_mask(rtwdev, |
| 2694 |
RF_PATH_A, BTC_BT_SS_GROUP, 0x5df); |
| 2695 |
rtw8852c_set_trx_mask(rtwdev, |
| 2696 |
RF_PATH_B, BTC_BT_SS_GROUP, 0x5df); |
| 2697 |
} |
| 2698 |
|
| 2699 |
/* set PTA break table */ |
| 2700 |
rtw89_write32(rtwdev, R_AX_BT_BREAK_TABLE, BTC_BREAK_PARAM); |
| 2701 |
|
| 2702 |
/* enable BT counter 0xda10[1:0] = 2b'11 */ |
| 2703 |
rtw89_write32_set(rtwdev, |
| 2704 |
R_AX_BT_CNT_CFG, B_AX_BT_CNT_EN | |
| 2705 |
B_AX_BT_CNT_RST_V1); |
| 2706 |
btc->cx.wl.status.map.init_ok = true; |
| 2707 |
} |
| 2708 |
|
| 2709 |
static |
| 2710 |
void rtw8852c_btc_set_wl_pri(struct rtw89_dev *rtwdev, u8 map, bool state) |
| 2711 |
{ |
| 2712 |
u32 bitmap = 0; |
| 2713 |
u32 reg = 0; |
| 2714 |
|
| 2715 |
switch (map) { |
| 2716 |
case BTC_PRI_MASK_TX_RESP: |
| 2717 |
reg = R_BTC_COEX_WL_REQ; |
| 2718 |
bitmap = B_BTC_RSP_ACK_HI; |
| 2719 |
break; |
| 2720 |
case BTC_PRI_MASK_BEACON: |
| 2721 |
reg = R_BTC_COEX_WL_REQ; |
| 2722 |
bitmap = B_BTC_TX_BCN_HI; |
| 2723 |
break; |
| 2724 |
default: |
| 2725 |
return; |
| 2726 |
} |
| 2727 |
|
| 2728 |
if (state) |
| 2729 |
rtw89_write32_set(rtwdev, reg, bitmap); |
| 2730 |
else |
| 2731 |
rtw89_write32_clr(rtwdev, reg, bitmap); |
| 2732 |
} |
| 2733 |
|
| 2734 |
union rtw8852c_btc_wl_txpwr_ctrl { |
| 2735 |
u32 txpwr_val; |
| 2736 |
struct { |
| 2737 |
union { |
| 2738 |
u16 ctrl_all_time; |
| 2739 |
struct { |
| 2740 |
s16 data:9; |
| 2741 |
u16 rsvd:6; |
| 2742 |
u16 flag:1; |
| 2743 |
} all_time; |
| 2744 |
}; |
| 2745 |
union { |
| 2746 |
u16 ctrl_gnt_bt; |
| 2747 |
struct { |
| 2748 |
s16 data:9; |
| 2749 |
u16 rsvd:7; |
| 2750 |
} gnt_bt; |
| 2751 |
}; |
| 2752 |
}; |
| 2753 |
} __packed; |
| 2754 |
|
| 2755 |
static void |
| 2756 |
rtw8852c_btc_set_wl_txpwr_ctrl(struct rtw89_dev *rtwdev, u32 txpwr_val) |
| 2757 |
{ |
| 2758 |
union rtw8852c_btc_wl_txpwr_ctrl arg = { .txpwr_val = txpwr_val }; |
| 2759 |
s32 val; |
| 2760 |
|
| 2761 |
#define __write_ctrl(_reg, _msk, _val, _en, _cond) \ |
| 2762 |
do { \ |
| 2763 |
u32 _wrt = FIELD_PREP(_msk, _val); \ |
| 2764 |
BUILD_BUG_ON((_msk & _en) != 0); \ |
| 2765 |
if (_cond) \ |
| 2766 |
_wrt |= _en; \ |
| 2767 |
else \ |
| 2768 |
_wrt &= ~_en; \ |
| 2769 |
rtw89_mac_txpwr_write32_mask(rtwdev, RTW89_PHY_0, _reg, \ |
| 2770 |
_msk | _en, _wrt); \ |
| 2771 |
} while (0) |
| 2772 |
|
| 2773 |
switch (arg.ctrl_all_time) { |
| 2774 |
case 0xffff: |
| 2775 |
val = 0; |
| 2776 |
break; |
| 2777 |
default: |
| 2778 |
val = arg.all_time.data; |
| 2779 |
break; |
| 2780 |
} |
| 2781 |
|
| 2782 |
__write_ctrl(R_AX_PWR_RATE_CTRL, B_AX_FORCE_PWR_BY_RATE_VALUE_MASK, |
| 2783 |
val, B_AX_FORCE_PWR_BY_RATE_EN, |
| 2784 |
arg.ctrl_all_time != 0xffff); |
| 2785 |
|
| 2786 |
switch (arg.ctrl_gnt_bt) { |
| 2787 |
case 0xffff: |
| 2788 |
val = 0; |
| 2789 |
break; |
| 2790 |
default: |
| 2791 |
val = arg.gnt_bt.data; |
| 2792 |
break; |
| 2793 |
} |
| 2794 |
|
| 2795 |
__write_ctrl(R_AX_PWR_COEXT_CTRL, B_AX_TXAGC_BT_MASK, val, |
| 2796 |
B_AX_TXAGC_BT_EN, arg.ctrl_gnt_bt != 0xffff); |
| 2797 |
|
| 2798 |
#undef __write_ctrl |
| 2799 |
} |
| 2800 |
|
| 2801 |
static |
| 2802 |
s8 rtw8852c_btc_get_bt_rssi(struct rtw89_dev *rtwdev, s8 val) |
| 2803 |
{ |
| 2804 |
/* +6 for compensate offset */ |
| 2805 |
return clamp_t(s8, val + 6, -100, 0) + 100; |
| 2806 |
} |
| 2807 |
|
| 2808 |
static const struct rtw89_btc_rf_trx_para rtw89_btc_8852c_rf_ul[] = { |
| 2809 |
{255, 0, 0, 7}, /* 0 -> original */ |
| 2810 |
{255, 2, 0, 7}, /* 1 -> for BT-connected ACI issue && BTG co-rx */ |
| 2811 |
{255, 0, 0, 7}, /* 2 ->reserved for shared-antenna */ |
| 2812 |
{255, 0, 0, 7}, /* 3- >reserved for shared-antenna */ |
| 2813 |
{255, 0, 0, 7}, /* 4 ->reserved for shared-antenna */ |
| 2814 |
{255, 1, 0, 7}, /* the below id is for non-shared-antenna free-run */ |
| 2815 |
{6, 1, 0, 7}, |
| 2816 |
{13, 1, 0, 7}, |
| 2817 |
{13, 1, 0, 7} |
| 2818 |
}; |
| 2819 |
|
| 2820 |
static const struct rtw89_btc_rf_trx_para rtw89_btc_8852c_rf_dl[] = { |
| 2821 |
{255, 0, 0, 7}, /* 0 -> original */ |
| 2822 |
{255, 2, 0, 7}, /* 1 -> reserved for shared-antenna */ |
| 2823 |
{255, 0, 0, 7}, /* 2 ->reserved for shared-antenna */ |
| 2824 |
{255, 0, 0, 7}, /* 3- >reserved for shared-antenna */ |
| 2825 |
{255, 0, 0, 7}, /* 4 ->reserved for shared-antenna */ |
| 2826 |
{255, 1, 0, 7}, /* the below id is for non-shared-antenna free-run */ |
| 2827 |
{255, 1, 0, 7}, |
| 2828 |
{255, 1, 0, 7}, |
| 2829 |
{255, 1, 0, 7} |
| 2830 |
}; |
| 2831 |
|
| 2832 |
static const u8 rtw89_btc_8852c_wl_rssi_thres[BTC_WL_RSSI_THMAX] = {60, 50, 40, 30}; |
| 2833 |
static const u8 rtw89_btc_8852c_bt_rssi_thres[BTC_BT_RSSI_THMAX] = {40, 36, 31, 28}; |
| 2834 |
|
| 2835 |
static const struct rtw89_btc_fbtc_mreg rtw89_btc_8852c_mon_reg[] = { |
| 2836 |
RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda00), |
| 2837 |
RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda04), |
| 2838 |
RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda24), |
| 2839 |
RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda30), |
| 2840 |
RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda34), |
| 2841 |
RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda38), |
| 2842 |
RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda44), |
| 2843 |
RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda48), |
| 2844 |
RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda4c), |
| 2845 |
RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xd200), |
| 2846 |
RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xd220), |
| 2847 |
RTW89_DEF_FBTC_MREG(REG_BB, 4, 0x980), |
| 2848 |
RTW89_DEF_FBTC_MREG(REG_BB, 4, 0x4aa4), |
| 2849 |
RTW89_DEF_FBTC_MREG(REG_BB, 4, 0x4778), |
| 2850 |
RTW89_DEF_FBTC_MREG(REG_BB, 4, 0x476c), |
| 2851 |
}; |
| 2852 |
|
| 2853 |
static |
| 2854 |
void rtw8852c_btc_update_bt_cnt(struct rtw89_dev *rtwdev) |
| 2855 |
{ |
| 2856 |
/* Feature move to firmware */ |
| 2857 |
} |
| 2858 |
|
| 2859 |
static |
| 2860 |
void rtw8852c_btc_wl_s1_standby(struct rtw89_dev *rtwdev, bool state) |
| 2861 |
{ |
| 2862 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWE, RFREG_MASK, 0x80000); |
| 2863 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x1); |
| 2864 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD1, RFREG_MASK, 0x620); |
| 2865 |
|
| 2866 |
/* set WL standby = Rx for GNT_BT_Tx = 1->0 settle issue */ |
| 2867 |
if (state) |
| 2868 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, |
| 2869 |
RFREG_MASK, 0x179c); |
| 2870 |
else |
| 2871 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, |
| 2872 |
RFREG_MASK, 0x208); |
| 2873 |
|
| 2874 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWE, RFREG_MASK, 0x0); |
| 2875 |
} |
| 2876 |
|
| 2877 |
static void rtw8852c_set_wl_lna2(struct rtw89_dev *rtwdev, u8 level) |
| 2878 |
{ |
| 2879 |
/* level=0 Default: TIA 1/0= (LNA2,TIAN6) = (7,1)/(5,1) = 21dB/12dB |
| 2880 |
* level=1 Fix LNA2=5: TIA 1/0= (LNA2,TIAN6) = (5,0)/(5,1) = 18dB/12dB |
| 2881 |
* To improve BT ACI in co-rx |
| 2882 |
*/ |
| 2883 |
|
| 2884 |
switch (level) { |
| 2885 |
case 0: /* default */ |
| 2886 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWE, RFREG_MASK, 0x1000); |
| 2887 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x0); |
| 2888 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x15); |
| 2889 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x1); |
| 2890 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x17); |
| 2891 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x2); |
| 2892 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x15); |
| 2893 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x3); |
| 2894 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x17); |
| 2895 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWE, RFREG_MASK, 0x0); |
| 2896 |
break; |
| 2897 |
case 1: /* Fix LNA2=5 */ |
| 2898 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWE, RFREG_MASK, 0x1000); |
| 2899 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x0); |
| 2900 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x15); |
| 2901 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x1); |
| 2902 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x5); |
| 2903 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x2); |
| 2904 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x15); |
| 2905 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x3); |
| 2906 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x5); |
| 2907 |
rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWE, RFREG_MASK, 0x0); |
| 2908 |
break; |
| 2909 |
} |
| 2910 |
} |
| 2911 |
|
| 2912 |
static void rtw8852c_btc_set_wl_rx_gain(struct rtw89_dev *rtwdev, u32 level) |
| 2913 |
{ |
| 2914 |
struct rtw89_btc *btc = &rtwdev->btc; |
| 2915 |
|
| 2916 |
switch (level) { |
| 2917 |
case 0: /* original */ |
| 2918 |
default: |
| 2919 |
rtw8852c_ctrl_nbtg_bt_tx(rtwdev, false, RTW89_PHY_0); |
| 2920 |
btc->dm.wl_lna2 = 0; |
| 2921 |
break; |
| 2922 |
case 1: /* for FDD free-run */ |
| 2923 |
rtw8852c_ctrl_nbtg_bt_tx(rtwdev, true, RTW89_PHY_0); |
| 2924 |
btc->dm.wl_lna2 = 0; |
| 2925 |
break; |
| 2926 |
case 2: /* for BTG Co-Rx*/ |
| 2927 |
rtw8852c_ctrl_nbtg_bt_tx(rtwdev, false, RTW89_PHY_0); |
| 2928 |
btc->dm.wl_lna2 = 1; |
| 2929 |
break; |
| 2930 |
} |
| 2931 |
|
| 2932 |
rtw8852c_set_wl_lna2(rtwdev, btc->dm.wl_lna2); |
| 2933 |
} |
| 2934 |
|
| 2935 |
static void rtw8852c_fill_freq_with_ppdu(struct rtw89_dev *rtwdev, |
| 2936 |
struct rtw89_rx_phy_ppdu *phy_ppdu, |
| 2937 |
struct ieee80211_rx_status *status) |
| 2938 |
{ |
| 2939 |
u8 chan_idx = phy_ppdu->chan_idx; |
| 2940 |
enum nl80211_band band; |
| 2941 |
u8 ch; |
| 2942 |
|
| 2943 |
if (chan_idx == 0) |
| 2944 |
return; |
| 2945 |
|
| 2946 |
rtw89_decode_chan_idx(rtwdev, chan_idx, &ch, &band); |
| 2947 |
status->freq = ieee80211_channel_to_frequency(ch, band); |
| 2948 |
status->band = band; |
| 2949 |
} |
| 2950 |
|
| 2951 |
static void rtw8852c_query_ppdu(struct rtw89_dev *rtwdev, |
| 2952 |
struct rtw89_rx_phy_ppdu *phy_ppdu, |
| 2953 |
struct ieee80211_rx_status *status) |
| 2954 |
{ |
| 2955 |
u8 path; |
| 2956 |
u8 *rx_power = phy_ppdu->rssi; |
| 2957 |
|
| 2958 |
if (!status->signal) |
| 2959 |
status->signal = RTW89_RSSI_RAW_TO_DBM(max(rx_power[RF_PATH_A], |
| 2960 |
rx_power[RF_PATH_B])); |
| 2961 |
|
| 2962 |
for (path = 0; path < rtwdev->chip->rf_path_num; path++) { |
| 2963 |
status->chains |= BIT(path); |
| 2964 |
status->chain_signal[path] = RTW89_RSSI_RAW_TO_DBM(rx_power[path]); |
| 2965 |
} |
| 2966 |
if (phy_ppdu->valid) |
| 2967 |
rtw8852c_fill_freq_with_ppdu(rtwdev, phy_ppdu, status); |
| 2968 |
} |
| 2969 |
|
| 2970 |
static int rtw8852c_mac_enable_bb_rf(struct rtw89_dev *rtwdev) |
| 2971 |
{ |
| 2972 |
int ret; |
| 2973 |
|
| 2974 |
rtw89_write8_set(rtwdev, R_AX_SYS_FUNC_EN, |
| 2975 |
B_AX_FEN_BBRSTB | B_AX_FEN_BB_GLB_RSTN); |
| 2976 |
|
| 2977 |
rtw89_write32_set(rtwdev, R_AX_WLRF_CTRL, B_AX_AFC_AFEDIG); |
| 2978 |
rtw89_write32_clr(rtwdev, R_AX_WLRF_CTRL, B_AX_AFC_AFEDIG); |
| 2979 |
rtw89_write32_set(rtwdev, R_AX_WLRF_CTRL, B_AX_AFC_AFEDIG); |
| 2980 |
|
| 2981 |
rtw89_write32_mask(rtwdev, R_AX_AFE_OFF_CTRL1, B_AX_S0_LDO_VSEL_F_MASK, 0x1); |
| 2982 |
rtw89_write32_mask(rtwdev, R_AX_AFE_OFF_CTRL1, B_AX_S1_LDO_VSEL_F_MASK, 0x1); |
| 2983 |
|
| 2984 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL0, 0x7, FULL_BIT_MASK); |
| 2985 |
if (ret) |
| 2986 |
return ret; |
| 2987 |
|
| 2988 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0x6c, FULL_BIT_MASK); |
| 2989 |
if (ret) |
| 2990 |
return ret; |
| 2991 |
|
| 2992 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_WL_RFC_S0, 0xc7, FULL_BIT_MASK); |
| 2993 |
if (ret) |
| 2994 |
return ret; |
| 2995 |
|
| 2996 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_WL_RFC_S1, 0xc7, FULL_BIT_MASK); |
| 2997 |
if (ret) |
| 2998 |
return ret; |
| 2999 |
|
| 3000 |
ret = rtw89_mac_write_xtal_si(rtwdev, XTAL3, 0xd, FULL_BIT_MASK); |
| 3001 |
if (ret) |
| 3002 |
return ret; |
| 3003 |
|
| 3004 |
return 0; |
| 3005 |
} |
| 3006 |
|
| 3007 |
static int rtw8852c_mac_disable_bb_rf(struct rtw89_dev *rtwdev) |
| 3008 |
{ |
| 3009 |
rtw89_write32_clr(rtwdev, R_AX_WLRF_CTRL, B_AX_AFC_AFEDIG); |
| 3010 |
rtw89_write8_clr(rtwdev, R_AX_SYS_FUNC_EN, |
| 3011 |
B_AX_FEN_BBRSTB | B_AX_FEN_BB_GLB_RSTN); |
| 3012 |
|
| 3013 |
return 0; |
| 3014 |
} |
| 3015 |
|
| 3016 |
static const struct rtw89_chanctx_listener rtw8852c_chanctx_listener = { |
| 3017 |
.callbacks[RTW89_CHANCTX_CALLBACK_RFK] = rtw8852c_rfk_chanctx_cb, |
| 3018 |
.callbacks[RTW89_CHANCTX_CALLBACK_TAS] = rtw89_tas_chanctx_cb, |
| 3019 |
}; |
| 3020 |
|
| 3021 |
#ifdef CONFIG_PM |
| 3022 |
static const struct wiphy_wowlan_support rtw_wowlan_stub_8852c = { |
| 3023 |
.flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT | |
| 3024 |
WIPHY_WOWLAN_NET_DETECT, |
| 3025 |
.n_patterns = RTW89_MAX_PATTERN_NUM, |
| 3026 |
.pattern_max_len = RTW89_MAX_PATTERN_SIZE, |
| 3027 |
.pattern_min_len = 1, |
| 3028 |
.max_nd_match_sets = RTW89_SCANOFLD_MAX_SSID, |
| 3029 |
}; |
| 3030 |
#endif |
| 3031 |
|
| 3032 |
static const struct rtw89_chip_ops rtw8852c_chip_ops = { |
| 3033 |
.enable_bb_rf = rtw8852c_mac_enable_bb_rf, |
| 3034 |
.disable_bb_rf = rtw8852c_mac_disable_bb_rf, |
| 3035 |
.bb_preinit = NULL, |
| 3036 |
.bb_postinit = NULL, |
| 3037 |
.bb_reset = rtw8852c_bb_reset, |
| 3038 |
.bb_sethw = rtw8852c_bb_sethw, |
| 3039 |
.read_rf = rtw89_phy_read_rf_v1, |
| 3040 |
.write_rf = rtw89_phy_write_rf_v1, |
| 3041 |
.set_channel = rtw8852c_set_channel, |
| 3042 |
.set_channel_help = rtw8852c_set_channel_help, |
| 3043 |
.read_efuse = rtw8852c_read_efuse, |
| 3044 |
.read_phycap = rtw8852c_read_phycap, |
| 3045 |
.fem_setup = NULL, |
| 3046 |
.rfe_gpio = NULL, |
| 3047 |
.rfk_hw_init = NULL, |
| 3048 |
.rfk_init = rtw8852c_rfk_init, |
| 3049 |
.rfk_init_late = NULL, |
| 3050 |
.rfk_channel = rtw8852c_rfk_channel, |
| 3051 |
.rfk_band_changed = rtw8852c_rfk_band_changed, |
| 3052 |
.rfk_scan = rtw8852c_rfk_scan, |
| 3053 |
.rfk_track = rtw8852c_rfk_track, |
| 3054 |
.power_trim = rtw8852c_power_trim, |
| 3055 |
.set_txpwr = rtw8852c_set_txpwr, |
| 3056 |
.set_txpwr_ctrl = rtw8852c_set_txpwr_ctrl, |
| 3057 |
.init_txpwr_unit = rtw8852c_init_txpwr_unit, |
| 3058 |
.get_thermal = rtw8852c_get_thermal, |
| 3059 |
.chan_to_rf18_val = NULL, |
| 3060 |
.ctrl_btg_bt_rx = rtw8852c_ctrl_btg_bt_rx, |
| 3061 |
.query_ppdu = rtw8852c_query_ppdu, |
| 3062 |
.convert_rpl_to_rssi = NULL, |
| 3063 |
.phy_rpt_to_rssi = NULL, |
| 3064 |
.ctrl_nbtg_bt_tx = rtw8852c_ctrl_nbtg_bt_tx, |
| 3065 |
.cfg_txrx_path = rtw8852c_bb_cfg_txrx_path, |
| 3066 |
.set_txpwr_ul_tb_offset = rtw8852c_set_txpwr_ul_tb_offset, |
| 3067 |
.digital_pwr_comp = NULL, |
| 3068 |
.calc_rx_gain_normal = NULL, |
| 3069 |
.pwr_on_func = rtw8852c_pwr_on_func, |
| 3070 |
.pwr_off_func = rtw8852c_pwr_off_func, |
| 3071 |
.query_rxdesc = rtw89_core_query_rxdesc, |
| 3072 |
.fill_txdesc = rtw89_core_fill_txdesc_v1, |
| 3073 |
.fill_txdesc_fwcmd = rtw89_core_fill_txdesc_fwcmd_v1, |
| 3074 |
.get_ch_dma = {rtw89_core_get_ch_dma, |
| 3075 |
rtw89_core_get_ch_dma_v2, |
| 3076 |
NULL,}, |
| 3077 |
.cfg_ctrl_path = rtw89_mac_cfg_ctrl_path_v1, |
| 3078 |
.mac_cfg_gnt = rtw89_mac_cfg_gnt_v1, |
| 3079 |
.stop_sch_tx = rtw89_mac_stop_sch_tx_v1, |
| 3080 |
.resume_sch_tx = rtw89_mac_resume_sch_tx_v1, |
| 3081 |
.h2c_dctl_sec_cam = rtw89_fw_h2c_dctl_sec_cam_v1, |
| 3082 |
.h2c_default_cmac_tbl = rtw89_fw_h2c_default_cmac_tbl, |
| 3083 |
.h2c_assoc_cmac_tbl = rtw89_fw_h2c_assoc_cmac_tbl, |
| 3084 |
.h2c_ampdu_cmac_tbl = NULL, |
| 3085 |
.h2c_txtime_cmac_tbl = rtw89_fw_h2c_txtime_cmac_tbl, |
| 3086 |
.h2c_punctured_cmac_tbl = NULL, |
| 3087 |
.h2c_default_dmac_tbl = NULL, |
| 3088 |
.h2c_update_beacon = rtw89_fw_h2c_update_beacon, |
| 3089 |
.h2c_ba_cam = rtw89_fw_h2c_ba_cam, |
| 3090 |
.h2c_wow_cam_update = rtw89_fw_h2c_wow_cam_update, |
| 3091 |
|
| 3092 |
.btc_set_rfe = rtw8852c_btc_set_rfe, |
| 3093 |
.btc_init_cfg = rtw8852c_btc_init_cfg, |
| 3094 |
.btc_set_wl_pri = rtw8852c_btc_set_wl_pri, |
| 3095 |
.btc_set_wl_txpwr_ctrl = rtw8852c_btc_set_wl_txpwr_ctrl, |
| 3096 |
.btc_get_bt_rssi = rtw8852c_btc_get_bt_rssi, |
| 3097 |
.btc_update_bt_cnt = rtw8852c_btc_update_bt_cnt, |
| 3098 |
.btc_wl_s1_standby = rtw8852c_btc_wl_s1_standby, |
| 3099 |
.btc_set_wl_rx_gain = rtw8852c_btc_set_wl_rx_gain, |
| 3100 |
.btc_set_policy = rtw89_btc_set_policy_v1, |
| 3101 |
}; |
| 3102 |
|
| 3103 |
const struct rtw89_chip_info rtw8852c_chip_info = { |
| 3104 |
.chip_id = RTL8852C, |
| 3105 |
.chip_gen = RTW89_CHIP_AX, |
| 3106 |
.ops = &rtw8852c_chip_ops, |
| 3107 |
.mac_def = &rtw89_mac_gen_ax, |
| 3108 |
.phy_def = &rtw89_phy_gen_ax, |
| 3109 |
.fw_basename = RTW8852C_FW_BASENAME, |
| 3110 |
.fw_format_max = RTW8852C_FW_FORMAT_MAX, |
| 3111 |
.try_ce_fw = false, |
| 3112 |
.bbmcu_nr = 0, |
| 3113 |
.needed_fw_elms = 0, |
| 3114 |
.fw_blacklist = &rtw89_fw_blacklist_default, |
| 3115 |
.fifo_size = 458752, |
| 3116 |
.small_fifo_size = false, |
| 3117 |
.dle_scc_rsvd_size = 0, |
| 3118 |
.max_amsdu_limit = 8000, |
| 3119 |
.max_vht_mpdu_cap = IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454, |
| 3120 |
.max_eht_mpdu_cap = 0, |
| 3121 |
.max_tx_agg_num = 128, |
| 3122 |
.max_rx_agg_num = 64, |
| 3123 |
.dis_2g_40m_ul_ofdma = false, |
| 3124 |
.rsvd_ple_ofst = 0x6f800, |
| 3125 |
.hfc_param_ini = {rtw8852c_hfc_param_ini_pcie, |
| 3126 |
rtw8852c_hfc_param_ini_usb, |
| 3127 |
NULL}, |
| 3128 |
.dle_mem = {rtw8852c_dle_mem_pcie, |
| 3129 |
rtw8852c_dle_mem_usb2, |
| 3130 |
rtw8852c_dle_mem_usb3, |
| 3131 |
NULL}, |
| 3132 |
.wde_qempty_acq_grpnum = 16, |
| 3133 |
.wde_qempty_mgq_grpsel = 16, |
| 3134 |
.rf_base_addr = {0xe000, 0xf000}, |
| 3135 |
.thermal_th = {0x32, 0x35}, |
| 3136 |
.pwr_on_seq = NULL, |
| 3137 |
.pwr_off_seq = NULL, |
| 3138 |
.bb_table = &rtw89_8852c_phy_bb_table, |
| 3139 |
.bb_gain_table = &rtw89_8852c_phy_bb_gain_table, |
| 3140 |
.rf_table = {&rtw89_8852c_phy_radiob_table, |
| 3141 |
&rtw89_8852c_phy_radioa_table,}, |
| 3142 |
.nctl_table = &rtw89_8852c_phy_nctl_table, |
| 3143 |
.nctl_post_table = NULL, |
| 3144 |
.dflt_parms = &rtw89_8852c_dflt_parms, |
| 3145 |
.rfe_parms_conf = NULL, |
| 3146 |
.chanctx_listener = &rtw8852c_chanctx_listener, |
| 3147 |
.txpwr_factor_bb = 3, |
| 3148 |
.txpwr_factor_rf = 2, |
| 3149 |
.txpwr_factor_mac = 1, |
| 3150 |
.dig_table = NULL, |
| 3151 |
.dig_regs = &rtw8852c_dig_regs, |
| 3152 |
.tssi_dbw_table = &rtw89_8852c_tssi_dbw_table, |
| 3153 |
.support_macid_num = RTW89_MAX_MAC_ID_NUM, |
| 3154 |
.support_link_num = 0, |
| 3155 |
.support_chanctx_num = 2, |
| 3156 |
.support_rnr = false, |
| 3157 |
.support_bands = BIT(NL80211_BAND_2GHZ) | |
| 3158 |
BIT(NL80211_BAND_5GHZ) | |
| 3159 |
BIT(NL80211_BAND_6GHZ), |
| 3160 |
.support_bandwidths = BIT(NL80211_CHAN_WIDTH_20) | |
| 3161 |
BIT(NL80211_CHAN_WIDTH_40) | |
| 3162 |
BIT(NL80211_CHAN_WIDTH_80) | |
| 3163 |
BIT(NL80211_CHAN_WIDTH_160), |
| 3164 |
.support_unii4 = true, |
| 3165 |
.support_ant_gain = true, |
| 3166 |
.support_tas = true, |
| 3167 |
.support_sar_by_ant = true, |
| 3168 |
.support_noise = false, |
| 3169 |
.ul_tb_waveform_ctrl = false, |
| 3170 |
.ul_tb_pwr_diff = true, |
| 3171 |
.rx_freq_frome_ie = false, |
| 3172 |
.hw_sec_hdr = true, |
| 3173 |
.hw_mgmt_tx_encrypt = true, |
| 3174 |
.hw_tkip_crypto = true, |
| 3175 |
.hw_mlo_bmc_crypto = false, |
| 3176 |
.rf_path_num = 2, |
| 3177 |
.tx_nss = 2, |
| 3178 |
.rx_nss = 2, |
| 3179 |
.acam_num = 128, |
| 3180 |
.bcam_num = 20, |
| 3181 |
.scam_num = 128, |
| 3182 |
.bacam_num = 8, |
| 3183 |
.bacam_dynamic_num = 8, |
| 3184 |
.bacam_ver = RTW89_BACAM_V0_EXT, |
| 3185 |
.addrcam_ver = 0, |
| 3186 |
.ppdu_max_usr = 8, |
| 3187 |
.sec_ctrl_efuse_size = 4, |
| 3188 |
.physical_efuse_size = 1216, |
| 3189 |
.logical_efuse_size = 2048, |
| 3190 |
.limit_efuse_size = 1280, |
| 3191 |
.dav_phy_efuse_size = 96, |
| 3192 |
.dav_log_efuse_size = 16, |
| 3193 |
.efuse_blocks = NULL, |
| 3194 |
.phycap_addr = 0x590, |
| 3195 |
.phycap_size = 0x60, |
| 3196 |
.para_ver = 0x1, |
| 3197 |
.wlcx_desired = 0x06000000, |
| 3198 |
.scbd = 0x1, |
| 3199 |
.mailbox = 0x1, |
| 3200 |
|
| 3201 |
.afh_guard_ch = 6, |
| 3202 |
.wl_rssi_thres = rtw89_btc_8852c_wl_rssi_thres, |
| 3203 |
.bt_rssi_thres = rtw89_btc_8852c_bt_rssi_thres, |
| 3204 |
.rssi_tol = 2, |
| 3205 |
.mon_reg_num = ARRAY_SIZE(rtw89_btc_8852c_mon_reg), |
| 3206 |
.mon_reg = rtw89_btc_8852c_mon_reg, |
| 3207 |
.rf_para_ulink_num = ARRAY_SIZE(rtw89_btc_8852c_rf_ul), |
| 3208 |
.rf_para_ulink = rtw89_btc_8852c_rf_ul, |
| 3209 |
.rf_para_dlink_num = ARRAY_SIZE(rtw89_btc_8852c_rf_dl), |
| 3210 |
.rf_para_dlink = rtw89_btc_8852c_rf_dl, |
| 3211 |
.ps_mode_supported = BIT(RTW89_PS_MODE_RFOFF) | |
| 3212 |
BIT(RTW89_PS_MODE_CLK_GATED) | |
| 3213 |
BIT(RTW89_PS_MODE_PWR_GATED), |
| 3214 |
.low_power_hci_modes = BIT(RTW89_PS_MODE_CLK_GATED) | |
| 3215 |
BIT(RTW89_PS_MODE_PWR_GATED), |
| 3216 |
.h2c_cctl_func_id = H2C_FUNC_MAC_CCTLINFO_UD_V1, |
| 3217 |
.hci_func_en_addr = R_AX_HCI_FUNC_EN_V1, |
| 3218 |
.h2c_desc_size = sizeof(struct rtw89_rxdesc_short), |
| 3219 |
.txwd_body_size = sizeof(struct rtw89_txwd_body_v1), |
| 3220 |
.txwd_info_size = sizeof(struct rtw89_txwd_info), |
| 3221 |
.h2c_ctrl_reg = R_AX_H2CREG_CTRL_V1, |
| 3222 |
.h2c_counter_reg = {R_AX_UDM1 + 1, B_AX_UDM1_HALMAC_H2C_DEQ_CNT_MASK >> 8}, |
| 3223 |
.h2c_regs = rtw8852c_h2c_regs, |
| 3224 |
.c2h_ctrl_reg = R_AX_C2HREG_CTRL_V1, |
| 3225 |
.c2h_counter_reg = {R_AX_UDM1 + 1, B_AX_UDM1_HALMAC_C2H_ENQ_CNT_MASK >> 8}, |
| 3226 |
.c2h_regs = rtw8852c_c2h_regs, |
| 3227 |
.page_regs = &rtw8852c_page_regs, |
| 3228 |
.wow_reason_reg = rtw8852c_wow_wakeup_regs, |
| 3229 |
.cfo_src_fd = false, |
| 3230 |
.cfo_hw_comp = false, |
| 3231 |
.dcfo_comp = &rtw8852c_dcfo_comp, |
| 3232 |
.dcfo_comp_sft = 12, |
| 3233 |
.nhm_report = NULL, |
| 3234 |
.nhm_th = NULL, |
| 3235 |
.imr_info = &rtw8852c_imr_info, |
| 3236 |
.imr_dmac_table = NULL, |
| 3237 |
.imr_cmac_table = NULL, |
| 3238 |
.rrsr_cfgs = &rtw8852c_rrsr_cfgs, |
| 3239 |
.bss_clr_vld = {R_BSS_CLR_MAP, B_BSS_CLR_MAP_VLD0}, |
| 3240 |
.bss_clr_map_reg = R_BSS_CLR_MAP, |
| 3241 |
.rfkill_init = &rtw8852c_rfkill_regs, |
| 3242 |
.rfkill_get = {R_AX_GPIO_EXT_CTRL, B_AX_GPIO_IN_9}, |
| 3243 |
.btc_sb = {{{R_AX_SCOREBOARD, R_AX_SCOREBOARD},}}, |
| 3244 |
.dma_ch_mask = 0, |
| 3245 |
.edcca_regs = &rtw8852c_edcca_regs, |
| 3246 |
#ifdef CONFIG_PM |
| 3247 |
.wowlan_stub = &rtw_wowlan_stub_8852c, |
| 3248 |
#endif |
| 3249 |
.xtal_info = NULL, |
| 3250 |
.default_quirks = 0, |
| 3251 |
}; |
| 3252 |
EXPORT_SYMBOL(rtw8852c_chip_info); |
| 3253 |
|
| 3254 |
MODULE_FIRMWARE(RTW8852C_MODULE_FIRMWARE); |
| 3255 |
MODULE_AUTHOR("Realtek Corporation"); |
| 3256 |
MODULE_DESCRIPTION("Realtek 802.11ax wireless 8852C driver"); |
| 3257 |
MODULE_LICENSE("Dual BSD/GPL"); |