From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Jonas Rebmann <jre@pengutronix.de>,
Sascha Hauer <s.hauer@pengutronix.de>,
"open list:BAREBOX" <barebox@lists.infradead.org>
Subject: Re: [PATCH] nvmem: core: Allow sub-register width nvmem_regmap_write()
Date: Tue, 26 May 2026 07:39:11 +0200 [thread overview]
Message-ID: <c36d3ed4-35b4-49b5-80ca-bfb442f5ee28@pengutronix.de> (raw)
In-Reply-To: <20260525-short_nvmem_write-v1-1-ff741d6ff1d5@pengutronix.de>
On 5/25/26 13:45, Jonas Rebmann wrote:
> From: Ahmad Fatoum <a.fatoum@pengutronix.de>
>
> The previous implementation of nvmem_regmap_write() required the
> supplied value to be a multiple of the register size defined by the
> driver ("expect users to observe alignment").
>
> This is however not respected by nvmem cell functions
> nvmem_cell_prepare_write_buffer()/__nvmem_cell_entry_write() which
> prepare the value buffer based on the "bits" supplied in the devicetree,
> resulting in EINVAL errors if an nvmem cell with "bits" spanning less
> bytes than val_bytes = DIV_ROUND_UP(config->val_bits, 8) of the nvmem
> driver.
>
> To resolve this, accept buffers shorter than val_bytes, and place them
> correctly with regard to endianness.
>
> Not-Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
> ---
> Ahmad and me pair-programmed this on friday. Ahmad, can we have your
> SoB?
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> drivers/nvmem/regmap.c | 29 ++++++++++++++++++++++-------
> 1 file changed, 22 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/nvmem/regmap.c b/drivers/nvmem/regmap.c
> index 98e57909eb..22e667af17 100644
> --- a/drivers/nvmem/regmap.c
> +++ b/drivers/nvmem/regmap.c
> @@ -12,16 +12,31 @@
> static int nvmem_regmap_write(void *ctx, unsigned offset, const void *val, size_t bytes)
> {
> struct regmap *map = ctx;
> + unsigned int tmp;
>
> - /*
> - * eFuse writes going through this function may be irreversible,
> - * so expect users to observe alignment.
> - */
> - if (bytes % regmap_get_val_bytes(map))
> + if (bytes > regmap_get_val_bytes(map)) {
> + if (bytes % regmap_get_val_bytes(map))
> + return -EINVAL;
> +
> + return regmap_bulk_write(map, offset, val,
> + bytes / regmap_get_val_bytes(map));
> + }
> +
> + switch (bytes) {
> + case 1:
> + tmp = *(u8 *)val;
> + break;
> + case 2:
> + tmp = *(u16 *)val;
> + break;
> + case 4:
> + tmp = *(u32 *)val;
> + break;
> + default:
> return -EINVAL;
> + }
>
> - return regmap_bulk_write(map, offset, val,
> - bytes / regmap_get_val_bytes(map));
> + return regmap_write(map, offset, tmp);
> }
>
> static int nvmem_regmap_read(void *ctx, unsigned offset, void *buf, size_t bytes)
>
> ---
> base-commit: f5956c772dc00837bad36fc66df8a53aae86558d
> change-id: 20260525-short_nvmem_write-86a2114f6774
>
> Best regards,
> --
> Jonas Rebmann <jre@pengutronix.de>
>
>
--
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 |
next prev parent reply other threads:[~2026-05-26 5:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-25 11:45 Jonas Rebmann
2026-05-26 5:39 ` Ahmad Fatoum [this message]
2026-05-26 6:26 ` Sascha Hauer
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=c36d3ed4-35b4-49b5-80ca-bfb442f5ee28@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=jre@pengutronix.de \
--cc=s.hauer@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