From nobody Thu Sep 19 01:17:33 2024 Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [195.130.137.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A25FB1E4B0 for ; Fri, 26 Jul 2024 13:38:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.130.137.89 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722001106; cv=none; b=uQjycYi7DRZRu0zgSyMHV0+R5OOrVHPHcv+xigu70ZPM9r9Ry+y1I+KEHqU3BU6dzqD4mr4vY3U2mbggF8TwoV2dAxxX/QDqY2P7il9oVcwzGz+y4cxBUYrh3rw5p3Mrn/2gYzSnzOSydzH/Ub+wtMqNGKtn0FQ46NSo2qT8NiU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722001106; c=relaxed/simple; bh=c0QJusAxP5dOfvfL9mRfUFCS79xP76Q4+6WOV2k+k0Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ACiYFTboZ6n3zB5EL+V6sASQGRXAI0i94pd5os5KvyR/TdYnlRXX6384x7PxTNPbSqGOfKNUEpSqHGzjzjIuSgluvX5wnxEEY2ZLASeQaivh5G6wZBe9BzA7URo5Nhl0v1CQ2m3wAocxTDVxRX2qHhmgS888xehl5LebkGcp5Cw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=glider.be; spf=none smtp.mailfrom=linux-m68k.org; arc=none smtp.client-ip=195.130.137.89 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=glider.be Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux-m68k.org Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed80:3d94:87cf:603a:d7ae]) by laurent.telenet-ops.be with bizsmtp id sDeD2C00S1mGjv501DeDkH; Fri, 26 Jul 2024 15:38:15 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1sXL8p-003cM2-R8; Fri, 26 Jul 2024 15:38:13 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1sXL9B-004G6J-KE; Fri, 26 Jul 2024 15:38:13 +0200 From: Geert Uytterhoeven To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Magnus Damm , Srinivas Kandagatla , Yoshihiro Shimoda , Arnd Bergmann Cc: devicetree@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v3 2/7] nvmem: Add R-Car E-FUSE driver Date: Fri, 26 Jul 2024 15:38:07 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" R-Car Gen4 SoCs contain fuses indicating hardware support or hardware (e.g. tuning) parameters. Add a driver to access the state of the fuses. This supports two types of hardware fuse providers: 1. E-FUSE non-volatile memory accessible through the Pin Function Controller on R-Car V3U and S4-8, 2. E-FUSE non-volatile memory accessible through OTP_MEM on R-Car V4H and V4M. The state of the cells can be read using the NVMEM framework, either from kernel space (e.g. by the Renesas UFSHCD driver), or from userspace. Signed-off-by: Geert Uytterhoeven Reviewed-by: Yoshihiro Shimoda --- v3: - Drop superfluous semicolon, - Drop the custom rcar_fuse_read() kernel API, in favor of the standard nvmem_cell_*() API, - Drop support for explicitly-instantiated platform devices with accompanying platform data, which would be needed to support fuses tightly integrated with the Pin Function Controller on R-Car Gen3 SoCs. It can be added when a use case shows up. - Move from drivers/soc/renesas/ to drivers/nvmem/, - Register the full register block that contains the E-FUSE data registers with the nvmem subsystem, but use keepouts to ignore all registers before the first or after the last documented data register. Undocumented registers in between are still accessible. - Replace offset/nregs in rcar_fuse_data by start/end, - Use __ioread32_copy() helper, - Initialize most fields of struct nvmem_config in its declaration, - Rename nvmem device from "fuse" to "rcar-fuse", - Use NVMEM_DEVID_NONE, - Add an entry to the MAINTAINERS file, v2: - Add Reviewed-by. --- MAINTAINERS | 1 + drivers/nvmem/Kconfig | 11 +++ drivers/nvmem/Makefile | 2 + drivers/nvmem/rcar-efuse.c | 142 +++++++++++++++++++++++++++++++++++++ 4 files changed, 156 insertions(+) create mode 100644 drivers/nvmem/rcar-efuse.c diff --git a/MAINTAINERS b/MAINTAINERS index 8da9c4ee231b4db4..142e1ecf88c19773 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2802,6 +2802,7 @@ F: arch/arm/mach-shmobile/ F: arch/arm/mach-shmobile/ F: arch/arm64/boot/dts/renesas/ F: arch/riscv/boot/dts/renesas/ +F: drivers/nvmem/rcar-efuse.c F: drivers/pmdomain/renesas/ F: drivers/soc/renesas/ F: include/linux/soc/renesas/ diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index 283134498fbc3315..567baf73be90375e 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -246,6 +246,17 @@ config NVMEM_RAVE_SP_EEPROM help Say y here to enable Rave SP EEPROM support. =20 +config NVMEM_RCAR_EFUSE + tristate "Renesas R-Car Gen4 E-FUSE support" + depends on (ARCH_RENESAS && ARM64) || COMPILE_TEST + depends on NVMEM + help + Enable support for reading the fuses in the E-FUSE or OTP + non-volatile memory block on Renesas R-Car Gen4 SoCs. + + This driver can also be built as a module. If so, the module + will be called nvmem-rcar-efuse. + config NVMEM_RMEM tristate "Reserved Memory Based Driver Support" depends on HAS_IOMEM diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index cdd01fbf1313b58c..5b77bbb6488bf89b 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -52,6 +52,8 @@ obj-$(CONFIG_NVMEM_QCOM_SEC_QFPROM) +=3D nvmem_sec_qfprom= .o nvmem_sec_qfprom-y :=3D sec-qfprom.o obj-$(CONFIG_NVMEM_RAVE_SP_EEPROM) +=3D nvmem-rave-sp-eeprom.o nvmem-rave-sp-eeprom-y :=3D rave-sp-eeprom.o +obj-$(CONFIG_NVMEM_RCAR_EFUSE) +=3D nvmem-rcar-efuse.o +nvmem-rcar-efuse-y :=3D rcar-efuse.o obj-$(CONFIG_NVMEM_RMEM) +=3D nvmem-rmem.o nvmem-rmem-y :=3D rmem.o obj-$(CONFIG_NVMEM_ROCKCHIP_EFUSE) +=3D nvmem_rockchip_efuse.o diff --git a/drivers/nvmem/rcar-efuse.c b/drivers/nvmem/rcar-efuse.c new file mode 100644 index 0000000000000000..f24bdb9cb5a7296f --- /dev/null +++ b/drivers/nvmem/rcar-efuse.c @@ -0,0 +1,142 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Renesas R-Car E-FUSE/OTP Driver + * + * Copyright (C) 2024 Glider bv + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +struct rcar_fuse { + struct nvmem_keepout keepouts[2]; + struct nvmem_device *nvmem; + struct device *dev; + void __iomem *base; +}; + +struct rcar_fuse_data { + unsigned int bank; /* 0: PFC + E-FUSE, 1: OPT_MEM + E-FUSE */ + unsigned int start; /* inclusive */ + unsigned int end; /* exclusive */ +}; + +static int rcar_fuse_reg_read(void *priv, unsigned int offset, void *val, + size_t bytes) +{ + struct rcar_fuse *fuse =3D priv; + int ret; + + ret =3D pm_runtime_resume_and_get(fuse->dev); + if (ret < 0) + return ret; + + __ioread32_copy(val, fuse->base + offset, bytes / 4); + + pm_runtime_put(fuse->dev); + + return 0; +} + +static int rcar_fuse_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + const struct rcar_fuse_data *data =3D device_get_match_data(dev); + struct nvmem_config config =3D { + .dev =3D dev, + .name =3D "rcar-fuse", + .id =3D NVMEM_DEVID_NONE, + .owner =3D THIS_MODULE, + .type =3D NVMEM_TYPE_OTP, + .read_only =3D true, + .root_only =3D true, + .reg_read =3D rcar_fuse_reg_read, + .word_size =3D 4, + .stride =3D 4, + }; + struct rcar_fuse *fuse; + struct resource *res; + int ret; + + ret =3D devm_pm_runtime_enable(dev); + if (ret < 0) + return ret; + + fuse =3D devm_kzalloc(dev, sizeof(*fuse), GFP_KERNEL); + if (!fuse) + return -ENOMEM; + + fuse->base =3D devm_platform_get_and_ioremap_resource(pdev, data->bank, + &res); + if (IS_ERR(fuse->base)) + return PTR_ERR(fuse->base); + + fuse->dev =3D dev; + fuse->keepouts[0].start =3D 0; + fuse->keepouts[0].end =3D data->start; + fuse->keepouts[1].start =3D data->end; + fuse->keepouts[1].end =3D resource_size(res); + + config.keepout =3D fuse->keepouts; + config.nkeepout =3D ARRAY_SIZE(fuse->keepouts); + config.size =3D resource_size(res); + config.priv =3D fuse; + + fuse->nvmem =3D devm_nvmem_register(dev, &config); + if (IS_ERR(fuse->nvmem)) + return dev_err_probe(dev, PTR_ERR(fuse->nvmem), + "Failed to register NVMEM device\n"); + + return 0; +} + +static const struct rcar_fuse_data rcar_fuse_v3u =3D { + .bank =3D 0, + .start =3D 0x0c0, + .end =3D 0x0e8, +}; + +static const struct rcar_fuse_data rcar_fuse_s4 =3D { + .bank =3D 0, + .start =3D 0x0c0, + .end =3D 0x14c, +}; + +static const struct rcar_fuse_data rcar_fuse_v4h =3D { + .bank =3D 1, + .start =3D 0x100, + .end =3D 0x1a0, +}; + +static const struct rcar_fuse_data rcar_fuse_v4m =3D { + .bank =3D 1, + .start =3D 0x100, + .end =3D 0x110, +}; + +static const struct of_device_id rcar_fuse_match[] =3D { + { .compatible =3D "renesas,r8a779a0-efuse", .data =3D &rcar_fuse_v3u }, + { .compatible =3D "renesas,r8a779f0-efuse", .data =3D &rcar_fuse_s4 }, + { .compatible =3D "renesas,r8a779g0-otp", .data =3D &rcar_fuse_v4h }, + { .compatible =3D "renesas,r8a779h0-otp", .data =3D &rcar_fuse_v4m }, + { /* sentinel */ } +}; + +static struct platform_driver rcar_fuse_driver =3D { + .probe =3D rcar_fuse_probe, + .driver =3D { + .name =3D "rcar_fuse", + .of_match_table =3D rcar_fuse_match, + }, +}; +module_platform_driver(rcar_fuse_driver); + +MODULE_DESCRIPTION("Renesas R-Car E-FUSE/OTP driver"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Geert Uytterhoeven"); --=20 2.34.1