reset-uniphier-glue.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 <[email protected]>
  6. #include <linux/clk.h>
  7. #include <linux/module.h>
  8. #include <linux/of_device.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. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  50. priv->rdata.membase = devm_ioremap_resource(dev, res);
  51. if (IS_ERR(priv->rdata.membase))
  52. return PTR_ERR(priv->rdata.membase);
  53. for (i = 0; i < priv->data->nclks; i++)
  54. priv->clk[i].id = priv->data->clock_names[i];
  55. ret = devm_clk_bulk_get(dev, priv->data->nclks, priv->clk);
  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(dev, priv->data->nrsts,
  61. priv->rst);
  62. if (ret)
  63. return ret;
  64. ret = clk_bulk_prepare_enable(priv->data->nclks, priv->clk);
  65. if (ret)
  66. return ret;
  67. ret = devm_add_action_or_reset(dev, uniphier_clk_disable, priv);
  68. if (ret)
  69. return ret;
  70. ret = reset_control_bulk_deassert(priv->data->nrsts, priv->rst);
  71. if (ret)
  72. return ret;
  73. ret = devm_add_action_or_reset(dev, uniphier_rst_assert, priv);
  74. if (ret)
  75. return ret;
  76. spin_lock_init(&priv->rdata.lock);
  77. priv->rdata.rcdev.owner = THIS_MODULE;
  78. priv->rdata.rcdev.nr_resets = resource_size(res) * BITS_PER_BYTE;
  79. priv->rdata.rcdev.ops = &reset_simple_ops;
  80. priv->rdata.rcdev.of_node = dev->of_node;
  81. priv->rdata.active_low = true;
  82. platform_set_drvdata(pdev, priv);
  83. return devm_reset_controller_register(dev, &priv->rdata.rcdev);
  84. }
  85. static const char * const uniphier_pro4_clock_reset_names[] = {
  86. "gio", "link",
  87. };
  88. static const struct uniphier_glue_reset_soc_data uniphier_pro4_data = {
  89. .nclks = ARRAY_SIZE(uniphier_pro4_clock_reset_names),
  90. .clock_names = uniphier_pro4_clock_reset_names,
  91. .nrsts = ARRAY_SIZE(uniphier_pro4_clock_reset_names),
  92. .reset_names = uniphier_pro4_clock_reset_names,
  93. };
  94. static const char * const uniphier_pxs2_clock_reset_names[] = {
  95. "link",
  96. };
  97. static const struct uniphier_glue_reset_soc_data uniphier_pxs2_data = {
  98. .nclks = ARRAY_SIZE(uniphier_pxs2_clock_reset_names),
  99. .clock_names = uniphier_pxs2_clock_reset_names,
  100. .nrsts = ARRAY_SIZE(uniphier_pxs2_clock_reset_names),
  101. .reset_names = uniphier_pxs2_clock_reset_names,
  102. };
  103. static const struct of_device_id uniphier_glue_reset_match[] = {
  104. {
  105. .compatible = "socionext,uniphier-pro4-usb3-reset",
  106. .data = &uniphier_pro4_data,
  107. },
  108. {
  109. .compatible = "socionext,uniphier-pro5-usb3-reset",
  110. .data = &uniphier_pro4_data,
  111. },
  112. {
  113. .compatible = "socionext,uniphier-pxs2-usb3-reset",
  114. .data = &uniphier_pxs2_data,
  115. },
  116. {
  117. .compatible = "socionext,uniphier-ld20-usb3-reset",
  118. .data = &uniphier_pxs2_data,
  119. },
  120. {
  121. .compatible = "socionext,uniphier-pxs3-usb3-reset",
  122. .data = &uniphier_pxs2_data,
  123. },
  124. {
  125. .compatible = "socionext,uniphier-nx1-usb3-reset",
  126. .data = &uniphier_pxs2_data,
  127. },
  128. {
  129. .compatible = "socionext,uniphier-pro4-ahci-reset",
  130. .data = &uniphier_pro4_data,
  131. },
  132. {
  133. .compatible = "socionext,uniphier-pxs2-ahci-reset",
  134. .data = &uniphier_pxs2_data,
  135. },
  136. {
  137. .compatible = "socionext,uniphier-pxs3-ahci-reset",
  138. .data = &uniphier_pxs2_data,
  139. },
  140. { /* Sentinel */ }
  141. };
  142. MODULE_DEVICE_TABLE(of, uniphier_glue_reset_match);
  143. static struct platform_driver uniphier_glue_reset_driver = {
  144. .probe = uniphier_glue_reset_probe,
  145. .driver = {
  146. .name = "uniphier-glue-reset",
  147. .of_match_table = uniphier_glue_reset_match,
  148. },
  149. };
  150. module_platform_driver(uniphier_glue_reset_driver);
  151. MODULE_AUTHOR("Kunihiko Hayashi <[email protected]>");
  152. MODULE_DESCRIPTION("UniPhier Glue layer reset driver");
  153. MODULE_LICENSE("GPL");