Skip to content

Commit

Permalink
mt76: mt7615: add support for mtd eeprom parsing
Browse files Browse the repository at this point in the history
Calibration data are often available on a specific mtd partition on
embedded devices. Take into account eeprom calibration data if
available.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
  • Loading branch information
Lorenzo Bianconi authored and Felix Fietkau committed Jun 27, 2019
1 parent eadfd98 commit f9461a6
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions drivers/net/wireless/mediatek/mt76/mt7615/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ static int mt7615_efuse_read(struct mt7615_dev *dev, u32 base,

static int mt7615_efuse_init(struct mt7615_dev *dev)
{
u32 base = mt7615_reg_map(dev, MT_EFUSE_BASE);
int len = MT7615_EEPROM_SIZE;
int ret, i;
u32 val, base = mt7615_reg_map(dev, MT_EFUSE_BASE);
int i, len = MT7615_EEPROM_SIZE;
void *buf;

if (mt76_rr(dev, base + MT_EFUSE_BASE_CTRL) & MT_EFUSE_BASE_CTRL_EMPTY)
return -EINVAL;
val = mt76_rr(dev, base + MT_EFUSE_BASE_CTRL);
if (val & MT_EFUSE_BASE_CTRL_EMPTY)
return 0;

dev->mt76.otp.data = devm_kzalloc(dev->mt76.dev, len, GFP_KERNEL);
dev->mt76.otp.size = len;
Expand All @@ -57,6 +57,8 @@ static int mt7615_efuse_init(struct mt7615_dev *dev)

buf = dev->mt76.otp.data;
for (i = 0; i + 16 <= len; i += 16) {
int ret;

ret = mt7615_efuse_read(dev, base, i, buf + i);
if (ret)
return ret;
Expand All @@ -76,6 +78,18 @@ static int mt7615_eeprom_load(struct mt7615_dev *dev)
return mt7615_efuse_init(dev);
}

static int mt7615_check_eeprom(struct mt76_dev *dev)
{
u16 val = get_unaligned_le16(dev->eeprom.data);

switch (val) {
case 0x7615:
return 0;
default:
return -EINVAL;
}
}

int mt7615_eeprom_init(struct mt7615_dev *dev)
{
int ret;
Expand All @@ -84,7 +98,10 @@ int mt7615_eeprom_init(struct mt7615_dev *dev)
if (ret < 0)
return ret;

memcpy(dev->mt76.eeprom.data, dev->mt76.otp.data, MT7615_EEPROM_SIZE);
ret = mt7615_check_eeprom(&dev->mt76);
if (ret && dev->mt76.otp.data)
memcpy(dev->mt76.eeprom.data, dev->mt76.otp.data,
MT7615_EEPROM_SIZE);

dev->mt76.cap.has_2ghz = true;
dev->mt76.cap.has_5ghz = true;
Expand Down

0 comments on commit f9461a6

Please sign in to comment.