* [PATCH 0/3] hwrng: Add Cortina Systems CS7542 random number generator
@ 2026-11-23 18:41 Fil Dunsky via B4 Relay
2026-11-23 18:41 ` [PATCH 1/3] dt-bindings: rng: Add Cortina Systems CS7542 TRNG Fil Dunsky via B4 Relay
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-23 18:41 UTC (permalink / raw)
To: Olivia Mackall, Herbert Xu, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: 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. The driver has no
platform Kconfig dependency. Its shared global scratch bit is updated
through a syscon regmap rather than an overlapping raw ioremap.
Polling is bounded. A nonblocking read starts or resumes a pending
transaction and returns immediately if data is not ready, instead of
entering the blocking poll path. Partial output and failure cleanup
preserve the caller's buffer bounds.
The existing OpenWrt quality setting of 512 is retained for review.
The output tests below only check access and obvious stuck output;
they do not characterize entropy or establish this quality estimate.
Feedback on that inherited policy is explicitly requested before
publication of a final version.
The three patches are the binding, the driver/Kconfig/Makefile and a
MAINTAINERS entry. They apply to Linux v7.4-rc4 without the pending
CS75xx platform or clock/pinctrl series. The TRNG syscon phandle can
refer to a generic syscon; the local board integration uses the new
CS7542 global-control binding being prepared separately.
Validation:
- binding schema, example compilation and style checks passed
- strict source checkpatch with --no-signoff: no errors/warnings/checks
- complete minimal ARM vmlinux and modules builds with both new
drivers built in and modular, COMPILE_TEST=n, without the platform
- actual driver functions tested with mocked MMIO/regmap and UBSAN
- exact sources booted in a Linux 7.4-rc4 RAM integration kernel on
Almond+, with platform v9, clock/pinctrl and the accepted watchdog
The first nonblocking read returned EAGAIN and subsequent reads
provided 4096 bytes. Output was neither all zero nor repetitions of one
16-byte block; no entropy estimate is inferred from those tests.
The final combined RAM test recorded 16 checks with no failures and
returned to installed OpenWrt 6.18.64 through the watchdog. Both CPUs
were online. The firmware was not flashed. Earlier incomplete or
experimental alarm runs are not counted as this successful test.
---
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 | 38 +++++
MAINTAINERS | 7 +
drivers/char/hw_random/Kconfig | 11 ++
drivers/char/hw_random/Makefile | 1 +
drivers/char/hw_random/cs75xx-trng.c | 159 +++++++++++++++++++++
5 files changed, 216 insertions(+)
---
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
change-id: 20261123-b4-cs7542-trng-1a1b9f1cd392
Best regards,
--
Fil Dunsky <filipp.dunsky@gmail.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] dt-bindings: rng: Add Cortina Systems CS7542 TRNG
2026-11-23 18:41 [PATCH 0/3] hwrng: Add Cortina Systems CS7542 random number generator Fil Dunsky via B4 Relay
@ 2026-11-23 18:41 ` Fil Dunsky via B4 Relay
2026-11-23 18:41 ` [PATCH 2/3] hwrng: Add Cortina Systems CS7542 TRNG driver Fil Dunsky via B4 Relay
2026-11-23 18:41 ` [PATCH 3/3] MAINTAINERS: Add Cortina Systems CS7542 TRNG support Fil Dunsky via B4 Relay
2 siblings, 0 replies; 4+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-23 18:41 UTC (permalink / raw)
To: Olivia Mackall, Herbert Xu, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: linux-crypto, devicetree, linux-arm-kernel, linux-kernel
From: Fil Dunsky <filipp.dunsky@gmail.com>
Describe the Elliptic TRNG register block and its reference to the
shared global control syscon.
Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
.../bindings/rng/cortina,cs7542-trng.yaml | 38 ++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/Documentation/devicetree/bindings/rng/cortina,cs7542-trng.yaml b/Documentation/devicetree/bindings/rng/cortina,cs7542-trng.yaml
new file mode 100644
index 000000000..9118397d6
--- /dev/null
+++ b/Documentation/devicetree/bindings/rng/cortina,cs7542-trng.yaml
@@ -0,0 +1,38 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/rng/cortina,cs7542-trng.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Cortina Systems CS7542 true random number generator
+
+maintainers:
+ - Fil Dunsky <filipp.dunsky@gmail.com>
+
+properties:
+ compatible:
+ const: cortina,cs7542-trng
+
+ reg:
+ maxItems: 1
+
+ cortina,syscon:
+ $ref: /schemas/types.yaml#/definitions/phandle
+ description:
+ Global control syscon containing the scratch register at offset 0xc0.
+ Bit 5 is set before initializing the random number generator.
+
+required:
+ - compatible
+ - reg
+ - cortina,syscon
+
+additionalProperties: false
+
+examples:
+ - |
+ rng@f0600000 {
+ compatible = "cortina,cs7542-trng";
+ reg = <0xf0600000 0x20>;
+ cortina,syscon = <&global_control>;
+ };
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/3] hwrng: Add Cortina Systems CS7542 TRNG driver
2026-11-23 18:41 [PATCH 0/3] hwrng: Add Cortina Systems CS7542 random number generator Fil Dunsky via B4 Relay
2026-11-23 18:41 ` [PATCH 1/3] dt-bindings: rng: Add Cortina Systems CS7542 TRNG Fil Dunsky via B4 Relay
@ 2026-11-23 18:41 ` Fil Dunsky via B4 Relay
2026-11-23 18:41 ` [PATCH 3/3] MAINTAINERS: Add Cortina Systems CS7542 TRNG support Fil Dunsky via B4 Relay
2 siblings, 0 replies; 4+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-23 18:41 UTC (permalink / raw)
To: Olivia Mackall, Herbert Xu, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: 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.
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 | 159 +++++++++++++++++++++++++++++++++++
3 files changed, 171 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..38a1958df
--- /dev/null
+++ b/drivers/char/hw_random/cs75xx-trng.c
@@ -0,0 +1,159 @@
+// 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/bits.h>
+#include <linux/hw_random.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/mfd/syscon.h>
+#include <linux/mod_devicetable.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_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;
+}
+
+static int cs75xx_trng_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct cs75xx_trng *t;
+
+ 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");
+
+ 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 [flat|nested] 4+ messages in thread
* [PATCH 3/3] MAINTAINERS: Add Cortina Systems CS7542 TRNG support
2026-11-23 18:41 [PATCH 0/3] hwrng: Add Cortina Systems CS7542 random number generator Fil Dunsky via B4 Relay
2026-11-23 18:41 ` [PATCH 1/3] dt-bindings: rng: Add Cortina Systems CS7542 TRNG Fil Dunsky via B4 Relay
2026-11-23 18:41 ` [PATCH 2/3] hwrng: Add Cortina Systems CS7542 TRNG driver Fil Dunsky via B4 Relay
@ 2026-11-23 18:41 ` Fil Dunsky via B4 Relay
2 siblings, 0 replies; 4+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-23 18:41 UTC (permalink / raw)
To: Olivia Mackall, Herbert Xu, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: linux-crypto, devicetree, linux-arm-kernel, linux-kernel
From: Fil Dunsky <filipp.dunsky@gmail.com>
Route changes to the CS7542 random number generator driver and binding
to their subsystem mailing list and the platform maintainer.
Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
MAINTAINERS | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 44540a1eb..46d0a5778 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2949,6 +2949,13 @@ F: tools/perf/tests/shell/coresight/*
F: tools/perf/util/cs-etm-decoder/*
F: tools/perf/util/cs-etm.*
+ARM/CORTINA SYSTEMS CS7542 RANDOM NUMBER GENERATOR
+M: Fil Dunsky <filipp.dunsky@gmail.com>
+L: linux-crypto@vger.kernel.org
+S: Maintained
+F: Documentation/devicetree/bindings/rng/cortina,cs7542-trng.yaml
+F: drivers/char/hw_random/cs75xx-trng.c
+
ARM/CORTINA SYSTEMS GEMINI ARM ARCHITECTURE
M: Hans Ulli Kroll <ulli.kroll@googlemail.com>
M: Linus Walleij <linusw@kernel.org>
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-23 18:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 18:41 [PATCH 0/3] hwrng: Add Cortina Systems CS7542 random number generator Fil Dunsky via B4 Relay
2026-11-23 18:41 ` [PATCH 1/3] dt-bindings: rng: Add Cortina Systems CS7542 TRNG Fil Dunsky via B4 Relay
2026-11-23 18:41 ` [PATCH 2/3] hwrng: Add Cortina Systems CS7542 TRNG driver Fil Dunsky via B4 Relay
2026-11-23 18:41 ` [PATCH 3/3] MAINTAINERS: Add Cortina Systems CS7542 TRNG support Fil Dunsky via B4 Relay
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®