ixp4xx-rng.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * drivers/char/hw_random/ixp4xx-rng.c
  4. *
  5. * RNG driver for Intel IXP4xx family of NPUs
  6. *
  7. * Author: Deepak Saxena <[email protected]>
  8. *
  9. * Copyright 2005 (c) MontaVista Software, Inc.
  10. *
  11. * Fixes by Michael Buesch
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/types.h>
  15. #include <linux/module.h>
  16. #include <linux/moduleparam.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/init.h>
  19. #include <linux/bitops.h>
  20. #include <linux/hw_random.h>
  21. #include <linux/of.h>
  22. #include <linux/soc/ixp4xx/cpu.h>
  23. #include <asm/io.h>
  24. static int ixp4xx_rng_data_read(struct hwrng *rng, u32 *buffer)
  25. {
  26. void __iomem * rng_base = (void __iomem *)rng->priv;
  27. *buffer = __raw_readl(rng_base);
  28. return 4;
  29. }
  30. static struct hwrng ixp4xx_rng_ops = {
  31. .name = "ixp4xx",
  32. .data_read = ixp4xx_rng_data_read,
  33. };
  34. static int ixp4xx_rng_probe(struct platform_device *pdev)
  35. {
  36. void __iomem * rng_base;
  37. struct device *dev = &pdev->dev;
  38. if (!cpu_is_ixp46x()) /* includes IXP455 */
  39. return -ENOSYS;
  40. rng_base = devm_platform_ioremap_resource(pdev, 0);
  41. if (IS_ERR(rng_base))
  42. return PTR_ERR(rng_base);
  43. ixp4xx_rng_ops.priv = (unsigned long)rng_base;
  44. return devm_hwrng_register(dev, &ixp4xx_rng_ops);
  45. }
  46. static const struct of_device_id ixp4xx_rng_of_match[] = {
  47. {
  48. .compatible = "intel,ixp46x-rng",
  49. },
  50. {},
  51. };
  52. MODULE_DEVICE_TABLE(of, ixp4xx_rng_of_match);
  53. static struct platform_driver ixp4xx_rng_driver = {
  54. .driver = {
  55. .name = "ixp4xx-hwrandom",
  56. .of_match_table = ixp4xx_rng_of_match,
  57. },
  58. .probe = ixp4xx_rng_probe,
  59. };
  60. module_platform_driver(ixp4xx_rng_driver);
  61. MODULE_AUTHOR("Deepak Saxena <[email protected]>");
  62. MODULE_DESCRIPTION("H/W Pseudo-Random Number Generator (RNG) driver for IXP45x/46x");
  63. MODULE_LICENSE("GPL");