xref: /openbmc/linux/drivers/net/wireless/realtek/rtw89/rtw8852c.c (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
10ac80e05SPing-Ke Shih // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
20ac80e05SPing-Ke Shih /* Copyright(c) 2019-2022  Realtek Corporation
30ac80e05SPing-Ke Shih  */
40ac80e05SPing-Ke Shih 
5065cf8f9SChia-Yuan Li #include "coex.h"
6a82174c6SPing-Ke Shih #include "debug.h"
7e8955811SPing-Ke Shih #include "fw.h"
82a7e54dbSPing-Ke Shih #include "mac.h"
984d0e33eSChung-Hsuan Hung #include "phy.h"
102a7e54dbSPing-Ke Shih #include "reg.h"
110ac80e05SPing-Ke Shih #include "rtw8852c.h"
121b00e923SPing-Ke Shih #include "rtw8852c_rfk.h"
13eefad995SPing-Ke Shih #include "rtw8852c_table.h"
141b00e923SPing-Ke Shih #include "util.h"
150ac80e05SPing-Ke Shih 
16ffde7f34SPing-Ke Shih #define RTW8852C_FW_FORMAT_MAX 0
17ffde7f34SPing-Ke Shih #define RTW8852C_FW_BASENAME "rtw89/rtw8852c_fw"
18ffde7f34SPing-Ke Shih #define RTW8852C_MODULE_FIRMWARE \
19ffde7f34SPing-Ke Shih 	RTW8852C_FW_BASENAME ".bin"
20ffde7f34SPing-Ke Shih 
217b9c98c7SPing-Ke Shih static const struct rtw89_hfc_ch_cfg rtw8852c_hfc_chcfg_pcie[] = {
227b9c98c7SPing-Ke Shih 	{13, 1614, grp_0}, /* ACH 0 */
237b9c98c7SPing-Ke Shih 	{13, 1614, grp_0}, /* ACH 1 */
247b9c98c7SPing-Ke Shih 	{13, 1614, grp_0}, /* ACH 2 */
257b9c98c7SPing-Ke Shih 	{13, 1614, grp_0}, /* ACH 3 */
267b9c98c7SPing-Ke Shih 	{13, 1614, grp_1}, /* ACH 4 */
277b9c98c7SPing-Ke Shih 	{13, 1614, grp_1}, /* ACH 5 */
287b9c98c7SPing-Ke Shih 	{13, 1614, grp_1}, /* ACH 6 */
297b9c98c7SPing-Ke Shih 	{13, 1614, grp_1}, /* ACH 7 */
307b9c98c7SPing-Ke Shih 	{13, 1614, grp_0}, /* B0MGQ */
317b9c98c7SPing-Ke Shih 	{13, 1614, grp_0}, /* B0HIQ */
327b9c98c7SPing-Ke Shih 	{13, 1614, grp_1}, /* B1MGQ */
337b9c98c7SPing-Ke Shih 	{13, 1614, grp_1}, /* B1HIQ */
347b9c98c7SPing-Ke Shih 	{40, 0, 0} /* FWCMDQ */
357b9c98c7SPing-Ke Shih };
367b9c98c7SPing-Ke Shih 
377b9c98c7SPing-Ke Shih static const struct rtw89_hfc_pub_cfg rtw8852c_hfc_pubcfg_pcie = {
387b9c98c7SPing-Ke Shih 	1614, /* Group 0 */
397b9c98c7SPing-Ke Shih 	1614, /* Group 1 */
407b9c98c7SPing-Ke Shih 	3228, /* Public Max */
417b9c98c7SPing-Ke Shih 	0 /* WP threshold */
427b9c98c7SPing-Ke Shih };
437b9c98c7SPing-Ke Shih 
447b9c98c7SPing-Ke Shih static const struct rtw89_hfc_param_ini rtw8852c_hfc_param_ini_pcie[] = {
457b9c98c7SPing-Ke Shih 	[RTW89_QTA_SCC] = {rtw8852c_hfc_chcfg_pcie, &rtw8852c_hfc_pubcfg_pcie,
467b9c98c7SPing-Ke Shih 			   &rtw89_mac_size.hfc_preccfg_pcie, RTW89_HCIFC_POH},
477b9c98c7SPing-Ke Shih 	[RTW89_QTA_DLFW] = {NULL, NULL, &rtw89_mac_size.hfc_preccfg_pcie,
487b9c98c7SPing-Ke Shih 			    RTW89_HCIFC_POH},
497b9c98c7SPing-Ke Shih 	[RTW89_QTA_INVALID] = {NULL},
507b9c98c7SPing-Ke Shih };
517b9c98c7SPing-Ke Shih 
5279d099e0SPing-Ke Shih static const struct rtw89_dle_mem rtw8852c_dle_mem_pcie[] = {
5330645118SPing-Ke Shih 	[RTW89_QTA_SCC] = {RTW89_QTA_SCC, &rtw89_mac_size.wde_size19,
5430645118SPing-Ke Shih 			   &rtw89_mac_size.ple_size19, &rtw89_mac_size.wde_qt18,
5530645118SPing-Ke Shih 			   &rtw89_mac_size.wde_qt18, &rtw89_mac_size.ple_qt46,
5630645118SPing-Ke Shih 			   &rtw89_mac_size.ple_qt47},
5730645118SPing-Ke Shih 	[RTW89_QTA_DLFW] = {RTW89_QTA_DLFW, &rtw89_mac_size.wde_size18,
5830645118SPing-Ke Shih 			    &rtw89_mac_size.ple_size18, &rtw89_mac_size.wde_qt17,
5930645118SPing-Ke Shih 			    &rtw89_mac_size.wde_qt17, &rtw89_mac_size.ple_qt44,
6030645118SPing-Ke Shih 			    &rtw89_mac_size.ple_qt45},
6179d099e0SPing-Ke Shih 	[RTW89_QTA_INVALID] = {RTW89_QTA_INVALID, NULL, NULL, NULL, NULL, NULL,
6279d099e0SPing-Ke Shih 			       NULL},
6379d099e0SPing-Ke Shih };
6479d099e0SPing-Ke Shih 
65e8955811SPing-Ke Shih static const u32 rtw8852c_h2c_regs[RTW89_H2CREG_MAX] = {
66e8955811SPing-Ke Shih 	R_AX_H2CREG_DATA0_V1, R_AX_H2CREG_DATA1_V1, R_AX_H2CREG_DATA2_V1,
67e8955811SPing-Ke Shih 	R_AX_H2CREG_DATA3_V1
68e8955811SPing-Ke Shih };
69e8955811SPing-Ke Shih 
70e8955811SPing-Ke Shih static const u32 rtw8852c_c2h_regs[RTW89_H2CREG_MAX] = {
71e8955811SPing-Ke Shih 	R_AX_C2HREG_DATA0_V1, R_AX_C2HREG_DATA1_V1, R_AX_C2HREG_DATA2_V1,
72e8955811SPing-Ke Shih 	R_AX_C2HREG_DATA3_V1
73e8955811SPing-Ke Shih };
74e8955811SPing-Ke Shih 
75ab8a5671SPing-Ke Shih static const struct rtw89_page_regs rtw8852c_page_regs = {
76ab8a5671SPing-Ke Shih 	.hci_fc_ctrl	= R_AX_HCI_FC_CTRL_V1,
77ab8a5671SPing-Ke Shih 	.ch_page_ctrl	= R_AX_CH_PAGE_CTRL_V1,
78ab8a5671SPing-Ke Shih 	.ach_page_ctrl	= R_AX_ACH0_PAGE_CTRL_V1,
79ab8a5671SPing-Ke Shih 	.ach_page_info	= R_AX_ACH0_PAGE_INFO_V1,
80ab8a5671SPing-Ke Shih 	.pub_page_info3	= R_AX_PUB_PAGE_INFO3_V1,
81ab8a5671SPing-Ke Shih 	.pub_page_ctrl1	= R_AX_PUB_PAGE_CTRL1_V1,
82ab8a5671SPing-Ke Shih 	.pub_page_ctrl2	= R_AX_PUB_PAGE_CTRL2_V1,
83ab8a5671SPing-Ke Shih 	.pub_page_info1	= R_AX_PUB_PAGE_INFO1_V1,
84ab8a5671SPing-Ke Shih 	.pub_page_info2 = R_AX_PUB_PAGE_INFO2_V1,
85ab8a5671SPing-Ke Shih 	.wp_page_ctrl1	= R_AX_WP_PAGE_CTRL1_V1,
86ab8a5671SPing-Ke Shih 	.wp_page_ctrl2	= R_AX_WP_PAGE_CTRL2_V1,
87ab8a5671SPing-Ke Shih 	.wp_page_info1	= R_AX_WP_PAGE_INFO1_V1,
88ab8a5671SPing-Ke Shih };
89ab8a5671SPing-Ke Shih 
90b7379148SYuan-Han Zhang static const struct rtw89_reg_def rtw8852c_dcfo_comp = {
91b7379148SYuan-Han Zhang 	R_DCFO_COMP_S0_V1, B_DCFO_COMP_S0_V1_MSK
92b7379148SYuan-Han Zhang };
93b7379148SYuan-Han Zhang 
94eeadcd2aSChia-Yuan Li static const struct rtw89_imr_info rtw8852c_imr_info = {
95eeadcd2aSChia-Yuan Li 	.wdrls_imr_set		= B_AX_WDRLS_IMR_SET_V1,
96eeadcd2aSChia-Yuan Li 	.wsec_imr_reg		= R_AX_SEC_ERROR_FLAG_IMR,
97eeadcd2aSChia-Yuan Li 	.wsec_imr_set		= B_AX_TX_HANG_IMR | B_AX_RX_HANG_IMR,
98eeadcd2aSChia-Yuan Li 	.mpdu_tx_imr_set	= B_AX_MPDU_TX_IMR_SET_V1,
99eeadcd2aSChia-Yuan Li 	.mpdu_rx_imr_set	= B_AX_MPDU_RX_IMR_SET_V1,
100eeadcd2aSChia-Yuan Li 	.sta_sch_imr_set	= B_AX_STA_SCHEDULER_IMR_SET,
101eeadcd2aSChia-Yuan Li 	.txpktctl_imr_b0_reg	= R_AX_TXPKTCTL_B0_ERRFLAG_IMR,
102eeadcd2aSChia-Yuan Li 	.txpktctl_imr_b0_clr	= B_AX_TXPKTCTL_IMR_B0_CLR_V1,
103eeadcd2aSChia-Yuan Li 	.txpktctl_imr_b0_set	= B_AX_TXPKTCTL_IMR_B0_SET_V1,
104eeadcd2aSChia-Yuan Li 	.txpktctl_imr_b1_reg	= R_AX_TXPKTCTL_B1_ERRFLAG_IMR,
105eeadcd2aSChia-Yuan Li 	.txpktctl_imr_b1_clr	= B_AX_TXPKTCTL_IMR_B1_CLR_V1,
106eeadcd2aSChia-Yuan Li 	.txpktctl_imr_b1_set	= B_AX_TXPKTCTL_IMR_B1_SET_V1,
107eeadcd2aSChia-Yuan Li 	.wde_imr_clr		= B_AX_WDE_IMR_CLR_V1,
108eeadcd2aSChia-Yuan Li 	.wde_imr_set		= B_AX_WDE_IMR_SET_V1,
109eeadcd2aSChia-Yuan Li 	.ple_imr_clr		= B_AX_PLE_IMR_CLR_V1,
110eeadcd2aSChia-Yuan Li 	.ple_imr_set		= B_AX_PLE_IMR_SET_V1,
111eeadcd2aSChia-Yuan Li 	.host_disp_imr_clr	= B_AX_HOST_DISP_IMR_CLR_V1,
112eeadcd2aSChia-Yuan Li 	.host_disp_imr_set	= B_AX_HOST_DISP_IMR_SET_V1,
113eeadcd2aSChia-Yuan Li 	.cpu_disp_imr_clr	= B_AX_CPU_DISP_IMR_CLR_V1,
114eeadcd2aSChia-Yuan Li 	.cpu_disp_imr_set	= B_AX_CPU_DISP_IMR_SET_V1,
115eeadcd2aSChia-Yuan Li 	.other_disp_imr_clr	= B_AX_OTHER_DISP_IMR_CLR_V1,
116eeadcd2aSChia-Yuan Li 	.other_disp_imr_set	= B_AX_OTHER_DISP_IMR_SET_V1,
11775f1ed29SPing-Ke Shih 	.bbrpt_com_err_imr_reg	= R_AX_BBRPT_COM_ERR_IMR,
118eeadcd2aSChia-Yuan Li 	.bbrpt_chinfo_err_imr_reg = R_AX_BBRPT_CHINFO_ERR_IMR,
119eeadcd2aSChia-Yuan Li 	.bbrpt_err_imr_set	= R_AX_BBRPT_CHINFO_IMR_SET_V1,
120eeadcd2aSChia-Yuan Li 	.bbrpt_dfs_err_imr_reg	= R_AX_BBRPT_DFS_ERR_IMR,
121d86369e9SChia-Yuan Li 	.ptcl_imr_clr		= B_AX_PTCL_IMR_CLR_V1,
122d86369e9SChia-Yuan Li 	.ptcl_imr_set		= B_AX_PTCL_IMR_SET_V1,
123d86369e9SChia-Yuan Li 	.cdma_imr_0_reg		= R_AX_RX_ERR_FLAG_IMR,
124d86369e9SChia-Yuan Li 	.cdma_imr_0_clr		= B_AX_RX_ERR_IMR_CLR_V1,
125d86369e9SChia-Yuan Li 	.cdma_imr_0_set		= B_AX_RX_ERR_IMR_SET_V1,
126d86369e9SChia-Yuan Li 	.cdma_imr_1_reg		= R_AX_TX_ERR_FLAG_IMR,
127d86369e9SChia-Yuan Li 	.cdma_imr_1_clr		= B_AX_TX_ERR_IMR_CLR_V1,
128d86369e9SChia-Yuan Li 	.cdma_imr_1_set		= B_AX_TX_ERR_IMR_SET_V1,
129d86369e9SChia-Yuan Li 	.phy_intf_imr_reg	= R_AX_PHYINFO_ERR_IMR_V1,
130d86369e9SChia-Yuan Li 	.phy_intf_imr_clr	= B_AX_PHYINFO_IMR_CLR_V1,
131d86369e9SChia-Yuan Li 	.phy_intf_imr_set	= B_AX_PHYINFO_IMR_SET_V1,
132d86369e9SChia-Yuan Li 	.rmac_imr_reg		= R_AX_RX_ERR_IMR,
133d86369e9SChia-Yuan Li 	.rmac_imr_clr		= B_AX_RMAC_IMR_CLR_V1,
134d86369e9SChia-Yuan Li 	.rmac_imr_set		= B_AX_RMAC_IMR_SET_V1,
135d86369e9SChia-Yuan Li 	.tmac_imr_reg		= R_AX_TRXPTCL_ERROR_INDICA_MASK,
136d86369e9SChia-Yuan Li 	.tmac_imr_clr		= B_AX_TMAC_IMR_CLR_V1,
137d86369e9SChia-Yuan Li 	.tmac_imr_set		= B_AX_TMAC_IMR_SET_V1,
138eeadcd2aSChia-Yuan Li };
139eeadcd2aSChia-Yuan Li 
1409ef9edb9SChia-Yuan Li static const struct rtw89_rrsr_cfgs rtw8852c_rrsr_cfgs = {
1419ef9edb9SChia-Yuan Li 	.ref_rate = {R_AX_TRXPTCL_RRSR_CTL_0, B_AX_WMAC_RESP_REF_RATE_SEL, 0},
1429ef9edb9SChia-Yuan Li 	.rsc = {R_AX_PTCL_RRSR1, B_AX_RSC_MASK, 2},
1439ef9edb9SChia-Yuan Li };
1449ef9edb9SChia-Yuan Li 
14587deaad9SEric Huang static const struct rtw89_dig_regs rtw8852c_dig_regs = {
14687deaad9SEric Huang 	.seg0_pd_reg = R_SEG0R_PD,
14787deaad9SEric Huang 	.pd_lower_bound_mask = B_SEG0R_PD_LOWER_BOUND_MSK,
14887deaad9SEric Huang 	.pd_spatial_reuse_en = B_SEG0R_PD_SPATIAL_REUSE_EN_MSK,
149*058b2074SCheng-Chieh Hsieh 	.bmode_pd_reg = R_BMODE_PDTH_EN_V1,
150*058b2074SCheng-Chieh Hsieh 	.bmode_cca_rssi_limit_en = B_BMODE_PDTH_LIMIT_EN_MSK_V1,
151*058b2074SCheng-Chieh Hsieh 	.bmode_pd_lower_bound_reg = R_BMODE_PDTH_V1,
152*058b2074SCheng-Chieh Hsieh 	.bmode_rssi_nocca_low_th_mask = B_BMODE_PDTH_LOWER_BOUND_MSK_V1,
15387deaad9SEric Huang 	.p0_lna_init = {R_PATH0_LNA_INIT_V1, B_PATH0_LNA_INIT_IDX_MSK},
15487deaad9SEric Huang 	.p1_lna_init = {R_PATH1_LNA_INIT_V1, B_PATH1_LNA_INIT_IDX_MSK},
15587deaad9SEric Huang 	.p0_tia_init = {R_PATH0_TIA_INIT_V1, B_PATH0_TIA_INIT_IDX_MSK_V1},
15687deaad9SEric Huang 	.p1_tia_init = {R_PATH1_TIA_INIT_V1, B_PATH1_TIA_INIT_IDX_MSK_V1},
15787deaad9SEric Huang 	.p0_rxb_init = {R_PATH0_RXB_INIT_V1, B_PATH0_RXB_INIT_IDX_MSK_V1},
15887deaad9SEric Huang 	.p1_rxb_init = {R_PATH1_RXB_INIT_V1, B_PATH1_RXB_INIT_IDX_MSK_V1},
15987deaad9SEric Huang 	.p0_p20_pagcugc_en = {R_PATH0_P20_FOLLOW_BY_PAGCUGC_V1,
16087deaad9SEric Huang 			      B_PATH0_P20_FOLLOW_BY_PAGCUGC_EN_MSK},
16187deaad9SEric Huang 	.p0_s20_pagcugc_en = {R_PATH0_S20_FOLLOW_BY_PAGCUGC_V1,
16287deaad9SEric Huang 			      B_PATH0_S20_FOLLOW_BY_PAGCUGC_EN_MSK},
16387deaad9SEric Huang 	.p1_p20_pagcugc_en = {R_PATH1_P20_FOLLOW_BY_PAGCUGC_V1,
16487deaad9SEric Huang 			      B_PATH1_P20_FOLLOW_BY_PAGCUGC_EN_MSK},
16587deaad9SEric Huang 	.p1_s20_pagcugc_en = {R_PATH1_S20_FOLLOW_BY_PAGCUGC_V1,
16687deaad9SEric Huang 			      B_PATH1_S20_FOLLOW_BY_PAGCUGC_EN_MSK},
16787deaad9SEric Huang };
16887deaad9SEric Huang 
1691b00e923SPing-Ke Shih static void rtw8852c_ctrl_btg(struct rtw89_dev *rtwdev, bool btg);
170755fda37SYi-Tang Chiu static void rtw8852c_ctrl_tx_path_tmac(struct rtw89_dev *rtwdev, u8 tx_path,
171755fda37SYi-Tang Chiu 				       enum rtw89_mac_idx mac_idx);
1721b00e923SPing-Ke Shih 
rtw8852c_pwr_on_func(struct rtw89_dev * rtwdev)1732a7e54dbSPing-Ke Shih static int rtw8852c_pwr_on_func(struct rtw89_dev *rtwdev)
1742a7e54dbSPing-Ke Shih {
1752a7e54dbSPing-Ke Shih 	u32 val32;
1762a7e54dbSPing-Ke Shih 	u32 ret;
1772a7e54dbSPing-Ke Shih 
1782a7e54dbSPing-Ke Shih 	val32 = rtw89_read32_mask(rtwdev, R_AX_SYS_STATUS1, B_AX_PAD_HCI_SEL_V2_MASK);
1792a7e54dbSPing-Ke Shih 	if (val32 == MAC_AX_HCI_SEL_PCIE_USB)
1802a7e54dbSPing-Ke Shih 		rtw89_write32_set(rtwdev, R_AX_LDO_AON_CTRL0, B_AX_PD_REGU_L);
1812a7e54dbSPing-Ke Shih 
1822a7e54dbSPing-Ke Shih 	rtw89_write32_clr(rtwdev, R_AX_SYS_PW_CTRL, B_AX_AFSM_WLSUS_EN |
1832a7e54dbSPing-Ke Shih 						    B_AX_AFSM_PCIE_SUS_EN);
1842a7e54dbSPing-Ke Shih 	rtw89_write32_set(rtwdev, R_AX_SYS_PW_CTRL, B_AX_DIS_WLBT_PDNSUSEN_SOPC);
1852a7e54dbSPing-Ke Shih 	rtw89_write32_set(rtwdev, R_AX_WLLPS_CTRL, B_AX_DIS_WLBT_LPSEN_LOPC);
1862a7e54dbSPing-Ke Shih 	rtw89_write32_clr(rtwdev, R_AX_SYS_PW_CTRL, B_AX_APDM_HPDN);
1872a7e54dbSPing-Ke Shih 	rtw89_write32_clr(rtwdev, R_AX_SYS_PW_CTRL, B_AX_APFM_SWLPS);
1882a7e54dbSPing-Ke Shih 
1892a7e54dbSPing-Ke Shih 	ret = read_poll_timeout(rtw89_read32, val32, val32 & B_AX_RDY_SYSPWR,
1902a7e54dbSPing-Ke Shih 				1000, 20000, false, rtwdev, R_AX_SYS_PW_CTRL);
1912a7e54dbSPing-Ke Shih 	if (ret)
1922a7e54dbSPing-Ke Shih 		return ret;
1932a7e54dbSPing-Ke Shih 
1942a7e54dbSPing-Ke Shih 	rtw89_write32_set(rtwdev, R_AX_SYS_PW_CTRL, B_AX_EN_WLON);
1952a7e54dbSPing-Ke Shih 	rtw89_write32_set(rtwdev, R_AX_SYS_PW_CTRL, B_AX_APFN_ONMAC);
1962a7e54dbSPing-Ke Shih 
1972a7e54dbSPing-Ke Shih 	ret = read_poll_timeout(rtw89_read32, val32, !(val32 & B_AX_APFN_ONMAC),
1982a7e54dbSPing-Ke Shih 				1000, 20000, false, rtwdev, R_AX_SYS_PW_CTRL);
1992a7e54dbSPing-Ke Shih 	if (ret)
2002a7e54dbSPing-Ke Shih 		return ret;
2012a7e54dbSPing-Ke Shih 
2022a7e54dbSPing-Ke Shih 	rtw89_write8_set(rtwdev, R_AX_PLATFORM_ENABLE, B_AX_PLATFORM_EN);
2032a7e54dbSPing-Ke Shih 	rtw89_write8_clr(rtwdev, R_AX_PLATFORM_ENABLE, B_AX_PLATFORM_EN);
2042a7e54dbSPing-Ke Shih 	rtw89_write8_set(rtwdev, R_AX_PLATFORM_ENABLE, B_AX_PLATFORM_EN);
2052a7e54dbSPing-Ke Shih 	rtw89_write8_clr(rtwdev, R_AX_PLATFORM_ENABLE, B_AX_PLATFORM_EN);
2062a7e54dbSPing-Ke Shih 
2072a7e54dbSPing-Ke Shih 	rtw89_write8_set(rtwdev, R_AX_PLATFORM_ENABLE, B_AX_PLATFORM_EN);
2082a7e54dbSPing-Ke Shih 	rtw89_write32_clr(rtwdev, R_AX_SYS_SDIO_CTRL, B_AX_PCIE_CALIB_EN_V1);
2092a7e54dbSPing-Ke Shih 
2102a7e54dbSPing-Ke Shih 	rtw89_write32_clr(rtwdev, R_AX_SYS_ISO_CTRL_EXTEND, B_AX_CMAC1_FEN);
2112a7e54dbSPing-Ke Shih 	rtw89_write32_set(rtwdev, R_AX_SYS_ISO_CTRL_EXTEND, B_AX_R_SYM_ISO_CMAC12PP);
2122a7e54dbSPing-Ke Shih 	rtw89_write32_clr(rtwdev, R_AX_AFE_CTRL1, B_AX_R_SYM_WLCMAC1_P4_PC_EN |
2132a7e54dbSPing-Ke Shih 						  B_AX_R_SYM_WLCMAC1_P3_PC_EN |
2142a7e54dbSPing-Ke Shih 						  B_AX_R_SYM_WLCMAC1_P2_PC_EN |
2152a7e54dbSPing-Ke Shih 						  B_AX_R_SYM_WLCMAC1_P1_PC_EN |
2162a7e54dbSPing-Ke Shih 						  B_AX_R_SYM_WLCMAC1_PC_EN);
2172a7e54dbSPing-Ke Shih 	rtw89_write32_set(rtwdev, R_AX_SYS_ADIE_PAD_PWR_CTRL, B_AX_SYM_PADPDN_WL_PTA_1P3);
2182a7e54dbSPing-Ke Shih 
2192a7e54dbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL,
2202a7e54dbSPing-Ke Shih 				      XTAL_SI_GND_SHDN_WL, XTAL_SI_GND_SHDN_WL);
2212a7e54dbSPing-Ke Shih 	if (ret)
2222a7e54dbSPing-Ke Shih 		return ret;
2232a7e54dbSPing-Ke Shih 
2242a7e54dbSPing-Ke Shih 	rtw89_write32_set(rtwdev, R_AX_SYS_ADIE_PAD_PWR_CTRL, B_AX_SYM_PADPDN_WL_RFC_1P3);
2252a7e54dbSPing-Ke Shih 
2262a7e54dbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL,
2272a7e54dbSPing-Ke Shih 				      XTAL_SI_SHDN_WL, XTAL_SI_SHDN_WL);
2282a7e54dbSPing-Ke Shih 	if (ret)
2292a7e54dbSPing-Ke Shih 		return ret;
2302a7e54dbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, XTAL_SI_OFF_WEI,
2312a7e54dbSPing-Ke Shih 				      XTAL_SI_OFF_WEI);
2322a7e54dbSPing-Ke Shih 	if (ret)
2332a7e54dbSPing-Ke Shih 		return ret;
2342a7e54dbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, XTAL_SI_OFF_EI,
2352a7e54dbSPing-Ke Shih 				      XTAL_SI_OFF_EI);
2362a7e54dbSPing-Ke Shih 	if (ret)
2372a7e54dbSPing-Ke Shih 		return ret;
2382a7e54dbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_RFC2RF);
2392a7e54dbSPing-Ke Shih 	if (ret)
2402a7e54dbSPing-Ke Shih 		return ret;
2412a7e54dbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, XTAL_SI_PON_WEI,
2422a7e54dbSPing-Ke Shih 				      XTAL_SI_PON_WEI);
2432a7e54dbSPing-Ke Shih 	if (ret)
2442a7e54dbSPing-Ke Shih 		return ret;
2452a7e54dbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, XTAL_SI_PON_EI,
2462a7e54dbSPing-Ke Shih 				      XTAL_SI_PON_EI);
2472a7e54dbSPing-Ke Shih 	if (ret)
2482a7e54dbSPing-Ke Shih 		return ret;
2492a7e54dbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_SRAM2RFC);
2502a7e54dbSPing-Ke Shih 	if (ret)
2512a7e54dbSPing-Ke Shih 		return ret;
2522a7e54dbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_XTAL_XMD_2, 0, XTAL_SI_LDO_LPS);
2532a7e54dbSPing-Ke Shih 	if (ret)
2542a7e54dbSPing-Ke Shih 		return ret;
2552a7e54dbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_XTAL_XMD_4, 0, XTAL_SI_LPS_CAP);
2562a7e54dbSPing-Ke Shih 	if (ret)
2572a7e54dbSPing-Ke Shih 		return ret;
2582a7e54dbSPing-Ke Shih 
2592a7e54dbSPing-Ke Shih 	rtw89_write32_set(rtwdev, R_AX_PMC_DBG_CTRL2, B_AX_SYSON_DIS_PMCR_AX_WRMSK);
2602a7e54dbSPing-Ke Shih 	rtw89_write32_set(rtwdev, R_AX_SYS_ISO_CTRL, B_AX_ISO_EB2CORE);
2612a7e54dbSPing-Ke Shih 	rtw89_write32_clr(rtwdev, R_AX_SYS_ISO_CTRL, B_AX_PWC_EV2EF_B15);
2622a7e54dbSPing-Ke Shih 
2632a7e54dbSPing-Ke Shih 	fsleep(1000);
2642a7e54dbSPing-Ke Shih 
2652a7e54dbSPing-Ke Shih 	rtw89_write32_clr(rtwdev, R_AX_SYS_ISO_CTRL, B_AX_PWC_EV2EF_B14);
2662a7e54dbSPing-Ke Shih 	rtw89_write32_clr(rtwdev, R_AX_PMC_DBG_CTRL2, B_AX_SYSON_DIS_PMCR_AX_WRMSK);
2672a7e54dbSPing-Ke Shih 	rtw89_write32_set(rtwdev, R_AX_GPIO0_15_EECS_EESK_LED1_PULL_LOW_EN,
2682a7e54dbSPing-Ke Shih 			  B_AX_EECS_PULL_LOW_EN | B_AX_EESK_PULL_LOW_EN |
2692a7e54dbSPing-Ke Shih 			  B_AX_LED1_PULL_LOW_EN);
2702a7e54dbSPing-Ke Shih 
2712a7e54dbSPing-Ke Shih 	rtw89_write32_set(rtwdev, R_AX_DMAC_FUNC_EN,
2722a7e54dbSPing-Ke Shih 			  B_AX_MAC_FUNC_EN | B_AX_DMAC_FUNC_EN | B_AX_MPDU_PROC_EN |
2732a7e54dbSPing-Ke Shih 			  B_AX_WD_RLS_EN | B_AX_DLE_WDE_EN | B_AX_TXPKT_CTRL_EN |
2742a7e54dbSPing-Ke Shih 			  B_AX_STA_SCH_EN | B_AX_DLE_PLE_EN | B_AX_PKT_BUF_EN |
2752a7e54dbSPing-Ke Shih 			  B_AX_DMAC_TBL_EN | B_AX_PKT_IN_EN | B_AX_DLE_CPUIO_EN |
2762a7e54dbSPing-Ke Shih 			  B_AX_DISPATCHER_EN | B_AX_BBRPT_EN | B_AX_MAC_SEC_EN |
2772a7e54dbSPing-Ke Shih 			  B_AX_MAC_UN_EN | B_AX_H_AXIDMA_EN);
2782a7e54dbSPing-Ke Shih 
2792a7e54dbSPing-Ke Shih 	rtw89_write32_set(rtwdev, R_AX_CMAC_FUNC_EN,
2802a7e54dbSPing-Ke Shih 			  B_AX_CMAC_EN | B_AX_CMAC_TXEN | B_AX_CMAC_RXEN |
2812a7e54dbSPing-Ke Shih 			  B_AX_FORCE_CMACREG_GCKEN | B_AX_PHYINTF_EN |
2822a7e54dbSPing-Ke Shih 			  B_AX_CMAC_DMA_EN | B_AX_PTCLTOP_EN | B_AX_SCHEDULER_EN |
2832a7e54dbSPing-Ke Shih 			  B_AX_TMAC_EN | B_AX_RMAC_EN);
2842a7e54dbSPing-Ke Shih 
285d187691aSPing-Ke Shih 	rtw89_write32_mask(rtwdev, R_AX_LED1_FUNC_SEL, B_AX_PINMUX_EESK_FUNC_SEL_V1_MASK,
286d187691aSPing-Ke Shih 			   PINMUX_EESK_FUNC_SEL_BT_LOG);
287d187691aSPing-Ke Shih 
2882a7e54dbSPing-Ke Shih 	return 0;
2892a7e54dbSPing-Ke Shih }
2902a7e54dbSPing-Ke Shih 
rtw8852c_pwr_off_func(struct rtw89_dev * rtwdev)2912a7e54dbSPing-Ke Shih static int rtw8852c_pwr_off_func(struct rtw89_dev *rtwdev)
2922a7e54dbSPing-Ke Shih {
2932a7e54dbSPing-Ke Shih 	u32 val32;
2942a7e54dbSPing-Ke Shih 	u32 ret;
2952a7e54dbSPing-Ke Shih 
2962a7e54dbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, XTAL_SI_RFC2RF,
2972a7e54dbSPing-Ke Shih 				      XTAL_SI_RFC2RF);
2982a7e54dbSPing-Ke Shih 	if (ret)
2992a7e54dbSPing-Ke Shih 		return ret;
3002a7e54dbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_OFF_EI);
3012a7e54dbSPing-Ke Shih 	if (ret)
3022a7e54dbSPing-Ke Shih 		return ret;
3032a7e54dbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_OFF_WEI);
3042a7e54dbSPing-Ke Shih 	if (ret)
3052a7e54dbSPing-Ke Shih 		return ret;
3062a7e54dbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_WL_RFC_S0, 0, XTAL_SI_RF00);
3072a7e54dbSPing-Ke Shih 	if (ret)
3082a7e54dbSPing-Ke Shih 		return ret;
3092a7e54dbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_WL_RFC_S1, 0, XTAL_SI_RF10);
3102a7e54dbSPing-Ke Shih 	if (ret)
3112a7e54dbSPing-Ke Shih 		return ret;
3122a7e54dbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, XTAL_SI_SRAM2RFC,
3132a7e54dbSPing-Ke Shih 				      XTAL_SI_SRAM2RFC);
3142a7e54dbSPing-Ke Shih 	if (ret)
3152a7e54dbSPing-Ke Shih 		return ret;
3162a7e54dbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_PON_EI);
3172a7e54dbSPing-Ke Shih 	if (ret)
3182a7e54dbSPing-Ke Shih 		return ret;
3192a7e54dbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_PON_WEI);
3202a7e54dbSPing-Ke Shih 	if (ret)
3212a7e54dbSPing-Ke Shih 		return ret;
3222a7e54dbSPing-Ke Shih 
3232a7e54dbSPing-Ke Shih 	rtw89_write32_set(rtwdev, R_AX_SYS_PW_CTRL, B_AX_EN_WLON);
3242a7e54dbSPing-Ke Shih 	rtw89_write8_clr(rtwdev, R_AX_SYS_FUNC_EN, B_AX_FEN_BB_GLB_RSTN | B_AX_FEN_BBRSTB);
3252a7e54dbSPing-Ke Shih 	rtw89_write32_clr(rtwdev, R_AX_SYS_ISO_CTRL_EXTEND,
3262a7e54dbSPing-Ke Shih 			  B_AX_R_SYM_FEN_WLBBGLB_1 | B_AX_R_SYM_FEN_WLBBFUN_1);
3272a7e54dbSPing-Ke Shih 	rtw89_write32_clr(rtwdev, R_AX_SYS_ADIE_PAD_PWR_CTRL, B_AX_SYM_PADPDN_WL_RFC_1P3);
3282a7e54dbSPing-Ke Shih 
3292a7e54dbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_SHDN_WL);
3302a7e54dbSPing-Ke Shih 	if (ret)
3312a7e54dbSPing-Ke Shih 		return ret;
3322a7e54dbSPing-Ke Shih 
3332a7e54dbSPing-Ke Shih 	rtw89_write32_clr(rtwdev, R_AX_SYS_ADIE_PAD_PWR_CTRL, B_AX_SYM_PADPDN_WL_PTA_1P3);
3342a7e54dbSPing-Ke Shih 
3352a7e54dbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_GND_SHDN_WL);
3362a7e54dbSPing-Ke Shih 	if (ret)
3372a7e54dbSPing-Ke Shih 		return ret;
3382a7e54dbSPing-Ke Shih 
3392a7e54dbSPing-Ke Shih 	rtw89_write32_set(rtwdev, R_AX_SYS_PW_CTRL, B_AX_APFM_OFFMAC);
3402a7e54dbSPing-Ke Shih 
3412a7e54dbSPing-Ke Shih 	ret = read_poll_timeout(rtw89_read32, val32, !(val32 & B_AX_APFM_OFFMAC),
3422a7e54dbSPing-Ke Shih 				1000, 20000, false, rtwdev, R_AX_SYS_PW_CTRL);
3432a7e54dbSPing-Ke Shih 	if (ret)
3442a7e54dbSPing-Ke Shih 		return ret;
3452a7e54dbSPing-Ke Shih 
3462a7e54dbSPing-Ke Shih 	rtw89_write32(rtwdev, R_AX_WLLPS_CTRL, 0x0001A0B0);
3472a7e54dbSPing-Ke Shih 	rtw89_write32_set(rtwdev, R_AX_SYS_PW_CTRL, B_AX_XTAL_OFF_A_DIE);
3482a7e54dbSPing-Ke Shih 	rtw89_write32_set(rtwdev, R_AX_SYS_PW_CTRL, B_AX_APFM_SWLPS);
3492a7e54dbSPing-Ke Shih 
3502a7e54dbSPing-Ke Shih 	return 0;
3512a7e54dbSPing-Ke Shih }
3522a7e54dbSPing-Ke Shih 
rtw8852c_e_efuse_parsing(struct rtw89_efuse * efuse,struct rtw8852c_efuse * map)353ea372064SPing-Ke Shih static void rtw8852c_e_efuse_parsing(struct rtw89_efuse *efuse,
354ea372064SPing-Ke Shih 				     struct rtw8852c_efuse *map)
355ea372064SPing-Ke Shih {
356ea372064SPing-Ke Shih 	ether_addr_copy(efuse->addr, map->e.mac_addr);
357ea372064SPing-Ke Shih 	efuse->rfe_type = map->rfe_type;
358ea372064SPing-Ke Shih 	efuse->xtal_cap = map->xtal_k;
359ea372064SPing-Ke Shih }
360ea372064SPing-Ke Shih 
rtw8852c_efuse_parsing_tssi(struct rtw89_dev * rtwdev,struct rtw8852c_efuse * map)361ea372064SPing-Ke Shih static void rtw8852c_efuse_parsing_tssi(struct rtw89_dev *rtwdev,
362ea372064SPing-Ke Shih 					struct rtw8852c_efuse *map)
363ea372064SPing-Ke Shih {
364ea372064SPing-Ke Shih 	struct rtw89_tssi_info *tssi = &rtwdev->tssi;
365ea372064SPing-Ke Shih 	struct rtw8852c_tssi_offset *ofst[] = {&map->path_a_tssi, &map->path_b_tssi};
366ea372064SPing-Ke Shih 	u8 *bw40_1s_tssi_6g_ofst[] = {map->bw40_1s_tssi_6g_a, map->bw40_1s_tssi_6g_b};
367ea372064SPing-Ke Shih 	u8 i, j;
368ea372064SPing-Ke Shih 
369ea372064SPing-Ke Shih 	tssi->thermal[RF_PATH_A] = map->path_a_therm;
370ea372064SPing-Ke Shih 	tssi->thermal[RF_PATH_B] = map->path_b_therm;
371ea372064SPing-Ke Shih 
372ea372064SPing-Ke Shih 	for (i = 0; i < RF_PATH_NUM_8852C; i++) {
373ea372064SPing-Ke Shih 		memcpy(tssi->tssi_cck[i], ofst[i]->cck_tssi,
374ea372064SPing-Ke Shih 		       sizeof(ofst[i]->cck_tssi));
375ea372064SPing-Ke Shih 
376ea372064SPing-Ke Shih 		for (j = 0; j < TSSI_CCK_CH_GROUP_NUM; j++)
377ea372064SPing-Ke Shih 			rtw89_debug(rtwdev, RTW89_DBG_TSSI,
378ea372064SPing-Ke Shih 				    "[TSSI][EFUSE] path=%d cck[%d]=0x%x\n",
379ea372064SPing-Ke Shih 				    i, j, tssi->tssi_cck[i][j]);
380ea372064SPing-Ke Shih 
381ea372064SPing-Ke Shih 		memcpy(tssi->tssi_mcs[i], ofst[i]->bw40_tssi,
382ea372064SPing-Ke Shih 		       sizeof(ofst[i]->bw40_tssi));
383ea372064SPing-Ke Shih 		memcpy(tssi->tssi_mcs[i] + TSSI_MCS_2G_CH_GROUP_NUM,
384ea372064SPing-Ke Shih 		       ofst[i]->bw40_1s_tssi_5g, sizeof(ofst[i]->bw40_1s_tssi_5g));
385ea372064SPing-Ke Shih 		memcpy(tssi->tssi_6g_mcs[i], bw40_1s_tssi_6g_ofst[i],
386ea372064SPing-Ke Shih 		       sizeof(tssi->tssi_6g_mcs[i]));
387ea372064SPing-Ke Shih 
388ea372064SPing-Ke Shih 		for (j = 0; j < TSSI_MCS_CH_GROUP_NUM; j++)
389ea372064SPing-Ke Shih 			rtw89_debug(rtwdev, RTW89_DBG_TSSI,
390ea372064SPing-Ke Shih 				    "[TSSI][EFUSE] path=%d mcs[%d]=0x%x\n",
391ea372064SPing-Ke Shih 				    i, j, tssi->tssi_mcs[i][j]);
392ea372064SPing-Ke Shih 	}
393ea372064SPing-Ke Shih }
394ea372064SPing-Ke Shih 
_decode_efuse_gain(u8 data,s8 * high,s8 * low)395e6b17cbdSPing-Ke Shih static bool _decode_efuse_gain(u8 data, s8 *high, s8 *low)
396e6b17cbdSPing-Ke Shih {
397e6b17cbdSPing-Ke Shih 	if (high)
398e6b17cbdSPing-Ke Shih 		*high = sign_extend32(FIELD_GET(GENMASK(7,  4), data), 3);
399e6b17cbdSPing-Ke Shih 	if (low)
400e6b17cbdSPing-Ke Shih 		*low = sign_extend32(FIELD_GET(GENMASK(3,  0), data), 3);
401e6b17cbdSPing-Ke Shih 
402e6b17cbdSPing-Ke Shih 	return data != 0xff;
403e6b17cbdSPing-Ke Shih }
404e6b17cbdSPing-Ke Shih 
rtw8852c_efuse_parsing_gain_offset(struct rtw89_dev * rtwdev,struct rtw8852c_efuse * map)405e6b17cbdSPing-Ke Shih static void rtw8852c_efuse_parsing_gain_offset(struct rtw89_dev *rtwdev,
406e6b17cbdSPing-Ke Shih 					       struct rtw8852c_efuse *map)
407e6b17cbdSPing-Ke Shih {
408e6b17cbdSPing-Ke Shih 	struct rtw89_phy_efuse_gain *gain = &rtwdev->efuse_gain;
409e6b17cbdSPing-Ke Shih 	bool valid = false;
410e6b17cbdSPing-Ke Shih 
411e6b17cbdSPing-Ke Shih 	valid |= _decode_efuse_gain(map->rx_gain_2g_cck,
412e6b17cbdSPing-Ke Shih 				    &gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_2G_CCK],
413e6b17cbdSPing-Ke Shih 				    &gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_2G_CCK]);
414e6b17cbdSPing-Ke Shih 	valid |= _decode_efuse_gain(map->rx_gain_2g_ofdm,
415e6b17cbdSPing-Ke Shih 				    &gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_2G_OFDM],
416e6b17cbdSPing-Ke Shih 				    &gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_2G_OFDM]);
417e6b17cbdSPing-Ke Shih 	valid |= _decode_efuse_gain(map->rx_gain_5g_low,
418e6b17cbdSPing-Ke Shih 				    &gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_5G_LOW],
419e6b17cbdSPing-Ke Shih 				    &gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_5G_LOW]);
420e6b17cbdSPing-Ke Shih 	valid |= _decode_efuse_gain(map->rx_gain_5g_mid,
421e6b17cbdSPing-Ke Shih 				    &gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_5G_MID],
422e6b17cbdSPing-Ke Shih 				    &gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_5G_MID]);
423e6b17cbdSPing-Ke Shih 	valid |= _decode_efuse_gain(map->rx_gain_5g_high,
424e6b17cbdSPing-Ke Shih 				    &gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_5G_HIGH],
425e6b17cbdSPing-Ke Shih 				    &gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_5G_HIGH]);
426e6b17cbdSPing-Ke Shih 
427e6b17cbdSPing-Ke Shih 	gain->offset_valid = valid;
428e6b17cbdSPing-Ke Shih }
429e6b17cbdSPing-Ke Shih 
rtw8852c_read_efuse(struct rtw89_dev * rtwdev,u8 * log_map)430ea372064SPing-Ke Shih static int rtw8852c_read_efuse(struct rtw89_dev *rtwdev, u8 *log_map)
431ea372064SPing-Ke Shih {
432ea372064SPing-Ke Shih 	struct rtw89_efuse *efuse = &rtwdev->efuse;
433ea372064SPing-Ke Shih 	struct rtw8852c_efuse *map;
434ea372064SPing-Ke Shih 
435ea372064SPing-Ke Shih 	map = (struct rtw8852c_efuse *)log_map;
436ea372064SPing-Ke Shih 
437ea372064SPing-Ke Shih 	efuse->country_code[0] = map->country_code[0];
438ea372064SPing-Ke Shih 	efuse->country_code[1] = map->country_code[1];
439ea372064SPing-Ke Shih 	rtw8852c_efuse_parsing_tssi(rtwdev, map);
440e6b17cbdSPing-Ke Shih 	rtw8852c_efuse_parsing_gain_offset(rtwdev, map);
441ea372064SPing-Ke Shih 
442ea372064SPing-Ke Shih 	switch (rtwdev->hci.type) {
443ea372064SPing-Ke Shih 	case RTW89_HCI_TYPE_PCIE:
444ea372064SPing-Ke Shih 		rtw8852c_e_efuse_parsing(efuse, map);
445ea372064SPing-Ke Shih 		break;
446ea372064SPing-Ke Shih 	default:
447ea372064SPing-Ke Shih 		return -ENOTSUPP;
448ea372064SPing-Ke Shih 	}
449ea372064SPing-Ke Shih 
450ea372064SPing-Ke Shih 	rtw89_info(rtwdev, "chip rfe_type is %d\n", efuse->rfe_type);
451ea372064SPing-Ke Shih 
452ea372064SPing-Ke Shih 	return 0;
453ea372064SPing-Ke Shih }
454ea372064SPing-Ke Shih 
rtw8852c_phycap_parsing_tssi(struct rtw89_dev * rtwdev,u8 * phycap_map)455a82174c6SPing-Ke Shih static void rtw8852c_phycap_parsing_tssi(struct rtw89_dev *rtwdev, u8 *phycap_map)
456a82174c6SPing-Ke Shih {
457a82174c6SPing-Ke Shih 	struct rtw89_tssi_info *tssi = &rtwdev->tssi;
458a82174c6SPing-Ke Shih 	static const u32 tssi_trim_addr[RF_PATH_NUM_8852C] = {0x5D6, 0x5AB};
459a82174c6SPing-Ke Shih 	static const u32 tssi_trim_addr_6g[RF_PATH_NUM_8852C] = {0x5CE, 0x5A3};
460a82174c6SPing-Ke Shih 	u32 addr = rtwdev->chip->phycap_addr;
461a82174c6SPing-Ke Shih 	bool pg = false;
462a82174c6SPing-Ke Shih 	u32 ofst;
463a82174c6SPing-Ke Shih 	u8 i, j;
464a82174c6SPing-Ke Shih 
465a82174c6SPing-Ke Shih 	for (i = 0; i < RF_PATH_NUM_8852C; i++) {
466a82174c6SPing-Ke Shih 		for (j = 0; j < TSSI_TRIM_CH_GROUP_NUM; j++) {
467a82174c6SPing-Ke Shih 			/* addrs are in decreasing order */
468a82174c6SPing-Ke Shih 			ofst = tssi_trim_addr[i] - addr - j;
469a82174c6SPing-Ke Shih 			tssi->tssi_trim[i][j] = phycap_map[ofst];
470a82174c6SPing-Ke Shih 
471a82174c6SPing-Ke Shih 			if (phycap_map[ofst] != 0xff)
472a82174c6SPing-Ke Shih 				pg = true;
473a82174c6SPing-Ke Shih 		}
474a82174c6SPing-Ke Shih 
475a82174c6SPing-Ke Shih 		for (j = 0; j < TSSI_TRIM_CH_GROUP_NUM_6G; j++) {
476a82174c6SPing-Ke Shih 			/* addrs are in decreasing order */
477a82174c6SPing-Ke Shih 			ofst = tssi_trim_addr_6g[i] - addr - j;
478a82174c6SPing-Ke Shih 			tssi->tssi_trim_6g[i][j] = phycap_map[ofst];
479a82174c6SPing-Ke Shih 
480a82174c6SPing-Ke Shih 			if (phycap_map[ofst] != 0xff)
481a82174c6SPing-Ke Shih 				pg = true;
482a82174c6SPing-Ke Shih 		}
483a82174c6SPing-Ke Shih 	}
484a82174c6SPing-Ke Shih 
485a82174c6SPing-Ke Shih 	if (!pg) {
486a82174c6SPing-Ke Shih 		memset(tssi->tssi_trim, 0, sizeof(tssi->tssi_trim));
487a82174c6SPing-Ke Shih 		memset(tssi->tssi_trim_6g, 0, sizeof(tssi->tssi_trim_6g));
488a82174c6SPing-Ke Shih 		rtw89_debug(rtwdev, RTW89_DBG_TSSI,
489a82174c6SPing-Ke Shih 			    "[TSSI][TRIM] no PG, set all trim info to 0\n");
490a82174c6SPing-Ke Shih 	}
491a82174c6SPing-Ke Shih 
492a82174c6SPing-Ke Shih 	for (i = 0; i < RF_PATH_NUM_8852C; i++)
493a82174c6SPing-Ke Shih 		for (j = 0; j < TSSI_TRIM_CH_GROUP_NUM; j++)
494a82174c6SPing-Ke Shih 			rtw89_debug(rtwdev, RTW89_DBG_TSSI,
495a82174c6SPing-Ke Shih 				    "[TSSI] path=%d idx=%d trim=0x%x addr=0x%x\n",
496a82174c6SPing-Ke Shih 				    i, j, tssi->tssi_trim[i][j],
497a82174c6SPing-Ke Shih 				    tssi_trim_addr[i] - j);
498a82174c6SPing-Ke Shih }
499a82174c6SPing-Ke Shih 
rtw8852c_phycap_parsing_thermal_trim(struct rtw89_dev * rtwdev,u8 * phycap_map)500a82174c6SPing-Ke Shih static void rtw8852c_phycap_parsing_thermal_trim(struct rtw89_dev *rtwdev,
501a82174c6SPing-Ke Shih 						 u8 *phycap_map)
502a82174c6SPing-Ke Shih {
503a82174c6SPing-Ke Shih 	struct rtw89_power_trim_info *info = &rtwdev->pwr_trim;
504a82174c6SPing-Ke Shih 	static const u32 thm_trim_addr[RF_PATH_NUM_8852C] = {0x5DF, 0x5DC};
505a82174c6SPing-Ke Shih 	u32 addr = rtwdev->chip->phycap_addr;
506a82174c6SPing-Ke Shih 	u8 i;
507a82174c6SPing-Ke Shih 
508a82174c6SPing-Ke Shih 	for (i = 0; i < RF_PATH_NUM_8852C; i++) {
509a82174c6SPing-Ke Shih 		info->thermal_trim[i] = phycap_map[thm_trim_addr[i] - addr];
510a82174c6SPing-Ke Shih 
511a82174c6SPing-Ke Shih 		rtw89_debug(rtwdev, RTW89_DBG_RFK,
512a82174c6SPing-Ke Shih 			    "[THERMAL][TRIM] path=%d thermal_trim=0x%x\n",
513a82174c6SPing-Ke Shih 			    i, info->thermal_trim[i]);
514a82174c6SPing-Ke Shih 
515a82174c6SPing-Ke Shih 		if (info->thermal_trim[i] != 0xff)
516a82174c6SPing-Ke Shih 			info->pg_thermal_trim = true;
517a82174c6SPing-Ke Shih 	}
518a82174c6SPing-Ke Shih }
519a82174c6SPing-Ke Shih 
rtw8852c_thermal_trim(struct rtw89_dev * rtwdev)520a82174c6SPing-Ke Shih static void rtw8852c_thermal_trim(struct rtw89_dev *rtwdev)
521a82174c6SPing-Ke Shih {
522a82174c6SPing-Ke Shih #define __thm_setting(raw)				\
523a82174c6SPing-Ke Shih ({							\
524a82174c6SPing-Ke Shih 	u8 __v = (raw);					\
525a82174c6SPing-Ke Shih 	((__v & 0x1) << 3) | ((__v & 0x1f) >> 1);	\
526a82174c6SPing-Ke Shih })
527a82174c6SPing-Ke Shih 	struct rtw89_power_trim_info *info = &rtwdev->pwr_trim;
528a82174c6SPing-Ke Shih 	u8 i, val;
529a82174c6SPing-Ke Shih 
530a82174c6SPing-Ke Shih 	if (!info->pg_thermal_trim) {
531a82174c6SPing-Ke Shih 		rtw89_debug(rtwdev, RTW89_DBG_RFK,
532a82174c6SPing-Ke Shih 			    "[THERMAL][TRIM] no PG, do nothing\n");
533a82174c6SPing-Ke Shih 
534a82174c6SPing-Ke Shih 		return;
535a82174c6SPing-Ke Shih 	}
536a82174c6SPing-Ke Shih 
537a82174c6SPing-Ke Shih 	for (i = 0; i < RF_PATH_NUM_8852C; i++) {
538a82174c6SPing-Ke Shih 		val = __thm_setting(info->thermal_trim[i]);
539a82174c6SPing-Ke Shih 		rtw89_write_rf(rtwdev, i, RR_TM2, RR_TM2_OFF, val);
540a82174c6SPing-Ke Shih 
541a82174c6SPing-Ke Shih 		rtw89_debug(rtwdev, RTW89_DBG_RFK,
542a82174c6SPing-Ke Shih 			    "[THERMAL][TRIM] path=%d thermal_setting=0x%x\n",
543a82174c6SPing-Ke Shih 			    i, val);
544a82174c6SPing-Ke Shih 	}
545a82174c6SPing-Ke Shih #undef __thm_setting
546a82174c6SPing-Ke Shih }
547a82174c6SPing-Ke Shih 
rtw8852c_phycap_parsing_pa_bias_trim(struct rtw89_dev * rtwdev,u8 * phycap_map)548a82174c6SPing-Ke Shih static void rtw8852c_phycap_parsing_pa_bias_trim(struct rtw89_dev *rtwdev,
549a82174c6SPing-Ke Shih 						 u8 *phycap_map)
550a82174c6SPing-Ke Shih {
551a82174c6SPing-Ke Shih 	struct rtw89_power_trim_info *info = &rtwdev->pwr_trim;
552a82174c6SPing-Ke Shih 	static const u32 pabias_trim_addr[RF_PATH_NUM_8852C] = {0x5DE, 0x5DB};
553a82174c6SPing-Ke Shih 	u32 addr = rtwdev->chip->phycap_addr;
554a82174c6SPing-Ke Shih 	u8 i;
555a82174c6SPing-Ke Shih 
556a82174c6SPing-Ke Shih 	for (i = 0; i < RF_PATH_NUM_8852C; i++) {
557a82174c6SPing-Ke Shih 		info->pa_bias_trim[i] = phycap_map[pabias_trim_addr[i] - addr];
558a82174c6SPing-Ke Shih 
559a82174c6SPing-Ke Shih 		rtw89_debug(rtwdev, RTW89_DBG_RFK,
560a82174c6SPing-Ke Shih 			    "[PA_BIAS][TRIM] path=%d pa_bias_trim=0x%x\n",
561a82174c6SPing-Ke Shih 			    i, info->pa_bias_trim[i]);
562a82174c6SPing-Ke Shih 
563a82174c6SPing-Ke Shih 		if (info->pa_bias_trim[i] != 0xff)
564a82174c6SPing-Ke Shih 			info->pg_pa_bias_trim = true;
565a82174c6SPing-Ke Shih 	}
566a82174c6SPing-Ke Shih }
567a82174c6SPing-Ke Shih 
rtw8852c_pa_bias_trim(struct rtw89_dev * rtwdev)568a82174c6SPing-Ke Shih static void rtw8852c_pa_bias_trim(struct rtw89_dev *rtwdev)
569a82174c6SPing-Ke Shih {
570a82174c6SPing-Ke Shih 	struct rtw89_power_trim_info *info = &rtwdev->pwr_trim;
571a82174c6SPing-Ke Shih 	u8 pabias_2g, pabias_5g;
572a82174c6SPing-Ke Shih 	u8 i;
573a82174c6SPing-Ke Shih 
574a82174c6SPing-Ke Shih 	if (!info->pg_pa_bias_trim) {
575a82174c6SPing-Ke Shih 		rtw89_debug(rtwdev, RTW89_DBG_RFK,
576a82174c6SPing-Ke Shih 			    "[PA_BIAS][TRIM] no PG, do nothing\n");
577a82174c6SPing-Ke Shih 
578a82174c6SPing-Ke Shih 		return;
579a82174c6SPing-Ke Shih 	}
580a82174c6SPing-Ke Shih 
581a82174c6SPing-Ke Shih 	for (i = 0; i < RF_PATH_NUM_8852C; i++) {
582a82174c6SPing-Ke Shih 		pabias_2g = FIELD_GET(GENMASK(3, 0), info->pa_bias_trim[i]);
583a82174c6SPing-Ke Shih 		pabias_5g = FIELD_GET(GENMASK(7, 4), info->pa_bias_trim[i]);
584a82174c6SPing-Ke Shih 
585a82174c6SPing-Ke Shih 		rtw89_debug(rtwdev, RTW89_DBG_RFK,
586a82174c6SPing-Ke Shih 			    "[PA_BIAS][TRIM] path=%d 2G=0x%x 5G=0x%x\n",
587a82174c6SPing-Ke Shih 			    i, pabias_2g, pabias_5g);
588a82174c6SPing-Ke Shih 
589a82174c6SPing-Ke Shih 		rtw89_write_rf(rtwdev, i, RR_BIASA, RR_BIASA_TXG, pabias_2g);
590a82174c6SPing-Ke Shih 		rtw89_write_rf(rtwdev, i, RR_BIASA, RR_BIASA_TXA, pabias_5g);
591a82174c6SPing-Ke Shih 	}
592a82174c6SPing-Ke Shih }
593a82174c6SPing-Ke Shih 
rtw8852c_read_phycap(struct rtw89_dev * rtwdev,u8 * phycap_map)594a82174c6SPing-Ke Shih static int rtw8852c_read_phycap(struct rtw89_dev *rtwdev, u8 *phycap_map)
595a82174c6SPing-Ke Shih {
596a82174c6SPing-Ke Shih 	rtw8852c_phycap_parsing_tssi(rtwdev, phycap_map);
597a82174c6SPing-Ke Shih 	rtw8852c_phycap_parsing_thermal_trim(rtwdev, phycap_map);
598a82174c6SPing-Ke Shih 	rtw8852c_phycap_parsing_pa_bias_trim(rtwdev, phycap_map);
599a82174c6SPing-Ke Shih 
600a82174c6SPing-Ke Shih 	return 0;
601a82174c6SPing-Ke Shih }
602a82174c6SPing-Ke Shih 
rtw8852c_power_trim(struct rtw89_dev * rtwdev)603a82174c6SPing-Ke Shih static void rtw8852c_power_trim(struct rtw89_dev *rtwdev)
604a82174c6SPing-Ke Shih {
605a82174c6SPing-Ke Shih 	rtw8852c_thermal_trim(rtwdev);
606a82174c6SPing-Ke Shih 	rtw8852c_pa_bias_trim(rtwdev);
607a82174c6SPing-Ke Shih }
608a82174c6SPing-Ke Shih 
rtw8852c_set_channel_mac(struct rtw89_dev * rtwdev,const struct rtw89_chan * chan,u8 mac_idx)60963fb5c98SPing-Ke Shih static void rtw8852c_set_channel_mac(struct rtw89_dev *rtwdev,
6103e5831caSZong-Zhe Yang 				     const struct rtw89_chan *chan,
61163fb5c98SPing-Ke Shih 				     u8 mac_idx)
61263fb5c98SPing-Ke Shih {
613c220d08eSPing-Ke Shih 	u32 rf_mod = rtw89_mac_reg_by_idx(rtwdev, R_AX_WMAC_RFMOD, mac_idx);
614c220d08eSPing-Ke Shih 	u32 sub_carr = rtw89_mac_reg_by_idx(rtwdev, R_AX_TX_SUB_CARRIER_VALUE, mac_idx);
615c220d08eSPing-Ke Shih 	u32 chk_rate = rtw89_mac_reg_by_idx(rtwdev, R_AX_TXRATE_CHK, mac_idx);
61663fb5c98SPing-Ke Shih 	u8 txsc20 = 0, txsc40 = 0, txsc80 = 0;
61763fb5c98SPing-Ke Shih 	u8 rf_mod_val = 0, chk_rate_mask = 0;
61863fb5c98SPing-Ke Shih 	u32 txsc;
61963fb5c98SPing-Ke Shih 
6203e5831caSZong-Zhe Yang 	switch (chan->band_width) {
62163fb5c98SPing-Ke Shih 	case RTW89_CHANNEL_WIDTH_160:
6223e5831caSZong-Zhe Yang 		txsc80 = rtw89_phy_get_txsc(rtwdev, chan,
62363fb5c98SPing-Ke Shih 					    RTW89_CHANNEL_WIDTH_80);
62463fb5c98SPing-Ke Shih 		fallthrough;
62563fb5c98SPing-Ke Shih 	case RTW89_CHANNEL_WIDTH_80:
6263e5831caSZong-Zhe Yang 		txsc40 = rtw89_phy_get_txsc(rtwdev, chan,
62763fb5c98SPing-Ke Shih 					    RTW89_CHANNEL_WIDTH_40);
62863fb5c98SPing-Ke Shih 		fallthrough;
62963fb5c98SPing-Ke Shih 	case RTW89_CHANNEL_WIDTH_40:
6303e5831caSZong-Zhe Yang 		txsc20 = rtw89_phy_get_txsc(rtwdev, chan,
63163fb5c98SPing-Ke Shih 					    RTW89_CHANNEL_WIDTH_20);
63263fb5c98SPing-Ke Shih 		break;
63363fb5c98SPing-Ke Shih 	default:
63463fb5c98SPing-Ke Shih 		break;
63563fb5c98SPing-Ke Shih 	}
63663fb5c98SPing-Ke Shih 
6373e5831caSZong-Zhe Yang 	switch (chan->band_width) {
63863fb5c98SPing-Ke Shih 	case RTW89_CHANNEL_WIDTH_160:
63963fb5c98SPing-Ke Shih 		rf_mod_val = AX_WMAC_RFMOD_160M;
64063fb5c98SPing-Ke Shih 		txsc = FIELD_PREP(B_AX_TXSC_20M_MASK, txsc20) |
64163fb5c98SPing-Ke Shih 		       FIELD_PREP(B_AX_TXSC_40M_MASK, txsc40) |
64263fb5c98SPing-Ke Shih 		       FIELD_PREP(B_AX_TXSC_80M_MASK, txsc80);
64363fb5c98SPing-Ke Shih 		break;
64463fb5c98SPing-Ke Shih 	case RTW89_CHANNEL_WIDTH_80:
64563fb5c98SPing-Ke Shih 		rf_mod_val = AX_WMAC_RFMOD_80M;
64663fb5c98SPing-Ke Shih 		txsc = FIELD_PREP(B_AX_TXSC_20M_MASK, txsc20) |
64763fb5c98SPing-Ke Shih 		       FIELD_PREP(B_AX_TXSC_40M_MASK, txsc40);
64863fb5c98SPing-Ke Shih 		break;
64963fb5c98SPing-Ke Shih 	case RTW89_CHANNEL_WIDTH_40:
65063fb5c98SPing-Ke Shih 		rf_mod_val = AX_WMAC_RFMOD_40M;
65163fb5c98SPing-Ke Shih 		txsc = FIELD_PREP(B_AX_TXSC_20M_MASK, txsc20);
65263fb5c98SPing-Ke Shih 		break;
65363fb5c98SPing-Ke Shih 	case RTW89_CHANNEL_WIDTH_20:
65463fb5c98SPing-Ke Shih 	default:
65563fb5c98SPing-Ke Shih 		rf_mod_val = AX_WMAC_RFMOD_20M;
65663fb5c98SPing-Ke Shih 		txsc = 0;
65763fb5c98SPing-Ke Shih 		break;
65863fb5c98SPing-Ke Shih 	}
65963fb5c98SPing-Ke Shih 	rtw89_write8_mask(rtwdev, rf_mod, B_AX_WMAC_RFMOD_MASK, rf_mod_val);
66063fb5c98SPing-Ke Shih 	rtw89_write32(rtwdev, sub_carr, txsc);
66163fb5c98SPing-Ke Shih 
6623e5831caSZong-Zhe Yang 	switch (chan->band_type) {
66363fb5c98SPing-Ke Shih 	case RTW89_BAND_2G:
66463fb5c98SPing-Ke Shih 		chk_rate_mask = B_AX_BAND_MODE;
66563fb5c98SPing-Ke Shih 		break;
66663fb5c98SPing-Ke Shih 	case RTW89_BAND_5G:
66763fb5c98SPing-Ke Shih 	case RTW89_BAND_6G:
66863fb5c98SPing-Ke Shih 		chk_rate_mask = B_AX_CHECK_CCK_EN | B_AX_RTS_LIMIT_IN_OFDM6;
66963fb5c98SPing-Ke Shih 		break;
67063fb5c98SPing-Ke Shih 	default:
6713e5831caSZong-Zhe Yang 		rtw89_warn(rtwdev, "Invalid band_type:%d\n", chan->band_type);
67263fb5c98SPing-Ke Shih 		return;
67363fb5c98SPing-Ke Shih 	}
67463fb5c98SPing-Ke Shih 	rtw89_write8_clr(rtwdev, chk_rate, B_AX_BAND_MODE | B_AX_CHECK_CCK_EN |
67563fb5c98SPing-Ke Shih 					   B_AX_RTS_LIMIT_IN_OFDM6);
67663fb5c98SPing-Ke Shih 	rtw89_write8_set(rtwdev, chk_rate, chk_rate_mask);
67763fb5c98SPing-Ke Shih }
67863fb5c98SPing-Ke Shih 
6791b00e923SPing-Ke Shih static const u32 rtw8852c_sco_barker_threshold[14] = {
6801b00e923SPing-Ke Shih 	0x1fe4f, 0x1ff5e, 0x2006c, 0x2017b, 0x2028a, 0x20399, 0x204a8, 0x205b6,
6811b00e923SPing-Ke Shih 	0x206c5, 0x207d4, 0x208e3, 0x209f2, 0x20b00, 0x20d8a
6821b00e923SPing-Ke Shih };
6831b00e923SPing-Ke Shih 
6841b00e923SPing-Ke Shih static const u32 rtw8852c_sco_cck_threshold[14] = {
6851b00e923SPing-Ke Shih 	0x2bdac, 0x2bf21, 0x2c095, 0x2c209, 0x2c37e, 0x2c4f2, 0x2c666, 0x2c7db,
6861b00e923SPing-Ke Shih 	0x2c94f, 0x2cac3, 0x2cc38, 0x2cdac, 0x2cf21, 0x2d29e
6871b00e923SPing-Ke Shih };
6881b00e923SPing-Ke Shih 
rtw8852c_ctrl_sco_cck(struct rtw89_dev * rtwdev,u8 central_ch,u8 primary_ch,enum rtw89_bandwidth bw)6891b00e923SPing-Ke Shih static int rtw8852c_ctrl_sco_cck(struct rtw89_dev *rtwdev, u8 central_ch,
6901b00e923SPing-Ke Shih 				 u8 primary_ch, enum rtw89_bandwidth bw)
6911b00e923SPing-Ke Shih {
6921b00e923SPing-Ke Shih 	u8 ch_element;
6931b00e923SPing-Ke Shih 
6941b00e923SPing-Ke Shih 	if (bw == RTW89_CHANNEL_WIDTH_20) {
6951b00e923SPing-Ke Shih 		ch_element = central_ch - 1;
6961b00e923SPing-Ke Shih 	} else if (bw == RTW89_CHANNEL_WIDTH_40) {
6971b00e923SPing-Ke Shih 		if (primary_ch == 1)
6981b00e923SPing-Ke Shih 			ch_element = central_ch - 1 + 2;
6991b00e923SPing-Ke Shih 		else
7001b00e923SPing-Ke Shih 			ch_element = central_ch - 1 - 2;
7011b00e923SPing-Ke Shih 	} else {
7021b00e923SPing-Ke Shih 		rtw89_warn(rtwdev, "Invalid BW:%d for CCK\n", bw);
7031b00e923SPing-Ke Shih 		return -EINVAL;
7041b00e923SPing-Ke Shih 	}
7051b00e923SPing-Ke Shih 	rtw89_phy_write32_mask(rtwdev, R_BK_FC0_INV_V1, B_BK_FC0_INV_MSK_V1,
7061b00e923SPing-Ke Shih 			       rtw8852c_sco_barker_threshold[ch_element]);
7071b00e923SPing-Ke Shih 	rtw89_phy_write32_mask(rtwdev, R_CCK_FC0_INV_V1, B_CCK_FC0_INV_MSK_V1,
7081b00e923SPing-Ke Shih 			       rtw8852c_sco_cck_threshold[ch_element]);
7091b00e923SPing-Ke Shih 
7101b00e923SPing-Ke Shih 	return 0;
7111b00e923SPing-Ke Shih }
7121b00e923SPing-Ke Shih 
713e885871eSZong-Zhe Yang struct rtw8852c_bb_gain {
714e885871eSZong-Zhe Yang 	u32 gain_g[BB_PATH_NUM_8852C];
715e885871eSZong-Zhe Yang 	u32 gain_a[BB_PATH_NUM_8852C];
716e885871eSZong-Zhe Yang 	u32 gain_mask;
717e885871eSZong-Zhe Yang };
718e885871eSZong-Zhe Yang 
719e885871eSZong-Zhe Yang static const struct rtw8852c_bb_gain bb_gain_lna[LNA_GAIN_NUM] = {
720e885871eSZong-Zhe Yang 	{ .gain_g = {0x4678, 0x475C}, .gain_a = {0x45DC, 0x4740},
721e885871eSZong-Zhe Yang 	  .gain_mask = 0x00ff0000 },
722e885871eSZong-Zhe Yang 	{ .gain_g = {0x4678, 0x475C}, .gain_a = {0x45DC, 0x4740},
723e885871eSZong-Zhe Yang 	  .gain_mask = 0xff000000 },
724e885871eSZong-Zhe Yang 	{ .gain_g = {0x467C, 0x4760}, .gain_a = {0x4660, 0x4744},
725e885871eSZong-Zhe Yang 	  .gain_mask = 0x000000ff },
726e885871eSZong-Zhe Yang 	{ .gain_g = {0x467C, 0x4760}, .gain_a = {0x4660, 0x4744},
727e885871eSZong-Zhe Yang 	  .gain_mask = 0x0000ff00 },
728e885871eSZong-Zhe Yang 	{ .gain_g = {0x467C, 0x4760}, .gain_a = {0x4660, 0x4744},
729e885871eSZong-Zhe Yang 	  .gain_mask = 0x00ff0000 },
730e885871eSZong-Zhe Yang 	{ .gain_g = {0x467C, 0x4760}, .gain_a = {0x4660, 0x4744},
731e885871eSZong-Zhe Yang 	  .gain_mask = 0xff000000 },
732e885871eSZong-Zhe Yang 	{ .gain_g = {0x4680, 0x4764}, .gain_a = {0x4664, 0x4748},
733e885871eSZong-Zhe Yang 	  .gain_mask = 0x000000ff },
734e885871eSZong-Zhe Yang };
735e885871eSZong-Zhe Yang 
736e885871eSZong-Zhe Yang static const struct rtw8852c_bb_gain bb_gain_tia[TIA_GAIN_NUM] = {
737e885871eSZong-Zhe Yang 	{ .gain_g = {0x4680, 0x4764}, .gain_a = {0x4664, 0x4748},
738e885871eSZong-Zhe Yang 	  .gain_mask = 0x00ff0000 },
739e885871eSZong-Zhe Yang 	{ .gain_g = {0x4680, 0x4764}, .gain_a = {0x4664, 0x4748},
740e885871eSZong-Zhe Yang 	  .gain_mask = 0xff000000 },
741e885871eSZong-Zhe Yang };
742e885871eSZong-Zhe Yang 
743e885871eSZong-Zhe Yang struct rtw8852c_bb_gain_bypass {
744e885871eSZong-Zhe Yang 	u32 gain_g[BB_PATH_NUM_8852C];
745e885871eSZong-Zhe Yang 	u32 gain_a[BB_PATH_NUM_8852C];
746e885871eSZong-Zhe Yang 	u32 gain_mask_g;
747e885871eSZong-Zhe Yang 	u32 gain_mask_a;
748e885871eSZong-Zhe Yang };
749e885871eSZong-Zhe Yang 
750e885871eSZong-Zhe Yang static
751e885871eSZong-Zhe Yang const struct rtw8852c_bb_gain_bypass bb_gain_bypass_lna[LNA_GAIN_NUM] = {
752e885871eSZong-Zhe Yang 	{ .gain_g = {0x4BB8, 0x4C7C}, .gain_a = {0x4BB4, 0x4C78},
753e885871eSZong-Zhe Yang 	  .gain_mask_g = 0xff000000, .gain_mask_a = 0xff},
754e885871eSZong-Zhe Yang 	{ .gain_g = {0x4BBC, 0x4C80}, .gain_a = {0x4BB4, 0x4C78},
755e885871eSZong-Zhe Yang 	  .gain_mask_g = 0xff, .gain_mask_a = 0xff00},
756e885871eSZong-Zhe Yang 	{ .gain_g = {0x4BBC, 0x4C80}, .gain_a = {0x4BB4, 0x4C78},
757e885871eSZong-Zhe Yang 	  .gain_mask_g = 0xff00, .gain_mask_a = 0xff0000},
758e885871eSZong-Zhe Yang 	{ .gain_g = {0x4BBC, 0x4C80}, .gain_a = {0x4BB4, 0x4C78},
759e885871eSZong-Zhe Yang 	  .gain_mask_g = 0xff0000, .gain_mask_a = 0xff000000},
760e885871eSZong-Zhe Yang 	{ .gain_g = {0x4BBC, 0x4C80}, .gain_a = {0x4BB8, 0x4C7C},
761e885871eSZong-Zhe Yang 	  .gain_mask_g = 0xff000000, .gain_mask_a = 0xff},
762e885871eSZong-Zhe Yang 	{ .gain_g = {0x4BC0, 0x4C84}, .gain_a = {0x4BB8, 0x4C7C},
763e885871eSZong-Zhe Yang 	  .gain_mask_g = 0xff, .gain_mask_a = 0xff00},
764e885871eSZong-Zhe Yang 	{ .gain_g = {0x4BC0, 0x4C84}, .gain_a = {0x4BB8, 0x4C7C},
765e885871eSZong-Zhe Yang 	  .gain_mask_g = 0xff00, .gain_mask_a = 0xff0000},
766e885871eSZong-Zhe Yang };
767e885871eSZong-Zhe Yang 
768e885871eSZong-Zhe Yang struct rtw8852c_bb_gain_op1db {
769e885871eSZong-Zhe Yang 	struct {
770e885871eSZong-Zhe Yang 		u32 lna[BB_PATH_NUM_8852C];
771e885871eSZong-Zhe Yang 		u32 tia_lna[BB_PATH_NUM_8852C];
772e885871eSZong-Zhe Yang 		u32 mask;
773e885871eSZong-Zhe Yang 	} reg[LNA_GAIN_NUM];
774e885871eSZong-Zhe Yang 	u32 reg_tia0_lna6[BB_PATH_NUM_8852C];
775e885871eSZong-Zhe Yang 	u32 mask_tia0_lna6;
776e885871eSZong-Zhe Yang };
777e885871eSZong-Zhe Yang 
778e885871eSZong-Zhe Yang static const struct rtw8852c_bb_gain_op1db bb_gain_op1db_a = {
779e885871eSZong-Zhe Yang 	.reg = {
780e885871eSZong-Zhe Yang 		{ .lna = {0x4668, 0x474c}, .tia_lna = {0x4670, 0x4754},
781e885871eSZong-Zhe Yang 		  .mask = 0xff},
782e885871eSZong-Zhe Yang 		{ .lna = {0x4668, 0x474c}, .tia_lna = {0x4670, 0x4754},
783e885871eSZong-Zhe Yang 		  .mask = 0xff00},
784e885871eSZong-Zhe Yang 		{ .lna = {0x4668, 0x474c}, .tia_lna = {0x4670, 0x4754},
785e885871eSZong-Zhe Yang 		  .mask = 0xff0000},
786e885871eSZong-Zhe Yang 		{ .lna = {0x4668, 0x474c}, .tia_lna = {0x4670, 0x4754},
787e885871eSZong-Zhe Yang 		  .mask = 0xff000000},
788e885871eSZong-Zhe Yang 		{ .lna = {0x466c, 0x4750}, .tia_lna = {0x4674, 0x4758},
789e885871eSZong-Zhe Yang 		  .mask = 0xff},
790e885871eSZong-Zhe Yang 		{ .lna = {0x466c, 0x4750}, .tia_lna = {0x4674, 0x4758},
791e885871eSZong-Zhe Yang 		  .mask = 0xff00},
792e885871eSZong-Zhe Yang 		{ .lna = {0x466c, 0x4750}, .tia_lna = {0x4674, 0x4758},
793e885871eSZong-Zhe Yang 		  .mask = 0xff0000},
794e885871eSZong-Zhe Yang 	},
795e885871eSZong-Zhe Yang 	.reg_tia0_lna6 = {0x4674, 0x4758},
796e885871eSZong-Zhe Yang 	.mask_tia0_lna6 = 0xff000000,
797e885871eSZong-Zhe Yang };
798e885871eSZong-Zhe Yang 
rtw8852c_set_gain_error(struct rtw89_dev * rtwdev,enum rtw89_subband subband,enum rtw89_rf_path path)799e885871eSZong-Zhe Yang static void rtw8852c_set_gain_error(struct rtw89_dev *rtwdev,
800e885871eSZong-Zhe Yang 				    enum rtw89_subband subband,
801e885871eSZong-Zhe Yang 				    enum rtw89_rf_path path)
802e885871eSZong-Zhe Yang {
803e885871eSZong-Zhe Yang 	const struct rtw89_phy_bb_gain_info *gain = &rtwdev->bb_gain;
8046e5125bcSPing-Ke Shih 	u8 gain_band = rtw89_subband_to_bb_gain_band(subband);
805e885871eSZong-Zhe Yang 	s32 val;
806e885871eSZong-Zhe Yang 	u32 reg;
807e885871eSZong-Zhe Yang 	u32 mask;
808e885871eSZong-Zhe Yang 	int i;
809e885871eSZong-Zhe Yang 
810e885871eSZong-Zhe Yang 	for (i = 0; i < LNA_GAIN_NUM; i++) {
811e885871eSZong-Zhe Yang 		if (subband == RTW89_CH_2G)
812e885871eSZong-Zhe Yang 			reg = bb_gain_lna[i].gain_g[path];
813e885871eSZong-Zhe Yang 		else
814e885871eSZong-Zhe Yang 			reg = bb_gain_lna[i].gain_a[path];
815e885871eSZong-Zhe Yang 
816e885871eSZong-Zhe Yang 		mask = bb_gain_lna[i].gain_mask;
817e885871eSZong-Zhe Yang 		val = gain->lna_gain[gain_band][path][i];
818e885871eSZong-Zhe Yang 		rtw89_phy_write32_mask(rtwdev, reg, mask, val);
819e885871eSZong-Zhe Yang 
820e885871eSZong-Zhe Yang 		if (subband == RTW89_CH_2G) {
821e885871eSZong-Zhe Yang 			reg = bb_gain_bypass_lna[i].gain_g[path];
822e885871eSZong-Zhe Yang 			mask = bb_gain_bypass_lna[i].gain_mask_g;
823e885871eSZong-Zhe Yang 		} else {
824e885871eSZong-Zhe Yang 			reg = bb_gain_bypass_lna[i].gain_a[path];
825e885871eSZong-Zhe Yang 			mask = bb_gain_bypass_lna[i].gain_mask_a;
826e885871eSZong-Zhe Yang 		}
827e885871eSZong-Zhe Yang 
828e885871eSZong-Zhe Yang 		val = gain->lna_gain_bypass[gain_band][path][i];
829e885871eSZong-Zhe Yang 		rtw89_phy_write32_mask(rtwdev, reg, mask, val);
830e885871eSZong-Zhe Yang 
831e885871eSZong-Zhe Yang 		if (subband != RTW89_CH_2G) {
832e885871eSZong-Zhe Yang 			reg = bb_gain_op1db_a.reg[i].lna[path];
833e885871eSZong-Zhe Yang 			mask = bb_gain_op1db_a.reg[i].mask;
834e885871eSZong-Zhe Yang 			val = gain->lna_op1db[gain_band][path][i];
835e885871eSZong-Zhe Yang 			rtw89_phy_write32_mask(rtwdev, reg, mask, val);
836e885871eSZong-Zhe Yang 
837e885871eSZong-Zhe Yang 			reg = bb_gain_op1db_a.reg[i].tia_lna[path];
838e885871eSZong-Zhe Yang 			mask = bb_gain_op1db_a.reg[i].mask;
839e885871eSZong-Zhe Yang 			val = gain->tia_lna_op1db[gain_band][path][i];
840e885871eSZong-Zhe Yang 			rtw89_phy_write32_mask(rtwdev, reg, mask, val);
841e885871eSZong-Zhe Yang 		}
842e885871eSZong-Zhe Yang 	}
843e885871eSZong-Zhe Yang 
844e885871eSZong-Zhe Yang 	if (subband != RTW89_CH_2G) {
845e885871eSZong-Zhe Yang 		reg = bb_gain_op1db_a.reg_tia0_lna6[path];
846e885871eSZong-Zhe Yang 		mask = bb_gain_op1db_a.mask_tia0_lna6;
847e885871eSZong-Zhe Yang 		val = gain->tia_lna_op1db[gain_band][path][7];
848e885871eSZong-Zhe Yang 		rtw89_phy_write32_mask(rtwdev, reg, mask, val);
849e885871eSZong-Zhe Yang 	}
850e885871eSZong-Zhe Yang 
851e885871eSZong-Zhe Yang 	for (i = 0; i < TIA_GAIN_NUM; i++) {
852e885871eSZong-Zhe Yang 		if (subband == RTW89_CH_2G)
853e885871eSZong-Zhe Yang 			reg = bb_gain_tia[i].gain_g[path];
854e885871eSZong-Zhe Yang 		else
855e885871eSZong-Zhe Yang 			reg = bb_gain_tia[i].gain_a[path];
856e885871eSZong-Zhe Yang 
857e885871eSZong-Zhe Yang 		mask = bb_gain_tia[i].gain_mask;
858e885871eSZong-Zhe Yang 		val = gain->tia_gain[gain_band][path][i];
859e885871eSZong-Zhe Yang 		rtw89_phy_write32_mask(rtwdev, reg, mask, val);
860e885871eSZong-Zhe Yang 	}
861e885871eSZong-Zhe Yang }
862e885871eSZong-Zhe Yang 
rtw8852c_set_gain_offset(struct rtw89_dev * rtwdev,const struct rtw89_chan * chan,enum rtw89_phy_idx phy_idx,enum rtw89_rf_path path)863e6b17cbdSPing-Ke Shih static void rtw8852c_set_gain_offset(struct rtw89_dev *rtwdev,
8643e5831caSZong-Zhe Yang 				     const struct rtw89_chan *chan,
865e6b17cbdSPing-Ke Shih 				     enum rtw89_phy_idx phy_idx,
866e6b17cbdSPing-Ke Shih 				     enum rtw89_rf_path path)
867e6b17cbdSPing-Ke Shih {
868e6b17cbdSPing-Ke Shih 	static const u32 rssi_ofst_addr[2] = {R_PATH0_G_TIA0_LNA6_OP1DB_V1,
869e6b17cbdSPing-Ke Shih 					      R_PATH1_G_TIA0_LNA6_OP1DB_V1};
870e6b17cbdSPing-Ke Shih 	static const u32 rpl_mask[2] = {B_RPL_PATHA_MASK, B_RPL_PATHB_MASK};
871e6b17cbdSPing-Ke Shih 	static const u32 rpl_tb_mask[2] = {B_RSSI_M_PATHA_MASK, B_RSSI_M_PATHB_MASK};
872e6b17cbdSPing-Ke Shih 	struct rtw89_phy_efuse_gain *efuse_gain = &rtwdev->efuse_gain;
873e6b17cbdSPing-Ke Shih 	enum rtw89_gain_offset gain_band;
874e6b17cbdSPing-Ke Shih 	s32 offset_q0, offset_base_q4;
875e6b17cbdSPing-Ke Shih 	s32 tmp = 0;
876e6b17cbdSPing-Ke Shih 
877e6b17cbdSPing-Ke Shih 	if (!efuse_gain->offset_valid)
878e6b17cbdSPing-Ke Shih 		return;
879e6b17cbdSPing-Ke Shih 
880e6b17cbdSPing-Ke Shih 	if (rtwdev->dbcc_en && path == RF_PATH_B)
881e6b17cbdSPing-Ke Shih 		phy_idx = RTW89_PHY_1;
882e6b17cbdSPing-Ke Shih 
8833e5831caSZong-Zhe Yang 	if (chan->band_type == RTW89_BAND_2G) {
884e6b17cbdSPing-Ke Shih 		offset_q0 = efuse_gain->offset[path][RTW89_GAIN_OFFSET_2G_CCK];
885e6b17cbdSPing-Ke Shih 		offset_base_q4 = efuse_gain->offset_base[phy_idx];
886e6b17cbdSPing-Ke Shih 
887e6b17cbdSPing-Ke Shih 		tmp = clamp_t(s32, (-offset_q0 << 3) + (offset_base_q4 >> 1),
888e6b17cbdSPing-Ke Shih 			      S8_MIN >> 1, S8_MAX >> 1);
889e6b17cbdSPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_RPL_OFST, B_RPL_OFST_MASK, tmp & 0x7f);
890e6b17cbdSPing-Ke Shih 	}
891e6b17cbdSPing-Ke Shih 
8926e5125bcSPing-Ke Shih 	gain_band = rtw89_subband_to_gain_offset_band_of_ofdm(chan->subband_type);
893e6b17cbdSPing-Ke Shih 
894e6b17cbdSPing-Ke Shih 	offset_q0 = -efuse_gain->offset[path][gain_band];
895e6b17cbdSPing-Ke Shih 	offset_base_q4 = efuse_gain->offset_base[phy_idx];
896e6b17cbdSPing-Ke Shih 
897e6b17cbdSPing-Ke Shih 	tmp = (offset_q0 << 2) + (offset_base_q4 >> 2);
898e6b17cbdSPing-Ke Shih 	tmp = clamp_t(s32, -tmp, S8_MIN, S8_MAX);
899e6b17cbdSPing-Ke Shih 	rtw89_phy_write32_mask(rtwdev, rssi_ofst_addr[path], B_PATH0_R_G_OFST_MASK, tmp & 0xff);
900e6b17cbdSPing-Ke Shih 
901e6b17cbdSPing-Ke Shih 	tmp = clamp_t(s32, offset_q0 << 4, S8_MIN, S8_MAX);
902e6b17cbdSPing-Ke Shih 	rtw89_phy_write32_idx(rtwdev, R_RPL_PATHAB, rpl_mask[path], tmp & 0xff, phy_idx);
903e6b17cbdSPing-Ke Shih 	rtw89_phy_write32_idx(rtwdev, R_RSSI_M_PATHAB, rpl_tb_mask[path], tmp & 0xff, phy_idx);
904e6b17cbdSPing-Ke Shih }
905e6b17cbdSPing-Ke Shih 
rtw8852c_ctrl_ch(struct rtw89_dev * rtwdev,const struct rtw89_chan * chan,enum rtw89_phy_idx phy_idx)9061b00e923SPing-Ke Shih static void rtw8852c_ctrl_ch(struct rtw89_dev *rtwdev,
9073e5831caSZong-Zhe Yang 			     const struct rtw89_chan *chan,
9081b00e923SPing-Ke Shih 			     enum rtw89_phy_idx phy_idx)
9091b00e923SPing-Ke Shih {
9101b00e923SPing-Ke Shih 	u8 sco;
9113e5831caSZong-Zhe Yang 	u16 central_freq = chan->freq;
9123e5831caSZong-Zhe Yang 	u8 central_ch = chan->channel;
9133e5831caSZong-Zhe Yang 	u8 band = chan->band_type;
9143e5831caSZong-Zhe Yang 	u8 subband = chan->subband_type;
9151b00e923SPing-Ke Shih 	bool is_2g = band == RTW89_BAND_2G;
9161b00e923SPing-Ke Shih 	u8 chan_idx;
9171b00e923SPing-Ke Shih 
9181b00e923SPing-Ke Shih 	if (!central_freq) {
9191b00e923SPing-Ke Shih 		rtw89_warn(rtwdev, "Invalid central_freq\n");
9201b00e923SPing-Ke Shih 		return;
9211b00e923SPing-Ke Shih 	}
9221b00e923SPing-Ke Shih 
9231b00e923SPing-Ke Shih 	if (phy_idx == RTW89_PHY_0) {
9241b00e923SPing-Ke Shih 		/* Path A */
9251b00e923SPing-Ke Shih 		rtw8852c_set_gain_error(rtwdev, subband, RF_PATH_A);
9263e5831caSZong-Zhe Yang 		rtw8852c_set_gain_offset(rtwdev, chan, phy_idx, RF_PATH_A);
9271b00e923SPing-Ke Shih 
9281b00e923SPing-Ke Shih 		if (is_2g)
9291b00e923SPing-Ke Shih 			rtw89_phy_write32_idx(rtwdev, R_PATH0_BAND_SEL_V1,
9301b00e923SPing-Ke Shih 					      B_PATH0_BAND_SEL_MSK_V1, 1,
9311b00e923SPing-Ke Shih 					      phy_idx);
9321b00e923SPing-Ke Shih 		else
9331b00e923SPing-Ke Shih 			rtw89_phy_write32_idx(rtwdev, R_PATH0_BAND_SEL_V1,
9341b00e923SPing-Ke Shih 					      B_PATH0_BAND_SEL_MSK_V1, 0,
9351b00e923SPing-Ke Shih 					      phy_idx);
9361b00e923SPing-Ke Shih 		/* Path B */
9371b00e923SPing-Ke Shih 		if (!rtwdev->dbcc_en) {
9381b00e923SPing-Ke Shih 			rtw8852c_set_gain_error(rtwdev, subband, RF_PATH_B);
9393e5831caSZong-Zhe Yang 			rtw8852c_set_gain_offset(rtwdev, chan, phy_idx, RF_PATH_B);
9401b00e923SPing-Ke Shih 
9411b00e923SPing-Ke Shih 			if (is_2g)
9421b00e923SPing-Ke Shih 				rtw89_phy_write32_idx(rtwdev,
9431b00e923SPing-Ke Shih 						      R_PATH1_BAND_SEL_V1,
9441b00e923SPing-Ke Shih 						      B_PATH1_BAND_SEL_MSK_V1,
9451b00e923SPing-Ke Shih 						      1, phy_idx);
9461b00e923SPing-Ke Shih 			else
9471b00e923SPing-Ke Shih 				rtw89_phy_write32_idx(rtwdev,
9481b00e923SPing-Ke Shih 						      R_PATH1_BAND_SEL_V1,
9491b00e923SPing-Ke Shih 						      B_PATH1_BAND_SEL_MSK_V1,
9501b00e923SPing-Ke Shih 						      0, phy_idx);
9511b00e923SPing-Ke Shih 			rtw89_phy_write32_clr(rtwdev, R_2P4G_BAND, B_2P4G_BAND_SEL);
9521b00e923SPing-Ke Shih 		} else {
9531b00e923SPing-Ke Shih 			if (is_2g)
9541b00e923SPing-Ke Shih 				rtw89_phy_write32_clr(rtwdev, R_2P4G_BAND, B_2P4G_BAND_SEL);
9551b00e923SPing-Ke Shih 			else
9561b00e923SPing-Ke Shih 				rtw89_phy_write32_set(rtwdev, R_2P4G_BAND, B_2P4G_BAND_SEL);
9571b00e923SPing-Ke Shih 		}
9581b00e923SPing-Ke Shih 		/* SCO compensate FC setting */
9591b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_FC0_V1, B_FC0_MSK_V1,
9601b00e923SPing-Ke Shih 				      central_freq, phy_idx);
9611b00e923SPing-Ke Shih 		/* round_up((1/fc0)*pow(2,18)) */
9621b00e923SPing-Ke Shih 		sco = DIV_ROUND_CLOSEST(1 << 18, central_freq);
9631b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_FC0_BW, B_FC0_BW_INV, sco,
9641b00e923SPing-Ke Shih 				      phy_idx);
9651b00e923SPing-Ke Shih 	} else {
9661b00e923SPing-Ke Shih 		/* Path B */
9671b00e923SPing-Ke Shih 		rtw8852c_set_gain_error(rtwdev, subband, RF_PATH_B);
9683e5831caSZong-Zhe Yang 		rtw8852c_set_gain_offset(rtwdev, chan, phy_idx, RF_PATH_B);
9691b00e923SPing-Ke Shih 
9701b00e923SPing-Ke Shih 		if (is_2g)
9711b00e923SPing-Ke Shih 			rtw89_phy_write32_idx(rtwdev, R_PATH1_BAND_SEL_V1,
9721b00e923SPing-Ke Shih 					      B_PATH1_BAND_SEL_MSK_V1,
9731b00e923SPing-Ke Shih 					      1, phy_idx);
9741b00e923SPing-Ke Shih 		else
9751b00e923SPing-Ke Shih 			rtw89_phy_write32_idx(rtwdev, R_PATH1_BAND_SEL_V1,
9761b00e923SPing-Ke Shih 					      B_PATH1_BAND_SEL_MSK_V1,
9771b00e923SPing-Ke Shih 					      0, phy_idx);
9781b00e923SPing-Ke Shih 		/* SCO compensate FC setting */
9791b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_FC0_V1, B_FC0_MSK_V1,
9801b00e923SPing-Ke Shih 				      central_freq, phy_idx);
9811b00e923SPing-Ke Shih 		/* round_up((1/fc0)*pow(2,18)) */
9821b00e923SPing-Ke Shih 		sco = DIV_ROUND_CLOSEST(1 << 18, central_freq);
9831b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_FC0_BW, B_FC0_BW_INV, sco,
9841b00e923SPing-Ke Shih 				      phy_idx);
9851b00e923SPing-Ke Shih 	}
9861b00e923SPing-Ke Shih 	/* CCK parameters */
9871b00e923SPing-Ke Shih 	if (band == RTW89_BAND_2G) {
9881b00e923SPing-Ke Shih 		if (central_ch == 14) {
9891b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PCOEFF0_V1,
9901b00e923SPing-Ke Shih 					       B_PCOEFF01_MSK_V1, 0x3b13ff);
9911b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PCOEFF2_V1,
9921b00e923SPing-Ke Shih 					       B_PCOEFF23_MSK_V1, 0x1c42de);
9931b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PCOEFF4_V1,
9941b00e923SPing-Ke Shih 					       B_PCOEFF45_MSK_V1, 0xfdb0ad);
9951b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PCOEFF6_V1,
9961b00e923SPing-Ke Shih 					       B_PCOEFF67_MSK_V1, 0xf60f6e);
9971b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PCOEFF8_V1,
9981b00e923SPing-Ke Shih 					       B_PCOEFF89_MSK_V1, 0xfd8f92);
9991b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PCOEFFA_V1,
10001b00e923SPing-Ke Shih 					       B_PCOEFFAB_MSK_V1, 0x2d011);
10011b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PCOEFFC_V1,
10021b00e923SPing-Ke Shih 					       B_PCOEFFCD_MSK_V1, 0x1c02c);
10031b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PCOEFFE_V1,
10041b00e923SPing-Ke Shih 					       B_PCOEFFEF_MSK_V1, 0xfff00a);
10051b00e923SPing-Ke Shih 		} else {
10061b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PCOEFF0_V1,
10071b00e923SPing-Ke Shih 					       B_PCOEFF01_MSK_V1, 0x3d23ff);
10081b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PCOEFF2_V1,
10091b00e923SPing-Ke Shih 					       B_PCOEFF23_MSK_V1, 0x29b354);
10101b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PCOEFF4_V1,
10111b00e923SPing-Ke Shih 					       B_PCOEFF45_MSK_V1, 0xfc1c8);
10121b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PCOEFF6_V1,
10131b00e923SPing-Ke Shih 					       B_PCOEFF67_MSK_V1, 0xfdb053);
10141b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PCOEFF8_V1,
10151b00e923SPing-Ke Shih 					       B_PCOEFF89_MSK_V1, 0xf86f9a);
10161b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PCOEFFA_V1,
10171b00e923SPing-Ke Shih 					       B_PCOEFFAB_MSK_V1, 0xfaef92);
10181b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PCOEFFC_V1,
10191b00e923SPing-Ke Shih 					       B_PCOEFFCD_MSK_V1, 0xfe5fcc);
10201b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PCOEFFE_V1,
10211b00e923SPing-Ke Shih 					       B_PCOEFFEF_MSK_V1, 0xffdff5);
10221b00e923SPing-Ke Shih 		}
10231b00e923SPing-Ke Shih 	}
10241b00e923SPing-Ke Shih 
1025bb9040b3SPo-Hao Huang 	chan_idx = rtw89_encode_chan_idx(rtwdev, chan->primary_channel, band);
10261b00e923SPing-Ke Shih 	rtw89_phy_write32_idx(rtwdev, R_MAC_PIN_SEL, B_CH_IDX_SEG0, chan_idx, phy_idx);
10271b00e923SPing-Ke Shih }
10281b00e923SPing-Ke Shih 
rtw8852c_bw_setting(struct rtw89_dev * rtwdev,u8 bw,u8 path)10291b00e923SPing-Ke Shih static void rtw8852c_bw_setting(struct rtw89_dev *rtwdev, u8 bw, u8 path)
10301b00e923SPing-Ke Shih {
10311b00e923SPing-Ke Shih 	static const u32 adc_sel[2] = {0xC0EC, 0xC1EC};
10321b00e923SPing-Ke Shih 	static const u32 wbadc_sel[2] = {0xC0E4, 0xC1E4};
10331b00e923SPing-Ke Shih 
10341b00e923SPing-Ke Shih 	switch (bw) {
10351b00e923SPing-Ke Shih 	case RTW89_CHANNEL_WIDTH_5:
10361b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, adc_sel[path], 0x6000, 0x1);
10371b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, wbadc_sel[path], 0x30, 0x0);
10381b00e923SPing-Ke Shih 		break;
10391b00e923SPing-Ke Shih 	case RTW89_CHANNEL_WIDTH_10:
10401b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, adc_sel[path], 0x6000, 0x2);
10411b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, wbadc_sel[path], 0x30, 0x1);
10421b00e923SPing-Ke Shih 		break;
10431b00e923SPing-Ke Shih 	case RTW89_CHANNEL_WIDTH_20:
10441b00e923SPing-Ke Shih 	case RTW89_CHANNEL_WIDTH_40:
10451b00e923SPing-Ke Shih 	case RTW89_CHANNEL_WIDTH_80:
10461b00e923SPing-Ke Shih 	case RTW89_CHANNEL_WIDTH_160:
10471b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, adc_sel[path], 0x6000, 0x0);
10481b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, wbadc_sel[path], 0x30, 0x2);
10491b00e923SPing-Ke Shih 		break;
10501b00e923SPing-Ke Shih 	default:
10511b00e923SPing-Ke Shih 		rtw89_warn(rtwdev, "Fail to set ADC\n");
10521b00e923SPing-Ke Shih 	}
10531b00e923SPing-Ke Shih }
10541b00e923SPing-Ke Shih 
rtw8852c_edcca_per20_bitmap_sifs(struct rtw89_dev * rtwdev,u8 bw,enum rtw89_phy_idx phy_idx)10551b00e923SPing-Ke Shih static void rtw8852c_edcca_per20_bitmap_sifs(struct rtw89_dev *rtwdev, u8 bw,
10561b00e923SPing-Ke Shih 					     enum rtw89_phy_idx phy_idx)
10571b00e923SPing-Ke Shih {
10581b00e923SPing-Ke Shih 	if (bw == RTW89_CHANNEL_WIDTH_20) {
10591b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_SNDCCA_A1, B_SNDCCA_A1_EN, 0xff, phy_idx);
10601b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_SNDCCA_A2, B_SNDCCA_A2_VAL, 0, phy_idx);
10611b00e923SPing-Ke Shih 	} else {
10621b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_SNDCCA_A1, B_SNDCCA_A1_EN, 0, phy_idx);
10631b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_SNDCCA_A2, B_SNDCCA_A2_VAL, 0, phy_idx);
10641b00e923SPing-Ke Shih 	}
10651b00e923SPing-Ke Shih }
10661b00e923SPing-Ke Shih 
10671b00e923SPing-Ke Shih static void
rtw8852c_ctrl_bw(struct rtw89_dev * rtwdev,u8 pri_ch,u8 bw,enum rtw89_phy_idx phy_idx)10681b00e923SPing-Ke Shih rtw8852c_ctrl_bw(struct rtw89_dev *rtwdev, u8 pri_ch, u8 bw,
10691b00e923SPing-Ke Shih 		 enum rtw89_phy_idx phy_idx)
10701b00e923SPing-Ke Shih {
10711b00e923SPing-Ke Shih 	u8 mod_sbw = 0;
10721b00e923SPing-Ke Shih 
10731b00e923SPing-Ke Shih 	switch (bw) {
10741b00e923SPing-Ke Shih 	case RTW89_CHANNEL_WIDTH_5:
10751b00e923SPing-Ke Shih 	case RTW89_CHANNEL_WIDTH_10:
10761b00e923SPing-Ke Shih 	case RTW89_CHANNEL_WIDTH_20:
10771b00e923SPing-Ke Shih 		if (bw == RTW89_CHANNEL_WIDTH_5)
10781b00e923SPing-Ke Shih 			mod_sbw = 0x1;
10791b00e923SPing-Ke Shih 		else if (bw == RTW89_CHANNEL_WIDTH_10)
10801b00e923SPing-Ke Shih 			mod_sbw = 0x2;
10811b00e923SPing-Ke Shih 		else if (bw == RTW89_CHANNEL_WIDTH_20)
10821b00e923SPing-Ke Shih 			mod_sbw = 0x0;
10831b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_FC0_BW, B_FC0_BW_SET, 0x0,
10841b00e923SPing-Ke Shih 				      phy_idx);
10851b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD, B_CHBW_MOD_SBW,
10861b00e923SPing-Ke Shih 				      mod_sbw, phy_idx);
10871b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD, B_CHBW_MOD_PRICH, 0x0,
10881b00e923SPing-Ke Shih 				      phy_idx);
10891b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_SAMPL_DLY_T_V1,
10901b00e923SPing-Ke Shih 				       B_PATH0_SAMPL_DLY_T_MSK_V1, 0x3);
10911b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_SAMPL_DLY_T_V1,
10921b00e923SPing-Ke Shih 				       B_PATH1_SAMPL_DLY_T_MSK_V1, 0x3);
10931b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_BW_SEL_V1,
10941b00e923SPing-Ke Shih 				       B_PATH0_BW_SEL_MSK_V1, 0xf);
10951b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_BW_SEL_V1,
10961b00e923SPing-Ke Shih 				       B_PATH1_BW_SEL_MSK_V1, 0xf);
10971b00e923SPing-Ke Shih 		break;
10981b00e923SPing-Ke Shih 	case RTW89_CHANNEL_WIDTH_40:
10991b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_FC0_BW, B_FC0_BW_SET, 0x1,
11001b00e923SPing-Ke Shih 				      phy_idx);
11011b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD, B_CHBW_MOD_SBW, 0x0,
11021b00e923SPing-Ke Shih 				      phy_idx);
11031b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD, B_CHBW_MOD_PRICH,
11041b00e923SPing-Ke Shih 				      pri_ch,
11051b00e923SPing-Ke Shih 				      phy_idx);
11061b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_SAMPL_DLY_T_V1,
11071b00e923SPing-Ke Shih 				       B_PATH0_SAMPL_DLY_T_MSK_V1, 0x3);
11081b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_SAMPL_DLY_T_V1,
11091b00e923SPing-Ke Shih 				       B_PATH1_SAMPL_DLY_T_MSK_V1, 0x3);
11101b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_BW_SEL_V1,
11111b00e923SPing-Ke Shih 				       B_PATH0_BW_SEL_MSK_V1, 0xf);
11121b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_BW_SEL_V1,
11131b00e923SPing-Ke Shih 				       B_PATH1_BW_SEL_MSK_V1, 0xf);
11141b00e923SPing-Ke Shih 		break;
11151b00e923SPing-Ke Shih 	case RTW89_CHANNEL_WIDTH_80:
11161b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_FC0_BW, B_FC0_BW_SET, 0x2,
11171b00e923SPing-Ke Shih 				      phy_idx);
11181b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD, B_CHBW_MOD_SBW, 0x0,
11191b00e923SPing-Ke Shih 				      phy_idx);
11201b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD, B_CHBW_MOD_PRICH,
11211b00e923SPing-Ke Shih 				      pri_ch,
11221b00e923SPing-Ke Shih 				      phy_idx);
11231b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_SAMPL_DLY_T_V1,
11241b00e923SPing-Ke Shih 				       B_PATH0_SAMPL_DLY_T_MSK_V1, 0x2);
11251b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_SAMPL_DLY_T_V1,
11261b00e923SPing-Ke Shih 				       B_PATH1_SAMPL_DLY_T_MSK_V1, 0x2);
11271b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_BW_SEL_V1,
11281b00e923SPing-Ke Shih 				       B_PATH0_BW_SEL_MSK_V1, 0xd);
11291b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_BW_SEL_V1,
11301b00e923SPing-Ke Shih 				       B_PATH1_BW_SEL_MSK_V1, 0xd);
11311b00e923SPing-Ke Shih 		break;
11321b00e923SPing-Ke Shih 	case RTW89_CHANNEL_WIDTH_160:
11331b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_FC0_BW, B_FC0_BW_SET, 0x3,
11341b00e923SPing-Ke Shih 				      phy_idx);
11351b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD, B_CHBW_MOD_SBW, 0x0,
11361b00e923SPing-Ke Shih 				      phy_idx);
11371b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD, B_CHBW_MOD_PRICH,
11381b00e923SPing-Ke Shih 				      pri_ch,
11391b00e923SPing-Ke Shih 				      phy_idx);
11401b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_SAMPL_DLY_T_V1,
11411b00e923SPing-Ke Shih 				       B_PATH0_SAMPL_DLY_T_MSK_V1, 0x1);
11421b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_SAMPL_DLY_T_V1,
11431b00e923SPing-Ke Shih 				       B_PATH1_SAMPL_DLY_T_MSK_V1, 0x1);
11441b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_BW_SEL_V1,
11451b00e923SPing-Ke Shih 				       B_PATH0_BW_SEL_MSK_V1, 0xb);
11461b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_BW_SEL_V1,
11471b00e923SPing-Ke Shih 				       B_PATH1_BW_SEL_MSK_V1, 0xb);
11481b00e923SPing-Ke Shih 		break;
11491b00e923SPing-Ke Shih 	default:
11501b00e923SPing-Ke Shih 		rtw89_warn(rtwdev, "Fail to switch bw (bw:%d, pri ch:%d)\n", bw,
11511b00e923SPing-Ke Shih 			   pri_ch);
11521b00e923SPing-Ke Shih 	}
11531b00e923SPing-Ke Shih 
11541b00e923SPing-Ke Shih 	if (bw == RTW89_CHANNEL_WIDTH_40) {
11551b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_RX_BW40_2XFFT_EN_V1,
11561b00e923SPing-Ke Shih 				      B_RX_BW40_2XFFT_EN_MSK_V1, 0x1, phy_idx);
11571b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_T2F_GI_COMB, B_T2F_GI_COMB_EN, 1, phy_idx);
11581b00e923SPing-Ke Shih 	} else {
11591b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_RX_BW40_2XFFT_EN_V1,
11601b00e923SPing-Ke Shih 				      B_RX_BW40_2XFFT_EN_MSK_V1, 0x0, phy_idx);
11611b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_T2F_GI_COMB, B_T2F_GI_COMB_EN, 0, phy_idx);
11621b00e923SPing-Ke Shih 	}
11631b00e923SPing-Ke Shih 
11641b00e923SPing-Ke Shih 	if (phy_idx == RTW89_PHY_0) {
11651b00e923SPing-Ke Shih 		rtw8852c_bw_setting(rtwdev, bw, RF_PATH_A);
11661b00e923SPing-Ke Shih 		if (!rtwdev->dbcc_en)
11671b00e923SPing-Ke Shih 			rtw8852c_bw_setting(rtwdev, bw, RF_PATH_B);
11681b00e923SPing-Ke Shih 	} else {
11691b00e923SPing-Ke Shih 		rtw8852c_bw_setting(rtwdev, bw, RF_PATH_B);
11701b00e923SPing-Ke Shih 	}
11711b00e923SPing-Ke Shih 
11721b00e923SPing-Ke Shih 	rtw8852c_edcca_per20_bitmap_sifs(rtwdev, bw, phy_idx);
11731b00e923SPing-Ke Shih }
11741b00e923SPing-Ke Shih 
rtw8852c_spur_freq(struct rtw89_dev * rtwdev,const struct rtw89_chan * chan)11751b00e923SPing-Ke Shih static u32 rtw8852c_spur_freq(struct rtw89_dev *rtwdev,
11763e5831caSZong-Zhe Yang 			      const struct rtw89_chan *chan)
11771b00e923SPing-Ke Shih {
11783e5831caSZong-Zhe Yang 	u8 center_chan = chan->channel;
11793e5831caSZong-Zhe Yang 	u8 bw = chan->band_width;
11801b00e923SPing-Ke Shih 
11813e5831caSZong-Zhe Yang 	switch (chan->band_type) {
11821b00e923SPing-Ke Shih 	case RTW89_BAND_2G:
11831b00e923SPing-Ke Shih 		if (bw == RTW89_CHANNEL_WIDTH_20) {
11841b00e923SPing-Ke Shih 			if (center_chan >= 5 && center_chan <= 8)
11851b00e923SPing-Ke Shih 				return 2440;
11861b00e923SPing-Ke Shih 			if (center_chan == 13)
11871b00e923SPing-Ke Shih 				return 2480;
11881b00e923SPing-Ke Shih 		} else if (bw == RTW89_CHANNEL_WIDTH_40) {
11891b00e923SPing-Ke Shih 			if (center_chan >= 3 && center_chan <= 10)
11901b00e923SPing-Ke Shih 				return 2440;
11911b00e923SPing-Ke Shih 		}
11921b00e923SPing-Ke Shih 		break;
11931b00e923SPing-Ke Shih 	case RTW89_BAND_5G:
11941b00e923SPing-Ke Shih 		if (center_chan == 151 || center_chan == 153 ||
11951b00e923SPing-Ke Shih 		    center_chan == 155 || center_chan == 163)
11961b00e923SPing-Ke Shih 			return 5760;
11971b00e923SPing-Ke Shih 		break;
11981b00e923SPing-Ke Shih 	case RTW89_BAND_6G:
11991b00e923SPing-Ke Shih 		if (center_chan == 195 || center_chan == 197 ||
12001b00e923SPing-Ke Shih 		    center_chan == 199 || center_chan == 207)
12011b00e923SPing-Ke Shih 			return 6920;
12021b00e923SPing-Ke Shih 		break;
12031b00e923SPing-Ke Shih 	default:
12041b00e923SPing-Ke Shih 		break;
12051b00e923SPing-Ke Shih 	}
12061b00e923SPing-Ke Shih 
12071b00e923SPing-Ke Shih 	return 0;
12081b00e923SPing-Ke Shih }
12091b00e923SPing-Ke Shih 
12101b00e923SPing-Ke Shih #define CARRIER_SPACING_312_5 312500 /* 312.5 kHz */
12111b00e923SPing-Ke Shih #define CARRIER_SPACING_78_125 78125 /* 78.125 kHz */
12121b00e923SPing-Ke Shih #define MAX_TONE_NUM 2048
12131b00e923SPing-Ke Shih 
rtw8852c_set_csi_tone_idx(struct rtw89_dev * rtwdev,const struct rtw89_chan * chan,enum rtw89_phy_idx phy_idx)12141b00e923SPing-Ke Shih static void rtw8852c_set_csi_tone_idx(struct rtw89_dev *rtwdev,
12153e5831caSZong-Zhe Yang 				      const struct rtw89_chan *chan,
12161b00e923SPing-Ke Shih 				      enum rtw89_phy_idx phy_idx)
12171b00e923SPing-Ke Shih {
12181b00e923SPing-Ke Shih 	u32 spur_freq;
12191b00e923SPing-Ke Shih 	s32 freq_diff, csi_idx, csi_tone_idx;
12201b00e923SPing-Ke Shih 
12213e5831caSZong-Zhe Yang 	spur_freq = rtw8852c_spur_freq(rtwdev, chan);
12221b00e923SPing-Ke Shih 	if (spur_freq == 0) {
12231b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_SEG0CSI_EN, B_SEG0CSI_EN, 0, phy_idx);
12241b00e923SPing-Ke Shih 		return;
12251b00e923SPing-Ke Shih 	}
12261b00e923SPing-Ke Shih 
12273e5831caSZong-Zhe Yang 	freq_diff = (spur_freq - chan->freq) * 1000000;
12281b00e923SPing-Ke Shih 	csi_idx = s32_div_u32_round_closest(freq_diff, CARRIER_SPACING_78_125);
12291b00e923SPing-Ke Shih 	s32_div_u32_round_down(csi_idx, MAX_TONE_NUM, &csi_tone_idx);
12301b00e923SPing-Ke Shih 
12311b00e923SPing-Ke Shih 	rtw89_phy_write32_idx(rtwdev, R_SEG0CSI, B_SEG0CSI_IDX, csi_tone_idx, phy_idx);
12321b00e923SPing-Ke Shih 	rtw89_phy_write32_idx(rtwdev, R_SEG0CSI_EN, B_SEG0CSI_EN, 1, phy_idx);
12331b00e923SPing-Ke Shih }
12341b00e923SPing-Ke Shih 
12351b00e923SPing-Ke Shih static const struct rtw89_nbi_reg_def rtw8852c_nbi_reg_def[] = {
12361b00e923SPing-Ke Shih 	[RF_PATH_A] = {
12371b00e923SPing-Ke Shih 		.notch1_idx = {0x4C14, 0xFF},
12381b00e923SPing-Ke Shih 		.notch1_frac_idx = {0x4C14, 0xC00},
12391b00e923SPing-Ke Shih 		.notch1_en = {0x4C14, 0x1000},
12401b00e923SPing-Ke Shih 		.notch2_idx = {0x4C20, 0xFF},
12411b00e923SPing-Ke Shih 		.notch2_frac_idx = {0x4C20, 0xC00},
12421b00e923SPing-Ke Shih 		.notch2_en = {0x4C20, 0x1000},
12431b00e923SPing-Ke Shih 	},
12441b00e923SPing-Ke Shih 	[RF_PATH_B] = {
12451b00e923SPing-Ke Shih 		.notch1_idx = {0x4CD8, 0xFF},
12461b00e923SPing-Ke Shih 		.notch1_frac_idx = {0x4CD8, 0xC00},
12471b00e923SPing-Ke Shih 		.notch1_en = {0x4CD8, 0x1000},
12481b00e923SPing-Ke Shih 		.notch2_idx = {0x4CE4, 0xFF},
12491b00e923SPing-Ke Shih 		.notch2_frac_idx = {0x4CE4, 0xC00},
12501b00e923SPing-Ke Shih 		.notch2_en = {0x4CE4, 0x1000},
12511b00e923SPing-Ke Shih 	},
12521b00e923SPing-Ke Shih };
12531b00e923SPing-Ke Shih 
rtw8852c_set_nbi_tone_idx(struct rtw89_dev * rtwdev,const struct rtw89_chan * chan,enum rtw89_rf_path path)12541b00e923SPing-Ke Shih static void rtw8852c_set_nbi_tone_idx(struct rtw89_dev *rtwdev,
12553e5831caSZong-Zhe Yang 				      const struct rtw89_chan *chan,
12561b00e923SPing-Ke Shih 				      enum rtw89_rf_path path)
12571b00e923SPing-Ke Shih {
12581b00e923SPing-Ke Shih 	const struct rtw89_nbi_reg_def *nbi = &rtw8852c_nbi_reg_def[path];
12591b00e923SPing-Ke Shih 	u32 spur_freq, fc;
12601b00e923SPing-Ke Shih 	s32 freq_diff;
12611b00e923SPing-Ke Shih 	s32 nbi_idx, nbi_tone_idx;
12621b00e923SPing-Ke Shih 	s32 nbi_frac_idx, nbi_frac_tone_idx;
12631b00e923SPing-Ke Shih 	bool notch2_chk = false;
12641b00e923SPing-Ke Shih 
12653e5831caSZong-Zhe Yang 	spur_freq = rtw8852c_spur_freq(rtwdev, chan);
12661b00e923SPing-Ke Shih 	if (spur_freq == 0) {
12671b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, nbi->notch1_en.addr, nbi->notch1_en.mask, 0);
12681b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, nbi->notch1_en.addr, nbi->notch1_en.mask, 0);
12691b00e923SPing-Ke Shih 		return;
12701b00e923SPing-Ke Shih 	}
12711b00e923SPing-Ke Shih 
12723e5831caSZong-Zhe Yang 	fc = chan->freq;
12733e5831caSZong-Zhe Yang 	if (chan->band_width == RTW89_CHANNEL_WIDTH_160) {
12741b00e923SPing-Ke Shih 		fc = (spur_freq > fc) ? fc + 40 : fc - 40;
12753e5831caSZong-Zhe Yang 		if ((fc > spur_freq &&
12763e5831caSZong-Zhe Yang 		     chan->channel < chan->primary_channel) ||
12773e5831caSZong-Zhe Yang 		    (fc < spur_freq &&
12783e5831caSZong-Zhe Yang 		     chan->channel > chan->primary_channel))
12791b00e923SPing-Ke Shih 			notch2_chk = true;
12801b00e923SPing-Ke Shih 	}
12811b00e923SPing-Ke Shih 
12821b00e923SPing-Ke Shih 	freq_diff = (spur_freq - fc) * 1000000;
12831b00e923SPing-Ke Shih 	nbi_idx = s32_div_u32_round_down(freq_diff, CARRIER_SPACING_312_5, &nbi_frac_idx);
12841b00e923SPing-Ke Shih 
12853e5831caSZong-Zhe Yang 	if (chan->band_width == RTW89_CHANNEL_WIDTH_20) {
12861b00e923SPing-Ke Shih 		s32_div_u32_round_down(nbi_idx + 32, 64, &nbi_tone_idx);
12871b00e923SPing-Ke Shih 	} else {
12883e5831caSZong-Zhe Yang 		u16 tone_para = (chan->band_width == RTW89_CHANNEL_WIDTH_40) ?
12893e5831caSZong-Zhe Yang 				128 : 256;
12901b00e923SPing-Ke Shih 
12911b00e923SPing-Ke Shih 		s32_div_u32_round_down(nbi_idx, tone_para, &nbi_tone_idx);
12921b00e923SPing-Ke Shih 	}
12931b00e923SPing-Ke Shih 	nbi_frac_tone_idx = s32_div_u32_round_closest(nbi_frac_idx, CARRIER_SPACING_78_125);
12941b00e923SPing-Ke Shih 
12953e5831caSZong-Zhe Yang 	if (chan->band_width == RTW89_CHANNEL_WIDTH_160 && notch2_chk) {
12961b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, nbi->notch2_idx.addr,
12971b00e923SPing-Ke Shih 				       nbi->notch2_idx.mask, nbi_tone_idx);
12981b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, nbi->notch2_frac_idx.addr,
12991b00e923SPing-Ke Shih 				       nbi->notch2_frac_idx.mask, nbi_frac_tone_idx);
13001b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, nbi->notch2_en.addr, nbi->notch2_en.mask, 0);
13011b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, nbi->notch2_en.addr, nbi->notch2_en.mask, 1);
13021b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, nbi->notch1_en.addr, nbi->notch1_en.mask, 0);
13031b00e923SPing-Ke Shih 	} else {
13041b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, nbi->notch1_idx.addr,
13051b00e923SPing-Ke Shih 				       nbi->notch1_idx.mask, nbi_tone_idx);
13061b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, nbi->notch1_frac_idx.addr,
13071b00e923SPing-Ke Shih 				       nbi->notch1_frac_idx.mask, nbi_frac_tone_idx);
13081b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, nbi->notch1_en.addr, nbi->notch1_en.mask, 0);
13091b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, nbi->notch1_en.addr, nbi->notch1_en.mask, 1);
13101b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, nbi->notch2_en.addr, nbi->notch2_en.mask, 0);
13111b00e923SPing-Ke Shih 	}
13121b00e923SPing-Ke Shih }
13131b00e923SPing-Ke Shih 
rtw8852c_spur_notch(struct rtw89_dev * rtwdev,u32 val,enum rtw89_phy_idx phy_idx)13140cd75e4fSHsuan Hung static void rtw8852c_spur_notch(struct rtw89_dev *rtwdev, u32 val,
13150cd75e4fSHsuan Hung 				enum rtw89_phy_idx phy_idx)
13160cd75e4fSHsuan Hung {
13170cd75e4fSHsuan Hung 	u32 notch;
13180cd75e4fSHsuan Hung 	u32 notch2;
13190cd75e4fSHsuan Hung 
13200cd75e4fSHsuan Hung 	if (phy_idx == RTW89_PHY_0) {
13210cd75e4fSHsuan Hung 		notch = R_PATH0_NOTCH;
13220cd75e4fSHsuan Hung 		notch2 = R_PATH0_NOTCH2;
13230cd75e4fSHsuan Hung 	} else {
13240cd75e4fSHsuan Hung 		notch = R_PATH1_NOTCH;
13250cd75e4fSHsuan Hung 		notch2 = R_PATH1_NOTCH2;
13260cd75e4fSHsuan Hung 	}
13270cd75e4fSHsuan Hung 
13280cd75e4fSHsuan Hung 	rtw89_phy_write32_mask(rtwdev, notch,
13290cd75e4fSHsuan Hung 			       B_PATH0_NOTCH_VAL | B_PATH0_NOTCH_EN, val);
13300cd75e4fSHsuan Hung 	rtw89_phy_write32_set(rtwdev, notch, B_PATH0_NOTCH_EN);
13310cd75e4fSHsuan Hung 	rtw89_phy_write32_mask(rtwdev, notch2,
13320cd75e4fSHsuan Hung 			       B_PATH0_NOTCH2_VAL | B_PATH0_NOTCH2_EN, val);
13330cd75e4fSHsuan Hung 	rtw89_phy_write32_set(rtwdev, notch2, B_PATH0_NOTCH2_EN);
13340cd75e4fSHsuan Hung }
13350cd75e4fSHsuan Hung 
rtw8852c_spur_elimination(struct rtw89_dev * rtwdev,const struct rtw89_chan * chan,u8 pri_ch_idx,enum rtw89_phy_idx phy_idx)13361b00e923SPing-Ke Shih static void rtw8852c_spur_elimination(struct rtw89_dev *rtwdev,
13373e5831caSZong-Zhe Yang 				      const struct rtw89_chan *chan,
13380cd75e4fSHsuan Hung 				      u8 pri_ch_idx,
13391b00e923SPing-Ke Shih 				      enum rtw89_phy_idx phy_idx)
13401b00e923SPing-Ke Shih {
13413e5831caSZong-Zhe Yang 	rtw8852c_set_csi_tone_idx(rtwdev, chan, phy_idx);
13421b00e923SPing-Ke Shih 
13431b00e923SPing-Ke Shih 	if (phy_idx == RTW89_PHY_0) {
13443e5831caSZong-Zhe Yang 		if (chan->band_width == RTW89_CHANNEL_WIDTH_160 &&
13450cd75e4fSHsuan Hung 		    (pri_ch_idx == RTW89_SC_20_LOWER ||
13460cd75e4fSHsuan Hung 		     pri_ch_idx == RTW89_SC_20_UP3X)) {
13470cd75e4fSHsuan Hung 			rtw8852c_spur_notch(rtwdev, 0xe7f, RTW89_PHY_0);
13480cd75e4fSHsuan Hung 			if (!rtwdev->dbcc_en)
13490cd75e4fSHsuan Hung 				rtw8852c_spur_notch(rtwdev, 0xe7f, RTW89_PHY_1);
13503e5831caSZong-Zhe Yang 		} else if (chan->band_width == RTW89_CHANNEL_WIDTH_160 &&
13510cd75e4fSHsuan Hung 			   (pri_ch_idx == RTW89_SC_20_UPPER ||
13520cd75e4fSHsuan Hung 			    pri_ch_idx == RTW89_SC_20_LOW3X)) {
13530cd75e4fSHsuan Hung 			rtw8852c_spur_notch(rtwdev, 0x280, RTW89_PHY_0);
13540cd75e4fSHsuan Hung 			if (!rtwdev->dbcc_en)
13550cd75e4fSHsuan Hung 				rtw8852c_spur_notch(rtwdev, 0x280, RTW89_PHY_1);
13560cd75e4fSHsuan Hung 		} else {
13573e5831caSZong-Zhe Yang 			rtw8852c_set_nbi_tone_idx(rtwdev, chan, RF_PATH_A);
13581b00e923SPing-Ke Shih 			if (!rtwdev->dbcc_en)
13593e5831caSZong-Zhe Yang 				rtw8852c_set_nbi_tone_idx(rtwdev, chan,
13600cd75e4fSHsuan Hung 							  RF_PATH_B);
13610cd75e4fSHsuan Hung 		}
13620cd75e4fSHsuan Hung 	} else {
13633e5831caSZong-Zhe Yang 		if (chan->band_width == RTW89_CHANNEL_WIDTH_160 &&
13640cd75e4fSHsuan Hung 		    (pri_ch_idx == RTW89_SC_20_LOWER ||
13650cd75e4fSHsuan Hung 		     pri_ch_idx == RTW89_SC_20_UP3X)) {
13660cd75e4fSHsuan Hung 			rtw8852c_spur_notch(rtwdev, 0xe7f, RTW89_PHY_1);
13673e5831caSZong-Zhe Yang 		} else if (chan->band_width == RTW89_CHANNEL_WIDTH_160 &&
13680cd75e4fSHsuan Hung 			   (pri_ch_idx == RTW89_SC_20_UPPER ||
13690cd75e4fSHsuan Hung 			    pri_ch_idx == RTW89_SC_20_LOW3X)) {
13700cd75e4fSHsuan Hung 			rtw8852c_spur_notch(rtwdev, 0x280, RTW89_PHY_1);
13711b00e923SPing-Ke Shih 		} else {
13723e5831caSZong-Zhe Yang 			rtw8852c_set_nbi_tone_idx(rtwdev, chan, RF_PATH_B);
13731b00e923SPing-Ke Shih 		}
13741b00e923SPing-Ke Shih 	}
13751b00e923SPing-Ke Shih 
13760cd75e4fSHsuan Hung 	if (pri_ch_idx == RTW89_SC_20_UP3X || pri_ch_idx == RTW89_SC_20_LOW3X)
13770cd75e4fSHsuan Hung 		rtw89_phy_write32_idx(rtwdev, R_PD_BOOST_EN, B_PD_BOOST_EN, 0, phy_idx);
13780cd75e4fSHsuan Hung 	else
13790cd75e4fSHsuan Hung 		rtw89_phy_write32_idx(rtwdev, R_PD_BOOST_EN, B_PD_BOOST_EN, 1, phy_idx);
13800cd75e4fSHsuan Hung }
13810cd75e4fSHsuan Hung 
rtw8852c_5m_mask(struct rtw89_dev * rtwdev,const struct rtw89_chan * chan,enum rtw89_phy_idx phy_idx)13821b00e923SPing-Ke Shih static void rtw8852c_5m_mask(struct rtw89_dev *rtwdev,
13833e5831caSZong-Zhe Yang 			     const struct rtw89_chan *chan,
13841b00e923SPing-Ke Shih 			     enum rtw89_phy_idx phy_idx)
13851b00e923SPing-Ke Shih {
1386d33fc8d0SEric Huang 	u8 pri_ch = chan->pri_ch_idx;
13871b00e923SPing-Ke Shih 	bool mask_5m_low;
13881b00e923SPing-Ke Shih 	bool mask_5m_en;
13891b00e923SPing-Ke Shih 
13903e5831caSZong-Zhe Yang 	switch (chan->band_width) {
13911b00e923SPing-Ke Shih 	case RTW89_CHANNEL_WIDTH_40:
13921b00e923SPing-Ke Shih 		mask_5m_en = true;
1393d33fc8d0SEric Huang 		mask_5m_low = pri_ch == RTW89_SC_20_LOWER;
13941b00e923SPing-Ke Shih 		break;
13951b00e923SPing-Ke Shih 	case RTW89_CHANNEL_WIDTH_80:
1396d33fc8d0SEric Huang 		mask_5m_en = pri_ch == RTW89_SC_20_UPMOST ||
1397d33fc8d0SEric Huang 			     pri_ch == RTW89_SC_20_LOWEST;
1398d33fc8d0SEric Huang 		mask_5m_low = pri_ch == RTW89_SC_20_LOWEST;
13991b00e923SPing-Ke Shih 		break;
14001b00e923SPing-Ke Shih 	default:
14011b00e923SPing-Ke Shih 		mask_5m_en = false;
14021b00e923SPing-Ke Shih 		mask_5m_low = false;
14031b00e923SPing-Ke Shih 		break;
14041b00e923SPing-Ke Shih 	}
14051b00e923SPing-Ke Shih 
14061b00e923SPing-Ke Shih 	if (!mask_5m_en) {
14071b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET, B_PATH0_5MDET_EN, 0x0);
14081b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET, B_PATH1_5MDET_EN, 0x0);
14091b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_ASSIGN_SBD_OPT,
14101b00e923SPing-Ke Shih 				      B_ASSIGN_SBD_OPT_EN, 0x0, phy_idx);
14111b00e923SPing-Ke Shih 	} else {
14121b00e923SPing-Ke Shih 		if (mask_5m_low) {
14131b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET, B_PATH0_5MDET_TH, 0x4);
14141b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET, B_PATH0_5MDET_EN, 0x1);
14151b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET, B_PATH0_5MDET_SB2, 0x0);
14161b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET, B_PATH0_5MDET_SB0, 0x1);
14171b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET, B_PATH1_5MDET_TH, 0x4);
14181b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET, B_PATH1_5MDET_EN, 0x1);
14191b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET, B_PATH1_5MDET_SB2, 0x0);
14201b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET, B_PATH1_5MDET_SB0, 0x1);
14211b00e923SPing-Ke Shih 		} else {
14221b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET, B_PATH0_5MDET_TH, 0x4);
14231b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET, B_PATH0_5MDET_EN, 0x1);
14241b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET, B_PATH0_5MDET_SB2, 0x1);
14251b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET, B_PATH0_5MDET_SB0, 0x0);
14261b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET, B_PATH1_5MDET_TH, 0x4);
14271b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET, B_PATH1_5MDET_EN, 0x1);
14281b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET, B_PATH1_5MDET_SB2, 0x1);
14291b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET, B_PATH1_5MDET_SB0, 0x0);
14301b00e923SPing-Ke Shih 		}
14311b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_ASSIGN_SBD_OPT, B_ASSIGN_SBD_OPT_EN, 0x1, phy_idx);
14321b00e923SPing-Ke Shih 	}
14331b00e923SPing-Ke Shih }
14341b00e923SPing-Ke Shih 
rtw8852c_bb_reset_all(struct rtw89_dev * rtwdev,enum rtw89_phy_idx phy_idx)1435cc99eefaSPing-Ke Shih static void rtw8852c_bb_reset_all(struct rtw89_dev *rtwdev,
1436cc99eefaSPing-Ke Shih 				  enum rtw89_phy_idx phy_idx)
1437cc99eefaSPing-Ke Shih {
1438cc99eefaSPing-Ke Shih 	/*HW SI reset*/
1439cc99eefaSPing-Ke Shih 	rtw89_phy_write32_mask(rtwdev, R_S0_HW_SI_DIS, B_S0_HW_SI_DIS_W_R_TRIG,
1440cc99eefaSPing-Ke Shih 			       0x7);
1441cc99eefaSPing-Ke Shih 	rtw89_phy_write32_mask(rtwdev, R_S1_HW_SI_DIS, B_S1_HW_SI_DIS_W_R_TRIG,
1442cc99eefaSPing-Ke Shih 			       0x7);
1443cc99eefaSPing-Ke Shih 
1444cc99eefaSPing-Ke Shih 	udelay(1);
1445cc99eefaSPing-Ke Shih 
1446cc99eefaSPing-Ke Shih 	rtw89_phy_write32_idx(rtwdev, R_RSTB_ASYNC, B_RSTB_ASYNC_ALL, 1,
1447cc99eefaSPing-Ke Shih 			      phy_idx);
1448cc99eefaSPing-Ke Shih 	rtw89_phy_write32_idx(rtwdev, R_RSTB_ASYNC, B_RSTB_ASYNC_ALL, 0,
1449cc99eefaSPing-Ke Shih 			      phy_idx);
1450cc99eefaSPing-Ke Shih 	/*HW SI reset*/
1451cc99eefaSPing-Ke Shih 	rtw89_phy_write32_mask(rtwdev, R_S0_HW_SI_DIS, B_S0_HW_SI_DIS_W_R_TRIG,
1452cc99eefaSPing-Ke Shih 			       0x0);
1453cc99eefaSPing-Ke Shih 	rtw89_phy_write32_mask(rtwdev, R_S1_HW_SI_DIS, B_S1_HW_SI_DIS_W_R_TRIG,
1454cc99eefaSPing-Ke Shih 			       0x0);
1455cc99eefaSPing-Ke Shih 
1456cc99eefaSPing-Ke Shih 	rtw89_phy_write32_idx(rtwdev, R_RSTB_ASYNC, B_RSTB_ASYNC_ALL, 1,
1457cc99eefaSPing-Ke Shih 			      phy_idx);
1458cc99eefaSPing-Ke Shih }
1459cc99eefaSPing-Ke Shih 
rtw8852c_bb_reset_en(struct rtw89_dev * rtwdev,enum rtw89_band band,enum rtw89_phy_idx phy_idx,bool en)1460ce57e55cSZong-Zhe Yang static void rtw8852c_bb_reset_en(struct rtw89_dev *rtwdev, enum rtw89_band band,
1461cc99eefaSPing-Ke Shih 				 enum rtw89_phy_idx phy_idx, bool en)
1462cc99eefaSPing-Ke Shih {
1463cc99eefaSPing-Ke Shih 	if (en) {
1464cc99eefaSPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_S0_HW_SI_DIS,
1465cc99eefaSPing-Ke Shih 				      B_S0_HW_SI_DIS_W_R_TRIG, 0x0, phy_idx);
1466cc99eefaSPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_S1_HW_SI_DIS,
1467cc99eefaSPing-Ke Shih 				      B_S1_HW_SI_DIS_W_R_TRIG, 0x0, phy_idx);
1468cc99eefaSPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_RSTB_ASYNC, B_RSTB_ASYNC_ALL, 1,
1469cc99eefaSPing-Ke Shih 				      phy_idx);
1470ce57e55cSZong-Zhe Yang 		if (band == RTW89_BAND_2G)
1471cc99eefaSPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_RXCCA_V1, B_RXCCA_DIS_V1, 0x0);
1472cc99eefaSPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PD_CTRL, B_PD_HIT_DIS, 0x0);
1473cc99eefaSPing-Ke Shih 	} else {
1474cc99eefaSPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_RXCCA_V1, B_RXCCA_DIS_V1, 0x1);
1475cc99eefaSPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PD_CTRL, B_PD_HIT_DIS, 0x1);
1476cc99eefaSPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_S0_HW_SI_DIS,
1477cc99eefaSPing-Ke Shih 				      B_S0_HW_SI_DIS_W_R_TRIG, 0x7, phy_idx);
1478cc99eefaSPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_S1_HW_SI_DIS,
1479cc99eefaSPing-Ke Shih 				      B_S1_HW_SI_DIS_W_R_TRIG, 0x7, phy_idx);
1480cc99eefaSPing-Ke Shih 		fsleep(1);
1481cc99eefaSPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_RSTB_ASYNC, B_RSTB_ASYNC_ALL, 0,
1482cc99eefaSPing-Ke Shih 				      phy_idx);
1483cc99eefaSPing-Ke Shih 	}
1484cc99eefaSPing-Ke Shih }
1485cc99eefaSPing-Ke Shih 
rtw8852c_bb_reset(struct rtw89_dev * rtwdev,enum rtw89_phy_idx phy_idx)1486cc99eefaSPing-Ke Shih static void rtw8852c_bb_reset(struct rtw89_dev *rtwdev,
1487cc99eefaSPing-Ke Shih 			      enum rtw89_phy_idx phy_idx)
1488cc99eefaSPing-Ke Shih {
1489cc99eefaSPing-Ke Shih 	rtw8852c_bb_reset_all(rtwdev, phy_idx);
1490cc99eefaSPing-Ke Shih }
1491cc99eefaSPing-Ke Shih 
1492cc99eefaSPing-Ke Shih static
rtw8852c_bb_gpio_trsw(struct rtw89_dev * rtwdev,enum rtw89_rf_path path,u8 tx_path_en,u8 trsw_tx,u8 trsw_rx,u8 trsw,u8 trsw_b)1493cc99eefaSPing-Ke Shih void rtw8852c_bb_gpio_trsw(struct rtw89_dev *rtwdev, enum rtw89_rf_path path,
1494cc99eefaSPing-Ke Shih 			   u8 tx_path_en, u8 trsw_tx,
1495cc99eefaSPing-Ke Shih 			   u8 trsw_rx, u8 trsw, u8 trsw_b)
1496cc99eefaSPing-Ke Shih {
1497cc99eefaSPing-Ke Shih 	static const u32 path_cr_bases[] = {0x5868, 0x7868};
1498cc99eefaSPing-Ke Shih 	u32 mask_ofst = 16;
1499cc99eefaSPing-Ke Shih 	u32 cr;
1500cc99eefaSPing-Ke Shih 	u32 val;
1501cc99eefaSPing-Ke Shih 
1502cc99eefaSPing-Ke Shih 	if (path >= ARRAY_SIZE(path_cr_bases))
1503cc99eefaSPing-Ke Shih 		return;
1504cc99eefaSPing-Ke Shih 
1505cc99eefaSPing-Ke Shih 	cr = path_cr_bases[path];
1506cc99eefaSPing-Ke Shih 
1507cc99eefaSPing-Ke Shih 	mask_ofst += (tx_path_en * 4 + trsw_tx * 2 + trsw_rx) * 2;
1508cc99eefaSPing-Ke Shih 	val = FIELD_PREP(B_P0_TRSW_A, trsw) | FIELD_PREP(B_P0_TRSW_B, trsw_b);
1509cc99eefaSPing-Ke Shih 
1510cc99eefaSPing-Ke Shih 	rtw89_phy_write32_mask(rtwdev, cr, (B_P0_TRSW_A | B_P0_TRSW_B) << mask_ofst, val);
1511cc99eefaSPing-Ke Shih }
1512cc99eefaSPing-Ke Shih 
1513cc99eefaSPing-Ke Shih enum rtw8852c_rfe_src {
1514cc99eefaSPing-Ke Shih 	PAPE_RFM,
1515cc99eefaSPing-Ke Shih 	TRSW_RFM,
1516cc99eefaSPing-Ke Shih 	LNAON_RFM,
1517cc99eefaSPing-Ke Shih };
1518cc99eefaSPing-Ke Shih 
1519cc99eefaSPing-Ke Shih static
rtw8852c_bb_gpio_rfm(struct rtw89_dev * rtwdev,enum rtw89_rf_path path,enum rtw8852c_rfe_src src,u8 dis_tx_gnt_wl,u8 active_tx_opt,u8 act_bt_en,u8 rfm_output_val)1520cc99eefaSPing-Ke Shih void rtw8852c_bb_gpio_rfm(struct rtw89_dev *rtwdev, enum rtw89_rf_path path,
1521cc99eefaSPing-Ke Shih 			  enum rtw8852c_rfe_src src, u8 dis_tx_gnt_wl,
1522cc99eefaSPing-Ke Shih 			  u8 active_tx_opt, u8 act_bt_en, u8 rfm_output_val)
1523cc99eefaSPing-Ke Shih {
1524cc99eefaSPing-Ke Shih 	static const u32 path_cr_bases[] = {0x5894, 0x7894};
1525cc99eefaSPing-Ke Shih 	static const u32 masks[] = {0, 8, 16};
1526cc99eefaSPing-Ke Shih 	u32 mask, mask_ofst;
1527cc99eefaSPing-Ke Shih 	u32 cr;
1528cc99eefaSPing-Ke Shih 	u32 val;
1529cc99eefaSPing-Ke Shih 
1530cc99eefaSPing-Ke Shih 	if (src >= ARRAY_SIZE(masks) || path >= ARRAY_SIZE(path_cr_bases))
1531cc99eefaSPing-Ke Shih 		return;
1532cc99eefaSPing-Ke Shih 
1533cc99eefaSPing-Ke Shih 	mask_ofst = masks[src];
1534cc99eefaSPing-Ke Shih 	cr = path_cr_bases[path];
1535cc99eefaSPing-Ke Shih 
1536cc99eefaSPing-Ke Shih 	val = FIELD_PREP(B_P0_RFM_DIS_WL, dis_tx_gnt_wl) |
1537cc99eefaSPing-Ke Shih 	      FIELD_PREP(B_P0_RFM_TX_OPT, active_tx_opt) |
1538cc99eefaSPing-Ke Shih 	      FIELD_PREP(B_P0_RFM_BT_EN, act_bt_en) |
1539cc99eefaSPing-Ke Shih 	      FIELD_PREP(B_P0_RFM_OUT, rfm_output_val);
1540cc99eefaSPing-Ke Shih 	mask = 0xff << mask_ofst;
1541cc99eefaSPing-Ke Shih 
1542cc99eefaSPing-Ke Shih 	rtw89_phy_write32_mask(rtwdev, cr, mask, val);
1543cc99eefaSPing-Ke Shih }
1544cc99eefaSPing-Ke Shih 
rtw8852c_bb_gpio_init(struct rtw89_dev * rtwdev)1545cc99eefaSPing-Ke Shih static void rtw8852c_bb_gpio_init(struct rtw89_dev *rtwdev)
1546cc99eefaSPing-Ke Shih {
1547cc99eefaSPing-Ke Shih 	static const u32 cr_bases[] = {0x5800, 0x7800};
1548cc99eefaSPing-Ke Shih 	u32 addr;
1549cc99eefaSPing-Ke Shih 	u8 i;
1550cc99eefaSPing-Ke Shih 
1551cc99eefaSPing-Ke Shih 	for (i = 0; i < ARRAY_SIZE(cr_bases); i++) {
1552cc99eefaSPing-Ke Shih 		addr = cr_bases[i];
1553cc99eefaSPing-Ke Shih 		rtw89_phy_write32_set(rtwdev, (addr | 0x68), B_P0_TRSW_A);
1554cc99eefaSPing-Ke Shih 		rtw89_phy_write32_clr(rtwdev, (addr | 0x68), B_P0_TRSW_X);
1555cc99eefaSPing-Ke Shih 		rtw89_phy_write32_clr(rtwdev, (addr | 0x68), B_P0_TRSW_SO_A2);
1556cc99eefaSPing-Ke Shih 		rtw89_phy_write32(rtwdev, (addr | 0x80), 0x77777777);
1557cc99eefaSPing-Ke Shih 		rtw89_phy_write32(rtwdev, (addr | 0x84), 0x77777777);
1558cc99eefaSPing-Ke Shih 	}
1559cc99eefaSPing-Ke Shih 
1560cc99eefaSPing-Ke Shih 	rtw89_phy_write32(rtwdev, R_RFE_E_A2, 0xffffffff);
1561cc99eefaSPing-Ke Shih 	rtw89_phy_write32(rtwdev, R_RFE_O_SEL_A2, 0);
1562cc99eefaSPing-Ke Shih 	rtw89_phy_write32(rtwdev, R_RFE_SEL0_A2, 0);
1563cc99eefaSPing-Ke Shih 	rtw89_phy_write32(rtwdev, R_RFE_SEL32_A2, 0);
1564cc99eefaSPing-Ke Shih 
1565cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_A, 0, 0, 0, 0, 1);
1566cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_A, 0, 0, 1, 1, 0);
1567cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_A, 0, 1, 0, 1, 0);
1568cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_A, 0, 1, 1, 1, 0);
1569cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_A, 1, 0, 0, 0, 1);
1570cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_A, 1, 0, 1, 1, 0);
1571cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_A, 1, 1, 0, 1, 0);
1572cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_A, 1, 1, 1, 1, 0);
1573cc99eefaSPing-Ke Shih 
1574cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_B, 0, 0, 0, 0, 1);
1575cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_B, 0, 0, 1, 1, 0);
1576cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_B, 0, 1, 0, 1, 0);
1577cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_B, 0, 1, 1, 1, 0);
1578cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_B, 1, 0, 0, 0, 1);
1579cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_B, 1, 0, 1, 1, 0);
1580cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_B, 1, 1, 0, 1, 0);
1581cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_trsw(rtwdev, RF_PATH_B, 1, 1, 1, 1, 0);
1582cc99eefaSPing-Ke Shih 
1583cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_rfm(rtwdev, RF_PATH_A, PAPE_RFM, 0, 0, 0, 0x0);
1584cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_rfm(rtwdev, RF_PATH_A, TRSW_RFM, 0, 0, 0, 0x4);
1585cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_rfm(rtwdev, RF_PATH_A, LNAON_RFM, 0, 0, 0, 0x8);
1586cc99eefaSPing-Ke Shih 
1587cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_rfm(rtwdev, RF_PATH_B, PAPE_RFM, 0, 0, 0, 0x0);
1588cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_rfm(rtwdev, RF_PATH_B, TRSW_RFM, 0, 0, 0, 0x4);
1589cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_rfm(rtwdev, RF_PATH_B, LNAON_RFM, 0, 0, 0, 0x8);
1590cc99eefaSPing-Ke Shih }
1591cc99eefaSPing-Ke Shih 
rtw8852c_bb_macid_ctrl_init(struct rtw89_dev * rtwdev,enum rtw89_phy_idx phy_idx)1592cc99eefaSPing-Ke Shih static void rtw8852c_bb_macid_ctrl_init(struct rtw89_dev *rtwdev,
1593cc99eefaSPing-Ke Shih 					enum rtw89_phy_idx phy_idx)
1594cc99eefaSPing-Ke Shih {
1595cc99eefaSPing-Ke Shih 	u32 addr;
1596cc99eefaSPing-Ke Shih 
1597cc99eefaSPing-Ke Shih 	for (addr = R_AX_PWR_MACID_LMT_TABLE0;
1598cc99eefaSPing-Ke Shih 	     addr <= R_AX_PWR_MACID_LMT_TABLE127; addr += 4)
1599cc99eefaSPing-Ke Shih 		rtw89_mac_txpwr_write32(rtwdev, phy_idx, addr, 0);
1600cc99eefaSPing-Ke Shih }
1601cc99eefaSPing-Ke Shih 
rtw8852c_bb_sethw(struct rtw89_dev * rtwdev)1602cc99eefaSPing-Ke Shih static void rtw8852c_bb_sethw(struct rtw89_dev *rtwdev)
1603cc99eefaSPing-Ke Shih {
1604e6b17cbdSPing-Ke Shih 	struct rtw89_phy_efuse_gain *gain = &rtwdev->efuse_gain;
1605e6b17cbdSPing-Ke Shih 
1606cc99eefaSPing-Ke Shih 	rtw89_phy_write32_set(rtwdev, R_DBCC_80P80_SEL_EVM_RPT,
1607cc99eefaSPing-Ke Shih 			      B_DBCC_80P80_SEL_EVM_RPT_EN);
1608cc99eefaSPing-Ke Shih 	rtw89_phy_write32_set(rtwdev, R_DBCC_80P80_SEL_EVM_RPT2,
1609cc99eefaSPing-Ke Shih 			      B_DBCC_80P80_SEL_EVM_RPT2_EN);
1610cc99eefaSPing-Ke Shih 
1611cc99eefaSPing-Ke Shih 	rtw8852c_bb_macid_ctrl_init(rtwdev, RTW89_PHY_0);
1612cc99eefaSPing-Ke Shih 	rtw8852c_bb_gpio_init(rtwdev);
1613e6b17cbdSPing-Ke Shih 
1614e6b17cbdSPing-Ke Shih 	/* read these registers after loading BB parameters */
1615e6b17cbdSPing-Ke Shih 	gain->offset_base[RTW89_PHY_0] =
1616e6b17cbdSPing-Ke Shih 		rtw89_phy_read32_mask(rtwdev, R_RPL_BIAS_COMP, B_RPL_BIAS_COMP_MASK);
1617e6b17cbdSPing-Ke Shih 	gain->offset_base[RTW89_PHY_1] =
1618e6b17cbdSPing-Ke Shih 		rtw89_phy_read32_mask(rtwdev, R_RPL_BIAS_COMP1, B_RPL_BIAS_COMP1_MASK);
1619cc99eefaSPing-Ke Shih }
1620cc99eefaSPing-Ke Shih 
rtw8852c_set_channel_bb(struct rtw89_dev * rtwdev,const struct rtw89_chan * chan,enum rtw89_phy_idx phy_idx)16211b00e923SPing-Ke Shih static void rtw8852c_set_channel_bb(struct rtw89_dev *rtwdev,
16223e5831caSZong-Zhe Yang 				    const struct rtw89_chan *chan,
16231b00e923SPing-Ke Shih 				    enum rtw89_phy_idx phy_idx)
16241b00e923SPing-Ke Shih {
1625e69ae29eSPing-Ke Shih 	static const u32 ru_alloc_msk[2] = {B_P80_AT_HIGH_FREQ_RU_ALLOC_PHY0,
1626e69ae29eSPing-Ke Shih 					    B_P80_AT_HIGH_FREQ_RU_ALLOC_PHY1};
1627755fda37SYi-Tang Chiu 	struct rtw89_hal *hal = &rtwdev->hal;
16283e5831caSZong-Zhe Yang 	bool cck_en = chan->band_type == RTW89_BAND_2G;
16293e5831caSZong-Zhe Yang 	u8 pri_ch_idx = chan->pri_ch_idx;
16301b00e923SPing-Ke Shih 	u32 mask, reg;
1631755fda37SYi-Tang Chiu 	u8 ntx_path;
16321b00e923SPing-Ke Shih 
16333e5831caSZong-Zhe Yang 	if (chan->band_type == RTW89_BAND_2G)
16343e5831caSZong-Zhe Yang 		rtw8852c_ctrl_sco_cck(rtwdev, chan->channel,
16353e5831caSZong-Zhe Yang 				      chan->primary_channel,
16363e5831caSZong-Zhe Yang 				      chan->band_width);
16371b00e923SPing-Ke Shih 
16383e5831caSZong-Zhe Yang 	rtw8852c_ctrl_ch(rtwdev, chan, phy_idx);
16393e5831caSZong-Zhe Yang 	rtw8852c_ctrl_bw(rtwdev, pri_ch_idx, chan->band_width, phy_idx);
16401b00e923SPing-Ke Shih 	if (cck_en) {
16411b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_UPD_CLK_ADC, B_ENABLE_CCK, 1);
16421b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_RXCCA_V1, B_RXCCA_DIS_V1, 0);
16431b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_PD_ARBITER_OFF,
16441b00e923SPing-Ke Shih 				      B_PD_ARBITER_OFF, 0x0, phy_idx);
16451b00e923SPing-Ke Shih 	} else {
16461b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_UPD_CLK_ADC, B_ENABLE_CCK, 0);
16471b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_RXCCA_V1, B_RXCCA_DIS_V1, 1);
16481b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_PD_ARBITER_OFF,
16491b00e923SPing-Ke Shih 				      B_PD_ARBITER_OFF, 0x1, phy_idx);
16501b00e923SPing-Ke Shih 	}
16511b00e923SPing-Ke Shih 
16523e5831caSZong-Zhe Yang 	rtw8852c_spur_elimination(rtwdev, chan, pri_ch_idx, phy_idx);
16533e5831caSZong-Zhe Yang 	rtw8852c_ctrl_btg(rtwdev, chan->band_type == RTW89_BAND_2G);
16543e5831caSZong-Zhe Yang 	rtw8852c_5m_mask(rtwdev, chan, phy_idx);
16551b00e923SPing-Ke Shih 
16563e5831caSZong-Zhe Yang 	if (chan->band_width == RTW89_CHANNEL_WIDTH_160 &&
16571b00e923SPing-Ke Shih 	    rtwdev->hal.cv != CHIP_CAV) {
16581b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_P80_AT_HIGH_FREQ,
16591b00e923SPing-Ke Shih 				      B_P80_AT_HIGH_FREQ, 0x0, phy_idx);
1660c220d08eSPing-Ke Shih 		reg = rtw89_mac_reg_by_idx(rtwdev, R_P80_AT_HIGH_FREQ_BB_WRP, phy_idx);
16613e5831caSZong-Zhe Yang 		if (chan->primary_channel > chan->channel) {
16621b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev,
16631b00e923SPing-Ke Shih 					       R_P80_AT_HIGH_FREQ_RU_ALLOC,
16641b00e923SPing-Ke Shih 					       ru_alloc_msk[phy_idx], 1);
16651b00e923SPing-Ke Shih 			rtw89_write32_mask(rtwdev, reg,
16661b00e923SPing-Ke Shih 					   B_P80_AT_HIGH_FREQ_BB_WRP, 1);
16671b00e923SPing-Ke Shih 		} else {
16681b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev,
16691b00e923SPing-Ke Shih 					       R_P80_AT_HIGH_FREQ_RU_ALLOC,
16701b00e923SPing-Ke Shih 					       ru_alloc_msk[phy_idx], 0);
16711b00e923SPing-Ke Shih 			rtw89_write32_mask(rtwdev, reg,
16721b00e923SPing-Ke Shih 					   B_P80_AT_HIGH_FREQ_BB_WRP, 0);
16731b00e923SPing-Ke Shih 		}
16741b00e923SPing-Ke Shih 	}
16751b00e923SPing-Ke Shih 
16763e5831caSZong-Zhe Yang 	if (chan->band_type == RTW89_BAND_6G &&
16773e5831caSZong-Zhe Yang 	    chan->band_width == RTW89_CHANNEL_WIDTH_160)
16781b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_CDD_EVM_CHK_EN,
16791b00e923SPing-Ke Shih 				      B_CDD_EVM_CHK_EN, 0, phy_idx);
16801b00e923SPing-Ke Shih 	else
16811b00e923SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_CDD_EVM_CHK_EN,
16821b00e923SPing-Ke Shih 				      B_CDD_EVM_CHK_EN, 1, phy_idx);
16831b00e923SPing-Ke Shih 
16841b00e923SPing-Ke Shih 	if (!rtwdev->dbcc_en) {
16851b00e923SPing-Ke Shih 		mask = B_P0_TXPW_RSTB_TSSI | B_P0_TXPW_RSTB_MANON;
16861b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_P0_TXPW_RSTB, mask, 0x1);
16871b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_P0_TXPW_RSTB, mask, 0x3);
16881b00e923SPing-Ke Shih 		mask = B_P1_TXPW_RSTB_TSSI | B_P1_TXPW_RSTB_MANON;
16891b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_P1_TXPW_RSTB, mask, 0x1);
16901b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_P1_TXPW_RSTB, mask, 0x3);
16911b00e923SPing-Ke Shih 	} else {
16921b00e923SPing-Ke Shih 		if (phy_idx == RTW89_PHY_0) {
16931b00e923SPing-Ke Shih 			mask = B_P0_TXPW_RSTB_TSSI | B_P0_TXPW_RSTB_MANON;
16941b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_P0_TXPW_RSTB, mask, 0x1);
16951b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_P0_TXPW_RSTB, mask, 0x3);
16961b00e923SPing-Ke Shih 		} else {
16971b00e923SPing-Ke Shih 			mask = B_P1_TXPW_RSTB_TSSI | B_P1_TXPW_RSTB_MANON;
16981b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_P1_TXPW_RSTB, mask, 0x1);
16991b00e923SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_P1_TXPW_RSTB, mask, 0x3);
17001b00e923SPing-Ke Shih 		}
17011b00e923SPing-Ke Shih 	}
17021b00e923SPing-Ke Shih 
1703ef16380bSPing-Ke Shih 	if (chan->band_type == RTW89_BAND_6G)
1704ef16380bSPing-Ke Shih 		rtw89_phy_write32_set(rtwdev, R_MUIC, B_MUIC_EN);
1705ef16380bSPing-Ke Shih 	else
1706ef16380bSPing-Ke Shih 		rtw89_phy_write32_clr(rtwdev, R_MUIC, B_MUIC_EN);
1707ef16380bSPing-Ke Shih 
1708755fda37SYi-Tang Chiu 	if (hal->antenna_tx)
1709755fda37SYi-Tang Chiu 		ntx_path = hal->antenna_tx;
1710755fda37SYi-Tang Chiu 	else
1711755fda37SYi-Tang Chiu 		ntx_path = chan->band_type == RTW89_BAND_6G ? RF_B : RF_AB;
1712755fda37SYi-Tang Chiu 
1713755fda37SYi-Tang Chiu 	rtw8852c_ctrl_tx_path_tmac(rtwdev, ntx_path, (enum rtw89_mac_idx)phy_idx);
1714755fda37SYi-Tang Chiu 
17151b00e923SPing-Ke Shih 	rtw8852c_bb_reset_all(rtwdev, phy_idx);
17161b00e923SPing-Ke Shih }
17171b00e923SPing-Ke Shih 
rtw8852c_set_channel(struct rtw89_dev * rtwdev,const struct rtw89_chan * chan,enum rtw89_mac_idx mac_idx,enum rtw89_phy_idx phy_idx)17181b00e923SPing-Ke Shih static void rtw8852c_set_channel(struct rtw89_dev *rtwdev,
1719ce57e55cSZong-Zhe Yang 				 const struct rtw89_chan *chan,
1720ce57e55cSZong-Zhe Yang 				 enum rtw89_mac_idx mac_idx,
1721ce57e55cSZong-Zhe Yang 				 enum rtw89_phy_idx phy_idx)
17221b00e923SPing-Ke Shih {
1723ce57e55cSZong-Zhe Yang 	rtw8852c_set_channel_mac(rtwdev, chan, mac_idx);
1724ce57e55cSZong-Zhe Yang 	rtw8852c_set_channel_bb(rtwdev, chan, phy_idx);
1725ce57e55cSZong-Zhe Yang 	rtw8852c_set_channel_rf(rtwdev, chan, phy_idx);
17261b00e923SPing-Ke Shih }
17271b00e923SPing-Ke Shih 
rtw8852c_dfs_en(struct rtw89_dev * rtwdev,bool en)172879dafcd4SPing-Ke Shih static void rtw8852c_dfs_en(struct rtw89_dev *rtwdev, bool en)
172979dafcd4SPing-Ke Shih {
173079dafcd4SPing-Ke Shih 	if (en)
173179dafcd4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_UPD_P0, B_UPD_P0_EN, 1);
173279dafcd4SPing-Ke Shih 	else
173379dafcd4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_UPD_P0, B_UPD_P0_EN, 0);
173479dafcd4SPing-Ke Shih }
173579dafcd4SPing-Ke Shih 
rtw8852c_adc_en(struct rtw89_dev * rtwdev,bool en)173679dafcd4SPing-Ke Shih static void rtw8852c_adc_en(struct rtw89_dev *rtwdev, bool en)
173779dafcd4SPing-Ke Shih {
173879dafcd4SPing-Ke Shih 	if (en)
173979dafcd4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_ADC_FIFO, B_ADC_FIFO_RST,
174079dafcd4SPing-Ke Shih 				       0x0);
174179dafcd4SPing-Ke Shih 	else
174279dafcd4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_ADC_FIFO, B_ADC_FIFO_RST,
174379dafcd4SPing-Ke Shih 				       0xf);
174479dafcd4SPing-Ke Shih }
174579dafcd4SPing-Ke Shih 
rtw8852c_set_channel_help(struct rtw89_dev * rtwdev,bool enter,struct rtw89_channel_help_params * p,const struct rtw89_chan * chan,enum rtw89_mac_idx mac_idx,enum rtw89_phy_idx phy_idx)174679dafcd4SPing-Ke Shih static void rtw8852c_set_channel_help(struct rtw89_dev *rtwdev, bool enter,
1747ce57e55cSZong-Zhe Yang 				      struct rtw89_channel_help_params *p,
1748ce57e55cSZong-Zhe Yang 				      const struct rtw89_chan *chan,
1749ce57e55cSZong-Zhe Yang 				      enum rtw89_mac_idx mac_idx,
1750ce57e55cSZong-Zhe Yang 				      enum rtw89_phy_idx phy_idx)
175179dafcd4SPing-Ke Shih {
175279dafcd4SPing-Ke Shih 	if (enter) {
1753ce57e55cSZong-Zhe Yang 		rtw89_chip_stop_sch_tx(rtwdev, mac_idx, &p->tx_en,
1754ce57e55cSZong-Zhe Yang 				       RTW89_SCH_TX_SEL_ALL);
1755ce57e55cSZong-Zhe Yang 		rtw89_mac_cfg_ppdu_status(rtwdev, mac_idx, false);
175679dafcd4SPing-Ke Shih 		rtw8852c_dfs_en(rtwdev, false);
1757ce57e55cSZong-Zhe Yang 		rtw8852c_tssi_cont_en_phyidx(rtwdev, false, phy_idx);
175879dafcd4SPing-Ke Shih 		rtw8852c_adc_en(rtwdev, false);
175979dafcd4SPing-Ke Shih 		fsleep(40);
1760ce57e55cSZong-Zhe Yang 		rtw8852c_bb_reset_en(rtwdev, chan->band_type, phy_idx, false);
176179dafcd4SPing-Ke Shih 	} else {
1762ce57e55cSZong-Zhe Yang 		rtw89_mac_cfg_ppdu_status(rtwdev, mac_idx, true);
176379dafcd4SPing-Ke Shih 		rtw8852c_adc_en(rtwdev, true);
176479dafcd4SPing-Ke Shih 		rtw8852c_dfs_en(rtwdev, true);
1765ce57e55cSZong-Zhe Yang 		rtw8852c_tssi_cont_en_phyidx(rtwdev, true, phy_idx);
1766ce57e55cSZong-Zhe Yang 		rtw8852c_bb_reset_en(rtwdev, chan->band_type, phy_idx, true);
1767ce57e55cSZong-Zhe Yang 		rtw89_chip_resume_sch_tx(rtwdev, mac_idx, p->tx_en);
176879dafcd4SPing-Ke Shih 	}
176979dafcd4SPing-Ke Shih }
177079dafcd4SPing-Ke Shih 
rtw8852c_rfk_init(struct rtw89_dev * rtwdev)177116b44ed0SPing-Ke Shih static void rtw8852c_rfk_init(struct rtw89_dev *rtwdev)
177216b44ed0SPing-Ke Shih {
177338f25decSZong-Zhe Yang 	struct rtw89_rfk_mcc_info *rfk_mcc = &rtwdev->rfk_mcc;
177416b44ed0SPing-Ke Shih 
1775e5efc4d5SPing-Ke Shih 	rtwdev->is_tssi_mode[RF_PATH_A] = false;
1776e5efc4d5SPing-Ke Shih 	rtwdev->is_tssi_mode[RF_PATH_B] = false;
177738f25decSZong-Zhe Yang 	memset(rfk_mcc, 0, sizeof(*rfk_mcc));
1778fb8177d7SPing-Ke Shih 	rtw8852c_lck_init(rtwdev);
177976599a8dSPing-Ke Shih 
178030052c5aSPing-Ke Shih 	rtw8852c_rck(rtwdev);
178176599a8dSPing-Ke Shih 	rtw8852c_dack(rtwdev);
1782ac91be97SPing-Ke Shih 	rtw8852c_rx_dck(rtwdev, RTW89_PHY_0, false);
178316b44ed0SPing-Ke Shih }
178416b44ed0SPing-Ke Shih 
rtw8852c_rfk_channel(struct rtw89_dev * rtwdev)178516b44ed0SPing-Ke Shih static void rtw8852c_rfk_channel(struct rtw89_dev *rtwdev)
178616b44ed0SPing-Ke Shih {
1787e5efc4d5SPing-Ke Shih 	enum rtw89_phy_idx phy_idx = RTW89_PHY_0;
1788e5efc4d5SPing-Ke Shih 
17895309cd5eSPing-Ke Shih 	rtw8852c_mcc_get_ch_info(rtwdev, phy_idx);
1790ac91be97SPing-Ke Shih 	rtw8852c_rx_dck(rtwdev, phy_idx, false);
17912da8109dSPing-Ke Shih 	rtw8852c_iqk(rtwdev, phy_idx);
1792e5efc4d5SPing-Ke Shih 	rtw8852c_tssi(rtwdev, phy_idx);
1793da4cea16SPing-Ke Shih 	rtw8852c_dpk(rtwdev, phy_idx);
179416b44ed0SPing-Ke Shih 	rtw89_fw_h2c_rf_ntfy_mcc(rtwdev);
179516b44ed0SPing-Ke Shih }
179616b44ed0SPing-Ke Shih 
rtw8852c_rfk_band_changed(struct rtw89_dev * rtwdev,enum rtw89_phy_idx phy_idx)1797010d0051SZong-Zhe Yang static void rtw8852c_rfk_band_changed(struct rtw89_dev *rtwdev,
1798010d0051SZong-Zhe Yang 				      enum rtw89_phy_idx phy_idx)
1799e5efc4d5SPing-Ke Shih {
1800010d0051SZong-Zhe Yang 	rtw8852c_tssi_scan(rtwdev, phy_idx);
1801e5efc4d5SPing-Ke Shih }
1802e5efc4d5SPing-Ke Shih 
rtw8852c_rfk_scan(struct rtw89_dev * rtwdev,bool start)1803e5efc4d5SPing-Ke Shih static void rtw8852c_rfk_scan(struct rtw89_dev *rtwdev, bool start)
1804e5efc4d5SPing-Ke Shih {
1805e5efc4d5SPing-Ke Shih 	rtw8852c_wifi_scan_notify(rtwdev, start, RTW89_PHY_0);
1806e5efc4d5SPing-Ke Shih }
1807e5efc4d5SPing-Ke Shih 
rtw8852c_rfk_track(struct rtw89_dev * rtwdev)1808fb8177d7SPing-Ke Shih static void rtw8852c_rfk_track(struct rtw89_dev *rtwdev)
1809fb8177d7SPing-Ke Shih {
1810da4cea16SPing-Ke Shih 	rtw8852c_dpk_track(rtwdev);
1811fb8177d7SPing-Ke Shih 	rtw8852c_lck_track(rtwdev);
1812e3d365ffSPing-Ke Shih 	rtw8852c_rx_dck_track(rtwdev);
1813fb8177d7SPing-Ke Shih }
1814fb8177d7SPing-Ke Shih 
rtw8852c_bb_cal_txpwr_ref(struct rtw89_dev * rtwdev,enum rtw89_phy_idx phy_idx,s16 ref)1815af0cac15SPing-Ke Shih static u32 rtw8852c_bb_cal_txpwr_ref(struct rtw89_dev *rtwdev,
1816af0cac15SPing-Ke Shih 				     enum rtw89_phy_idx phy_idx, s16 ref)
1817af0cac15SPing-Ke Shih {
1818af0cac15SPing-Ke Shih 	s8 ofst_int = 0;
1819af0cac15SPing-Ke Shih 	u8 base_cw_0db = 0x27;
1820af0cac15SPing-Ke Shih 	u16 tssi_16dbm_cw = 0x12c;
1821af0cac15SPing-Ke Shih 	s16 pwr_s10_3 = 0;
1822af0cac15SPing-Ke Shih 	s16 rf_pwr_cw = 0;
1823af0cac15SPing-Ke Shih 	u16 bb_pwr_cw = 0;
1824af0cac15SPing-Ke Shih 	u32 pwr_cw = 0;
1825af0cac15SPing-Ke Shih 	u32 tssi_ofst_cw = 0;
1826af0cac15SPing-Ke Shih 
1827af0cac15SPing-Ke Shih 	pwr_s10_3 = (ref << 1) + (s16)(ofst_int) + (s16)(base_cw_0db << 3);
1828af0cac15SPing-Ke Shih 	bb_pwr_cw = FIELD_GET(GENMASK(2, 0), pwr_s10_3);
1829af0cac15SPing-Ke Shih 	rf_pwr_cw = FIELD_GET(GENMASK(8, 3), pwr_s10_3);
1830af0cac15SPing-Ke Shih 	rf_pwr_cw = clamp_t(s16, rf_pwr_cw, 15, 63);
1831af0cac15SPing-Ke Shih 	pwr_cw = (rf_pwr_cw << 3) | bb_pwr_cw;
1832af0cac15SPing-Ke Shih 
1833af0cac15SPing-Ke Shih 	tssi_ofst_cw = (u32)((s16)tssi_16dbm_cw + (ref << 1) - (16 << 3));
1834af0cac15SPing-Ke Shih 	rtw89_debug(rtwdev, RTW89_DBG_TXPWR,
1835af0cac15SPing-Ke Shih 		    "[TXPWR] tssi_ofst_cw=%d rf_cw=0x%x bb_cw=0x%x\n",
1836af0cac15SPing-Ke Shih 		    tssi_ofst_cw, rf_pwr_cw, bb_pwr_cw);
1837af0cac15SPing-Ke Shih 
1838af0cac15SPing-Ke Shih 	return (tssi_ofst_cw << 18) | (pwr_cw << 9) | (ref & GENMASK(8, 0));
1839af0cac15SPing-Ke Shih }
1840af0cac15SPing-Ke Shih 
1841a9ffae8dSYuan-Han Zhang static
rtw8852c_set_txpwr_ul_tb_offset(struct rtw89_dev * rtwdev,s8 pw_ofst,enum rtw89_mac_idx mac_idx)1842a9ffae8dSYuan-Han Zhang void rtw8852c_set_txpwr_ul_tb_offset(struct rtw89_dev *rtwdev,
1843a9ffae8dSYuan-Han Zhang 				     s8 pw_ofst, enum rtw89_mac_idx mac_idx)
1844a9ffae8dSYuan-Han Zhang {
1845a9ffae8dSYuan-Han Zhang 	s8 pw_ofst_2tx;
1846a9ffae8dSYuan-Han Zhang 	s8 val_1t;
1847a9ffae8dSYuan-Han Zhang 	s8 val_2t;
1848a9ffae8dSYuan-Han Zhang 	u32 reg;
1849a9ffae8dSYuan-Han Zhang 	u8 i;
1850a9ffae8dSYuan-Han Zhang 
1851a9ffae8dSYuan-Han Zhang 	if (pw_ofst < -32 || pw_ofst > 31) {
1852a9ffae8dSYuan-Han Zhang 		rtw89_warn(rtwdev, "[ULTB] Err pwr_offset=%d\n", pw_ofst);
1853a9ffae8dSYuan-Han Zhang 		return;
1854a9ffae8dSYuan-Han Zhang 	}
1855a9ffae8dSYuan-Han Zhang 	val_1t = pw_ofst << 2;
1856a9ffae8dSYuan-Han Zhang 	pw_ofst_2tx = max(pw_ofst - 3, -32);
1857a9ffae8dSYuan-Han Zhang 	val_2t = pw_ofst_2tx << 2;
1858a9ffae8dSYuan-Han Zhang 
1859a9ffae8dSYuan-Han Zhang 	rtw89_debug(rtwdev, RTW89_DBG_TXPWR, "[ULTB] val_1tx=0x%x\n", val_1t);
1860a9ffae8dSYuan-Han Zhang 	rtw89_debug(rtwdev, RTW89_DBG_TXPWR, "[ULTB] val_2tx=0x%x\n", val_2t);
1861a9ffae8dSYuan-Han Zhang 
1862a9ffae8dSYuan-Han Zhang 	for (i = 0; i < 4; i++) {
1863a9ffae8dSYuan-Han Zhang 		/* 1TX */
1864c220d08eSPing-Ke Shih 		reg = rtw89_mac_reg_by_idx(rtwdev, R_AX_PWR_UL_TB_1T, mac_idx);
1865a9ffae8dSYuan-Han Zhang 		rtw89_write32_mask(rtwdev, reg,
1866a9ffae8dSYuan-Han Zhang 				   B_AX_PWR_UL_TB_1T_V1_MASK << (8 * i),
1867a9ffae8dSYuan-Han Zhang 				   val_1t);
1868a9ffae8dSYuan-Han Zhang 		/* 2TX */
1869c220d08eSPing-Ke Shih 		reg = rtw89_mac_reg_by_idx(rtwdev, R_AX_PWR_UL_TB_2T, mac_idx);
1870a9ffae8dSYuan-Han Zhang 		rtw89_write32_mask(rtwdev, reg,
1871a9ffae8dSYuan-Han Zhang 				   B_AX_PWR_UL_TB_2T_V1_MASK << (8 * i),
1872a9ffae8dSYuan-Han Zhang 				   val_2t);
1873a9ffae8dSYuan-Han Zhang 	}
1874a9ffae8dSYuan-Han Zhang }
1875a9ffae8dSYuan-Han Zhang 
rtw8852c_set_txpwr_ref(struct rtw89_dev * rtwdev,enum rtw89_phy_idx phy_idx)1876af0cac15SPing-Ke Shih static void rtw8852c_set_txpwr_ref(struct rtw89_dev *rtwdev,
1877af0cac15SPing-Ke Shih 				   enum rtw89_phy_idx phy_idx)
1878af0cac15SPing-Ke Shih {
1879af0cac15SPing-Ke Shih 	static const u32 addr[RF_PATH_NUM_8852C] = {0x5800, 0x7800};
1880af0cac15SPing-Ke Shih 	const u32 mask = 0x7FFFFFF;
1881af0cac15SPing-Ke Shih 	const u8 ofst_ofdm = 0x4;
1882af0cac15SPing-Ke Shih 	const u8 ofst_cck = 0x8;
1883af0cac15SPing-Ke Shih 	s16 ref_ofdm = 0;
1884af0cac15SPing-Ke Shih 	s16 ref_cck = 0;
1885af0cac15SPing-Ke Shih 	u32 val;
1886af0cac15SPing-Ke Shih 	u8 i;
1887af0cac15SPing-Ke Shih 
1888af0cac15SPing-Ke Shih 	rtw89_debug(rtwdev, RTW89_DBG_TXPWR, "[TXPWR] set txpwr reference\n");
1889af0cac15SPing-Ke Shih 
1890af0cac15SPing-Ke Shih 	rtw89_mac_txpwr_write32_mask(rtwdev, phy_idx, R_AX_PWR_RATE_CTRL,
1891af0cac15SPing-Ke Shih 				     GENMASK(27, 10), 0x0);
1892af0cac15SPing-Ke Shih 
1893af0cac15SPing-Ke Shih 	rtw89_debug(rtwdev, RTW89_DBG_TXPWR, "[TXPWR] set bb ofdm txpwr ref\n");
1894af0cac15SPing-Ke Shih 	val = rtw8852c_bb_cal_txpwr_ref(rtwdev, phy_idx, ref_ofdm);
1895af0cac15SPing-Ke Shih 
1896af0cac15SPing-Ke Shih 	for (i = 0; i < RF_PATH_NUM_8852C; i++)
1897af0cac15SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, addr[i] + ofst_ofdm, mask, val,
1898af0cac15SPing-Ke Shih 				      phy_idx);
1899af0cac15SPing-Ke Shih 
1900af0cac15SPing-Ke Shih 	rtw89_debug(rtwdev, RTW89_DBG_TXPWR, "[TXPWR] set bb cck txpwr ref\n");
1901af0cac15SPing-Ke Shih 	val = rtw8852c_bb_cal_txpwr_ref(rtwdev, phy_idx, ref_cck);
1902af0cac15SPing-Ke Shih 
1903af0cac15SPing-Ke Shih 	for (i = 0; i < RF_PATH_NUM_8852C; i++)
1904af0cac15SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, addr[i] + ofst_cck, mask, val,
1905af0cac15SPing-Ke Shih 				      phy_idx);
1906af0cac15SPing-Ke Shih }
1907af0cac15SPing-Ke Shih 
rtw8852c_bb_set_tx_shape_dfir(struct rtw89_dev * rtwdev,const struct rtw89_chan * chan,u8 tx_shape_idx,enum rtw89_phy_idx phy_idx)1908af0cac15SPing-Ke Shih static void rtw8852c_bb_set_tx_shape_dfir(struct rtw89_dev *rtwdev,
1909764f07f4SZong-Zhe Yang 					  const struct rtw89_chan *chan,
1910af0cac15SPing-Ke Shih 					  u8 tx_shape_idx,
1911af0cac15SPing-Ke Shih 					  enum rtw89_phy_idx phy_idx)
1912af0cac15SPing-Ke Shih {
1913af0cac15SPing-Ke Shih #define __DFIR_CFG_MASK 0xffffff
1914af0cac15SPing-Ke Shih #define __DFIR_CFG_NR 8
1915af0cac15SPing-Ke Shih #define __DECL_DFIR_VAR(_prefix, _name, _val...) \
1916af0cac15SPing-Ke Shih 	static const u32 _prefix ## _ ## _name[] = {_val}; \
1917af0cac15SPing-Ke Shih 	static_assert(ARRAY_SIZE(_prefix ## _ ## _name) == __DFIR_CFG_NR)
1918af0cac15SPing-Ke Shih #define __DECL_DFIR_PARAM(_name, _val...) __DECL_DFIR_VAR(param, _name, _val)
1919af0cac15SPing-Ke Shih #define __DECL_DFIR_ADDR(_name, _val...) __DECL_DFIR_VAR(addr, _name, _val)
1920af0cac15SPing-Ke Shih 
1921af0cac15SPing-Ke Shih 	__DECL_DFIR_PARAM(flat,
1922af0cac15SPing-Ke Shih 			  0x003D23FF, 0x0029B354, 0x000FC1C8, 0x00FDB053,
1923af0cac15SPing-Ke Shih 			  0x00F86F9A, 0x00FAEF92, 0x00FE5FCC, 0x00FFDFF5);
1924af0cac15SPing-Ke Shih 	__DECL_DFIR_PARAM(sharp,
1925af0cac15SPing-Ke Shih 			  0x003D83FF, 0x002C636A, 0x0013F204, 0x00008090,
1926af0cac15SPing-Ke Shih 			  0x00F87FB0, 0x00F99F83, 0x00FDBFBA, 0x00003FF5);
1927af0cac15SPing-Ke Shih 	__DECL_DFIR_PARAM(sharp_14,
1928af0cac15SPing-Ke Shih 			  0x003B13FF, 0x001C42DE, 0x00FDB0AD, 0x00F60F6E,
1929af0cac15SPing-Ke Shih 			  0x00FD8F92, 0x0002D011, 0x0001C02C, 0x00FFF00A);
1930af0cac15SPing-Ke Shih 	__DECL_DFIR_ADDR(filter,
1931af0cac15SPing-Ke Shih 			 0x45BC, 0x45CC, 0x45D0, 0x45D4, 0x45D8, 0x45C0,
1932af0cac15SPing-Ke Shih 			 0x45C4, 0x45C8);
1933cbb145b9SZong-Zhe Yang 	u8 ch = chan->channel;
1934af0cac15SPing-Ke Shih 	const u32 *param;
1935af0cac15SPing-Ke Shih 	int i;
1936af0cac15SPing-Ke Shih 
1937af0cac15SPing-Ke Shih 	if (ch > 14) {
1938af0cac15SPing-Ke Shih 		rtw89_warn(rtwdev,
1939af0cac15SPing-Ke Shih 			   "set tx shape dfir by unknown ch: %d on 2G\n", ch);
1940af0cac15SPing-Ke Shih 		return;
1941af0cac15SPing-Ke Shih 	}
1942af0cac15SPing-Ke Shih 
1943af0cac15SPing-Ke Shih 	if (ch == 14)
1944af0cac15SPing-Ke Shih 		param = param_sharp_14;
1945af0cac15SPing-Ke Shih 	else
1946af0cac15SPing-Ke Shih 		param = tx_shape_idx == 0 ? param_flat : param_sharp;
1947af0cac15SPing-Ke Shih 
1948af0cac15SPing-Ke Shih 	for (i = 0; i < __DFIR_CFG_NR; i++) {
1949af0cac15SPing-Ke Shih 		rtw89_debug(rtwdev, RTW89_DBG_TXPWR,
1950af0cac15SPing-Ke Shih 			    "set tx shape dfir: 0x%x: 0x%x\n", addr_filter[i],
1951af0cac15SPing-Ke Shih 			    param[i]);
1952af0cac15SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, addr_filter[i], __DFIR_CFG_MASK,
1953af0cac15SPing-Ke Shih 				      param[i], phy_idx);
1954af0cac15SPing-Ke Shih 	}
1955af0cac15SPing-Ke Shih 
1956af0cac15SPing-Ke Shih #undef __DECL_DFIR_ADDR
1957af0cac15SPing-Ke Shih #undef __DECL_DFIR_PARAM
1958af0cac15SPing-Ke Shih #undef __DECL_DFIR_VAR
1959af0cac15SPing-Ke Shih #undef __DFIR_CFG_NR
1960af0cac15SPing-Ke Shih #undef __DFIR_CFG_MASK
1961af0cac15SPing-Ke Shih }
1962af0cac15SPing-Ke Shih 
rtw8852c_set_tx_shape(struct rtw89_dev * rtwdev,const struct rtw89_chan * chan,enum rtw89_phy_idx phy_idx)1963af0cac15SPing-Ke Shih static void rtw8852c_set_tx_shape(struct rtw89_dev *rtwdev,
196407ef5f2fSZong-Zhe Yang 				  const struct rtw89_chan *chan,
1965af0cac15SPing-Ke Shih 				  enum rtw89_phy_idx phy_idx)
1966af0cac15SPing-Ke Shih {
1967cbb145b9SZong-Zhe Yang 	u8 band = chan->band_type;
1968af0cac15SPing-Ke Shih 	u8 regd = rtw89_regd_get(rtwdev, band);
1969af0cac15SPing-Ke Shih 	u8 tx_shape_cck = rtw89_8852c_tx_shape[band][RTW89_RS_CCK][regd];
1970af0cac15SPing-Ke Shih 	u8 tx_shape_ofdm = rtw89_8852c_tx_shape[band][RTW89_RS_OFDM][regd];
1971af0cac15SPing-Ke Shih 
1972af0cac15SPing-Ke Shih 	if (band == RTW89_BAND_2G)
1973764f07f4SZong-Zhe Yang 		rtw8852c_bb_set_tx_shape_dfir(rtwdev, chan, tx_shape_cck, phy_idx);
1974af0cac15SPing-Ke Shih 
1975af0cac15SPing-Ke Shih 	rtw89_phy_tssi_ctrl_set_bandedge_cfg(rtwdev,
1976af0cac15SPing-Ke Shih 					     (enum rtw89_mac_idx)phy_idx,
1977af0cac15SPing-Ke Shih 					     tx_shape_ofdm);
1978af0cac15SPing-Ke Shih }
1979af0cac15SPing-Ke Shih 
rtw8852c_set_txpwr(struct rtw89_dev * rtwdev,const struct rtw89_chan * chan,enum rtw89_phy_idx phy_idx)198007ef5f2fSZong-Zhe Yang static void rtw8852c_set_txpwr(struct rtw89_dev *rtwdev,
198107ef5f2fSZong-Zhe Yang 			       const struct rtw89_chan *chan,
198207ef5f2fSZong-Zhe Yang 			       enum rtw89_phy_idx phy_idx)
1983af0cac15SPing-Ke Shih {
19849b43bd1aSZong-Zhe Yang 	rtw89_phy_set_txpwr_byrate(rtwdev, chan, phy_idx);
19859b43bd1aSZong-Zhe Yang 	rtw89_phy_set_txpwr_offset(rtwdev, chan, phy_idx);
198607ef5f2fSZong-Zhe Yang 	rtw8852c_set_tx_shape(rtwdev, chan, phy_idx);
19879b43bd1aSZong-Zhe Yang 	rtw89_phy_set_txpwr_limit(rtwdev, chan, phy_idx);
19889b43bd1aSZong-Zhe Yang 	rtw89_phy_set_txpwr_limit_ru(rtwdev, chan, phy_idx);
1989af0cac15SPing-Ke Shih }
1990af0cac15SPing-Ke Shih 
rtw8852c_set_txpwr_ctrl(struct rtw89_dev * rtwdev,enum rtw89_phy_idx phy_idx)199107ef5f2fSZong-Zhe Yang static void rtw8852c_set_txpwr_ctrl(struct rtw89_dev *rtwdev,
199207ef5f2fSZong-Zhe Yang 				    enum rtw89_phy_idx phy_idx)
1993af0cac15SPing-Ke Shih {
199407ef5f2fSZong-Zhe Yang 	rtw8852c_set_txpwr_ref(rtwdev, phy_idx);
1995af0cac15SPing-Ke Shih }
1996af0cac15SPing-Ke Shih 
1997af0cac15SPing-Ke Shih static void
rtw8852c_init_tssi_ctrl(struct rtw89_dev * rtwdev,enum rtw89_phy_idx phy_idx)1998af0cac15SPing-Ke Shih rtw8852c_init_tssi_ctrl(struct rtw89_dev *rtwdev, enum rtw89_phy_idx phy_idx)
1999af0cac15SPing-Ke Shih {
2000af0cac15SPing-Ke Shih 	static const struct rtw89_reg2_def ctrl_ini[] = {
2001af0cac15SPing-Ke Shih 		{0xD938, 0x00010100},
2002af0cac15SPing-Ke Shih 		{0xD93C, 0x0500D500},
2003af0cac15SPing-Ke Shih 		{0xD940, 0x00000500},
2004af0cac15SPing-Ke Shih 		{0xD944, 0x00000005},
2005af0cac15SPing-Ke Shih 		{0xD94C, 0x00220000},
2006af0cac15SPing-Ke Shih 		{0xD950, 0x00030000},
2007af0cac15SPing-Ke Shih 	};
2008af0cac15SPing-Ke Shih 	u32 addr;
2009af0cac15SPing-Ke Shih 	int i;
2010af0cac15SPing-Ke Shih 
2011af0cac15SPing-Ke Shih 	for (addr = R_AX_TSSI_CTRL_HEAD; addr <= R_AX_TSSI_CTRL_TAIL; addr += 4)
2012af0cac15SPing-Ke Shih 		rtw89_mac_txpwr_write32(rtwdev, phy_idx, addr, 0);
2013af0cac15SPing-Ke Shih 
2014af0cac15SPing-Ke Shih 	for (i = 0; i < ARRAY_SIZE(ctrl_ini); i++)
2015af0cac15SPing-Ke Shih 		rtw89_mac_txpwr_write32(rtwdev, phy_idx, ctrl_ini[i].addr,
2016af0cac15SPing-Ke Shih 					ctrl_ini[i].data);
2017af0cac15SPing-Ke Shih 
2018af0cac15SPing-Ke Shih 	rtw89_phy_tssi_ctrl_set_bandedge_cfg(rtwdev,
2019af0cac15SPing-Ke Shih 					     (enum rtw89_mac_idx)phy_idx,
2020af0cac15SPing-Ke Shih 					     RTW89_TSSI_BANDEDGE_FLAT);
2021af0cac15SPing-Ke Shih }
2022af0cac15SPing-Ke Shih 
2023af0cac15SPing-Ke Shih static int
rtw8852c_init_txpwr_unit(struct rtw89_dev * rtwdev,enum rtw89_phy_idx phy_idx)2024af0cac15SPing-Ke Shih rtw8852c_init_txpwr_unit(struct rtw89_dev *rtwdev, enum rtw89_phy_idx phy_idx)
2025af0cac15SPing-Ke Shih {
2026af0cac15SPing-Ke Shih 	int ret;
2027af0cac15SPing-Ke Shih 
2028af0cac15SPing-Ke Shih 	ret = rtw89_mac_txpwr_write32(rtwdev, phy_idx, R_AX_PWR_UL_CTRL2, 0x07763333);
2029af0cac15SPing-Ke Shih 	if (ret)
2030af0cac15SPing-Ke Shih 		return ret;
2031af0cac15SPing-Ke Shih 
2032af0cac15SPing-Ke Shih 	ret = rtw89_mac_txpwr_write32(rtwdev, phy_idx, R_AX_PWR_COEXT_CTRL, 0x01ebf000);
2033af0cac15SPing-Ke Shih 	if (ret)
2034af0cac15SPing-Ke Shih 		return ret;
2035af0cac15SPing-Ke Shih 
2036af0cac15SPing-Ke Shih 	ret = rtw89_mac_txpwr_write32(rtwdev, phy_idx, R_AX_PWR_UL_CTRL0, 0x0002f8ff);
2037af0cac15SPing-Ke Shih 	if (ret)
2038af0cac15SPing-Ke Shih 		return ret;
2039af0cac15SPing-Ke Shih 
2040af0cac15SPing-Ke Shih 	rtw8852c_set_txpwr_ul_tb_offset(rtwdev, 0, phy_idx == RTW89_PHY_1 ?
2041af0cac15SPing-Ke Shih 							      RTW89_MAC_1 :
2042af0cac15SPing-Ke Shih 							      RTW89_MAC_0);
2043af0cac15SPing-Ke Shih 	rtw8852c_init_tssi_ctrl(rtwdev, phy_idx);
2044af0cac15SPing-Ke Shih 
2045af0cac15SPing-Ke Shih 	return 0;
2046af0cac15SPing-Ke Shih }
2047af0cac15SPing-Ke Shih 
rtw8852c_bb_cfg_rx_path(struct rtw89_dev * rtwdev,u8 rx_path)2048cd89a471SPing-Ke Shih static void rtw8852c_bb_cfg_rx_path(struct rtw89_dev *rtwdev, u8 rx_path)
2049cd89a471SPing-Ke Shih {
2050cbb145b9SZong-Zhe Yang 	const struct rtw89_chan *chan = rtw89_chan_get(rtwdev, RTW89_SUB_ENTITY_0);
2051cbb145b9SZong-Zhe Yang 	u8 band = chan->band_type;
2052cd89a471SPing-Ke Shih 	u32 rst_mask0 = B_P0_TXPW_RSTB_MANON | B_P0_TXPW_RSTB_TSSI;
2053cd89a471SPing-Ke Shih 	u32 rst_mask1 = B_P1_TXPW_RSTB_MANON | B_P1_TXPW_RSTB_TSSI;
2054cd89a471SPing-Ke Shih 
2055cd89a471SPing-Ke Shih 	if (rtwdev->dbcc_en) {
2056cd89a471SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_CHBW_MOD, B_ANT_RX_SEG0, 1);
2057cd89a471SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD, B_ANT_RX_SEG0, 2,
2058cd89a471SPing-Ke Shih 				      RTW89_PHY_1);
2059cd89a471SPing-Ke Shih 
2060cd89a471SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_FC0_BW, B_ANT_RX_1RCCA_SEG0,
2061cd89a471SPing-Ke Shih 				       1);
2062cd89a471SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_FC0_BW, B_ANT_RX_1RCCA_SEG1,
2063cd89a471SPing-Ke Shih 				       1);
2064cd89a471SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_FC0_BW, B_ANT_RX_1RCCA_SEG0, 2,
2065cd89a471SPing-Ke Shih 				      RTW89_PHY_1);
2066cd89a471SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_FC0_BW, B_ANT_RX_1RCCA_SEG1, 2,
2067cd89a471SPing-Ke Shih 				      RTW89_PHY_1);
2068cd89a471SPing-Ke Shih 
2069cd89a471SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_RXHT_MCS_LIMIT,
2070cd89a471SPing-Ke Shih 				       B_RXHT_MCS_LIMIT, 0);
2071cd89a471SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_RXVHT_MCS_LIMIT,
2072cd89a471SPing-Ke Shih 				       B_RXVHT_MCS_LIMIT, 0);
2073cd89a471SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_USER_MAX, 8);
2074cd89a471SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_MAX_NSS, 0);
2075cd89a471SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHETB_MAX_NSS, 0);
2076cd89a471SPing-Ke Shih 
2077cd89a471SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_RXHT_MCS_LIMIT,
2078cd89a471SPing-Ke Shih 				      B_RXHT_MCS_LIMIT, 0, RTW89_PHY_1);
2079cd89a471SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_RXVHT_MCS_LIMIT,
2080cd89a471SPing-Ke Shih 				      B_RXVHT_MCS_LIMIT, 0, RTW89_PHY_1);
2081cd89a471SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_RXHE, B_RXHE_USER_MAX, 1,
2082cd89a471SPing-Ke Shih 				      RTW89_PHY_1);
2083cd89a471SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_RXHE, B_RXHE_MAX_NSS, 0,
2084cd89a471SPing-Ke Shih 				      RTW89_PHY_1);
2085cd89a471SPing-Ke Shih 		rtw89_phy_write32_idx(rtwdev, R_RXHE, B_RXHETB_MAX_NSS, 0,
2086cd89a471SPing-Ke Shih 				      RTW89_PHY_1);
2087cd89a471SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_P0_TXPW_RSTB, rst_mask0, 1);
2088cd89a471SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_P0_TXPW_RSTB, rst_mask0, 3);
2089cd89a471SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_P1_TXPW_RSTB, rst_mask1, 1);
2090cd89a471SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_P1_TXPW_RSTB, rst_mask1, 3);
2091cd89a471SPing-Ke Shih 	} else {
2092cd89a471SPing-Ke Shih 		if (rx_path == RF_PATH_A) {
2093cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_CHBW_MOD,
2094cd89a471SPing-Ke Shih 					       B_ANT_RX_SEG0, 1);
2095cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_FC0_BW,
2096cd89a471SPing-Ke Shih 					       B_ANT_RX_1RCCA_SEG0, 1);
2097cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_FC0_BW,
2098cd89a471SPing-Ke Shih 					       B_ANT_RX_1RCCA_SEG1, 1);
2099cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_RXHT_MCS_LIMIT,
2100cd89a471SPing-Ke Shih 					       B_RXHT_MCS_LIMIT, 0);
2101cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_RXVHT_MCS_LIMIT,
2102cd89a471SPing-Ke Shih 					       B_RXVHT_MCS_LIMIT, 0);
2103cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_MAX_NSS,
2104cd89a471SPing-Ke Shih 					       0);
2105cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHETB_MAX_NSS,
2106cd89a471SPing-Ke Shih 					       0);
2107cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_P0_TXPW_RSTB,
2108cd89a471SPing-Ke Shih 					       rst_mask0, 1);
2109cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_P0_TXPW_RSTB,
2110cd89a471SPing-Ke Shih 					       rst_mask0, 3);
2111cd89a471SPing-Ke Shih 		} else if (rx_path == RF_PATH_B) {
2112cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_CHBW_MOD,
2113cd89a471SPing-Ke Shih 					       B_ANT_RX_SEG0, 2);
2114cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_FC0_BW,
2115cd89a471SPing-Ke Shih 					       B_ANT_RX_1RCCA_SEG0, 2);
2116cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_FC0_BW,
2117cd89a471SPing-Ke Shih 					       B_ANT_RX_1RCCA_SEG1, 2);
2118cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_RXHT_MCS_LIMIT,
2119cd89a471SPing-Ke Shih 					       B_RXHT_MCS_LIMIT, 0);
2120cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_RXVHT_MCS_LIMIT,
2121cd89a471SPing-Ke Shih 					       B_RXVHT_MCS_LIMIT, 0);
2122cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_MAX_NSS,
2123cd89a471SPing-Ke Shih 					       0);
2124cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHETB_MAX_NSS,
2125cd89a471SPing-Ke Shih 					       0);
2126cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_P1_TXPW_RSTB,
2127cd89a471SPing-Ke Shih 					       rst_mask1, 1);
2128cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_P1_TXPW_RSTB,
2129cd89a471SPing-Ke Shih 					       rst_mask1, 3);
2130cd89a471SPing-Ke Shih 		} else {
2131cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_CHBW_MOD,
2132cd89a471SPing-Ke Shih 					       B_ANT_RX_SEG0, 3);
2133cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_FC0_BW,
2134cd89a471SPing-Ke Shih 					       B_ANT_RX_1RCCA_SEG0, 3);
2135cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_FC0_BW,
2136cd89a471SPing-Ke Shih 					       B_ANT_RX_1RCCA_SEG1, 3);
2137cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_RXHT_MCS_LIMIT,
2138cd89a471SPing-Ke Shih 					       B_RXHT_MCS_LIMIT, 1);
2139cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_RXVHT_MCS_LIMIT,
2140cd89a471SPing-Ke Shih 					       B_RXVHT_MCS_LIMIT, 1);
2141cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_MAX_NSS,
2142cd89a471SPing-Ke Shih 					       1);
2143cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHETB_MAX_NSS,
2144cd89a471SPing-Ke Shih 					       1);
2145cbb145b9SZong-Zhe Yang 			rtw8852c_ctrl_btg(rtwdev, band == RTW89_BAND_2G);
2146cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_P0_TXPW_RSTB,
2147cd89a471SPing-Ke Shih 					       rst_mask0, 1);
2148cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_P0_TXPW_RSTB,
2149cd89a471SPing-Ke Shih 					       rst_mask0, 3);
2150cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_P1_TXPW_RSTB,
2151cd89a471SPing-Ke Shih 					       rst_mask1, 1);
2152cd89a471SPing-Ke Shih 			rtw89_phy_write32_mask(rtwdev, R_P1_TXPW_RSTB,
2153cd89a471SPing-Ke Shih 					       rst_mask1, 3);
2154cd89a471SPing-Ke Shih 		}
2155cd89a471SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_USER_MAX, 8);
2156cd89a471SPing-Ke Shih 	}
2157cd89a471SPing-Ke Shih }
2158cd89a471SPing-Ke Shih 
rtw8852c_ctrl_tx_path_tmac(struct rtw89_dev * rtwdev,u8 tx_path,enum rtw89_mac_idx mac_idx)2159cd89a471SPing-Ke Shih static void rtw8852c_ctrl_tx_path_tmac(struct rtw89_dev *rtwdev, u8 tx_path,
2160cd89a471SPing-Ke Shih 				       enum rtw89_mac_idx mac_idx)
2161cd89a471SPing-Ke Shih {
2162cd89a471SPing-Ke Shih 	struct rtw89_reg2_def path_com[] = {
2163cd89a471SPing-Ke Shih 		{R_AX_PATH_COM0, AX_PATH_COM0_DFVAL},
2164cd89a471SPing-Ke Shih 		{R_AX_PATH_COM1, AX_PATH_COM1_DFVAL},
2165cd89a471SPing-Ke Shih 		{R_AX_PATH_COM2, AX_PATH_COM2_DFVAL},
2166cd89a471SPing-Ke Shih 		{R_AX_PATH_COM3, AX_PATH_COM3_DFVAL},
2167cd89a471SPing-Ke Shih 		{R_AX_PATH_COM4, AX_PATH_COM4_DFVAL},
2168cd89a471SPing-Ke Shih 		{R_AX_PATH_COM5, AX_PATH_COM5_DFVAL},
2169cd89a471SPing-Ke Shih 		{R_AX_PATH_COM6, AX_PATH_COM6_DFVAL},
2170cd89a471SPing-Ke Shih 		{R_AX_PATH_COM7, AX_PATH_COM7_DFVAL},
2171cd89a471SPing-Ke Shih 		{R_AX_PATH_COM8, AX_PATH_COM8_DFVAL},
2172cd89a471SPing-Ke Shih 		{R_AX_PATH_COM9, AX_PATH_COM9_DFVAL},
2173cd89a471SPing-Ke Shih 		{R_AX_PATH_COM10, AX_PATH_COM10_DFVAL},
2174cd89a471SPing-Ke Shih 		{R_AX_PATH_COM11, AX_PATH_COM11_DFVAL},
2175cd89a471SPing-Ke Shih 	};
2176cd89a471SPing-Ke Shih 	u32 addr;
2177cd89a471SPing-Ke Shih 	u32 reg;
2178cd89a471SPing-Ke Shih 	u8 cr_size = ARRAY_SIZE(path_com);
2179cd89a471SPing-Ke Shih 	u8 i = 0;
2180cd89a471SPing-Ke Shih 
2181cd89a471SPing-Ke Shih 	rtw89_phy_write32_idx(rtwdev, R_MAC_SEL, B_MAC_SEL_MOD, 0, RTW89_PHY_0);
2182cd89a471SPing-Ke Shih 	rtw89_phy_write32_idx(rtwdev, R_MAC_SEL, B_MAC_SEL_MOD, 0, RTW89_PHY_1);
2183cd89a471SPing-Ke Shih 
2184cd89a471SPing-Ke Shih 	for (addr = R_AX_MACID_ANT_TABLE;
2185cd89a471SPing-Ke Shih 	     addr <= R_AX_MACID_ANT_TABLE_LAST; addr += 4) {
2186c220d08eSPing-Ke Shih 		reg = rtw89_mac_reg_by_idx(rtwdev, addr, mac_idx);
2187cd89a471SPing-Ke Shih 		rtw89_write32(rtwdev, reg, 0);
2188cd89a471SPing-Ke Shih 	}
2189cd89a471SPing-Ke Shih 
2190d3efeee2SPing-Ke Shih 	if (tx_path == RF_A) {
2191cd89a471SPing-Ke Shih 		path_com[0].data = AX_PATH_COM0_PATHA;
2192cd89a471SPing-Ke Shih 		path_com[1].data = AX_PATH_COM1_PATHA;
2193cd89a471SPing-Ke Shih 		path_com[2].data = AX_PATH_COM2_PATHA;
2194cd89a471SPing-Ke Shih 		path_com[7].data = AX_PATH_COM7_PATHA;
2195cd89a471SPing-Ke Shih 		path_com[8].data = AX_PATH_COM8_PATHA;
2196d3efeee2SPing-Ke Shih 	} else if (tx_path == RF_B) {
2197cd89a471SPing-Ke Shih 		path_com[0].data = AX_PATH_COM0_PATHB;
2198cd89a471SPing-Ke Shih 		path_com[1].data = AX_PATH_COM1_PATHB;
2199cd89a471SPing-Ke Shih 		path_com[2].data = AX_PATH_COM2_PATHB;
2200cd89a471SPing-Ke Shih 		path_com[7].data = AX_PATH_COM7_PATHB;
2201cd89a471SPing-Ke Shih 		path_com[8].data = AX_PATH_COM8_PATHB;
2202d3efeee2SPing-Ke Shih 	} else if (tx_path == RF_AB) {
2203cd89a471SPing-Ke Shih 		path_com[0].data = AX_PATH_COM0_PATHAB;
2204cd89a471SPing-Ke Shih 		path_com[1].data = AX_PATH_COM1_PATHAB;
2205cd89a471SPing-Ke Shih 		path_com[2].data = AX_PATH_COM2_PATHAB;
2206cd89a471SPing-Ke Shih 		path_com[7].data = AX_PATH_COM7_PATHAB;
2207cd89a471SPing-Ke Shih 		path_com[8].data = AX_PATH_COM8_PATHAB;
2208cd89a471SPing-Ke Shih 	} else {
2209cd89a471SPing-Ke Shih 		rtw89_warn(rtwdev, "[Invalid Tx Path]Tx Path: %d\n", tx_path);
2210cd89a471SPing-Ke Shih 		return;
2211cd89a471SPing-Ke Shih 	}
2212cd89a471SPing-Ke Shih 
2213cd89a471SPing-Ke Shih 	for (i = 0; i < cr_size; i++) {
2214cd89a471SPing-Ke Shih 		rtw89_debug(rtwdev, RTW89_DBG_TSSI, "0x%x = 0x%x\n",
2215cd89a471SPing-Ke Shih 			    path_com[i].addr, path_com[i].data);
2216c220d08eSPing-Ke Shih 		reg = rtw89_mac_reg_by_idx(rtwdev, path_com[i].addr, mac_idx);
2217cd89a471SPing-Ke Shih 		rtw89_write32(rtwdev, reg, path_com[i].data);
2218cd89a471SPing-Ke Shih 	}
2219cd89a471SPing-Ke Shih }
2220cd89a471SPing-Ke Shih 
rtw8852c_bb_ctrl_btc_preagc(struct rtw89_dev * rtwdev,bool bt_en)2221e212d5d4SPing-Ke Shih static void rtw8852c_bb_ctrl_btc_preagc(struct rtw89_dev *rtwdev, bool bt_en)
2222e212d5d4SPing-Ke Shih {
2223e212d5d4SPing-Ke Shih 	if (bt_en) {
2224e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_FRC_FIR_TYPE_V1,
2225e212d5d4SPing-Ke Shih 				       B_PATH0_FRC_FIR_TYPE_MSK_V1, 0x3);
2226e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_FRC_FIR_TYPE_V1,
2227e212d5d4SPing-Ke Shih 				       B_PATH1_FRC_FIR_TYPE_MSK_V1, 0x3);
2228e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_RXBB_V1,
2229e212d5d4SPing-Ke Shih 				       B_PATH0_RXBB_MSK_V1, 0xf);
2230e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_RXBB_V1,
2231e212d5d4SPing-Ke Shih 				       B_PATH1_RXBB_MSK_V1, 0xf);
2232e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_G_LNA6_OP1DB_V1,
2233e212d5d4SPing-Ke Shih 				       B_PATH0_G_LNA6_OP1DB_V1, 0x80);
2234e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_G_LNA6_OP1DB_V1,
2235e212d5d4SPing-Ke Shih 				       B_PATH1_G_LNA6_OP1DB_V1, 0x80);
2236e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_G_TIA0_LNA6_OP1DB_V1,
2237e212d5d4SPing-Ke Shih 				       B_PATH0_G_TIA0_LNA6_OP1DB_V1, 0x80);
2238e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_G_TIA1_LNA6_OP1DB_V1,
2239e212d5d4SPing-Ke Shih 				       B_PATH0_G_TIA1_LNA6_OP1DB_V1, 0x80);
2240e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_G_TIA0_LNA6_OP1DB_V1,
2241e212d5d4SPing-Ke Shih 				       B_PATH1_G_TIA0_LNA6_OP1DB_V1, 0x80);
2242e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_G_TIA1_LNA6_OP1DB_V1,
2243e212d5d4SPing-Ke Shih 				       B_PATH1_G_TIA1_LNA6_OP1DB_V1, 0x80);
2244e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_BT_BACKOFF_V1,
2245e212d5d4SPing-Ke Shih 				       B_PATH0_BT_BACKOFF_V1, 0x780D1E);
2246e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_BT_BACKOFF_V1,
2247e212d5d4SPing-Ke Shih 				       B_PATH1_BT_BACKOFF_V1, 0x780D1E);
2248e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_P0_BACKOFF_IBADC_V1,
2249e212d5d4SPing-Ke Shih 				       B_P0_BACKOFF_IBADC_V1, 0x34);
2250e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_P1_BACKOFF_IBADC_V1,
2251e212d5d4SPing-Ke Shih 				       B_P1_BACKOFF_IBADC_V1, 0x34);
2252e212d5d4SPing-Ke Shih 	} else {
2253e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_FRC_FIR_TYPE_V1,
2254e212d5d4SPing-Ke Shih 				       B_PATH0_FRC_FIR_TYPE_MSK_V1, 0x0);
2255e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_FRC_FIR_TYPE_V1,
2256e212d5d4SPing-Ke Shih 				       B_PATH1_FRC_FIR_TYPE_MSK_V1, 0x0);
2257e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_RXBB_V1,
2258e212d5d4SPing-Ke Shih 				       B_PATH0_RXBB_MSK_V1, 0x60);
2259e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_RXBB_V1,
2260e212d5d4SPing-Ke Shih 				       B_PATH1_RXBB_MSK_V1, 0x60);
2261e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_G_LNA6_OP1DB_V1,
2262e212d5d4SPing-Ke Shih 				       B_PATH0_G_LNA6_OP1DB_V1, 0x1a);
2263e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_G_LNA6_OP1DB_V1,
2264e212d5d4SPing-Ke Shih 				       B_PATH1_G_LNA6_OP1DB_V1, 0x1a);
2265e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_G_TIA0_LNA6_OP1DB_V1,
2266e212d5d4SPing-Ke Shih 				       B_PATH0_G_TIA0_LNA6_OP1DB_V1, 0x2a);
2267e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_G_TIA1_LNA6_OP1DB_V1,
2268e212d5d4SPing-Ke Shih 				       B_PATH0_G_TIA1_LNA6_OP1DB_V1, 0x2a);
2269e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_G_TIA0_LNA6_OP1DB_V1,
2270e212d5d4SPing-Ke Shih 				       B_PATH1_G_TIA0_LNA6_OP1DB_V1, 0x2a);
2271e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_G_TIA1_LNA6_OP1DB_V1,
2272e212d5d4SPing-Ke Shih 				       B_PATH1_G_TIA1_LNA6_OP1DB_V1, 0x2a);
2273e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_BT_BACKOFF_V1,
2274e212d5d4SPing-Ke Shih 				       B_PATH0_BT_BACKOFF_V1, 0x79E99E);
2275e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_BT_BACKOFF_V1,
2276e212d5d4SPing-Ke Shih 				       B_PATH1_BT_BACKOFF_V1, 0x79E99E);
2277e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_P0_BACKOFF_IBADC_V1,
2278e212d5d4SPing-Ke Shih 				       B_P0_BACKOFF_IBADC_V1, 0x26);
2279e212d5d4SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_P1_BACKOFF_IBADC_V1,
2280e212d5d4SPing-Ke Shih 				       B_P1_BACKOFF_IBADC_V1, 0x26);
2281e212d5d4SPing-Ke Shih 	}
2282e212d5d4SPing-Ke Shih }
2283e212d5d4SPing-Ke Shih 
rtw8852c_bb_cfg_txrx_path(struct rtw89_dev * rtwdev)2284cd89a471SPing-Ke Shih static void rtw8852c_bb_cfg_txrx_path(struct rtw89_dev *rtwdev)
2285cd89a471SPing-Ke Shih {
2286cd89a471SPing-Ke Shih 	struct rtw89_hal *hal = &rtwdev->hal;
2287cd89a471SPing-Ke Shih 
2288cd89a471SPing-Ke Shih 	rtw8852c_bb_cfg_rx_path(rtwdev, RF_PATH_AB);
2289cd89a471SPing-Ke Shih 
2290cd89a471SPing-Ke Shih 	if (hal->rx_nss == 1) {
2291cd89a471SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_RXHT_MCS_LIMIT, B_RXHT_MCS_LIMIT, 0);
2292cd89a471SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_RXVHT_MCS_LIMIT, B_RXVHT_MCS_LIMIT, 0);
2293cd89a471SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_MAX_NSS, 0);
2294cd89a471SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHETB_MAX_NSS, 0);
2295cd89a471SPing-Ke Shih 	} else {
2296cd89a471SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_RXHT_MCS_LIMIT, B_RXHT_MCS_LIMIT, 1);
2297cd89a471SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_RXVHT_MCS_LIMIT, B_RXVHT_MCS_LIMIT, 1);
2298cd89a471SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_MAX_NSS, 1);
2299cd89a471SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHETB_MAX_NSS, 1);
2300cd89a471SPing-Ke Shih 	}
2301cd89a471SPing-Ke Shih }
2302cd89a471SPing-Ke Shih 
rtw8852c_get_thermal(struct rtw89_dev * rtwdev,enum rtw89_rf_path rf_path)23033ecca403SPing-Ke Shih static u8 rtw8852c_get_thermal(struct rtw89_dev *rtwdev, enum rtw89_rf_path rf_path)
23043ecca403SPing-Ke Shih {
23053ecca403SPing-Ke Shih 	rtw89_write_rf(rtwdev, rf_path, RR_TM, RR_TM_TRI, 0x1);
23063ecca403SPing-Ke Shih 	rtw89_write_rf(rtwdev, rf_path, RR_TM, RR_TM_TRI, 0x0);
23073ecca403SPing-Ke Shih 	rtw89_write_rf(rtwdev, rf_path, RR_TM, RR_TM_TRI, 0x1);
23083ecca403SPing-Ke Shih 
23093ecca403SPing-Ke Shih 	fsleep(200);
23103ecca403SPing-Ke Shih 
23113ecca403SPing-Ke Shih 	return rtw89_read_rf(rtwdev, rf_path, RR_TM, RR_TM_VAL);
23123ecca403SPing-Ke Shih }
23133ecca403SPing-Ke Shih 
rtw8852c_btc_set_rfe(struct rtw89_dev * rtwdev)23142fb822f8SPing-Ke Shih static void rtw8852c_btc_set_rfe(struct rtw89_dev *rtwdev)
23152fb822f8SPing-Ke Shih {
23162fb822f8SPing-Ke Shih 	struct rtw89_btc *btc = &rtwdev->btc;
23172fb822f8SPing-Ke Shih 	struct rtw89_btc_module *module = &btc->mdinfo;
23182fb822f8SPing-Ke Shih 
23192fb822f8SPing-Ke Shih 	module->rfe_type = rtwdev->efuse.rfe_type;
23202fb822f8SPing-Ke Shih 	module->cv = rtwdev->hal.cv;
23212fb822f8SPing-Ke Shih 	module->bt_solo = 0;
23222fb822f8SPing-Ke Shih 	module->switch_type = BTC_SWITCH_INTERNAL;
23232fb822f8SPing-Ke Shih 
23242fb822f8SPing-Ke Shih 	if (module->rfe_type > 0)
23252fb822f8SPing-Ke Shih 		module->ant.num = (module->rfe_type % 2 ? 2 : 3);
23262fb822f8SPing-Ke Shih 	else
23272fb822f8SPing-Ke Shih 		module->ant.num = 2;
23282fb822f8SPing-Ke Shih 
23292fb822f8SPing-Ke Shih 	module->ant.diversity = 0;
23302fb822f8SPing-Ke Shih 	module->ant.isolation = 10;
23312fb822f8SPing-Ke Shih 
23322fb822f8SPing-Ke Shih 	if (module->ant.num == 3) {
23332fb822f8SPing-Ke Shih 		module->ant.type = BTC_ANT_DEDICATED;
23342fb822f8SPing-Ke Shih 		module->bt_pos = BTC_BT_ALONE;
23352fb822f8SPing-Ke Shih 	} else {
23362fb822f8SPing-Ke Shih 		module->ant.type = BTC_ANT_SHARED;
23372fb822f8SPing-Ke Shih 		module->bt_pos = BTC_BT_BTG;
23382fb822f8SPing-Ke Shih 	}
23392fb822f8SPing-Ke Shih }
23402fb822f8SPing-Ke Shih 
rtw8852c_ctrl_btg(struct rtw89_dev * rtwdev,bool btg)23411b00e923SPing-Ke Shih static void rtw8852c_ctrl_btg(struct rtw89_dev *rtwdev, bool btg)
23421b00e923SPing-Ke Shih {
23431b00e923SPing-Ke Shih 	if (btg) {
23441b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_BT_SHARE_V1,
23451b00e923SPing-Ke Shih 				       B_PATH0_BT_SHARE_V1, 0x1);
23461b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_BTG_PATH_V1,
23471b00e923SPing-Ke Shih 				       B_PATH0_BTG_PATH_V1, 0x0);
23481b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_G_LNA6_OP1DB_V1,
23491b00e923SPing-Ke Shih 				       B_PATH1_G_LNA6_OP1DB_V1, 0x20);
23501b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_G_TIA0_LNA6_OP1DB_V1,
23511b00e923SPing-Ke Shih 				       B_PATH1_G_TIA0_LNA6_OP1DB_V1, 0x30);
23521b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_BT_SHARE_V1,
23531b00e923SPing-Ke Shih 				       B_PATH1_BT_SHARE_V1, 0x1);
23541b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_BTG_PATH_V1,
23551b00e923SPing-Ke Shih 				       B_PATH1_BTG_PATH_V1, 0x1);
23561b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PMAC_GNT, B_PMAC_GNT_P1, 0x0);
23571b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_CHBW_MOD, B_BT_SHARE, 0x1);
23581b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_FC0_BW, B_ANT_RX_BT_SEG0, 0x2);
23591b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_BT_DYN_DC_EST_EN,
23601b00e923SPing-Ke Shih 				       B_BT_DYN_DC_EST_EN_MSK, 0x1);
23611b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_GNT_BT_WGT_EN, B_GNT_BT_WGT_EN,
23621b00e923SPing-Ke Shih 				       0x1);
23631b00e923SPing-Ke Shih 	} else {
23641b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_BT_SHARE_V1,
23651b00e923SPing-Ke Shih 				       B_PATH0_BT_SHARE_V1, 0x0);
23661b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH0_BTG_PATH_V1,
23671b00e923SPing-Ke Shih 				       B_PATH0_BTG_PATH_V1, 0x0);
23681b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_G_LNA6_OP1DB_V1,
23691b00e923SPing-Ke Shih 				       B_PATH1_G_LNA6_OP1DB_V1, 0x1a);
23701b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_G_TIA0_LNA6_OP1DB_V1,
23711b00e923SPing-Ke Shih 				       B_PATH1_G_TIA0_LNA6_OP1DB_V1, 0x2a);
23721b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_BT_SHARE_V1,
23731b00e923SPing-Ke Shih 				       B_PATH1_BT_SHARE_V1, 0x0);
23741b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PATH1_BTG_PATH_V1,
23751b00e923SPing-Ke Shih 				       B_PATH1_BTG_PATH_V1, 0x0);
23761b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PMAC_GNT, B_PMAC_GNT_P1, 0xf);
23771b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_PMAC_GNT, B_PMAC_GNT_P2, 0x4);
23781b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_CHBW_MOD, B_BT_SHARE, 0x0);
23791b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_FC0_BW, B_ANT_RX_BT_SEG0, 0x0);
23801b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_BT_DYN_DC_EST_EN,
23811b00e923SPing-Ke Shih 				       B_BT_DYN_DC_EST_EN_MSK, 0x0);
23821b00e923SPing-Ke Shih 		rtw89_phy_write32_mask(rtwdev, R_GNT_BT_WGT_EN, B_GNT_BT_WGT_EN,
23831b00e923SPing-Ke Shih 				       0x0);
23841b00e923SPing-Ke Shih 	}
23851b00e923SPing-Ke Shih }
23861b00e923SPing-Ke Shih 
2387065cf8f9SChia-Yuan Li static
rtw8852c_set_trx_mask(struct rtw89_dev * rtwdev,u8 path,u8 group,u32 val)2388065cf8f9SChia-Yuan Li void rtw8852c_set_trx_mask(struct rtw89_dev *rtwdev, u8 path, u8 group, u32 val)
2389065cf8f9SChia-Yuan Li {
2390065cf8f9SChia-Yuan Li 	rtw89_write_rf(rtwdev, path, RR_LUTWE, RFREG_MASK, 0x20000);
2391065cf8f9SChia-Yuan Li 	rtw89_write_rf(rtwdev, path, RR_LUTWA, RFREG_MASK, group);
2392065cf8f9SChia-Yuan Li 	rtw89_write_rf(rtwdev, path, RR_LUTWD0, RFREG_MASK, val);
2393065cf8f9SChia-Yuan Li 	rtw89_write_rf(rtwdev, path, RR_LUTWE, RFREG_MASK, 0x0);
2394065cf8f9SChia-Yuan Li }
2395065cf8f9SChia-Yuan Li 
rtw8852c_btc_init_cfg(struct rtw89_dev * rtwdev)2396065cf8f9SChia-Yuan Li static void rtw8852c_btc_init_cfg(struct rtw89_dev *rtwdev)
2397065cf8f9SChia-Yuan Li {
2398065cf8f9SChia-Yuan Li 	struct rtw89_btc *btc = &rtwdev->btc;
2399065cf8f9SChia-Yuan Li 	struct rtw89_btc_module *module = &btc->mdinfo;
2400065cf8f9SChia-Yuan Li 	const struct rtw89_chip_info *chip = rtwdev->chip;
2401065cf8f9SChia-Yuan Li 	const struct rtw89_mac_ax_coex coex_params = {
2402065cf8f9SChia-Yuan Li 		.pta_mode = RTW89_MAC_AX_COEX_RTK_MODE,
2403065cf8f9SChia-Yuan Li 		.direction = RTW89_MAC_AX_COEX_INNER,
2404065cf8f9SChia-Yuan Li 	};
2405065cf8f9SChia-Yuan Li 
2406065cf8f9SChia-Yuan Li 	/* PTA init  */
2407065cf8f9SChia-Yuan Li 	rtw89_mac_coex_init_v1(rtwdev, &coex_params);
2408065cf8f9SChia-Yuan Li 
2409065cf8f9SChia-Yuan Li 	/* set WL Tx response = Hi-Pri */
2410065cf8f9SChia-Yuan Li 	chip->ops->btc_set_wl_pri(rtwdev, BTC_PRI_MASK_TX_RESP, true);
2411065cf8f9SChia-Yuan Li 	chip->ops->btc_set_wl_pri(rtwdev, BTC_PRI_MASK_BEACON, true);
2412065cf8f9SChia-Yuan Li 
2413065cf8f9SChia-Yuan Li 	/* set rf gnt debug off */
2414065cf8f9SChia-Yuan Li 	rtw89_write_rf(rtwdev, RF_PATH_A, RR_WLSEL, RFREG_MASK, 0x0);
2415065cf8f9SChia-Yuan Li 	rtw89_write_rf(rtwdev, RF_PATH_B, RR_WLSEL, RFREG_MASK, 0x0);
2416065cf8f9SChia-Yuan Li 
2417065cf8f9SChia-Yuan Li 	/* set WL Tx thru in TRX mask table if GNT_WL = 0 && BT_S1 = ss group */
2418065cf8f9SChia-Yuan Li 	if (module->ant.type == BTC_ANT_SHARED) {
2419065cf8f9SChia-Yuan Li 		rtw8852c_set_trx_mask(rtwdev,
2420065cf8f9SChia-Yuan Li 				      RF_PATH_A, BTC_BT_SS_GROUP, 0x5ff);
2421065cf8f9SChia-Yuan Li 		rtw8852c_set_trx_mask(rtwdev,
2422065cf8f9SChia-Yuan Li 				      RF_PATH_B, BTC_BT_SS_GROUP, 0x5ff);
2423065cf8f9SChia-Yuan Li 		/* set path-A(S0) Tx/Rx no-mask if GNT_WL=0 && BT_S1=tx group */
2424065cf8f9SChia-Yuan Li 		rtw8852c_set_trx_mask(rtwdev,
2425065cf8f9SChia-Yuan Li 				      RF_PATH_A, BTC_BT_TX_GROUP, 0x5ff);
2426065cf8f9SChia-Yuan Li 	} else { /* set WL Tx stb if GNT_WL = 0 && BT_S1 = ss group for 3-ant */
2427065cf8f9SChia-Yuan Li 		rtw8852c_set_trx_mask(rtwdev,
2428065cf8f9SChia-Yuan Li 				      RF_PATH_A, BTC_BT_SS_GROUP, 0x5df);
2429065cf8f9SChia-Yuan Li 		rtw8852c_set_trx_mask(rtwdev,
2430065cf8f9SChia-Yuan Li 				      RF_PATH_B, BTC_BT_SS_GROUP, 0x5df);
2431065cf8f9SChia-Yuan Li 	}
2432065cf8f9SChia-Yuan Li 
2433065cf8f9SChia-Yuan Li 	/* set PTA break table */
2434065cf8f9SChia-Yuan Li 	rtw89_write32(rtwdev, R_AX_BT_BREAK_TABLE, BTC_BREAK_PARAM);
2435065cf8f9SChia-Yuan Li 
2436065cf8f9SChia-Yuan Li 	 /* enable BT counter 0xda10[1:0] = 2b'11 */
2437065cf8f9SChia-Yuan Li 	rtw89_write32_set(rtwdev,
2438065cf8f9SChia-Yuan Li 			  R_AX_BT_CNT_CFG, B_AX_BT_CNT_EN |
2439065cf8f9SChia-Yuan Li 			  B_AX_BT_CNT_RST_V1);
2440065cf8f9SChia-Yuan Li 	btc->cx.wl.status.map.init_ok = true;
2441065cf8f9SChia-Yuan Li }
2442065cf8f9SChia-Yuan Li 
24432fb822f8SPing-Ke Shih static
rtw8852c_btc_set_wl_pri(struct rtw89_dev * rtwdev,u8 map,bool state)24442fb822f8SPing-Ke Shih void rtw8852c_btc_set_wl_pri(struct rtw89_dev *rtwdev, u8 map, bool state)
24452fb822f8SPing-Ke Shih {
24462fb822f8SPing-Ke Shih 	u32 bitmap = 0;
24472fb822f8SPing-Ke Shih 	u32 reg = 0;
24482fb822f8SPing-Ke Shih 
24492fb822f8SPing-Ke Shih 	switch (map) {
24502fb822f8SPing-Ke Shih 	case BTC_PRI_MASK_TX_RESP:
24512fb822f8SPing-Ke Shih 		reg = R_BTC_COEX_WL_REQ;
24522fb822f8SPing-Ke Shih 		bitmap = B_BTC_RSP_ACK_HI;
24532fb822f8SPing-Ke Shih 		break;
24542fb822f8SPing-Ke Shih 	case BTC_PRI_MASK_BEACON:
24552fb822f8SPing-Ke Shih 		reg = R_BTC_COEX_WL_REQ;
24562fb822f8SPing-Ke Shih 		bitmap = B_BTC_TX_BCN_HI;
24572fb822f8SPing-Ke Shih 		break;
24582fb822f8SPing-Ke Shih 	default:
24592fb822f8SPing-Ke Shih 		return;
24602fb822f8SPing-Ke Shih 	}
24612fb822f8SPing-Ke Shih 
24622fb822f8SPing-Ke Shih 	if (state)
24632fb822f8SPing-Ke Shih 		rtw89_write32_set(rtwdev, reg, bitmap);
24642fb822f8SPing-Ke Shih 	else
24652fb822f8SPing-Ke Shih 		rtw89_write32_clr(rtwdev, reg, bitmap);
24662fb822f8SPing-Ke Shih }
24672fb822f8SPing-Ke Shih 
24682fb822f8SPing-Ke Shih union rtw8852c_btc_wl_txpwr_ctrl {
24692fb822f8SPing-Ke Shih 	u32 txpwr_val;
24702fb822f8SPing-Ke Shih 	struct {
24712fb822f8SPing-Ke Shih 		union {
24722fb822f8SPing-Ke Shih 			u16 ctrl_all_time;
24732fb822f8SPing-Ke Shih 			struct {
24742fb822f8SPing-Ke Shih 				s16 data:9;
24752fb822f8SPing-Ke Shih 				u16 rsvd:6;
24762fb822f8SPing-Ke Shih 				u16 flag:1;
24772fb822f8SPing-Ke Shih 			} all_time;
24782fb822f8SPing-Ke Shih 		};
24792fb822f8SPing-Ke Shih 		union {
24802fb822f8SPing-Ke Shih 			u16 ctrl_gnt_bt;
24812fb822f8SPing-Ke Shih 			struct {
24822fb822f8SPing-Ke Shih 				s16 data:9;
24832fb822f8SPing-Ke Shih 				u16 rsvd:7;
24842fb822f8SPing-Ke Shih 			} gnt_bt;
24852fb822f8SPing-Ke Shih 		};
24862fb822f8SPing-Ke Shih 	};
24872fb822f8SPing-Ke Shih } __packed;
24882fb822f8SPing-Ke Shih 
24892fb822f8SPing-Ke Shih static void
rtw8852c_btc_set_wl_txpwr_ctrl(struct rtw89_dev * rtwdev,u32 txpwr_val)24902fb822f8SPing-Ke Shih rtw8852c_btc_set_wl_txpwr_ctrl(struct rtw89_dev *rtwdev, u32 txpwr_val)
24912fb822f8SPing-Ke Shih {
24922fb822f8SPing-Ke Shih 	union rtw8852c_btc_wl_txpwr_ctrl arg = { .txpwr_val = txpwr_val };
24932fb822f8SPing-Ke Shih 	s32 val;
24942fb822f8SPing-Ke Shih 
24952fb822f8SPing-Ke Shih #define __write_ctrl(_reg, _msk, _val, _en, _cond)		\
24962fb822f8SPing-Ke Shih do {								\
249768bf56e3SPing-Ke Shih 	u32 _wrt = FIELD_PREP(_msk, _val);			\
249868bf56e3SPing-Ke Shih 	BUILD_BUG_ON((_msk & _en) != 0);			\
24992fb822f8SPing-Ke Shih 	if (_cond)						\
250068bf56e3SPing-Ke Shih 		_wrt |= _en;					\
25012fb822f8SPing-Ke Shih 	else							\
250268bf56e3SPing-Ke Shih 		_wrt &= ~_en;					\
25032fb822f8SPing-Ke Shih 	rtw89_mac_txpwr_write32_mask(rtwdev, RTW89_PHY_0, _reg,	\
250468bf56e3SPing-Ke Shih 				     _msk | _en, _wrt);		\
25052fb822f8SPing-Ke Shih } while (0)
25062fb822f8SPing-Ke Shih 
25072fb822f8SPing-Ke Shih 	switch (arg.ctrl_all_time) {
25082fb822f8SPing-Ke Shih 	case 0xffff:
25092fb822f8SPing-Ke Shih 		val = 0;
25102fb822f8SPing-Ke Shih 		break;
25112fb822f8SPing-Ke Shih 	default:
25122fb822f8SPing-Ke Shih 		val = arg.all_time.data;
25132fb822f8SPing-Ke Shih 		break;
25142fb822f8SPing-Ke Shih 	}
25152fb822f8SPing-Ke Shih 
25162fb822f8SPing-Ke Shih 	__write_ctrl(R_AX_PWR_RATE_CTRL, B_AX_FORCE_PWR_BY_RATE_VALUE_MASK,
25172fb822f8SPing-Ke Shih 		     val, B_AX_FORCE_PWR_BY_RATE_EN,
25182fb822f8SPing-Ke Shih 		     arg.ctrl_all_time != 0xffff);
25192fb822f8SPing-Ke Shih 
25202fb822f8SPing-Ke Shih 	switch (arg.ctrl_gnt_bt) {
25212fb822f8SPing-Ke Shih 	case 0xffff:
25222fb822f8SPing-Ke Shih 		val = 0;
25232fb822f8SPing-Ke Shih 		break;
25242fb822f8SPing-Ke Shih 	default:
25252fb822f8SPing-Ke Shih 		val = arg.gnt_bt.data;
25262fb822f8SPing-Ke Shih 		break;
252711dc130bSYang Li 	}
25282fb822f8SPing-Ke Shih 
25292fb822f8SPing-Ke Shih 	__write_ctrl(R_AX_PWR_COEXT_CTRL, B_AX_TXAGC_BT_MASK, val,
25302fb822f8SPing-Ke Shih 		     B_AX_TXAGC_BT_EN, arg.ctrl_gnt_bt != 0xffff);
25312fb822f8SPing-Ke Shih 
25322fb822f8SPing-Ke Shih #undef __write_ctrl
25332fb822f8SPing-Ke Shih }
25342fb822f8SPing-Ke Shih 
25352fb822f8SPing-Ke Shih static
rtw8852c_btc_get_bt_rssi(struct rtw89_dev * rtwdev,s8 val)25362fb822f8SPing-Ke Shih s8 rtw8852c_btc_get_bt_rssi(struct rtw89_dev *rtwdev, s8 val)
25372fb822f8SPing-Ke Shih {
25382380a220SChing-Te Ku 	/* +6 for compensate offset */
25392380a220SChing-Te Ku 	return clamp_t(s8, val + 6, -100, 0) + 100;
25402fb822f8SPing-Ke Shih }
25412fb822f8SPing-Ke Shih 
254278af3cc6SPing-Ke Shih static const struct rtw89_btc_rf_trx_para rtw89_btc_8852c_rf_ul[] = {
254378af3cc6SPing-Ke Shih 	{255, 0, 0, 7}, /* 0 -> original */
254478af3cc6SPing-Ke Shih 	{255, 2, 0, 7}, /* 1 -> for BT-connected ACI issue && BTG co-rx */
254578af3cc6SPing-Ke Shih 	{255, 0, 0, 7}, /* 2 ->reserved for shared-antenna */
254678af3cc6SPing-Ke Shih 	{255, 0, 0, 7}, /* 3- >reserved for shared-antenna */
254778af3cc6SPing-Ke Shih 	{255, 0, 0, 7}, /* 4 ->reserved for shared-antenna */
254836ef71dbSChing-Te Ku 	{255, 1, 0, 7}, /* the below id is for non-shared-antenna free-run */
254978af3cc6SPing-Ke Shih 	{6, 1, 0, 7},
255078af3cc6SPing-Ke Shih 	{13, 1, 0, 7},
255178af3cc6SPing-Ke Shih 	{13, 1, 0, 7}
255278af3cc6SPing-Ke Shih };
255378af3cc6SPing-Ke Shih 
255478af3cc6SPing-Ke Shih static const struct rtw89_btc_rf_trx_para rtw89_btc_8852c_rf_dl[] = {
255578af3cc6SPing-Ke Shih 	{255, 0, 0, 7}, /* 0 -> original */
255678af3cc6SPing-Ke Shih 	{255, 2, 0, 7}, /* 1 -> reserved for shared-antenna */
255778af3cc6SPing-Ke Shih 	{255, 0, 0, 7}, /* 2 ->reserved for shared-antenna */
255878af3cc6SPing-Ke Shih 	{255, 0, 0, 7}, /* 3- >reserved for shared-antenna */
255978af3cc6SPing-Ke Shih 	{255, 0, 0, 7}, /* 4 ->reserved for shared-antenna */
256036ef71dbSChing-Te Ku 	{255, 1, 0, 7}, /* the below id is for non-shared-antenna free-run */
256178af3cc6SPing-Ke Shih 	{255, 1, 0, 7},
256278af3cc6SPing-Ke Shih 	{255, 1, 0, 7},
256378af3cc6SPing-Ke Shih 	{255, 1, 0, 7}
256478af3cc6SPing-Ke Shih };
256578af3cc6SPing-Ke Shih 
256678af3cc6SPing-Ke Shih static const u8 rtw89_btc_8852c_wl_rssi_thres[BTC_WL_RSSI_THMAX] = {60, 50, 40, 30};
256778af3cc6SPing-Ke Shih static const u8 rtw89_btc_8852c_bt_rssi_thres[BTC_BT_RSSI_THMAX] = {40, 36, 31, 28};
256878af3cc6SPing-Ke Shih 
256978af3cc6SPing-Ke Shih static const struct rtw89_btc_fbtc_mreg rtw89_btc_8852c_mon_reg[] = {
257078af3cc6SPing-Ke Shih 	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda00),
257178af3cc6SPing-Ke Shih 	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda04),
257278af3cc6SPing-Ke Shih 	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda24),
257378af3cc6SPing-Ke Shih 	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda30),
257478af3cc6SPing-Ke Shih 	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda34),
257578af3cc6SPing-Ke Shih 	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda38),
257678af3cc6SPing-Ke Shih 	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda44),
257778af3cc6SPing-Ke Shih 	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda48),
257878af3cc6SPing-Ke Shih 	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda4c),
257978af3cc6SPing-Ke Shih 	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xd200),
258078af3cc6SPing-Ke Shih 	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xd220),
258178af3cc6SPing-Ke Shih 	RTW89_DEF_FBTC_MREG(REG_BB, 4, 0x980),
25829fde3056SChing-Te Ku 	RTW89_DEF_FBTC_MREG(REG_BB, 4, 0x4aa4),
25839fde3056SChing-Te Ku 	RTW89_DEF_FBTC_MREG(REG_BB, 4, 0x4778),
25849fde3056SChing-Te Ku 	RTW89_DEF_FBTC_MREG(REG_BB, 4, 0x476c),
258578af3cc6SPing-Ke Shih };
258678af3cc6SPing-Ke Shih 
25872fb822f8SPing-Ke Shih static
rtw8852c_btc_update_bt_cnt(struct rtw89_dev * rtwdev)25882fb822f8SPing-Ke Shih void rtw8852c_btc_update_bt_cnt(struct rtw89_dev *rtwdev)
25892fb822f8SPing-Ke Shih {
25901162584cSChing-Te Ku 	/* Feature move to firmware */
25912fb822f8SPing-Ke Shih }
25922fb822f8SPing-Ke Shih 
25932fb822f8SPing-Ke Shih static
rtw8852c_btc_wl_s1_standby(struct rtw89_dev * rtwdev,bool state)25942fb822f8SPing-Ke Shih void rtw8852c_btc_wl_s1_standby(struct rtw89_dev *rtwdev, bool state)
25952fb822f8SPing-Ke Shih {
25962fb822f8SPing-Ke Shih 	rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWE, RFREG_MASK, 0x80000);
25972fb822f8SPing-Ke Shih 	rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x1);
25982fb822f8SPing-Ke Shih 	rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD1, RFREG_MASK, 0x620);
25992fb822f8SPing-Ke Shih 
26002fb822f8SPing-Ke Shih 	/* set WL standby = Rx for GNT_BT_Tx = 1->0 settle issue */
26012fb822f8SPing-Ke Shih 	if (state)
26022fb822f8SPing-Ke Shih 		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0,
26032fb822f8SPing-Ke Shih 			       RFREG_MASK, 0x179c);
26042fb822f8SPing-Ke Shih 	else
26052fb822f8SPing-Ke Shih 		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0,
26062fb822f8SPing-Ke Shih 			       RFREG_MASK, 0x208);
26072fb822f8SPing-Ke Shih 
26082fb822f8SPing-Ke Shih 	rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWE, RFREG_MASK, 0x0);
26092fb822f8SPing-Ke Shih }
26102fb822f8SPing-Ke Shih 
rtw8852c_set_wl_lna2(struct rtw89_dev * rtwdev,u8 level)2611f2fe93b3SChing-Te Ku static void rtw8852c_set_wl_lna2(struct rtw89_dev *rtwdev, u8 level)
2612f2fe93b3SChing-Te Ku {
2613f2fe93b3SChing-Te Ku 	/* level=0 Default:    TIA 1/0= (LNA2,TIAN6) = (7,1)/(5,1) = 21dB/12dB
2614f2fe93b3SChing-Te Ku 	 * level=1 Fix LNA2=5: TIA 1/0= (LNA2,TIAN6) = (5,0)/(5,1) = 18dB/12dB
2615f2fe93b3SChing-Te Ku 	 * To improve BT ACI in co-rx
2616f2fe93b3SChing-Te Ku 	 */
2617f2fe93b3SChing-Te Ku 
2618f2fe93b3SChing-Te Ku 	switch (level) {
2619f2fe93b3SChing-Te Ku 	case 0: /* default */
2620f2fe93b3SChing-Te Ku 		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWE, RFREG_MASK, 0x1000);
2621f2fe93b3SChing-Te Ku 		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x0);
2622f2fe93b3SChing-Te Ku 		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x15);
2623f2fe93b3SChing-Te Ku 		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x1);
2624f2fe93b3SChing-Te Ku 		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x17);
2625f2fe93b3SChing-Te Ku 		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x2);
2626f2fe93b3SChing-Te Ku 		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x15);
2627f2fe93b3SChing-Te Ku 		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x3);
2628f2fe93b3SChing-Te Ku 		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x17);
2629f2fe93b3SChing-Te Ku 		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWE, RFREG_MASK, 0x0);
2630f2fe93b3SChing-Te Ku 		break;
2631f2fe93b3SChing-Te Ku 	case 1: /* Fix LNA2=5  */
2632f2fe93b3SChing-Te Ku 		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWE, RFREG_MASK, 0x1000);
2633f2fe93b3SChing-Te Ku 		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x0);
2634f2fe93b3SChing-Te Ku 		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x15);
2635f2fe93b3SChing-Te Ku 		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x1);
2636f2fe93b3SChing-Te Ku 		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x5);
2637f2fe93b3SChing-Te Ku 		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x2);
2638f2fe93b3SChing-Te Ku 		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x15);
2639f2fe93b3SChing-Te Ku 		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x3);
2640f2fe93b3SChing-Te Ku 		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x5);
2641f2fe93b3SChing-Te Ku 		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWE, RFREG_MASK, 0x0);
2642f2fe93b3SChing-Te Ku 		break;
2643f2fe93b3SChing-Te Ku 	}
2644f2fe93b3SChing-Te Ku }
2645f2fe93b3SChing-Te Ku 
rtw8852c_btc_set_wl_rx_gain(struct rtw89_dev * rtwdev,u32 level)2646f2fe93b3SChing-Te Ku static void rtw8852c_btc_set_wl_rx_gain(struct rtw89_dev *rtwdev, u32 level)
2647f2fe93b3SChing-Te Ku {
264820595db3SChing-Te Ku 	struct rtw89_btc *btc = &rtwdev->btc;
264920595db3SChing-Te Ku 
2650f2fe93b3SChing-Te Ku 	switch (level) {
2651f2fe93b3SChing-Te Ku 	case 0: /* original */
265220595db3SChing-Te Ku 	default:
2653f2fe93b3SChing-Te Ku 		rtw8852c_bb_ctrl_btc_preagc(rtwdev, false);
265420595db3SChing-Te Ku 		btc->dm.wl_lna2 = 0;
2655f2fe93b3SChing-Te Ku 		break;
2656f2fe93b3SChing-Te Ku 	case 1: /* for FDD free-run */
2657f2fe93b3SChing-Te Ku 		rtw8852c_bb_ctrl_btc_preagc(rtwdev, true);
265820595db3SChing-Te Ku 		btc->dm.wl_lna2 = 0;
2659f2fe93b3SChing-Te Ku 		break;
2660f2fe93b3SChing-Te Ku 	case 2: /* for BTG Co-Rx*/
2661f2fe93b3SChing-Te Ku 		rtw8852c_bb_ctrl_btc_preagc(rtwdev, false);
266220595db3SChing-Te Ku 		btc->dm.wl_lna2 = 1;
2663f2fe93b3SChing-Te Ku 		break;
2664f2fe93b3SChing-Te Ku 	}
266520595db3SChing-Te Ku 
266620595db3SChing-Te Ku 	rtw8852c_set_wl_lna2(rtwdev, btc->dm.wl_lna2);
2667f2fe93b3SChing-Te Ku }
2668f2fe93b3SChing-Te Ku 
rtw8852c_fill_freq_with_ppdu(struct rtw89_dev * rtwdev,struct rtw89_rx_phy_ppdu * phy_ppdu,struct ieee80211_rx_status * status)2669f4ae7cccSPing-Ke Shih static void rtw8852c_fill_freq_with_ppdu(struct rtw89_dev *rtwdev,
2670f4ae7cccSPing-Ke Shih 					 struct rtw89_rx_phy_ppdu *phy_ppdu,
2671f4ae7cccSPing-Ke Shih 					 struct ieee80211_rx_status *status)
2672f4ae7cccSPing-Ke Shih {
2673f4ae7cccSPing-Ke Shih 	u8 chan_idx = phy_ppdu->chan_idx;
2674f4ae7cccSPing-Ke Shih 	enum nl80211_band band;
2675f4ae7cccSPing-Ke Shih 	u8 ch;
2676f4ae7cccSPing-Ke Shih 
2677f4ae7cccSPing-Ke Shih 	if (chan_idx == 0)
2678f4ae7cccSPing-Ke Shih 		return;
2679f4ae7cccSPing-Ke Shih 
2680bb9040b3SPo-Hao Huang 	rtw89_decode_chan_idx(rtwdev, chan_idx, &ch, &band);
2681f4ae7cccSPing-Ke Shih 	status->freq = ieee80211_channel_to_frequency(ch, band);
2682f4ae7cccSPing-Ke Shih 	status->band = band;
2683f4ae7cccSPing-Ke Shih }
2684f4ae7cccSPing-Ke Shih 
rtw8852c_query_ppdu(struct rtw89_dev * rtwdev,struct rtw89_rx_phy_ppdu * phy_ppdu,struct ieee80211_rx_status * status)2685f4ae7cccSPing-Ke Shih static void rtw8852c_query_ppdu(struct rtw89_dev *rtwdev,
2686f4ae7cccSPing-Ke Shih 				struct rtw89_rx_phy_ppdu *phy_ppdu,
2687f4ae7cccSPing-Ke Shih 				struct ieee80211_rx_status *status)
2688f4ae7cccSPing-Ke Shih {
2689f4ae7cccSPing-Ke Shih 	u8 path;
26906ce472d6SPing-Ke Shih 	u8 *rx_power = phy_ppdu->rssi;
2691f4ae7cccSPing-Ke Shih 
26926ce472d6SPing-Ke Shih 	status->signal = RTW89_RSSI_RAW_TO_DBM(max(rx_power[RF_PATH_A], rx_power[RF_PATH_B]));
2693f4ae7cccSPing-Ke Shih 	for (path = 0; path < rtwdev->chip->rf_path_num; path++) {
2694f4ae7cccSPing-Ke Shih 		status->chains |= BIT(path);
26956ce472d6SPing-Ke Shih 		status->chain_signal[path] = RTW89_RSSI_RAW_TO_DBM(rx_power[path]);
2696f4ae7cccSPing-Ke Shih 	}
2697f4ae7cccSPing-Ke Shih 	if (phy_ppdu->valid)
2698f4ae7cccSPing-Ke Shih 		rtw8852c_fill_freq_with_ppdu(rtwdev, phy_ppdu, status);
2699f4ae7cccSPing-Ke Shih }
2700f4ae7cccSPing-Ke Shih 
rtw8852c_mac_enable_bb_rf(struct rtw89_dev * rtwdev)270161ebeecbSPing-Ke Shih static int rtw8852c_mac_enable_bb_rf(struct rtw89_dev *rtwdev)
270261ebeecbSPing-Ke Shih {
270361ebeecbSPing-Ke Shih 	int ret;
270461ebeecbSPing-Ke Shih 
270561ebeecbSPing-Ke Shih 	rtw89_write8_set(rtwdev, R_AX_SYS_FUNC_EN,
270661ebeecbSPing-Ke Shih 			 B_AX_FEN_BBRSTB | B_AX_FEN_BB_GLB_RSTN);
270761ebeecbSPing-Ke Shih 
270861ebeecbSPing-Ke Shih 	rtw89_write32_set(rtwdev, R_AX_WLRF_CTRL, B_AX_AFC_AFEDIG);
270961ebeecbSPing-Ke Shih 	rtw89_write32_clr(rtwdev, R_AX_WLRF_CTRL, B_AX_AFC_AFEDIG);
271061ebeecbSPing-Ke Shih 	rtw89_write32_set(rtwdev, R_AX_WLRF_CTRL, B_AX_AFC_AFEDIG);
271161ebeecbSPing-Ke Shih 
271261ebeecbSPing-Ke Shih 	rtw89_write32_mask(rtwdev, R_AX_AFE_OFF_CTRL1, B_AX_S0_LDO_VSEL_F_MASK, 0x1);
271361ebeecbSPing-Ke Shih 	rtw89_write32_mask(rtwdev, R_AX_AFE_OFF_CTRL1, B_AX_S1_LDO_VSEL_F_MASK, 0x1);
271461ebeecbSPing-Ke Shih 
271561ebeecbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL0, 0x7, FULL_BIT_MASK);
271661ebeecbSPing-Ke Shih 	if (ret)
271761ebeecbSPing-Ke Shih 		return ret;
271861ebeecbSPing-Ke Shih 
271961ebeecbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0x6c, FULL_BIT_MASK);
272061ebeecbSPing-Ke Shih 	if (ret)
272161ebeecbSPing-Ke Shih 		return ret;
272261ebeecbSPing-Ke Shih 
272361ebeecbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_WL_RFC_S0, 0xc7, FULL_BIT_MASK);
272461ebeecbSPing-Ke Shih 	if (ret)
272561ebeecbSPing-Ke Shih 		return ret;
272661ebeecbSPing-Ke Shih 
272761ebeecbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_WL_RFC_S1, 0xc7, FULL_BIT_MASK);
272861ebeecbSPing-Ke Shih 	if (ret)
272961ebeecbSPing-Ke Shih 		return ret;
273061ebeecbSPing-Ke Shih 
273161ebeecbSPing-Ke Shih 	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL3, 0xd, FULL_BIT_MASK);
273261ebeecbSPing-Ke Shih 	if (ret)
273361ebeecbSPing-Ke Shih 		return ret;
273461ebeecbSPing-Ke Shih 
273561ebeecbSPing-Ke Shih 	return 0;
273661ebeecbSPing-Ke Shih }
273761ebeecbSPing-Ke Shih 
rtw8852c_mac_disable_bb_rf(struct rtw89_dev * rtwdev)273814b6e9f4SPing-Ke Shih static int rtw8852c_mac_disable_bb_rf(struct rtw89_dev *rtwdev)
273961ebeecbSPing-Ke Shih {
274061ebeecbSPing-Ke Shih 	rtw89_write8_clr(rtwdev, R_AX_SYS_FUNC_EN,
274161ebeecbSPing-Ke Shih 			 B_AX_FEN_BBRSTB | B_AX_FEN_BB_GLB_RSTN);
274214b6e9f4SPing-Ke Shih 
274314b6e9f4SPing-Ke Shih 	return 0;
274461ebeecbSPing-Ke Shih }
274561ebeecbSPing-Ke Shih 
274619e28c7fSChin-Yen Lee #ifdef CONFIG_PM
274719e28c7fSChin-Yen Lee static const struct wiphy_wowlan_support rtw_wowlan_stub_8852c = {
274819e28c7fSChin-Yen Lee 	.flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT,
2749d2b68e95SChin-Yen Lee 	.n_patterns = RTW89_MAX_PATTERN_NUM,
2750d2b68e95SChin-Yen Lee 	.pattern_max_len = RTW89_MAX_PATTERN_SIZE,
2751d2b68e95SChin-Yen Lee 	.pattern_min_len = 1,
275219e28c7fSChin-Yen Lee };
275319e28c7fSChin-Yen Lee #endif
275419e28c7fSChin-Yen Lee 
27550ac80e05SPing-Ke Shih static const struct rtw89_chip_ops rtw8852c_chip_ops = {
275661ebeecbSPing-Ke Shih 	.enable_bb_rf		= rtw8852c_mac_enable_bb_rf,
275761ebeecbSPing-Ke Shih 	.disable_bb_rf		= rtw8852c_mac_disable_bb_rf,
2758cc99eefaSPing-Ke Shih 	.bb_reset		= rtw8852c_bb_reset,
2759cc99eefaSPing-Ke Shih 	.bb_sethw		= rtw8852c_bb_sethw,
276078af3cc6SPing-Ke Shih 	.read_rf		= rtw89_phy_read_rf_v1,
276178af3cc6SPing-Ke Shih 	.write_rf		= rtw89_phy_write_rf_v1,
27621b00e923SPing-Ke Shih 	.set_channel		= rtw8852c_set_channel,
276379dafcd4SPing-Ke Shih 	.set_channel_help	= rtw8852c_set_channel_help,
2764ea372064SPing-Ke Shih 	.read_efuse		= rtw8852c_read_efuse,
2765a82174c6SPing-Ke Shih 	.read_phycap		= rtw8852c_read_phycap,
276678af3cc6SPing-Ke Shih 	.fem_setup		= NULL,
2767f03bd042SPing-Ke Shih 	.rfe_gpio		= NULL,
276816b44ed0SPing-Ke Shih 	.rfk_init		= rtw8852c_rfk_init,
276916b44ed0SPing-Ke Shih 	.rfk_channel		= rtw8852c_rfk_channel,
2770e5efc4d5SPing-Ke Shih 	.rfk_band_changed	= rtw8852c_rfk_band_changed,
2771e5efc4d5SPing-Ke Shih 	.rfk_scan		= rtw8852c_rfk_scan,
2772fb8177d7SPing-Ke Shih 	.rfk_track		= rtw8852c_rfk_track,
2773a82174c6SPing-Ke Shih 	.power_trim		= rtw8852c_power_trim,
2774af0cac15SPing-Ke Shih 	.set_txpwr		= rtw8852c_set_txpwr,
2775af0cac15SPing-Ke Shih 	.set_txpwr_ctrl		= rtw8852c_set_txpwr_ctrl,
2776af0cac15SPing-Ke Shih 	.init_txpwr_unit	= rtw8852c_init_txpwr_unit,
27773ecca403SPing-Ke Shih 	.get_thermal		= rtw8852c_get_thermal,
277878af3cc6SPing-Ke Shih 	.ctrl_btg		= rtw8852c_ctrl_btg,
2779f4ae7cccSPing-Ke Shih 	.query_ppdu		= rtw8852c_query_ppdu,
2780e212d5d4SPing-Ke Shih 	.bb_ctrl_btc_preagc	= rtw8852c_bb_ctrl_btc_preagc,
2781cd89a471SPing-Ke Shih 	.cfg_txrx_path		= rtw8852c_bb_cfg_txrx_path,
278278af3cc6SPing-Ke Shih 	.set_txpwr_ul_tb_offset	= rtw8852c_set_txpwr_ul_tb_offset,
27832a7e54dbSPing-Ke Shih 	.pwr_on_func		= rtw8852c_pwr_on_func,
27842a7e54dbSPing-Ke Shih 	.pwr_off_func		= rtw8852c_pwr_off_func,
2785de9f9338SPing-Ke Shih 	.query_rxdesc		= rtw89_core_query_rxdesc,
2786f59acddeSPing-Ke Shih 	.fill_txdesc		= rtw89_core_fill_txdesc_v1,
2787a95bd62eSPing-Ke Shih 	.fill_txdesc_fwcmd	= rtw89_core_fill_txdesc_fwcmd_v1,
2788feed6541SChia-Yuan Li 	.cfg_ctrl_path		= rtw89_mac_cfg_ctrl_path_v1,
2789feed6541SChia-Yuan Li 	.mac_cfg_gnt		= rtw89_mac_cfg_gnt_v1,
2790de7ba639SPing-Ke Shih 	.stop_sch_tx		= rtw89_mac_stop_sch_tx_v1,
2791de7ba639SPing-Ke Shih 	.resume_sch_tx		= rtw89_mac_resume_sch_tx_v1,
27920a6f299bSPing-Ke Shih 	.h2c_dctl_sec_cam	= rtw89_fw_h2c_dctl_sec_cam_v1,
2793065cf8f9SChia-Yuan Li 
27942fb822f8SPing-Ke Shih 	.btc_set_rfe		= rtw8852c_btc_set_rfe,
2795065cf8f9SChia-Yuan Li 	.btc_init_cfg		= rtw8852c_btc_init_cfg,
27962fb822f8SPing-Ke Shih 	.btc_set_wl_pri		= rtw8852c_btc_set_wl_pri,
27972fb822f8SPing-Ke Shih 	.btc_set_wl_txpwr_ctrl	= rtw8852c_btc_set_wl_txpwr_ctrl,
27982fb822f8SPing-Ke Shih 	.btc_get_bt_rssi	= rtw8852c_btc_get_bt_rssi,
27992fb822f8SPing-Ke Shih 	.btc_update_bt_cnt	= rtw8852c_btc_update_bt_cnt,
28002fb822f8SPing-Ke Shih 	.btc_wl_s1_standby	= rtw8852c_btc_wl_s1_standby,
2801f2fe93b3SChing-Te Ku 	.btc_set_wl_rx_gain	= rtw8852c_btc_set_wl_rx_gain,
2802a8a0b1f7SChing-Te Ku 	.btc_set_policy		= rtw89_btc_set_policy_v1,
28030ac80e05SPing-Ke Shih };
28040ac80e05SPing-Ke Shih 
28050ac80e05SPing-Ke Shih const struct rtw89_chip_info rtw8852c_chip_info = {
28060ac80e05SPing-Ke Shih 	.chip_id		= RTL8852C,
2807f698afa7SPing-Ke Shih 	.chip_gen		= RTW89_CHIP_AX,
28080ac80e05SPing-Ke Shih 	.ops			= &rtw8852c_chip_ops,
2809c220d08eSPing-Ke Shih 	.mac_def		= &rtw89_mac_gen_ax,
28101165f571SPing-Ke Shih 	.phy_def		= &rtw89_phy_gen_ax,
2811ffde7f34SPing-Ke Shih 	.fw_basename		= RTW8852C_FW_BASENAME,
2812ffde7f34SPing-Ke Shih 	.fw_format_max		= RTW8852C_FW_FORMAT_MAX,
28137410bd72SPing-Ke Shih 	.try_ce_fw		= false,
2814dd59c6a3SPing-Ke Shih 	.needed_fw_elms		= 0,
281578af3cc6SPing-Ke Shih 	.fifo_size		= 458752,
2816ce816ab5SPing-Ke Shih 	.small_fifo_size	= false,
28175f8c35b9SPing-Ke Shih 	.dle_scc_rsvd_size	= 0,
281878af3cc6SPing-Ke Shih 	.max_amsdu_limit	= 8000,
281978af3cc6SPing-Ke Shih 	.dis_2g_40m_ul_ofdma	= false,
282078af3cc6SPing-Ke Shih 	.rsvd_ple_ofst		= 0x6f800,
28217b9c98c7SPing-Ke Shih 	.hfc_param_ini		= rtw8852c_hfc_param_ini_pcie,
282279d099e0SPing-Ke Shih 	.dle_mem		= rtw8852c_dle_mem_pcie,
282341d56769SChih-Kang Chang 	.wde_qempty_acq_num     = 16,
282441d56769SChih-Kang Chang 	.wde_qempty_mgq_sel     = 16,
282584d0e33eSChung-Hsuan Hung 	.rf_base_addr		= {0xe000, 0xf000},
28262a7e54dbSPing-Ke Shih 	.pwr_on_seq		= NULL,
28272a7e54dbSPing-Ke Shih 	.pwr_off_seq		= NULL,
2828eefad995SPing-Ke Shih 	.bb_table		= &rtw89_8852c_phy_bb_table,
2829eefad995SPing-Ke Shih 	.bb_gain_table		= &rtw89_8852c_phy_bb_gain_table,
2830eefad995SPing-Ke Shih 	.rf_table		= {&rtw89_8852c_phy_radiob_table,
2831eefad995SPing-Ke Shih 				   &rtw89_8852c_phy_radioa_table,},
2832eefad995SPing-Ke Shih 	.nctl_table		= &rtw89_8852c_phy_nctl_table,
2833a24be8bbSPing-Ke Shih 	.nctl_post_table	= NULL,
2834342475acSPing-Ke Shih 	.byr_table		= &rtw89_8852c_byr_table,
28355395482aSZong-Zhe Yang 	.dflt_parms		= &rtw89_8852c_dflt_parms,
28365395482aSZong-Zhe Yang 	.rfe_parms_conf		= NULL,
2837342475acSPing-Ke Shih 	.txpwr_factor_rf	= 2,
2838342475acSPing-Ke Shih 	.txpwr_factor_mac	= 1,
2839d264edb1SJohnson Lin 	.dig_table		= NULL,
284087deaad9SEric Huang 	.dig_regs		= &rtw8852c_dig_regs,
2841c7845551SPing-Ke Shih 	.tssi_dbw_table		= &rtw89_8852c_tssi_dbw_table,
2842deebea35SZong-Zhe Yang 	.support_chanctx_num	= 1,
284378af3cc6SPing-Ke Shih 	.support_bands		= BIT(NL80211_BAND_2GHZ) |
284478af3cc6SPing-Ke Shih 				  BIT(NL80211_BAND_5GHZ) |
284578af3cc6SPing-Ke Shih 				  BIT(NL80211_BAND_6GHZ),
284678af3cc6SPing-Ke Shih 	.support_bw160		= true,
2847a002f981SZong-Zhe Yang 	.support_unii4		= true,
284829136c95SEric Huang 	.support_ul_tb_ctrl     = false,
284979a6c9a4SPing-Ke Shih 	.hw_sec_hdr		= true,
285078af3cc6SPing-Ke Shih 	.rf_path_num		= 2,
285178af3cc6SPing-Ke Shih 	.tx_nss			= 2,
285278af3cc6SPing-Ke Shih 	.rx_nss			= 2,
285378af3cc6SPing-Ke Shih 	.acam_num		= 128,
285478af3cc6SPing-Ke Shih 	.bcam_num		= 20,
285578af3cc6SPing-Ke Shih 	.scam_num		= 128,
28562def7356SPing-Ke Shih 	.bacam_num		= 8,
28578b1b4730SPing-Ke Shih 	.bacam_dynamic_num	= 8,
2858b6335d91SPing-Ke Shih 	.bacam_ver		= RTW89_BACAM_V0_EXT,
2859bdfbf06cSPing-Ke Shih 	.sec_ctrl_efuse_size	= 4,
2860bdfbf06cSPing-Ke Shih 	.physical_efuse_size	= 1216,
2861bdfbf06cSPing-Ke Shih 	.logical_efuse_size	= 2048,
2862bdfbf06cSPing-Ke Shih 	.limit_efuse_size	= 1280,
2863bdfbf06cSPing-Ke Shih 	.dav_phy_efuse_size	= 96,
2864bdfbf06cSPing-Ke Shih 	.dav_log_efuse_size	= 16,
2865a82174c6SPing-Ke Shih 	.phycap_addr		= 0x590,
2866a82174c6SPing-Ke Shih 	.phycap_size		= 0x60,
28672e405cffSChing-Te Ku 	.para_ver		= 0x1,
28682e405cffSChing-Te Ku 	.wlcx_desired		= 0x06000000,
28692e405cffSChing-Te Ku 	.btcx_desired		= 0x7,
287078af3cc6SPing-Ke Shih 	.scbd			= 0x1,
287178af3cc6SPing-Ke Shih 	.mailbox		= 0x1,
2872ba787c07SChing-Te Ku 
287378af3cc6SPing-Ke Shih 	.afh_guard_ch		= 6,
287478af3cc6SPing-Ke Shih 	.wl_rssi_thres		= rtw89_btc_8852c_wl_rssi_thres,
287578af3cc6SPing-Ke Shih 	.bt_rssi_thres		= rtw89_btc_8852c_bt_rssi_thres,
287678af3cc6SPing-Ke Shih 	.rssi_tol		= 2,
287778af3cc6SPing-Ke Shih 	.mon_reg_num		= ARRAY_SIZE(rtw89_btc_8852c_mon_reg),
287878af3cc6SPing-Ke Shih 	.mon_reg		= rtw89_btc_8852c_mon_reg,
287978af3cc6SPing-Ke Shih 	.rf_para_ulink_num	= ARRAY_SIZE(rtw89_btc_8852c_rf_ul),
288078af3cc6SPing-Ke Shih 	.rf_para_ulink		= rtw89_btc_8852c_rf_ul,
288178af3cc6SPing-Ke Shih 	.rf_para_dlink_num	= ARRAY_SIZE(rtw89_btc_8852c_rf_dl),
288278af3cc6SPing-Ke Shih 	.rf_para_dlink		= rtw89_btc_8852c_rf_dl,
2883183c8effSChin-Yen Lee 	.ps_mode_supported	= BIT(RTW89_PS_MODE_RFOFF) |
2884183c8effSChin-Yen Lee 				  BIT(RTW89_PS_MODE_CLK_GATED) |
2885183c8effSChin-Yen Lee 				  BIT(RTW89_PS_MODE_PWR_GATED),
288652edbb9fSPing-Ke Shih 	.low_power_hci_modes	= BIT(RTW89_PS_MODE_CLK_GATED) |
288752edbb9fSPing-Ke Shih 				  BIT(RTW89_PS_MODE_PWR_GATED),
2888aa7f148bSPing-Ke Shih 	.h2c_cctl_func_id	= H2C_FUNC_MAC_CCTLINFO_UD_V1,
28892af64b4aSPing-Ke Shih 	.hci_func_en_addr	= R_AX_HCI_FUNC_EN_V1,
2890a95bd62eSPing-Ke Shih 	.h2c_desc_size		= sizeof(struct rtw89_rxdesc_short),
2891f59acddeSPing-Ke Shih 	.txwd_body_size		= sizeof(struct rtw89_txwd_body_v1),
2892e8955811SPing-Ke Shih 	.h2c_ctrl_reg		= R_AX_H2CREG_CTRL_V1,
2893e749ef96SPing-Ke Shih 	.h2c_counter_reg	= {R_AX_UDM1 + 1, B_AX_UDM1_HALMAC_H2C_DEQ_CNT_MASK >> 8},
2894e8955811SPing-Ke Shih 	.h2c_regs		= rtw8852c_h2c_regs,
2895e8955811SPing-Ke Shih 	.c2h_ctrl_reg		= R_AX_C2HREG_CTRL_V1,
2896e749ef96SPing-Ke Shih 	.c2h_counter_reg	= {R_AX_UDM1 + 1, B_AX_UDM1_HALMAC_C2H_ENQ_CNT_MASK >> 8},
2897e8955811SPing-Ke Shih 	.c2h_regs		= rtw8852c_c2h_regs,
2898ab8a5671SPing-Ke Shih 	.page_regs		= &rtw8852c_page_regs,
289910cd4092SEric Huang 	.cfo_src_fd		= false,
29009f9882dbSEric Huang 	.cfo_hw_comp            = false,
2901b7379148SYuan-Han Zhang 	.dcfo_comp		= &rtw8852c_dcfo_comp,
29029f9882dbSEric Huang 	.dcfo_comp_sft		= 12,
29039ef9edb9SChia-Yuan Li 	.imr_info		= &rtw8852c_imr_info,
29049ef9edb9SChia-Yuan Li 	.rrsr_cfgs		= &rtw8852c_rrsr_cfgs,
2905a48f4fd0SEric Huang 	.bss_clr_map_reg	= R_BSS_CLR_MAP,
2906a1b7163aSPing-Ke Shih 	.dma_ch_mask		= 0,
2907280c4447SChih-Kang Chang 	.edcca_lvl_reg		= R_SEG0R_EDCCA_LVL,
290819e28c7fSChin-Yen Lee #ifdef CONFIG_PM
290919e28c7fSChin-Yen Lee 	.wowlan_stub		= &rtw_wowlan_stub_8852c,
291019e28c7fSChin-Yen Lee #endif
29110789881aSChia-Yuan Li 	.xtal_info		= NULL,
29120ac80e05SPing-Ke Shih };
29130ac80e05SPing-Ke Shih EXPORT_SYMBOL(rtw8852c_chip_info);
29140ac80e05SPing-Ke Shih 
2915ffde7f34SPing-Ke Shih MODULE_FIRMWARE(RTW8852C_MODULE_FIRMWARE);
29160ac80e05SPing-Ke Shih MODULE_AUTHOR("Realtek Corporation");
29170ac80e05SPing-Ke Shih MODULE_DESCRIPTION("Realtek 802.11ax wireless 8852C driver");
29180ac80e05SPing-Ke Shih MODULE_LICENSE("Dual BSD/GPL");
2919