All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/21] nvmem: Layouts support
@ 2023-03-07 16:53 Miquel Raynal
  2023-03-07 16:53 ` [PATCH v2 01/21] of: Fix modalias string generation Miquel Raynal
                   ` (21 more replies)
  0 siblings, 22 replies; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 16:53 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Miquel Raynal, Stephen Boyd,
	Peter Chen, Rafael J . Wysocki, Len Brown, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, Sebastian Reichel,
	Wolfram Sang, Mark Brown, Heikki Krogerus

Hello,

This is a fully featured series with hopefully all what is needed for
upstream acceptance, ie:
* A bit of OF cleanup
* Full nvmem layout support merging Michael's and my patches
* Only the fixes not applying to this series have been kept "un merged"
* Support for SL28 VPD and ONIE TLV table layouts
* Layouts can be compiled as modules

In order for this series to work out-of-the-box it requires to be
applied on top of Michael Walle's mtd fixes series (robots running on
it, I will provide an immutable tag in the coming days) but for
compile-testing only it is not required.

Link: https://lore.kernel.org/linux-mtd/20230306125805.678668-1-michael@walle.cc/T/#t

So to summarize:
* Rob's feedback is welcome on the OF patches
* Greg's and Srinivas feedback is welcome on the nvmem patches
* If everybody agrees I expect the full series to be applied rather
  early by Srinivas on top of the -rc he wants.
* Once time for the final PR I expect Greg to merge the immutable tag
  I will provide with Michael's patches before taking these patches from
  Srinivas.
* Rob might request an immutable tag from Greg (at least with the OF
  patches) if there are any conflicts with his tree. Otherwise if that's
  foreseen, Rob can also merge the OF patches and produce an immutable
  tag himself if that's preferred. Indeed, no hurry, but there are other
  OF cleanup patches which do not have to be in this series which will
  come later to continue the OF cleanup even further if my understanding
  of Rob's whishes is right :)

Link: https://github.com/miquelraynal/linux-0day/tree/nvmem-layouts-and-of-cleanup

Thanks,
Miquèl

Changes in v2:
* Included all initial core nvmem changes.
* Merged all the relevant fixes.
* Updated the commit logs of the Fixes tag when relevant.
* Followed Rob advises to migrate the module related helpers into
  of/module.c and get the useless helpers out of of_device.c
* Added my Signed-off-by when relevant.
* Collected tags.

Colin Ian King (1):
  dt-bindings: nvmem: Fix spelling mistake "platforn" -> "platform"

Michael Walle (9):
  nvmem: core: return -ENOENT if nvmem cell is not found
  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: sl28vpd: Add new layout driver
  MAINTAINERS: add myself as sl28vpd nvmem layout driver

Miquel Raynal (11):
  of: Fix modalias string generation
  of: Update of_device_get_modalias()
  of: Rename of_modalias_node()
  of: Move of_modalias() to module.c
  of: Move the request module helper logic to module.c
  usb: ulpi: Use of_request_module()
  of: device: Kill of_device_request_module()
  nvmem: core: handle the absence of expected layouts
  nvmem: core: request layout modules loading
  nvmem: layouts: onie-tlv: Add new layout driver
  MAINTAINERS: Add myself as ONIE tlv NVMEM layout maintainer

 .../nvmem/layouts/onie,tlv-layout.yaml        |   2 +-
 Documentation/driver-api/nvmem.rst            |  15 +
 MAINTAINERS                                   |  12 +
 drivers/acpi/bus.c                            |   7 +-
 drivers/gpu/drm/drm_mipi_dsi.c                |   2 +-
 drivers/hsi/hsi_core.c                        |   2 +-
 drivers/i2c/busses/i2c-powermac.c             |   2 +-
 drivers/i2c/i2c-core-of.c                     |   2 +-
 drivers/nvmem/Kconfig                         |   4 +
 drivers/nvmem/Makefile                        |   1 +
 drivers/nvmem/core.c                          | 162 ++++++++++-
 drivers/nvmem/imx-ocotp.c                     |  30 +-
 drivers/nvmem/layouts/Kconfig                 |  23 ++
 drivers/nvmem/layouts/Makefile                |   7 +
 drivers/nvmem/layouts/onie-tlv.c              | 257 ++++++++++++++++++
 drivers/nvmem/layouts/sl28vpd.c               | 165 +++++++++++
 drivers/of/Makefile                           |   2 +-
 drivers/of/base.c                             |  15 +-
 drivers/of/device.c                           |  75 +----
 drivers/of/module.c                           |  73 +++++
 drivers/spi/spi.c                             |   4 +-
 drivers/usb/common/ulpi.c                     |   2 +-
 include/linux/nvmem-consumer.h                |   7 +
 include/linux/nvmem-provider.h                |  66 ++++-
 include/linux/of.h                            |  16 +-
 include/linux/of_device.h                     |   6 -
 26 files changed, 846 insertions(+), 113 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
 create mode 100644 drivers/of/module.c

-- 
2.34.1


^ permalink raw reply	[flat|nested] 42+ messages in thread

* [PATCH v2 01/21] of: Fix modalias string generation
  2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
@ 2023-03-07 16:53 ` Miquel Raynal
  2023-03-07 16:53 ` [PATCH v2 02/21] of: Update of_device_get_modalias() Miquel Raynal
                   ` (20 subsequent siblings)
  21 siblings, 0 replies; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 16:53 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Miquel Raynal, Stephen Boyd,
	Peter Chen, Rob Herring

The helper generating an OF based modalias (of_device_get_modalias())
works fine, but due to the use of snprintf() internally it needs a
buffer one byte longer than what should be needed just for the entire
string (excluding the '\0'). Most users of this helper are sysfs hooks
providing the modalias string to users. They all provide a PAGE_SIZE
buffer which is way above the number of bytes required to fit the
modalias string and hence do not suffer from this issue.

There is another user though, of_device_request_module(), which is only
called by drivers/usb/common/ulpi.c. This request module function is
faulty, but maybe because in most cases there is an alternative, ULPI
driver users have not noticed it.

In this function, of_device_get_modalias() is called twice. The first
time without buffer just to get the number of bytes required by the
modalias string (excluding the null byte), and a second time, after
buffer allocation, to fill the buffer. The allocation asks for an
additional byte, in order to store the trailing '\0'. However, the
buffer *length* provided to of_device_get_modalias() excludes this extra
byte. The internal use of snprintf() with a length that is exactly the
number of bytes to be written has the effect of using the last available
byte to store a '\0', which then smashes the last character of the
modalias string.

Provide the actual size of the buffer to of_device_get_modalias() to fix
this issue.

Note: the "str[size - 1] = '\0';" line is not really needed as snprintf
will anyway end the string with a null byte, but there is a possibility
that this function might be called on a struct device_node without
compatible, in this case snprintf() would not be executed. So we keep it
just to avoid possible unbounded strings.

Cc: Stephen Boyd <sboyd@kernel.org>
Cc: Peter Chen <peter.chen@kernel.org>
Fixes: 9c829c097f2f ("of: device: Support loading a module with OF based modalias")
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Rob Herring <robh@kernel.org>
---
 drivers/of/device.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/of/device.c b/drivers/of/device.c
index c674a13c3055..877f50379fab 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -297,12 +297,15 @@ int of_device_request_module(struct device *dev)
 	if (size < 0)
 		return size;
 
-	str = kmalloc(size + 1, GFP_KERNEL);
+	/* Reserve an additional byte for the trailing '\0' */
+	size++;
+
+	str = kmalloc(size, GFP_KERNEL);
 	if (!str)
 		return -ENOMEM;
 
 	of_device_get_modalias(dev, str, size);
-	str[size] = '\0';
+	str[size - 1] = '\0';
 	ret = request_module(str);
 	kfree(str);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH v2 02/21] of: Update of_device_get_modalias()
  2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
  2023-03-07 16:53 ` [PATCH v2 01/21] of: Fix modalias string generation Miquel Raynal
@ 2023-03-07 16:53 ` Miquel Raynal
  2023-03-08  0:28   ` Rob Herring
  2023-03-07 16:53 ` [PATCH v2 03/21] of: Rename of_modalias_node() Miquel Raynal
                   ` (19 subsequent siblings)
  21 siblings, 1 reply; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 16:53 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Miquel Raynal

This function only needs a "struct device_node" to work, but for
convenience the author (and only user) of this helper did use a "struct
device" and put it in device.c.

Let's convert this helper to take a "struct device node" instead. This
change asks for two additional changes: renaming it "of_modalias()"
to fit the current naming, and moving it outside of device.c which will
be done in a follow-up commit.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/of/device.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/drivers/of/device.c b/drivers/of/device.c
index 877f50379fab..2bbb67798916 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -248,7 +248,7 @@ const void *of_device_get_match_data(const struct device *dev)
 }
 EXPORT_SYMBOL(of_device_get_match_data);
 
-static ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
+static ssize_t of_modalias(struct device_node *np, char *str, ssize_t len)
 {
 	const char *compat;
 	char *c;
@@ -256,19 +256,16 @@ static ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len
 	ssize_t csize;
 	ssize_t tsize;
 
-	if ((!dev) || (!dev->of_node))
-		return -ENODEV;
-
 	/* Name & Type */
 	/* %p eats all alphanum characters, so %c must be used here */
-	csize = snprintf(str, len, "of:N%pOFn%c%s", dev->of_node, 'T',
-			 of_node_get_device_type(dev->of_node));
+	csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T',
+			 of_node_get_device_type(np));
 	tsize = csize;
 	len -= csize;
 	if (str)
 		str += csize;
 
-	of_property_for_each_string(dev->of_node, "compatible", p, compat) {
+	of_property_for_each_string(np, "compatible", p, compat) {
 		csize = strlen(compat) + 1;
 		tsize += csize;
 		if (csize > len)
@@ -293,7 +290,10 @@ int of_device_request_module(struct device *dev)
 	ssize_t size;
 	int ret;
 
-	size = of_device_get_modalias(dev, NULL, 0);
+	if (!dev || !dev->of_node)
+		return -ENODEV;
+
+	size = of_modalias(dev->of_node, NULL, 0);
 	if (size < 0)
 		return size;
 
@@ -304,7 +304,7 @@ int of_device_request_module(struct device *dev)
 	if (!str)
 		return -ENOMEM;
 
-	of_device_get_modalias(dev, str, size);
+	of_modalias(dev->of_node, str, size);
 	str[size - 1] = '\0';
 	ret = request_module(str);
 	kfree(str);
@@ -321,7 +321,12 @@ EXPORT_SYMBOL_GPL(of_device_request_module);
  */
 ssize_t of_device_modalias(struct device *dev, char *str, ssize_t len)
 {
-	ssize_t sl = of_device_get_modalias(dev, str, len - 2);
+	ssize_t sl;
+
+	if (!dev || !dev->of_node)
+		return -ENODEV;
+
+	sl = of_modalias(dev->of_node, str, len - 2);
 	if (sl < 0)
 		return sl;
 	if (sl > len - 2)
@@ -386,8 +391,8 @@ int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env)
 	if (add_uevent_var(env, "MODALIAS="))
 		return -ENOMEM;
 
-	sl = of_device_get_modalias(dev, &env->buf[env->buflen-1],
-				    sizeof(env->buf) - env->buflen);
+	sl = of_modalias(dev->of_node, &env->buf[env->buflen-1],
+			 sizeof(env->buf) - env->buflen);
 	if (sl >= (sizeof(env->buf) - env->buflen))
 		return -ENOMEM;
 	env->buflen += sl;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH v2 03/21] of: Rename of_modalias_node()
  2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
  2023-03-07 16:53 ` [PATCH v2 01/21] of: Fix modalias string generation Miquel Raynal
  2023-03-07 16:53 ` [PATCH v2 02/21] of: Update of_device_get_modalias() Miquel Raynal
@ 2023-03-07 16:53 ` Miquel Raynal
  2023-03-08  0:19   ` Rob Herring
  2023-03-07 16:53 ` [PATCH v2 04/21] of: Move of_modalias() to module.c Miquel Raynal
                   ` (18 subsequent siblings)
  21 siblings, 1 reply; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 16:53 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Miquel Raynal, Rafael J . Wysocki,
	Len Brown, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	Sebastian Reichel, Wolfram Sang, Mark Brown

This helper does not produce a real modalias, but tries to get the
"product" compatible part of the "vendor,product" compatibles only. It
is far from creating a purely useful modalias string and does not seem
to be used like that directly anyway, so let's try to give this helper a
more meaningful name before moving there a real modalias helper (already
existing under of/device.c).

Also update the various documentations to refer to the strings as
"aliases" rather than "modaliases" which has a real meaning in the Linux
kernel.

There is no functional change.

Cc: Rafael J. Wysocki <rafael@kernel.org>
Cc: Len Brown <lenb@kernel.org>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Sebastian Reichel <sre@kernel.org>
Cc: Wolfram Sang <wsa@kernel.org>
Cc: Mark Brown <broonie@kernel.org>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/acpi/bus.c                |  7 ++++---
 drivers/gpu/drm/drm_mipi_dsi.c    |  2 +-
 drivers/hsi/hsi_core.c            |  2 +-
 drivers/i2c/busses/i2c-powermac.c |  2 +-
 drivers/i2c/i2c-core-of.c         |  2 +-
 drivers/of/base.c                 | 15 ++++++++-------
 drivers/spi/spi.c                 |  4 ++--
 include/linux/of.h                |  2 +-
 8 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 0c05ccde1f7a..6eea487a1de6 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -817,9 +817,10 @@ static bool acpi_of_modalias(struct acpi_device *adev,
  * @modalias:   Pointer to buffer that modalias value will be copied into
  * @len:	Length of modalias buffer
  *
- * This is a counterpart of of_modalias_node() for struct acpi_device objects.
- * If there is a compatible string for @adev, it will be copied to @modalias
- * with the vendor prefix stripped; otherwise, @default_id will be used.
+ * This is a counterpart of of_alias_from_compatible() for struct acpi_device
+ * objects. If there is a compatible string for @adev, it will be copied to
+ * @modalias with the vendor prefix stripped; otherwise, @default_id will be
+ * used.
  */
 void acpi_set_modalias(struct acpi_device *adev, const char *default_id,
 		       char *modalias, size_t len)
diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
index 497ef4b6a90a..0f0a715704ba 100644
--- a/drivers/gpu/drm/drm_mipi_dsi.c
+++ b/drivers/gpu/drm/drm_mipi_dsi.c
@@ -160,7 +160,7 @@ of_mipi_dsi_device_add(struct mipi_dsi_host *host, struct device_node *node)
 	int ret;
 	u32 reg;
 
-	if (of_modalias_node(node, info.type, sizeof(info.type)) < 0) {
+	if (of_alias_from_compatible(node, info.type, sizeof(info.type)) < 0) {
 		drm_err(host, "modalias failure on %pOF\n", node);
 		return ERR_PTR(-EINVAL);
 	}
diff --git a/drivers/hsi/hsi_core.c b/drivers/hsi/hsi_core.c
index 884066109699..8066e31bbece 100644
--- a/drivers/hsi/hsi_core.c
+++ b/drivers/hsi/hsi_core.c
@@ -207,7 +207,7 @@ static void hsi_add_client_from_dt(struct hsi_port *port,
 	if (!cl)
 		return;
 
-	err = of_modalias_node(client, name, sizeof(name));
+	err = of_alias_from_compatible(client, name, sizeof(name));
 	if (err)
 		goto err;
 
diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c
index 2e74747eec9c..ec706a3aba26 100644
--- a/drivers/i2c/busses/i2c-powermac.c
+++ b/drivers/i2c/busses/i2c-powermac.c
@@ -284,7 +284,7 @@ static bool i2c_powermac_get_type(struct i2c_adapter *adap,
 	 */
 
 	/* First try proper modalias */
-	if (of_modalias_node(node, tmp, sizeof(tmp)) >= 0) {
+	if (of_alias_from_compatible(node, tmp, sizeof(tmp)) >= 0) {
 		snprintf(type, type_size, "MAC,%s", tmp);
 		return true;
 	}
diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
index 3ed74aa4b44b..df21c2b69bed 100644
--- a/drivers/i2c/i2c-core-of.c
+++ b/drivers/i2c/i2c-core-of.c
@@ -27,7 +27,7 @@ int of_i2c_get_board_info(struct device *dev, struct device_node *node,
 
 	memset(info, 0, sizeof(*info));
 
-	if (of_modalias_node(node, info->type, sizeof(info->type)) < 0) {
+	if (of_alias_from_compatible(node, info->type, sizeof(info->type)) < 0) {
 		dev_err(dev, "of_i2c: modalias failure on %pOF\n", node);
 		return -EINVAL;
 	}
diff --git a/drivers/of/base.c b/drivers/of/base.c
index d5a5c35eba72..fd98a302a07f 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1208,19 +1208,20 @@ struct device_node *of_find_matching_node_and_match(struct device_node *from,
 EXPORT_SYMBOL(of_find_matching_node_and_match);
 
 /**
- * of_modalias_node - Lookup appropriate modalias for a device node
+ * of_alias_from_compatible - Lookup appropriate alias for a device node
+ *			      depending on compatible
  * @node:	pointer to a device tree node
- * @modalias:	Pointer to buffer that modalias value will be copied into
- * @len:	Length of modalias value
+ * @modalias:	Pointer to buffer that alias value will be copied into
+ * @len:	Length of alias value
  *
  * Based on the value of the compatible property, this routine will attempt
- * to choose an appropriate modalias value for a particular device tree node.
+ * to choose an appropriate alias value for a particular device tree node.
  * It does this by stripping the manufacturer prefix (as delimited by a ',')
  * from the first entry in the compatible list property.
  *
  * Return: This routine returns 0 on success, <0 on failure.
  */
-int of_modalias_node(struct device_node *node, char *modalias, int len)
+int of_alias_from_compatible(struct device_node *node, char *alias, int len)
 {
 	const char *compatible, *p;
 	int cplen;
@@ -1229,10 +1230,10 @@ int of_modalias_node(struct device_node *node, char *modalias, int len)
 	if (!compatible || strlen(compatible) > cplen)
 		return -ENODEV;
 	p = strchr(compatible, ',');
-	strscpy(modalias, p ? p + 1 : compatible, len);
+	strscpy(alias, p ? p + 1 : compatible, len);
 	return 0;
 }
-EXPORT_SYMBOL_GPL(of_modalias_node);
+EXPORT_SYMBOL_GPL(of_alias_from_compatible);
 
 /**
  * of_find_node_by_phandle - Find a node given a phandle
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 3cc7bb4d03de..e4447ae59892 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -2333,8 +2333,8 @@ of_register_spi_device(struct spi_controller *ctlr, struct device_node *nc)
 	}
 
 	/* Select device driver */
-	rc = of_modalias_node(nc, spi->modalias,
-				sizeof(spi->modalias));
+	rc = of_alias_from_compatible(nc, spi->modalias,
+				      sizeof(spi->modalias));
 	if (rc < 0) {
 		dev_err(&ctlr->dev, "cannot find modalias for %pOF\n", nc);
 		goto err_out;
diff --git a/include/linux/of.h b/include/linux/of.h
index 98c252d2d851..fc7ada57df33 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -362,7 +362,7 @@ extern int of_n_addr_cells(struct device_node *np);
 extern int of_n_size_cells(struct device_node *np);
 extern const struct of_device_id *of_match_node(
 	const struct of_device_id *matches, const struct device_node *node);
-extern int of_modalias_node(struct device_node *node, char *modalias, int len);
+extern int of_alias_from_compatible(struct device_node *node, char *alias, int len);
 extern void of_print_phandle_args(const char *msg, const struct of_phandle_args *args);
 extern int __of_parse_phandle_with_args(const struct device_node *np,
 	const char *list_name, const char *cells_name, int cell_count,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH v2 04/21] of: Move of_modalias() to module.c
  2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
                   ` (2 preceding siblings ...)
  2023-03-07 16:53 ` [PATCH v2 03/21] of: Rename of_modalias_node() Miquel Raynal
@ 2023-03-07 16:53 ` Miquel Raynal
  2023-03-08  0:23   ` Rob Herring
  2023-03-07 16:53 ` [PATCH v2 05/21] of: Move the request module helper logic " Miquel Raynal
                   ` (17 subsequent siblings)
  21 siblings, 1 reply; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 16:53 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Miquel Raynal

Create a specific .c file for of related module handling.
Move of_modalias() inside as a first step.

Suggested-by: Rob Herring <robh+dt@kernel.org>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/of/Makefile |  2 +-
 drivers/of/device.c | 37 -------------------------------------
 drivers/of/module.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/of.h  |  8 ++++++++
 4 files changed, 52 insertions(+), 38 deletions(-)
 create mode 100644 drivers/of/module.c

diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index e0360a44306e..ae9923fd2940 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -1,5 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
-obj-y = base.o device.o platform.o property.o
+obj-y = base.o device.o module.o platform.o property.o
 obj-$(CONFIG_OF_KOBJ) += kobj.o
 obj-$(CONFIG_OF_DYNAMIC) += dynamic.o
 obj-$(CONFIG_OF_FLATTREE) += fdt.o
diff --git a/drivers/of/device.c b/drivers/of/device.c
index 2bbb67798916..44f1f2ef12b7 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -1,5 +1,4 @@
 // SPDX-License-Identifier: GPL-2.0
-#include <linux/string.h>
 #include <linux/kernel.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
@@ -248,42 +247,6 @@ const void *of_device_get_match_data(const struct device *dev)
 }
 EXPORT_SYMBOL(of_device_get_match_data);
 
-static ssize_t of_modalias(struct device_node *np, char *str, ssize_t len)
-{
-	const char *compat;
-	char *c;
-	struct property *p;
-	ssize_t csize;
-	ssize_t tsize;
-
-	/* Name & Type */
-	/* %p eats all alphanum characters, so %c must be used here */
-	csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T',
-			 of_node_get_device_type(np));
-	tsize = csize;
-	len -= csize;
-	if (str)
-		str += csize;
-
-	of_property_for_each_string(np, "compatible", p, compat) {
-		csize = strlen(compat) + 1;
-		tsize += csize;
-		if (csize > len)
-			continue;
-
-		csize = snprintf(str, len, "C%s", compat);
-		for (c = str; c; ) {
-			c = strchr(c, ' ');
-			if (c)
-				*c++ = '_';
-		}
-		len -= csize;
-		str += csize;
-	}
-
-	return tsize;
-}
-
 int of_device_request_module(struct device *dev)
 {
 	char *str;
diff --git a/drivers/of/module.c b/drivers/of/module.c
new file mode 100644
index 000000000000..9c6a53f32c0f
--- /dev/null
+++ b/drivers/of/module.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Linux kernel module helpers.
+ */
+
+#include <linux/of.h>
+#include <linux/string.h>
+
+ssize_t of_modalias(struct device_node *np, char *str, ssize_t len)
+{
+	const char *compat;
+	char *c;
+	struct property *p;
+	ssize_t csize;
+	ssize_t tsize;
+
+	/* Name & Type */
+	/* %p eats all alphanum characters, so %c must be used here */
+	csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T',
+			 of_node_get_device_type(np));
+	tsize = csize;
+	len -= csize;
+	if (str)
+		str += csize;
+
+	of_property_for_each_string(np, "compatible", p, compat) {
+		csize = strlen(compat) + 1;
+		tsize += csize;
+		if (csize > len)
+			continue;
+
+		csize = snprintf(str, len, "C%s", compat);
+		for (c = str; c; ) {
+			c = strchr(c, ' ');
+			if (c)
+				*c++ = '_';
+		}
+		len -= csize;
+		str += csize;
+	}
+
+	return tsize;
+}
diff --git a/include/linux/of.h b/include/linux/of.h
index fc7ada57df33..1372f8647272 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -373,6 +373,9 @@ extern int of_parse_phandle_with_args_map(const struct device_node *np,
 extern int of_count_phandle_with_args(const struct device_node *np,
 	const char *list_name, const char *cells_name);
 
+/* module functions */
+extern ssize_t of_modalias(struct device_node *np, char *str, ssize_t len);
+
 /* phandle iterator functions */
 extern int of_phandle_iterator_init(struct of_phandle_iterator *it,
 				    const struct device_node *np,
@@ -730,6 +733,11 @@ static inline int of_count_phandle_with_args(const struct device_node *np,
 	return -ENOSYS;
 }
 
+static inline ssize_t of_modalias(struct device_node *np, char *str, ssize_t len)
+{
+	return -ENODEV;
+}
+
 static inline int of_phandle_iterator_init(struct of_phandle_iterator *it,
 					   const struct device_node *np,
 					   const char *list_name,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH v2 05/21] of: Move the request module helper logic to module.c
  2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
                   ` (3 preceding siblings ...)
  2023-03-07 16:53 ` [PATCH v2 04/21] of: Move of_modalias() to module.c Miquel Raynal
@ 2023-03-07 16:53 ` Miquel Raynal
  2023-03-08  0:25   ` Rob Herring
  2023-03-07 16:53 ` [PATCH v2 06/21] usb: ulpi: Use of_request_module() Miquel Raynal
                   ` (16 subsequent siblings)
  21 siblings, 1 reply; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 16:53 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Miquel Raynal

Depending on device.c for pure OF handling is considered
backwards. Let's extract the content of of_device_request_module() to
have the real logic under module.c.

The next step will be to convert users of of_device_request_module() to
use the new helper.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/of/device.c | 25 ++-----------------------
 drivers/of/module.c | 30 ++++++++++++++++++++++++++++++
 include/linux/of.h  |  6 ++++++
 3 files changed, 38 insertions(+), 23 deletions(-)

diff --git a/drivers/of/device.c b/drivers/of/device.c
index 44f1f2ef12b7..4bbb6e6388a9 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -8,7 +8,6 @@
 #include <linux/dma-direct.h> /* for bus_dma_region */
 #include <linux/dma-map-ops.h>
 #include <linux/init.h>
-#include <linux/module.h>
 #include <linux/mod_devicetable.h>
 #include <linux/slab.h>
 #include <linux/platform_device.h>
@@ -249,30 +248,10 @@ EXPORT_SYMBOL(of_device_get_match_data);
 
 int of_device_request_module(struct device *dev)
 {
-	char *str;
-	ssize_t size;
-	int ret;
-
-	if (!dev || !dev->of_node)
+	if (!dev)
 		return -ENODEV;
 
-	size = of_modalias(dev->of_node, NULL, 0);
-	if (size < 0)
-		return size;
-
-	/* Reserve an additional byte for the trailing '\0' */
-	size++;
-
-	str = kmalloc(size, GFP_KERNEL);
-	if (!str)
-		return -ENOMEM;
-
-	of_modalias(dev->of_node, str, size);
-	str[size - 1] = '\0';
-	ret = request_module(str);
-	kfree(str);
-
-	return ret;
+	return of_request_module(dev->of_node);
 }
 EXPORT_SYMBOL_GPL(of_device_request_module);
 
diff --git a/drivers/of/module.c b/drivers/of/module.c
index 9c6a53f32c0f..0cb3bb83b700 100644
--- a/drivers/of/module.c
+++ b/drivers/of/module.c
@@ -4,6 +4,7 @@
  */
 
 #include <linux/of.h>
+#include <linux/module.h>
 #include <linux/string.h>
 
 ssize_t of_modalias(struct device_node *np, char *str, ssize_t len)
@@ -41,3 +42,32 @@ ssize_t of_modalias(struct device_node *np, char *str, ssize_t len)
 
 	return tsize;
 }
+
+int of_request_module(struct device_node *np)
+{
+	char *str;
+	ssize_t size;
+	int ret;
+
+	if (!np)
+		return -ENODEV;
+
+	size = of_modalias(np, NULL, 0);
+	if (size < 0)
+		return size;
+
+	/* Reserve an additional byte for the trailing '\0' */
+	size++;
+
+	str = kmalloc(size, GFP_KERNEL);
+	if (!str)
+		return -ENOMEM;
+
+	of_modalias(np, str, size);
+	str[size - 1] = '\0';
+	ret = request_module(str);
+	kfree(str);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(of_request_module);
diff --git a/include/linux/of.h b/include/linux/of.h
index 1372f8647272..692581486403 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -375,6 +375,7 @@ extern int of_count_phandle_with_args(const struct device_node *np,
 
 /* module functions */
 extern ssize_t of_modalias(struct device_node *np, char *str, ssize_t len);
+extern int of_request_module(struct device_node *np);
 
 /* phandle iterator functions */
 extern int of_phandle_iterator_init(struct of_phandle_iterator *it,
@@ -738,6 +739,11 @@ static inline ssize_t of_modalias(struct device_node *np, char *str, ssize_t len
 	return -ENODEV;
 }
 
+static inline int of_request_module(struct device_node *np)
+{
+	return -ENODEV;
+}
+
 static inline int of_phandle_iterator_init(struct of_phandle_iterator *it,
 					   const struct device_node *np,
 					   const char *list_name,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH v2 06/21] usb: ulpi: Use of_request_module()
  2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
                   ` (4 preceding siblings ...)
  2023-03-07 16:53 ` [PATCH v2 05/21] of: Move the request module helper logic " Miquel Raynal
@ 2023-03-07 16:53 ` Miquel Raynal
  2023-03-08  0:25   ` Rob Herring
  2023-03-07 16:53 ` [PATCH v2 07/21] of: device: Kill of_device_request_module() Miquel Raynal
                   ` (15 subsequent siblings)
  21 siblings, 1 reply; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 16:53 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Miquel Raynal, Heikki Krogerus

There is a new helper supposed to replace of_device_request_module(),
called of_request_module(). They are both strictly equivalent, besides
the fact the latter receives a "struct device_node" directly. Use it.

Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/usb/common/ulpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
index 60e8174686a1..6a2b69642e83 100644
--- a/drivers/usb/common/ulpi.c
+++ b/drivers/usb/common/ulpi.c
@@ -229,7 +229,7 @@ static int ulpi_read_id(struct ulpi *ulpi)
 	request_module("ulpi:v%04xp%04x", ulpi->id.vendor, ulpi->id.product);
 	return 0;
 err:
-	of_device_request_module(&ulpi->dev);
+	of_request_module(ulpi->dev.of_node);
 	return 0;
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH v2 07/21] of: device: Kill of_device_request_module()
  2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
                   ` (5 preceding siblings ...)
  2023-03-07 16:53 ` [PATCH v2 06/21] usb: ulpi: Use of_request_module() Miquel Raynal
@ 2023-03-07 16:53 ` Miquel Raynal
  2023-03-08  0:26   ` Rob Herring
  2023-03-07 16:53 ` [PATCH v2 08/21] dt-bindings: nvmem: Fix spelling mistake "platforn" -> "platform" Miquel Raynal
                   ` (14 subsequent siblings)
  21 siblings, 1 reply; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 16:53 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Miquel Raynal

A new helper has been introduced, of_request_module(). Users have been
converted, this helper can now be deleted.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/of/device.c       | 9 ---------
 include/linux/of_device.h | 6 ------
 2 files changed, 15 deletions(-)

diff --git a/drivers/of/device.c b/drivers/of/device.c
index 4bbb6e6388a9..717392cd416b 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -246,15 +246,6 @@ const void *of_device_get_match_data(const struct device *dev)
 }
 EXPORT_SYMBOL(of_device_get_match_data);
 
-int of_device_request_module(struct device *dev)
-{
-	if (!dev)
-		return -ENODEV;
-
-	return of_request_module(dev->of_node);
-}
-EXPORT_SYMBOL_GPL(of_device_request_module);
-
 /**
  * of_device_modalias - Fill buffer with newline terminated modalias string
  * @dev:	Calling device
diff --git a/include/linux/of_device.h b/include/linux/of_device.h
index ab7d557d541d..40c6c8d5299e 100644
--- a/include/linux/of_device.h
+++ b/include/linux/of_device.h
@@ -33,7 +33,6 @@ extern void of_device_unregister(struct platform_device *ofdev);
 extern const void *of_device_get_match_data(const struct device *dev);
 
 extern ssize_t of_device_modalias(struct device *dev, char *str, ssize_t len);
-extern int of_device_request_module(struct device *dev);
 
 extern void of_device_uevent(const struct device *dev, struct kobj_uevent_env *env);
 extern int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env);
@@ -78,11 +77,6 @@ static inline int of_device_modalias(struct device *dev,
 	return -ENODEV;
 }
 
-static inline int of_device_request_module(struct device *dev)
-{
-	return -ENODEV;
-}
-
 static inline int of_device_uevent_modalias(struct device *dev,
 				   struct kobj_uevent_env *env)
 {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH v2 08/21] dt-bindings: nvmem: Fix spelling mistake "platforn" -> "platform"
  2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
                   ` (6 preceding siblings ...)
  2023-03-07 16:53 ` [PATCH v2 07/21] of: device: Kill of_device_request_module() Miquel Raynal
@ 2023-03-07 16:53 ` Miquel Raynal
  2023-03-08  0:08   ` Rob Herring
  2023-03-10  9:55   ` Srinivas Kandagatla
  2023-03-07 16:53 ` [PATCH v2 09/21] nvmem: core: return -ENOENT if nvmem cell is not found Miquel Raynal
                   ` (13 subsequent siblings)
  21 siblings, 2 replies; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 16:53 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Colin Ian King, Miquel Raynal

From: Colin Ian King <colin.i.king@gmail.com>

There is a spelling mistake in platforn-name. Fix it.

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 .../devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml b/Documentation/devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml
index 5a0e7671aa3f..714a6538cc7c 100644
--- a/Documentation/devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml
+++ b/Documentation/devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml
@@ -61,7 +61,7 @@ properties:
     type: object
     additionalProperties: false
 
-  platforn-name:
+  platform-name:
     type: object
     additionalProperties: false
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH v2 09/21] nvmem: core: return -ENOENT if nvmem cell is not found
  2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
                   ` (7 preceding siblings ...)
  2023-03-07 16:53 ` [PATCH v2 08/21] dt-bindings: nvmem: Fix spelling mistake "platforn" -> "platform" Miquel Raynal
@ 2023-03-07 16:53 ` Miquel Raynal
  2023-03-07 17:04   ` Michael Walle
  2023-03-10  9:57   ` Srinivas Kandagatla
  2023-03-07 16:53 ` [PATCH v2 10/21] nvmem: core: introduce NVMEM layouts Miquel Raynal
                   ` (12 subsequent siblings)
  21 siblings, 2 replies; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 16:53 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Alexander Stein, Miquel Raynal

From: Michael Walle <michael@walle.cc>

Prior to commit 3cb05fdbaed6 ("nvmem: core: add an index parameter to
the cell") of_nvmem_cell_get() would return -ENOENT if the cell wasn't
found. Particularly, if of_property_match_string() returned -EINVAL,
that return code was passed as the index to of_parse_phandle(), which
then detected it as invalid and returned NULL. That led to an return
code of -ENOENT.

With the new code, the negative index will lead to an -EINVAL of
of_parse_phandle_with_optional_args() which pass straight to the
caller and break those who expect an -ENOENT.

Fix it by always returning -ENOENT.

Fixes: efff2655ab0f ("nvmem: core: add an index parameter to the cell")
Reported-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Michael Walle <michael@walle.cc>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/nvmem/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 174ef3574e07..22024b830788 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -1231,7 +1231,7 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id)
 						  "#nvmem-cell-cells",
 						  index, &cell_spec);
 	if (ret)
-		return ERR_PTR(ret);
+		return ERR_PTR(-ENOENT);
 
 	if (cell_spec.args_count > 1)
 		return ERR_PTR(-EINVAL);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH v2 10/21] nvmem: core: introduce NVMEM layouts
  2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
                   ` (8 preceding siblings ...)
  2023-03-07 16:53 ` [PATCH v2 09/21] nvmem: core: return -ENOENT if nvmem cell is not found Miquel Raynal
@ 2023-03-07 16:53 ` Miquel Raynal
  2023-03-07 16:53 ` [PATCH v2 11/21] nvmem: core: handle the absence of expected layouts Miquel Raynal
                   ` (11 subsequent siblings)
  21 siblings, 0 replies; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 16:53 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Miquel Raynal

From: Michael Walle <michael@walle.cc>

NVMEM layouts are used to generate NVMEM cells during runtime. Think of
an EEPROM with a well-defined conent. For now, the content can be
described by a device tree or a board file. But this only works if the
offsets and lengths are static and don't change. One could also argue
that putting the layout of the EEPROM in the device tree is the wrong
place. Instead, the device tree should just have a specific compatible
string.

Right now there are two use cases:
 (1) The NVMEM cell needs special processing. E.g. if it only specifies
     a base MAC address offset and you need to add an offset, or it
     needs to parse a MAC from ASCII format or some proprietary format.
     (Post processing of cells is added in a later commit).
 (2) u-boot environment parsing. The cells don't have a particular
     offset but it needs parsing the content to determine the offsets
     and length.

Co-developed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Michael Walle <michael@walle.cc>
---
 Documentation/driver-api/nvmem.rst |  15 ++++
 drivers/nvmem/Kconfig              |   4 +
 drivers/nvmem/Makefile             |   1 +
 drivers/nvmem/core.c               | 120 +++++++++++++++++++++++++++++
 drivers/nvmem/layouts/Kconfig      |   5 ++
 drivers/nvmem/layouts/Makefile     |   4 +
 include/linux/nvmem-consumer.h     |   7 ++
 include/linux/nvmem-provider.h     |  51 ++++++++++++
 8 files changed, 207 insertions(+)
 create mode 100644 drivers/nvmem/layouts/Kconfig
 create mode 100644 drivers/nvmem/layouts/Makefile

diff --git a/Documentation/driver-api/nvmem.rst b/Documentation/driver-api/nvmem.rst
index e3366322d46c..de221e91c8e3 100644
--- a/Documentation/driver-api/nvmem.rst
+++ b/Documentation/driver-api/nvmem.rst
@@ -185,3 +185,18 @@ ex::
 =====================
 
 See Documentation/devicetree/bindings/nvmem/nvmem.txt
+
+8. NVMEM layouts
+================
+
+NVMEM layouts are yet another mechanism to create cells. With the device
+tree binding it is possible to specify simple cells by using an offset
+and a length. Sometimes, the cells doesn't have a static offset, but
+the content is still well defined, e.g. tag-length-values. In this case,
+the NVMEM device content has to be first parsed and the cells need to
+be added accordingly. Layouts let you read the content of the NVMEM device
+and let you add cells dynamically.
+
+Another use case for layouts is the post processing of cells. With layouts,
+it is possible to associate a custom post processing hook to a cell. It
+even possible to add this hook to cells not created by the layout itself.
diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index 6dec38805041..ae2c5257ed97 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -21,6 +21,10 @@ config NVMEM_SYSFS
 	 This interface is mostly used by userspace applications to
 	 read/write directly into nvmem.
 
+# Layouts
+
+source "drivers/nvmem/layouts/Kconfig"
+
 # Devices
 
 config NVMEM_APPLE_EFUSES
diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
index 6a1efffa88f0..f82431ec8aef 100644
--- a/drivers/nvmem/Makefile
+++ b/drivers/nvmem/Makefile
@@ -5,6 +5,7 @@
 
 obj-$(CONFIG_NVMEM)		+= nvmem_core.o
 nvmem_core-y			:= core.o
+obj-y				+= layouts/
 
 # Devices
 obj-$(CONFIG_NVMEM_APPLE_EFUSES)	+= nvmem-apple-efuses.o
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 22024b830788..b9be1faeb7be 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -40,6 +40,7 @@ struct nvmem_device {
 	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;
 };
 
@@ -74,6 +75,9 @@ static LIST_HEAD(nvmem_lookup_list);
 
 static BLOCKING_NOTIFIER_HEAD(nvmem_notifier);
 
+static DEFINE_SPINLOCK(nvmem_layout_lock);
+static LIST_HEAD(nvmem_layouts);
+
 static int __nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset,
 			    void *val, size_t bytes)
 {
@@ -728,6 +732,101 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
 	return 0;
 }
 
+int __nvmem_layout_register(struct nvmem_layout *layout, struct module *owner)
+{
+	layout->owner = owner;
+
+	spin_lock(&nvmem_layout_lock);
+	list_add(&layout->node, &nvmem_layouts);
+	spin_unlock(&nvmem_layout_lock);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(__nvmem_layout_register);
+
+void nvmem_layout_unregister(struct nvmem_layout *layout)
+{
+	spin_lock(&nvmem_layout_lock);
+	list_del(&layout->node);
+	spin_unlock(&nvmem_layout_lock);
+}
+EXPORT_SYMBOL_GPL(nvmem_layout_unregister);
+
+static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *nvmem)
+{
+	struct device_node *layout_np, *np = nvmem->dev.of_node;
+	struct nvmem_layout *l, *layout = NULL;
+
+	layout_np = of_get_child_by_name(np, "nvmem-layout");
+	if (!layout_np)
+		return NULL;
+
+	spin_lock(&nvmem_layout_lock);
+
+	list_for_each_entry(l, &nvmem_layouts, node) {
+		if (of_match_node(l->of_match_table, layout_np)) {
+			if (try_module_get(l->owner))
+				layout = l;
+
+			break;
+		}
+	}
+
+	spin_unlock(&nvmem_layout_lock);
+	of_node_put(layout_np);
+
+	return layout;
+}
+
+static void nvmem_layout_put(struct nvmem_layout *layout)
+{
+	if (layout)
+		module_put(layout->owner);
+}
+
+static int nvmem_add_cells_from_layout(struct nvmem_device *nvmem)
+{
+	struct nvmem_layout *layout = nvmem->layout;
+	int ret;
+
+	if (layout && layout->add_cells) {
+		ret = layout->add_cells(&nvmem->dev, nvmem, layout);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+#if IS_ENABLED(CONFIG_OF)
+/**
+ * of_nvmem_layout_get_container() - Get OF node to layout container.
+ *
+ * @nvmem: nvmem device.
+ *
+ * Return: a node pointer with refcount incremented or NULL if no
+ * container exists. Use of_node_put() on it when done.
+ */
+struct device_node *of_nvmem_layout_get_container(struct nvmem_device *nvmem)
+{
+	return of_get_child_by_name(nvmem->dev.of_node, "nvmem-layout");
+}
+EXPORT_SYMBOL_GPL(of_nvmem_layout_get_container);
+#endif
+
+const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem,
+					struct nvmem_layout *layout)
+{
+	struct device_node __maybe_unused *layout_np;
+	const struct of_device_id *match;
+
+	layout_np = of_nvmem_layout_get_container(nvmem);
+	match = of_match_node(layout->of_match_table, layout_np);
+
+	return match ? match->data : NULL;
+}
+EXPORT_SYMBOL_GPL(nvmem_layout_get_match_data);
+
 /**
  * nvmem_register() - Register a nvmem device for given nvmem_config.
  * Also creates a binary entry in /sys/bus/nvmem/devices/dev-name/nvmem
@@ -834,6 +933,12 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 			goto err_put_device;
 	}
 
+	/*
+	 * If the driver supplied a layout by config->layout, the module
+	 * pointer will be NULL and nvmem_layout_put() will be a noop.
+	 */
+	nvmem->layout = config->layout ?: nvmem_layout_get(nvmem);
+
 	if (config->cells) {
 		rval = nvmem_add_cells(nvmem, config->cells, config->ncells);
 		if (rval)
@@ -854,12 +959,17 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 	if (rval)
 		goto err_remove_cells;
 
+	rval = nvmem_add_cells_from_layout(nvmem);
+	if (rval)
+		goto err_remove_cells;
+
 	blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem);
 
 	return nvmem;
 
 err_remove_cells:
 	nvmem_device_remove_all_cells(nvmem);
+	nvmem_layout_put(nvmem->layout);
 	if (config->compat)
 		nvmem_sysfs_remove_compat(nvmem, config);
 err_put_device:
@@ -881,6 +991,7 @@ static void nvmem_device_release(struct kref *kref)
 		device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom);
 
 	nvmem_device_remove_all_cells(nvmem);
+	nvmem_layout_put(nvmem->layout);
 	device_unregister(&nvmem->dev);
 }
 
@@ -1246,6 +1357,15 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id)
 		return ERR_PTR(-EINVAL);
 	}
 
+	/* nvmem layouts produce cells within the nvmem-layout container */
+	if (of_node_name_eq(nvmem_np, "nvmem-layout")) {
+		nvmem_np = of_get_next_parent(nvmem_np);
+		if (!nvmem_np) {
+			of_node_put(cell_np);
+			return ERR_PTR(-EINVAL);
+		}
+	}
+
 	nvmem = __nvmem_device_get(nvmem_np, device_match_of_node);
 	of_node_put(nvmem_np);
 	if (IS_ERR(nvmem)) {
diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig
new file mode 100644
index 000000000000..9ad3911d1605
--- /dev/null
+++ b/drivers/nvmem/layouts/Kconfig
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+
+menu "Layout Types"
+
+endmenu
diff --git a/drivers/nvmem/layouts/Makefile b/drivers/nvmem/layouts/Makefile
new file mode 100644
index 000000000000..6fdb3c60a4fa
--- /dev/null
+++ b/drivers/nvmem/layouts/Makefile
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for nvmem layouts.
+#
diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h
index 1f62f7ba71ca..fa030d93b768 100644
--- a/include/linux/nvmem-consumer.h
+++ b/include/linux/nvmem-consumer.h
@@ -239,6 +239,7 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
 				     const char *id);
 struct nvmem_device *of_nvmem_device_get(struct device_node *np,
 					 const char *name);
+struct device_node *of_nvmem_layout_get_container(struct nvmem_device *nvmem);
 #else
 static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
 						   const char *id)
@@ -251,6 +252,12 @@ static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np,
 {
 	return ERR_PTR(-EOPNOTSUPP);
 }
+
+static inline struct device_node *
+of_nvmem_layout_get_container(struct nvmem_device *nvmem)
+{
+	return ERR_PTR(-EOPNOTSUPP);
+}
 #endif /* CONFIG_NVMEM && CONFIG_OF */
 
 #endif  /* ifndef _LINUX_NVMEM_CONSUMER_H */
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index 0262b86194eb..535c5f9f3309 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -88,6 +88,7 @@ struct nvmem_cell_info {
  * @stride:	Minimum read/write access stride.
  * @priv:	User context passed to read/write callbacks.
  * @ignore_wp:  Write Protect pin is managed by the provider.
+ * @layout:	Fixed layout associated with this nvmem device.
  *
  * Note: A default "nvmem<id>" name will be assigned to the device if
  * no name is specified in its configuration. In such case "<id>" is
@@ -109,6 +110,7 @@ struct nvmem_config {
 	bool			read_only;
 	bool			root_only;
 	bool			ignore_wp;
+	struct nvmem_layout	*layout;
 	struct device_node	*of_node;
 	bool			no_of_node;
 	nvmem_reg_read_t	reg_read;
@@ -142,6 +144,33 @@ struct nvmem_cell_table {
 	struct list_head	node;
 };
 
+/**
+ * struct nvmem_layout - NVMEM layout definitions
+ *
+ * @name:		Layout name.
+ * @of_match_table:	Open firmware match 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().
+ * @owner:		Pointer to struct module.
+ * @node:		List node.
+ *
+ * A nvmem device can hold a well defined structure which can just be
+ * evaluated during runtime. For example a TLV list, or a list of "name=val"
+ * pairs. A nvmem layout can parse the nvmem device and add appropriate
+ * cells.
+ */
+struct nvmem_layout {
+	const char *name;
+	const struct of_device_id *of_match_table;
+	int (*add_cells)(struct device *dev, struct nvmem_device *nvmem,
+			 struct nvmem_layout *layout);
+
+	/* private */
+	struct module *owner;
+	struct list_head node;
+};
+
 #if IS_ENABLED(CONFIG_NVMEM)
 
 struct nvmem_device *nvmem_register(const struct nvmem_config *cfg);
@@ -156,6 +185,14 @@ void nvmem_del_cell_table(struct nvmem_cell_table *table);
 int nvmem_add_one_cell(struct nvmem_device *nvmem,
 		       const struct nvmem_cell_info *info);
 
+int __nvmem_layout_register(struct nvmem_layout *layout, struct module *owner);
+#define nvmem_layout_register(layout) \
+	__nvmem_layout_register(layout, THIS_MODULE)
+void nvmem_layout_unregister(struct nvmem_layout *layout);
+
+const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem,
+					struct nvmem_layout *layout);
+
 #else
 
 static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c)
@@ -179,5 +216,19 @@ static inline int nvmem_add_one_cell(struct nvmem_device *nvmem,
 	return -EOPNOTSUPP;
 }
 
+static inline int nvmem_layout_register(struct nvmem_layout *layout)
+{
+	return -EOPNOTSUPP;
+}
+
+static inline void nvmem_layout_unregister(struct nvmem_layout *layout) {}
+
+static inline const void *
+nvmem_layout_get_match_data(struct nvmem_device *nvmem,
+			    struct nvmem_layout *layout)
+{
+	return NULL;
+}
+
 #endif /* CONFIG_NVMEM */
 #endif  /* ifndef _LINUX_NVMEM_PROVIDER_H */
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH v2 11/21] nvmem: core: handle the absence of expected layouts
  2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
                   ` (9 preceding siblings ...)
  2023-03-07 16:53 ` [PATCH v2 10/21] nvmem: core: introduce NVMEM layouts Miquel Raynal
@ 2023-03-07 16:53 ` Miquel Raynal
  2023-03-10 10:30   ` Srinivas Kandagatla
  2023-03-07 16:53 ` [PATCH v2 12/21] nvmem: core: request layout modules loading Miquel Raynal
                   ` (10 subsequent siblings)
  21 siblings, 1 reply; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 16:53 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Miquel Raynal

Make nvmem_layout_get() return -EPROBE_DEFER while the expected layout
is not available. This condition cannot be triggered today as nvmem
layout drivers are initialed as part of an early init call, but soon
these drivers will be converted into modules and be initialized with a
standard priority, so the unavailability of the drivers might become a
reality that must be taken care of.

Let's anticipate this by telling the caller the layout might not yet be
available. A probe deferral is requested in this case.

Please note this does not affect any nvmem device not using layouts,
because an early check against the "nvmem-layout" container presence
will return NULL in this case.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Tested-by: Michael Walle <michael@walle.cc>
---
 drivers/nvmem/core.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index b9be1faeb7be..51fd792b8d70 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -755,7 +755,7 @@ EXPORT_SYMBOL_GPL(nvmem_layout_unregister);
 static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *nvmem)
 {
 	struct device_node *layout_np, *np = nvmem->dev.of_node;
-	struct nvmem_layout *l, *layout = NULL;
+	struct nvmem_layout *l, *layout = ERR_PTR(-EPROBE_DEFER);
 
 	layout_np = of_get_child_by_name(np, "nvmem-layout");
 	if (!layout_np)
@@ -938,6 +938,13 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 	 * pointer will be NULL and nvmem_layout_put() will be a noop.
 	 */
 	nvmem->layout = config->layout ?: nvmem_layout_get(nvmem);
+	if (IS_ERR(nvmem->layout)) {
+		rval = PTR_ERR(nvmem->layout);
+		nvmem->layout = NULL;
+
+		if (rval == -EPROBE_DEFER)
+			goto err_teardown_compat;
+	}
 
 	if (config->cells) {
 		rval = nvmem_add_cells(nvmem, config->cells, config->ncells);
@@ -970,6 +977,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 err_remove_cells:
 	nvmem_device_remove_all_cells(nvmem);
 	nvmem_layout_put(nvmem->layout);
+err_teardown_compat:
 	if (config->compat)
 		nvmem_sysfs_remove_compat(nvmem, config);
 err_put_device:
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH v2 12/21] nvmem: core: request layout modules loading
  2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
                   ` (10 preceding siblings ...)
  2023-03-07 16:53 ` [PATCH v2 11/21] nvmem: core: handle the absence of expected layouts Miquel Raynal
@ 2023-03-07 16:53 ` Miquel Raynal
  2023-03-07 16:53 ` [PATCH v2 13/21] nvmem: core: add per-cell post processing Miquel Raynal
                   ` (9 subsequent siblings)
  21 siblings, 0 replies; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 16:53 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Miquel Raynal

When a storage device like an eeprom or an mtd device probes, it
registers an nvmem device if the nvmem subsystem has been enabled (bool
symbol). During nvmem registration, if the device is using layouts to
expose dynamic nvmem cells, the core will first try to get a reference
over the layout driver callbacks. In practice there is not relationship
that can be described between the storage driver and the nvmem
layout. So there is no way we can enforce both drivers will be built-in
or both will be modules. If the storage device driver is built-in but
the layout is built as a module, instead of badly failing with an
endless probe deferral loop, lets just make a modprobe call in case the
driver was made available in an initramfs with
of_device_node_request_module(), and offer a fully functional system to
the user.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Tested-by: Michael Walle <michael@walle.cc>
---
 drivers/nvmem/core.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 51fd792b8d70..9ef7617e2718 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -17,6 +17,7 @@
 #include <linux/nvmem-provider.h>
 #include <linux/gpio/consumer.h>
 #include <linux/of.h>
+#include <linux/of_device.h>
 #include <linux/slab.h>
 
 struct nvmem_device {
@@ -761,6 +762,13 @@ static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *nvmem)
 	if (!layout_np)
 		return NULL;
 
+	/*
+	 * In case the nvmem device was built-in while the layout was built as a
+	 * module, we shall manually request the layout driver loading otherwise
+	 * we'll never have any match.
+	 */
+	of_device_node_request_module(layout_np);
+
 	spin_lock(&nvmem_layout_lock);
 
 	list_for_each_entry(l, &nvmem_layouts, node) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH v2 13/21] nvmem: core: add per-cell post processing
  2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
                   ` (11 preceding siblings ...)
  2023-03-07 16:53 ` [PATCH v2 12/21] nvmem: core: request layout modules loading Miquel Raynal
@ 2023-03-07 16:53 ` Miquel Raynal
  2023-03-07 16:53 ` [PATCH v2 14/21] nvmem: core: allow to modify a cell before adding it Miquel Raynal
                   ` (8 subsequent siblings)
  21 siblings, 0 replies; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 16:53 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Miquel Raynal

From: Michael Walle <michael@walle.cc>

Instead of relying on the name the consumer is using for the cell, like
it is done for the nvmem .cell_post_process configuration parameter,
provide a per-cell post processing hook. This can then be populated by
the NVMEM provider (or the NVMEM layout) when adding the cell.

Signed-off-by: Michael Walle <michael@walle.cc>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/nvmem/core.c           | 17 +++++++++++++++++
 include/linux/nvmem-provider.h |  3 +++
 2 files changed, 20 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 9ef7617e2718..664d48f0dfa7 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -54,6 +54,7 @@ struct nvmem_cell_entry {
 	int			bytes;
 	int			bit_offset;
 	int			nbits;
+	nvmem_cell_post_process_t read_post_process;
 	struct device_node	*np;
 	struct nvmem_device	*nvmem;
 	struct list_head	node;
@@ -470,6 +471,7 @@ static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem,
 	cell->offset = info->offset;
 	cell->bytes = info->bytes;
 	cell->name = info->name;
+	cell->read_post_process = info->read_post_process;
 
 	cell->bit_offset = info->bit_offset;
 	cell->nbits = info->nbits;
@@ -1563,6 +1565,13 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem,
 	if (cell->bit_offset || cell->nbits)
 		nvmem_shift_read_buffer_in_place(cell, buf);
 
+	if (cell->read_post_process) {
+		rc = cell->read_post_process(nvmem->priv, id, index,
+					     cell->offset, buf, cell->bytes);
+		if (rc)
+			return rc;
+	}
+
 	if (nvmem->cell_post_process) {
 		rc = nvmem->cell_post_process(nvmem->priv, id, index,
 					      cell->offset, buf, cell->bytes);
@@ -1671,6 +1680,14 @@ static int __nvmem_cell_entry_write(struct nvmem_cell_entry *cell, void *buf, si
 	    (cell->bit_offset == 0 && len != cell->bytes))
 		return -EINVAL;
 
+	/*
+	 * Any cells which have a read_post_process hook are read-only because
+	 * we cannot reverse the operation and it might affect other cells,
+	 * too.
+	 */
+	if (cell->read_post_process)
+		return -EINVAL;
+
 	if (cell->bit_offset || cell->nbits) {
 		buf = nvmem_cell_prepare_write_buffer(cell, buf, len);
 		if (IS_ERR(buf))
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index 535c5f9f3309..3bfc23553a9e 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -54,6 +54,8 @@ struct nvmem_keepout {
  * @bit_offset:	Bit offset if cell is smaller than a byte.
  * @nbits:	Number of bits.
  * @np:		Optional device_node pointer.
+ * @read_post_process:	Callback for optional post processing of cell data
+ *			on reads.
  */
 struct nvmem_cell_info {
 	const char		*name;
@@ -62,6 +64,7 @@ struct nvmem_cell_info {
 	unsigned int		bit_offset;
 	unsigned int		nbits;
 	struct device_node	*np;
+	nvmem_cell_post_process_t read_post_process;
 };
 
 /**
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH v2 14/21] nvmem: core: allow to modify a cell before adding it
  2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
                   ` (12 preceding siblings ...)
  2023-03-07 16:53 ` [PATCH v2 13/21] nvmem: core: add per-cell post processing Miquel Raynal
@ 2023-03-07 16:53 ` Miquel Raynal
  2023-03-07 16:53 ` [PATCH v2 15/21] nvmem: imx-ocotp: replace global post processing with layouts Miquel Raynal
                   ` (7 subsequent siblings)
  21 siblings, 0 replies; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 16:53 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Miquel Raynal

From: Michael Walle <michael@walle.cc>

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 <michael@walle.cc>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 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 664d48f0dfa7..82e11b9576ad 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -695,6 +695,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 device_node *child;
 	const __be32 *addr;
@@ -724,6 +725,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 3bfc23553a9e..be81cc88eabc 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -155,6 +155,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.
  *
@@ -168,6 +170,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.34.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH v2 15/21] nvmem: imx-ocotp: replace global post processing with layouts
  2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
                   ` (13 preceding siblings ...)
  2023-03-07 16:53 ` [PATCH v2 14/21] nvmem: core: allow to modify a cell before adding it Miquel Raynal
@ 2023-03-07 16:53 ` Miquel Raynal
  2023-03-07 16:53 ` [PATCH v2 16/21] nvmem: cell: drop global cell_post_process Miquel Raynal
                   ` (6 subsequent siblings)
  21 siblings, 0 replies; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 16:53 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Miquel Raynal

From: Michael Walle <michael@walle.cc>

In preparation of retiring the global post processing hook change this
driver to use layouts. The layout will be supplied during registration
and will be used to add the post processing hook to all added cells.

Signed-off-by: Michael Walle <michael@walle.cc>
Tested-by: Michael Walle <michael@walle.cc> # on kontron-pitx-imx8m
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/nvmem/imx-ocotp.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c
index e9b52ecb3f72..ac0edb6398f1 100644
--- a/drivers/nvmem/imx-ocotp.c
+++ b/drivers/nvmem/imx-ocotp.c
@@ -225,18 +225,13 @@ static int imx_ocotp_read(void *context, unsigned int offset,
 static int imx_ocotp_cell_pp(void *context, const char *id, int index,
 			     unsigned int offset, void *data, size_t bytes)
 {
-	struct ocotp_priv *priv = context;
+	u8 *buf = data;
+	int i;
 
 	/* Deal with some post processing of nvmem cell data */
-	if (id && !strcmp(id, "mac-address")) {
-		if (priv->params->reverse_mac_address) {
-			u8 *buf = data;
-			int i;
-
-			for (i = 0; i < bytes/2; i++)
-				swap(buf[i], buf[bytes - i - 1]);
-		}
-	}
+	if (id && !strcmp(id, "mac-address"))
+		for (i = 0; i < bytes / 2; i++)
+			swap(buf[i], buf[bytes - i - 1]);
 
 	return 0;
 }
@@ -488,7 +483,6 @@ static struct nvmem_config imx_ocotp_nvmem_config = {
 	.stride = 1,
 	.reg_read = imx_ocotp_read,
 	.reg_write = imx_ocotp_write,
-	.cell_post_process = imx_ocotp_cell_pp,
 };
 
 static const struct ocotp_params imx6q_params = {
@@ -595,6 +589,17 @@ static const struct of_device_id imx_ocotp_dt_ids[] = {
 };
 MODULE_DEVICE_TABLE(of, imx_ocotp_dt_ids);
 
+static void imx_ocotp_fixup_cell_info(struct nvmem_device *nvmem,
+				      struct nvmem_layout *layout,
+				      struct nvmem_cell_info *cell)
+{
+	cell->read_post_process = imx_ocotp_cell_pp;
+}
+
+struct nvmem_layout imx_ocotp_layout = {
+	.fixup_cell_info = imx_ocotp_fixup_cell_info,
+};
+
 static int imx_ocotp_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -619,6 +624,9 @@ static int imx_ocotp_probe(struct platform_device *pdev)
 	imx_ocotp_nvmem_config.size = 4 * priv->params->nregs;
 	imx_ocotp_nvmem_config.dev = dev;
 	imx_ocotp_nvmem_config.priv = priv;
+	if (priv->params->reverse_mac_address)
+		imx_ocotp_nvmem_config.layout = &imx_ocotp_layout;
+
 	priv->config = &imx_ocotp_nvmem_config;
 
 	clk_prepare_enable(priv->clk);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH v2 16/21] nvmem: cell: drop global cell_post_process
  2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
                   ` (14 preceding siblings ...)
  2023-03-07 16:53 ` [PATCH v2 15/21] nvmem: imx-ocotp: replace global post processing with layouts Miquel Raynal
@ 2023-03-07 16:53 ` Miquel Raynal
  2023-03-07 16:53 ` [PATCH v2 17/21] nvmem: core: provide own priv pointer in post process callback Miquel Raynal
                   ` (5 subsequent siblings)
  21 siblings, 0 replies; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 16:53 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Miquel Raynal

From: Michael Walle <michael@walle.cc>

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 <michael@walle.cc>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 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 82e11b9576ad..31d1d10c0e1c 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -39,7 +39,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;
@@ -903,7 +902,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)
@@ -1576,13 +1574,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 be81cc88eabc..d3d7af86a283 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.
@@ -118,7 +117,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.34.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH v2 17/21] nvmem: core: provide own priv pointer in post process callback
  2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
                   ` (15 preceding siblings ...)
  2023-03-07 16:53 ` [PATCH v2 16/21] nvmem: cell: drop global cell_post_process Miquel Raynal
@ 2023-03-07 16:53 ` Miquel Raynal
  2023-03-07 16:53 ` [PATCH v2 18/21] nvmem: layouts: sl28vpd: Add new layout driver Miquel Raynal
                   ` (4 subsequent siblings)
  21 siblings, 0 replies; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 16:53 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Miquel Raynal

From: Michael Walle <michael@walle.cc>

It doesn't make any more sense to have a opaque pointer set up by the
nvmem device. Usually, the layout isn't associated with a particular
nvmem device. Instead, let the caller who set the post process callback
provide the priv pointer.

Signed-off-by: Michael Walle <michael@walle.cc>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/nvmem/core.c           | 4 +++-
 include/linux/nvmem-provider.h | 5 ++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 31d1d10c0e1c..8e07b9df3221 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -54,6 +54,7 @@ struct nvmem_cell_entry {
 	int			bit_offset;
 	int			nbits;
 	nvmem_cell_post_process_t read_post_process;
+	void			*priv;
 	struct device_node	*np;
 	struct nvmem_device	*nvmem;
 	struct list_head	node;
@@ -471,6 +472,7 @@ static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem,
 	cell->bytes = info->bytes;
 	cell->name = info->name;
 	cell->read_post_process = info->read_post_process;
+	cell->priv = info->priv;
 
 	cell->bit_offset = info->bit_offset;
 	cell->nbits = info->nbits;
@@ -1568,7 +1570,7 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem,
 		nvmem_shift_read_buffer_in_place(cell, buf);
 
 	if (cell->read_post_process) {
-		rc = cell->read_post_process(nvmem->priv, id, index,
+		rc = cell->read_post_process(cell->priv, id, index,
 					     cell->offset, buf, cell->bytes);
 		if (rc)
 			return rc;
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index d3d7af86a283..0cf9f9490514 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -20,7 +20,8 @@ typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset,
 				 void *val, size_t bytes);
 /* used for vendor specific post processing of cell data */
 typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, int index,
-					 unsigned int offset, void *buf, size_t bytes);
+					 unsigned int offset, void *buf,
+					 size_t bytes);
 
 enum nvmem_type {
 	NVMEM_TYPE_UNKNOWN = 0,
@@ -56,6 +57,7 @@ struct nvmem_keepout {
  * @np:		Optional device_node pointer.
  * @read_post_process:	Callback for optional post processing of cell data
  *			on reads.
+ * @priv:	Opaque data passed to the read_post_process hook.
  */
 struct nvmem_cell_info {
 	const char		*name;
@@ -65,6 +67,7 @@ struct nvmem_cell_info {
 	unsigned int		nbits;
 	struct device_node	*np;
 	nvmem_cell_post_process_t read_post_process;
+	void			*priv;
 };
 
 /**
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH v2 18/21] nvmem: layouts: sl28vpd: Add new layout driver
  2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
                   ` (16 preceding siblings ...)
  2023-03-07 16:53 ` [PATCH v2 17/21] nvmem: core: provide own priv pointer in post process callback Miquel Raynal
@ 2023-03-07 16:53 ` Miquel Raynal
  2023-03-07 16:53 ` [PATCH v2 19/21] MAINTAINERS: add myself as sl28vpd nvmem " Miquel Raynal
                   ` (3 subsequent siblings)
  21 siblings, 0 replies; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 16:53 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Miquel Raynal

From: Michael Walle <michael@walle.cc>

This layout applies to the VPD of the Kontron sl28 boards. The VPD only
contains a base MAC address. Therefore, we have to add an individual
offset to it. This is done by taking the second argument of the nvmem
phandle into account. Also this let us checking the VPD version and the
checksum.

Signed-off-by: Michael Walle <michael@walle.cc>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/nvmem/layouts/Kconfig   |   9 ++
 drivers/nvmem/layouts/Makefile  |   2 +
 drivers/nvmem/layouts/sl28vpd.c | 165 ++++++++++++++++++++++++++++++++
 3 files changed, 176 insertions(+)
 create mode 100644 drivers/nvmem/layouts/sl28vpd.c

diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig
index 9ad3911d1605..fd161347c129 100644
--- a/drivers/nvmem/layouts/Kconfig
+++ b/drivers/nvmem/layouts/Kconfig
@@ -2,4 +2,13 @@
 
 menu "Layout Types"
 
+config NVMEM_LAYOUT_SL28_VPD
+	tristate "Kontron sl28 VPD layout support"
+	select CRC8
+	help
+	  Say Y here if you want to support the VPD layout of the Kontron
+	  SMARC-sAL28 boards.
+
+	  If unsure, say N.
+
 endmenu
diff --git a/drivers/nvmem/layouts/Makefile b/drivers/nvmem/layouts/Makefile
index 6fdb3c60a4fa..fc617b9e87d0 100644
--- a/drivers/nvmem/layouts/Makefile
+++ b/drivers/nvmem/layouts/Makefile
@@ -2,3 +2,5 @@
 #
 # Makefile for nvmem layouts.
 #
+
+obj-$(CONFIG_NVMEM_LAYOUT_SL28_VPD) += sl28vpd.o
diff --git a/drivers/nvmem/layouts/sl28vpd.c b/drivers/nvmem/layouts/sl28vpd.c
new file mode 100644
index 000000000000..9370e41bad73
--- /dev/null
+++ b/drivers/nvmem/layouts/sl28vpd.c
@@ -0,0 +1,165 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/crc8.h>
+#include <linux/etherdevice.h>
+#include <linux/nvmem-consumer.h>
+#include <linux/nvmem-provider.h>
+#include <linux/of.h>
+#include <uapi/linux/if_ether.h>
+
+#define SL28VPD_MAGIC 'V'
+
+struct sl28vpd_header {
+	u8 magic;
+	u8 version;
+} __packed;
+
+struct sl28vpd_v1 {
+	struct sl28vpd_header header;
+	char serial_number[15];
+	u8 base_mac_address[ETH_ALEN];
+	u8 crc8;
+} __packed;
+
+static int sl28vpd_mac_address_pp(void *priv, const char *id, int index,
+				  unsigned int offset, void *buf,
+				  size_t bytes)
+{
+	if (bytes != ETH_ALEN)
+		return -EINVAL;
+
+	if (index < 0)
+		return -EINVAL;
+
+	if (!is_valid_ether_addr(buf))
+		return -EINVAL;
+
+	eth_addr_add(buf, index);
+
+	return 0;
+}
+
+static const struct nvmem_cell_info sl28vpd_v1_entries[] = {
+	{
+		.name = "serial-number",
+		.offset = offsetof(struct sl28vpd_v1, serial_number),
+		.bytes = sizeof_field(struct sl28vpd_v1, serial_number),
+	},
+	{
+		.name = "base-mac-address",
+		.offset = offsetof(struct sl28vpd_v1, base_mac_address),
+		.bytes = sizeof_field(struct sl28vpd_v1, base_mac_address),
+		.read_post_process = sl28vpd_mac_address_pp,
+	},
+};
+
+static int sl28vpd_v1_check_crc(struct device *dev, struct nvmem_device *nvmem)
+{
+	struct sl28vpd_v1 data_v1;
+	u8 table[CRC8_TABLE_SIZE];
+	int ret;
+	u8 crc;
+
+	crc8_populate_msb(table, 0x07);
+
+	ret = nvmem_device_read(nvmem, 0, sizeof(data_v1), &data_v1);
+	if (ret < 0)
+		return ret;
+	else if (ret != sizeof(data_v1))
+		return -EIO;
+
+	crc = crc8(table, (void *)&data_v1, sizeof(data_v1) - 1, 0);
+
+	if (crc != data_v1.crc8) {
+		dev_err(dev,
+			"Checksum is invalid (got %02x, expected %02x).\n",
+			crc, data_v1.crc8);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int sl28vpd_add_cells(struct device *dev, struct nvmem_device *nvmem,
+			     struct nvmem_layout *layout)
+{
+	const struct nvmem_cell_info *pinfo;
+	struct nvmem_cell_info info = {0};
+	struct device_node *layout_np;
+	struct sl28vpd_header hdr;
+	int ret, i;
+
+	/* check header */
+	ret = nvmem_device_read(nvmem, 0, sizeof(hdr), &hdr);
+	if (ret < 0)
+		return ret;
+	else if (ret != sizeof(hdr))
+		return -EIO;
+
+	if (hdr.magic != SL28VPD_MAGIC) {
+		dev_err(dev, "Invalid magic value (%02x)\n", hdr.magic);
+		return -EINVAL;
+	}
+
+	if (hdr.version != 1) {
+		dev_err(dev, "Version %d is unsupported.\n", hdr.version);
+		return -EINVAL;
+	}
+
+	ret = sl28vpd_v1_check_crc(dev, nvmem);
+	if (ret)
+		return ret;
+
+	layout_np = of_nvmem_layout_get_container(nvmem);
+	if (!layout_np)
+		return -ENOENT;
+
+	for (i = 0; i < ARRAY_SIZE(sl28vpd_v1_entries); i++) {
+		pinfo = &sl28vpd_v1_entries[i];
+
+		info.name = pinfo->name;
+		info.offset = pinfo->offset;
+		info.bytes = pinfo->bytes;
+		info.read_post_process = pinfo->read_post_process;
+		info.np = of_get_child_by_name(layout_np, pinfo->name);
+
+		ret = nvmem_add_one_cell(nvmem, &info);
+		if (ret) {
+			of_node_put(layout_np);
+			return ret;
+		}
+	}
+
+	of_node_put(layout_np);
+
+	return 0;
+}
+
+static const struct of_device_id sl28vpd_of_match_table[] = {
+	{ .compatible = "kontron,sl28-vpd" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, sl28vpd_of_match_table);
+
+struct nvmem_layout sl28vpd_layout = {
+	.name = "sl28-vpd",
+	.of_match_table = sl28vpd_of_match_table,
+	.add_cells = sl28vpd_add_cells,
+};
+
+static int __init sl28vpd_init(void)
+{
+	return nvmem_layout_register(&sl28vpd_layout);
+}
+
+static void __exit sl28vpd_exit(void)
+{
+	nvmem_layout_unregister(&sl28vpd_layout);
+}
+
+module_init(sl28vpd_init);
+module_exit(sl28vpd_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Michael Walle <michael@walle.cc>");
+MODULE_DESCRIPTION("NVMEM layout driver for the VPD of Kontron sl28 boards");
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH v2 19/21] MAINTAINERS: add myself as sl28vpd nvmem layout driver
  2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
                   ` (17 preceding siblings ...)
  2023-03-07 16:53 ` [PATCH v2 18/21] nvmem: layouts: sl28vpd: Add new layout driver Miquel Raynal
@ 2023-03-07 16:53 ` Miquel Raynal
  2023-03-07 16:53 ` [PATCH v2 20/21] nvmem: layouts: onie-tlv: Add new " Miquel Raynal
                   ` (2 subsequent siblings)
  21 siblings, 0 replies; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 16:53 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Miquel Raynal

From: Michael Walle <michael@walle.cc>

Add myself as a maintainer for the new sl28vpd nvmem layout driver.

Signed-off-by: Michael Walle <michael@walle.cc>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 MAINTAINERS | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index f61eb221415b..70aa4547d784 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -19178,6 +19178,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 <michael@walle.cc>
+S:	Maintained
+F:	Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml
+F:	drivers/nvmem/layouts/sl28vpd.c
+
 SLAB ALLOCATOR
 M:	Christoph Lameter <cl@linux.com>
 M:	Pekka Enberg <penberg@kernel.org>
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH v2 20/21] nvmem: layouts: onie-tlv: Add new layout driver
  2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
                   ` (18 preceding siblings ...)
  2023-03-07 16:53 ` [PATCH v2 19/21] MAINTAINERS: add myself as sl28vpd nvmem " Miquel Raynal
@ 2023-03-07 16:53 ` Miquel Raynal
  2023-03-07 16:53 ` [PATCH v2 21/21] MAINTAINERS: Add myself as ONIE tlv NVMEM layout maintainer Miquel Raynal
  2023-03-07 17:09 ` [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
  21 siblings, 0 replies; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 16:53 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Miquel Raynal

This layout applies on top of any non volatile storage device containing
an ONIE table factory flashed. This table follows the tlv
(type-length-value) organization described in the link below. We cannot
afford using regular parsers because the content of these tables is
manufacturer specific and must be dynamically discovered.

Link: https://opencomputeproject.github.io/onie/design-spec/hw_requirements.html
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/nvmem/layouts/Kconfig    |   9 ++
 drivers/nvmem/layouts/Makefile   |   1 +
 drivers/nvmem/layouts/onie-tlv.c | 257 +++++++++++++++++++++++++++++++
 3 files changed, 267 insertions(+)
 create mode 100644 drivers/nvmem/layouts/onie-tlv.c

diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig
index fd161347c129..7ff1ee1c1f05 100644
--- a/drivers/nvmem/layouts/Kconfig
+++ b/drivers/nvmem/layouts/Kconfig
@@ -11,4 +11,13 @@ config NVMEM_LAYOUT_SL28_VPD
 
 	  If unsure, say N.
 
+config NVMEM_LAYOUT_ONIE_TLV
+	tristate "ONIE tlv support"
+	select CRC32
+	help
+	  Say Y here if you want to support the Open Compute Project ONIE
+	  Type-Length-Value standard table.
+
+	  If unsure, say N.
+
 endmenu
diff --git a/drivers/nvmem/layouts/Makefile b/drivers/nvmem/layouts/Makefile
index fc617b9e87d0..2974bd7d33ed 100644
--- a/drivers/nvmem/layouts/Makefile
+++ b/drivers/nvmem/layouts/Makefile
@@ -4,3 +4,4 @@
 #
 
 obj-$(CONFIG_NVMEM_LAYOUT_SL28_VPD) += sl28vpd.o
+obj-$(CONFIG_NVMEM_LAYOUT_ONIE_TLV) += onie-tlv.o
diff --git a/drivers/nvmem/layouts/onie-tlv.c b/drivers/nvmem/layouts/onie-tlv.c
new file mode 100644
index 000000000000..d45b7301a69d
--- /dev/null
+++ b/drivers/nvmem/layouts/onie-tlv.c
@@ -0,0 +1,257 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ONIE tlv NVMEM cells provider
+ *
+ * Copyright (C) 2022 Open Compute Group ONIE
+ * Author: Miquel Raynal <miquel.raynal@bootlin.com>
+ * Based on the nvmem driver written by: Vadym Kochan <vadym.kochan@plvision.eu>
+ * Inspired by the first layout written by: Rafał Miłecki <rafal@milecki.pl>
+ */
+
+#include <linux/crc32.h>
+#include <linux/etherdevice.h>
+#include <linux/nvmem-consumer.h>
+#include <linux/nvmem-provider.h>
+#include <linux/of.h>
+
+#define ONIE_TLV_MAX_LEN 2048
+#define ONIE_TLV_CRC_FIELD_SZ 6
+#define ONIE_TLV_CRC_SZ 4
+#define ONIE_TLV_HDR_ID	"TlvInfo"
+
+struct onie_tlv_hdr {
+	u8 id[8];
+	u8 version;
+	__be16 data_len;
+} __packed;
+
+struct onie_tlv {
+	u8 type;
+	u8 len;
+} __packed;
+
+static const char *onie_tlv_cell_name(u8 type)
+{
+	switch (type) {
+	case 0x21:
+		return "product-name";
+	case 0x22:
+		return "part-number";
+	case 0x23:
+		return "serial-number";
+	case 0x24:
+		return "mac-address";
+	case 0x25:
+		return "manufacture-date";
+	case 0x26:
+		return "device-version";
+	case 0x27:
+		return "label-revision";
+	case 0x28:
+		return "platform-name";
+	case 0x29:
+		return "onie-version";
+	case 0x2A:
+		return "num-macs";
+	case 0x2B:
+		return "manufacturer";
+	case 0x2C:
+		return "country-code";
+	case 0x2D:
+		return "vendor";
+	case 0x2E:
+		return "diag-version";
+	case 0x2F:
+		return "service-tag";
+	case 0xFD:
+		return "vendor-extension";
+	case 0xFE:
+		return "crc32";
+	default:
+		break;
+	}
+
+	return NULL;
+}
+
+static int onie_tlv_mac_read_cb(void *priv, const char *id, int index,
+				unsigned int offset, void *buf,
+				size_t bytes)
+{
+	eth_addr_add(buf, index);
+
+	return 0;
+}
+
+static nvmem_cell_post_process_t onie_tlv_read_cb(u8 type, u8 *buf)
+{
+	switch (type) {
+	case 0x24:
+		return &onie_tlv_mac_read_cb;
+	default:
+		break;
+	}
+
+	return NULL;
+}
+
+static int onie_tlv_add_cells(struct device *dev, struct nvmem_device *nvmem,
+			      size_t data_len, u8 *data)
+{
+	struct nvmem_cell_info cell = {};
+	struct device_node *layout;
+	struct onie_tlv tlv;
+	unsigned int hdr_len = sizeof(struct onie_tlv_hdr);
+	unsigned int offset = 0;
+	int ret;
+
+	layout = of_nvmem_layout_get_container(nvmem);
+	if (!layout)
+		return -ENOENT;
+
+	while (offset < data_len) {
+		memcpy(&tlv, data + offset, sizeof(tlv));
+		if (offset + tlv.len >= data_len) {
+			dev_err(dev, "Out of bounds field (0x%x bytes at 0x%x)\n",
+				tlv.len, hdr_len + offset);
+			break;
+		}
+
+		cell.name = onie_tlv_cell_name(tlv.type);
+		if (!cell.name)
+			continue;
+
+		cell.offset = hdr_len + offset + sizeof(tlv.type) + sizeof(tlv.len);
+		cell.bytes = tlv.len;
+		cell.np = of_get_child_by_name(layout, cell.name);
+		cell.read_post_process = onie_tlv_read_cb(tlv.type, data + offset + sizeof(tlv));
+
+		ret = nvmem_add_one_cell(nvmem, &cell);
+		if (ret) {
+			of_node_put(layout);
+			return ret;
+		}
+
+		offset += sizeof(tlv) + tlv.len;
+	}
+
+	of_node_put(layout);
+
+	return 0;
+}
+
+static bool onie_tlv_hdr_is_valid(struct device *dev, struct onie_tlv_hdr *hdr)
+{
+	if (memcmp(hdr->id, ONIE_TLV_HDR_ID, sizeof(hdr->id))) {
+		dev_err(dev, "Invalid header\n");
+		return false;
+	}
+
+	if (hdr->version != 0x1) {
+		dev_err(dev, "Invalid version number\n");
+		return false;
+	}
+
+	return true;
+}
+
+static bool onie_tlv_crc_is_valid(struct device *dev, size_t table_len, u8 *table)
+{
+	struct onie_tlv crc_hdr;
+	u32 read_crc, calc_crc;
+	__be32 crc_be;
+
+	memcpy(&crc_hdr, table + table_len - ONIE_TLV_CRC_FIELD_SZ, sizeof(crc_hdr));
+	if (crc_hdr.type != 0xfe || crc_hdr.len != ONIE_TLV_CRC_SZ) {
+		dev_err(dev, "Invalid CRC field\n");
+		return false;
+	}
+
+	/* The table contains a JAMCRC, which is XOR'ed compared to the original
+	 * CRC32 implementation as known in the Ethernet world.
+	 */
+	memcpy(&crc_be, table + table_len - ONIE_TLV_CRC_SZ, ONIE_TLV_CRC_SZ);
+	read_crc = be32_to_cpu(crc_be);
+	calc_crc = crc32(~0, table, table_len - ONIE_TLV_CRC_SZ) ^ 0xFFFFFFFF;
+	if (read_crc != calc_crc) {
+		dev_err(dev, "Invalid CRC read: 0x%08x, expected: 0x%08x\n",
+			read_crc, calc_crc);
+		return false;
+	}
+
+	return true;
+}
+
+static int onie_tlv_parse_table(struct device *dev, struct nvmem_device *nvmem,
+				struct nvmem_layout *layout)
+{
+	struct onie_tlv_hdr hdr;
+	size_t table_len, data_len, hdr_len;
+	u8 *table, *data;
+	int ret;
+
+	ret = nvmem_device_read(nvmem, 0, sizeof(hdr), &hdr);
+	if (ret < 0)
+		return ret;
+
+	if (!onie_tlv_hdr_is_valid(dev, &hdr)) {
+		dev_err(dev, "Invalid ONIE TLV header\n");
+		return -EINVAL;
+	}
+
+	hdr_len = sizeof(hdr.id) + sizeof(hdr.version) + sizeof(hdr.data_len);
+	data_len = be16_to_cpu(hdr.data_len);
+	table_len = hdr_len + data_len;
+	if (table_len > ONIE_TLV_MAX_LEN) {
+		dev_err(dev, "Invalid ONIE TLV data length\n");
+		return -EINVAL;
+	}
+
+	table = devm_kmalloc(dev, table_len, GFP_KERNEL);
+	if (!table)
+		return -ENOMEM;
+
+	ret = nvmem_device_read(nvmem, 0, table_len, table);
+	if (ret != table_len)
+		return ret;
+
+	if (!onie_tlv_crc_is_valid(dev, table_len, table))
+		return -EINVAL;
+
+	data = table + hdr_len;
+	ret = onie_tlv_add_cells(dev, nvmem, data_len, data);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static const struct of_device_id onie_tlv_of_match_table[] = {
+	{ .compatible = "onie,tlv-layout", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, onie_tlv_of_match_table);
+
+static struct nvmem_layout onie_tlv_layout = {
+	.name = "ONIE tlv layout",
+	.of_match_table = onie_tlv_of_match_table,
+	.add_cells = onie_tlv_parse_table,
+};
+
+static int __init onie_tlv_init(void)
+{
+	return nvmem_layout_register(&onie_tlv_layout);
+}
+
+static void __exit onie_tlv_exit(void)
+{
+	nvmem_layout_unregister(&onie_tlv_layout);
+}
+
+module_init(onie_tlv_init);
+module_exit(onie_tlv_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Miquel Raynal <miquel.raynal@bootlin.com>");
+MODULE_DESCRIPTION("NVMEM layout driver for Onie TLV table parsing");
+MODULE_ALIAS("NVMEM layout driver for Onie TLV table parsing");
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH v2 21/21] MAINTAINERS: Add myself as ONIE tlv NVMEM layout maintainer
  2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
                   ` (19 preceding siblings ...)
  2023-03-07 16:53 ` [PATCH v2 20/21] nvmem: layouts: onie-tlv: Add new " Miquel Raynal
@ 2023-03-07 16:53 ` Miquel Raynal
  2023-03-07 17:09 ` [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
  21 siblings, 0 replies; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 16:53 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Miquel Raynal

Following the introduction of the bindings for this NVMEM parser and the
layout driver, add myself as maintainer.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 MAINTAINERS | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 70aa4547d784..60b8f2c07e7f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -15577,6 +15577,12 @@ L:	linux-hwmon@vger.kernel.org
 S:	Maintained
 F:	drivers/hwmon/oxp-sensors.c
 
+ONIE TLV NVMEM LAYOUT DRIVER
+M:	Miquel Raynal <miquel.raynal@bootlin.com>
+S:	Maintained
+F:	Documentation/devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml
+F:	drivers/nvmem/layouts/onie-tlv.c
+
 ONION OMEGA2+ BOARD
 M:	Harvey Hunt <harveyhuntnexus@gmail.com>
 L:	linux-mips@vger.kernel.org
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 09/21] nvmem: core: return -ENOENT if nvmem cell is not found
  2023-03-07 16:53 ` [PATCH v2 09/21] nvmem: core: return -ENOENT if nvmem cell is not found Miquel Raynal
@ 2023-03-07 17:04   ` Michael Walle
  2023-03-10  9:57   ` Srinivas Kandagatla
  1 sibling, 0 replies; 42+ messages in thread
From: Michael Walle @ 2023-03-07 17:04 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Srinivas Kandagatla, linux-kernel, Greg Kroah-Hartman,
	Rafał Miłecki, Robert Marko, Luka Perkov,
	Thomas Petazzoni, Rob Herring, Frank Rowand, devicetree,
	Alexander Stein

Am 2023-03-07 17:53, schrieb Miquel Raynal:
> From: Michael Walle <michael@walle.cc>
> 
> Prior to commit 3cb05fdbaed6 ("nvmem: core: add an index parameter to
> the cell") of_nvmem_cell_get() would return -ENOENT if the cell wasn't
> found. Particularly, if of_property_match_string() returned -EINVAL,
> that return code was passed as the index to of_parse_phandle(), which
> then detected it as invalid and returned NULL. That led to an return
> code of -ENOENT.
> 
> With the new code, the negative index will lead to an -EINVAL of
> of_parse_phandle_with_optional_args() which pass straight to the
> caller and break those who expect an -ENOENT.
> 
> Fix it by always returning -ENOENT.
> 
> Fixes: efff2655ab0f ("nvmem: core: add an index parameter to the cell")
> Reported-by: Alexander Stein <alexander.stein@ew.tq-group.com>
> Signed-off-by: Michael Walle <michael@walle.cc>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>

Misses the Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
tag. But.. this is already applied anyways:
https://lore.kernel.org/r/515d5fed-2083-c1fd-eea5-148d9e1c45bd@linaro.org/

-michael

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 00/21] nvmem: Layouts support
  2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
                   ` (20 preceding siblings ...)
  2023-03-07 16:53 ` [PATCH v2 21/21] MAINTAINERS: Add myself as ONIE tlv NVMEM layout maintainer Miquel Raynal
@ 2023-03-07 17:09 ` Miquel Raynal
  21 siblings, 0 replies; 42+ messages in thread
From: Miquel Raynal @ 2023-03-07 17:09 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Stephen Boyd, Peter Chen,
	Rafael J . Wysocki, Len Brown, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, Sebastian Reichel, Wolfram Sang, Mark Brown,
	Heikki Krogerus

Hi all,

miquel.raynal@bootlin.com wrote on Tue,  7 Mar 2023 17:53:38 +0100:

> Hello,
> 
> This is a fully featured series with hopefully all what is needed for
> upstream acceptance, ie:
> * A bit of OF cleanup
> * Full nvmem layout support merging Michael's and my patches
> * Only the fixes not applying to this series have been kept "un merged"
> * Support for SL28 VPD and ONIE TLV table layouts
> * Layouts can be compiled as modules

Unfortunately that is not gonna fly, I of course messed with the base
branch. Please ignore this, I will update, make everything fit and
resend.

Sincere apologies for the noise.

Thanks,
Miquèl

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 08/21] dt-bindings: nvmem: Fix spelling mistake "platforn" -> "platform"
  2023-03-07 16:53 ` [PATCH v2 08/21] dt-bindings: nvmem: Fix spelling mistake "platforn" -> "platform" Miquel Raynal
@ 2023-03-08  0:08   ` Rob Herring
  2023-03-08 14:07     ` Miquel Raynal
  2023-03-10  9:55   ` Srinivas Kandagatla
  1 sibling, 1 reply; 42+ messages in thread
From: Rob Herring @ 2023-03-08  0:08 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Colin Ian King, Rob Herring, Thomas Petazzoni,
	Rafał Miłecki, Michael Walle, devicetree, Frank Rowand,
	Greg Kroah-Hartman, linux-kernel, Srinivas Kandagatla,
	Luka Perkov, Robert Marko


On Tue, 07 Mar 2023 17:53:46 +0100, Miquel Raynal wrote:
> From: Colin Ian King <colin.i.king@gmail.com>
> 
> There is a spelling mistake in platforn-name. Fix it.
> 
> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
>  .../devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml      | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 


Please add Acked-by/Reviewed-by tags when posting new versions. However,
there's no need to repost patches *only* to add the tags. The upstream
maintainer will do that for acks received on the version they apply.

If a tag was not added on purpose, please state why and what changed.

Missing tags:

Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>




^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 03/21] of: Rename of_modalias_node()
  2023-03-07 16:53 ` [PATCH v2 03/21] of: Rename of_modalias_node() Miquel Raynal
@ 2023-03-08  0:19   ` Rob Herring
  2023-03-08 14:17     ` Miquel Raynal
  2023-03-08 22:06     ` Sebastian Reichel
  0 siblings, 2 replies; 42+ messages in thread
From: Rob Herring @ 2023-03-08  0:19 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Srinivas Kandagatla, linux-kernel, Greg Kroah-Hartman,
	Michael Walle, Rafał Miłecki, Robert Marko,
	Luka Perkov, Thomas Petazzoni, Frank Rowand, devicetree,
	Rafael J . Wysocki, Len Brown, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, Sebastian Reichel, Wolfram Sang, Mark Brown

On Tue, Mar 07, 2023 at 05:53:41PM +0100, Miquel Raynal wrote:
> This helper does not produce a real modalias, but tries to get the
> "product" compatible part of the "vendor,product" compatibles only. It
> is far from creating a purely useful modalias string and does not seem
> to be used like that directly anyway, so let's try to give this helper a
> more meaningful name before moving there a real modalias helper (already
> existing under of/device.c).
> 
> Also update the various documentations to refer to the strings as
> "aliases" rather than "modaliases" which has a real meaning in the Linux
> kernel.
> 
> There is no functional change.
> 
> Cc: Rafael J. Wysocki <rafael@kernel.org>
> Cc: Len Brown <lenb@kernel.org>
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Maxime Ripard <mripard@kernel.org>
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Sebastian Reichel <sre@kernel.org>
> Cc: Wolfram Sang <wsa@kernel.org>
> Cc: Mark Brown <broonie@kernel.org>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
>  drivers/acpi/bus.c                |  7 ++++---
>  drivers/gpu/drm/drm_mipi_dsi.c    |  2 +-
>  drivers/hsi/hsi_core.c            |  2 +-

These should not have been using this function. The matching on just the 
product was a relic from I2C and SPI which we don't want to propogate. 
No clue why ACPI needed it...

If you respin or want to fixup while applying, can you add a kerneldoc 
comment to not add new users of the function. Not that anyone will 
follow that... :(

Reviewed-by: Rob Herring <robh@kernel.org>

>  drivers/i2c/busses/i2c-powermac.c |  2 +-
>  drivers/i2c/i2c-core-of.c         |  2 +-
>  drivers/of/base.c                 | 15 ++++++++-------
>  drivers/spi/spi.c                 |  4 ++--
>  include/linux/of.h                |  2 +-
>  8 files changed, 19 insertions(+), 17 deletions(-)

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 04/21] of: Move of_modalias() to module.c
  2023-03-07 16:53 ` [PATCH v2 04/21] of: Move of_modalias() to module.c Miquel Raynal
@ 2023-03-08  0:23   ` Rob Herring
  2023-03-08 14:51     ` Miquel Raynal
  0 siblings, 1 reply; 42+ messages in thread
From: Rob Herring @ 2023-03-08  0:23 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Srinivas Kandagatla, linux-kernel, Greg Kroah-Hartman,
	Michael Walle, Rafał Miłecki, Robert Marko,
	Luka Perkov, Thomas Petazzoni, Frank Rowand, devicetree

On Tue, Mar 07, 2023 at 05:53:42PM +0100, Miquel Raynal wrote:
> Create a specific .c file for of related module handling.
> Move of_modalias() inside as a first step.

Perhaps a comment as to why it needs to be public? Or is it just shared 
within the DT core? If so, we have of_private.h for that.

> 
> Suggested-by: Rob Herring <robh+dt@kernel.org>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
>  drivers/of/Makefile |  2 +-
>  drivers/of/device.c | 37 -------------------------------------
>  drivers/of/module.c | 43 +++++++++++++++++++++++++++++++++++++++++++
>  include/linux/of.h  |  8 ++++++++
>  4 files changed, 52 insertions(+), 38 deletions(-)
>  create mode 100644 drivers/of/module.c
> 
> diff --git a/drivers/of/Makefile b/drivers/of/Makefile
> index e0360a44306e..ae9923fd2940 100644
> --- a/drivers/of/Makefile
> +++ b/drivers/of/Makefile
> @@ -1,5 +1,5 @@
>  # SPDX-License-Identifier: GPL-2.0
> -obj-y = base.o device.o platform.o property.o
> +obj-y = base.o device.o module.o platform.o property.o
>  obj-$(CONFIG_OF_KOBJ) += kobj.o
>  obj-$(CONFIG_OF_DYNAMIC) += dynamic.o
>  obj-$(CONFIG_OF_FLATTREE) += fdt.o
> diff --git a/drivers/of/device.c b/drivers/of/device.c
> index 2bbb67798916..44f1f2ef12b7 100644
> --- a/drivers/of/device.c
> +++ b/drivers/of/device.c
> @@ -1,5 +1,4 @@
>  // SPDX-License-Identifier: GPL-2.0
> -#include <linux/string.h>
>  #include <linux/kernel.h>
>  #include <linux/of.h>
>  #include <linux/of_device.h>
> @@ -248,42 +247,6 @@ const void *of_device_get_match_data(const struct device *dev)
>  }
>  EXPORT_SYMBOL(of_device_get_match_data);
>  
> -static ssize_t of_modalias(struct device_node *np, char *str, ssize_t len)
> -{
> -	const char *compat;
> -	char *c;
> -	struct property *p;
> -	ssize_t csize;
> -	ssize_t tsize;
> -
> -	/* Name & Type */
> -	/* %p eats all alphanum characters, so %c must be used here */
> -	csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T',
> -			 of_node_get_device_type(np));
> -	tsize = csize;
> -	len -= csize;
> -	if (str)
> -		str += csize;
> -
> -	of_property_for_each_string(np, "compatible", p, compat) {
> -		csize = strlen(compat) + 1;
> -		tsize += csize;
> -		if (csize > len)
> -			continue;
> -
> -		csize = snprintf(str, len, "C%s", compat);
> -		for (c = str; c; ) {
> -			c = strchr(c, ' ');
> -			if (c)
> -				*c++ = '_';
> -		}
> -		len -= csize;
> -		str += csize;
> -	}
> -
> -	return tsize;
> -}
> -
>  int of_device_request_module(struct device *dev)
>  {
>  	char *str;
> diff --git a/drivers/of/module.c b/drivers/of/module.c
> new file mode 100644
> index 000000000000..9c6a53f32c0f
> --- /dev/null
> +++ b/drivers/of/module.c
> @@ -0,0 +1,43 @@
> +// SPDX-License-Identifier: GPL-2.0+

Existing license was GPL-2.0 (-only).

> +/*
> + * Linux kernel module helpers.
> + */
> +
> +#include <linux/of.h>
> +#include <linux/string.h>
> +
> +ssize_t of_modalias(struct device_node *np, char *str, ssize_t len)
> +{
> +	const char *compat;
> +	char *c;
> +	struct property *p;
> +	ssize_t csize;
> +	ssize_t tsize;
> +
> +	/* Name & Type */
> +	/* %p eats all alphanum characters, so %c must be used here */
> +	csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T',
> +			 of_node_get_device_type(np));
> +	tsize = csize;
> +	len -= csize;
> +	if (str)
> +		str += csize;
> +
> +	of_property_for_each_string(np, "compatible", p, compat) {
> +		csize = strlen(compat) + 1;
> +		tsize += csize;
> +		if (csize > len)
> +			continue;
> +
> +		csize = snprintf(str, len, "C%s", compat);
> +		for (c = str; c; ) {
> +			c = strchr(c, ' ');
> +			if (c)
> +				*c++ = '_';
> +		}
> +		len -= csize;
> +		str += csize;
> +	}
> +
> +	return tsize;
> +}
> diff --git a/include/linux/of.h b/include/linux/of.h
> index fc7ada57df33..1372f8647272 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -373,6 +373,9 @@ extern int of_parse_phandle_with_args_map(const struct device_node *np,
>  extern int of_count_phandle_with_args(const struct device_node *np,
>  	const char *list_name, const char *cells_name);
>  
> +/* module functions */
> +extern ssize_t of_modalias(struct device_node *np, char *str, ssize_t len);
> +
>  /* phandle iterator functions */
>  extern int of_phandle_iterator_init(struct of_phandle_iterator *it,
>  				    const struct device_node *np,
> @@ -730,6 +733,11 @@ static inline int of_count_phandle_with_args(const struct device_node *np,
>  	return -ENOSYS;
>  }
>  
> +static inline ssize_t of_modalias(struct device_node *np, char *str, ssize_t len)
> +{
> +	return -ENODEV;
> +}
> +
>  static inline int of_phandle_iterator_init(struct of_phandle_iterator *it,
>  					   const struct device_node *np,
>  					   const char *list_name,
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 05/21] of: Move the request module helper logic to module.c
  2023-03-07 16:53 ` [PATCH v2 05/21] of: Move the request module helper logic " Miquel Raynal
@ 2023-03-08  0:25   ` Rob Herring
  0 siblings, 0 replies; 42+ messages in thread
From: Rob Herring @ 2023-03-08  0:25 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Srinivas Kandagatla, linux-kernel, Greg Kroah-Hartman,
	Michael Walle, Rafał Miłecki, Robert Marko,
	Luka Perkov, Thomas Petazzoni, Frank Rowand, devicetree

On Tue, Mar 07, 2023 at 05:53:43PM +0100, Miquel Raynal wrote:
> Depending on device.c for pure OF handling is considered
> backwards. Let's extract the content of of_device_request_module() to
> have the real logic under module.c.
> 
> The next step will be to convert users of of_device_request_module() to
> use the new helper.
> 
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
>  drivers/of/device.c | 25 ++-----------------------
>  drivers/of/module.c | 30 ++++++++++++++++++++++++++++++
>  include/linux/of.h  |  6 ++++++
>  3 files changed, 38 insertions(+), 23 deletions(-)

Other than the licensing inherited,

Reviewed-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 06/21] usb: ulpi: Use of_request_module()
  2023-03-07 16:53 ` [PATCH v2 06/21] usb: ulpi: Use of_request_module() Miquel Raynal
@ 2023-03-08  0:25   ` Rob Herring
  0 siblings, 0 replies; 42+ messages in thread
From: Rob Herring @ 2023-03-08  0:25 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Srinivas Kandagatla, linux-kernel, Greg Kroah-Hartman,
	Michael Walle, Rafał Miłecki, Robert Marko,
	Luka Perkov, Thomas Petazzoni, Frank Rowand, devicetree,
	Heikki Krogerus

On Tue, Mar 07, 2023 at 05:53:44PM +0100, Miquel Raynal wrote:
> There is a new helper supposed to replace of_device_request_module(),
> called of_request_module(). They are both strictly equivalent, besides
> the fact the latter receives a "struct device_node" directly. Use it.
> 
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
>  drivers/usb/common/ulpi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Acked-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 07/21] of: device: Kill of_device_request_module()
  2023-03-07 16:53 ` [PATCH v2 07/21] of: device: Kill of_device_request_module() Miquel Raynal
@ 2023-03-08  0:26   ` Rob Herring
  0 siblings, 0 replies; 42+ messages in thread
From: Rob Herring @ 2023-03-08  0:26 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Srinivas Kandagatla, linux-kernel, Greg Kroah-Hartman,
	Michael Walle, Rafał Miłecki, Robert Marko,
	Luka Perkov, Thomas Petazzoni, Frank Rowand, devicetree

On Tue, Mar 07, 2023 at 05:53:45PM +0100, Miquel Raynal wrote:
> A new helper has been introduced, of_request_module(). Users have been
> converted, this helper can now be deleted.
> 
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
>  drivers/of/device.c       | 9 ---------
>  include/linux/of_device.h | 6 ------
>  2 files changed, 15 deletions(-)

Reviewed-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 02/21] of: Update of_device_get_modalias()
  2023-03-07 16:53 ` [PATCH v2 02/21] of: Update of_device_get_modalias() Miquel Raynal
@ 2023-03-08  0:28   ` Rob Herring
  0 siblings, 0 replies; 42+ messages in thread
From: Rob Herring @ 2023-03-08  0:28 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Srinivas Kandagatla, linux-kernel, Greg Kroah-Hartman,
	Michael Walle, Rafał Miłecki, Robert Marko,
	Luka Perkov, Thomas Petazzoni, Frank Rowand, devicetree

On Tue, Mar 07, 2023 at 05:53:40PM +0100, Miquel Raynal wrote:
> This function only needs a "struct device_node" to work, but for
> convenience the author (and only user) of this helper did use a "struct
> device" and put it in device.c.
> 
> Let's convert this helper to take a "struct device node" instead. This
> change asks for two additional changes: renaming it "of_modalias()"
> to fit the current naming, and moving it outside of device.c which will
> be done in a follow-up commit.
> 
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
>  drivers/of/device.c | 29 +++++++++++++++++------------
>  1 file changed, 17 insertions(+), 12 deletions(-)

Reviewed-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 08/21] dt-bindings: nvmem: Fix spelling mistake "platforn" -> "platform"
  2023-03-08  0:08   ` Rob Herring
@ 2023-03-08 14:07     ` Miquel Raynal
  0 siblings, 0 replies; 42+ messages in thread
From: Miquel Raynal @ 2023-03-08 14:07 UTC (permalink / raw)
  To: Rob Herring
  Cc: Colin Ian King, Rob Herring, Thomas Petazzoni,
	Rafał Miłecki, Michael Walle, devicetree, Frank Rowand,
	Greg Kroah-Hartman, linux-kernel, Srinivas Kandagatla,
	Luka Perkov, Robert Marko

Hi Rob,

robh@kernel.org wrote on Tue, 7 Mar 2023 18:08:54 -0600:

> On Tue, 07 Mar 2023 17:53:46 +0100, Miquel Raynal wrote:
> > From: Colin Ian King <colin.i.king@gmail.com>
> > 
> > There is a spelling mistake in platforn-name. Fix it.
> > 
> > Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
> > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> > ---
> >  .../devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml      | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >   
> 
> 
> Please add Acked-by/Reviewed-by tags when posting new versions. However,
> there's no need to repost patches *only* to add the tags. The upstream
> maintainer will do that for acks received on the version they apply.
> 
> If a tag was not added on purpose, please state why and what changed.
> 
> Missing tags:
> 
> Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

I am absolutely sorry for dropping that tag, I took the patches from
the mailing list directly after an e-mail listing a set of patches that
have been dropped right before the merge window. I did not remember that
Ack when I performed that painful cherry-pick.

Thanks,
Miquèl

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 03/21] of: Rename of_modalias_node()
  2023-03-08  0:19   ` Rob Herring
@ 2023-03-08 14:17     ` Miquel Raynal
  2023-03-08 22:06     ` Sebastian Reichel
  1 sibling, 0 replies; 42+ messages in thread
From: Miquel Raynal @ 2023-03-08 14:17 UTC (permalink / raw)
  To: Rob Herring
  Cc: Srinivas Kandagatla, linux-kernel, Greg Kroah-Hartman,
	Michael Walle, Rafał Miłecki, Robert Marko,
	Luka Perkov, Thomas Petazzoni, Frank Rowand, devicetree,
	Rafael J . Wysocki, Len Brown, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, Sebastian Reichel, Wolfram Sang, Mark Brown

Hi Rob,

robh@kernel.org wrote on Tue, 7 Mar 2023 18:19:03 -0600:

> On Tue, Mar 07, 2023 at 05:53:41PM +0100, Miquel Raynal wrote:
> > This helper does not produce a real modalias, but tries to get the
> > "product" compatible part of the "vendor,product" compatibles only. It
> > is far from creating a purely useful modalias string and does not seem
> > to be used like that directly anyway, so let's try to give this helper a
> > more meaningful name before moving there a real modalias helper (already
> > existing under of/device.c).
> > 
> > Also update the various documentations to refer to the strings as
> > "aliases" rather than "modaliases" which has a real meaning in the Linux
> > kernel.
> > 
> > There is no functional change.
> > 
> > Cc: Rafael J. Wysocki <rafael@kernel.org>
> > Cc: Len Brown <lenb@kernel.org>
> > Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> > Cc: Maxime Ripard <mripard@kernel.org>
> > Cc: Thomas Zimmermann <tzimmermann@suse.de>
> > Cc: Sebastian Reichel <sre@kernel.org>
> > Cc: Wolfram Sang <wsa@kernel.org>
> > Cc: Mark Brown <broonie@kernel.org>
> > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> > ---
> >  drivers/acpi/bus.c                |  7 ++++---
> >  drivers/gpu/drm/drm_mipi_dsi.c    |  2 +-
> >  drivers/hsi/hsi_core.c            |  2 +-  
> 
> These should not have been using this function. The matching on just the 
> product was a relic from I2C and SPI which we don't want to propogate. 
> No clue why ACPI needed it...
> 
> If you respin or want to fixup while applying, can you add a kerneldoc 
> comment to not add new users of the function. Not that anyone will 
> follow that... :(

I extensively scratched my forehead while trying to understand the use
of this function. I've added this to my v3:

  * It does this by stripping the manufacturer prefix (as delimited by a ',')
  * from the first entry in the compatible list property.
  *
+ * Note: The matching on just the "product" side of the compatible is a relic
+ * from I2C and SPI. Please do not add any new user.
+ *
  * Return: This routine returns 0 on success, <0 on failure.
  */

> Reviewed-by: Rob Herring <robh@kernel.org>
> 
> >  drivers/i2c/busses/i2c-powermac.c |  2 +-
> >  drivers/i2c/i2c-core-of.c         |  2 +-
> >  drivers/of/base.c                 | 15 ++++++++-------
> >  drivers/spi/spi.c                 |  4 ++--
> >  include/linux/of.h                |  2 +-
> >  8 files changed, 19 insertions(+), 17 deletions(-)  


Thanks,
Miquèl

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 04/21] of: Move of_modalias() to module.c
  2023-03-08  0:23   ` Rob Herring
@ 2023-03-08 14:51     ` Miquel Raynal
  0 siblings, 0 replies; 42+ messages in thread
From: Miquel Raynal @ 2023-03-08 14:51 UTC (permalink / raw)
  To: Rob Herring
  Cc: Srinivas Kandagatla, linux-kernel, Greg Kroah-Hartman,
	Michael Walle, Rafał Miłecki, Robert Marko,
	Luka Perkov, Thomas Petazzoni, Frank Rowand, devicetree

Hi Rob,

robh@kernel.org wrote on Tue, 7 Mar 2023 18:23:06 -0600:

> On Tue, Mar 07, 2023 at 05:53:42PM +0100, Miquel Raynal wrote:
> > Create a specific .c file for of related module handling.
> > Move of_modalias() inside as a first step.  
> 
> Perhaps a comment as to why it needs to be public? Or is it just shared 
> within the DT core? If so, we have of_private.h for that.

Good point. This helper is actually only used internally (was static
before). At first I wanted to convert all users to use the "new" OF
module-related helpers, but unfortunately, the "dev->of_node_reused"
check makes this impossible. I thus need to keep a few users of
of_modalias() in of_device.h in the coming patches. I could move
of_modalias() to of_private.h but that would mean exposing all the
internals and private definitions to the drivers including of_device.h,
which seemed extremely unsatisfying to me.

I've updated the commit log with:

    The helper is exposed through of.h even though it is only used by core
    files because the users from device.c will soon be split into an OF-only
    helper in module.c as well as a device-oriented inline helper in
    of_device.h. Putting this helper in of_private.h would require to
    include of_private.h from of_device.h, which is not acceptable.

> 
> > 
> > Suggested-by: Rob Herring <robh+dt@kernel.org>
> > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> > ---
> >  drivers/of/Makefile |  2 +-
> >  drivers/of/device.c | 37 -------------------------------------
> >  drivers/of/module.c | 43 +++++++++++++++++++++++++++++++++++++++++++
> >  include/linux/of.h  |  8 ++++++++
> >  4 files changed, 52 insertions(+), 38 deletions(-)
> >  create mode 100644 drivers/of/module.c
> > 
> > diff --git a/drivers/of/Makefile b/drivers/of/Makefile
> > index e0360a44306e..ae9923fd2940 100644
> > --- a/drivers/of/Makefile
> > +++ b/drivers/of/Makefile
> > @@ -1,5 +1,5 @@
> >  # SPDX-License-Identifier: GPL-2.0
> > -obj-y = base.o device.o platform.o property.o
> > +obj-y = base.o device.o module.o platform.o property.o
> >  obj-$(CONFIG_OF_KOBJ) += kobj.o
> >  obj-$(CONFIG_OF_DYNAMIC) += dynamic.o
> >  obj-$(CONFIG_OF_FLATTREE) += fdt.o
> > diff --git a/drivers/of/device.c b/drivers/of/device.c
> > index 2bbb67798916..44f1f2ef12b7 100644
> > --- a/drivers/of/device.c
> > +++ b/drivers/of/device.c

[...]

> > diff --git a/drivers/of/module.c b/drivers/of/module.c
> > new file mode 100644
> > index 000000000000..9c6a53f32c0f
> > --- /dev/null
> > +++ b/drivers/of/module.c
> > @@ -0,0 +1,43 @@
> > +// SPDX-License-Identifier: GPL-2.0+  
> 
> Existing license was GPL-2.0 (-only).

Oh right, I took the license from base.c, you're right I should have
taken the one from device.c.

Thanks,
Miquèl

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 03/21] of: Rename of_modalias_node()
  2023-03-08  0:19   ` Rob Herring
  2023-03-08 14:17     ` Miquel Raynal
@ 2023-03-08 22:06     ` Sebastian Reichel
  2023-03-09 13:28       ` Rob Herring
  1 sibling, 1 reply; 42+ messages in thread
From: Sebastian Reichel @ 2023-03-08 22:06 UTC (permalink / raw)
  To: Rob Herring
  Cc: Miquel Raynal, Srinivas Kandagatla, linux-kernel,
	Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Frank Rowand,
	devicetree, Rafael J . Wysocki, Len Brown, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, Wolfram Sang, Mark Brown

[-- Attachment #1: Type: text/plain, Size: 2487 bytes --]

Hi,

On Tue, Mar 07, 2023 at 06:19:03PM -0600, Rob Herring wrote:
> On Tue, Mar 07, 2023 at 05:53:41PM +0100, Miquel Raynal wrote:
> > This helper does not produce a real modalias, but tries to get the
> > "product" compatible part of the "vendor,product" compatibles only. It
> > is far from creating a purely useful modalias string and does not seem
> > to be used like that directly anyway, so let's try to give this helper a
> > more meaningful name before moving there a real modalias helper (already
> > existing under of/device.c).
> > 
> > Also update the various documentations to refer to the strings as
> > "aliases" rather than "modaliases" which has a real meaning in the Linux
> > kernel.
> > 
> > There is no functional change.
> > 
> > Cc: Rafael J. Wysocki <rafael@kernel.org>
> > Cc: Len Brown <lenb@kernel.org>
> > Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> > Cc: Maxime Ripard <mripard@kernel.org>
> > Cc: Thomas Zimmermann <tzimmermann@suse.de>
> > Cc: Sebastian Reichel <sre@kernel.org>
> > Cc: Wolfram Sang <wsa@kernel.org>
> > Cc: Mark Brown <broonie@kernel.org>
> > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> > ---
> >  drivers/acpi/bus.c                |  7 ++++---
> >  drivers/gpu/drm/drm_mipi_dsi.c    |  2 +-
> >  drivers/hsi/hsi_core.c            |  2 +-
> 
> These should not have been using this function. The matching on just the 
> product was a relic from I2C and SPI which we don't want to propogate. 
> No clue why ACPI needed it...
> 
> If you respin or want to fixup while applying, can you add a kerneldoc 
> comment to not add new users of the function. Not that anyone will 
> follow that... :(
> 
> Reviewed-by: Rob Herring <robh@kernel.org>

I just checked and HSI is not using the data for matching. Instead
it uses the returned data to set the device name. Matching happens
using the full compatible.

FWIW the MIPI HSI standard never became a big thing, so we have only
one HSI DT driver upstream and that is the Nokia N900 modem driver.

Anyways:

Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com> # for HSI

-- Sebastian

> 
> >  drivers/i2c/busses/i2c-powermac.c |  2 +-
> >  drivers/i2c/i2c-core-of.c         |  2 +-
> >  drivers/of/base.c                 | 15 ++++++++-------
> >  drivers/spi/spi.c                 |  4 ++--
> >  include/linux/of.h                |  2 +-
> >  8 files changed, 19 insertions(+), 17 deletions(-)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 03/21] of: Rename of_modalias_node()
  2023-03-08 22:06     ` Sebastian Reichel
@ 2023-03-09 13:28       ` Rob Herring
  0 siblings, 0 replies; 42+ messages in thread
From: Rob Herring @ 2023-03-09 13:28 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Miquel Raynal, Srinivas Kandagatla, linux-kernel,
	Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Frank Rowand,
	devicetree, Rafael J . Wysocki, Len Brown, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, Wolfram Sang, Mark Brown

On Wed, Mar 8, 2023 at 4:06 PM Sebastian Reichel
<sebastian.reichel@collabora.com> wrote:
>
> Hi,
>
> On Tue, Mar 07, 2023 at 06:19:03PM -0600, Rob Herring wrote:
> > On Tue, Mar 07, 2023 at 05:53:41PM +0100, Miquel Raynal wrote:
> > > This helper does not produce a real modalias, but tries to get the
> > > "product" compatible part of the "vendor,product" compatibles only. It
> > > is far from creating a purely useful modalias string and does not seem
> > > to be used like that directly anyway, so let's try to give this helper a
> > > more meaningful name before moving there a real modalias helper (already
> > > existing under of/device.c).
> > >
> > > Also update the various documentations to refer to the strings as
> > > "aliases" rather than "modaliases" which has a real meaning in the Linux
> > > kernel.
> > >
> > > There is no functional change.
> > >
> > > Cc: Rafael J. Wysocki <rafael@kernel.org>
> > > Cc: Len Brown <lenb@kernel.org>
> > > Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> > > Cc: Maxime Ripard <mripard@kernel.org>
> > > Cc: Thomas Zimmermann <tzimmermann@suse.de>
> > > Cc: Sebastian Reichel <sre@kernel.org>
> > > Cc: Wolfram Sang <wsa@kernel.org>
> > > Cc: Mark Brown <broonie@kernel.org>
> > > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> > > ---
> > >  drivers/acpi/bus.c                |  7 ++++---
> > >  drivers/gpu/drm/drm_mipi_dsi.c    |  2 +-
> > >  drivers/hsi/hsi_core.c            |  2 +-
> >
> > These should not have been using this function. The matching on just the
> > product was a relic from I2C and SPI which we don't want to propogate.
> > No clue why ACPI needed it...
> >
> > If you respin or want to fixup while applying, can you add a kerneldoc
> > comment to not add new users of the function. Not that anyone will
> > follow that... :(
> >
> > Reviewed-by: Rob Herring <robh@kernel.org>
>
> I just checked and HSI is not using the data for matching. Instead
> it uses the returned data to set the device name. Matching happens
> using the full compatible.
>
> FWIW the MIPI HSI standard never became a big thing, so we have only
> one HSI DT driver upstream and that is the Nokia N900 modem driver.

Can we add a patch in removing the call then.

I'm pretty sure MIPI stands for Must Invent Peripheral Interfaces.

Rob

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 08/21] dt-bindings: nvmem: Fix spelling mistake "platforn" -> "platform"
  2023-03-07 16:53 ` [PATCH v2 08/21] dt-bindings: nvmem: Fix spelling mistake "platforn" -> "platform" Miquel Raynal
  2023-03-08  0:08   ` Rob Herring
@ 2023-03-10  9:55   ` Srinivas Kandagatla
  1 sibling, 0 replies; 42+ messages in thread
From: Srinivas Kandagatla @ 2023-03-10  9:55 UTC (permalink / raw)
  To: Miquel Raynal, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Colin Ian King



On 07/03/2023 16:53, Miquel Raynal wrote:
> From: Colin Ian King <colin.i.king@gmail.com>
> 
> There is a spelling mistake in platforn-name. Fix it.
> 
> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---

Applied thanks,

--srini
>   .../devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml      | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/Documentation/devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml b/Documentation/devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml
> index 5a0e7671aa3f..714a6538cc7c 100644
> --- a/Documentation/devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml
> +++ b/Documentation/devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml
> @@ -61,7 +61,7 @@ properties:
>       type: object
>       additionalProperties: false
>   
> -  platforn-name:
> +  platform-name:
>       type: object
>       additionalProperties: false
>   

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 09/21] nvmem: core: return -ENOENT if nvmem cell is not found
  2023-03-07 16:53 ` [PATCH v2 09/21] nvmem: core: return -ENOENT if nvmem cell is not found Miquel Raynal
  2023-03-07 17:04   ` Michael Walle
@ 2023-03-10  9:57   ` Srinivas Kandagatla
  2023-03-10 10:00     ` Miquel Raynal
  1 sibling, 1 reply; 42+ messages in thread
From: Srinivas Kandagatla @ 2023-03-10  9:57 UTC (permalink / raw)
  To: Miquel Raynal, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree, Alexander Stein



On 07/03/2023 16:53, Miquel Raynal wrote:
> From: Michael Walle <michael@walle.cc>
> 
> Prior to commit 3cb05fdbaed6 ("nvmem: core: add an index parameter to
> the cell") of_nvmem_cell_get() would return -ENOENT if the cell wasn't
> found. Particularly, if of_property_match_string() returned -EINVAL,
> that return code was passed as the index to of_parse_phandle(), which
> then detected it as invalid and returned NULL. That led to an return
> code of -ENOENT.
> 
> With the new code, the negative index will lead to an -EINVAL of
> of_parse_phandle_with_optional_args() which pass straight to the
> caller and break those who expect an -ENOENT.
> 
> Fix it by always returning -ENOENT.
> 
> Fixes: efff2655ab0f ("nvmem: core: add an index parameter to the cell")
> Reported-by: Alexander Stein <alexander.stein@ew.tq-group.com>
> Signed-off-by: Michael Walle <michael@walle.cc>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---

Already applied.

--srini
>   drivers/nvmem/core.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 174ef3574e07..22024b830788 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -1231,7 +1231,7 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id)
>   						  "#nvmem-cell-cells",
>   						  index, &cell_spec);
>   	if (ret)
> -		return ERR_PTR(ret);
> +		return ERR_PTR(-ENOENT);
>   
>   	if (cell_spec.args_count > 1)
>   		return ERR_PTR(-EINVAL);

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 09/21] nvmem: core: return -ENOENT if nvmem cell is not found
  2023-03-10  9:57   ` Srinivas Kandagatla
@ 2023-03-10 10:00     ` Miquel Raynal
  0 siblings, 0 replies; 42+ messages in thread
From: Miquel Raynal @ 2023-03-10 10:00 UTC (permalink / raw)
  To: Srinivas Kandagatla
  Cc: linux-kernel, Greg Kroah-Hartman, Michael Walle,
	Rafał Miłecki, Robert Marko, Luka Perkov,
	Thomas Petazzoni, Rob Herring, Frank Rowand, devicetree,
	Alexander Stein

Hi Srinivas,

srinivas.kandagatla@linaro.org wrote on Fri, 10 Mar 2023 09:57:54 +0000:

> On 07/03/2023 16:53, Miquel Raynal wrote:
> > From: Michael Walle <michael@walle.cc>
> > 
> > Prior to commit 3cb05fdbaed6 ("nvmem: core: add an index parameter to
> > the cell") of_nvmem_cell_get() would return -ENOENT if the cell wasn't
> > found. Particularly, if of_property_match_string() returned -EINVAL,
> > that return code was passed as the index to of_parse_phandle(), which
> > then detected it as invalid and returned NULL. That led to an return
> > code of -ENOENT.
> > 
> > With the new code, the negative index will lead to an -EINVAL of
> > of_parse_phandle_with_optional_args() which pass straight to the
> > caller and break those who expect an -ENOENT.
> > 
> > Fix it by always returning -ENOENT.
> > 
> > Fixes: efff2655ab0f ("nvmem: core: add an index parameter to the cell")
> > Reported-by: Alexander Stein <alexander.stein@ew.tq-group.com>
> > Signed-off-by: Michael Walle <michael@walle.cc>
> > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> > ---  
> 
> Already applied.

Yes, sorry, Michael spotted it as well, I wasn't based on the right
branch. v3 is udpated on this regard.

Thanks,
Miquèl

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 11/21] nvmem: core: handle the absence of expected layouts
  2023-03-07 16:53 ` [PATCH v2 11/21] nvmem: core: handle the absence of expected layouts Miquel Raynal
@ 2023-03-10 10:30   ` Srinivas Kandagatla
  2023-03-10 10:45     ` Miquel Raynal
  0 siblings, 1 reply; 42+ messages in thread
From: Srinivas Kandagatla @ 2023-03-10 10:30 UTC (permalink / raw)
  To: Miquel Raynal, linux-kernel
  Cc: Greg Kroah-Hartman, Michael Walle, Rafał Miłecki,
	Robert Marko, Luka Perkov, Thomas Petazzoni, Rob Herring,
	Frank Rowand, devicetree



On 07/03/2023 16:53, Miquel Raynal wrote:
> Make nvmem_layout_get() return -EPROBE_DEFER while the expected layout
> is not available. This condition cannot be triggered today as nvmem
> layout drivers are initialed as part of an early init call, but soon
> these drivers will be converted into modules and be initialized with a
> standard priority, so the unavailability of the drivers might become a
> reality that must be taken care of.
> 
> Let's anticipate this by telling the caller the layout might not yet be
> available. A probe deferral is requested in this case.
> 
> Please note this does not affect any nvmem device not using layouts,
> because an early check against the "nvmem-layout" container presence
> will return NULL in this case.
> 
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> Tested-by: Michael Walle <michael@walle.cc>
> ---
>   drivers/nvmem/core.c | 10 +++++++++-
>   1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index b9be1faeb7be..51fd792b8d70 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -755,7 +755,7 @@ EXPORT_SYMBOL_GPL(nvmem_layout_unregister);
>   static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *nvmem)
>   {

Any reason why this is not part of 10/21?

kernel doc for nvmem_layout_get needs updating with this behavior.


--srini

>   	struct device_node *layout_np, *np = nvmem->dev.of_node;
> -	struct nvmem_layout *l, *layout = NULL;
> +	struct nvmem_layout *l, *layout = ERR_PTR(-EPROBE_DEFER);
>   
>   	layout_np = of_get_child_by_name(np, "nvmem-layout");
>   	if (!layout_np)
> @@ -938,6 +938,13 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
>   	 * pointer will be NULL and nvmem_layout_put() will be a noop.
>   	 */
>   	nvmem->layout = config->layout ?: nvmem_layout_get(nvmem);
> +	if (IS_ERR(nvmem->layout)) {
> +		rval = PTR_ERR(nvmem->layout);
> +		nvmem->layout = NULL;
> +
> +		if (rval == -EPROBE_DEFER)
> +			goto err_teardown_compat;
> +	}
>   
>   	if (config->cells) {
>   		rval = nvmem_add_cells(nvmem, config->cells, config->ncells);
> @@ -970,6 +977,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
>   err_remove_cells:
>   	nvmem_device_remove_all_cells(nvmem);
>   	nvmem_layout_put(nvmem->layout);
> +err_teardown_compat:
>   	if (config->compat)
>   		nvmem_sysfs_remove_compat(nvmem, config);
>   err_put_device:

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 11/21] nvmem: core: handle the absence of expected layouts
  2023-03-10 10:30   ` Srinivas Kandagatla
@ 2023-03-10 10:45     ` Miquel Raynal
  2023-03-10 10:49       ` Srinivas Kandagatla
  0 siblings, 1 reply; 42+ messages in thread
From: Miquel Raynal @ 2023-03-10 10:45 UTC (permalink / raw)
  To: Srinivas Kandagatla
  Cc: linux-kernel, Greg Kroah-Hartman, Michael Walle,
	Rafał Miłecki, Robert Marko, Luka Perkov,
	Thomas Petazzoni, Rob Herring, Frank Rowand, devicetree

Hi Srinivas,

srinivas.kandagatla@linaro.org wrote on Fri, 10 Mar 2023 10:30:14 +0000:

> On 07/03/2023 16:53, Miquel Raynal wrote:
> > Make nvmem_layout_get() return -EPROBE_DEFER while the expected layout
> > is not available. This condition cannot be triggered today as nvmem
> > layout drivers are initialed as part of an early init call, but soon
> > these drivers will be converted into modules and be initialized with a
> > standard priority, so the unavailability of the drivers might become a
> > reality that must be taken care of.
> > 
> > Let's anticipate this by telling the caller the layout might not yet be
> > available. A probe deferral is requested in this case.
> > 
> > Please note this does not affect any nvmem device not using layouts,
> > because an early check against the "nvmem-layout" container presence
> > will return NULL in this case.
> > 
> > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> > Tested-by: Michael Walle <michael@walle.cc>
> > ---
> >   drivers/nvmem/core.c | 10 +++++++++-
> >   1 file changed, 9 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> > index b9be1faeb7be..51fd792b8d70 100644
> > --- a/drivers/nvmem/core.c
> > +++ b/drivers/nvmem/core.c
> > @@ -755,7 +755,7 @@ EXPORT_SYMBOL_GPL(nvmem_layout_unregister);
> >   static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *nvmem)
> >   {  
> 
> Any reason why this is not part of 10/21?

Yes, I would like to credit everybody for his work, so Michael for the
base implementation and myself for the module sitaution handling,
arguing this is two different features. May we keep these separated?

> kernel doc for nvmem_layout_get needs updating with this behavior.

There is no kdoc for nvmem_layout_get, do you want one ? I thought the
comment where this function is called would be more descriptive (and
read by interested people).

Thanks,
Miquèl

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 11/21] nvmem: core: handle the absence of expected layouts
  2023-03-10 10:45     ` Miquel Raynal
@ 2023-03-10 10:49       ` Srinivas Kandagatla
  0 siblings, 0 replies; 42+ messages in thread
From: Srinivas Kandagatla @ 2023-03-10 10:49 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: linux-kernel, Greg Kroah-Hartman, Michael Walle,
	Rafał Miłecki, Robert Marko, Luka Perkov,
	Thomas Petazzoni, Rob Herring, Frank Rowand, devicetree



On 10/03/2023 10:45, Miquel Raynal wrote:
> Hi Srinivas,
> 
> srinivas.kandagatla@linaro.org wrote on Fri, 10 Mar 2023 10:30:14 +0000:
> 
>> On 07/03/2023 16:53, Miquel Raynal wrote:
>>> Make nvmem_layout_get() return -EPROBE_DEFER while the expected layout
>>> is not available. This condition cannot be triggered today as nvmem
>>> layout drivers are initialed as part of an early init call, but soon
>>> these drivers will be converted into modules and be initialized with a
>>> standard priority, so the unavailability of the drivers might become a
>>> reality that must be taken care of.
>>>
>>> Let's anticipate this by telling the caller the layout might not yet be
>>> available. A probe deferral is requested in this case.
>>>
>>> Please note this does not affect any nvmem device not using layouts,
>>> because an early check against the "nvmem-layout" container presence
>>> will return NULL in this case.
>>>
>>> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
>>> Tested-by: Michael Walle <michael@walle.cc>
>>> ---
>>>    drivers/nvmem/core.c | 10 +++++++++-
>>>    1 file changed, 9 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
>>> index b9be1faeb7be..51fd792b8d70 100644
>>> --- a/drivers/nvmem/core.c
>>> +++ b/drivers/nvmem/core.c
>>> @@ -755,7 +755,7 @@ EXPORT_SYMBOL_GPL(nvmem_layout_unregister);
>>>    static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *nvmem)
>>>    {
>>
>> Any reason why this is not part of 10/21?
> 
> Yes, I would like to credit everybody for his work, so Michael for the
> base implementation and myself for the module sitaution handling,
> arguing this is two different features. May we keep these separated?

Thanks for clarifying this, that should be fine.

--srini

^ permalink raw reply	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2023-03-10 10:49 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-07 16:53 [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal
2023-03-07 16:53 ` [PATCH v2 01/21] of: Fix modalias string generation Miquel Raynal
2023-03-07 16:53 ` [PATCH v2 02/21] of: Update of_device_get_modalias() Miquel Raynal
2023-03-08  0:28   ` Rob Herring
2023-03-07 16:53 ` [PATCH v2 03/21] of: Rename of_modalias_node() Miquel Raynal
2023-03-08  0:19   ` Rob Herring
2023-03-08 14:17     ` Miquel Raynal
2023-03-08 22:06     ` Sebastian Reichel
2023-03-09 13:28       ` Rob Herring
2023-03-07 16:53 ` [PATCH v2 04/21] of: Move of_modalias() to module.c Miquel Raynal
2023-03-08  0:23   ` Rob Herring
2023-03-08 14:51     ` Miquel Raynal
2023-03-07 16:53 ` [PATCH v2 05/21] of: Move the request module helper logic " Miquel Raynal
2023-03-08  0:25   ` Rob Herring
2023-03-07 16:53 ` [PATCH v2 06/21] usb: ulpi: Use of_request_module() Miquel Raynal
2023-03-08  0:25   ` Rob Herring
2023-03-07 16:53 ` [PATCH v2 07/21] of: device: Kill of_device_request_module() Miquel Raynal
2023-03-08  0:26   ` Rob Herring
2023-03-07 16:53 ` [PATCH v2 08/21] dt-bindings: nvmem: Fix spelling mistake "platforn" -> "platform" Miquel Raynal
2023-03-08  0:08   ` Rob Herring
2023-03-08 14:07     ` Miquel Raynal
2023-03-10  9:55   ` Srinivas Kandagatla
2023-03-07 16:53 ` [PATCH v2 09/21] nvmem: core: return -ENOENT if nvmem cell is not found Miquel Raynal
2023-03-07 17:04   ` Michael Walle
2023-03-10  9:57   ` Srinivas Kandagatla
2023-03-10 10:00     ` Miquel Raynal
2023-03-07 16:53 ` [PATCH v2 10/21] nvmem: core: introduce NVMEM layouts Miquel Raynal
2023-03-07 16:53 ` [PATCH v2 11/21] nvmem: core: handle the absence of expected layouts Miquel Raynal
2023-03-10 10:30   ` Srinivas Kandagatla
2023-03-10 10:45     ` Miquel Raynal
2023-03-10 10:49       ` Srinivas Kandagatla
2023-03-07 16:53 ` [PATCH v2 12/21] nvmem: core: request layout modules loading Miquel Raynal
2023-03-07 16:53 ` [PATCH v2 13/21] nvmem: core: add per-cell post processing Miquel Raynal
2023-03-07 16:53 ` [PATCH v2 14/21] nvmem: core: allow to modify a cell before adding it Miquel Raynal
2023-03-07 16:53 ` [PATCH v2 15/21] nvmem: imx-ocotp: replace global post processing with layouts Miquel Raynal
2023-03-07 16:53 ` [PATCH v2 16/21] nvmem: cell: drop global cell_post_process Miquel Raynal
2023-03-07 16:53 ` [PATCH v2 17/21] nvmem: core: provide own priv pointer in post process callback Miquel Raynal
2023-03-07 16:53 ` [PATCH v2 18/21] nvmem: layouts: sl28vpd: Add new layout driver Miquel Raynal
2023-03-07 16:53 ` [PATCH v2 19/21] MAINTAINERS: add myself as sl28vpd nvmem " Miquel Raynal
2023-03-07 16:53 ` [PATCH v2 20/21] nvmem: layouts: onie-tlv: Add new " Miquel Raynal
2023-03-07 16:53 ` [PATCH v2 21/21] MAINTAINERS: Add myself as ONIE tlv NVMEM layout maintainer Miquel Raynal
2023-03-07 17:09 ` [PATCH v2 00/21] nvmem: Layouts support Miquel Raynal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.