* [PATCH v4 1/3] dt-bindings: nvmem: add byte-mask property for non-contiguous byte selection
2026-12-02 11:36 [PATCH v4 0/3] nvmem: Add byte-mask support for non-contiguous byte selection Hongmei Xu
@ 2026-12-02 11:36 ` Hongmei Xu
2026-12-02 11:36 ` [PATCH v4 2/3] nvmem: core: add byte-mask support for non-contiguous cell bytes Hongmei Xu
2026-12-02 11:36 ` [PATCH v4 3/3] arm64: dts: qcom: Add eFuse nvmem cells for Ethernet MAC addresses Hongmei Xu
2 siblings, 0 replies; 4+ messages in thread
From: Hongmei Xu @ 2026-12-02 11:36 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Rafał Miłecki
Cc: devicetree, linux-kernel, Hongmei Xu
Add the byte-mask property to the fixed-cell binding. This allows
selecting non-contiguous physical bytes from an NVMEM region to form
a logical cell value.
Some SoCs (e.g. Qualcomm efuse controllers) store a logical value such
as a MAC address across non-contiguous physical bytes, with one or more
bytes in between reserved or unused. byte-mask lets the DT describe this
directly in the fixed-cell binding without requiring a device-specific
provider for a common pattern.
Bit N set in byte-mask means physical byte N relative to the cell's
base offset is included in the output; selected bytes are packed into
the output buffer in ascending byte order. The number of set bits must
not exceed the cell's logical size given by reg. byte-mask and bits are
mutually exclusive. Cells using byte-mask are read-only.
Signed-off-by: Hongmei Xu <hongmei.xu@oss.qualcomm.com>
---
.../bindings/nvmem/layouts/fixed-cell.yaml | 21 +++++++++++++++++++++
.../devicetree/bindings/nvmem/qcom,qfprom.yaml | 1 +
2 files changed, 22 insertions(+)
diff --git a/Documentation/devicetree/bindings/nvmem/layouts/fixed-cell.yaml b/Documentation/devicetree/bindings/nvmem/layouts/fixed-cell.yaml
index 38e3ad50ff4f..46e1101ee98a 100644
--- a/Documentation/devicetree/bindings/nvmem/layouts/fixed-cell.yaml
+++ b/Documentation/devicetree/bindings/nvmem/layouts/fixed-cell.yaml
@@ -34,6 +34,20 @@ properties:
description:
Size in bit within the address range specified by reg.
+ byte-mask:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ minimum: 1
+ description: >
+ Bitmask selecting which physical bytes within the NVMEM device region
+ contribute to this cell's output. Bit N set means physical byte N
+ relative to the cell's base offset is included; selected bytes are
+ packed into the output buffer in ascending byte order. Byte positions
+ are relative to the cell's base offset and limited to a 32-byte window.
+ The highest set bit must not reference a byte beyond the device size.
+ The number of set bits must not exceed the cell's logical size given by
+ reg. Cannot be used together with bits. Cells using byte-mask are
+ read-only; write operations are not supported.
+
allOf:
- if:
properties:
@@ -48,6 +62,13 @@ allOf:
const: 1
required:
- "#nvmem-cell-cells"
+ - if:
+ required: [ byte-mask ]
+ then:
+ properties:
+ bits: false
+ description:
+ byte-mask and bits are mutually exclusive.
required:
- reg
diff --git a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
index 566304ed4c78..d7f48d4ed1ba 100644
--- a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
+++ b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
@@ -42,6 +42,7 @@ properties:
- qcom,msm8976-qfprom
- qcom,msm8996-qfprom
- qcom,msm8998-qfprom
+ - qcom,nord-qfprom
- qcom,qcm2290-qfprom
- qcom,qcs404-qfprom
- qcom,qcs615-qfprom
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v4 2/3] nvmem: core: add byte-mask support for non-contiguous cell bytes
2026-12-02 11:36 [PATCH v4 0/3] nvmem: Add byte-mask support for non-contiguous byte selection Hongmei Xu
2026-12-02 11:36 ` [PATCH v4 1/3] dt-bindings: nvmem: add byte-mask property " Hongmei Xu
@ 2026-12-02 11:36 ` Hongmei Xu
2026-12-02 11:36 ` [PATCH v4 3/3] arm64: dts: qcom: Add eFuse nvmem cells for Ethernet MAC addresses Hongmei Xu
2 siblings, 0 replies; 4+ messages in thread
From: Hongmei Xu @ 2026-12-02 11:36 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Rafał Miłecki
Cc: devicetree, linux-kernel, Hongmei Xu
Add support for a byte-mask cell property that selects non-contiguous
physical bytes from an NVMEM device region to form a logical cell value.
When byte-mask is set, bit N set in the mask means physical byte N is
included; selected bytes are packed into the output buffer in ascending
byte order. If fewer bytes are selected than the cell's logical size
given by reg, the remaining output bytes are zero-filled.
Four checks are performed at cell registration:
- byte-mask and bits/bit-offset are mutually exclusive.
- The cell offset must not exceed the device size.
- The number of set bits must not exceed the cell's logical size (reg),
to prevent output buffer overflow.
- The highest set bit must not reference a byte beyond the NVMEM device
size.
Signed-off-by: Hongmei Xu <hongmei.xu@oss.qualcomm.com>
---
drivers/nvmem/core.c | 95 +++++++++++++++++++++++++++++++++++++++---
include/linux/nvmem-provider.h | 8 ++++
2 files changed, 97 insertions(+), 6 deletions(-)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 7d4cce8e2742..8bc657cd9930 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -33,6 +33,7 @@ struct nvmem_cell_entry {
int bytes;
int bit_offset;
int nbits;
+ u32 byte_mask;
nvmem_cell_post_process_t read_post_process;
void *priv;
struct device_node *np;
@@ -589,6 +590,47 @@ static void nvmem_cell_entry_add(struct nvmem_cell_entry *cell)
blocking_notifier_call_chain(&nvmem_notifier, NVMEM_CELL_ADD, cell);
}
+static int nvmem_validate_byte_mask(struct nvmem_device *nvmem,
+ const struct nvmem_cell_info *info)
+{
+ int out_bytes;
+
+ if (!info->byte_mask)
+ return 0;
+
+ if (info->nbits || info->bit_offset) {
+ dev_err(&nvmem->dev,
+ "cell %s byte-mask and bits are mutually exclusive\n",
+ info->name ?: "<unknown>");
+ return -EINVAL;
+ }
+
+ if (info->offset >= nvmem->size) {
+ dev_err(&nvmem->dev,
+ "cell %s offset %u exceeds device size %zu\n",
+ info->name ?: "<unknown>", info->offset, nvmem->size);
+ return -EINVAL;
+ }
+
+ out_bytes = hweight32(info->byte_mask);
+ if (out_bytes > info->bytes) {
+ dev_err(&nvmem->dev,
+ "cell %s byte-mask set-bit count %d exceeds reg size %d\n",
+ info->name ?: "<unknown>", out_bytes, info->bytes);
+ return -EINVAL;
+ }
+
+ if (ALIGN(fls(info->byte_mask), nvmem->word_size) > nvmem->size - info->offset) {
+ dev_err(&nvmem->dev,
+ "cell %s byte-mask bit %d exceeds device size %zu\n",
+ info->name ?: "<unknown>",
+ fls(info->byte_mask) - 1, nvmem->size);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem,
const struct nvmem_cell_info *info,
struct nvmem_cell_entry *cell)
@@ -603,12 +645,22 @@ static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem,
cell->bit_offset = info->bit_offset;
cell->nbits = info->nbits;
+ cell->byte_mask = info->byte_mask;
cell->np = info->np;
+ if (cell->byte_mask) {
+ int rc = nvmem_validate_byte_mask(nvmem, info);
+
+ if (rc)
+ return rc;
+ }
+
if (cell->nbits) {
cell->bytes = DIV_ROUND_UP(cell->nbits + cell->bit_offset,
BITS_PER_BYTE);
cell->raw_len = ALIGN(cell->bytes, nvmem->word_size);
+ } else if (cell->byte_mask) {
+ cell->raw_len = ALIGN(fls(info->byte_mask), nvmem->word_size);
}
if (!IS_ALIGNED(cell->offset, nvmem->stride)) {
@@ -804,7 +856,7 @@ int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np)
{
struct device *dev = &nvmem->dev;
const __be32 *addr;
- int len, ret;
+ int len, ret = 0;
for_each_child_of_node_scoped(np, child) {
struct nvmem_cell_info info = {0};
@@ -829,10 +881,13 @@ int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np)
info.nbits < 1 ||
info.bit_offset + info.nbits > BITS_PER_BYTE * info.bytes) {
dev_err(dev, "nvmem: invalid bits on %pOF\n", child);
+ kfree(info.name);
return -EINVAL;
}
}
+ of_property_read_u32(child, "byte-mask", &info.byte_mask);
+
info.np = of_node_get(child);
if (nvmem->fixup_dt_cell_info)
@@ -1648,28 +1703,52 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem,
struct nvmem_cell_entry *cell,
void *buf, size_t *len, const char *id, int index)
{
+ u8 *rawbuf = NULL;
+ void *readbuf = buf;
int rc;
- rc = nvmem_reg_read(nvmem, cell->offset, buf, cell->raw_len);
+ if (cell->byte_mask) {
+ rawbuf = kzalloc(cell->raw_len, GFP_KERNEL);
+ if (!rawbuf)
+ return -ENOMEM;
+ readbuf = rawbuf;
+ }
+
+ rc = nvmem_reg_read(nvmem, cell->offset, readbuf, cell->raw_len);
if (rc)
- return rc;
+ goto err_exit;
/* shift bits in-place */
if (cell->bit_offset || cell->nbits)
nvmem_shift_read_buffer_in_place(cell, buf);
+ /* compact non-contiguous bytes selected by byte_mask */
+ if (cell->byte_mask) {
+ int out_idx = 0;
+ int i;
+
+ for (i = 0; i < cell->raw_len; i++) {
+ if (cell->byte_mask & BIT(i))
+ ((u8 *)buf)[out_idx++] = rawbuf[i];
+ }
+ memset((u8 *)buf + out_idx, 0, cell->bytes - out_idx);
+ }
+
if (cell->read_post_process) {
rc = cell->read_post_process(cell->priv, id, index,
- cell->offset, buf, cell->raw_len);
+ cell->offset, buf,
+ cell->byte_mask ? cell->bytes : cell->raw_len);
if (rc)
- return rc;
+ goto err_exit;
}
if (len)
*len = cell->bytes;
- return 0;
+err_exit:
+ kfree(rawbuf);
+ return rc;
}
/**
@@ -1776,6 +1855,10 @@ static int __nvmem_cell_entry_write(struct nvmem_cell_entry *cell, void *buf, si
if (cell->read_post_process)
return -EINVAL;
+ /* byte-mask cells have no scatter-write implementation yet */
+ if (cell->byte_mask)
+ return -EINVAL;
+
if (cell->bit_offset || cell->nbits) {
if (len != BITS_TO_BYTES(cell->nbits) && len != cell->bytes)
return -EINVAL;
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index 6063fe5b7784..066d27bb4284 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -57,6 +57,13 @@ struct nvmem_keepout {
* @bytes: Length of the cell.
* @bit_offset: Bit offset if cell is smaller than a byte.
* @nbits: Number of bits.
+ * @byte_mask: Bitmask selecting physical bytes to include in the output.
+ * Bit N=1 means physical byte N relative to the cell's base
+ * offset is packed into the output buffer; bit N=0 means skip.
+ * The physical read window extends to the highest set bit,
+ * aligned to the device word size. The number of set bits must
+ * not exceed the cell's logical size (bytes). Unselected output
+ * positions are zero-filled. Zero means no masking.
* @np: Optional device_node pointer.
* @read_post_process: Callback for optional post processing of cell data
* on reads.
@@ -69,6 +76,7 @@ struct nvmem_cell_info {
unsigned int bytes;
unsigned int bit_offset;
unsigned int nbits;
+ u32 byte_mask;
struct device_node *np;
nvmem_cell_post_process_t read_post_process;
void *priv;
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v4 3/3] arm64: dts: qcom: Add eFuse nvmem cells for Ethernet MAC addresses
2026-12-02 11:36 [PATCH v4 0/3] nvmem: Add byte-mask support for non-contiguous byte selection Hongmei Xu
2026-12-02 11:36 ` [PATCH v4 1/3] dt-bindings: nvmem: add byte-mask property " Hongmei Xu
2026-12-02 11:36 ` [PATCH v4 2/3] nvmem: core: add byte-mask support for non-contiguous cell bytes Hongmei Xu
@ 2026-12-02 11:36 ` Hongmei Xu
2 siblings, 0 replies; 4+ messages in thread
From: Hongmei Xu @ 2026-12-02 11:36 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Rafał Miłecki
Cc: devicetree, linux-kernel, Hongmei Xu
Add a QFPROM eFuse node to expose the Ethernet MAC addresses for
EMAC0 and EMAC1 as nvmem cells.
The MAC addresses are stored in OEM_CONFIG8/9 registers starting at
0x360d4320:
bytes 0-4 shared by both EMACs
byte 5 last octet of EMAC0 MAC address
byte 6 last octet of EMAC1 MAC address
EMAC0 reads six consecutive bytes (0-5), requiring no byte selection.
EMAC1 shares bytes 0-4 but takes byte 6 as its last octet, skipping
byte 5. A byte-mask of 0x5F (0b01011111) is used to select bytes
0,1,2,3,4,6 and compact them into the six-byte output buffer.
Only 8 bytes are mapped to avoid overlapping with adjacent QFPROM
devices in the register space.
Signed-off-by: Hongmei Xu <hongmei.xu@oss.qualcomm.com>
---
arch/arm64/boot/dts/qcom/nord.dtsi | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/arch/arm64/boot/dts/qcom/nord.dtsi b/arch/arm64/boot/dts/qcom/nord.dtsi
index fdbe290350dd..cfe1f39648fb 100644
--- a/arch/arm64/boot/dts/qcom/nord.dtsi
+++ b/arch/arm64/boot/dts/qcom/nord.dtsi
@@ -1471,6 +1471,28 @@ rng: rng@10c3000 {
reg = <0x0 0x010c3000 0x0 0x1000>;
};
+ efuse: efuse@360d4320 {
+ compatible = "qcom,nord-qfprom", "qcom,qfprom";
+ reg = <0x0 0x360d4320 0x0 0x8>;
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ nvmem-layout {
+ compatible = "fixed-layout";
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ mac_addr0: mac-addr0@0 {
+ reg = <0x0 0x6>;
+ };
+
+ mac_addr1: mac-addr1@0,1 {
+ reg = <0x0 0x6>;
+ byte-mask = <0x5f>;
+ };
+ };
+ };
+
ufs_mem_hc: ufshc@1d44000 {
compatible = "qcom,nord-ufshc",
"qcom,ufshc",
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread