reset-zx2967.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * ZTE's zx2967 family reset controller driver
  3. *
  4. * Copyright (C) 2017 ZTE Ltd.
  5. *
  6. * Author: Baoyou Xie <baoyou.xie@linaro.org>
  7. *
  8. * License terms: GNU General Public License (GPL) version 2
  9. */
  10. #include <linux/of_address.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/reset-controller.h>
  13. struct zx2967_reset {
  14. void __iomem *reg_base;
  15. spinlock_t lock;
  16. struct reset_controller_dev rcdev;
  17. };
  18. static int zx2967_reset_act(struct reset_controller_dev *rcdev,
  19. unsigned long id, bool assert)
  20. {
  21. struct zx2967_reset *reset = NULL;
  22. int bank = id / 32;
  23. int offset = id % 32;
  24. u32 reg;
  25. unsigned long flags;
  26. reset = container_of(rcdev, struct zx2967_reset, rcdev);
  27. spin_lock_irqsave(&reset->lock, flags);
  28. reg = readl_relaxed(reset->reg_base + (bank * 4));
  29. if (assert)
  30. reg &= ~BIT(offset);
  31. else
  32. reg |= BIT(offset);
  33. writel_relaxed(reg, reset->reg_base + (bank * 4));
  34. spin_unlock_irqrestore(&reset->lock, flags);
  35. return 0;
  36. }
  37. static int zx2967_reset_assert(struct reset_controller_dev *rcdev,
  38. unsigned long id)
  39. {
  40. return zx2967_reset_act(rcdev, id, true);
  41. }
  42. static int zx2967_reset_deassert(struct reset_controller_dev *rcdev,
  43. unsigned long id)
  44. {
  45. return zx2967_reset_act(rcdev, id, false);
  46. }
  47. static const struct reset_control_ops zx2967_reset_ops = {
  48. .assert = zx2967_reset_assert,
  49. .deassert = zx2967_reset_deassert,
  50. };
  51. static int zx2967_reset_probe(struct platform_device *pdev)
  52. {
  53. struct zx2967_reset *reset;
  54. struct resource *res;
  55. reset = devm_kzalloc(&pdev->dev, sizeof(*reset), GFP_KERNEL);
  56. if (!reset)
  57. return -ENOMEM;
  58. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  59. reset->reg_base = devm_ioremap_resource(&pdev->dev, res);
  60. if (IS_ERR(reset->reg_base))
  61. return PTR_ERR(reset->reg_base);
  62. spin_lock_init(&reset->lock);
  63. reset->rcdev.owner = THIS_MODULE;
  64. reset->rcdev.nr_resets = resource_size(res) * 8;
  65. reset->rcdev.ops = &zx2967_reset_ops;
  66. reset->rcdev.of_node = pdev->dev.of_node;
  67. return devm_reset_controller_register(&pdev->dev, &reset->rcdev);
  68. }
  69. static const struct of_device_id zx2967_reset_dt_ids[] = {
  70. { .compatible = "zte,zx296718-reset", },
  71. {},
  72. };
  73. static struct platform_driver zx2967_reset_driver = {
  74. .probe = zx2967_reset_probe,
  75. .driver = {
  76. .name = "zx2967-reset",
  77. .of_match_table = zx2967_reset_dt_ids,
  78. },
  79. };
  80. builtin_platform_driver(zx2967_reset_driver);