All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/10] nvmem: patches (set 1) for 5.13
@ 2021-03-30 11:12 Srinivas Kandagatla
  2021-03-30 11:12 ` [PATCH 01/10] dt-bindings: nvmem: mediatek: add support for MediaTek mt8192 SoC Srinivas Kandagatla
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Srinivas Kandagatla @ 2021-03-30 11:12 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Srinivas Kandagatla

Hi Greg,

Here are some nvmem patches for 5.13 which includes
- adding support to new Broadcom NVRAM, MediaTek mt8192,
 Qualcomm sc7280 nvmem provider
- Add new function to make numbers reading easy
- Update qfprom to support fuse blowing!
- few minor fixes.

Can you please queue them up for 5.13.

thanks for you help,
srini

Colin Ian King (1):
  nvmem: core: Fix unintentional sign extension issue

Douglas Anderson (1):
  nvmem: core: Add functions to make number reading easy

Rafał Miłecki (2):
  dt-bindings: nvmem: add Broadcom's NVRAM
  nvmem: brcm_nvram: new driver exposing Broadcom's NVRAM

Rajendra Nayak (2):
  dt-bindings: nvmem: Add SoC compatible for sc7280
  nvmem: qfprom: Add support for fuse blowing on sc7280

Ravi Kumar Bokka (1):
  drivers: nvmem: Fix voltage settings for QTI qfprom-efuse

Ryan Wu (1):
  dt-bindings: nvmem: mediatek: add support for MediaTek mt8192 SoC

Srinivas Kandagatla (1):
  nvmem: rmem: fix undefined reference to memremap

Zheng Yongjun (1):
  nvmem: convert comma to semicolon

 .../devicetree/bindings/nvmem/brcm,nvram.yaml | 34 +++++++
 .../devicetree/bindings/nvmem/mtk-efuse.txt   |  1 +
 .../bindings/nvmem/qcom,qfprom.yaml           |  1 +
 drivers/nvmem/Kconfig                         | 10 ++
 drivers/nvmem/Makefile                        |  2 +
 drivers/nvmem/brcm_nvram.c                    | 78 +++++++++++++++
 drivers/nvmem/core.c                          | 95 +++++++++++++++++++
 drivers/nvmem/qcom-spmi-sdam.c                |  2 +-
 drivers/nvmem/qfprom.c                        | 44 +++++++++
 drivers/nvmem/snvs_lpgpr.c                    |  2 +-
 include/linux/nvmem-consumer.h                |  4 +
 11 files changed, 271 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
 create mode 100644 drivers/nvmem/brcm_nvram.c

-- 
2.21.0


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

* [PATCH 01/10] dt-bindings: nvmem: mediatek: add support for MediaTek mt8192 SoC
  2021-03-30 11:12 [PATCH 00/10] nvmem: patches (set 1) for 5.13 Srinivas Kandagatla
@ 2021-03-30 11:12 ` Srinivas Kandagatla
  2021-03-30 11:12 ` [PATCH 02/10] nvmem: convert comma to semicolon Srinivas Kandagatla
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Srinivas Kandagatla @ 2021-03-30 11:12 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Ryan Wu, Rob Herring, Srinivas Kandagatla

From: Ryan Wu <Yz.Wu@mediatek.com>

This updates dt-binding documentation for MediaTek mt8192

Signed-off-by: Ryan Wu <Yz.Wu@mediatek.com>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 Documentation/devicetree/bindings/nvmem/mtk-efuse.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/nvmem/mtk-efuse.txt b/Documentation/devicetree/bindings/nvmem/mtk-efuse.txt
index ef93c3b95424..2f2895b1f06d 100644
--- a/Documentation/devicetree/bindings/nvmem/mtk-efuse.txt
+++ b/Documentation/devicetree/bindings/nvmem/mtk-efuse.txt
@@ -8,6 +8,7 @@ Required properties:
 	      "mediatek,mt7623-efuse", "mediatek,efuse": for MT7623
 	      "mediatek,mt8173-efuse" or "mediatek,efuse": for MT8173
 	      "mediatek,mt8516-efuse", "mediatek,efuse": for MT8516
+	      "mediatek,mt8192-efuse", "mediatek,efuse": for MT8192
 - reg: Should contain registers location and length
 
 = Data cells =
-- 
2.21.0


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

* [PATCH 02/10] nvmem: convert comma to semicolon
  2021-03-30 11:12 [PATCH 00/10] nvmem: patches (set 1) for 5.13 Srinivas Kandagatla
  2021-03-30 11:12 ` [PATCH 01/10] dt-bindings: nvmem: mediatek: add support for MediaTek mt8192 SoC Srinivas Kandagatla
@ 2021-03-30 11:12 ` Srinivas Kandagatla
  2021-03-30 11:12 ` [PATCH 03/10] drivers: nvmem: Fix voltage settings for QTI qfprom-efuse Srinivas Kandagatla
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Srinivas Kandagatla @ 2021-03-30 11:12 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Zheng Yongjun, Bjorn Andersson, Srinivas Kandagatla

From: Zheng Yongjun <zhengyongjun3@huawei.com>

Replace a comma between expression statements by a semicolon.

Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/qcom-spmi-sdam.c | 2 +-
 drivers/nvmem/snvs_lpgpr.c     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/nvmem/qcom-spmi-sdam.c b/drivers/nvmem/qcom-spmi-sdam.c
index f6e9f96933ca..4fcb63507ecd 100644
--- a/drivers/nvmem/qcom-spmi-sdam.c
+++ b/drivers/nvmem/qcom-spmi-sdam.c
@@ -141,7 +141,7 @@ static int sdam_probe(struct platform_device *pdev)
 	sdam->sdam_config.dev = &pdev->dev;
 	sdam->sdam_config.name = "spmi_sdam";
 	sdam->sdam_config.id = NVMEM_DEVID_AUTO;
-	sdam->sdam_config.owner = THIS_MODULE,
+	sdam->sdam_config.owner = THIS_MODULE;
 	sdam->sdam_config.stride = 1;
 	sdam->sdam_config.word_size = 1;
 	sdam->sdam_config.reg_read = sdam_read;
diff --git a/drivers/nvmem/snvs_lpgpr.c b/drivers/nvmem/snvs_lpgpr.c
index c527d26ca6ac..4692aa985bd6 100644
--- a/drivers/nvmem/snvs_lpgpr.c
+++ b/drivers/nvmem/snvs_lpgpr.c
@@ -123,7 +123,7 @@ static int snvs_lpgpr_probe(struct platform_device *pdev)
 	cfg->dev = dev;
 	cfg->stride = 4;
 	cfg->word_size = 4;
-	cfg->size = dcfg->size,
+	cfg->size = dcfg->size;
 	cfg->owner = THIS_MODULE;
 	cfg->reg_read  = snvs_lpgpr_read;
 	cfg->reg_write = snvs_lpgpr_write;
-- 
2.21.0


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

* [PATCH 03/10] drivers: nvmem: Fix voltage settings for QTI qfprom-efuse
  2021-03-30 11:12 [PATCH 00/10] nvmem: patches (set 1) for 5.13 Srinivas Kandagatla
  2021-03-30 11:12 ` [PATCH 01/10] dt-bindings: nvmem: mediatek: add support for MediaTek mt8192 SoC Srinivas Kandagatla
  2021-03-30 11:12 ` [PATCH 02/10] nvmem: convert comma to semicolon Srinivas Kandagatla
@ 2021-03-30 11:12 ` Srinivas Kandagatla
  2021-03-30 11:12 ` [PATCH 04/10] dt-bindings: nvmem: add Broadcom's NVRAM Srinivas Kandagatla
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Srinivas Kandagatla @ 2021-03-30 11:12 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, Ravi Kumar Bokka, Douglas Anderson, Srinivas Kandagatla

From: Ravi Kumar Bokka <rbokka@codeaurora.org>

QFPROM controller hardware requires 1.8V min for fuse blowing.
So, this change sets the voltage to 1.8V, required to blow the fuse
for qfprom-efuse controller.

To disable fuse blowing, we set the voltage to 0V since this may
be a shared rail and may be able to run at a lower rate when we're
not blowing fuses.

Fixes: 93b4e49f8c86 ("nvmem: qfprom: Add fuse blowing support")
Reported-by: Douglas Anderson <dianders@chromium.org>
Suggested-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Ravi Kumar Bokka <rbokka@codeaurora.org>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/qfprom.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/nvmem/qfprom.c b/drivers/nvmem/qfprom.c
index 6cace24dfbf7..100d69d8f2e1 100644
--- a/drivers/nvmem/qfprom.c
+++ b/drivers/nvmem/qfprom.c
@@ -127,6 +127,16 @@ static void qfprom_disable_fuse_blowing(const struct qfprom_priv *priv,
 {
 	int ret;
 
+	/*
+	 * This may be a shared rail and may be able to run at a lower rate
+	 * when we're not blowing fuses.  At the moment, the regulator framework
+	 * applies voltage constraints even on disabled rails, so remove our
+	 * constraints and allow the rail to be adjusted by other users.
+	 */
+	ret = regulator_set_voltage(priv->vcc, 0, INT_MAX);
+	if (ret)
+		dev_warn(priv->dev, "Failed to set 0 voltage (ignoring)\n");
+
 	ret = regulator_disable(priv->vcc);
 	if (ret)
 		dev_warn(priv->dev, "Failed to disable regulator (ignoring)\n");
@@ -172,6 +182,17 @@ static int qfprom_enable_fuse_blowing(const struct qfprom_priv *priv,
 		goto err_clk_prepared;
 	}
 
+	/*
+	 * Hardware requires 1.8V min for fuse blowing; this may be
+	 * a rail shared do don't specify a max--regulator constraints
+	 * will handle.
+	 */
+	ret = regulator_set_voltage(priv->vcc, 1800000, INT_MAX);
+	if (ret) {
+		dev_err(priv->dev, "Failed to set 1.8 voltage\n");
+		goto err_clk_rate_set;
+	}
+
 	ret = regulator_enable(priv->vcc);
 	if (ret) {
 		dev_err(priv->dev, "Failed to enable regulator\n");
-- 
2.21.0


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

* [PATCH 04/10] dt-bindings: nvmem: add Broadcom's NVRAM
  2021-03-30 11:12 [PATCH 00/10] nvmem: patches (set 1) for 5.13 Srinivas Kandagatla
                   ` (2 preceding siblings ...)
  2021-03-30 11:12 ` [PATCH 03/10] drivers: nvmem: Fix voltage settings for QTI qfprom-efuse Srinivas Kandagatla
@ 2021-03-30 11:12 ` Srinivas Kandagatla
  2021-03-30 11:12 ` [PATCH 05/10] nvmem: brcm_nvram: new driver exposing " Srinivas Kandagatla
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Srinivas Kandagatla @ 2021-03-30 11:12 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, Rafał Miłecki, Rob Herring, Srinivas Kandagatla

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

Broadcom's NVRAM structure contains device data and can be accessed
using I/O mapping.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 .../devicetree/bindings/nvmem/brcm,nvram.yaml | 34 +++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml

diff --git a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
new file mode 100644
index 000000000000..58ff6b0bdb1a
--- /dev/null
+++ b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
@@ -0,0 +1,34 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/nvmem/brcm,nvram.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Broadcom's NVRAM
+
+description: |
+  Broadcom's NVRAM is a structure containing device specific environment
+  variables. It is used for storing device configuration, booting parameters
+  and calibration data.
+
+  NVRAM can be accessed on Broadcom BCM47xx MIPS and Northstar ARM Cortex-A9
+  devices usiong I/O mapped memory.
+
+maintainers:
+  - Rafał Miłecki <rafal@milecki.pl>
+
+allOf:
+  - $ref: "nvmem.yaml#"
+
+properties:
+  compatible:
+    const: brcm,nvram
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    nvram@1eff0000 {
+            compatible = "brcm,nvram";
+            reg = <0x1eff0000 0x10000>;
+    };
-- 
2.21.0


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

* [PATCH 05/10] nvmem: brcm_nvram: new driver exposing Broadcom's NVRAM
  2021-03-30 11:12 [PATCH 00/10] nvmem: patches (set 1) for 5.13 Srinivas Kandagatla
                   ` (3 preceding siblings ...)
  2021-03-30 11:12 ` [PATCH 04/10] dt-bindings: nvmem: add Broadcom's NVRAM Srinivas Kandagatla
@ 2021-03-30 11:12 ` Srinivas Kandagatla
  2021-03-30 11:12 ` [PATCH 06/10] nvmem: core: Add functions to make number reading easy Srinivas Kandagatla
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Srinivas Kandagatla @ 2021-03-30 11:12 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Rafał Miłecki, Srinivas Kandagatla

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

This driver provides access to Broadcom's NVRAM.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/Kconfig      |  9 +++++
 drivers/nvmem/Makefile     |  2 +
 drivers/nvmem/brcm_nvram.c | 78 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 89 insertions(+)
 create mode 100644 drivers/nvmem/brcm_nvram.c

diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index 75d2594c16e1..642ddc699fd1 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -278,4 +278,13 @@ config NVMEM_RMEM
 
 	  This driver can also be built as a module. If so, the module
 	  will be called nvmem-rmem.
+
+config NVMEM_BRCM_NVRAM
+	tristate "Broadcom's NVRAM support"
+	depends on ARCH_BCM_5301X || COMPILE_TEST
+	depends on HAS_IOMEM
+	help
+	  This driver provides support for Broadcom's NVRAM that can be accessed
+	  using I/O mapping.
+
 endif
diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
index 5376b8e0dae5..bbea1410240a 100644
--- a/drivers/nvmem/Makefile
+++ b/drivers/nvmem/Makefile
@@ -57,3 +57,5 @@ obj-$(CONFIG_SPRD_EFUSE)	+= nvmem_sprd_efuse.o
 nvmem_sprd_efuse-y		:= sprd-efuse.o
 obj-$(CONFIG_NVMEM_RMEM) 	+= nvmem-rmem.o
 nvmem-rmem-y			:= rmem.o
+obj-$(CONFIG_NVMEM_BRCM_NVRAM)	+= nvmem_brcm_nvram.o
+nvmem_brcm_nvram-y		:= brcm_nvram.o
diff --git a/drivers/nvmem/brcm_nvram.c b/drivers/nvmem/brcm_nvram.c
new file mode 100644
index 000000000000..bd2ecaaf4585
--- /dev/null
+++ b/drivers/nvmem/brcm_nvram.c
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2021 Rafał Miłecki <rafal@milecki.pl>
+ */
+
+#include <linux/io.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/nvmem-provider.h>
+#include <linux/platform_device.h>
+
+struct brcm_nvram {
+	struct device *dev;
+	void __iomem *base;
+};
+
+static int brcm_nvram_read(void *context, unsigned int offset, void *val,
+			   size_t bytes)
+{
+	struct brcm_nvram *priv = context;
+	u8 *dst = val;
+
+	while (bytes--)
+		*dst++ = readb(priv->base + offset++);
+
+	return 0;
+}
+
+static int brcm_nvram_probe(struct platform_device *pdev)
+{
+	struct nvmem_config config = {
+		.name = "brcm-nvram",
+		.reg_read = brcm_nvram_read,
+	};
+	struct device *dev = &pdev->dev;
+	struct resource *res;
+	struct brcm_nvram *priv;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+	priv->dev = dev;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	priv->base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(priv->base))
+		return PTR_ERR(priv->base);
+
+	config.dev = dev;
+	config.priv = priv;
+	config.size = resource_size(res);
+
+	return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &config));
+}
+
+static const struct of_device_id brcm_nvram_of_match_table[] = {
+	{ .compatible = "brcm,nvram", },
+	{},
+};
+
+static struct platform_driver brcm_nvram_driver = {
+	.probe = brcm_nvram_probe,
+	.driver = {
+		.name = "brcm_nvram",
+		.of_match_table = brcm_nvram_of_match_table,
+	},
+};
+
+static int __init brcm_nvram_init(void)
+{
+	return platform_driver_register(&brcm_nvram_driver);
+}
+
+subsys_initcall_sync(brcm_nvram_init);
+
+MODULE_AUTHOR("Rafał Miłecki");
+MODULE_LICENSE("GPL");
+MODULE_DEVICE_TABLE(of, brcm_nvram_of_match_table);
-- 
2.21.0


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

* [PATCH 06/10] nvmem: core: Add functions to make number reading easy
  2021-03-30 11:12 [PATCH 00/10] nvmem: patches (set 1) for 5.13 Srinivas Kandagatla
                   ` (4 preceding siblings ...)
  2021-03-30 11:12 ` [PATCH 05/10] nvmem: brcm_nvram: new driver exposing " Srinivas Kandagatla
@ 2021-03-30 11:12 ` Srinivas Kandagatla
  2021-03-30 11:12 ` [PATCH 07/10] nvmem: core: Fix unintentional sign extension issue Srinivas Kandagatla
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Srinivas Kandagatla @ 2021-03-30 11:12 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Douglas Anderson, Srinivas Kandagatla

From: Douglas Anderson <dianders@chromium.org>

Sometimes the clients of nvmem just want to get a number out of
nvmem. They don't want to think about exactly how many bytes the nvmem
cell took up. They just want the number. Let's make it easy.

In general this concept is useful because nvmem space is precious and
usually the fewest bits are allocated that will hold a given value on
a given system. However, even though small numbers might be fine on
one system that doesn't mean that logically the number couldn't be
bigger. Imagine nvmem containing a max frequency for a component. On
one system perhaps that fits in 16 bits. On another system it might
fit in 32 bits. The code reading this number doesn't care--it just
wants the number.

We'll provide two functions: nvmem_cell_read_variable_le_u32() and
nvmem_cell_read_variable_le_u64().

Comparing these to the existing functions like nvmem_cell_read_u32():
* These new functions have no problems if the value was stored in
  nvmem in fewer bytes. It's OK to use these function as long as the
  value stored will fit in 32-bits (or 64-bits).
* These functions avoid problems that the earlier APIs had with bit
  offsets. For instance, you can't use nvmem_cell_read_u32() to read a
  value has nbits=32 and bit_offset=4 because the nvmem cell must be
  at least 5 bytes big to hold this value. The new API accounts for
  this and works fine.
* These functions make it very explicit that they assume that the
  number was stored in little endian format. The old functions made
  this assumption whenever bit_offset was non-zero (see
  nvmem_shift_read_buffer_in_place()) but didn't whenever the
  bit_offset was zero.

NOTE: it's assumed that we don't need an 8-bit or 16-bit version of
this function. The 32-bit version of the function can be used to read
8-bit or 16-bit data.

At the moment, I'm only adding the "unsigned" versions of these
functions, but if it ends up being useful someone could add a "signed"
version that did 2's complement sign extension.

At the moment, I'm only adding the "little endian" versions of these
functions. Adding the "big endian" version would require adding "big
endian" support to nvmem_shift_read_buffer_in_place().

Signed-off-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/core.c           | 95 ++++++++++++++++++++++++++++++++++
 include/linux/nvmem-consumer.h |  4 ++
 2 files changed, 99 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index a5ab1e0c74cf..635e3131eb5f 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -1606,6 +1606,101 @@ int nvmem_cell_read_u64(struct device *dev, const char *cell_id, u64 *val)
 }
 EXPORT_SYMBOL_GPL(nvmem_cell_read_u64);
 
+static void *nvmem_cell_read_variable_common(struct device *dev,
+					     const char *cell_id,
+					     size_t max_len, size_t *len)
+{
+	struct nvmem_cell *cell;
+	int nbits;
+	void *buf;
+
+	cell = nvmem_cell_get(dev, cell_id);
+	if (IS_ERR(cell))
+		return cell;
+
+	nbits = cell->nbits;
+	buf = nvmem_cell_read(cell, len);
+	nvmem_cell_put(cell);
+	if (IS_ERR(buf))
+		return buf;
+
+	/*
+	 * If nbits is set then nvmem_cell_read() can significantly exaggerate
+	 * the length of the real data. Throw away the extra junk.
+	 */
+	if (nbits)
+		*len = DIV_ROUND_UP(nbits, 8);
+
+	if (*len > max_len) {
+		kfree(buf);
+		return ERR_PTR(-ERANGE);
+	}
+
+	return buf;
+}
+
+/**
+ * nvmem_cell_read_variable_le_u32() - Read up to 32-bits of data as a little endian number.
+ *
+ * @dev: Device that requests the nvmem cell.
+ * @cell_id: Name of nvmem cell to read.
+ * @val: pointer to output value.
+ *
+ * Return: 0 on success or negative errno.
+ */
+int nvmem_cell_read_variable_le_u32(struct device *dev, const char *cell_id,
+				    u32 *val)
+{
+	size_t len;
+	u8 *buf;
+	int i;
+
+	buf = nvmem_cell_read_variable_common(dev, cell_id, sizeof(*val), &len);
+	if (IS_ERR(buf))
+		return PTR_ERR(buf);
+
+	/* Copy w/ implicit endian conversion */
+	*val = 0;
+	for (i = 0; i < len; i++)
+		*val |= buf[i] << (8 * i);
+
+	kfree(buf);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(nvmem_cell_read_variable_le_u32);
+
+/**
+ * nvmem_cell_read_variable_le_u64() - Read up to 64-bits of data as a little endian number.
+ *
+ * @dev: Device that requests the nvmem cell.
+ * @cell_id: Name of nvmem cell to read.
+ * @val: pointer to output value.
+ *
+ * Return: 0 on success or negative errno.
+ */
+int nvmem_cell_read_variable_le_u64(struct device *dev, const char *cell_id,
+				    u64 *val)
+{
+	size_t len;
+	u8 *buf;
+	int i;
+
+	buf = nvmem_cell_read_variable_common(dev, cell_id, sizeof(*val), &len);
+	if (IS_ERR(buf))
+		return PTR_ERR(buf);
+
+	/* Copy w/ implicit endian conversion */
+	*val = 0;
+	for (i = 0; i < len; i++)
+		*val |= buf[i] << (8 * i);
+
+	kfree(buf);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(nvmem_cell_read_variable_le_u64);
+
 /**
  * nvmem_device_cell_read() - Read a given nvmem device and cell
  *
diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h
index 052293f4cbdb..923dada24eb4 100644
--- a/include/linux/nvmem-consumer.h
+++ b/include/linux/nvmem-consumer.h
@@ -65,6 +65,10 @@ int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val);
 int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val);
 int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val);
 int nvmem_cell_read_u64(struct device *dev, const char *cell_id, u64 *val);
+int nvmem_cell_read_variable_le_u32(struct device *dev, const char *cell_id,
+				    u32 *val);
+int nvmem_cell_read_variable_le_u64(struct device *dev, const char *cell_id,
+				    u64 *val);
 
 /* direct nvmem device read/write interface */
 struct nvmem_device *nvmem_device_get(struct device *dev, const char *name);
-- 
2.21.0


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

* [PATCH 07/10] nvmem: core: Fix unintentional sign extension issue
  2021-03-30 11:12 [PATCH 00/10] nvmem: patches (set 1) for 5.13 Srinivas Kandagatla
                   ` (5 preceding siblings ...)
  2021-03-30 11:12 ` [PATCH 06/10] nvmem: core: Add functions to make number reading easy Srinivas Kandagatla
@ 2021-03-30 11:12 ` Srinivas Kandagatla
  2021-03-30 11:12 ` [PATCH 08/10] nvmem: rmem: fix undefined reference to memremap Srinivas Kandagatla
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Srinivas Kandagatla @ 2021-03-30 11:12 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, Colin Ian King, Douglas Anderson, Srinivas Kandagatla

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

The shifting of the u8 integer buf[3] by 24 bits to the left will
be promoted to a 32 bit signed int and then sign-extended to a
u64. In the event that the top bit of buf[3] is set then all
then all the upper 32 bits of the u64 end up as also being set
because of the sign-extension. Fix this by casting buf[i] to
a u64 before the shift.

Addresses-Coverity: ("Unintended sign extension")
Fixes: 097eb1136ebb ("nvmem: core: Add functions to make number reading easy")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
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 635e3131eb5f..bca671ff4e54 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -1693,7 +1693,7 @@ int nvmem_cell_read_variable_le_u64(struct device *dev, const char *cell_id,
 	/* Copy w/ implicit endian conversion */
 	*val = 0;
 	for (i = 0; i < len; i++)
-		*val |= buf[i] << (8 * i);
+		*val |= (uint64_t)buf[i] << (8 * i);
 
 	kfree(buf);
 
-- 
2.21.0


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

* [PATCH 08/10] nvmem: rmem: fix undefined reference to memremap
  2021-03-30 11:12 [PATCH 00/10] nvmem: patches (set 1) for 5.13 Srinivas Kandagatla
                   ` (6 preceding siblings ...)
  2021-03-30 11:12 ` [PATCH 07/10] nvmem: core: Fix unintentional sign extension issue Srinivas Kandagatla
@ 2021-03-30 11:12 ` Srinivas Kandagatla
  2021-03-30 11:12 ` [PATCH 09/10] dt-bindings: nvmem: Add SoC compatible for sc7280 Srinivas Kandagatla
  2021-03-30 11:12 ` [PATCH 10/10] nvmem: qfprom: Add support for fuse blowing on sc7280 Srinivas Kandagatla
  9 siblings, 0 replies; 11+ messages in thread
From: Srinivas Kandagatla @ 2021-03-30 11:12 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, Srinivas Kandagatla, kernel test robot,
	Nicolas Saenz Julienne

Fix below error reporte by kernel test robot
rmem.c:(.text+0x14e): undefined reference to memremap
s390x-linux-gnu-ld: rmem.c:(.text+0x1b6): undefined reference to memunmap

Reported-by: kernel test robot <lkp@intel.com>
Fixes: 5a3fa75a4d9c ("nvmem: Add driver to expose reserved memory as nvmem")
Reviewed-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index 642ddc699fd1..dd2019006838 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -272,6 +272,7 @@ config SPRD_EFUSE
 
 config NVMEM_RMEM
 	tristate "Reserved Memory Based Driver Support"
+	depends on HAS_IOMEM
 	help
 	  This driver maps reserved memory into an nvmem device. It might be
 	  useful to expose information left by firmware in memory.
-- 
2.21.0


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

* [PATCH 09/10] dt-bindings: nvmem: Add SoC compatible for sc7280
  2021-03-30 11:12 [PATCH 00/10] nvmem: patches (set 1) for 5.13 Srinivas Kandagatla
                   ` (7 preceding siblings ...)
  2021-03-30 11:12 ` [PATCH 08/10] nvmem: rmem: fix undefined reference to memremap Srinivas Kandagatla
@ 2021-03-30 11:12 ` Srinivas Kandagatla
  2021-03-30 11:12 ` [PATCH 10/10] nvmem: qfprom: Add support for fuse blowing on sc7280 Srinivas Kandagatla
  9 siblings, 0 replies; 11+ messages in thread
From: Srinivas Kandagatla @ 2021-03-30 11:12 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Rajendra Nayak, Rob Herring, Srinivas Kandagatla

From: Rajendra Nayak <rnayak@codeaurora.org>

Document SoC compatible for sc7280

Signed-off-by: Rajendra Nayak <rnayak@codeaurora.org>
Acked-by: Rob Herring <robh@kernel.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 992777c90a0b..861b205016b1 100644
--- a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
+++ b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
@@ -24,6 +24,7 @@ properties:
           - qcom,msm8998-qfprom
           - qcom,qcs404-qfprom
           - qcom,sc7180-qfprom
+          - qcom,sc7280-qfprom
           - qcom,sdm845-qfprom
       - const: qcom,qfprom
 
-- 
2.21.0


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

* [PATCH 10/10] nvmem: qfprom: Add support for fuse blowing on sc7280
  2021-03-30 11:12 [PATCH 00/10] nvmem: patches (set 1) for 5.13 Srinivas Kandagatla
                   ` (8 preceding siblings ...)
  2021-03-30 11:12 ` [PATCH 09/10] dt-bindings: nvmem: Add SoC compatible for sc7280 Srinivas Kandagatla
@ 2021-03-30 11:12 ` Srinivas Kandagatla
  9 siblings, 0 replies; 11+ messages in thread
From: Srinivas Kandagatla @ 2021-03-30 11:12 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, Rajendra Nayak, Ravi Kumar Bokka, Srinivas Kandagatla

From: Rajendra Nayak <rnayak@codeaurora.org>

Handle the differences across LDO voltage needed for blowing fuses,
and the blow timer value, identified using a minor version of 15
on sc7280.

Signed-off-by: Rajendra Nayak <rnayak@codeaurora.org>
Signed-off-by: Ravi Kumar Bokka <rbokka@codeaurora.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/qfprom.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/drivers/nvmem/qfprom.c b/drivers/nvmem/qfprom.c
index 100d69d8f2e1..d6d3f24685a8 100644
--- a/drivers/nvmem/qfprom.c
+++ b/drivers/nvmem/qfprom.c
@@ -45,11 +45,13 @@ MODULE_PARM_DESC(read_raw_data, "Read raw instead of corrected data");
  * @qfprom_blow_timer_value: The timer value of qfprom when doing efuse blow.
  * @qfprom_blow_set_freq:    The frequency required to set when we start the
  *                           fuse blowing.
+ * @qfprom_blow_uV:          LDO voltage to be set when doing efuse blow
  */
 struct qfprom_soc_data {
 	u32 accel_value;
 	u32 qfprom_blow_timer_value;
 	u32 qfprom_blow_set_freq;
+	int qfprom_blow_uV;
 };
 
 /**
@@ -111,6 +113,15 @@ static const struct qfprom_soc_compatible_data sc7180_qfprom = {
 	.nkeepout = ARRAY_SIZE(sc7180_qfprom_keepout)
 };
 
+static const struct nvmem_keepout sc7280_qfprom_keepout[] = {
+	{.start = 0x128, .end = 0x148},
+	{.start = 0x238, .end = 0x248}
+};
+
+static const struct qfprom_soc_compatible_data sc7280_qfprom = {
+	.keepout = sc7280_qfprom_keepout,
+	.nkeepout = ARRAY_SIZE(sc7280_qfprom_keepout)
+};
 /**
  * qfprom_disable_fuse_blowing() - Undo enabling of fuse blowing.
  * @priv: Our driver data.
@@ -168,6 +179,7 @@ static int qfprom_enable_fuse_blowing(const struct qfprom_priv *priv,
 				      struct qfprom_touched_values *old)
 {
 	int ret;
+	int qfprom_blow_uV = priv->soc_data->qfprom_blow_uV;
 
 	ret = clk_prepare_enable(priv->secclk);
 	if (ret) {
@@ -187,9 +199,9 @@ static int qfprom_enable_fuse_blowing(const struct qfprom_priv *priv,
 	 * a rail shared do don't specify a max--regulator constraints
 	 * will handle.
 	 */
-	ret = regulator_set_voltage(priv->vcc, 1800000, INT_MAX);
+	ret = regulator_set_voltage(priv->vcc, qfprom_blow_uV, INT_MAX);
 	if (ret) {
-		dev_err(priv->dev, "Failed to set 1.8 voltage\n");
+		dev_err(priv->dev, "Failed to set %duV\n", qfprom_blow_uV);
 		goto err_clk_rate_set;
 	}
 
@@ -311,6 +323,14 @@ static const struct qfprom_soc_data qfprom_7_8_data = {
 	.accel_value = 0xD10,
 	.qfprom_blow_timer_value = 25,
 	.qfprom_blow_set_freq = 4800000,
+	.qfprom_blow_uV = 1800000,
+};
+
+static const struct qfprom_soc_data qfprom_7_15_data = {
+	.accel_value = 0xD08,
+	.qfprom_blow_timer_value = 24,
+	.qfprom_blow_set_freq = 4800000,
+	.qfprom_blow_uV = 1900000,
 };
 
 static int qfprom_probe(struct platform_device *pdev)
@@ -379,6 +399,8 @@ static int qfprom_probe(struct platform_device *pdev)
 
 		if (major_version == 7 && minor_version == 8)
 			priv->soc_data = &qfprom_7_8_data;
+		if (major_version == 7 && minor_version == 15)
+			priv->soc_data = &qfprom_7_15_data;
 
 		priv->vcc = devm_regulator_get(&pdev->dev, "vcc");
 		if (IS_ERR(priv->vcc))
@@ -405,6 +427,7 @@ static int qfprom_probe(struct platform_device *pdev)
 static const struct of_device_id qfprom_of_match[] = {
 	{ .compatible = "qcom,qfprom",},
 	{ .compatible = "qcom,sc7180-qfprom", .data = &sc7180_qfprom},
+	{ .compatible = "qcom,sc7280-qfprom", .data = &sc7280_qfprom},
 	{/* sentinel */},
 };
 MODULE_DEVICE_TABLE(of, qfprom_of_match);
-- 
2.21.0


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

end of thread, other threads:[~2021-03-30 11:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-30 11:12 [PATCH 00/10] nvmem: patches (set 1) for 5.13 Srinivas Kandagatla
2021-03-30 11:12 ` [PATCH 01/10] dt-bindings: nvmem: mediatek: add support for MediaTek mt8192 SoC Srinivas Kandagatla
2021-03-30 11:12 ` [PATCH 02/10] nvmem: convert comma to semicolon Srinivas Kandagatla
2021-03-30 11:12 ` [PATCH 03/10] drivers: nvmem: Fix voltage settings for QTI qfprom-efuse Srinivas Kandagatla
2021-03-30 11:12 ` [PATCH 04/10] dt-bindings: nvmem: add Broadcom's NVRAM Srinivas Kandagatla
2021-03-30 11:12 ` [PATCH 05/10] nvmem: brcm_nvram: new driver exposing " Srinivas Kandagatla
2021-03-30 11:12 ` [PATCH 06/10] nvmem: core: Add functions to make number reading easy Srinivas Kandagatla
2021-03-30 11:12 ` [PATCH 07/10] nvmem: core: Fix unintentional sign extension issue Srinivas Kandagatla
2021-03-30 11:12 ` [PATCH 08/10] nvmem: rmem: fix undefined reference to memremap Srinivas Kandagatla
2021-03-30 11:12 ` [PATCH 09/10] dt-bindings: nvmem: Add SoC compatible for sc7280 Srinivas Kandagatla
2021-03-30 11:12 ` [PATCH 10/10] nvmem: qfprom: Add support for fuse blowing on sc7280 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.