reset-ast2500.c 2.5 KB

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