reset-ast2600.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright 2020 ASPEED Technology Inc.
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <log.h>
  8. #include <misc.h>
  9. #include <reset.h>
  10. #include <reset-uclass.h>
  11. #include <linux/err.h>
  12. #include <asm/io.h>
  13. #include <asm/arch/scu_ast2600.h>
  14. struct ast2600_reset_priv {
  15. struct ast2600_scu *scu;
  16. };
  17. static int ast2600_reset_request(struct reset_ctl *reset_ctl)
  18. {
  19. debug("%s(reset_ctl=%p) (dev=%p, id=%lu)\n", __func__, reset_ctl,
  20. reset_ctl->dev, reset_ctl->id);
  21. return 0;
  22. }
  23. static int ast2600_reset_free(struct reset_ctl *reset_ctl)
  24. {
  25. debug("%s(reset_ctl=%p) (dev=%p, id=%lu)\n", __func__, reset_ctl,
  26. reset_ctl->dev, reset_ctl->id);
  27. return 0;
  28. }
  29. static int ast2600_reset_assert(struct reset_ctl *reset_ctl)
  30. {
  31. struct ast2600_reset_priv *priv = dev_get_priv(reset_ctl->dev);
  32. struct ast2600_scu *scu = priv->scu;
  33. debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id);
  34. if (reset_ctl->id < 32)
  35. writel(BIT(reset_ctl->id), &scu->modrst_ctrl1);
  36. else
  37. writel(BIT(reset_ctl->id - 32), &scu->modrst_ctrl2);
  38. return 0;
  39. }
  40. static int ast2600_reset_deassert(struct reset_ctl *reset_ctl)
  41. {
  42. struct ast2600_reset_priv *priv = dev_get_priv(reset_ctl->dev);
  43. struct ast2600_scu *scu = priv->scu;
  44. debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id);
  45. if (reset_ctl->id < 32)
  46. writel(BIT(reset_ctl->id), &scu->modrst_clr1);
  47. else
  48. writel(BIT(reset_ctl->id - 32), &scu->modrst_clr2);
  49. return 0;
  50. }
  51. static int ast2600_reset_probe(struct udevice *dev)
  52. {
  53. int rc;
  54. struct ast2600_reset_priv *priv = dev_get_priv(dev);
  55. struct udevice *scu_dev;
  56. /* get SCU base from clock device */
  57. rc = uclass_get_device_by_driver(UCLASS_CLK,
  58. DM_DRIVER_GET(aspeed_ast2600_scu), &scu_dev);
  59. if (rc) {
  60. debug("%s: clock device not found, rc=%d\n", __func__, rc);
  61. return rc;
  62. }
  63. priv->scu = devfdt_get_addr_ptr(scu_dev);
  64. if (IS_ERR_OR_NULL(priv->scu)) {
  65. debug("%s: invalid SCU base pointer\n", __func__);
  66. return PTR_ERR(priv->scu);
  67. }
  68. return 0;
  69. }
  70. static const struct udevice_id ast2600_reset_ids[] = {
  71. { .compatible = "aspeed,ast2600-reset" },
  72. { }
  73. };
  74. struct reset_ops ast2600_reset_ops = {
  75. .request = ast2600_reset_request,
  76. .rfree = ast2600_reset_free,
  77. .rst_assert = ast2600_reset_assert,
  78. .rst_deassert = ast2600_reset_deassert,
  79. };
  80. U_BOOT_DRIVER(ast2600_reset) = {
  81. .name = "ast2600_reset",
  82. .id = UCLASS_RESET,
  83. .of_match = ast2600_reset_ids,
  84. .probe = ast2600_reset_probe,
  85. .ops = &ast2600_reset_ops,
  86. .priv_auto = sizeof(struct ast2600_reset_priv),
  87. };