mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Lucas Stach <l.stach@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 1/5] nvmem: add support for post processing
Date: Mon, 6 Feb 2023 08:43:15 +0100	[thread overview]
Message-ID: <20230206074315.GB13319@pengutronix.de> (raw)
In-Reply-To: <20230202173312.504493-1-l.stach@pengutronix.de>

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 <l.stach@pengutronix.de>
> ---
>  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 |



      parent reply	other threads:[~2023-02-06  7:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-02 17:33 Lucas Stach
2023-02-02 17:33 ` [PATCH 2/5] nvmem: ocotp: switch to nvmem_regmap_register Lucas Stach
2023-02-02 17:33 ` [PATCH 3/5] nvmem: regmap: allow to register with post processing Lucas Stach
2023-02-02 17:33 ` [PATCH 4/5] nvmem: ocotp: add post processing for MAC cells Lucas Stach
2023-02-02 17:33 ` [PATCH 5/5] ARM: dts: i.MX8MP: drop OCOTP MAC address provider Lucas Stach
2023-02-06  7:43 ` Sascha Hauer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230206074315.GB13319@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=l.stach@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox