Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] wifi: mt76: add support for providing precal in nvmem cells #765

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 75 additions & 18 deletions eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Ansuel marked this conversation as resolved.
Show resolved Hide resolved
if (data) {
if (size > len)
return -EINVAL;
if (size > len)
return -EINVAL;

memcpy(eep, data, size);
memcpy(eep, data, size);

return 0;
}
return 0;
}

#ifdef CONFIG_MTD
static int mt76_get_of_epprom_from_mtd(struct mt76_dev *dev, void *eep, int offset, int len)
{
struct device_node *np = dev->dev->of_node;
struct mtd_info *mtd;
const __be32 *list;
const char *part;
phandle phandle;
int size;
size_t retlen;
int ret;

list = of_get_property(np, "mediatek,mtd-eeprom", &size);
if (!list)
Expand Down Expand Up @@ -96,9 +101,61 @@ 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

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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should also fail for retlen > len. If NVMEM cell is bigger than expected EEPROM I'd say sth it just wrong there. I wouldn't advise copying just first N bytes of NVMEM cell as you do below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh this is almost a pattern... In theory this should never happen... Should we enforce and match always the requested len?

And use != ?

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;
rmilecki marked this conversation as resolved.
Show resolved Hide resolved

ret = mt76_get_of_eeprom_data(dev, eep, len);
if (!ret)
return 0;

#ifdef CONFIG_MTD
ret = mt76_get_of_epprom_from_mtd(dev, eep, offset, len);
if (!ret)
return 0;
#endif

ret = mt76_get_of_epprom_from_nvmem(dev, eep, len);

return ret;
}
EXPORT_SYMBOL_GPL(mt76_get_of_eeprom);

Expand Down