2021-05-11 13:31:40

by Linus Walleij

[permalink] [raw]
Subject: [PATCH 1/5] hw_random: ixp4xx: enable compile-testing

From: Arnd Bergmann <[email protected]>

The driver is almost portable already, it just needs to
include the new header for the cpu definition.

Cc: Deepak Saxena <[email protected]>
Signed-off-by: Arnd Bergmann <[email protected]>
Signed-off-by: Linus Walleij <[email protected]>
---
The idea is to apply this through the ARM SoC tree along
with other IXP4xx refactorings.
Please tell me if you prefer another solution.
---
drivers/char/hw_random/Kconfig | 2 +-
drivers/char/hw_random/ixp4xx-rng.c | 3 +--
2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
index 1fe006f3f12f..f033a11cc90d 100644
--- a/drivers/char/hw_random/Kconfig
+++ b/drivers/char/hw_random/Kconfig
@@ -152,7 +152,7 @@ config HW_RANDOM_VIA

config HW_RANDOM_IXP4XX
tristate "Intel IXP4xx NPU HW Pseudo-Random Number Generator support"
- depends on ARCH_IXP4XX
+ depends on ARCH_IXP4XX || COMPILE_TEST
default HW_RANDOM
help
This driver provides kernel-side support for the Pseudo-Random
diff --git a/drivers/char/hw_random/ixp4xx-rng.c b/drivers/char/hw_random/ixp4xx-rng.c
index beec1627db3c..34781028caec 100644
--- a/drivers/char/hw_random/ixp4xx-rng.c
+++ b/drivers/char/hw_random/ixp4xx-rng.c
@@ -21,10 +21,9 @@
#include <linux/init.h>
#include <linux/bitops.h>
#include <linux/hw_random.h>
+#include <linux/soc/ixp4xx/cpu.h>

#include <asm/io.h>
-#include <mach/hardware.h>
-

static int ixp4xx_rng_data_read(struct hwrng *rng, u32 *buffer)
{
--
2.30.2


2021-05-11 13:31:53

by Linus Walleij

[permalink] [raw]
Subject: [PATCH 5/5] hw_random: ixp4xx: Add OF support

This makes the hardware random number generator found in
the IXP46x SoCs probe from the device tree.

Cc: Deepak Saxena <[email protected]>
Signed-off-by: Linus Walleij <[email protected]>
---
The idea is to apply this through the ARM SoC tree along
with other IXP4xx refactorings.
Please tell me if you prefer another solution.
---
drivers/char/hw_random/ixp4xx-rng.c | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/drivers/char/hw_random/ixp4xx-rng.c b/drivers/char/hw_random/ixp4xx-rng.c
index 8b59aeefd4a4..188854dd16a9 100644
--- a/drivers/char/hw_random/ixp4xx-rng.c
+++ b/drivers/char/hw_random/ixp4xx-rng.c
@@ -19,6 +19,7 @@
#include <linux/init.h>
#include <linux/bitops.h>
#include <linux/hw_random.h>
+#include <linux/of.h>
#include <linux/soc/ixp4xx/cpu.h>

#include <asm/io.h>
@@ -55,9 +56,18 @@ static int ixp4xx_rng_probe(struct platform_device *pdev)
return devm_hwrng_register(dev, &ixp4xx_rng_ops);
}

+static const struct of_device_id ixp4xx_rng_of_match[] = {
+ {
+ .compatible = "intel,ixp46x-rng",
+ },
+ {},
+};
+MODULE_DEVICE_TABLE(of, ixp4xx_rng_of_match);
+
static struct platform_driver ixp4xx_rng_driver = {
.driver = {
.name = "ixp4xx-hwrandom",
+ .of_match_table = ixp4xx_rng_of_match,
},
.probe = ixp4xx_rng_probe,
};
--
2.30.2

2021-05-11 13:31:57

by Linus Walleij

[permalink] [raw]
Subject: [PATCH 4/5] hw_random: ixp4xx: Add DT bindings

This adds device tree bindings for the simple random number
generator found in the IXP46x SoCs.

Cc: Deepak Saxena <[email protected]>
Cc: [email protected]
Signed-off-by: Linus Walleij <[email protected]>
---
The idea is to apply this through the ARM SoC tree along
with other IXP4xx refactorings.
Please tell me if you prefer another solution.
---
.../bindings/rng/intel,ixp46x-rng.yaml | 36 +++++++++++++++++++
MAINTAINERS | 1 +
2 files changed, 37 insertions(+)
create mode 100644 Documentation/devicetree/bindings/rng/intel,ixp46x-rng.yaml

diff --git a/Documentation/devicetree/bindings/rng/intel,ixp46x-rng.yaml b/Documentation/devicetree/bindings/rng/intel,ixp46x-rng.yaml
new file mode 100644
index 000000000000..61963fa9347e
--- /dev/null
+++ b/Documentation/devicetree/bindings/rng/intel,ixp46x-rng.yaml
@@ -0,0 +1,36 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/rng/intel,ixp46x-rng.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Intel IXP46x RNG bindings
+
+description: |
+ The Intel IXP46x has a random number generator at a fixed physical
+ location in memory. Each read is guaranteed to provide a unique
+ 32 bit random number.
+
+maintainers:
+ - Linus Walleij <[email protected]>
+
+properties:
+ compatible:
+ const: intel,ixp46x-rng
+
+ reg:
+ maxItems: 1
+
+required:
+ - compatible
+ - reg
+
+additionalProperties: false
+
+examples:
+ - |
+ rng@70002100 {
+ compatible = "intel,ixp46x-rng";
+ reg = <0x70002100 4>;
+ };
+
diff --git a/MAINTAINERS b/MAINTAINERS
index bd7aff0c120f..cc4bb4e75f04 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -9248,6 +9248,7 @@ F: include/linux/soc/ixp4xx/qmgr.h
INTEL IXP4XX RANDOM NUMBER GENERATOR SUPPORT
M: Deepak Saxena <[email protected]>
S: Maintained
+F: Documentation/devicetree/bindings/display/intel,ixp46x-rng.yaml
F: drivers/char/hw_random/ixp4xx-rng.c

INTEL KEEM BAY DRM DRIVER
--
2.30.2

2021-05-11 13:32:39

by Linus Walleij

[permalink] [raw]
Subject: [PATCH 3/5] hw_random: ixp4xx: Turn into a module

Instead of just initializing always, which will invariably
create problems on multiplatform builds, turn this driver into
a module and pass a resource with the memory location.
The device only exist on the IXP46x so we only register
the device for the IXP46x SoC.

Cc: Deepak Saxena <[email protected]>
Signed-off-by: Linus Walleij <[email protected]>
---
The idea is to apply this through the ARM SoC tree along
with other IXP4xx refactorings.
Please tell me if you prefer another solution.
---
arch/arm/mach-ixp4xx/common.c | 24 ++++++++++++++++++-
drivers/char/hw_random/ixp4xx-rng.c | 37 +++++++++++++----------------
2 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/arch/arm/mach-ixp4xx/common.c b/arch/arm/mach-ixp4xx/common.c
index f86c1bf34eea..a10aa14d09b1 100644
--- a/arch/arm/mach-ixp4xx/common.c
+++ b/arch/arm/mach-ixp4xx/common.c
@@ -237,6 +237,27 @@ static struct resource ixp46x_i2c_resources[] = {
}
};

+/* A single 32-bit register on IXP46x */
+#define IXP4XX_HWRANDOM_BASE_PHYS 0x70002100
+
+static struct resource ixp46x_hwrandom_resource[] = {
+ {
+ .start = IXP4XX_HWRANDOM_BASE_PHYS,
+ .end = IXP4XX_HWRANDOM_BASE_PHYS + 0x3,
+ .flags = IORESOURCE_MEM,
+ },
+};
+
+static struct platform_device ixp46x_hwrandom_device = {
+ .name = "ixp4xx-hwrandom",
+ .id = -1,
+ .dev = {
+ .coherent_dma_mask = DMA_BIT_MASK(32),
+ },
+ .resource = ixp46x_hwrandom_resource,
+ .num_resources = ARRAY_SIZE(ixp46x_hwrandom_resource),
+};
+
/*
* I2C controller. The IXP46x uses the same block as the IOP3xx, so
* we just use the same device name.
@@ -249,7 +270,8 @@ static struct platform_device ixp46x_i2c_controller = {
};

static struct platform_device *ixp46x_devices[] __initdata = {
- &ixp46x_i2c_controller
+ &ixp46x_hwrandom_device,
+ &ixp46x_i2c_controller,
};

unsigned long ixp4xx_exp_bus_size;
diff --git a/drivers/char/hw_random/ixp4xx-rng.c b/drivers/char/hw_random/ixp4xx-rng.c
index defd8176cb68..8b59aeefd4a4 100644
--- a/drivers/char/hw_random/ixp4xx-rng.c
+++ b/drivers/char/hw_random/ixp4xx-rng.c
@@ -15,6 +15,7 @@
#include <linux/types.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
+#include <linux/platform_device.h>
#include <linux/init.h>
#include <linux/bitops.h>
#include <linux/hw_random.h>
@@ -36,35 +37,31 @@ static struct hwrng ixp4xx_rng_ops = {
.data_read = ixp4xx_rng_data_read,
};

-static int __init ixp4xx_rng_init(void)
+static int ixp4xx_rng_probe(struct platform_device *pdev)
{
void __iomem * rng_base;
- int err;
+ struct device *dev = &pdev->dev;
+ struct resource *res;

if (!cpu_is_ixp46x()) /* includes IXP455 */
return -ENOSYS;

- rng_base = ioremap(0x70002100, 4);
- if (!rng_base)
- return -ENOMEM;
- ixp4xx_rng_ops.priv = (unsigned long)rng_base;
- err = hwrng_register(&ixp4xx_rng_ops);
- if (err)
- iounmap(rng_base);
-
- return err;
-}
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ rng_base = devm_ioremap_resource(dev, res);
+ if (IS_ERR(rng_base))
+ return PTR_ERR(rng_base);

-static void __exit ixp4xx_rng_exit(void)
-{
- void __iomem * rng_base = (void __iomem *)ixp4xx_rng_ops.priv;
-
- hwrng_unregister(&ixp4xx_rng_ops);
- iounmap(rng_base);
+ ixp4xx_rng_ops.priv = (unsigned long)rng_base;
+ return devm_hwrng_register(dev, &ixp4xx_rng_ops);
}

-module_init(ixp4xx_rng_init);
-module_exit(ixp4xx_rng_exit);
+static struct platform_driver ixp4xx_rng_driver = {
+ .driver = {
+ .name = "ixp4xx-hwrandom",
+ },
+ .probe = ixp4xx_rng_probe,
+};
+module_platform_driver(ixp4xx_rng_driver);

MODULE_AUTHOR("Deepak Saxena <[email protected]>");
MODULE_DESCRIPTION("H/W Pseudo-Random Number Generator (RNG) driver for IXP45x/46x");
--
2.30.2

2021-05-19 06:03:59

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH 4/5] hw_random: ixp4xx: Add DT bindings

On Tue, 11 May 2021 15:29:27 +0200, Linus Walleij wrote:
> This adds device tree bindings for the simple random number
> generator found in the IXP46x SoCs.
>
> Cc: Deepak Saxena <[email protected]>
> Cc: [email protected]
> Signed-off-by: Linus Walleij <[email protected]>
> ---
> The idea is to apply this through the ARM SoC tree along
> with other IXP4xx refactorings.
> Please tell me if you prefer another solution.
> ---
> .../bindings/rng/intel,ixp46x-rng.yaml | 36 +++++++++++++++++++
> MAINTAINERS | 1 +
> 2 files changed, 37 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/rng/intel,ixp46x-rng.yaml
>

Reviewed-by: Rob Herring <[email protected]>

2021-05-21 10:06:51

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH 1/5] hw_random: ixp4xx: enable compile-testing

On Tue, May 11, 2021 at 03:29:24PM +0200, Linus Walleij wrote:
> From: Arnd Bergmann <[email protected]>
>
> The driver is almost portable already, it just needs to
> include the new header for the cpu definition.
>
> Cc: Deepak Saxena <[email protected]>
> Signed-off-by: Arnd Bergmann <[email protected]>
> Signed-off-by: Linus Walleij <[email protected]>
> ---
> The idea is to apply this through the ARM SoC tree along
> with other IXP4xx refactorings.
> Please tell me if you prefer another solution.
> ---
> drivers/char/hw_random/Kconfig | 2 +-
> drivers/char/hw_random/ixp4xx-rng.c | 3 +--
> 2 files changed, 2 insertions(+), 3 deletions(-)

Acked-by: Herbert Xu <[email protected]>
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

2021-05-21 10:06:51

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH 3/5] hw_random: ixp4xx: Turn into a module

On Tue, May 11, 2021 at 03:29:26PM +0200, Linus Walleij wrote:
> Instead of just initializing always, which will invariably
> create problems on multiplatform builds, turn this driver into
> a module and pass a resource with the memory location.
> The device only exist on the IXP46x so we only register
> the device for the IXP46x SoC.
>
> Cc: Deepak Saxena <[email protected]>
> Signed-off-by: Linus Walleij <[email protected]>
> ---
> The idea is to apply this through the ARM SoC tree along
> with other IXP4xx refactorings.
> Please tell me if you prefer another solution.
> ---
> arch/arm/mach-ixp4xx/common.c | 24 ++++++++++++++++++-
> drivers/char/hw_random/ixp4xx-rng.c | 37 +++++++++++++----------------
> 2 files changed, 40 insertions(+), 21 deletions(-)

Acked-by: Herbert Xu <[email protected]>
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

2021-05-21 10:07:03

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH 5/5] hw_random: ixp4xx: Add OF support

On Tue, May 11, 2021 at 03:29:28PM +0200, Linus Walleij wrote:
> This makes the hardware random number generator found in
> the IXP46x SoCs probe from the device tree.
>
> Cc: Deepak Saxena <[email protected]>
> Signed-off-by: Linus Walleij <[email protected]>
> ---
> The idea is to apply this through the ARM SoC tree along
> with other IXP4xx refactorings.
> Please tell me if you prefer another solution.
> ---
> drivers/char/hw_random/ixp4xx-rng.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)

Acked-by: Herbert Xu <[email protected]>
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt