sysreset_ast.c 961 B

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