Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Macpaul Lin | 9096963 | 2011-01-26 18:46:28 +0800 | [diff] [blame] | 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 | * |
Macpaul Lin | 9096963 | 2011-01-26 18:46:28 +0800 | [diff] [blame] | 12 | * 27/11/2004 Initial release, Faraday. |
| 13 | * 12/01/2011 Port to u-boot, Macpaul Lin. |
| 14 | */ |
| 15 | |
| 16 | #include <common.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 17 | #include <log.h> |
Macpaul Lin | 9096963 | 2011-01-26 18:46:28 +0800 | [diff] [blame] | 18 | #include <watchdog.h> |
| 19 | #include <asm/io.h> |
Macpaul Lin | 04c2dd8 | 2011-04-12 13:04:02 +0800 | [diff] [blame] | 20 | #include <faraday/ftwdt010_wdt.h> |
Macpaul Lin | 9096963 | 2011-01-26 18:46:28 +0800 | [diff] [blame] | 21 | |
| 22 | /* |
| 23 | * Set the watchdog time interval. |
| 24 | * Counter is 32 bit. |
| 25 | */ |
Macpaul Lin | 04c2dd8 | 2011-04-12 13:04:02 +0800 | [diff] [blame] | 26 | int ftwdt010_wdt_settimeout(unsigned int timeout) |
Macpaul Lin | 9096963 | 2011-01-26 18:46:28 +0800 | [diff] [blame] | 27 | { |
| 28 | unsigned int reg; |
| 29 | |
| 30 | struct ftwdt010_wdt *wd = (struct ftwdt010_wdt *)CONFIG_FTWDT010_BASE; |
| 31 | |
| 32 | debug("Activating WDT..\n"); |
| 33 | |
| 34 | /* Check if disabled */ |
| 35 | if (readl(&wd->wdcr) & ~FTWDT010_WDCR_ENABLE) { |
| 36 | printf("sorry, watchdog is disabled\n"); |
| 37 | return -1; |
| 38 | } |
| 39 | |
| 40 | /* |
| 41 | * In a 66MHz system, |
| 42 | * if you set WDLOAD as 0x03EF1480 (66000000) |
| 43 | * the reset timer is 1 second. |
| 44 | */ |
| 45 | reg = FTWDT010_WDLOAD(timeout * FTWDT010_TIMEOUT_FACTOR); |
| 46 | |
| 47 | writel(reg, &wd->wdload); |
| 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |
Macpaul Lin | 04c2dd8 | 2011-04-12 13:04:02 +0800 | [diff] [blame] | 52 | void ftwdt010_wdt_reset(void) |
Macpaul Lin | 9096963 | 2011-01-26 18:46:28 +0800 | [diff] [blame] | 53 | { |
| 54 | struct ftwdt010_wdt *wd = (struct ftwdt010_wdt *)CONFIG_FTWDT010_BASE; |
| 55 | |
| 56 | /* clear control register */ |
| 57 | writel(0, &wd->wdcr); |
| 58 | |
| 59 | /* Write Magic number */ |
| 60 | writel(FTWDT010_WDRESTART_MAGIC, &wd->wdrestart); |
| 61 | |
| 62 | /* Enable WDT */ |
| 63 | writel((FTWDT010_WDCR_RST | FTWDT010_WDCR_ENABLE), &wd->wdcr); |
| 64 | } |
| 65 | |
Macpaul Lin | 04c2dd8 | 2011-04-12 13:04:02 +0800 | [diff] [blame] | 66 | void ftwdt010_wdt_disable(void) |
Macpaul Lin | 9096963 | 2011-01-26 18:46:28 +0800 | [diff] [blame] | 67 | { |
| 68 | struct ftwdt010_wdt *wd = (struct ftwdt010_wdt *)CONFIG_FTWDT010_BASE; |
| 69 | |
| 70 | debug("Deactivating WDT..\n"); |
| 71 | |
| 72 | /* |
| 73 | * It was defined with CONFIG_WATCHDOG_NOWAYOUT in Linux |
| 74 | * |
| 75 | * Shut off the timer. |
| 76 | * Lock it in if it's a module and we defined ...NOWAYOUT |
| 77 | */ |
| 78 | writel(0, &wd->wdcr); |
| 79 | } |
| 80 | |
Macpaul Lin | 04c2dd8 | 2011-04-12 13:04:02 +0800 | [diff] [blame] | 81 | #if defined(CONFIG_HW_WATCHDOG) |
| 82 | void hw_watchdog_reset(void) |
Macpaul Lin | 9096963 | 2011-01-26 18:46:28 +0800 | [diff] [blame] | 83 | { |
| 84 | ftwdt010_wdt_reset(); |
| 85 | } |
| 86 | |
| 87 | void hw_watchdog_init(void) |
| 88 | { |
| 89 | /* set timer in ms */ |
| 90 | ftwdt010_wdt_settimeout(CONFIG_FTWDT010_HW_TIMEOUT * 1000); |
| 91 | } |
Macpaul Lin | 04c2dd8 | 2011-04-12 13:04:02 +0800 | [diff] [blame] | 92 | #endif |