ast_wdt.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * (C) Copyright 2016 Google, Inc
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <asm/io.h>
  8. #include <asm/arch/wdt.h>
  9. #include <linux/err.h>
  10. void wdt_stop(struct ast_wdt *wdt)
  11. {
  12. clrbits_le32(&wdt->ctrl, WDT_CTRL_EN);
  13. }
  14. void wdt_start(struct ast_wdt *wdt, u32 timeout)
  15. {
  16. writel(timeout, &wdt->counter_reload_val);
  17. writel(WDT_COUNTER_RESTART_VAL, &wdt->counter_restart);
  18. /*
  19. * Setting CLK1MHZ bit is just for compatibility with ast2400 part.
  20. * On ast2500 watchdog timer clock is fixed at 1MHz and the bit is
  21. * read-only
  22. */
  23. setbits_le32(&wdt->ctrl,
  24. WDT_CTRL_EN | WDT_CTRL_RESET | WDT_CTRL_CLK1MHZ);
  25. }
  26. struct ast_wdt *ast_get_wdt(u8 wdt_number)
  27. {
  28. if (wdt_number > CONFIG_WDT_NUM - 1)
  29. return ERR_PTR(-EINVAL);
  30. return (struct ast_wdt *)(WDT_BASE +
  31. sizeof(struct ast_wdt) * wdt_number);
  32. }
  33. int ast_wdt_reset_masked(struct ast_wdt *wdt, u32 mask)
  34. {
  35. #ifdef CONFIG_ASPEED_AST2500
  36. if (!mask)
  37. return -EINVAL;
  38. writel(mask, &wdt->reset_mask);
  39. clrbits_le32(&wdt->ctrl,
  40. WDT_CTRL_RESET_MASK << WDT_CTRL_RESET_MODE_SHIFT);
  41. wdt_start(wdt, 1);
  42. /* Wait for WDT to reset */
  43. while (readl(&wdt->ctrl) & WDT_CTRL_EN)
  44. ;
  45. wdt_stop(wdt);
  46. return 0;
  47. #else
  48. return -EINVAL;
  49. #endif
  50. }