omap_wdt.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * omap_wdt.c
  4. *
  5. * (C) Copyright 2013
  6. * Heiko Schocher, DENX Software Engineering, hs@denx.de.
  7. *
  8. * Based on:
  9. *
  10. * Watchdog driver for the TI OMAP 16xx & 24xx/34xx 32KHz (non-secure) watchdog
  11. *
  12. * commit 2d991a164a61858012651e13c59521975504e260
  13. * Author: Bill Pemberton <wfp5p@virginia.edu>
  14. * Date: Mon Nov 19 13:21:41 2012 -0500
  15. *
  16. * watchdog: remove use of __devinit
  17. *
  18. * CONFIG_HOTPLUG is going away as an option so __devinit is no longer
  19. * needed.
  20. *
  21. * Author: MontaVista Software, Inc.
  22. * <gdavis@mvista.com> or <source@mvista.com>
  23. *
  24. * History:
  25. *
  26. * 20030527: George G. Davis <gdavis@mvista.com>
  27. * Initially based on linux-2.4.19-rmk7-pxa1/drivers/char/sa1100_wdt.c
  28. * (c) Copyright 2000 Oleg Drokin <green@crimea.edu>
  29. * Based on SoftDog driver by Alan Cox <alan@lxorguk.ukuu.org.uk>
  30. *
  31. * Copyright (c) 2004 Texas Instruments.
  32. * 1. Modified to support OMAP1610 32-KHz watchdog timer
  33. * 2. Ported to 2.6 kernel
  34. *
  35. * Copyright (c) 2005 David Brownell
  36. * Use the driver model and standard identifiers; handle bigger timeouts.
  37. */
  38. #include <common.h>
  39. #include <watchdog.h>
  40. #include <asm/arch/hardware.h>
  41. #include <asm/io.h>
  42. #include <asm/processor.h>
  43. #include <asm/arch/cpu.h>
  44. /* Hardware timeout in seconds */
  45. #define WDT_HW_TIMEOUT 60
  46. static unsigned int wdt_trgr_pattern = 0x1234;
  47. void hw_watchdog_reset(void)
  48. {
  49. struct wd_timer *wdt = (struct wd_timer *)WDT_BASE;
  50. /*
  51. * Somebody just triggered watchdog reset and write to WTGR register
  52. * is in progress. It is resetting right now, no need to trigger it
  53. * again
  54. */
  55. if ((readl(&wdt->wdtwwps)) & WDT_WWPS_PEND_WTGR)
  56. return;
  57. wdt_trgr_pattern = ~wdt_trgr_pattern;
  58. writel(wdt_trgr_pattern, &wdt->wdtwtgr);
  59. /*
  60. * Don't wait for posted write to complete, i.e. don't check
  61. * WDT_WWPS_PEND_WTGR bit in WWPS register. There is no writes to
  62. * WTGR register outside of this func, and if entering it
  63. * we see WDT_WWPS_PEND_WTGR bit set, it means watchdog reset
  64. * was just triggered. This prevents us from wasting time in busy
  65. * polling of WDT_WWPS_PEND_WTGR bit.
  66. */
  67. }
  68. static int omap_wdt_set_timeout(unsigned int timeout)
  69. {
  70. struct wd_timer *wdt = (struct wd_timer *)WDT_BASE;
  71. u32 pre_margin = GET_WLDR_VAL(timeout);
  72. /* just count up at 32 KHz */
  73. while (readl(&wdt->wdtwwps) & WDT_WWPS_PEND_WLDR)
  74. ;
  75. writel(pre_margin, &wdt->wdtwldr);
  76. while (readl(&wdt->wdtwwps) & WDT_WWPS_PEND_WLDR)
  77. ;
  78. return 0;
  79. }
  80. void hw_watchdog_disable(void)
  81. {
  82. struct wd_timer *wdt = (struct wd_timer *)WDT_BASE;
  83. /*
  84. * Disable watchdog
  85. */
  86. writel(0xAAAA, &wdt->wdtwspr);
  87. while (readl(&wdt->wdtwwps) != 0x0)
  88. ;
  89. writel(0x5555, &wdt->wdtwspr);
  90. while (readl(&wdt->wdtwwps) != 0x0)
  91. ;
  92. }
  93. void hw_watchdog_init(void)
  94. {
  95. struct wd_timer *wdt = (struct wd_timer *)WDT_BASE;
  96. /*
  97. * Make sure the watchdog is disabled. This is unfortunately required
  98. * because writing to various registers with the watchdog running has no
  99. * effect.
  100. */
  101. hw_watchdog_disable();
  102. /* initialize prescaler */
  103. while (readl(&wdt->wdtwwps) & WDT_WWPS_PEND_WCLR)
  104. ;
  105. writel(WDT_WCLR_PRE | (PTV << WDT_WCLR_PTV_OFF), &wdt->wdtwclr);
  106. while (readl(&wdt->wdtwwps) & WDT_WWPS_PEND_WCLR)
  107. ;
  108. omap_wdt_set_timeout(WDT_HW_TIMEOUT);
  109. /* Sequence to enable the watchdog */
  110. writel(0xBBBB, &wdt->wdtwspr);
  111. while ((readl(&wdt->wdtwwps)) & WDT_WWPS_PEND_WSPR)
  112. ;
  113. writel(0x4444, &wdt->wdtwspr);
  114. while ((readl(&wdt->wdtwwps)) & WDT_WWPS_PEND_WSPR)
  115. ;
  116. }