mt76: support reading EEPROM data embedded in fdt
authorDaniel Golle <daniel@makrotopia.org>
Wed, 25 Aug 2021 01:32:16 +0000 (02:32 +0100)
committerFelix Fietkau <nbd@nbd.name>
Wed, 20 Oct 2021 08:36:48 +0000 (10:36 +0200)
Some platforms boot from SD card and don't come with calibration data
stored anywhere on the board.
As EEPROM data is rather small it can be embedded into the device tree
to be loaded from there by the mt76.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/eeprom.c

index 376c3bd883e5b6838a56263957111a693878e415..e65b2262e6927a9bd0de0b55052261c02175ebd4 100644 (file)
@@ -15,6 +15,7 @@ int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len)
        struct device_node *np = dev->dev->of_node;
        struct mtd_info *mtd;
        const __be32 *list;
+       const void *data;
        const char *part;
        phandle phandle;
        int size;
@@ -24,6 +25,16 @@ int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len)
        if (!np)
                return -ENOENT;
 
+       data = of_get_property(np, "mediatek,eeprom-data", &size);
+       if (data) {
+               if (size > len)
+                       return -EINVAL;
+
+               memcpy(eep, data, size);
+
+               return 0;
+       }
+
        list = of_get_property(np, "mediatek,mtd-eeprom", &size);
        if (!list)
                return -ENOENT;