summaryrefslogtreecommitdiffstats
path: root/drivers/nvmem
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2018-05-28 21:47:31 -0700
committerSascha Hauer <s.hauer@pengutronix.de>2018-05-31 17:26:49 +0200
commitb8dce5d3a3be4ecb92055732927f0213976902d4 (patch)
tree6cab07c899d9e4aac363d7b86cc694ea7b7dab68 /drivers/nvmem
parent611a0d0b73d55b74a43c573ef80a843c70d2baad (diff)
downloadbarebox-b8dce5d3a3be4ecb92055732927f0213976902d4.tar.gz
barebox-b8dce5d3a3be4ecb92055732927f0213976902d4.tar.xz
nvmem: ocotp: Convert to NVMEM device
Not that barebox has a proper NVMEM subsystem, convert OCOTP driver to use that to both make things more consistent with Linux and also allow accessing OCOTP fields without the need for imx_ocotp_read_field()/imx_ocotp_write_field(). Cc: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Tested-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/nvmem')
-rw-r--r--drivers/nvmem/ocotp.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/drivers/nvmem/ocotp.c b/drivers/nvmem/ocotp.c
index 8c44bbb16e..86d0b9cd07 100644
--- a/drivers/nvmem/ocotp.c
+++ b/drivers/nvmem/ocotp.c
@@ -29,6 +29,7 @@
#include <regmap.h>
#include <linux/clk.h>
#include <mach/ocotp.h>
+#include <linux/nvmem-provider.h>
/*
* a single MAC address reference has the form
@@ -105,6 +106,7 @@ struct ocotp_priv {
struct regmap_config map_config;
const struct imx_ocotp_data *data;
int mac_offset_idx;
+ struct nvmem_config config;
};
static struct ocotp_priv *imx_ocotp;
@@ -484,12 +486,34 @@ static void imx_ocotp_init_dt(struct ocotp_priv *priv)
}
}
+static int imx_ocotp_write(struct device_d *dev, const int offset,
+ const void *val, int bytes)
+{
+ struct ocotp_priv *priv = dev->parent->priv;
+
+ return regmap_bulk_write(priv->map, offset, val, bytes);
+}
+
+static int imx_ocotp_read(struct device_d *dev, const int offset, void *val,
+ int bytes)
+{
+ struct ocotp_priv *priv = dev->parent->priv;
+
+ return regmap_bulk_read(priv->map, offset, val, bytes);
+}
+
+static const struct nvmem_bus imx_ocotp_nvmem_bus = {
+ .write = imx_ocotp_write,
+ .read = imx_ocotp_read,
+};
+
static int imx_ocotp_probe(struct device_d *dev)
{
struct resource *iores;
struct ocotp_priv *priv;
int ret = 0;
const struct imx_ocotp_data *data;
+ struct nvmem_device *nvmem;
ret = dev_get_drvdata(dev, (const void **)&data);
if (ret)
@@ -520,9 +544,17 @@ static int imx_ocotp_probe(struct device_d *dev)
if (IS_ERR(priv->map))
return PTR_ERR(priv->map);
- ret = regmap_register_cdev(priv->map, "imx-ocotp");
- if (ret)
- return ret;
+ priv->config.name = "imx-ocotp";
+ priv->config.dev = dev;
+ priv->config.stride = 4;
+ priv->config.word_size = 4;
+ priv->config.size = data->num_regs;
+ priv->config.bus = &imx_ocotp_nvmem_bus;
+ dev->priv = priv;
+
+ nvmem = nvmem_register(&priv->config);
+ if (IS_ERR(nvmem))
+ return PTR_ERR(nvmem);
imx_ocotp = priv;