Skip to contentSkip to conversation

nvmem: core: support passing DT node in cell info

PATCH Applied Rafał Miłecki 2 participants 3 messages Feb 28, 2022 – Apr 8, 2022 NVMEM framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 nvmem: core: support passing DT node in cell info

From: Rafał Miłecki <[email protected]>

Some hardware may have NVMEM cells described in Device Tree using individual nodes. Let drivers pass such nodes to the NVMEM subsystem so they can be later used by NVMEM consumers.

---
 drivers/nvmem/core.c           | 1 +
 include/linux/nvmem-consumer.h | 1 +
 2 files changed, 2 insertions(+)
drivers/nvmem/core.c +1 -0
index 6d5702e715d6..5fcf2793b599 100644
@@ -467,6 +467,7 @@ 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->np = info->np;
 
 	if (cell->nbits)
 		cell->bytes = DIV_ROUND_UP(cell->nbits + cell->bit_offset,
include/linux/nvmem-consumer.h +1 -0
index c0c0cefc3b92..980f9c9ac0bc 100644
@@ -25,6 +25,7 @@ struct nvmem_cell_info {
 	unsigned int		bytes;
 	unsigned int		bit_offset;
 	unsigned int		nbits;
+	struct device_node	*np;
 };
 
 /**
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 nvmem: brcm_nvram: find Device Tree nodes for NVMEM cells

From: Rafał Miłecki <[email protected]>

DT binding for Broadcom's NVRAM supports specifying NVMEM cells as NVMEM device (provider) subnodes. Look for such subnodes when collecing NVMEM cells. This allows NVMEM consumers to use NVRAM variables.

---
 drivers/nvmem/brcm_nvram.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/nvmem/brcm_nvram.c +2 -0
index 439f00b9eef6..450b927691c3 100644
@@ -8,6 +8,7 @@
 #include <linux/module.h>
 #include <linux/nvmem-consumer.h>
 #include <linux/nvmem-provider.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 
@@ -72,6 +73,7 @@ static int brcm_nvram_add_cells(struct brcm_nvram *priv, uint8_t *data,
 			return -ENOMEM;
 		priv->cells[idx].offset = value - (char *)data;
 		priv->cells[idx].bytes = strlen(value);
+		priv->cells[idx].np = of_get_child_by_name(dev->of_node, priv->cells[idx].name);
 	}
 
 	return 0;
Signature · 1 line
2.34.1
#2 lore raw
In reply to Rafał Miłecki
Quoted 8 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

Some hardware may have NVMEM cells described in Device Tree using individual nodes. Let drivers pass such nodes to the NVMEM subsystem so they can be later used by NVMEM consumers.

---

Applied both, thanks,

--srini

Quoted 28 lines
  drivers/nvmem/core.c           | 1 +
  include/linux/nvmem-consumer.h | 1 +
  2 files changed, 2 insertions(+)
drivers/nvmem/core.c +1 -0
index 6d5702e715d6..5fcf2793b599 100644
@@ -467,6 +467,7 @@ 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->np = info->np;
 
  	if (cell->nbits)
  		cell->bytes = DIV_ROUND_UP(cell->nbits + cell->bit_offset,
include/linux/nvmem-consumer.h +1 -0
index c0c0cefc3b92..980f9c9ac0bc 100644
@@ -25,6 +25,7 @@ struct nvmem_cell_info {
  	unsigned int		bytes;
  	unsigned int		bit_offset;
  	unsigned int		nbits;
+	struct device_node	*np;
  };
 
  /**