ixp4xx-rng.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * drivers/char/hw_random/ixp4xx-rng.c
  3. *
  4. * RNG driver for Intel IXP4xx family of NPUs
  5. *
  6. * Author: Deepak Saxena <dsaxena@plexity.net>
  7. *
  8. * Copyright 2005 (c) MontaVista Software, Inc.
  9. *
  10. * Fixes by Michael Buesch
  11. *
  12. * This file is licensed under the terms of the GNU General Public
  13. * License version 2. This program is licensed "as is" without any
  14. * warranty of any kind, whether express or implied.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/types.h>
  18. #include <linux/module.h>
  19. #include <linux/moduleparam.h>
  20. #include <linux/init.h>
  21. #include <linux/bitops.h>
  22. #include <linux/hw_random.h>
  23. #include <asm/io.h>
  24. #include <mach/hardware.h>
  25. static int ixp4xx_rng_data_read(struct hwrng *rng, u32 *buffer)
  26. {
  27. void __iomem * rng_base = (void __iomem *)rng->priv;
  28. *buffer = __raw_readl(rng_base);
  29. return 4;
  30. }
  31. static struct hwrng ixp4xx_rng_ops = {
  32. .name = "ixp4xx",
  33. .data_read = ixp4xx_rng_data_read,
  34. };
  35. static int __init ixp4xx_rng_init(void)
  36. {
  37. void __iomem * rng_base;
  38. int err;
  39. if (!cpu_is_ixp46x()) /* includes IXP455 */
  40. return -ENOSYS;
  41. rng_base = ioremap(0x70002100, 4);
  42. if (!rng_base)
  43. return -ENOMEM;
  44. ixp4xx_rng_ops.priv = (unsigned long)rng_base;
  45. err = hwrng_register(&ixp4xx_rng_ops);
  46. if (err)
  47. iounmap(rng_base);
  48. return err;
  49. }
  50. static void __exit ixp4xx_rng_exit(void)
  51. {
  52. void __iomem * rng_base = (void __iomem *)ixp4xx_rng_ops.priv;
  53. hwrng_unregister(&ixp4xx_rng_ops);
  54. iounmap(rng_base);
  55. }
  56. module_init(ixp4xx_rng_init);
  57. module_exit(ixp4xx_rng_exit);
  58. MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>");
  59. MODULE_DESCRIPTION("H/W Pseudo-Random Number Generator (RNG) driver for IXP45x/46x");
  60. MODULE_LICENSE("GPL");