* [PATCH v2 0/3] Meson S4 HW RNG Support
@ 2023-08-07 13:06 Alexey Romanov
2023-08-07 13:06 ` [PATCH v2 1/3] drivers: rng: meson: add support for S4 Alexey Romanov
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Alexey Romanov @ 2023-08-07 13:06 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
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.
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.38.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/3] drivers: rng: meson: add support for S4
2023-08-07 13:06 [PATCH v2 0/3] Meson S4 HW RNG Support Alexey Romanov
@ 2023-08-07 13:06 ` Alexey Romanov
2023-08-07 13:06 ` [PATCH v2 2/3] dt-bindings: rng: meson: add meson-rng-s4 compatible Alexey Romanov
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Alexey Romanov @ 2023-08-07 13:06 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
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..5e1dee659866 100644
--- a/drivers/char/hw_random/meson-rng.c
+++ b/drivers/char/hw_random/meson-rng.c
@@ -13,12 +13,24 @@
#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;
+ const struct meson_rng_priv *priv;
};
static int meson_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
@@ -31,6 +43,47 @@ 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;
@@ -41,6 +94,10 @@ static int meson_rng_probe(struct platform_device *pdev)
if (!data)
return -ENOMEM;
+ data->priv = device_get_match_data(&pdev->dev);
+ if (!data->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 = data->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.38.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/3] dt-bindings: rng: meson: add meson-rng-s4 compatible
2023-08-07 13:06 [PATCH v2 0/3] Meson S4 HW RNG Support Alexey Romanov
2023-08-07 13:06 ` [PATCH v2 1/3] drivers: rng: meson: add support for S4 Alexey Romanov
@ 2023-08-07 13:06 ` Alexey Romanov
2023-08-08 12:09 ` Conor Dooley
2023-08-07 13:06 ` [PATCH v2 3/3] arch/arm64: dts: meson-s4: add hwrng node Alexey Romanov
2023-08-16 16:08 ` [PATCH v2 0/3] Meson S4 HW RNG Support Alexey Romanov
3 siblings, 1 reply; 8+ messages in thread
From: Alexey Romanov @ 2023-08-07 13:06 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
Now the driver has a separate algo for S4 SoC.
Signed-off-by: Alexey Romanov <avromanov@sberdevices.ru>
---
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.38.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 3/3] arch/arm64: dts: meson-s4: add hwrng node
2023-08-07 13:06 [PATCH v2 0/3] Meson S4 HW RNG Support Alexey Romanov
2023-08-07 13:06 ` [PATCH v2 1/3] drivers: rng: meson: add support for S4 Alexey Romanov
2023-08-07 13:06 ` [PATCH v2 2/3] dt-bindings: rng: meson: add meson-rng-s4 compatible Alexey Romanov
@ 2023-08-07 13:06 ` Alexey Romanov
2023-08-16 16:08 ` [PATCH v2 0/3] Meson S4 HW RNG Support Alexey Romanov
3 siblings, 0 replies; 8+ messages in thread
From: Alexey Romanov @ 2023-08-07 13:06 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
Using this node, we can obtain random numbers via
hardware random number generator.
Signed-off-by: Alexey Romanov <avromanov@sberdevices.ru>
---
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 f24460186d3d..b3a1ecf36467 100644
--- a/arch/arm64/boot/dts/amlogic/meson-s4.dtsi
+++ b/arch/arm64/boot/dts/amlogic/meson-s4.dtsi
@@ -133,6 +133,11 @@ reset: reset-controller@2000 {
reg = <0x0 0x2000 0x0 0x98>;
#reset-cells = <1>;
};
+
+ hwrng: rng@440788 {
+ compatible = "amlogic,meson-s4-rng";
+ reg = <0x0 0x440788 0x0 0x0c>;
+ };
};
};
};
--
2.38.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/3] dt-bindings: rng: meson: add meson-rng-s4 compatible
2023-08-07 13:06 ` [PATCH v2 2/3] dt-bindings: rng: meson: add meson-rng-s4 compatible Alexey Romanov
@ 2023-08-08 12:09 ` Conor Dooley
2023-08-08 12:11 ` Conor Dooley
0 siblings, 1 reply; 8+ messages in thread
From: Conor Dooley @ 2023-08-08 12:09 UTC (permalink / raw)
To: Alexey Romanov
Cc: narmstrong, neil.armstrong, olivia, herbert, robh+dt,
krzysztof.kozlowski+dt, conor+dt, khilman, jbrunet,
martin.blumenstingl, f.fainelli, hkallweit1, lists,
linux-arm-kernel, linux-amlogic, linux-kernel, devicetree,
linux-crypto, kernel
[-- Attachment #1.1: Type: text/plain, Size: 880 bytes --]
On Mon, Aug 07, 2023 at 04:06:10PM +0300, Alexey Romanov wrote:
> Now the driver has a separate algo for S4 SoC.
>
> Signed-off-by: Alexey Romanov <avromanov@sberdevices.ru>
Acked-by: Conor Dooley <conor.dooley@microchip.com>
Thanks,
Conor.
> ---
> 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.38.1
>
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
[-- Attachment #2: Type: text/plain, Size: 176 bytes --]
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/3] dt-bindings: rng: meson: add meson-rng-s4 compatible
2023-08-08 12:09 ` Conor Dooley
@ 2023-08-08 12:11 ` Conor Dooley
2023-08-16 16:09 ` Alexey Romanov
0 siblings, 1 reply; 8+ messages in thread
From: Conor Dooley @ 2023-08-08 12:11 UTC (permalink / raw)
To: Alexey Romanov
Cc: narmstrong, neil.armstrong, olivia, herbert, robh+dt,
krzysztof.kozlowski+dt, conor+dt, khilman, jbrunet,
martin.blumenstingl, f.fainelli, hkallweit1, lists,
linux-arm-kernel, linux-amlogic, linux-kernel, devicetree,
linux-crypto, kernel
[-- Attachment #1.1: Type: text/plain, Size: 477 bytes --]
On Tue, Aug 08, 2023 at 01:09:45PM +0100, Conor Dooley wrote:
> On Mon, Aug 07, 2023 at 04:06:10PM +0300, Alexey Romanov wrote:
> > Now the driver has a separate algo for S4 SoC.
> >
> > Signed-off-by: Alexey Romanov <avromanov@sberdevices.ru>
>
> Acked-by: Conor Dooley <conor.dooley@microchip.com>
Actually, one comment, please, for bindings, write commit messages that
relate to the hardware rather than drivers. The bindings describe the
hardware, after all.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
[-- Attachment #2: Type: text/plain, Size: 176 bytes --]
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/3] Meson S4 HW RNG Support
2023-08-07 13:06 [PATCH v2 0/3] Meson S4 HW RNG Support Alexey Romanov
` (2 preceding siblings ...)
2023-08-07 13:06 ` [PATCH v2 3/3] arch/arm64: dts: meson-s4: add hwrng node Alexey Romanov
@ 2023-08-16 16:08 ` Alexey Romanov
3 siblings, 0 replies; 8+ messages in thread
From: Alexey Romanov @ 2023-08-16 16:08 UTC (permalink / raw)
To: narmstrong@baylibre.com, neil.armstrong@linaro.org,
olivia@selenic.com, herbert@gondor.apana.org.au,
robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org,
conor+dt@kernel.org, conor@kernel.org, khilman@baylibre.com,
jbrunet@baylibre.com, martin.blumenstingl@googlemail.com,
f.fainelli@gmail.com, hkallweit1@gmail.com, lists@kaiser.cx
Cc: linux-arm-kernel@lists.infradead.org,
linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, linux-crypto@vger.kernel.org, kernel
Hi!
Really sorry for the noise, but
I would like to receive some feedback on my patchset.
On Mon, Aug 07, 2023 at 04:06:08PM +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.
>
> 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.38.1
>
--
Thank you,
Alexey
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/3] dt-bindings: rng: meson: add meson-rng-s4 compatible
2023-08-08 12:11 ` Conor Dooley
@ 2023-08-16 16:09 ` Alexey Romanov
0 siblings, 0 replies; 8+ messages in thread
From: Alexey Romanov @ 2023-08-16 16:09 UTC (permalink / raw)
To: Conor Dooley
Cc: narmstrong@baylibre.com, neil.armstrong@linaro.org,
olivia@selenic.com, herbert@gondor.apana.org.au,
robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org,
conor+dt@kernel.org, khilman@baylibre.com, jbrunet@baylibre.com,
martin.blumenstingl@googlemail.com, f.fainelli@gmail.com,
hkallweit1@gmail.com, lists@kaiser.cx,
linux-arm-kernel@lists.infradead.org,
linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, linux-crypto@vger.kernel.org, kernel
Hi, Conor!
Thank you for the review.
On Tue, Aug 08, 2023 at 01:11:24PM +0100, Conor Dooley wrote:
> On Tue, Aug 08, 2023 at 01:09:45PM +0100, Conor Dooley wrote:
> > On Mon, Aug 07, 2023 at 04:06:10PM +0300, Alexey Romanov wrote:
> > > Now the driver has a separate algo for S4 SoC.
> > >
> > > Signed-off-by: Alexey Romanov <avromanov@sberdevices.ru>
> >
> > Acked-by: Conor Dooley <conor.dooley@microchip.com>
>
> Actually, one comment, please, for bindings, write commit messages that
> relate to the hardware rather than drivers. The bindings describe the
> hardware, after all.
Yeah, will fix this in V3.
--
Thank you,
Alexey
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-08-16 16:10 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-07 13:06 [PATCH v2 0/3] Meson S4 HW RNG Support Alexey Romanov
2023-08-07 13:06 ` [PATCH v2 1/3] drivers: rng: meson: add support for S4 Alexey Romanov
2023-08-07 13:06 ` [PATCH v2 2/3] dt-bindings: rng: meson: add meson-rng-s4 compatible Alexey Romanov
2023-08-08 12:09 ` Conor Dooley
2023-08-08 12:11 ` Conor Dooley
2023-08-16 16:09 ` Alexey Romanov
2023-08-07 13:06 ` [PATCH v2 3/3] arch/arm64: dts: meson-s4: add hwrng node Alexey Romanov
2023-08-16 16:08 ` [PATCH v2 0/3] Meson S4 HW RNG Support Alexey Romanov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox