Commit f4fabce1 authored by Alan Cox's avatar Alan Cox Committed by Wim Van Sebroeck

[WATCHDOG 23/57] ks8695_wdt: clean up, coding style, unlocked_ioctl

Review and switch to unlocked_ioctl
Signed-off-by: default avatarAlan Cox <alan@redhat.com>
Signed-off-by: default avatarWim Van Sebroeck <wim@iguana.be>
parent 20d35f3e
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/watchdog.h> #include <linux/watchdog.h>
#include <asm/io.h> #include <linux/io.h>
#include <asm/uaccess.h> #include <linux/uaccess.h>
#include <asm/arch/regs-timer.h> #include <asm/arch/regs-timer.h>
...@@ -31,38 +31,44 @@ static int wdt_time = WDT_DEFAULT_TIME; ...@@ -31,38 +31,44 @@ static int wdt_time = WDT_DEFAULT_TIME;
static int nowayout = WATCHDOG_NOWAYOUT; static int nowayout = WATCHDOG_NOWAYOUT;
module_param(wdt_time, int, 0); module_param(wdt_time, int, 0);
MODULE_PARM_DESC(wdt_time, "Watchdog time in seconds. (default="__MODULE_STRING(WDT_DEFAULT_TIME) ")"); MODULE_PARM_DESC(wdt_time, "Watchdog time in seconds. (default="
__MODULE_STRING(WDT_DEFAULT_TIME) ")");
#ifdef CONFIG_WATCHDOG_NOWAYOUT #ifdef CONFIG_WATCHDOG_NOWAYOUT
module_param(nowayout, int, 0); module_param(nowayout, int, 0);
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
#endif #endif
static unsigned long ks8695wdt_busy; static unsigned long ks8695wdt_busy;
static spinlock_t ks8695_lock;
/* ......................................................................... */ /* ......................................................................... */
/* /*
* Disable the watchdog. * Disable the watchdog.
*/ */
static void inline ks8695_wdt_stop(void) static inline void ks8695_wdt_stop(void)
{ {
unsigned long tmcon; unsigned long tmcon;
spin_lock(&ks8695_lock);
/* disable timer0 */ /* disable timer0 */
tmcon = __raw_readl(KS8695_TMR_VA + KS8695_TMCON); tmcon = __raw_readl(KS8695_TMR_VA + KS8695_TMCON);
__raw_writel(tmcon & ~TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON); __raw_writel(tmcon & ~TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON);
spin_unlock(&ks8695_lock);
} }
/* /*
* Enable and reset the watchdog. * Enable and reset the watchdog.
*/ */
static void inline ks8695_wdt_start(void) static inline void ks8695_wdt_start(void)
{ {
unsigned long tmcon; unsigned long tmcon;
unsigned long tval = wdt_time * CLOCK_TICK_RATE; unsigned long tval = wdt_time * CLOCK_TICK_RATE;
spin_lock(&ks8695_lock);
/* disable timer0 */ /* disable timer0 */
tmcon = __raw_readl(KS8695_TMR_VA + KS8695_TMCON); tmcon = __raw_readl(KS8695_TMR_VA + KS8695_TMCON);
__raw_writel(tmcon & ~TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON); __raw_writel(tmcon & ~TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON);
...@@ -73,19 +79,22 @@ static void inline ks8695_wdt_start(void) ...@@ -73,19 +79,22 @@ static void inline ks8695_wdt_start(void)
/* re-enable timer0 */ /* re-enable timer0 */
tmcon = __raw_readl(KS8695_TMR_VA + KS8695_TMCON); tmcon = __raw_readl(KS8695_TMR_VA + KS8695_TMCON);
__raw_writel(tmcon | TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON); __raw_writel(tmcon | TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON);
spin_unlock(&ks8695_lock);
} }
/* /*
* Reload the watchdog timer. (ie, pat the watchdog) * Reload the watchdog timer. (ie, pat the watchdog)
*/ */
static void inline ks8695_wdt_reload(void) static inline void ks8695_wdt_reload(void)
{ {
unsigned long tmcon; unsigned long tmcon;
spin_lock(&ks8695_lock);
/* disable, then re-enable timer0 */ /* disable, then re-enable timer0 */
tmcon = __raw_readl(KS8695_TMR_VA + KS8695_TMCON); tmcon = __raw_readl(KS8695_TMR_VA + KS8695_TMCON);
__raw_writel(tmcon & ~TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON); __raw_writel(tmcon & ~TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON);
__raw_writel(tmcon | TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON); __raw_writel(tmcon | TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON);
spin_unlock(&ks8695_lock);
} }
/* /*
...@@ -102,7 +111,8 @@ static int ks8695_wdt_settimeout(int new_time) ...@@ -102,7 +111,8 @@ static int ks8695_wdt_settimeout(int new_time)
if ((new_time <= 0) || (new_time > WDT_MAX_TIME)) if ((new_time <= 0) || (new_time > WDT_MAX_TIME))
return -EINVAL; return -EINVAL;
/* Set new watchdog time. It will be used when ks8695_wdt_start() is called. */ /* Set new watchdog time. It will be used when
ks8695_wdt_start() is called. */
wdt_time = new_time; wdt_time = new_time;
return 0; return 0;
} }
...@@ -128,9 +138,9 @@ static int ks8695_wdt_open(struct inode *inode, struct file *file) ...@@ -128,9 +138,9 @@ static int ks8695_wdt_open(struct inode *inode, struct file *file)
*/ */
static int ks8695_wdt_close(struct inode *inode, struct file *file) static int ks8695_wdt_close(struct inode *inode, struct file *file)
{ {
/* Disable the watchdog when file is closed */
if (!nowayout) if (!nowayout)
ks8695_wdt_stop(); /* Disable the watchdog when file is closed */ ks8695_wdt_stop();
clear_bit(0, &ks8695wdt_busy); clear_bit(0, &ks8695wdt_busy);
return 0; return 0;
} }
...@@ -143,60 +153,52 @@ static struct watchdog_info ks8695_wdt_info = { ...@@ -143,60 +153,52 @@ static struct watchdog_info ks8695_wdt_info = {
/* /*
* Handle commands from user-space. * Handle commands from user-space.
*/ */
static int ks8695_wdt_ioctl(struct inode *inode, struct file *file, static long ks8695_wdt_ioctl(struct file *file, unsigned int cmd,
unsigned int cmd, unsigned long arg) unsigned long arg)
{ {
void __user *argp = (void __user *)arg; void __user *argp = (void __user *)arg;
int __user *p = argp; int __user *p = argp;
int new_value; int new_value;
switch(cmd) { switch (cmd) {
case WDIOC_KEEPALIVE: case WDIOC_KEEPALIVE:
ks8695_wdt_reload(); /* pat the watchdog */ ks8695_wdt_reload(); /* pat the watchdog */
return 0; return 0;
case WDIOC_GETSUPPORT:
case WDIOC_GETSUPPORT: return copy_to_user(argp, &ks8695_wdt_info,
return copy_to_user(argp, &ks8695_wdt_info, sizeof(ks8695_wdt_info)) ? -EFAULT : 0; sizeof(ks8695_wdt_info)) ? -EFAULT : 0;
case WDIOC_SETTIMEOUT:
case WDIOC_SETTIMEOUT: if (get_user(new_value, p))
if (get_user(new_value, p)) return -EFAULT;
return -EFAULT; if (ks8695_wdt_settimeout(new_value))
return -EINVAL;
if (ks8695_wdt_settimeout(new_value)) /* Enable new time value */
return -EINVAL; ks8695_wdt_start();
/* Return current value */
/* Enable new time value */ return put_user(wdt_time, p);
case WDIOC_GETTIMEOUT:
return put_user(wdt_time, p);
case WDIOC_GETSTATUS:
case WDIOC_GETBOOTSTATUS:
return put_user(0, p);
case WDIOC_SETOPTIONS:
if (get_user(new_value, p))
return -EFAULT;
if (new_value & WDIOS_DISABLECARD)
ks8695_wdt_stop();
if (new_value & WDIOS_ENABLECARD)
ks8695_wdt_start(); ks8695_wdt_start();
return 0;
/* Return current value */ default:
return put_user(wdt_time, p); return -ENOTTY;
case WDIOC_GETTIMEOUT:
return put_user(wdt_time, p);
case WDIOC_GETSTATUS:
case WDIOC_GETBOOTSTATUS:
return put_user(0, p);
case WDIOC_SETOPTIONS:
if (get_user(new_value, p))
return -EFAULT;
if (new_value & WDIOS_DISABLECARD)
ks8695_wdt_stop();
if (new_value & WDIOS_ENABLECARD)
ks8695_wdt_start();
return 0;
default:
return -ENOTTY;
} }
} }
/* /*
* Pat the watchdog whenever device is written to. * Pat the watchdog whenever device is written to.
*/ */
static ssize_t ks8695_wdt_write(struct file *file, const char *data, size_t len, loff_t *ppos) static ssize_t ks8695_wdt_write(struct file *file, const char *data,
size_t len, loff_t *ppos)
{ {
ks8695_wdt_reload(); /* pat the watchdog */ ks8695_wdt_reload(); /* pat the watchdog */
return len; return len;
...@@ -207,7 +209,7 @@ static ssize_t ks8695_wdt_write(struct file *file, const char *data, size_t len, ...@@ -207,7 +209,7 @@ static ssize_t ks8695_wdt_write(struct file *file, const char *data, size_t len,
static const struct file_operations ks8695wdt_fops = { static const struct file_operations ks8695wdt_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.llseek = no_llseek, .llseek = no_llseek,
.ioctl = ks8695_wdt_ioctl, .unlocked_ioctl = ks8695_wdt_ioctl,
.open = ks8695_wdt_open, .open = ks8695_wdt_open,
.release = ks8695_wdt_close, .release = ks8695_wdt_close,
.write = ks8695_wdt_write, .write = ks8695_wdt_write,
...@@ -231,7 +233,8 @@ static int __init ks8695wdt_probe(struct platform_device *pdev) ...@@ -231,7 +233,8 @@ static int __init ks8695wdt_probe(struct platform_device *pdev)
if (res) if (res)
return res; return res;
printk("KS8695 Watchdog Timer enabled (%d seconds%s)\n", wdt_time, nowayout ? ", nowayout" : ""); printk(KERN_INFO "KS8695 Watchdog Timer enabled (%d seconds%s)\n",
wdt_time, nowayout ? ", nowayout" : "");
return 0; return 0;
} }
...@@ -285,12 +288,14 @@ static struct platform_driver ks8695wdt_driver = { ...@@ -285,12 +288,14 @@ static struct platform_driver ks8695wdt_driver = {
static int __init ks8695_wdt_init(void) static int __init ks8695_wdt_init(void)
{ {
/* Check that the heartbeat value is within range; if not reset to the default */ spin_lock_init(&ks8695_lock);
/* Check that the heartbeat value is within range;
if not reset to the default */
if (ks8695_wdt_settimeout(wdt_time)) { if (ks8695_wdt_settimeout(wdt_time)) {
ks8695_wdt_settimeout(WDT_DEFAULT_TIME); ks8695_wdt_settimeout(WDT_DEFAULT_TIME);
pr_info("ks8695_wdt: wdt_time value must be 1 <= wdt_time <= %i, using %d\n", wdt_time, WDT_MAX_TIME); pr_info("ks8695_wdt: wdt_time value must be 1 <= wdt_time <= %i, using %d\n",
wdt_time, WDT_MAX_TIME);
} }
return platform_driver_register(&ks8695wdt_driver); return platform_driver_register(&ks8695wdt_driver);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment