0010-reset-starfive-Extract-the-common-JH71X0-reset-code.patch 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. From dbee38aac9811a25e3e3204f813048bf64155248 Mon Sep 17 00:00:00 2001
  2. From: Emil Renner Berthing <[email protected]>
  3. Date: Sat, 1 Apr 2023 19:19:22 +0800
  4. Subject: [PATCH 010/122] reset: starfive: Extract the common JH71X0 reset code
  5. Extract the common JH71X0 reset code for reusing them to
  6. support JH7110 SoC.
  7. Tested-by: Tommaso Merciai <[email protected]>
  8. Reviewed-by: Conor Dooley <[email protected]>
  9. Reviewed-by: Emil Renner Berthing <[email protected]>
  10. Signed-off-by: Emil Renner Berthing <[email protected]>
  11. Signed-off-by: Hal Feng <[email protected]>
  12. Signed-off-by: Conor Dooley <[email protected]>
  13. ---
  14. .../reset/starfive/reset-starfive-jh7100.c | 49 ++++++++++++
  15. .../reset/starfive/reset-starfive-jh71x0.c | 76 ++++++-------------
  16. .../reset/starfive/reset-starfive-jh71x0.h | 5 +-
  17. 3 files changed, 76 insertions(+), 54 deletions(-)
  18. --- a/drivers/reset/starfive/reset-starfive-jh7100.c
  19. +++ b/drivers/reset/starfive/reset-starfive-jh7100.c
  20. @@ -10,6 +10,55 @@
  21. #include "reset-starfive-jh71x0.h"
  22. +#include <dt-bindings/reset/starfive-jh7100.h>
  23. +
  24. +/* register offsets */
  25. +#define JH7100_RESET_ASSERT0 0x00
  26. +#define JH7100_RESET_ASSERT1 0x04
  27. +#define JH7100_RESET_ASSERT2 0x08
  28. +#define JH7100_RESET_ASSERT3 0x0c
  29. +#define JH7100_RESET_STATUS0 0x10
  30. +#define JH7100_RESET_STATUS1 0x14
  31. +#define JH7100_RESET_STATUS2 0x18
  32. +#define JH7100_RESET_STATUS3 0x1c
  33. +
  34. +/*
  35. + * Writing a 1 to the n'th bit of the m'th ASSERT register asserts
  36. + * line 32m + n, and writing a 0 deasserts the same line.
  37. + * Most reset lines have their status inverted so a 0 bit in the STATUS
  38. + * register means the line is asserted and a 1 means it's deasserted. A few
  39. + * lines don't though, so store the expected value of the status registers when
  40. + * all lines are asserted.
  41. + */
  42. +static const u64 jh7100_reset_asserted[2] = {
  43. + /* STATUS0 */
  44. + BIT_ULL_MASK(JH7100_RST_U74) |
  45. + BIT_ULL_MASK(JH7100_RST_VP6_DRESET) |
  46. + BIT_ULL_MASK(JH7100_RST_VP6_BRESET) |
  47. + /* STATUS1 */
  48. + BIT_ULL_MASK(JH7100_RST_HIFI4_DRESET) |
  49. + BIT_ULL_MASK(JH7100_RST_HIFI4_BRESET),
  50. + /* STATUS2 */
  51. + BIT_ULL_MASK(JH7100_RST_E24) |
  52. + /* STATUS3 */
  53. + 0,
  54. +};
  55. +
  56. +static int __init jh7100_reset_probe(struct platform_device *pdev)
  57. +{
  58. + void __iomem *base = devm_platform_ioremap_resource(pdev, 0);
  59. +
  60. + if (IS_ERR(base))
  61. + return PTR_ERR(base);
  62. +
  63. + return reset_starfive_jh7100_register(&pdev->dev, pdev->dev.of_node,
  64. + base + JH7100_RESET_ASSERT0,
  65. + base + JH7100_RESET_STATUS0,
  66. + jh7100_reset_asserted,
  67. + JH7100_RSTN_END,
  68. + THIS_MODULE);
  69. +}
  70. +
  71. static const struct of_device_id jh7100_reset_dt_ids[] = {
  72. { .compatible = "starfive,jh7100-reset" },
  73. { /* sentinel */ }
  74. --- a/drivers/reset/starfive/reset-starfive-jh71x0.c
  75. +++ b/drivers/reset/starfive/reset-starfive-jh71x0.c
  76. @@ -10,51 +10,18 @@
  77. #include <linux/io.h>
  78. #include <linux/io-64-nonatomic-lo-hi.h>
  79. #include <linux/iopoll.h>
  80. -#include <linux/platform_device.h>
  81. #include <linux/reset-controller.h>
  82. #include <linux/spinlock.h>
  83. #include "reset-starfive-jh71x0.h"
  84. -#include <dt-bindings/reset/starfive-jh7100.h>
  85. -
  86. -/* register offsets */
  87. -#define JH7100_RESET_ASSERT0 0x00
  88. -#define JH7100_RESET_ASSERT1 0x04
  89. -#define JH7100_RESET_ASSERT2 0x08
  90. -#define JH7100_RESET_ASSERT3 0x0c
  91. -#define JH7100_RESET_STATUS0 0x10
  92. -#define JH7100_RESET_STATUS1 0x14
  93. -#define JH7100_RESET_STATUS2 0x18
  94. -#define JH7100_RESET_STATUS3 0x1c
  95. -
  96. -/*
  97. - * Writing a 1 to the n'th bit of the m'th ASSERT register asserts
  98. - * line 32m + n, and writing a 0 deasserts the same line.
  99. - * Most reset lines have their status inverted so a 0 bit in the STATUS
  100. - * register means the line is asserted and a 1 means it's deasserted. A few
  101. - * lines don't though, so store the expected value of the status registers when
  102. - * all lines are asserted.
  103. - */
  104. -static const u64 jh7100_reset_asserted[2] = {
  105. - /* STATUS0 */
  106. - BIT_ULL_MASK(JH7100_RST_U74) |
  107. - BIT_ULL_MASK(JH7100_RST_VP6_DRESET) |
  108. - BIT_ULL_MASK(JH7100_RST_VP6_BRESET) |
  109. - /* STATUS1 */
  110. - BIT_ULL_MASK(JH7100_RST_HIFI4_DRESET) |
  111. - BIT_ULL_MASK(JH7100_RST_HIFI4_BRESET),
  112. - /* STATUS2 */
  113. - BIT_ULL_MASK(JH7100_RST_E24) |
  114. - /* STATUS3 */
  115. - 0,
  116. -};
  117. -
  118. struct jh7100_reset {
  119. struct reset_controller_dev rcdev;
  120. /* protect registers against concurrent read-modify-write */
  121. spinlock_t lock;
  122. - void __iomem *base;
  123. + void __iomem *assert;
  124. + void __iomem *status;
  125. + const u64 *asserted;
  126. };
  127. static inline struct jh7100_reset *
  128. @@ -69,9 +36,9 @@ static int jh7100_reset_update(struct re
  129. struct jh7100_reset *data = jh7100_reset_from(rcdev);
  130. unsigned long offset = BIT_ULL_WORD(id);
  131. u64 mask = BIT_ULL_MASK(id);
  132. - void __iomem *reg_assert = data->base + JH7100_RESET_ASSERT0 + offset * sizeof(u64);
  133. - void __iomem *reg_status = data->base + JH7100_RESET_STATUS0 + offset * sizeof(u64);
  134. - u64 done = jh7100_reset_asserted[offset] & mask;
  135. + void __iomem *reg_assert = data->assert + offset * sizeof(u64);
  136. + void __iomem *reg_status = data->status + offset * sizeof(u64);
  137. + u64 done = data->asserted ? data->asserted[offset] & mask : 0;
  138. u64 value;
  139. unsigned long flags;
  140. int ret;
  141. @@ -125,10 +92,10 @@ static int jh7100_reset_status(struct re
  142. struct jh7100_reset *data = jh7100_reset_from(rcdev);
  143. unsigned long offset = BIT_ULL_WORD(id);
  144. u64 mask = BIT_ULL_MASK(id);
  145. - void __iomem *reg_status = data->base + JH7100_RESET_STATUS0 + offset * sizeof(u64);
  146. + void __iomem *reg_status = data->status + offset * sizeof(u64);
  147. u64 value = readq(reg_status);
  148. - return !((value ^ jh7100_reset_asserted[offset]) & mask);
  149. + return !((value ^ data->asserted[offset]) & mask);
  150. }
  151. static const struct reset_control_ops jh7100_reset_ops = {
  152. @@ -138,25 +105,28 @@ static const struct reset_control_ops jh
  153. .status = jh7100_reset_status,
  154. };
  155. -int jh7100_reset_probe(struct platform_device *pdev)
  156. +int reset_starfive_jh7100_register(struct device *dev, struct device_node *of_node,
  157. + void __iomem *assert, void __iomem *status,
  158. + const u64 *asserted, unsigned int nr_resets,
  159. + struct module *owner)
  160. {
  161. struct jh7100_reset *data;
  162. - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
  163. + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
  164. if (!data)
  165. return -ENOMEM;
  166. - data->base = devm_platform_ioremap_resource(pdev, 0);
  167. - if (IS_ERR(data->base))
  168. - return PTR_ERR(data->base);
  169. -
  170. data->rcdev.ops = &jh7100_reset_ops;
  171. - data->rcdev.owner = THIS_MODULE;
  172. - data->rcdev.nr_resets = JH7100_RSTN_END;
  173. - data->rcdev.dev = &pdev->dev;
  174. - data->rcdev.of_node = pdev->dev.of_node;
  175. + data->rcdev.owner = owner;
  176. + data->rcdev.nr_resets = nr_resets;
  177. + data->rcdev.dev = dev;
  178. + data->rcdev.of_node = of_node;
  179. +
  180. spin_lock_init(&data->lock);
  181. + data->assert = assert;
  182. + data->status = status;
  183. + data->asserted = asserted;
  184. - return devm_reset_controller_register(&pdev->dev, &data->rcdev);
  185. + return devm_reset_controller_register(dev, &data->rcdev);
  186. }
  187. -EXPORT_SYMBOL_GPL(jh7100_reset_probe);
  188. +EXPORT_SYMBOL_GPL(reset_starfive_jh7100_register);
  189. --- a/drivers/reset/starfive/reset-starfive-jh71x0.h
  190. +++ b/drivers/reset/starfive/reset-starfive-jh71x0.h
  191. @@ -6,6 +6,9 @@
  192. #ifndef __RESET_STARFIVE_JH71X0_H
  193. #define __RESET_STARFIVE_JH71X0_H
  194. -int jh7100_reset_probe(struct platform_device *pdev);
  195. +int reset_starfive_jh7100_register(struct device *dev, struct device_node *of_node,
  196. + void __iomem *assert, void __iomem *status,
  197. + const u64 *asserted, unsigned int nr_resets,
  198. + struct module *owner);
  199. #endif /* __RESET_STARFIVE_JH71X0_H */