All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/37] nvmem: patches for 6.3
@ 2023-01-27 11:15 Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 01/37] nvmem: sunxi_sid: Drop the workaround on A64 Srinivas Kandagatla
                   ` (37 more replies)
  0 siblings, 38 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Srinivas Kandagatla

Hi Greg,

Here are some nvmem patches bit more than usual for 6.3 which includes

- Adding support for nvmem layouts, thanks to Michael and Miquel for
  driving this effort.
- Add support to stm32 STM32MP15x OPTEE based nvmem provider
- Updated to qfprom bindings to include various Qualcomm SoCs.
- adding sl28vpd provider layout
- move imx provider to use new layout apis
- add ONIE provider layout. 
- new helper eth_addr_add().
- few minor enhancements to core and providersdrivers.

Can you please queue them up for 6.3.

thanks for you help,
srini

MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

AngeloGioacchino Del Regno (1):
  dt-bindings: nvmem: Fix qcom,qfprom compatibles enum ordering

Arnd Bergmann (1):
  nvmem: stm32: fix OPTEE dependency

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

Johan Hovold (1):
  nvmem: qcom-spmi-sdam: register at device init time

Konrad Dybcio (2):
  dt-bindings: nvmem: Add compatible for SM8150
  dt-bindings: nvmem: Add compatible for SM8250

Marijn Suijten (1):
  dt-bindings: nvmem: Add compatible for MSM8976

Michael Walle (19):
  net: add helper eth_addr_add()
  of: base: add of_parse_phandle_with_optional_args()
  of: property: make #.*-cells optional for simple props
  of: property: add #nvmem-cell-cells property
  nvmem: core: add an index parameter to the cell
  nvmem: core: move struct nvmem_cell_info to nvmem-provider.h
  nvmem: core: drop the removal of the cells in nvmem_add_cells()
  nvmem: core: add nvmem_add_one_cell()
  nvmem: core: use nvmem_add_one_cell() in nvmem_add_cells_from_of()
  nvmem: core: introduce NVMEM layouts
  nvmem: core: add per-cell post processing
  nvmem: core: allow to modify a cell before adding it
  nvmem: imx-ocotp: replace global post processing with layouts
  nvmem: cell: drop global cell_post_process
  nvmem: core: provide own priv pointer in post process callback
  nvmem: layouts: add sl28vpd layout
  MAINTAINERS: add myself as sl28vpd nvmem layout driver
  nvmem: core: return -ENOENT if nvmem cell is not found
  of: property: fix #nvmem-cell-cells parsing

Miquel Raynal (2):
  nvmem: layouts: Add ONIE tlv layout driver
  MAINTAINERS: Add myself as ONIE tlv NVMEM layout maintainer

Patrick Delaunay (2):
  nvmem: stm32: add OP-TEE support for STM32MP13x
  nvmem: stm32: detect bsec pta presence for STM32MP15x

Rafał Miłecki (1):
  nvmem: core: fix nvmem_layout_get_match_data()

Randy Dunlap (1):
  nvmem: rave-sp-eeprm: fix kernel-doc bad line warning

Richard Acayan (1):
  dt-bindings: nvmem: qfprom: add sdm670 compatible

Robert Marko (1):
  dt-bindings: nvmem: qfprom: add IPQ8074 compatible

Russell King (Oracle) (1):
  nvmem: core: remove spurious white space

Samuel Holland (1):
  nvmem: sunxi_sid: Drop the workaround on A64

 .../nvmem/layouts/onie,tlv-layout.yaml        |   2 +-
 .../bindings/nvmem/qcom,qfprom.yaml           |   7 +-
 Documentation/driver-api/nvmem.rst            |  15 +
 MAINTAINERS                                   |  12 +
 drivers/nvmem/Kconfig                         |  14 +
 drivers/nvmem/Makefile                        |   2 +
 drivers/nvmem/core.c                          | 283 ++++++++++++-----
 drivers/nvmem/imx-ocotp.c                     |  34 +-
 drivers/nvmem/layouts/Kconfig                 |  23 ++
 drivers/nvmem/layouts/Makefile                |   7 +
 drivers/nvmem/layouts/onie-tlv.c              | 244 ++++++++++++++
 drivers/nvmem/layouts/sl28vpd.c               | 153 +++++++++
 drivers/nvmem/qcom-spmi-sdam.c                |  13 +-
 drivers/nvmem/rave-sp-eeprom.c                |   2 +-
 drivers/nvmem/stm32-bsec-optee-ta.c           | 298 ++++++++++++++++++
 drivers/nvmem/stm32-bsec-optee-ta.h           |  80 +++++
 drivers/nvmem/stm32-romem.c                   |  84 ++++-
 drivers/nvmem/sunxi_sid.c                     |   8 +-
 drivers/of/property.c                         |   6 +-
 include/linux/etherdevice.h                   |  14 +
 include/linux/nvmem-consumer.h                |  17 +-
 include/linux/nvmem-provider.h                |  95 +++++-
 include/linux/of.h                            |  25 ++
 23 files changed, 1310 insertions(+), 128 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/nvmem/stm32-bsec-optee-ta.c
 create mode 100644 drivers/nvmem/stm32-bsec-optee-ta.h

-- 
2.25.1


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

* [PATCH 01/37] nvmem: sunxi_sid: Drop the workaround on A64
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 02/37] dt-bindings: nvmem: Fix qcom,qfprom compatibles enum ordering Srinivas Kandagatla
                   ` (36 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Samuel Holland, Srinivas Kandagatla

From: Samuel Holland <samuel@sholland.org>

Now that the SRAM readout code is fixed by using 32-bit accesses, it
always returns the same values as register readout, so the A64 variant
no longer needs the workaround. This makes the D1 variant structure
redundant, so remove it.

Signed-off-by: Samuel Holland <samuel@sholland.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/sunxi_sid.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/nvmem/sunxi_sid.c b/drivers/nvmem/sunxi_sid.c
index 92dfe4cb10e3..a970f1741cc6 100644
--- a/drivers/nvmem/sunxi_sid.c
+++ b/drivers/nvmem/sunxi_sid.c
@@ -197,15 +197,9 @@ static const struct sunxi_sid_cfg sun8i_h3_cfg = {
 	.need_register_readout = true,
 };
 
-static const struct sunxi_sid_cfg sun20i_d1_cfg = {
-	.value_offset = 0x200,
-	.size = 0x100,
-};
-
 static const struct sunxi_sid_cfg sun50i_a64_cfg = {
 	.value_offset = 0x200,
 	.size = 0x100,
-	.need_register_readout = true,
 };
 
 static const struct sunxi_sid_cfg sun50i_h6_cfg = {
@@ -218,7 +212,7 @@ static const struct of_device_id sunxi_sid_of_match[] = {
 	{ .compatible = "allwinner,sun7i-a20-sid", .data = &sun7i_a20_cfg },
 	{ .compatible = "allwinner,sun8i-a83t-sid", .data = &sun50i_a64_cfg },
 	{ .compatible = "allwinner,sun8i-h3-sid", .data = &sun8i_h3_cfg },
-	{ .compatible = "allwinner,sun20i-d1-sid", .data = &sun20i_d1_cfg },
+	{ .compatible = "allwinner,sun20i-d1-sid", .data = &sun50i_a64_cfg },
 	{ .compatible = "allwinner,sun50i-a64-sid", .data = &sun50i_a64_cfg },
 	{ .compatible = "allwinner,sun50i-h5-sid", .data = &sun50i_a64_cfg },
 	{ .compatible = "allwinner,sun50i-h6-sid", .data = &sun50i_h6_cfg },
-- 
2.25.1


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

* [PATCH 02/37] dt-bindings: nvmem: Fix qcom,qfprom compatibles enum ordering
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 01/37] nvmem: sunxi_sid: Drop the workaround on A64 Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 03/37] dt-bindings: nvmem: Add compatible for MSM8976 Srinivas Kandagatla
                   ` (35 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, AngeloGioacchino Del Regno, Krzysztof Kozlowski,
	Srinivas Kandagatla

From: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>

Move qcom,msm8974-qfprom after qcom,msm8916-qfprom to respect
alphabetical ordering.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
index 8e89b15b535f..cc39514e8c84 100644
--- a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
+++ b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
@@ -19,8 +19,8 @@ properties:
           - qcom,apq8064-qfprom
           - qcom,apq8084-qfprom
           - qcom,ipq8064-qfprom
-          - qcom,msm8974-qfprom
           - qcom,msm8916-qfprom
+          - qcom,msm8974-qfprom
           - qcom,msm8996-qfprom
           - qcom,msm8998-qfprom
           - qcom,qcs404-qfprom
-- 
2.25.1


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

* [PATCH 03/37] dt-bindings: nvmem: Add compatible for MSM8976
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 01/37] nvmem: sunxi_sid: Drop the workaround on A64 Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 02/37] dt-bindings: nvmem: Fix qcom,qfprom compatibles enum ordering Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 04/37] dt-bindings: nvmem: qfprom: add sdm670 compatible Srinivas Kandagatla
                   ` (34 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, Marijn Suijten, AngeloGioacchino Del Regno,
	Krzysztof Kozlowski, Srinivas Kandagatla

From: Marijn Suijten <marijn.suijten@somainline.org>

Document generic QFPROM compatibility on MSM8976.

Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org>
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
index cc39514e8c84..48cfec0c9ece 100644
--- a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
+++ b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
@@ -21,6 +21,7 @@ properties:
           - qcom,ipq8064-qfprom
           - qcom,msm8916-qfprom
           - qcom,msm8974-qfprom
+          - qcom,msm8976-qfprom
           - qcom,msm8996-qfprom
           - qcom,msm8998-qfprom
           - qcom,qcs404-qfprom
-- 
2.25.1


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

* [PATCH 04/37] dt-bindings: nvmem: qfprom: add sdm670 compatible
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (2 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 03/37] dt-bindings: nvmem: Add compatible for MSM8976 Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 23:39   ` Richard Acayan
  2023-01-27 11:15 ` [PATCH 05/37] dt-bindings: nvmem: Add compatible for SM8150 Srinivas Kandagatla
                   ` (33 subsequent siblings)
  37 siblings, 1 reply; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, Richard Acayan, Krzysztof Kozlowski, Srinivas Kandagatla

From: Richard Acayan <mailingradian@gmail.com>

There is some configuration in SDM670's QFPROM. Add the compatible for
it.

Signed-off-by: Richard Acayan <mailingradian@gmail.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
index 48cfec0c9ece..b7811bbb0e71 100644
--- a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
+++ b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
@@ -28,6 +28,7 @@ properties:
           - qcom,sc7180-qfprom
           - qcom,sc7280-qfprom
           - qcom,sdm630-qfprom
+          - qcom,sdm670-qfprom
           - qcom,sdm845-qfprom
           - qcom,sm6115-qfprom
       - const: qcom,qfprom
-- 
2.25.1


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

* [PATCH 05/37] dt-bindings: nvmem: Add compatible for SM8150
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (3 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 04/37] dt-bindings: nvmem: qfprom: add sdm670 compatible Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 06/37] dt-bindings: nvmem: Add compatible for SM8250 Srinivas Kandagatla
                   ` (32 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, Konrad Dybcio, Krzysztof Kozlowski, Srinivas Kandagatla

From: Konrad Dybcio <konrad.dybcio@linaro.org>

Docuemnt the QFPROM on SM8150.

Signed-off-by: Konrad Dybcio <konrad.dybcio@linaro.org>
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
index b7811bbb0e71..a248033026b1 100644
--- a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
+++ b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
@@ -31,6 +31,7 @@ properties:
           - qcom,sdm670-qfprom
           - qcom,sdm845-qfprom
           - qcom,sm6115-qfprom
+          - qcom,sm8150-qfprom
       - const: qcom,qfprom
 
   reg:
-- 
2.25.1


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

* [PATCH 06/37] dt-bindings: nvmem: Add compatible for SM8250
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (4 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 05/37] dt-bindings: nvmem: Add compatible for SM8150 Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 07/37] nvmem: core: remove spurious white space Srinivas Kandagatla
                   ` (31 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, Konrad Dybcio, Krzysztof Kozlowski, Srinivas Kandagatla

From: Konrad Dybcio <konrad.dybcio@linaro.org>

Docuemnt the QFPROM on SM8250.

Signed-off-by: Konrad Dybcio <konrad.dybcio@linaro.org>
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
index a248033026b1..9ddf3cef9e84 100644
--- a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
+++ b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
@@ -32,6 +32,7 @@ properties:
           - qcom,sdm845-qfprom
           - qcom,sm6115-qfprom
           - qcom,sm8150-qfprom
+          - qcom,sm8250-qfprom
       - const: qcom,qfprom
 
   reg:
-- 
2.25.1


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

* [PATCH 07/37] nvmem: core: remove spurious white space
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (5 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 06/37] dt-bindings: nvmem: Add compatible for SM8250 Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 08/37] net: add helper eth_addr_add() Srinivas Kandagatla
                   ` (30 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Russell King (Oracle), Srinivas Kandagatla

From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>

Remove a spurious white space in for the ida_alloc() call.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 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 34ee9d36ee7b..233c6c275031 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -764,7 +764,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 	if (!nvmem)
 		return ERR_PTR(-ENOMEM);
 
-	rval  = ida_alloc(&nvmem_ida, GFP_KERNEL);
+	rval = ida_alloc(&nvmem_ida, GFP_KERNEL);
 	if (rval < 0) {
 		kfree(nvmem);
 		return ERR_PTR(rval);
-- 
2.25.1


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

* [PATCH 08/37] net: add helper eth_addr_add()
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (6 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 07/37] nvmem: core: remove spurious white space Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 09/37] of: base: add of_parse_phandle_with_optional_args() Srinivas Kandagatla
                   ` (29 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, Michael Walle, Andrew Lunn, Jakub Kicinski,
	Srinivas Kandagatla

From: Michael Walle <michael@walle.cc>

Add a helper to add an offset to a ethernet address. This comes in handy
if you have a base ethernet address for multiple interfaces.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 include/linux/etherdevice.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
index a541f0c4f146..224645f17c33 100644
--- a/include/linux/etherdevice.h
+++ b/include/linux/etherdevice.h
@@ -507,6 +507,20 @@ static inline void eth_addr_inc(u8 *addr)
 	u64_to_ether_addr(u, addr);
 }
 
+/**
+ * eth_addr_add() - Add (or subtract) an offset to/from the given MAC address.
+ *
+ * @offset: Offset to add.
+ * @addr: Pointer to a six-byte array containing Ethernet address to increment.
+ */
+static inline void eth_addr_add(u8 *addr, long offset)
+{
+	u64 u = ether_addr_to_u64(addr);
+
+	u += offset;
+	u64_to_ether_addr(u, addr);
+}
+
 /**
  * is_etherdev_addr - Tell if given Ethernet address belongs to the device.
  * @dev: Pointer to a device structure
-- 
2.25.1


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

* [PATCH 09/37] of: base: add of_parse_phandle_with_optional_args()
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (7 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 08/37] net: add helper eth_addr_add() Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 10/37] of: property: make #.*-cells optional for simple props Srinivas Kandagatla
                   ` (28 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Michael Walle, Rob Herring, Srinivas Kandagatla

From: Michael Walle <michael@walle.cc>

Add a new variant of the of_parse_phandle_with_args() which treats the
cells name as optional. If it's missing, it is assumed that the phandle
has no arguments.

Up until now, a nvmem node didn't have any arguments, so all the device
trees haven't any '#*-cells' property. But there is a need for an
additional argument for the phandle, for which we need a '#*-cells'
property. Therefore, we need to support nvmem nodes with and without
this property.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 include/linux/of.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/include/linux/of.h b/include/linux/of.h
index 8b9f94386dc3..98c252d2d851 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -1008,6 +1008,31 @@ static inline int of_parse_phandle_with_fixed_args(const struct device_node *np,
 					    index, out_args);
 }
 
+/**
+ * of_parse_phandle_with_optional_args() - Find a node pointed by phandle in a list
+ * @np:		pointer to a device tree node containing a list
+ * @list_name:	property name that contains a list
+ * @cells_name:	property name that specifies phandles' arguments count
+ * @index:	index of a phandle to parse out
+ * @out_args:	optional pointer to output arguments structure (will be filled)
+ *
+ * Same as of_parse_phandle_with_args() except that if the cells_name property
+ * is not found, cell_count of 0 is assumed.
+ *
+ * This is used to useful, if you have a phandle which didn't have arguments
+ * before and thus doesn't have a '#*-cells' property but is now migrated to
+ * having arguments while retaining backwards compatibility.
+ */
+static inline int of_parse_phandle_with_optional_args(const struct device_node *np,
+						      const char *list_name,
+						      const char *cells_name,
+						      int index,
+						      struct of_phandle_args *out_args)
+{
+	return __of_parse_phandle_with_args(np, list_name, cells_name,
+					    0, index, out_args);
+}
+
 /**
  * of_property_count_u8_elems - Count the number of u8 elements in a property
  *
-- 
2.25.1


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

* [PATCH 10/37] of: property: make #.*-cells optional for simple props
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (8 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 09/37] of: base: add of_parse_phandle_with_optional_args() Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 11/37] of: property: add #nvmem-cell-cells property Srinivas Kandagatla
                   ` (27 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, Michael Walle, Miquel Raynal, Rob Herring,
	Srinivas Kandagatla

From: Michael Walle <michael@walle.cc>

Sometimes, future bindings for phandles will get additional arguments.
Thus the target node of the phandle will need a new #.*-cells property.
To be backwards compatible, this needs to be optional.

Prepare the DEFINE_SIMPLE_PROPS() to handle the cells name as optional.

Signed-off-by: Michael Walle <michael@walle.cc>
Tested-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/of/property.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/of/property.c b/drivers/of/property.c
index 134cfc980b70..3043ca7735db 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -1256,8 +1256,8 @@ static struct device_node *parse_suffix_prop_cells(struct device_node *np,
 	if (strcmp_suffix(prop_name, suffix))
 		return NULL;
 
-	if (of_parse_phandle_with_args(np, prop_name, cells_name, index,
-				       &sup_args))
+	if (__of_parse_phandle_with_args(np, prop_name, cells_name, 0, index,
+					 &sup_args))
 		return NULL;
 
 	return sup_args.np;
-- 
2.25.1


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

* [PATCH 11/37] of: property: add #nvmem-cell-cells property
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (9 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 10/37] of: property: make #.*-cells optional for simple props Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 12/37] nvmem: core: add an index parameter to the cell Srinivas Kandagatla
                   ` (26 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, Michael Walle, Miquel Raynal, Rob Herring,
	Srinivas Kandagatla

From: Michael Walle <michael@walle.cc>

Bindings describe the new '#nvmem-cell-cells' property. Now that the
arguments count property is optional, we just add this property to the
nvmem-cells.

Signed-off-by: Michael Walle <michael@walle.cc>
Tested-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/of/property.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/of/property.c b/drivers/of/property.c
index 3043ca7735db..8d9ba20a8f90 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -1307,7 +1307,7 @@ DEFINE_SIMPLE_PROP(dmas, "dmas", "#dma-cells")
 DEFINE_SIMPLE_PROP(power_domains, "power-domains", "#power-domain-cells")
 DEFINE_SIMPLE_PROP(hwlocks, "hwlocks", "#hwlock-cells")
 DEFINE_SIMPLE_PROP(extcon, "extcon", NULL)
-DEFINE_SIMPLE_PROP(nvmem_cells, "nvmem-cells", NULL)
+DEFINE_SIMPLE_PROP(nvmem_cells, "nvmem-cells", "#nvmem-cell-cells")
 DEFINE_SIMPLE_PROP(phys, "phys", "#phy-cells")
 DEFINE_SIMPLE_PROP(wakeup_parent, "wakeup-parent", NULL)
 DEFINE_SIMPLE_PROP(pinctrl0, "pinctrl-0", NULL)
-- 
2.25.1


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

* [PATCH 12/37] nvmem: core: add an index parameter to the cell
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (10 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 11/37] of: property: add #nvmem-cell-cells property Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 13/37] nvmem: core: move struct nvmem_cell_info to nvmem-provider.h Srinivas Kandagatla
                   ` (25 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Michael Walle, Srinivas Kandagatla

From: Michael Walle <michael@walle.cc>

Sometimes a cell can represend multiple values. For example, a base
ethernet address stored in the NVMEM can be expanded into multiple
discreet ones by adding an offset.

For this use case, introduce an index parameter which is then used to
distiguish between values. This parameter will then be passed to the
post process hook which can then use it to create different values
during reading.

At the moment, there is only support for the device tree path. You can
add the index to the phandle, e.g.

  &net {
          nvmem-cells = <&base_mac_address 2>;
          nvmem-cell-names = "mac-address";
  };

  &nvmem_provider {
          base_mac_address: base-mac-address@0 {
                  #nvmem-cell-cells = <1>;
                  reg = <0 6>;
          };
  };

Signed-off-by: Michael Walle <michael@walle.cc>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/core.c           | 37 ++++++++++++++++++++++++----------
 drivers/nvmem/imx-ocotp.c      |  4 ++--
 include/linux/nvmem-provider.h |  4 ++--
 3 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 233c6c275031..30567dd51fba 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -60,6 +60,7 @@ struct nvmem_cell_entry {
 struct nvmem_cell {
 	struct nvmem_cell_entry *entry;
 	const char		*id;
+	int			index;
 };
 
 static DEFINE_MUTEX(nvmem_mutex);
@@ -1122,7 +1123,8 @@ struct nvmem_device *devm_nvmem_device_get(struct device *dev, const char *id)
 }
 EXPORT_SYMBOL_GPL(devm_nvmem_device_get);
 
-static struct nvmem_cell *nvmem_create_cell(struct nvmem_cell_entry *entry, const char *id)
+static struct nvmem_cell *nvmem_create_cell(struct nvmem_cell_entry *entry,
+					    const char *id, int index)
 {
 	struct nvmem_cell *cell;
 	const char *name = NULL;
@@ -1141,6 +1143,7 @@ static struct nvmem_cell *nvmem_create_cell(struct nvmem_cell_entry *entry, cons
 
 	cell->id = name;
 	cell->entry = entry;
+	cell->index = index;
 
 	return cell;
 }
@@ -1179,7 +1182,7 @@ nvmem_cell_get_from_lookup(struct device *dev, const char *con_id)
 				__nvmem_device_put(nvmem);
 				cell = ERR_PTR(-ENOENT);
 			} else {
-				cell = nvmem_create_cell(cell_entry, con_id);
+				cell = nvmem_create_cell(cell_entry, con_id, 0);
 				if (IS_ERR(cell))
 					__nvmem_device_put(nvmem);
 			}
@@ -1227,15 +1230,27 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id)
 	struct nvmem_device *nvmem;
 	struct nvmem_cell_entry *cell_entry;
 	struct nvmem_cell *cell;
+	struct of_phandle_args cell_spec;
 	int index = 0;
+	int cell_index = 0;
+	int ret;
 
 	/* if cell name exists, find index to the name */
 	if (id)
 		index = of_property_match_string(np, "nvmem-cell-names", id);
 
-	cell_np = of_parse_phandle(np, "nvmem-cells", index);
-	if (!cell_np)
-		return ERR_PTR(-ENOENT);
+	ret = of_parse_phandle_with_optional_args(np, "nvmem-cells",
+						  "#nvmem-cell-cells",
+						  index, &cell_spec);
+	if (ret)
+		return ERR_PTR(ret);
+
+	if (cell_spec.args_count > 1)
+		return ERR_PTR(-EINVAL);
+
+	cell_np = cell_spec.np;
+	if (cell_spec.args_count)
+		cell_index = cell_spec.args[0];
 
 	nvmem_np = of_get_parent(cell_np);
 	if (!nvmem_np) {
@@ -1257,7 +1272,7 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id)
 		return ERR_PTR(-ENOENT);
 	}
 
-	cell = nvmem_create_cell(cell_entry, id);
+	cell = nvmem_create_cell(cell_entry, id, cell_index);
 	if (IS_ERR(cell))
 		__nvmem_device_put(nvmem);
 
@@ -1410,8 +1425,8 @@ static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void
 }
 
 static int __nvmem_cell_read(struct nvmem_device *nvmem,
-		      struct nvmem_cell_entry *cell,
-		      void *buf, size_t *len, const char *id)
+			     struct nvmem_cell_entry *cell,
+			     void *buf, size_t *len, const char *id, int index)
 {
 	int rc;
 
@@ -1425,7 +1440,7 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem,
 		nvmem_shift_read_buffer_in_place(cell, buf);
 
 	if (nvmem->cell_post_process) {
-		rc = nvmem->cell_post_process(nvmem->priv, id,
+		rc = nvmem->cell_post_process(nvmem->priv, id, index,
 					      cell->offset, buf, cell->bytes);
 		if (rc)
 			return rc;
@@ -1460,7 +1475,7 @@ void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
 	if (!buf)
 		return ERR_PTR(-ENOMEM);
 
-	rc = __nvmem_cell_read(nvmem, cell->entry, buf, len, cell->id);
+	rc = __nvmem_cell_read(nvmem, cell->entry, buf, len, cell->id, cell->index);
 	if (rc) {
 		kfree(buf);
 		return ERR_PTR(rc);
@@ -1773,7 +1788,7 @@ ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
 	if (rc)
 		return rc;
 
-	rc = __nvmem_cell_read(nvmem, &cell, buf, &len, NULL);
+	rc = __nvmem_cell_read(nvmem, &cell, buf, &len, NULL, 0);
 	if (rc)
 		return rc;
 
diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c
index 14284e866f26..e9b52ecb3f72 100644
--- a/drivers/nvmem/imx-ocotp.c
+++ b/drivers/nvmem/imx-ocotp.c
@@ -222,8 +222,8 @@ static int imx_ocotp_read(void *context, unsigned int offset,
 	return ret;
 }
 
-static int imx_ocotp_cell_pp(void *context, const char *id, unsigned int offset,
-			     void *data, size_t bytes)
+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;
 
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index bb15c9234e21..55181d837969 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -20,8 +20,8 @@ typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset,
 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, unsigned int offset,
-					  void *buf, size_t bytes);
+typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, int index,
+					 unsigned int offset, void *buf, size_t bytes);
 
 enum nvmem_type {
 	NVMEM_TYPE_UNKNOWN = 0,
-- 
2.25.1


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

* [PATCH 13/37] nvmem: core: move struct nvmem_cell_info to nvmem-provider.h
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (11 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 12/37] nvmem: core: add an index parameter to the cell Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 14/37] nvmem: core: drop the removal of the cells in nvmem_add_cells() Srinivas Kandagatla
                   ` (24 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Michael Walle, Srinivas Kandagatla

From: Michael Walle <michael@walle.cc>

struct nvmem_cell_info is used to describe a cell. Thus this should
really be in the nvmem-provider's header. There are two (unused) nvmem
access methods which use the nvmem_cell_info to describe the cell to be
accesses. One can argue, that they will create a cell before accessing,
thus they are both a provider and a consumer.

struct nvmem_cell_info will get used more and more by nvmem-providers,
don't force them to also include the consumer header, although they are
not.

Signed-off-by: Michael Walle <michael@walle.cc>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 include/linux/nvmem-consumer.h | 10 +---------
 include/linux/nvmem-provider.h | 19 ++++++++++++++++++-
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h
index 980f9c9ac0bc..1f62f7ba71ca 100644
--- a/include/linux/nvmem-consumer.h
+++ b/include/linux/nvmem-consumer.h
@@ -18,15 +18,7 @@ struct device_node;
 /* consumer cookie */
 struct nvmem_cell;
 struct nvmem_device;
-
-struct nvmem_cell_info {
-	const char		*name;
-	unsigned int		offset;
-	unsigned int		bytes;
-	unsigned int		bit_offset;
-	unsigned int		nbits;
-	struct device_node	*np;
-};
+struct nvmem_cell_info;
 
 /**
  * struct nvmem_cell_lookup - cell lookup entry
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index 55181d837969..a953a3a59535 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -14,7 +14,6 @@
 #include <linux/gpio/consumer.h>
 
 struct nvmem_device;
-struct nvmem_cell_info;
 typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset,
 				void *val, size_t bytes);
 typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset,
@@ -47,6 +46,24 @@ struct nvmem_keepout {
 	unsigned char value;
 };
 
+/**
+ * struct nvmem_cell_info - NVMEM cell description
+ * @name:	Name.
+ * @offset:	Offset within the NVMEM device.
+ * @bytes:	Length of the cell.
+ * @bit_offset:	Bit offset if cell is smaller than a byte.
+ * @nbits:	Number of bits.
+ * @np:		Optional device_node pointer.
+ */
+struct nvmem_cell_info {
+	const char		*name;
+	unsigned int		offset;
+	unsigned int		bytes;
+	unsigned int		bit_offset;
+	unsigned int		nbits;
+	struct device_node	*np;
+};
+
 /**
  * struct nvmem_config - NVMEM device configuration
  *
-- 
2.25.1


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

* [PATCH 14/37] nvmem: core: drop the removal of the cells in nvmem_add_cells()
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (12 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 13/37] nvmem: core: move struct nvmem_cell_info to nvmem-provider.h Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 15/37] nvmem: core: add nvmem_add_one_cell() Srinivas Kandagatla
                   ` (23 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Michael Walle, Srinivas Kandagatla

From: Michael Walle <michael@walle.cc>

If nvmem_add_cells() fails, the whole nvmem_register() will fail
and the cells will then be removed anyway. This is a preparation
to introduce a nvmem_add_one_cell() which can then be used by
nvmem_add_cells().

This is then the same to what nvmem_add_cells_from_table() and
nvmem_add_cells_from_of() do.

Signed-off-by: Michael Walle <michael@walle.cc>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/core.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 30567dd51fba..98ae70695f36 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -515,7 +515,7 @@ static int nvmem_add_cells(struct nvmem_device *nvmem,
 		    int ncells)
 {
 	struct nvmem_cell_entry **cells;
-	int i, rval;
+	int i, rval = 0;
 
 	cells = kcalloc(ncells, sizeof(*cells), GFP_KERNEL);
 	if (!cells)
@@ -525,28 +525,22 @@ static int nvmem_add_cells(struct nvmem_device *nvmem,
 		cells[i] = kzalloc(sizeof(**cells), GFP_KERNEL);
 		if (!cells[i]) {
 			rval = -ENOMEM;
-			goto err;
+			goto out;
 		}
 
 		rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, &info[i], cells[i]);
 		if (rval) {
 			kfree(cells[i]);
-			goto err;
+			goto out;
 		}
 
 		nvmem_cell_entry_add(cells[i]);
 	}
 
+out:
 	/* remove tmp array */
 	kfree(cells);
 
-	return 0;
-err:
-	while (i--)
-		nvmem_cell_entry_drop(cells[i]);
-
-	kfree(cells);
-
 	return rval;
 }
 
-- 
2.25.1


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

* [PATCH 15/37] nvmem: core: add nvmem_add_one_cell()
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (13 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 14/37] nvmem: core: drop the removal of the cells in nvmem_add_cells() Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 16/37] nvmem: core: use nvmem_add_one_cell() in nvmem_add_cells_from_of() Srinivas Kandagatla
                   ` (22 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Michael Walle, Srinivas Kandagatla

From: Michael Walle <michael@walle.cc>

Add a new function to add exactly one cell. This will be used by the
nvmem layout drivers to add custom cells. In contrast to the
nvmem_add_cells(), this has the advantage that we don't have to assemble
a list of cells on runtime.

Signed-off-by: Michael Walle <michael@walle.cc>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/core.c           | 59 ++++++++++++++++++++--------------
 include/linux/nvmem-provider.h |  8 +++++
 2 files changed, 43 insertions(+), 24 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 98ae70695f36..58f8e33e7a8c 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -501,6 +501,36 @@ static int nvmem_cell_info_to_nvmem_cell_entry(struct nvmem_device *nvmem,
 	return 0;
 }
 
+/**
+ * nvmem_add_one_cell() - Add one cell information to an nvmem device
+ *
+ * @nvmem: nvmem device to add cells to.
+ * @info: nvmem cell info to add to the device
+ *
+ * Return: 0 or negative error code on failure.
+ */
+int nvmem_add_one_cell(struct nvmem_device *nvmem,
+		       const struct nvmem_cell_info *info)
+{
+	struct nvmem_cell_entry *cell;
+	int rval;
+
+	cell = kzalloc(sizeof(*cell), GFP_KERNEL);
+	if (!cell)
+		return -ENOMEM;
+
+	rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, info, cell);
+	if (rval) {
+		kfree(cell);
+		return rval;
+	}
+
+	nvmem_cell_entry_add(cell);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(nvmem_add_one_cell);
+
 /**
  * nvmem_add_cells() - Add cell information to an nvmem device
  *
@@ -514,34 +544,15 @@ static int nvmem_add_cells(struct nvmem_device *nvmem,
 		    const struct nvmem_cell_info *info,
 		    int ncells)
 {
-	struct nvmem_cell_entry **cells;
-	int i, rval = 0;
-
-	cells = kcalloc(ncells, sizeof(*cells), GFP_KERNEL);
-	if (!cells)
-		return -ENOMEM;
+	int i, rval;
 
 	for (i = 0; i < ncells; i++) {
-		cells[i] = kzalloc(sizeof(**cells), GFP_KERNEL);
-		if (!cells[i]) {
-			rval = -ENOMEM;
-			goto out;
-		}
-
-		rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, &info[i], cells[i]);
-		if (rval) {
-			kfree(cells[i]);
-			goto out;
-		}
-
-		nvmem_cell_entry_add(cells[i]);
+		rval = nvmem_add_one_cell(nvmem, &info[i]);
+		if (rval)
+			return rval;
 	}
 
-out:
-	/* remove tmp array */
-	kfree(cells);
-
-	return rval;
+	return 0;
 }
 
 /**
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index a953a3a59535..0262b86194eb 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -153,6 +153,9 @@ struct nvmem_device *devm_nvmem_register(struct device *dev,
 void nvmem_add_cell_table(struct nvmem_cell_table *table);
 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);
+
 #else
 
 static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c)
@@ -170,6 +173,11 @@ devm_nvmem_register(struct device *dev, const struct nvmem_config *c)
 
 static inline void nvmem_add_cell_table(struct nvmem_cell_table *table) {}
 static inline void nvmem_del_cell_table(struct nvmem_cell_table *table) {}
+static inline int nvmem_add_one_cell(struct nvmem_device *nvmem,
+				     const struct nvmem_cell_info *info)
+{
+	return -EOPNOTSUPP;
+}
 
 #endif /* CONFIG_NVMEM */
 #endif  /* ifndef _LINUX_NVMEM_PROVIDER_H */
-- 
2.25.1


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

* [PATCH 16/37] nvmem: core: use nvmem_add_one_cell() in nvmem_add_cells_from_of()
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (14 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 15/37] nvmem: core: add nvmem_add_one_cell() Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 17/37] nvmem: core: introduce NVMEM layouts Srinivas Kandagatla
                   ` (21 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Michael Walle, Srinivas Kandagatla

From: Michael Walle <michael@walle.cc>

Convert nvmem_add_cells_from_of() to use the new nvmem_add_one_cell().
This will remove duplicate code and it will make it possible to add a
hook to a nvmem layout in between, which can change fields before the
cell is finally added.

Signed-off-by: Michael Walle <michael@walle.cc>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/core.c | 45 ++++++++++++++------------------------------
 1 file changed, 14 insertions(+), 31 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 58f8e33e7a8c..174ef3574e07 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -688,15 +688,14 @@ static int nvmem_validate_keepouts(struct nvmem_device *nvmem)
 
 static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
 {
-	struct device_node *parent, *child;
 	struct device *dev = &nvmem->dev;
-	struct nvmem_cell_entry *cell;
+	struct device_node *child;
 	const __be32 *addr;
-	int len;
+	int len, ret;
 
-	parent = dev->of_node;
+	for_each_child_of_node(dev->of_node, child) {
+		struct nvmem_cell_info info = {0};
 
-	for_each_child_of_node(parent, child) {
 		addr = of_get_property(child, "reg", &len);
 		if (!addr)
 			continue;
@@ -706,40 +705,24 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
 			return -EINVAL;
 		}
 
-		cell = kzalloc(sizeof(*cell), GFP_KERNEL);
-		if (!cell) {
-			of_node_put(child);
-			return -ENOMEM;
-		}
-
-		cell->nvmem = nvmem;
-		cell->offset = be32_to_cpup(addr++);
-		cell->bytes = be32_to_cpup(addr);
-		cell->name = kasprintf(GFP_KERNEL, "%pOFn", child);
+		info.offset = be32_to_cpup(addr++);
+		info.bytes = be32_to_cpup(addr);
+		info.name = kasprintf(GFP_KERNEL, "%pOFn", child);
 
 		addr = of_get_property(child, "bits", &len);
 		if (addr && len == (2 * sizeof(u32))) {
-			cell->bit_offset = be32_to_cpup(addr++);
-			cell->nbits = be32_to_cpup(addr);
+			info.bit_offset = be32_to_cpup(addr++);
+			info.nbits = be32_to_cpup(addr);
 		}
 
-		if (cell->nbits)
-			cell->bytes = DIV_ROUND_UP(
-					cell->nbits + cell->bit_offset,
-					BITS_PER_BYTE);
+		info.np = of_node_get(child);
 
-		if (!IS_ALIGNED(cell->offset, nvmem->stride)) {
-			dev_err(dev, "cell %s unaligned to nvmem stride %d\n",
-				cell->name, nvmem->stride);
-			/* Cells already added will be freed later. */
-			kfree_const(cell->name);
-			kfree(cell);
+		ret = nvmem_add_one_cell(nvmem, &info);
+		kfree(info.name);
+		if (ret) {
 			of_node_put(child);
-			return -EINVAL;
+			return ret;
 		}
-
-		cell->np = of_node_get(child);
-		nvmem_cell_entry_add(cell);
 	}
 
 	return 0;
-- 
2.25.1


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

* [PATCH 17/37] nvmem: core: introduce NVMEM layouts
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (15 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 16/37] nvmem: core: use nvmem_add_one_cell() in nvmem_add_cells_from_of() Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 18/37] nvmem: core: add per-cell post processing Srinivas Kandagatla
                   ` (20 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Michael Walle, Miquel Raynal, Srinivas Kandagatla

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>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 Documentation/driver-api/nvmem.rst |  15 ++++
 drivers/nvmem/Kconfig              |   4 +
 drivers/nvmem/Makefile             |   1 +
 drivers/nvmem/core.c               | 118 +++++++++++++++++++++++++++++
 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, 205 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 755f551426b5..0e10b5b094b9 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 fa80fe17e567..4cf87ef6c24d 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 174ef3574e07..d2c427c5ebc6 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,99 @@ 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)
+{
+	const struct of_device_id *match;
+
+	match = of_match_node(layout->of_match_table, nvmem->dev.of_node);
+
+	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 +931,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)
@@ -848,6 +951,10 @@ 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;
+
 	dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name);
 
 	rval = device_add(&nvmem->dev);
@@ -862,6 +969,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 	nvmem_device_remove_all_cells(nvmem);
 	if (config->compat)
 		nvmem_sysfs_remove_compat(nvmem, config);
+	nvmem_layout_put(nvmem->layout);
 err_put_device:
 	put_device(&nvmem->dev);
 
@@ -881,6 +989,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 +1355,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.25.1


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

* [PATCH 18/37] nvmem: core: add per-cell post processing
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (16 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 17/37] nvmem: core: introduce NVMEM layouts Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 19/37] nvmem: core: allow to modify a cell before adding it Srinivas Kandagatla
                   ` (19 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Michael Walle, Srinivas Kandagatla

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: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 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 d2c427c5ebc6..80051726b064 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -53,6 +53,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;
@@ -469,6 +470,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;
@@ -1545,6 +1547,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);
@@ -1653,6 +1662,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.25.1


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

* [PATCH 19/37] nvmem: core: allow to modify a cell before adding it
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (17 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 18/37] nvmem: core: add per-cell post processing Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 20/37] nvmem: imx-ocotp: replace global post processing with layouts Srinivas Kandagatla
                   ` (18 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Michael Walle, Srinivas Kandagatla

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: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 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 80051726b064..216a8eb01d00 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -694,6 +694,7 @@ static int nvmem_validate_keepouts(struct nvmem_device *nvmem)
 
 static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
 {
+	struct nvmem_layout *layout = nvmem->layout;
 	struct device *dev = &nvmem->dev;
 	struct device_node *child;
 	const __be32 *addr;
@@ -723,6 +724,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.25.1


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

* [PATCH 20/37] nvmem: imx-ocotp: replace global post processing with layouts
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (18 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 19/37] nvmem: core: allow to modify a cell before adding it Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 21/37] nvmem: cell: drop global cell_post_process Srinivas Kandagatla
                   ` (17 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Michael Walle, Srinivas Kandagatla

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: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 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.25.1


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

* [PATCH 21/37] nvmem: cell: drop global cell_post_process
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (19 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 20/37] nvmem: imx-ocotp: replace global post processing with layouts Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 22/37] nvmem: core: provide own priv pointer in post process callback Srinivas Kandagatla
                   ` (16 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Michael Walle, Srinivas Kandagatla

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: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 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 216a8eb01d00..ae59d9cb901c 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -38,7 +38,6 @@ struct nvmem_device {
 	unsigned int		nkeepout;
 	nvmem_reg_read_t	reg_read;
 	nvmem_reg_write_t	reg_write;
-	nvmem_cell_post_process_t cell_post_process;
 	struct gpio_desc	*wp_gpio;
 	struct nvmem_layout	*layout;
 	void *priv;
@@ -893,7 +892,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)
@@ -1558,13 +1556,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.25.1


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

* [PATCH 22/37] nvmem: core: provide own priv pointer in post process callback
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (20 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 21/37] nvmem: cell: drop global cell_post_process Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 23/37] nvmem: layouts: add sl28vpd layout Srinivas Kandagatla
                   ` (15 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Michael Walle, Srinivas Kandagatla

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: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 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 ae59d9cb901c..81ad6a4c4f86 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -53,6 +53,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;
@@ -470,6 +471,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;
@@ -1550,7 +1552,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.25.1


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

* [PATCH 23/37] nvmem: layouts: add sl28vpd layout
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (21 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 22/37] nvmem: core: provide own priv pointer in post process callback Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 24/37] MAINTAINERS: add myself as sl28vpd nvmem layout driver Srinivas Kandagatla
                   ` (14 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Michael Walle, Srinivas Kandagatla

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: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/layouts/Kconfig   |   9 ++
 drivers/nvmem/layouts/Makefile  |   2 +
 drivers/nvmem/layouts/sl28vpd.c | 153 ++++++++++++++++++++++++++++++++
 3 files changed, 164 insertions(+)
 create mode 100644 drivers/nvmem/layouts/sl28vpd.c

diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig
index 9ad3911d1605..75082f6b471d 100644
--- a/drivers/nvmem/layouts/Kconfig
+++ b/drivers/nvmem/layouts/Kconfig
@@ -2,4 +2,13 @@
 
 menu "Layout Types"
 
+config NVMEM_LAYOUT_SL28_VPD
+	bool "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..a36800f201a3
--- /dev/null
+++ b/drivers/nvmem/layouts/sl28vpd.c
@@ -0,0 +1,153 @@
+// 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" },
+	{},
+};
+
+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);
+}
+subsys_initcall(sl28vpd_init);
-- 
2.25.1


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

* [PATCH 24/37] MAINTAINERS: add myself as sl28vpd nvmem layout driver
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (22 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 23/37] nvmem: layouts: add sl28vpd layout Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 25/37] nvmem: layouts: Add ONIE tlv " Srinivas Kandagatla
                   ` (13 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Michael Walle, Srinivas Kandagatla

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: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 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.25.1


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

* [PATCH 25/37] nvmem: layouts: Add ONIE tlv layout driver
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (23 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 24/37] MAINTAINERS: add myself as sl28vpd nvmem layout driver Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 26/37] MAINTAINERS: Add myself as ONIE tlv NVMEM layout maintainer Srinivas Kandagatla
                   ` (12 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Miquel Raynal, Srinivas Kandagatla

From: Miquel Raynal <miquel.raynal@bootlin.com>

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>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/layouts/Kconfig    |   9 ++
 drivers/nvmem/layouts/Makefile   |   1 +
 drivers/nvmem/layouts/onie-tlv.c | 244 +++++++++++++++++++++++++++++++
 3 files changed, 254 insertions(+)
 create mode 100644 drivers/nvmem/layouts/onie-tlv.c

diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig
index 75082f6b471d..9ad50474cb77 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
+	bool "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..074c7c700845
--- /dev/null
+++ b/drivers/nvmem/layouts/onie-tlv.c
@@ -0,0 +1,244 @@
+// 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 "platforn-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", },
+	{},
+};
+
+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);
+}
+subsys_initcall(onie_tlv_init);
-- 
2.25.1


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

* [PATCH 26/37] MAINTAINERS: Add myself as ONIE tlv NVMEM layout maintainer
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (24 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 25/37] nvmem: layouts: Add ONIE tlv " Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 27/37] nvmem: core: return -ENOENT if nvmem cell is not found Srinivas Kandagatla
                   ` (11 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Miquel Raynal, Srinivas Kandagatla

From: Miquel Raynal <miquel.raynal@bootlin.com>

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>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 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.25.1


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

* [PATCH 27/37] nvmem: core: return -ENOENT if nvmem cell is not found
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (25 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 26/37] MAINTAINERS: Add myself as ONIE tlv NVMEM layout maintainer Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 28/37] nvmem: layouts: Fix spelling mistake "platforn" -> "platform" Srinivas Kandagatla
                   ` (10 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Michael Walle, Alexander Stein, Srinivas Kandagatla

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: e894d5ad177c ("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>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 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 81ad6a4c4f86..30057b0094a2 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -1346,7 +1346,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.25.1


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

* [PATCH 28/37] nvmem: layouts: Fix spelling mistake "platforn" -> "platform"
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (26 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 27/37] nvmem: core: return -ENOENT if nvmem cell is not found Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 29/37] dt-bindings: nvmem: " Srinivas Kandagatla
                   ` (9 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Colin Ian King, Srinivas Kandagatla

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

There is a spelling mistake in the literal string. Fix it.

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/layouts/onie-tlv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvmem/layouts/onie-tlv.c b/drivers/nvmem/layouts/onie-tlv.c
index 074c7c700845..767f39fff717 100644
--- a/drivers/nvmem/layouts/onie-tlv.c
+++ b/drivers/nvmem/layouts/onie-tlv.c
@@ -48,7 +48,7 @@ static const char *onie_tlv_cell_name(u8 type)
 	case 0x27:
 		return "label-revision";
 	case 0x28:
-		return "platforn-name";
+		return "platform-name";
 	case 0x29:
 		return "onie-version";
 	case 0x2A:
-- 
2.25.1


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

* [PATCH 29/37] dt-bindings: nvmem: Fix spelling mistake "platforn" -> "platform"
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (27 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 28/37] nvmem: layouts: Fix spelling mistake "platforn" -> "platform" Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 30/37] nvmem: core: fix nvmem_layout_get_match_data() Srinivas Kandagatla
                   ` (8 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Colin Ian King, Srinivas Kandagatla

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: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 .../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.25.1


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

* [PATCH 30/37] nvmem: core: fix nvmem_layout_get_match_data()
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (28 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 29/37] dt-bindings: nvmem: " Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:15 ` [PATCH 31/37] nvmem: stm32: add OP-TEE support for STM32MP13x Srinivas Kandagatla
                   ` (7 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, Rafał Miłecki, Michael Walle,
	Srinivas Kandagatla

From: Rafał Miłecki <rafal@milecki.pl>

This function was trying to match wrong OF node (parent device's)
against an of_match_table. It was always returning NULL.

Make it match layout's OF node against layout's of_match_table.

Note: __maybe_unused is needed to avoid:
warning: variable 'layout_np' set but not used [-Wunused-but-set-variable]
(of_match_node() is no-op without CONFIG_OF).

Fixes: f61a093b4a0e ("nvmem: core: introduce NVMEM layouts")
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Reviewed-by: Michael Walle <michael@walle.cc>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 30057b0094a2..38a5728bc65c 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -824,9 +824,11 @@ EXPORT_SYMBOL_GPL(of_nvmem_layout_get_container);
 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;
 
-	match = of_match_node(layout->of_match_table, nvmem->dev.of_node);
+	layout_np = of_nvmem_layout_get_container(nvmem);
+	match = of_match_node(layout->of_match_table, layout_np);
 
 	return match ? match->data : NULL;
 }
-- 
2.25.1


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

* [PATCH 31/37] nvmem: stm32: add OP-TEE support for STM32MP13x
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (29 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 30/37] nvmem: core: fix nvmem_layout_get_match_data() Srinivas Kandagatla
@ 2023-01-27 11:15 ` Srinivas Kandagatla
  2023-01-27 11:16 ` [PATCH 32/37] nvmem: stm32: detect bsec pta presence for STM32MP15x Srinivas Kandagatla
                   ` (6 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:15 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, Patrick Delaunay, Etienne Carriere, Srinivas Kandagatla

From: Patrick Delaunay <patrick.delaunay@foss.st.com>

For boot with OP-TEE on STM32MP13, the communication with the secure
world no more use STMicroelectronics SMC but communication with the
STM32MP BSEC TA, for data access (read/write) or lock operation:
- all the request are sent to OP-TEE trusted application,
- for upper OTP with ECC protection and with word programming only
  each OTP are permanently locked when programmed to avoid ECC error
  on the second write operation

Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/Kconfig               |  11 +
 drivers/nvmem/Makefile              |   1 +
 drivers/nvmem/stm32-bsec-optee-ta.c | 298 ++++++++++++++++++++++++++++
 drivers/nvmem/stm32-bsec-optee-ta.h |  80 ++++++++
 drivers/nvmem/stm32-romem.c         |  54 ++++-
 5 files changed, 441 insertions(+), 3 deletions(-)
 create mode 100644 drivers/nvmem/stm32-bsec-optee-ta.c
 create mode 100644 drivers/nvmem/stm32-bsec-optee-ta.h

diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index 0e10b5b094b9..ed8ef7460be2 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -294,9 +294,20 @@ config NVMEM_SPRD_EFUSE
 	  This driver can also be built as a module. If so, the module
 	  will be called nvmem-sprd-efuse.
 
+config NVMEM_STM32_BSEC_OPTEE_TA
+	bool "STM32MP BSEC OP-TEE TA support for nvmem-stm32-romem driver"
+	depends on OPTEE
+	help
+	  Say y here to enable the accesses to STM32MP SoC OTPs by the OP-TEE
+	  trusted application STM32MP BSEC.
+
+	  This library is a used by stm32-romem driver or included in the module
+	  called nvmem-stm32-romem.
+
 config NVMEM_STM32_ROMEM
 	tristate "STMicroelectronics STM32 factory-programmed memory support"
 	depends on ARCH_STM32 || COMPILE_TEST
+	imply NVMEM_STM32_BSEC_OPTEE_TA
 	help
 	  Say y here to enable read-only access for STMicroelectronics STM32
 	  factory-programmed memory area.
diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
index 4cf87ef6c24d..f82431ec8aef 100644
--- a/drivers/nvmem/Makefile
+++ b/drivers/nvmem/Makefile
@@ -62,6 +62,7 @@ obj-$(CONFIG_NVMEM_SPRD_EFUSE)		+= nvmem_sprd_efuse.o
 nvmem_sprd_efuse-y			:= sprd-efuse.o
 obj-$(CONFIG_NVMEM_STM32_ROMEM)		+= nvmem_stm32_romem.o
 nvmem_stm32_romem-y 			:= stm32-romem.o
+nvmem_stm32_romem-$(CONFIG_NVMEM_STM32_BSEC_OPTEE_TA) += stm32-bsec-optee-ta.o
 obj-$(CONFIG_NVMEM_SUNPLUS_OCOTP)	+= nvmem_sunplus_ocotp.o
 nvmem_sunplus_ocotp-y			:= sunplus-ocotp.o
 obj-$(CONFIG_NVMEM_SUNXI_SID)		+= nvmem_sunxi_sid.o
diff --git a/drivers/nvmem/stm32-bsec-optee-ta.c b/drivers/nvmem/stm32-bsec-optee-ta.c
new file mode 100644
index 000000000000..f89ce791dd12
--- /dev/null
+++ b/drivers/nvmem/stm32-bsec-optee-ta.c
@@ -0,0 +1,298 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * OP-TEE STM32MP BSEC PTA interface, used by STM32 ROMEM driver
+ *
+ * Copyright (C) 2022, STMicroelectronics - All Rights Reserved
+ */
+
+#include <linux/tee_drv.h>
+
+#include "stm32-bsec-optee-ta.h"
+
+/*
+ * Read OTP memory
+ *
+ * [in]		value[0].a		OTP start offset in byte
+ * [in]		value[0].b		Access type (0:shadow, 1:fuse, 2:lock)
+ * [out]	memref[1].buffer	Output buffer to store read values
+ * [out]	memref[1].size		Size of OTP to be read
+ *
+ * Return codes:
+ * TEE_SUCCESS - Invoke command success
+ * TEE_ERROR_BAD_PARAMETERS - Incorrect input param
+ * TEE_ERROR_ACCESS_DENIED - OTP not accessible by caller
+ */
+#define PTA_BSEC_READ_MEM		0x0
+
+/*
+ * Write OTP memory
+ *
+ * [in]		value[0].a		OTP start offset in byte
+ * [in]		value[0].b		Access type (0:shadow, 1:fuse, 2:lock)
+ * [in]		memref[1].buffer	Input buffer to read values
+ * [in]		memref[1].size		Size of OTP to be written
+ *
+ * Return codes:
+ * TEE_SUCCESS - Invoke command success
+ * TEE_ERROR_BAD_PARAMETERS - Incorrect input param
+ * TEE_ERROR_ACCESS_DENIED - OTP not accessible by caller
+ */
+#define PTA_BSEC_WRITE_MEM		0x1
+
+/* value of PTA_BSEC access type = value[in] b */
+#define SHADOW_ACCESS	0
+#define FUSE_ACCESS	1
+#define LOCK_ACCESS	2
+
+/* Bitfield definition for LOCK status */
+#define LOCK_PERM			BIT(30)
+
+/* OP-TEE STM32MP BSEC TA UUID */
+static const uuid_t stm32mp_bsec_ta_uuid =
+	UUID_INIT(0x94cf71ad, 0x80e6, 0x40b5,
+		  0xa7, 0xc6, 0x3d, 0xc5, 0x01, 0xeb, 0x28, 0x03);
+
+/*
+ * Check whether this driver supports the BSEC TA in the TEE instance
+ * represented by the params (ver/data) to this function.
+ */
+static int stm32_bsec_optee_ta_match(struct tee_ioctl_version_data *ver,
+				     const void *data)
+{
+	/* Currently this driver only supports GP compliant, OP-TEE based TA */
+	if ((ver->impl_id == TEE_IMPL_ID_OPTEE) &&
+		(ver->gen_caps & TEE_GEN_CAP_GP))
+		return 1;
+	else
+		return 0;
+}
+
+/* Open a session to OP-TEE for STM32MP BSEC TA */
+static int stm32_bsec_ta_open_session(struct tee_context *ctx, u32 *id)
+{
+	struct tee_ioctl_open_session_arg sess_arg;
+	int rc;
+
+	memset(&sess_arg, 0, sizeof(sess_arg));
+	export_uuid(sess_arg.uuid, &stm32mp_bsec_ta_uuid);
+	sess_arg.clnt_login = TEE_IOCTL_LOGIN_REE_KERNEL;
+	sess_arg.num_params = 0;
+
+	rc = tee_client_open_session(ctx, &sess_arg, NULL);
+	if ((rc < 0) || (sess_arg.ret != 0)) {
+		pr_err("%s: tee_client_open_session failed err:%#x, ret:%#x\n",
+		       __func__, sess_arg.ret, rc);
+		if (!rc)
+			rc = -EINVAL;
+	} else {
+		*id = sess_arg.session;
+	}
+
+	return rc;
+}
+
+/* close a session to OP-TEE for STM32MP BSEC TA */
+static void stm32_bsec_ta_close_session(void *ctx, u32 id)
+{
+	tee_client_close_session(ctx, id);
+}
+
+/* stm32_bsec_optee_ta_open() - initialize the STM32MP BSEC TA */
+int stm32_bsec_optee_ta_open(struct tee_context **ctx)
+{
+	struct tee_context *tee_ctx;
+	u32 session_id;
+	int rc;
+
+	/* Open context with TEE driver */
+	tee_ctx = tee_client_open_context(NULL, stm32_bsec_optee_ta_match, NULL, NULL);
+	if (IS_ERR(tee_ctx)) {
+		rc = PTR_ERR(tee_ctx);
+		if (rc == -ENOENT)
+			return -EPROBE_DEFER;
+		pr_err("%s: tee_client_open_context failed (%d)\n", __func__, rc);
+
+		return rc;
+	}
+
+	/* Check STM32MP BSEC TA presence */
+	rc = stm32_bsec_ta_open_session(tee_ctx, &session_id);
+	if (rc) {
+		tee_client_close_context(tee_ctx);
+		return rc;
+	}
+
+	stm32_bsec_ta_close_session(tee_ctx, session_id);
+
+	*ctx = tee_ctx;
+
+	return 0;
+}
+
+/* stm32_bsec_optee_ta_open() - release the PTA STM32MP BSEC TA */
+void stm32_bsec_optee_ta_close(void *ctx)
+{
+	tee_client_close_context(ctx);
+}
+
+/* stm32_bsec_optee_ta_read() - nvmem read access using PTA client driver */
+int stm32_bsec_optee_ta_read(struct tee_context *ctx, unsigned int offset,
+			     void *buf, size_t bytes)
+{
+	struct tee_shm *shm;
+	struct tee_ioctl_invoke_arg arg;
+	struct tee_param param[2];
+	u8 *shm_buf;
+	u32 start, num_bytes;
+	int ret;
+	u32 session_id;
+
+	ret = stm32_bsec_ta_open_session(ctx, &session_id);
+	if (ret)
+		return ret;
+
+	memset(&arg, 0, sizeof(arg));
+	memset(&param, 0, sizeof(param));
+
+	arg.func = PTA_BSEC_READ_MEM;
+	arg.session = session_id;
+	arg.num_params = 2;
+
+	/* align access on 32bits */
+	start = ALIGN_DOWN(offset, 4);
+	num_bytes = round_up(offset + bytes - start, 4);
+	param[0].attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT;
+	param[0].u.value.a = start;
+	param[0].u.value.b = SHADOW_ACCESS;
+
+	shm = tee_shm_alloc_kernel_buf(ctx, num_bytes);
+	if (IS_ERR(shm)) {
+		ret = PTR_ERR(shm);
+		goto out_tee_session;
+	}
+
+	param[1].attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT;
+	param[1].u.memref.shm = shm;
+	param[1].u.memref.size = num_bytes;
+
+	ret = tee_client_invoke_func(ctx, &arg, param);
+	if (ret < 0 || arg.ret != 0) {
+		pr_err("TA_BSEC invoke failed TEE err:%#x, ret:%#x\n",
+			arg.ret, ret);
+		if (!ret)
+			ret = -EIO;
+	}
+	if (!ret) {
+		shm_buf = tee_shm_get_va(shm, 0);
+		if (IS_ERR(shm_buf)) {
+			ret = PTR_ERR(shm_buf);
+			pr_err("tee_shm_get_va failed for transmit (%d)\n", ret);
+		} else {
+			/* read data from 32 bits aligned buffer */
+			memcpy(buf, &shm_buf[offset % 4], bytes);
+		}
+	}
+
+	tee_shm_free(shm);
+
+out_tee_session:
+	stm32_bsec_ta_close_session(ctx, session_id);
+
+	return ret;
+}
+
+/* stm32_bsec_optee_ta_write() - nvmem write access using PTA client driver */
+int stm32_bsec_optee_ta_write(struct tee_context *ctx, unsigned int lower,
+			      unsigned int offset, void *buf, size_t bytes)
+{	struct tee_shm *shm;
+	struct tee_ioctl_invoke_arg arg;
+	struct tee_param param[2];
+	u8 *shm_buf;
+	int ret;
+	u32 session_id;
+
+	ret = stm32_bsec_ta_open_session(ctx, &session_id);
+	if (ret)
+		return ret;
+
+	/* Allow only writing complete 32-bits aligned words */
+	if ((bytes % 4) || (offset % 4))
+		return -EINVAL;
+
+	memset(&arg, 0, sizeof(arg));
+	memset(&param, 0, sizeof(param));
+
+	arg.func = PTA_BSEC_WRITE_MEM;
+	arg.session = session_id;
+	arg.num_params = 2;
+
+	param[0].attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT;
+	param[0].u.value.a = offset;
+	param[0].u.value.b = FUSE_ACCESS;
+
+	shm = tee_shm_alloc_kernel_buf(ctx, bytes);
+	if (IS_ERR(shm)) {
+		ret = PTR_ERR(shm);
+		goto out_tee_session;
+	}
+
+	param[1].attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT;
+	param[1].u.memref.shm = shm;
+	param[1].u.memref.size = bytes;
+
+	shm_buf = tee_shm_get_va(shm, 0);
+	if (IS_ERR(shm_buf)) {
+		ret = PTR_ERR(shm_buf);
+		pr_err("tee_shm_get_va failed for transmit (%d)\n", ret);
+		tee_shm_free(shm);
+
+		goto out_tee_session;
+	}
+
+	memcpy(shm_buf, buf, bytes);
+
+	ret = tee_client_invoke_func(ctx, &arg, param);
+	if (ret < 0 || arg.ret != 0) {
+		pr_err("TA_BSEC invoke failed TEE err:%#x, ret:%#x\n", arg.ret, ret);
+		if (!ret)
+			ret = -EIO;
+	}
+	pr_debug("Write OTPs %d to %zu, ret=%d\n", offset / 4, (offset + bytes) / 4, ret);
+
+	/* Lock the upper OTPs with ECC protection, word programming only */
+	if (!ret && ((offset + bytes) >= (lower * 4))) {
+		u32 start, nb_lock;
+		u32 *lock = (u32 *)shm_buf;
+		int i;
+
+		/*
+		 * don't lock the lower OTPs, no ECC protection and incremental
+		 * bit programming, a second write is allowed
+		 */
+		start = max_t(u32, offset, lower * 4);
+		nb_lock = (offset + bytes - start) / 4;
+
+		param[0].u.value.a = start;
+		param[0].u.value.b = LOCK_ACCESS;
+		param[1].u.memref.size = nb_lock * 4;
+
+		for (i = 0; i < nb_lock; i++)
+			lock[i] = LOCK_PERM;
+
+		ret = tee_client_invoke_func(ctx, &arg, param);
+		if (ret < 0 || arg.ret != 0) {
+			pr_err("TA_BSEC invoke failed TEE err:%#x, ret:%#x\n", arg.ret, ret);
+			if (!ret)
+				ret = -EIO;
+		}
+		pr_debug("Lock upper OTPs %d to %d, ret=%d\n",
+			 start / 4, start / 4 + nb_lock, ret);
+	}
+
+	tee_shm_free(shm);
+
+out_tee_session:
+	stm32_bsec_ta_close_session(ctx, session_id);
+
+	return ret;
+}
diff --git a/drivers/nvmem/stm32-bsec-optee-ta.h b/drivers/nvmem/stm32-bsec-optee-ta.h
new file mode 100644
index 000000000000..3966a0535179
--- /dev/null
+++ b/drivers/nvmem/stm32-bsec-optee-ta.h
@@ -0,0 +1,80 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * OP-TEE STM32MP BSEC PTA interface, used by STM32 ROMEM driver
+ *
+ * Copyright (C) 2022, STMicroelectronics - All Rights Reserved
+ */
+
+#if IS_ENABLED(CONFIG_NVMEM_STM32_BSEC_OPTEE_TA)
+/**
+ * stm32_bsec_optee_ta_open() - initialize the STM32 BSEC TA
+ * @ctx: the OP-TEE context on success
+ *
+ * Return:
+ *	On success, 0. On failure, -errno.
+ */
+int stm32_bsec_optee_ta_open(struct tee_context **ctx);
+
+/**
+ * stm32_bsec_optee_ta_close() - release the STM32 BSEC TA
+ * @ctx: the OP-TEE context
+ *
+ * This function used to clean the OP-TEE resources initialized in
+ * stm32_bsec_optee_ta_open(); it can be used as callback to
+ * devm_add_action_or_reset()
+ */
+void stm32_bsec_optee_ta_close(void *ctx);
+
+/**
+ * stm32_bsec_optee_ta_read() - nvmem read access using TA client driver
+ * @ctx: the OP-TEE context provided by stm32_bsec_optee_ta_open
+ * @offset: nvmem offset
+ * @buf: buffer to fill with nvem values
+ * @bytes: number of bytes to read
+ *
+ * Return:
+ *	On success, 0. On failure, -errno.
+ */
+int stm32_bsec_optee_ta_read(struct tee_context *ctx, unsigned int offset,
+			     void *buf, size_t bytes);
+
+/**
+ * stm32_bsec_optee_ta_write() - nvmem write access using TA client driver
+ * @ctx: the OP-TEE context provided by stm32_bsec_optee_ta_open
+ * @lower: number of lower OTP, not protected by ECC
+ * @offset: nvmem offset
+ * @buf: buffer with nvem values
+ * @bytes: number of bytes to write
+ *
+ * Return:
+ *	On success, 0. On failure, -errno.
+ */
+int stm32_bsec_optee_ta_write(struct tee_context *ctx, unsigned int lower,
+			      unsigned int offset, void *buf, size_t bytes);
+
+#else
+
+static inline int stm32_bsec_optee_ta_open(struct tee_context **ctx)
+{
+	return -EOPNOTSUPP;
+}
+
+static inline void stm32_bsec_optee_ta_close(void *ctx)
+{
+}
+
+static inline int stm32_bsec_optee_ta_read(struct tee_context *ctx,
+					   unsigned int offset, void *buf,
+					   size_t bytes)
+{
+	return -EOPNOTSUPP;
+}
+
+static inline int stm32_bsec_optee_ta_write(struct tee_context *ctx,
+					    unsigned int lower,
+					    unsigned int offset, void *buf,
+					    size_t bytes)
+{
+	return -EOPNOTSUPP;
+}
+#endif /* CONFIG_NVMEM_STM32_BSEC_OPTEE_TA */
diff --git a/drivers/nvmem/stm32-romem.c b/drivers/nvmem/stm32-romem.c
index d1d03c2ad081..978a63edf297 100644
--- a/drivers/nvmem/stm32-romem.c
+++ b/drivers/nvmem/stm32-romem.c
@@ -11,6 +11,9 @@
 #include <linux/module.h>
 #include <linux/nvmem-provider.h>
 #include <linux/of_device.h>
+#include <linux/tee_drv.h>
+
+#include "stm32-bsec-optee-ta.h"
 
 /* BSEC secure service access from non-secure */
 #define STM32_SMC_BSEC			0x82001003
@@ -25,12 +28,14 @@
 struct stm32_romem_cfg {
 	int size;
 	u8 lower;
+	bool ta;
 };
 
 struct stm32_romem_priv {
 	void __iomem *base;
 	struct nvmem_config cfg;
 	u8 lower;
+	struct tee_context *ctx;
 };
 
 static int stm32_romem_read(void *context, unsigned int offset, void *buf,
@@ -138,12 +143,29 @@ static int stm32_bsec_write(void *context, unsigned int offset, void *buf,
 	return 0;
 }
 
+static int stm32_bsec_pta_read(void *context, unsigned int offset, void *buf,
+			       size_t bytes)
+{
+	struct stm32_romem_priv *priv = context;
+
+	return stm32_bsec_optee_ta_read(priv->ctx, offset, buf, bytes);
+}
+
+static int stm32_bsec_pta_write(void *context, unsigned int offset, void *buf,
+				size_t bytes)
+{
+	struct stm32_romem_priv *priv = context;
+
+	return stm32_bsec_optee_ta_write(priv->ctx, priv->lower, offset, buf, bytes);
+}
+
 static int stm32_romem_probe(struct platform_device *pdev)
 {
 	const struct stm32_romem_cfg *cfg;
 	struct device *dev = &pdev->dev;
 	struct stm32_romem_priv *priv;
 	struct resource *res;
+	int rc;
 
 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
@@ -173,15 +195,31 @@ static int stm32_romem_probe(struct platform_device *pdev)
 	} else {
 		priv->cfg.size = cfg->size;
 		priv->lower = cfg->lower;
-		priv->cfg.reg_read = stm32_bsec_read;
-		priv->cfg.reg_write = stm32_bsec_write;
+		if (cfg->ta) {
+			rc = stm32_bsec_optee_ta_open(&priv->ctx);
+			/* wait for OP-TEE client driver to be up and ready */
+			if (rc)
+				return rc;
+		}
+		if (priv->ctx) {
+			rc = devm_add_action_or_reset(dev, stm32_bsec_optee_ta_close, priv->ctx);
+			if (rc) {
+				dev_err(dev, "devm_add_action_or_reset() failed (%d)\n", rc);
+				return rc;
+			}
+			priv->cfg.reg_read = stm32_bsec_pta_read;
+			priv->cfg.reg_write = stm32_bsec_pta_write;
+		} else {
+			priv->cfg.reg_read = stm32_bsec_read;
+			priv->cfg.reg_write = stm32_bsec_write;
+		}
 	}
 
 	return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &priv->cfg));
 }
 
 /*
- * STM32MP15 BSEC OTP regions: 4096 OTP bits (with 3072 effective bits)
+ * STM32MP15/13 BSEC OTP regions: 4096 OTP bits (with 3072 effective bits)
  * => 96 x 32-bits data words
  * - Lower: 1K bits, 2:1 redundancy, incremental bit programming
  *   => 32 (x 32-bits) lower shadow registers = words 0 to 31
@@ -191,6 +229,13 @@ static int stm32_romem_probe(struct platform_device *pdev)
 static const struct stm32_romem_cfg stm32mp15_bsec_cfg = {
 	.size = 384,
 	.lower = 32,
+	.ta = false,
+};
+
+static const struct stm32_romem_cfg stm32mp13_bsec_cfg = {
+	.size = 384,
+	.lower = 32,
+	.ta = true,
 };
 
 static const struct of_device_id stm32_romem_of_match[] = {
@@ -198,7 +243,10 @@ static const struct of_device_id stm32_romem_of_match[] = {
 		.compatible = "st,stm32mp15-bsec",
 		.data = (void *)&stm32mp15_bsec_cfg,
 	}, {
+		.compatible = "st,stm32mp13-bsec",
+		.data = (void *)&stm32mp13_bsec_cfg,
 	},
+	{ /* sentinel */ },
 };
 MODULE_DEVICE_TABLE(of, stm32_romem_of_match);
 
-- 
2.25.1


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

* [PATCH 32/37] nvmem: stm32: detect bsec pta presence for STM32MP15x
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (30 preceding siblings ...)
  2023-01-27 11:15 ` [PATCH 31/37] nvmem: stm32: add OP-TEE support for STM32MP13x Srinivas Kandagatla
@ 2023-01-27 11:16 ` Srinivas Kandagatla
  2023-01-27 11:16 ` [PATCH 33/37] nvmem: rave-sp-eeprm: fix kernel-doc bad line warning Srinivas Kandagatla
                   ` (5 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:16 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, Patrick Delaunay, Etienne Carriere, Srinivas Kandagatla

From: Patrick Delaunay <patrick.delaunay@foss.st.com>

On STM32MP15x SoC, the SMC backend is optional when OP-TEE is used;
the PTA BSEC should be used as it is done on STM32MP13x platform,
but the BSEC SMC can be also used: it is a legacy mode in OP-TEE,
not recommended but used in previous OP-TEE firmware.

The presence of OP-TEE is dynamically detected in STM32MP15x device tree
and the supported NVMEM backend is dynamically detected:
- PTA with stm32_bsec_pta_find
- SMC with stm32_bsec_check

With OP-TEE but without PTA and SMC detection, the probe is deferred for
STM32MP15x devices.

On STM32MP13x platform, only the PTA is supported with cfg->ta = true
and this detection is skipped.

Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/stm32-romem.c | 38 +++++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/drivers/nvmem/stm32-romem.c b/drivers/nvmem/stm32-romem.c
index 978a63edf297..ba779e26937a 100644
--- a/drivers/nvmem/stm32-romem.c
+++ b/drivers/nvmem/stm32-romem.c
@@ -159,6 +159,31 @@ static int stm32_bsec_pta_write(void *context, unsigned int offset, void *buf,
 	return stm32_bsec_optee_ta_write(priv->ctx, priv->lower, offset, buf, bytes);
 }
 
+static bool stm32_bsec_smc_check(void)
+{
+	u32 val;
+	int ret;
+
+	/* check that the OP-TEE support the BSEC SMC (legacy mode) */
+	ret = stm32_bsec_smc(STM32_SMC_READ_SHADOW, 0, 0, &val);
+
+	return !ret;
+}
+
+static bool optee_presence_check(void)
+{
+	struct device_node *np;
+	bool tee_detected = false;
+
+	/* check that the OP-TEE node is present and available. */
+	np = of_find_compatible_node(NULL, NULL, "linaro,optee-tz");
+	if (np && of_device_is_available(np))
+		tee_detected = true;
+	of_node_put(np);
+
+	return tee_detected;
+}
+
 static int stm32_romem_probe(struct platform_device *pdev)
 {
 	const struct stm32_romem_cfg *cfg;
@@ -195,11 +220,16 @@ static int stm32_romem_probe(struct platform_device *pdev)
 	} else {
 		priv->cfg.size = cfg->size;
 		priv->lower = cfg->lower;
-		if (cfg->ta) {
+		if (cfg->ta || optee_presence_check()) {
 			rc = stm32_bsec_optee_ta_open(&priv->ctx);
-			/* wait for OP-TEE client driver to be up and ready */
-			if (rc)
-				return rc;
+			if (rc) {
+				/* wait for OP-TEE client driver to be up and ready */
+				if (rc == -EPROBE_DEFER)
+					return -EPROBE_DEFER;
+				/* BSEC PTA is required or SMC not supported */
+				if (cfg->ta || !stm32_bsec_smc_check())
+					return rc;
+			}
 		}
 		if (priv->ctx) {
 			rc = devm_add_action_or_reset(dev, stm32_bsec_optee_ta_close, priv->ctx);
-- 
2.25.1


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

* [PATCH 33/37] nvmem: rave-sp-eeprm: fix kernel-doc bad line warning
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (31 preceding siblings ...)
  2023-01-27 11:16 ` [PATCH 32/37] nvmem: stm32: detect bsec pta presence for STM32MP15x Srinivas Kandagatla
@ 2023-01-27 11:16 ` Srinivas Kandagatla
  2023-01-27 11:16 ` [PATCH 34/37] of: property: fix #nvmem-cell-cells parsing Srinivas Kandagatla
                   ` (4 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:16 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, Randy Dunlap, Srinivas Kandagatla,
	Andrey Vostrikov, Nikita Yushchenko, Andrey Smirnov

From: Randy Dunlap <rdunlap@infradead.org>

Convert an empty line to " *" to avoid a kernel-doc warning:

drivers/nvmem/rave-sp-eeprom.c:48: warning: bad line:

Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: Andrey Vostrikov <andrey.vostrikov@cogentembedded.com>
Cc: Nikita Yushchenko <nikita.yoush@cogentembedded.com>
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/rave-sp-eeprom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvmem/rave-sp-eeprom.c b/drivers/nvmem/rave-sp-eeprom.c
index 66699d44f73d..c456011b75e8 100644
--- a/drivers/nvmem/rave-sp-eeprom.c
+++ b/drivers/nvmem/rave-sp-eeprom.c
@@ -45,7 +45,7 @@ enum rave_sp_eeprom_header_size {
  * @type:	Access type (see enum rave_sp_eeprom_access_type)
  * @success:	Success flag (Success = 1, Failure = 0)
  * @data:	Read data
-
+ *
  * Note this structure corresponds to RSP_*_EEPROM payload from RAVE
  * SP ICD
  */
-- 
2.25.1


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

* [PATCH 34/37] of: property: fix #nvmem-cell-cells parsing
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (32 preceding siblings ...)
  2023-01-27 11:16 ` [PATCH 33/37] nvmem: rave-sp-eeprm: fix kernel-doc bad line warning Srinivas Kandagatla
@ 2023-01-27 11:16 ` Srinivas Kandagatla
  2023-01-27 11:16 ` [PATCH 35/37] nvmem: qcom-spmi-sdam: register at device init time Srinivas Kandagatla
                   ` (3 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:16 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, Michael Walle, Peng Fan, Rob Herring, Robert Marko,
	Srinivas Kandagatla

From: Michael Walle <michael@walle.cc>

Commit 6a80b3e6fb41 ("of: property: make #.*-cells optional for simple
props") claims to make the cells-name property optional for simple
properties, but changed the code for the wrong property, i.e. for
DEFINE_SUFFIX_PROP(). Fix that.

Fixes: 6a80b3e6fb41 ("of: property: make #.*-cells optional for simple props")
Reported-by: Peng Fan <peng.fan@nxp.com>
Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Rob Herring <robh@kernel.org>
Tested-by: Robert Marko <robimarko@gmail.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/of/property.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/of/property.c b/drivers/of/property.c
index 8d9ba20a8f90..95b838185b2f 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -1202,8 +1202,8 @@ static struct device_node *parse_prop_cells(struct device_node *np,
 	if (strcmp(prop_name, list_name))
 		return NULL;
 
-	if (of_parse_phandle_with_args(np, list_name, cells_name, index,
-				       &sup_args))
+	if (__of_parse_phandle_with_args(np, list_name, cells_name, 0, index,
+					 &sup_args))
 		return NULL;
 
 	return sup_args.np;
@@ -1256,8 +1256,8 @@ static struct device_node *parse_suffix_prop_cells(struct device_node *np,
 	if (strcmp_suffix(prop_name, suffix))
 		return NULL;
 
-	if (__of_parse_phandle_with_args(np, prop_name, cells_name, 0, index,
-					 &sup_args))
+	if (of_parse_phandle_with_args(np, prop_name, cells_name, index,
+				       &sup_args))
 		return NULL;
 
 	return sup_args.np;
-- 
2.25.1


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

* [PATCH 35/37] nvmem: qcom-spmi-sdam: register at device init time
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (33 preceding siblings ...)
  2023-01-27 11:16 ` [PATCH 34/37] of: property: fix #nvmem-cell-cells parsing Srinivas Kandagatla
@ 2023-01-27 11:16 ` Srinivas Kandagatla
  2023-01-27 11:16 ` [PATCH 36/37] dt-bindings: nvmem: qfprom: add IPQ8074 compatible Srinivas Kandagatla
                   ` (2 subsequent siblings)
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:16 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Johan Hovold, Bjorn Andersson, Srinivas Kandagatla

From: Johan Hovold <johan+linaro@kernel.org>

There are currently no in-tree users of the Qualcomm SDAM nvmem driver
and there is generally no point in registering a driver that can be
built as a module at subsys init time.

Register the driver at the normal device init time instead and let
driver core sort out the probe order.

Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
Reviewed-by: Bjorn Andersson <andersson@kernel.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/qcom-spmi-sdam.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/nvmem/qcom-spmi-sdam.c b/drivers/nvmem/qcom-spmi-sdam.c
index 8499892044b7..f822790db49e 100644
--- a/drivers/nvmem/qcom-spmi-sdam.c
+++ b/drivers/nvmem/qcom-spmi-sdam.c
@@ -175,18 +175,7 @@ static struct platform_driver sdam_driver = {
 	},
 	.probe		= sdam_probe,
 };
-
-static int __init sdam_init(void)
-{
-	return platform_driver_register(&sdam_driver);
-}
-subsys_initcall(sdam_init);
-
-static void __exit sdam_exit(void)
-{
-	return platform_driver_unregister(&sdam_driver);
-}
-module_exit(sdam_exit);
+module_platform_driver(sdam_driver);
 
 MODULE_DESCRIPTION("QCOM SPMI SDAM driver");
 MODULE_LICENSE("GPL v2");
-- 
2.25.1


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

* [PATCH 36/37] dt-bindings: nvmem: qfprom: add IPQ8074 compatible
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (34 preceding siblings ...)
  2023-01-27 11:16 ` [PATCH 35/37] nvmem: qcom-spmi-sdam: register at device init time Srinivas Kandagatla
@ 2023-01-27 11:16 ` Srinivas Kandagatla
  2023-01-27 11:16 ` [PATCH 37/37] nvmem: stm32: fix OPTEE dependency Srinivas Kandagatla
  2023-01-28 13:43 ` [PATCH 00/37] nvmem: patches for 6.3 Greg KH
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:16 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, Robert Marko, Krzysztof Kozlowski, Srinivas Kandagatla

From: Robert Marko <robimarko@gmail.com>

Document IPQ8074 compatible for QFPROM, its compatible with the generic
QFPROM fallback.

Signed-off-by: Robert Marko <robimarko@gmail.com>
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
index 9ddf3cef9e84..2173fe82317d 100644
--- a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
+++ b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
@@ -19,6 +19,7 @@ properties:
           - qcom,apq8064-qfprom
           - qcom,apq8084-qfprom
           - qcom,ipq8064-qfprom
+          - qcom,ipq8074-qfprom
           - qcom,msm8916-qfprom
           - qcom,msm8974-qfprom
           - qcom,msm8976-qfprom
-- 
2.25.1


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

* [PATCH 37/37] nvmem: stm32: fix OPTEE dependency
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (35 preceding siblings ...)
  2023-01-27 11:16 ` [PATCH 36/37] dt-bindings: nvmem: qfprom: add IPQ8074 compatible Srinivas Kandagatla
@ 2023-01-27 11:16 ` Srinivas Kandagatla
  2023-01-28 13:43 ` [PATCH 00/37] nvmem: patches for 6.3 Greg KH
  37 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-27 11:16 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Arnd Bergmann

From: Arnd Bergmann <arnd@arndb.de>

The stm32 nvmem driver fails to link as built-in when OPTEE
is a loadable module:

aarch64-linux-ld: drivers/nvmem/stm32-bsec-optee-ta.o: in function `stm32_bsec:
stm32-bsec-optee-ta.c:(.text+0xc8): undefined reference to `tee_client_open_session'
aarch64-linux-ld: drivers/nvmem/stm32-bsec-optee-ta.o: in function `stm32_bsec:
stm32-bsec-optee-ta.c:(.text+0x1fc): undefined reference to `tee_client_open_context'

Change the CONFIG_NVMEM_STM32_ROMEM definition so it can only
be built-in if OPTEE is either built-in or disabled, and
make NVMEM_STM32_BSEC_OPTEE_TA a hidden symbol instead.

Fixes: ae46fd89cc0cc ("nvmem: stm32: add OP-TEE support for STM32MP13x")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/nvmem/Kconfig | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index ed8ef7460be2..ae2c5257ed97 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -295,8 +295,7 @@ config NVMEM_SPRD_EFUSE
 	  will be called nvmem-sprd-efuse.
 
 config NVMEM_STM32_BSEC_OPTEE_TA
-	bool "STM32MP BSEC OP-TEE TA support for nvmem-stm32-romem driver"
-	depends on OPTEE
+	def_bool NVMEM_STM32_ROMEM && OPTEE
 	help
 	  Say y here to enable the accesses to STM32MP SoC OTPs by the OP-TEE
 	  trusted application STM32MP BSEC.
@@ -307,7 +306,7 @@ config NVMEM_STM32_BSEC_OPTEE_TA
 config NVMEM_STM32_ROMEM
 	tristate "STMicroelectronics STM32 factory-programmed memory support"
 	depends on ARCH_STM32 || COMPILE_TEST
-	imply NVMEM_STM32_BSEC_OPTEE_TA
+	depends on OPTEE || !OPTEE
 	help
 	  Say y here to enable read-only access for STMicroelectronics STM32
 	  factory-programmed memory area.
-- 
2.25.1


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

* Re: [PATCH 04/37] dt-bindings: nvmem: qfprom: add sdm670 compatible
  2023-01-27 11:15 ` [PATCH 04/37] dt-bindings: nvmem: qfprom: add sdm670 compatible Srinivas Kandagatla
@ 2023-01-27 23:39   ` Richard Acayan
  0 siblings, 0 replies; 46+ messages in thread
From: Richard Acayan @ 2023-01-27 23:39 UTC (permalink / raw)
  To: Srinivas Kandagatla; +Cc: gregkh, linux-kernel, Krzysztof Kozlowski

On Fri, Jan 27, 2023 at 11:15:32AM +0000, Srinivas Kandagatla wrote:
> From: Richard Acayan <mailingradian@gmail.com>
>
> There is some configuration in SDM670's QFPROM. Add the compatible for
> it.
>
> Signed-off-by: Richard Acayan <mailingradian@gmail.com>
> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Sorry for only noticing this now, but this was originally Acked-by:

https://lore.kernel.org/linux-arm-msm/5190e9be-1ac8-6ef8-83f1-e6ec0df9e0b7@linaro.org/

> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> ---
>  Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
> index 48cfec0c9ece..b7811bbb0e71 100644
> --- a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
> +++ b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
> @@ -28,6 +28,7 @@ properties:
>            - qcom,sc7180-qfprom
>            - qcom,sc7280-qfprom
>            - qcom,sdm630-qfprom
> +          - qcom,sdm670-qfprom
>            - qcom,sdm845-qfprom
>            - qcom,sm6115-qfprom
>        - const: qcom,qfprom
> -- 
> 2.25.1
>

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

* Re: [PATCH 00/37] nvmem: patches for 6.3
  2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
                   ` (36 preceding siblings ...)
  2023-01-27 11:16 ` [PATCH 37/37] nvmem: stm32: fix OPTEE dependency Srinivas Kandagatla
@ 2023-01-28 13:43 ` Greg KH
  2023-01-30 11:27   ` Srinivas Kandagatla
  37 siblings, 1 reply; 46+ messages in thread
From: Greg KH @ 2023-01-28 13:43 UTC (permalink / raw)
  To: Srinivas Kandagatla; +Cc: linux-kernel

On Fri, Jan 27, 2023 at 11:15:28AM +0000, Srinivas Kandagatla wrote:
> Hi Greg,
> 
> Here are some nvmem patches bit more than usual for 6.3 which includes
> 
> - Adding support for nvmem layouts, thanks to Michael and Miquel for
>   driving this effort.
> - Add support to stm32 STM32MP15x OPTEE based nvmem provider
> - Updated to qfprom bindings to include various Qualcomm SoCs.
> - adding sl28vpd provider layout
> - move imx provider to use new layout apis
> - add ONIE provider layout. 
> - new helper eth_addr_add().
> - few minor enhancements to core and providersdrivers.
> 
> Can you please queue them up for 6.3.

This series does NOT apply to my char-misc-next branch, which is based
on 6.2-rc5.  What did you generate it against?

Can you rebase it and resend?

thanks,

greg k-h

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

* Re: [PATCH 00/37] nvmem: patches for 6.3
  2023-01-28 13:43 ` [PATCH 00/37] nvmem: patches for 6.3 Greg KH
@ 2023-01-30 11:27   ` Srinivas Kandagatla
  2023-01-30 11:59     ` Greg KH
  0 siblings, 1 reply; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-30 11:27 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel



On 28/01/2023 13:43, Greg KH wrote:
> On Fri, Jan 27, 2023 at 11:15:28AM +0000, Srinivas Kandagatla wrote:
>> Hi Greg,
>>
>> Here are some nvmem patches bit more than usual for 6.3 which includes
>>
>> - Adding support for nvmem layouts, thanks to Michael and Miquel for
>>    driving this effort.
>> - Add support to stm32 STM32MP15x OPTEE based nvmem provider
>> - Updated to qfprom bindings to include various Qualcomm SoCs.
>> - adding sl28vpd provider layout
>> - move imx provider to use new layout apis
>> - add ONIE provider layout.
>> - new helper eth_addr_add().
>> - few minor enhancements to core and providersdrivers.
>>
>> Can you please queue them up for 6.3.
> 
> This series does NOT apply to my char-misc-next branch, which is based
> on 6.2-rc5.  What did you generate it against?
> 
These were on top of nvmem-fixes based on 6.2-rc1.


> Can you rebase it and resend?

char-misc-next does not have nvmem-fixes yet, which branch should I 
rebase these on?

thanks,
srini

> 
> thanks,
> 
> greg k-h

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

* Re: [PATCH 00/37] nvmem: patches for 6.3
  2023-01-30 11:27   ` Srinivas Kandagatla
@ 2023-01-30 11:59     ` Greg KH
  2023-01-30 15:54       ` Srinivas Kandagatla
  0 siblings, 1 reply; 46+ messages in thread
From: Greg KH @ 2023-01-30 11:59 UTC (permalink / raw)
  To: Srinivas Kandagatla; +Cc: linux-kernel

On Mon, Jan 30, 2023 at 11:27:06AM +0000, Srinivas Kandagatla wrote:
> 
> 
> On 28/01/2023 13:43, Greg KH wrote:
> > On Fri, Jan 27, 2023 at 11:15:28AM +0000, Srinivas Kandagatla wrote:
> > > Hi Greg,
> > > 
> > > Here are some nvmem patches bit more than usual for 6.3 which includes
> > > 
> > > - Adding support for nvmem layouts, thanks to Michael and Miquel for
> > >    driving this effort.
> > > - Add support to stm32 STM32MP15x OPTEE based nvmem provider
> > > - Updated to qfprom bindings to include various Qualcomm SoCs.
> > > - adding sl28vpd provider layout
> > > - move imx provider to use new layout apis
> > > - add ONIE provider layout.
> > > - new helper eth_addr_add().
> > > - few minor enhancements to core and providersdrivers.
> > > 
> > > Can you please queue them up for 6.3.
> > 
> > This series does NOT apply to my char-misc-next branch, which is based
> > on 6.2-rc5.  What did you generate it against?
> > 
> These were on top of nvmem-fixes based on 6.2-rc1.

Ah, always say that please.

> > Can you rebase it and resend?
> 
> char-misc-next does not have nvmem-fixes yet, which branch should I rebase
> these on?

char-misc-next please.  If there are going to be merge conflicts when
the char-misc-linus branch gets merged into that with these changes,
please let me know.

thanks,

greg k-h

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

* Re: [PATCH 00/37] nvmem: patches for 6.3
  2023-01-30 11:59     ` Greg KH
@ 2023-01-30 15:54       ` Srinivas Kandagatla
  2023-02-06  7:45         ` Greg KH
  0 siblings, 1 reply; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-01-30 15:54 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel



On 30/01/2023 11:59, Greg KH wrote:
> On Mon, Jan 30, 2023 at 11:27:06AM +0000, Srinivas Kandagatla wrote:
>>
>>
>> On 28/01/2023 13:43, Greg KH wrote:
>>> On Fri, Jan 27, 2023 at 11:15:28AM +0000, Srinivas Kandagatla wrote:
>>>> Hi Greg,
>>>>
>>>> Here are some nvmem patches bit more than usual for 6.3 which includes
>>>>
>>>> - Adding support for nvmem layouts, thanks to Michael and Miquel for
>>>>     driving this effort.
>>>> - Add support to stm32 STM32MP15x OPTEE based nvmem provider
>>>> - Updated to qfprom bindings to include various Qualcomm SoCs.
>>>> - adding sl28vpd provider layout
>>>> - move imx provider to use new layout apis
>>>> - add ONIE provider layout.
>>>> - new helper eth_addr_add().
>>>> - few minor enhancements to core and providersdrivers.
>>>>
>>>> Can you please queue them up for 6.3.
>>>
>>> This series does NOT apply to my char-misc-next branch, which is based
>>> on 6.2-rc5.  What did you generate it against?
>>>
>> These were on top of nvmem-fixes based on 6.2-rc1.
> 
> Ah, always say that please.
My bad, I assumed that fixes will be applied and then these patches. But 
I should have mentioned this clearly.

> 
>>> Can you rebase it and resend?
>>
>> char-misc-next does not have nvmem-fixes yet, which branch should I rebase
>> these on?
> 
> char-misc-next please.  If there are going to be merge conflicts when
> the char-misc-linus branch gets merged into that with these changes, > please let me know.

Yes, for sure this is going to conflict. some of the patches in this set 
are on top of fixes.


--srini


> 
> thanks,
> 
> greg k-h

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

* Re: [PATCH 00/37] nvmem: patches for 6.3
  2023-01-30 15:54       ` Srinivas Kandagatla
@ 2023-02-06  7:45         ` Greg KH
  2023-02-06  7:46           ` Greg KH
  0 siblings, 1 reply; 46+ messages in thread
From: Greg KH @ 2023-02-06  7:45 UTC (permalink / raw)
  To: Srinivas Kandagatla; +Cc: linux-kernel

On Mon, Jan 30, 2023 at 03:54:58PM +0000, Srinivas Kandagatla wrote:
> 
> 
> On 30/01/2023 11:59, Greg KH wrote:
> > On Mon, Jan 30, 2023 at 11:27:06AM +0000, Srinivas Kandagatla wrote:
> > > 
> > > 
> > > On 28/01/2023 13:43, Greg KH wrote:
> > > > On Fri, Jan 27, 2023 at 11:15:28AM +0000, Srinivas Kandagatla wrote:
> > > > > Hi Greg,
> > > > > 
> > > > > Here are some nvmem patches bit more than usual for 6.3 which includes
> > > > > 
> > > > > - Adding support for nvmem layouts, thanks to Michael and Miquel for
> > > > >     driving this effort.
> > > > > - Add support to stm32 STM32MP15x OPTEE based nvmem provider
> > > > > - Updated to qfprom bindings to include various Qualcomm SoCs.
> > > > > - adding sl28vpd provider layout
> > > > > - move imx provider to use new layout apis
> > > > > - add ONIE provider layout.
> > > > > - new helper eth_addr_add().
> > > > > - few minor enhancements to core and providersdrivers.
> > > > > 
> > > > > Can you please queue them up for 6.3.
> > > > 
> > > > This series does NOT apply to my char-misc-next branch, which is based
> > > > on 6.2-rc5.  What did you generate it against?
> > > > 
> > > These were on top of nvmem-fixes based on 6.2-rc1.
> > 
> > Ah, always say that please.
> My bad, I assumed that fixes will be applied and then these patches. But I
> should have mentioned this clearly.
> 
> > 
> > > > Can you rebase it and resend?
> > > 
> > > char-misc-next does not have nvmem-fixes yet, which branch should I rebase
> > > these on?
> > 
> > char-misc-next please.  If there are going to be merge conflicts when
> > the char-misc-linus branch gets merged into that with these changes, > please let me know.
> 
> Yes, for sure this is going to conflict. some of the patches in this set are
> on top of fixes.

Ok, now that the char-misc-linus branch is merged into my -next branch,
I've applied these.

thanks,

greg k-h

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

* Re: [PATCH 00/37] nvmem: patches for 6.3
  2023-02-06  7:45         ` Greg KH
@ 2023-02-06  7:46           ` Greg KH
  2023-02-06 10:13             ` Srinivas Kandagatla
  0 siblings, 1 reply; 46+ messages in thread
From: Greg KH @ 2023-02-06  7:46 UTC (permalink / raw)
  To: Srinivas Kandagatla; +Cc: linux-kernel

On Mon, Feb 06, 2023 at 08:45:29AM +0100, Greg KH wrote:
> On Mon, Jan 30, 2023 at 03:54:58PM +0000, Srinivas Kandagatla wrote:
> > 
> > 
> > On 30/01/2023 11:59, Greg KH wrote:
> > > On Mon, Jan 30, 2023 at 11:27:06AM +0000, Srinivas Kandagatla wrote:
> > > > 
> > > > 
> > > > On 28/01/2023 13:43, Greg KH wrote:
> > > > > On Fri, Jan 27, 2023 at 11:15:28AM +0000, Srinivas Kandagatla wrote:
> > > > > > Hi Greg,
> > > > > > 
> > > > > > Here are some nvmem patches bit more than usual for 6.3 which includes
> > > > > > 
> > > > > > - Adding support for nvmem layouts, thanks to Michael and Miquel for
> > > > > >     driving this effort.
> > > > > > - Add support to stm32 STM32MP15x OPTEE based nvmem provider
> > > > > > - Updated to qfprom bindings to include various Qualcomm SoCs.
> > > > > > - adding sl28vpd provider layout
> > > > > > - move imx provider to use new layout apis
> > > > > > - add ONIE provider layout.
> > > > > > - new helper eth_addr_add().
> > > > > > - few minor enhancements to core and providersdrivers.
> > > > > > 
> > > > > > Can you please queue them up for 6.3.
> > > > > 
> > > > > This series does NOT apply to my char-misc-next branch, which is based
> > > > > on 6.2-rc5.  What did you generate it against?
> > > > > 
> > > > These were on top of nvmem-fixes based on 6.2-rc1.
> > > 
> > > Ah, always say that please.
> > My bad, I assumed that fixes will be applied and then these patches. But I
> > should have mentioned this clearly.
> > 
> > > 
> > > > > Can you rebase it and resend?
> > > > 
> > > > char-misc-next does not have nvmem-fixes yet, which branch should I rebase
> > > > these on?
> > > 
> > > char-misc-next please.  If there are going to be merge conflicts when
> > > the char-misc-linus branch gets merged into that with these changes, > please let me know.
> > 
> > Yes, for sure this is going to conflict. some of the patches in this set are
> > on top of fixes.
> 
> Ok, now that the char-misc-linus branch is merged into my -next branch,
> I've applied these.

Nope, lots of errors:

Commit: b4fee523c0d7 ("nvmem: stm32: fix OPTEE dependency")
	Fixes tag: Fixes: ae46fd89cc0cc ("nvmem: stm32: add OP-TEE support for STM32MP13x")
	Has these problem(s):
		- Target SHA1 does not exist
Commit: b6dc9d9a156a ("of: property: fix #nvmem-cell-cells parsing")
	Fixes tag: Fixes: 6a80b3e6fb41 ("of: property: make #.*-cells optional for simple props")
	Has these problem(s):
		- Target SHA1 does not exist
Commit: 57a71161cecb ("nvmem: core: fix nvmem_layout_get_match_data()")
	Fixes tag: Fixes: f61a093b4a0e ("nvmem: core: introduce NVMEM layouts")
	Has these problem(s):
		- Target SHA1 does not exist
Commit: 8e1cd6f05f71 ("nvmem: core: return -ENOENT if nvmem cell is not found")
	Fixes tag: Fixes: e894d5ad177c ("nvmem: core: add an index parameter to the cell")
	Has these problem(s):
		- Target SHA1 does not exist


Can you please fix this up and resend?

thanks,

greg k-h

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

* Re: [PATCH 00/37] nvmem: patches for 6.3
  2023-02-06  7:46           ` Greg KH
@ 2023-02-06 10:13             ` Srinivas Kandagatla
  0 siblings, 0 replies; 46+ messages in thread
From: Srinivas Kandagatla @ 2023-02-06 10:13 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel



On 06/02/2023 07:46, Greg KH wrote:
> On Mon, Feb 06, 2023 at 08:45:29AM +0100, Greg KH wrote:
>> On Mon, Jan 30, 2023 at 03:54:58PM +0000, Srinivas Kandagatla wrote:
>>>
>>>
>>> On 30/01/2023 11:59, Greg KH wrote:
>>>> On Mon, Jan 30, 2023 at 11:27:06AM +0000, Srinivas Kandagatla wrote:
>>>>>
>>>>>
>>>>> On 28/01/2023 13:43, Greg KH wrote:
>>>>>> On Fri, Jan 27, 2023 at 11:15:28AM +0000, Srinivas Kandagatla wrote:
>>>>>>> Hi Greg,
>>>>>>>
>>>>>>> Here are some nvmem patches bit more than usual for 6.3 which includes
>>>>>>>
>>>>>>> - Adding support for nvmem layouts, thanks to Michael and Miquel for
>>>>>>>      driving this effort.
>>>>>>> - Add support to stm32 STM32MP15x OPTEE based nvmem provider
>>>>>>> - Updated to qfprom bindings to include various Qualcomm SoCs.
>>>>>>> - adding sl28vpd provider layout
>>>>>>> - move imx provider to use new layout apis
>>>>>>> - add ONIE provider layout.
>>>>>>> - new helper eth_addr_add().
>>>>>>> - few minor enhancements to core and providersdrivers.
>>>>>>>
>>>>>>> Can you please queue them up for 6.3.
>>>>>>
>>>>>> This series does NOT apply to my char-misc-next branch, which is based
>>>>>> on 6.2-rc5.  What did you generate it against?
>>>>>>
>>>>> These were on top of nvmem-fixes based on 6.2-rc1.
>>>>
>>>> Ah, always say that please.
>>> My bad, I assumed that fixes will be applied and then these patches. But I
>>> should have mentioned this clearly.
>>>
>>>>
>>>>>> Can you rebase it and resend?
>>>>>
>>>>> char-misc-next does not have nvmem-fixes yet, which branch should I rebase
>>>>> these on?
>>>>
>>>> char-misc-next please.  If there are going to be merge conflicts when
>>>> the char-misc-linus branch gets merged into that with these changes, > please let me know.
>>>
>>> Yes, for sure this is going to conflict. some of the patches in this set are
>>> on top of fixes.
>>
>> Ok, now that the char-misc-linus branch is merged into my -next branch,
>> I've applied these.
> 
> Nope, lots of errors:
> 
> Commit: b4fee523c0d7 ("nvmem: stm32: fix OPTEE dependency")
> 	Fixes tag: Fixes: ae46fd89cc0cc ("nvmem: stm32: add OP-TEE support for STM32MP13x")
> 	Has these problem(s):
> 		- Target SHA1 does not exist
> Commit: b6dc9d9a156a ("of: property: fix #nvmem-cell-cells parsing")
> 	Fixes tag: Fixes: 6a80b3e6fb41 ("of: property: make #.*-cells optional for simple props")
> 	Has these problem(s):
> 		- Target SHA1 does not exist
> Commit: 57a71161cecb ("nvmem: core: fix nvmem_layout_get_match_data()")
> 	Fixes tag: Fixes: f61a093b4a0e ("nvmem: core: introduce NVMEM layouts")
> 	Has these problem(s):
> 		- Target SHA1 does not exist
> Commit: 8e1cd6f05f71 ("nvmem: core: return -ENOENT if nvmem cell is not found")
> 	Fixes tag: Fixes: e894d5ad177c ("nvmem: core: add an index parameter to the cell")
> 	Has these problem(s):
> 		- Target SHA1 does not exist
> 
> 
> Can you please fix this up and resend?
> 
thanks Greg for trying out.
Sure, will rebase on top of char-misc-next

--srini
> thanks,
> 
> greg k-h

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

end of thread, other threads:[~2023-02-06 10:14 UTC | newest]

Thread overview: 46+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 01/37] nvmem: sunxi_sid: Drop the workaround on A64 Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 02/37] dt-bindings: nvmem: Fix qcom,qfprom compatibles enum ordering Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 03/37] dt-bindings: nvmem: Add compatible for MSM8976 Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 04/37] dt-bindings: nvmem: qfprom: add sdm670 compatible Srinivas Kandagatla
2023-01-27 23:39   ` Richard Acayan
2023-01-27 11:15 ` [PATCH 05/37] dt-bindings: nvmem: Add compatible for SM8150 Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 06/37] dt-bindings: nvmem: Add compatible for SM8250 Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 07/37] nvmem: core: remove spurious white space Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 08/37] net: add helper eth_addr_add() Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 09/37] of: base: add of_parse_phandle_with_optional_args() Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 10/37] of: property: make #.*-cells optional for simple props Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 11/37] of: property: add #nvmem-cell-cells property Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 12/37] nvmem: core: add an index parameter to the cell Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 13/37] nvmem: core: move struct nvmem_cell_info to nvmem-provider.h Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 14/37] nvmem: core: drop the removal of the cells in nvmem_add_cells() Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 15/37] nvmem: core: add nvmem_add_one_cell() Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 16/37] nvmem: core: use nvmem_add_one_cell() in nvmem_add_cells_from_of() Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 17/37] nvmem: core: introduce NVMEM layouts Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 18/37] nvmem: core: add per-cell post processing Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 19/37] nvmem: core: allow to modify a cell before adding it Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 20/37] nvmem: imx-ocotp: replace global post processing with layouts Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 21/37] nvmem: cell: drop global cell_post_process Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 22/37] nvmem: core: provide own priv pointer in post process callback Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 23/37] nvmem: layouts: add sl28vpd layout Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 24/37] MAINTAINERS: add myself as sl28vpd nvmem layout driver Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 25/37] nvmem: layouts: Add ONIE tlv " Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 26/37] MAINTAINERS: Add myself as ONIE tlv NVMEM layout maintainer Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 27/37] nvmem: core: return -ENOENT if nvmem cell is not found Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 28/37] nvmem: layouts: Fix spelling mistake "platforn" -> "platform" Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 29/37] dt-bindings: nvmem: " Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 30/37] nvmem: core: fix nvmem_layout_get_match_data() Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 31/37] nvmem: stm32: add OP-TEE support for STM32MP13x Srinivas Kandagatla
2023-01-27 11:16 ` [PATCH 32/37] nvmem: stm32: detect bsec pta presence for STM32MP15x Srinivas Kandagatla
2023-01-27 11:16 ` [PATCH 33/37] nvmem: rave-sp-eeprm: fix kernel-doc bad line warning Srinivas Kandagatla
2023-01-27 11:16 ` [PATCH 34/37] of: property: fix #nvmem-cell-cells parsing Srinivas Kandagatla
2023-01-27 11:16 ` [PATCH 35/37] nvmem: qcom-spmi-sdam: register at device init time Srinivas Kandagatla
2023-01-27 11:16 ` [PATCH 36/37] dt-bindings: nvmem: qfprom: add IPQ8074 compatible Srinivas Kandagatla
2023-01-27 11:16 ` [PATCH 37/37] nvmem: stm32: fix OPTEE dependency Srinivas Kandagatla
2023-01-28 13:43 ` [PATCH 00/37] nvmem: patches for 6.3 Greg KH
2023-01-30 11:27   ` Srinivas Kandagatla
2023-01-30 11:59     ` Greg KH
2023-01-30 15:54       ` Srinivas Kandagatla
2023-02-06  7:45         ` Greg KH
2023-02-06  7:46           ` Greg KH
2023-02-06 10:13             ` Srinivas Kandagatla

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.