Skip to content

Commit

Permalink
wifi: mt76: split get_of_eeprom in subfunction
Browse files Browse the repository at this point in the history
In preparation for NVMEM support, split get_of_eeprom() in subfunction
to tidy the code and facilitate the addition of alternative method to
get eeprom data. No behaviour change intended.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
  • Loading branch information
Ansuel committed Mar 25, 2023
1 parent 021ded3 commit 71264ff
Showing 1 changed file with 46 additions and 15 deletions.
61 changes: 46 additions & 15 deletions eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,28 @@
#include <linux/etherdevice.h>
#include "mt76.h"

int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len)
#ifdef CONFIG_OF
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_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;
Expand All @@ -22,19 +41,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;
Expand Down Expand Up @@ -96,6 +102,31 @@ int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len)
out_put_node:
of_node_put(np);
return ret;
}
#endif
#endif

int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len)
{
#if defined(CONFIG_OF)
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_mtd(dev, eep, offset, len);
if (!ret)
goto exit;
#endif

exit:
return ret;
#else
return -ENOENT;
#endif
Expand Down

0 comments on commit 71264ff

Please sign in to comment.