diff --git a/eeprom.c b/eeprom.c index ea54b7af7..b2e6e1ed3 100644 --- a/eeprom.c +++ b/eeprom.c @@ -9,9 +9,27 @@ #include #include "mt76.h" -int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len) +int mt76_get_of_eeprom_data(struct mt76_dev *dev, void *eep, int len) +{ + struct device_node *np = dev->dev->of_node; + const void *data; + int size; + + data = of_get_property(np, "mediatek,eeprom-data", &size); + if (!data) + return -ENOENT; + + if (size > len) + return -EINVAL; + + memcpy(eep, data, size); + + return 0; +} + +#ifdef CONFIG_MTD +int mt76_get_of_epprom_from_mtd(struct mt76_dev *dev, void *eep, int offset, int len) { -#if defined(CONFIG_OF) && defined(CONFIG_MTD) struct device_node *np = dev->dev->of_node; struct mtd_info *mtd; const __be32 *list; @@ -22,19 +40,6 @@ int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len) size_t retlen; int ret; - 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; @@ -96,9 +101,29 @@ int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len) out_put_node: of_node_put(np); return ret; -#else - return -ENOENT; +} #endif + +int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len) +{ + struct device_node *np = dev->dev->of_node; + int ret; + + if (!np) + return -ENOENT; + + ret = mt76_get_of_eeprom_data(dev, eep, len); + if (!ret) + goto exit; + +#ifdef CONFIG_MTD + ret = mt76_get_of_epprom_from_mtd(dev, eep, offset, len); + if (!ret) + goto exit; +#endif + +exit: + return ret; } EXPORT_SYMBOL_GPL(mt76_get_of_eeprom);