From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>,
Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Subject: [PATCH 7/7] nvmem: ocotp: Convert to NVMEM device
Date: Tue, 22 May 2018 16:05:18 -0700 [thread overview]
Message-ID: <20180522230518.9070-8-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <20180522230518.9070-1-andrew.smirnov@gmail.com>
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>
---
drivers/nvmem/ocotp.c | 38 +++++++++++++++++++++++++++++++++++---
1 file changed, 35 insertions(+), 3 deletions(-)
diff --git a/drivers/nvmem/ocotp.c b/drivers/nvmem/ocotp.c
index 4c9927b37..1a3a30b49 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;
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
prev parent reply other threads:[~2018-05-22 23:05 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-22 23:05 [PATCH 0/7] VF610 OCOTP MAC address layout change Andrey Smirnov
2018-05-22 23:05 ` [PATCH 1/7] i.MX: ocotp: Unify code paths for reading MAC address Andrey Smirnov
2018-05-22 23:05 ` [PATCH 2/7] i.MX: ocotp: Change MAC address layout for VFxxx Andrey Smirnov
2018-05-23 8:21 ` Sascha Hauer
2018-05-25 3:06 ` Andrey Smirnov
2018-05-22 23:05 ` [PATCH 3/7] i.MX: ocotp: Simplify OCOTP field packing/unpacking Andrey Smirnov
2018-05-22 23:05 ` [PATCH 4/7] i.MX: ocotp: Simplify BF macro Andrey Smirnov
2018-05-22 23:05 ` [PATCH 5/7] i.MX: ocotp: Move OCOTP driver to drivers/nvmem Andrey Smirnov
2018-05-22 23:05 ` [PATCH 6/7] nvmem: Use name from struct nvmem_config for cdev Andrey Smirnov
2018-05-22 23:05 ` Andrey Smirnov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180522230518.9070-8-andrew.smirnov@gmail.com \
--to=andrew.smirnov@gmail.com \
--cc=barebox@lists.infradead.org \
--cc=vivien.didelot@savoirfairelinux.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox