From aaf90b24fde77a38ee9f0a60d7097ded6a94ad1f Mon Sep 17 00:00:00 2001 From: Ivan Mironov Date: Mon, 17 Mar 2025 01:31:11 +0100 Subject: [PATCH] wifi: mt76: mt7996: Use tx_power from default fw if EEPROM contains 0s Some Banana Pi BPI-R4-NIC-BE14 WiFi modules are sold with zeros instead of usable tx_power values in EEPROM for 2.4 GHz and 5 GHz bands. This patch replaces tx_power zeros with default values from firmware files while keeping the rest of the EEPROM data intact (including valid 6 GHz tx_power table). Signed-off-by: Ivan Mironov Cc: stable@vger.kernel.org Fixes: 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices") Closes: https://github.com/openwrt/openwrt/issues/17489 Link: https://github.com/openwrt/mt76/pull/954 --- mt7996/eeprom.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/mt7996/eeprom.c b/mt7996/eeprom.c index 53dfac02f..4299f06c7 100644 --- a/mt7996/eeprom.c +++ b/mt7996/eeprom.c @@ -87,6 +87,36 @@ mt7996_eeprom_parse_stream(const u8 *eeprom, u8 band_idx, u8 *path, } } +static void +mt7996_eeprom_fixup_tx_power(struct mt7996_dev *dev, const u8 *def) +{ + u8 *eeprom = dev->mt76.eeprom.data; + int i; + bool zeros_detected = false; + + if (!eeprom[MT_EE_TX0_POWER_2G]) { + eeprom[MT_EE_TX0_POWER_2G] = def[MT_EE_TX0_POWER_2G]; + zeros_detected = true; + } + + for (i = MT_EE_TX0_POWER_5G; i < MT_EE_TX0_POWER_5G + 5; ++i) { + if (!eeprom[i]) { + eeprom[i] = def[i]; + zeros_detected = true; + } + } + + for (i = MT_EE_TX0_POWER_6G; i < MT_EE_TX0_POWER_6G + 8; ++i) { + if (!eeprom[i]) { + eeprom[i] = def[i]; + zeros_detected = true; + } + } + + if (zeros_detected) + dev_warn(dev->mt76.dev, "eeprom tx_power zeros detected, using defaults\n"); +} + static bool mt7996_eeprom_variant_valid(struct mt7996_dev *dev, const u8 *def) { #define FEM_INT 0 @@ -142,6 +172,8 @@ mt7996_eeprom_check_or_use_default(struct mt7996_dev *dev, bool use_default) goto out; } + mt7996_eeprom_fixup_tx_power(dev, fw->data); + if (!use_default && mt7996_eeprom_variant_valid(dev, fw->data)) goto out;