Skip to content

Commit

Permalink
wifi: mt76: add support for providing precal in nvmem cells
Browse files Browse the repository at this point in the history
Add support for providing precal in nvmem cells by adding nvmem cell as
an alternative source for mt76_get_of_eeprom().

Nvmem cells will follow standard nvmem cell definition and needs to be
called 'precal' to be correctly identified.

Signed-off-by: Christian Marangi <[email protected]>
  • Loading branch information
Ansuel committed May 8, 2023
1 parent e7bceae commit a69380b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#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"

Expand Down Expand Up @@ -103,6 +104,37 @@ static int mt76_get_of_epprom_from_mtd(struct mt76_dev *dev, void *eep, int offs
}
#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, "precal");
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;
Expand All @@ -121,6 +153,8 @@ int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len)
return 0;
#endif

ret = mt76_get_of_epprom_from_nvmem(dev, eep, len);

return ret;
}
EXPORT_SYMBOL_GPL(mt76_get_of_eeprom);
Expand Down

0 comments on commit a69380b

Please sign in to comment.