Skip to content

Commit 854a004

Browse files
author
Linus Walleij
committed
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 <dsaxena@plexity.net> Acked-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 479dfb6 commit 854a004

2 files changed

Lines changed: 40 additions & 21 deletions

File tree

arch/arm/mach-ixp4xx/common.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,27 @@ static struct resource ixp46x_i2c_resources[] = {
236236
}
237237
};
238238

239+
/* A single 32-bit register on IXP46x */
240+
#define IXP4XX_HWRANDOM_BASE_PHYS 0x70002100
241+
242+
static struct resource ixp46x_hwrandom_resource[] = {
243+
{
244+
.start = IXP4XX_HWRANDOM_BASE_PHYS,
245+
.end = IXP4XX_HWRANDOM_BASE_PHYS + 0x3,
246+
.flags = IORESOURCE_MEM,
247+
},
248+
};
249+
250+
static struct platform_device ixp46x_hwrandom_device = {
251+
.name = "ixp4xx-hwrandom",
252+
.id = -1,
253+
.dev = {
254+
.coherent_dma_mask = DMA_BIT_MASK(32),
255+
},
256+
.resource = ixp46x_hwrandom_resource,
257+
.num_resources = ARRAY_SIZE(ixp46x_hwrandom_resource),
258+
};
259+
239260
/*
240261
* I2C controller. The IXP46x uses the same block as the IOP3xx, so
241262
* we just use the same device name.
@@ -248,7 +269,8 @@ static struct platform_device ixp46x_i2c_controller = {
248269
};
249270

250271
static struct platform_device *ixp46x_devices[] __initdata = {
251-
&ixp46x_i2c_controller
272+
&ixp46x_hwrandom_device,
273+
&ixp46x_i2c_controller,
252274
};
253275

254276
unsigned long ixp4xx_exp_bus_size;

drivers/char/hw_random/ixp4xx-rng.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/types.h>
1616
#include <linux/module.h>
1717
#include <linux/moduleparam.h>
18+
#include <linux/platform_device.h>
1819
#include <linux/init.h>
1920
#include <linux/bitops.h>
2021
#include <linux/hw_random.h>
@@ -36,35 +37,31 @@ static struct hwrng ixp4xx_rng_ops = {
3637
.data_read = ixp4xx_rng_data_read,
3738
};
3839

39-
static int __init ixp4xx_rng_init(void)
40+
static int ixp4xx_rng_probe(struct platform_device *pdev)
4041
{
4142
void __iomem * rng_base;
42-
int err;
43+
struct device *dev = &pdev->dev;
44+
struct resource *res;
4345

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

47-
rng_base = ioremap(0x70002100, 4);
48-
if (!rng_base)
49-
return -ENOMEM;
50-
ixp4xx_rng_ops.priv = (unsigned long)rng_base;
51-
err = hwrng_register(&ixp4xx_rng_ops);
52-
if (err)
53-
iounmap(rng_base);
54-
55-
return err;
56-
}
49+
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
50+
rng_base = devm_ioremap_resource(dev, res);
51+
if (IS_ERR(rng_base))
52+
return PTR_ERR(rng_base);
5753

58-
static void __exit ixp4xx_rng_exit(void)
59-
{
60-
void __iomem * rng_base = (void __iomem *)ixp4xx_rng_ops.priv;
61-
62-
hwrng_unregister(&ixp4xx_rng_ops);
63-
iounmap(rng_base);
54+
ixp4xx_rng_ops.priv = (unsigned long)rng_base;
55+
return devm_hwrng_register(dev, &ixp4xx_rng_ops);
6456
}
6557

66-
module_init(ixp4xx_rng_init);
67-
module_exit(ixp4xx_rng_exit);
58+
static struct platform_driver ixp4xx_rng_driver = {
59+
.driver = {
60+
.name = "ixp4xx-hwrandom",
61+
},
62+
.probe = ixp4xx_rng_probe,
63+
};
64+
module_platform_driver(ixp4xx_rng_driver);
6865

6966
MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>");
7067
MODULE_DESCRIPTION("H/W Pseudo-Random Number Generator (RNG) driver for IXP45x/46x");

0 commit comments

Comments
 (0)