reset-ast2600.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_assert(struct reset_ctl *reset_ctl)
  18. {
  19. struct ast2600_reset_priv *priv = dev_get_priv(reset_ctl->dev);
  20. struct ast2600_scu *scu = priv->scu;
  21. debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id);
  22. if (reset_ctl->id < 32)
  23. writel(BIT(reset_ctl->id), &scu->modrst_ctrl1);
  24. else
  25. writel(BIT(reset_ctl->id - 32), &scu->modrst_ctrl2);
  26. return 0;
  27. }
  28. static int ast2600_reset_deassert(struct reset_ctl *reset_ctl)
  29. {
  30. struct ast2600_reset_priv *priv = dev_get_priv(reset_ctl->dev);
  31. struct ast2600_scu *scu = priv->scu;
  32. debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id);
  33. if (reset_ctl->id < 32)
  34. writel(BIT(reset_ctl->id), &scu->modrst_clr1);
  35. else
  36. writel(BIT(reset_ctl->id - 32), &scu->modrst_clr2);
  37. return 0;
  38. }
  39. static int ast2600_reset_status(struct reset_ctl *reset_ctl)
  40. {
  41. struct ast2600_reset_priv *priv = dev_get_priv(reset_ctl->dev);
  42. struct ast2600_scu *scu = priv->scu;
  43. int status;
  44. debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id);
  45. if (reset_ctl->id < 32)
  46. status = BIT(reset_ctl->id) & readl(&scu->modrst_ctrl1);
  47. else
  48. status = BIT(reset_ctl->id - 32) & readl(&scu->modrst_ctrl2);
  49. return !!status;
  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. .rst_assert = ast2600_reset_assert,
  76. .rst_deassert = ast2600_reset_deassert,
  77. .rst_status = ast2600_reset_status,
  78. };
  79. U_BOOT_DRIVER(ast2600_reset) = {
  80. .name = "ast2600_reset",
  81. .id = UCLASS_RESET,
  82. .of_match = ast2600_reset_ids,
  83. .probe = ast2600_reset_probe,
  84. .ops = &ast2600_reset_ops,
  85. .priv_auto = sizeof(struct ast2600_reset_priv),
  86. };