18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
28c2ecf20Sopenharmony_ci/* Copyright(c) 2018-2019  Realtek Corporation
38c2ecf20Sopenharmony_ci */
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#ifndef __RTW8821C_H__
68c2ecf20Sopenharmony_ci#define __RTW8821C_H__
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <asm/byteorder.h>
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#define RCR_VHT_ACK		BIT(26)
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_cistruct rtw8821ce_efuse {
138c2ecf20Sopenharmony_ci	u8 mac_addr[ETH_ALEN];		/* 0xd0 */
148c2ecf20Sopenharmony_ci	u8 vender_id[2];
158c2ecf20Sopenharmony_ci	u8 device_id[2];
168c2ecf20Sopenharmony_ci	u8 sub_vender_id[2];
178c2ecf20Sopenharmony_ci	u8 sub_device_id[2];
188c2ecf20Sopenharmony_ci	u8 pmc[2];
198c2ecf20Sopenharmony_ci	u8 exp_device_cap[2];
208c2ecf20Sopenharmony_ci	u8 msi_cap;
218c2ecf20Sopenharmony_ci	u8 ltr_cap;			/* 0xe3 */
228c2ecf20Sopenharmony_ci	u8 exp_link_control[2];
238c2ecf20Sopenharmony_ci	u8 link_cap[4];
248c2ecf20Sopenharmony_ci	u8 link_control[2];
258c2ecf20Sopenharmony_ci	u8 serial_number[8];
268c2ecf20Sopenharmony_ci	u8 res0:2;			/* 0xf4 */
278c2ecf20Sopenharmony_ci	u8 ltr_en:1;
288c2ecf20Sopenharmony_ci	u8 res1:2;
298c2ecf20Sopenharmony_ci	u8 obff:2;
308c2ecf20Sopenharmony_ci	u8 res2:3;
318c2ecf20Sopenharmony_ci	u8 obff_cap:2;
328c2ecf20Sopenharmony_ci	u8 res3:4;
338c2ecf20Sopenharmony_ci	u8 res4[3];
348c2ecf20Sopenharmony_ci	u8 class_code[3];
358c2ecf20Sopenharmony_ci	u8 pci_pm_L1_2_supp:1;
368c2ecf20Sopenharmony_ci	u8 pci_pm_L1_1_supp:1;
378c2ecf20Sopenharmony_ci	u8 aspm_pm_L1_2_supp:1;
388c2ecf20Sopenharmony_ci	u8 aspm_pm_L1_1_supp:1;
398c2ecf20Sopenharmony_ci	u8 L1_pm_substates_supp:1;
408c2ecf20Sopenharmony_ci	u8 res5:3;
418c2ecf20Sopenharmony_ci	u8 port_common_mode_restore_time;
428c2ecf20Sopenharmony_ci	u8 port_t_power_on_scale:2;
438c2ecf20Sopenharmony_ci	u8 res6:1;
448c2ecf20Sopenharmony_ci	u8 port_t_power_on_value:5;
458c2ecf20Sopenharmony_ci	u8 res7;
468c2ecf20Sopenharmony_ci};
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cistruct rtw8821c_efuse {
498c2ecf20Sopenharmony_ci	__le16 rtl_id;
508c2ecf20Sopenharmony_ci	u8 res0[0x0e];
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci	/* power index for four RF paths */
538c2ecf20Sopenharmony_ci	struct rtw_txpwr_idx txpwr_idx_table[4];
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci	u8 channel_plan;		/* 0xb8 */
568c2ecf20Sopenharmony_ci	u8 xtal_k;
578c2ecf20Sopenharmony_ci	u8 thermal_meter;
588c2ecf20Sopenharmony_ci	u8 iqk_lck;
598c2ecf20Sopenharmony_ci	u8 pa_type;			/* 0xbc */
608c2ecf20Sopenharmony_ci	u8 lna_type_2g[2];		/* 0xbd */
618c2ecf20Sopenharmony_ci	u8 lna_type_5g[2];
628c2ecf20Sopenharmony_ci	u8 rf_board_option;
638c2ecf20Sopenharmony_ci	u8 rf_feature_option;
648c2ecf20Sopenharmony_ci	u8 rf_bt_setting;
658c2ecf20Sopenharmony_ci	u8 eeprom_version;
668c2ecf20Sopenharmony_ci	u8 eeprom_customer_id;
678c2ecf20Sopenharmony_ci	u8 tx_bb_swing_setting_2g;
688c2ecf20Sopenharmony_ci	u8 tx_bb_swing_setting_5g;
698c2ecf20Sopenharmony_ci	u8 tx_pwr_calibrate_rate;
708c2ecf20Sopenharmony_ci	u8 rf_antenna_option;		/* 0xc9 */
718c2ecf20Sopenharmony_ci	u8 rfe_option;
728c2ecf20Sopenharmony_ci	u8 country_code[2];
738c2ecf20Sopenharmony_ci	u8 res[3];
748c2ecf20Sopenharmony_ci	union {
758c2ecf20Sopenharmony_ci		struct rtw8821ce_efuse e;
768c2ecf20Sopenharmony_ci	};
778c2ecf20Sopenharmony_ci};
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_cistatic inline void
808c2ecf20Sopenharmony_ci_rtw_write32s_mask(struct rtw_dev *rtwdev, u32 addr, u32 mask, u32 data)
818c2ecf20Sopenharmony_ci{
828c2ecf20Sopenharmony_ci	/* 0xC00-0xCFF and 0xE00-0xEFF have the same layout */
838c2ecf20Sopenharmony_ci	rtw_write32_mask(rtwdev, addr, mask, data);
848c2ecf20Sopenharmony_ci	rtw_write32_mask(rtwdev, addr + 0x200, mask, data);
858c2ecf20Sopenharmony_ci}
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci#define rtw_write32s_mask(rtwdev, addr, mask, data)			       \
888c2ecf20Sopenharmony_ci	do {								       \
898c2ecf20Sopenharmony_ci		BUILD_BUG_ON((addr) < 0xC00 || (addr) >= 0xD00);	       \
908c2ecf20Sopenharmony_ci									       \
918c2ecf20Sopenharmony_ci		_rtw_write32s_mask(rtwdev, addr, mask, data);		       \
928c2ecf20Sopenharmony_ci	} while (0)
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci#define BIT_FEN_PCIEA BIT(6)
958c2ecf20Sopenharmony_ci#define WLAN_SLOT_TIME		0x09
968c2ecf20Sopenharmony_ci#define WLAN_PIFS_TIME		0x19
978c2ecf20Sopenharmony_ci#define WLAN_SIFS_CCK_CONT_TX	0xA
988c2ecf20Sopenharmony_ci#define WLAN_SIFS_OFDM_CONT_TX	0xE
998c2ecf20Sopenharmony_ci#define WLAN_SIFS_CCK_TRX	0x10
1008c2ecf20Sopenharmony_ci#define WLAN_SIFS_OFDM_TRX	0x10
1018c2ecf20Sopenharmony_ci#define WLAN_VO_TXOP_LIMIT	0x186
1028c2ecf20Sopenharmony_ci#define WLAN_VI_TXOP_LIMIT	0x3BC
1038c2ecf20Sopenharmony_ci#define WLAN_RDG_NAV		0x05
1048c2ecf20Sopenharmony_ci#define WLAN_TXOP_NAV		0x1B
1058c2ecf20Sopenharmony_ci#define WLAN_CCK_RX_TSF		0x30
1068c2ecf20Sopenharmony_ci#define WLAN_OFDM_RX_TSF	0x30
1078c2ecf20Sopenharmony_ci#define WLAN_TBTT_PROHIBIT	0x04
1088c2ecf20Sopenharmony_ci#define WLAN_TBTT_HOLD_TIME	0x064
1098c2ecf20Sopenharmony_ci#define WLAN_DRV_EARLY_INT	0x04
1108c2ecf20Sopenharmony_ci#define WLAN_BCN_DMA_TIME	0x02
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#define WLAN_RX_FILTER0		0x0FFFFFFF
1138c2ecf20Sopenharmony_ci#define WLAN_RX_FILTER2		0xFFFF
1148c2ecf20Sopenharmony_ci#define WLAN_RCR_CFG		0xE400220E
1158c2ecf20Sopenharmony_ci#define WLAN_RXPKT_MAX_SZ	12288
1168c2ecf20Sopenharmony_ci#define WLAN_RXPKT_MAX_SZ_512	(WLAN_RXPKT_MAX_SZ >> 9)
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci#define WLAN_AMPDU_MAX_TIME		0x70
1198c2ecf20Sopenharmony_ci#define WLAN_RTS_LEN_TH			0xFF
1208c2ecf20Sopenharmony_ci#define WLAN_RTS_TX_TIME_TH		0x08
1218c2ecf20Sopenharmony_ci#define WLAN_MAX_AGG_PKT_LIMIT		0x20
1228c2ecf20Sopenharmony_ci#define WLAN_RTS_MAX_AGG_PKT_LIMIT	0x20
1238c2ecf20Sopenharmony_ci#define FAST_EDCA_VO_TH		0x06
1248c2ecf20Sopenharmony_ci#define FAST_EDCA_VI_TH		0x06
1258c2ecf20Sopenharmony_ci#define FAST_EDCA_BE_TH		0x06
1268c2ecf20Sopenharmony_ci#define FAST_EDCA_BK_TH		0x06
1278c2ecf20Sopenharmony_ci#define WLAN_BAR_RETRY_LIMIT		0x01
1288c2ecf20Sopenharmony_ci#define WLAN_RA_TRY_RATE_AGG_LIMIT	0x08
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci#define WLAN_TX_FUNC_CFG1		0x30
1318c2ecf20Sopenharmony_ci#define WLAN_TX_FUNC_CFG2		0x30
1328c2ecf20Sopenharmony_ci#define WLAN_MAC_OPT_NORM_FUNC1		0x98
1338c2ecf20Sopenharmony_ci#define WLAN_MAC_OPT_LB_FUNC1		0x80
1348c2ecf20Sopenharmony_ci#define WLAN_MAC_OPT_FUNC2		0xb0810041
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci#define WLAN_SIFS_CFG	(WLAN_SIFS_CCK_CONT_TX | \
1378c2ecf20Sopenharmony_ci			(WLAN_SIFS_OFDM_CONT_TX << BIT_SHIFT_SIFS_OFDM_CTX) | \
1388c2ecf20Sopenharmony_ci			(WLAN_SIFS_CCK_TRX << BIT_SHIFT_SIFS_CCK_TRX) | \
1398c2ecf20Sopenharmony_ci			(WLAN_SIFS_OFDM_TRX << BIT_SHIFT_SIFS_OFDM_TRX))
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci#define WLAN_TBTT_TIME	(WLAN_TBTT_PROHIBIT |\
1428c2ecf20Sopenharmony_ci			(WLAN_TBTT_HOLD_TIME << BIT_SHIFT_TBTT_HOLD_TIME_AP))
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci#define WLAN_NAV_CFG		(WLAN_RDG_NAV | (WLAN_TXOP_NAV << 16))
1458c2ecf20Sopenharmony_ci#define WLAN_RX_TSF_CFG		(WLAN_CCK_RX_TSF | (WLAN_OFDM_RX_TSF) << 8)
1468c2ecf20Sopenharmony_ci#define WLAN_PRE_TXCNT_TIME_TH		0x1E4
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci/* phy status page0 */
1498c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P0_PWDB(phy_stat)                                         \
1508c2ecf20Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x00), GENMASK(15, 8))
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci/* phy status page1 */
1538c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P1_PWDB_A(phy_stat)                                       \
1548c2ecf20Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x00), GENMASK(15, 8))
1558c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P1_PWDB_B(phy_stat)                                       \
1568c2ecf20Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x00), GENMASK(23, 16))
1578c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P1_RF_MODE(phy_stat)                                      \
1588c2ecf20Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x03), GENMASK(29, 28))
1598c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P1_L_RXSC(phy_stat)                                       \
1608c2ecf20Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x01), GENMASK(11, 8))
1618c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P1_HT_RXSC(phy_stat)                                      \
1628c2ecf20Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x01), GENMASK(15, 12))
1638c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P1_RXEVM_A(phy_stat)                                      \
1648c2ecf20Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x04), GENMASK(7, 0))
1658c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P1_RXEVM_B(phy_stat)                                      \
1668c2ecf20Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x04), GENMASK(15, 8))
1678c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P1_CFO_TAIL_A(phy_stat)                                 \
1688c2ecf20Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x05), GENMASK(7, 0))
1698c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P1_CFO_TAIL_B(phy_stat)                                 \
1708c2ecf20Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x05), GENMASK(15, 8))
1718c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P1_RXSNR_A(phy_stat)                                      \
1728c2ecf20Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x06), GENMASK(7, 0))
1738c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P1_RXSNR_B(phy_stat)                                      \
1748c2ecf20Sopenharmony_ci	le32_get_bits(*((__le32 *)(phy_stat) + 0x06), GENMASK(15, 8))
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci#define REG_INIRTS_RATE_SEL 0x0480
1778c2ecf20Sopenharmony_ci#define REG_HTSTFWT	0x800
1788c2ecf20Sopenharmony_ci#define REG_RXPSEL	0x808
1798c2ecf20Sopenharmony_ci#define BIT_RX_PSEL_RST		(BIT(28) | BIT(29))
1808c2ecf20Sopenharmony_ci#define REG_TXPSEL	0x80c
1818c2ecf20Sopenharmony_ci#define REG_RXCCAMSK	0x814
1828c2ecf20Sopenharmony_ci#define REG_CCASEL	0x82c
1838c2ecf20Sopenharmony_ci#define REG_PDMFTH	0x830
1848c2ecf20Sopenharmony_ci#define REG_CCA2ND	0x838
1858c2ecf20Sopenharmony_ci#define REG_L1WT	0x83c
1868c2ecf20Sopenharmony_ci#define REG_L1PKWT	0x840
1878c2ecf20Sopenharmony_ci#define REG_MRC		0x850
1888c2ecf20Sopenharmony_ci#define REG_CLKTRK	0x860
1898c2ecf20Sopenharmony_ci#define REG_ADCCLK	0x8ac
1908c2ecf20Sopenharmony_ci#define REG_ADC160	0x8c4
1918c2ecf20Sopenharmony_ci#define REG_ADC40	0x8c8
1928c2ecf20Sopenharmony_ci#define REG_CHFIR	0x8f0
1938c2ecf20Sopenharmony_ci#define REG_CDDTXP	0x93c
1948c2ecf20Sopenharmony_ci#define REG_TXPSEL1	0x940
1958c2ecf20Sopenharmony_ci#define REG_ACBB0	0x948
1968c2ecf20Sopenharmony_ci#define REG_ACBBRXFIR	0x94c
1978c2ecf20Sopenharmony_ci#define REG_ACGG2TBL	0x958
1988c2ecf20Sopenharmony_ci#define REG_FAS		0x9a4
1998c2ecf20Sopenharmony_ci#define REG_RXSB	0xa00
2008c2ecf20Sopenharmony_ci#define REG_ADCINI	0xa04
2018c2ecf20Sopenharmony_ci#define REG_PWRTH	0xa08
2028c2ecf20Sopenharmony_ci#define REG_TXSF2	0xa24
2038c2ecf20Sopenharmony_ci#define REG_TXSF6	0xa28
2048c2ecf20Sopenharmony_ci#define REG_FA_CCK	0xa5c
2058c2ecf20Sopenharmony_ci#define REG_RXDESC	0xa2c
2068c2ecf20Sopenharmony_ci#define REG_ENTXCCK	0xa80
2078c2ecf20Sopenharmony_ci#define REG_PWRTH2	0xaa8
2088c2ecf20Sopenharmony_ci#define REG_CSRATIO	0xaaa
2098c2ecf20Sopenharmony_ci#define REG_TXFILTER	0xaac
2108c2ecf20Sopenharmony_ci#define REG_CNTRST	0xb58
2118c2ecf20Sopenharmony_ci#define REG_AGCTR_A	0xc08
2128c2ecf20Sopenharmony_ci#define REG_TXSCALE_A	0xc1c
2138c2ecf20Sopenharmony_ci#define REG_TXDFIR	0xc20
2148c2ecf20Sopenharmony_ci#define REG_RXIGI_A	0xc50
2158c2ecf20Sopenharmony_ci#define REG_TXAGCIDX	0xc94
2168c2ecf20Sopenharmony_ci#define REG_TRSW	0xca0
2178c2ecf20Sopenharmony_ci#define REG_RFESEL0	0xcb0
2188c2ecf20Sopenharmony_ci#define REG_RFESEL8	0xcb4
2198c2ecf20Sopenharmony_ci#define REG_RFECTL	0xcb8
2208c2ecf20Sopenharmony_ci#define REG_RFEINV	0xcbc
2218c2ecf20Sopenharmony_ci#define REG_AGCTR_B	0xe08
2228c2ecf20Sopenharmony_ci#define REG_RXIGI_B	0xe50
2238c2ecf20Sopenharmony_ci#define REG_CRC_CCK	0xf04
2248c2ecf20Sopenharmony_ci#define REG_CRC_OFDM	0xf14
2258c2ecf20Sopenharmony_ci#define REG_CRC_HT	0xf10
2268c2ecf20Sopenharmony_ci#define REG_CRC_VHT	0xf0c
2278c2ecf20Sopenharmony_ci#define REG_CCA_OFDM	0xf08
2288c2ecf20Sopenharmony_ci#define REG_FA_OFDM	0xf48
2298c2ecf20Sopenharmony_ci#define REG_CCA_CCK	0xfcc
2308c2ecf20Sopenharmony_ci#define REG_ANTWT	0x1904
2318c2ecf20Sopenharmony_ci#define REG_IQKFAILMSK	0x1bf0
2328c2ecf20Sopenharmony_ci#define BIT_MASK_R_RFE_SEL_15	GENMASK(31, 28)
2338c2ecf20Sopenharmony_ci#define BIT_SDIO_INT BIT(18)
2348c2ecf20Sopenharmony_ci#define SAMPLE_RATE_MASK GENMASK(5, 0)
2358c2ecf20Sopenharmony_ci#define SAMPLE_RATE	0x5
2368c2ecf20Sopenharmony_ci#define BT_CNT_ENABLE	0x1
2378c2ecf20Sopenharmony_ci#define BIT_BCN_QUEUE	BIT(3)
2388c2ecf20Sopenharmony_ci#define BCN_PRI_EN	0x1
2398c2ecf20Sopenharmony_ci#define PTA_CTRL_PIN	0x66
2408c2ecf20Sopenharmony_ci#define DPDT_CTRL_PIN	0x77
2418c2ecf20Sopenharmony_ci#define ANTDIC_CTRL_PIN	0x88
2428c2ecf20Sopenharmony_ci#define REG_CTRL_TYPE	0x67
2438c2ecf20Sopenharmony_ci#define BIT_CTRL_TYPE1	BIT(5)
2448c2ecf20Sopenharmony_ci#define BIT_CTRL_TYPE2	BIT(4)
2458c2ecf20Sopenharmony_ci#define CTRL_TYPE_MASK	GENMASK(15, 8)
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci#define RF18_BAND_MASK		(BIT(16) | BIT(9) | BIT(8))
2488c2ecf20Sopenharmony_ci#define RF18_BAND_2G		(0)
2498c2ecf20Sopenharmony_ci#define RF18_BAND_5G		(BIT(16) | BIT(8))
2508c2ecf20Sopenharmony_ci#define RF18_CHANNEL_MASK	(MASKBYTE0)
2518c2ecf20Sopenharmony_ci#define RF18_RFSI_MASK		(BIT(18) | BIT(17))
2528c2ecf20Sopenharmony_ci#define RF18_RFSI_GE		(BIT(17))
2538c2ecf20Sopenharmony_ci#define RF18_RFSI_GT		(BIT(18))
2548c2ecf20Sopenharmony_ci#define RF18_BW_MASK		(BIT(11) | BIT(10))
2558c2ecf20Sopenharmony_ci#define RF18_BW_20M		(BIT(11) | BIT(10))
2568c2ecf20Sopenharmony_ci#define RF18_BW_40M		(BIT(11))
2578c2ecf20Sopenharmony_ci#define RF18_BW_80M		(BIT(10))
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ci#endif
260