developer | 36fe709 | 2023-09-27 12:24:47 +0800 | [diff] [blame] | 1 | From 68772db4cdffdeceb9c65823ec060b4ec0642136 Mon Sep 17 00:00:00 2001 |
developer | 6a1998b | 2022-12-08 18:09:45 +0800 | [diff] [blame] | 2 | From: Peter Chiu <chui-hao.chiu@mediatek.com> |
| 3 | Date: Fri, 20 May 2022 19:19:25 +0800 |
developer | 36fe709 | 2023-09-27 12:24:47 +0800 | [diff] [blame] | 4 | Subject: [PATCH 1016/1034] wifi: mt76: mt7915: add mt7986 and mt7916 |
developer | 78848c6 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 5 | pre-calibration |
developer | 6a1998b | 2022-12-08 18:09:45 +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> |
| 12 | --- |
| 13 | mt7915/eeprom.c | 15 +++++------ |
| 14 | mt7915/eeprom.h | 1 + |
| 15 | mt7915/mcu.c | 72 ++++++++++++++++++++++++++++++++++++------------- |
| 16 | 3 files changed, 62 insertions(+), 26 deletions(-) |
| 17 | |
| 18 | diff --git a/mt7915/eeprom.c b/mt7915/eeprom.c |
developer | 36fe709 | 2023-09-27 12:24:47 +0800 | [diff] [blame] | 19 | index f5ab3319..a5c99a5e 100644 |
developer | 6a1998b | 2022-12-08 18:09:45 +0800 | [diff] [blame] | 20 | --- 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) |
| 53 | diff --git a/mt7915/eeprom.h b/mt7915/eeprom.h |
developer | 36fe709 | 2023-09-27 12:24:47 +0800 | [diff] [blame] | 54 | index 88aaa16a..fdae347e 100644 |
developer | 6a1998b | 2022-12-08 18:09:45 +0800 | [diff] [blame] | 55 | --- 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, |
| 65 | diff --git a/mt7915/mcu.c b/mt7915/mcu.c |
developer | 36fe709 | 2023-09-27 12:24:47 +0800 | [diff] [blame] | 66 | index c8b97e89..fa2c6919 100644 |
developer | 6a1998b | 2022-12-08 18:09:45 +0800 | [diff] [blame] | 67 | --- a/mt7915/mcu.c |
| 68 | +++ b/mt7915/mcu.c |
developer | 36fe709 | 2023-09-27 12:24:47 +0800 | [diff] [blame] | 69 | @@ -2946,7 +2946,8 @@ static int mt7915_mcu_set_pre_cal(struct mt7915_dev *dev, u8 idx, |
developer | 6a1998b | 2022-12-08 18:09:45 +0800 | [diff] [blame] | 70 | 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 | |
| 77 | if (!(eep[offs] & MT_EE_WIFI_CAL_GROUP)) |
| 78 | return 0; |
developer | 36fe709 | 2023-09-27 12:24:47 +0800 | [diff] [blame] | 79 | @@ -2984,9 +2985,9 @@ static int mt7915_find_freq_idx(const u16 *freqs, int n_freqs, u16 cur) |
developer | 6a1998b | 2022-12-08 18:09:45 +0800 | [diff] [blame] | 80 | 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[] = { |
| 87 | + const u16 freq_list_v1[] = { |
| 88 | 5180, 5200, 5220, 5240, |
| 89 | 5260, 5280, 5300, 5320, |
| 90 | 5500, 5520, 5540, 5560, |
developer | 36fe709 | 2023-09-27 12:24:47 +0800 | [diff] [blame] | 91 | @@ -2994,34 +2995,69 @@ static int mt7915_dpd_freq_idx(u16 freq, u8 bw) |
developer | 6a1998b | 2022-12-08 18:09:45 +0800 | [diff] [blame] | 92 | 5660, 5680, 5700, 5745, |
| 93 | 5765, 5785, 5805, 5825 |
| 94 | }; |
| 95 | - int offset_2g = ARRAY_SIZE(freq_list); |
| 96 | + const u16 freq_list_v2[] = { |
| 97 | + /* 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 | + }; |
| 127 | + const u16 *freq_list = freq_list_v1; |
| 128 | + 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) |
developer | 36fe709 | 2023-09-27 12:24:47 +0800 | [diff] [blame] | 171 | @@ -3053,24 +3089,24 @@ int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy) |
developer | 6a1998b | 2022-12-08 18:09:45 +0800 | [diff] [blame] | 172 | if (!(eep[offs] & dpd_mask)) |
| 173 | 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 | -- |
developer | 36fe709 | 2023-09-27 12:24:47 +0800 | [diff] [blame] | 202 | 2.39.2 |
developer | 6a1998b | 2022-12-08 18:09:45 +0800 | [diff] [blame] | 203 | |