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 __RTW8822B_H__ 68c2ecf20Sopenharmony_ci#define __RTW8822B_H__ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <asm/byteorder.h> 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#define RCR_VHT_ACK BIT(26) 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_cistruct rtw8822bu_efuse { 138c2ecf20Sopenharmony_ci u8 res4[4]; /* 0xd0 */ 148c2ecf20Sopenharmony_ci u8 usb_optional_function; 158c2ecf20Sopenharmony_ci u8 res5[0x1e]; 168c2ecf20Sopenharmony_ci u8 res6[2]; 178c2ecf20Sopenharmony_ci u8 serial[0x0b]; /* 0xf5 */ 188c2ecf20Sopenharmony_ci u8 vid; /* 0x100 */ 198c2ecf20Sopenharmony_ci u8 res7; 208c2ecf20Sopenharmony_ci u8 pid; 218c2ecf20Sopenharmony_ci u8 res8[4]; 228c2ecf20Sopenharmony_ci u8 mac_addr[ETH_ALEN]; /* 0x107 */ 238c2ecf20Sopenharmony_ci u8 res9[2]; 248c2ecf20Sopenharmony_ci u8 vendor_name[0x07]; 258c2ecf20Sopenharmony_ci u8 res10[2]; 268c2ecf20Sopenharmony_ci u8 device_name[0x14]; 278c2ecf20Sopenharmony_ci u8 res11[0xcf]; 288c2ecf20Sopenharmony_ci u8 package_type; /* 0x1fb */ 298c2ecf20Sopenharmony_ci u8 res12[0x4]; 308c2ecf20Sopenharmony_ci}; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_cistruct rtw8822be_efuse { 338c2ecf20Sopenharmony_ci u8 mac_addr[ETH_ALEN]; /* 0xd0 */ 348c2ecf20Sopenharmony_ci u8 vender_id[2]; 358c2ecf20Sopenharmony_ci u8 device_id[2]; 368c2ecf20Sopenharmony_ci u8 sub_vender_id[2]; 378c2ecf20Sopenharmony_ci u8 sub_device_id[2]; 388c2ecf20Sopenharmony_ci u8 pmc[2]; 398c2ecf20Sopenharmony_ci u8 exp_device_cap[2]; 408c2ecf20Sopenharmony_ci u8 msi_cap; 418c2ecf20Sopenharmony_ci u8 ltr_cap; /* 0xe3 */ 428c2ecf20Sopenharmony_ci u8 exp_link_control[2]; 438c2ecf20Sopenharmony_ci u8 link_cap[4]; 448c2ecf20Sopenharmony_ci u8 link_control[2]; 458c2ecf20Sopenharmony_ci u8 serial_number[8]; 468c2ecf20Sopenharmony_ci u8 res0:2; /* 0xf4 */ 478c2ecf20Sopenharmony_ci u8 ltr_en:1; 488c2ecf20Sopenharmony_ci u8 res1:2; 498c2ecf20Sopenharmony_ci u8 obff:2; 508c2ecf20Sopenharmony_ci u8 res2:3; 518c2ecf20Sopenharmony_ci u8 obff_cap:2; 528c2ecf20Sopenharmony_ci u8 res3:4; 538c2ecf20Sopenharmony_ci u8 res4[3]; 548c2ecf20Sopenharmony_ci u8 class_code[3]; 558c2ecf20Sopenharmony_ci u8 pci_pm_L1_2_supp:1; 568c2ecf20Sopenharmony_ci u8 pci_pm_L1_1_supp:1; 578c2ecf20Sopenharmony_ci u8 aspm_pm_L1_2_supp:1; 588c2ecf20Sopenharmony_ci u8 aspm_pm_L1_1_supp:1; 598c2ecf20Sopenharmony_ci u8 L1_pm_substates_supp:1; 608c2ecf20Sopenharmony_ci u8 res5:3; 618c2ecf20Sopenharmony_ci u8 port_common_mode_restore_time; 628c2ecf20Sopenharmony_ci u8 port_t_power_on_scale:2; 638c2ecf20Sopenharmony_ci u8 res6:1; 648c2ecf20Sopenharmony_ci u8 port_t_power_on_value:5; 658c2ecf20Sopenharmony_ci u8 res7; 668c2ecf20Sopenharmony_ci}; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_cistruct rtw8822b_efuse { 698c2ecf20Sopenharmony_ci __le16 rtl_id; 708c2ecf20Sopenharmony_ci u8 res0[0x0e]; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci /* power index for four RF paths */ 738c2ecf20Sopenharmony_ci struct rtw_txpwr_idx txpwr_idx_table[4]; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci u8 channel_plan; /* 0xb8 */ 768c2ecf20Sopenharmony_ci u8 xtal_k; 778c2ecf20Sopenharmony_ci u8 thermal_meter; 788c2ecf20Sopenharmony_ci u8 iqk_lck; 798c2ecf20Sopenharmony_ci u8 pa_type; /* 0xbc */ 808c2ecf20Sopenharmony_ci u8 lna_type_2g[2]; /* 0xbd */ 818c2ecf20Sopenharmony_ci u8 lna_type_5g[2]; 828c2ecf20Sopenharmony_ci u8 rf_board_option; 838c2ecf20Sopenharmony_ci u8 rf_feature_option; 848c2ecf20Sopenharmony_ci u8 rf_bt_setting; 858c2ecf20Sopenharmony_ci u8 eeprom_version; 868c2ecf20Sopenharmony_ci u8 eeprom_customer_id; 878c2ecf20Sopenharmony_ci u8 tx_bb_swing_setting_2g; 888c2ecf20Sopenharmony_ci u8 tx_bb_swing_setting_5g; 898c2ecf20Sopenharmony_ci u8 tx_pwr_calibrate_rate; 908c2ecf20Sopenharmony_ci u8 rf_antenna_option; /* 0xc9 */ 918c2ecf20Sopenharmony_ci u8 rfe_option; 928c2ecf20Sopenharmony_ci u8 country_code[2]; 938c2ecf20Sopenharmony_ci u8 res[3]; 948c2ecf20Sopenharmony_ci union { 958c2ecf20Sopenharmony_ci struct rtw8822bu_efuse u; 968c2ecf20Sopenharmony_ci struct rtw8822be_efuse e; 978c2ecf20Sopenharmony_ci }; 988c2ecf20Sopenharmony_ci}; 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_cistatic inline void 1018c2ecf20Sopenharmony_ci_rtw_write32s_mask(struct rtw_dev *rtwdev, u32 addr, u32 mask, u32 data) 1028c2ecf20Sopenharmony_ci{ 1038c2ecf20Sopenharmony_ci /* 0xC00-0xCFF and 0xE00-0xEFF have the same layout */ 1048c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, addr, mask, data); 1058c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, addr + 0x200, mask, data); 1068c2ecf20Sopenharmony_ci} 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci#define rtw_write32s_mask(rtwdev, addr, mask, data) \ 1098c2ecf20Sopenharmony_ci do { \ 1108c2ecf20Sopenharmony_ci BUILD_BUG_ON((addr) < 0xC00 || (addr) >= 0xD00); \ 1118c2ecf20Sopenharmony_ci \ 1128c2ecf20Sopenharmony_ci _rtw_write32s_mask(rtwdev, addr, mask, data); \ 1138c2ecf20Sopenharmony_ci } while (0) 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci/* phy status page0 */ 1168c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P0_PWDB(phy_stat) \ 1178c2ecf20Sopenharmony_ci le32_get_bits(*((__le32 *)(phy_stat) + 0x00), GENMASK(15, 8)) 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci/* phy status page1 */ 1208c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P1_PWDB_A(phy_stat) \ 1218c2ecf20Sopenharmony_ci le32_get_bits(*((__le32 *)(phy_stat) + 0x00), GENMASK(15, 8)) 1228c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P1_PWDB_B(phy_stat) \ 1238c2ecf20Sopenharmony_ci le32_get_bits(*((__le32 *)(phy_stat) + 0x00), GENMASK(23, 16)) 1248c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P1_RF_MODE(phy_stat) \ 1258c2ecf20Sopenharmony_ci le32_get_bits(*((__le32 *)(phy_stat) + 0x03), GENMASK(29, 28)) 1268c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P1_L_RXSC(phy_stat) \ 1278c2ecf20Sopenharmony_ci le32_get_bits(*((__le32 *)(phy_stat) + 0x01), GENMASK(11, 8)) 1288c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P1_HT_RXSC(phy_stat) \ 1298c2ecf20Sopenharmony_ci le32_get_bits(*((__le32 *)(phy_stat) + 0x01), GENMASK(15, 12)) 1308c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P1_RXEVM_A(phy_stat) \ 1318c2ecf20Sopenharmony_ci le32_get_bits(*((__le32 *)(phy_stat) + 0x04), GENMASK(7, 0)) 1328c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P1_RXEVM_B(phy_stat) \ 1338c2ecf20Sopenharmony_ci le32_get_bits(*((__le32 *)(phy_stat) + 0x04), GENMASK(15, 8)) 1348c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P1_CFO_TAIL_A(phy_stat) \ 1358c2ecf20Sopenharmony_ci le32_get_bits(*((__le32 *)(phy_stat) + 0x05), GENMASK(7, 0)) 1368c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P1_CFO_TAIL_B(phy_stat) \ 1378c2ecf20Sopenharmony_ci le32_get_bits(*((__le32 *)(phy_stat) + 0x05), GENMASK(15, 8)) 1388c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P1_RXSNR_A(phy_stat) \ 1398c2ecf20Sopenharmony_ci le32_get_bits(*((__le32 *)(phy_stat) + 0x06), GENMASK(7, 0)) 1408c2ecf20Sopenharmony_ci#define GET_PHY_STAT_P1_RXSNR_B(phy_stat) \ 1418c2ecf20Sopenharmony_ci le32_get_bits(*((__le32 *)(phy_stat) + 0x06), GENMASK(15, 8)) 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci#define REG_HTSTFWT 0x800 1448c2ecf20Sopenharmony_ci#define REG_RXPSEL 0x808 1458c2ecf20Sopenharmony_ci#define BIT_RX_PSEL_RST (BIT(28) | BIT(29)) 1468c2ecf20Sopenharmony_ci#define REG_TXPSEL 0x80c 1478c2ecf20Sopenharmony_ci#define REG_RXCCAMSK 0x814 1488c2ecf20Sopenharmony_ci#define REG_CCASEL 0x82c 1498c2ecf20Sopenharmony_ci#define REG_PDMFTH 0x830 1508c2ecf20Sopenharmony_ci#define REG_CCA2ND 0x838 1518c2ecf20Sopenharmony_ci#define REG_L1WT 0x83c 1528c2ecf20Sopenharmony_ci#define REG_L1PKWT 0x840 1538c2ecf20Sopenharmony_ci#define REG_MRC 0x850 1548c2ecf20Sopenharmony_ci#define REG_CLKTRK 0x860 1558c2ecf20Sopenharmony_ci#define REG_ADCCLK 0x8ac 1568c2ecf20Sopenharmony_ci#define REG_ADC160 0x8c4 1578c2ecf20Sopenharmony_ci#define REG_ADC40 0x8c8 1588c2ecf20Sopenharmony_ci#define REG_CDDTXP 0x93c 1598c2ecf20Sopenharmony_ci#define REG_TXPSEL1 0x940 1608c2ecf20Sopenharmony_ci#define REG_ACBB0 0x948 1618c2ecf20Sopenharmony_ci#define REG_ACBBRXFIR 0x94c 1628c2ecf20Sopenharmony_ci#define REG_ACGG2TBL 0x958 1638c2ecf20Sopenharmony_ci#define REG_RXSB 0xa00 1648c2ecf20Sopenharmony_ci#define REG_ADCINI 0xa04 1658c2ecf20Sopenharmony_ci#define REG_TXSF2 0xa24 1668c2ecf20Sopenharmony_ci#define REG_TXSF6 0xa28 1678c2ecf20Sopenharmony_ci#define REG_RXDESC 0xa2c 1688c2ecf20Sopenharmony_ci#define REG_ENTXCCK 0xa80 1698c2ecf20Sopenharmony_ci#define REG_AGCTR_A 0xc08 1708c2ecf20Sopenharmony_ci#define REG_TXDFIR 0xc20 1718c2ecf20Sopenharmony_ci#define REG_RXIGI_A 0xc50 1728c2ecf20Sopenharmony_ci#define REG_TRSW 0xca0 1738c2ecf20Sopenharmony_ci#define REG_RFESEL0 0xcb0 1748c2ecf20Sopenharmony_ci#define REG_RFESEL8 0xcb4 1758c2ecf20Sopenharmony_ci#define REG_RFECTL 0xcb8 1768c2ecf20Sopenharmony_ci#define REG_RFEINV 0xcbc 1778c2ecf20Sopenharmony_ci#define REG_AGCTR_B 0xe08 1788c2ecf20Sopenharmony_ci#define REG_RXIGI_B 0xe50 1798c2ecf20Sopenharmony_ci#define REG_ANTWT 0x1904 1808c2ecf20Sopenharmony_ci#define REG_IQKFAILMSK 0x1bf0 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci#endif 183