xilinx_tb_wdt.c 1.6 KB

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