developer | c04f540 | 2023-02-03 09:22:26 +0800 | [diff] [blame^] | 1 | From fd1a769323cb64ed9d21d0f291beb3dfcb9adb35 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 | c04f540 | 2023-02-03 09:22:26 +0800 | [diff] [blame^] | 4 | Subject: [PATCH 1119/1133] 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 | 071927d | 2022-08-31 20:39:29 +0800 | [diff] [blame] | 12 | mt7915/eeprom.c | 15 +++++------ |
| 13 | mt7915/eeprom.h | 1 + |
| 14 | mt7915/mcu.c | 72 ++++++++++++++++++++++++++++++++++++------------- |
| 15 | 3 files changed, 62 insertions(+), 26 deletions(-) |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 16 | |
| 17 | diff --git a/mt7915/eeprom.c b/mt7915/eeprom.c |
developer | c04f540 | 2023-02-03 09:22:26 +0800 | [diff] [blame^] | 18 | index a7962893..55ba90ac 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 | c04f540 | 2023-02-03 09:22:26 +0800 | [diff] [blame^] | 53 | index 88aaa16a..fdae347e 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, |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 64 | diff --git a/mt7915/mcu.c b/mt7915/mcu.c |
developer | c04f540 | 2023-02-03 09:22:26 +0800 | [diff] [blame^] | 65 | index e82b7e14..28698d37 100644 |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 66 | --- a/mt7915/mcu.c |
| 67 | +++ b/mt7915/mcu.c |
developer | c04f540 | 2023-02-03 09:22:26 +0800 | [diff] [blame^] | 68 | @@ -2966,7 +2966,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] | 69 | int mt7915_mcu_apply_group_cal(struct mt7915_dev *dev) |
| 70 | { |
| 71 | u8 idx = 0, *cal = dev->cal, *eep = dev->mt76.eeprom.data; |
| 72 | - u32 total = MT_EE_CAL_GROUP_SIZE; |
| 73 | + u32 total = mt7915_get_cal_group_size(dev); |
| 74 | + u32 offs = is_mt7915(&dev->mt76) ? MT_EE_DO_PRE_CAL : MT_EE_DO_PRE_CAL_V2; |
| 75 | |
developer | 071927d | 2022-08-31 20:39:29 +0800 | [diff] [blame] | 76 | if (!(eep[offs] & MT_EE_WIFI_CAL_GROUP)) |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 77 | return 0; |
developer | c04f540 | 2023-02-03 09:22:26 +0800 | [diff] [blame^] | 78 | @@ -3004,9 +3005,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] | 79 | return -1; |
| 80 | } |
| 81 | |
| 82 | -static int mt7915_dpd_freq_idx(u16 freq, u8 bw) |
| 83 | +static int mt7915_dpd_freq_idx(struct mt7915_dev *dev, u16 freq, u8 bw) |
| 84 | { |
| 85 | - static const u16 freq_list[] = { |
developer | 071927d | 2022-08-31 20:39:29 +0800 | [diff] [blame] | 86 | + const u16 freq_list_v1[] = { |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 87 | 5180, 5200, 5220, 5240, |
| 88 | 5260, 5280, 5300, 5320, |
| 89 | 5500, 5520, 5540, 5560, |
developer | c04f540 | 2023-02-03 09:22:26 +0800 | [diff] [blame^] | 90 | @@ -3014,34 +3015,69 @@ static int mt7915_dpd_freq_idx(u16 freq, u8 bw) |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 91 | 5660, 5680, 5700, 5745, |
| 92 | 5765, 5785, 5805, 5825 |
| 93 | }; |
| 94 | - int offset_2g = ARRAY_SIZE(freq_list); |
developer | 071927d | 2022-08-31 20:39:29 +0800 | [diff] [blame] | 95 | + const u16 freq_list_v2[] = { |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 96 | + /* 6G BW20*/ |
| 97 | + 5955, 5975, 5995, 6015, |
| 98 | + 6035, 6055, 6075, 6095, |
| 99 | + 6115, 6135, 6155, 6175, |
| 100 | + 6195, 6215, 6235, 6255, |
| 101 | + 6275, 6295, 6315, 6335, |
| 102 | + 6355, 6375, 6395, 6415, |
| 103 | + 6435, 6455, 6475, 6495, |
| 104 | + 6515, 6535, 6555, 6575, |
| 105 | + 6595, 6615, 6635, 6655, |
| 106 | + 6675, 6695, 6715, 6735, |
| 107 | + 6755, 6775, 6795, 6815, |
| 108 | + 6835, 6855, 6875, 6895, |
| 109 | + 6915, 6935, 6955, 6975, |
| 110 | + 6995, 7015, 7035, 7055, |
| 111 | + 7075, 7095, 7115, |
| 112 | + /* 6G BW160 */ |
| 113 | + 6025, 6185, 6345, 6505, |
| 114 | + 6665, 6825, 6985, |
| 115 | + /* 5G BW20 */ |
| 116 | + 5180, 5200, 5220, 5240, |
| 117 | + 5260, 5280, 5300, 5320, |
| 118 | + 5500, 5520, 5540, 5560, |
| 119 | + 5580, 5600, 5620, 5640, |
| 120 | + 5660, 5680, 5700, 5720, |
| 121 | + 5745, 5765, 5785, 5805, |
| 122 | + 5825, 5845, 5865, 5885, |
| 123 | + /* 5G BW160 */ |
| 124 | + 5250, 5570, 5815 |
| 125 | + }; |
developer | 071927d | 2022-08-31 20:39:29 +0800 | [diff] [blame] | 126 | + const u16 *freq_list = freq_list_v1; |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 127 | + int n_freqs = ARRAY_SIZE(freq_list_v1); |
| 128 | int idx; |
| 129 | |
| 130 | + if (!is_mt7915(&dev->mt76)) { |
| 131 | + freq_list = freq_list_v2; |
| 132 | + n_freqs = ARRAY_SIZE(freq_list_v2); |
| 133 | + } |
| 134 | + |
| 135 | if (freq < 4000) { |
| 136 | if (freq < 2432) |
| 137 | - return offset_2g; |
| 138 | + return n_freqs; |
| 139 | if (freq < 2457) |
| 140 | - return offset_2g + 1; |
| 141 | + return n_freqs + 1; |
| 142 | |
| 143 | - return offset_2g + 2; |
| 144 | + return n_freqs + 2; |
| 145 | } |
| 146 | |
| 147 | - if (bw == NL80211_CHAN_WIDTH_80P80 || bw == NL80211_CHAN_WIDTH_160) |
| 148 | + if (bw == NL80211_CHAN_WIDTH_80P80) |
| 149 | return -1; |
| 150 | |
| 151 | if (bw != NL80211_CHAN_WIDTH_20) { |
| 152 | - idx = mt7915_find_freq_idx(freq_list, ARRAY_SIZE(freq_list), |
| 153 | - freq + 10); |
| 154 | + idx = mt7915_find_freq_idx(freq_list, n_freqs, freq + 10); |
| 155 | if (idx >= 0) |
| 156 | return idx; |
| 157 | |
| 158 | - idx = mt7915_find_freq_idx(freq_list, ARRAY_SIZE(freq_list), |
| 159 | - freq - 10); |
| 160 | + idx = mt7915_find_freq_idx(freq_list, n_freqs, freq - 10); |
| 161 | if (idx >= 0) |
| 162 | return idx; |
| 163 | } |
| 164 | |
| 165 | - return mt7915_find_freq_idx(freq_list, ARRAY_SIZE(freq_list), freq); |
| 166 | + return mt7915_find_freq_idx(freq_list, n_freqs, freq); |
| 167 | } |
| 168 | |
| 169 | int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy) |
developer | c04f540 | 2023-02-03 09:22:26 +0800 | [diff] [blame^] | 170 | @@ -3073,24 +3109,24 @@ int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy) |
developer | 071927d | 2022-08-31 20:39:29 +0800 | [diff] [blame] | 171 | if (!(eep[offs] & dpd_mask)) |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 172 | return 0; |
| 173 | |
| 174 | - idx = mt7915_dpd_freq_idx(center_freq, chandef->width); |
| 175 | + idx = mt7915_dpd_freq_idx(dev, center_freq, chandef->width); |
| 176 | if (idx < 0) |
| 177 | return -EINVAL; |
| 178 | |
| 179 | /* Items: Tx DPD, Tx Flatness */ |
| 180 | - idx = idx * 2; |
| 181 | - cal += MT_EE_CAL_GROUP_SIZE; |
| 182 | + idx = idx * cal_num; |
| 183 | + cal += mt7915_get_cal_group_size(dev) + (idx * MT_EE_CAL_UNIT); |
| 184 | |
| 185 | - while (total--) { |
| 186 | + while (cal_num--) { |
| 187 | int ret; |
| 188 | |
| 189 | - cal += (idx * MT_EE_CAL_UNIT); |
| 190 | ret = mt7915_mcu_set_pre_cal(dev, idx, cal, MT_EE_CAL_UNIT, |
| 191 | MCU_EXT_CMD(DPD_PRE_CAL_INFO)); |
| 192 | if (ret) |
| 193 | return ret; |
| 194 | |
| 195 | idx++; |
| 196 | + cal += MT_EE_CAL_UNIT; |
| 197 | } |
| 198 | |
| 199 | return 0; |
| 200 | -- |
developer | c04f540 | 2023-02-03 09:22:26 +0800 | [diff] [blame^] | 201 | 2.18.0 |
developer | b1d08d2 | 2022-05-26 16:56:25 +0800 | [diff] [blame] | 202 | |