blob: 47cf4209c44e7c4f3459e34a021d573bd1452e0d [file] [log] [blame]
From 7f862ec237b850ed6b0e1683f46fd3b30368880d Mon Sep 17 00:00:00 2001
From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
Date: Fri, 14 Jun 2024 10:14:31 +0800
Subject: [PATCH 157/193] mtk: mt76: mt7996: update adie efuse merge support
Refactor efuse merge due to FW supporting the efuse merge mcu command
Change-Id: I99f3c3577826f505e402c884cc1f4815f519d2bc
Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
---
mt7996/eeprom.c | 144 --------------------------------------------
mt7996/mcu.c | 155 +++++++++++++++++++++++++++++++++++++++++++++++-
mt7996/mcu.h | 1 +
3 files changed, 153 insertions(+), 147 deletions(-)
diff --git a/mt7996/eeprom.c b/mt7996/eeprom.c
index 72a21fc..327a36b 100644
--- a/mt7996/eeprom.c
+++ b/mt7996/eeprom.c
@@ -564,146 +564,6 @@ fail:
return ret;
}
-static int mt7996_apply_cal_free_data(struct mt7996_dev *dev)
-{
-#define MT_EE_CAL_FREE_MAX_SIZE 30
-#define MT_EE_7977BN_OFFSET (0x1200 - 0x500)
-#define MT_EE_END_OFFSET 0xffff
- enum adie_type {
- ADIE_7975,
- ADIE_7976,
- ADIE_7977,
- ADIE_7978,
- ADIE_7979,
- };
- static const u16 adie_offs_list[][MT_EE_CAL_FREE_MAX_SIZE] = {
- [ADIE_7975] = {0x5cd, 0x5cf, 0x5d1, 0x5d3, 0x6c0, 0x6c1, 0x6c2, 0x6c3,
- 0x7a1, 0x7a6, 0x7a8, 0x7aa, -1},
- [ADIE_7976] = {0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x53, 0x55, 0x57, 0x59,
- 0x70, 0x71, 0x790, 0x791, 0x794, 0x795, 0x7a6, 0x7a8, 0x7aa, -1},
- [ADIE_7977] = {0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x53, 0x55, 0x57, 0x59,
- 0x69, 0x6a, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, -1},
- [ADIE_7978] = {0x91, 0x95, 0x100, 0x102, 0x104, 0x106, 0x107,
- 0x108, 0x109, 0x10a, 0x10b, 0x10c, 0x10e, 0x110, -1},
- [ADIE_7979] = {0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x53, 0x55, 0x57, 0x59,
- 0x69, 0x6a, 0x7a, 0x7b, 0x7c, 0x7e, 0x80, -1},
- };
- static const u16 eep_offs_list[][MT_EE_CAL_FREE_MAX_SIZE] = {
- [ADIE_7975] = {0x451, 0x453, 0x455, 0x457, 0x44c, 0x44d, 0x44e, 0x44f,
- 0xba1, 0xba6, 0xba8, 0xbaa, -1},
- [ADIE_7976] = {0x44c, 0x44d, 0x44e, 0x44f, 0x450,
- 0x451, 0x453, 0x455, 0x457, 0x459,
- 0x470, 0x471, 0xb90, 0xb91, 0xb94, 0xb95,
- 0xba6, 0xba8, 0xbaa, -1},
- [ADIE_7977] = {0x124c, 0x124d, 0x124e, 0x124f, 0x1250,
- 0x1251, 0x1253, 0x1255, 0x1257, 0x1259,
- 0x1269, 0x126a, 0x127a, 0x127b, 0x127c, 0x127d, 0x127e, -1},
- [ADIE_7978] = {0xb91, 0xb95, 0x480, 0x482, 0x484, 0x486, 0x487, 0x488, 0x489,
- 0x48a, 0x48b, 0x48c, 0x48e, 0x490, -1},
- [ADIE_7979] = {0x124c, 0x124d, 0x124e, 0x124f, 0x1250, 0x1251,
- 0x1253, 0x1255, 0x1257, 0x1259, 0x1269, 0x126a,
- 0x127a, 0x127b, 0x127c, 0x127e, 0x1280, -1},
- };
- static const u16 adie_base_7996[] = {
- 0x400, 0x1e00, 0x1200
- };
- static const u16 adie_base_7992[] = {
- 0x400, 0x1200, 0x0
- };
- static const u16 *adie_offs[__MT_MAX_BAND];
- static const u16 *eep_offs[__MT_MAX_BAND];
- static const u16 *adie_base;
- u8 *eeprom = dev->mt76.eeprom.data;
- u8 buf[MT7996_EEPROM_BLOCK_SIZE];
- int adie_id, band, i, ret;
-
- switch (mt76_chip(&dev->mt76)) {
- case 0x7990:
- adie_base = adie_base_7996;
- /* adie 0 */
- if (dev->fem_type == MT7996_FEM_INT && dev->chip_sku != MT7996_VAR_TYPE_233)
- adie_id = ADIE_7975;
- else
- adie_id = ADIE_7976;
- adie_offs[0] = adie_offs_list[adie_id];
- eep_offs[0] = eep_offs_list[adie_id];
-
- /* adie 1 */
- if (dev->chip_sku == MT7996_VAR_TYPE_444) {
- adie_offs[1] = adie_offs_list[ADIE_7977];
- eep_offs[1] = eep_offs_list[ADIE_7977];
- }
-
- /* adie 2 */
- adie_offs[2] = adie_offs_list[ADIE_7977];
- eep_offs[2] = eep_offs_list[ADIE_7977];
- break;
- case 0x7992:
- adie_base = adie_base_7992;
- /* adie 0 */
- if (dev->chip_sku == MT7992_VAR_TYPE_44 &&
- dev->fem_type != MT7996_FEM_EXT)
- adie_id = ADIE_7975;
- else if (dev->chip_sku == MT7992_VAR_TYPE_24)
- adie_id = ADIE_7978;
- else
- adie_id = ADIE_7976;
- adie_offs[0] = adie_offs_list[adie_id];
- eep_offs[0] = eep_offs_list[adie_id];
-
- /* adie 1 */
- if (dev->chip_sku == MT7992_VAR_TYPE_44 &&
- dev->fem_type != MT7996_FEM_INT)
- adie_id = ADIE_7977;
- else if (dev->chip_sku != MT7992_VAR_TYPE_23)
- adie_id = ADIE_7979;
- else
- break;
- adie_offs[1] = adie_offs_list[adie_id];
- eep_offs[1] = eep_offs_list[adie_id];
- break;
- default:
- return -EINVAL;
- }
-
- for (band = 0; band < __MT_MAX_BAND; band++) {
- u16 adie_offset, eep_offset;
- u32 block_num, prev_block_num = -1;
-
- if (!adie_offs[band])
- continue;
-
- for (i = 0; i < MT_EE_CAL_FREE_MAX_SIZE; i++) {
- adie_offset = adie_offs[band][i] + adie_base[band];
- eep_offset = eep_offs[band][i];
- block_num = adie_offset / MT7996_EEPROM_BLOCK_SIZE;
-
- if (adie_offs[band][i] == MT_EE_END_OFFSET)
- break;
-
- if (is_mt7996(&dev->mt76) && dev->chip_sku == MT7996_VAR_TYPE_444 &&
- band == MT_BAND1)
- eep_offset -= MT_EE_7977BN_OFFSET;
-
- if (prev_block_num != block_num) {
- ret = mt7996_mcu_get_eeprom(dev, adie_offset, buf);
- if (ret) {
- if (ret != -EINVAL)
- return ret;
-
- prev_block_num = -1;
- continue;
- }
- }
-
- eeprom[eep_offset] = buf[adie_offset % MT7996_EEPROM_BLOCK_SIZE];
- prev_block_num = block_num;
- }
- }
-
- return 0;
-}
-
int mt7996_eeprom_init(struct mt7996_dev *dev)
{
int ret;
@@ -714,10 +574,6 @@ int mt7996_eeprom_init(struct mt7996_dev *dev)
mt7996_eeprom_load_precal(dev);
- ret = mt7996_apply_cal_free_data(dev);
- if (ret)
- return ret;
-
ret = mt7996_eeprom_parse_hw_cap(dev, &dev->phy);
if (ret < 0)
return ret;
diff --git a/mt7996/mcu.c b/mt7996/mcu.c
index 534a362..27dfe29 100644
--- a/mt7996/mcu.c
+++ b/mt7996/mcu.c
@@ -4603,6 +4603,150 @@ int mt7996_mcu_set_chan_info(struct mt7996_phy *phy, u16 tag, bool sta)
&req, sizeof(req), true);
}
+static int mt7996_mcu_set_cal_free_data(struct mt7996_dev *dev)
+{
+#define MT_EE_CAL_FREE_MAX_SIZE 30
+#define MT_EE_7977BN_OFFSET (0x1200 - 0x500)
+#define MT_EE_END_OFFSET 0xffff
+ enum adie_type {
+ ADIE_7975,
+ ADIE_7976,
+ ADIE_7977,
+ ADIE_7978,
+ ADIE_7979,
+ };
+ static const u16 adie_offs_list[][MT_EE_CAL_FREE_MAX_SIZE] = {
+ [ADIE_7975] = {0x5cd, 0x5cf, 0x5d1, 0x5d3, 0x6c0, 0x6c1, 0x6c2, 0x6c3,
+ 0x7a1, 0x7a6, 0x7a8, 0x7aa, -1},
+ [ADIE_7976] = {0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x53, 0x55, 0x57, 0x59,
+ 0x70, 0x71, 0x790, 0x791, 0x794, 0x795, 0x7a6, 0x7a8, 0x7aa, -1},
+ [ADIE_7977] = {0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x53, 0x55, 0x57, 0x59,
+ 0x69, 0x6a, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, -1},
+ [ADIE_7978] = {0x91, 0x95, 0x100, 0x102, 0x104, 0x106, 0x107,
+ 0x108, 0x109, 0x10a, 0x10b, 0x10c, 0x10e, 0x110, -1},
+ [ADIE_7979] = {0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x53, 0x55, 0x57, 0x59,
+ 0x69, 0x6a, 0x7a, 0x7b, 0x7c, 0x7e, 0x80, -1},
+ };
+ static const u16 eep_offs_list[][MT_EE_CAL_FREE_MAX_SIZE] = {
+ [ADIE_7975] = {0x451, 0x453, 0x455, 0x457, 0x44c, 0x44d, 0x44e, 0x44f,
+ 0xba1, 0xba6, 0xba8, 0xbaa, -1},
+ [ADIE_7976] = {0x44c, 0x44d, 0x44e, 0x44f, 0x450,
+ 0x451, 0x453, 0x455, 0x457, 0x459,
+ 0x470, 0x471, 0xb90, 0xb91, 0xb94, 0xb95,
+ 0xba6, 0xba8, 0xbaa, -1},
+ [ADIE_7977] = {0x124c, 0x124d, 0x124e, 0x124f, 0x1250,
+ 0x1251, 0x1253, 0x1255, 0x1257, 0x1259,
+ 0x1269, 0x126a, 0x127a, 0x127b, 0x127c, 0x127d, 0x127e, -1},
+ [ADIE_7978] = {0xb91, 0xb95, 0x480, 0x482, 0x484, 0x486, 0x487, 0x488, 0x489,
+ 0x48a, 0x48b, 0x48c, 0x48e, 0x490, -1},
+ [ADIE_7979] = {0x124c, 0x124d, 0x124e, 0x124f, 0x1250, 0x1251,
+ 0x1253, 0x1255, 0x1257, 0x1259, 0x1269, 0x126a,
+ 0x127a, 0x127b, 0x127c, 0x127e, 0x1280, -1},
+ };
+ static const u16 adie_base_7996[] = {
+ 0x400, 0x1e00, 0x1200
+ };
+ static const u16 adie_base_7992[] = {
+ 0x400, 0x1200, 0x0
+ };
+ static const u16 *adie_offs[__MT_MAX_BAND];
+ static const u16 *eep_offs[__MT_MAX_BAND];
+ static const u16 *adie_base;
+ int adie_id, band, i, ret;
+
+ switch (mt76_chip(&dev->mt76)) {
+ case 0x7990:
+ adie_base = adie_base_7996;
+ /* adie 0 */
+ if (dev->fem_type == MT7996_FEM_INT && dev->chip_sku != MT7996_VAR_TYPE_233)
+ adie_id = ADIE_7975;
+ else
+ adie_id = ADIE_7976;
+ adie_offs[0] = adie_offs_list[adie_id];
+ eep_offs[0] = eep_offs_list[adie_id];
+
+ /* adie 1 */
+ if (dev->chip_sku == MT7996_VAR_TYPE_444) {
+ adie_offs[1] = adie_offs_list[ADIE_7977];
+ eep_offs[1] = eep_offs_list[ADIE_7977];
+ }
+
+ /* adie 2 */
+ adie_offs[2] = adie_offs_list[ADIE_7977];
+ eep_offs[2] = eep_offs_list[ADIE_7977];
+ break;
+ case 0x7992:
+ adie_base = adie_base_7992;
+ /* adie 0 */
+ if (dev->chip_sku == MT7992_VAR_TYPE_44 &&
+ dev->fem_type != MT7996_FEM_EXT)
+ adie_id = ADIE_7975;
+ else if (dev->chip_sku == MT7992_VAR_TYPE_24)
+ adie_id = ADIE_7978;
+ else
+ adie_id = ADIE_7976;
+ adie_offs[0] = adie_offs_list[adie_id];
+ eep_offs[0] = eep_offs_list[adie_id];
+
+ /* adie 1 */
+ if (dev->chip_sku == MT7992_VAR_TYPE_44 &&
+ dev->fem_type != MT7996_FEM_INT)
+ adie_id = ADIE_7977;
+ else if (dev->chip_sku != MT7992_VAR_TYPE_23)
+ adie_id = ADIE_7979;
+ else
+ break;
+ adie_offs[1] = adie_offs_list[adie_id];
+ eep_offs[1] = eep_offs_list[adie_id];
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ for (band = 0; band < __MT_MAX_BAND; band++) {
+ struct {
+ /* fixed field */
+ u8 __rsv[4];
+
+ __le16 tag;
+ __le16 len;
+ __le16 adie_offset;
+ __le16 eep_offset;
+ __le16 count;
+ u8 rsv[2];
+ } __packed req = {
+ .tag = cpu_to_le16(UNI_EFUSE_PATCH),
+ .len = cpu_to_le16(sizeof(req) - 4),
+ .count = cpu_to_le16(1),
+ };
+ u16 adie_offset, eep_offset;
+
+ if (!adie_offs[band])
+ continue;
+
+ for (i = 0; i < MT_EE_CAL_FREE_MAX_SIZE; i++) {
+ adie_offset = adie_offs[band][i] + adie_base[band];
+ eep_offset = eep_offs[band][i];
+
+ if (adie_offs[band][i] == MT_EE_END_OFFSET)
+ break;
+
+ if (is_mt7996(&dev->mt76) && dev->chip_sku == MT7996_VAR_TYPE_444 &&
+ band == MT_BAND1)
+ eep_offset -= MT_EE_7977BN_OFFSET;
+
+ req.eep_offset = cpu_to_le16(eep_offset);
+ req.adie_offset = cpu_to_le16(adie_offset);
+ ret = mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(EFUSE_CTRL),
+ &req, sizeof(req), true);
+ if (ret)
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
int mt7996_mcu_set_eeprom_flash(struct mt7996_dev *dev)
{
#define MAX_PAGE_IDX_MASK GENMASK(7, 5)
@@ -4656,12 +4800,17 @@ int mt7996_mcu_set_eeprom(struct mt7996_dev *dev)
.buffer_mode = EE_MODE_EFUSE,
.format = EE_FORMAT_WHOLE
};
+ int ret;
if (dev->flash_mode)
- return mt7996_mcu_set_eeprom_flash(dev);
+ ret = mt7996_mcu_set_eeprom_flash(dev);
+ else
+ ret = mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(EFUSE_CTRL),
+ &req, sizeof(req), true);
+ if (ret)
+ return ret;
- return mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(EFUSE_CTRL),
- &req, sizeof(req), true);
+ return mt7996_mcu_set_cal_free_data(dev);
}
int mt7996_mcu_get_eeprom(struct mt7996_dev *dev, u32 offset, u8 *buf, u32 buf_len)
diff --git a/mt7996/mcu.h b/mt7996/mcu.h
index 05b29c9..d99e9a6 100644
--- a/mt7996/mcu.h
+++ b/mt7996/mcu.h
@@ -1038,6 +1038,7 @@ enum {
UNI_EFUSE_BUFFER_MODE,
UNI_EFUSE_FREE_BLOCK,
UNI_EFUSE_BUFFER_RD,
+ UNI_EFUSE_PATCH,
};
enum {
--
2.45.2