1 /* SPDX-License-Identifier: ISC */ 2 /* Copyright (C) 2020 MediaTek Inc. */ 3 4 #ifndef __MT7915_EEPROM_H 5 #define __MT7915_EEPROM_H 6 7 #include "mt7915.h" 8 9 struct cal_data { 10 u8 count; 11 u16 offset[60]; 12 }; 13 14 enum mt7915_eeprom_field { 15 MT_EE_CHIP_ID = 0x000, 16 MT_EE_VERSION = 0x002, 17 MT_EE_MAC_ADDR = 0x004, 18 MT_EE_MAC_ADDR2 = 0x00a, 19 MT_EE_DDIE_FT_VERSION = 0x050, 20 MT_EE_DO_PRE_CAL = 0x062, 21 MT_EE_WIFI_CONF = 0x190, 22 MT_EE_DO_PRE_CAL_V2 = 0x19a, 23 MT_EE_RATE_DELTA_2G = 0x252, 24 MT_EE_RATE_DELTA_5G = 0x29d, 25 MT_EE_TX0_POWER_2G = 0x2fc, 26 MT_EE_TX0_POWER_5G = 0x34b, 27 MT_EE_RATE_DELTA_2G_V2 = 0x7d3, 28 MT_EE_RATE_DELTA_5G_V2 = 0x81e, 29 MT_EE_RATE_DELTA_6G_V2 = 0x884, /* 6g fields only appear in eeprom v2 */ 30 MT_EE_TX0_POWER_2G_V2 = 0x441, 31 MT_EE_TX0_POWER_5G_V2 = 0x445, 32 MT_EE_TX0_POWER_6G_V2 = 0x465, 33 MT_EE_ADIE_FT_VERSION = 0x9a0, 34 35 __MT_EE_MAX = 0xe00, 36 __MT_EE_MAX_V2 = 0x1000, 37 /* 0xe10 ~ 0x5780 used to save group cal data */ 38 MT_EE_PRECAL = 0xe10, 39 MT_EE_PRECAL_V2 = 0x1010 40 }; 41 42 #define MT_EE_WIFI_CAL_GROUP BIT(0) 43 #define MT_EE_WIFI_CAL_DPD_2G BIT(2) 44 #define MT_EE_WIFI_CAL_DPD_5G BIT(1) 45 #define MT_EE_WIFI_CAL_DPD_6G BIT(3) 46 #define MT_EE_WIFI_CAL_DPD GENMASK(3, 1) 47 #define MT_EE_CAL_UNIT 1024 48 #define MT_EE_CAL_GROUP_SIZE_7915 (49 * MT_EE_CAL_UNIT + 16) 49 #define MT_EE_CAL_GROUP_SIZE_7916 (54 * MT_EE_CAL_UNIT + 16) 50 #define MT_EE_CAL_GROUP_SIZE_7975 (54 * MT_EE_CAL_UNIT + 16) 51 #define MT_EE_CAL_GROUP_SIZE_7976 (94 * MT_EE_CAL_UNIT + 16) 52 #define MT_EE_CAL_GROUP_SIZE_7916_6G (94 * MT_EE_CAL_UNIT + 16) 53 #define MT_EE_CAL_DPD_SIZE_V1 (54 * MT_EE_CAL_UNIT) 54 #define MT_EE_CAL_DPD_SIZE_V2 (300 * MT_EE_CAL_UNIT) 55 #define MT_EE_CAL_DPD_SIZE_V2_7981 (102 * MT_EE_CAL_UNIT) /* no 6g dpd data */ 56 57 #define MT_EE_WIFI_CONF0_TX_PATH GENMASK(2, 0) 58 #define MT_EE_WIFI_CONF0_BAND_SEL GENMASK(7, 6) 59 #define MT_EE_WIFI_CONF1_BAND_SEL GENMASK(7, 6) 60 #define MT_EE_WIFI_CONF_STREAM_NUM GENMASK(7, 5) 61 #define MT_EE_WIFI_CONF3_TX_PATH_B0 GENMASK(1, 0) 62 #define MT_EE_WIFI_CONF3_TX_PATH_B1 GENMASK(5, 4) 63 #define MT_EE_WIFI_CONF7_TSSI0_2G BIT(0) 64 #define MT_EE_WIFI_CONF7_TSSI0_5G BIT(2) 65 #define MT_EE_WIFI_CONF7_TSSI1_5G BIT(4) 66 67 #define MT_EE_RATE_DELTA_MASK GENMASK(5, 0) 68 #define MT_EE_RATE_DELTA_SIGN BIT(6) 69 #define MT_EE_RATE_DELTA_EN BIT(7) 70 71 enum mt7915_adie_sku { 72 MT7976_ONE_ADIE_DBDC = 0x7, 73 MT7975_ONE_ADIE = 0x8, 74 MT7976_ONE_ADIE = 0xa, 75 MT7975_DUAL_ADIE = 0xd, 76 MT7976_DUAL_ADIE = 0xf, 77 }; 78 79 enum mt7915_eeprom_band { 80 MT_EE_BAND_SEL_DEFAULT, 81 MT_EE_BAND_SEL_5GHZ, 82 MT_EE_BAND_SEL_2GHZ, 83 MT_EE_BAND_SEL_DUAL, 84 }; 85 86 enum { 87 MT_EE_V2_BAND_SEL_2GHZ, 88 MT_EE_V2_BAND_SEL_5GHZ, 89 MT_EE_V2_BAND_SEL_6GHZ, 90 MT_EE_V2_BAND_SEL_5GHZ_6GHZ, 91 }; 92 93 enum mt7915_sku_rate_group { 94 SKU_CCK, 95 SKU_OFDM, 96 SKU_HT_BW20, 97 SKU_HT_BW40, 98 SKU_VHT_BW20, 99 SKU_VHT_BW40, 100 SKU_VHT_BW80, 101 SKU_VHT_BW160, 102 SKU_HE_RU26, 103 SKU_HE_RU52, 104 SKU_HE_RU106, 105 SKU_HE_RU242, 106 SKU_HE_RU484, 107 SKU_HE_RU996, 108 SKU_HE_RU2x996, 109 MAX_SKU_RATE_GROUP_NUM, 110 }; 111 112 static inline int 113 mt7915_get_channel_group_5g(int channel, bool is_7976) 114 { 115 if (is_7976) { 116 if (channel <= 64) 117 return 0; 118 if (channel <= 96) 119 return 1; 120 if (channel <= 128) 121 return 2; 122 if (channel <= 144) 123 return 3; 124 return 4; 125 } 126 127 if (channel >= 184 && channel <= 196) 128 return 0; 129 if (channel <= 48) 130 return 1; 131 if (channel <= 64) 132 return 2; 133 if (channel <= 96) 134 return 3; 135 if (channel <= 112) 136 return 4; 137 if (channel <= 128) 138 return 5; 139 if (channel <= 144) 140 return 6; 141 return 7; 142 } 143 144 static inline int 145 mt7915_get_channel_group_6g(int channel) 146 { 147 if (channel <= 29) 148 return 0; 149 150 return DIV_ROUND_UP(channel - 29, 32); 151 } 152 153 static inline bool 154 mt7915_tssi_enabled(struct mt7915_dev *dev, enum nl80211_band band) 155 { 156 u8 *eep = dev->mt76.eeprom.data; 157 u8 offs = is_mt7981(&dev->mt76) ? 8 : 7; 158 u8 val = eep[MT_EE_WIFI_CONF + offs]; 159 160 if (band == NL80211_BAND_2GHZ) 161 return val & MT_EE_WIFI_CONF7_TSSI0_2G; 162 163 if (dev->dbdc_support) 164 return val & MT_EE_WIFI_CONF7_TSSI1_5G; 165 else 166 return val & MT_EE_WIFI_CONF7_TSSI0_5G; 167 } 168 169 static inline u32 170 mt7915_get_cal_group_size(struct mt7915_dev *dev) 171 { 172 u8 *eep = dev->mt76.eeprom.data; 173 u32 val; 174 175 if (is_mt7915(&dev->mt76)) { 176 return MT_EE_CAL_GROUP_SIZE_7915; 177 } else if (is_mt7916(&dev->mt76)) { 178 val = eep[MT_EE_WIFI_CONF + 1]; 179 val = FIELD_GET(MT_EE_WIFI_CONF0_BAND_SEL, val); 180 return (val == MT_EE_V2_BAND_SEL_6GHZ) ? MT_EE_CAL_GROUP_SIZE_7916_6G : 181 MT_EE_CAL_GROUP_SIZE_7916; 182 } else if (mt7915_check_adie(dev, false)) { 183 return MT_EE_CAL_GROUP_SIZE_7976; 184 } else { 185 return MT_EE_CAL_GROUP_SIZE_7975; 186 } 187 } 188 189 static inline u32 190 mt7915_get_cal_dpd_size(struct mt7915_dev *dev) 191 { 192 if (is_mt7915(&dev->mt76)) 193 return MT_EE_CAL_DPD_SIZE_V1; 194 else if (is_mt7981(&dev->mt76)) 195 return MT_EE_CAL_DPD_SIZE_V2_7981; 196 else 197 return MT_EE_CAL_DPD_SIZE_V2; 198 } 199 200 extern const u8 mt7915_sku_group_len[MAX_SKU_RATE_GROUP_NUM]; 201 202 #endif 203