From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 5/5] nvmem: stm32-bsec: simplify using new nvmem_regmap_register
Date: Mon, 31 May 2021 09:24:06 +0200 [thread overview]
Message-ID: <20210531072406.5630-6-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20210531072406.5630-1-a.fatoum@pengutronix.de>
The nvmem_regmap_register code is mostly copy-pasted from the stm32-bsec
driver, so have it use the new helper.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/nvmem/bsec.c | 92 ++++++--------------------------------------
1 file changed, 11 insertions(+), 81 deletions(-)
diff --git a/drivers/nvmem/bsec.c b/drivers/nvmem/bsec.c
index f154864d266e..509a5fa872f7 100644
--- a/drivers/nvmem/bsec.c
+++ b/drivers/nvmem/bsec.c
@@ -21,9 +21,7 @@
#define BSEC_OTP_SERIAL 13
struct bsec_priv {
- struct regmap *map;
u32 svc_id;
- struct device_d dev;
struct regmap_config map_config;
struct nvmem_config config;
};
@@ -72,59 +70,6 @@ static struct regmap_bus stm32_bsec_regmap_bus = {
.reg_read = stm32_bsec_read_shadow,
};
-static int stm32_bsec_write(void *ctx, unsigned offset, const void *val, size_t bytes)
-{
- struct bsec_priv *priv = ctx;
-
- /* Allow only writing complete 32-bits aligned words */
- if ((bytes % 4) || (offset % 4))
- return -EINVAL;
-
- return regmap_bulk_write(priv->map, offset, val, bytes);
-}
-
-static int stm32_bsec_read(void *ctx, unsigned offset, void *buf, size_t bytes)
-{
- struct bsec_priv *priv = ctx;
- u32 roffset, rbytes, val;
- u8 *buf8 = buf, *val8 = (u8 *)&val;
- int i, j = 0, ret, skip_bytes, size;
-
- /* Round unaligned access to 32-bits */
- roffset = rounddown(offset, 4);
- skip_bytes = offset & 0x3;
- rbytes = roundup(bytes + skip_bytes, 4);
-
- if (roffset + rbytes > priv->config.size)
- return -EINVAL;
-
- for (i = roffset; i < roffset + rbytes; i += 4) {
- ret = regmap_bulk_read(priv->map, i, &val, 4);
- if (ret) {
- dev_err(dev, "Can't read data%d (%d)\n", i, ret);
- return ret;
- }
-
- /* skip first bytes in case of unaligned read */
- if (skip_bytes)
- size = min(bytes, 4 - skip_bytes);
- else
- size = min(bytes, 4);
-
- memcpy(&buf8[j], &val8[skip_bytes], size);
- bytes -= size;
- j += size;
- skip_bytes = 0;
- }
-
- return 0;
-}
-
-static const struct nvmem_bus stm32_bsec_nvmem_bus = {
- .write = stm32_bsec_write,
- .read = stm32_bsec_read,
-};
-
static void stm32_bsec_set_unique_machine_id(struct regmap *map)
{
u32 unique_id[3];
@@ -151,9 +96,9 @@ static int stm32_bsec_read_mac(struct regmap *map, int offset, u8 *mac)
return 0;
}
-static void stm32_bsec_init_dt(struct bsec_priv *priv)
+static void stm32_bsec_init_dt(struct device_d *dev, struct regmap *map)
{
- struct device_node *node = priv->dev.parent->device_node;
+ struct device_node *node = dev->device_node;
struct device_node *rnode;
u32 phandle, offset;
char mac[ETH_ALEN];
@@ -162,9 +107,6 @@ static void stm32_bsec_init_dt(struct bsec_priv *priv)
int len;
int ret;
- if (!node)
- return;
-
prop = of_get_property(node, "barebox,provide-mac-address", &len);
if (!prop)
return;
@@ -177,10 +119,9 @@ static void stm32_bsec_init_dt(struct bsec_priv *priv)
rnode = of_find_node_by_phandle(phandle);
offset = be32_to_cpup(prop++);
- ret = stm32_bsec_read_mac(priv->map, offset, mac);
+ ret = stm32_bsec_read_mac(map, offset, mac);
if (ret) {
- dev_warn(&priv->dev, "error setting MAC address: %s\n",
- strerror(-ret));
+ dev_warn(dev, "error setting MAC address: %s\n", strerror(-ret));
return;
}
@@ -189,6 +130,7 @@ static void stm32_bsec_init_dt(struct bsec_priv *priv)
static int stm32_bsec_probe(struct device_d *dev)
{
+ struct regmap *map;
struct bsec_priv *priv;
int ret = 0;
const struct stm32_bsec_data *data;
@@ -202,35 +144,23 @@ static int stm32_bsec_probe(struct device_d *dev)
priv->svc_id = data->svc_id;
- dev_set_name(&priv->dev, "bsec");
- priv->dev.parent = dev;
- register_device(&priv->dev);
-
priv->map_config.reg_bits = 32;
priv->map_config.val_bits = 32;
priv->map_config.reg_stride = 4;
priv->map_config.max_register = data->num_regs;
- priv->map = regmap_init(dev, &stm32_bsec_regmap_bus, priv, &priv->map_config);
- if (IS_ERR(priv->map))
- return PTR_ERR(priv->map);
-
- priv->config.name = "stm32-bsec";
- priv->config.priv = priv;
- priv->config.dev = dev;
- priv->config.stride = 1;
- priv->config.word_size = 1;
- priv->config.size = data->num_regs;
- priv->config.bus = &stm32_bsec_nvmem_bus;
+ map = regmap_init(dev, &stm32_bsec_regmap_bus, priv, &priv->map_config);
+ if (IS_ERR(map))
+ return PTR_ERR(map);
- nvmem = nvmem_register(&priv->config);
+ nvmem = nvmem_regmap_register(map, "stm32-bsec");
if (IS_ERR(nvmem))
return PTR_ERR(nvmem);
if (IS_ENABLED(CONFIG_MACHINE_ID))
- stm32_bsec_set_unique_machine_id(priv->map);
+ stm32_bsec_set_unique_machine_id(map);
- stm32_bsec_init_dt(priv);
+ stm32_bsec_init_dt(dev, map);
return 0;
}
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2021-05-31 7:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-31 7:24 [PATCH 0/5] add regmap helpers for NVMEM and i2c Ahmad Fatoum
2021-05-31 7:24 ` [PATCH 1/5] regmap: implement regmap_init_i2c Ahmad Fatoum
2021-05-31 7:24 ` [PATCH 2/5] mfd: stpmic1: simplify using regmap_init_i2c Ahmad Fatoum
2021-05-31 7:24 ` [PATCH 3/5] nvmem: provider: align read/write callback prototype with upstream Ahmad Fatoum
2021-05-31 7:24 ` [PATCH 4/5] nvmem: add nvmem_regmap_register helper Ahmad Fatoum
2021-05-31 7:24 ` Ahmad Fatoum [this message]
2021-06-02 6:36 ` [PATCH 0/5] add regmap helpers for NVMEM and i2c Sascha Hauer
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=20210531072406.5630-6-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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