xilinx_tb_wdt.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) 2011-2013 Xilinx Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <asm/io.h>
  8. #include <asm/microblaze_intc.h>
  9. #include <asm/processor.h>
  10. #include <watchdog.h>
  11. #define XWT_CSR0_WRS_MASK 0x00000008 /* Reset status Mask */
  12. #define XWT_CSR0_WDS_MASK 0x00000004 /* Timer state Mask */
  13. #define XWT_CSR0_EWDT1_MASK 0x00000002 /* Enable bit 1 Mask*/
  14. #define XWT_CSRX_EWDT2_MASK 0x00000001 /* Enable bit 2 Mask */
  15. struct watchdog_regs {
  16. u32 twcsr0; /* 0x0 */
  17. u32 twcsr1; /* 0x4 */
  18. u32 tbr; /* 0x8 */
  19. };
  20. static struct watchdog_regs *watchdog_base =
  21. (struct watchdog_regs *)CONFIG_WATCHDOG_BASEADDR;
  22. void hw_watchdog_reset(void)
  23. {
  24. u32 reg;
  25. /* Read the current contents of TCSR0 */
  26. reg = readl(&watchdog_base->twcsr0);
  27. /* Clear the watchdog WDS bit */
  28. if (reg & (XWT_CSR0_EWDT1_MASK | XWT_CSRX_EWDT2_MASK))
  29. writel(reg | XWT_CSR0_WDS_MASK, &watchdog_base->twcsr0);
  30. }
  31. void hw_watchdog_disable(void)
  32. {
  33. u32 reg;
  34. /* Read the current contents of TCSR0 */
  35. reg = readl(&watchdog_base->twcsr0);
  36. writel(reg & ~XWT_CSR0_EWDT1_MASK, &watchdog_base->twcsr0);
  37. writel(~XWT_CSRX_EWDT2_MASK, &watchdog_base->twcsr1);
  38. puts("Watchdog disabled!\n");
  39. }
  40. static void hw_watchdog_isr(void *arg)
  41. {
  42. hw_watchdog_reset();
  43. }
  44. void hw_watchdog_init(void)
  45. {
  46. int ret;
  47. writel((XWT_CSR0_WRS_MASK | XWT_CSR0_WDS_MASK | XWT_CSR0_EWDT1_MASK),
  48. &watchdog_base->twcsr0);
  49. writel(XWT_CSRX_EWDT2_MASK, &watchdog_base->twcsr1);
  50. ret = install_interrupt_handler(CONFIG_WATCHDOG_IRQ,
  51. hw_watchdog_isr, NULL);
  52. if (ret)
  53. puts("Watchdog IRQ registration failed.");
  54. }