blob: 3556945793a19049b24a04fcf6a73009691aea56 [file] [log] [blame]
From dcace898314b1d369b61a0c4f7f9e325f04784dc Mon Sep 17 00:00:00 2001
From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
Date: Fri, 26 May 2023 14:44:04 +0800
Subject: [PATCH 61/98] wifi: mt76: mt7996: add kite eeprom load support
Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
---
mt7996/eeprom.c | 33 ++++++++++++++++++++++-----------
mt7996/mcu.c | 2 +-
mt7996/mt7996.h | 10 ++++++++++
3 files changed, 33 insertions(+), 12 deletions(-)
diff --git a/mt7996/eeprom.c b/mt7996/eeprom.c
index 56605de..6605853 100644
--- a/mt7996/eeprom.c
+++ b/mt7996/eeprom.c
@@ -53,9 +53,12 @@ static int mt7996_check_eeprom(struct mt7996_dev *dev)
u8 *eeprom = dev->mt76.eeprom.data;
u16 val = get_unaligned_le16(eeprom);
+#define CHECK_EEPROM_ERR(match) (match ? 0 : -EINVAL)
switch (val) {
case 0x7990:
- return 0;
+ return CHECK_EEPROM_ERR(is_mt7996(&dev->mt76));
+ case 0x7992:
+ return CHECK_EEPROM_ERR(is_mt7992(&dev->mt76));
default:
return -EINVAL;
}
@@ -66,13 +69,20 @@ const char *mt7996_eeprom_name(struct mt7996_dev *dev)
if (dev->bin_file_mode)
return dev->mt76.bin_file_name;
- /* reserve for future variants */
- if (dev->testmode_enable)
- return MT7996_EEPROM_DEFAULT_TM;
- else if (dev->chip_sku == MT7996_SKU_404)
- return MT7996_EEPROM_DEFAULT_404;
- else
+ switch (mt76_chip(&dev->mt76)) {
+ case 0x7990:
+ if (dev->testmode_enable)
+ return MT7996_EEPROM_DEFAULT_TM;
+ else if (dev->chip_sku == MT7996_SKU_404)
+ return MT7996_EEPROM_DEFAULT_404;
+ else
+ return MT7996_EEPROM_DEFAULT;
+ case 0x7992:
+ return dev->testmode_enable ?
+ MT7992_EEPROM_DEFAULT_TM : MT7992_EEPROM_DEFAULT;
+ default:
return MT7996_EEPROM_DEFAULT;
+ }
}
int
@@ -125,7 +135,7 @@ mt7996_eeprom_load_default(struct mt7996_dev *dev)
goto out;
}
- memcpy(eeprom, fw->data, MT7996_EEPROM_SIZE);
+ memcpy(eeprom, fw->data, mt7996_eeprom_size(dev));
dev->flash_mode = true;
out:
@@ -141,7 +151,7 @@ static int mt7996_eeprom_load_flash(struct mt7996_dev *dev)
/* return > 0 for load success, return 0 for load failed, return < 0 for non memory */
dev->bin_file_mode = mt76_check_bin_file_mode(&dev->mt76);
if (dev->bin_file_mode) {
- dev->mt76.eeprom.size = MT7996_EEPROM_SIZE;
+ dev->mt76.eeprom.size = mt7996_eeprom_size(dev);
dev->mt76.eeprom.data = devm_kzalloc(dev->mt76.dev, dev->mt76.eeprom.size,
GFP_KERNEL);
if (!dev->mt76.eeprom.data)
@@ -153,7 +163,7 @@ static int mt7996_eeprom_load_flash(struct mt7996_dev *dev)
if (mt7996_check_eeprom(dev))
return 0;
} else {
- ret = mt76_eeprom_init(&dev->mt76, MT7996_EEPROM_SIZE);
+ ret = mt76_eeprom_init(&dev->mt76, mt7996_eeprom_size(dev));
}
return ret;
@@ -186,6 +196,7 @@ static int mt7996_eeprom_load(struct mt7996_dev *dev)
{
int ret;
u8 free_block_num;
+ u16 eeprom_size = mt7996_eeprom_size(dev);
u32 block_num, i;
u32 eeprom_blk_size = MT7996_EEPROM_BLOCK_SIZE;
@@ -200,7 +211,7 @@ static int mt7996_eeprom_load(struct mt7996_dev *dev)
return -EINVAL;
/* read eeprom data from efuse */
- block_num = DIV_ROUND_UP(MT7996_EEPROM_SIZE, eeprom_blk_size);
+ block_num = DIV_ROUND_UP(eeprom_size, eeprom_blk_size);
for (i = 0; i < block_num; i++) {
ret = mt7996_mcu_get_eeprom(dev, i * eeprom_blk_size);
if (ret < 0)
diff --git a/mt7996/mcu.c b/mt7996/mcu.c
index 255d0ba..e9088ba 100644
--- a/mt7996/mcu.c
+++ b/mt7996/mcu.c
@@ -3425,7 +3425,7 @@ static int mt7996_mcu_set_eeprom_flash(struct mt7996_dev *dev)
.tag = cpu_to_le16(UNI_EFUSE_BUFFER_MODE),
.buffer_mode = EE_MODE_BUFFER
};
- u16 eeprom_size = MT7996_EEPROM_SIZE;
+ u16 eeprom_size = mt7996_eeprom_size(dev);
u8 total = DIV_ROUND_UP(eeprom_size, PER_PAGE_SIZE);
u8 *eep = (u8 *)dev->mt76.eeprom.data;
int eep_len, i;
diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h
index eb192eb..433d886 100644
--- a/mt7996/mt7996.h
+++ b/mt7996/mt7996.h
@@ -44,7 +44,12 @@
#define MT7996_EEPROM_DEFAULT "mediatek/mt7996/mt7996_eeprom.bin"
#define MT7996_EEPROM_DEFAULT_404 "mediatek/mt7996/mt7996_eeprom_dual_404.bin"
#define MT7996_EEPROM_DEFAULT_TM "mediatek/mt7996/mt7996_eeprom_tm.bin"
+#define MT7992_EEPROM_DEFAULT "mediatek/mt7996/mt7992_eeprom.bin"
+#define MT7992_EEPROM_DEFAULT_TM "mediatek/mt7996/mt7992_eeprom_tm.bin"
+
#define MT7996_EEPROM_SIZE 7680
+#define MT7992_EEPROM_SIZE 7680
+
#define MT7996_EEPROM_BLOCK_SIZE 16
#define MT7996_TOKEN_SIZE 16384
#define MT7996_HW_TOKEN_SIZE 8192
@@ -643,6 +648,11 @@ void mt7996_mcu_scs_sta_poll(struct work_struct *work);
void mt7996_tm_rf_test_event(struct mt7996_dev *dev, struct sk_buff *skb);
#endif
+static inline u16 mt7996_eeprom_size(struct mt7996_dev *dev)
+{
+ return is_mt7996(&dev->mt76) ? MT7996_EEPROM_SIZE : MT7992_EEPROM_SIZE;
+}
+
static inline u8 mt7996_max_interface_num(struct mt7996_dev *dev)
{
return min(MT7996_MAX_INTERFACES * (1 + dev->dbdc_support + dev->tbtc_support),
--
2.18.0