This is now the third attempt to fetch the MAC addresses from the VPD
for the Kontron sl28 boards. Previous discussions can be found here:
https://lore.kernel.org/lkml/[email protected]/
NVMEM cells are typically added by board code or by the devicetree. But
as the cells get more complex, there is (valid) push back from the
devicetree maintainers to not put that handling in the devicetree.
Therefore, introduce NVMEM layouts. They operate on the NVMEM device and
can add cells during runtime. That way it is possible to add more complex
cells than it is possible right now with the offset/length/bits
description in the device tree. For example, you can have post processing
for individual cells (think of endian swapping, or ethernet offset
handling).
The imx-ocotp driver is the only user of the global post processing hook,
convert it to nvmem layouts and drop the global post pocessing hook.
For now, the layouts are selected by the device tree. But the idea is
that also board files or other drivers could set a layout. Although no
code for that exists yet.
Thanks to Miquel, the device tree bindings are already approved and merged.
NVMEM layouts as modules?
While possible in principle, it doesn't make any sense because the NVMEM
core can't be compiled as a module. The layouts needs to be available at
probe time. (That is also the reason why they get registered with
subsys_initcall().) So if the NVMEM core would be a module, the layouts
could be modules, too.
Michael Walle (18):
net: add helper eth_addr_add()
of: base: add of_parse_phandle_with_optional_args()
of: property: make #.*-cells optional for simple props
of: property: add #nvmem-cell-cells property
nvmem: core: fix device node refcounting
nvmem: core: add an index parameter to the cell
nvmem: core: move struct nvmem_cell_info to nvmem-provider.h
nvmem: core: drop the removal of the cells in nvmem_add_cells()
nvmem: core: add nvmem_add_one_cell()
nvmem: core: use nvmem_add_one_cell() in nvmem_add_cells_from_of()
nvmem: core: introduce NVMEM layouts
nvmem: core: add per-cell post processing
nvmem: core: allow to modify a cell before adding it
nvmem: imx-ocotp: replace global post processing with layouts
nvmem: cell: drop global cell_post_process
nvmem: core: provide own priv pointer in post process callback
nvmem: layouts: add sl28vpd layout
MAINTAINERS: add myself as sl28vpd nvmem layout driver
Miquel Raynal (2):
nvmem: layouts: Add ONIE tlv layout driver
MAINTAINERS: Add myself as ONIE tlv NVMEM layout maintainer
Documentation/driver-api/nvmem.rst | 15 ++
MAINTAINERS | 12 ++
drivers/nvmem/Kconfig | 4 +
drivers/nvmem/Makefile | 1 +
drivers/nvmem/core.c | 285 ++++++++++++++++++++++-------
drivers/nvmem/imx-ocotp.c | 34 ++--
drivers/nvmem/layouts/Kconfig | 23 +++
drivers/nvmem/layouts/Makefile | 7 +
drivers/nvmem/layouts/onie-tlv.c | 244 ++++++++++++++++++++++++
drivers/nvmem/layouts/sl28vpd.c | 153 ++++++++++++++++
drivers/of/property.c | 6 +-
include/linux/etherdevice.h | 14 ++
include/linux/nvmem-consumer.h | 17 +-
include/linux/nvmem-provider.h | 95 +++++++++-
include/linux/of.h | 25 +++
15 files changed, 836 insertions(+), 99 deletions(-)
create mode 100644 drivers/nvmem/layouts/Kconfig
create mode 100644 drivers/nvmem/layouts/Makefile
create mode 100644 drivers/nvmem/layouts/onie-tlv.c
create mode 100644 drivers/nvmem/layouts/sl28vpd.c
--
2.30.2
Add myself as a maintainer for the new sl28vpd nvmem layout driver.
Signed-off-by: Michael Walle <[email protected]>
---
changes since v3:
- none
changes since v2:
- new patch
MAINTAINERS | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 36ff8badc6bb..0e0cc35d90b7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -19103,6 +19103,12 @@ F: drivers/irqchip/irq-sl28cpld.c
F: drivers/pwm/pwm-sl28cpld.c
F: drivers/watchdog/sl28cpld_wdt.c
+SL28 VPD NVMEM LAYOUT DRIVER
+M: Michael Walle <[email protected]>
+S: Maintained
+F: Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml
+F: drivers/nvmem/layouts/sl28vpd.c
+
SLAB ALLOCATOR
M: Christoph Lameter <[email protected]>
M: Pekka Enberg <[email protected]>
--
2.30.2
There are no users anymore for the global cell_post_process callback
anymore. New users should use proper nvmem layouts.
Signed-off-by: Michael Walle <[email protected]>
---
changes since v3:
- none
changes since v2:
- none
changes since v1:
- new patch
drivers/nvmem/core.c | 9 ---------
include/linux/nvmem-provider.h | 2 --
2 files changed, 11 deletions(-)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index ccbde9629f7f..5733bf79dda1 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -38,7 +38,6 @@ struct nvmem_device {
unsigned int nkeepout;
nvmem_reg_read_t reg_read;
nvmem_reg_write_t reg_write;
- nvmem_cell_post_process_t cell_post_process;
struct gpio_desc *wp_gpio;
struct nvmem_layout *layout;
void *priv;
@@ -899,7 +898,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
nvmem->type = config->type;
nvmem->reg_read = config->reg_read;
nvmem->reg_write = config->reg_write;
- nvmem->cell_post_process = config->cell_post_process;
nvmem->keepout = config->keepout;
nvmem->nkeepout = config->nkeepout;
if (config->of_node)
@@ -1570,13 +1568,6 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem,
return rc;
}
- if (nvmem->cell_post_process) {
- rc = nvmem->cell_post_process(nvmem->priv, id, index,
- cell->offset, buf, cell->bytes);
- if (rc)
- return rc;
- }
-
if (len)
*len = cell->bytes;
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index bfaba5227ac9..12833fe4eb4d 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -85,7 +85,6 @@ struct nvmem_cell_info {
* @no_of_node: Device should not use the parent's of_node even if it's !NULL.
* @reg_read: Callback to read data.
* @reg_write: Callback to write data.
- * @cell_post_process: Callback for vendor specific post processing of cell data
* @size: Device size.
* @word_size: Minimum read/write access granularity.
* @stride: Minimum read/write access stride.
@@ -120,7 +119,6 @@ struct nvmem_config {
bool no_of_node;
nvmem_reg_read_t reg_read;
nvmem_reg_write_t reg_write;
- nvmem_cell_post_process_t cell_post_process;
int size;
int word_size;
int stride;
--
2.30.2
Provide a way to modify a cell before it will get added. This is useful
to attach a custom post processing hook via a layout.
Signed-off-by: Michael Walle <[email protected]>
---
changes since v3:
- none
changes since v2:
- none
changes since v1:
- new patch
drivers/nvmem/core.c | 4 ++++
include/linux/nvmem-provider.h | 5 +++++
2 files changed, 9 insertions(+)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index e75642a675ae..ccbde9629f7f 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -694,6 +694,7 @@ static int nvmem_validate_keepouts(struct nvmem_device *nvmem)
static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
{
+ struct nvmem_layout *layout = nvmem->layout;
struct device *dev = &nvmem->dev;
struct nvmem_cell_entry *cell;
struct device_node *child;
@@ -730,6 +731,9 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
info.np = of_node_get(child);
+ if (layout && layout->fixup_cell_info)
+ layout->fixup_cell_info(nvmem, layout, &info);
+
ret = nvmem_add_one_cell(nvmem, &info);
kfree(info.name);
if (ret) {
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index 1930496d8854..bfaba5227ac9 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -157,6 +157,8 @@ struct nvmem_cell_table {
* @add_cells: Will be called if a nvmem device is found which
* has this layout. The function will add layout
* specific cells with nvmem_add_one_cell().
+ * @fixup_cell_info: Will be called before a cell is added. Can be
+ * used to modify the nvmem_cell_info.
* @owner: Pointer to struct module.
* @node: List node.
*
@@ -170,6 +172,9 @@ struct nvmem_layout {
const struct of_device_id *of_match_table;
int (*add_cells)(struct device *dev, struct nvmem_device *nvmem,
struct nvmem_layout *layout);
+ void (*fixup_cell_info)(struct nvmem_device *nvmem,
+ struct nvmem_layout *layout,
+ struct nvmem_cell_info *cell);
/* private */
struct module *owner;
--
2.30.2