summaryrefslogtreecommitdiffstats
path: root/drivers/nvmem
diff options
context:
space:
mode:
authorLucas Stach <l.stach@pengutronix.de>2023-02-02 18:33:08 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2023-02-06 08:42:57 +0100
commit68c9f07905c52ef36d9a73a3c9ad0186ced68d06 (patch)
tree0aba7c9c2ec02cb932e1a03bee86060297087bfc /drivers/nvmem
parent0275cbae004d3f8510589d486645cd5d205cc525 (diff)
downloadbarebox-68c9f07905c52ef36d9a73a3c9ad0186ced68d06.tar.gz
barebox-68c9f07905c52ef36d9a73a3c9ad0186ced68d06.tar.xz
nvmem: add support for post processing
This is a port of the Linux commit 5008062f1c3f ("nvmem: core: add nvmem cell post processing callback"). It looks a little different, as Linux switched to create nvmem cells at registration time, effectively deduplicating the cells, but then needed to introduce nvmem_cells_entry to be able to store the lookup name, which is used by the post-processing. As Barebox simply created a nvmem cell per lookup, as Linux did before e888d445ac33 ("nvmem: resolve cells from DT at registration time"), we can simply store the lookup name in the cell. Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Link: https://lore.barebox.org/20230202173312.504493-1-l.stach@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/nvmem')
-rw-r--r--drivers/nvmem/core.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index cd3328a650..e0110296f8 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -26,10 +26,12 @@ struct nvmem_device {
bool read_only;
struct cdev cdev;
void *priv;
+ nvmem_cell_post_process_t cell_post_process;
};
struct nvmem_cell {
const char *name;
+ const char *id;
int offset;
int bytes;
int bit_offset;
@@ -145,6 +147,7 @@ static struct nvmem_cell *nvmem_find_cell(const char *cell_id)
static void nvmem_cell_drop(struct nvmem_cell *cell)
{
list_del(&cell->node);
+ kfree(cell->id);
kfree(cell);
}
@@ -209,6 +212,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
np = config->cdev ? config->cdev->device_node : config->dev->of_node;
nvmem->dev.of_node = np;
nvmem->priv = config->priv;
+ nvmem->cell_post_process = config->cell_post_process;
if (config->read_only || !config->bus->write || of_property_read_bool(np, "read-only"))
nvmem->read_only = true;
@@ -417,6 +421,7 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
cell->offset = be32_to_cpup(addr++);
cell->bytes = be32_to_cpup(addr);
cell->name = cell_np->name;
+ cell->id = kstrdup_const(name, GFP_KERNEL);
addr = of_get_property(cell_np, "bits", &len);
if (addr && len == (2 * sizeof(u32))) {
@@ -534,6 +539,13 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem,
if (cell->bit_offset || cell->nbits)
nvmem_shift_read_buffer_in_place(cell, buf);
+ if (nvmem->cell_post_process) {
+ rc = nvmem->cell_post_process(nvmem->priv, cell->id,
+ cell->offset, buf, cell->bytes);
+ if (rc)
+ return rc;
+ }
+
*len = cell->bytes;
return 0;