162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
262306a36Sopenharmony_ci/* Copyright(c) 2019-2022  Realtek Corporation
362306a36Sopenharmony_ci */
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include "coex.h"
662306a36Sopenharmony_ci#include "fw.h"
762306a36Sopenharmony_ci#include "mac.h"
862306a36Sopenharmony_ci#include "phy.h"
962306a36Sopenharmony_ci#include "reg.h"
1062306a36Sopenharmony_ci#include "rtw8852b.h"
1162306a36Sopenharmony_ci#include "rtw8852b_rfk.h"
1262306a36Sopenharmony_ci#include "rtw8852b_table.h"
1362306a36Sopenharmony_ci#include "txrx.h"
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#define RTW8852B_FW_FORMAT_MAX 1
1662306a36Sopenharmony_ci#define RTW8852B_FW_BASENAME "rtw89/rtw8852b_fw"
1762306a36Sopenharmony_ci#define RTW8852B_MODULE_FIRMWARE \
1862306a36Sopenharmony_ci	RTW8852B_FW_BASENAME "-" __stringify(RTW8852B_FW_FORMAT_MAX) ".bin"
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_cistatic const struct rtw89_hfc_ch_cfg rtw8852b_hfc_chcfg_pcie[] = {
2162306a36Sopenharmony_ci	{5, 341, grp_0}, /* ACH 0 */
2262306a36Sopenharmony_ci	{5, 341, grp_0}, /* ACH 1 */
2362306a36Sopenharmony_ci	{4, 342, grp_0}, /* ACH 2 */
2462306a36Sopenharmony_ci	{4, 342, grp_0}, /* ACH 3 */
2562306a36Sopenharmony_ci	{0, 0, grp_0}, /* ACH 4 */
2662306a36Sopenharmony_ci	{0, 0, grp_0}, /* ACH 5 */
2762306a36Sopenharmony_ci	{0, 0, grp_0}, /* ACH 6 */
2862306a36Sopenharmony_ci	{0, 0, grp_0}, /* ACH 7 */
2962306a36Sopenharmony_ci	{4, 342, grp_0}, /* B0MGQ */
3062306a36Sopenharmony_ci	{4, 342, grp_0}, /* B0HIQ */
3162306a36Sopenharmony_ci	{0, 0, grp_0}, /* B1MGQ */
3262306a36Sopenharmony_ci	{0, 0, grp_0}, /* B1HIQ */
3362306a36Sopenharmony_ci	{40, 0, 0} /* FWCMDQ */
3462306a36Sopenharmony_ci};
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_cistatic const struct rtw89_hfc_pub_cfg rtw8852b_hfc_pubcfg_pcie = {
3762306a36Sopenharmony_ci	446, /* Group 0 */
3862306a36Sopenharmony_ci	0, /* Group 1 */
3962306a36Sopenharmony_ci	446, /* Public Max */
4062306a36Sopenharmony_ci	0 /* WP threshold */
4162306a36Sopenharmony_ci};
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_cistatic const struct rtw89_hfc_param_ini rtw8852b_hfc_param_ini_pcie[] = {
4462306a36Sopenharmony_ci	[RTW89_QTA_SCC] = {rtw8852b_hfc_chcfg_pcie, &rtw8852b_hfc_pubcfg_pcie,
4562306a36Sopenharmony_ci			   &rtw89_mac_size.hfc_preccfg_pcie, RTW89_HCIFC_POH},
4662306a36Sopenharmony_ci	[RTW89_QTA_DLFW] = {NULL, NULL, &rtw89_mac_size.hfc_preccfg_pcie,
4762306a36Sopenharmony_ci			    RTW89_HCIFC_POH},
4862306a36Sopenharmony_ci	[RTW89_QTA_INVALID] = {NULL},
4962306a36Sopenharmony_ci};
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_cistatic const struct rtw89_dle_mem rtw8852b_dle_mem_pcie[] = {
5262306a36Sopenharmony_ci	[RTW89_QTA_SCC] = {RTW89_QTA_SCC, &rtw89_mac_size.wde_size7,
5362306a36Sopenharmony_ci			   &rtw89_mac_size.ple_size6, &rtw89_mac_size.wde_qt7,
5462306a36Sopenharmony_ci			   &rtw89_mac_size.wde_qt7, &rtw89_mac_size.ple_qt18,
5562306a36Sopenharmony_ci			   &rtw89_mac_size.ple_qt58},
5662306a36Sopenharmony_ci	[RTW89_QTA_WOW] = {RTW89_QTA_WOW, &rtw89_mac_size.wde_size7,
5762306a36Sopenharmony_ci			   &rtw89_mac_size.ple_size6, &rtw89_mac_size.wde_qt7,
5862306a36Sopenharmony_ci			   &rtw89_mac_size.wde_qt7, &rtw89_mac_size.ple_qt18,
5962306a36Sopenharmony_ci			   &rtw89_mac_size.ple_qt_52b_wow},
6062306a36Sopenharmony_ci	[RTW89_QTA_DLFW] = {RTW89_QTA_DLFW, &rtw89_mac_size.wde_size9,
6162306a36Sopenharmony_ci			    &rtw89_mac_size.ple_size8, &rtw89_mac_size.wde_qt4,
6262306a36Sopenharmony_ci			    &rtw89_mac_size.wde_qt4, &rtw89_mac_size.ple_qt13,
6362306a36Sopenharmony_ci			    &rtw89_mac_size.ple_qt13},
6462306a36Sopenharmony_ci	[RTW89_QTA_INVALID] = {RTW89_QTA_INVALID, NULL, NULL, NULL, NULL, NULL,
6562306a36Sopenharmony_ci			       NULL},
6662306a36Sopenharmony_ci};
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_cistatic const struct rtw89_reg3_def rtw8852b_pmac_ht20_mcs7_tbl[] = {
6962306a36Sopenharmony_ci	{0x4580, 0x0000ffff, 0x0},
7062306a36Sopenharmony_ci	{0x4580, 0xffff0000, 0x0},
7162306a36Sopenharmony_ci	{0x4584, 0x0000ffff, 0x0},
7262306a36Sopenharmony_ci	{0x4584, 0xffff0000, 0x0},
7362306a36Sopenharmony_ci	{0x4580, 0x0000ffff, 0x1},
7462306a36Sopenharmony_ci	{0x4578, 0x00ffffff, 0x2018b},
7562306a36Sopenharmony_ci	{0x4570, 0x03ffffff, 0x7},
7662306a36Sopenharmony_ci	{0x4574, 0x03ffffff, 0x32407},
7762306a36Sopenharmony_ci	{0x45b8, 0x00000010, 0x0},
7862306a36Sopenharmony_ci	{0x45b8, 0x00000100, 0x0},
7962306a36Sopenharmony_ci	{0x45b8, 0x00000080, 0x0},
8062306a36Sopenharmony_ci	{0x45b8, 0x00000008, 0x0},
8162306a36Sopenharmony_ci	{0x45a0, 0x0000ff00, 0x0},
8262306a36Sopenharmony_ci	{0x45a0, 0xff000000, 0x1},
8362306a36Sopenharmony_ci	{0x45a4, 0x0000ff00, 0x2},
8462306a36Sopenharmony_ci	{0x45a4, 0xff000000, 0x3},
8562306a36Sopenharmony_ci	{0x45b8, 0x00000020, 0x0},
8662306a36Sopenharmony_ci	{0x4568, 0xe0000000, 0x0},
8762306a36Sopenharmony_ci	{0x45b8, 0x00000002, 0x1},
8862306a36Sopenharmony_ci	{0x456c, 0xe0000000, 0x0},
8962306a36Sopenharmony_ci	{0x45b4, 0x00006000, 0x0},
9062306a36Sopenharmony_ci	{0x45b4, 0x00001800, 0x1},
9162306a36Sopenharmony_ci	{0x45b8, 0x00000040, 0x0},
9262306a36Sopenharmony_ci	{0x45b8, 0x00000004, 0x0},
9362306a36Sopenharmony_ci	{0x45b8, 0x00000200, 0x0},
9462306a36Sopenharmony_ci	{0x4598, 0xf8000000, 0x0},
9562306a36Sopenharmony_ci	{0x45b8, 0x00100000, 0x0},
9662306a36Sopenharmony_ci	{0x45a8, 0x00000fc0, 0x0},
9762306a36Sopenharmony_ci	{0x45b8, 0x00200000, 0x0},
9862306a36Sopenharmony_ci	{0x45b0, 0x00000038, 0x0},
9962306a36Sopenharmony_ci	{0x45b0, 0x000001c0, 0x0},
10062306a36Sopenharmony_ci	{0x45a0, 0x000000ff, 0x0},
10162306a36Sopenharmony_ci	{0x45b8, 0x00400000, 0x0},
10262306a36Sopenharmony_ci	{0x4590, 0x000007ff, 0x0},
10362306a36Sopenharmony_ci	{0x45b0, 0x00000e00, 0x0},
10462306a36Sopenharmony_ci	{0x45ac, 0x0000001f, 0x0},
10562306a36Sopenharmony_ci	{0x45b8, 0x00800000, 0x0},
10662306a36Sopenharmony_ci	{0x45a8, 0x0003f000, 0x0},
10762306a36Sopenharmony_ci	{0x45b8, 0x01000000, 0x0},
10862306a36Sopenharmony_ci	{0x45b0, 0x00007000, 0x0},
10962306a36Sopenharmony_ci	{0x45b0, 0x00038000, 0x0},
11062306a36Sopenharmony_ci	{0x45a0, 0x00ff0000, 0x0},
11162306a36Sopenharmony_ci	{0x45b8, 0x02000000, 0x0},
11262306a36Sopenharmony_ci	{0x4590, 0x003ff800, 0x0},
11362306a36Sopenharmony_ci	{0x45b0, 0x001c0000, 0x0},
11462306a36Sopenharmony_ci	{0x45ac, 0x000003e0, 0x0},
11562306a36Sopenharmony_ci	{0x45b8, 0x04000000, 0x0},
11662306a36Sopenharmony_ci	{0x45a8, 0x00fc0000, 0x0},
11762306a36Sopenharmony_ci	{0x45b8, 0x08000000, 0x0},
11862306a36Sopenharmony_ci	{0x45b0, 0x00e00000, 0x0},
11962306a36Sopenharmony_ci	{0x45b0, 0x07000000, 0x0},
12062306a36Sopenharmony_ci	{0x45a4, 0x000000ff, 0x0},
12162306a36Sopenharmony_ci	{0x45b8, 0x10000000, 0x0},
12262306a36Sopenharmony_ci	{0x4594, 0x000007ff, 0x0},
12362306a36Sopenharmony_ci	{0x45b0, 0x38000000, 0x0},
12462306a36Sopenharmony_ci	{0x45ac, 0x00007c00, 0x0},
12562306a36Sopenharmony_ci	{0x45b8, 0x20000000, 0x0},
12662306a36Sopenharmony_ci	{0x45a8, 0x3f000000, 0x0},
12762306a36Sopenharmony_ci	{0x45b8, 0x40000000, 0x0},
12862306a36Sopenharmony_ci	{0x45b4, 0x00000007, 0x0},
12962306a36Sopenharmony_ci	{0x45b4, 0x00000038, 0x0},
13062306a36Sopenharmony_ci	{0x45a4, 0x00ff0000, 0x0},
13162306a36Sopenharmony_ci	{0x45b8, 0x80000000, 0x0},
13262306a36Sopenharmony_ci	{0x4594, 0x003ff800, 0x0},
13362306a36Sopenharmony_ci	{0x45b4, 0x000001c0, 0x0},
13462306a36Sopenharmony_ci	{0x4598, 0xf8000000, 0x0},
13562306a36Sopenharmony_ci	{0x45b8, 0x00100000, 0x0},
13662306a36Sopenharmony_ci	{0x45a8, 0x00000fc0, 0x7},
13762306a36Sopenharmony_ci	{0x45b8, 0x00200000, 0x0},
13862306a36Sopenharmony_ci	{0x45b0, 0x00000038, 0x0},
13962306a36Sopenharmony_ci	{0x45b0, 0x000001c0, 0x0},
14062306a36Sopenharmony_ci	{0x45a0, 0x000000ff, 0x0},
14162306a36Sopenharmony_ci	{0x45b4, 0x06000000, 0x0},
14262306a36Sopenharmony_ci	{0x45b0, 0x00000007, 0x0},
14362306a36Sopenharmony_ci	{0x45b8, 0x00080000, 0x0},
14462306a36Sopenharmony_ci	{0x45a8, 0x0000003f, 0x0},
14562306a36Sopenharmony_ci	{0x457c, 0xffe00000, 0x1},
14662306a36Sopenharmony_ci	{0x4530, 0xffffffff, 0x0},
14762306a36Sopenharmony_ci	{0x4588, 0x00003fff, 0x0},
14862306a36Sopenharmony_ci	{0x4598, 0x000001ff, 0x0},
14962306a36Sopenharmony_ci	{0x4534, 0xffffffff, 0x0},
15062306a36Sopenharmony_ci	{0x4538, 0xffffffff, 0x0},
15162306a36Sopenharmony_ci	{0x453c, 0xffffffff, 0x0},
15262306a36Sopenharmony_ci	{0x4588, 0x0fffc000, 0x0},
15362306a36Sopenharmony_ci	{0x4598, 0x0003fe00, 0x0},
15462306a36Sopenharmony_ci	{0x4540, 0xffffffff, 0x0},
15562306a36Sopenharmony_ci	{0x4544, 0xffffffff, 0x0},
15662306a36Sopenharmony_ci	{0x4548, 0xffffffff, 0x0},
15762306a36Sopenharmony_ci	{0x458c, 0x00003fff, 0x0},
15862306a36Sopenharmony_ci	{0x4598, 0x07fc0000, 0x0},
15962306a36Sopenharmony_ci	{0x454c, 0xffffffff, 0x0},
16062306a36Sopenharmony_ci	{0x4550, 0xffffffff, 0x0},
16162306a36Sopenharmony_ci	{0x4554, 0xffffffff, 0x0},
16262306a36Sopenharmony_ci	{0x458c, 0x0fffc000, 0x0},
16362306a36Sopenharmony_ci	{0x459c, 0x000001ff, 0x0},
16462306a36Sopenharmony_ci	{0x4558, 0xffffffff, 0x0},
16562306a36Sopenharmony_ci	{0x455c, 0xffffffff, 0x0},
16662306a36Sopenharmony_ci	{0x4530, 0xffffffff, 0x4e790001},
16762306a36Sopenharmony_ci	{0x4588, 0x00003fff, 0x0},
16862306a36Sopenharmony_ci	{0x4598, 0x000001ff, 0x1},
16962306a36Sopenharmony_ci	{0x4534, 0xffffffff, 0x0},
17062306a36Sopenharmony_ci	{0x4538, 0xffffffff, 0x4b},
17162306a36Sopenharmony_ci	{0x45ac, 0x38000000, 0x7},
17262306a36Sopenharmony_ci	{0x4588, 0xf0000000, 0x0},
17362306a36Sopenharmony_ci	{0x459c, 0x7e000000, 0x0},
17462306a36Sopenharmony_ci	{0x45b8, 0x00040000, 0x0},
17562306a36Sopenharmony_ci	{0x45b8, 0x00020000, 0x0},
17662306a36Sopenharmony_ci	{0x4590, 0xffc00000, 0x0},
17762306a36Sopenharmony_ci	{0x45b8, 0x00004000, 0x0},
17862306a36Sopenharmony_ci	{0x4578, 0xff000000, 0x0},
17962306a36Sopenharmony_ci	{0x45b8, 0x00000400, 0x0},
18062306a36Sopenharmony_ci	{0x45b8, 0x00000800, 0x0},
18162306a36Sopenharmony_ci	{0x45b8, 0x00001000, 0x0},
18262306a36Sopenharmony_ci	{0x45b8, 0x00002000, 0x0},
18362306a36Sopenharmony_ci	{0x45b4, 0x00018000, 0x0},
18462306a36Sopenharmony_ci	{0x45ac, 0x07800000, 0x0},
18562306a36Sopenharmony_ci	{0x45b4, 0x00000600, 0x2},
18662306a36Sopenharmony_ci	{0x459c, 0x0001fe00, 0x80},
18762306a36Sopenharmony_ci	{0x45ac, 0x00078000, 0x3},
18862306a36Sopenharmony_ci	{0x459c, 0x01fe0000, 0x1},
18962306a36Sopenharmony_ci};
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_cistatic const struct rtw89_reg3_def rtw8852b_btc_preagc_en_defs[] = {
19262306a36Sopenharmony_ci	{0x46D0, GENMASK(1, 0), 0x3},
19362306a36Sopenharmony_ci	{0x4790, GENMASK(1, 0), 0x3},
19462306a36Sopenharmony_ci	{0x4AD4, GENMASK(31, 0), 0xf},
19562306a36Sopenharmony_ci	{0x4AE0, GENMASK(31, 0), 0xf},
19662306a36Sopenharmony_ci	{0x4688, GENMASK(31, 24), 0x80},
19762306a36Sopenharmony_ci	{0x476C, GENMASK(31, 24), 0x80},
19862306a36Sopenharmony_ci	{0x4694, GENMASK(7, 0), 0x80},
19962306a36Sopenharmony_ci	{0x4694, GENMASK(15, 8), 0x80},
20062306a36Sopenharmony_ci	{0x4778, GENMASK(7, 0), 0x80},
20162306a36Sopenharmony_ci	{0x4778, GENMASK(15, 8), 0x80},
20262306a36Sopenharmony_ci	{0x4AE4, GENMASK(23, 0), 0x780D1E},
20362306a36Sopenharmony_ci	{0x4AEC, GENMASK(23, 0), 0x780D1E},
20462306a36Sopenharmony_ci	{0x469C, GENMASK(31, 26), 0x34},
20562306a36Sopenharmony_ci	{0x49F0, GENMASK(31, 26), 0x34},
20662306a36Sopenharmony_ci};
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_cistatic DECLARE_PHY_REG3_TBL(rtw8852b_btc_preagc_en_defs);
20962306a36Sopenharmony_ci
21062306a36Sopenharmony_cistatic const struct rtw89_reg3_def rtw8852b_btc_preagc_dis_defs[] = {
21162306a36Sopenharmony_ci	{0x46D0, GENMASK(1, 0), 0x0},
21262306a36Sopenharmony_ci	{0x4790, GENMASK(1, 0), 0x0},
21362306a36Sopenharmony_ci	{0x4AD4, GENMASK(31, 0), 0x60},
21462306a36Sopenharmony_ci	{0x4AE0, GENMASK(31, 0), 0x60},
21562306a36Sopenharmony_ci	{0x4688, GENMASK(31, 24), 0x1a},
21662306a36Sopenharmony_ci	{0x476C, GENMASK(31, 24), 0x1a},
21762306a36Sopenharmony_ci	{0x4694, GENMASK(7, 0), 0x2a},
21862306a36Sopenharmony_ci	{0x4694, GENMASK(15, 8), 0x2a},
21962306a36Sopenharmony_ci	{0x4778, GENMASK(7, 0), 0x2a},
22062306a36Sopenharmony_ci	{0x4778, GENMASK(15, 8), 0x2a},
22162306a36Sopenharmony_ci	{0x4AE4, GENMASK(23, 0), 0x79E99E},
22262306a36Sopenharmony_ci	{0x4AEC, GENMASK(23, 0), 0x79E99E},
22362306a36Sopenharmony_ci	{0x469C, GENMASK(31, 26), 0x26},
22462306a36Sopenharmony_ci	{0x49F0, GENMASK(31, 26), 0x26},
22562306a36Sopenharmony_ci};
22662306a36Sopenharmony_ci
22762306a36Sopenharmony_cistatic DECLARE_PHY_REG3_TBL(rtw8852b_btc_preagc_dis_defs);
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_cistatic const u32 rtw8852b_h2c_regs[RTW89_H2CREG_MAX] = {
23062306a36Sopenharmony_ci	R_AX_H2CREG_DATA0, R_AX_H2CREG_DATA1,  R_AX_H2CREG_DATA2,
23162306a36Sopenharmony_ci	R_AX_H2CREG_DATA3
23262306a36Sopenharmony_ci};
23362306a36Sopenharmony_ci
23462306a36Sopenharmony_cistatic const u32 rtw8852b_c2h_regs[RTW89_C2HREG_MAX] = {
23562306a36Sopenharmony_ci	R_AX_C2HREG_DATA0, R_AX_C2HREG_DATA1, R_AX_C2HREG_DATA2,
23662306a36Sopenharmony_ci	R_AX_C2HREG_DATA3
23762306a36Sopenharmony_ci};
23862306a36Sopenharmony_ci
23962306a36Sopenharmony_cistatic const struct rtw89_page_regs rtw8852b_page_regs = {
24062306a36Sopenharmony_ci	.hci_fc_ctrl	= R_AX_HCI_FC_CTRL,
24162306a36Sopenharmony_ci	.ch_page_ctrl	= R_AX_CH_PAGE_CTRL,
24262306a36Sopenharmony_ci	.ach_page_ctrl	= R_AX_ACH0_PAGE_CTRL,
24362306a36Sopenharmony_ci	.ach_page_info	= R_AX_ACH0_PAGE_INFO,
24462306a36Sopenharmony_ci	.pub_page_info3	= R_AX_PUB_PAGE_INFO3,
24562306a36Sopenharmony_ci	.pub_page_ctrl1	= R_AX_PUB_PAGE_CTRL1,
24662306a36Sopenharmony_ci	.pub_page_ctrl2	= R_AX_PUB_PAGE_CTRL2,
24762306a36Sopenharmony_ci	.pub_page_info1	= R_AX_PUB_PAGE_INFO1,
24862306a36Sopenharmony_ci	.pub_page_info2 = R_AX_PUB_PAGE_INFO2,
24962306a36Sopenharmony_ci	.wp_page_ctrl1	= R_AX_WP_PAGE_CTRL1,
25062306a36Sopenharmony_ci	.wp_page_ctrl2	= R_AX_WP_PAGE_CTRL2,
25162306a36Sopenharmony_ci	.wp_page_info1	= R_AX_WP_PAGE_INFO1,
25262306a36Sopenharmony_ci};
25362306a36Sopenharmony_ci
25462306a36Sopenharmony_cistatic const struct rtw89_reg_def rtw8852b_dcfo_comp = {
25562306a36Sopenharmony_ci	R_DCFO_COMP_S0, B_DCFO_COMP_S0_MSK
25662306a36Sopenharmony_ci};
25762306a36Sopenharmony_ci
25862306a36Sopenharmony_cistatic const struct rtw89_imr_info rtw8852b_imr_info = {
25962306a36Sopenharmony_ci	.wdrls_imr_set		= B_AX_WDRLS_IMR_SET,
26062306a36Sopenharmony_ci	.wsec_imr_reg		= R_AX_SEC_DEBUG,
26162306a36Sopenharmony_ci	.wsec_imr_set		= B_AX_IMR_ERROR,
26262306a36Sopenharmony_ci	.mpdu_tx_imr_set	= 0,
26362306a36Sopenharmony_ci	.mpdu_rx_imr_set	= 0,
26462306a36Sopenharmony_ci	.sta_sch_imr_set	= B_AX_STA_SCHEDULER_IMR_SET,
26562306a36Sopenharmony_ci	.txpktctl_imr_b0_reg	= R_AX_TXPKTCTL_ERR_IMR_ISR,
26662306a36Sopenharmony_ci	.txpktctl_imr_b0_clr	= B_AX_TXPKTCTL_IMR_B0_CLR,
26762306a36Sopenharmony_ci	.txpktctl_imr_b0_set	= B_AX_TXPKTCTL_IMR_B0_SET,
26862306a36Sopenharmony_ci	.txpktctl_imr_b1_reg	= R_AX_TXPKTCTL_ERR_IMR_ISR_B1,
26962306a36Sopenharmony_ci	.txpktctl_imr_b1_clr	= B_AX_TXPKTCTL_IMR_B1_CLR,
27062306a36Sopenharmony_ci	.txpktctl_imr_b1_set	= B_AX_TXPKTCTL_IMR_B1_SET,
27162306a36Sopenharmony_ci	.wde_imr_clr		= B_AX_WDE_IMR_CLR,
27262306a36Sopenharmony_ci	.wde_imr_set		= B_AX_WDE_IMR_SET,
27362306a36Sopenharmony_ci	.ple_imr_clr		= B_AX_PLE_IMR_CLR,
27462306a36Sopenharmony_ci	.ple_imr_set		= B_AX_PLE_IMR_SET,
27562306a36Sopenharmony_ci	.host_disp_imr_clr	= B_AX_HOST_DISP_IMR_CLR,
27662306a36Sopenharmony_ci	.host_disp_imr_set	= B_AX_HOST_DISP_IMR_SET,
27762306a36Sopenharmony_ci	.cpu_disp_imr_clr	= B_AX_CPU_DISP_IMR_CLR,
27862306a36Sopenharmony_ci	.cpu_disp_imr_set	= B_AX_CPU_DISP_IMR_SET,
27962306a36Sopenharmony_ci	.other_disp_imr_clr	= B_AX_OTHER_DISP_IMR_CLR,
28062306a36Sopenharmony_ci	.other_disp_imr_set	= 0,
28162306a36Sopenharmony_ci	.bbrpt_com_err_imr_reg	= R_AX_BBRPT_COM_ERR_IMR_ISR,
28262306a36Sopenharmony_ci	.bbrpt_chinfo_err_imr_reg = R_AX_BBRPT_CHINFO_ERR_IMR_ISR,
28362306a36Sopenharmony_ci	.bbrpt_err_imr_set	= 0,
28462306a36Sopenharmony_ci	.bbrpt_dfs_err_imr_reg	= R_AX_BBRPT_DFS_ERR_IMR_ISR,
28562306a36Sopenharmony_ci	.ptcl_imr_clr		= B_AX_PTCL_IMR_CLR_ALL,
28662306a36Sopenharmony_ci	.ptcl_imr_set		= B_AX_PTCL_IMR_SET,
28762306a36Sopenharmony_ci	.cdma_imr_0_reg		= R_AX_DLE_CTRL,
28862306a36Sopenharmony_ci	.cdma_imr_0_clr		= B_AX_DLE_IMR_CLR,
28962306a36Sopenharmony_ci	.cdma_imr_0_set		= B_AX_DLE_IMR_SET,
29062306a36Sopenharmony_ci	.cdma_imr_1_reg		= 0,
29162306a36Sopenharmony_ci	.cdma_imr_1_clr		= 0,
29262306a36Sopenharmony_ci	.cdma_imr_1_set		= 0,
29362306a36Sopenharmony_ci	.phy_intf_imr_reg	= R_AX_PHYINFO_ERR_IMR,
29462306a36Sopenharmony_ci	.phy_intf_imr_clr	= 0,
29562306a36Sopenharmony_ci	.phy_intf_imr_set	= 0,
29662306a36Sopenharmony_ci	.rmac_imr_reg		= R_AX_RMAC_ERR_ISR,
29762306a36Sopenharmony_ci	.rmac_imr_clr		= B_AX_RMAC_IMR_CLR,
29862306a36Sopenharmony_ci	.rmac_imr_set		= B_AX_RMAC_IMR_SET,
29962306a36Sopenharmony_ci	.tmac_imr_reg		= R_AX_TMAC_ERR_IMR_ISR,
30062306a36Sopenharmony_ci	.tmac_imr_clr		= B_AX_TMAC_IMR_CLR,
30162306a36Sopenharmony_ci	.tmac_imr_set		= B_AX_TMAC_IMR_SET,
30262306a36Sopenharmony_ci};
30362306a36Sopenharmony_ci
30462306a36Sopenharmony_cistatic const struct rtw89_rrsr_cfgs rtw8852b_rrsr_cfgs = {
30562306a36Sopenharmony_ci	.ref_rate = {R_AX_TRXPTCL_RRSR_CTL_0, B_AX_WMAC_RESP_REF_RATE_SEL, 0},
30662306a36Sopenharmony_ci	.rsc = {R_AX_TRXPTCL_RRSR_CTL_0, B_AX_WMAC_RESP_RSC_MASK, 2},
30762306a36Sopenharmony_ci};
30862306a36Sopenharmony_ci
30962306a36Sopenharmony_cistatic const struct rtw89_dig_regs rtw8852b_dig_regs = {
31062306a36Sopenharmony_ci	.seg0_pd_reg = R_SEG0R_PD_V1,
31162306a36Sopenharmony_ci	.pd_lower_bound_mask = B_SEG0R_PD_LOWER_BOUND_MSK,
31262306a36Sopenharmony_ci	.pd_spatial_reuse_en = B_SEG0R_PD_SPATIAL_REUSE_EN_MSK_V1,
31362306a36Sopenharmony_ci	.bmode_pd_reg = R_BMODE_PDTH_EN_V1,
31462306a36Sopenharmony_ci	.bmode_cca_rssi_limit_en = B_BMODE_PDTH_LIMIT_EN_MSK_V1,
31562306a36Sopenharmony_ci	.bmode_pd_lower_bound_reg = R_BMODE_PDTH_V1,
31662306a36Sopenharmony_ci	.bmode_rssi_nocca_low_th_mask = B_BMODE_PDTH_LOWER_BOUND_MSK_V1,
31762306a36Sopenharmony_ci	.p0_lna_init = {R_PATH0_LNA_INIT_V1, B_PATH0_LNA_INIT_IDX_MSK},
31862306a36Sopenharmony_ci	.p1_lna_init = {R_PATH1_LNA_INIT_V1, B_PATH1_LNA_INIT_IDX_MSK},
31962306a36Sopenharmony_ci	.p0_tia_init = {R_PATH0_TIA_INIT_V1, B_PATH0_TIA_INIT_IDX_MSK_V1},
32062306a36Sopenharmony_ci	.p1_tia_init = {R_PATH1_TIA_INIT_V1, B_PATH1_TIA_INIT_IDX_MSK_V1},
32162306a36Sopenharmony_ci	.p0_rxb_init = {R_PATH0_RXB_INIT_V1, B_PATH0_RXB_INIT_IDX_MSK_V1},
32262306a36Sopenharmony_ci	.p1_rxb_init = {R_PATH1_RXB_INIT_V1, B_PATH1_RXB_INIT_IDX_MSK_V1},
32362306a36Sopenharmony_ci	.p0_p20_pagcugc_en = {R_PATH0_P20_FOLLOW_BY_PAGCUGC_V2,
32462306a36Sopenharmony_ci			      B_PATH0_P20_FOLLOW_BY_PAGCUGC_EN_MSK},
32562306a36Sopenharmony_ci	.p0_s20_pagcugc_en = {R_PATH0_S20_FOLLOW_BY_PAGCUGC_V2,
32662306a36Sopenharmony_ci			      B_PATH0_S20_FOLLOW_BY_PAGCUGC_EN_MSK},
32762306a36Sopenharmony_ci	.p1_p20_pagcugc_en = {R_PATH1_P20_FOLLOW_BY_PAGCUGC_V2,
32862306a36Sopenharmony_ci			      B_PATH1_P20_FOLLOW_BY_PAGCUGC_EN_MSK},
32962306a36Sopenharmony_ci	.p1_s20_pagcugc_en = {R_PATH1_S20_FOLLOW_BY_PAGCUGC_V2,
33062306a36Sopenharmony_ci			      B_PATH1_S20_FOLLOW_BY_PAGCUGC_EN_MSK},
33162306a36Sopenharmony_ci};
33262306a36Sopenharmony_ci
33362306a36Sopenharmony_cistatic const struct rtw89_btc_rf_trx_para rtw89_btc_8852b_rf_ul[] = {
33462306a36Sopenharmony_ci	{255, 0, 0, 7}, /* 0 -> original */
33562306a36Sopenharmony_ci	{255, 2, 0, 7}, /* 1 -> for BT-connected ACI issue && BTG co-rx */
33662306a36Sopenharmony_ci	{255, 0, 0, 7}, /* 2 ->reserved for shared-antenna */
33762306a36Sopenharmony_ci	{255, 0, 0, 7}, /* 3- >reserved for shared-antenna */
33862306a36Sopenharmony_ci	{255, 0, 0, 7}, /* 4 ->reserved for shared-antenna */
33962306a36Sopenharmony_ci	{255, 1, 0, 7}, /* the below id is for non-shared-antenna free-run */
34062306a36Sopenharmony_ci	{6, 1, 0, 7},
34162306a36Sopenharmony_ci	{13, 1, 0, 7},
34262306a36Sopenharmony_ci	{13, 1, 0, 7}
34362306a36Sopenharmony_ci};
34462306a36Sopenharmony_ci
34562306a36Sopenharmony_cistatic const struct rtw89_btc_rf_trx_para rtw89_btc_8852b_rf_dl[] = {
34662306a36Sopenharmony_ci	{255, 0, 0, 7}, /* 0 -> original */
34762306a36Sopenharmony_ci	{255, 2, 0, 7}, /* 1 -> reserved for shared-antenna */
34862306a36Sopenharmony_ci	{255, 0, 0, 7}, /* 2 ->reserved for shared-antenna */
34962306a36Sopenharmony_ci	{255, 0, 0, 7}, /* 3- >reserved for shared-antenna */
35062306a36Sopenharmony_ci	{255, 0, 0, 7}, /* 4 ->reserved for shared-antenna */
35162306a36Sopenharmony_ci	{255, 1, 0, 7}, /* the below id is for non-shared-antenna free-run */
35262306a36Sopenharmony_ci	{255, 1, 0, 7},
35362306a36Sopenharmony_ci	{255, 1, 0, 7},
35462306a36Sopenharmony_ci	{255, 1, 0, 7}
35562306a36Sopenharmony_ci};
35662306a36Sopenharmony_ci
35762306a36Sopenharmony_cistatic const struct rtw89_btc_fbtc_mreg rtw89_btc_8852b_mon_reg[] = {
35862306a36Sopenharmony_ci	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda24),
35962306a36Sopenharmony_ci	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda28),
36062306a36Sopenharmony_ci	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda2c),
36162306a36Sopenharmony_ci	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda30),
36262306a36Sopenharmony_ci	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda4c),
36362306a36Sopenharmony_ci	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda10),
36462306a36Sopenharmony_ci	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda20),
36562306a36Sopenharmony_ci	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xda34),
36662306a36Sopenharmony_ci	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xcef4),
36762306a36Sopenharmony_ci	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0x8424),
36862306a36Sopenharmony_ci	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xd200),
36962306a36Sopenharmony_ci	RTW89_DEF_FBTC_MREG(REG_MAC, 4, 0xd220),
37062306a36Sopenharmony_ci	RTW89_DEF_FBTC_MREG(REG_BB, 4, 0x980),
37162306a36Sopenharmony_ci	RTW89_DEF_FBTC_MREG(REG_BB, 4, 0x4738),
37262306a36Sopenharmony_ci	RTW89_DEF_FBTC_MREG(REG_BB, 4, 0x4688),
37362306a36Sopenharmony_ci	RTW89_DEF_FBTC_MREG(REG_BB, 4, 0x4694),
37462306a36Sopenharmony_ci};
37562306a36Sopenharmony_ci
37662306a36Sopenharmony_cistatic const u8 rtw89_btc_8852b_wl_rssi_thres[BTC_WL_RSSI_THMAX] = {70, 60, 50, 40};
37762306a36Sopenharmony_cistatic const u8 rtw89_btc_8852b_bt_rssi_thres[BTC_BT_RSSI_THMAX] = {50, 40, 30, 20};
37862306a36Sopenharmony_ci
37962306a36Sopenharmony_cistatic int rtw8852b_pwr_on_func(struct rtw89_dev *rtwdev)
38062306a36Sopenharmony_ci{
38162306a36Sopenharmony_ci	u32 val32;
38262306a36Sopenharmony_ci	u32 ret;
38362306a36Sopenharmony_ci
38462306a36Sopenharmony_ci	rtw89_write32_clr(rtwdev, R_AX_SYS_PW_CTRL, B_AX_AFSM_WLSUS_EN |
38562306a36Sopenharmony_ci						    B_AX_AFSM_PCIE_SUS_EN);
38662306a36Sopenharmony_ci	rtw89_write32_set(rtwdev, R_AX_SYS_PW_CTRL, B_AX_DIS_WLBT_PDNSUSEN_SOPC);
38762306a36Sopenharmony_ci	rtw89_write32_set(rtwdev, R_AX_WLLPS_CTRL, B_AX_DIS_WLBT_LPSEN_LOPC);
38862306a36Sopenharmony_ci	rtw89_write32_clr(rtwdev, R_AX_SYS_PW_CTRL, B_AX_APDM_HPDN);
38962306a36Sopenharmony_ci	rtw89_write32_clr(rtwdev, R_AX_SYS_PW_CTRL, B_AX_APFM_SWLPS);
39062306a36Sopenharmony_ci
39162306a36Sopenharmony_ci	ret = read_poll_timeout(rtw89_read32, val32, val32 & B_AX_RDY_SYSPWR,
39262306a36Sopenharmony_ci				1000, 20000, false, rtwdev, R_AX_SYS_PW_CTRL);
39362306a36Sopenharmony_ci	if (ret)
39462306a36Sopenharmony_ci		return ret;
39562306a36Sopenharmony_ci
39662306a36Sopenharmony_ci	rtw89_write32_set(rtwdev, R_AX_AFE_LDO_CTRL, B_AX_AON_OFF_PC_EN);
39762306a36Sopenharmony_ci	ret = read_poll_timeout(rtw89_read32, val32, val32 & B_AX_AON_OFF_PC_EN,
39862306a36Sopenharmony_ci				1000, 20000, false, rtwdev, R_AX_AFE_LDO_CTRL);
39962306a36Sopenharmony_ci	if (ret)
40062306a36Sopenharmony_ci		return ret;
40162306a36Sopenharmony_ci
40262306a36Sopenharmony_ci	rtw89_write32_mask(rtwdev, R_AX_SPS_DIG_OFF_CTRL0, B_AX_C1_L1_MASK, 0x1);
40362306a36Sopenharmony_ci	rtw89_write32_mask(rtwdev, R_AX_SPS_DIG_OFF_CTRL0, B_AX_C3_L1_MASK, 0x3);
40462306a36Sopenharmony_ci	rtw89_write32_set(rtwdev, R_AX_SYS_PW_CTRL, B_AX_EN_WLON);
40562306a36Sopenharmony_ci	rtw89_write32_set(rtwdev, R_AX_SYS_PW_CTRL, B_AX_APFN_ONMAC);
40662306a36Sopenharmony_ci
40762306a36Sopenharmony_ci	ret = read_poll_timeout(rtw89_read32, val32, !(val32 & B_AX_APFN_ONMAC),
40862306a36Sopenharmony_ci				1000, 20000, false, rtwdev, R_AX_SYS_PW_CTRL);
40962306a36Sopenharmony_ci	if (ret)
41062306a36Sopenharmony_ci		return ret;
41162306a36Sopenharmony_ci
41262306a36Sopenharmony_ci	rtw89_write8_set(rtwdev, R_AX_PLATFORM_ENABLE, B_AX_PLATFORM_EN);
41362306a36Sopenharmony_ci	rtw89_write8_clr(rtwdev, R_AX_PLATFORM_ENABLE, B_AX_PLATFORM_EN);
41462306a36Sopenharmony_ci	rtw89_write8_set(rtwdev, R_AX_PLATFORM_ENABLE, B_AX_PLATFORM_EN);
41562306a36Sopenharmony_ci	rtw89_write8_clr(rtwdev, R_AX_PLATFORM_ENABLE, B_AX_PLATFORM_EN);
41662306a36Sopenharmony_ci
41762306a36Sopenharmony_ci	rtw89_write8_set(rtwdev, R_AX_PLATFORM_ENABLE, B_AX_PLATFORM_EN);
41862306a36Sopenharmony_ci	rtw89_write32_clr(rtwdev, R_AX_SYS_SDIO_CTRL, B_AX_PCIE_CALIB_EN_V1);
41962306a36Sopenharmony_ci
42062306a36Sopenharmony_ci	rtw89_write32_set(rtwdev, R_AX_SYS_ADIE_PAD_PWR_CTRL, B_AX_SYM_PADPDN_WL_PTA_1P3);
42162306a36Sopenharmony_ci
42262306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL,
42362306a36Sopenharmony_ci				      XTAL_SI_GND_SHDN_WL, XTAL_SI_GND_SHDN_WL);
42462306a36Sopenharmony_ci	if (ret)
42562306a36Sopenharmony_ci		return ret;
42662306a36Sopenharmony_ci
42762306a36Sopenharmony_ci	rtw89_write32_set(rtwdev, R_AX_SYS_ADIE_PAD_PWR_CTRL, B_AX_SYM_PADPDN_WL_RFC_1P3);
42862306a36Sopenharmony_ci
42962306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL,
43062306a36Sopenharmony_ci				      XTAL_SI_SHDN_WL, XTAL_SI_SHDN_WL);
43162306a36Sopenharmony_ci	if (ret)
43262306a36Sopenharmony_ci		return ret;
43362306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, XTAL_SI_OFF_WEI,
43462306a36Sopenharmony_ci				      XTAL_SI_OFF_WEI);
43562306a36Sopenharmony_ci	if (ret)
43662306a36Sopenharmony_ci		return ret;
43762306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, XTAL_SI_OFF_EI,
43862306a36Sopenharmony_ci				      XTAL_SI_OFF_EI);
43962306a36Sopenharmony_ci	if (ret)
44062306a36Sopenharmony_ci		return ret;
44162306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_RFC2RF);
44262306a36Sopenharmony_ci	if (ret)
44362306a36Sopenharmony_ci		return ret;
44462306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, XTAL_SI_PON_WEI,
44562306a36Sopenharmony_ci				      XTAL_SI_PON_WEI);
44662306a36Sopenharmony_ci	if (ret)
44762306a36Sopenharmony_ci		return ret;
44862306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, XTAL_SI_PON_EI,
44962306a36Sopenharmony_ci				      XTAL_SI_PON_EI);
45062306a36Sopenharmony_ci	if (ret)
45162306a36Sopenharmony_ci		return ret;
45262306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_SRAM2RFC);
45362306a36Sopenharmony_ci	if (ret)
45462306a36Sopenharmony_ci		return ret;
45562306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_SRAM_CTRL, 0, XTAL_SI_SRAM_DIS);
45662306a36Sopenharmony_ci	if (ret)
45762306a36Sopenharmony_ci		return ret;
45862306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_XTAL_XMD_2, 0, XTAL_SI_LDO_LPS);
45962306a36Sopenharmony_ci	if (ret)
46062306a36Sopenharmony_ci		return ret;
46162306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_XTAL_XMD_4, 0, XTAL_SI_LPS_CAP);
46262306a36Sopenharmony_ci	if (ret)
46362306a36Sopenharmony_ci		return ret;
46462306a36Sopenharmony_ci
46562306a36Sopenharmony_ci	rtw89_write32_set(rtwdev, R_AX_PMC_DBG_CTRL2, B_AX_SYSON_DIS_PMCR_AX_WRMSK);
46662306a36Sopenharmony_ci	rtw89_write32_set(rtwdev, R_AX_SYS_ISO_CTRL, B_AX_ISO_EB2CORE);
46762306a36Sopenharmony_ci	rtw89_write32_clr(rtwdev, R_AX_SYS_ISO_CTRL, B_AX_PWC_EV2EF_B15);
46862306a36Sopenharmony_ci
46962306a36Sopenharmony_ci	fsleep(1000);
47062306a36Sopenharmony_ci
47162306a36Sopenharmony_ci	rtw89_write32_clr(rtwdev, R_AX_SYS_ISO_CTRL, B_AX_PWC_EV2EF_B14);
47262306a36Sopenharmony_ci	rtw89_write32_clr(rtwdev, R_AX_PMC_DBG_CTRL2, B_AX_SYSON_DIS_PMCR_AX_WRMSK);
47362306a36Sopenharmony_ci
47462306a36Sopenharmony_ci	if (!rtwdev->efuse.valid || rtwdev->efuse.power_k_valid)
47562306a36Sopenharmony_ci		goto func_en;
47662306a36Sopenharmony_ci
47762306a36Sopenharmony_ci	rtw89_write32_mask(rtwdev, R_AX_SPS_DIG_ON_CTRL0, B_AX_VOL_L1_MASK, 0x9);
47862306a36Sopenharmony_ci	rtw89_write32_mask(rtwdev, R_AX_SPS_DIG_ON_CTRL0, B_AX_VREFPFM_L_MASK, 0xA);
47962306a36Sopenharmony_ci
48062306a36Sopenharmony_ci	if (rtwdev->hal.cv == CHIP_CBV) {
48162306a36Sopenharmony_ci		rtw89_write32_set(rtwdev, R_AX_PMC_DBG_CTRL2, B_AX_SYSON_DIS_PMCR_AX_WRMSK);
48262306a36Sopenharmony_ci		rtw89_write16_mask(rtwdev, R_AX_HCI_LDO_CTRL, B_AX_R_AX_VADJ_MASK, 0xA);
48362306a36Sopenharmony_ci		rtw89_write32_clr(rtwdev, R_AX_PMC_DBG_CTRL2, B_AX_SYSON_DIS_PMCR_AX_WRMSK);
48462306a36Sopenharmony_ci	}
48562306a36Sopenharmony_ci
48662306a36Sopenharmony_cifunc_en:
48762306a36Sopenharmony_ci	rtw89_write32_set(rtwdev, R_AX_DMAC_FUNC_EN,
48862306a36Sopenharmony_ci			  B_AX_MAC_FUNC_EN | B_AX_DMAC_FUNC_EN | B_AX_MPDU_PROC_EN |
48962306a36Sopenharmony_ci			  B_AX_WD_RLS_EN | B_AX_DLE_WDE_EN | B_AX_TXPKT_CTRL_EN |
49062306a36Sopenharmony_ci			  B_AX_STA_SCH_EN | B_AX_DLE_PLE_EN | B_AX_PKT_BUF_EN |
49162306a36Sopenharmony_ci			  B_AX_DMAC_TBL_EN | B_AX_PKT_IN_EN | B_AX_DLE_CPUIO_EN |
49262306a36Sopenharmony_ci			  B_AX_DISPATCHER_EN | B_AX_BBRPT_EN | B_AX_MAC_SEC_EN |
49362306a36Sopenharmony_ci			  B_AX_DMACREG_GCKEN);
49462306a36Sopenharmony_ci	rtw89_write32_set(rtwdev, R_AX_CMAC_FUNC_EN,
49562306a36Sopenharmony_ci			  B_AX_CMAC_EN | B_AX_CMAC_TXEN | B_AX_CMAC_RXEN |
49662306a36Sopenharmony_ci			  B_AX_FORCE_CMACREG_GCKEN | B_AX_PHYINTF_EN | B_AX_CMAC_DMA_EN |
49762306a36Sopenharmony_ci			  B_AX_PTCLTOP_EN | B_AX_SCHEDULER_EN | B_AX_TMAC_EN |
49862306a36Sopenharmony_ci			  B_AX_RMAC_EN);
49962306a36Sopenharmony_ci
50062306a36Sopenharmony_ci	rtw89_write32_mask(rtwdev, R_AX_EECS_EESK_FUNC_SEL, B_AX_PINMUX_EESK_FUNC_SEL_MASK,
50162306a36Sopenharmony_ci			   PINMUX_EESK_FUNC_SEL_BT_LOG);
50262306a36Sopenharmony_ci
50362306a36Sopenharmony_ci	return 0;
50462306a36Sopenharmony_ci}
50562306a36Sopenharmony_ci
50662306a36Sopenharmony_cistatic int rtw8852b_pwr_off_func(struct rtw89_dev *rtwdev)
50762306a36Sopenharmony_ci{
50862306a36Sopenharmony_ci	u32 val32;
50962306a36Sopenharmony_ci	u32 ret;
51062306a36Sopenharmony_ci
51162306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, XTAL_SI_RFC2RF,
51262306a36Sopenharmony_ci				      XTAL_SI_RFC2RF);
51362306a36Sopenharmony_ci	if (ret)
51462306a36Sopenharmony_ci		return ret;
51562306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_OFF_EI);
51662306a36Sopenharmony_ci	if (ret)
51762306a36Sopenharmony_ci		return ret;
51862306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_OFF_WEI);
51962306a36Sopenharmony_ci	if (ret)
52062306a36Sopenharmony_ci		return ret;
52162306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_WL_RFC_S0, 0, XTAL_SI_RF00);
52262306a36Sopenharmony_ci	if (ret)
52362306a36Sopenharmony_ci		return ret;
52462306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_WL_RFC_S1, 0, XTAL_SI_RF10);
52562306a36Sopenharmony_ci	if (ret)
52662306a36Sopenharmony_ci		return ret;
52762306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, XTAL_SI_SRAM2RFC,
52862306a36Sopenharmony_ci				      XTAL_SI_SRAM2RFC);
52962306a36Sopenharmony_ci	if (ret)
53062306a36Sopenharmony_ci		return ret;
53162306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_PON_EI);
53262306a36Sopenharmony_ci	if (ret)
53362306a36Sopenharmony_ci		return ret;
53462306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_PON_WEI);
53562306a36Sopenharmony_ci	if (ret)
53662306a36Sopenharmony_ci		return ret;
53762306a36Sopenharmony_ci
53862306a36Sopenharmony_ci	rtw89_write32_set(rtwdev, R_AX_SYS_PW_CTRL, B_AX_EN_WLON);
53962306a36Sopenharmony_ci	rtw89_write8_clr(rtwdev, R_AX_SYS_FUNC_EN, B_AX_FEN_BB_GLB_RSTN | B_AX_FEN_BBRSTB);
54062306a36Sopenharmony_ci	rtw89_write32_clr(rtwdev, R_AX_SYS_ADIE_PAD_PWR_CTRL, B_AX_SYM_PADPDN_WL_RFC_1P3);
54162306a36Sopenharmony_ci
54262306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_SHDN_WL);
54362306a36Sopenharmony_ci	if (ret)
54462306a36Sopenharmony_ci		return ret;
54562306a36Sopenharmony_ci
54662306a36Sopenharmony_ci	rtw89_write32_clr(rtwdev, R_AX_SYS_ADIE_PAD_PWR_CTRL, B_AX_SYM_PADPDN_WL_PTA_1P3);
54762306a36Sopenharmony_ci
54862306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_ANAPAR_WL, 0, XTAL_SI_GND_SHDN_WL);
54962306a36Sopenharmony_ci	if (ret)
55062306a36Sopenharmony_ci		return ret;
55162306a36Sopenharmony_ci
55262306a36Sopenharmony_ci	rtw89_write32_set(rtwdev, R_AX_SYS_PW_CTRL, B_AX_APFM_OFFMAC);
55362306a36Sopenharmony_ci
55462306a36Sopenharmony_ci	ret = read_poll_timeout(rtw89_read32, val32, !(val32 & B_AX_APFM_OFFMAC),
55562306a36Sopenharmony_ci				1000, 20000, false, rtwdev, R_AX_SYS_PW_CTRL);
55662306a36Sopenharmony_ci	if (ret)
55762306a36Sopenharmony_ci		return ret;
55862306a36Sopenharmony_ci
55962306a36Sopenharmony_ci	rtw89_write32(rtwdev, R_AX_WLLPS_CTRL, SW_LPS_OPTION);
56062306a36Sopenharmony_ci	rtw89_write32_set(rtwdev, R_AX_SYS_SWR_CTRL1, B_AX_SYM_CTRL_SPS_PWMFREQ);
56162306a36Sopenharmony_ci	rtw89_write32_mask(rtwdev, R_AX_SPS_DIG_ON_CTRL0, B_AX_REG_ZCDC_H_MASK, 0x3);
56262306a36Sopenharmony_ci	rtw89_write32_set(rtwdev, R_AX_SYS_PW_CTRL, B_AX_APFM_SWLPS);
56362306a36Sopenharmony_ci
56462306a36Sopenharmony_ci	return 0;
56562306a36Sopenharmony_ci}
56662306a36Sopenharmony_ci
56762306a36Sopenharmony_cistatic void rtw8852be_efuse_parsing(struct rtw89_efuse *efuse,
56862306a36Sopenharmony_ci				    struct rtw8852b_efuse *map)
56962306a36Sopenharmony_ci{
57062306a36Sopenharmony_ci	ether_addr_copy(efuse->addr, map->e.mac_addr);
57162306a36Sopenharmony_ci	efuse->rfe_type = map->rfe_type;
57262306a36Sopenharmony_ci	efuse->xtal_cap = map->xtal_k;
57362306a36Sopenharmony_ci}
57462306a36Sopenharmony_ci
57562306a36Sopenharmony_cistatic void rtw8852b_efuse_parsing_tssi(struct rtw89_dev *rtwdev,
57662306a36Sopenharmony_ci					struct rtw8852b_efuse *map)
57762306a36Sopenharmony_ci{
57862306a36Sopenharmony_ci	struct rtw89_tssi_info *tssi = &rtwdev->tssi;
57962306a36Sopenharmony_ci	struct rtw8852b_tssi_offset *ofst[] = {&map->path_a_tssi, &map->path_b_tssi};
58062306a36Sopenharmony_ci	u8 i, j;
58162306a36Sopenharmony_ci
58262306a36Sopenharmony_ci	tssi->thermal[RF_PATH_A] = map->path_a_therm;
58362306a36Sopenharmony_ci	tssi->thermal[RF_PATH_B] = map->path_b_therm;
58462306a36Sopenharmony_ci
58562306a36Sopenharmony_ci	for (i = 0; i < RF_PATH_NUM_8852B; i++) {
58662306a36Sopenharmony_ci		memcpy(tssi->tssi_cck[i], ofst[i]->cck_tssi,
58762306a36Sopenharmony_ci		       sizeof(ofst[i]->cck_tssi));
58862306a36Sopenharmony_ci
58962306a36Sopenharmony_ci		for (j = 0; j < TSSI_CCK_CH_GROUP_NUM; j++)
59062306a36Sopenharmony_ci			rtw89_debug(rtwdev, RTW89_DBG_TSSI,
59162306a36Sopenharmony_ci				    "[TSSI][EFUSE] path=%d cck[%d]=0x%x\n",
59262306a36Sopenharmony_ci				    i, j, tssi->tssi_cck[i][j]);
59362306a36Sopenharmony_ci
59462306a36Sopenharmony_ci		memcpy(tssi->tssi_mcs[i], ofst[i]->bw40_tssi,
59562306a36Sopenharmony_ci		       sizeof(ofst[i]->bw40_tssi));
59662306a36Sopenharmony_ci		memcpy(tssi->tssi_mcs[i] + TSSI_MCS_2G_CH_GROUP_NUM,
59762306a36Sopenharmony_ci		       ofst[i]->bw40_1s_tssi_5g, sizeof(ofst[i]->bw40_1s_tssi_5g));
59862306a36Sopenharmony_ci
59962306a36Sopenharmony_ci		for (j = 0; j < TSSI_MCS_CH_GROUP_NUM; j++)
60062306a36Sopenharmony_ci			rtw89_debug(rtwdev, RTW89_DBG_TSSI,
60162306a36Sopenharmony_ci				    "[TSSI][EFUSE] path=%d mcs[%d]=0x%x\n",
60262306a36Sopenharmony_ci				    i, j, tssi->tssi_mcs[i][j]);
60362306a36Sopenharmony_ci	}
60462306a36Sopenharmony_ci}
60562306a36Sopenharmony_ci
60662306a36Sopenharmony_cistatic bool _decode_efuse_gain(u8 data, s8 *high, s8 *low)
60762306a36Sopenharmony_ci{
60862306a36Sopenharmony_ci	if (high)
60962306a36Sopenharmony_ci		*high = sign_extend32(FIELD_GET(GENMASK(7,  4), data), 3);
61062306a36Sopenharmony_ci	if (low)
61162306a36Sopenharmony_ci		*low = sign_extend32(FIELD_GET(GENMASK(3,  0), data), 3);
61262306a36Sopenharmony_ci
61362306a36Sopenharmony_ci	return data != 0xff;
61462306a36Sopenharmony_ci}
61562306a36Sopenharmony_ci
61662306a36Sopenharmony_cistatic void rtw8852b_efuse_parsing_gain_offset(struct rtw89_dev *rtwdev,
61762306a36Sopenharmony_ci					       struct rtw8852b_efuse *map)
61862306a36Sopenharmony_ci{
61962306a36Sopenharmony_ci	struct rtw89_phy_efuse_gain *gain = &rtwdev->efuse_gain;
62062306a36Sopenharmony_ci	bool valid = false;
62162306a36Sopenharmony_ci
62262306a36Sopenharmony_ci	valid |= _decode_efuse_gain(map->rx_gain_2g_cck,
62362306a36Sopenharmony_ci				    &gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_2G_CCK],
62462306a36Sopenharmony_ci				    &gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_2G_CCK]);
62562306a36Sopenharmony_ci	valid |= _decode_efuse_gain(map->rx_gain_2g_ofdm,
62662306a36Sopenharmony_ci				    &gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_2G_OFDM],
62762306a36Sopenharmony_ci				    &gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_2G_OFDM]);
62862306a36Sopenharmony_ci	valid |= _decode_efuse_gain(map->rx_gain_5g_low,
62962306a36Sopenharmony_ci				    &gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_5G_LOW],
63062306a36Sopenharmony_ci				    &gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_5G_LOW]);
63162306a36Sopenharmony_ci	valid |= _decode_efuse_gain(map->rx_gain_5g_mid,
63262306a36Sopenharmony_ci				    &gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_5G_MID],
63362306a36Sopenharmony_ci				    &gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_5G_MID]);
63462306a36Sopenharmony_ci	valid |= _decode_efuse_gain(map->rx_gain_5g_high,
63562306a36Sopenharmony_ci				    &gain->offset[RF_PATH_A][RTW89_GAIN_OFFSET_5G_HIGH],
63662306a36Sopenharmony_ci				    &gain->offset[RF_PATH_B][RTW89_GAIN_OFFSET_5G_HIGH]);
63762306a36Sopenharmony_ci
63862306a36Sopenharmony_ci	gain->offset_valid = valid;
63962306a36Sopenharmony_ci}
64062306a36Sopenharmony_ci
64162306a36Sopenharmony_cistatic int rtw8852b_read_efuse(struct rtw89_dev *rtwdev, u8 *log_map)
64262306a36Sopenharmony_ci{
64362306a36Sopenharmony_ci	struct rtw89_efuse *efuse = &rtwdev->efuse;
64462306a36Sopenharmony_ci	struct rtw8852b_efuse *map;
64562306a36Sopenharmony_ci
64662306a36Sopenharmony_ci	map = (struct rtw8852b_efuse *)log_map;
64762306a36Sopenharmony_ci
64862306a36Sopenharmony_ci	efuse->country_code[0] = map->country_code[0];
64962306a36Sopenharmony_ci	efuse->country_code[1] = map->country_code[1];
65062306a36Sopenharmony_ci	rtw8852b_efuse_parsing_tssi(rtwdev, map);
65162306a36Sopenharmony_ci	rtw8852b_efuse_parsing_gain_offset(rtwdev, map);
65262306a36Sopenharmony_ci
65362306a36Sopenharmony_ci	switch (rtwdev->hci.type) {
65462306a36Sopenharmony_ci	case RTW89_HCI_TYPE_PCIE:
65562306a36Sopenharmony_ci		rtw8852be_efuse_parsing(efuse, map);
65662306a36Sopenharmony_ci		break;
65762306a36Sopenharmony_ci	default:
65862306a36Sopenharmony_ci		return -EOPNOTSUPP;
65962306a36Sopenharmony_ci	}
66062306a36Sopenharmony_ci
66162306a36Sopenharmony_ci	rtw89_info(rtwdev, "chip rfe_type is %d\n", efuse->rfe_type);
66262306a36Sopenharmony_ci
66362306a36Sopenharmony_ci	return 0;
66462306a36Sopenharmony_ci}
66562306a36Sopenharmony_ci
66662306a36Sopenharmony_cistatic void rtw8852b_phycap_parsing_power_cal(struct rtw89_dev *rtwdev, u8 *phycap_map)
66762306a36Sopenharmony_ci{
66862306a36Sopenharmony_ci#define PWR_K_CHK_OFFSET 0x5E9
66962306a36Sopenharmony_ci#define PWR_K_CHK_VALUE 0xAA
67062306a36Sopenharmony_ci	u32 offset = PWR_K_CHK_OFFSET - rtwdev->chip->phycap_addr;
67162306a36Sopenharmony_ci
67262306a36Sopenharmony_ci	if (phycap_map[offset] == PWR_K_CHK_VALUE)
67362306a36Sopenharmony_ci		rtwdev->efuse.power_k_valid = true;
67462306a36Sopenharmony_ci}
67562306a36Sopenharmony_ci
67662306a36Sopenharmony_cistatic void rtw8852b_phycap_parsing_tssi(struct rtw89_dev *rtwdev, u8 *phycap_map)
67762306a36Sopenharmony_ci{
67862306a36Sopenharmony_ci	struct rtw89_tssi_info *tssi = &rtwdev->tssi;
67962306a36Sopenharmony_ci	static const u32 tssi_trim_addr[RF_PATH_NUM_8852B] = {0x5D6, 0x5AB};
68062306a36Sopenharmony_ci	u32 addr = rtwdev->chip->phycap_addr;
68162306a36Sopenharmony_ci	bool pg = false;
68262306a36Sopenharmony_ci	u32 ofst;
68362306a36Sopenharmony_ci	u8 i, j;
68462306a36Sopenharmony_ci
68562306a36Sopenharmony_ci	for (i = 0; i < RF_PATH_NUM_8852B; i++) {
68662306a36Sopenharmony_ci		for (j = 0; j < TSSI_TRIM_CH_GROUP_NUM; j++) {
68762306a36Sopenharmony_ci			/* addrs are in decreasing order */
68862306a36Sopenharmony_ci			ofst = tssi_trim_addr[i] - addr - j;
68962306a36Sopenharmony_ci			tssi->tssi_trim[i][j] = phycap_map[ofst];
69062306a36Sopenharmony_ci
69162306a36Sopenharmony_ci			if (phycap_map[ofst] != 0xff)
69262306a36Sopenharmony_ci				pg = true;
69362306a36Sopenharmony_ci		}
69462306a36Sopenharmony_ci	}
69562306a36Sopenharmony_ci
69662306a36Sopenharmony_ci	if (!pg) {
69762306a36Sopenharmony_ci		memset(tssi->tssi_trim, 0, sizeof(tssi->tssi_trim));
69862306a36Sopenharmony_ci		rtw89_debug(rtwdev, RTW89_DBG_TSSI,
69962306a36Sopenharmony_ci			    "[TSSI][TRIM] no PG, set all trim info to 0\n");
70062306a36Sopenharmony_ci	}
70162306a36Sopenharmony_ci
70262306a36Sopenharmony_ci	for (i = 0; i < RF_PATH_NUM_8852B; i++)
70362306a36Sopenharmony_ci		for (j = 0; j < TSSI_TRIM_CH_GROUP_NUM; j++)
70462306a36Sopenharmony_ci			rtw89_debug(rtwdev, RTW89_DBG_TSSI,
70562306a36Sopenharmony_ci				    "[TSSI] path=%d idx=%d trim=0x%x addr=0x%x\n",
70662306a36Sopenharmony_ci				    i, j, tssi->tssi_trim[i][j],
70762306a36Sopenharmony_ci				    tssi_trim_addr[i] - j);
70862306a36Sopenharmony_ci}
70962306a36Sopenharmony_ci
71062306a36Sopenharmony_cistatic void rtw8852b_phycap_parsing_thermal_trim(struct rtw89_dev *rtwdev,
71162306a36Sopenharmony_ci						 u8 *phycap_map)
71262306a36Sopenharmony_ci{
71362306a36Sopenharmony_ci	struct rtw89_power_trim_info *info = &rtwdev->pwr_trim;
71462306a36Sopenharmony_ci	static const u32 thm_trim_addr[RF_PATH_NUM_8852B] = {0x5DF, 0x5DC};
71562306a36Sopenharmony_ci	u32 addr = rtwdev->chip->phycap_addr;
71662306a36Sopenharmony_ci	u8 i;
71762306a36Sopenharmony_ci
71862306a36Sopenharmony_ci	for (i = 0; i < RF_PATH_NUM_8852B; i++) {
71962306a36Sopenharmony_ci		info->thermal_trim[i] = phycap_map[thm_trim_addr[i] - addr];
72062306a36Sopenharmony_ci
72162306a36Sopenharmony_ci		rtw89_debug(rtwdev, RTW89_DBG_RFK,
72262306a36Sopenharmony_ci			    "[THERMAL][TRIM] path=%d thermal_trim=0x%x\n",
72362306a36Sopenharmony_ci			    i, info->thermal_trim[i]);
72462306a36Sopenharmony_ci
72562306a36Sopenharmony_ci		if (info->thermal_trim[i] != 0xff)
72662306a36Sopenharmony_ci			info->pg_thermal_trim = true;
72762306a36Sopenharmony_ci	}
72862306a36Sopenharmony_ci}
72962306a36Sopenharmony_ci
73062306a36Sopenharmony_cistatic void rtw8852b_thermal_trim(struct rtw89_dev *rtwdev)
73162306a36Sopenharmony_ci{
73262306a36Sopenharmony_ci#define __thm_setting(raw)				\
73362306a36Sopenharmony_ci({							\
73462306a36Sopenharmony_ci	u8 __v = (raw);					\
73562306a36Sopenharmony_ci	((__v & 0x1) << 3) | ((__v & 0x1f) >> 1);	\
73662306a36Sopenharmony_ci})
73762306a36Sopenharmony_ci	struct rtw89_power_trim_info *info = &rtwdev->pwr_trim;
73862306a36Sopenharmony_ci	u8 i, val;
73962306a36Sopenharmony_ci
74062306a36Sopenharmony_ci	if (!info->pg_thermal_trim) {
74162306a36Sopenharmony_ci		rtw89_debug(rtwdev, RTW89_DBG_RFK,
74262306a36Sopenharmony_ci			    "[THERMAL][TRIM] no PG, do nothing\n");
74362306a36Sopenharmony_ci
74462306a36Sopenharmony_ci		return;
74562306a36Sopenharmony_ci	}
74662306a36Sopenharmony_ci
74762306a36Sopenharmony_ci	for (i = 0; i < RF_PATH_NUM_8852B; i++) {
74862306a36Sopenharmony_ci		val = __thm_setting(info->thermal_trim[i]);
74962306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, i, RR_TM2, RR_TM2_OFF, val);
75062306a36Sopenharmony_ci
75162306a36Sopenharmony_ci		rtw89_debug(rtwdev, RTW89_DBG_RFK,
75262306a36Sopenharmony_ci			    "[THERMAL][TRIM] path=%d thermal_setting=0x%x\n",
75362306a36Sopenharmony_ci			    i, val);
75462306a36Sopenharmony_ci	}
75562306a36Sopenharmony_ci#undef __thm_setting
75662306a36Sopenharmony_ci}
75762306a36Sopenharmony_ci
75862306a36Sopenharmony_cistatic void rtw8852b_phycap_parsing_pa_bias_trim(struct rtw89_dev *rtwdev,
75962306a36Sopenharmony_ci						 u8 *phycap_map)
76062306a36Sopenharmony_ci{
76162306a36Sopenharmony_ci	struct rtw89_power_trim_info *info = &rtwdev->pwr_trim;
76262306a36Sopenharmony_ci	static const u32 pabias_trim_addr[RF_PATH_NUM_8852B] = {0x5DE, 0x5DB};
76362306a36Sopenharmony_ci	u32 addr = rtwdev->chip->phycap_addr;
76462306a36Sopenharmony_ci	u8 i;
76562306a36Sopenharmony_ci
76662306a36Sopenharmony_ci	for (i = 0; i < RF_PATH_NUM_8852B; i++) {
76762306a36Sopenharmony_ci		info->pa_bias_trim[i] = phycap_map[pabias_trim_addr[i] - addr];
76862306a36Sopenharmony_ci
76962306a36Sopenharmony_ci		rtw89_debug(rtwdev, RTW89_DBG_RFK,
77062306a36Sopenharmony_ci			    "[PA_BIAS][TRIM] path=%d pa_bias_trim=0x%x\n",
77162306a36Sopenharmony_ci			    i, info->pa_bias_trim[i]);
77262306a36Sopenharmony_ci
77362306a36Sopenharmony_ci		if (info->pa_bias_trim[i] != 0xff)
77462306a36Sopenharmony_ci			info->pg_pa_bias_trim = true;
77562306a36Sopenharmony_ci	}
77662306a36Sopenharmony_ci}
77762306a36Sopenharmony_ci
77862306a36Sopenharmony_cistatic void rtw8852b_pa_bias_trim(struct rtw89_dev *rtwdev)
77962306a36Sopenharmony_ci{
78062306a36Sopenharmony_ci	struct rtw89_power_trim_info *info = &rtwdev->pwr_trim;
78162306a36Sopenharmony_ci	u8 pabias_2g, pabias_5g;
78262306a36Sopenharmony_ci	u8 i;
78362306a36Sopenharmony_ci
78462306a36Sopenharmony_ci	if (!info->pg_pa_bias_trim) {
78562306a36Sopenharmony_ci		rtw89_debug(rtwdev, RTW89_DBG_RFK,
78662306a36Sopenharmony_ci			    "[PA_BIAS][TRIM] no PG, do nothing\n");
78762306a36Sopenharmony_ci
78862306a36Sopenharmony_ci		return;
78962306a36Sopenharmony_ci	}
79062306a36Sopenharmony_ci
79162306a36Sopenharmony_ci	for (i = 0; i < RF_PATH_NUM_8852B; i++) {
79262306a36Sopenharmony_ci		pabias_2g = FIELD_GET(GENMASK(3, 0), info->pa_bias_trim[i]);
79362306a36Sopenharmony_ci		pabias_5g = FIELD_GET(GENMASK(7, 4), info->pa_bias_trim[i]);
79462306a36Sopenharmony_ci
79562306a36Sopenharmony_ci		rtw89_debug(rtwdev, RTW89_DBG_RFK,
79662306a36Sopenharmony_ci			    "[PA_BIAS][TRIM] path=%d 2G=0x%x 5G=0x%x\n",
79762306a36Sopenharmony_ci			    i, pabias_2g, pabias_5g);
79862306a36Sopenharmony_ci
79962306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, i, RR_BIASA, RR_BIASA_TXG, pabias_2g);
80062306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, i, RR_BIASA, RR_BIASA_TXA, pabias_5g);
80162306a36Sopenharmony_ci	}
80262306a36Sopenharmony_ci}
80362306a36Sopenharmony_ci
80462306a36Sopenharmony_cistatic void rtw8852b_phycap_parsing_gain_comp(struct rtw89_dev *rtwdev, u8 *phycap_map)
80562306a36Sopenharmony_ci{
80662306a36Sopenharmony_ci	static const u32 comp_addrs[][RTW89_SUBBAND_2GHZ_5GHZ_NR] = {
80762306a36Sopenharmony_ci		{0x5BB, 0x5BA, 0, 0x5B9, 0x5B8},
80862306a36Sopenharmony_ci		{0x590, 0x58F, 0, 0x58E, 0x58D},
80962306a36Sopenharmony_ci	};
81062306a36Sopenharmony_ci	struct rtw89_phy_efuse_gain *gain = &rtwdev->efuse_gain;
81162306a36Sopenharmony_ci	u32 phycap_addr = rtwdev->chip->phycap_addr;
81262306a36Sopenharmony_ci	bool valid = false;
81362306a36Sopenharmony_ci	int path, i;
81462306a36Sopenharmony_ci	u8 data;
81562306a36Sopenharmony_ci
81662306a36Sopenharmony_ci	for (path = 0; path < 2; path++)
81762306a36Sopenharmony_ci		for (i = 0; i < RTW89_SUBBAND_2GHZ_5GHZ_NR; i++) {
81862306a36Sopenharmony_ci			if (comp_addrs[path][i] == 0)
81962306a36Sopenharmony_ci				continue;
82062306a36Sopenharmony_ci
82162306a36Sopenharmony_ci			data = phycap_map[comp_addrs[path][i] - phycap_addr];
82262306a36Sopenharmony_ci			valid |= _decode_efuse_gain(data, NULL,
82362306a36Sopenharmony_ci						    &gain->comp[path][i]);
82462306a36Sopenharmony_ci		}
82562306a36Sopenharmony_ci
82662306a36Sopenharmony_ci	gain->comp_valid = valid;
82762306a36Sopenharmony_ci}
82862306a36Sopenharmony_ci
82962306a36Sopenharmony_cistatic int rtw8852b_read_phycap(struct rtw89_dev *rtwdev, u8 *phycap_map)
83062306a36Sopenharmony_ci{
83162306a36Sopenharmony_ci	rtw8852b_phycap_parsing_power_cal(rtwdev, phycap_map);
83262306a36Sopenharmony_ci	rtw8852b_phycap_parsing_tssi(rtwdev, phycap_map);
83362306a36Sopenharmony_ci	rtw8852b_phycap_parsing_thermal_trim(rtwdev, phycap_map);
83462306a36Sopenharmony_ci	rtw8852b_phycap_parsing_pa_bias_trim(rtwdev, phycap_map);
83562306a36Sopenharmony_ci	rtw8852b_phycap_parsing_gain_comp(rtwdev, phycap_map);
83662306a36Sopenharmony_ci
83762306a36Sopenharmony_ci	return 0;
83862306a36Sopenharmony_ci}
83962306a36Sopenharmony_ci
84062306a36Sopenharmony_cistatic void rtw8852b_power_trim(struct rtw89_dev *rtwdev)
84162306a36Sopenharmony_ci{
84262306a36Sopenharmony_ci	rtw8852b_thermal_trim(rtwdev);
84362306a36Sopenharmony_ci	rtw8852b_pa_bias_trim(rtwdev);
84462306a36Sopenharmony_ci}
84562306a36Sopenharmony_ci
84662306a36Sopenharmony_cistatic void rtw8852b_set_channel_mac(struct rtw89_dev *rtwdev,
84762306a36Sopenharmony_ci				     const struct rtw89_chan *chan,
84862306a36Sopenharmony_ci				     u8 mac_idx)
84962306a36Sopenharmony_ci{
85062306a36Sopenharmony_ci	u32 rf_mod = rtw89_mac_reg_by_idx(rtwdev, R_AX_WMAC_RFMOD, mac_idx);
85162306a36Sopenharmony_ci	u32 sub_carr = rtw89_mac_reg_by_idx(rtwdev, R_AX_TX_SUB_CARRIER_VALUE, mac_idx);
85262306a36Sopenharmony_ci	u32 chk_rate = rtw89_mac_reg_by_idx(rtwdev, R_AX_TXRATE_CHK, mac_idx);
85362306a36Sopenharmony_ci	u8 txsc20 = 0, txsc40 = 0;
85462306a36Sopenharmony_ci
85562306a36Sopenharmony_ci	switch (chan->band_width) {
85662306a36Sopenharmony_ci	case RTW89_CHANNEL_WIDTH_80:
85762306a36Sopenharmony_ci		txsc40 = rtw89_phy_get_txsc(rtwdev, chan, RTW89_CHANNEL_WIDTH_40);
85862306a36Sopenharmony_ci		fallthrough;
85962306a36Sopenharmony_ci	case RTW89_CHANNEL_WIDTH_40:
86062306a36Sopenharmony_ci		txsc20 = rtw89_phy_get_txsc(rtwdev, chan, RTW89_CHANNEL_WIDTH_20);
86162306a36Sopenharmony_ci		break;
86262306a36Sopenharmony_ci	default:
86362306a36Sopenharmony_ci		break;
86462306a36Sopenharmony_ci	}
86562306a36Sopenharmony_ci
86662306a36Sopenharmony_ci	switch (chan->band_width) {
86762306a36Sopenharmony_ci	case RTW89_CHANNEL_WIDTH_80:
86862306a36Sopenharmony_ci		rtw89_write8_mask(rtwdev, rf_mod, B_AX_WMAC_RFMOD_MASK, BIT(1));
86962306a36Sopenharmony_ci		rtw89_write32(rtwdev, sub_carr, txsc20 | (txsc40 << 4));
87062306a36Sopenharmony_ci		break;
87162306a36Sopenharmony_ci	case RTW89_CHANNEL_WIDTH_40:
87262306a36Sopenharmony_ci		rtw89_write8_mask(rtwdev, rf_mod, B_AX_WMAC_RFMOD_MASK, BIT(0));
87362306a36Sopenharmony_ci		rtw89_write32(rtwdev, sub_carr, txsc20);
87462306a36Sopenharmony_ci		break;
87562306a36Sopenharmony_ci	case RTW89_CHANNEL_WIDTH_20:
87662306a36Sopenharmony_ci		rtw89_write8_clr(rtwdev, rf_mod, B_AX_WMAC_RFMOD_MASK);
87762306a36Sopenharmony_ci		rtw89_write32(rtwdev, sub_carr, 0);
87862306a36Sopenharmony_ci		break;
87962306a36Sopenharmony_ci	default:
88062306a36Sopenharmony_ci		break;
88162306a36Sopenharmony_ci	}
88262306a36Sopenharmony_ci
88362306a36Sopenharmony_ci	if (chan->channel > 14) {
88462306a36Sopenharmony_ci		rtw89_write8_clr(rtwdev, chk_rate, B_AX_BAND_MODE);
88562306a36Sopenharmony_ci		rtw89_write8_set(rtwdev, chk_rate,
88662306a36Sopenharmony_ci				 B_AX_CHECK_CCK_EN | B_AX_RTS_LIMIT_IN_OFDM6);
88762306a36Sopenharmony_ci	} else {
88862306a36Sopenharmony_ci		rtw89_write8_set(rtwdev, chk_rate, B_AX_BAND_MODE);
88962306a36Sopenharmony_ci		rtw89_write8_clr(rtwdev, chk_rate,
89062306a36Sopenharmony_ci				 B_AX_CHECK_CCK_EN | B_AX_RTS_LIMIT_IN_OFDM6);
89162306a36Sopenharmony_ci	}
89262306a36Sopenharmony_ci}
89362306a36Sopenharmony_ci
89462306a36Sopenharmony_cistatic const u32 rtw8852b_sco_barker_threshold[14] = {
89562306a36Sopenharmony_ci	0x1cfea, 0x1d0e1, 0x1d1d7, 0x1d2cd, 0x1d3c3, 0x1d4b9, 0x1d5b0, 0x1d6a6,
89662306a36Sopenharmony_ci	0x1d79c, 0x1d892, 0x1d988, 0x1da7f, 0x1db75, 0x1ddc4
89762306a36Sopenharmony_ci};
89862306a36Sopenharmony_ci
89962306a36Sopenharmony_cistatic const u32 rtw8852b_sco_cck_threshold[14] = {
90062306a36Sopenharmony_ci	0x27de3, 0x27f35, 0x28088, 0x281da, 0x2832d, 0x2847f, 0x285d2, 0x28724,
90162306a36Sopenharmony_ci	0x28877, 0x289c9, 0x28b1c, 0x28c6e, 0x28dc1, 0x290ed
90262306a36Sopenharmony_ci};
90362306a36Sopenharmony_ci
90462306a36Sopenharmony_cistatic void rtw8852b_ctrl_sco_cck(struct rtw89_dev *rtwdev, u8 primary_ch)
90562306a36Sopenharmony_ci{
90662306a36Sopenharmony_ci	u8 ch_element = primary_ch - 1;
90762306a36Sopenharmony_ci
90862306a36Sopenharmony_ci	rtw89_phy_write32_mask(rtwdev, R_RXSCOBC, B_RXSCOBC_TH,
90962306a36Sopenharmony_ci			       rtw8852b_sco_barker_threshold[ch_element]);
91062306a36Sopenharmony_ci	rtw89_phy_write32_mask(rtwdev, R_RXSCOCCK, B_RXSCOCCK_TH,
91162306a36Sopenharmony_ci			       rtw8852b_sco_cck_threshold[ch_element]);
91262306a36Sopenharmony_ci}
91362306a36Sopenharmony_ci
91462306a36Sopenharmony_cistatic u8 rtw8852b_sco_mapping(u8 central_ch)
91562306a36Sopenharmony_ci{
91662306a36Sopenharmony_ci	if (central_ch == 1)
91762306a36Sopenharmony_ci		return 109;
91862306a36Sopenharmony_ci	else if (central_ch >= 2 && central_ch <= 6)
91962306a36Sopenharmony_ci		return 108;
92062306a36Sopenharmony_ci	else if (central_ch >= 7 && central_ch <= 10)
92162306a36Sopenharmony_ci		return 107;
92262306a36Sopenharmony_ci	else if (central_ch >= 11 && central_ch <= 14)
92362306a36Sopenharmony_ci		return 106;
92462306a36Sopenharmony_ci	else if (central_ch == 36 || central_ch == 38)
92562306a36Sopenharmony_ci		return 51;
92662306a36Sopenharmony_ci	else if (central_ch >= 40 && central_ch <= 58)
92762306a36Sopenharmony_ci		return 50;
92862306a36Sopenharmony_ci	else if (central_ch >= 60 && central_ch <= 64)
92962306a36Sopenharmony_ci		return 49;
93062306a36Sopenharmony_ci	else if (central_ch == 100 || central_ch == 102)
93162306a36Sopenharmony_ci		return 48;
93262306a36Sopenharmony_ci	else if (central_ch >= 104 && central_ch <= 126)
93362306a36Sopenharmony_ci		return 47;
93462306a36Sopenharmony_ci	else if (central_ch >= 128 && central_ch <= 151)
93562306a36Sopenharmony_ci		return 46;
93662306a36Sopenharmony_ci	else if (central_ch >= 153 && central_ch <= 177)
93762306a36Sopenharmony_ci		return 45;
93862306a36Sopenharmony_ci	else
93962306a36Sopenharmony_ci		return 0;
94062306a36Sopenharmony_ci}
94162306a36Sopenharmony_ci
94262306a36Sopenharmony_cistruct rtw8852b_bb_gain {
94362306a36Sopenharmony_ci	u32 gain_g[BB_PATH_NUM_8852B];
94462306a36Sopenharmony_ci	u32 gain_a[BB_PATH_NUM_8852B];
94562306a36Sopenharmony_ci	u32 gain_mask;
94662306a36Sopenharmony_ci};
94762306a36Sopenharmony_ci
94862306a36Sopenharmony_cistatic const struct rtw8852b_bb_gain bb_gain_lna[LNA_GAIN_NUM] = {
94962306a36Sopenharmony_ci	{ .gain_g = {0x4678, 0x475C}, .gain_a = {0x45DC, 0x4740},
95062306a36Sopenharmony_ci	  .gain_mask = 0x00ff0000 },
95162306a36Sopenharmony_ci	{ .gain_g = {0x4678, 0x475C}, .gain_a = {0x45DC, 0x4740},
95262306a36Sopenharmony_ci	  .gain_mask = 0xff000000 },
95362306a36Sopenharmony_ci	{ .gain_g = {0x467C, 0x4760}, .gain_a = {0x4660, 0x4744},
95462306a36Sopenharmony_ci	  .gain_mask = 0x000000ff },
95562306a36Sopenharmony_ci	{ .gain_g = {0x467C, 0x4760}, .gain_a = {0x4660, 0x4744},
95662306a36Sopenharmony_ci	  .gain_mask = 0x0000ff00 },
95762306a36Sopenharmony_ci	{ .gain_g = {0x467C, 0x4760}, .gain_a = {0x4660, 0x4744},
95862306a36Sopenharmony_ci	  .gain_mask = 0x00ff0000 },
95962306a36Sopenharmony_ci	{ .gain_g = {0x467C, 0x4760}, .gain_a = {0x4660, 0x4744},
96062306a36Sopenharmony_ci	  .gain_mask = 0xff000000 },
96162306a36Sopenharmony_ci	{ .gain_g = {0x4680, 0x4764}, .gain_a = {0x4664, 0x4748},
96262306a36Sopenharmony_ci	  .gain_mask = 0x000000ff },
96362306a36Sopenharmony_ci};
96462306a36Sopenharmony_ci
96562306a36Sopenharmony_cistatic const struct rtw8852b_bb_gain bb_gain_tia[TIA_GAIN_NUM] = {
96662306a36Sopenharmony_ci	{ .gain_g = {0x4680, 0x4764}, .gain_a = {0x4664, 0x4748},
96762306a36Sopenharmony_ci	  .gain_mask = 0x00ff0000 },
96862306a36Sopenharmony_ci	{ .gain_g = {0x4680, 0x4764}, .gain_a = {0x4664, 0x4748},
96962306a36Sopenharmony_ci	  .gain_mask = 0xff000000 },
97062306a36Sopenharmony_ci};
97162306a36Sopenharmony_ci
97262306a36Sopenharmony_cistatic void rtw8852b_set_gain_error(struct rtw89_dev *rtwdev,
97362306a36Sopenharmony_ci				    enum rtw89_subband subband,
97462306a36Sopenharmony_ci				    enum rtw89_rf_path path)
97562306a36Sopenharmony_ci{
97662306a36Sopenharmony_ci	const struct rtw89_phy_bb_gain_info *gain = &rtwdev->bb_gain;
97762306a36Sopenharmony_ci	u8 gain_band = rtw89_subband_to_bb_gain_band(subband);
97862306a36Sopenharmony_ci	s32 val;
97962306a36Sopenharmony_ci	u32 reg;
98062306a36Sopenharmony_ci	u32 mask;
98162306a36Sopenharmony_ci	int i;
98262306a36Sopenharmony_ci
98362306a36Sopenharmony_ci	for (i = 0; i < LNA_GAIN_NUM; i++) {
98462306a36Sopenharmony_ci		if (subband == RTW89_CH_2G)
98562306a36Sopenharmony_ci			reg = bb_gain_lna[i].gain_g[path];
98662306a36Sopenharmony_ci		else
98762306a36Sopenharmony_ci			reg = bb_gain_lna[i].gain_a[path];
98862306a36Sopenharmony_ci
98962306a36Sopenharmony_ci		mask = bb_gain_lna[i].gain_mask;
99062306a36Sopenharmony_ci		val = gain->lna_gain[gain_band][path][i];
99162306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, reg, mask, val);
99262306a36Sopenharmony_ci	}
99362306a36Sopenharmony_ci
99462306a36Sopenharmony_ci	for (i = 0; i < TIA_GAIN_NUM; i++) {
99562306a36Sopenharmony_ci		if (subband == RTW89_CH_2G)
99662306a36Sopenharmony_ci			reg = bb_gain_tia[i].gain_g[path];
99762306a36Sopenharmony_ci		else
99862306a36Sopenharmony_ci			reg = bb_gain_tia[i].gain_a[path];
99962306a36Sopenharmony_ci
100062306a36Sopenharmony_ci		mask = bb_gain_tia[i].gain_mask;
100162306a36Sopenharmony_ci		val = gain->tia_gain[gain_band][path][i];
100262306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, reg, mask, val);
100362306a36Sopenharmony_ci	}
100462306a36Sopenharmony_ci}
100562306a36Sopenharmony_ci
100662306a36Sopenharmony_cistatic void rtw8852b_set_gain_offset(struct rtw89_dev *rtwdev,
100762306a36Sopenharmony_ci				     enum rtw89_subband subband,
100862306a36Sopenharmony_ci				     enum rtw89_phy_idx phy_idx)
100962306a36Sopenharmony_ci{
101062306a36Sopenharmony_ci	static const u32 gain_err_addr[2] = {R_P0_AGC_RSVD, R_P1_AGC_RSVD};
101162306a36Sopenharmony_ci	static const u32 rssi_ofst_addr[2] = {R_PATH0_G_TIA1_LNA6_OP1DB_V1,
101262306a36Sopenharmony_ci					      R_PATH1_G_TIA1_LNA6_OP1DB_V1};
101362306a36Sopenharmony_ci	struct rtw89_hal *hal = &rtwdev->hal;
101462306a36Sopenharmony_ci	struct rtw89_phy_efuse_gain *efuse_gain = &rtwdev->efuse_gain;
101562306a36Sopenharmony_ci	enum rtw89_gain_offset gain_ofdm_band;
101662306a36Sopenharmony_ci	s32 offset_a, offset_b;
101762306a36Sopenharmony_ci	s32 offset_ofdm, offset_cck;
101862306a36Sopenharmony_ci	s32 tmp;
101962306a36Sopenharmony_ci	u8 path;
102062306a36Sopenharmony_ci
102162306a36Sopenharmony_ci	if (!efuse_gain->comp_valid)
102262306a36Sopenharmony_ci		goto next;
102362306a36Sopenharmony_ci
102462306a36Sopenharmony_ci	for (path = RF_PATH_A; path < BB_PATH_NUM_8852B; path++) {
102562306a36Sopenharmony_ci		tmp = efuse_gain->comp[path][subband];
102662306a36Sopenharmony_ci		tmp = clamp_t(s32, tmp << 2, S8_MIN, S8_MAX);
102762306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, gain_err_addr[path], MASKBYTE0, tmp);
102862306a36Sopenharmony_ci	}
102962306a36Sopenharmony_ci
103062306a36Sopenharmony_cinext:
103162306a36Sopenharmony_ci	if (!efuse_gain->offset_valid)
103262306a36Sopenharmony_ci		return;
103362306a36Sopenharmony_ci
103462306a36Sopenharmony_ci	gain_ofdm_band = rtw89_subband_to_gain_offset_band_of_ofdm(subband);
103562306a36Sopenharmony_ci
103662306a36Sopenharmony_ci	offset_a = -efuse_gain->offset[RF_PATH_A][gain_ofdm_band];
103762306a36Sopenharmony_ci	offset_b = -efuse_gain->offset[RF_PATH_B][gain_ofdm_band];
103862306a36Sopenharmony_ci
103962306a36Sopenharmony_ci	tmp = -((offset_a << 2) + (efuse_gain->offset_base[RTW89_PHY_0] >> 2));
104062306a36Sopenharmony_ci	tmp = clamp_t(s32, tmp, S8_MIN, S8_MAX);
104162306a36Sopenharmony_ci	rtw89_phy_write32_mask(rtwdev, rssi_ofst_addr[RF_PATH_A], B_PATH0_R_G_OFST_MASK, tmp);
104262306a36Sopenharmony_ci
104362306a36Sopenharmony_ci	tmp = -((offset_b << 2) + (efuse_gain->offset_base[RTW89_PHY_0] >> 2));
104462306a36Sopenharmony_ci	tmp = clamp_t(s32, tmp, S8_MIN, S8_MAX);
104562306a36Sopenharmony_ci	rtw89_phy_write32_mask(rtwdev, rssi_ofst_addr[RF_PATH_B], B_PATH0_R_G_OFST_MASK, tmp);
104662306a36Sopenharmony_ci
104762306a36Sopenharmony_ci	if (hal->antenna_rx == RF_B) {
104862306a36Sopenharmony_ci		offset_ofdm = -efuse_gain->offset[RF_PATH_B][gain_ofdm_band];
104962306a36Sopenharmony_ci		offset_cck = -efuse_gain->offset[RF_PATH_B][0];
105062306a36Sopenharmony_ci	} else {
105162306a36Sopenharmony_ci		offset_ofdm = -efuse_gain->offset[RF_PATH_A][gain_ofdm_band];
105262306a36Sopenharmony_ci		offset_cck = -efuse_gain->offset[RF_PATH_A][0];
105362306a36Sopenharmony_ci	}
105462306a36Sopenharmony_ci
105562306a36Sopenharmony_ci	tmp = (offset_ofdm << 4) + efuse_gain->offset_base[RTW89_PHY_0];
105662306a36Sopenharmony_ci	tmp = clamp_t(s32, tmp, S8_MIN, S8_MAX);
105762306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_P0_RPL1, B_P0_RPL1_BIAS_MASK, tmp, phy_idx);
105862306a36Sopenharmony_ci
105962306a36Sopenharmony_ci	tmp = (offset_ofdm << 4) + efuse_gain->rssi_base[RTW89_PHY_0];
106062306a36Sopenharmony_ci	tmp = clamp_t(s32, tmp, S8_MIN, S8_MAX);
106162306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_P1_RPL1, B_P0_RPL1_BIAS_MASK, tmp, phy_idx);
106262306a36Sopenharmony_ci
106362306a36Sopenharmony_ci	if (subband == RTW89_CH_2G) {
106462306a36Sopenharmony_ci		tmp = (offset_cck << 3) + (efuse_gain->offset_base[RTW89_PHY_0] >> 1);
106562306a36Sopenharmony_ci		tmp = clamp_t(s32, tmp, S8_MIN >> 1, S8_MAX >> 1);
106662306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RX_RPL_OFST,
106762306a36Sopenharmony_ci				       B_RX_RPL_OFST_CCK_MASK, tmp);
106862306a36Sopenharmony_ci	}
106962306a36Sopenharmony_ci}
107062306a36Sopenharmony_ci
107162306a36Sopenharmony_cistatic
107262306a36Sopenharmony_civoid rtw8852b_set_rxsc_rpl_comp(struct rtw89_dev *rtwdev, enum rtw89_subband subband)
107362306a36Sopenharmony_ci{
107462306a36Sopenharmony_ci	const struct rtw89_phy_bb_gain_info *gain = &rtwdev->bb_gain;
107562306a36Sopenharmony_ci	u8 band = rtw89_subband_to_bb_gain_band(subband);
107662306a36Sopenharmony_ci	u32 val;
107762306a36Sopenharmony_ci
107862306a36Sopenharmony_ci	val = FIELD_PREP(B_P0_RPL1_20_MASK, (gain->rpl_ofst_20[band][RF_PATH_A] +
107962306a36Sopenharmony_ci					     gain->rpl_ofst_20[band][RF_PATH_B]) / 2) |
108062306a36Sopenharmony_ci	      FIELD_PREP(B_P0_RPL1_40_MASK, (gain->rpl_ofst_40[band][RF_PATH_A][0] +
108162306a36Sopenharmony_ci					     gain->rpl_ofst_40[band][RF_PATH_B][0]) / 2) |
108262306a36Sopenharmony_ci	      FIELD_PREP(B_P0_RPL1_41_MASK, (gain->rpl_ofst_40[band][RF_PATH_A][1] +
108362306a36Sopenharmony_ci					     gain->rpl_ofst_40[band][RF_PATH_B][1]) / 2);
108462306a36Sopenharmony_ci	val >>= B_P0_RPL1_SHIFT;
108562306a36Sopenharmony_ci	rtw89_phy_write32_mask(rtwdev, R_P0_RPL1, B_P0_RPL1_MASK, val);
108662306a36Sopenharmony_ci	rtw89_phy_write32_mask(rtwdev, R_P1_RPL1, B_P0_RPL1_MASK, val);
108762306a36Sopenharmony_ci
108862306a36Sopenharmony_ci	val = FIELD_PREP(B_P0_RTL2_42_MASK, (gain->rpl_ofst_40[band][RF_PATH_A][2] +
108962306a36Sopenharmony_ci					     gain->rpl_ofst_40[band][RF_PATH_B][2]) / 2) |
109062306a36Sopenharmony_ci	      FIELD_PREP(B_P0_RTL2_80_MASK, (gain->rpl_ofst_80[band][RF_PATH_A][0] +
109162306a36Sopenharmony_ci					     gain->rpl_ofst_80[band][RF_PATH_B][0]) / 2) |
109262306a36Sopenharmony_ci	      FIELD_PREP(B_P0_RTL2_81_MASK, (gain->rpl_ofst_80[band][RF_PATH_A][1] +
109362306a36Sopenharmony_ci					     gain->rpl_ofst_80[band][RF_PATH_B][1]) / 2) |
109462306a36Sopenharmony_ci	      FIELD_PREP(B_P0_RTL2_8A_MASK, (gain->rpl_ofst_80[band][RF_PATH_A][10] +
109562306a36Sopenharmony_ci					     gain->rpl_ofst_80[band][RF_PATH_B][10]) / 2);
109662306a36Sopenharmony_ci	rtw89_phy_write32(rtwdev, R_P0_RPL2, val);
109762306a36Sopenharmony_ci	rtw89_phy_write32(rtwdev, R_P1_RPL2, val);
109862306a36Sopenharmony_ci
109962306a36Sopenharmony_ci	val = FIELD_PREP(B_P0_RTL3_82_MASK, (gain->rpl_ofst_80[band][RF_PATH_A][2] +
110062306a36Sopenharmony_ci					     gain->rpl_ofst_80[band][RF_PATH_B][2]) / 2) |
110162306a36Sopenharmony_ci	      FIELD_PREP(B_P0_RTL3_83_MASK, (gain->rpl_ofst_80[band][RF_PATH_A][3] +
110262306a36Sopenharmony_ci					     gain->rpl_ofst_80[band][RF_PATH_B][3]) / 2) |
110362306a36Sopenharmony_ci	      FIELD_PREP(B_P0_RTL3_84_MASK, (gain->rpl_ofst_80[band][RF_PATH_A][4] +
110462306a36Sopenharmony_ci					     gain->rpl_ofst_80[band][RF_PATH_B][4]) / 2) |
110562306a36Sopenharmony_ci	      FIELD_PREP(B_P0_RTL3_89_MASK, (gain->rpl_ofst_80[band][RF_PATH_A][9] +
110662306a36Sopenharmony_ci					     gain->rpl_ofst_80[band][RF_PATH_B][9]) / 2);
110762306a36Sopenharmony_ci	rtw89_phy_write32(rtwdev, R_P0_RPL3, val);
110862306a36Sopenharmony_ci	rtw89_phy_write32(rtwdev, R_P1_RPL3, val);
110962306a36Sopenharmony_ci}
111062306a36Sopenharmony_ci
111162306a36Sopenharmony_cistatic void rtw8852b_ctrl_ch(struct rtw89_dev *rtwdev,
111262306a36Sopenharmony_ci			     const struct rtw89_chan *chan,
111362306a36Sopenharmony_ci			     enum rtw89_phy_idx phy_idx)
111462306a36Sopenharmony_ci{
111562306a36Sopenharmony_ci	u8 central_ch = chan->channel;
111662306a36Sopenharmony_ci	u8 subband = chan->subband_type;
111762306a36Sopenharmony_ci	u8 sco_comp;
111862306a36Sopenharmony_ci	bool is_2g = central_ch <= 14;
111962306a36Sopenharmony_ci
112062306a36Sopenharmony_ci	/* Path A */
112162306a36Sopenharmony_ci	if (is_2g)
112262306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_PATH0_BAND_SEL_V1,
112362306a36Sopenharmony_ci				      B_PATH0_BAND_SEL_MSK_V1, 1, phy_idx);
112462306a36Sopenharmony_ci	else
112562306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_PATH0_BAND_SEL_V1,
112662306a36Sopenharmony_ci				      B_PATH0_BAND_SEL_MSK_V1, 0, phy_idx);
112762306a36Sopenharmony_ci
112862306a36Sopenharmony_ci	/* Path B */
112962306a36Sopenharmony_ci	if (is_2g)
113062306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_PATH1_BAND_SEL_V1,
113162306a36Sopenharmony_ci				      B_PATH1_BAND_SEL_MSK_V1, 1, phy_idx);
113262306a36Sopenharmony_ci	else
113362306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_PATH1_BAND_SEL_V1,
113462306a36Sopenharmony_ci				      B_PATH1_BAND_SEL_MSK_V1, 0, phy_idx);
113562306a36Sopenharmony_ci
113662306a36Sopenharmony_ci	/* SCO compensate FC setting */
113762306a36Sopenharmony_ci	sco_comp = rtw8852b_sco_mapping(central_ch);
113862306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_FC0_BW_V1, B_FC0_BW_INV, sco_comp, phy_idx);
113962306a36Sopenharmony_ci
114062306a36Sopenharmony_ci	if (chan->band_type == RTW89_BAND_6G)
114162306a36Sopenharmony_ci		return;
114262306a36Sopenharmony_ci
114362306a36Sopenharmony_ci	/* CCK parameters */
114462306a36Sopenharmony_ci	if (central_ch == 14) {
114562306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXFIR0, B_TXFIR_C01, 0x3b13ff);
114662306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXFIR2, B_TXFIR_C23, 0x1c42de);
114762306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXFIR4, B_TXFIR_C45, 0xfdb0ad);
114862306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXFIR6, B_TXFIR_C67, 0xf60f6e);
114962306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXFIR8, B_TXFIR_C89, 0xfd8f92);
115062306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXFIRA, B_TXFIR_CAB, 0x2d011);
115162306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXFIRC, B_TXFIR_CCD, 0x1c02c);
115262306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXFIRE, B_TXFIR_CEF, 0xfff00a);
115362306a36Sopenharmony_ci	} else {
115462306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXFIR0, B_TXFIR_C01, 0x3d23ff);
115562306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXFIR2, B_TXFIR_C23, 0x29b354);
115662306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXFIR4, B_TXFIR_C45, 0xfc1c8);
115762306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXFIR6, B_TXFIR_C67, 0xfdb053);
115862306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXFIR8, B_TXFIR_C89, 0xf86f9a);
115962306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXFIRA, B_TXFIR_CAB, 0xfaef92);
116062306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXFIRC, B_TXFIR_CCD, 0xfe5fcc);
116162306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXFIRE, B_TXFIR_CEF, 0xffdff5);
116262306a36Sopenharmony_ci	}
116362306a36Sopenharmony_ci
116462306a36Sopenharmony_ci	rtw8852b_set_gain_error(rtwdev, subband, RF_PATH_A);
116562306a36Sopenharmony_ci	rtw8852b_set_gain_error(rtwdev, subband, RF_PATH_B);
116662306a36Sopenharmony_ci	rtw8852b_set_gain_offset(rtwdev, subband, phy_idx);
116762306a36Sopenharmony_ci	rtw8852b_set_rxsc_rpl_comp(rtwdev, subband);
116862306a36Sopenharmony_ci}
116962306a36Sopenharmony_ci
117062306a36Sopenharmony_cistatic void rtw8852b_bw_setting(struct rtw89_dev *rtwdev, u8 bw, u8 path)
117162306a36Sopenharmony_ci{
117262306a36Sopenharmony_ci	static const u32 adc_sel[2] = {0xC0EC, 0xC1EC};
117362306a36Sopenharmony_ci	static const u32 wbadc_sel[2] = {0xC0E4, 0xC1E4};
117462306a36Sopenharmony_ci
117562306a36Sopenharmony_ci	switch (bw) {
117662306a36Sopenharmony_ci	case RTW89_CHANNEL_WIDTH_5:
117762306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, adc_sel[path], 0x6000, 0x1);
117862306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, wbadc_sel[path], 0x30, 0x0);
117962306a36Sopenharmony_ci		break;
118062306a36Sopenharmony_ci	case RTW89_CHANNEL_WIDTH_10:
118162306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, adc_sel[path], 0x6000, 0x2);
118262306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, wbadc_sel[path], 0x30, 0x1);
118362306a36Sopenharmony_ci		break;
118462306a36Sopenharmony_ci	case RTW89_CHANNEL_WIDTH_20:
118562306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, adc_sel[path], 0x6000, 0x0);
118662306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, wbadc_sel[path], 0x30, 0x2);
118762306a36Sopenharmony_ci		break;
118862306a36Sopenharmony_ci	case RTW89_CHANNEL_WIDTH_40:
118962306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, adc_sel[path], 0x6000, 0x0);
119062306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, wbadc_sel[path], 0x30, 0x2);
119162306a36Sopenharmony_ci		break;
119262306a36Sopenharmony_ci	case RTW89_CHANNEL_WIDTH_80:
119362306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, adc_sel[path], 0x6000, 0x0);
119462306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, wbadc_sel[path], 0x30, 0x2);
119562306a36Sopenharmony_ci		break;
119662306a36Sopenharmony_ci	default:
119762306a36Sopenharmony_ci		rtw89_warn(rtwdev, "Fail to set ADC\n");
119862306a36Sopenharmony_ci	}
119962306a36Sopenharmony_ci}
120062306a36Sopenharmony_ci
120162306a36Sopenharmony_cistatic void rtw8852b_ctrl_bw(struct rtw89_dev *rtwdev, u8 pri_ch, u8 bw,
120262306a36Sopenharmony_ci			     enum rtw89_phy_idx phy_idx)
120362306a36Sopenharmony_ci{
120462306a36Sopenharmony_ci	u32 rx_path_0;
120562306a36Sopenharmony_ci
120662306a36Sopenharmony_ci	switch (bw) {
120762306a36Sopenharmony_ci	case RTW89_CHANNEL_WIDTH_5:
120862306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_FC0_BW_V1, B_FC0_BW_SET, 0x0, phy_idx);
120962306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD_V1, B_CHBW_MOD_SBW, 0x1, phy_idx);
121062306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD_V1, B_CHBW_MOD_PRICH, 0x0, phy_idx);
121162306a36Sopenharmony_ci
121262306a36Sopenharmony_ci		/*Set RF mode at 3 */
121362306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_P0_RFMODE_ORI_RX,
121462306a36Sopenharmony_ci				      B_P0_RFMODE_ORI_RX_ALL, 0x333, phy_idx);
121562306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_P1_RFMODE_ORI_RX,
121662306a36Sopenharmony_ci				      B_P1_RFMODE_ORI_RX_ALL, 0x333, phy_idx);
121762306a36Sopenharmony_ci		break;
121862306a36Sopenharmony_ci	case RTW89_CHANNEL_WIDTH_10:
121962306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_FC0_BW_V1, B_FC0_BW_SET, 0x0, phy_idx);
122062306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD_V1, B_CHBW_MOD_SBW, 0x2, phy_idx);
122162306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD_V1, B_CHBW_MOD_PRICH, 0x0, phy_idx);
122262306a36Sopenharmony_ci
122362306a36Sopenharmony_ci		/*Set RF mode at 3 */
122462306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_P0_RFMODE_ORI_RX,
122562306a36Sopenharmony_ci				      B_P0_RFMODE_ORI_RX_ALL, 0x333, phy_idx);
122662306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_P1_RFMODE_ORI_RX,
122762306a36Sopenharmony_ci				      B_P1_RFMODE_ORI_RX_ALL, 0x333, phy_idx);
122862306a36Sopenharmony_ci		break;
122962306a36Sopenharmony_ci	case RTW89_CHANNEL_WIDTH_20:
123062306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_FC0_BW_V1, B_FC0_BW_SET, 0x0, phy_idx);
123162306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD_V1, B_CHBW_MOD_SBW, 0x0, phy_idx);
123262306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD_V1, B_CHBW_MOD_PRICH, 0x0, phy_idx);
123362306a36Sopenharmony_ci
123462306a36Sopenharmony_ci		/*Set RF mode at 3 */
123562306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_P0_RFMODE_ORI_RX,
123662306a36Sopenharmony_ci				      B_P0_RFMODE_ORI_RX_ALL, 0x333, phy_idx);
123762306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_P1_RFMODE_ORI_RX,
123862306a36Sopenharmony_ci				      B_P1_RFMODE_ORI_RX_ALL, 0x333, phy_idx);
123962306a36Sopenharmony_ci		break;
124062306a36Sopenharmony_ci	case RTW89_CHANNEL_WIDTH_40:
124162306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_FC0_BW_V1, B_FC0_BW_SET, 0x1, phy_idx);
124262306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD_V1, B_CHBW_MOD_SBW, 0x0, phy_idx);
124362306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD_V1, B_CHBW_MOD_PRICH,
124462306a36Sopenharmony_ci				      pri_ch, phy_idx);
124562306a36Sopenharmony_ci
124662306a36Sopenharmony_ci		/*Set RF mode at 3 */
124762306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_P0_RFMODE_ORI_RX,
124862306a36Sopenharmony_ci				      B_P0_RFMODE_ORI_RX_ALL, 0x333, phy_idx);
124962306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_P1_RFMODE_ORI_RX,
125062306a36Sopenharmony_ci				      B_P1_RFMODE_ORI_RX_ALL, 0x333, phy_idx);
125162306a36Sopenharmony_ci		/*CCK primary channel */
125262306a36Sopenharmony_ci		if (pri_ch == RTW89_SC_20_UPPER)
125362306a36Sopenharmony_ci			rtw89_phy_write32_mask(rtwdev, R_RXSC, B_RXSC_EN, 1);
125462306a36Sopenharmony_ci		else
125562306a36Sopenharmony_ci			rtw89_phy_write32_mask(rtwdev, R_RXSC, B_RXSC_EN, 0);
125662306a36Sopenharmony_ci
125762306a36Sopenharmony_ci		break;
125862306a36Sopenharmony_ci	case RTW89_CHANNEL_WIDTH_80:
125962306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_FC0_BW_V1, B_FC0_BW_SET, 0x2, phy_idx);
126062306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD_V1, B_CHBW_MOD_SBW, 0x0, phy_idx);
126162306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD_V1, B_CHBW_MOD_PRICH,
126262306a36Sopenharmony_ci				      pri_ch, phy_idx);
126362306a36Sopenharmony_ci
126462306a36Sopenharmony_ci		/*Set RF mode at A */
126562306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_P0_RFMODE_ORI_RX,
126662306a36Sopenharmony_ci				      B_P0_RFMODE_ORI_RX_ALL, 0xaaa, phy_idx);
126762306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_P1_RFMODE_ORI_RX,
126862306a36Sopenharmony_ci				      B_P1_RFMODE_ORI_RX_ALL, 0xaaa, phy_idx);
126962306a36Sopenharmony_ci		break;
127062306a36Sopenharmony_ci	default:
127162306a36Sopenharmony_ci		rtw89_warn(rtwdev, "Fail to switch bw (bw:%d, pri ch:%d)\n", bw,
127262306a36Sopenharmony_ci			   pri_ch);
127362306a36Sopenharmony_ci	}
127462306a36Sopenharmony_ci
127562306a36Sopenharmony_ci	rtw8852b_bw_setting(rtwdev, bw, RF_PATH_A);
127662306a36Sopenharmony_ci	rtw8852b_bw_setting(rtwdev, bw, RF_PATH_B);
127762306a36Sopenharmony_ci
127862306a36Sopenharmony_ci	rx_path_0 = rtw89_phy_read32_idx(rtwdev, R_CHBW_MOD_V1, B_ANT_RX_SEG0,
127962306a36Sopenharmony_ci					 phy_idx);
128062306a36Sopenharmony_ci	if (rx_path_0 == 0x1)
128162306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_P1_RFMODE_ORI_RX,
128262306a36Sopenharmony_ci				      B_P1_RFMODE_ORI_RX_ALL, 0x111, phy_idx);
128362306a36Sopenharmony_ci	else if (rx_path_0 == 0x2)
128462306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_P0_RFMODE_ORI_RX,
128562306a36Sopenharmony_ci				      B_P0_RFMODE_ORI_RX_ALL, 0x111, phy_idx);
128662306a36Sopenharmony_ci}
128762306a36Sopenharmony_ci
128862306a36Sopenharmony_cistatic void rtw8852b_ctrl_cck_en(struct rtw89_dev *rtwdev, bool cck_en)
128962306a36Sopenharmony_ci{
129062306a36Sopenharmony_ci	if (cck_en) {
129162306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_UPD_CLK_ADC, B_ENABLE_CCK, 1);
129262306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXCCA, B_RXCCA_DIS, 0);
129362306a36Sopenharmony_ci	} else {
129462306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_UPD_CLK_ADC, B_ENABLE_CCK, 0);
129562306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXCCA, B_RXCCA_DIS, 1);
129662306a36Sopenharmony_ci	}
129762306a36Sopenharmony_ci}
129862306a36Sopenharmony_ci
129962306a36Sopenharmony_cistatic void rtw8852b_5m_mask(struct rtw89_dev *rtwdev, const struct rtw89_chan *chan,
130062306a36Sopenharmony_ci			     enum rtw89_phy_idx phy_idx)
130162306a36Sopenharmony_ci{
130262306a36Sopenharmony_ci	u8 pri_ch = chan->pri_ch_idx;
130362306a36Sopenharmony_ci	bool mask_5m_low;
130462306a36Sopenharmony_ci	bool mask_5m_en;
130562306a36Sopenharmony_ci
130662306a36Sopenharmony_ci	switch (chan->band_width) {
130762306a36Sopenharmony_ci	case RTW89_CHANNEL_WIDTH_40:
130862306a36Sopenharmony_ci		/* Prich=1: Mask 5M High, Prich=2: Mask 5M Low */
130962306a36Sopenharmony_ci		mask_5m_en = true;
131062306a36Sopenharmony_ci		mask_5m_low = pri_ch == RTW89_SC_20_LOWER;
131162306a36Sopenharmony_ci		break;
131262306a36Sopenharmony_ci	case RTW89_CHANNEL_WIDTH_80:
131362306a36Sopenharmony_ci		/* Prich=3: Mask 5M High, Prich=4: Mask 5M Low, Else: Disable */
131462306a36Sopenharmony_ci		mask_5m_en = pri_ch == RTW89_SC_20_UPMOST ||
131562306a36Sopenharmony_ci			     pri_ch == RTW89_SC_20_LOWEST;
131662306a36Sopenharmony_ci		mask_5m_low = pri_ch == RTW89_SC_20_LOWEST;
131762306a36Sopenharmony_ci		break;
131862306a36Sopenharmony_ci	default:
131962306a36Sopenharmony_ci		mask_5m_en = false;
132062306a36Sopenharmony_ci		break;
132162306a36Sopenharmony_ci	}
132262306a36Sopenharmony_ci
132362306a36Sopenharmony_ci	if (!mask_5m_en) {
132462306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET_V1, B_PATH0_5MDET_EN, 0x0);
132562306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET_V1, B_PATH1_5MDET_EN, 0x0);
132662306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_ASSIGN_SBD_OPT_V1,
132762306a36Sopenharmony_ci				      B_ASSIGN_SBD_OPT_EN_V1, 0x0, phy_idx);
132862306a36Sopenharmony_ci		return;
132962306a36Sopenharmony_ci	}
133062306a36Sopenharmony_ci
133162306a36Sopenharmony_ci	if (mask_5m_low) {
133262306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET_V1, B_PATH0_5MDET_TH, 0x4);
133362306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET_V1, B_PATH0_5MDET_EN, 0x1);
133462306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET_V1, B_PATH0_5MDET_SB2, 0x0);
133562306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET_V1, B_PATH0_5MDET_SB0, 0x1);
133662306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET_V1, B_PATH1_5MDET_TH, 0x4);
133762306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET_V1, B_PATH1_5MDET_EN, 0x1);
133862306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET_V1, B_PATH1_5MDET_SB2, 0x0);
133962306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET_V1, B_PATH1_5MDET_SB0, 0x1);
134062306a36Sopenharmony_ci	} else {
134162306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET_V1, B_PATH0_5MDET_TH, 0x4);
134262306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET_V1, B_PATH0_5MDET_EN, 0x1);
134362306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET_V1, B_PATH0_5MDET_SB2, 0x1);
134462306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH0_5MDET_V1, B_PATH0_5MDET_SB0, 0x0);
134562306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET_V1, B_PATH1_5MDET_TH, 0x4);
134662306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET_V1, B_PATH1_5MDET_EN, 0x1);
134762306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET_V1, B_PATH1_5MDET_SB2, 0x1);
134862306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH1_5MDET_V1, B_PATH1_5MDET_SB0, 0x0);
134962306a36Sopenharmony_ci	}
135062306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_ASSIGN_SBD_OPT_V1,
135162306a36Sopenharmony_ci			      B_ASSIGN_SBD_OPT_EN_V1, 0x1, phy_idx);
135262306a36Sopenharmony_ci}
135362306a36Sopenharmony_ci
135462306a36Sopenharmony_cistatic void rtw8852b_bb_reset_all(struct rtw89_dev *rtwdev, enum rtw89_phy_idx phy_idx)
135562306a36Sopenharmony_ci{
135662306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_S0_HW_SI_DIS, B_S0_HW_SI_DIS_W_R_TRIG, 0x7, phy_idx);
135762306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_S1_HW_SI_DIS, B_S1_HW_SI_DIS_W_R_TRIG, 0x7, phy_idx);
135862306a36Sopenharmony_ci	fsleep(1);
135962306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_RSTB_ASYNC, B_RSTB_ASYNC_ALL, 1, phy_idx);
136062306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_RSTB_ASYNC, B_RSTB_ASYNC_ALL, 0, phy_idx);
136162306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_S0_HW_SI_DIS, B_S0_HW_SI_DIS_W_R_TRIG, 0x0, phy_idx);
136262306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_S1_HW_SI_DIS, B_S1_HW_SI_DIS_W_R_TRIG, 0x0, phy_idx);
136362306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_RSTB_ASYNC, B_RSTB_ASYNC_ALL, 1, phy_idx);
136462306a36Sopenharmony_ci}
136562306a36Sopenharmony_ci
136662306a36Sopenharmony_cistatic void rtw8852b_bb_reset_en(struct rtw89_dev *rtwdev, enum rtw89_band band,
136762306a36Sopenharmony_ci				 enum rtw89_phy_idx phy_idx, bool en)
136862306a36Sopenharmony_ci{
136962306a36Sopenharmony_ci	if (en) {
137062306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_S0_HW_SI_DIS,
137162306a36Sopenharmony_ci				      B_S0_HW_SI_DIS_W_R_TRIG, 0x0, phy_idx);
137262306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_S1_HW_SI_DIS,
137362306a36Sopenharmony_ci				      B_S1_HW_SI_DIS_W_R_TRIG, 0x0, phy_idx);
137462306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_RSTB_ASYNC, B_RSTB_ASYNC_ALL, 1, phy_idx);
137562306a36Sopenharmony_ci		if (band == RTW89_BAND_2G)
137662306a36Sopenharmony_ci			rtw89_phy_write32_mask(rtwdev, R_RXCCA, B_RXCCA_DIS, 0x0);
137762306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PD_CTRL, B_PD_HIT_DIS, 0x0);
137862306a36Sopenharmony_ci	} else {
137962306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXCCA, B_RXCCA_DIS, 0x1);
138062306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PD_CTRL, B_PD_HIT_DIS, 0x1);
138162306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_S0_HW_SI_DIS,
138262306a36Sopenharmony_ci				      B_S0_HW_SI_DIS_W_R_TRIG, 0x7, phy_idx);
138362306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_S1_HW_SI_DIS,
138462306a36Sopenharmony_ci				      B_S1_HW_SI_DIS_W_R_TRIG, 0x7, phy_idx);
138562306a36Sopenharmony_ci		fsleep(1);
138662306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_RSTB_ASYNC, B_RSTB_ASYNC_ALL, 0, phy_idx);
138762306a36Sopenharmony_ci	}
138862306a36Sopenharmony_ci}
138962306a36Sopenharmony_ci
139062306a36Sopenharmony_cistatic void rtw8852b_bb_reset(struct rtw89_dev *rtwdev,
139162306a36Sopenharmony_ci			      enum rtw89_phy_idx phy_idx)
139262306a36Sopenharmony_ci{
139362306a36Sopenharmony_ci	rtw89_phy_write32_set(rtwdev, R_P0_TXPW_RSTB, B_P0_TXPW_RSTB_MANON);
139462306a36Sopenharmony_ci	rtw89_phy_write32_set(rtwdev, R_P0_TSSI_TRK, B_P0_TSSI_TRK_EN);
139562306a36Sopenharmony_ci	rtw89_phy_write32_set(rtwdev, R_P1_TXPW_RSTB, B_P1_TXPW_RSTB_MANON);
139662306a36Sopenharmony_ci	rtw89_phy_write32_set(rtwdev, R_P1_TSSI_TRK, B_P1_TSSI_TRK_EN);
139762306a36Sopenharmony_ci	rtw8852b_bb_reset_all(rtwdev, phy_idx);
139862306a36Sopenharmony_ci	rtw89_phy_write32_clr(rtwdev, R_P0_TXPW_RSTB, B_P0_TXPW_RSTB_MANON);
139962306a36Sopenharmony_ci	rtw89_phy_write32_clr(rtwdev, R_P0_TSSI_TRK, B_P0_TSSI_TRK_EN);
140062306a36Sopenharmony_ci	rtw89_phy_write32_clr(rtwdev, R_P1_TXPW_RSTB, B_P1_TXPW_RSTB_MANON);
140162306a36Sopenharmony_ci	rtw89_phy_write32_clr(rtwdev, R_P1_TSSI_TRK, B_P1_TSSI_TRK_EN);
140262306a36Sopenharmony_ci}
140362306a36Sopenharmony_ci
140462306a36Sopenharmony_cistatic void rtw8852b_bb_macid_ctrl_init(struct rtw89_dev *rtwdev,
140562306a36Sopenharmony_ci					enum rtw89_phy_idx phy_idx)
140662306a36Sopenharmony_ci{
140762306a36Sopenharmony_ci	u32 addr;
140862306a36Sopenharmony_ci
140962306a36Sopenharmony_ci	for (addr = R_AX_PWR_MACID_LMT_TABLE0;
141062306a36Sopenharmony_ci	     addr <= R_AX_PWR_MACID_LMT_TABLE127; addr += 4)
141162306a36Sopenharmony_ci		rtw89_mac_txpwr_write32(rtwdev, phy_idx, addr, 0);
141262306a36Sopenharmony_ci}
141362306a36Sopenharmony_ci
141462306a36Sopenharmony_cistatic void rtw8852b_bb_sethw(struct rtw89_dev *rtwdev)
141562306a36Sopenharmony_ci{
141662306a36Sopenharmony_ci	struct rtw89_phy_efuse_gain *gain = &rtwdev->efuse_gain;
141762306a36Sopenharmony_ci
141862306a36Sopenharmony_ci	rtw89_phy_write32_clr(rtwdev, R_P0_EN_SOUND_WO_NDP, B_P0_EN_SOUND_WO_NDP);
141962306a36Sopenharmony_ci	rtw89_phy_write32_clr(rtwdev, R_P1_EN_SOUND_WO_NDP, B_P1_EN_SOUND_WO_NDP);
142062306a36Sopenharmony_ci
142162306a36Sopenharmony_ci	rtw8852b_bb_macid_ctrl_init(rtwdev, RTW89_PHY_0);
142262306a36Sopenharmony_ci
142362306a36Sopenharmony_ci	/* read these registers after loading BB parameters */
142462306a36Sopenharmony_ci	gain->offset_base[RTW89_PHY_0] =
142562306a36Sopenharmony_ci		rtw89_phy_read32_mask(rtwdev, R_P0_RPL1, B_P0_RPL1_BIAS_MASK);
142662306a36Sopenharmony_ci	gain->rssi_base[RTW89_PHY_0] =
142762306a36Sopenharmony_ci		rtw89_phy_read32_mask(rtwdev, R_P1_RPL1, B_P0_RPL1_BIAS_MASK);
142862306a36Sopenharmony_ci}
142962306a36Sopenharmony_ci
143062306a36Sopenharmony_cistatic void rtw8852b_bb_set_pop(struct rtw89_dev *rtwdev)
143162306a36Sopenharmony_ci{
143262306a36Sopenharmony_ci	if (rtwdev->hw->conf.flags & IEEE80211_CONF_MONITOR)
143362306a36Sopenharmony_ci		rtw89_phy_write32_clr(rtwdev, R_PKT_CTRL, B_PKT_POP_EN);
143462306a36Sopenharmony_ci}
143562306a36Sopenharmony_ci
143662306a36Sopenharmony_cistatic void rtw8852b_set_channel_bb(struct rtw89_dev *rtwdev, const struct rtw89_chan *chan,
143762306a36Sopenharmony_ci				    enum rtw89_phy_idx phy_idx)
143862306a36Sopenharmony_ci{
143962306a36Sopenharmony_ci	bool cck_en = chan->channel <= 14;
144062306a36Sopenharmony_ci	u8 pri_ch_idx = chan->pri_ch_idx;
144162306a36Sopenharmony_ci	u8 band = chan->band_type, chan_idx;
144262306a36Sopenharmony_ci
144362306a36Sopenharmony_ci	if (cck_en)
144462306a36Sopenharmony_ci		rtw8852b_ctrl_sco_cck(rtwdev,  chan->primary_channel);
144562306a36Sopenharmony_ci
144662306a36Sopenharmony_ci	rtw8852b_ctrl_ch(rtwdev, chan, phy_idx);
144762306a36Sopenharmony_ci	rtw8852b_ctrl_bw(rtwdev, pri_ch_idx, chan->band_width, phy_idx);
144862306a36Sopenharmony_ci	rtw8852b_ctrl_cck_en(rtwdev, cck_en);
144962306a36Sopenharmony_ci	if (chan->band_type == RTW89_BAND_5G) {
145062306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH0_BT_SHARE_V1,
145162306a36Sopenharmony_ci				       B_PATH0_BT_SHARE_V1, 0x0);
145262306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH0_BTG_PATH_V1,
145362306a36Sopenharmony_ci				       B_PATH0_BTG_PATH_V1, 0x0);
145462306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH1_BT_SHARE_V1,
145562306a36Sopenharmony_ci				       B_PATH1_BT_SHARE_V1, 0x0);
145662306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH1_BTG_PATH_V1,
145762306a36Sopenharmony_ci				       B_PATH1_BTG_PATH_V1, 0x0);
145862306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_CHBW_MOD_V1, B_BT_SHARE, 0x0);
145962306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_FC0_BW_V1, B_ANT_RX_BT_SEG0, 0x0);
146062306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_BT_DYN_DC_EST_EN_V1,
146162306a36Sopenharmony_ci				       B_BT_DYN_DC_EST_EN_MSK, 0x0);
146262306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_GNT_BT_WGT_EN, B_GNT_BT_WGT_EN, 0x0);
146362306a36Sopenharmony_ci	}
146462306a36Sopenharmony_ci	chan_idx = rtw89_encode_chan_idx(rtwdev, chan->primary_channel, band);
146562306a36Sopenharmony_ci	rtw89_phy_write32_mask(rtwdev, R_MAC_PIN_SEL, B_CH_IDX_SEG0, chan_idx);
146662306a36Sopenharmony_ci	rtw8852b_5m_mask(rtwdev, chan, phy_idx);
146762306a36Sopenharmony_ci	rtw8852b_bb_set_pop(rtwdev);
146862306a36Sopenharmony_ci	rtw8852b_bb_reset_all(rtwdev, phy_idx);
146962306a36Sopenharmony_ci}
147062306a36Sopenharmony_ci
147162306a36Sopenharmony_cistatic void rtw8852b_set_channel(struct rtw89_dev *rtwdev,
147262306a36Sopenharmony_ci				 const struct rtw89_chan *chan,
147362306a36Sopenharmony_ci				 enum rtw89_mac_idx mac_idx,
147462306a36Sopenharmony_ci				 enum rtw89_phy_idx phy_idx)
147562306a36Sopenharmony_ci{
147662306a36Sopenharmony_ci	rtw8852b_set_channel_mac(rtwdev, chan, mac_idx);
147762306a36Sopenharmony_ci	rtw8852b_set_channel_bb(rtwdev, chan, phy_idx);
147862306a36Sopenharmony_ci	rtw8852b_set_channel_rf(rtwdev, chan, phy_idx);
147962306a36Sopenharmony_ci}
148062306a36Sopenharmony_ci
148162306a36Sopenharmony_cistatic void rtw8852b_tssi_cont_en(struct rtw89_dev *rtwdev, bool en,
148262306a36Sopenharmony_ci				  enum rtw89_rf_path path)
148362306a36Sopenharmony_ci{
148462306a36Sopenharmony_ci	static const u32 tssi_trk[2] = {R_P0_TSSI_TRK, R_P1_TSSI_TRK};
148562306a36Sopenharmony_ci	static const u32 ctrl_bbrst[2] = {R_P0_TXPW_RSTB, R_P1_TXPW_RSTB};
148662306a36Sopenharmony_ci
148762306a36Sopenharmony_ci	if (en) {
148862306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, ctrl_bbrst[path], B_P0_TXPW_RSTB_MANON, 0x0);
148962306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, tssi_trk[path], B_P0_TSSI_TRK_EN, 0x0);
149062306a36Sopenharmony_ci	} else {
149162306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, ctrl_bbrst[path], B_P0_TXPW_RSTB_MANON, 0x1);
149262306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, tssi_trk[path], B_P0_TSSI_TRK_EN, 0x1);
149362306a36Sopenharmony_ci	}
149462306a36Sopenharmony_ci}
149562306a36Sopenharmony_ci
149662306a36Sopenharmony_cistatic void rtw8852b_tssi_cont_en_phyidx(struct rtw89_dev *rtwdev, bool en,
149762306a36Sopenharmony_ci					 u8 phy_idx)
149862306a36Sopenharmony_ci{
149962306a36Sopenharmony_ci	if (!rtwdev->dbcc_en) {
150062306a36Sopenharmony_ci		rtw8852b_tssi_cont_en(rtwdev, en, RF_PATH_A);
150162306a36Sopenharmony_ci		rtw8852b_tssi_cont_en(rtwdev, en, RF_PATH_B);
150262306a36Sopenharmony_ci	} else {
150362306a36Sopenharmony_ci		if (phy_idx == RTW89_PHY_0)
150462306a36Sopenharmony_ci			rtw8852b_tssi_cont_en(rtwdev, en, RF_PATH_A);
150562306a36Sopenharmony_ci		else
150662306a36Sopenharmony_ci			rtw8852b_tssi_cont_en(rtwdev, en, RF_PATH_B);
150762306a36Sopenharmony_ci	}
150862306a36Sopenharmony_ci}
150962306a36Sopenharmony_ci
151062306a36Sopenharmony_cistatic void rtw8852b_adc_en(struct rtw89_dev *rtwdev, bool en)
151162306a36Sopenharmony_ci{
151262306a36Sopenharmony_ci	if (en)
151362306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_ADC_FIFO, B_ADC_FIFO_RST, 0x0);
151462306a36Sopenharmony_ci	else
151562306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_ADC_FIFO, B_ADC_FIFO_RST, 0xf);
151662306a36Sopenharmony_ci}
151762306a36Sopenharmony_ci
151862306a36Sopenharmony_cistatic void rtw8852b_set_channel_help(struct rtw89_dev *rtwdev, bool enter,
151962306a36Sopenharmony_ci				      struct rtw89_channel_help_params *p,
152062306a36Sopenharmony_ci				      const struct rtw89_chan *chan,
152162306a36Sopenharmony_ci				      enum rtw89_mac_idx mac_idx,
152262306a36Sopenharmony_ci				      enum rtw89_phy_idx phy_idx)
152362306a36Sopenharmony_ci{
152462306a36Sopenharmony_ci	if (enter) {
152562306a36Sopenharmony_ci		rtw89_chip_stop_sch_tx(rtwdev, RTW89_MAC_0, &p->tx_en, RTW89_SCH_TX_SEL_ALL);
152662306a36Sopenharmony_ci		rtw89_mac_cfg_ppdu_status(rtwdev, RTW89_MAC_0, false);
152762306a36Sopenharmony_ci		rtw8852b_tssi_cont_en_phyidx(rtwdev, false, RTW89_PHY_0);
152862306a36Sopenharmony_ci		rtw8852b_adc_en(rtwdev, false);
152962306a36Sopenharmony_ci		fsleep(40);
153062306a36Sopenharmony_ci		rtw8852b_bb_reset_en(rtwdev, chan->band_type, phy_idx, false);
153162306a36Sopenharmony_ci	} else {
153262306a36Sopenharmony_ci		rtw89_mac_cfg_ppdu_status(rtwdev, RTW89_MAC_0, true);
153362306a36Sopenharmony_ci		rtw8852b_adc_en(rtwdev, true);
153462306a36Sopenharmony_ci		rtw8852b_tssi_cont_en_phyidx(rtwdev, true, RTW89_PHY_0);
153562306a36Sopenharmony_ci		rtw8852b_bb_reset_en(rtwdev, chan->band_type, phy_idx, true);
153662306a36Sopenharmony_ci		rtw89_chip_resume_sch_tx(rtwdev, RTW89_MAC_0, p->tx_en);
153762306a36Sopenharmony_ci	}
153862306a36Sopenharmony_ci}
153962306a36Sopenharmony_ci
154062306a36Sopenharmony_cistatic void rtw8852b_rfk_init(struct rtw89_dev *rtwdev)
154162306a36Sopenharmony_ci{
154262306a36Sopenharmony_ci	rtwdev->is_tssi_mode[RF_PATH_A] = false;
154362306a36Sopenharmony_ci	rtwdev->is_tssi_mode[RF_PATH_B] = false;
154462306a36Sopenharmony_ci
154562306a36Sopenharmony_ci	rtw8852b_dpk_init(rtwdev);
154662306a36Sopenharmony_ci	rtw8852b_rck(rtwdev);
154762306a36Sopenharmony_ci	rtw8852b_dack(rtwdev);
154862306a36Sopenharmony_ci	rtw8852b_rx_dck(rtwdev, RTW89_PHY_0);
154962306a36Sopenharmony_ci}
155062306a36Sopenharmony_ci
155162306a36Sopenharmony_cistatic void rtw8852b_rfk_channel(struct rtw89_dev *rtwdev)
155262306a36Sopenharmony_ci{
155362306a36Sopenharmony_ci	enum rtw89_phy_idx phy_idx = RTW89_PHY_0;
155462306a36Sopenharmony_ci
155562306a36Sopenharmony_ci	rtw8852b_rx_dck(rtwdev, phy_idx);
155662306a36Sopenharmony_ci	rtw8852b_iqk(rtwdev, phy_idx);
155762306a36Sopenharmony_ci	rtw8852b_tssi(rtwdev, phy_idx, true);
155862306a36Sopenharmony_ci	rtw8852b_dpk(rtwdev, phy_idx);
155962306a36Sopenharmony_ci}
156062306a36Sopenharmony_ci
156162306a36Sopenharmony_cistatic void rtw8852b_rfk_band_changed(struct rtw89_dev *rtwdev,
156262306a36Sopenharmony_ci				      enum rtw89_phy_idx phy_idx)
156362306a36Sopenharmony_ci{
156462306a36Sopenharmony_ci	rtw8852b_tssi_scan(rtwdev, phy_idx);
156562306a36Sopenharmony_ci}
156662306a36Sopenharmony_ci
156762306a36Sopenharmony_cistatic void rtw8852b_rfk_scan(struct rtw89_dev *rtwdev, bool start)
156862306a36Sopenharmony_ci{
156962306a36Sopenharmony_ci	rtw8852b_wifi_scan_notify(rtwdev, start, RTW89_PHY_0);
157062306a36Sopenharmony_ci}
157162306a36Sopenharmony_ci
157262306a36Sopenharmony_cistatic void rtw8852b_rfk_track(struct rtw89_dev *rtwdev)
157362306a36Sopenharmony_ci{
157462306a36Sopenharmony_ci	rtw8852b_dpk_track(rtwdev);
157562306a36Sopenharmony_ci}
157662306a36Sopenharmony_ci
157762306a36Sopenharmony_cistatic u32 rtw8852b_bb_cal_txpwr_ref(struct rtw89_dev *rtwdev,
157862306a36Sopenharmony_ci				     enum rtw89_phy_idx phy_idx, s16 ref)
157962306a36Sopenharmony_ci{
158062306a36Sopenharmony_ci	const u16 tssi_16dbm_cw = 0x12c;
158162306a36Sopenharmony_ci	const u8 base_cw_0db = 0x27;
158262306a36Sopenharmony_ci	const s8 ofst_int = 0;
158362306a36Sopenharmony_ci	s16 pwr_s10_3;
158462306a36Sopenharmony_ci	s16 rf_pwr_cw;
158562306a36Sopenharmony_ci	u16 bb_pwr_cw;
158662306a36Sopenharmony_ci	u32 pwr_cw;
158762306a36Sopenharmony_ci	u32 tssi_ofst_cw;
158862306a36Sopenharmony_ci
158962306a36Sopenharmony_ci	pwr_s10_3 = (ref << 1) + (s16)(ofst_int) + (s16)(base_cw_0db << 3);
159062306a36Sopenharmony_ci	bb_pwr_cw = FIELD_GET(GENMASK(2, 0), pwr_s10_3);
159162306a36Sopenharmony_ci	rf_pwr_cw = FIELD_GET(GENMASK(8, 3), pwr_s10_3);
159262306a36Sopenharmony_ci	rf_pwr_cw = clamp_t(s16, rf_pwr_cw, 15, 63);
159362306a36Sopenharmony_ci	pwr_cw = (rf_pwr_cw << 3) | bb_pwr_cw;
159462306a36Sopenharmony_ci
159562306a36Sopenharmony_ci	tssi_ofst_cw = (u32)((s16)tssi_16dbm_cw + (ref << 1) - (16 << 3));
159662306a36Sopenharmony_ci	rtw89_debug(rtwdev, RTW89_DBG_TXPWR,
159762306a36Sopenharmony_ci		    "[TXPWR] tssi_ofst_cw=%d rf_cw=0x%x bb_cw=0x%x\n",
159862306a36Sopenharmony_ci		    tssi_ofst_cw, rf_pwr_cw, bb_pwr_cw);
159962306a36Sopenharmony_ci
160062306a36Sopenharmony_ci	return FIELD_PREP(B_DPD_TSSI_CW, tssi_ofst_cw) |
160162306a36Sopenharmony_ci	       FIELD_PREP(B_DPD_PWR_CW, pwr_cw) |
160262306a36Sopenharmony_ci	       FIELD_PREP(B_DPD_REF, ref);
160362306a36Sopenharmony_ci}
160462306a36Sopenharmony_ci
160562306a36Sopenharmony_cistatic void rtw8852b_set_txpwr_ref(struct rtw89_dev *rtwdev,
160662306a36Sopenharmony_ci				   enum rtw89_phy_idx phy_idx)
160762306a36Sopenharmony_ci{
160862306a36Sopenharmony_ci	static const u32 addr[RF_PATH_NUM_8852B] = {0x5800, 0x7800};
160962306a36Sopenharmony_ci	const u32 mask = B_DPD_TSSI_CW | B_DPD_PWR_CW | B_DPD_REF;
161062306a36Sopenharmony_ci	const u8 ofst_ofdm = 0x4;
161162306a36Sopenharmony_ci	const u8 ofst_cck = 0x8;
161262306a36Sopenharmony_ci	const s16 ref_ofdm = 0;
161362306a36Sopenharmony_ci	const s16 ref_cck = 0;
161462306a36Sopenharmony_ci	u32 val;
161562306a36Sopenharmony_ci	u8 i;
161662306a36Sopenharmony_ci
161762306a36Sopenharmony_ci	rtw89_debug(rtwdev, RTW89_DBG_TXPWR, "[TXPWR] set txpwr reference\n");
161862306a36Sopenharmony_ci
161962306a36Sopenharmony_ci	rtw89_mac_txpwr_write32_mask(rtwdev, phy_idx, R_AX_PWR_RATE_CTRL,
162062306a36Sopenharmony_ci				     B_AX_PWR_REF, 0x0);
162162306a36Sopenharmony_ci
162262306a36Sopenharmony_ci	rtw89_debug(rtwdev, RTW89_DBG_TXPWR, "[TXPWR] set bb ofdm txpwr ref\n");
162362306a36Sopenharmony_ci	val = rtw8852b_bb_cal_txpwr_ref(rtwdev, phy_idx, ref_ofdm);
162462306a36Sopenharmony_ci
162562306a36Sopenharmony_ci	for (i = 0; i < RF_PATH_NUM_8852B; i++)
162662306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, addr[i] + ofst_ofdm, mask, val,
162762306a36Sopenharmony_ci				      phy_idx);
162862306a36Sopenharmony_ci
162962306a36Sopenharmony_ci	rtw89_debug(rtwdev, RTW89_DBG_TXPWR, "[TXPWR] set bb cck txpwr ref\n");
163062306a36Sopenharmony_ci	val = rtw8852b_bb_cal_txpwr_ref(rtwdev, phy_idx, ref_cck);
163162306a36Sopenharmony_ci
163262306a36Sopenharmony_ci	for (i = 0; i < RF_PATH_NUM_8852B; i++)
163362306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, addr[i] + ofst_cck, mask, val,
163462306a36Sopenharmony_ci				      phy_idx);
163562306a36Sopenharmony_ci}
163662306a36Sopenharmony_ci
163762306a36Sopenharmony_cistatic void rtw8852b_bb_set_tx_shape_dfir(struct rtw89_dev *rtwdev,
163862306a36Sopenharmony_ci					  const struct rtw89_chan *chan,
163962306a36Sopenharmony_ci					  u8 tx_shape_idx,
164062306a36Sopenharmony_ci					  enum rtw89_phy_idx phy_idx)
164162306a36Sopenharmony_ci{
164262306a36Sopenharmony_ci#define __DFIR_CFG_ADDR(i) (R_TXFIR0 + ((i) << 2))
164362306a36Sopenharmony_ci#define __DFIR_CFG_MASK 0xffffffff
164462306a36Sopenharmony_ci#define __DFIR_CFG_NR 8
164562306a36Sopenharmony_ci#define __DECL_DFIR_PARAM(_name, _val...) \
164662306a36Sopenharmony_ci	static const u32 param_ ## _name[] = {_val}; \
164762306a36Sopenharmony_ci	static_assert(ARRAY_SIZE(param_ ## _name) == __DFIR_CFG_NR)
164862306a36Sopenharmony_ci
164962306a36Sopenharmony_ci	__DECL_DFIR_PARAM(flat,
165062306a36Sopenharmony_ci			  0x023D23FF, 0x0029B354, 0x000FC1C8, 0x00FDB053,
165162306a36Sopenharmony_ci			  0x00F86F9A, 0x06FAEF92, 0x00FE5FCC, 0x00FFDFF5);
165262306a36Sopenharmony_ci	__DECL_DFIR_PARAM(sharp,
165362306a36Sopenharmony_ci			  0x023D83FF, 0x002C636A, 0x0013F204, 0x00008090,
165462306a36Sopenharmony_ci			  0x00F87FB0, 0x06F99F83, 0x00FDBFBA, 0x00003FF5);
165562306a36Sopenharmony_ci	__DECL_DFIR_PARAM(sharp_14,
165662306a36Sopenharmony_ci			  0x023B13FF, 0x001C42DE, 0x00FDB0AD, 0x00F60F6E,
165762306a36Sopenharmony_ci			  0x00FD8F92, 0x0602D011, 0x0001C02C, 0x00FFF00A);
165862306a36Sopenharmony_ci	u8 ch = chan->channel;
165962306a36Sopenharmony_ci	const u32 *param;
166062306a36Sopenharmony_ci	u32 addr;
166162306a36Sopenharmony_ci	int i;
166262306a36Sopenharmony_ci
166362306a36Sopenharmony_ci	if (ch > 14) {
166462306a36Sopenharmony_ci		rtw89_warn(rtwdev,
166562306a36Sopenharmony_ci			   "set tx shape dfir by unknown ch: %d on 2G\n", ch);
166662306a36Sopenharmony_ci		return;
166762306a36Sopenharmony_ci	}
166862306a36Sopenharmony_ci
166962306a36Sopenharmony_ci	if (ch == 14)
167062306a36Sopenharmony_ci		param = param_sharp_14;
167162306a36Sopenharmony_ci	else
167262306a36Sopenharmony_ci		param = tx_shape_idx == 0 ? param_flat : param_sharp;
167362306a36Sopenharmony_ci
167462306a36Sopenharmony_ci	for (i = 0; i < __DFIR_CFG_NR; i++) {
167562306a36Sopenharmony_ci		addr = __DFIR_CFG_ADDR(i);
167662306a36Sopenharmony_ci		rtw89_debug(rtwdev, RTW89_DBG_TXPWR,
167762306a36Sopenharmony_ci			    "set tx shape dfir: 0x%x: 0x%x\n", addr, param[i]);
167862306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, addr, __DFIR_CFG_MASK, param[i],
167962306a36Sopenharmony_ci				      phy_idx);
168062306a36Sopenharmony_ci	}
168162306a36Sopenharmony_ci
168262306a36Sopenharmony_ci#undef __DECL_DFIR_PARAM
168362306a36Sopenharmony_ci#undef __DFIR_CFG_NR
168462306a36Sopenharmony_ci#undef __DFIR_CFG_MASK
168562306a36Sopenharmony_ci#undef __DECL_CFG_ADDR
168662306a36Sopenharmony_ci}
168762306a36Sopenharmony_ci
168862306a36Sopenharmony_cistatic void rtw8852b_set_tx_shape(struct rtw89_dev *rtwdev,
168962306a36Sopenharmony_ci				  const struct rtw89_chan *chan,
169062306a36Sopenharmony_ci				  enum rtw89_phy_idx phy_idx)
169162306a36Sopenharmony_ci{
169262306a36Sopenharmony_ci	u8 band = chan->band_type;
169362306a36Sopenharmony_ci	u8 regd = rtw89_regd_get(rtwdev, band);
169462306a36Sopenharmony_ci	u8 tx_shape_cck = rtw89_8852b_tx_shape[band][RTW89_RS_CCK][regd];
169562306a36Sopenharmony_ci	u8 tx_shape_ofdm = rtw89_8852b_tx_shape[band][RTW89_RS_OFDM][regd];
169662306a36Sopenharmony_ci
169762306a36Sopenharmony_ci	if (band == RTW89_BAND_2G)
169862306a36Sopenharmony_ci		rtw8852b_bb_set_tx_shape_dfir(rtwdev, chan, tx_shape_cck, phy_idx);
169962306a36Sopenharmony_ci
170062306a36Sopenharmony_ci	rtw89_phy_write32_mask(rtwdev, R_DCFO_OPT, B_TXSHAPE_TRIANGULAR_CFG,
170162306a36Sopenharmony_ci			       tx_shape_ofdm);
170262306a36Sopenharmony_ci}
170362306a36Sopenharmony_ci
170462306a36Sopenharmony_cistatic void rtw8852b_set_txpwr(struct rtw89_dev *rtwdev,
170562306a36Sopenharmony_ci			       const struct rtw89_chan *chan,
170662306a36Sopenharmony_ci			       enum rtw89_phy_idx phy_idx)
170762306a36Sopenharmony_ci{
170862306a36Sopenharmony_ci	rtw89_phy_set_txpwr_byrate(rtwdev, chan, phy_idx);
170962306a36Sopenharmony_ci	rtw89_phy_set_txpwr_offset(rtwdev, chan, phy_idx);
171062306a36Sopenharmony_ci	rtw8852b_set_tx_shape(rtwdev, chan, phy_idx);
171162306a36Sopenharmony_ci	rtw89_phy_set_txpwr_limit(rtwdev, chan, phy_idx);
171262306a36Sopenharmony_ci	rtw89_phy_set_txpwr_limit_ru(rtwdev, chan, phy_idx);
171362306a36Sopenharmony_ci}
171462306a36Sopenharmony_ci
171562306a36Sopenharmony_cistatic void rtw8852b_set_txpwr_ctrl(struct rtw89_dev *rtwdev,
171662306a36Sopenharmony_ci				    enum rtw89_phy_idx phy_idx)
171762306a36Sopenharmony_ci{
171862306a36Sopenharmony_ci	rtw8852b_set_txpwr_ref(rtwdev, phy_idx);
171962306a36Sopenharmony_ci}
172062306a36Sopenharmony_ci
172162306a36Sopenharmony_cistatic
172262306a36Sopenharmony_civoid rtw8852b_set_txpwr_ul_tb_offset(struct rtw89_dev *rtwdev,
172362306a36Sopenharmony_ci				     s8 pw_ofst, enum rtw89_mac_idx mac_idx)
172462306a36Sopenharmony_ci{
172562306a36Sopenharmony_ci	u32 reg;
172662306a36Sopenharmony_ci
172762306a36Sopenharmony_ci	if (pw_ofst < -16 || pw_ofst > 15) {
172862306a36Sopenharmony_ci		rtw89_warn(rtwdev, "[ULTB] Err pwr_offset=%d\n", pw_ofst);
172962306a36Sopenharmony_ci		return;
173062306a36Sopenharmony_ci	}
173162306a36Sopenharmony_ci
173262306a36Sopenharmony_ci	reg = rtw89_mac_reg_by_idx(rtwdev, R_AX_PWR_UL_TB_CTRL, mac_idx);
173362306a36Sopenharmony_ci	rtw89_write32_set(rtwdev, reg, B_AX_PWR_UL_TB_CTRL_EN);
173462306a36Sopenharmony_ci
173562306a36Sopenharmony_ci	reg = rtw89_mac_reg_by_idx(rtwdev, R_AX_PWR_UL_TB_1T, mac_idx);
173662306a36Sopenharmony_ci	rtw89_write32_mask(rtwdev, reg, B_AX_PWR_UL_TB_1T_MASK, pw_ofst);
173762306a36Sopenharmony_ci
173862306a36Sopenharmony_ci	pw_ofst = max_t(s8, pw_ofst - 3, -16);
173962306a36Sopenharmony_ci	reg = rtw89_mac_reg_by_idx(rtwdev, R_AX_PWR_UL_TB_2T, mac_idx);
174062306a36Sopenharmony_ci	rtw89_write32_mask(rtwdev, reg, B_AX_PWR_UL_TB_2T_MASK, pw_ofst);
174162306a36Sopenharmony_ci}
174262306a36Sopenharmony_ci
174362306a36Sopenharmony_cistatic int
174462306a36Sopenharmony_cirtw8852b_init_txpwr_unit(struct rtw89_dev *rtwdev, enum rtw89_phy_idx phy_idx)
174562306a36Sopenharmony_ci{
174662306a36Sopenharmony_ci	int ret;
174762306a36Sopenharmony_ci
174862306a36Sopenharmony_ci	ret = rtw89_mac_txpwr_write32(rtwdev, phy_idx, R_AX_PWR_UL_CTRL2, 0x07763333);
174962306a36Sopenharmony_ci	if (ret)
175062306a36Sopenharmony_ci		return ret;
175162306a36Sopenharmony_ci
175262306a36Sopenharmony_ci	ret = rtw89_mac_txpwr_write32(rtwdev, phy_idx, R_AX_PWR_COEXT_CTRL, 0x01ebf000);
175362306a36Sopenharmony_ci	if (ret)
175462306a36Sopenharmony_ci		return ret;
175562306a36Sopenharmony_ci
175662306a36Sopenharmony_ci	ret = rtw89_mac_txpwr_write32(rtwdev, phy_idx, R_AX_PWR_UL_CTRL0, 0x0002f8ff);
175762306a36Sopenharmony_ci	if (ret)
175862306a36Sopenharmony_ci		return ret;
175962306a36Sopenharmony_ci
176062306a36Sopenharmony_ci	rtw8852b_set_txpwr_ul_tb_offset(rtwdev, 0, phy_idx == RTW89_PHY_1 ?
176162306a36Sopenharmony_ci						   RTW89_MAC_1 : RTW89_MAC_0);
176262306a36Sopenharmony_ci
176362306a36Sopenharmony_ci	return 0;
176462306a36Sopenharmony_ci}
176562306a36Sopenharmony_ci
176662306a36Sopenharmony_civoid rtw8852b_bb_set_plcp_tx(struct rtw89_dev *rtwdev)
176762306a36Sopenharmony_ci{
176862306a36Sopenharmony_ci	const struct rtw89_reg3_def *def = rtw8852b_pmac_ht20_mcs7_tbl;
176962306a36Sopenharmony_ci	u8 i;
177062306a36Sopenharmony_ci
177162306a36Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(rtw8852b_pmac_ht20_mcs7_tbl); i++, def++)
177262306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, def->addr, def->mask, def->data);
177362306a36Sopenharmony_ci}
177462306a36Sopenharmony_ci
177562306a36Sopenharmony_cistatic void rtw8852b_stop_pmac_tx(struct rtw89_dev *rtwdev,
177662306a36Sopenharmony_ci				  struct rtw8852b_bb_pmac_info *tx_info,
177762306a36Sopenharmony_ci				  enum rtw89_phy_idx idx)
177862306a36Sopenharmony_ci{
177962306a36Sopenharmony_ci	rtw89_debug(rtwdev, RTW89_DBG_TSSI, "PMAC Stop Tx");
178062306a36Sopenharmony_ci	if (tx_info->mode == CONT_TX)
178162306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_PMAC_TX_PRD, B_PMAC_CTX_EN, 0, idx);
178262306a36Sopenharmony_ci	else if (tx_info->mode == PKTS_TX)
178362306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_PMAC_TX_PRD, B_PMAC_PTX_EN, 0, idx);
178462306a36Sopenharmony_ci}
178562306a36Sopenharmony_ci
178662306a36Sopenharmony_cistatic void rtw8852b_start_pmac_tx(struct rtw89_dev *rtwdev,
178762306a36Sopenharmony_ci				   struct rtw8852b_bb_pmac_info *tx_info,
178862306a36Sopenharmony_ci				   enum rtw89_phy_idx idx)
178962306a36Sopenharmony_ci{
179062306a36Sopenharmony_ci	enum rtw8852b_pmac_mode mode = tx_info->mode;
179162306a36Sopenharmony_ci	u32 pkt_cnt = tx_info->tx_cnt;
179262306a36Sopenharmony_ci	u16 period = tx_info->period;
179362306a36Sopenharmony_ci
179462306a36Sopenharmony_ci	if (mode == CONT_TX && !tx_info->is_cck) {
179562306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_PMAC_TX_PRD, B_PMAC_CTX_EN, 1, idx);
179662306a36Sopenharmony_ci		rtw89_debug(rtwdev, RTW89_DBG_TSSI, "PMAC CTx Start");
179762306a36Sopenharmony_ci	} else if (mode == PKTS_TX) {
179862306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_PMAC_TX_PRD, B_PMAC_PTX_EN, 1, idx);
179962306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_PMAC_TX_PRD,
180062306a36Sopenharmony_ci				      B_PMAC_TX_PRD_MSK, period, idx);
180162306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_PMAC_TX_CNT, B_PMAC_TX_CNT_MSK,
180262306a36Sopenharmony_ci				      pkt_cnt, idx);
180362306a36Sopenharmony_ci		rtw89_debug(rtwdev, RTW89_DBG_TSSI, "PMAC PTx Start");
180462306a36Sopenharmony_ci	}
180562306a36Sopenharmony_ci
180662306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_PMAC_TX_CTRL, B_PMAC_TXEN_DIS, 1, idx);
180762306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_PMAC_TX_CTRL, B_PMAC_TXEN_DIS, 0, idx);
180862306a36Sopenharmony_ci}
180962306a36Sopenharmony_ci
181062306a36Sopenharmony_civoid rtw8852b_bb_set_pmac_tx(struct rtw89_dev *rtwdev,
181162306a36Sopenharmony_ci			     struct rtw8852b_bb_pmac_info *tx_info,
181262306a36Sopenharmony_ci			     enum rtw89_phy_idx idx)
181362306a36Sopenharmony_ci{
181462306a36Sopenharmony_ci	const struct rtw89_chan *chan = rtw89_chan_get(rtwdev, RTW89_SUB_ENTITY_0);
181562306a36Sopenharmony_ci
181662306a36Sopenharmony_ci	if (!tx_info->en_pmac_tx) {
181762306a36Sopenharmony_ci		rtw8852b_stop_pmac_tx(rtwdev, tx_info, idx);
181862306a36Sopenharmony_ci		rtw89_phy_write32_idx(rtwdev, R_PD_CTRL, B_PD_HIT_DIS, 0, idx);
181962306a36Sopenharmony_ci		if (chan->band_type == RTW89_BAND_2G)
182062306a36Sopenharmony_ci			rtw89_phy_write32_clr(rtwdev, R_RXCCA, B_RXCCA_DIS);
182162306a36Sopenharmony_ci		return;
182262306a36Sopenharmony_ci	}
182362306a36Sopenharmony_ci
182462306a36Sopenharmony_ci	rtw89_debug(rtwdev, RTW89_DBG_TSSI, "PMAC Tx Enable");
182562306a36Sopenharmony_ci
182662306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_PMAC_GNT, B_PMAC_GNT_TXEN, 1, idx);
182762306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_PMAC_GNT, B_PMAC_GNT_RXEN, 1, idx);
182862306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_PMAC_RX_CFG1, B_PMAC_OPT1_MSK, 0x3f, idx);
182962306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_RSTB_ASYNC, B_RSTB_ASYNC_ALL, 0, idx);
183062306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_PD_CTRL, B_PD_HIT_DIS, 1, idx);
183162306a36Sopenharmony_ci	rtw89_phy_write32_set(rtwdev, R_RXCCA, B_RXCCA_DIS);
183262306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_RSTB_ASYNC, B_RSTB_ASYNC_ALL, 1, idx);
183362306a36Sopenharmony_ci
183462306a36Sopenharmony_ci	rtw8852b_start_pmac_tx(rtwdev, tx_info, idx);
183562306a36Sopenharmony_ci}
183662306a36Sopenharmony_ci
183762306a36Sopenharmony_civoid rtw8852b_bb_set_pmac_pkt_tx(struct rtw89_dev *rtwdev, u8 enable,
183862306a36Sopenharmony_ci				 u16 tx_cnt, u16 period, u16 tx_time,
183962306a36Sopenharmony_ci				 enum rtw89_phy_idx idx)
184062306a36Sopenharmony_ci{
184162306a36Sopenharmony_ci	struct rtw8852b_bb_pmac_info tx_info = {0};
184262306a36Sopenharmony_ci
184362306a36Sopenharmony_ci	tx_info.en_pmac_tx = enable;
184462306a36Sopenharmony_ci	tx_info.is_cck = 0;
184562306a36Sopenharmony_ci	tx_info.mode = PKTS_TX;
184662306a36Sopenharmony_ci	tx_info.tx_cnt = tx_cnt;
184762306a36Sopenharmony_ci	tx_info.period = period;
184862306a36Sopenharmony_ci	tx_info.tx_time = tx_time;
184962306a36Sopenharmony_ci
185062306a36Sopenharmony_ci	rtw8852b_bb_set_pmac_tx(rtwdev, &tx_info, idx);
185162306a36Sopenharmony_ci}
185262306a36Sopenharmony_ci
185362306a36Sopenharmony_civoid rtw8852b_bb_set_power(struct rtw89_dev *rtwdev, s16 pwr_dbm,
185462306a36Sopenharmony_ci			   enum rtw89_phy_idx idx)
185562306a36Sopenharmony_ci{
185662306a36Sopenharmony_ci	rtw89_debug(rtwdev, RTW89_DBG_TSSI, "PMAC CFG Tx PWR = %d", pwr_dbm);
185762306a36Sopenharmony_ci
185862306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_MAC_SEL, B_MAC_SEL_PWR_EN, 1, idx);
185962306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_TXPWR, B_TXPWR_MSK, pwr_dbm, idx);
186062306a36Sopenharmony_ci}
186162306a36Sopenharmony_ci
186262306a36Sopenharmony_civoid rtw8852b_bb_cfg_tx_path(struct rtw89_dev *rtwdev, u8 tx_path)
186362306a36Sopenharmony_ci{
186462306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_MAC_SEL, B_MAC_SEL_MOD, 7, RTW89_PHY_0);
186562306a36Sopenharmony_ci
186662306a36Sopenharmony_ci	rtw89_debug(rtwdev, RTW89_DBG_TSSI, "PMAC CFG Tx Path = %d", tx_path);
186762306a36Sopenharmony_ci
186862306a36Sopenharmony_ci	if (tx_path == RF_PATH_A) {
186962306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXPATH_SEL, B_TXPATH_SEL_MSK, 1);
187062306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXNSS_MAP, B_TXNSS_MAP_MSK, 0);
187162306a36Sopenharmony_ci	} else if (tx_path == RF_PATH_B) {
187262306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXPATH_SEL, B_TXPATH_SEL_MSK, 2);
187362306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXNSS_MAP, B_TXNSS_MAP_MSK, 0);
187462306a36Sopenharmony_ci	} else if (tx_path == RF_PATH_AB) {
187562306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXPATH_SEL, B_TXPATH_SEL_MSK, 3);
187662306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXNSS_MAP, B_TXNSS_MAP_MSK, 4);
187762306a36Sopenharmony_ci	} else {
187862306a36Sopenharmony_ci		rtw89_debug(rtwdev, RTW89_DBG_TSSI, "Error Tx Path");
187962306a36Sopenharmony_ci	}
188062306a36Sopenharmony_ci}
188162306a36Sopenharmony_ci
188262306a36Sopenharmony_civoid rtw8852b_bb_tx_mode_switch(struct rtw89_dev *rtwdev,
188362306a36Sopenharmony_ci				enum rtw89_phy_idx idx, u8 mode)
188462306a36Sopenharmony_ci{
188562306a36Sopenharmony_ci	if (mode != 0)
188662306a36Sopenharmony_ci		return;
188762306a36Sopenharmony_ci
188862306a36Sopenharmony_ci	rtw89_debug(rtwdev, RTW89_DBG_TSSI, "Tx mode switch");
188962306a36Sopenharmony_ci
189062306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_PMAC_GNT, B_PMAC_GNT_TXEN, 0, idx);
189162306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_PMAC_GNT, B_PMAC_GNT_RXEN, 0, idx);
189262306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_PMAC_RX_CFG1, B_PMAC_OPT1_MSK, 0, idx);
189362306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_PMAC_RXMOD, B_PMAC_RXMOD_MSK, 0, idx);
189462306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_MAC_SEL, B_MAC_SEL_DPD_EN, 0, idx);
189562306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_MAC_SEL, B_MAC_SEL_MOD, 0, idx);
189662306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_MAC_SEL, B_MAC_SEL_PWR_EN, 0, idx);
189762306a36Sopenharmony_ci}
189862306a36Sopenharmony_ci
189962306a36Sopenharmony_civoid rtw8852b_bb_backup_tssi(struct rtw89_dev *rtwdev, enum rtw89_phy_idx idx,
190062306a36Sopenharmony_ci			     struct rtw8852b_bb_tssi_bak *bak)
190162306a36Sopenharmony_ci{
190262306a36Sopenharmony_ci	s32 tmp;
190362306a36Sopenharmony_ci
190462306a36Sopenharmony_ci	bak->tx_path = rtw89_phy_read32_idx(rtwdev, R_TXPATH_SEL, B_TXPATH_SEL_MSK, idx);
190562306a36Sopenharmony_ci	bak->rx_path = rtw89_phy_read32_idx(rtwdev, R_CHBW_MOD_V1, B_ANT_RX_SEG0, idx);
190662306a36Sopenharmony_ci	bak->p0_rfmode = rtw89_phy_read32_idx(rtwdev, R_P0_RFMODE, MASKDWORD, idx);
190762306a36Sopenharmony_ci	bak->p0_rfmode_ftm = rtw89_phy_read32_idx(rtwdev, R_P0_RFMODE_FTM_RX, MASKDWORD, idx);
190862306a36Sopenharmony_ci	bak->p1_rfmode = rtw89_phy_read32_idx(rtwdev, R_P1_RFMODE, MASKDWORD, idx);
190962306a36Sopenharmony_ci	bak->p1_rfmode_ftm = rtw89_phy_read32_idx(rtwdev, R_P1_RFMODE_FTM_RX, MASKDWORD, idx);
191062306a36Sopenharmony_ci	tmp = rtw89_phy_read32_idx(rtwdev, R_TXPWR, B_TXPWR_MSK, idx);
191162306a36Sopenharmony_ci	bak->tx_pwr = sign_extend32(tmp, 8);
191262306a36Sopenharmony_ci}
191362306a36Sopenharmony_ci
191462306a36Sopenharmony_civoid rtw8852b_bb_restore_tssi(struct rtw89_dev *rtwdev, enum rtw89_phy_idx idx,
191562306a36Sopenharmony_ci			      const struct rtw8852b_bb_tssi_bak *bak)
191662306a36Sopenharmony_ci{
191762306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_TXPATH_SEL, B_TXPATH_SEL_MSK, bak->tx_path, idx);
191862306a36Sopenharmony_ci	if (bak->tx_path == RF_AB)
191962306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXNSS_MAP, B_TXNSS_MAP_MSK, 0x4);
192062306a36Sopenharmony_ci	else
192162306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_TXNSS_MAP, B_TXNSS_MAP_MSK, 0x0);
192262306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_CHBW_MOD_V1, B_ANT_RX_SEG0, bak->rx_path, idx);
192362306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_MAC_SEL, B_MAC_SEL_PWR_EN, 1, idx);
192462306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_P0_RFMODE, MASKDWORD, bak->p0_rfmode, idx);
192562306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_P0_RFMODE_FTM_RX, MASKDWORD, bak->p0_rfmode_ftm, idx);
192662306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_P1_RFMODE, MASKDWORD, bak->p1_rfmode, idx);
192762306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_P1_RFMODE_FTM_RX, MASKDWORD, bak->p1_rfmode_ftm, idx);
192862306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_TXPWR, B_TXPWR_MSK, bak->tx_pwr, idx);
192962306a36Sopenharmony_ci}
193062306a36Sopenharmony_ci
193162306a36Sopenharmony_cistatic void rtw8852b_bb_ctrl_btc_preagc(struct rtw89_dev *rtwdev, bool bt_en)
193262306a36Sopenharmony_ci{
193362306a36Sopenharmony_ci	rtw89_phy_write_reg3_tbl(rtwdev, bt_en ? &rtw8852b_btc_preagc_en_defs_tbl :
193462306a36Sopenharmony_ci						 &rtw8852b_btc_preagc_dis_defs_tbl);
193562306a36Sopenharmony_ci}
193662306a36Sopenharmony_ci
193762306a36Sopenharmony_cistatic void rtw8852b_ctrl_btg(struct rtw89_dev *rtwdev, bool btg)
193862306a36Sopenharmony_ci{
193962306a36Sopenharmony_ci	if (btg) {
194062306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH0_BT_SHARE_V1,
194162306a36Sopenharmony_ci				       B_PATH0_BT_SHARE_V1, 0x1);
194262306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH0_BTG_PATH_V1,
194362306a36Sopenharmony_ci				       B_PATH0_BTG_PATH_V1, 0x0);
194462306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH1_G_LNA6_OP1DB_V1,
194562306a36Sopenharmony_ci				       B_PATH1_G_LNA6_OP1DB_V1, 0x20);
194662306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH1_G_TIA0_LNA6_OP1DB_V1,
194762306a36Sopenharmony_ci				       B_PATH1_G_TIA0_LNA6_OP1DB_V1, 0x30);
194862306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH1_BT_SHARE_V1,
194962306a36Sopenharmony_ci				       B_PATH1_BT_SHARE_V1, 0x1);
195062306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH1_BTG_PATH_V1,
195162306a36Sopenharmony_ci				       B_PATH1_BTG_PATH_V1, 0x1);
195262306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PMAC_GNT, B_PMAC_GNT_P1, 0x0);
195362306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_CHBW_MOD_V1, B_BT_SHARE, 0x1);
195462306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_FC0_BW_V1, B_ANT_RX_BT_SEG0, 0x2);
195562306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_BT_DYN_DC_EST_EN_V1,
195662306a36Sopenharmony_ci				       B_BT_DYN_DC_EST_EN_MSK, 0x1);
195762306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_GNT_BT_WGT_EN, B_GNT_BT_WGT_EN, 0x1);
195862306a36Sopenharmony_ci	} else {
195962306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH0_BT_SHARE_V1,
196062306a36Sopenharmony_ci				       B_PATH0_BT_SHARE_V1, 0x0);
196162306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH0_BTG_PATH_V1,
196262306a36Sopenharmony_ci				       B_PATH0_BTG_PATH_V1, 0x0);
196362306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH1_G_LNA6_OP1DB_V1,
196462306a36Sopenharmony_ci				       B_PATH1_G_LNA6_OP1DB_V1, 0x1a);
196562306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH1_G_TIA0_LNA6_OP1DB_V1,
196662306a36Sopenharmony_ci				       B_PATH1_G_TIA0_LNA6_OP1DB_V1, 0x2a);
196762306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH1_BT_SHARE_V1,
196862306a36Sopenharmony_ci				       B_PATH1_BT_SHARE_V1, 0x0);
196962306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PATH1_BTG_PATH_V1,
197062306a36Sopenharmony_ci				       B_PATH1_BTG_PATH_V1, 0x0);
197162306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_PMAC_GNT, B_PMAC_GNT_P1, 0xc);
197262306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_CHBW_MOD_V1, B_BT_SHARE, 0x0);
197362306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_FC0_BW_V1, B_ANT_RX_BT_SEG0, 0x0);
197462306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_BT_DYN_DC_EST_EN_V1,
197562306a36Sopenharmony_ci				       B_BT_DYN_DC_EST_EN_MSK, 0x1);
197662306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_GNT_BT_WGT_EN, B_GNT_BT_WGT_EN, 0x0);
197762306a36Sopenharmony_ci	}
197862306a36Sopenharmony_ci}
197962306a36Sopenharmony_ci
198062306a36Sopenharmony_civoid rtw8852b_bb_ctrl_rx_path(struct rtw89_dev *rtwdev,
198162306a36Sopenharmony_ci			      enum rtw89_rf_path_bit rx_path)
198262306a36Sopenharmony_ci{
198362306a36Sopenharmony_ci	const struct rtw89_chan *chan = rtw89_chan_get(rtwdev, RTW89_SUB_ENTITY_0);
198462306a36Sopenharmony_ci	u32 rst_mask0;
198562306a36Sopenharmony_ci	u32 rst_mask1;
198662306a36Sopenharmony_ci
198762306a36Sopenharmony_ci	if (rx_path == RF_A) {
198862306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_CHBW_MOD_V1, B_ANT_RX_SEG0, 1);
198962306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_FC0_BW_V1, B_ANT_RX_1RCCA_SEG0, 1);
199062306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_FC0_BW_V1, B_ANT_RX_1RCCA_SEG1, 1);
199162306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXHT_MCS_LIMIT, B_RXHT_MCS_LIMIT, 0);
199262306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXVHT_MCS_LIMIT, B_RXVHT_MCS_LIMIT, 0);
199362306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_USER_MAX, 4);
199462306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_MAX_NSS, 0);
199562306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHETB_MAX_NSS, 0);
199662306a36Sopenharmony_ci	} else if (rx_path == RF_B) {
199762306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_CHBW_MOD_V1, B_ANT_RX_SEG0, 2);
199862306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_FC0_BW_V1, B_ANT_RX_1RCCA_SEG0, 2);
199962306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_FC0_BW_V1, B_ANT_RX_1RCCA_SEG1, 2);
200062306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXHT_MCS_LIMIT, B_RXHT_MCS_LIMIT, 0);
200162306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXVHT_MCS_LIMIT, B_RXVHT_MCS_LIMIT, 0);
200262306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_USER_MAX, 4);
200362306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_MAX_NSS, 0);
200462306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHETB_MAX_NSS, 0);
200562306a36Sopenharmony_ci	} else if (rx_path == RF_AB) {
200662306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_CHBW_MOD_V1, B_ANT_RX_SEG0, 3);
200762306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_FC0_BW_V1, B_ANT_RX_1RCCA_SEG0, 3);
200862306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_FC0_BW_V1, B_ANT_RX_1RCCA_SEG1, 3);
200962306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXHT_MCS_LIMIT, B_RXHT_MCS_LIMIT, 1);
201062306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXVHT_MCS_LIMIT, B_RXVHT_MCS_LIMIT, 1);
201162306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_USER_MAX, 4);
201262306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_MAX_NSS, 1);
201362306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHETB_MAX_NSS, 1);
201462306a36Sopenharmony_ci	}
201562306a36Sopenharmony_ci
201662306a36Sopenharmony_ci	rtw8852b_set_gain_offset(rtwdev, chan->subband_type, RTW89_PHY_0);
201762306a36Sopenharmony_ci
201862306a36Sopenharmony_ci	if (chan->band_type == RTW89_BAND_2G &&
201962306a36Sopenharmony_ci	    (rx_path == RF_B || rx_path == RF_AB))
202062306a36Sopenharmony_ci		rtw8852b_ctrl_btg(rtwdev, true);
202162306a36Sopenharmony_ci	else
202262306a36Sopenharmony_ci		rtw8852b_ctrl_btg(rtwdev, false);
202362306a36Sopenharmony_ci
202462306a36Sopenharmony_ci	rst_mask0 = B_P0_TXPW_RSTB_MANON | B_P0_TXPW_RSTB_TSSI;
202562306a36Sopenharmony_ci	rst_mask1 = B_P1_TXPW_RSTB_MANON | B_P1_TXPW_RSTB_TSSI;
202662306a36Sopenharmony_ci	if (rx_path == RF_A) {
202762306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_P0_TXPW_RSTB, rst_mask0, 1);
202862306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_P0_TXPW_RSTB, rst_mask0, 3);
202962306a36Sopenharmony_ci	} else {
203062306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_P1_TXPW_RSTB, rst_mask1, 1);
203162306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_P1_TXPW_RSTB, rst_mask1, 3);
203262306a36Sopenharmony_ci	}
203362306a36Sopenharmony_ci}
203462306a36Sopenharmony_ci
203562306a36Sopenharmony_cistatic void rtw8852b_bb_ctrl_rf_mode_rx_path(struct rtw89_dev *rtwdev,
203662306a36Sopenharmony_ci					     enum rtw89_rf_path_bit rx_path)
203762306a36Sopenharmony_ci{
203862306a36Sopenharmony_ci	if (rx_path == RF_A) {
203962306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_P0_RFMODE,
204062306a36Sopenharmony_ci				       B_P0_RFMODE_ORI_TXRX_FTM_TX, 0x1233312);
204162306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_P0_RFMODE_FTM_RX,
204262306a36Sopenharmony_ci				       B_P0_RFMODE_FTM_RX, 0x333);
204362306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_P1_RFMODE,
204462306a36Sopenharmony_ci				       B_P1_RFMODE_ORI_TXRX_FTM_TX, 0x1111111);
204562306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_P1_RFMODE_FTM_RX,
204662306a36Sopenharmony_ci				       B_P1_RFMODE_FTM_RX, 0x111);
204762306a36Sopenharmony_ci	} else if (rx_path == RF_B) {
204862306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_P0_RFMODE,
204962306a36Sopenharmony_ci				       B_P0_RFMODE_ORI_TXRX_FTM_TX, 0x1111111);
205062306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_P0_RFMODE_FTM_RX,
205162306a36Sopenharmony_ci				       B_P0_RFMODE_FTM_RX, 0x111);
205262306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_P1_RFMODE,
205362306a36Sopenharmony_ci				       B_P1_RFMODE_ORI_TXRX_FTM_TX, 0x1233312);
205462306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_P1_RFMODE_FTM_RX,
205562306a36Sopenharmony_ci				       B_P1_RFMODE_FTM_RX, 0x333);
205662306a36Sopenharmony_ci	} else if (rx_path == RF_AB) {
205762306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_P0_RFMODE,
205862306a36Sopenharmony_ci				       B_P0_RFMODE_ORI_TXRX_FTM_TX, 0x1233312);
205962306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_P0_RFMODE_FTM_RX,
206062306a36Sopenharmony_ci				       B_P0_RFMODE_FTM_RX, 0x333);
206162306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_P1_RFMODE,
206262306a36Sopenharmony_ci				       B_P1_RFMODE_ORI_TXRX_FTM_TX, 0x1233312);
206362306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_P1_RFMODE_FTM_RX,
206462306a36Sopenharmony_ci				       B_P1_RFMODE_FTM_RX, 0x333);
206562306a36Sopenharmony_ci	}
206662306a36Sopenharmony_ci}
206762306a36Sopenharmony_ci
206862306a36Sopenharmony_cistatic void rtw8852b_bb_cfg_txrx_path(struct rtw89_dev *rtwdev)
206962306a36Sopenharmony_ci{
207062306a36Sopenharmony_ci	struct rtw89_hal *hal = &rtwdev->hal;
207162306a36Sopenharmony_ci	enum rtw89_rf_path_bit rx_path = hal->antenna_rx ? hal->antenna_rx : RF_AB;
207262306a36Sopenharmony_ci
207362306a36Sopenharmony_ci	rtw8852b_bb_ctrl_rx_path(rtwdev, rx_path);
207462306a36Sopenharmony_ci	rtw8852b_bb_ctrl_rf_mode_rx_path(rtwdev, rx_path);
207562306a36Sopenharmony_ci
207662306a36Sopenharmony_ci	if (rtwdev->hal.rx_nss == 1) {
207762306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXHT_MCS_LIMIT, B_RXHT_MCS_LIMIT, 0);
207862306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXVHT_MCS_LIMIT, B_RXVHT_MCS_LIMIT, 0);
207962306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_MAX_NSS, 0);
208062306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHETB_MAX_NSS, 0);
208162306a36Sopenharmony_ci	} else {
208262306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXHT_MCS_LIMIT, B_RXHT_MCS_LIMIT, 1);
208362306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXVHT_MCS_LIMIT, B_RXVHT_MCS_LIMIT, 1);
208462306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHE_MAX_NSS, 1);
208562306a36Sopenharmony_ci		rtw89_phy_write32_mask(rtwdev, R_RXHE, B_RXHETB_MAX_NSS, 1);
208662306a36Sopenharmony_ci	}
208762306a36Sopenharmony_ci
208862306a36Sopenharmony_ci	rtw89_phy_write32_idx(rtwdev, R_MAC_SEL, B_MAC_SEL_MOD, 0x0, RTW89_PHY_0);
208962306a36Sopenharmony_ci}
209062306a36Sopenharmony_ci
209162306a36Sopenharmony_cistatic u8 rtw8852b_get_thermal(struct rtw89_dev *rtwdev, enum rtw89_rf_path rf_path)
209262306a36Sopenharmony_ci{
209362306a36Sopenharmony_ci	if (rtwdev->is_tssi_mode[rf_path]) {
209462306a36Sopenharmony_ci		u32 addr = 0x1c10 + (rf_path << 13);
209562306a36Sopenharmony_ci
209662306a36Sopenharmony_ci		return rtw89_phy_read32_mask(rtwdev, addr, 0x3F000000);
209762306a36Sopenharmony_ci	}
209862306a36Sopenharmony_ci
209962306a36Sopenharmony_ci	rtw89_write_rf(rtwdev, rf_path, RR_TM, RR_TM_TRI, 0x1);
210062306a36Sopenharmony_ci	rtw89_write_rf(rtwdev, rf_path, RR_TM, RR_TM_TRI, 0x0);
210162306a36Sopenharmony_ci	rtw89_write_rf(rtwdev, rf_path, RR_TM, RR_TM_TRI, 0x1);
210262306a36Sopenharmony_ci
210362306a36Sopenharmony_ci	fsleep(200);
210462306a36Sopenharmony_ci
210562306a36Sopenharmony_ci	return rtw89_read_rf(rtwdev, rf_path, RR_TM, RR_TM_VAL);
210662306a36Sopenharmony_ci}
210762306a36Sopenharmony_ci
210862306a36Sopenharmony_cistatic void rtw8852b_btc_set_rfe(struct rtw89_dev *rtwdev)
210962306a36Sopenharmony_ci{
211062306a36Sopenharmony_ci	struct rtw89_btc *btc = &rtwdev->btc;
211162306a36Sopenharmony_ci	struct rtw89_btc_module *module = &btc->mdinfo;
211262306a36Sopenharmony_ci
211362306a36Sopenharmony_ci	module->rfe_type = rtwdev->efuse.rfe_type;
211462306a36Sopenharmony_ci	module->cv = rtwdev->hal.cv;
211562306a36Sopenharmony_ci	module->bt_solo = 0;
211662306a36Sopenharmony_ci	module->switch_type = BTC_SWITCH_INTERNAL;
211762306a36Sopenharmony_ci
211862306a36Sopenharmony_ci	if (module->rfe_type > 0)
211962306a36Sopenharmony_ci		module->ant.num = module->rfe_type % 2 ? 2 : 3;
212062306a36Sopenharmony_ci	else
212162306a36Sopenharmony_ci		module->ant.num = 2;
212262306a36Sopenharmony_ci
212362306a36Sopenharmony_ci	module->ant.diversity = 0;
212462306a36Sopenharmony_ci	module->ant.isolation = 10;
212562306a36Sopenharmony_ci
212662306a36Sopenharmony_ci	if (module->ant.num == 3) {
212762306a36Sopenharmony_ci		module->ant.type = BTC_ANT_DEDICATED;
212862306a36Sopenharmony_ci		module->bt_pos = BTC_BT_ALONE;
212962306a36Sopenharmony_ci	} else {
213062306a36Sopenharmony_ci		module->ant.type = BTC_ANT_SHARED;
213162306a36Sopenharmony_ci		module->bt_pos = BTC_BT_BTG;
213262306a36Sopenharmony_ci	}
213362306a36Sopenharmony_ci}
213462306a36Sopenharmony_ci
213562306a36Sopenharmony_cistatic
213662306a36Sopenharmony_civoid rtw8852b_set_trx_mask(struct rtw89_dev *rtwdev, u8 path, u8 group, u32 val)
213762306a36Sopenharmony_ci{
213862306a36Sopenharmony_ci	rtw89_write_rf(rtwdev, path, RR_LUTWE, RFREG_MASK, 0x20000);
213962306a36Sopenharmony_ci	rtw89_write_rf(rtwdev, path, RR_LUTWA, RFREG_MASK, group);
214062306a36Sopenharmony_ci	rtw89_write_rf(rtwdev, path, RR_LUTWD0, RFREG_MASK, val);
214162306a36Sopenharmony_ci	rtw89_write_rf(rtwdev, path, RR_LUTWE, RFREG_MASK, 0x0);
214262306a36Sopenharmony_ci}
214362306a36Sopenharmony_ci
214462306a36Sopenharmony_cistatic void rtw8852b_btc_init_cfg(struct rtw89_dev *rtwdev)
214562306a36Sopenharmony_ci{
214662306a36Sopenharmony_ci	struct rtw89_btc *btc = &rtwdev->btc;
214762306a36Sopenharmony_ci	struct rtw89_btc_module *module = &btc->mdinfo;
214862306a36Sopenharmony_ci	const struct rtw89_chip_info *chip = rtwdev->chip;
214962306a36Sopenharmony_ci	const struct rtw89_mac_ax_coex coex_params = {
215062306a36Sopenharmony_ci		.pta_mode = RTW89_MAC_AX_COEX_RTK_MODE,
215162306a36Sopenharmony_ci		.direction = RTW89_MAC_AX_COEX_INNER,
215262306a36Sopenharmony_ci	};
215362306a36Sopenharmony_ci
215462306a36Sopenharmony_ci	/* PTA init  */
215562306a36Sopenharmony_ci	rtw89_mac_coex_init(rtwdev, &coex_params);
215662306a36Sopenharmony_ci
215762306a36Sopenharmony_ci	/* set WL Tx response = Hi-Pri */
215862306a36Sopenharmony_ci	chip->ops->btc_set_wl_pri(rtwdev, BTC_PRI_MASK_TX_RESP, true);
215962306a36Sopenharmony_ci	chip->ops->btc_set_wl_pri(rtwdev, BTC_PRI_MASK_BEACON, true);
216062306a36Sopenharmony_ci
216162306a36Sopenharmony_ci	/* set rf gnt debug off */
216262306a36Sopenharmony_ci	rtw89_write_rf(rtwdev, RF_PATH_A, RR_WLSEL, RFREG_MASK, 0x0);
216362306a36Sopenharmony_ci	rtw89_write_rf(rtwdev, RF_PATH_B, RR_WLSEL, RFREG_MASK, 0x0);
216462306a36Sopenharmony_ci
216562306a36Sopenharmony_ci	/* set WL Tx thru in TRX mask table if GNT_WL = 0 && BT_S1 = ss group */
216662306a36Sopenharmony_ci	if (module->ant.type == BTC_ANT_SHARED) {
216762306a36Sopenharmony_ci		rtw8852b_set_trx_mask(rtwdev, RF_PATH_A, BTC_BT_SS_GROUP, 0x5ff);
216862306a36Sopenharmony_ci		rtw8852b_set_trx_mask(rtwdev, RF_PATH_B, BTC_BT_SS_GROUP, 0x5ff);
216962306a36Sopenharmony_ci		/* set path-A(S0) Tx/Rx no-mask if GNT_WL=0 && BT_S1=tx group */
217062306a36Sopenharmony_ci		rtw8852b_set_trx_mask(rtwdev, RF_PATH_A, BTC_BT_TX_GROUP, 0x5ff);
217162306a36Sopenharmony_ci		rtw8852b_set_trx_mask(rtwdev, RF_PATH_B, BTC_BT_TX_GROUP, 0x55f);
217262306a36Sopenharmony_ci	} else { /* set WL Tx stb if GNT_WL = 0 && BT_S1 = ss group for 3-ant */
217362306a36Sopenharmony_ci		rtw8852b_set_trx_mask(rtwdev, RF_PATH_A, BTC_BT_SS_GROUP, 0x5df);
217462306a36Sopenharmony_ci		rtw8852b_set_trx_mask(rtwdev, RF_PATH_B, BTC_BT_SS_GROUP, 0x5df);
217562306a36Sopenharmony_ci		rtw8852b_set_trx_mask(rtwdev, RF_PATH_A, BTC_BT_TX_GROUP, 0x5ff);
217662306a36Sopenharmony_ci		rtw8852b_set_trx_mask(rtwdev, RF_PATH_B, BTC_BT_TX_GROUP, 0x5ff);
217762306a36Sopenharmony_ci	}
217862306a36Sopenharmony_ci
217962306a36Sopenharmony_ci	/* set PTA break table */
218062306a36Sopenharmony_ci	rtw89_write32(rtwdev, R_BTC_BREAK_TABLE, BTC_BREAK_PARAM);
218162306a36Sopenharmony_ci
218262306a36Sopenharmony_ci	 /* enable BT counter 0xda40[16,2] = 2b'11 */
218362306a36Sopenharmony_ci	rtw89_write32_set(rtwdev, R_AX_CSR_MODE, B_AX_BT_CNT_RST | B_AX_STATIS_BT_EN);
218462306a36Sopenharmony_ci	btc->cx.wl.status.map.init_ok = true;
218562306a36Sopenharmony_ci}
218662306a36Sopenharmony_ci
218762306a36Sopenharmony_cistatic
218862306a36Sopenharmony_civoid rtw8852b_btc_set_wl_pri(struct rtw89_dev *rtwdev, u8 map, bool state)
218962306a36Sopenharmony_ci{
219062306a36Sopenharmony_ci	u32 bitmap;
219162306a36Sopenharmony_ci	u32 reg;
219262306a36Sopenharmony_ci
219362306a36Sopenharmony_ci	switch (map) {
219462306a36Sopenharmony_ci	case BTC_PRI_MASK_TX_RESP:
219562306a36Sopenharmony_ci		reg = R_BTC_BT_COEX_MSK_TABLE;
219662306a36Sopenharmony_ci		bitmap = B_BTC_PRI_MASK_TX_RESP_V1;
219762306a36Sopenharmony_ci		break;
219862306a36Sopenharmony_ci	case BTC_PRI_MASK_BEACON:
219962306a36Sopenharmony_ci		reg = R_AX_WL_PRI_MSK;
220062306a36Sopenharmony_ci		bitmap = B_AX_PTA_WL_PRI_MASK_BCNQ;
220162306a36Sopenharmony_ci		break;
220262306a36Sopenharmony_ci	case BTC_PRI_MASK_RX_CCK:
220362306a36Sopenharmony_ci		reg = R_BTC_BT_COEX_MSK_TABLE;
220462306a36Sopenharmony_ci		bitmap = B_BTC_PRI_MASK_RXCCK_V1;
220562306a36Sopenharmony_ci		break;
220662306a36Sopenharmony_ci	default:
220762306a36Sopenharmony_ci		return;
220862306a36Sopenharmony_ci	}
220962306a36Sopenharmony_ci
221062306a36Sopenharmony_ci	if (state)
221162306a36Sopenharmony_ci		rtw89_write32_set(rtwdev, reg, bitmap);
221262306a36Sopenharmony_ci	else
221362306a36Sopenharmony_ci		rtw89_write32_clr(rtwdev, reg, bitmap);
221462306a36Sopenharmony_ci}
221562306a36Sopenharmony_ci
221662306a36Sopenharmony_ciunion rtw8852b_btc_wl_txpwr_ctrl {
221762306a36Sopenharmony_ci	u32 txpwr_val;
221862306a36Sopenharmony_ci	struct {
221962306a36Sopenharmony_ci		union {
222062306a36Sopenharmony_ci			u16 ctrl_all_time;
222162306a36Sopenharmony_ci			struct {
222262306a36Sopenharmony_ci				s16 data:9;
222362306a36Sopenharmony_ci				u16 rsvd:6;
222462306a36Sopenharmony_ci				u16 flag:1;
222562306a36Sopenharmony_ci			} all_time;
222662306a36Sopenharmony_ci		};
222762306a36Sopenharmony_ci		union {
222862306a36Sopenharmony_ci			u16 ctrl_gnt_bt;
222962306a36Sopenharmony_ci			struct {
223062306a36Sopenharmony_ci				s16 data:9;
223162306a36Sopenharmony_ci				u16 rsvd:7;
223262306a36Sopenharmony_ci			} gnt_bt;
223362306a36Sopenharmony_ci		};
223462306a36Sopenharmony_ci	};
223562306a36Sopenharmony_ci} __packed;
223662306a36Sopenharmony_ci
223762306a36Sopenharmony_cistatic void
223862306a36Sopenharmony_cirtw8852b_btc_set_wl_txpwr_ctrl(struct rtw89_dev *rtwdev, u32 txpwr_val)
223962306a36Sopenharmony_ci{
224062306a36Sopenharmony_ci	union rtw8852b_btc_wl_txpwr_ctrl arg = { .txpwr_val = txpwr_val };
224162306a36Sopenharmony_ci	s32 val;
224262306a36Sopenharmony_ci
224362306a36Sopenharmony_ci#define __write_ctrl(_reg, _msk, _val, _en, _cond)		\
224462306a36Sopenharmony_cido {								\
224562306a36Sopenharmony_ci	u32 _wrt = FIELD_PREP(_msk, _val);			\
224662306a36Sopenharmony_ci	BUILD_BUG_ON(!!(_msk & _en));				\
224762306a36Sopenharmony_ci	if (_cond)						\
224862306a36Sopenharmony_ci		_wrt |= _en;					\
224962306a36Sopenharmony_ci	else							\
225062306a36Sopenharmony_ci		_wrt &= ~_en;					\
225162306a36Sopenharmony_ci	rtw89_mac_txpwr_write32_mask(rtwdev, RTW89_PHY_0, _reg,	\
225262306a36Sopenharmony_ci				     _msk | _en, _wrt);		\
225362306a36Sopenharmony_ci} while (0)
225462306a36Sopenharmony_ci
225562306a36Sopenharmony_ci	switch (arg.ctrl_all_time) {
225662306a36Sopenharmony_ci	case 0xffff:
225762306a36Sopenharmony_ci		val = 0;
225862306a36Sopenharmony_ci		break;
225962306a36Sopenharmony_ci	default:
226062306a36Sopenharmony_ci		val = arg.all_time.data;
226162306a36Sopenharmony_ci		break;
226262306a36Sopenharmony_ci	}
226362306a36Sopenharmony_ci
226462306a36Sopenharmony_ci	__write_ctrl(R_AX_PWR_RATE_CTRL, B_AX_FORCE_PWR_BY_RATE_VALUE_MASK,
226562306a36Sopenharmony_ci		     val, B_AX_FORCE_PWR_BY_RATE_EN,
226662306a36Sopenharmony_ci		     arg.ctrl_all_time != 0xffff);
226762306a36Sopenharmony_ci
226862306a36Sopenharmony_ci	switch (arg.ctrl_gnt_bt) {
226962306a36Sopenharmony_ci	case 0xffff:
227062306a36Sopenharmony_ci		val = 0;
227162306a36Sopenharmony_ci		break;
227262306a36Sopenharmony_ci	default:
227362306a36Sopenharmony_ci		val = arg.gnt_bt.data;
227462306a36Sopenharmony_ci		break;
227562306a36Sopenharmony_ci	}
227662306a36Sopenharmony_ci
227762306a36Sopenharmony_ci	__write_ctrl(R_AX_PWR_COEXT_CTRL, B_AX_TXAGC_BT_MASK, val,
227862306a36Sopenharmony_ci		     B_AX_TXAGC_BT_EN, arg.ctrl_gnt_bt != 0xffff);
227962306a36Sopenharmony_ci
228062306a36Sopenharmony_ci#undef __write_ctrl
228162306a36Sopenharmony_ci}
228262306a36Sopenharmony_ci
228362306a36Sopenharmony_cistatic
228462306a36Sopenharmony_cis8 rtw8852b_btc_get_bt_rssi(struct rtw89_dev *rtwdev, s8 val)
228562306a36Sopenharmony_ci{
228662306a36Sopenharmony_ci	/* +6 for compensate offset */
228762306a36Sopenharmony_ci	return clamp_t(s8, val + 6, -100, 0) + 100;
228862306a36Sopenharmony_ci}
228962306a36Sopenharmony_ci
229062306a36Sopenharmony_cistatic
229162306a36Sopenharmony_civoid rtw8852b_btc_update_bt_cnt(struct rtw89_dev *rtwdev)
229262306a36Sopenharmony_ci{
229362306a36Sopenharmony_ci	/* Feature move to firmware */
229462306a36Sopenharmony_ci}
229562306a36Sopenharmony_ci
229662306a36Sopenharmony_cistatic void rtw8852b_btc_wl_s1_standby(struct rtw89_dev *rtwdev, bool state)
229762306a36Sopenharmony_ci{
229862306a36Sopenharmony_ci	rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWE, RFREG_MASK, 0x80000);
229962306a36Sopenharmony_ci	rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x1);
230062306a36Sopenharmony_ci	rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD1, RFREG_MASK, 0x31);
230162306a36Sopenharmony_ci
230262306a36Sopenharmony_ci	/* set WL standby = Rx for GNT_BT_Tx = 1->0 settle issue */
230362306a36Sopenharmony_ci	if (state)
230462306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x179);
230562306a36Sopenharmony_ci	else
230662306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x20);
230762306a36Sopenharmony_ci
230862306a36Sopenharmony_ci	rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWE, RFREG_MASK, 0x0);
230962306a36Sopenharmony_ci}
231062306a36Sopenharmony_ci
231162306a36Sopenharmony_cistatic void rtw8852b_btc_set_wl_lna2(struct rtw89_dev *rtwdev, u8 level)
231262306a36Sopenharmony_ci{
231362306a36Sopenharmony_ci	switch (level) {
231462306a36Sopenharmony_ci	case 0: /* default */
231562306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWE, RFREG_MASK, 0x1000);
231662306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x0);
231762306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x15);
231862306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x1);
231962306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x17);
232062306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x2);
232162306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x15);
232262306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x3);
232362306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x17);
232462306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWE, RFREG_MASK, 0x0);
232562306a36Sopenharmony_ci		break;
232662306a36Sopenharmony_ci	case 1: /* Fix LNA2=5  */
232762306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWE, RFREG_MASK, 0x1000);
232862306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x0);
232962306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x15);
233062306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x1);
233162306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x5);
233262306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x2);
233362306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x15);
233462306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x3);
233562306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD0, RFREG_MASK, 0x5);
233662306a36Sopenharmony_ci		rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWE, RFREG_MASK, 0x0);
233762306a36Sopenharmony_ci		break;
233862306a36Sopenharmony_ci	}
233962306a36Sopenharmony_ci}
234062306a36Sopenharmony_ci
234162306a36Sopenharmony_cistatic void rtw8852b_btc_set_wl_rx_gain(struct rtw89_dev *rtwdev, u32 level)
234262306a36Sopenharmony_ci{
234362306a36Sopenharmony_ci	struct rtw89_btc *btc = &rtwdev->btc;
234462306a36Sopenharmony_ci
234562306a36Sopenharmony_ci	switch (level) {
234662306a36Sopenharmony_ci	case 0: /* original */
234762306a36Sopenharmony_ci	default:
234862306a36Sopenharmony_ci		rtw8852b_bb_ctrl_btc_preagc(rtwdev, false);
234962306a36Sopenharmony_ci		btc->dm.wl_lna2 = 0;
235062306a36Sopenharmony_ci		break;
235162306a36Sopenharmony_ci	case 1: /* for FDD free-run */
235262306a36Sopenharmony_ci		rtw8852b_bb_ctrl_btc_preagc(rtwdev, true);
235362306a36Sopenharmony_ci		btc->dm.wl_lna2 = 0;
235462306a36Sopenharmony_ci		break;
235562306a36Sopenharmony_ci	case 2: /* for BTG Co-Rx*/
235662306a36Sopenharmony_ci		rtw8852b_bb_ctrl_btc_preagc(rtwdev, false);
235762306a36Sopenharmony_ci		btc->dm.wl_lna2 = 1;
235862306a36Sopenharmony_ci		break;
235962306a36Sopenharmony_ci	}
236062306a36Sopenharmony_ci
236162306a36Sopenharmony_ci	rtw8852b_btc_set_wl_lna2(rtwdev, btc->dm.wl_lna2);
236262306a36Sopenharmony_ci}
236362306a36Sopenharmony_ci
236462306a36Sopenharmony_cistatic void rtw8852b_fill_freq_with_ppdu(struct rtw89_dev *rtwdev,
236562306a36Sopenharmony_ci					 struct rtw89_rx_phy_ppdu *phy_ppdu,
236662306a36Sopenharmony_ci					 struct ieee80211_rx_status *status)
236762306a36Sopenharmony_ci{
236862306a36Sopenharmony_ci	u16 chan = phy_ppdu->chan_idx;
236962306a36Sopenharmony_ci	enum nl80211_band band;
237062306a36Sopenharmony_ci	u8 ch;
237162306a36Sopenharmony_ci
237262306a36Sopenharmony_ci	if (chan == 0)
237362306a36Sopenharmony_ci		return;
237462306a36Sopenharmony_ci
237562306a36Sopenharmony_ci	rtw89_decode_chan_idx(rtwdev, chan, &ch, &band);
237662306a36Sopenharmony_ci	status->freq = ieee80211_channel_to_frequency(ch, band);
237762306a36Sopenharmony_ci	status->band = band;
237862306a36Sopenharmony_ci}
237962306a36Sopenharmony_ci
238062306a36Sopenharmony_cistatic void rtw8852b_query_ppdu(struct rtw89_dev *rtwdev,
238162306a36Sopenharmony_ci				struct rtw89_rx_phy_ppdu *phy_ppdu,
238262306a36Sopenharmony_ci				struct ieee80211_rx_status *status)
238362306a36Sopenharmony_ci{
238462306a36Sopenharmony_ci	u8 path;
238562306a36Sopenharmony_ci	u8 *rx_power = phy_ppdu->rssi;
238662306a36Sopenharmony_ci
238762306a36Sopenharmony_ci	status->signal = RTW89_RSSI_RAW_TO_DBM(max(rx_power[RF_PATH_A], rx_power[RF_PATH_B]));
238862306a36Sopenharmony_ci	for (path = 0; path < rtwdev->chip->rf_path_num; path++) {
238962306a36Sopenharmony_ci		status->chains |= BIT(path);
239062306a36Sopenharmony_ci		status->chain_signal[path] = RTW89_RSSI_RAW_TO_DBM(rx_power[path]);
239162306a36Sopenharmony_ci	}
239262306a36Sopenharmony_ci	if (phy_ppdu->valid)
239362306a36Sopenharmony_ci		rtw8852b_fill_freq_with_ppdu(rtwdev, phy_ppdu, status);
239462306a36Sopenharmony_ci}
239562306a36Sopenharmony_ci
239662306a36Sopenharmony_cistatic int rtw8852b_mac_enable_bb_rf(struct rtw89_dev *rtwdev)
239762306a36Sopenharmony_ci{
239862306a36Sopenharmony_ci	int ret;
239962306a36Sopenharmony_ci
240062306a36Sopenharmony_ci	rtw89_write8_set(rtwdev, R_AX_SYS_FUNC_EN,
240162306a36Sopenharmony_ci			 B_AX_FEN_BBRSTB | B_AX_FEN_BB_GLB_RSTN);
240262306a36Sopenharmony_ci	rtw89_write32_mask(rtwdev, R_AX_SPS_DIG_ON_CTRL0, B_AX_REG_ZCDC_H_MASK, 0x1);
240362306a36Sopenharmony_ci	rtw89_write32_set(rtwdev, R_AX_WLRF_CTRL, B_AX_AFC_AFEDIG);
240462306a36Sopenharmony_ci	rtw89_write32_clr(rtwdev, R_AX_WLRF_CTRL, B_AX_AFC_AFEDIG);
240562306a36Sopenharmony_ci	rtw89_write32_set(rtwdev, R_AX_WLRF_CTRL, B_AX_AFC_AFEDIG);
240662306a36Sopenharmony_ci
240762306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_WL_RFC_S0, 0xC7,
240862306a36Sopenharmony_ci				      FULL_BIT_MASK);
240962306a36Sopenharmony_ci	if (ret)
241062306a36Sopenharmony_ci		return ret;
241162306a36Sopenharmony_ci
241262306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_WL_RFC_S1, 0xC7,
241362306a36Sopenharmony_ci				      FULL_BIT_MASK);
241462306a36Sopenharmony_ci	if (ret)
241562306a36Sopenharmony_ci		return ret;
241662306a36Sopenharmony_ci
241762306a36Sopenharmony_ci	rtw89_write8(rtwdev, R_AX_PHYREG_SET, PHYREG_SET_XYN_CYCLE);
241862306a36Sopenharmony_ci
241962306a36Sopenharmony_ci	return 0;
242062306a36Sopenharmony_ci}
242162306a36Sopenharmony_ci
242262306a36Sopenharmony_cistatic int rtw8852b_mac_disable_bb_rf(struct rtw89_dev *rtwdev)
242362306a36Sopenharmony_ci{
242462306a36Sopenharmony_ci	u8 wl_rfc_s0;
242562306a36Sopenharmony_ci	u8 wl_rfc_s1;
242662306a36Sopenharmony_ci	int ret;
242762306a36Sopenharmony_ci
242862306a36Sopenharmony_ci	rtw89_write8_clr(rtwdev, R_AX_SYS_FUNC_EN,
242962306a36Sopenharmony_ci			 B_AX_FEN_BBRSTB | B_AX_FEN_BB_GLB_RSTN);
243062306a36Sopenharmony_ci
243162306a36Sopenharmony_ci	ret = rtw89_mac_read_xtal_si(rtwdev, XTAL_SI_WL_RFC_S0, &wl_rfc_s0);
243262306a36Sopenharmony_ci	if (ret)
243362306a36Sopenharmony_ci		return ret;
243462306a36Sopenharmony_ci	wl_rfc_s0 &= ~XTAL_SI_RF00S_EN;
243562306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_WL_RFC_S0, wl_rfc_s0,
243662306a36Sopenharmony_ci				      FULL_BIT_MASK);
243762306a36Sopenharmony_ci	if (ret)
243862306a36Sopenharmony_ci		return ret;
243962306a36Sopenharmony_ci
244062306a36Sopenharmony_ci	ret = rtw89_mac_read_xtal_si(rtwdev, XTAL_SI_WL_RFC_S1, &wl_rfc_s1);
244162306a36Sopenharmony_ci	if (ret)
244262306a36Sopenharmony_ci		return ret;
244362306a36Sopenharmony_ci	wl_rfc_s1 &= ~XTAL_SI_RF10S_EN;
244462306a36Sopenharmony_ci	ret = rtw89_mac_write_xtal_si(rtwdev, XTAL_SI_WL_RFC_S1, wl_rfc_s1,
244562306a36Sopenharmony_ci				      FULL_BIT_MASK);
244662306a36Sopenharmony_ci	return ret;
244762306a36Sopenharmony_ci}
244862306a36Sopenharmony_ci
244962306a36Sopenharmony_cistatic const struct rtw89_chip_ops rtw8852b_chip_ops = {
245062306a36Sopenharmony_ci	.enable_bb_rf		= rtw8852b_mac_enable_bb_rf,
245162306a36Sopenharmony_ci	.disable_bb_rf		= rtw8852b_mac_disable_bb_rf,
245262306a36Sopenharmony_ci	.bb_reset		= rtw8852b_bb_reset,
245362306a36Sopenharmony_ci	.bb_sethw		= rtw8852b_bb_sethw,
245462306a36Sopenharmony_ci	.read_rf		= rtw89_phy_read_rf_v1,
245562306a36Sopenharmony_ci	.write_rf		= rtw89_phy_write_rf_v1,
245662306a36Sopenharmony_ci	.set_channel		= rtw8852b_set_channel,
245762306a36Sopenharmony_ci	.set_channel_help	= rtw8852b_set_channel_help,
245862306a36Sopenharmony_ci	.read_efuse		= rtw8852b_read_efuse,
245962306a36Sopenharmony_ci	.read_phycap		= rtw8852b_read_phycap,
246062306a36Sopenharmony_ci	.fem_setup		= NULL,
246162306a36Sopenharmony_ci	.rfe_gpio		= NULL,
246262306a36Sopenharmony_ci	.rfk_init		= rtw8852b_rfk_init,
246362306a36Sopenharmony_ci	.rfk_channel		= rtw8852b_rfk_channel,
246462306a36Sopenharmony_ci	.rfk_band_changed	= rtw8852b_rfk_band_changed,
246562306a36Sopenharmony_ci	.rfk_scan		= rtw8852b_rfk_scan,
246662306a36Sopenharmony_ci	.rfk_track		= rtw8852b_rfk_track,
246762306a36Sopenharmony_ci	.power_trim		= rtw8852b_power_trim,
246862306a36Sopenharmony_ci	.set_txpwr		= rtw8852b_set_txpwr,
246962306a36Sopenharmony_ci	.set_txpwr_ctrl		= rtw8852b_set_txpwr_ctrl,
247062306a36Sopenharmony_ci	.init_txpwr_unit	= rtw8852b_init_txpwr_unit,
247162306a36Sopenharmony_ci	.get_thermal		= rtw8852b_get_thermal,
247262306a36Sopenharmony_ci	.ctrl_btg		= rtw8852b_ctrl_btg,
247362306a36Sopenharmony_ci	.query_ppdu		= rtw8852b_query_ppdu,
247462306a36Sopenharmony_ci	.bb_ctrl_btc_preagc	= rtw8852b_bb_ctrl_btc_preagc,
247562306a36Sopenharmony_ci	.cfg_txrx_path		= rtw8852b_bb_cfg_txrx_path,
247662306a36Sopenharmony_ci	.set_txpwr_ul_tb_offset	= rtw8852b_set_txpwr_ul_tb_offset,
247762306a36Sopenharmony_ci	.pwr_on_func		= rtw8852b_pwr_on_func,
247862306a36Sopenharmony_ci	.pwr_off_func		= rtw8852b_pwr_off_func,
247962306a36Sopenharmony_ci	.query_rxdesc		= rtw89_core_query_rxdesc,
248062306a36Sopenharmony_ci	.fill_txdesc		= rtw89_core_fill_txdesc,
248162306a36Sopenharmony_ci	.fill_txdesc_fwcmd	= rtw89_core_fill_txdesc,
248262306a36Sopenharmony_ci	.cfg_ctrl_path		= rtw89_mac_cfg_ctrl_path,
248362306a36Sopenharmony_ci	.mac_cfg_gnt		= rtw89_mac_cfg_gnt,
248462306a36Sopenharmony_ci	.stop_sch_tx		= rtw89_mac_stop_sch_tx,
248562306a36Sopenharmony_ci	.resume_sch_tx		= rtw89_mac_resume_sch_tx,
248662306a36Sopenharmony_ci	.h2c_dctl_sec_cam	= NULL,
248762306a36Sopenharmony_ci
248862306a36Sopenharmony_ci	.btc_set_rfe		= rtw8852b_btc_set_rfe,
248962306a36Sopenharmony_ci	.btc_init_cfg		= rtw8852b_btc_init_cfg,
249062306a36Sopenharmony_ci	.btc_set_wl_pri		= rtw8852b_btc_set_wl_pri,
249162306a36Sopenharmony_ci	.btc_set_wl_txpwr_ctrl	= rtw8852b_btc_set_wl_txpwr_ctrl,
249262306a36Sopenharmony_ci	.btc_get_bt_rssi	= rtw8852b_btc_get_bt_rssi,
249362306a36Sopenharmony_ci	.btc_update_bt_cnt	= rtw8852b_btc_update_bt_cnt,
249462306a36Sopenharmony_ci	.btc_wl_s1_standby	= rtw8852b_btc_wl_s1_standby,
249562306a36Sopenharmony_ci	.btc_set_wl_rx_gain	= rtw8852b_btc_set_wl_rx_gain,
249662306a36Sopenharmony_ci	.btc_set_policy		= rtw89_btc_set_policy_v1,
249762306a36Sopenharmony_ci};
249862306a36Sopenharmony_ci
249962306a36Sopenharmony_ci#ifdef CONFIG_PM
250062306a36Sopenharmony_cistatic const struct wiphy_wowlan_support rtw_wowlan_stub_8852b = {
250162306a36Sopenharmony_ci	.flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT,
250262306a36Sopenharmony_ci	.n_patterns = RTW89_MAX_PATTERN_NUM,
250362306a36Sopenharmony_ci	.pattern_max_len = RTW89_MAX_PATTERN_SIZE,
250462306a36Sopenharmony_ci	.pattern_min_len = 1,
250562306a36Sopenharmony_ci};
250662306a36Sopenharmony_ci#endif
250762306a36Sopenharmony_ci
250862306a36Sopenharmony_ciconst struct rtw89_chip_info rtw8852b_chip_info = {
250962306a36Sopenharmony_ci	.chip_id		= RTL8852B,
251062306a36Sopenharmony_ci	.chip_gen		= RTW89_CHIP_AX,
251162306a36Sopenharmony_ci	.ops			= &rtw8852b_chip_ops,
251262306a36Sopenharmony_ci	.mac_def		= &rtw89_mac_gen_ax,
251362306a36Sopenharmony_ci	.phy_def		= &rtw89_phy_gen_ax,
251462306a36Sopenharmony_ci	.fw_basename		= RTW8852B_FW_BASENAME,
251562306a36Sopenharmony_ci	.fw_format_max		= RTW8852B_FW_FORMAT_MAX,
251662306a36Sopenharmony_ci	.try_ce_fw		= true,
251762306a36Sopenharmony_ci	.needed_fw_elms		= 0,
251862306a36Sopenharmony_ci	.fifo_size		= 196608,
251962306a36Sopenharmony_ci	.small_fifo_size	= true,
252062306a36Sopenharmony_ci	.dle_scc_rsvd_size	= 98304,
252162306a36Sopenharmony_ci	.max_amsdu_limit	= 3500,
252262306a36Sopenharmony_ci	.dis_2g_40m_ul_ofdma	= true,
252362306a36Sopenharmony_ci	.rsvd_ple_ofst		= 0x2f800,
252462306a36Sopenharmony_ci	.hfc_param_ini		= rtw8852b_hfc_param_ini_pcie,
252562306a36Sopenharmony_ci	.dle_mem		= rtw8852b_dle_mem_pcie,
252662306a36Sopenharmony_ci	.wde_qempty_acq_num	= 4,
252762306a36Sopenharmony_ci	.wde_qempty_mgq_sel	= 4,
252862306a36Sopenharmony_ci	.rf_base_addr		= {0xe000, 0xf000},
252962306a36Sopenharmony_ci	.pwr_on_seq		= NULL,
253062306a36Sopenharmony_ci	.pwr_off_seq		= NULL,
253162306a36Sopenharmony_ci	.bb_table		= &rtw89_8852b_phy_bb_table,
253262306a36Sopenharmony_ci	.bb_gain_table		= &rtw89_8852b_phy_bb_gain_table,
253362306a36Sopenharmony_ci	.rf_table		= {&rtw89_8852b_phy_radioa_table,
253462306a36Sopenharmony_ci				   &rtw89_8852b_phy_radiob_table,},
253562306a36Sopenharmony_ci	.nctl_table		= &rtw89_8852b_phy_nctl_table,
253662306a36Sopenharmony_ci	.nctl_post_table	= NULL,
253762306a36Sopenharmony_ci	.byr_table		= &rtw89_8852b_byr_table,
253862306a36Sopenharmony_ci	.dflt_parms		= &rtw89_8852b_dflt_parms,
253962306a36Sopenharmony_ci	.rfe_parms_conf		= NULL,
254062306a36Sopenharmony_ci	.txpwr_factor_rf	= 2,
254162306a36Sopenharmony_ci	.txpwr_factor_mac	= 1,
254262306a36Sopenharmony_ci	.dig_table		= NULL,
254362306a36Sopenharmony_ci	.dig_regs		= &rtw8852b_dig_regs,
254462306a36Sopenharmony_ci	.tssi_dbw_table		= NULL,
254562306a36Sopenharmony_ci	.support_chanctx_num	= 0,
254662306a36Sopenharmony_ci	.support_bands		= BIT(NL80211_BAND_2GHZ) |
254762306a36Sopenharmony_ci				  BIT(NL80211_BAND_5GHZ),
254862306a36Sopenharmony_ci	.support_bw160		= false,
254962306a36Sopenharmony_ci	.support_unii4		= true,
255062306a36Sopenharmony_ci	.support_ul_tb_ctrl	= true,
255162306a36Sopenharmony_ci	.hw_sec_hdr		= false,
255262306a36Sopenharmony_ci	.rf_path_num		= 2,
255362306a36Sopenharmony_ci	.tx_nss			= 2,
255462306a36Sopenharmony_ci	.rx_nss			= 2,
255562306a36Sopenharmony_ci	.acam_num		= 128,
255662306a36Sopenharmony_ci	.bcam_num		= 10,
255762306a36Sopenharmony_ci	.scam_num		= 128,
255862306a36Sopenharmony_ci	.bacam_num		= 2,
255962306a36Sopenharmony_ci	.bacam_dynamic_num	= 4,
256062306a36Sopenharmony_ci	.bacam_ver		= RTW89_BACAM_V0,
256162306a36Sopenharmony_ci	.sec_ctrl_efuse_size	= 4,
256262306a36Sopenharmony_ci	.physical_efuse_size	= 1216,
256362306a36Sopenharmony_ci	.logical_efuse_size	= 2048,
256462306a36Sopenharmony_ci	.limit_efuse_size	= 1280,
256562306a36Sopenharmony_ci	.dav_phy_efuse_size	= 96,
256662306a36Sopenharmony_ci	.dav_log_efuse_size	= 16,
256762306a36Sopenharmony_ci	.phycap_addr		= 0x580,
256862306a36Sopenharmony_ci	.phycap_size		= 128,
256962306a36Sopenharmony_ci	.para_ver		= 0,
257062306a36Sopenharmony_ci	.wlcx_desired		= 0x05050000,
257162306a36Sopenharmony_ci	.btcx_desired		= 0x5,
257262306a36Sopenharmony_ci	.scbd			= 0x1,
257362306a36Sopenharmony_ci	.mailbox		= 0x1,
257462306a36Sopenharmony_ci
257562306a36Sopenharmony_ci	.afh_guard_ch		= 6,
257662306a36Sopenharmony_ci	.wl_rssi_thres		= rtw89_btc_8852b_wl_rssi_thres,
257762306a36Sopenharmony_ci	.bt_rssi_thres		= rtw89_btc_8852b_bt_rssi_thres,
257862306a36Sopenharmony_ci	.rssi_tol		= 2,
257962306a36Sopenharmony_ci	.mon_reg_num		= ARRAY_SIZE(rtw89_btc_8852b_mon_reg),
258062306a36Sopenharmony_ci	.mon_reg		= rtw89_btc_8852b_mon_reg,
258162306a36Sopenharmony_ci	.rf_para_ulink_num	= ARRAY_SIZE(rtw89_btc_8852b_rf_ul),
258262306a36Sopenharmony_ci	.rf_para_ulink		= rtw89_btc_8852b_rf_ul,
258362306a36Sopenharmony_ci	.rf_para_dlink_num	= ARRAY_SIZE(rtw89_btc_8852b_rf_dl),
258462306a36Sopenharmony_ci	.rf_para_dlink		= rtw89_btc_8852b_rf_dl,
258562306a36Sopenharmony_ci	.ps_mode_supported	= BIT(RTW89_PS_MODE_RFOFF) |
258662306a36Sopenharmony_ci				  BIT(RTW89_PS_MODE_CLK_GATED) |
258762306a36Sopenharmony_ci				  BIT(RTW89_PS_MODE_PWR_GATED),
258862306a36Sopenharmony_ci	.low_power_hci_modes	= 0,
258962306a36Sopenharmony_ci	.h2c_cctl_func_id	= H2C_FUNC_MAC_CCTLINFO_UD,
259062306a36Sopenharmony_ci	.hci_func_en_addr	= R_AX_HCI_FUNC_EN,
259162306a36Sopenharmony_ci	.h2c_desc_size		= sizeof(struct rtw89_txwd_body),
259262306a36Sopenharmony_ci	.txwd_body_size		= sizeof(struct rtw89_txwd_body),
259362306a36Sopenharmony_ci	.h2c_ctrl_reg		= R_AX_H2CREG_CTRL,
259462306a36Sopenharmony_ci	.h2c_counter_reg	= {R_AX_UDM1 + 1, B_AX_UDM1_HALMAC_H2C_DEQ_CNT_MASK >> 8},
259562306a36Sopenharmony_ci	.h2c_regs		= rtw8852b_h2c_regs,
259662306a36Sopenharmony_ci	.c2h_ctrl_reg		= R_AX_C2HREG_CTRL,
259762306a36Sopenharmony_ci	.c2h_counter_reg	= {R_AX_UDM1 + 1, B_AX_UDM1_HALMAC_C2H_ENQ_CNT_MASK >> 8},
259862306a36Sopenharmony_ci	.c2h_regs		= rtw8852b_c2h_regs,
259962306a36Sopenharmony_ci	.page_regs		= &rtw8852b_page_regs,
260062306a36Sopenharmony_ci	.cfo_src_fd		= true,
260162306a36Sopenharmony_ci	.cfo_hw_comp		= true,
260262306a36Sopenharmony_ci	.dcfo_comp		= &rtw8852b_dcfo_comp,
260362306a36Sopenharmony_ci	.dcfo_comp_sft		= 10,
260462306a36Sopenharmony_ci	.imr_info		= &rtw8852b_imr_info,
260562306a36Sopenharmony_ci	.rrsr_cfgs		= &rtw8852b_rrsr_cfgs,
260662306a36Sopenharmony_ci	.bss_clr_map_reg	= R_BSS_CLR_MAP_V1,
260762306a36Sopenharmony_ci	.dma_ch_mask		= BIT(RTW89_DMA_ACH4) | BIT(RTW89_DMA_ACH5) |
260862306a36Sopenharmony_ci				  BIT(RTW89_DMA_ACH6) | BIT(RTW89_DMA_ACH7) |
260962306a36Sopenharmony_ci				  BIT(RTW89_DMA_B1MG) | BIT(RTW89_DMA_B1HI),
261062306a36Sopenharmony_ci	.edcca_lvl_reg		= R_SEG0R_EDCCA_LVL_V1,
261162306a36Sopenharmony_ci#ifdef CONFIG_PM
261262306a36Sopenharmony_ci	.wowlan_stub		= &rtw_wowlan_stub_8852b,
261362306a36Sopenharmony_ci#endif
261462306a36Sopenharmony_ci	.xtal_info		= NULL,
261562306a36Sopenharmony_ci};
261662306a36Sopenharmony_ciEXPORT_SYMBOL(rtw8852b_chip_info);
261762306a36Sopenharmony_ci
261862306a36Sopenharmony_ciMODULE_FIRMWARE(RTW8852B_MODULE_FIRMWARE);
261962306a36Sopenharmony_ciMODULE_AUTHOR("Realtek Corporation");
262062306a36Sopenharmony_ciMODULE_DESCRIPTION("Realtek 802.11ax wireless 8852B driver");
262162306a36Sopenharmony_ciMODULE_LICENSE("Dual BSD/GPL");
2622