sysreset_ast.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * (C) Copyright 2016 Google, Inc
  3. *
  4. * SPDX-License-Identifier: GPL-2.0
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <errno.h>
  9. #include <sysreset.h>
  10. #include <asm/io.h>
  11. #include <asm/arch/wdt.h>
  12. #include <linux/err.h>
  13. /* Number of Watchdog Timer ticks before reset */
  14. #define AST_WDT_RESET_TIMEOUT 10
  15. #define AST_WDT_FOR_RESET 0
  16. static int ast_sysreset_request(struct udevice *dev, enum sysreset_t type)
  17. {
  18. struct ast_wdt *wdt = ast_get_wdt(AST_WDT_FOR_RESET);
  19. u32 reset_mode = 0;
  20. if (IS_ERR(wdt))
  21. return PTR_ERR(wdt);
  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. /* Clear reset mode bits */
  33. clrsetbits_le32(&wdt->ctrl,
  34. (WDT_CTRL_RESET_MODE_MASK << WDT_CTRL_RESET_MODE_SHIFT),
  35. (reset_mode << WDT_CTRL_RESET_MODE_SHIFT));
  36. wdt_start(wdt, AST_WDT_RESET_TIMEOUT);
  37. return -EINPROGRESS;
  38. }
  39. static struct sysreset_ops ast_sysreset = {
  40. .request = ast_sysreset_request,
  41. };
  42. U_BOOT_DRIVER(sysreset_ast) = {
  43. .name = "ast_sysreset",
  44. .id = UCLASS_SYSRESET,
  45. .ops = &ast_sysreset,
  46. };