summaryrefslogtreecommitdiff
path: root/drivers/net/wireless/mediatek/mt76/eeprom.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/mediatek/mt76/eeprom.c')
-rw-r--r--drivers/net/wireless/mediatek/mt76/eeprom.c87
1 files changed, 71 insertions, 16 deletions
diff --git a/drivers/net/wireless/mediatek/mt76/eeprom.c b/drivers/net/wireless/mediatek/mt76/eeprom.c
index dce851d42e08..36564930aef1 100644
--- a/drivers/net/wireless/mediatek/mt76/eeprom.c
+++ b/drivers/net/wireless/mediatek/mt76/eeprom.c
@@ -6,34 +6,39 @@
#include <linux/of_net.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
+#include <linux/nvmem-consumer.h>
#include <linux/etherdevice.h>
#include "mt76.h"
-int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len)
+static int mt76_get_of_eeprom_data(struct mt76_dev *dev, void *eep, int len)
{
-#if defined(CONFIG_OF) && defined(CONFIG_MTD)
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;
- size_t retlen;
- int ret;
- if (!np)
+ data = of_get_property(np, "mediatek,eeprom-data", &size);
+ if (!data)
return -ENOENT;
- data = of_get_property(np, "mediatek,eeprom-data", &size);
- if (data) {
- if (size > len)
- return -EINVAL;
+ if (size > len)
+ return -EINVAL;
- memcpy(eep, data, size);
+ memcpy(eep, data, size);
- return 0;
- }
+ return 0;
+}
+
+static int mt76_get_of_epprom_from_mtd(struct mt76_dev *dev, void *eep, int offset, int len)
+{
+#ifdef CONFIG_MTD
+ struct device_node *np = dev->dev->of_node;
+ struct mtd_info *mtd;
+ const __be32 *list;
+ const char *part;
+ phandle phandle;
+ size_t retlen;
+ int size;
+ int ret;
list = of_get_property(np, "mediatek,mtd-eeprom", &size);
if (!list)
@@ -100,6 +105,56 @@ out_put_node:
return -ENOENT;
#endif
}
+
+static int mt76_get_of_epprom_from_nvmem(struct mt76_dev *dev, void *eep, int len)
+{
+ struct device_node *np = dev->dev->of_node;
+ struct nvmem_cell *cell;
+ const void *data;
+ size_t retlen;
+ int ret = 0;
+
+ cell = of_nvmem_cell_get(np, "eeprom");
+ if (IS_ERR(cell))
+ return PTR_ERR(cell);
+
+ data = nvmem_cell_read(cell, &retlen);
+ nvmem_cell_put(cell);
+
+ if (IS_ERR(data))
+ return PTR_ERR(data);
+
+ if (retlen < len) {
+ ret = -EINVAL;
+ goto exit;
+ }
+
+ memcpy(eep, data, len);
+
+exit:
+ kfree(data);
+
+ return ret;
+}
+
+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)
+ return 0;
+
+ ret = mt76_get_of_epprom_from_mtd(dev, eep, offset, len);
+ if (!ret)
+ return 0;
+
+ return mt76_get_of_epprom_from_nvmem(dev, eep, len);
+}
EXPORT_SYMBOL_GPL(mt76_get_of_eeprom);
void