ftwdt010_wdt.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Watchdog driver for the FTWDT010 Watch Dog Driver
  4. *
  5. * (c) Copyright 2004 Faraday Technology Corp. (www.faraday-tech.com)
  6. * Based on sa1100_wdt.c by Oleg Drokin <green@crimea.edu>
  7. * Based on SoftDog driver by Alan Cox <alan@redhat.com>
  8. *
  9. * Copyright (C) 2011 Andes Technology Corporation
  10. * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
  11. *
  12. * 27/11/2004 Initial release, Faraday.
  13. * 12/01/2011 Port to u-boot, Macpaul Lin.
  14. */
  15. #include <common.h>
  16. #include <log.h>
  17. #include <watchdog.h>
  18. #include <asm/io.h>
  19. #include <faraday/ftwdt010_wdt.h>
  20. /*
  21. * Set the watchdog time interval.
  22. * Counter is 32 bit.
  23. */
  24. int ftwdt010_wdt_settimeout(unsigned int timeout)
  25. {
  26. unsigned int reg;
  27. struct ftwdt010_wdt *wd = (struct ftwdt010_wdt *)CONFIG_FTWDT010_BASE;
  28. debug("Activating WDT..\n");
  29. /* Check if disabled */
  30. if (readl(&wd->wdcr) & ~FTWDT010_WDCR_ENABLE) {
  31. printf("sorry, watchdog is disabled\n");
  32. return -1;
  33. }
  34. /*
  35. * In a 66MHz system,
  36. * if you set WDLOAD as 0x03EF1480 (66000000)
  37. * the reset timer is 1 second.
  38. */
  39. reg = FTWDT010_WDLOAD(timeout * FTWDT010_TIMEOUT_FACTOR);
  40. writel(reg, &wd->wdload);
  41. return 0;
  42. }
  43. void ftwdt010_wdt_reset(void)
  44. {
  45. struct ftwdt010_wdt *wd = (struct ftwdt010_wdt *)CONFIG_FTWDT010_BASE;
  46. /* clear control register */
  47. writel(0, &wd->wdcr);
  48. /* Write Magic number */
  49. writel(FTWDT010_WDRESTART_MAGIC, &wd->wdrestart);
  50. /* Enable WDT */
  51. writel((FTWDT010_WDCR_RST | FTWDT010_WDCR_ENABLE), &wd->wdcr);
  52. }
  53. void ftwdt010_wdt_disable(void)
  54. {
  55. struct ftwdt010_wdt *wd = (struct ftwdt010_wdt *)CONFIG_FTWDT010_BASE;
  56. debug("Deactivating WDT..\n");
  57. /*
  58. * It was defined with CONFIG_WATCHDOG_NOWAYOUT in Linux
  59. *
  60. * Shut off the timer.
  61. * Lock it in if it's a module and we defined ...NOWAYOUT
  62. */
  63. writel(0, &wd->wdcr);
  64. }
  65. #if defined(CONFIG_HW_WATCHDOG)
  66. void hw_watchdog_reset(void)
  67. {
  68. ftwdt010_wdt_reset();
  69. }
  70. void hw_watchdog_init(void)
  71. {
  72. /* set timer in ms */
  73. ftwdt010_wdt_settimeout(CONFIG_FTWDT010_HW_TIMEOUT * 1000);
  74. }
  75. #endif