1 --- a/drivers/cbus/retu-wdt.c
2 +++ b/drivers/cbus/retu-wdt.c
5 * Written by Amit Kucheria <amit.kucheria@nokia.com>
7 + * Cleanups by Michael Buesch <mb@bu3sch.de> (C) 2011
9 * This file is subject to the terms and conditions of the GNU General
10 * Public License. See the file "COPYING" in the main directory of this
11 * archive for more details.
13 #define RETU_WDT_DEFAULT_TIMER 32
14 #define RETU_WDT_MAX_TIMER 63
16 -static DEFINE_MUTEX(retu_wdt_mutex);
18 -/* Current period of watchdog */
19 -static unsigned int period_val = RETU_WDT_DEFAULT_TIMER;
23 + unsigned int period_val; /* Current period of watchdog */
25 - struct miscdevice retu_wdt_miscdev;
26 + struct miscdevice miscdev;
27 struct delayed_work ping_work;
31 -static struct retu_wdt_dev *retu_wdt;
33 -static int _retu_modify_counter(unsigned int new)
34 +static inline void _retu_modify_counter(struct retu_wdt_dev *wdev,
38 - retu_write_reg(retu_wdt->dev, RETU_REG_WATCHDOG, (u16)new);
41 + retu_write_reg(wdev->dev, RETU_REG_WATCHDOG, (u16)new);
44 -static int retu_modify_counter(unsigned int new)
45 +static int retu_modify_counter(struct retu_wdt_dev *wdev, unsigned int new)
47 if (new < RETU_WDT_MIN_TIMER || new > RETU_WDT_MAX_TIMER)
50 - mutex_lock(&retu_wdt_mutex);
52 - _retu_modify_counter(period_val);
53 - mutex_unlock(&retu_wdt_mutex);
54 + mutex_lock(&wdev->mutex);
55 + wdev->period_val = new;
56 + _retu_modify_counter(wdev, wdev->period_val);
57 + mutex_unlock(&wdev->mutex);
61 @@ -90,14 +86,14 @@ static int retu_modify_counter(unsigned
63 static void retu_wdt_ping_enable(struct retu_wdt_dev *wdev)
65 - _retu_modify_counter(RETU_WDT_MAX_TIMER);
66 + _retu_modify_counter(wdev, RETU_WDT_MAX_TIMER);
67 schedule_delayed_work(&wdev->ping_work,
68 round_jiffies_relative(RETU_WDT_DEFAULT_TIMER * HZ));
71 static void retu_wdt_ping_disable(struct retu_wdt_dev *wdev)
73 - _retu_modify_counter(RETU_WDT_MAX_TIMER);
74 + _retu_modify_counter(wdev, RETU_WDT_MAX_TIMER);
75 cancel_delayed_work_sync(&wdev->ping_work);
78 @@ -110,18 +106,21 @@ static void retu_wdt_ping_work(struct wo
80 static int retu_wdt_open(struct inode *inode, struct file *file)
82 - if (test_and_set_bit(0, &retu_wdt->users))
83 + struct miscdevice *mdev = file->private_data;
84 + struct retu_wdt_dev *wdev = container_of(mdev, struct retu_wdt_dev, miscdev);
86 + if (test_and_set_bit(0, &wdev->users))
89 - file->private_data = (void *)retu_wdt;
90 - retu_wdt_ping_disable(retu_wdt);
91 + retu_wdt_ping_disable(wdev);
93 return nonseekable_open(inode, file);
96 static int retu_wdt_release(struct inode *inode, struct file *file)
98 - struct retu_wdt_dev *wdev = file->private_data;
99 + struct miscdevice *mdev = file->private_data;
100 + struct retu_wdt_dev *wdev = container_of(mdev, struct retu_wdt_dev, miscdev);
102 #ifndef CONFIG_WATCHDOG_NOWAYOUT
103 retu_wdt_ping_enable(wdev);
104 @@ -134,8 +133,11 @@ static int retu_wdt_release(struct inode
105 static ssize_t retu_wdt_write(struct file *file, const char __user *data,
106 size_t len, loff_t *ppos)
108 + struct miscdevice *mdev = file->private_data;
109 + struct retu_wdt_dev *wdev = container_of(mdev, struct retu_wdt_dev, miscdev);
112 - retu_modify_counter(RETU_WDT_MAX_TIMER);
113 + retu_modify_counter(wdev, RETU_WDT_MAX_TIMER);
117 @@ -143,6 +145,8 @@ static ssize_t retu_wdt_write(struct fil
118 static long retu_wdt_ioctl(struct file *file, unsigned int cmd,
121 + struct miscdevice *mdev = file->private_data;
122 + struct retu_wdt_dev *wdev = container_of(mdev, struct retu_wdt_dev, miscdev);
125 static struct watchdog_info ident = {
126 @@ -167,15 +171,15 @@ static long retu_wdt_ioctl(struct file *
127 return put_user(omap_prcm_get_reset_sources(),
129 case WDIOC_KEEPALIVE:
130 - retu_modify_counter(RETU_WDT_MAX_TIMER);
131 + retu_modify_counter(wdev, RETU_WDT_MAX_TIMER);
133 case WDIOC_SETTIMEOUT:
134 if (get_user(new_margin, (int __user *)arg))
136 - retu_modify_counter(new_margin);
137 + retu_modify_counter(wdev, new_margin);
139 case WDIOC_GETTIMEOUT:
140 - return put_user(period_val, (int __user *)arg);
141 + return put_user(wdev->period_val, (int __user *)arg);
145 @@ -199,15 +203,17 @@ static int __init retu_wdt_probe(struct
148 wdev->dev = &pdev->dev;
149 + wdev->period_val = RETU_WDT_DEFAULT_TIMER;
150 + mutex_init(&wdev->mutex);
152 platform_set_drvdata(pdev, wdev);
154 - wdev->retu_wdt_miscdev.parent = &pdev->dev;
155 - wdev->retu_wdt_miscdev.minor = WATCHDOG_MINOR;
156 - wdev->retu_wdt_miscdev.name = "watchdog";
157 - wdev->retu_wdt_miscdev.fops = &retu_wdt_fops;
159 - ret = misc_register(&(wdev->retu_wdt_miscdev));
160 + wdev->miscdev.parent = &pdev->dev;
161 + wdev->miscdev.minor = WATCHDOG_MINOR;
162 + wdev->miscdev.name = "watchdog";
163 + wdev->miscdev.fops = &retu_wdt_fops;
165 + ret = misc_register(&wdev->miscdev);
169 @@ -216,9 +222,9 @@ static int __init retu_wdt_probe(struct
170 /* Kick the watchdog for kernel booting to finish.
171 * If nowayout is not set, we start the ping work. */
172 #ifdef CONFIG_WATCHDOG_NOWAYOUT
173 - retu_modify_counter(RETU_WDT_MAX_TIMER);
174 + retu_modify_counter(wdev, RETU_WDT_MAX_TIMER);
176 - retu_wdt_ping_enable(retu_wdt);
177 + retu_wdt_ping_enable(wdev);
181 @@ -234,7 +240,7 @@ static int __devexit retu_wdt_remove(str
182 struct retu_wdt_dev *wdev;
184 wdev = platform_get_drvdata(pdev);
185 - misc_deregister(&wdev->retu_wdt_miscdev);
186 + misc_deregister(&wdev->miscdev);
187 cancel_delayed_work_sync(&wdev->ping_work);