diff mbox series

[v2,18/29] nvmem: Add Realtek DHC eFuse driver

Message ID 20200623025106.31273-19-afaerber@suse.de (mailing list archive)
State New, archived
Headers show
Series ARM: Realtek DHC SoC info | expand

Commit Message

Andreas Färber June 23, 2020, 2:50 a.m. UTC
Implement enough of a read-only nvmem driver to easily read efuse cells.

Cc: Cheng-Yu Lee <cylee12@realtek.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 v2: New
 
 MAINTAINERS                   |  1 +
 drivers/nvmem/Kconfig         |  9 ++++
 drivers/nvmem/Makefile        |  2 +
 drivers/nvmem/rtk-dhc-efuse.c | 86 +++++++++++++++++++++++++++++++++++
 4 files changed, 98 insertions(+)
 create mode 100644 drivers/nvmem/rtk-dhc-efuse.c

Comments

Srinivas Kandagatla June 23, 2020, 9:32 a.m. UTC | #1
On 23/06/2020 03:50, Andreas Färber wrote:
> Implement enough of a read-only nvmem driver to easily read efuse cells.
> 
> Cc: Cheng-Yu Lee <cylee12@realtek.com>
> Signed-off-by: Andreas Färber <afaerber@suse.de>
> ---

This patch itself looks okay to me, I will apply this once DT patches 
are Reviewed/applied by DT maintainers!

--srini
>   v2: New
>   
>   MAINTAINERS                   |  1 +
>   drivers/nvmem/Kconfig         |  9 ++++
>   drivers/nvmem/Makefile        |  2 +
>   drivers/nvmem/rtk-dhc-efuse.c | 86 +++++++++++++++++++++++++++++++++++
>   4 files changed, 98 insertions(+)
>   create mode 100644 drivers/nvmem/rtk-dhc-efuse.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 1d0d6ab20451..02117fbf0e57 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -2312,6 +2312,7 @@ F:	Documentation/devicetree/bindings/soc/realtek/
>   F:	arch/arm/boot/dts/rtd*
>   F:	arch/arm/mach-realtek/
>   F:	arch/arm64/boot/dts/realtek/
> +F:	drivers/nvmem/rtk-dhc-efuse.c
>   F:	drivers/soc/realtek/
>   
>   ARM/RENESAS ARM64 ARCHITECTURE
> diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
> index d7b7f6d688e7..75cf43b16cf9 100644
> --- a/drivers/nvmem/Kconfig
> +++ b/drivers/nvmem/Kconfig
> @@ -129,6 +129,15 @@ config NVMEM_SPMI_SDAM
>   	  Qualcomm Technologies, Inc. PMICs. It provides the clients
>   	  an interface to read/write to the SDAM module's shared memory.
>   
> +config REALTEK_DHC_EFUSE
> +	tristate "Realtek DHC eFuse Support"
> +	depends on ARCH_REALTEK || COMPILE_TEST
> +	depends on HAS_IOMEM
> +	help
> +	  Say y here to enable read-only access to the Realtek Digital Home
> +	  This driver can also be built as a module. If so, the module
> +	  will be called nvmem-rtk-dhc-efuse.
> +
>   config ROCKCHIP_EFUSE
>   	tristate "Rockchip eFuse Support"
>   	depends on ARCH_ROCKCHIP || COMPILE_TEST
> diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
> index a7c377218341..67cefdfa44e6 100644
> --- a/drivers/nvmem/Makefile
> +++ b/drivers/nvmem/Makefile
> @@ -33,6 +33,8 @@ obj-$(CONFIG_ROCKCHIP_EFUSE)	+= nvmem_rockchip_efuse.o
>   nvmem_rockchip_efuse-y		:= rockchip-efuse.o
>   obj-$(CONFIG_ROCKCHIP_OTP)	+= nvmem-rockchip-otp.o
>   nvmem-rockchip-otp-y		:= rockchip-otp.o
> +obj-$(CONFIG_REALTEK_DHC_EFUSE)	+= nvmem-rtk-dhc-efuse.o
> +nvmem-rtk-dhc-efuse-y		:= rtk-dhc-efuse.o
>   obj-$(CONFIG_NVMEM_SUNXI_SID)	+= nvmem_sunxi_sid.o
>   nvmem_stm32_romem-y 		:= stm32-romem.o
>   obj-$(CONFIG_NVMEM_STM32_ROMEM) += nvmem_stm32_romem.o
> diff --git a/drivers/nvmem/rtk-dhc-efuse.c b/drivers/nvmem/rtk-dhc-efuse.c
> new file mode 100644
> index 000000000000..4672db2c2619
> --- /dev/null
> +++ b/drivers/nvmem/rtk-dhc-efuse.c
> @@ -0,0 +1,86 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Realtek Digital Home Center eFuse
> + *
> + * Copyright (c) 2020 Andreas Färber
> + */
> +
> +#include <linux/io.h>
> +#include <linux/module.h>
> +#include <linux/nvmem-provider.h>
> +#include <linux/of.h>
> +#include <linux/of_address.h>
> +#include <linux/platform_device.h>
> +#include <linux/slab.h>
> +
> +struct dhc_efuse {
> +	struct device *dev;
> +	void __iomem *base;
> +	struct nvmem_device *nvmem;
> +};
> +
> +static int dhc_efuse_reg_read(void *priv, unsigned int offset, void *val,
> +	size_t bytes)
> +{
> +	struct dhc_efuse *efuse = priv;
> +	u8 *buf = val;
> +
> +	while (bytes--)
> +		*buf++ = readb_relaxed(efuse->base + offset++);
> +
> +	return 0;
> +}
> +
> +static int dhc_efuse_probe(struct platform_device *pdev)
> +{
> +	struct dhc_efuse *efuse;
> +	struct nvmem_config config = {};
> +	struct resource *res;
> +
> +	efuse = devm_kzalloc(&pdev->dev, sizeof(*efuse), GFP_KERNEL);
> +	if (!efuse)
> +		return -ENOMEM;
> +
> +	efuse->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
> +	if (IS_ERR(efuse->base))
> +		return PTR_ERR(efuse->base);
> +
> +	efuse->dev = &pdev->dev;
> +
> +	config.dev = &pdev->dev;
> +	config.name = "dhc-efuse";
> +	config.owner = THIS_MODULE;
> +	config.type = NVMEM_TYPE_OTP;
> +	config.read_only = true,
> +	config.word_size = 4;
> +	config.stride = 1;
> +	config.size = resource_size(res);
> +	config.reg_read = dhc_efuse_reg_read;
> +	config.priv = efuse;
> +
> +	efuse->nvmem = devm_nvmem_register(&pdev->dev, &config);
> +	if (IS_ERR(efuse->nvmem)) {
> +		dev_err(&pdev->dev, "failed to register nvmem (%ld)\n",
> +			PTR_ERR(efuse->nvmem));
> +		return PTR_ERR(efuse->nvmem);
> +	}
> +
> +	return 0;
> +}
> +
> +static const struct of_device_id dhc_efuse_dt_ids[] = {
> +	 { .compatible = "realtek,rtd1195-efuse" },
> +	 { }
> +};
> +
> +static struct platform_driver dhc_efuse_driver = {
> +	.probe = dhc_efuse_probe,
> +	.driver = {
> +		.name = "rtk-dhc-efuse",
> +		.of_match_table	= dhc_efuse_dt_ids,
> +	},
> +};
> +module_platform_driver(dhc_efuse_driver);
> +
> +MODULE_DESCRIPTION("Realtek DHC eFuse driver");
> +MODULE_LICENSE("GPL");
>
Andreas Färber June 23, 2020, 11:15 a.m. UTC | #2
Hi Srini,

Am 23.06.20 um 11:32 schrieb Srinivas Kandagatla:
> On 23/06/2020 03:50, Andreas Färber wrote:
>> Implement enough of a read-only nvmem driver to easily read efuse cells.
>>
>> Cc: Cheng-Yu Lee <cylee12@realtek.com>
>> Signed-off-by: Andreas Färber <afaerber@suse.de>
>> ---
> 
> This patch itself looks okay to me, I will apply this once DT patches 
> are Reviewed/applied by DT maintainers!

Thanks - let's give the Realtek engineers some time to review, too:

* Driver naming - new [rtk-]dhc (Stanley) vs. in-tree rtd1195 elsewhere.

* My other driver was previously reading u32-sized registers directly, 
whereas here I switched to byte-sized reads based on other in-tree nvmem 
drivers. Downstream driver seems inconsistent wrt .word_size:
https://github.com/BPI-SINOVOIP/BPI-M4-bsp/blob/master/linux-rtk/drivers/nvmem/rtk-efuse.c#L191

* RTD1619 (RTD1319, too?) may need special handling and therefore its 
own DT compatible: There's a magic OTP_CTRL register write downstream 
that I am lacking documentation w/ names&explanations and use case for.
https://github.com/BPI-SINOVOIP/BPI-M4-bsp/blob/master/linux-rtk/drivers/nvmem/rtk-efuse.c#L216
That might obviously affect the binding, too, requiring oneOf - could be 
changed in a later step though.

I would take the .dts patches through my linux-realtek.git once the 
binding is approved.

* The downstream DTs have nvmem-cells and nvmem-cell-names properties in 
the efuse node directly, which I regarded as unnecessary from reading 
the consumer binding, placing those properties into the consuming node.

* Downstream DTs have more eFuse fields declared than the one I use in 
this series [1]; they are also inconsistent in prefixing them efuse_ vs. 
otp_; in the RTD1295 datasheet the block is called eFuse, so I used 
efuse_ for consistency. I have enforced the dashes convention for nodes,
as I didn't see the node name get used anywhere.

[1] https://patchwork.kernel.org/patch/11619643/

One more comment inline...

>>   v2: New
>>   MAINTAINERS                   |  1 +
>>   drivers/nvmem/Kconfig         |  9 ++++
>>   drivers/nvmem/Makefile        |  2 +
>>   drivers/nvmem/rtk-dhc-efuse.c | 86 +++++++++++++++++++++++++++++++++++
>>   4 files changed, 98 insertions(+)
>>   create mode 100644 drivers/nvmem/rtk-dhc-efuse.c
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 1d0d6ab20451..02117fbf0e57 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -2312,6 +2312,7 @@ F:    
>> Documentation/devicetree/bindings/soc/realtek/
>>   F:    arch/arm/boot/dts/rtd*
>>   F:    arch/arm/mach-realtek/
>>   F:    arch/arm64/boot/dts/realtek/
>> +F:    drivers/nvmem/rtk-dhc-efuse.c
>>   F:    drivers/soc/realtek/
>>   ARM/RENESAS ARM64 ARCHITECTURE
[snip]

This line addition will conflict with the next line, added earlier in 
this patchset. Same for the binding patch. Do you need a v3 reordering 
them? This driver seems easier to target for 5.9 than the rest of the 
series.

If you do not intend to take the dt-bindings patch (17/29) through your 
tree, I can queue it once ack'ed by Rob and you.

Thanks for the quick review,

Andreas
Srinivas Kandagatla July 20, 2020, 9:31 a.m. UTC | #3
On 23/06/2020 03:50, Andreas Färber wrote:
> Implement enough of a read-only nvmem driver to easily read efuse cells.
> 
> Cc: Cheng-Yu Lee <cylee12@realtek.com>
> Signed-off-by: Andreas Färber <afaerber@suse.de>

If you are expecting this to be applied, then please resend this patch 
splitting the MAINTAINER File changes separately!

--srini
> ---
>   v2: New
>   
>   MAINTAINERS                   |  1 +
>   drivers/nvmem/Kconfig         |  9 ++++
>   drivers/nvmem/Makefile        |  2 +
>   drivers/nvmem/rtk-dhc-efuse.c | 86 +++++++++++++++++++++++++++++++++++
>   4 files changed, 98 insertions(+)
>   create mode 100644 drivers/nvmem/rtk-dhc-efuse.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 1d0d6ab20451..02117fbf0e57 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -2312,6 +2312,7 @@ F:	Documentation/devicetree/bindings/soc/realtek/
>   F:	arch/arm/boot/dts/rtd*
>   F:	arch/arm/mach-realtek/
>   F:	arch/arm64/boot/dts/realtek/
> +F:	drivers/nvmem/rtk-dhc-efuse.c
>   F:	drivers/soc/realtek/
>   
>   ARM/RENESAS ARM64 ARCHITECTURE
> diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
> index d7b7f6d688e7..75cf43b16cf9 100644
> --- a/drivers/nvmem/Kconfig
> +++ b/drivers/nvmem/Kconfig
> @@ -129,6 +129,15 @@ config NVMEM_SPMI_SDAM
>   	  Qualcomm Technologies, Inc. PMICs. It provides the clients
>   	  an interface to read/write to the SDAM module's shared memory.
>   
> +config REALTEK_DHC_EFUSE
> +	tristate "Realtek DHC eFuse Support"
> +	depends on ARCH_REALTEK || COMPILE_TEST
> +	depends on HAS_IOMEM
> +	help
> +	  Say y here to enable read-only access to the Realtek Digital Home
> +	  This driver can also be built as a module. If so, the module
> +	  will be called nvmem-rtk-dhc-efuse.
> +
>   config ROCKCHIP_EFUSE
>   	tristate "Rockchip eFuse Support"
>   	depends on ARCH_ROCKCHIP || COMPILE_TEST
> diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
> index a7c377218341..67cefdfa44e6 100644
> --- a/drivers/nvmem/Makefile
> +++ b/drivers/nvmem/Makefile
> @@ -33,6 +33,8 @@ obj-$(CONFIG_ROCKCHIP_EFUSE)	+= nvmem_rockchip_efuse.o
>   nvmem_rockchip_efuse-y		:= rockchip-efuse.o
>   obj-$(CONFIG_ROCKCHIP_OTP)	+= nvmem-rockchip-otp.o
>   nvmem-rockchip-otp-y		:= rockchip-otp.o
> +obj-$(CONFIG_REALTEK_DHC_EFUSE)	+= nvmem-rtk-dhc-efuse.o
> +nvmem-rtk-dhc-efuse-y		:= rtk-dhc-efuse.o
>   obj-$(CONFIG_NVMEM_SUNXI_SID)	+= nvmem_sunxi_sid.o
>   nvmem_stm32_romem-y 		:= stm32-romem.o
>   obj-$(CONFIG_NVMEM_STM32_ROMEM) += nvmem_stm32_romem.o
> diff --git a/drivers/nvmem/rtk-dhc-efuse.c b/drivers/nvmem/rtk-dhc-efuse.c
> new file mode 100644
> index 000000000000..4672db2c2619
> --- /dev/null
> +++ b/drivers/nvmem/rtk-dhc-efuse.c
> @@ -0,0 +1,86 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Realtek Digital Home Center eFuse
> + *
> + * Copyright (c) 2020 Andreas Färber
> + */
> +
> +#include <linux/io.h>
> +#include <linux/module.h>
> +#include <linux/nvmem-provider.h>
> +#include <linux/of.h>
> +#include <linux/of_address.h>
> +#include <linux/platform_device.h>
> +#include <linux/slab.h>
> +
> +struct dhc_efuse {
> +	struct device *dev;
> +	void __iomem *base;
> +	struct nvmem_device *nvmem;
> +};
> +
> +static int dhc_efuse_reg_read(void *priv, unsigned int offset, void *val,
> +	size_t bytes)
> +{
> +	struct dhc_efuse *efuse = priv;
> +	u8 *buf = val;
> +
> +	while (bytes--)
> +		*buf++ = readb_relaxed(efuse->base + offset++);
> +
> +	return 0;
> +}
> +
> +static int dhc_efuse_probe(struct platform_device *pdev)
> +{
> +	struct dhc_efuse *efuse;
> +	struct nvmem_config config = {};
> +	struct resource *res;
> +
> +	efuse = devm_kzalloc(&pdev->dev, sizeof(*efuse), GFP_KERNEL);
> +	if (!efuse)
> +		return -ENOMEM;
> +
> +	efuse->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
> +	if (IS_ERR(efuse->base))
> +		return PTR_ERR(efuse->base);
> +
> +	efuse->dev = &pdev->dev;
> +
> +	config.dev = &pdev->dev;
> +	config.name = "dhc-efuse";
> +	config.owner = THIS_MODULE;
> +	config.type = NVMEM_TYPE_OTP;
> +	config.read_only = true,
> +	config.word_size = 4;
> +	config.stride = 1;
> +	config.size = resource_size(res);
> +	config.reg_read = dhc_efuse_reg_read;
> +	config.priv = efuse;
> +
> +	efuse->nvmem = devm_nvmem_register(&pdev->dev, &config);
> +	if (IS_ERR(efuse->nvmem)) {
> +		dev_err(&pdev->dev, "failed to register nvmem (%ld)\n",
> +			PTR_ERR(efuse->nvmem));
> +		return PTR_ERR(efuse->nvmem);
> +	}
> +
> +	return 0;
> +}
> +
> +static const struct of_device_id dhc_efuse_dt_ids[] = {
> +	 { .compatible = "realtek,rtd1195-efuse" },
> +	 { }
> +};
> +
> +static struct platform_driver dhc_efuse_driver = {
> +	.probe = dhc_efuse_probe,
> +	.driver = {
> +		.name = "rtk-dhc-efuse",
> +		.of_match_table	= dhc_efuse_dt_ids,
> +	},
> +};
> +module_platform_driver(dhc_efuse_driver);
> +
> +MODULE_DESCRIPTION("Realtek DHC eFuse driver");
> +MODULE_LICENSE("GPL");
>
diff mbox series

Patch

diff --git a/MAINTAINERS b/MAINTAINERS
index 1d0d6ab20451..02117fbf0e57 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2312,6 +2312,7 @@  F:	Documentation/devicetree/bindings/soc/realtek/
 F:	arch/arm/boot/dts/rtd*
 F:	arch/arm/mach-realtek/
 F:	arch/arm64/boot/dts/realtek/
+F:	drivers/nvmem/rtk-dhc-efuse.c
 F:	drivers/soc/realtek/
 
 ARM/RENESAS ARM64 ARCHITECTURE
diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index d7b7f6d688e7..75cf43b16cf9 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -129,6 +129,15 @@  config NVMEM_SPMI_SDAM
 	  Qualcomm Technologies, Inc. PMICs. It provides the clients
 	  an interface to read/write to the SDAM module's shared memory.
 
+config REALTEK_DHC_EFUSE
+	tristate "Realtek DHC eFuse Support"
+	depends on ARCH_REALTEK || COMPILE_TEST
+	depends on HAS_IOMEM
+	help
+	  Say y here to enable read-only access to the Realtek Digital Home
+	  This driver can also be built as a module. If so, the module
+	  will be called nvmem-rtk-dhc-efuse.
+
 config ROCKCHIP_EFUSE
 	tristate "Rockchip eFuse Support"
 	depends on ARCH_ROCKCHIP || COMPILE_TEST
diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
index a7c377218341..67cefdfa44e6 100644
--- a/drivers/nvmem/Makefile
+++ b/drivers/nvmem/Makefile
@@ -33,6 +33,8 @@  obj-$(CONFIG_ROCKCHIP_EFUSE)	+= nvmem_rockchip_efuse.o
 nvmem_rockchip_efuse-y		:= rockchip-efuse.o
 obj-$(CONFIG_ROCKCHIP_OTP)	+= nvmem-rockchip-otp.o
 nvmem-rockchip-otp-y		:= rockchip-otp.o
+obj-$(CONFIG_REALTEK_DHC_EFUSE)	+= nvmem-rtk-dhc-efuse.o
+nvmem-rtk-dhc-efuse-y		:= rtk-dhc-efuse.o
 obj-$(CONFIG_NVMEM_SUNXI_SID)	+= nvmem_sunxi_sid.o
 nvmem_stm32_romem-y 		:= stm32-romem.o
 obj-$(CONFIG_NVMEM_STM32_ROMEM) += nvmem_stm32_romem.o
diff --git a/drivers/nvmem/rtk-dhc-efuse.c b/drivers/nvmem/rtk-dhc-efuse.c
new file mode 100644
index 000000000000..4672db2c2619
--- /dev/null
+++ b/drivers/nvmem/rtk-dhc-efuse.c
@@ -0,0 +1,86 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Realtek Digital Home Center eFuse
+ *
+ * Copyright (c) 2020 Andreas Färber
+ */
+
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/nvmem-provider.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+struct dhc_efuse {
+	struct device *dev;
+	void __iomem *base;
+	struct nvmem_device *nvmem;
+};
+
+static int dhc_efuse_reg_read(void *priv, unsigned int offset, void *val,
+	size_t bytes)
+{
+	struct dhc_efuse *efuse = priv;
+	u8 *buf = val;
+
+	while (bytes--)
+		*buf++ = readb_relaxed(efuse->base + offset++);
+
+	return 0;
+}
+
+static int dhc_efuse_probe(struct platform_device *pdev)
+{
+	struct dhc_efuse *efuse;
+	struct nvmem_config config = {};
+	struct resource *res;
+
+	efuse = devm_kzalloc(&pdev->dev, sizeof(*efuse), GFP_KERNEL);
+	if (!efuse)
+		return -ENOMEM;
+
+	efuse->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
+	if (IS_ERR(efuse->base))
+		return PTR_ERR(efuse->base);
+
+	efuse->dev = &pdev->dev;
+
+	config.dev = &pdev->dev;
+	config.name = "dhc-efuse";
+	config.owner = THIS_MODULE;
+	config.type = NVMEM_TYPE_OTP;
+	config.read_only = true,
+	config.word_size = 4;
+	config.stride = 1;
+	config.size = resource_size(res);
+	config.reg_read = dhc_efuse_reg_read;
+	config.priv = efuse;
+
+	efuse->nvmem = devm_nvmem_register(&pdev->dev, &config);
+	if (IS_ERR(efuse->nvmem)) {
+		dev_err(&pdev->dev, "failed to register nvmem (%ld)\n",
+			PTR_ERR(efuse->nvmem));
+		return PTR_ERR(efuse->nvmem);
+	}
+
+	return 0;
+}
+
+static const struct of_device_id dhc_efuse_dt_ids[] = {
+	 { .compatible = "realtek,rtd1195-efuse" },
+	 { }
+};
+
+static struct platform_driver dhc_efuse_driver = {
+	.probe = dhc_efuse_probe,
+	.driver = {
+		.name = "rtk-dhc-efuse",
+		.of_match_table	= dhc_efuse_dt_ids,
+	},
+};
+module_platform_driver(dhc_efuse_driver);
+
+MODULE_DESCRIPTION("Realtek DHC eFuse driver");
+MODULE_LICENSE("GPL");