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 Mar 25, 2023
1 parent 71264ff commit 38ec69d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 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 @@ -104,6 +105,39 @@ int mt76_get_of_epprom_mtd(struct mt76_dev *dev, void *eep, int offset, int len)
return ret;
}
#endif

#if defined(CONFIG_NVMEM) && defined(CONFIG_MTD)
int mt76_get_of_eeprom_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;
}
#endif
#endif

int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len)
Expand All @@ -125,6 +159,9 @@ int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len)
goto exit;
#endif

#if defined(CONFIG_NVMEM) && defined(CONFIG_MTD)
ret = mt76_get_of_eeprom_nvmem(dev, epp, len);
#endif
exit:
return ret;
#else
Expand Down

0 comments on commit 38ec69d

Please sign in to comment.