ftwdt010_wdt.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Watchdog driver for the FTWDT010 Watch Dog Driver
  3. *
  4. * (c) Copyright 2004 Faraday Technology Corp. (www.faraday-tech.com)
  5. * Based on sa1100_wdt.c by Oleg Drokin <green@crimea.edu>
  6. * Based on SoftDog driver by Alan Cox <alan@redhat.com>
  7. *
  8. * Copyright (C) 2011 Andes Technology Corporation
  9. * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. *
  25. * 27/11/2004 Initial release, Faraday.
  26. * 12/01/2011 Port to u-boot, Macpaul Lin.
  27. */
  28. #include <common.h>
  29. #include <watchdog.h>
  30. #include <asm/io.h>
  31. #include <faraday/ftwdt010_wdt.h>
  32. /*
  33. * Set the watchdog time interval.
  34. * Counter is 32 bit.
  35. */
  36. int ftwdt010_wdt_settimeout(unsigned int timeout)
  37. {
  38. unsigned int reg;
  39. struct ftwdt010_wdt *wd = (struct ftwdt010_wdt *)CONFIG_FTWDT010_BASE;
  40. debug("Activating WDT..\n");
  41. /* Check if disabled */
  42. if (readl(&wd->wdcr) & ~FTWDT010_WDCR_ENABLE) {
  43. printf("sorry, watchdog is disabled\n");
  44. return -1;
  45. }
  46. /*
  47. * In a 66MHz system,
  48. * if you set WDLOAD as 0x03EF1480 (66000000)
  49. * the reset timer is 1 second.
  50. */
  51. reg = FTWDT010_WDLOAD(timeout * FTWDT010_TIMEOUT_FACTOR);
  52. writel(reg, &wd->wdload);
  53. return 0;
  54. }
  55. void ftwdt010_wdt_reset(void)
  56. {
  57. struct ftwdt010_wdt *wd = (struct ftwdt010_wdt *)CONFIG_FTWDT010_BASE;
  58. /* clear control register */
  59. writel(0, &wd->wdcr);
  60. /* Write Magic number */
  61. writel(FTWDT010_WDRESTART_MAGIC, &wd->wdrestart);
  62. /* Enable WDT */
  63. writel((FTWDT010_WDCR_RST | FTWDT010_WDCR_ENABLE), &wd->wdcr);
  64. }
  65. void ftwdt010_wdt_disable(void)
  66. {
  67. struct ftwdt010_wdt *wd = (struct ftwdt010_wdt *)CONFIG_FTWDT010_BASE;
  68. debug("Deactivating WDT..\n");
  69. /*
  70. * It was defined with CONFIG_WATCHDOG_NOWAYOUT in Linux
  71. *
  72. * Shut off the timer.
  73. * Lock it in if it's a module and we defined ...NOWAYOUT
  74. */
  75. writel(0, &wd->wdcr);
  76. }
  77. #if defined(CONFIG_HW_WATCHDOG)
  78. void hw_watchdog_reset(void)
  79. {
  80. ftwdt010_wdt_reset();
  81. }
  82. void hw_watchdog_init(void)
  83. {
  84. /* set timer in ms */
  85. ftwdt010_wdt_settimeout(CONFIG_FTWDT010_HW_TIMEOUT * 1000);
  86. }
  87. #endif