* [PATCH v5 1/3] drivers: rng: meson: add support for S4
2023-09-29 10:29 [PATCH v5 0/3] Meson S4 HW RNG Support Alexey Romanov
@ 2023-09-29 10:29 ` Alexey Romanov
2023-09-29 10:29 ` [PATCH v5 2/3] dt-bindings: rng: meson: add meson-rng-s4 compatible Alexey Romanov
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Alexey Romanov @ 2023-09-29 10:29 UTC (permalink / raw)
To: narmstrong, neil.armstrong, olivia, herbert, robh+dt,
krzysztof.kozlowski+dt, conor+dt, conor, khilman, jbrunet,
martin.blumenstingl, f.fainelli, hkallweit1, lists
Cc: linux-arm-kernel, linux-amlogic, linux-kernel, devicetree,
linux-crypto, kernel, Alexey Romanov
From: Alexey Romanov <avromanov@sberdevices.ru>
For some Amlogic SOC's, mechanism to obtain random number
has been changed. For example, S4 now uses status bit waiting algo.
Signed-off-by: Alexey Romanov <avromanov@sberdevices.ru>
---
drivers/char/hw_random/meson-rng.c | 80 ++++++++++++++++++++++++++++--
1 file changed, 77 insertions(+), 3 deletions(-)
diff --git a/drivers/char/hw_random/meson-rng.c b/drivers/char/hw_random/meson-rng.c
index a4eb8e35f13d..75225eb9fef6 100644
--- a/drivers/char/hw_random/meson-rng.c
+++ b/drivers/char/hw_random/meson-rng.c
@@ -13,12 +13,23 @@
#include <linux/types.h>
#include <linux/of.h>
#include <linux/clk.h>
+#include <linux/iopoll.h>
-#define RNG_DATA 0x00
+#define RNG_DATA 0x00
+#define RNG_S4_DATA 0x08
+#define RNG_S4_CFG 0x00
+
+#define RUN_BIT BIT(0)
+#define SEED_READY_STS_BIT BIT(31)
+
+struct meson_rng_priv {
+ int (*read)(struct hwrng *rng, void *buf, size_t max, bool wait);
+};
struct meson_rng_data {
void __iomem *base;
struct hwrng rng;
+ struct device *dev;
};
static int meson_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
@@ -31,16 +42,62 @@ static int meson_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
return sizeof(u32);
}
+static int meson_rng_wait_status(void __iomem *cfg_addr, int bit)
+{
+ u32 status = 0;
+ int ret;
+
+ ret = readl_relaxed_poll_timeout_atomic(cfg_addr,
+ status, !(status & bit),
+ 10, 10000);
+ if (ret)
+ return -EBUSY;
+
+ return 0;
+}
+
+static int meson_s4_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
+{
+ struct meson_rng_data *data =
+ container_of(rng, struct meson_rng_data, rng);
+
+ void __iomem *cfg_addr = data->base + RNG_S4_CFG;
+ int err;
+
+ writel_relaxed(readl_relaxed(cfg_addr) | SEED_READY_STS_BIT, cfg_addr);
+
+ err = meson_rng_wait_status(cfg_addr, SEED_READY_STS_BIT);
+ if (err) {
+ dev_err(data->dev, "Seed isn't ready, try again\n");
+ return err;
+ }
+
+ err = meson_rng_wait_status(cfg_addr, RUN_BIT);
+ if (err) {
+ dev_err(data->dev, "Can't get random number, try again\n");
+ return err;
+ }
+
+ *(u32 *)buf = readl_relaxed(data->base + RNG_S4_DATA);
+
+ return sizeof(u32);
+}
+
static int meson_rng_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct meson_rng_data *data;
struct clk *core_clk;
+ const struct meson_rng_priv *priv;
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;
+ priv = device_get_match_data(&pdev->dev);
+ if (!priv)
+ return -ENODEV;
+
data->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(data->base))
return PTR_ERR(data->base);
@@ -51,13 +108,30 @@ static int meson_rng_probe(struct platform_device *pdev)
"Failed to get core clock\n");
data->rng.name = pdev->name;
- data->rng.read = meson_rng_read;
+ data->rng.read = priv->read;
+
+ data->dev = &pdev->dev;
return devm_hwrng_register(dev, &data->rng);
}
+static const struct meson_rng_priv meson_rng_priv = {
+ .read = meson_rng_read,
+};
+
+static const struct meson_rng_priv meson_rng_priv_s4 = {
+ .read = meson_s4_rng_read,
+};
+
static const struct of_device_id meson_rng_of_match[] = {
- { .compatible = "amlogic,meson-rng", },
+ {
+ .compatible = "amlogic,meson-rng",
+ .data = (void *)&meson_rng_priv,
+ },
+ {
+ .compatible = "amlogic,meson-s4-rng",
+ .data = (void *)&meson_rng_priv_s4,
+ },
{},
};
MODULE_DEVICE_TABLE(of, meson_rng_of_match);
--
2.25.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v5 2/3] dt-bindings: rng: meson: add meson-rng-s4 compatible
2023-09-29 10:29 [PATCH v5 0/3] Meson S4 HW RNG Support Alexey Romanov
2023-09-29 10:29 ` [PATCH v5 1/3] drivers: rng: meson: add support for S4 Alexey Romanov
@ 2023-09-29 10:29 ` Alexey Romanov
2023-09-29 10:29 ` [PATCH v5 3/3] arch/arm64: dts: meson-s4: add hwrng node Alexey Romanov
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Alexey Romanov @ 2023-09-29 10:29 UTC (permalink / raw)
To: narmstrong, neil.armstrong, olivia, herbert, robh+dt,
krzysztof.kozlowski+dt, conor+dt, conor, khilman, jbrunet,
martin.blumenstingl, f.fainelli, hkallweit1, lists
Cc: linux-arm-kernel, linux-amlogic, linux-kernel, devicetree,
linux-crypto, kernel, Alexey Romanov, Conor Dooley
From: Alexey Romanov <avromanov@sberdevices.ru>
Add compatible for hardware number generator node for
Amlogic S4-series.
Signed-off-by: Alexey Romanov <avromanov@sberdevices.ru>
Acked-by: Conor Dooley <conor.dooley@microchip.com>
---
Documentation/devicetree/bindings/rng/amlogic,meson-rng.yaml | 1 +
1 file changed, 1 insertion(+)
diff --git a/Documentation/devicetree/bindings/rng/amlogic,meson-rng.yaml b/Documentation/devicetree/bindings/rng/amlogic,meson-rng.yaml
index 457a6e43d810..afa52af442a7 100644
--- a/Documentation/devicetree/bindings/rng/amlogic,meson-rng.yaml
+++ b/Documentation/devicetree/bindings/rng/amlogic,meson-rng.yaml
@@ -14,6 +14,7 @@ properties:
compatible:
enum:
- amlogic,meson-rng
+ - amlogic,meson-s4-rng
reg:
maxItems: 1
--
2.25.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v5 3/3] arch/arm64: dts: meson-s4: add hwrng node
2023-09-29 10:29 [PATCH v5 0/3] Meson S4 HW RNG Support Alexey Romanov
2023-09-29 10:29 ` [PATCH v5 1/3] drivers: rng: meson: add support for S4 Alexey Romanov
2023-09-29 10:29 ` [PATCH v5 2/3] dt-bindings: rng: meson: add meson-rng-s4 compatible Alexey Romanov
@ 2023-09-29 10:29 ` Alexey Romanov
2023-10-02 7:01 ` (subset) [PATCH v5 0/3] Meson S4 HW RNG Support Neil Armstrong
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Alexey Romanov @ 2023-09-29 10:29 UTC (permalink / raw)
To: narmstrong, neil.armstrong, olivia, herbert, robh+dt,
krzysztof.kozlowski+dt, conor+dt, conor, khilman, jbrunet,
martin.blumenstingl, f.fainelli, hkallweit1, lists
Cc: linux-arm-kernel, linux-amlogic, linux-kernel, devicetree,
linux-crypto, kernel, Alexey Romanov
From: Alexey Romanov <avromanov@sberdevices.ru>
Using this node, we can obtain random numbers via
hardware random number generator.
Signed-off-by: Alexey Romanov <avromanov@sberdevices.ru>
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
---
arch/arm64/boot/dts/amlogic/meson-s4.dtsi | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/arm64/boot/dts/amlogic/meson-s4.dtsi b/arch/arm64/boot/dts/amlogic/meson-s4.dtsi
index 5a3abcc08ee5..e0cfc54ebccb 100644
--- a/arch/arm64/boot/dts/amlogic/meson-s4.dtsi
+++ b/arch/arm64/boot/dts/amlogic/meson-s4.dtsi
@@ -148,6 +148,11 @@ ir: ir@84040 {
interrupts = <GIC_SPI 22 IRQ_TYPE_EDGE_RISING>;
status = "disabled";
};
+
+ hwrng: rng@440788 {
+ compatible = "amlogic,meson-s4-rng";
+ reg = <0x0 0x440788 0x0 0x0c>;
+ };
};
};
};
--
2.25.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: (subset) [PATCH v5 0/3] Meson S4 HW RNG Support
2023-09-29 10:29 [PATCH v5 0/3] Meson S4 HW RNG Support Alexey Romanov
` (2 preceding siblings ...)
2023-09-29 10:29 ` [PATCH v5 3/3] arch/arm64: dts: meson-s4: add hwrng node Alexey Romanov
@ 2023-10-02 7:01 ` Neil Armstrong
2023-10-05 10:27 ` Herbert Xu
2023-10-06 6:43 ` Neil Armstrong
5 siblings, 0 replies; 7+ messages in thread
From: Neil Armstrong @ 2023-10-02 7:01 UTC (permalink / raw)
To: olivia, herbert, robh+dt, krzysztof.kozlowski+dt, conor+dt,
conor, khilman, jbrunet, martin.blumenstingl, f.fainelli,
hkallweit1, lists, Neil Armstrong, Alexey Romanov
Cc: linux-arm-kernel, linux-amlogic, linux-kernel, devicetree,
linux-crypto, kernel
Hi,
On Fri, 29 Sep 2023 13:29:35 +0300, Alexey Romanov wrote:
> This patch series adds hwrng support for Amlogic S4-series.
> Now, S4 uses a new random number generation algorithm.
> This changes implemnents new algo and also adds description
> to meson-s4.dtsi.
>
> V2:
>
> [...]
Thanks, Applied to https://git.kernel.org/pub/scm/linux/kernel/git/amlogic/linux.git (v6.7/arm64-dt)
[3/3] arch/arm64: dts: meson-s4: add hwrng node
https://git.kernel.org/amlogic/c/1e3dbe8006247386592a2fdce3a52cca15625997
These changes has been applied on the intermediate git tree [1].
The v6.7/arm64-dt branch will then be sent via a formal Pull Request to the Linux SoC maintainers
for inclusion in their intermediate git branches in order to be sent to Linus during
the next merge window, or sooner if it's a set of fixes.
In the cases of fixes, those will be merged in the current release candidate
kernel and as soon they appear on the Linux master branch they will be
backported to the previous Stable and Long-Stable kernels [2].
The intermediate git branches are merged daily in the linux-next tree [3],
people are encouraged testing these pre-release kernels and report issues on the
relevant mailing-lists.
If problems are discovered on those changes, please submit a signed-off-by revert
patch followed by a corrective changeset.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/amlogic/linux.git
[2] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
[3] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
--
Neil
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v5 0/3] Meson S4 HW RNG Support
2023-09-29 10:29 [PATCH v5 0/3] Meson S4 HW RNG Support Alexey Romanov
` (3 preceding siblings ...)
2023-10-02 7:01 ` (subset) [PATCH v5 0/3] Meson S4 HW RNG Support Neil Armstrong
@ 2023-10-05 10:27 ` Herbert Xu
2023-10-06 6:43 ` Neil Armstrong
5 siblings, 0 replies; 7+ messages in thread
From: Herbert Xu @ 2023-10-05 10:27 UTC (permalink / raw)
To: Alexey Romanov
Cc: narmstrong, neil.armstrong, olivia, robh+dt,
krzysztof.kozlowski+dt, conor+dt, conor, khilman, jbrunet,
martin.blumenstingl, f.fainelli, hkallweit1, lists,
linux-arm-kernel, linux-amlogic, linux-kernel, devicetree,
linux-crypto, kernel
On Fri, Sep 29, 2023 at 01:29:35PM +0300, Alexey Romanov wrote:
> Hello!
>
> This patch series adds hwrng support for Amlogic S4-series.
> Now, S4 uses a new random number generation algorithm.
> This changes implemnents new algo and also adds description
> to meson-s4.dtsi.
>
> V2:
>
> - Use readl_relaxed_poll_timeout_atomic() function instead of loop.
> - Use two different functions: meson_rng_read() and meson_s4_rng_read().
> - Fix naming in DT schema (meson-s4-hwrng instead of meson-hwrng-s4).
> - A little code style fixes.
>
> V3:
>
> - Fix commit message in patch with dt-bindings schema changes.
>
> V4:
>
> - Drop struct meson_rng_priv field from struct meson_rng_data.
>
> V5:
>
> - Rebased over v6.7/arm64-dt (Amlogic repo).
>
> Alexey Romanov (3):
> drivers: rng: meson: add support for S4
> dt-bindings: rng: meson: add meson-rng-s4 compatible
> arch/arm64: dts: meson-s4: add hwrng node
>
> .../bindings/rng/amlogic,meson-rng.yaml | 1 +
> arch/arm64/boot/dts/amlogic/meson-s4.dtsi | 5 ++
> drivers/char/hw_random/meson-rng.c | 80 ++++++++++++++++++-
> 3 files changed, 83 insertions(+), 3 deletions(-)
>
> --
> 2.25.1
Patches 1-2 applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v5 0/3] Meson S4 HW RNG Support
2023-09-29 10:29 [PATCH v5 0/3] Meson S4 HW RNG Support Alexey Romanov
` (4 preceding siblings ...)
2023-10-05 10:27 ` Herbert Xu
@ 2023-10-06 6:43 ` Neil Armstrong
5 siblings, 0 replies; 7+ messages in thread
From: Neil Armstrong @ 2023-10-06 6:43 UTC (permalink / raw)
To: olivia, herbert, robh+dt, krzysztof.kozlowski+dt, conor+dt,
conor, khilman, jbrunet, martin.blumenstingl, f.fainelli,
hkallweit1, lists, Neil Armstrong, Alexey Romanov
Cc: linux-arm-kernel, linux-amlogic, linux-kernel, devicetree,
linux-crypto, kernel
Hi,
On Fri, 29 Sep 2023 13:29:35 +0300, Alexey Romanov wrote:
> This patch series adds hwrng support for Amlogic S4-series.
> Now, S4 uses a new random number generation algorithm.
> This changes implemnents new algo and also adds description
> to meson-s4.dtsi.
>
> V2:
>
> [...]
Thanks, Applied to https://git.kernel.org/pub/scm/linux/kernel/git/amlogic/linux.git (v6.7/arm64-dt)
[1/3] drivers: rng: meson: add support for S4
(no commit info)
[2/3] dt-bindings: rng: meson: add meson-rng-s4 compatible
(no commit info)
[3/3] arch/arm64: dts: meson-s4: add hwrng node
https://git.kernel.org/amlogic/c/1e3dbe8006247386592a2fdce3a52cca15625997
These changes has been applied on the intermediate git tree [1].
The v6.7/arm64-dt branch will then be sent via a formal Pull Request to the Linux SoC maintainers
for inclusion in their intermediate git branches in order to be sent to Linus during
the next merge window, or sooner if it's a set of fixes.
In the cases of fixes, those will be merged in the current release candidate
kernel and as soon they appear on the Linux master branch they will be
backported to the previous Stable and Long-Stable kernels [2].
The intermediate git branches are merged daily in the linux-next tree [3],
people are encouraged testing these pre-release kernels and report issues on the
relevant mailing-lists.
If problems are discovered on those changes, please submit a signed-off-by revert
patch followed by a corrective changeset.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/amlogic/linux.git
[2] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
[3] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
--
Neil
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply [flat|nested] 7+ messages in thread