From: Sven Peter via B4 Relay <devnull+sven.svenpeter.dev@kernel.org>
To: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
Janne Grunau <j@jannau.net>,
Alyssa Rosenzweig <alyssa@rosenzweig.io>,
Neal Gompa <neal@gompa.dev>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>
Cc: linux-kernel@vger.kernel.org, asahi@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
devicetree@vger.kernel.org, Sven Peter <sven@svenpeter.dev>
Subject: [PATCH 1/7] nvmem: core: allow bit offset > 8
Date: Sat, 10 May 2025 07:44:41 +0000 [thread overview]
Message-ID: <20250510-nvmem-dt-v1-1-eccfa6e33f6a@svenpeter.dev> (raw)
In-Reply-To: <20250510-nvmem-dt-v1-0-eccfa6e33f6a@svenpeter.dev>
From: Sven Peter <sven@svenpeter.dev>
Some nvmem controllers like Apple's eFuses or Nintendo's OTP have a cell
size that's larger than one byte. Consumers may however still need
access to a subset of bits that start after the first byte.
Signed-off-by: Sven Peter <sven@svenpeter.dev>
---
drivers/nvmem/core.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index fff85bbf0ecd0f638e21f127370105d9f79c00d2..1bd39b12c21a86b9b135be95251a52a10543c2ea 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -1630,15 +1630,24 @@ EXPORT_SYMBOL_GPL(nvmem_cell_put);
static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void *buf)
{
u8 *p, *b;
- int i, extra, bit_offset = cell->bit_offset;
+ int i, padding, extra, bit_offset = cell->bit_offset;
+ int bytes = cell->bytes;
p = b = buf;
if (bit_offset) {
+ /* Remove any full bytes at the beginning that contain no bits of interest */
+ padding = bit_offset / BITS_PER_BYTE;
+ if (padding) {
+ memmove(buf, buf + padding, bytes - padding);
+ bit_offset -= BITS_PER_BYTE * padding;
+ bytes -= padding;
+ }
+
/* First shift */
*b++ >>= bit_offset;
/* setup rest of the bytes if any */
- for (i = 1; i < cell->bytes; i++) {
+ for (i = 1; i < bytes; i++) {
/* Get bits from next byte and shift them towards msb */
*p |= *b << (BITS_PER_BYTE - bit_offset);
@@ -1651,7 +1660,7 @@ static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void
}
/* result fits in less bytes */
- extra = cell->bytes - DIV_ROUND_UP(cell->nbits, BITS_PER_BYTE);
+ extra = bytes - DIV_ROUND_UP(cell->nbits, BITS_PER_BYTE);
while (--extra >= 0)
*p-- = 0;
--
2.34.1
next prev parent reply other threads:[~2025-05-10 7:45 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-10 7:44 [PATCH 0/7] Support exposing bits of any byte as NVMEM cells Sven Peter via B4 Relay
2025-05-10 7:44 ` Sven Peter via B4 Relay [this message]
2025-05-10 7:44 ` [PATCH 2/7] nvmem: core: round up to word_size Sven Peter via B4 Relay
2025-05-10 7:44 ` [PATCH 3/7] Revert "nvmem: core: Print error on wrong bits DT property" Sven Peter via B4 Relay
2025-05-10 7:44 ` [PATCH 4/7] dt-bindings: nvmem: apple: Add T8112 compatible Sven Peter via B4 Relay
2025-05-14 20:34 ` Rob Herring
2025-05-10 7:44 ` [PATCH 5/7] arm64: dts: apple: t8103: Add eFuses node Sven Peter via B4 Relay
2025-05-10 7:44 ` [PATCH 6/7] arm64: dts: apple: t600x: " Sven Peter via B4 Relay
2025-05-10 7:44 ` [PATCH 7/7] arm64: dts: apple: t8112: " Sven Peter via B4 Relay
2025-05-12 12:49 ` [PATCH 0/7] Support exposing bits of any byte as NVMEM cells Rob Herring (Arm)
2025-05-14 20:32 ` Rob Herring
2025-05-14 20:38 ` Sven Peter
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=20250510-nvmem-dt-v1-1-eccfa6e33f6a@svenpeter.dev \
--to=devnull+sven.svenpeter.dev@kernel.org \
--cc=alyssa@rosenzweig.io \
--cc=asahi@lists.linux.dev \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=j@jannau.net \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=neal@gompa.dev \
--cc=robh@kernel.org \
--cc=srinivas.kandagatla@linaro.org \
--cc=sven@svenpeter.dev \
/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