Skip to content

Commit 19a954e

Browse files
Peter Chiunbd168
authored andcommitted
wifi: mt76: mt7915: add mt7986, mt7916 and mt7981 pre-calibration
Add pre-calibration for mt7986 and mt7916. It has different data size with mt7915. Group cal needs 54k and 94k for 2G + 5G and 2G + 6G, respectively. DPD cal needs 300k. Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com> Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com> Signed-off-by: Felix Fietkau <nbd@nbd.name>
1 parent 196f6a9 commit 19a954e

File tree

4 files changed

+147
-33
lines changed

4 files changed

+147
-33
lines changed

drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,26 @@ static int mt7915_eeprom_load_precal(struct mt7915_dev *dev)
99
{
1010
struct mt76_dev *mdev = &dev->mt76;
1111
u8 *eeprom = mdev->eeprom.data;
12-
u32 val = eeprom[MT_EE_DO_PRE_CAL];
13-
u32 offs;
12+
u32 offs = is_mt7915(&dev->mt76) ? MT_EE_DO_PRE_CAL : MT_EE_DO_PRE_CAL_V2;
13+
u32 size, val = eeprom[offs];
1414
int ret;
1515

16-
if (!dev->flash_mode)
16+
if (!dev->flash_mode || !val)
1717
return 0;
1818

19-
if (val != (MT_EE_WIFI_CAL_DPD | MT_EE_WIFI_CAL_GROUP))
20-
return 0;
19+
size = mt7915_get_cal_group_size(dev) + mt7915_get_cal_dpd_size(dev);
2120

22-
val = MT_EE_CAL_GROUP_SIZE + MT_EE_CAL_DPD_SIZE;
23-
dev->cal = devm_kzalloc(mdev->dev, val, GFP_KERNEL);
21+
dev->cal = devm_kzalloc(mdev->dev, size, GFP_KERNEL);
2422
if (!dev->cal)
2523
return -ENOMEM;
2624

2725
offs = is_mt7915(&dev->mt76) ? MT_EE_PRECAL : MT_EE_PRECAL_V2;
2826

29-
ret = mt76_get_of_data_from_mtd(mdev, dev->cal, offs, val);
27+
ret = mt76_get_of_data_from_mtd(mdev, dev->cal, offs, size);
3028
if (!ret)
3129
return ret;
3230

33-
return mt76_get_of_data_from_nvmem(mdev, dev->cal, "precal", val);
31+
return mt76_get_of_data_from_nvmem(mdev, dev->cal, "precal", size);
3432
}
3533

3634
static int mt7915_check_eeprom(struct mt7915_dev *dev)

drivers/net/wireless/mediatek/mt76/mt7915/eeprom.h

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ enum mt7915_eeprom_field {
1919
MT_EE_DDIE_FT_VERSION = 0x050,
2020
MT_EE_DO_PRE_CAL = 0x062,
2121
MT_EE_WIFI_CONF = 0x190,
22+
MT_EE_DO_PRE_CAL_V2 = 0x19a,
2223
MT_EE_RATE_DELTA_2G = 0x252,
2324
MT_EE_RATE_DELTA_5G = 0x29d,
2425
MT_EE_TX0_POWER_2G = 0x2fc,
@@ -39,10 +40,19 @@ enum mt7915_eeprom_field {
3940
};
4041

4142
#define MT_EE_WIFI_CAL_GROUP BIT(0)
42-
#define MT_EE_WIFI_CAL_DPD GENMASK(2, 1)
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)
4347
#define MT_EE_CAL_UNIT 1024
44-
#define MT_EE_CAL_GROUP_SIZE (49 * MT_EE_CAL_UNIT + 16)
45-
#define MT_EE_CAL_DPD_SIZE (54 * MT_EE_CAL_UNIT)
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 */
4656

4757
#define MT_EE_WIFI_CONF0_TX_PATH GENMASK(2, 0)
4858
#define MT_EE_WIFI_CONF0_BAND_SEL GENMASK(7, 6)
@@ -156,6 +166,37 @@ mt7915_tssi_enabled(struct mt7915_dev *dev, enum nl80211_band band)
156166
return val & MT_EE_WIFI_CONF7_TSSI0_5G;
157167
}
158168

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+
159200
extern const u8 mt7915_sku_group_len[MAX_SKU_RATE_GROUP_NUM];
160201

161202
#endif

drivers/net/wireless/mediatek/mt76/mt7915/mcu.c

Lines changed: 92 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,9 +2903,10 @@ static int mt7915_mcu_set_pre_cal(struct mt7915_dev *dev, u8 idx,
29032903
int mt7915_mcu_apply_group_cal(struct mt7915_dev *dev)
29042904
{
29052905
u8 idx = 0, *cal = dev->cal, *eep = dev->mt76.eeprom.data;
2906-
u32 total = MT_EE_CAL_GROUP_SIZE;
2906+
u32 total = mt7915_get_cal_group_size(dev);
2907+
u32 offs = is_mt7915(&dev->mt76) ? MT_EE_DO_PRE_CAL : MT_EE_DO_PRE_CAL_V2;
29072908

2908-
if (!(eep[MT_EE_DO_PRE_CAL] & MT_EE_WIFI_CAL_GROUP))
2909+
if (!(eep[offs] & MT_EE_WIFI_CAL_GROUP))
29092910
return 0;
29102911

29112912
/*
@@ -2941,75 +2942,145 @@ static int mt7915_find_freq_idx(const u16 *freqs, int n_freqs, u16 cur)
29412942
return -1;
29422943
}
29432944

2944-
static int mt7915_dpd_freq_idx(u16 freq, u8 bw)
2945+
static int mt7915_dpd_freq_idx(struct mt7915_dev *dev, u16 freq, u8 bw)
29452946
{
2946-
static const u16 freq_list[] = {
2947+
static const u16 freq_list_v1[] = {
29472948
5180, 5200, 5220, 5240,
29482949
5260, 5280, 5300, 5320,
29492950
5500, 5520, 5540, 5560,
29502951
5580, 5600, 5620, 5640,
29512952
5660, 5680, 5700, 5745,
29522953
5765, 5785, 5805, 5825
29532954
};
2954-
int offset_2g = ARRAY_SIZE(freq_list);
2955+
static const u16 freq_list_v2[] = {
2956+
/* 6G BW20*/
2957+
5955, 5975, 5995, 6015,
2958+
6035, 6055, 6075, 6095,
2959+
6115, 6135, 6155, 6175,
2960+
6195, 6215, 6235, 6255,
2961+
6275, 6295, 6315, 6335,
2962+
6355, 6375, 6395, 6415,
2963+
6435, 6455, 6475, 6495,
2964+
6515, 6535, 6555, 6575,
2965+
6595, 6615, 6635, 6655,
2966+
6675, 6695, 6715, 6735,
2967+
6755, 6775, 6795, 6815,
2968+
6835, 6855, 6875, 6895,
2969+
6915, 6935, 6955, 6975,
2970+
6995, 7015, 7035, 7055,
2971+
7075, 7095, 7115,
2972+
/* 6G BW160 */
2973+
6025, 6185, 6345, 6505,
2974+
6665, 6825, 6985,
2975+
/* 5G BW20 */
2976+
5180, 5200, 5220, 5240,
2977+
5260, 5280, 5300, 5320,
2978+
5500, 5520, 5540, 5560,
2979+
5580, 5600, 5620, 5640,
2980+
5660, 5680, 5700, 5720,
2981+
5745, 5765, 5785, 5805,
2982+
5825, 5845, 5865, 5885,
2983+
/* 5G BW160 */
2984+
5250, 5570, 5815
2985+
};
2986+
static const u16 freq_list_v2_7981[] = {
2987+
/* 5G BW20 */
2988+
5180, 5200, 5220, 5240,
2989+
5260, 5280, 5300, 5320,
2990+
5500, 5520, 5540, 5560,
2991+
5580, 5600, 5620, 5640,
2992+
5660, 5680, 5700, 5720,
2993+
5745, 5765, 5785, 5805,
2994+
5825, 5845, 5865, 5885,
2995+
/* 5G BW160 */
2996+
5250, 5570, 5815
2997+
};
2998+
const u16 *freq_list = freq_list_v1;
2999+
int n_freqs = ARRAY_SIZE(freq_list_v1);
29553000
int idx;
29563001

3002+
if (!is_mt7915(&dev->mt76)) {
3003+
if (is_mt7981(&dev->mt76)) {
3004+
freq_list = freq_list_v2_7981;
3005+
n_freqs = ARRAY_SIZE(freq_list_v2_7981);
3006+
} else {
3007+
freq_list = freq_list_v2;
3008+
n_freqs = ARRAY_SIZE(freq_list_v2);
3009+
}
3010+
}
3011+
29573012
if (freq < 4000) {
29583013
if (freq < 2432)
2959-
return offset_2g;
3014+
return n_freqs;
29603015
if (freq < 2457)
2961-
return offset_2g + 1;
3016+
return n_freqs + 1;
29623017

2963-
return offset_2g + 2;
3018+
return n_freqs + 2;
29643019
}
29653020

2966-
if (bw == NL80211_CHAN_WIDTH_80P80 || bw == NL80211_CHAN_WIDTH_160)
3021+
if (bw == NL80211_CHAN_WIDTH_80P80)
29673022
return -1;
29683023

29693024
if (bw != NL80211_CHAN_WIDTH_20) {
2970-
idx = mt7915_find_freq_idx(freq_list, ARRAY_SIZE(freq_list),
2971-
freq + 10);
3025+
idx = mt7915_find_freq_idx(freq_list, n_freqs, freq + 10);
29723026
if (idx >= 0)
29733027
return idx;
29743028

2975-
idx = mt7915_find_freq_idx(freq_list, ARRAY_SIZE(freq_list),
2976-
freq - 10);
3029+
idx = mt7915_find_freq_idx(freq_list, n_freqs, freq - 10);
29773030
if (idx >= 0)
29783031
return idx;
29793032
}
29803033

2981-
return mt7915_find_freq_idx(freq_list, ARRAY_SIZE(freq_list), freq);
3034+
return mt7915_find_freq_idx(freq_list, n_freqs, freq);
29823035
}
29833036

29843037
int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy)
29853038
{
29863039
struct mt7915_dev *dev = phy->dev;
29873040
struct cfg80211_chan_def *chandef = &phy->mt76->chandef;
2988-
u16 total = 2, center_freq = chandef->center_freq1;
3041+
enum nl80211_band band = chandef->chan->band;
3042+
u32 offs = is_mt7915(&dev->mt76) ? MT_EE_DO_PRE_CAL : MT_EE_DO_PRE_CAL_V2;
3043+
u16 center_freq = chandef->center_freq1;
29893044
u8 *cal = dev->cal, *eep = dev->mt76.eeprom.data;
3045+
u8 dpd_mask, cal_num = is_mt7915(&dev->mt76) ? 2 : 3;
29903046
int idx;
29913047

2992-
if (!(eep[MT_EE_DO_PRE_CAL] & MT_EE_WIFI_CAL_DPD))
3048+
switch (band) {
3049+
case NL80211_BAND_2GHZ:
3050+
dpd_mask = MT_EE_WIFI_CAL_DPD_2G;
3051+
break;
3052+
case NL80211_BAND_5GHZ:
3053+
dpd_mask = MT_EE_WIFI_CAL_DPD_5G;
3054+
break;
3055+
case NL80211_BAND_6GHZ:
3056+
dpd_mask = MT_EE_WIFI_CAL_DPD_6G;
3057+
break;
3058+
default:
3059+
dpd_mask = 0;
3060+
break;
3061+
}
3062+
3063+
if (!(eep[offs] & dpd_mask))
29933064
return 0;
29943065

2995-
idx = mt7915_dpd_freq_idx(center_freq, chandef->width);
3066+
idx = mt7915_dpd_freq_idx(dev, center_freq, chandef->width);
29963067
if (idx < 0)
29973068
return -EINVAL;
29983069

29993070
/* Items: Tx DPD, Tx Flatness */
3000-
idx = idx * 2;
3001-
cal += MT_EE_CAL_GROUP_SIZE;
3071+
idx = idx * cal_num;
3072+
cal += mt7915_get_cal_group_size(dev) + (idx * MT_EE_CAL_UNIT);
30023073

3003-
while (total--) {
3074+
while (cal_num--) {
30043075
int ret;
30053076

3006-
cal += (idx * MT_EE_CAL_UNIT);
30073077
ret = mt7915_mcu_set_pre_cal(dev, idx, cal, MT_EE_CAL_UNIT,
30083078
MCU_EXT_CMD(DPD_PRE_CAL_INFO));
30093079
if (ret)
30103080
return ret;
30113081

30123082
idx++;
3083+
cal += MT_EE_CAL_UNIT;
30133084
}
30143085

30153086
return 0;

drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ struct mt7915_dev {
302302
struct rchan *relay_fwlog;
303303

304304
void *cal;
305+
u32 cur_prek_offset;
306+
u8 dpd_chan_num_2g;
307+
u8 dpd_chan_num_5g;
308+
u8 dpd_chan_num_6g;
305309

306310
struct {
307311
u8 debug_wm;

0 commit comments

Comments
 (0)