Commit 86c71d3d authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Felix Fietkau

mt76: move eeprom utility routines in mt76x02_eeprom.h

Move shared eeprom utility routines in mt76x02_eeprom.h and
remove duplicated code
Signed-off-by: default avatarLorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent eef40d20
...@@ -21,31 +21,6 @@ ...@@ -21,31 +21,6 @@
#include "mt76x0.h" #include "mt76x0.h"
#include "eeprom.h" #include "eeprom.h"
static bool
field_valid(u8 val)
{
return val != 0xff;
}
static s8
field_validate(u8 val)
{
if (!field_valid(val))
return 0;
return val;
}
static inline int
sign_extend(u32 val, unsigned int size)
{
bool sign = val & BIT(size - 1);
val &= BIT(size - 1) - 1;
return sign ? val : -val;
}
static int static int
mt76x0_efuse_read(struct mt76x0_dev *dev, u16 addr, u8 *data, mt76x0_efuse_read(struct mt76x0_dev *dev, u16 addr, u8 *data,
enum mt76x0_eeprom_access_modes mode) enum mt76x0_eeprom_access_modes mode)
...@@ -137,14 +112,14 @@ mt76x0_set_chip_cap(struct mt76x0_dev *dev, u8 *eeprom) ...@@ -137,14 +112,14 @@ mt76x0_set_chip_cap(struct mt76x0_dev *dev, u8 *eeprom)
dev_dbg(dev->mt76.dev, "Has 2GHZ %d 5GHZ %d\n", dev_dbg(dev->mt76.dev, "Has 2GHZ %d 5GHZ %d\n",
dev->mt76.cap.has_2ghz, dev->mt76.cap.has_5ghz); dev->mt76.cap.has_2ghz, dev->mt76.cap.has_5ghz);
if (!field_valid(nic_conf1 & 0xff)) if (!mt76x02_field_valid(nic_conf1 & 0xff))
nic_conf1 &= 0xff00; nic_conf1 &= 0xff00;
if (nic_conf1 & MT_EE_NIC_CONF_1_HW_RF_CTRL) if (nic_conf1 & MT_EE_NIC_CONF_1_HW_RF_CTRL)
dev_err(dev->mt76.dev, dev_err(dev->mt76.dev,
"Error: this driver does not support HW RF ctrl\n"); "Error: this driver does not support HW RF ctrl\n");
if (!field_valid(nic_conf0 >> 8)) if (!mt76x02_field_valid(nic_conf0 >> 8))
return; return;
if (FIELD_GET(MT_EE_NIC_CONF_0_RX_PATH, nic_conf0) > 1 || if (FIELD_GET(MT_EE_NIC_CONF_0_RX_PATH, nic_conf0) > 1 ||
...@@ -183,8 +158,8 @@ mt76x0_set_temp_offset(struct mt76x0_dev *dev, u8 *eeprom) ...@@ -183,8 +158,8 @@ mt76x0_set_temp_offset(struct mt76x0_dev *dev, u8 *eeprom)
{ {
u8 temp = eeprom[MT_EE_TEMP_OFFSET]; u8 temp = eeprom[MT_EE_TEMP_OFFSET];
if (field_valid(temp)) if (mt76x02_field_valid(temp))
dev->ee->temp_off = sign_extend(temp, 8); dev->ee->temp_off = mt76x02_sign_extend(temp, 8);
else else
dev->ee->temp_off = -10; dev->ee->temp_off = -10;
} }
...@@ -231,8 +206,13 @@ mt76x0_set_rf_freq_off(struct mt76x0_dev *dev, u8 *eeprom) ...@@ -231,8 +206,13 @@ mt76x0_set_rf_freq_off(struct mt76x0_dev *dev, u8 *eeprom)
{ {
u8 comp; u8 comp;
dev->ee->rf_freq_off = field_validate(eeprom[MT_EE_FREQ_OFFSET]); comp = eeprom[MT_EE_FREQ_OFFSET_COMPENSATION];
comp = field_validate(eeprom[MT_EE_FREQ_OFFSET_COMPENSATION]); if (!mt76x02_field_valid(comp))
comp = 0;
dev->ee->rf_freq_off = eeprom[MT_EE_FREQ_OFFSET];
if (!mt76x02_field_valid(dev->ee->rf_freq_off))
dev->ee->rf_freq_off = 0;
if (comp & BIT(7)) if (comp & BIT(7))
dev->ee->rf_freq_off -= comp & 0x7f; dev->ee->rf_freq_off -= comp & 0x7f;
...@@ -311,7 +291,7 @@ get_delta(u8 val) ...@@ -311,7 +291,7 @@ get_delta(u8 val)
{ {
s8 ret; s8 ret;
if (!field_valid(val) || !(val & BIT(7))) if (!mt76x02_field_valid(val) || !(val & BIT(7)))
return 0; return 0;
ret = val & 0x1f; ret = val & 0x1f;
......
...@@ -121,4 +121,19 @@ enum mt76x02_eeprom_field { ...@@ -121,4 +121,19 @@ enum mt76x02_eeprom_field {
#define MT_EFUSE_USAGE_MAP_SIZE (MT_EE_USAGE_MAP_END - \ #define MT_EFUSE_USAGE_MAP_SIZE (MT_EE_USAGE_MAP_END - \
MT_EE_USAGE_MAP_START + 1) MT_EE_USAGE_MAP_START + 1)
static inline bool mt76x02_field_valid(u8 val)
{
return val != 0 && val != 0xff;
}
static inline int
mt76x02_sign_extend(u32 val, unsigned int size)
{
bool sign = val & BIT(size - 1);
val &= BIT(size - 1) - 1;
return sign ? val : -val;
}
#endif /* __MT76x02_EEPROM_H */ #endif /* __MT76x02_EEPROM_H */
...@@ -259,28 +259,12 @@ mt76x2_eeprom_load(struct mt76x2_dev *dev) ...@@ -259,28 +259,12 @@ mt76x2_eeprom_load(struct mt76x2_dev *dev)
return 0; return 0;
} }
static inline int
mt76x2_sign_extend(u32 val, unsigned int size)
{
bool sign = val & BIT(size - 1);
val &= BIT(size - 1) - 1;
return sign ? val : -val;
}
static inline int static inline int
mt76x2_sign_extend_optional(u32 val, unsigned int size) mt76x2_sign_extend_optional(u32 val, unsigned int size)
{ {
bool enable = val & BIT(size); bool enable = val & BIT(size);
return enable ? mt76x2_sign_extend(val, size) : 0; return enable ? mt76x02_sign_extend(val, size) : 0;
}
static bool
field_valid(u8 val)
{
return val != 0 && val != 0xff;
} }
static void static void
...@@ -288,14 +272,14 @@ mt76x2_set_rx_gain_group(struct mt76x2_dev *dev, u8 val) ...@@ -288,14 +272,14 @@ mt76x2_set_rx_gain_group(struct mt76x2_dev *dev, u8 val)
{ {
s8 *dest = dev->cal.rx.high_gain; s8 *dest = dev->cal.rx.high_gain;
if (!field_valid(val)) { if (!mt76x02_field_valid(val)) {
dest[0] = 0; dest[0] = 0;
dest[1] = 0; dest[1] = 0;
return; return;
} }
dest[0] = mt76x2_sign_extend(val, 4); dest[0] = mt76x02_sign_extend(val, 4);
dest[1] = mt76x2_sign_extend(val >> 4, 4); dest[1] = mt76x02_sign_extend(val >> 4, 4);
} }
static void static void
...@@ -303,7 +287,7 @@ mt76x2_set_rssi_offset(struct mt76x2_dev *dev, int chain, u8 val) ...@@ -303,7 +287,7 @@ mt76x2_set_rssi_offset(struct mt76x2_dev *dev, int chain, u8 val)
{ {
s8 *dest = dev->cal.rx.rssi_offset; s8 *dest = dev->cal.rx.rssi_offset;
if (!field_valid(val)) { if (!mt76x02_field_valid(val)) {
dest[chain] = 0; dest[chain] = 0;
return; return;
} }
...@@ -384,10 +368,10 @@ void mt76x2_read_rx_gain(struct mt76x2_dev *dev) ...@@ -384,10 +368,10 @@ void mt76x2_read_rx_gain(struct mt76x2_dev *dev)
val = mt76x2_eeprom_get(dev, MT_EE_RSSI_OFFSET_5G_1); val = mt76x2_eeprom_get(dev, MT_EE_RSSI_OFFSET_5G_1);
lna_5g[2] = val >> 8; lna_5g[2] = val >> 8;
if (!field_valid(lna_5g[1])) if (!mt76x02_field_valid(lna_5g[1]))
lna_5g[1] = lna_5g[0]; lna_5g[1] = lna_5g[0];
if (!field_valid(lna_5g[2])) if (!mt76x02_field_valid(lna_5g[2]))
lna_5g[2] = lna_5g[0]; lna_5g[2] = lna_5g[0];
dev->cal.rx.mcu_gain = (lna_2g & 0xff); dev->cal.rx.mcu_gain = (lna_2g & 0xff);
...@@ -413,14 +397,14 @@ void mt76x2_read_rx_gain(struct mt76x2_dev *dev) ...@@ -413,14 +397,14 @@ void mt76x2_read_rx_gain(struct mt76x2_dev *dev)
if (lna == 0xff) if (lna == 0xff)
lna = 0; lna = 0;
dev->cal.rx.lna_gain = mt76x2_sign_extend(lna, 8); dev->cal.rx.lna_gain = mt76x02_sign_extend(lna, 8);
} }
EXPORT_SYMBOL_GPL(mt76x2_read_rx_gain); EXPORT_SYMBOL_GPL(mt76x2_read_rx_gain);
static s8 static s8
mt76x2_rate_power_val(u8 val) mt76x2_rate_power_val(u8 val)
{ {
if (!field_valid(val)) if (!mt76x02_field_valid(val))
return 0; return 0;
return mt76x2_sign_extend_optional(val, 7); return mt76x2_sign_extend_optional(val, 7);
...@@ -601,7 +585,8 @@ void mt76x2_get_power_info(struct mt76x2_dev *dev, ...@@ -601,7 +585,8 @@ void mt76x2_get_power_info(struct mt76x2_dev *dev,
MT_EE_TX_POWER_1_START_2G); MT_EE_TX_POWER_1_START_2G);
} }
if (mt76x2_tssi_enabled(dev) || !field_valid(t->target_power)) if (mt76x2_tssi_enabled(dev) ||
!mt76x02_field_valid(t->target_power))
t->target_power = t->chain[0].target_power; t->target_power = t->chain[0].target_power;
t->delta_bw40 = mt76x2_rate_power_val(bw40); t->delta_bw40 = mt76x2_rate_power_val(bw40);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment