diff options
Diffstat (limited to 'drivers/char/hw_random/n2-drv.c')
| -rw-r--r-- | drivers/char/hw_random/n2-drv.c | 92 |
1 files changed, 39 insertions, 53 deletions
diff --git a/drivers/char/hw_random/n2-drv.c b/drivers/char/hw_random/n2-drv.c index a3f5e381e74..292a5889f67 100644 --- a/drivers/char/hw_random/n2-drv.c +++ b/drivers/char/hw_random/n2-drv.c @@ -1,13 +1,12 @@ /* n2-drv.c: Niagara-2 RNG driver. * - * Copyright (C) 2008 David S. Miller <davem@davemloft.net> + * Copyright (C) 2008, 2011 David S. Miller <davem@davemloft.net> */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/types.h> #include <linux/delay.h> -#include <linux/init.h> #include <linux/slab.h> #include <linux/workqueue.h> #include <linux/preempt.h> @@ -22,10 +21,10 @@ #define DRV_MODULE_NAME "n2rng" #define PFX DRV_MODULE_NAME ": " -#define DRV_MODULE_VERSION "0.1" -#define DRV_MODULE_RELDATE "May 15, 2008" +#define DRV_MODULE_VERSION "0.2" +#define DRV_MODULE_RELDATE "July 27, 2011" -static char version[] __devinitdata = +static char version[] = DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; MODULE_AUTHOR("David S. Miller (davem@davemloft.net)"); @@ -611,7 +610,7 @@ static void n2rng_work(struct work_struct *work) schedule_delayed_work(&np->work, HZ * 2); } -static void __devinit n2rng_driver_version(void) +static void n2rng_driver_version(void) { static int n2rng_version_printed; @@ -619,24 +618,29 @@ static void __devinit n2rng_driver_version(void) pr_info("%s", version); } -static int __devinit n2rng_probe(struct platform_device *op, - const struct of_device_id *match) +static const struct of_device_id n2rng_match[]; +static int n2rng_probe(struct platform_device *op) { - int victoria_falls = (match->data != NULL); + const struct of_device_id *match; + int multi_capable; int err = -ENOMEM; struct n2rng *np; - n2rng_driver_version(); + match = of_match_device(n2rng_match, &op->dev); + if (!match) + return -EINVAL; + multi_capable = (match->data != NULL); - np = kzalloc(sizeof(*np), GFP_KERNEL); + n2rng_driver_version(); + np = devm_kzalloc(&op->dev, sizeof(*np), GFP_KERNEL); if (!np) goto out; np->op = op; INIT_DELAYED_WORK(&np->work, n2rng_work); - if (victoria_falls) - np->flags |= N2RNG_FLAG_VF; + if (multi_capable) + np->flags |= N2RNG_FLAG_MULTI; err = -ENODEV; np->hvapi_major = 2; @@ -649,14 +653,14 @@ static int __devinit n2rng_probe(struct platform_device *op, &np->hvapi_minor)) { dev_err(&op->dev, "Cannot register suitable " "HVAPI version.\n"); - goto out_free; + goto out; } } - if (np->flags & N2RNG_FLAG_VF) { + if (np->flags & N2RNG_FLAG_MULTI) { if (np->hvapi_major < 2) { - dev_err(&op->dev, "VF RNG requires HVAPI major " - "version 2 or later, got %lu\n", + dev_err(&op->dev, "multi-unit-capable RNG requires " + "HVAPI major version 2 or later, got %lu\n", np->hvapi_major); goto out_hvapi_unregister; } @@ -672,19 +676,20 @@ static int __devinit n2rng_probe(struct platform_device *op, dev_info(&op->dev, "Registered RNG HVAPI major %lu minor %lu\n", np->hvapi_major, np->hvapi_minor); - np->units = kzalloc(sizeof(struct n2rng_unit) * np->num_units, - GFP_KERNEL); + np->units = devm_kzalloc(&op->dev, + sizeof(struct n2rng_unit) * np->num_units, + GFP_KERNEL); err = -ENOMEM; if (!np->units) goto out_hvapi_unregister; err = n2rng_init_control(np); if (err) - goto out_free_units; + goto out_hvapi_unregister; dev_info(&op->dev, "Found %s RNG, units: %d\n", - ((np->flags & N2RNG_FLAG_VF) ? - "Victoria Falls" : "Niagara2"), + ((np->flags & N2RNG_FLAG_MULTI) ? + "multi-unit-capable" : "single-unit"), np->num_units); np->hwrng.name = "n2rng"; @@ -693,30 +698,24 @@ static int __devinit n2rng_probe(struct platform_device *op, err = hwrng_register(&np->hwrng); if (err) - goto out_free_units; + goto out_hvapi_unregister; - dev_set_drvdata(&op->dev, np); + platform_set_drvdata(op, np); schedule_delayed_work(&np->work, 0); return 0; -out_free_units: - kfree(np->units); - np->units = NULL; - out_hvapi_unregister: sun4v_hvapi_unregister(HV_GRP_RNG); -out_free: - kfree(np); out: return err; } -static int __devexit n2rng_remove(struct platform_device *op) +static int n2rng_remove(struct platform_device *op) { - struct n2rng *np = dev_get_drvdata(&op->dev); + struct n2rng *np = platform_get_drvdata(op); np->flags |= N2RNG_FLAG_SHUTDOWN; @@ -726,13 +725,6 @@ static int __devexit n2rng_remove(struct platform_device *op) sun4v_hvapi_unregister(HV_GRP_RNG); - kfree(np->units); - np->units = NULL; - - kfree(np); - - dev_set_drvdata(&op->dev, NULL); - return 0; } @@ -746,29 +738,23 @@ static const struct of_device_id n2rng_match[] = { .compatible = "SUNW,vf-rng", .data = (void *) 1, }, + { + .name = "random-number-generator", + .compatible = "SUNW,kt-rng", + .data = (void *) 1, + }, {}, }; MODULE_DEVICE_TABLE(of, n2rng_match); -static struct of_platform_driver n2rng_driver = { +static struct platform_driver n2rng_driver = { .driver = { .name = "n2rng", .owner = THIS_MODULE, .of_match_table = n2rng_match, }, .probe = n2rng_probe, - .remove = __devexit_p(n2rng_remove), + .remove = n2rng_remove, }; -static int __init n2rng_init(void) -{ - return of_register_platform_driver(&n2rng_driver); -} - -static void __exit n2rng_exit(void) -{ - of_unregister_platform_driver(&n2rng_driver); -} - -module_init(n2rng_init); -module_exit(n2rng_exit); +module_platform_driver(n2rng_driver); |
