blob: 6f2c7f718f227cedc3cd61ef1073eb700f49f621 [file] [log] [blame]
developerf9843e22022-09-13 10:57:15 +08001From e93d8124ef77ded639c54ee1f762982a06bc7bfc Mon Sep 17 00:00:00 2001
developerb1d08d22022-05-26 16:56:25 +08002From: Peter Chiu <chui-hao.chiu@mediatek.com>
3Date: Fri, 20 May 2022 19:19:25 +0800
developerf9843e22022-09-13 10:57:15 +08004Subject: [PATCH 1117/1124] mt76: mt7915: add mt7986 and mt7916 pre-calibration
developerb1d08d22022-05-26 16:56:25 +08005
6Add pre-calibration for mt7986 and mt7916. It has different data size
7with mt7915. Group cal needs 54k and 94k for 2G + 5G and 2G + 6G,
8respectively. DPD cal needs 300k.
9
10Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com>
11---
developer071927d2022-08-31 20:39:29 +080012 mt7915/eeprom.c | 15 +++++------
13 mt7915/eeprom.h | 1 +
14 mt7915/mcu.c | 72 ++++++++++++++++++++++++++++++++++++-------------
15 3 files changed, 62 insertions(+), 26 deletions(-)
developerb1d08d22022-05-26 16:56:25 +080016
17diff --git a/mt7915/eeprom.c b/mt7915/eeprom.c
developer071927d2022-08-31 20:39:29 +080018index 4b1a981..ee3049e 100644
developerb1d08d22022-05-26 16:56:25 +080019--- a/mt7915/eeprom.c
20+++ b/mt7915/eeprom.c
21@@ -9,23 +9,22 @@ static int mt7915_eeprom_load_precal(struct mt7915_dev *dev)
22 {
23 struct mt76_dev *mdev = &dev->mt76;
24 u8 *eeprom = mdev->eeprom.data;
25- u32 val = eeprom[MT_EE_DO_PRE_CAL];
26- u32 offs;
27+ u32 offs = is_mt7915(&dev->mt76) ? MT_EE_DO_PRE_CAL : MT_EE_DO_PRE_CAL_V2;
28+ u32 size, val = eeprom[offs];
29
30- if (!dev->flash_mode)
31+ if (!dev->flash_mode || !val)
32 return 0;
33
34- if (val != (MT_EE_WIFI_CAL_DPD | MT_EE_WIFI_CAL_GROUP))
35- return 0;
36+ size = mt7915_get_cal_group_size(dev) +
37+ (is_mt7915(&dev->mt76) ? MT_EE_CAL_DPD_SIZE_V1 : MT_EE_CAL_DPD_SIZE_V2);
38
39- val = MT_EE_CAL_GROUP_SIZE + MT_EE_CAL_DPD_SIZE;
40- dev->cal = devm_kzalloc(mdev->dev, val, GFP_KERNEL);
41+ dev->cal = devm_kzalloc(mdev->dev, size, GFP_KERNEL);
42 if (!dev->cal)
43 return -ENOMEM;
44
45 offs = is_mt7915(&dev->mt76) ? MT_EE_PRECAL : MT_EE_PRECAL_V2;
46
47- return mt76_get_of_eeprom(mdev, dev->cal, offs, val);
48+ return mt76_get_of_eeprom(mdev, dev->cal, offs, size);
49 }
50
51 static int mt7915_check_eeprom(struct mt7915_dev *dev)
52diff --git a/mt7915/eeprom.h b/mt7915/eeprom.h
developer071927d2022-08-31 20:39:29 +080053index b980342..fb9fbfe 100644
developerb1d08d22022-05-26 16:56:25 +080054--- a/mt7915/eeprom.h
55+++ b/mt7915/eeprom.h
56@@ -19,6 +19,7 @@ enum mt7915_eeprom_field {
57 MT_EE_DDIE_FT_VERSION = 0x050,
58 MT_EE_DO_PRE_CAL = 0x062,
59 MT_EE_WIFI_CONF = 0x190,
60+ MT_EE_DO_PRE_CAL_V2 = 0x19a,
61 MT_EE_RATE_DELTA_2G = 0x252,
62 MT_EE_RATE_DELTA_5G = 0x29d,
63 MT_EE_TX0_POWER_2G = 0x2fc,
developerb1d08d22022-05-26 16:56:25 +080064diff --git a/mt7915/mcu.c b/mt7915/mcu.c
developer071927d2022-08-31 20:39:29 +080065index eb53095..9d1dea2 100644
developerb1d08d22022-05-26 16:56:25 +080066--- a/mt7915/mcu.c
67+++ b/mt7915/mcu.c
developer071927d2022-08-31 20:39:29 +080068@@ -2926,7 +2926,8 @@ static int mt7915_mcu_set_pre_cal(struct mt7915_dev *dev, u8 idx,
developerb1d08d22022-05-26 16:56:25 +080069 int mt7915_mcu_apply_group_cal(struct mt7915_dev *dev)
70 {
71 u8 idx = 0, *cal = dev->cal, *eep = dev->mt76.eeprom.data;
72- u32 total = MT_EE_CAL_GROUP_SIZE;
73+ u32 total = mt7915_get_cal_group_size(dev);
74+ u32 offs = is_mt7915(&dev->mt76) ? MT_EE_DO_PRE_CAL : MT_EE_DO_PRE_CAL_V2;
75
developer071927d2022-08-31 20:39:29 +080076 if (!(eep[offs] & MT_EE_WIFI_CAL_GROUP))
developerb1d08d22022-05-26 16:56:25 +080077 return 0;
developer071927d2022-08-31 20:39:29 +080078@@ -2964,9 +2965,9 @@ static int mt7915_find_freq_idx(const u16 *freqs, int n_freqs, u16 cur)
developerb1d08d22022-05-26 16:56:25 +080079 return -1;
80 }
81
82-static int mt7915_dpd_freq_idx(u16 freq, u8 bw)
83+static int mt7915_dpd_freq_idx(struct mt7915_dev *dev, u16 freq, u8 bw)
84 {
85- static const u16 freq_list[] = {
developer071927d2022-08-31 20:39:29 +080086+ const u16 freq_list_v1[] = {
developerb1d08d22022-05-26 16:56:25 +080087 5180, 5200, 5220, 5240,
88 5260, 5280, 5300, 5320,
89 5500, 5520, 5540, 5560,
developer071927d2022-08-31 20:39:29 +080090@@ -2974,34 +2975,69 @@ static int mt7915_dpd_freq_idx(u16 freq, u8 bw)
developerb1d08d22022-05-26 16:56:25 +080091 5660, 5680, 5700, 5745,
92 5765, 5785, 5805, 5825
93 };
94- int offset_2g = ARRAY_SIZE(freq_list);
developer071927d2022-08-31 20:39:29 +080095+ const u16 freq_list_v2[] = {
developerb1d08d22022-05-26 16:56:25 +080096+ /* 6G BW20*/
97+ 5955, 5975, 5995, 6015,
98+ 6035, 6055, 6075, 6095,
99+ 6115, 6135, 6155, 6175,
100+ 6195, 6215, 6235, 6255,
101+ 6275, 6295, 6315, 6335,
102+ 6355, 6375, 6395, 6415,
103+ 6435, 6455, 6475, 6495,
104+ 6515, 6535, 6555, 6575,
105+ 6595, 6615, 6635, 6655,
106+ 6675, 6695, 6715, 6735,
107+ 6755, 6775, 6795, 6815,
108+ 6835, 6855, 6875, 6895,
109+ 6915, 6935, 6955, 6975,
110+ 6995, 7015, 7035, 7055,
111+ 7075, 7095, 7115,
112+ /* 6G BW160 */
113+ 6025, 6185, 6345, 6505,
114+ 6665, 6825, 6985,
115+ /* 5G BW20 */
116+ 5180, 5200, 5220, 5240,
117+ 5260, 5280, 5300, 5320,
118+ 5500, 5520, 5540, 5560,
119+ 5580, 5600, 5620, 5640,
120+ 5660, 5680, 5700, 5720,
121+ 5745, 5765, 5785, 5805,
122+ 5825, 5845, 5865, 5885,
123+ /* 5G BW160 */
124+ 5250, 5570, 5815
125+ };
developer071927d2022-08-31 20:39:29 +0800126+ const u16 *freq_list = freq_list_v1;
developerb1d08d22022-05-26 16:56:25 +0800127+ int n_freqs = ARRAY_SIZE(freq_list_v1);
128 int idx;
129
130+ if (!is_mt7915(&dev->mt76)) {
131+ freq_list = freq_list_v2;
132+ n_freqs = ARRAY_SIZE(freq_list_v2);
133+ }
134+
135 if (freq < 4000) {
136 if (freq < 2432)
137- return offset_2g;
138+ return n_freqs;
139 if (freq < 2457)
140- return offset_2g + 1;
141+ return n_freqs + 1;
142
143- return offset_2g + 2;
144+ return n_freqs + 2;
145 }
146
147- if (bw == NL80211_CHAN_WIDTH_80P80 || bw == NL80211_CHAN_WIDTH_160)
148+ if (bw == NL80211_CHAN_WIDTH_80P80)
149 return -1;
150
151 if (bw != NL80211_CHAN_WIDTH_20) {
152- idx = mt7915_find_freq_idx(freq_list, ARRAY_SIZE(freq_list),
153- freq + 10);
154+ idx = mt7915_find_freq_idx(freq_list, n_freqs, freq + 10);
155 if (idx >= 0)
156 return idx;
157
158- idx = mt7915_find_freq_idx(freq_list, ARRAY_SIZE(freq_list),
159- freq - 10);
160+ idx = mt7915_find_freq_idx(freq_list, n_freqs, freq - 10);
161 if (idx >= 0)
162 return idx;
163 }
164
165- return mt7915_find_freq_idx(freq_list, ARRAY_SIZE(freq_list), freq);
166+ return mt7915_find_freq_idx(freq_list, n_freqs, freq);
167 }
168
169 int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy)
developer071927d2022-08-31 20:39:29 +0800170@@ -3033,24 +3069,24 @@ int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy)
171 if (!(eep[offs] & dpd_mask))
developerb1d08d22022-05-26 16:56:25 +0800172 return 0;
173
174- idx = mt7915_dpd_freq_idx(center_freq, chandef->width);
175+ idx = mt7915_dpd_freq_idx(dev, center_freq, chandef->width);
176 if (idx < 0)
177 return -EINVAL;
178
179 /* Items: Tx DPD, Tx Flatness */
180- idx = idx * 2;
181- cal += MT_EE_CAL_GROUP_SIZE;
182+ idx = idx * cal_num;
183+ cal += mt7915_get_cal_group_size(dev) + (idx * MT_EE_CAL_UNIT);
184
185- while (total--) {
186+ while (cal_num--) {
187 int ret;
188
189- cal += (idx * MT_EE_CAL_UNIT);
190 ret = mt7915_mcu_set_pre_cal(dev, idx, cal, MT_EE_CAL_UNIT,
191 MCU_EXT_CMD(DPD_PRE_CAL_INFO));
192 if (ret)
193 return ret;
194
195 idx++;
196+ cal += MT_EE_CAL_UNIT;
197 }
198
199 return 0;
200--
developer071927d2022-08-31 20:39:29 +08002012.18.0
developerb1d08d22022-05-26 16:56:25 +0800202