2019-06-20 16:28:46 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Watchdog driver for the SA11x0/PXA2xx
|
|
|
|
*
|
2009-03-18 08:35:09 +00:00
|
|
|
* (c) Copyright 2000 Oleg Drokin <green@crimea.edu>
|
|
|
|
* Based on SoftDog driver by Alan Cox <alan@lxorguk.ukuu.org.uk>
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* Neither Oleg Drokin nor iXcelerator.com admit liability nor provide
|
|
|
|
* warranty for any of this software. This material is provided
|
|
|
|
* "AS-IS" and at no charge.
|
|
|
|
*
|
|
|
|
* (c) Copyright 2000 Oleg Drokin <green@crimea.edu>
|
|
|
|
*
|
2009-03-18 08:35:09 +00:00
|
|
|
* 27/11/2000 Initial release
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2012-02-15 23:06:19 +00:00
|
|
|
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
2016-09-19 19:12:14 +00:00
|
|
|
#include <linux/clk.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/miscdevice.h>
|
|
|
|
#include <linux/watchdog.h>
|
|
|
|
#include <linux/init.h>
|
2012-03-20 19:33:19 +00:00
|
|
|
#include <linux/io.h>
|
2007-10-19 06:40:25 +00:00
|
|
|
#include <linux/bitops.h>
|
2008-05-19 13:08:05 +00:00
|
|
|
#include <linux/uaccess.h>
|
2008-11-29 17:35:51 +00:00
|
|
|
#include <linux/timex.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_PXA
|
2009-01-20 03:04:16 +00:00
|
|
|
#include <mach/regs-ost.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
|
2008-08-07 10:05:25 +00:00
|
|
|
#include <mach/reset.h>
|
2008-08-05 15:14:15 +00:00
|
|
|
#include <mach/hardware.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-12-24 03:32:45 +00:00
|
|
|
static unsigned long oscr_freq;
|
2005-04-16 22:20:36 +00:00
|
|
|
static unsigned long sa1100wdt_users;
|
2009-06-29 17:56:52 +00:00
|
|
|
static unsigned int pre_margin;
|
2005-04-16 22:20:36 +00:00
|
|
|
static int boot_status;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allow only one person to hold it open
|
|
|
|
*/
|
|
|
|
static int sa1100dog_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
2008-05-19 13:08:05 +00:00
|
|
|
if (test_and_set_bit(1, &sa1100wdt_users))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
/* Activate SA1100 Watchdog timer */
|
2012-06-06 10:42:36 +00:00
|
|
|
writel_relaxed(readl_relaxed(OSCR) + pre_margin, OSMR3);
|
|
|
|
writel_relaxed(OSSR_M3, OSSR);
|
|
|
|
writel_relaxed(OWER_WME, OWER);
|
|
|
|
writel_relaxed(readl_relaxed(OIER) | OIER_E3, OIER);
|
2019-03-26 20:51:19 +00:00
|
|
|
return stream_open(inode, file);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-08-03 19:34:52 +00:00
|
|
|
* The watchdog cannot be disabled.
|
|
|
|
*
|
|
|
|
* Previous comments suggested that turning off the interrupt by
|
|
|
|
* clearing OIER[E3] would prevent the watchdog timing out but this
|
|
|
|
* does not appear to be true (at least on the PXA255).
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
static int sa1100dog_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_crit("Device closed - timer will not stop\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
clear_bit(1, &sa1100wdt_users);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-19 13:08:05 +00:00
|
|
|
static ssize_t sa1100dog_write(struct file *file, const char __user *data,
|
|
|
|
size_t len, loff_t *ppos)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-08-03 19:34:52 +00:00
|
|
|
if (len)
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Refresh OSMR3 timer. */
|
2012-06-06 10:42:36 +00:00
|
|
|
writel_relaxed(readl_relaxed(OSCR) + pre_margin, OSMR3);
|
2005-04-16 22:20:36 +00:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2008-05-19 13:08:05 +00:00
|
|
|
static const struct watchdog_info ident = {
|
|
|
|
.options = WDIOF_CARDRESET | WDIOF_SETTIMEOUT
|
|
|
|
| WDIOF_KEEPALIVEPING,
|
2005-08-03 19:34:52 +00:00
|
|
|
.identity = "SA1100/PXA255 Watchdog",
|
2009-06-29 17:56:52 +00:00
|
|
|
.firmware_version = 1,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2008-05-19 13:08:05 +00:00
|
|
|
static long sa1100dog_ioctl(struct file *file, unsigned int cmd,
|
|
|
|
unsigned long arg)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-09-09 15:34:31 +00:00
|
|
|
int ret = -ENOTTY;
|
2005-04-16 22:20:36 +00:00
|
|
|
int time;
|
2005-11-07 10:21:24 +00:00
|
|
|
void __user *argp = (void __user *)arg;
|
|
|
|
int __user *p = argp;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case WDIOC_GETSUPPORT:
|
2005-11-07 10:21:24 +00:00
|
|
|
ret = copy_to_user(argp, &ident,
|
2005-04-16 22:20:36 +00:00
|
|
|
sizeof(ident)) ? -EFAULT : 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WDIOC_GETSTATUS:
|
2005-11-07 10:21:24 +00:00
|
|
|
ret = put_user(0, p);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WDIOC_GETBOOTSTATUS:
|
2005-11-07 10:21:24 +00:00
|
|
|
ret = put_user(boot_status, p);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
|
2008-07-18 11:41:17 +00:00
|
|
|
case WDIOC_KEEPALIVE:
|
2012-06-06 10:42:36 +00:00
|
|
|
writel_relaxed(readl_relaxed(OSCR) + pre_margin, OSMR3);
|
2008-07-18 11:41:17 +00:00
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
case WDIOC_SETTIMEOUT:
|
2005-11-07 10:21:24 +00:00
|
|
|
ret = get_user(time, p);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
|
2009-06-29 17:56:52 +00:00
|
|
|
if (time <= 0 || (oscr_freq * (long long)time >= 0xffffffff)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-12-24 03:32:45 +00:00
|
|
|
pre_margin = oscr_freq * time;
|
2012-06-06 10:42:36 +00:00
|
|
|
writel_relaxed(readl_relaxed(OSCR) + pre_margin, OSMR3);
|
2005-04-16 22:20:36 +00:00
|
|
|
/*fall through*/
|
|
|
|
|
|
|
|
case WDIOC_GETTIMEOUT:
|
2008-12-24 03:32:45 +00:00
|
|
|
ret = put_user(pre_margin / oscr_freq, p);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-05-19 13:08:05 +00:00
|
|
|
static const struct file_operations sa1100dog_fops = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.llseek = no_llseek,
|
|
|
|
.write = sa1100dog_write,
|
2008-05-19 13:08:05 +00:00
|
|
|
.unlocked_ioctl = sa1100dog_ioctl,
|
2005-04-16 22:20:36 +00:00
|
|
|
.open = sa1100dog_open,
|
|
|
|
.release = sa1100dog_release,
|
|
|
|
};
|
|
|
|
|
2008-05-19 13:08:05 +00:00
|
|
|
static struct miscdevice sa1100dog_miscdev = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.minor = WATCHDOG_MINOR,
|
2005-08-03 19:34:52 +00:00
|
|
|
.name = "watchdog",
|
2005-04-16 22:20:36 +00:00
|
|
|
.fops = &sa1100dog_fops,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int margin __initdata = 60; /* (secs) Default is 1 minute */
|
2016-09-19 19:12:14 +00:00
|
|
|
static struct clk *clk;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
static int __init sa1100dog_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2016-09-19 19:12:14 +00:00
|
|
|
clk = clk_get(NULL, "OSTIMER0");
|
|
|
|
if (IS_ERR(clk)) {
|
|
|
|
pr_err("SA1100/PXA2xx Watchdog Timer: clock not found: %d\n",
|
|
|
|
(int) PTR_ERR(clk));
|
|
|
|
return PTR_ERR(clk);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = clk_prepare_enable(clk);
|
|
|
|
if (ret) {
|
|
|
|
pr_err("SA1100/PXA2xx Watchdog Timer: clock failed to prepare+enable: %d\n",
|
|
|
|
ret);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
oscr_freq = clk_get_rate(clk);
|
2008-12-24 03:32:45 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Read the reset status, and save it for later. If
|
|
|
|
* we suspend, RCSR will be cleared, and the watchdog
|
|
|
|
* reset reason will be lost.
|
|
|
|
*/
|
2008-07-29 06:39:34 +00:00
|
|
|
boot_status = (reset_status & RESET_STATUS_WATCHDOG) ?
|
|
|
|
WDIOF_CARDRESET : 0;
|
2008-12-24 03:32:45 +00:00
|
|
|
pre_margin = oscr_freq * margin;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
ret = misc_register(&sa1100dog_miscdev);
|
2016-12-21 01:18:16 +00:00
|
|
|
if (ret == 0) {
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_info("SA1100/PXA2xx Watchdog Timer: timer margin %d sec\n",
|
|
|
|
margin);
|
2016-12-21 01:18:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-19 19:12:14 +00:00
|
|
|
clk_disable_unprepare(clk);
|
2016-12-21 01:18:16 +00:00
|
|
|
err:
|
2016-09-19 19:12:14 +00:00
|
|
|
clk_put(clk);
|
|
|
|
return ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit sa1100dog_exit(void)
|
|
|
|
{
|
|
|
|
misc_deregister(&sa1100dog_miscdev);
|
2016-09-19 19:12:14 +00:00
|
|
|
clk_disable_unprepare(clk);
|
|
|
|
clk_put(clk);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(sa1100dog_init);
|
|
|
|
module_exit(sa1100dog_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Oleg Drokin <green@crimea.edu>");
|
|
|
|
MODULE_DESCRIPTION("SA1100/PXA2xx Watchdog");
|
|
|
|
|
|
|
|
module_param(margin, int, 0);
|
|
|
|
MODULE_PARM_DESC(margin, "Watchdog margin in seconds (default 60s)");
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|