ast2500-reset.c 2.4 KB

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