reset-uniphier-glue.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // reset-uniphier-glue.c - Glue layer reset driver for UniPhier
  4. // Copyright 2018 Socionext Inc.
  5. // Author: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
  6. #include <linux/clk.h>
  7. #include <linux/module.h>
  8. #include <linux/of.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/reset.h>
  11. #include <linux/reset/reset-simple.h>
  12. #define MAX_CLKS 2
  13. #define MAX_RSTS 2
  14. struct uniphier_glue_reset_soc_data {
  15. int nclks;
  16. const char * const *clock_names;
  17. int nrsts;
  18. const char * const *reset_names;
  19. };
  20. struct uniphier_glue_reset_priv {
  21. struct clk_bulk_data clk[MAX_CLKS];
  22. struct reset_control_bulk_data rst[MAX_RSTS];
  23. struct reset_simple_data rdata;
  24. const struct uniphier_glue_reset_soc_data *data;
  25. };
  26. static void uniphier_clk_disable(void *_priv)
  27. {
  28. struct uniphier_glue_reset_priv *priv = _priv;
  29. clk_bulk_disable_unprepare(priv->data->nclks, priv->clk);
  30. }
  31. static void uniphier_rst_assert(void *_priv)
  32. {
  33. struct uniphier_glue_reset_priv *priv = _priv;
  34. reset_control_bulk_assert(priv->data->nrsts, priv->rst);
  35. }
  36. static int uniphier_glue_reset_probe(struct platform_device *pdev)
  37. {
  38. struct device *dev = &pdev->dev;
  39. struct uniphier_glue_reset_priv *priv;
  40. struct resource *res;
  41. int i, ret;
  42. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  43. if (!priv)
  44. return -ENOMEM;
  45. priv->data = of_device_get_match_data(dev);
  46. if (WARN_ON(!priv->data || priv->data->nclks > MAX_CLKS ||
  47. priv->data->nrsts > MAX_RSTS))
  48. return -EINVAL;
  49. priv->rdata.membase = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
  50. if (IS_ERR(priv->rdata.membase))
  51. return PTR_ERR(priv->rdata.membase);
  52. for (i = 0; i < priv->data->nclks; i++)
  53. priv->clk[i].id = priv->data->clock_names[i];
  54. ret = devm_clk_bulk_get(dev, priv->data->nclks, priv->clk);
  55. if (ret)
  56. return ret;
  57. for (i = 0; i < priv->data->nrsts; i++)
  58. priv->rst[i].id = priv->data->reset_names[i];
  59. ret = devm_reset_control_bulk_get_shared(dev, priv->data->nrsts,
  60. priv->rst);
  61. if (ret)
  62. return ret;
  63. ret = clk_bulk_prepare_enable(priv->data->nclks, priv->clk);
  64. if (ret)
  65. return ret;
  66. ret = devm_add_action_or_reset(dev, uniphier_clk_disable, priv);
  67. if (ret)
  68. return ret;
  69. ret = reset_control_bulk_deassert(priv->data->nrsts, priv->rst);
  70. if (ret)
  71. return ret;
  72. ret = devm_add_action_or_reset(dev, uniphier_rst_assert, priv);
  73. if (ret)
  74. return ret;
  75. spin_lock_init(&priv->rdata.lock);
  76. priv->rdata.rcdev.owner = THIS_MODULE;
  77. priv->rdata.rcdev.nr_resets = resource_size(res) * BITS_PER_BYTE;
  78. priv->rdata.rcdev.ops = &reset_simple_ops;
  79. priv->rdata.rcdev.of_node = dev->of_node;
  80. priv->rdata.active_low = true;
  81. return devm_reset_controller_register(dev, &priv->rdata.rcdev);
  82. }
  83. static const char * const uniphier_pro4_clock_reset_names[] = {
  84. "gio", "link",
  85. };
  86. static const struct uniphier_glue_reset_soc_data uniphier_pro4_data = {
  87. .nclks = ARRAY_SIZE(uniphier_pro4_clock_reset_names),
  88. .clock_names = uniphier_pro4_clock_reset_names,
  89. .nrsts = ARRAY_SIZE(uniphier_pro4_clock_reset_names),
  90. .reset_names = uniphier_pro4_clock_reset_names,
  91. };
  92. static const char * const uniphier_pxs2_clock_reset_names[] = {
  93. "link",
  94. };
  95. static const struct uniphier_glue_reset_soc_data uniphier_pxs2_data = {
  96. .nclks = ARRAY_SIZE(uniphier_pxs2_clock_reset_names),
  97. .clock_names = uniphier_pxs2_clock_reset_names,
  98. .nrsts = ARRAY_SIZE(uniphier_pxs2_clock_reset_names),
  99. .reset_names = uniphier_pxs2_clock_reset_names,
  100. };
  101. static const struct of_device_id uniphier_glue_reset_match[] = {
  102. {
  103. .compatible = "socionext,uniphier-pro4-usb3-reset",
  104. .data = &uniphier_pro4_data,
  105. },
  106. {
  107. .compatible = "socionext,uniphier-pro5-usb3-reset",
  108. .data = &uniphier_pro4_data,
  109. },
  110. {
  111. .compatible = "socionext,uniphier-pxs2-usb3-reset",
  112. .data = &uniphier_pxs2_data,
  113. },
  114. {
  115. .compatible = "socionext,uniphier-ld20-usb3-reset",
  116. .data = &uniphier_pxs2_data,
  117. },
  118. {
  119. .compatible = "socionext,uniphier-pxs3-usb3-reset",
  120. .data = &uniphier_pxs2_data,
  121. },
  122. {
  123. .compatible = "socionext,uniphier-nx1-usb3-reset",
  124. .data = &uniphier_pxs2_data,
  125. },
  126. {
  127. .compatible = "socionext,uniphier-pro4-ahci-reset",
  128. .data = &uniphier_pro4_data,
  129. },
  130. {
  131. .compatible = "socionext,uniphier-pxs2-ahci-reset",
  132. .data = &uniphier_pxs2_data,
  133. },
  134. {
  135. .compatible = "socionext,uniphier-pxs3-ahci-reset",
  136. .data = &uniphier_pxs2_data,
  137. },
  138. { /* Sentinel */ }
  139. };
  140. MODULE_DEVICE_TABLE(of, uniphier_glue_reset_match);
  141. static struct platform_driver uniphier_glue_reset_driver = {
  142. .probe = uniphier_glue_reset_probe,
  143. .driver = {
  144. .name = "uniphier-glue-reset",
  145. .of_match_table = uniphier_glue_reset_match,
  146. },
  147. };
  148. module_platform_driver(uniphier_glue_reset_driver);
  149. MODULE_AUTHOR("Kunihiko Hayashi <hayashi.kunihiko@socionext.com>");
  150. MODULE_DESCRIPTION("UniPhier Glue layer reset driver");
  151. MODULE_LICENSE("GPL");