devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/2] Add driver for OCOTP in Sunplus SP7021
@ 2021-12-15 11:35 Vincent Shih
  2021-12-15 11:35 ` [PATCH v3 1/2] nvmem: " Vincent Shih
  2021-12-15 11:35 ` [PATCH v3 2/2] dt-bindings: nvmem: Add bindings doc for Sunplus OCOTP driver Vincent Shih
  0 siblings, 2 replies; 7+ messages in thread
From: Vincent Shih @ 2021-12-15 11:35 UTC (permalink / raw)
  To: srinivas.kandagatla, linux-kernel, robh+dt, devicetree, wells.lu,
	vincent.shih
  Cc: Vincent Shih

This is a patch series for OCOTP driver for Sunplus SP7021 SoC.

Sunplus SP7021 is an ARM Cortex A7 (4 cores) based SoC. It integrates
many peripherals (ex: UART, I2C, SPI, SDIO, eMMC, USB, SD Card and
etc.) into a single chip. It is designed for industrial control.

Refer to:
https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
https://tibbo.com/store/plus1.html

Vincent Shih (2):
  nvmem: Add driver for OCOTP in Sunplus SP7021
  dt-bindings: nvmem: Add bindings doc for Sunplus OCOTP driver

 .../bindings/nvmem/sunplus,sp7021-ocotp.yaml       |  86 ++++++++
 MAINTAINERS                                        |   6 +
 drivers/nvmem/Kconfig                              |  12 +
 drivers/nvmem/Makefile                             |   2 +
 drivers/nvmem/sunplus-ocotp.c                      | 244 +++++++++++++++++++++
 5 files changed, 350 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nvmem/sunplus,sp7021-ocotp.yaml
 create mode 100644 drivers/nvmem/sunplus-ocotp.c

-- 
2.7.4


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

* [PATCH v3 1/2] nvmem: Add driver for OCOTP in Sunplus SP7021
  2021-12-15 11:35 [PATCH v3 0/2] Add driver for OCOTP in Sunplus SP7021 Vincent Shih
@ 2021-12-15 11:35 ` Vincent Shih
  2021-12-15 13:58   ` Srinivas Kandagatla
                     ` (2 more replies)
  2021-12-15 11:35 ` [PATCH v3 2/2] dt-bindings: nvmem: Add bindings doc for Sunplus OCOTP driver Vincent Shih
  1 sibling, 3 replies; 7+ messages in thread
From: Vincent Shih @ 2021-12-15 11:35 UTC (permalink / raw)
  To: srinivas.kandagatla, linux-kernel, robh+dt, devicetree, wells.lu,
	vincent.shih
  Cc: Vincent Shih

Add driver for OCOTP in Sunplus SP7021

Signed-off-by: Vincent Shih <vincent.sunplus@gmail.com>
---
Changes in v3:
 - Addressed the comments by Mr. Srinivas Kandagatla.
 - Replaced sp_otp_wait() with readl_poll_timeout().

 MAINTAINERS                   |   5 +
 drivers/nvmem/Kconfig         |  12 +++
 drivers/nvmem/Makefile        |   2 +
 drivers/nvmem/sunplus-ocotp.c | 244 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 263 insertions(+)
 create mode 100644 drivers/nvmem/sunplus-ocotp.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 80eebc1..0e6593a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -17947,6 +17947,11 @@ L:	netdev@vger.kernel.org
 S:	Maintained
 F:	drivers/net/ethernet/dlink/sundance.c
 
+SUNPLUS OCOTP DRIVER
+M:	Vincent Shih <vincent.sunplus@gmail.com>
+S:	Maintained
+F:	drivers/nvmem/sunplus-ocotp.c
+
 SUPERH
 M:	Yoshinori Sato <ysato@users.sourceforge.jp>
 M:	Rich Felker <dalias@libc.org>
diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index da41461..4559950 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -300,4 +300,16 @@ config NVMEM_BRCM_NVRAM
 	  This driver provides support for Broadcom's NVRAM that can be accessed
 	  using I/O mapping.
 
+config NVMEM_SUNPLUS_OCOTP
+	tristate "Sunplus SoC OTP support"
+	depends on SOC_SP7021 || COMPILE_TEST
+	depends on HAS_IOMEM
+	help
+	  This is a driver for the On-chip OTP controller (OCOTP) available
+	  on Sunplus SoCs. It provides access to 128 bytes of one-time
+	  programmable eFuse.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called nvmem-sunplus-ocotp.
+
 endif
diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
index dcbbde3..0f14cd9 100644
--- a/drivers/nvmem/Makefile
+++ b/drivers/nvmem/Makefile
@@ -61,3 +61,5 @@ 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
+obj-$(CONFIG_NVMEM_SUNPLUS_OCOTP)	+= nvmem_sunplus_ocotp.o
+nvmem_sunplus_ocotp-y		:= sunplus-ocotp.o
diff --git a/drivers/nvmem/sunplus-ocotp.c b/drivers/nvmem/sunplus-ocotp.c
new file mode 100644
index 0000000..cbaeaf3
--- /dev/null
+++ b/drivers/nvmem/sunplus-ocotp.c
@@ -0,0 +1,244 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * The OCOTP driver for Sunplus	SP7021
+ *
+ * Copyright (C) 2019 Sunplus Technology Inc., All rights reserved.
+ */
+
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/module.h>
+#include <linux/nvmem-provider.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+
+/*
+ * OTP memory
+ * Each bank contains 4 words (32 bits).
+ * Bank 0 starts at offset 0 from the base.
+ */
+
+#define OTP_WORDS_PER_BANK		4
+#define OTP_WORD_SIZE			sizeof(u32)
+#define OTP_BIT_ADDR_OF_BANK		(8 * OTP_WORD_SIZE * OTP_WORDS_PER_BANK)
+#define QAC628_OTP_NUM_BANKS		8
+#define QAC628_OTP_SIZE			(QAC628_OTP_NUM_BANKS * OTP_WORDS_PER_BANK * OTP_WORD_SIZE)
+#define OTP_READ_TIMEOUT_US		200000
+
+/* HB_GPIO */
+#define ADDRESS_8_DATA			0x20
+
+/* OTP_RX */
+#define OTP_CONTROL_2			0x48
+#define OTP_RD_PERIOD			GENMASK(15, 8)
+#define OTP_RD_PERIOD_MASK		~GENMASK(15, 8)
+#define ONE_CPU_CLOCK			0x1
+#define SEL_BAK_KEY2			BIT(5)
+#define SEL_BAK_KEY2_MASK		~BIT(5)
+#define SW_TRIM_EN			BIT(4)
+#define SW_TRIM_EN_MASK			~BIT(4)
+#define SEL_BAK_KEY			BIT(3)
+#define SEL_BAK_KEY_MASK		~BIT(3)
+#define OTP_READ			BIT(2)
+#define OTP_LOAD_SECURE_DATA		BIT(1)
+#define OTP_LOAD_SECURE_DATA_MASK	~BIT(1)
+#define OTP_DO_CRC			BIT(0)
+#define OTP_DO_CRC_MASK			~BIT(0)
+#define OTP_STATUS			0x4c
+#define OTP_READ_DONE			BIT(4)
+#define OTP_READ_DONE_MASK		~BIT(4)
+#define OTP_LOAD_SECURE_DONE_MASK	~BIT(2)
+#define OTP_READ_ADDRESS		0x50
+
+enum base_type {
+	HB_GPIO,
+	OTPRX,
+	BASEMAX,
+};
+
+struct sp_ocotp_priv {
+	struct device *dev;
+	void __iomem *base[BASEMAX];
+	struct clk *clk;
+};
+
+struct sp_ocotp_data {
+	int size;
+};
+
+const struct sp_ocotp_data  sp_otp_v0 = {
+	.size = QAC628_OTP_SIZE,
+};
+
+static int sp_otp_read_real(struct sp_ocotp_priv *otp, int addr, char *value)
+{
+	unsigned int addr_data;
+	unsigned int byte_shift;
+	unsigned int status;
+	int ret;
+
+	addr_data = addr % (OTP_WORD_SIZE * OTP_WORDS_PER_BANK);
+	addr_data = addr_data / OTP_WORD_SIZE;
+
+	byte_shift = addr % (OTP_WORD_SIZE * OTP_WORDS_PER_BANK);
+	byte_shift = byte_shift % OTP_WORD_SIZE;
+
+	addr = addr / (OTP_WORD_SIZE * OTP_WORDS_PER_BANK);
+	addr = addr * OTP_BIT_ADDR_OF_BANK;
+
+	writel(readl(otp->base[OTPRX] + OTP_STATUS) & OTP_READ_DONE_MASK &
+	       OTP_LOAD_SECURE_DONE_MASK, otp->base[OTPRX] + OTP_STATUS);
+	writel(addr, otp->base[OTPRX] + OTP_READ_ADDRESS);
+	writel(readl(otp->base[OTPRX] + OTP_CONTROL_2) | OTP_READ,
+	       otp->base[OTPRX] + OTP_CONTROL_2);
+	writel(readl(otp->base[OTPRX] + OTP_CONTROL_2) & SEL_BAK_KEY2_MASK & SW_TRIM_EN_MASK
+	       & SEL_BAK_KEY_MASK & OTP_LOAD_SECURE_DATA_MASK & OTP_DO_CRC_MASK,
+	       otp->base[OTPRX] + OTP_CONTROL_2);
+	writel((readl(otp->base[OTPRX] + OTP_CONTROL_2) & OTP_RD_PERIOD_MASK) |
+	       ((ONE_CPU_CLOCK * 0x1e) << 8), otp->base[OTPRX] + OTP_CONTROL_2);
+
+	ret = readl_poll_timeout(otp->base[OTPRX] + OTP_STATUS, status,
+				 status & OTP_READ_DONE, 10, OTP_READ_TIMEOUT_US);
+
+	if (ret < 0)
+		return ret;
+
+	*value = (readl(otp->base[HB_GPIO] + ADDRESS_8_DATA + addr_data * OTP_WORD_SIZE)
+		  >> (8 * byte_shift)) & 0xff;
+
+	return ret;
+}
+
+static int sp_ocotp_read(void *priv, unsigned int offset, void *value, size_t bytes)
+{
+	struct sp_ocotp_priv *otp = priv;
+	unsigned int addr;
+	char *buf = value;
+	char val[4];
+	int ret;
+
+	ret = clk_enable(otp->clk);
+	if (ret)
+		return ret;
+
+	*buf = 0;
+	for (addr = offset; addr < (offset + bytes); addr++) {
+		ret = sp_otp_read_real(otp, addr, val);
+		if (ret < 0) {
+			dev_err(otp->dev, "OTP read fail:%d at %d", ret, addr);
+			goto disable_clk;
+		}
+
+		*buf++ = *val;
+	}
+
+disable_clk:
+	clk_disable(otp->clk);
+
+	return ret;
+}
+
+static struct nvmem_config sp_ocotp_nvmem_config = {
+	.name = "sp-ocotp",
+	.read_only = true,
+	.word_size = 1,
+	.size = QAC628_OTP_SIZE,
+	.stride = 1,
+	.reg_read = sp_ocotp_read,
+	.owner = THIS_MODULE,
+};
+
+static int sp_ocotp_probe(struct platform_device *pdev)
+{
+	const struct of_device_id *match;
+	const struct sp_ocotp_data *otp_data;
+	struct device *dev = &pdev->dev;
+	struct nvmem_device *nvmem;
+	struct sp_ocotp_priv *otp;
+	struct resource *res;
+	int ret;
+
+	match = of_match_device(dev->driver->of_match_table, dev);
+	if (match && match->data)
+		otp_data = match->data;
+
+	otp = devm_kzalloc(dev, sizeof(*otp), GFP_KERNEL);
+	if (!otp)
+		return -ENOMEM;
+
+	otp->dev = dev;
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hb_gpio");
+	otp->base[HB_GPIO] = devm_ioremap_resource(dev, res);
+	if (IS_ERR(otp->base[HB_GPIO]))
+		return PTR_ERR(otp->base[HB_GPIO]);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "otprx");
+	otp->base[OTPRX] = devm_ioremap_resource(dev, res);
+	if (IS_ERR(otp->base[OTPRX]))
+		return PTR_ERR(otp->base[OTPRX]);
+
+	otp->clk = devm_clk_get(&pdev->dev, NULL);
+	if (IS_ERR(otp->clk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(otp->clk),
+						"devm_clk_get fail\n");
+
+	ret = clk_prepare(otp->clk);
+	if (ret < 0) {
+		dev_err(dev, "failed to prepare clk: %d\n", ret);
+		return ret;
+	}
+
+	sp_ocotp_nvmem_config.priv = otp;
+	sp_ocotp_nvmem_config.dev = dev;
+
+	nvmem = devm_nvmem_register(dev, &sp_ocotp_nvmem_config);
+	if (IS_ERR(nvmem))
+		return dev_err_probe(&pdev->dev, PTR_ERR(nvmem),
+						"register nvmem device fail\n");
+
+	platform_set_drvdata(pdev, nvmem);
+
+	dev_dbg(dev, "banks:%d x wpb:%d x wsize:%d = %d",
+		QAC628_OTP_NUM_BANKS, OTP_WORDS_PER_BANK,
+		OTP_WORD_SIZE, QAC628_OTP_SIZE);
+
+	dev_info(dev, "by Sunplus (C) 2020");
+
+	return 0;
+}
+
+static const struct of_device_id sp_ocotp_dt_ids[] = {
+	{ .compatible = "sunplus,sp7021-ocotp", .data = &sp_otp_v0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, sp_ocotp_dt_ids);
+
+static struct platform_driver sp_otp_driver = {
+	.probe     = sp_ocotp_probe,
+	.driver    = {
+		.name           = "sunplus,sp7021-ocotp",
+		.of_match_table = sp_ocotp_dt_ids,
+	}
+};
+
+static int __init sp_otp0_drv_new(void)
+{
+	return platform_driver_register(&sp_otp_driver);
+}
+module_init(sp_otp0_drv_new);
+
+static void __exit sp_otp0_drv_del(void)
+{
+	platform_driver_unregister(&sp_otp_driver);
+}
+module_exit(sp_otp0_drv_del);
+
+MODULE_AUTHOR("Vincent Shih <vincent.sunplus@gmail.com>");
+MODULE_DESCRIPTION("Sunplus On-Chip OTP driver");
+MODULE_LICENSE("GPL");
+
-- 
2.7.4


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

* [PATCH v3 2/2] dt-bindings: nvmem: Add bindings doc for Sunplus OCOTP driver
  2021-12-15 11:35 [PATCH v3 0/2] Add driver for OCOTP in Sunplus SP7021 Vincent Shih
  2021-12-15 11:35 ` [PATCH v3 1/2] nvmem: " Vincent Shih
@ 2021-12-15 11:35 ` Vincent Shih
  2021-12-15 15:51   ` Rob Herring
  1 sibling, 1 reply; 7+ messages in thread
From: Vincent Shih @ 2021-12-15 11:35 UTC (permalink / raw)
  To: srinivas.kandagatla, linux-kernel, robh+dt, devicetree, wells.lu,
	vincent.shih
  Cc: Vincent Shih

Add bindings doc for Sunplus OCOTP driver

Signed-off-by: Vincent Shih <vincent.sunplus@gmail.com>
---
Changes in v3
 - No change. It has been reviewed by Mr. Rob Herring
 
 .../bindings/nvmem/sunplus,sp7021-ocotp.yaml       | 86 ++++++++++++++++++++++
 MAINTAINERS                                        |  1 +
 2 files changed, 87 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nvmem/sunplus,sp7021-ocotp.yaml

diff --git a/Documentation/devicetree/bindings/nvmem/sunplus,sp7021-ocotp.yaml b/Documentation/devicetree/bindings/nvmem/sunplus,sp7021-ocotp.yaml
new file mode 100644
index 0000000..4b28f37
--- /dev/null
+++ b/Documentation/devicetree/bindings/nvmem/sunplus,sp7021-ocotp.yaml
@@ -0,0 +1,86 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) Sunplus Co., Ltd. 2021
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/nvmem/sunplus,sp7021-ocotp.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: On-Chip OTP Memory for Sunplus SP7021
+
+maintainers:
+  - Vincent Shih <vincent.sunplus@gmail.com>
+
+allOf:
+  - $ref: "nvmem.yaml#"
+
+properties:
+  compatible:
+    const: sunplus,sp7021-ocotp
+
+  reg:
+    maxItems: 2
+
+  reg-names:
+    items:
+      - const: hb_gpio
+      - const: otprx
+
+  clocks:
+    maxItems: 1
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 1
+
+  thermal-calibration:
+    type: object
+    description: thermal calibration values
+
+  disconnect-voltage:
+    type: object
+    description: disconnect voltages of usb2 port 0 and port 1
+
+  mac-address0:
+    type: object
+    description: MAC address of ethernet port 0
+
+  mac-address1:
+    type: object
+    description: MAC address of ethernet port 1
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - clocks
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/sp-sp7021.h>
+
+    otp: otp@9c00af00 {
+        compatible = "sunplus,sp7021-ocotp";
+        reg = <0x9c00af00 0x34>, <0x9c00af80 0x58>;
+        reg-names = "hb_gpio", "otprx";
+        clocks = <&clks OTPRX>;
+
+        #address-cells = <1>;
+        #size-cells = <1>;
+        therm_calib: thermal-calibration@14 {
+          reg = <0x14 0x3>;
+        };
+        disc_vol: disconnect-voltage@18 {
+          reg = <0x18 0x2>;
+        };
+        mac_addr0: mac-address0@34 {
+          reg = <0x34 0x6>;
+        };
+        mac_addr1: mac-address1@3a {
+          reg = <0x3a 0x6>;
+        };
+    };
+...
diff --git a/MAINTAINERS b/MAINTAINERS
index 0e6593a..2afd1ea 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -17950,6 +17950,7 @@ F:	drivers/net/ethernet/dlink/sundance.c
 SUNPLUS OCOTP DRIVER
 M:	Vincent Shih <vincent.sunplus@gmail.com>
 S:	Maintained
+F:	Documentation/devicetree/bindings/nvmem/sunplus,sp7021-ocotp.yaml
 F:	drivers/nvmem/sunplus-ocotp.c
 
 SUPERH
-- 
2.7.4


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

* Re: [PATCH v3 1/2] nvmem: Add driver for OCOTP in Sunplus SP7021
  2021-12-15 11:35 ` [PATCH v3 1/2] nvmem: " Vincent Shih
@ 2021-12-15 13:58   ` Srinivas Kandagatla
  2021-12-15 16:37   ` kernel test robot
  2021-12-16  1:10   ` kernel test robot
  2 siblings, 0 replies; 7+ messages in thread
From: Srinivas Kandagatla @ 2021-12-15 13:58 UTC (permalink / raw)
  To: Vincent Shih, linux-kernel, robh+dt, devicetree, wells.lu, vincent.shih



On 15/12/2021 11:35, Vincent Shih wrote:
> Add driver for OCOTP in Sunplus SP7021
> 
> Signed-off-by: Vincent Shih <vincent.sunplus@gmail.com>
> ---
> Changes in v3:
>   - Addressed the comments by Mr. Srinivas Kandagatla.
>   - Replaced sp_otp_wait() with readl_poll_timeout().
> 
>   MAINTAINERS                   |   5 +
>   drivers/nvmem/Kconfig         |  12 +++
>   drivers/nvmem/Makefile        |   2 +
>   drivers/nvmem/sunplus-ocotp.c | 244 ++++++++++++++++++++++++++++++++++++++++++
>   4 files changed, 263 insertions(+)
>   create mode 100644 drivers/nvmem/sunplus-ocotp.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 80eebc1..0e6593a 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -17947,6 +17947,11 @@ L:	netdev@vger.kernel.org
>   S:	Maintained
>   F:	drivers/net/ethernet/dlink/sundance.c
>   
> +SUNPLUS OCOTP DRIVER
> +M:	Vincent Shih <vincent.sunplus@gmail.com>
> +S:	Maintained
> +F:	drivers/nvmem/sunplus-ocotp.c
> +
>   SUPERH
>   M:	Yoshinori Sato <ysato@users.sourceforge.jp>
>   M:	Rich Felker <dalias@libc.org>
> diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
> index da41461..4559950 100644
> --- a/drivers/nvmem/Kconfig
> +++ b/drivers/nvmem/Kconfig
> @@ -300,4 +300,16 @@ config NVMEM_BRCM_NVRAM
>   	  This driver provides support for Broadcom's NVRAM that can be accessed
>   	  using I/O mapping.
>   
> +config NVMEM_SUNPLUS_OCOTP
> +	tristate "Sunplus SoC OTP support"
> +	depends on SOC_SP7021 || COMPILE_TEST
> +	depends on HAS_IOMEM
> +	help
> +	  This is a driver for the On-chip OTP controller (OCOTP) available
> +	  on Sunplus SoCs. It provides access to 128 bytes of one-time
> +	  programmable eFuse.
> +
> +	  This driver can also be built as a module. If so, the module
> +	  will be called nvmem-sunplus-ocotp.
> +
>   endif
> diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
> index dcbbde3..0f14cd9 100644
> --- a/drivers/nvmem/Makefile
> +++ b/drivers/nvmem/Makefile
> @@ -61,3 +61,5 @@ 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
> +obj-$(CONFIG_NVMEM_SUNPLUS_OCOTP)	+= nvmem_sunplus_ocotp.o
> +nvmem_sunplus_ocotp-y		:= sunplus-ocotp.o
> diff --git a/drivers/nvmem/sunplus-ocotp.c b/drivers/nvmem/sunplus-ocotp.c
> new file mode 100644
> index 0000000..cbaeaf3
> --- /dev/null
> +++ b/drivers/nvmem/sunplus-ocotp.c
> @@ -0,0 +1,244 @@
> +// SPDX-License-Identifier: GPL-2.0
...

> +};
> +
> +static int sp_otp_read_real(struct sp_ocotp_priv *otp, int addr, char *value)
> +{
> +	unsigned int addr_data;
> +	unsigned int byte_shift;
> +	unsigned int status;
> +	int ret;
> +
> +	addr_data = addr % (OTP_WORD_SIZE * OTP_WORDS_PER_BANK);
> +	addr_data = addr_data / OTP_WORD_SIZE;
> +
> +	byte_shift = addr % (OTP_WORD_SIZE * OTP_WORDS_PER_BANK);
> +	byte_shift = byte_shift % OTP_WORD_SIZE;
> +
> +	addr = addr / (OTP_WORD_SIZE * OTP_WORDS_PER_BANK);
> +	addr = addr * OTP_BIT_ADDR_OF_BANK;
> +
> +	writel(readl(otp->base[OTPRX] + OTP_STATUS) & OTP_READ_DONE_MASK &
> +	       OTP_LOAD_SECURE_DONE_MASK, otp->base[OTPRX] + OTP_STATUS);
> +	writel(addr, otp->base[OTPRX] + OTP_READ_ADDRESS);
> +	writel(readl(otp->base[OTPRX] + OTP_CONTROL_2) | OTP_READ,
> +	       otp->base[OTPRX] + OTP_CONTROL_2);
> +	writel(readl(otp->base[OTPRX] + OTP_CONTROL_2) & SEL_BAK_KEY2_MASK & SW_TRIM_EN_MASK
> +	       & SEL_BAK_KEY_MASK & OTP_LOAD_SECURE_DATA_MASK & OTP_DO_CRC_MASK,
> +	       otp->base[OTPRX] + OTP_CONTROL_2);
> +	writel((readl(otp->base[OTPRX] + OTP_CONTROL_2) & OTP_RD_PERIOD_MASK) |
> +	       ((ONE_CPU_CLOCK * 0x1e) << 8), otp->base[OTPRX] + OTP_CONTROL_2);

these magic values need a proper define

> +
> +	ret = readl_poll_timeout(otp->base[OTPRX] + OTP_STATUS, status,
> +				 status & OTP_READ_DONE, 10, OTP_READ_TIMEOUT_US);
> +
> +	if (ret < 0)
> +		return ret;
> +
> +	*value = (readl(otp->base[HB_GPIO] + ADDRESS_8_DATA + addr_data * OTP_WORD_SIZE)
> +		  >> (8 * byte_shift)) & 0xff;
> +
> +	return ret;
> +}
> +
> +static int sp_ocotp_read(void *priv, unsigned int offset, void *value, size_t bytes)
> +{
> +	struct sp_ocotp_priv *otp = priv;
> +	unsigned int addr;
> +	char *buf = value;
> +	char val[4];
> +	int ret;
> +
> +	ret = clk_enable(otp->clk);
> +	if (ret)
> +		return ret;
> +
> +	*buf = 0;
> +	for (addr = offset; addr < (offset + bytes); addr++) {
> +		ret = sp_otp_read_real(otp, addr, val);
> +		if (ret < 0) {
> +			dev_err(otp->dev, "OTP read fail:%d at %d", ret, addr);
> +			goto disable_clk;
> +		}
> +
> +		*buf++ = *val;
> +	}
> +
> +disable_clk:
> +	clk_disable(otp->clk);
> +
> +	return ret;
> +}
> +
> +static struct nvmem_config sp_ocotp_nvmem_config = {
> +	.name = "sp-ocotp",
> +	.read_only = true,
> +	.word_size = 1,
> +	.size = QAC628_OTP_SIZE,
> +	.stride = 1,
> +	.reg_read = sp_ocotp_read,
> +	.owner = THIS_MODULE,
> +};
> +
> +static int sp_ocotp_probe(struct platform_device *pdev)
> +{
> +	const struct of_device_id *match;
> +	const struct sp_ocotp_data *otp_data;
> +	struct device *dev = &pdev->dev;
> +	struct nvmem_device *nvmem;
> +	struct sp_ocotp_priv *otp;
> +	struct resource *res;
> +	int ret;
> +
> +	match = of_match_device(dev->driver->of_match_table, dev);
> +	if (match && match->data)
> +		otp_data = match->data;

this looks like dead code, otp_data is never used anywhere in the code.

> +
> +	otp = devm_kzalloc(dev, sizeof(*otp), GFP_KERNEL);
> +	if (!otp)
> +		return -ENOMEM;
> +
> +	otp->dev = dev;
> +
> +	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hb_gpio");
> +	otp->base[HB_GPIO] = devm_ioremap_resource(dev, res);
> +	if (IS_ERR(otp->base[HB_GPIO]))
> +		return PTR_ERR(otp->base[HB_GPIO]);
> +
> +	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "otprx");
> +	otp->base[OTPRX] = devm_ioremap_resource(dev, res);
> +	if (IS_ERR(otp->base[OTPRX]))
> +		return PTR_ERR(otp->base[OTPRX]);
> +
> +	otp->clk = devm_clk_get(&pdev->dev, NULL);
> +	if (IS_ERR(otp->clk))
> +		return dev_err_probe(&pdev->dev, PTR_ERR(otp->clk),
> +						"devm_clk_get fail\n");
> +
> +	ret = clk_prepare(otp->clk);
> +	if (ret < 0) {
> +		dev_err(dev, "failed to prepare clk: %d\n", ret);
> +		return ret;
> +	}
> +
> +	sp_ocotp_nvmem_config.priv = otp;
> +	sp_ocotp_nvmem_config.dev = dev;
> +
> +	nvmem = devm_nvmem_register(dev, &sp_ocotp_nvmem_config);
> +	if (IS_ERR(nvmem))
> +		return dev_err_probe(&pdev->dev, PTR_ERR(nvmem),
> +						"register nvmem device fail\n");
> +
> +	platform_set_drvdata(pdev, nvmem);
> +
> +	dev_dbg(dev, "banks:%d x wpb:%d x wsize:%d = %d",
> +		QAC628_OTP_NUM_BANKS, OTP_WORDS_PER_BANK,
> +		OTP_WORD_SIZE, QAC628_OTP_SIZE);
> +
> +	dev_info(dev, "by Sunplus (C) 2020");
> +
> +	return 0;
> +}
> +
> +static const struct of_device_id sp_ocotp_dt_ids[] = {
> +	{ .compatible = "sunplus,sp7021-ocotp", .data = &sp_otp_v0 },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(of, sp_ocotp_dt_ids);
> +
> +static struct platform_driver sp_otp_driver = {
> +	.probe     = sp_ocotp_probe,
> +	.driver    = {
> +		.name           = "sunplus,sp7021-ocotp",
> +		.of_match_table = sp_ocotp_dt_ids,
> +	}
> +};
> +

<---
> +static int __init sp_otp0_drv_new(void)
> +{
> +	return platform_driver_register(&sp_otp_driver);
> +}
> +module_init(sp_otp0_drv_new);
> +
> +static void __exit sp_otp0_drv_del(void)
> +{
> +	platform_driver_unregister(&sp_otp_driver);
> +}
> +module_exit(sp_otp0_drv_del);
--->

use
  module_platform_driver(sp_otp_driver);


--srini

> +
> +MODULE_AUTHOR("Vincent Shih <vincent.sunplus@gmail.com>");
> +MODULE_DESCRIPTION("Sunplus On-Chip OTP driver");
> +MODULE_LICENSE("GPL");
> +
> 

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

* Re: [PATCH v3 2/2] dt-bindings: nvmem: Add bindings doc for Sunplus OCOTP driver
  2021-12-15 11:35 ` [PATCH v3 2/2] dt-bindings: nvmem: Add bindings doc for Sunplus OCOTP driver Vincent Shih
@ 2021-12-15 15:51   ` Rob Herring
  0 siblings, 0 replies; 7+ messages in thread
From: Rob Herring @ 2021-12-15 15:51 UTC (permalink / raw)
  To: Vincent Shih
  Cc: wells.lu, srinivas.kandagatla, vincent.shih, devicetree,
	linux-kernel, robh+dt

On Wed, 15 Dec 2021 19:35:48 +0800, Vincent Shih wrote:
> Add bindings doc for Sunplus OCOTP driver
> 
> Signed-off-by: Vincent Shih <vincent.sunplus@gmail.com>
> ---
> Changes in v3
>  - No change. It has been reviewed by Mr. Rob Herring
> 
>  .../bindings/nvmem/sunplus,sp7021-ocotp.yaml       | 86 ++++++++++++++++++++++
>  MAINTAINERS                                        |  1 +
>  2 files changed, 87 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/nvmem/sunplus,sp7021-ocotp.yaml
> 


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

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


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

* Re: [PATCH v3 1/2] nvmem: Add driver for OCOTP in Sunplus SP7021
  2021-12-15 11:35 ` [PATCH v3 1/2] nvmem: " Vincent Shih
  2021-12-15 13:58   ` Srinivas Kandagatla
@ 2021-12-15 16:37   ` kernel test robot
  2021-12-16  1:10   ` kernel test robot
  2 siblings, 0 replies; 7+ messages in thread
From: kernel test robot @ 2021-12-15 16:37 UTC (permalink / raw)
  To: Vincent Shih, srinivas.kandagatla, linux-kernel, robh+dt,
	devicetree, wells.lu, vincent.shih
  Cc: kbuild-all, Vincent Shih

Hi Vincent,

I love your patch! Perhaps something to improve:

[auto build test WARNING on robh/for-next]
[also build test WARNING on linux/master linus/master v5.16-rc5 next-20211214]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Vincent-Shih/Add-driver-for-OCOTP-in-Sunplus-SP7021/20211215-193707
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20211216/202112160054.c4ehe4QI-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/c0a3142f164bb92fe79eafeb333050e7fcf42560
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Vincent-Shih/Add-driver-for-OCOTP-in-Sunplus-SP7021/20211215-193707
        git checkout c0a3142f164bb92fe79eafeb333050e7fcf42560
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=alpha SHELL=/bin/bash drivers/nvmem/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   In file included from include/linux/printk.h:555,
                    from include/linux/kernel.h:20,
                    from include/linux/clk.h:13,
                    from drivers/nvmem/sunplus-ocotp.c:9:
   drivers/nvmem/sunplus-ocotp.c: In function 'sp_ocotp_probe':
>> drivers/nvmem/sunplus-ocotp.c:206:22: warning: format '%d' expects argument of type 'int', but argument 6 has type 'long unsigned int' [-Wformat=]
     206 |         dev_dbg(dev, "banks:%d x wpb:%d x wsize:%d = %d",
         |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/dynamic_debug.h:134:29: note: in definition of macro '__dynamic_func_call'
     134 |                 func(&id, ##__VA_ARGS__);               \
         |                             ^~~~~~~~~~~
   include/linux/dynamic_debug.h:166:9: note: in expansion of macro '_dynamic_func_call'
     166 |         _dynamic_func_call(fmt,__dynamic_dev_dbg,               \
         |         ^~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:9: note: in expansion of macro 'dynamic_dev_dbg'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:30: note: in expansion of macro 'dev_fmt'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |                              ^~~~~~~
   drivers/nvmem/sunplus-ocotp.c:206:9: note: in expansion of macro 'dev_dbg'
     206 |         dev_dbg(dev, "banks:%d x wpb:%d x wsize:%d = %d",
         |         ^~~~~~~
   drivers/nvmem/sunplus-ocotp.c:206:50: note: format string is defined here
     206 |         dev_dbg(dev, "banks:%d x wpb:%d x wsize:%d = %d",
         |                                                 ~^
         |                                                  |
         |                                                  int
         |                                                 %ld
   In file included from include/linux/printk.h:555,
                    from include/linux/kernel.h:20,
                    from include/linux/clk.h:13,
                    from drivers/nvmem/sunplus-ocotp.c:9:
   drivers/nvmem/sunplus-ocotp.c:206:22: warning: format '%d' expects argument of type 'int', but argument 7 has type 'long unsigned int' [-Wformat=]
     206 |         dev_dbg(dev, "banks:%d x wpb:%d x wsize:%d = %d",
         |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/dynamic_debug.h:134:29: note: in definition of macro '__dynamic_func_call'
     134 |                 func(&id, ##__VA_ARGS__);               \
         |                             ^~~~~~~~~~~
   include/linux/dynamic_debug.h:166:9: note: in expansion of macro '_dynamic_func_call'
     166 |         _dynamic_func_call(fmt,__dynamic_dev_dbg,               \
         |         ^~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:9: note: in expansion of macro 'dynamic_dev_dbg'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:30: note: in expansion of macro 'dev_fmt'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |                              ^~~~~~~
   drivers/nvmem/sunplus-ocotp.c:206:9: note: in expansion of macro 'dev_dbg'
     206 |         dev_dbg(dev, "banks:%d x wpb:%d x wsize:%d = %d",
         |         ^~~~~~~
   drivers/nvmem/sunplus-ocotp.c:206:55: note: format string is defined here
     206 |         dev_dbg(dev, "banks:%d x wpb:%d x wsize:%d = %d",
         |                                                      ~^
         |                                                       |
         |                                                       int
         |                                                      %ld
   drivers/nvmem/sunplus-ocotp.c:158:37: warning: variable 'otp_data' set but not used [-Wunused-but-set-variable]
     158 |         const struct sp_ocotp_data *otp_data;
         |                                     ^~~~~~~~


vim +206 drivers/nvmem/sunplus-ocotp.c

     2	
     3	/*
     4	 * The OCOTP driver for Sunplus	SP7021
     5	 *
     6	 * Copyright (C) 2019 Sunplus Technology Inc., All rights reserved.
     7	 */
     8	
   > 9	#include <linux/clk.h>
    10	#include <linux/delay.h>
    11	#include <linux/device.h>
    12	#include <linux/io.h>
    13	#include <linux/iopoll.h>
    14	#include <linux/module.h>
    15	#include <linux/nvmem-provider.h>
    16	#include <linux/of_device.h>
    17	#include <linux/platform_device.h>
    18	
    19	/*
    20	 * OTP memory
    21	 * Each bank contains 4 words (32 bits).
    22	 * Bank 0 starts at offset 0 from the base.
    23	 */
    24	
    25	#define OTP_WORDS_PER_BANK		4
    26	#define OTP_WORD_SIZE			sizeof(u32)
    27	#define OTP_BIT_ADDR_OF_BANK		(8 * OTP_WORD_SIZE * OTP_WORDS_PER_BANK)
    28	#define QAC628_OTP_NUM_BANKS		8
    29	#define QAC628_OTP_SIZE			(QAC628_OTP_NUM_BANKS * OTP_WORDS_PER_BANK * OTP_WORD_SIZE)
    30	#define OTP_READ_TIMEOUT_US		200000
    31	
    32	/* HB_GPIO */
    33	#define ADDRESS_8_DATA			0x20
    34	
    35	/* OTP_RX */
    36	#define OTP_CONTROL_2			0x48
    37	#define OTP_RD_PERIOD			GENMASK(15, 8)
    38	#define OTP_RD_PERIOD_MASK		~GENMASK(15, 8)
    39	#define ONE_CPU_CLOCK			0x1
    40	#define SEL_BAK_KEY2			BIT(5)
    41	#define SEL_BAK_KEY2_MASK		~BIT(5)
    42	#define SW_TRIM_EN			BIT(4)
    43	#define SW_TRIM_EN_MASK			~BIT(4)
    44	#define SEL_BAK_KEY			BIT(3)
    45	#define SEL_BAK_KEY_MASK		~BIT(3)
    46	#define OTP_READ			BIT(2)
    47	#define OTP_LOAD_SECURE_DATA		BIT(1)
    48	#define OTP_LOAD_SECURE_DATA_MASK	~BIT(1)
    49	#define OTP_DO_CRC			BIT(0)
    50	#define OTP_DO_CRC_MASK			~BIT(0)
    51	#define OTP_STATUS			0x4c
    52	#define OTP_READ_DONE			BIT(4)
    53	#define OTP_READ_DONE_MASK		~BIT(4)
    54	#define OTP_LOAD_SECURE_DONE_MASK	~BIT(2)
    55	#define OTP_READ_ADDRESS		0x50
    56	
    57	enum base_type {
    58		HB_GPIO,
    59		OTPRX,
    60		BASEMAX,
    61	};
    62	
    63	struct sp_ocotp_priv {
    64		struct device *dev;
    65		void __iomem *base[BASEMAX];
    66		struct clk *clk;
    67	};
    68	
    69	struct sp_ocotp_data {
    70		int size;
    71	};
    72	
    73	const struct sp_ocotp_data  sp_otp_v0 = {
    74		.size = QAC628_OTP_SIZE,
    75	};
    76	
    77	static int sp_otp_read_real(struct sp_ocotp_priv *otp, int addr, char *value)
    78	{
    79		unsigned int addr_data;
    80		unsigned int byte_shift;
    81		unsigned int status;
    82		int ret;
    83	
    84		addr_data = addr % (OTP_WORD_SIZE * OTP_WORDS_PER_BANK);
    85		addr_data = addr_data / OTP_WORD_SIZE;
    86	
    87		byte_shift = addr % (OTP_WORD_SIZE * OTP_WORDS_PER_BANK);
    88		byte_shift = byte_shift % OTP_WORD_SIZE;
    89	
    90		addr = addr / (OTP_WORD_SIZE * OTP_WORDS_PER_BANK);
    91		addr = addr * OTP_BIT_ADDR_OF_BANK;
    92	
    93		writel(readl(otp->base[OTPRX] + OTP_STATUS) & OTP_READ_DONE_MASK &
    94		       OTP_LOAD_SECURE_DONE_MASK, otp->base[OTPRX] + OTP_STATUS);
    95		writel(addr, otp->base[OTPRX] + OTP_READ_ADDRESS);
    96		writel(readl(otp->base[OTPRX] + OTP_CONTROL_2) | OTP_READ,
    97		       otp->base[OTPRX] + OTP_CONTROL_2);
    98		writel(readl(otp->base[OTPRX] + OTP_CONTROL_2) & SEL_BAK_KEY2_MASK & SW_TRIM_EN_MASK
    99		       & SEL_BAK_KEY_MASK & OTP_LOAD_SECURE_DATA_MASK & OTP_DO_CRC_MASK,
   100		       otp->base[OTPRX] + OTP_CONTROL_2);
   101		writel((readl(otp->base[OTPRX] + OTP_CONTROL_2) & OTP_RD_PERIOD_MASK) |
   102		       ((ONE_CPU_CLOCK * 0x1e) << 8), otp->base[OTPRX] + OTP_CONTROL_2);
   103	
   104		ret = readl_poll_timeout(otp->base[OTPRX] + OTP_STATUS, status,
   105					 status & OTP_READ_DONE, 10, OTP_READ_TIMEOUT_US);
   106	
   107		if (ret < 0)
   108			return ret;
   109	
   110		*value = (readl(otp->base[HB_GPIO] + ADDRESS_8_DATA + addr_data * OTP_WORD_SIZE)
   111			  >> (8 * byte_shift)) & 0xff;
   112	
   113		return ret;
   114	}
   115	
   116	static int sp_ocotp_read(void *priv, unsigned int offset, void *value, size_t bytes)
   117	{
   118		struct sp_ocotp_priv *otp = priv;
   119		unsigned int addr;
   120		char *buf = value;
   121		char val[4];
   122		int ret;
   123	
   124		ret = clk_enable(otp->clk);
   125		if (ret)
   126			return ret;
   127	
   128		*buf = 0;
   129		for (addr = offset; addr < (offset + bytes); addr++) {
   130			ret = sp_otp_read_real(otp, addr, val);
   131			if (ret < 0) {
   132				dev_err(otp->dev, "OTP read fail:%d at %d", ret, addr);
   133				goto disable_clk;
   134			}
   135	
   136			*buf++ = *val;
   137		}
   138	
   139	disable_clk:
   140		clk_disable(otp->clk);
   141	
   142		return ret;
   143	}
   144	
   145	static struct nvmem_config sp_ocotp_nvmem_config = {
   146		.name = "sp-ocotp",
   147		.read_only = true,
   148		.word_size = 1,
   149		.size = QAC628_OTP_SIZE,
   150		.stride = 1,
   151		.reg_read = sp_ocotp_read,
   152		.owner = THIS_MODULE,
   153	};
   154	
   155	static int sp_ocotp_probe(struct platform_device *pdev)
   156	{
   157		const struct of_device_id *match;
   158		const struct sp_ocotp_data *otp_data;
   159		struct device *dev = &pdev->dev;
   160		struct nvmem_device *nvmem;
   161		struct sp_ocotp_priv *otp;
   162		struct resource *res;
   163		int ret;
   164	
   165		match = of_match_device(dev->driver->of_match_table, dev);
   166		if (match && match->data)
   167			otp_data = match->data;
   168	
   169		otp = devm_kzalloc(dev, sizeof(*otp), GFP_KERNEL);
   170		if (!otp)
   171			return -ENOMEM;
   172	
   173		otp->dev = dev;
   174	
   175		res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hb_gpio");
   176		otp->base[HB_GPIO] = devm_ioremap_resource(dev, res);
   177		if (IS_ERR(otp->base[HB_GPIO]))
   178			return PTR_ERR(otp->base[HB_GPIO]);
   179	
   180		res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "otprx");
   181		otp->base[OTPRX] = devm_ioremap_resource(dev, res);
   182		if (IS_ERR(otp->base[OTPRX]))
   183			return PTR_ERR(otp->base[OTPRX]);
   184	
   185		otp->clk = devm_clk_get(&pdev->dev, NULL);
   186		if (IS_ERR(otp->clk))
   187			return dev_err_probe(&pdev->dev, PTR_ERR(otp->clk),
   188							"devm_clk_get fail\n");
   189	
   190		ret = clk_prepare(otp->clk);
   191		if (ret < 0) {
   192			dev_err(dev, "failed to prepare clk: %d\n", ret);
   193			return ret;
   194		}
   195	
   196		sp_ocotp_nvmem_config.priv = otp;
   197		sp_ocotp_nvmem_config.dev = dev;
   198	
   199		nvmem = devm_nvmem_register(dev, &sp_ocotp_nvmem_config);
   200		if (IS_ERR(nvmem))
   201			return dev_err_probe(&pdev->dev, PTR_ERR(nvmem),
   202							"register nvmem device fail\n");
   203	
   204		platform_set_drvdata(pdev, nvmem);
   205	
 > 206		dev_dbg(dev, "banks:%d x wpb:%d x wsize:%d = %d",
   207			QAC628_OTP_NUM_BANKS, OTP_WORDS_PER_BANK,
   208			OTP_WORD_SIZE, QAC628_OTP_SIZE);
   209	
   210		dev_info(dev, "by Sunplus (C) 2020");
   211	
   212		return 0;
   213	}
   214	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

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

* Re: [PATCH v3 1/2] nvmem: Add driver for OCOTP in Sunplus SP7021
  2021-12-15 11:35 ` [PATCH v3 1/2] nvmem: " Vincent Shih
  2021-12-15 13:58   ` Srinivas Kandagatla
  2021-12-15 16:37   ` kernel test robot
@ 2021-12-16  1:10   ` kernel test robot
  2 siblings, 0 replies; 7+ messages in thread
From: kernel test robot @ 2021-12-16  1:10 UTC (permalink / raw)
  To: Vincent Shih, srinivas.kandagatla, linux-kernel, robh+dt,
	devicetree, wells.lu, vincent.shih
  Cc: kbuild-all, Vincent Shih

Hi Vincent,

I love your patch! Perhaps something to improve:

[auto build test WARNING on robh/for-next]
[also build test WARNING on linux/master linus/master v5.16-rc5 next-20211214]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Vincent-Shih/Add-driver-for-OCOTP-in-Sunplus-SP7021/20211215-193707
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
config: mips-allyesconfig (https://download.01.org/0day-ci/archive/20211216/202112160925.yTjMLuBB-lkp@intel.com/config)
compiler: mips-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/c0a3142f164bb92fe79eafeb333050e7fcf42560
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Vincent-Shih/Add-driver-for-OCOTP-in-Sunplus-SP7021/20211215-193707
        git checkout c0a3142f164bb92fe79eafeb333050e7fcf42560
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=mips SHELL=/bin/bash drivers/nvmem/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/nvmem/sunplus-ocotp.c: In function 'sp_ocotp_probe':
>> drivers/nvmem/sunplus-ocotp.c:158:37: warning: variable 'otp_data' set but not used [-Wunused-but-set-variable]
     158 |         const struct sp_ocotp_data *otp_data;
         |                                     ^~~~~~~~


vim +/otp_data +158 drivers/nvmem/sunplus-ocotp.c

   154	
   155	static int sp_ocotp_probe(struct platform_device *pdev)
   156	{
   157		const struct of_device_id *match;
 > 158		const struct sp_ocotp_data *otp_data;
   159		struct device *dev = &pdev->dev;
   160		struct nvmem_device *nvmem;
   161		struct sp_ocotp_priv *otp;
   162		struct resource *res;
   163		int ret;
   164	
   165		match = of_match_device(dev->driver->of_match_table, dev);
   166		if (match && match->data)
   167			otp_data = match->data;
   168	
   169		otp = devm_kzalloc(dev, sizeof(*otp), GFP_KERNEL);
   170		if (!otp)
   171			return -ENOMEM;
   172	
   173		otp->dev = dev;
   174	
   175		res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hb_gpio");
   176		otp->base[HB_GPIO] = devm_ioremap_resource(dev, res);
   177		if (IS_ERR(otp->base[HB_GPIO]))
   178			return PTR_ERR(otp->base[HB_GPIO]);
   179	
   180		res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "otprx");
   181		otp->base[OTPRX] = devm_ioremap_resource(dev, res);
   182		if (IS_ERR(otp->base[OTPRX]))
   183			return PTR_ERR(otp->base[OTPRX]);
   184	
   185		otp->clk = devm_clk_get(&pdev->dev, NULL);
   186		if (IS_ERR(otp->clk))
   187			return dev_err_probe(&pdev->dev, PTR_ERR(otp->clk),
   188							"devm_clk_get fail\n");
   189	
   190		ret = clk_prepare(otp->clk);
   191		if (ret < 0) {
   192			dev_err(dev, "failed to prepare clk: %d\n", ret);
   193			return ret;
   194		}
   195	
   196		sp_ocotp_nvmem_config.priv = otp;
   197		sp_ocotp_nvmem_config.dev = dev;
   198	
   199		nvmem = devm_nvmem_register(dev, &sp_ocotp_nvmem_config);
   200		if (IS_ERR(nvmem))
   201			return dev_err_probe(&pdev->dev, PTR_ERR(nvmem),
   202							"register nvmem device fail\n");
   203	
   204		platform_set_drvdata(pdev, nvmem);
   205	
   206		dev_dbg(dev, "banks:%d x wpb:%d x wsize:%d = %d",
   207			QAC628_OTP_NUM_BANKS, OTP_WORDS_PER_BANK,
   208			OTP_WORD_SIZE, QAC628_OTP_SIZE);
   209	
   210		dev_info(dev, "by Sunplus (C) 2020");
   211	
   212		return 0;
   213	}
   214	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

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

end of thread, other threads:[~2021-12-16  1:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-15 11:35 [PATCH v3 0/2] Add driver for OCOTP in Sunplus SP7021 Vincent Shih
2021-12-15 11:35 ` [PATCH v3 1/2] nvmem: " Vincent Shih
2021-12-15 13:58   ` Srinivas Kandagatla
2021-12-15 16:37   ` kernel test robot
2021-12-16  1:10   ` kernel test robot
2021-12-15 11:35 ` [PATCH v3 2/2] dt-bindings: nvmem: Add bindings doc for Sunplus OCOTP driver Vincent Shih
2021-12-15 15:51   ` Rob Herring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).