blob: 6f7204e75b856e5e56c0810a63a01f570c44ce4e [file] [log] [blame]
developer82d34062024-02-29 09:50:59 +08001From 5c93e5bf8cd5ae9eaa10fb1719614eb8d049e7bf Mon Sep 17 00:00:00 2001
developerb1d08d22022-05-26 16:56:25 +08002From: Peter Chiu <chui-hao.chiu@mediatek.com>
developer98601562023-12-13 10:44:32 +08003Date: Wed, 13 Dec 2023 09:55:27 +0800
developer82d34062024-02-29 09:50:59 +08004Subject: [PATCH 1016/1049] wifi: mt76: mt7915: add mt7986 and mt7916
developera72bbd82024-02-04 18:27:28 +08005 pre-calibration
developerb1d08d22022-05-26 16:56:25 +08006
7Add pre-calibration for mt7986 and mt7916. It has different data size
8with mt7915. Group cal needs 54k and 94k for 2G + 5G and 2G + 6G,
9respectively. DPD cal needs 300k.
10
11Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com>
developer98601562023-12-13 10:44:32 +080012Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
developerb1d08d22022-05-26 16:56:25 +080013---
developer98601562023-12-13 10:44:32 +080014 mt7915/eeprom.c | 17 ++++++------
developer071927d2022-08-31 20:39:29 +080015 mt7915/eeprom.h | 1 +
16 mt7915/mcu.c | 72 ++++++++++++++++++++++++++++++++++++-------------
developer98601562023-12-13 10:44:32 +080017 3 files changed, 63 insertions(+), 27 deletions(-)
developerb1d08d22022-05-26 16:56:25 +080018
19diff --git a/mt7915/eeprom.c b/mt7915/eeprom.c
developer82d34062024-02-29 09:50:59 +080020index 0441d91a..5e74b5ff 100644
developerb1d08d22022-05-26 16:56:25 +080021--- a/mt7915/eeprom.c
22+++ b/mt7915/eeprom.c
developer98601562023-12-13 10:44:32 +080023@@ -9,28 +9,27 @@ static int mt7915_eeprom_load_precal(struct mt7915_dev *dev)
developerb1d08d22022-05-26 16:56:25 +080024 {
25 struct mt76_dev *mdev = &dev->mt76;
26 u8 *eeprom = mdev->eeprom.data;
27- u32 val = eeprom[MT_EE_DO_PRE_CAL];
28- u32 offs;
29+ u32 offs = is_mt7915(&dev->mt76) ? MT_EE_DO_PRE_CAL : MT_EE_DO_PRE_CAL_V2;
30+ u32 size, val = eeprom[offs];
developer98601562023-12-13 10:44:32 +080031 int ret;
developerb1d08d22022-05-26 16:56:25 +080032
33- if (!dev->flash_mode)
34+ if (!dev->flash_mode || !val)
35 return 0;
36
37- if (val != (MT_EE_WIFI_CAL_DPD | MT_EE_WIFI_CAL_GROUP))
38- return 0;
39+ size = mt7915_get_cal_group_size(dev) +
40+ (is_mt7915(&dev->mt76) ? MT_EE_CAL_DPD_SIZE_V1 : MT_EE_CAL_DPD_SIZE_V2);
41
42- val = MT_EE_CAL_GROUP_SIZE + MT_EE_CAL_DPD_SIZE;
43- dev->cal = devm_kzalloc(mdev->dev, val, GFP_KERNEL);
44+ dev->cal = devm_kzalloc(mdev->dev, size, GFP_KERNEL);
45 if (!dev->cal)
46 return -ENOMEM;
47
48 offs = is_mt7915(&dev->mt76) ? MT_EE_PRECAL : MT_EE_PRECAL_V2;
49
developerade48b12023-12-12 10:37:24 +080050- ret = mt76_get_of_data_from_mtd(mdev, dev->cal, offs, val);
developer98601562023-12-13 10:44:32 +080051+ ret = mt76_get_of_data_from_mtd(mdev, dev->cal, offs, size);
52 if (!ret)
53 return ret;
54
developerade48b12023-12-12 10:37:24 +080055- return mt76_get_of_data_from_nvmem(mdev, dev->cal, "precal", val);
developer98601562023-12-13 10:44:32 +080056+ return mt76_get_of_data_from_nvmem(mdev, dev->cal, "precal", size);
developerb1d08d22022-05-26 16:56:25 +080057 }
58
59 static int mt7915_check_eeprom(struct mt7915_dev *dev)
60diff --git a/mt7915/eeprom.h b/mt7915/eeprom.h
developer82d34062024-02-29 09:50:59 +080061index 25f0b32a..4a313759 100644
developerb1d08d22022-05-26 16:56:25 +080062--- a/mt7915/eeprom.h
63+++ b/mt7915/eeprom.h
64@@ -19,6 +19,7 @@ enum mt7915_eeprom_field {
65 MT_EE_DDIE_FT_VERSION = 0x050,
66 MT_EE_DO_PRE_CAL = 0x062,
67 MT_EE_WIFI_CONF = 0x190,
68+ MT_EE_DO_PRE_CAL_V2 = 0x19a,
69 MT_EE_RATE_DELTA_2G = 0x252,
70 MT_EE_RATE_DELTA_5G = 0x29d,
71 MT_EE_TX0_POWER_2G = 0x2fc,
developerb1d08d22022-05-26 16:56:25 +080072diff --git a/mt7915/mcu.c b/mt7915/mcu.c
developer82d34062024-02-29 09:50:59 +080073index 1707aaf7..b21d888b 100644
developerb1d08d22022-05-26 16:56:25 +080074--- a/mt7915/mcu.c
75+++ b/mt7915/mcu.c
developera72bbd82024-02-04 18:27:28 +080076@@ -3044,7 +3044,8 @@ static int mt7915_mcu_set_pre_cal(struct mt7915_dev *dev, u8 idx,
developerb1d08d22022-05-26 16:56:25 +080077 int mt7915_mcu_apply_group_cal(struct mt7915_dev *dev)
78 {
79 u8 idx = 0, *cal = dev->cal, *eep = dev->mt76.eeprom.data;
80- u32 total = MT_EE_CAL_GROUP_SIZE;
81+ u32 total = mt7915_get_cal_group_size(dev);
82+ u32 offs = is_mt7915(&dev->mt76) ? MT_EE_DO_PRE_CAL : MT_EE_DO_PRE_CAL_V2;
83
developer071927d2022-08-31 20:39:29 +080084 if (!(eep[offs] & MT_EE_WIFI_CAL_GROUP))
developerb1d08d22022-05-26 16:56:25 +080085 return 0;
developera72bbd82024-02-04 18:27:28 +080086@@ -3082,9 +3083,9 @@ static int mt7915_find_freq_idx(const u16 *freqs, int n_freqs, u16 cur)
developerb1d08d22022-05-26 16:56:25 +080087 return -1;
88 }
89
90-static int mt7915_dpd_freq_idx(u16 freq, u8 bw)
91+static int mt7915_dpd_freq_idx(struct mt7915_dev *dev, u16 freq, u8 bw)
92 {
93- static const u16 freq_list[] = {
developer071927d2022-08-31 20:39:29 +080094+ const u16 freq_list_v1[] = {
developerb1d08d22022-05-26 16:56:25 +080095 5180, 5200, 5220, 5240,
96 5260, 5280, 5300, 5320,
97 5500, 5520, 5540, 5560,
developera72bbd82024-02-04 18:27:28 +080098@@ -3092,34 +3093,69 @@ static int mt7915_dpd_freq_idx(u16 freq, u8 bw)
developerb1d08d22022-05-26 16:56:25 +080099 5660, 5680, 5700, 5745,
100 5765, 5785, 5805, 5825
101 };
102- int offset_2g = ARRAY_SIZE(freq_list);
developer071927d2022-08-31 20:39:29 +0800103+ const u16 freq_list_v2[] = {
developerb1d08d22022-05-26 16:56:25 +0800104+ /* 6G BW20*/
105+ 5955, 5975, 5995, 6015,
106+ 6035, 6055, 6075, 6095,
107+ 6115, 6135, 6155, 6175,
108+ 6195, 6215, 6235, 6255,
109+ 6275, 6295, 6315, 6335,
110+ 6355, 6375, 6395, 6415,
111+ 6435, 6455, 6475, 6495,
112+ 6515, 6535, 6555, 6575,
113+ 6595, 6615, 6635, 6655,
114+ 6675, 6695, 6715, 6735,
115+ 6755, 6775, 6795, 6815,
116+ 6835, 6855, 6875, 6895,
117+ 6915, 6935, 6955, 6975,
118+ 6995, 7015, 7035, 7055,
119+ 7075, 7095, 7115,
120+ /* 6G BW160 */
121+ 6025, 6185, 6345, 6505,
122+ 6665, 6825, 6985,
123+ /* 5G BW20 */
124+ 5180, 5200, 5220, 5240,
125+ 5260, 5280, 5300, 5320,
126+ 5500, 5520, 5540, 5560,
127+ 5580, 5600, 5620, 5640,
128+ 5660, 5680, 5700, 5720,
129+ 5745, 5765, 5785, 5805,
130+ 5825, 5845, 5865, 5885,
131+ /* 5G BW160 */
132+ 5250, 5570, 5815
133+ };
developer071927d2022-08-31 20:39:29 +0800134+ const u16 *freq_list = freq_list_v1;
developerb1d08d22022-05-26 16:56:25 +0800135+ int n_freqs = ARRAY_SIZE(freq_list_v1);
136 int idx;
137
138+ if (!is_mt7915(&dev->mt76)) {
139+ freq_list = freq_list_v2;
140+ n_freqs = ARRAY_SIZE(freq_list_v2);
141+ }
142+
143 if (freq < 4000) {
144 if (freq < 2432)
145- return offset_2g;
146+ return n_freqs;
147 if (freq < 2457)
148- return offset_2g + 1;
149+ return n_freqs + 1;
150
151- return offset_2g + 2;
152+ return n_freqs + 2;
153 }
154
155- if (bw == NL80211_CHAN_WIDTH_80P80 || bw == NL80211_CHAN_WIDTH_160)
156+ if (bw == NL80211_CHAN_WIDTH_80P80)
157 return -1;
158
159 if (bw != NL80211_CHAN_WIDTH_20) {
160- idx = mt7915_find_freq_idx(freq_list, ARRAY_SIZE(freq_list),
161- freq + 10);
162+ idx = mt7915_find_freq_idx(freq_list, n_freqs, freq + 10);
163 if (idx >= 0)
164 return idx;
165
166- idx = mt7915_find_freq_idx(freq_list, ARRAY_SIZE(freq_list),
167- freq - 10);
168+ idx = mt7915_find_freq_idx(freq_list, n_freqs, freq - 10);
169 if (idx >= 0)
170 return idx;
171 }
172
173- return mt7915_find_freq_idx(freq_list, ARRAY_SIZE(freq_list), freq);
174+ return mt7915_find_freq_idx(freq_list, n_freqs, freq);
175 }
176
177 int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy)
developera72bbd82024-02-04 18:27:28 +0800178@@ -3151,24 +3187,24 @@ int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy)
developer071927d2022-08-31 20:39:29 +0800179 if (!(eep[offs] & dpd_mask))
developerb1d08d22022-05-26 16:56:25 +0800180 return 0;
181
182- idx = mt7915_dpd_freq_idx(center_freq, chandef->width);
183+ idx = mt7915_dpd_freq_idx(dev, center_freq, chandef->width);
184 if (idx < 0)
185 return -EINVAL;
186
187 /* Items: Tx DPD, Tx Flatness */
188- idx = idx * 2;
189- cal += MT_EE_CAL_GROUP_SIZE;
190+ idx = idx * cal_num;
191+ cal += mt7915_get_cal_group_size(dev) + (idx * MT_EE_CAL_UNIT);
192
193- while (total--) {
194+ while (cal_num--) {
195 int ret;
196
197- cal += (idx * MT_EE_CAL_UNIT);
198 ret = mt7915_mcu_set_pre_cal(dev, idx, cal, MT_EE_CAL_UNIT,
199 MCU_EXT_CMD(DPD_PRE_CAL_INFO));
200 if (ret)
201 return ret;
202
203 idx++;
204+ cal += MT_EE_CAL_UNIT;
205 }
206
207 return 0;
208--
developer0443cd32023-09-19 14:11:49 +08002092.18.0
developerb1d08d22022-05-26 16:56:25 +0800210