* [PATCH 3/5] nvmem: provider: align read/write callback prototype with upstream
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 ` Ahmad Fatoum
2021-05-31 7:24 ` [PATCH 4/5] nvmem: add nvmem_regmap_register helper Ahmad Fatoum
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2021-05-31 7:24 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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>
---
drivers/eeprom/at24.c | 17 +++++------------
drivers/net/phy/mv88e6xxx/chip.c | 11 +++++------
drivers/nvmem/bsec.c | 12 +++++-------
drivers/nvmem/core.c | 14 ++++++++------
drivers/nvmem/eeprom_93xx46.c | 13 +++++--------
drivers/nvmem/ocotp.c | 12 +++++-------
drivers/nvmem/rave-sp-eeprom.c | 15 +++++----------
drivers/nvmem/snvs_lpgpr.c | 13 +++++--------
drivers/rtc/rtc-imxdi.c | 13 +++++--------
include/linux/nvmem-provider.h | 7 +++----
10 files changed, 51 insertions(+), 76 deletions(-)
diff --git a/drivers/eeprom/at24.c b/drivers/eeprom/at24.c
index 8c04c5684b61..1d35088c6bbc 100644
--- a/drivers/eeprom/at24.c
+++ b/drivers/eeprom/at24.c
@@ -245,12 +245,9 @@ static ssize_t at24_read(struct at24_data *at24,
return retval;
}
-static int at24_nvmem_read(struct device_d *dev, int off,
- void *buf, int count)
+static int at24_nvmem_read(void *ctx, unsigned off, void *buf, size_t count)
{
- struct at24_data *at24 = dev->parent->priv;
-
- return at24_read(at24, buf, off, count);
+ return at24_read(ctx, buf, off, count);
}
/*
@@ -363,12 +360,9 @@ static ssize_t at24_write(struct at24_data *at24, const char *buf, loff_t off,
return retval;
}
-static int at24_nvmem_write(struct device_d *dev, const int off,
- const void *buf, int count)
+static int at24_nvmem_write(void *ctx, unsigned off, const void *buf, size_t count)
{
- struct at24_data *at24 = dev->parent->priv;
-
- return at24_write(at24, buf, off, count);
+ return at24_write(ctx, buf, off, count);
}
static const struct nvmem_bus at24_nvmem_bus = {
@@ -495,14 +489,13 @@ static int at24_probe(struct device_d *dev)
at24->nvmem_config.name = devname;
at24->nvmem_config.dev = dev;
+ at24->nvmem_config.priv = at24;
at24->nvmem_config.read_only = !writable;
at24->nvmem_config.bus = &at24_nvmem_bus;
at24->nvmem_config.stride = 1;
at24->nvmem_config.word_size = 1;
at24->nvmem_config.size = chip.byte_len;
- dev->priv = at24;
-
at24->nvmem = nvmem_register(&at24->nvmem_config);
err = PTR_ERR_OR_ZERO(at24->nvmem);
if (err)
diff --git a/drivers/net/phy/mv88e6xxx/chip.c b/drivers/net/phy/mv88e6xxx/chip.c
index b1bffe5cbc4e..873c6f84634b 100644
--- a/drivers/net/phy/mv88e6xxx/chip.c
+++ b/drivers/net/phy/mv88e6xxx/chip.c
@@ -779,10 +779,9 @@ static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
return 0;
}
-static int mv88e6xxx_eeprom_read(struct device_d *dev, const int offset,
- void *val, int bytes)
+static int mv88e6xxx_eeprom_read(void *ctx, unsigned offset, void *val, size_t bytes)
{
- struct mv88e6xxx_chip *chip = dev->parent->priv;
+ struct mv88e6xxx_chip *chip = ctx;
struct ethtool_eeprom eeprom = {
.offset = offset,
.len = bytes,
@@ -794,10 +793,9 @@ static int mv88e6xxx_eeprom_read(struct device_d *dev, const int offset,
return chip->info->ops->get_eeprom(chip, &eeprom, val);
}
-static int mv88e6xxx_eeprom_write(struct device_d *dev, const int offset,
- const void *val, int bytes)
+static int mv88e6xxx_eeprom_write(void *ctx, unsigned offset, const void *val, size_t bytes)
{
- struct mv88e6xxx_chip *chip = dev->parent->priv;
+ struct mv88e6xxx_chip *chip = ctx;
struct ethtool_eeprom eeprom = {
.offset = offset,
.len = bytes,
@@ -883,6 +881,7 @@ static int mv88e6xxx_probe(struct device_d *dev)
struct nvmem_config config = {
.name = basprintf("%s-eeprom", dev_name(dev)),
.dev = dev,
+ .priv = chip,
.word_size = 1,
.stride = 1,
.size = eeprom_len,
diff --git a/drivers/nvmem/bsec.c b/drivers/nvmem/bsec.c
index 836e62ecbcc7..f154864d266e 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;
@@ -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))
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 2a1c4b694145..cfeecf70cd5d 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -33,6 +33,7 @@ struct nvmem_device {
size_t size;
bool read_only;
struct cdev cdev;
+ void *priv;
};
struct nvmem_cell {
@@ -206,6 +207,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
nvmem->bus = config->bus;
np = config->dev->device_node;
nvmem->dev.device_node = np;
+ nvmem->priv = config->priv;
nvmem->read_only = of_property_read_bool(np, "read-only") |
config->read_only;
@@ -507,7 +509,7 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem,
{
int rc;
- rc = nvmem->bus->read(&nvmem->dev, cell->offset, buf, cell->bytes);
+ rc = nvmem->bus->read(nvmem->priv, cell->offset, buf, cell->bytes);
if (IS_ERR_VALUE(rc))
return rc;
@@ -572,7 +574,7 @@ static inline void *nvmem_cell_prepare_write_buffer(struct nvmem_cell *cell,
*b <<= bit_offset;
/* setup the first byte with lsb bits from nvmem */
- rc = nvmem->bus->read(&nvmem->dev, cell->offset, &v, 1);
+ rc = nvmem->bus->read(nvmem->priv, cell->offset, &v, 1);
*b++ |= GENMASK(bit_offset - 1, 0) & v;
/* setup rest of the byte if any */
@@ -589,7 +591,7 @@ static inline void *nvmem_cell_prepare_write_buffer(struct nvmem_cell *cell,
/* if it's not end on byte boundary */
if ((nbits + bit_offset) % BITS_PER_BYTE) {
/* setup the last byte with msb bits from nvmem */
- rc = nvmem->bus->read(&nvmem->dev, cell->offset + cell->bytes - 1,
+ rc = nvmem->bus->read(nvmem->priv, cell->offset + cell->bytes - 1,
&v, 1);
*p |= GENMASK(7, (nbits + bit_offset) % BITS_PER_BYTE) & v;
@@ -622,7 +624,7 @@ int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len)
return PTR_ERR(buf);
}
- rc = nvmem->bus->write(&nvmem->dev, cell->offset, buf, cell->bytes);
+ rc = nvmem->bus->write(nvmem->priv, cell->offset, buf, cell->bytes);
/* free the tmp buffer */
if (cell->bit_offset || cell->nbits)
@@ -719,7 +721,7 @@ int nvmem_device_read(struct nvmem_device *nvmem,
if (!bytes)
return 0;
- rc = nvmem->bus->read(&nvmem->dev, offset, buf, bytes);
+ rc = nvmem->bus->read(nvmem->priv, offset, buf, bytes);
if (IS_ERR_VALUE(rc))
return rc;
@@ -753,7 +755,7 @@ int nvmem_device_write(struct nvmem_device *nvmem,
if (!bytes)
return 0;
- rc = nvmem->bus->write(&nvmem->dev, offset, buf, bytes);
+ rc = nvmem->bus->write(nvmem->priv, offset, buf, bytes);
if (IS_ERR_VALUE(rc))
return rc;
diff --git a/drivers/nvmem/eeprom_93xx46.c b/drivers/nvmem/eeprom_93xx46.c
index 49ed396dc210..5833cb0d86ab 100644
--- a/drivers/nvmem/eeprom_93xx46.c
+++ b/drivers/nvmem/eeprom_93xx46.c
@@ -79,10 +79,9 @@ static inline bool has_quirk_instruction_length(struct eeprom_93xx46_dev *edev)
return edev->pdata->quirks & EEPROM_93XX46_QUIRK_INSTRUCTION_LENGTH;
}
-static int eeprom_93xx46_read(struct device_d *dev, int off,
- void *val, int count)
+static int eeprom_93xx46_read(void *ctx, unsigned off, void *val, size_t count)
{
- struct eeprom_93xx46_dev *edev = dev->parent->priv;
+ struct eeprom_93xx46_dev *edev = ctx;
char *buf = val;
int err = 0;
@@ -241,10 +240,9 @@ eeprom_93xx46_write_word(struct eeprom_93xx46_dev *edev,
return ret;
}
-static int eeprom_93xx46_write(struct device_d *dev, const int off,
- const void *val, int count)
+static int eeprom_93xx46_write(void *ctx, unsigned off, const void *val, size_t count)
{
- struct eeprom_93xx46_dev *edev = dev->parent->priv;
+ struct eeprom_93xx46_dev *edev = ctx;
const char *buf = val;
int i, ret, step = 1;
@@ -411,14 +409,13 @@ static int eeprom_93xx46_probe(struct device_d *dev)
edev->size = 128;
edev->nvmem_config.name = dev_name(&spi->dev);
edev->nvmem_config.dev = &spi->dev;
+ edev->nvmem_config.priv = edev;
edev->nvmem_config.read_only = pd->flags & EE_READONLY;
edev->nvmem_config.bus = &eeprom_93xx46_nvmem_bus;
edev->nvmem_config.stride = 4;
edev->nvmem_config.word_size = 1;
edev->nvmem_config.size = edev->size;
- dev->priv = edev;
-
edev->nvmem = nvmem_register(&edev->nvmem_config);
if (IS_ERR(edev->nvmem)) {
err = PTR_ERR(edev->nvmem);
diff --git a/drivers/nvmem/ocotp.c b/drivers/nvmem/ocotp.c
index cee50955e97f..b2fad3c68770 100644
--- a/drivers/nvmem/ocotp.c
+++ b/drivers/nvmem/ocotp.c
@@ -673,18 +673,16 @@ 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)
+static int imx_ocotp_write(void *ctx, unsigned offset, const void *val, size_t bytes)
{
- struct ocotp_priv *priv = dev->parent->priv;
+ struct ocotp_priv *priv = ctx;
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)
+static int imx_ocotp_read(void *ctx, unsigned offset, void *val, size_t bytes)
{
- struct ocotp_priv *priv = dev->parent->priv;
+ struct ocotp_priv *priv = ctx;
return regmap_bulk_read(priv->map, offset, val, bytes);
}
@@ -746,11 +744,11 @@ static int imx_ocotp_probe(struct device_d *dev)
priv->config.name = "imx-ocotp";
priv->config.dev = dev;
+ priv->config.priv = priv;
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))
diff --git a/drivers/nvmem/rave-sp-eeprom.c b/drivers/nvmem/rave-sp-eeprom.c
index 6c6ed17f18f6..f27491e5472b 100644
--- a/drivers/nvmem/rave-sp-eeprom.c
+++ b/drivers/nvmem/rave-sp-eeprom.c
@@ -280,19 +280,15 @@ static int rave_sp_eeprom_access(struct rave_sp_eeprom *eeprom,
return 0;
}
-static int rave_sp_eeprom_read(struct device_d *dev, const int offset,
- void *val, int bytes)
+static int rave_sp_eeprom_read(void *ctx, unsigned offset, void *val, size_t bytes)
{
- return rave_sp_eeprom_access(dev->parent->priv,
- RAVE_SP_EEPROM_READ,
+ return rave_sp_eeprom_access(ctx, RAVE_SP_EEPROM_READ,
offset, val, bytes);
}
-static int rave_sp_eeprom_write(struct device_d *dev, const int offset,
- const void *val, int bytes)
+static int rave_sp_eeprom_write(void *ctx, unsigned offset, const void *val, size_t bytes)
{
- return rave_sp_eeprom_access(dev->parent->priv,
- RAVE_SP_EEPROM_WRITE,
+ return rave_sp_eeprom_access(ctx, RAVE_SP_EEPROM_WRITE,
offset, (void *)val, bytes);
}
@@ -329,8 +325,6 @@ static int rave_sp_eeprom_probe(struct device_d *dev)
eeprom->address = reg[0];
eeprom->sp = sp;
- dev->priv = eeprom;
-
if (size > SZ_8K)
eeprom->header_size = RAVE_SP_EEPROM_HEADER_BIG;
else
@@ -343,6 +337,7 @@ static int rave_sp_eeprom_probe(struct device_d *dev)
of_property_read_string(dev->device_node, "zii,eeprom-name",
&config.name);
config.dev = dev;
+ config.priv = eeprom;
config.word_size = 1;
config.stride = 1;
config.size = reg[1];
diff --git a/drivers/nvmem/snvs_lpgpr.c b/drivers/nvmem/snvs_lpgpr.c
index fe7fe599f65e..1890af135d61 100644
--- a/drivers/nvmem/snvs_lpgpr.c
+++ b/drivers/nvmem/snvs_lpgpr.c
@@ -42,10 +42,9 @@ static const struct snvs_lpgpr_cfg snvs_lpgpr_cfg_imx6q = {
.offset_lplr = IMX6Q_SNVS_LPLR,
};
-static int snvs_lpgpr_write(struct device_d *dev, const int offset,
- const void *val, int bytes)
+static int snvs_lpgpr_write(void *ctx, unsigned offset, const void *val, size_t bytes)
{
- struct snvs_lpgpr_priv *priv = dev->parent->priv;
+ struct snvs_lpgpr_priv *priv = ctx;
const struct snvs_lpgpr_cfg *dcfg = priv->dcfg;
unsigned int lock_reg;
int ret;
@@ -68,10 +67,9 @@ static int snvs_lpgpr_write(struct device_d *dev, const int offset,
bytes);
}
-static int snvs_lpgpr_read(struct device_d *dev, const int offset, void *val,
- int bytes)
+static int snvs_lpgpr_read(void *ctx, unsigned offset, void *val, size_t bytes)
{
- struct snvs_lpgpr_priv *priv = dev->parent->priv;
+ struct snvs_lpgpr_priv *priv = ctx;
const struct snvs_lpgpr_cfg *dcfg = priv->dcfg;
return regmap_bulk_read(priv->regmap, dcfg->offset + offset,
@@ -113,6 +111,7 @@ static int snvs_lpgpr_probe(struct device_d *dev)
cfg = &priv->cfg;
cfg->name = dev_name(dev);
cfg->dev = dev;
+ cfg->priv = priv;
cfg->stride = 4;
cfg->word_size = 4;
cfg->size = 4;
@@ -124,8 +123,6 @@ static int snvs_lpgpr_probe(struct device_d *dev)
return PTR_ERR(nvmem);
}
- dev->priv = priv;
-
return 0;
}
diff --git a/drivers/rtc/rtc-imxdi.c b/drivers/rtc/rtc-imxdi.c
index 8fcaf631fff9..82ed6d500753 100644
--- a/drivers/rtc/rtc-imxdi.c
+++ b/drivers/rtc/rtc-imxdi.c
@@ -511,10 +511,9 @@ static const struct rtc_class_ops dryice_rtc_ops = {
.set_time = dryice_rtc_set_time,
};
-static int nvstore_write(struct device_d *dev, const int reg, const void *val,
- int bytes)
+static int nvstore_write(void *ctx, unsigned reg, const void *val, size_t bytes)
{
- struct imxdi_dev *imxdi = dev->parent->priv;
+ struct imxdi_dev *imxdi = ctx;
const u32 *val32 = val;
if (bytes != 4)
@@ -525,10 +524,9 @@ static int nvstore_write(struct device_d *dev, const int reg, const void *val,
return 0;
}
-static int nvstore_read(struct device_d *dev, const int reg, void *val,
- int bytes)
+static int nvstore_read(void *ctx, unsigned reg, void *val, size_t bytes)
{
- struct imxdi_dev *imxdi = dev->parent->priv;
+ struct imxdi_dev *imxdi = ctx;
u32 *val32 = val;
if (bytes != 4)
@@ -588,9 +586,8 @@ static int __init dryice_rtc_probe(struct device_d *dev)
if (ret)
goto err;
- dev->priv = imxdi;
-
nvstore_nvmem_config.dev = dev;
+ nvstore_nvmem_config.priv = imxdi;
imxdi->nvmem = nvmem_register(&nvstore_nvmem_config);
if (IS_ENABLED(CONFIG_NVMEM) && IS_ERR(imxdi->nvmem)) {
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index 6ef5ea6854d9..ac9ad21711aa 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -18,10 +18,8 @@
struct nvmem_device;
struct nvmem_bus {
- int (*write)(struct device_d *dev, const int reg, const void *val,
- int val_size);
- int (*read)(struct device_d *dev, const int reg, void *val,
- int val_size);
+ int (*write)(void *ctx, unsigned int reg, const void *val, size_t val_size);
+ int (*read)(void *ctx, unsigned int reg, void *val, size_t val_size);
};
struct nvmem_config {
@@ -32,6 +30,7 @@ struct nvmem_config {
int word_size;
int size;
const struct nvmem_bus *bus;
+ void *priv;
};
#if IS_ENABLED(CONFIG_NVMEM)
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 5/5] nvmem: stm32-bsec: simplify using new nvmem_regmap_register
2021-05-31 7:24 [PATCH 0/5] add regmap helpers for NVMEM and i2c Ahmad Fatoum
` (3 preceding siblings ...)
2021-05-31 7:24 ` [PATCH 4/5] nvmem: add nvmem_regmap_register helper Ahmad Fatoum
@ 2021-05-31 7:24 ` Ahmad Fatoum
2021-06-02 6:36 ` [PATCH 0/5] add regmap helpers for NVMEM and i2c Sascha Hauer
5 siblings, 0 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2021-05-31 7:24 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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
^ permalink raw reply [flat|nested] 7+ messages in thread