blob: 0a2cb924d4c1db34ad597ebb868d8f8709042a64 [file] [log] [blame]
developerbbd45e12023-05-19 08:22:06 +08001From cd68747e751a5efef46b66675568ba16050d84d2 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
developerbbd45e12023-05-19 08:22:06 +08004Subject: [PATCH 1017/1033] wifi: mt76: mt7915: add mt7986 and mt7916
developerc9233442023-04-04 06:06:17 +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>
12---
developer071927d2022-08-31 20:39:29 +080013 mt7915/eeprom.c | 15 +++++------
14 mt7915/eeprom.h | 1 +
15 mt7915/mcu.c | 72 ++++++++++++++++++++++++++++++++++++-------------
16 3 files changed, 62 insertions(+), 26 deletions(-)
developerb1d08d22022-05-26 16:56:25 +080017
18diff --git a/mt7915/eeprom.c b/mt7915/eeprom.c
developerbbd45e12023-05-19 08:22:06 +080019index f5ab331..a5c99a5 100644
developerb1d08d22022-05-26 16:56:25 +080020--- a/mt7915/eeprom.c
21+++ b/mt7915/eeprom.c
22@@ -9,23 +9,22 @@ static int mt7915_eeprom_load_precal(struct mt7915_dev *dev)
23 {
24 struct mt76_dev *mdev = &dev->mt76;
25 u8 *eeprom = mdev->eeprom.data;
26- u32 val = eeprom[MT_EE_DO_PRE_CAL];
27- u32 offs;
28+ u32 offs = is_mt7915(&dev->mt76) ? MT_EE_DO_PRE_CAL : MT_EE_DO_PRE_CAL_V2;
29+ u32 size, val = eeprom[offs];
30
31- if (!dev->flash_mode)
32+ if (!dev->flash_mode || !val)
33 return 0;
34
35- if (val != (MT_EE_WIFI_CAL_DPD | MT_EE_WIFI_CAL_GROUP))
36- return 0;
37+ size = mt7915_get_cal_group_size(dev) +
38+ (is_mt7915(&dev->mt76) ? MT_EE_CAL_DPD_SIZE_V1 : MT_EE_CAL_DPD_SIZE_V2);
39
40- val = MT_EE_CAL_GROUP_SIZE + MT_EE_CAL_DPD_SIZE;
41- dev->cal = devm_kzalloc(mdev->dev, val, GFP_KERNEL);
42+ dev->cal = devm_kzalloc(mdev->dev, size, GFP_KERNEL);
43 if (!dev->cal)
44 return -ENOMEM;
45
46 offs = is_mt7915(&dev->mt76) ? MT_EE_PRECAL : MT_EE_PRECAL_V2;
47
48- return mt76_get_of_eeprom(mdev, dev->cal, offs, val);
49+ return mt76_get_of_eeprom(mdev, dev->cal, offs, size);
50 }
51
52 static int mt7915_check_eeprom(struct mt7915_dev *dev)
53diff --git a/mt7915/eeprom.h b/mt7915/eeprom.h
developer1d9da7d2023-04-15 12:45:34 +080054index 88aaa16..fdae347 100644
developerb1d08d22022-05-26 16:56:25 +080055--- a/mt7915/eeprom.h
56+++ b/mt7915/eeprom.h
57@@ -19,6 +19,7 @@ enum mt7915_eeprom_field {
58 MT_EE_DDIE_FT_VERSION = 0x050,
59 MT_EE_DO_PRE_CAL = 0x062,
60 MT_EE_WIFI_CONF = 0x190,
61+ MT_EE_DO_PRE_CAL_V2 = 0x19a,
62 MT_EE_RATE_DELTA_2G = 0x252,
63 MT_EE_RATE_DELTA_5G = 0x29d,
64 MT_EE_TX0_POWER_2G = 0x2fc,
developerb1d08d22022-05-26 16:56:25 +080065diff --git a/mt7915/mcu.c b/mt7915/mcu.c
developerbbd45e12023-05-19 08:22:06 +080066index bc28454..fcd07ed 100644
developerb1d08d22022-05-26 16:56:25 +080067--- a/mt7915/mcu.c
68+++ b/mt7915/mcu.c
developerbbd45e12023-05-19 08:22:06 +080069@@ -2903,7 +2903,8 @@ static int mt7915_mcu_set_pre_cal(struct mt7915_dev *dev, u8 idx,
developerb1d08d22022-05-26 16:56:25 +080070 int mt7915_mcu_apply_group_cal(struct mt7915_dev *dev)
71 {
72 u8 idx = 0, *cal = dev->cal, *eep = dev->mt76.eeprom.data;
73- u32 total = MT_EE_CAL_GROUP_SIZE;
74+ u32 total = mt7915_get_cal_group_size(dev);
75+ u32 offs = is_mt7915(&dev->mt76) ? MT_EE_DO_PRE_CAL : MT_EE_DO_PRE_CAL_V2;
76
developer071927d2022-08-31 20:39:29 +080077 if (!(eep[offs] & MT_EE_WIFI_CAL_GROUP))
developerb1d08d22022-05-26 16:56:25 +080078 return 0;
developerbbd45e12023-05-19 08:22:06 +080079@@ -2941,9 +2942,9 @@ static int mt7915_find_freq_idx(const u16 *freqs, int n_freqs, u16 cur)
developerb1d08d22022-05-26 16:56:25 +080080 return -1;
81 }
82
83-static int mt7915_dpd_freq_idx(u16 freq, u8 bw)
84+static int mt7915_dpd_freq_idx(struct mt7915_dev *dev, u16 freq, u8 bw)
85 {
86- static const u16 freq_list[] = {
developer071927d2022-08-31 20:39:29 +080087+ const u16 freq_list_v1[] = {
developerb1d08d22022-05-26 16:56:25 +080088 5180, 5200, 5220, 5240,
89 5260, 5280, 5300, 5320,
90 5500, 5520, 5540, 5560,
developerbbd45e12023-05-19 08:22:06 +080091@@ -2951,34 +2952,69 @@ static int mt7915_dpd_freq_idx(u16 freq, u8 bw)
developerb1d08d22022-05-26 16:56:25 +080092 5660, 5680, 5700, 5745,
93 5765, 5785, 5805, 5825
94 };
95- int offset_2g = ARRAY_SIZE(freq_list);
developer071927d2022-08-31 20:39:29 +080096+ const u16 freq_list_v2[] = {
developerb1d08d22022-05-26 16:56:25 +080097+ /* 6G BW20*/
98+ 5955, 5975, 5995, 6015,
99+ 6035, 6055, 6075, 6095,
100+ 6115, 6135, 6155, 6175,
101+ 6195, 6215, 6235, 6255,
102+ 6275, 6295, 6315, 6335,
103+ 6355, 6375, 6395, 6415,
104+ 6435, 6455, 6475, 6495,
105+ 6515, 6535, 6555, 6575,
106+ 6595, 6615, 6635, 6655,
107+ 6675, 6695, 6715, 6735,
108+ 6755, 6775, 6795, 6815,
109+ 6835, 6855, 6875, 6895,
110+ 6915, 6935, 6955, 6975,
111+ 6995, 7015, 7035, 7055,
112+ 7075, 7095, 7115,
113+ /* 6G BW160 */
114+ 6025, 6185, 6345, 6505,
115+ 6665, 6825, 6985,
116+ /* 5G BW20 */
117+ 5180, 5200, 5220, 5240,
118+ 5260, 5280, 5300, 5320,
119+ 5500, 5520, 5540, 5560,
120+ 5580, 5600, 5620, 5640,
121+ 5660, 5680, 5700, 5720,
122+ 5745, 5765, 5785, 5805,
123+ 5825, 5845, 5865, 5885,
124+ /* 5G BW160 */
125+ 5250, 5570, 5815
126+ };
developer071927d2022-08-31 20:39:29 +0800127+ const u16 *freq_list = freq_list_v1;
developerb1d08d22022-05-26 16:56:25 +0800128+ int n_freqs = ARRAY_SIZE(freq_list_v1);
129 int idx;
130
131+ if (!is_mt7915(&dev->mt76)) {
132+ freq_list = freq_list_v2;
133+ n_freqs = ARRAY_SIZE(freq_list_v2);
134+ }
135+
136 if (freq < 4000) {
137 if (freq < 2432)
138- return offset_2g;
139+ return n_freqs;
140 if (freq < 2457)
141- return offset_2g + 1;
142+ return n_freqs + 1;
143
144- return offset_2g + 2;
145+ return n_freqs + 2;
146 }
147
148- if (bw == NL80211_CHAN_WIDTH_80P80 || bw == NL80211_CHAN_WIDTH_160)
149+ if (bw == NL80211_CHAN_WIDTH_80P80)
150 return -1;
151
152 if (bw != NL80211_CHAN_WIDTH_20) {
153- idx = mt7915_find_freq_idx(freq_list, ARRAY_SIZE(freq_list),
154- freq + 10);
155+ idx = mt7915_find_freq_idx(freq_list, n_freqs, freq + 10);
156 if (idx >= 0)
157 return idx;
158
159- idx = mt7915_find_freq_idx(freq_list, ARRAY_SIZE(freq_list),
160- freq - 10);
161+ idx = mt7915_find_freq_idx(freq_list, n_freqs, freq - 10);
162 if (idx >= 0)
163 return idx;
164 }
165
166- return mt7915_find_freq_idx(freq_list, ARRAY_SIZE(freq_list), freq);
167+ return mt7915_find_freq_idx(freq_list, n_freqs, freq);
168 }
169
170 int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy)
developerbbd45e12023-05-19 08:22:06 +0800171@@ -3010,24 +3046,24 @@ int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy)
developer071927d2022-08-31 20:39:29 +0800172 if (!(eep[offs] & dpd_mask))
developerb1d08d22022-05-26 16:56:25 +0800173 return 0;
174
175- idx = mt7915_dpd_freq_idx(center_freq, chandef->width);
176+ idx = mt7915_dpd_freq_idx(dev, center_freq, chandef->width);
177 if (idx < 0)
178 return -EINVAL;
179
180 /* Items: Tx DPD, Tx Flatness */
181- idx = idx * 2;
182- cal += MT_EE_CAL_GROUP_SIZE;
183+ idx = idx * cal_num;
184+ cal += mt7915_get_cal_group_size(dev) + (idx * MT_EE_CAL_UNIT);
185
186- while (total--) {
187+ while (cal_num--) {
188 int ret;
189
190- cal += (idx * MT_EE_CAL_UNIT);
191 ret = mt7915_mcu_set_pre_cal(dev, idx, cal, MT_EE_CAL_UNIT,
192 MCU_EXT_CMD(DPD_PRE_CAL_INFO));
193 if (ret)
194 return ret;
195
196 idx++;
197+ cal += MT_EE_CAL_UNIT;
198 }
199
200 return 0;
201--
developer2324aa22023-04-12 11:30:15 +08002022.18.0
developerb1d08d22022-05-26 16:56:25 +0800203