summaryrefslogtreecommitdiffstats
path: root/drivers/nvmem/bsec.c
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2021-05-31 09:24:04 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-06-02 10:16:08 +0200
commite94dddebbccd1d8fe4901dbc84d9bcde20f9039d (patch)
tree3662c0635143a1c6dc3996f8c52ec2fe9bdb1caa /drivers/nvmem/bsec.c
parent2a2c65fa6fead0daa79bd3d6667b9f63b3b2106b (diff)
downloadbarebox-e94dddebbccd1d8fe4901dbc84d9bcde20f9039d.tar.gz
barebox-e94dddebbccd1d8fe4901dbc84d9bcde20f9039d.tar.xz
nvmem: provider: align read/write callback prototype with upstream
barebox allocates a NVMEM device as part of nvmem_register, which it passes along to the callbacks. Callbacks then use dev->parent->priv to retrieve the driver private data. This indirection makes definition of nvmem helpers inconvenient, because they would need to hijack the ->priv member of the hardware device. Avoid this by passing along some private data pointer defined at registration time, just like Linux does. This will be used in a follow up commit. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210531072406.5630-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/nvmem/bsec.c')
-rw-r--r--drivers/nvmem/bsec.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/drivers/nvmem/bsec.c b/drivers/nvmem/bsec.c
index 836e62ecbc..0e772b4ea6 100644
--- a/drivers/nvmem/bsec.c
+++ b/drivers/nvmem/bsec.c
@@ -72,10 +72,9 @@ static struct regmap_bus stm32_bsec_regmap_bus = {
.reg_read = stm32_bsec_read_shadow,
};
-static int stm32_bsec_write(struct device_d *dev, int offset,
- const void *val, int bytes)
+static int stm32_bsec_write(void *ctx, unsigned offset, const void *val, size_t bytes)
{
- struct bsec_priv *priv = dev->parent->priv;
+ struct bsec_priv *priv = ctx;
/* Allow only writing complete 32-bits aligned words */
if ((bytes % 4) || (offset % 4))
@@ -84,10 +83,9 @@ static int stm32_bsec_write(struct device_d *dev, int offset,
return regmap_bulk_write(priv->map, offset, val, bytes);
}
-static int stm32_bsec_read(struct device_d *dev, int offset,
- void *buf, int bytes)
+static int stm32_bsec_read(void *ctx, unsigned offset, void *buf, size_t bytes)
{
- struct bsec_priv *priv = dev->parent->priv;
+ struct bsec_priv *priv = ctx;
u32 roffset, rbytes, val;
u8 *buf8 = buf, *val8 = (u8 *)&val;
int i, j = 0, ret, skip_bytes, size;
@@ -103,7 +101,7 @@ static int stm32_bsec_read(struct device_d *dev, int offset,
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);
+ dev_err(&priv->dev, "Can't read data%d (%d)\n", i, ret);
return ret;
}
@@ -218,12 +216,12 @@ static int stm32_bsec_probe(struct device_d *dev)
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;
- dev->priv = priv;
nvmem = nvmem_register(&priv->config);
if (IS_ERR(nvmem))