reset-pistachio.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Pistachio SoC Reset Controller driver
  4. *
  5. * Copyright (C) 2015 Imagination Technologies Ltd.
  6. *
  7. * Author: Damien Horsley <Damien.Horsley@imgtec.com>
  8. */
  9. #include <linux/init.h>
  10. #include <linux/of.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/regmap.h>
  13. #include <linux/reset-controller.h>
  14. #include <linux/slab.h>
  15. #include <linux/mfd/syscon.h>
  16. #include <dt-bindings/reset/pistachio-resets.h>
  17. #define PISTACHIO_SOFT_RESET 0
  18. struct pistachio_reset_data {
  19. struct reset_controller_dev rcdev;
  20. struct regmap *periph_regs;
  21. };
  22. static inline int pistachio_reset_shift(unsigned long id)
  23. {
  24. switch (id) {
  25. case PISTACHIO_RESET_I2C0:
  26. case PISTACHIO_RESET_I2C1:
  27. case PISTACHIO_RESET_I2C2:
  28. case PISTACHIO_RESET_I2C3:
  29. case PISTACHIO_RESET_I2S_IN:
  30. case PISTACHIO_RESET_PRL_OUT:
  31. case PISTACHIO_RESET_SPDIF_OUT:
  32. case PISTACHIO_RESET_SPI:
  33. case PISTACHIO_RESET_PWM_PDM:
  34. case PISTACHIO_RESET_UART0:
  35. case PISTACHIO_RESET_UART1:
  36. case PISTACHIO_RESET_QSPI:
  37. case PISTACHIO_RESET_MDC:
  38. case PISTACHIO_RESET_SDHOST:
  39. case PISTACHIO_RESET_ETHERNET:
  40. case PISTACHIO_RESET_IR:
  41. case PISTACHIO_RESET_HASH:
  42. case PISTACHIO_RESET_TIMER:
  43. return id;
  44. case PISTACHIO_RESET_I2S_OUT:
  45. case PISTACHIO_RESET_SPDIF_IN:
  46. case PISTACHIO_RESET_EVT:
  47. return id + 6;
  48. case PISTACHIO_RESET_USB_H:
  49. case PISTACHIO_RESET_USB_PR:
  50. case PISTACHIO_RESET_USB_PHY_PR:
  51. case PISTACHIO_RESET_USB_PHY_PON:
  52. return id + 7;
  53. default:
  54. return -EINVAL;
  55. }
  56. }
  57. static int pistachio_reset_assert(struct reset_controller_dev *rcdev,
  58. unsigned long id)
  59. {
  60. struct pistachio_reset_data *rd;
  61. u32 mask;
  62. int shift;
  63. rd = container_of(rcdev, struct pistachio_reset_data, rcdev);
  64. shift = pistachio_reset_shift(id);
  65. if (shift < 0)
  66. return shift;
  67. mask = BIT(shift);
  68. return regmap_update_bits(rd->periph_regs, PISTACHIO_SOFT_RESET,
  69. mask, mask);
  70. }
  71. static int pistachio_reset_deassert(struct reset_controller_dev *rcdev,
  72. unsigned long id)
  73. {
  74. struct pistachio_reset_data *rd;
  75. u32 mask;
  76. int shift;
  77. rd = container_of(rcdev, struct pistachio_reset_data, rcdev);
  78. shift = pistachio_reset_shift(id);
  79. if (shift < 0)
  80. return shift;
  81. mask = BIT(shift);
  82. return regmap_update_bits(rd->periph_regs, PISTACHIO_SOFT_RESET,
  83. mask, 0);
  84. }
  85. static const struct reset_control_ops pistachio_reset_ops = {
  86. .assert = pistachio_reset_assert,
  87. .deassert = pistachio_reset_deassert,
  88. };
  89. static int pistachio_reset_probe(struct platform_device *pdev)
  90. {
  91. struct pistachio_reset_data *rd;
  92. struct device *dev = &pdev->dev;
  93. struct device_node *np = pdev->dev.of_node;
  94. rd = devm_kzalloc(dev, sizeof(*rd), GFP_KERNEL);
  95. if (!rd)
  96. return -ENOMEM;
  97. rd->periph_regs = syscon_node_to_regmap(np->parent);
  98. if (IS_ERR(rd->periph_regs))
  99. return PTR_ERR(rd->periph_regs);
  100. rd->rcdev.owner = THIS_MODULE;
  101. rd->rcdev.nr_resets = PISTACHIO_RESET_MAX + 1;
  102. rd->rcdev.ops = &pistachio_reset_ops;
  103. rd->rcdev.of_node = np;
  104. return devm_reset_controller_register(dev, &rd->rcdev);
  105. }
  106. static const struct of_device_id pistachio_reset_dt_ids[] = {
  107. { .compatible = "img,pistachio-reset", },
  108. { /* sentinel */ },
  109. };
  110. static struct platform_driver pistachio_reset_driver = {
  111. .probe = pistachio_reset_probe,
  112. .driver = {
  113. .name = "pistachio-reset",
  114. .of_match_table = pistachio_reset_dt_ids,
  115. },
  116. };
  117. builtin_platform_driver(pistachio_reset_driver);