ast2500-reset.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright 2017 Google, Inc
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <misc.h>
  8. #include <reset.h>
  9. #include <reset-uclass.h>
  10. #include <wdt.h>
  11. #include <asm/io.h>
  12. #include <asm/arch/scu_ast2500.h>
  13. #include <asm/arch/wdt.h>
  14. struct ast2500_reset_priv {
  15. /* WDT used to perform resets. */
  16. struct udevice *wdt;
  17. struct ast2500_scu *scu;
  18. };
  19. static int ast2500_ofdata_to_platdata(struct udevice *dev)
  20. {
  21. struct ast2500_reset_priv *priv = dev_get_priv(dev);
  22. int ret;
  23. ret = uclass_get_device_by_phandle(UCLASS_WDT, dev, "aspeed,wdt",
  24. &priv->wdt);
  25. if (ret) {
  26. debug("%s: can't find WDT for reset controller", __func__);
  27. return ret;
  28. }
  29. return 0;
  30. }
  31. static int ast2500_reset_assert(struct reset_ctl *reset_ctl)
  32. {
  33. struct ast2500_reset_priv *priv = dev_get_priv(reset_ctl->dev);
  34. u32 reset_mode, reset_mask;
  35. bool reset_sdram;
  36. int ret;
  37. /*
  38. * To reset SDRAM, a specifal flag in SYSRESET register
  39. * needs to be enabled first
  40. */
  41. reset_mode = ast_reset_mode_from_flags(reset_ctl->id);
  42. reset_mask = ast_reset_mask_from_flags(reset_ctl->id);
  43. reset_sdram = reset_mode == WDT_CTRL_RESET_SOC &&
  44. (reset_mask & WDT_RESET_SDRAM);
  45. if (reset_sdram) {
  46. ast_scu_unlock(priv->scu);
  47. setbits_le32(&priv->scu->sysreset_ctrl1,
  48. SCU_SYSRESET_SDRAM_WDT);
  49. ret = wdt_expire_now(priv->wdt, reset_ctl->id);
  50. clrbits_le32(&priv->scu->sysreset_ctrl1,
  51. SCU_SYSRESET_SDRAM_WDT);
  52. ast_scu_lock(priv->scu);
  53. } else {
  54. ret = wdt_expire_now(priv->wdt, reset_ctl->id);
  55. }
  56. return ret;
  57. }
  58. static int ast2500_reset_request(struct reset_ctl *reset_ctl)
  59. {
  60. debug("%s(reset_ctl=%p) (dev=%p, id=%lu)\n", __func__, reset_ctl,
  61. reset_ctl->dev, reset_ctl->id);
  62. return 0;
  63. }
  64. static int ast2500_reset_probe(struct udevice *dev)
  65. {
  66. struct ast2500_reset_priv *priv = dev_get_priv(dev);
  67. priv->scu = ast_get_scu();
  68. return 0;
  69. }
  70. static const struct udevice_id ast2500_reset_ids[] = {
  71. { .compatible = "aspeed,ast2500-reset" },
  72. { }
  73. };
  74. struct reset_ops ast2500_reset_ops = {
  75. .rst_assert = ast2500_reset_assert,
  76. .request = ast2500_reset_request,
  77. };
  78. U_BOOT_DRIVER(ast2500_reset) = {
  79. .name = "ast2500_reset",
  80. .id = UCLASS_RESET,
  81. .of_match = ast2500_reset_ids,
  82. .probe = ast2500_reset_probe,
  83. .ops = &ast2500_reset_ops,
  84. .ofdata_to_platdata = ast2500_ofdata_to_platdata,
  85. .priv_auto_alloc_size = sizeof(struct ast2500_reset_priv),
  86. };