reset-uniphier-glue.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 int uniphier_glue_reset_probe(struct platform_device *pdev)
  32. {
  33. struct device *dev = &pdev->dev;
  34. struct uniphier_glue_reset_priv *priv;
  35. struct resource *res;
  36. int i, ret;
  37. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  38. if (!priv)
  39. return -ENOMEM;
  40. priv->data = of_device_get_match_data(dev);
  41. if (WARN_ON(!priv->data || priv->data->nclks > MAX_CLKS ||
  42. priv->data->nrsts > MAX_RSTS))
  43. return -EINVAL;
  44. priv->rdata.membase = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
  45. if (IS_ERR(priv->rdata.membase))
  46. return PTR_ERR(priv->rdata.membase);
  47. for (i = 0; i < priv->data->nclks; i++)
  48. priv->clk[i].id = priv->data->clock_names[i];
  49. ret = devm_clk_bulk_get(dev, priv->data->nclks, priv->clk);
  50. if (ret)
  51. return ret;
  52. ret = clk_bulk_prepare_enable(priv->data->nclks, priv->clk);
  53. if (ret)
  54. return ret;
  55. ret = devm_add_action_or_reset(dev, uniphier_clk_disable, priv);
  56. if (ret)
  57. return ret;
  58. for (i = 0; i < priv->data->nrsts; i++)
  59. priv->rst[i].id = priv->data->reset_names[i];
  60. ret = devm_reset_control_bulk_get_shared_deasserted(dev,
  61. priv->data->nrsts,
  62. priv->rst);
  63. if (ret)
  64. return ret;
  65. spin_lock_init(&priv->rdata.lock);
  66. priv->rdata.rcdev.owner = THIS_MODULE;
  67. priv->rdata.rcdev.nr_resets = resource_size(res) * BITS_PER_BYTE;
  68. priv->rdata.rcdev.ops = &reset_simple_ops;
  69. priv->rdata.rcdev.of_node = dev->of_node;
  70. priv->rdata.active_low = true;
  71. return devm_reset_controller_register(dev, &priv->rdata.rcdev);
  72. }
  73. static const char * const uniphier_pro4_clock_reset_names[] = {
  74. "gio", "link",
  75. };
  76. static const struct uniphier_glue_reset_soc_data uniphier_pro4_data = {
  77. .nclks = ARRAY_SIZE(uniphier_pro4_clock_reset_names),
  78. .clock_names = uniphier_pro4_clock_reset_names,
  79. .nrsts = ARRAY_SIZE(uniphier_pro4_clock_reset_names),
  80. .reset_names = uniphier_pro4_clock_reset_names,
  81. };
  82. static const char * const uniphier_pxs2_clock_reset_names[] = {
  83. "link",
  84. };
  85. static const struct uniphier_glue_reset_soc_data uniphier_pxs2_data = {
  86. .nclks = ARRAY_SIZE(uniphier_pxs2_clock_reset_names),
  87. .clock_names = uniphier_pxs2_clock_reset_names,
  88. .nrsts = ARRAY_SIZE(uniphier_pxs2_clock_reset_names),
  89. .reset_names = uniphier_pxs2_clock_reset_names,
  90. };
  91. static const struct of_device_id uniphier_glue_reset_match[] = {
  92. {
  93. .compatible = "socionext,uniphier-pro4-usb3-reset",
  94. .data = &uniphier_pro4_data,
  95. },
  96. {
  97. .compatible = "socionext,uniphier-pro5-usb3-reset",
  98. .data = &uniphier_pro4_data,
  99. },
  100. {
  101. .compatible = "socionext,uniphier-pxs2-usb3-reset",
  102. .data = &uniphier_pxs2_data,
  103. },
  104. {
  105. .compatible = "socionext,uniphier-ld20-usb3-reset",
  106. .data = &uniphier_pxs2_data,
  107. },
  108. {
  109. .compatible = "socionext,uniphier-pxs3-usb3-reset",
  110. .data = &uniphier_pxs2_data,
  111. },
  112. {
  113. .compatible = "socionext,uniphier-nx1-usb3-reset",
  114. .data = &uniphier_pxs2_data,
  115. },
  116. {
  117. .compatible = "socionext,uniphier-pro4-ahci-reset",
  118. .data = &uniphier_pro4_data,
  119. },
  120. {
  121. .compatible = "socionext,uniphier-pxs2-ahci-reset",
  122. .data = &uniphier_pxs2_data,
  123. },
  124. {
  125. .compatible = "socionext,uniphier-pxs3-ahci-reset",
  126. .data = &uniphier_pxs2_data,
  127. },
  128. { /* Sentinel */ }
  129. };
  130. MODULE_DEVICE_TABLE(of, uniphier_glue_reset_match);
  131. static struct platform_driver uniphier_glue_reset_driver = {
  132. .probe = uniphier_glue_reset_probe,
  133. .driver = {
  134. .name = "uniphier-glue-reset",
  135. .of_match_table = uniphier_glue_reset_match,
  136. },
  137. };
  138. module_platform_driver(uniphier_glue_reset_driver);
  139. MODULE_AUTHOR("Kunihiko Hayashi <hayashi.kunihiko@socionext.com>");
  140. MODULE_DESCRIPTION("UniPhier Glue layer reset driver");
  141. MODULE_LICENSE("GPL");