ftwdt010_wdt.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 <watchdog.h>
  17. #include <asm/io.h>
  18. #include <faraday/ftwdt010_wdt.h>
  19. /*
  20. * Set the watchdog time interval.
  21. * Counter is 32 bit.
  22. */
  23. int ftwdt010_wdt_settimeout(unsigned int timeout)
  24. {
  25. unsigned int reg;
  26. struct ftwdt010_wdt *wd = (struct ftwdt010_wdt *)CONFIG_FTWDT010_BASE;
  27. debug("Activating WDT..\n");
  28. /* Check if disabled */
  29. if (readl(&wd->wdcr) & ~FTWDT010_WDCR_ENABLE) {
  30. printf("sorry, watchdog is disabled\n");
  31. return -1;
  32. }
  33. /*
  34. * In a 66MHz system,
  35. * if you set WDLOAD as 0x03EF1480 (66000000)
  36. * the reset timer is 1 second.
  37. */
  38. reg = FTWDT010_WDLOAD(timeout * FTWDT010_TIMEOUT_FACTOR);
  39. writel(reg, &wd->wdload);
  40. return 0;
  41. }
  42. void ftwdt010_wdt_reset(void)
  43. {
  44. struct ftwdt010_wdt *wd = (struct ftwdt010_wdt *)CONFIG_FTWDT010_BASE;
  45. /* clear control register */
  46. writel(0, &wd->wdcr);
  47. /* Write Magic number */
  48. writel(FTWDT010_WDRESTART_MAGIC, &wd->wdrestart);
  49. /* Enable WDT */
  50. writel((FTWDT010_WDCR_RST | FTWDT010_WDCR_ENABLE), &wd->wdcr);
  51. }
  52. void ftwdt010_wdt_disable(void)
  53. {
  54. struct ftwdt010_wdt *wd = (struct ftwdt010_wdt *)CONFIG_FTWDT010_BASE;
  55. debug("Deactivating WDT..\n");
  56. /*
  57. * It was defined with CONFIG_WATCHDOG_NOWAYOUT in Linux
  58. *
  59. * Shut off the timer.
  60. * Lock it in if it's a module and we defined ...NOWAYOUT
  61. */
  62. writel(0, &wd->wdcr);
  63. }
  64. #if defined(CONFIG_HW_WATCHDOG)
  65. void hw_watchdog_reset(void)
  66. {
  67. ftwdt010_wdt_reset();
  68. }
  69. void hw_watchdog_init(void)
  70. {
  71. /* set timer in ms */
  72. ftwdt010_wdt_settimeout(CONFIG_FTWDT010_HW_TIMEOUT * 1000);
  73. }
  74. #endif