reset-axs10x.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (C) 2017 Synopsys.
  3. *
  4. * Synopsys AXS10x reset driver.
  5. *
  6. * This file is licensed under the terms of the GNU General Public
  7. * License version 2. This program is licensed "as is" without any
  8. * warranty of any kind, whether express or implied.
  9. */
  10. #include <linux/io.h>
  11. #include <linux/module.h>
  12. #include <linux/mod_devicetable.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/reset-controller.h>
  15. #define to_axs10x_rst(p) container_of((p), struct axs10x_rst, rcdev)
  16. #define AXS10X_MAX_RESETS 32
  17. struct axs10x_rst {
  18. void __iomem *regs_rst;
  19. spinlock_t lock;
  20. struct reset_controller_dev rcdev;
  21. };
  22. static int axs10x_reset_reset(struct reset_controller_dev *rcdev,
  23. unsigned long id)
  24. {
  25. struct axs10x_rst *rst = to_axs10x_rst(rcdev);
  26. unsigned long flags;
  27. spin_lock_irqsave(&rst->lock, flags);
  28. writel(BIT(id), rst->regs_rst);
  29. spin_unlock_irqrestore(&rst->lock, flags);
  30. return 0;
  31. }
  32. static const struct reset_control_ops axs10x_reset_ops = {
  33. .reset = axs10x_reset_reset,
  34. };
  35. static int axs10x_reset_probe(struct platform_device *pdev)
  36. {
  37. struct axs10x_rst *rst;
  38. rst = devm_kzalloc(&pdev->dev, sizeof(*rst), GFP_KERNEL);
  39. if (!rst)
  40. return -ENOMEM;
  41. rst->regs_rst = devm_platform_ioremap_resource(pdev, 0);
  42. if (IS_ERR(rst->regs_rst))
  43. return PTR_ERR(rst->regs_rst);
  44. spin_lock_init(&rst->lock);
  45. rst->rcdev.owner = THIS_MODULE;
  46. rst->rcdev.ops = &axs10x_reset_ops;
  47. rst->rcdev.of_node = pdev->dev.of_node;
  48. rst->rcdev.nr_resets = AXS10X_MAX_RESETS;
  49. return devm_reset_controller_register(&pdev->dev, &rst->rcdev);
  50. }
  51. static const struct of_device_id axs10x_reset_dt_match[] = {
  52. { .compatible = "snps,axs10x-reset" },
  53. { },
  54. };
  55. static struct platform_driver axs10x_reset_driver = {
  56. .probe = axs10x_reset_probe,
  57. .driver = {
  58. .name = "axs10x-reset",
  59. .of_match_table = axs10x_reset_dt_match,
  60. },
  61. };
  62. builtin_platform_driver(axs10x_reset_driver);
  63. MODULE_AUTHOR("Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>");
  64. MODULE_DESCRIPTION("Synopsys AXS10x reset driver");
  65. MODULE_LICENSE("GPL v2");