From patchwork Tue Jun 23 02:50:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 11619659 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6C8EE14E3 for ; Tue, 23 Jun 2020 03:03:48 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4424120786 for ; Tue, 23 Jun 2020 03:03:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="TkJuABxE"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="c31stJxN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4424120786 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=H54dM0e4Jp0mj2YSf2rbL8c0z6zXQVq7yKY2U4NBmDI=; b=TkJuABxEVVGmqbOLVxI/DD1Yt OkjDTCd2XQfSpxBKJ5cS0ONbupipqvcDiDV+c/ugyVP6DYwOjVXHeDWS3bElbgqb4GCtE9xA3IpEh v62Apnd6HY3Js9EJSzMylxfzDJRwkEnQ0J+R6H4R3WAbHBDvgDMBKiD+o1E759pXdT43ZoSYxGY9/ nTIgqiIEo/V090Qt4U4sNWrcsRfjb+xRwFtC+N0/CwsL26YE8s1sJF023wRldveiv/QfyC1SXYAn6 jusB5hKJVEKku3ev/ArW/uiY6a9IWJxKVbxx6DObx7185IQr4OztAARnJzeak3H/AzDu7t3oXNxWQ 6zsP/mLag==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jnZBi-0000Kn-Ih; Tue, 23 Jun 2020 03:01:30 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jnZ3i-0002lT-35; Tue, 23 Jun 2020 02:53:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description; bh=1X6JQmlyO/7lB//QQ3nXejnV6kNwzuxP2EVIq4k5O6U=; b=c31stJxNDM/wgAuhfxXPNkzQZF A3nsD7Asjzq7Tf0AbzzTYZJFn3gplDOV3X7XBdThBeLbTSaklWpAA3TvR5SEukSpSVZA9sDNvaA9G RoSBaornx4S832AieOrMAayXFWSSXTkhuYD9fJfvC2NoymJQGdgl+BfE6QAag7EL2fAz93W4nslIV fbr+MYtL/UpuuFzvMhnc7KGSRB/lTkZrBAvkmtTHYxzIDg+U+bmjp0+5HKYWcuwYe489wGaM2h8qj pP7yqS7e4QpVgVDZKtejNtbBKxV2e+1H/fhSN8t9iTmsBJE3xTlI2g+0egouNEClPH+u00rhAA7xZ HMv7QdcQ==; Received: from mx2.suse.de ([195.135.220.15]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jnZ3e-0005Wx-Eb; Tue, 23 Jun 2020 02:53:12 +0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 216E2B19B; Tue, 23 Jun 2020 02:51:38 +0000 (UTC) From: =?utf-8?q?Andreas_F=C3=A4rber?= To: linux-realtek-soc@lists.infradead.org Subject: [PATCH v2 18/29] nvmem: Add Realtek DHC eFuse driver Date: Tue, 23 Jun 2020 04:50:55 +0200 Message-Id: <20200623025106.31273-19-afaerber@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200623025106.31273-1-afaerber@suse.de> References: <20200623025106.31273-1-afaerber@suse.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200623_035310_627884_48E87224 X-CRM114-Status: GOOD ( 20.88 ) X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.4.4 on casper.infradead.org summary: Content analysis details: (-4.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [195.135.220.15 listed in wl.mailspike.net] -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [195.135.220.15 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?SmFtZXMgVGFpIFvmiLTlv5fls7Bd?= , Edgar Lee , linux-kernel@vger.kernel.org, Srinivas Kandagatla , =?utf-8?b?U3Rhbmxl?= =?utf-8?b?eSBDaGFuZyBb5piM6IKy5b63XQ==?= , =?utf-8?q?Andreas_F=C3=A4rber?= , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Implement enough of a read-only nvmem driver to easily read efuse cells. Cc: Cheng-Yu Lee Signed-off-by: Andreas Färber --- 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 +#include +#include +#include +#include +#include +#include + +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");