rtw8821c.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
  2. /* Copyright(c) 2018-2019 Realtek Corporation
  3. */
  4. #ifndef __RTW8821C_H__
  5. #define __RTW8821C_H__
  6. #include <asm/byteorder.h>
  7. #define RCR_VHT_ACK BIT(26)
  8. struct rtw8821ce_efuse {
  9. u8 mac_addr[ETH_ALEN]; /* 0xd0 */
  10. u8 vender_id[2];
  11. u8 device_id[2];
  12. u8 sub_vender_id[2];
  13. u8 sub_device_id[2];
  14. u8 pmc[2];
  15. u8 exp_device_cap[2];
  16. u8 msi_cap;
  17. u8 ltr_cap; /* 0xe3 */
  18. u8 exp_link_control[2];
  19. u8 link_cap[4];
  20. u8 link_control[2];
  21. u8 serial_number[8];
  22. u8 res0:2; /* 0xf4 */
  23. u8 ltr_en:1;
  24. u8 res1:2;
  25. u8 obff:2;
  26. u8 res2:3;
  27. u8 obff_cap:2;
  28. u8 res3:4;
  29. u8 res4[3];
  30. u8 class_code[3];
  31. u8 pci_pm_L1_2_supp:1;
  32. u8 pci_pm_L1_1_supp:1;
  33. u8 aspm_pm_L1_2_supp:1;
  34. u8 aspm_pm_L1_1_supp:1;
  35. u8 L1_pm_substates_supp:1;
  36. u8 res5:3;
  37. u8 port_common_mode_restore_time;
  38. u8 port_t_power_on_scale:2;
  39. u8 res6:1;
  40. u8 port_t_power_on_value:5;
  41. u8 res7;
  42. };
  43. struct rtw8821c_efuse {
  44. __le16 rtl_id;
  45. u8 res0[0x0e];
  46. /* power index for four RF paths */
  47. struct rtw_txpwr_idx txpwr_idx_table[4];
  48. u8 channel_plan; /* 0xb8 */
  49. u8 xtal_k;
  50. u8 thermal_meter;
  51. u8 iqk_lck;
  52. u8 pa_type; /* 0xbc */
  53. u8 lna_type_2g[2]; /* 0xbd */
  54. u8 lna_type_5g[2];
  55. u8 rf_board_option;
  56. u8 rf_feature_option;
  57. u8 rf_bt_setting;
  58. u8 eeprom_version;
  59. u8 eeprom_customer_id;
  60. u8 tx_bb_swing_setting_2g;
  61. u8 tx_bb_swing_setting_5g;
  62. u8 tx_pwr_calibrate_rate;
  63. u8 rf_antenna_option; /* 0xc9 */
  64. u8 rfe_option;
  65. u8 country_code[2];
  66. u8 res[3];
  67. union {
  68. struct rtw8821ce_efuse e;
  69. };
  70. };
  71. static inline void
  72. _rtw_write32s_mask(struct rtw_dev *rtwdev, u32 addr, u32 mask, u32 data)
  73. {
  74. /* 0xC00-0xCFF and 0xE00-0xEFF have the same layout */
  75. rtw_write32_mask(rtwdev, addr, mask, data);
  76. rtw_write32_mask(rtwdev, addr + 0x200, mask, data);
  77. }
  78. extern const struct rtw_chip_info rtw8821c_hw_spec;
  79. #define rtw_write32s_mask(rtwdev, addr, mask, data) \
  80. do { \
  81. BUILD_BUG_ON((addr) < 0xC00 || (addr) >= 0xD00); \
  82. \
  83. _rtw_write32s_mask(rtwdev, addr, mask, data); \
  84. } while (0)
  85. #define BIT_FEN_PCIEA BIT(6)
  86. #define WLAN_SLOT_TIME 0x09
  87. #define WLAN_PIFS_TIME 0x19
  88. #define WLAN_SIFS_CCK_CONT_TX 0xA
  89. #define WLAN_SIFS_OFDM_CONT_TX 0xE
  90. #define WLAN_SIFS_CCK_TRX 0x10
  91. #define WLAN_SIFS_OFDM_TRX 0x10
  92. #define WLAN_VO_TXOP_LIMIT 0x186
  93. #define WLAN_VI_TXOP_LIMIT 0x3BC
  94. #define WLAN_RDG_NAV 0x05
  95. #define WLAN_TXOP_NAV 0x1B
  96. #define WLAN_CCK_RX_TSF 0x30
  97. #define WLAN_OFDM_RX_TSF 0x30
  98. #define WLAN_TBTT_PROHIBIT 0x04
  99. #define WLAN_TBTT_HOLD_TIME 0x064
  100. #define WLAN_DRV_EARLY_INT 0x04
  101. #define WLAN_BCN_DMA_TIME 0x02
  102. #define WLAN_RX_FILTER0 0x0FFFFFFF
  103. #define WLAN_RX_FILTER2 0xFFFF
  104. #define WLAN_RCR_CFG 0xE400220E
  105. #define WLAN_RXPKT_MAX_SZ 12288
  106. #define WLAN_RXPKT_MAX_SZ_512 (WLAN_RXPKT_MAX_SZ >> 9)
  107. #define WLAN_AMPDU_MAX_TIME 0x70
  108. #define WLAN_RTS_LEN_TH 0xFF
  109. #define WLAN_RTS_TX_TIME_TH 0x08
  110. #define WLAN_MAX_AGG_PKT_LIMIT 0x20
  111. #define WLAN_RTS_MAX_AGG_PKT_LIMIT 0x20
  112. #define FAST_EDCA_VO_TH 0x06
  113. #define FAST_EDCA_VI_TH 0x06
  114. #define FAST_EDCA_BE_TH 0x06
  115. #define FAST_EDCA_BK_TH 0x06
  116. #define WLAN_BAR_RETRY_LIMIT 0x01
  117. #define WLAN_RA_TRY_RATE_AGG_LIMIT 0x08
  118. #define WLAN_TX_FUNC_CFG1 0x30
  119. #define WLAN_TX_FUNC_CFG2 0x30
  120. #define WLAN_MAC_OPT_NORM_FUNC1 0x98
  121. #define WLAN_MAC_OPT_LB_FUNC1 0x80
  122. #define WLAN_MAC_OPT_FUNC2 0xb0810041
  123. #define WLAN_SIFS_CFG (WLAN_SIFS_CCK_CONT_TX | \
  124. (WLAN_SIFS_OFDM_CONT_TX << BIT_SHIFT_SIFS_OFDM_CTX) | \
  125. (WLAN_SIFS_CCK_TRX << BIT_SHIFT_SIFS_CCK_TRX) | \
  126. (WLAN_SIFS_OFDM_TRX << BIT_SHIFT_SIFS_OFDM_TRX))
  127. #define WLAN_TBTT_TIME (WLAN_TBTT_PROHIBIT |\
  128. (WLAN_TBTT_HOLD_TIME << BIT_SHIFT_TBTT_HOLD_TIME_AP))
  129. #define WLAN_NAV_CFG (WLAN_RDG_NAV | (WLAN_TXOP_NAV << 16))
  130. #define WLAN_RX_TSF_CFG (WLAN_CCK_RX_TSF | (WLAN_OFDM_RX_TSF) << 8)
  131. #define WLAN_PRE_TXCNT_TIME_TH 0x1E4
  132. /* phy status page0 */
  133. #define GET_PHY_STAT_P0_PWDB(phy_stat) \
  134. le32_get_bits(*((__le32 *)(phy_stat) + 0x00), GENMASK(15, 8))
  135. #define GET_PHY_STAT_P0_VGA(phy_stat) \
  136. le32_get_bits(*((__le32 *)(phy_stat) + 0x03), GENMASK(12, 8))
  137. #define GET_PHY_STAT_P0_LNA_L(phy_stat) \
  138. le32_get_bits(*((__le32 *)(phy_stat) + 0x03), GENMASK(15, 13))
  139. #define GET_PHY_STAT_P0_LNA_H(phy_stat) \
  140. le32_get_bits(*((__le32 *)(phy_stat) + 0x03), BIT(23))
  141. #define BIT_LNA_H_MASK BIT(3)
  142. #define BIT_LNA_L_MASK GENMASK(2, 0)
  143. /* phy status page1 */
  144. #define GET_PHY_STAT_P1_PWDB_A(phy_stat) \
  145. le32_get_bits(*((__le32 *)(phy_stat) + 0x00), GENMASK(15, 8))
  146. #define GET_PHY_STAT_P1_PWDB_B(phy_stat) \
  147. le32_get_bits(*((__le32 *)(phy_stat) + 0x00), GENMASK(23, 16))
  148. #define GET_PHY_STAT_P1_RF_MODE(phy_stat) \
  149. le32_get_bits(*((__le32 *)(phy_stat) + 0x03), GENMASK(29, 28))
  150. #define GET_PHY_STAT_P1_L_RXSC(phy_stat) \
  151. le32_get_bits(*((__le32 *)(phy_stat) + 0x01), GENMASK(11, 8))
  152. #define GET_PHY_STAT_P1_HT_RXSC(phy_stat) \
  153. le32_get_bits(*((__le32 *)(phy_stat) + 0x01), GENMASK(15, 12))
  154. #define GET_PHY_STAT_P1_RXEVM_A(phy_stat) \
  155. le32_get_bits(*((__le32 *)(phy_stat) + 0x04), GENMASK(7, 0))
  156. #define GET_PHY_STAT_P1_RXEVM_B(phy_stat) \
  157. le32_get_bits(*((__le32 *)(phy_stat) + 0x04), GENMASK(15, 8))
  158. #define GET_PHY_STAT_P1_CFO_TAIL_A(phy_stat) \
  159. le32_get_bits(*((__le32 *)(phy_stat) + 0x05), GENMASK(7, 0))
  160. #define GET_PHY_STAT_P1_CFO_TAIL_B(phy_stat) \
  161. le32_get_bits(*((__le32 *)(phy_stat) + 0x05), GENMASK(15, 8))
  162. #define GET_PHY_STAT_P1_RXSNR_A(phy_stat) \
  163. le32_get_bits(*((__le32 *)(phy_stat) + 0x06), GENMASK(7, 0))
  164. #define GET_PHY_STAT_P1_RXSNR_B(phy_stat) \
  165. le32_get_bits(*((__le32 *)(phy_stat) + 0x06), GENMASK(15, 8))
  166. #define REG_SYS_CTRL 0x000
  167. #define BIT_FEN_EN BIT(26)
  168. #define REG_INIRTS_RATE_SEL 0x0480
  169. #define REG_HTSTFWT 0x800
  170. #define REG_RXPSEL 0x808
  171. #define BIT_RX_PSEL_RST (BIT(28) | BIT(29))
  172. #define REG_TXPSEL 0x80c
  173. #define REG_RXCCAMSK 0x814
  174. #define REG_CCASEL 0x82c
  175. #define REG_PDMFTH 0x830
  176. #define REG_CCA2ND 0x838
  177. #define REG_L1WT 0x83c
  178. #define REG_L1PKWT 0x840
  179. #define REG_MRC 0x850
  180. #define REG_CLKTRK 0x860
  181. #define REG_ADCCLK 0x8ac
  182. #define REG_ADC160 0x8c4
  183. #define REG_ADC40 0x8c8
  184. #define REG_CHFIR 0x8f0
  185. #define REG_CDDTXP 0x93c
  186. #define REG_TXPSEL1 0x940
  187. #define REG_ACBB0 0x948
  188. #define REG_ACBBRXFIR 0x94c
  189. #define REG_ACGG2TBL 0x958
  190. #define REG_FAS 0x9a4
  191. #define REG_RXSB 0xa00
  192. #define REG_ADCINI 0xa04
  193. #define REG_PWRTH 0xa08
  194. #define REG_TXSF2 0xa24
  195. #define REG_TXSF6 0xa28
  196. #define REG_FA_CCK 0xa5c
  197. #define REG_RXDESC 0xa2c
  198. #define REG_ENTXCCK 0xa80
  199. #define BTG_LNA 0xfc84
  200. #define WLG_LNA 0x7532
  201. #define REG_ENRXCCA 0xa84
  202. #define BTG_CCA 0x0e
  203. #define WLG_CCA 0x12
  204. #define REG_PWRTH2 0xaa8
  205. #define REG_CSRATIO 0xaaa
  206. #define REG_TXFILTER 0xaac
  207. #define REG_CNTRST 0xb58
  208. #define REG_AGCTR_A 0xc08
  209. #define REG_TXSCALE_A 0xc1c
  210. #define REG_TXDFIR 0xc20
  211. #define REG_RXIGI_A 0xc50
  212. #define REG_TXAGCIDX 0xc94
  213. #define REG_TRSW 0xca0
  214. #define REG_RFESEL0 0xcb0
  215. #define REG_RFESEL8 0xcb4
  216. #define REG_RFECTL 0xcb8
  217. #define B_BTG_SWITCH BIT(16)
  218. #define B_CTRL_SWITCH BIT(18)
  219. #define B_WL_SWITCH (BIT(20) | BIT(22))
  220. #define B_WLG_SWITCH BIT(21)
  221. #define B_WLA_SWITCH BIT(23)
  222. #define REG_RFEINV 0xcbc
  223. #define REG_AGCTR_B 0xe08
  224. #define REG_RXIGI_B 0xe50
  225. #define REG_CRC_CCK 0xf04
  226. #define REG_CRC_OFDM 0xf14
  227. #define REG_CRC_HT 0xf10
  228. #define REG_CRC_VHT 0xf0c
  229. #define REG_CCA_OFDM 0xf08
  230. #define REG_FA_OFDM 0xf48
  231. #define REG_CCA_CCK 0xfcc
  232. #define REG_DMEM_CTRL 0x1080
  233. #define BIT_WL_RST BIT(16)
  234. #define REG_ANTWT 0x1904
  235. #define REG_IQKFAILMSK 0x1bf0
  236. #define BIT_MASK_R_RFE_SEL_15 GENMASK(31, 28)
  237. #define BIT_SDIO_INT BIT(18)
  238. #define BT_CNT_ENABLE 0x1
  239. #define BIT_BCN_QUEUE BIT(3)
  240. #define BCN_PRI_EN 0x1
  241. #define PTA_CTRL_PIN 0x66
  242. #define DPDT_CTRL_PIN 0x77
  243. #define ANTDIC_CTRL_PIN 0x88
  244. #define REG_CTRL_TYPE 0x67
  245. #define BIT_CTRL_TYPE1 BIT(5)
  246. #define BIT_CTRL_TYPE2 BIT(4)
  247. #define CTRL_TYPE_MASK GENMASK(15, 8)
  248. #define RF18_BAND_MASK (BIT(16) | BIT(9) | BIT(8))
  249. #define RF18_BAND_2G (0)
  250. #define RF18_BAND_5G (BIT(16) | BIT(8))
  251. #define RF18_CHANNEL_MASK (MASKBYTE0)
  252. #define RF18_RFSI_MASK (BIT(18) | BIT(17))
  253. #define RF18_RFSI_GE (BIT(17))
  254. #define RF18_RFSI_GT (BIT(18))
  255. #define RF18_BW_MASK (BIT(11) | BIT(10))
  256. #define RF18_BW_20M (BIT(11) | BIT(10))
  257. #define RF18_BW_40M (BIT(11))
  258. #define RF18_BW_80M (BIT(10))
  259. #endif