ast2500-reset.c 2.4 KB

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