* Re: [PATCH v2 2/3] hwrng: Add Cortina Systems CS7542 TRNG driver
@ 2026-12-02 12:48 kernel test robot
0 siblings, 0 replies; 3+ messages in thread
From: kernel test robot @ 2026-12-02 12:48 UTC (permalink / raw)
To: oe-kbuild; +Cc: lkp
::::::
:::::: Manual check reason: "low confidence static check warning: drivers/char/hw_random/cs75xx-trng.c:172:9: sparse: warning: Initializer entry defined twice"
:::::: Manual check reason: "linux-review patch is more than 7 days old, verify it wasn't already superseded"
::::::
BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20261124-b4-cs7542-trng-v2-2-0192937b44be@gmail.com>
References: <20261124-b4-cs7542-trng-v2-2-0192937b44be@gmail.com>
TO: Fil Dunsky via B4 Relay <devnull+filipp.dunsky.gmail.com@kernel.org>
TO: Olivia Mackall <olivia@selenic.com>
TO: Herbert Xu <herbert@gondor.apana.org.au>
TO: Rob Herring <robh@kernel.org>
TO: Krzysztof Kozlowski <krzk@kernel.org>
TO: Conor Dooley <conor+dt@kernel.org>
CC: "Uwe Kleine-König" <u.kleine-koenig@baylibre.com>
CC: linux-crypto@vger.kernel.org
CC: devicetree@vger.kernel.org
CC: linux-arm-kernel@lists.infradead.org
CC: linux-kernel@vger.kernel.org
Hi Fil,
kernel test robot noticed the following build warnings:
[auto build test WARNING on b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f]
url: https://github.com/intel-lab-lkp/linux/commits/Fil-Dunsky-via-B4-Relay/dt-bindings-rng-Add-Cortina-Systems-CS7542-TRNG/20261124-112019
base: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
patch link: https://lore.kernel.org/r/20261124-b4-cs7542-trng-v2-2-0192937b44be%40gmail.com
patch subject: [PATCH v2 2/3] hwrng: Add Cortina Systems CS7542 TRNG driver
:::::: branch date: 8 days ago
:::::: commit date: 8 days ago
config: arc-randconfig-r2306-20261130 (https://download.01.org/0day-ci/archive/20261202/20261202134013.4kZYMPi8-lkp@intel.com/config)
compiler: arc-linux-gcc (GCC) 9.5.0
sparse: v0.6.5-rc1-94-g0d159c10
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261202/20261202134013.4kZYMPi8-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/r/20261202134013.4kZYMPi8-lkp@intel.com/
sparse warnings: (new ones prefixed by >>)
>> drivers/char/hw_random/cs75xx-trng.c:172:9: sparse: warning: Initializer entry defined twice
drivers/char/hw_random/cs75xx-trng.c:173:9: sparse: also defined here
vim +172 drivers/char/hw_random/cs75xx-trng.c
afad09adc9498c Fil Dunsky 2026-11-24 170
afad09adc9498c Fil Dunsky 2026-11-24 171 static const struct of_device_id cs75xx_trng_of_match[] = {
afad09adc9498c Fil Dunsky 2026-11-24 @172 { .compatible = "cortina,cs7542-trng" },
afad09adc9498c Fil Dunsky 2026-11-24 173 { }
afad09adc9498c Fil Dunsky 2026-11-24 174 };
afad09adc9498c Fil Dunsky 2026-11-24 175 MODULE_DEVICE_TABLE(of, cs75xx_trng_of_match);
afad09adc9498c Fil Dunsky 2026-11-24 176
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH v2 0/3] hwrng: Add Cortina Systems CS7542 random number generator
@ 2026-11-24 8:20 Fil Dunsky via B4 Relay
2026-11-24 8:20 ` Fil Dunsky via B4 Relay
0 siblings, 1 reply; 3+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-24 8:20 UTC (permalink / raw)
To: Olivia Mackall, Herbert Xu, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: Uwe Kleine-König, linux-crypto, devicetree, linux-arm-kernel,
linux-kernel
Add the Elliptic random number generator integrated in the CS7542,
based on the GPL vendor and OpenWrt implementations. Use a syscon
regmap for its shared global scratch bit and provide bounded polling,
nonblocking pending requests and partial output through the hwrng core.
Hardware ring reseeding is limited to the documented CS7542 A1 path.
The vendor driver avoids it on A0 for erratum 28891 and substitutes a
RTC/timer-derived nonce. Reject unsupported revisions using the global
syscon identification register instead of adopting that workaround.
The saved Almond+ capture identifies the tested board as CS7542 A1.
The binding, driver and MAINTAINERS entry apply to Linux v7.4-rc4
without the pending CS75xx platform or clock/pinctrl series.
The existing OpenWrt entropy quality setting of 512 is retained for
review. The output smoke tests do not establish an entropy estimate.
The v1 sources passed binding/example checks, ARM built-in and module
builds and RAM hardware smoke tests on Almond+. The hardware test
returned EAGAIN for the first nonblocking read, then provided 4096
bytes without all-zero or repeated-block output.
No additional hardware run is claimed for v2. The generating path on
A1 is unchanged; revision checks and their error paths were tested
with the actual C code and mocked resource/regmap/hwrng interfaces.
Full ARM W=1 built-in and module builds were repeated for v2.
---
Changes in v2:
- Drop the redundant linux/mod_devicetable.h include as suggested by
Uwe Kleine-König. The existing linux/of.h provides the OF device ID.
- Restrict hardware reseeding to CS7542 A1 after inspecting the vendor
erratum 28891 workaround. Propagate revision-read failures and reject
unsupported silicon before registering the hwrng.
- Describe the hardware revision restriction and identification register
in the binding.
- Link to v1: https://lore.kernel.org/all/20261123-b4-cs7542-trng-v1-0-92d9ffcee531@gmail.com/
To: Fil Dunsky <filipp.dunsky@gmail.com>
To: Olivia Mackall <olivia@selenic.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
To: Rob Herring <robh@kernel.org>
To: Krzysztof Kozlowski <krzk+dt@kernel.org>
To: Conor Dooley <conor+dt@kernel.org>
Cc: linux-crypto@vger.kernel.org
Cc: devicetree@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
Fil Dunsky (3):
dt-bindings: rng: Add Cortina Systems CS7542 TRNG
hwrng: Add Cortina Systems CS7542 TRNG driver
MAINTAINERS: Add Cortina Systems CS7542 TRNG support
.../bindings/rng/cortina,cs7542-trng.yaml | 43 +++++
MAINTAINERS | 7 +
drivers/char/hw_random/Kconfig | 11 ++
drivers/char/hw_random/Makefile | 1 +
drivers/char/hw_random/cs75xx-trng.c | 187 +++++++++++++++++++++
5 files changed, 249 insertions(+)
---
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
change-id: 20261123-b4-cs7542-trng-1a1b9f1cd392
Best regards,
--
Fil Dunsky <filipp.dunsky@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH v2 2/3] hwrng: Add Cortina Systems CS7542 TRNG driver 2026-11-24 8:20 [PATCH v2 0/3] hwrng: Add Cortina Systems CS7542 random number generator Fil Dunsky via B4 Relay @ 2026-11-24 8:20 ` Fil Dunsky via B4 Relay 0 siblings, 0 replies; 3+ messages in thread From: Fil Dunsky @ 2026-11-24 8:20 UTC (permalink / raw) To: Olivia Mackall, Herbert Xu, Rob Herring, Krzysztof Kozlowski, Conor Dooley Cc: Uwe Kleine-König, linux-crypto, devicetree, linux-arm-kernel, linux-kernel Adapt the OpenWrt implementation to use a syscon regmap for the shared scratch bit. Bound polling and retain a pending request across nonblocking calls instead of entering a blocking poll when wait=false. Handle partial output and wipe the temporary data on error paths. Retain the existing OpenWrt entropy quality setting of 512 for review. Hardware output smoke tests do not establish an entropy estimate. Restrict hardware reseeding to the documented CS7542 A1 revision, using identification bits read through the global syscon before registration. The vendor driver avoids ring reseeding on A0 for erratum 28891; its RTC/timer-derived nonce workaround is not a replacement entropy source. Propagate identification errors and reject unsupported revisions. Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com> --- drivers/char/hw_random/Kconfig | 11 +++ drivers/char/hw_random/Makefile | 1 + drivers/char/hw_random/cs75xx-trng.c | 187 +++++++++++++++++++++++++++++++++++ 3 files changed, 199 insertions(+) diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig index d3108991c..1c6a3f9f8 100644 --- a/drivers/char/hw_random/Kconfig +++ b/drivers/char/hw_random/Kconfig @@ -648,6 +648,17 @@ config HW_RANDOM_QCOM To compile this driver as a module, choose M here. The module will be called qcom-rng. If unsure, say N. + +config HW_RANDOM_CS75XX + tristate "Cortina Systems CS7542 random number generator" + depends on OF && HAS_IOMEM + select MFD_SYSCON + help + Support the Elliptic random number generator in the CS7542 SoC. + Access the shared global control block through a syscon regmap. + Provide polled reads through the hardware RNG framework. + The module will be named cs75xx-trng. + endif # HW_RANDOM config UML_RANDOM diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile index 8fce2aa6c..b7b5fdaa7 100644 --- a/drivers/char/hw_random/Makefile +++ b/drivers/char/hw_random/Makefile @@ -55,3 +55,4 @@ obj-$(CONFIG_HW_RANDOM_ROCKCHIP) += rockchip-rng.o obj-$(CONFIG_HW_RANDOM_JH7110) += jh7110-trng.o obj-$(CONFIG_HW_RANDOM_XILINX) += xilinx-trng.o obj-$(CONFIG_HW_RANDOM_QCOM) += qcom-rng.o +obj-$(CONFIG_HW_RANDOM_CS75XX) += cs75xx-trng.o diff --git a/drivers/char/hw_random/cs75xx-trng.c b/drivers/char/hw_random/cs75xx-trng.c new file mode 100644 index 000000000..588a01aae --- /dev/null +++ b/drivers/char/hw_random/cs75xx-trng.c @@ -0,0 +1,187 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Cortina CS75xx (Goldengate) true random number generator + * + * The block is an Elliptic TRNG: control at 0x00, interrupt status at 0x04, + * interrupt enable at 0x08 and four data words from 0x10. A new value is + * requested with GEN_NEW and is ready when the DONE status bit is set. + * The vendor driver also sets bit 5 of the GLOBAL_SCRATCH register before + * using the block, so does this one. + */ + +#include <linux/bitfield.h> +#include <linux/bits.h> +#include <linux/hw_random.h> +#include <linux/io.h> +#include <linux/iopoll.h> +#include <linux/mfd/syscon.h> +#include <linux/of.h> +#include <linux/regmap.h> +#include <linux/slab.h> +#include <linux/string.h> +#include <linux/module.h> +#include <linux/platform_device.h> + +#define TRNG_CTRL 0x00 +#define TRNG_CTRL_GEN_NEW BIT(0) +#define TRNG_CTRL_RESEED BIT(31) +#define TRNG_IRQ_STAT 0x04 +#define TRNG_IRQ_EN 0x08 +#define TRNG_IRQ_DONE BIT(27) +#define TRNG_DATA 0x10 +#define TRNG_WORDS 4 + +#define GLOBAL_JTAG_ID 0x00 +#define GLOBAL_JTAG_ID_SOC GENMASK(15, 12) +#define GLOBAL_JTAG_ID_CS7542_A1 8 + +#define GLOBAL_SCRATCH 0xc0 +#define GLOBAL_SCRATCH_TRNG BIT(5) + +#define TRNG_TIMEOUT_US 10000 + +struct cs75xx_trng { + struct hwrng rng; + void __iomem *base; + struct regmap *global; + bool pending; +}; + +static int cs75xx_trng_wait(struct cs75xx_trng *t) +{ + u32 val; + int ret; + + ret = readl_poll_timeout(t->base + TRNG_IRQ_STAT, val, + val & TRNG_IRQ_DONE, 1, TRNG_TIMEOUT_US); + writel(TRNG_IRQ_DONE, t->base + TRNG_IRQ_STAT); + return ret; +} + +static int cs75xx_trng_init(struct hwrng *rng) +{ + struct cs75xx_trng *t = container_of(rng, struct cs75xx_trng, rng); + int ret; + + ret = regmap_update_bits(t->global, GLOBAL_SCRATCH, + GLOBAL_SCRATCH_TRNG, GLOBAL_SCRATCH_TRNG); + if (ret) + return ret; + writel(0, t->base + TRNG_IRQ_EN); + writel(TRNG_IRQ_DONE, t->base + TRNG_IRQ_STAT); + t->pending = false; + writel(TRNG_CTRL_RESEED, t->base + TRNG_CTRL); + return cs75xx_trng_wait(t); +} + +static int cs75xx_trng_read(struct hwrng *rng, void *buf, size_t max, bool wait) +{ + struct cs75xx_trng *t = container_of(rng, struct cs75xx_trng, rng); + u32 data[TRNG_WORDS]; + size_t done = 0; + int i, ret; + + while (done < max) { + size_t n = min(max - done, sizeof(data)); + + if (!t->pending) { + writel(TRNG_IRQ_DONE, t->base + TRNG_IRQ_STAT); + writel(TRNG_CTRL_GEN_NEW, t->base + TRNG_CTRL); + t->pending = true; + } + + if (wait) { + ret = cs75xx_trng_wait(t); + } else { + if (!(readl(t->base + TRNG_IRQ_STAT) & TRNG_IRQ_DONE)) + break; + writel(TRNG_IRQ_DONE, t->base + TRNG_IRQ_STAT); + ret = 0; + } + t->pending = false; + if (ret) { + memzero_explicit(data, sizeof(data)); + return done ? done : ret; + } + + for (i = 0; i < TRNG_WORDS; i++) + data[i] = readl(t->base + TRNG_DATA + 4 * i); + memcpy((u8 *)buf + done, data, n); + done += n; + + if (!wait) + break; + } + + memzero_explicit(data, sizeof(data)); + return done; +} + +/* A0 ring reseeding is affected by vendor erratum 28891. Do not replace + * the entropy source with the vendor's RTC/timer-derived nonce workaround. + */ +static int cs75xx_trng_check_revision(struct device *dev, struct regmap *global) +{ + u32 id; + int ret; + + ret = regmap_read(global, GLOBAL_JTAG_ID, &id); + if (ret) + return dev_err_probe(dev, ret, "cannot read SoC revision\n"); + + if (FIELD_GET(GLOBAL_JTAG_ID_SOC, id) != GLOBAL_JTAG_ID_CS7542_A1) + return dev_err_probe(dev, -ENODEV, + "hardware reseeding requires CS7542 A1\n"); + + return 0; +} + +static int cs75xx_trng_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct cs75xx_trng *t; + int ret; + + t = devm_kzalloc(dev, sizeof(*t), GFP_KERNEL); + if (!t) + return -ENOMEM; + + t->base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(t->base)) + return PTR_ERR(t->base); + + t->global = syscon_regmap_lookup_by_phandle(dev->of_node, + "cortina,syscon"); + if (IS_ERR(t->global)) + return dev_err_probe(dev, PTR_ERR(t->global), + "cannot get global control regmap\n"); + + ret = cs75xx_trng_check_revision(dev, t->global); + if (ret) + return ret; + + t->rng.name = dev_name(dev); + t->rng.init = cs75xx_trng_init; + t->rng.read = cs75xx_trng_read; + t->rng.quality = 512; + + return devm_hwrng_register(dev, &t->rng); +} + +static const struct of_device_id cs75xx_trng_of_match[] = { + { .compatible = "cortina,cs7542-trng" }, + { } +}; +MODULE_DEVICE_TABLE(of, cs75xx_trng_of_match); + +static struct platform_driver cs75xx_trng_driver = { + .probe = cs75xx_trng_probe, + .driver = { + .name = "cs75xx-trng", + .of_match_table = cs75xx_trng_of_match, + }, +}; +module_platform_driver(cs75xx_trng_driver); + +MODULE_DESCRIPTION("Cortina CS75xx TRNG driver"); +MODULE_LICENSE("GPL"); -- 2.53.0 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v2 2/3] hwrng: Add Cortina Systems CS7542 TRNG driver @ 2026-11-24 8:20 ` Fil Dunsky via B4 Relay 0 siblings, 0 replies; 3+ messages in thread From: Fil Dunsky via B4 Relay @ 2026-11-24 8:20 UTC (permalink / raw) To: Olivia Mackall, Herbert Xu, Rob Herring, Krzysztof Kozlowski, Conor Dooley Cc: Uwe Kleine-König, linux-crypto, devicetree, linux-arm-kernel, linux-kernel From: Fil Dunsky <filipp.dunsky@gmail.com> Adapt the OpenWrt implementation to use a syscon regmap for the shared scratch bit. Bound polling and retain a pending request across nonblocking calls instead of entering a blocking poll when wait=false. Handle partial output and wipe the temporary data on error paths. Retain the existing OpenWrt entropy quality setting of 512 for review. Hardware output smoke tests do not establish an entropy estimate. Restrict hardware reseeding to the documented CS7542 A1 revision, using identification bits read through the global syscon before registration. The vendor driver avoids ring reseeding on A0 for erratum 28891; its RTC/timer-derived nonce workaround is not a replacement entropy source. Propagate identification errors and reject unsupported revisions. Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com> --- drivers/char/hw_random/Kconfig | 11 +++ drivers/char/hw_random/Makefile | 1 + drivers/char/hw_random/cs75xx-trng.c | 187 +++++++++++++++++++++++++++++++++++ 3 files changed, 199 insertions(+) diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig index d3108991c..1c6a3f9f8 100644 --- a/drivers/char/hw_random/Kconfig +++ b/drivers/char/hw_random/Kconfig @@ -648,6 +648,17 @@ config HW_RANDOM_QCOM To compile this driver as a module, choose M here. The module will be called qcom-rng. If unsure, say N. + +config HW_RANDOM_CS75XX + tristate "Cortina Systems CS7542 random number generator" + depends on OF && HAS_IOMEM + select MFD_SYSCON + help + Support the Elliptic random number generator in the CS7542 SoC. + Access the shared global control block through a syscon regmap. + Provide polled reads through the hardware RNG framework. + The module will be named cs75xx-trng. + endif # HW_RANDOM config UML_RANDOM diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile index 8fce2aa6c..b7b5fdaa7 100644 --- a/drivers/char/hw_random/Makefile +++ b/drivers/char/hw_random/Makefile @@ -55,3 +55,4 @@ obj-$(CONFIG_HW_RANDOM_ROCKCHIP) += rockchip-rng.o obj-$(CONFIG_HW_RANDOM_JH7110) += jh7110-trng.o obj-$(CONFIG_HW_RANDOM_XILINX) += xilinx-trng.o obj-$(CONFIG_HW_RANDOM_QCOM) += qcom-rng.o +obj-$(CONFIG_HW_RANDOM_CS75XX) += cs75xx-trng.o diff --git a/drivers/char/hw_random/cs75xx-trng.c b/drivers/char/hw_random/cs75xx-trng.c new file mode 100644 index 000000000..588a01aae --- /dev/null +++ b/drivers/char/hw_random/cs75xx-trng.c @@ -0,0 +1,187 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Cortina CS75xx (Goldengate) true random number generator + * + * The block is an Elliptic TRNG: control at 0x00, interrupt status at 0x04, + * interrupt enable at 0x08 and four data words from 0x10. A new value is + * requested with GEN_NEW and is ready when the DONE status bit is set. + * The vendor driver also sets bit 5 of the GLOBAL_SCRATCH register before + * using the block, so does this one. + */ + +#include <linux/bitfield.h> +#include <linux/bits.h> +#include <linux/hw_random.h> +#include <linux/io.h> +#include <linux/iopoll.h> +#include <linux/mfd/syscon.h> +#include <linux/of.h> +#include <linux/regmap.h> +#include <linux/slab.h> +#include <linux/string.h> +#include <linux/module.h> +#include <linux/platform_device.h> + +#define TRNG_CTRL 0x00 +#define TRNG_CTRL_GEN_NEW BIT(0) +#define TRNG_CTRL_RESEED BIT(31) +#define TRNG_IRQ_STAT 0x04 +#define TRNG_IRQ_EN 0x08 +#define TRNG_IRQ_DONE BIT(27) +#define TRNG_DATA 0x10 +#define TRNG_WORDS 4 + +#define GLOBAL_JTAG_ID 0x00 +#define GLOBAL_JTAG_ID_SOC GENMASK(15, 12) +#define GLOBAL_JTAG_ID_CS7542_A1 8 + +#define GLOBAL_SCRATCH 0xc0 +#define GLOBAL_SCRATCH_TRNG BIT(5) + +#define TRNG_TIMEOUT_US 10000 + +struct cs75xx_trng { + struct hwrng rng; + void __iomem *base; + struct regmap *global; + bool pending; +}; + +static int cs75xx_trng_wait(struct cs75xx_trng *t) +{ + u32 val; + int ret; + + ret = readl_poll_timeout(t->base + TRNG_IRQ_STAT, val, + val & TRNG_IRQ_DONE, 1, TRNG_TIMEOUT_US); + writel(TRNG_IRQ_DONE, t->base + TRNG_IRQ_STAT); + return ret; +} + +static int cs75xx_trng_init(struct hwrng *rng) +{ + struct cs75xx_trng *t = container_of(rng, struct cs75xx_trng, rng); + int ret; + + ret = regmap_update_bits(t->global, GLOBAL_SCRATCH, + GLOBAL_SCRATCH_TRNG, GLOBAL_SCRATCH_TRNG); + if (ret) + return ret; + writel(0, t->base + TRNG_IRQ_EN); + writel(TRNG_IRQ_DONE, t->base + TRNG_IRQ_STAT); + t->pending = false; + writel(TRNG_CTRL_RESEED, t->base + TRNG_CTRL); + return cs75xx_trng_wait(t); +} + +static int cs75xx_trng_read(struct hwrng *rng, void *buf, size_t max, bool wait) +{ + struct cs75xx_trng *t = container_of(rng, struct cs75xx_trng, rng); + u32 data[TRNG_WORDS]; + size_t done = 0; + int i, ret; + + while (done < max) { + size_t n = min(max - done, sizeof(data)); + + if (!t->pending) { + writel(TRNG_IRQ_DONE, t->base + TRNG_IRQ_STAT); + writel(TRNG_CTRL_GEN_NEW, t->base + TRNG_CTRL); + t->pending = true; + } + + if (wait) { + ret = cs75xx_trng_wait(t); + } else { + if (!(readl(t->base + TRNG_IRQ_STAT) & TRNG_IRQ_DONE)) + break; + writel(TRNG_IRQ_DONE, t->base + TRNG_IRQ_STAT); + ret = 0; + } + t->pending = false; + if (ret) { + memzero_explicit(data, sizeof(data)); + return done ? done : ret; + } + + for (i = 0; i < TRNG_WORDS; i++) + data[i] = readl(t->base + TRNG_DATA + 4 * i); + memcpy((u8 *)buf + done, data, n); + done += n; + + if (!wait) + break; + } + + memzero_explicit(data, sizeof(data)); + return done; +} + +/* A0 ring reseeding is affected by vendor erratum 28891. Do not replace + * the entropy source with the vendor's RTC/timer-derived nonce workaround. + */ +static int cs75xx_trng_check_revision(struct device *dev, struct regmap *global) +{ + u32 id; + int ret; + + ret = regmap_read(global, GLOBAL_JTAG_ID, &id); + if (ret) + return dev_err_probe(dev, ret, "cannot read SoC revision\n"); + + if (FIELD_GET(GLOBAL_JTAG_ID_SOC, id) != GLOBAL_JTAG_ID_CS7542_A1) + return dev_err_probe(dev, -ENODEV, + "hardware reseeding requires CS7542 A1\n"); + + return 0; +} + +static int cs75xx_trng_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct cs75xx_trng *t; + int ret; + + t = devm_kzalloc(dev, sizeof(*t), GFP_KERNEL); + if (!t) + return -ENOMEM; + + t->base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(t->base)) + return PTR_ERR(t->base); + + t->global = syscon_regmap_lookup_by_phandle(dev->of_node, + "cortina,syscon"); + if (IS_ERR(t->global)) + return dev_err_probe(dev, PTR_ERR(t->global), + "cannot get global control regmap\n"); + + ret = cs75xx_trng_check_revision(dev, t->global); + if (ret) + return ret; + + t->rng.name = dev_name(dev); + t->rng.init = cs75xx_trng_init; + t->rng.read = cs75xx_trng_read; + t->rng.quality = 512; + + return devm_hwrng_register(dev, &t->rng); +} + +static const struct of_device_id cs75xx_trng_of_match[] = { + { .compatible = "cortina,cs7542-trng" }, + { } +}; +MODULE_DEVICE_TABLE(of, cs75xx_trng_of_match); + +static struct platform_driver cs75xx_trng_driver = { + .probe = cs75xx_trng_probe, + .driver = { + .name = "cs75xx-trng", + .of_match_table = cs75xx_trng_of_match, + }, +}; +module_platform_driver(cs75xx_trng_driver); + +MODULE_DESCRIPTION("Cortina CS75xx TRNG driver"); +MODULE_LICENSE("GPL"); -- 2.53.0 ^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-02 12:49 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-02 12:48 [PATCH v2 2/3] hwrng: Add Cortina Systems CS7542 TRNG driver kernel test robot -- strict thread matches above, loose matches on Subject: below -- 2026-11-24 8:20 [PATCH v2 0/3] hwrng: Add Cortina Systems CS7542 random number generator Fil Dunsky via B4 Relay 2026-11-24 8:20 ` [PATCH v2 2/3] hwrng: Add Cortina Systems CS7542 TRNG driver Fil Dunsky 2026-11-24 8:20 ` Fil Dunsky via B4 Relay
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.