On Thu, Feb 02, 2023 at 06:33:08PM +0100, Lucas Stach wrote:
> 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 <[email protected]>
> ---
>  drivers/nvmem/core.c           | 12 ++++++++++++
>  include/linux/nvmem-provider.h |  6 ++++++
>  2 files changed, 18 insertions(+)

Applied, thanks

Sascha

> 
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index cd3328a650d6..e0110296f87b 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;
> diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
> index 1d4e1b75b204..2f130e51791c 100644
> --- a/include/linux/nvmem-provider.h
> +++ b/include/linux/nvmem-provider.h
> @@ -22,6 +22,11 @@ struct nvmem_bus {
>       int (*read)(void *ctx, unsigned int reg, void *val, size_t val_size);
>  };
>  
> +/* used for vendor specific post processing of cell data */
> +typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id,
> +                                      unsigned int offset, void *buf,
> +                                      size_t bytes);
> +
>  struct nvmem_config {
>       struct device           *dev;
>       const char              *name;
> @@ -32,6 +37,7 @@ struct nvmem_config {
>       int                     size;
>       const struct nvmem_bus  *bus;
>       void                    *priv;
> +     nvmem_cell_post_process_t cell_post_process;
>  };
>  
>  struct regmap;
> -- 
> 2.39.1
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

Reply via email to