developer | 82d3406 | 2024-02-29 09:50:59 +0800 | [diff] [blame^] | 1 | From 5c93e5bf8cd5ae9eaa10fb1719614eb8d049e7bf Mon Sep 17 00:00:00 2001 |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 2 | From: Peter Chiu <chui-hao.chiu@mediatek.com> |
developer | 9860156 | 2023-12-13 10:44:32 +0800 | [diff] [blame] | 3 | Date: Wed, 13 Dec 2023 09:55:27 +0800 |
developer | 82d3406 | 2024-02-29 09:50:59 +0800 | [diff] [blame^] | 4 | Subject: [PATCH 1016/1049] wifi: mt76: mt7915: add mt7986 and mt7916 |
developer | a72bbd8 | 2024-02-04 18:27:28 +0800 | [diff] [blame] | 5 | pre-calibration |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 6 | |
| 7 | Add pre-calibration for mt7986 and mt7916. It has different data size |
| 8 | with mt7915. Group cal needs 54k and 94k for 2G + 5G and 2G + 6G, |
| 9 | respectively. DPD cal needs 300k. |
| 10 | |
| 11 | Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com> |
developer | 9860156 | 2023-12-13 10:44:32 +0800 | [diff] [blame] | 12 | Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 13 | --- |
developer | 9860156 | 2023-12-13 10:44:32 +0800 | [diff] [blame] | 14 | mt7915/eeprom.c | 17 ++++++------ |
developer | 071927d | 2022-08-31 20:39:29 +0800 | [diff] [blame] | 15 | mt7915/eeprom.h | 1 + |
| 16 | mt7915/mcu.c | 72 ++++++++++++++++++++++++++++++++++++------------- |
developer | 9860156 | 2023-12-13 10:44:32 +0800 | [diff] [blame] | 17 | 3 files changed, 63 insertions(+), 27 deletions(-) |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 18 | |
| 19 | diff --git a/mt7915/eeprom.c b/mt7915/eeprom.c |
developer | 82d3406 | 2024-02-29 09:50:59 +0800 | [diff] [blame^] | 20 | index 0441d91a..5e74b5ff 100644 |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 21 | --- a/mt7915/eeprom.c |
| 22 | +++ b/mt7915/eeprom.c |
developer | 9860156 | 2023-12-13 10:44:32 +0800 | [diff] [blame] | 23 | @@ -9,28 +9,27 @@ static int mt7915_eeprom_load_precal(struct mt7915_dev *dev) |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 24 | { |
| 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]; |
developer | 9860156 | 2023-12-13 10:44:32 +0800 | [diff] [blame] | 31 | int ret; |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 32 | |
| 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 | |
developer | ade48b1 | 2023-12-12 10:37:24 +0800 | [diff] [blame] | 50 | - ret = mt76_get_of_data_from_mtd(mdev, dev->cal, offs, val); |
developer | 9860156 | 2023-12-13 10:44:32 +0800 | [diff] [blame] | 51 | + ret = mt76_get_of_data_from_mtd(mdev, dev->cal, offs, size); |
| 52 | if (!ret) |
| 53 | return ret; |
| 54 | |
developer | ade48b1 | 2023-12-12 10:37:24 +0800 | [diff] [blame] | 55 | - return mt76_get_of_data_from_nvmem(mdev, dev->cal, "precal", val); |
developer | 9860156 | 2023-12-13 10:44:32 +0800 | [diff] [blame] | 56 | + return mt76_get_of_data_from_nvmem(mdev, dev->cal, "precal", size); |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | static int mt7915_check_eeprom(struct mt7915_dev *dev) |
| 60 | diff --git a/mt7915/eeprom.h b/mt7915/eeprom.h |
developer | 82d3406 | 2024-02-29 09:50:59 +0800 | [diff] [blame^] | 61 | index 25f0b32a..4a313759 100644 |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 62 | --- 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, |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 72 | diff --git a/mt7915/mcu.c b/mt7915/mcu.c |
developer | 82d3406 | 2024-02-29 09:50:59 +0800 | [diff] [blame^] | 73 | index 1707aaf7..b21d888b 100644 |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 74 | --- a/mt7915/mcu.c |
| 75 | +++ b/mt7915/mcu.c |
developer | a72bbd8 | 2024-02-04 18:27:28 +0800 | [diff] [blame] | 76 | @@ -3044,7 +3044,8 @@ static int mt7915_mcu_set_pre_cal(struct mt7915_dev *dev, u8 idx, |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 77 | 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 | |
developer | 071927d | 2022-08-31 20:39:29 +0800 | [diff] [blame] | 84 | if (!(eep[offs] & MT_EE_WIFI_CAL_GROUP)) |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 85 | return 0; |
developer | a72bbd8 | 2024-02-04 18:27:28 +0800 | [diff] [blame] | 86 | @@ -3082,9 +3083,9 @@ static int mt7915_find_freq_idx(const u16 *freqs, int n_freqs, u16 cur) |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 87 | 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[] = { |
developer | 071927d | 2022-08-31 20:39:29 +0800 | [diff] [blame] | 94 | + const u16 freq_list_v1[] = { |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 95 | 5180, 5200, 5220, 5240, |
| 96 | 5260, 5280, 5300, 5320, |
| 97 | 5500, 5520, 5540, 5560, |
developer | a72bbd8 | 2024-02-04 18:27:28 +0800 | [diff] [blame] | 98 | @@ -3092,34 +3093,69 @@ static int mt7915_dpd_freq_idx(u16 freq, u8 bw) |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 99 | 5660, 5680, 5700, 5745, |
| 100 | 5765, 5785, 5805, 5825 |
| 101 | }; |
| 102 | - int offset_2g = ARRAY_SIZE(freq_list); |
developer | 071927d | 2022-08-31 20:39:29 +0800 | [diff] [blame] | 103 | + const u16 freq_list_v2[] = { |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 104 | + /* 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 | + }; |
developer | 071927d | 2022-08-31 20:39:29 +0800 | [diff] [blame] | 134 | + const u16 *freq_list = freq_list_v1; |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 135 | + 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) |
developer | a72bbd8 | 2024-02-04 18:27:28 +0800 | [diff] [blame] | 178 | @@ -3151,24 +3187,24 @@ int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy) |
developer | 071927d | 2022-08-31 20:39:29 +0800 | [diff] [blame] | 179 | if (!(eep[offs] & dpd_mask)) |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 180 | 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 | -- |
developer | 0443cd3 | 2023-09-19 14:11:49 +0800 | [diff] [blame] | 209 | 2.18.0 |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 210 | |