sysreset_ast.c 944 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 <sysreset.h>
  9. #include <wdt.h>
  10. #include <asm/io.h>
  11. #include <asm/arch/wdt.h>
  12. #include <linux/err.h>
  13. static int ast_sysreset_request(struct udevice *dev, enum sysreset_t type)
  14. {
  15. struct udevice *wdt;
  16. u32 reset_mode;
  17. int ret = uclass_first_device(UCLASS_WDT, &wdt);
  18. if (ret)
  19. return ret;
  20. switch (type) {
  21. case SYSRESET_WARM:
  22. reset_mode = WDT_CTRL_RESET_CPU;
  23. break;
  24. case SYSRESET_COLD:
  25. reset_mode = WDT_CTRL_RESET_CHIP;
  26. break;
  27. default:
  28. return -EPROTONOSUPPORT;
  29. }
  30. ret = wdt_expire_now(wdt, reset_mode);
  31. if (ret) {
  32. debug("Sysreset failed: %d", ret);
  33. return ret;
  34. }
  35. return -EINPROGRESS;
  36. }
  37. static struct sysreset_ops ast_sysreset = {
  38. .request = ast_sysreset_request,
  39. };
  40. U_BOOT_DRIVER(sysreset_ast) = {
  41. .name = "ast_sysreset",
  42. .id = UCLASS_SYSRESET,
  43. .ops = &ast_sysreset,
  44. };