001-v5.18-02-clk-ralink-make-system-controller-node-a-reset-provi.patch 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. From 38a8553b0a22ed54f014d8402fedd268b529175c Mon Sep 17 00:00:00 2001
  2. From: Sergio Paracuellos <[email protected]>
  3. Date: Thu, 10 Feb 2022 10:48:59 +0100
  4. Subject: [PATCH 2/2] clk: ralink: make system controller node a reset provider
  5. MT7621 system controller node is already providing the clocks for the whole
  6. system but must also serve as a reset provider. Hence, add reset controller
  7. related code to the clock driver itself. To get resets properly ready for
  8. the rest of the world we need to move platform driver initialization process
  9. to 'arch_initcall'.
  10. CC: Philipp Zabel <[email protected]>
  11. Reviewed-by: Philipp Zabel <[email protected]>
  12. Acked-by: Stephen Boyd <[email protected]>
  13. Signed-off-by: Sergio Paracuellos <[email protected]>
  14. Link: https://lore.kernel.org/r/[email protected]
  15. Signed-off-by: Greg Kroah-Hartman <[email protected]>
  16. ---
  17. drivers/clk/ralink/clk-mt7621.c | 92 ++++++++++++++++++++++++++++++++++++++++-
  18. 1 file changed, 91 insertions(+), 1 deletion(-)
  19. --- a/drivers/clk/ralink/clk-mt7621.c
  20. +++ b/drivers/clk/ralink/clk-mt7621.c
  21. @@ -11,14 +11,17 @@
  22. #include <linux/mfd/syscon.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/regmap.h>
  25. +#include <linux/reset-controller.h>
  26. #include <linux/slab.h>
  27. #include <dt-bindings/clock/mt7621-clk.h>
  28. +#include <dt-bindings/reset/mt7621-reset.h>
  29. /* Configuration registers */
  30. #define SYSC_REG_SYSTEM_CONFIG0 0x10
  31. #define SYSC_REG_SYSTEM_CONFIG1 0x14
  32. #define SYSC_REG_CLKCFG0 0x2c
  33. #define SYSC_REG_CLKCFG1 0x30
  34. +#define SYSC_REG_RESET_CTRL 0x34
  35. #define SYSC_REG_CUR_CLK_STS 0x44
  36. #define MEMC_REG_CPU_PLL 0x648
  37. @@ -398,6 +401,82 @@ free_clk_priv:
  38. }
  39. CLK_OF_DECLARE_DRIVER(mt7621_clk, "mediatek,mt7621-sysc", mt7621_clk_init);
  40. +struct mt7621_rst {
  41. + struct reset_controller_dev rcdev;
  42. + struct regmap *sysc;
  43. +};
  44. +
  45. +static struct mt7621_rst *to_mt7621_rst(struct reset_controller_dev *dev)
  46. +{
  47. + return container_of(dev, struct mt7621_rst, rcdev);
  48. +}
  49. +
  50. +static int mt7621_assert_device(struct reset_controller_dev *rcdev,
  51. + unsigned long id)
  52. +{
  53. + struct mt7621_rst *data = to_mt7621_rst(rcdev);
  54. + struct regmap *sysc = data->sysc;
  55. +
  56. + return regmap_update_bits(sysc, SYSC_REG_RESET_CTRL, BIT(id), BIT(id));
  57. +}
  58. +
  59. +static int mt7621_deassert_device(struct reset_controller_dev *rcdev,
  60. + unsigned long id)
  61. +{
  62. + struct mt7621_rst *data = to_mt7621_rst(rcdev);
  63. + struct regmap *sysc = data->sysc;
  64. +
  65. + return regmap_update_bits(sysc, SYSC_REG_RESET_CTRL, BIT(id), 0);
  66. +}
  67. +
  68. +static int mt7621_reset_device(struct reset_controller_dev *rcdev,
  69. + unsigned long id)
  70. +{
  71. + int ret;
  72. +
  73. + ret = mt7621_assert_device(rcdev, id);
  74. + if (ret < 0)
  75. + return ret;
  76. +
  77. + return mt7621_deassert_device(rcdev, id);
  78. +}
  79. +
  80. +static int mt7621_rst_xlate(struct reset_controller_dev *rcdev,
  81. + const struct of_phandle_args *reset_spec)
  82. +{
  83. + unsigned long id = reset_spec->args[0];
  84. +
  85. + if (id == MT7621_RST_SYS || id >= rcdev->nr_resets)
  86. + return -EINVAL;
  87. +
  88. + return id;
  89. +}
  90. +
  91. +static const struct reset_control_ops reset_ops = {
  92. + .reset = mt7621_reset_device,
  93. + .assert = mt7621_assert_device,
  94. + .deassert = mt7621_deassert_device
  95. +};
  96. +
  97. +static int mt7621_reset_init(struct device *dev, struct regmap *sysc)
  98. +{
  99. + struct mt7621_rst *rst_data;
  100. +
  101. + rst_data = devm_kzalloc(dev, sizeof(*rst_data), GFP_KERNEL);
  102. + if (!rst_data)
  103. + return -ENOMEM;
  104. +
  105. + rst_data->sysc = sysc;
  106. + rst_data->rcdev.ops = &reset_ops;
  107. + rst_data->rcdev.owner = THIS_MODULE;
  108. + rst_data->rcdev.nr_resets = 32;
  109. + rst_data->rcdev.of_reset_n_cells = 1;
  110. + rst_data->rcdev.of_xlate = mt7621_rst_xlate;
  111. + rst_data->rcdev.of_node = dev_of_node(dev);
  112. +
  113. + return devm_reset_controller_register(dev, &rst_data->rcdev);
  114. +}
  115. +
  116. static int mt7621_clk_probe(struct platform_device *pdev)
  117. {
  118. struct device_node *np = pdev->dev.of_node;
  119. @@ -424,6 +503,12 @@ static int mt7621_clk_probe(struct platf
  120. return ret;
  121. }
  122. + ret = mt7621_reset_init(dev, priv->sysc);
  123. + if (ret) {
  124. + dev_err(dev, "Could not init reset controller\n");
  125. + return ret;
  126. + }
  127. +
  128. count = ARRAY_SIZE(mt7621_clks_base) +
  129. ARRAY_SIZE(mt7621_fixed_clks) + ARRAY_SIZE(mt7621_gates);
  130. clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, count),
  131. @@ -485,4 +570,9 @@ static struct platform_driver mt7621_clk
  132. .of_match_table = mt7621_clk_of_match,
  133. },
  134. };
  135. -builtin_platform_driver(mt7621_clk_driver);
  136. +
  137. +static int __init mt7621_clk_reset_init(void)
  138. +{
  139. + return platform_driver_register(&mt7621_clk_driver);
  140. +}
  141. +arch_initcall(mt7621_clk_reset_init);