sysreset_ast.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * (C) Copyright 2016 Google, Inc
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <errno.h>
  8. #include <log.h>
  9. #include <sysreset.h>
  10. #include <wdt.h>
  11. #include <asm/io.h>
  12. #include <asm/arch/wdt.h>
  13. #include <linux/err.h>
  14. #include <hang.h>
  15. static int ast_sysreset_request(struct udevice *dev, enum sysreset_t type)
  16. {
  17. struct udevice *wdt;
  18. u32 reset_mode;
  19. int ret = uclass_first_device(UCLASS_WDT, &wdt);
  20. if (ret)
  21. return ret;
  22. switch (type) {
  23. case SYSRESET_WARM:
  24. reset_mode = WDT_CTRL_RESET_CPU;
  25. break;
  26. case SYSRESET_COLD:
  27. reset_mode = WDT_CTRL_RESET_CHIP;
  28. break;
  29. default:
  30. return -EPROTONOSUPPORT;
  31. }
  32. #if !defined(CONFIG_SPL_BUILD)
  33. ret = wdt_expire_now(wdt, reset_mode);
  34. if (ret) {
  35. debug("Sysreset failed: %d", ret);
  36. return ret;
  37. }
  38. #else
  39. hang();
  40. #endif
  41. return -EINPROGRESS;
  42. }
  43. static struct sysreset_ops ast_sysreset = {
  44. .request = ast_sysreset_request,
  45. };
  46. U_BOOT_DRIVER(sysreset_ast) = {
  47. .name = "ast_sysreset",
  48. .id = UCLASS_SYSRESET,
  49. .ops = &ast_sysreset,
  50. };