2007-06-07 23:06:41 +00:00
|
|
|
/*
|
|
|
|
* Watchdog driver for Atmel AT32AP700X devices
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005-2006 Atmel Corporation
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
2007-10-30 13:56:20 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Errata: WDT Clear is blocked after WDT Reset
|
|
|
|
*
|
|
|
|
* A watchdog timer event will, after reset, block writes to the WDT_CLEAR
|
|
|
|
* register, preventing the program to clear the next Watchdog Timer Reset.
|
|
|
|
*
|
|
|
|
* If you still want to use the WDT after a WDT reset a small code can be
|
|
|
|
* insterted at the startup checking the AVR32_PM.rcause register for WDT reset
|
|
|
|
* and use a GPIO pin to reset the system. This method requires that one of the
|
|
|
|
* GPIO pins are available and connected externally to the RESET_N pin. After
|
|
|
|
* the GPIO pin has pulled down the reset line the GPIO will be reset and leave
|
|
|
|
* the pin tristated with pullup.
|
2007-06-07 23:06:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/miscdevice.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/watchdog.h>
|
2007-06-07 23:06:43 +00:00
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/io.h>
|
2007-07-03 17:59:04 +00:00
|
|
|
#include <linux/spinlock.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2007-06-07 23:06:41 +00:00
|
|
|
|
|
|
|
#define TIMEOUT_MIN 1
|
|
|
|
#define TIMEOUT_MAX 2
|
2007-06-18 20:49:35 +00:00
|
|
|
#define TIMEOUT_DEFAULT TIMEOUT_MAX
|
|
|
|
|
|
|
|
/* module parameters */
|
|
|
|
static int timeout = TIMEOUT_DEFAULT;
|
|
|
|
module_param(timeout, int, 0);
|
|
|
|
MODULE_PARM_DESC(timeout,
|
|
|
|
"Timeout value. Limited to be 1 or 2 seconds. (default="
|
|
|
|
__MODULE_STRING(TIMEOUT_DEFAULT) ")");
|
2007-06-07 23:06:41 +00:00
|
|
|
|
2012-03-05 15:51:11 +00:00
|
|
|
static bool nowayout = WATCHDOG_NOWAYOUT;
|
|
|
|
module_param(nowayout, bool, 0);
|
2007-06-20 21:36:43 +00:00
|
|
|
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
|
|
|
|
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
|
|
|
|
|
2007-06-07 23:06:41 +00:00
|
|
|
/* Watchdog registers and write/read macro */
|
|
|
|
#define WDT_CTRL 0x00
|
|
|
|
#define WDT_CTRL_EN 0
|
|
|
|
#define WDT_CTRL_PSEL 8
|
|
|
|
#define WDT_CTRL_KEY 24
|
|
|
|
|
|
|
|
#define WDT_CLR 0x04
|
|
|
|
|
2007-10-30 13:56:20 +00:00
|
|
|
#define WDT_RCAUSE 0x10
|
|
|
|
#define WDT_RCAUSE_POR 0
|
|
|
|
#define WDT_RCAUSE_EXT 2
|
|
|
|
#define WDT_RCAUSE_WDT 3
|
|
|
|
#define WDT_RCAUSE_JTAG 4
|
|
|
|
#define WDT_RCAUSE_SERP 5
|
|
|
|
|
2007-06-07 23:06:41 +00:00
|
|
|
#define WDT_BIT(name) (1 << WDT_##name)
|
2007-06-17 19:34:23 +00:00
|
|
|
#define WDT_BF(name, value) ((value) << WDT_##name)
|
2007-06-07 23:06:41 +00:00
|
|
|
|
2007-06-17 19:34:23 +00:00
|
|
|
#define wdt_readl(dev, reg) \
|
2007-06-07 23:06:41 +00:00
|
|
|
__raw_readl((dev)->regs + WDT_##reg)
|
2007-06-17 19:34:23 +00:00
|
|
|
#define wdt_writel(dev, reg, value) \
|
2007-06-07 23:06:41 +00:00
|
|
|
__raw_writel((value), (dev)->regs + WDT_##reg)
|
|
|
|
|
|
|
|
struct wdt_at32ap700x {
|
|
|
|
void __iomem *regs;
|
2007-07-03 17:59:04 +00:00
|
|
|
spinlock_t io_lock;
|
2007-06-07 23:06:41 +00:00
|
|
|
int timeout;
|
2007-10-30 13:56:20 +00:00
|
|
|
int boot_status;
|
2007-07-03 17:59:29 +00:00
|
|
|
unsigned long users;
|
2007-06-07 23:06:41 +00:00
|
|
|
struct miscdevice miscdev;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct wdt_at32ap700x *wdt;
|
2007-06-20 21:36:43 +00:00
|
|
|
static char expect_release;
|
2007-06-07 23:06:41 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable the watchdog.
|
|
|
|
*/
|
2007-06-17 19:34:23 +00:00
|
|
|
static inline void at32_wdt_stop(void)
|
2007-06-07 23:06:41 +00:00
|
|
|
{
|
2007-07-03 17:59:29 +00:00
|
|
|
unsigned long psel;
|
|
|
|
|
2007-07-03 17:59:04 +00:00
|
|
|
spin_lock(&wdt->io_lock);
|
2007-07-03 17:59:29 +00:00
|
|
|
psel = wdt_readl(wdt, CTRL) & WDT_BF(CTRL_PSEL, 0x0f);
|
2007-06-07 23:06:41 +00:00
|
|
|
wdt_writel(wdt, CTRL, psel | WDT_BF(CTRL_KEY, 0x55));
|
|
|
|
wdt_writel(wdt, CTRL, psel | WDT_BF(CTRL_KEY, 0xaa));
|
2007-07-03 17:59:04 +00:00
|
|
|
spin_unlock(&wdt->io_lock);
|
2007-06-07 23:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable and reset the watchdog.
|
|
|
|
*/
|
2007-06-17 19:34:23 +00:00
|
|
|
static inline void at32_wdt_start(void)
|
2007-06-07 23:06:41 +00:00
|
|
|
{
|
|
|
|
/* 0xf is 2^16 divider = 2 sec, 0xe is 2^15 divider = 1 sec */
|
|
|
|
unsigned long psel = (wdt->timeout > 1) ? 0xf : 0xe;
|
|
|
|
|
2007-07-03 17:59:04 +00:00
|
|
|
spin_lock(&wdt->io_lock);
|
2007-06-07 23:06:41 +00:00
|
|
|
wdt_writel(wdt, CTRL, WDT_BIT(CTRL_EN)
|
|
|
|
| WDT_BF(CTRL_PSEL, psel)
|
|
|
|
| WDT_BF(CTRL_KEY, 0x55));
|
|
|
|
wdt_writel(wdt, CTRL, WDT_BIT(CTRL_EN)
|
|
|
|
| WDT_BF(CTRL_PSEL, psel)
|
|
|
|
| WDT_BF(CTRL_KEY, 0xaa));
|
2007-07-03 17:59:04 +00:00
|
|
|
spin_unlock(&wdt->io_lock);
|
2007-06-07 23:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pat the watchdog timer.
|
|
|
|
*/
|
2007-06-17 19:34:23 +00:00
|
|
|
static inline void at32_wdt_pat(void)
|
2007-06-07 23:06:41 +00:00
|
|
|
{
|
2007-07-03 17:59:04 +00:00
|
|
|
spin_lock(&wdt->io_lock);
|
2007-06-07 23:06:41 +00:00
|
|
|
wdt_writel(wdt, CLR, 0x42);
|
2007-07-03 17:59:04 +00:00
|
|
|
spin_unlock(&wdt->io_lock);
|
2007-06-07 23:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Watchdog device is opened, and watchdog starts running.
|
|
|
|
*/
|
|
|
|
static int at32_wdt_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
if (test_and_set_bit(1, &wdt->users))
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
at32_wdt_start();
|
|
|
|
return nonseekable_open(inode, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-06-20 21:36:43 +00:00
|
|
|
* Close the watchdog device.
|
2007-06-07 23:06:41 +00:00
|
|
|
*/
|
|
|
|
static int at32_wdt_close(struct inode *inode, struct file *file)
|
|
|
|
{
|
2007-06-20 21:36:43 +00:00
|
|
|
if (expect_release == 42) {
|
|
|
|
at32_wdt_stop();
|
|
|
|
} else {
|
|
|
|
dev_dbg(wdt->miscdev.parent,
|
2007-10-30 13:56:20 +00:00
|
|
|
"unexpected close, not stopping watchdog!\n");
|
2007-06-20 21:36:43 +00:00
|
|
|
at32_wdt_pat();
|
|
|
|
}
|
2007-06-07 23:06:41 +00:00
|
|
|
clear_bit(1, &wdt->users);
|
2007-06-20 21:36:43 +00:00
|
|
|
expect_release = 0;
|
2007-06-07 23:06:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Change the watchdog time interval.
|
|
|
|
*/
|
|
|
|
static int at32_wdt_settimeout(int time)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* All counting occurs at 1 / SLOW_CLOCK (32 kHz) and max prescaler is
|
|
|
|
* 2 ^ 16 allowing up to 2 seconds timeout.
|
|
|
|
*/
|
|
|
|
if ((time < TIMEOUT_MIN) || (time > TIMEOUT_MAX))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2007-06-07 23:06:43 +00:00
|
|
|
/*
|
|
|
|
* Set new watchdog time. It will be used when at32_wdt_start() is
|
|
|
|
* called.
|
|
|
|
*/
|
2007-06-07 23:06:41 +00:00
|
|
|
wdt->timeout = time;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-10-30 13:56:20 +00:00
|
|
|
/*
|
|
|
|
* Get the watchdog status.
|
|
|
|
*/
|
|
|
|
static int at32_wdt_get_status(void)
|
|
|
|
{
|
|
|
|
int rcause;
|
|
|
|
int status = 0;
|
|
|
|
|
|
|
|
rcause = wdt_readl(wdt, RCAUSE);
|
|
|
|
|
|
|
|
switch (rcause) {
|
|
|
|
case WDT_BIT(RCAUSE_EXT):
|
|
|
|
status = WDIOF_EXTERN1;
|
|
|
|
break;
|
|
|
|
case WDT_BIT(RCAUSE_WDT):
|
|
|
|
status = WDIOF_CARDRESET;
|
|
|
|
break;
|
|
|
|
case WDT_BIT(RCAUSE_POR): /* fall through */
|
|
|
|
case WDT_BIT(RCAUSE_JTAG): /* fall through */
|
|
|
|
case WDT_BIT(RCAUSE_SERP): /* fall through */
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2009-12-26 18:55:22 +00:00
|
|
|
static const struct watchdog_info at32_wdt_info = {
|
2007-06-07 23:06:41 +00:00
|
|
|
.identity = "at32ap700x watchdog",
|
2007-06-20 21:36:43 +00:00
|
|
|
.options = WDIOF_SETTIMEOUT |
|
|
|
|
WDIOF_KEEPALIVEPING |
|
|
|
|
WDIOF_MAGICCLOSE,
|
2007-06-07 23:06:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle commands from user-space.
|
|
|
|
*/
|
2008-05-19 13:05:13 +00:00
|
|
|
static long at32_wdt_ioctl(struct file *file,
|
|
|
|
unsigned int cmd, unsigned long arg)
|
2007-06-07 23:06:41 +00:00
|
|
|
{
|
|
|
|
int ret = -ENOTTY;
|
|
|
|
int time;
|
|
|
|
void __user *argp = (void __user *)arg;
|
|
|
|
int __user *p = argp;
|
|
|
|
|
2007-06-07 23:06:43 +00:00
|
|
|
switch (cmd) {
|
2007-06-07 23:06:41 +00:00
|
|
|
case WDIOC_GETSUPPORT:
|
|
|
|
ret = copy_to_user(argp, &at32_wdt_info,
|
|
|
|
sizeof(at32_wdt_info)) ? -EFAULT : 0;
|
|
|
|
break;
|
2007-10-30 13:56:20 +00:00
|
|
|
case WDIOC_GETSTATUS:
|
2007-06-07 23:06:41 +00:00
|
|
|
ret = put_user(0, p);
|
|
|
|
break;
|
2007-10-30 13:56:20 +00:00
|
|
|
case WDIOC_GETBOOTSTATUS:
|
|
|
|
ret = put_user(wdt->boot_status, p);
|
|
|
|
break;
|
2007-06-07 23:06:41 +00:00
|
|
|
case WDIOC_SETOPTIONS:
|
|
|
|
ret = get_user(time, p);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
if (time & WDIOS_DISABLECARD)
|
|
|
|
at32_wdt_stop();
|
|
|
|
if (time & WDIOS_ENABLECARD)
|
|
|
|
at32_wdt_start();
|
|
|
|
ret = 0;
|
|
|
|
break;
|
2008-07-18 11:41:17 +00:00
|
|
|
case WDIOC_KEEPALIVE:
|
|
|
|
at32_wdt_pat();
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
case WDIOC_SETTIMEOUT:
|
|
|
|
ret = get_user(time, p);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
ret = at32_wdt_settimeout(time);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
/* Enable new time value */
|
|
|
|
at32_wdt_start();
|
|
|
|
/* fall through */
|
|
|
|
case WDIOC_GETTIMEOUT:
|
|
|
|
ret = put_user(wdt->timeout, p);
|
|
|
|
break;
|
2007-06-07 23:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-06-20 21:36:43 +00:00
|
|
|
static ssize_t at32_wdt_write(struct file *file, const char __user *data,
|
|
|
|
size_t len, loff_t *ppos)
|
2007-06-07 23:06:41 +00:00
|
|
|
{
|
2007-06-20 21:36:43 +00:00
|
|
|
/* See if we got the magic character 'V' and reload the timer */
|
|
|
|
if (len) {
|
|
|
|
if (!nowayout) {
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* note: just in case someone wrote the magic
|
|
|
|
* character five months ago...
|
|
|
|
*/
|
|
|
|
expect_release = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* scan to see whether or not we got the magic
|
|
|
|
* character
|
|
|
|
*/
|
|
|
|
for (i = 0; i != len; i++) {
|
|
|
|
char c;
|
2008-08-06 20:19:41 +00:00
|
|
|
if (get_user(c, data + i))
|
2007-06-20 21:36:43 +00:00
|
|
|
return -EFAULT;
|
|
|
|
if (c == 'V')
|
|
|
|
expect_release = 42;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* someone wrote to us, we should pat the watchdog */
|
|
|
|
at32_wdt_pat();
|
|
|
|
}
|
2007-06-07 23:06:41 +00:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations at32_wdt_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.llseek = no_llseek,
|
2008-05-19 13:05:13 +00:00
|
|
|
.unlocked_ioctl = at32_wdt_ioctl,
|
2007-06-07 23:06:41 +00:00
|
|
|
.open = at32_wdt_open,
|
|
|
|
.release = at32_wdt_close,
|
|
|
|
.write = at32_wdt_write,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init at32_wdt_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct resource *regs;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (wdt) {
|
|
|
|
dev_dbg(&pdev->dev, "only 1 wdt instance supported.\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (!regs) {
|
|
|
|
dev_dbg(&pdev->dev, "missing mmio resource\n");
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
2013-04-30 04:59:48 +00:00
|
|
|
wdt = devm_kzalloc(&pdev->dev, sizeof(struct wdt_at32ap700x),
|
|
|
|
GFP_KERNEL);
|
2007-06-07 23:06:41 +00:00
|
|
|
if (!wdt) {
|
|
|
|
dev_dbg(&pdev->dev, "no memory for wdt structure\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2013-04-30 04:59:48 +00:00
|
|
|
wdt->regs = devm_ioremap(&pdev->dev, regs->start, resource_size(regs));
|
2007-06-08 18:03:01 +00:00
|
|
|
if (!wdt->regs) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
dev_dbg(&pdev->dev, "could not map I/O memory\n");
|
|
|
|
goto err_free;
|
|
|
|
}
|
2007-10-30 13:56:20 +00:00
|
|
|
|
2007-07-03 17:59:04 +00:00
|
|
|
spin_lock_init(&wdt->io_lock);
|
2007-10-30 13:56:20 +00:00
|
|
|
wdt->boot_status = at32_wdt_get_status();
|
|
|
|
|
|
|
|
/* Work-around for watchdog silicon errata. */
|
|
|
|
if (wdt->boot_status & WDIOF_CARDRESET) {
|
|
|
|
dev_info(&pdev->dev, "CPU must be reset with external "
|
|
|
|
"reset or POR due to silicon errata.\n");
|
|
|
|
ret = -EIO;
|
2013-04-30 04:59:48 +00:00
|
|
|
goto err_free;
|
2007-10-30 13:56:20 +00:00
|
|
|
} else {
|
|
|
|
wdt->users = 0;
|
|
|
|
}
|
2010-06-08 06:44:32 +00:00
|
|
|
|
|
|
|
wdt->miscdev.minor = WATCHDOG_MINOR;
|
|
|
|
wdt->miscdev.name = "watchdog";
|
|
|
|
wdt->miscdev.fops = &at32_wdt_fops;
|
|
|
|
wdt->miscdev.parent = &pdev->dev;
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, wdt);
|
2007-06-07 23:06:41 +00:00
|
|
|
|
2007-06-18 20:49:35 +00:00
|
|
|
if (at32_wdt_settimeout(timeout)) {
|
|
|
|
at32_wdt_settimeout(TIMEOUT_DEFAULT);
|
2007-06-07 23:06:41 +00:00
|
|
|
dev_dbg(&pdev->dev,
|
|
|
|
"default timeout invalid, set to %d sec.\n",
|
2007-06-18 20:49:35 +00:00
|
|
|
TIMEOUT_DEFAULT);
|
2007-06-07 23:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = misc_register(&wdt->miscdev);
|
|
|
|
if (ret) {
|
|
|
|
dev_dbg(&pdev->dev, "failed to register wdt miscdev\n");
|
2013-05-03 20:11:14 +00:00
|
|
|
goto err_free;
|
2007-06-07 23:06:41 +00:00
|
|
|
}
|
|
|
|
|
2007-06-20 21:36:43 +00:00
|
|
|
dev_info(&pdev->dev,
|
|
|
|
"AT32AP700X WDT at 0x%p, timeout %d sec (nowayout=%d)\n",
|
|
|
|
wdt->regs, wdt->timeout, nowayout);
|
2007-06-07 23:06:41 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2007-06-08 18:03:01 +00:00
|
|
|
err_free:
|
2007-06-07 23:06:41 +00:00
|
|
|
wdt = NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __exit at32_wdt_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
if (wdt && platform_get_drvdata(pdev) == wdt) {
|
2007-06-20 21:36:43 +00:00
|
|
|
/* Stop the timer before we leave */
|
|
|
|
if (!nowayout)
|
|
|
|
at32_wdt_stop();
|
|
|
|
|
2007-06-07 23:06:41 +00:00
|
|
|
misc_deregister(&wdt->miscdev);
|
|
|
|
wdt = NULL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void at32_wdt_shutdown(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
at32_wdt_stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
static int at32_wdt_suspend(struct platform_device *pdev, pm_message_t message)
|
|
|
|
{
|
|
|
|
at32_wdt_stop();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int at32_wdt_resume(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
if (wdt->users)
|
|
|
|
at32_wdt_start();
|
|
|
|
return 0;
|
|
|
|
}
|
2007-06-07 23:08:53 +00:00
|
|
|
#else
|
|
|
|
#define at32_wdt_suspend NULL
|
|
|
|
#define at32_wdt_resume NULL
|
2007-06-07 23:06:41 +00:00
|
|
|
#endif
|
|
|
|
|
2008-04-11 04:29:23 +00:00
|
|
|
/* work with hotplug and coldplug */
|
|
|
|
MODULE_ALIAS("platform:at32_wdt");
|
|
|
|
|
2007-06-07 23:06:41 +00:00
|
|
|
static struct platform_driver at32_wdt_driver = {
|
|
|
|
.remove = __exit_p(at32_wdt_remove),
|
|
|
|
.suspend = at32_wdt_suspend,
|
|
|
|
.resume = at32_wdt_resume,
|
|
|
|
.driver = {
|
|
|
|
.name = "at32_wdt",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
.shutdown = at32_wdt_shutdown,
|
|
|
|
};
|
|
|
|
|
2013-01-09 11:15:27 +00:00
|
|
|
module_platform_driver_probe(at32_wdt_driver, at32_wdt_probe);
|
2007-06-07 23:06:41 +00:00
|
|
|
|
2011-06-28 15:01:14 +00:00
|
|
|
MODULE_AUTHOR("Hans-Christian Egtvedt <egtvedt@samfundet.no>");
|
2007-06-07 23:06:41 +00:00
|
|
|
MODULE_DESCRIPTION("Watchdog driver for Atmel AT32AP700X");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
|