162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
262306a36Sopenharmony_ci/* Copyright(c) 2018-2019  Realtek Corporation
362306a36Sopenharmony_ci */
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#ifndef __RTW8822B_H__
662306a36Sopenharmony_ci#define __RTW8822B_H__
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#include <asm/byteorder.h>
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#define RCR_VHT_ACK		BIT(26)
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_cistruct rtw8822bu_efuse {
1362306a36Sopenharmony_ci	u8 res4[4];			/* 0xd0 */
1462306a36Sopenharmony_ci	u8 usb_optional_function;
1562306a36Sopenharmony_ci	u8 res5[0x1e];
1662306a36Sopenharmony_ci	u8 res6[2];
1762306a36Sopenharmony_ci	u8 serial[0x0b];		/* 0xf5 */
1862306a36Sopenharmony_ci	u8 vid;				/* 0x100 */
1962306a36Sopenharmony_ci	u8 res7;
2062306a36Sopenharmony_ci	u8 pid;
2162306a36Sopenharmony_ci	u8 res8[4];
2262306a36Sopenharmony_ci	u8 mac_addr[ETH_ALEN];		/* 0x107 */
2362306a36Sopenharmony_ci	u8 res9[2];
2462306a36Sopenharmony_ci	u8 vendor_name[0x07];
2562306a36Sopenharmony_ci	u8 res10[2];
2662306a36Sopenharmony_ci	u8 device_name[0x14];
2762306a36Sopenharmony_ci	u8 res11[0xcf];
2862306a36Sopenharmony_ci	u8 package_type;		/* 0x1fb */
2962306a36Sopenharmony_ci	u8 res12[0x4];
3062306a36Sopenharmony_ci};
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_cistruct rtw8822be_efuse {
3362306a36Sopenharmony_ci	u8 mac_addr[ETH_ALEN];		/* 0xd0 */
3462306a36Sopenharmony_ci	u8 vender_id[2];
3562306a36Sopenharmony_ci	u8 device_id[2];
3662306a36Sopenharmony_ci	u8 sub_vender_id[2];
3762306a36Sopenharmony_ci	u8 sub_device_id[2];
3862306a36Sopenharmony_ci	u8 pmc[2];
3962306a36Sopenharmony_ci	u8 exp_device_cap[2];
4062306a36Sopenharmony_ci	u8 msi_cap;
4162306a36Sopenharmony_ci	u8 ltr_cap;			/* 0xe3 */
4262306a36Sopenharmony_ci	u8 exp_link_control[2];
4362306a36Sopenharmony_ci	u8 link_cap[4];
4462306a36Sopenharmony_ci	u8 link_control[2];
4562306a36Sopenharmony_ci	u8 serial_number[8];
4662306a36Sopenharmony_ci	u8 res0:2;			/* 0xf4 */
4762306a36Sopenharmony_ci	u8 ltr_en:1;
4862306a36Sopenharmony_ci	u8 res1:2;
4962306a36Sopenharmony_ci	u8 obff:2;
5062306a36Sopenharmony_ci	u8 res2:3;
5162306a36Sopenharmony_ci	u8 obff_cap:2;
5262306a36Sopenharmony_ci	u8 res3:4;
5362306a36Sopenharmony_ci	u8 res4[3];
5462306a36Sopenharmony_ci	u8 class_code[3];
5562306a36Sopenharmony_ci	u8 pci_pm_L1_2_supp:1;
5662306a36Sopenharmony_ci	u8 pci_pm_L1_1_supp:1;
5762306a36Sopenharmony_ci	u8 aspm_pm_L1_2_supp:1;
5862306a36Sopenharmony_ci	u8 aspm_pm_L1_1_supp:1;
5962306a36Sopenharmony_ci	u8 L1_pm_substates_supp:1;
6062306a36Sopenharmony_ci	u8 res5:3;
6162306a36Sopenharmony_ci	u8 port_common_mode_restore_time;
6262306a36Sopenharmony_ci	u8 port_t_power_on_scale:2;
6362306a36Sopenharmony_ci	u8 res6:1;
6462306a36Sopenharmony_ci	u8 port_t_power_on_value:5;
6562306a36Sopenharmony_ci	u8 res7;
6662306a36Sopenharmony_ci};
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_cistruct rtw8822bs_efuse {
6962306a36Sopenharmony_ci	u8 res4[0x4a];			/* 0xd0 */
7062306a36Sopenharmony_ci	u8 mac_addr[ETH_ALEN];		/* 0x11a */
7162306a36Sopenharmony_ci} __packed;
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_cistruct rtw8822b_efuse {
7462306a36Sopenharmony_ci	__le16 rtl_id;
7562306a36Sopenharmony_ci	u8 res0[0x0e];
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci	/* power index for four RF paths */
7862306a36Sopenharmony_ci	struct rtw_txpwr_idx txpwr_idx_table[4];
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci	u8 channel_plan;		/* 0xb8 */
8162306a36Sopenharmony_ci	u8 xtal_k;
8262306a36Sopenharmony_ci	u8 thermal_meter;
8362306a36Sopenharmony_ci	u8 iqk_lck;
8462306a36Sopenharmony_ci	u8 pa_type;			/* 0xbc */
8562306a36Sopenharmony_ci	u8 lna_type_2g[2];		/* 0xbd */
8662306a36Sopenharmony_ci	u8 lna_type_5g[2];
8762306a36Sopenharmony_ci	u8 rf_board_option;
8862306a36Sopenharmony_ci	u8 rf_feature_option;
8962306a36Sopenharmony_ci	u8 rf_bt_setting;
9062306a36Sopenharmony_ci	u8 eeprom_version;
9162306a36Sopenharmony_ci	u8 eeprom_customer_id;
9262306a36Sopenharmony_ci	u8 tx_bb_swing_setting_2g;
9362306a36Sopenharmony_ci	u8 tx_bb_swing_setting_5g;
9462306a36Sopenharmony_ci	u8 tx_pwr_calibrate_rate;
9562306a36Sopenharmony_ci	u8 rf_antenna_option;		/* 0xc9 */
9662306a36Sopenharmony_ci	u8 rfe_option;
9762306a36Sopenharmony_ci	u8 country_code[2];
9862306a36Sopenharmony_ci	u8 res[3];
9962306a36Sopenharmony_ci	union {
10062306a36Sopenharmony_ci		struct rtw8822be_efuse e;
10162306a36Sopenharmony_ci		struct rtw8822bu_efuse u;
10262306a36Sopenharmony_ci		struct rtw8822bs_efuse s;
10362306a36Sopenharmony_ci	};
10462306a36Sopenharmony_ci};
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_cistatic inline void
10762306a36Sopenharmony_ci_rtw_write32s_mask(struct rtw_dev *rtwdev, u32 addr, u32 mask, u32 data)
10862306a36Sopenharmony_ci{
10962306a36Sopenharmony_ci	/* 0xC00-0xCFF and 0xE00-0xEFF have the same layout */
11062306a36Sopenharmony_ci	rtw_write32_mask(rtwdev, addr, mask, data);
11162306a36Sopenharmony_ci	rtw_write32_mask(rtwdev, addr + 0x200, mask, data);
11262306a36Sopenharmony_ci}
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci#define rtw_write32s_mask(rtwdev, addr, mask, data)			       \
11562306a36Sopenharmony_ci	do {								       \
11662306a36Sopenharmony_ci		BUILD_BUG_ON((addr) < 0xC00 || (addr) >= 0xD00);	       \
11762306a36Sopenharmony_ci									       \
11862306a36Sopenharmony_ci		_rtw_write32s_mask(rtwdev, addr, mask, data);		       \
11962306a36Sopenharmony_ci	} while (0)
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci/* phy status page0 */
12262306a36Sopenharmony_ci#define GET_PHY_STAT_P0_PWDB(phy_stat)                                         \
12362306a36Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x00), GENMASK(15, 8))
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci/* phy status page1 */
12662306a36Sopenharmony_ci#define GET_PHY_STAT_P1_PWDB_A(phy_stat)                                       \
12762306a36Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x00), GENMASK(15, 8))
12862306a36Sopenharmony_ci#define GET_PHY_STAT_P1_PWDB_B(phy_stat)                                       \
12962306a36Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x00), GENMASK(23, 16))
13062306a36Sopenharmony_ci#define GET_PHY_STAT_P1_RF_MODE(phy_stat)                                      \
13162306a36Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x03), GENMASK(29, 28))
13262306a36Sopenharmony_ci#define GET_PHY_STAT_P1_L_RXSC(phy_stat)                                       \
13362306a36Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x01), GENMASK(11, 8))
13462306a36Sopenharmony_ci#define GET_PHY_STAT_P1_HT_RXSC(phy_stat)                                      \
13562306a36Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x01), GENMASK(15, 12))
13662306a36Sopenharmony_ci#define GET_PHY_STAT_P1_RXEVM_A(phy_stat)                                      \
13762306a36Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x04), GENMASK(7, 0))
13862306a36Sopenharmony_ci#define GET_PHY_STAT_P1_RXEVM_B(phy_stat)                                      \
13962306a36Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x04), GENMASK(15, 8))
14062306a36Sopenharmony_ci#define GET_PHY_STAT_P1_CFO_TAIL_A(phy_stat)                                 \
14162306a36Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x05), GENMASK(7, 0))
14262306a36Sopenharmony_ci#define GET_PHY_STAT_P1_CFO_TAIL_B(phy_stat)                                 \
14362306a36Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x05), GENMASK(15, 8))
14462306a36Sopenharmony_ci#define GET_PHY_STAT_P1_RXSNR_A(phy_stat)                                      \
14562306a36Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x06), GENMASK(7, 0))
14662306a36Sopenharmony_ci#define GET_PHY_STAT_P1_RXSNR_B(phy_stat)                                      \
14762306a36Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x06), GENMASK(15, 8))
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci#define RTW8822B_EDCCA_MAX	0x7f
15062306a36Sopenharmony_ci#define RTW8822B_EDCCA_SRC_DEF	1
15162306a36Sopenharmony_ci#define REG_HTSTFWT	0x800
15262306a36Sopenharmony_ci#define REG_RXPSEL	0x808
15362306a36Sopenharmony_ci#define BIT_RX_PSEL_RST		(BIT(28) | BIT(29))
15462306a36Sopenharmony_ci#define REG_TXPSEL	0x80c
15562306a36Sopenharmony_ci#define REG_RXCCAMSK	0x814
15662306a36Sopenharmony_ci#define REG_CCASEL	0x82c
15762306a36Sopenharmony_ci#define REG_PDMFTH	0x830
15862306a36Sopenharmony_ci#define REG_CCA2ND	0x838
15962306a36Sopenharmony_ci#define REG_L1WT	0x83c
16062306a36Sopenharmony_ci#define REG_L1PKWT	0x840
16162306a36Sopenharmony_ci#define REG_MRC		0x850
16262306a36Sopenharmony_ci#define REG_CLKTRK	0x860
16362306a36Sopenharmony_ci#define REG_EDCCA_POW_MA	0x8a0
16462306a36Sopenharmony_ci#define BIT_MA_LEVEL	GENMASK(1, 0)
16562306a36Sopenharmony_ci#define REG_ADCCLK	0x8ac
16662306a36Sopenharmony_ci#define REG_ADC160	0x8c4
16762306a36Sopenharmony_ci#define REG_ADC40	0x8c8
16862306a36Sopenharmony_ci#define REG_EDCCA_DECISION	0x8dc
16962306a36Sopenharmony_ci#define BIT_EDCCA_OPTION	BIT(5)
17062306a36Sopenharmony_ci#define REG_CDDTXP	0x93c
17162306a36Sopenharmony_ci#define REG_TXPSEL1	0x940
17262306a36Sopenharmony_ci#define REG_EDCCA_SOURCE	0x944
17362306a36Sopenharmony_ci#define BIT_SOURCE_OPTION	GENMASK(29, 28)
17462306a36Sopenharmony_ci#define REG_ACBB0	0x948
17562306a36Sopenharmony_ci#define REG_ACBBRXFIR	0x94c
17662306a36Sopenharmony_ci#define REG_ACGG2TBL	0x958
17762306a36Sopenharmony_ci#define REG_RXSB	0xa00
17862306a36Sopenharmony_ci#define REG_ADCINI	0xa04
17962306a36Sopenharmony_ci#define REG_TXSF2	0xa24
18062306a36Sopenharmony_ci#define REG_TXSF6	0xa28
18162306a36Sopenharmony_ci#define REG_RXDESC	0xa2c
18262306a36Sopenharmony_ci#define REG_ENTXCCK	0xa80
18362306a36Sopenharmony_ci#define REG_AGCTR_A	0xc08
18462306a36Sopenharmony_ci#define REG_TXDFIR	0xc20
18562306a36Sopenharmony_ci#define REG_RXIGI_A	0xc50
18662306a36Sopenharmony_ci#define REG_TRSW	0xca0
18762306a36Sopenharmony_ci#define REG_RFESEL0	0xcb0
18862306a36Sopenharmony_ci#define REG_RFESEL8	0xcb4
18962306a36Sopenharmony_ci#define REG_RFECTL	0xcb8
19062306a36Sopenharmony_ci#define REG_RFEINV	0xcbc
19162306a36Sopenharmony_ci#define REG_AGCTR_B	0xe08
19262306a36Sopenharmony_ci#define REG_RXIGI_B	0xe50
19362306a36Sopenharmony_ci#define REG_ANTWT	0x1904
19462306a36Sopenharmony_ci#define REG_IQKFAILMSK	0x1bf0
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ciextern const struct rtw_chip_info rtw8822b_hw_spec;
19762306a36Sopenharmony_ci
19862306a36Sopenharmony_ci#endif
199