xilinx_tb_wdt.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) 2011-2013 Xilinx Inc.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <asm/io.h>
  24. #include <asm/microblaze_intc.h>
  25. #include <asm/processor.h>
  26. #include <watchdog.h>
  27. #define XWT_CSR0_WRS_MASK 0x00000008 /* Reset status Mask */
  28. #define XWT_CSR0_WDS_MASK 0x00000004 /* Timer state Mask */
  29. #define XWT_CSR0_EWDT1_MASK 0x00000002 /* Enable bit 1 Mask*/
  30. #define XWT_CSRX_EWDT2_MASK 0x00000001 /* Enable bit 2 Mask */
  31. struct watchdog_regs {
  32. u32 twcsr0; /* 0x0 */
  33. u32 twcsr1; /* 0x4 */
  34. u32 tbr; /* 0x8 */
  35. };
  36. static struct watchdog_regs *watchdog_base =
  37. (struct watchdog_regs *)CONFIG_WATCHDOG_BASEADDR;
  38. void hw_watchdog_reset(void)
  39. {
  40. u32 reg;
  41. /* Read the current contents of TCSR0 */
  42. reg = readl(&watchdog_base->twcsr0);
  43. /* Clear the watchdog WDS bit */
  44. if (reg & (XWT_CSR0_EWDT1_MASK | XWT_CSRX_EWDT2_MASK))
  45. writel(reg | XWT_CSR0_WDS_MASK, &watchdog_base->twcsr0);
  46. }
  47. void hw_watchdog_disable(void)
  48. {
  49. u32 reg;
  50. /* Read the current contents of TCSR0 */
  51. reg = readl(&watchdog_base->twcsr0);
  52. writel(reg & ~XWT_CSR0_EWDT1_MASK, &watchdog_base->twcsr0);
  53. writel(~XWT_CSRX_EWDT2_MASK, &watchdog_base->twcsr1);
  54. puts("Watchdog disabled!\n");
  55. }
  56. static void hw_watchdog_isr(void *arg)
  57. {
  58. hw_watchdog_reset();
  59. }
  60. int hw_watchdog_init(void)
  61. {
  62. int ret;
  63. writel((XWT_CSR0_WRS_MASK | XWT_CSR0_WDS_MASK | XWT_CSR0_EWDT1_MASK),
  64. &watchdog_base->twcsr0);
  65. writel(XWT_CSRX_EWDT2_MASK, &watchdog_base->twcsr1);
  66. ret = install_interrupt_handler(CONFIG_WATCHDOG_IRQ,
  67. hw_watchdog_isr, NULL);
  68. if (ret)
  69. return 1;
  70. return 0;
  71. }