developer | d59e477 | 2022-07-14 13:48:49 +0800 | [diff] [blame] | 1 | From a4033091ec1a76b05364ea714f2abea7addbebb9 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> |
| 3 | Date: Fri, 20 May 2022 19:19:25 +0800 |
developer | d59e477 | 2022-07-14 13:48:49 +0800 | [diff] [blame] | 4 | Subject: [PATCH 1115/1119] mt76: mt7915: add mt7986 and mt7916 pre-calibration |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 5 | |
| 6 | Add pre-calibration for mt7986 and mt7916. It has different data size |
| 7 | with mt7915. Group cal needs 54k and 94k for 2G + 5G and 2G + 6G, |
| 8 | respectively. DPD cal needs 300k. |
| 9 | |
| 10 | Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com> |
| 11 | --- |
developer | d59e477 | 2022-07-14 13:48:49 +0800 | [diff] [blame] | 12 | .../wireless/mediatek/mt76/mt7915/eeprom.c | 15 ++-- |
| 13 | .../wireless/mediatek/mt76/mt7915/eeprom.h | 27 ++++++- |
| 14 | .../net/wireless/mediatek/mt76/mt7915/mcu.c | 80 ++++++++++++++----- |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 15 | 3 files changed, 90 insertions(+), 32 deletions(-) |
| 16 | |
| 17 | diff --git a/mt7915/eeprom.c b/mt7915/eeprom.c |
developer | d59e477 | 2022-07-14 13:48:49 +0800 | [diff] [blame] | 18 | index 4b1a9811..ee3049e5 100644 |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 19 | --- 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) |
| 52 | diff --git a/mt7915/eeprom.h b/mt7915/eeprom.h |
developer | d59e477 | 2022-07-14 13:48:49 +0800 | [diff] [blame] | 53 | index 7578ac6d..e924baef 100644 |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 54 | --- 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, |
| 64 | @@ -39,10 +40,14 @@ enum mt7915_eeprom_field { |
| 65 | }; |
| 66 | |
| 67 | #define MT_EE_WIFI_CAL_GROUP BIT(0) |
| 68 | -#define MT_EE_WIFI_CAL_DPD GENMASK(2, 1) |
| 69 | +#define MT_EE_WIFI_CAL_DPD GENMASK(3, 1) |
| 70 | #define MT_EE_CAL_UNIT 1024 |
| 71 | -#define MT_EE_CAL_GROUP_SIZE (49 * MT_EE_CAL_UNIT + 16) |
| 72 | -#define MT_EE_CAL_DPD_SIZE (54 * MT_EE_CAL_UNIT) |
| 73 | +#define MT_EE_CAL_GROUP_SIZE_7915 (49 * MT_EE_CAL_UNIT + 16) |
| 74 | +#define MT_EE_CAL_GROUP_SIZE_7916 (54 * MT_EE_CAL_UNIT + 16) |
| 75 | +#define MT_EE_CAL_GROUP_SIZE_7975 (54 * MT_EE_CAL_UNIT + 16) |
| 76 | +#define MT_EE_CAL_GROUP_SIZE_7976 (94 * MT_EE_CAL_UNIT + 16) |
| 77 | +#define MT_EE_CAL_DPD_SIZE_V1 (54 * MT_EE_CAL_UNIT) |
| 78 | +#define MT_EE_CAL_DPD_SIZE_V2 (300 * MT_EE_CAL_UNIT) |
| 79 | |
| 80 | #define MT_EE_WIFI_CONF0_TX_PATH GENMASK(2, 0) |
| 81 | #define MT_EE_WIFI_CONF0_BAND_SEL GENMASK(7, 6) |
| 82 | @@ -160,6 +165,22 @@ mt7915_tssi_enabled(struct mt7915_dev *dev, enum nl80211_band band) |
| 83 | return val & MT_EE_WIFI_CONF7_TSSI0_5G; |
| 84 | } |
| 85 | |
| 86 | +static inline u32 |
| 87 | +mt7915_get_cal_group_size(struct mt7915_dev *dev) |
| 88 | +{ |
| 89 | + switch (mt76_chip(&dev->mt76)) { |
| 90 | + case 0x7915: |
| 91 | + return MT_EE_CAL_GROUP_SIZE_7915; |
| 92 | + case 0x7916: |
| 93 | + return MT_EE_CAL_GROUP_SIZE_7916; |
| 94 | + default: |
| 95 | + if (mt7915_check_adie(dev, false)) |
| 96 | + return MT_EE_CAL_GROUP_SIZE_7976; |
| 97 | + |
| 98 | + return MT_EE_CAL_GROUP_SIZE_7975; |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | extern const u8 mt7915_sku_group_len[MAX_SKU_RATE_GROUP_NUM]; |
| 103 | |
| 104 | #endif |
| 105 | diff --git a/mt7915/mcu.c b/mt7915/mcu.c |
developer | d59e477 | 2022-07-14 13:48:49 +0800 | [diff] [blame] | 106 | index c65fee98..29422f55 100644 |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 107 | --- a/mt7915/mcu.c |
| 108 | +++ b/mt7915/mcu.c |
developer | d59e477 | 2022-07-14 13:48:49 +0800 | [diff] [blame] | 109 | @@ -2930,9 +2930,10 @@ static int mt7915_mcu_set_pre_cal(struct mt7915_dev *dev, u8 idx, |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 110 | int mt7915_mcu_apply_group_cal(struct mt7915_dev *dev) |
| 111 | { |
| 112 | u8 idx = 0, *cal = dev->cal, *eep = dev->mt76.eeprom.data; |
| 113 | - u32 total = MT_EE_CAL_GROUP_SIZE; |
| 114 | + u32 total = mt7915_get_cal_group_size(dev); |
| 115 | + u32 offs = is_mt7915(&dev->mt76) ? MT_EE_DO_PRE_CAL : MT_EE_DO_PRE_CAL_V2; |
| 116 | |
| 117 | - if (1 || !(eep[MT_EE_DO_PRE_CAL] & MT_EE_WIFI_CAL_GROUP)) |
| 118 | + if (1 || !(eep[offs] & MT_EE_WIFI_CAL_GROUP)) |
| 119 | return 0; |
| 120 | |
| 121 | /* |
developer | d59e477 | 2022-07-14 13:48:49 +0800 | [diff] [blame] | 122 | @@ -2968,9 +2969,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] | 123 | return -1; |
| 124 | } |
| 125 | |
| 126 | -static int mt7915_dpd_freq_idx(u16 freq, u8 bw) |
| 127 | +static int mt7915_dpd_freq_idx(struct mt7915_dev *dev, u16 freq, u8 bw) |
| 128 | { |
| 129 | - static const u16 freq_list[] = { |
| 130 | + static const u16 freq_list_v1[] = { |
| 131 | 5180, 5200, 5220, 5240, |
| 132 | 5260, 5280, 5300, 5320, |
| 133 | 5500, 5520, 5540, 5560, |
developer | d59e477 | 2022-07-14 13:48:49 +0800 | [diff] [blame] | 134 | @@ -2978,65 +2979,102 @@ static int mt7915_dpd_freq_idx(u16 freq, u8 bw) |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 135 | 5660, 5680, 5700, 5745, |
| 136 | 5765, 5785, 5805, 5825 |
| 137 | }; |
| 138 | - int offset_2g = ARRAY_SIZE(freq_list); |
| 139 | + static const u16 freq_list_v2[] = { |
| 140 | + /* 6G BW20*/ |
| 141 | + 5955, 5975, 5995, 6015, |
| 142 | + 6035, 6055, 6075, 6095, |
| 143 | + 6115, 6135, 6155, 6175, |
| 144 | + 6195, 6215, 6235, 6255, |
| 145 | + 6275, 6295, 6315, 6335, |
| 146 | + 6355, 6375, 6395, 6415, |
| 147 | + 6435, 6455, 6475, 6495, |
| 148 | + 6515, 6535, 6555, 6575, |
| 149 | + 6595, 6615, 6635, 6655, |
| 150 | + 6675, 6695, 6715, 6735, |
| 151 | + 6755, 6775, 6795, 6815, |
| 152 | + 6835, 6855, 6875, 6895, |
| 153 | + 6915, 6935, 6955, 6975, |
| 154 | + 6995, 7015, 7035, 7055, |
| 155 | + 7075, 7095, 7115, |
| 156 | + /* 6G BW160 */ |
| 157 | + 6025, 6185, 6345, 6505, |
| 158 | + 6665, 6825, 6985, |
| 159 | + /* 5G BW20 */ |
| 160 | + 5180, 5200, 5220, 5240, |
| 161 | + 5260, 5280, 5300, 5320, |
| 162 | + 5500, 5520, 5540, 5560, |
| 163 | + 5580, 5600, 5620, 5640, |
| 164 | + 5660, 5680, 5700, 5720, |
| 165 | + 5745, 5765, 5785, 5805, |
| 166 | + 5825, 5845, 5865, 5885, |
| 167 | + /* 5G BW160 */ |
| 168 | + 5250, 5570, 5815 |
| 169 | + }; |
| 170 | + static const u16 *freq_list = freq_list_v1; |
| 171 | + int n_freqs = ARRAY_SIZE(freq_list_v1); |
| 172 | int idx; |
| 173 | |
| 174 | + if (!is_mt7915(&dev->mt76)) { |
| 175 | + freq_list = freq_list_v2; |
| 176 | + n_freqs = ARRAY_SIZE(freq_list_v2); |
| 177 | + } |
| 178 | + |
| 179 | if (freq < 4000) { |
| 180 | if (freq < 2432) |
| 181 | - return offset_2g; |
| 182 | + return n_freqs; |
| 183 | if (freq < 2457) |
| 184 | - return offset_2g + 1; |
| 185 | + return n_freqs + 1; |
| 186 | |
| 187 | - return offset_2g + 2; |
| 188 | + return n_freqs + 2; |
| 189 | } |
| 190 | |
| 191 | - if (bw == NL80211_CHAN_WIDTH_80P80 || bw == NL80211_CHAN_WIDTH_160) |
| 192 | + if (bw == NL80211_CHAN_WIDTH_80P80) |
| 193 | return -1; |
| 194 | |
| 195 | if (bw != NL80211_CHAN_WIDTH_20) { |
| 196 | - idx = mt7915_find_freq_idx(freq_list, ARRAY_SIZE(freq_list), |
| 197 | - freq + 10); |
| 198 | + idx = mt7915_find_freq_idx(freq_list, n_freqs, freq + 10); |
| 199 | if (idx >= 0) |
| 200 | return idx; |
| 201 | |
| 202 | - idx = mt7915_find_freq_idx(freq_list, ARRAY_SIZE(freq_list), |
| 203 | - freq - 10); |
| 204 | + idx = mt7915_find_freq_idx(freq_list, n_freqs, freq - 10); |
| 205 | if (idx >= 0) |
| 206 | return idx; |
| 207 | } |
| 208 | |
| 209 | - return mt7915_find_freq_idx(freq_list, ARRAY_SIZE(freq_list), freq); |
| 210 | + return mt7915_find_freq_idx(freq_list, n_freqs, freq); |
| 211 | } |
| 212 | |
| 213 | int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy) |
| 214 | { |
| 215 | struct mt7915_dev *dev = phy->dev; |
| 216 | struct cfg80211_chan_def *chandef = &phy->mt76->chandef; |
| 217 | - u16 total = 2, center_freq = chandef->center_freq1; |
| 218 | + u32 offs = is_mt7915(&dev->mt76) ? MT_EE_DO_PRE_CAL : MT_EE_DO_PRE_CAL_V2; |
| 219 | + u16 center_freq = chandef->center_freq1; |
| 220 | u8 *cal = dev->cal, *eep = dev->mt76.eeprom.data; |
| 221 | + u8 cal_num = is_mt7915(&dev->mt76) ? 2 : 3; |
| 222 | int idx; |
| 223 | |
| 224 | - if (1 || !(eep[MT_EE_DO_PRE_CAL] & MT_EE_WIFI_CAL_DPD)) |
| 225 | + if (1 || !(eep[offs] & MT_EE_WIFI_CAL_DPD)) |
| 226 | return 0; |
| 227 | |
| 228 | - idx = mt7915_dpd_freq_idx(center_freq, chandef->width); |
| 229 | + idx = mt7915_dpd_freq_idx(dev, center_freq, chandef->width); |
| 230 | if (idx < 0) |
| 231 | return -EINVAL; |
| 232 | |
| 233 | /* Items: Tx DPD, Tx Flatness */ |
| 234 | - idx = idx * 2; |
| 235 | - cal += MT_EE_CAL_GROUP_SIZE; |
| 236 | + idx = idx * cal_num; |
| 237 | + cal += mt7915_get_cal_group_size(dev) + (idx * MT_EE_CAL_UNIT); |
| 238 | |
| 239 | - while (total--) { |
| 240 | + while (cal_num--) { |
| 241 | int ret; |
| 242 | |
| 243 | - cal += (idx * MT_EE_CAL_UNIT); |
| 244 | ret = mt7915_mcu_set_pre_cal(dev, idx, cal, MT_EE_CAL_UNIT, |
| 245 | MCU_EXT_CMD(DPD_PRE_CAL_INFO)); |
| 246 | if (ret) |
| 247 | return ret; |
| 248 | |
| 249 | idx++; |
| 250 | + cal += MT_EE_CAL_UNIT; |
| 251 | } |
| 252 | |
| 253 | return 0; |
| 254 | -- |
developer | d59e477 | 2022-07-14 13:48:49 +0800 | [diff] [blame] | 255 | 2.25.1 |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 256 | |