diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2021-06-19 05:45:07 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2021-06-21 08:04:36 +0200 |
commit | d61d31fc4d4beaf261ff9f7f9d24907f52576d7e (patch) | |
tree | 0bd9b63fb2960acae423f6c3d91cfef27f314d79 /drivers | |
parent | 20dbfeaff73ff9417bf0fa74e373ffa1f1059a60 (diff) | |
download | barebox-d61d31fc4d4beaf261ff9f7f9d24907f52576d7e.tar.gz barebox-d61d31fc4d4beaf261ff9f7f9d24907f52576d7e.tar.xz |
nvmem: add support for nvmem-cells binding
Recently, nvmem cell and MTD partition bindings were made to coexist:
Partitions can now be compatible = "nvmem-cells"; which registers a
NVMEM provider and interprets its child nodes as cells. Teach barebox
about this. This allows fetching NVMEM cells from MTD partitions and
hostfiles.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20210619034516.6737-5-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/nvmem/Makefile | 2 | ||||
-rw-r--r-- | drivers/nvmem/core.c | 12 | ||||
-rw-r--r-- | drivers/nvmem/partition.c | 40 | ||||
-rw-r--r-- | drivers/of/partition.c | 7 |
4 files changed, 55 insertions, 6 deletions
diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index 6330f3d6e6..53c02dc785 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -3,7 +3,7 @@ # obj-$(CONFIG_NVMEM) += nvmem_core.o -nvmem_core-y := core.o regmap.o +nvmem_core-y := core.o regmap.o partition.o obj-$(CONFIG_NVMEM_RMEM) += rmem.o diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 3c14e390de..c060e627db 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -205,7 +205,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) nvmem->size = config->size; nvmem->dev.parent = config->dev; nvmem->bus = config->bus; - np = config->dev->device_node; + np = config->cdev ? config->cdev->device_node : config->dev->device_node; nvmem->dev.device_node = np; nvmem->priv = config->priv; @@ -223,10 +223,12 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) return ERR_PTR(rval); } - rval = nvmem_register_cdev(nvmem, config->name); - if (rval) { - kfree(nvmem); - return ERR_PTR(rval); + if (!config->cdev) { + rval = nvmem_register_cdev(nvmem, config->name); + if (rval) { + kfree(nvmem); + return ERR_PTR(rval); + } } list_add_tail(&nvmem->node, &nvmem_devs); diff --git a/drivers/nvmem/partition.c b/drivers/nvmem/partition.c new file mode 100644 index 0000000000..3f0bdc58de --- /dev/null +++ b/drivers/nvmem/partition.c @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <common.h> +#include <driver.h> +#include <malloc.h> +#include <xfuncs.h> +#include <errno.h> +#include <init.h> +#include <io.h> +#include <linux/nvmem-provider.h> + +static int nvmem_cdev_write(void *ctx, unsigned offset, const void *val, size_t bytes) +{ + return cdev_write(ctx, val, bytes, offset, 0); +} + +static int nvmem_cdev_read(void *ctx, unsigned offset, void *buf, size_t bytes) +{ + return cdev_read(ctx, buf, bytes, offset, 0); +} + +static struct nvmem_bus nvmem_cdev_bus = { + .read = nvmem_cdev_read, + .write = nvmem_cdev_write, +}; + +struct nvmem_device *nvmem_partition_register(struct cdev *cdev) +{ + struct nvmem_config config = {}; + + config.name = cdev->name; + config.dev = cdev->dev; + config.cdev = cdev; + config.priv = cdev; + config.stride = 1; + config.word_size = 1; + config.size = cdev->size; + config.bus = &nvmem_cdev_bus; + + return nvmem_register(&config); +} diff --git a/drivers/of/partition.c b/drivers/of/partition.c index b71716218b..b6d0523fd9 100644 --- a/drivers/of/partition.c +++ b/drivers/of/partition.c @@ -20,6 +20,7 @@ #include <linux/mtd/mtd.h> #include <linux/err.h> #include <nand.h> +#include <linux/nvmem-provider.h> #include <init.h> #include <globalvar.h> @@ -83,6 +84,12 @@ struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node) if (new) new->device_node = node;; + if (IS_ENABLED(CONFIG_NVMEM) && of_device_is_compatible(node, "nvmem-cells")) { + struct nvmem_device *nvmem = nvmem_partition_register(new); + if (IS_ERR(nvmem)) + dev_warn(cdev->dev, "nvmem registeration failed: %pe\n", nvmem); + } + free(filename); return new; |