14d31112e7898b24c372bc5ed3da6cb9d01b6582
[openwrt.git] / target / linux / omap24xx / patches-2.6.38 / 540-cbus-retu-wdt-remove-static-variables.patch
1 Index: linux-2.6.38-rc6/drivers/cbus/retu-wdt.c
2 ===================================================================
3 --- linux-2.6.38-rc6.orig/drivers/cbus/retu-wdt.c 2011-03-04 16:22:03.524019824 +0100
4 +++ linux-2.6.38-rc6/drivers/cbus/retu-wdt.c 2011-03-04 16:22:31.186357952 +0100
5 @@ -7,6 +7,8 @@
6 *
7 * Written by Amit Kucheria <amit.kucheria@nokia.com>
8 *
9 + * Cleanups by Michael Buesch <mb@bu3sch.de> (C) 2011
10 + *
11 * This file is subject to the terms and conditions of the GNU General
12 * Public License. See the file "COPYING" in the main directory of this
13 * archive for more details.
14 @@ -48,37 +50,31 @@
15 #define RETU_WDT_DEFAULT_TIMER 32
16 #define RETU_WDT_MAX_TIMER 63
17
18 -static DEFINE_MUTEX(retu_wdt_mutex);
19 -
20 -/* Current period of watchdog */
21 -static unsigned int period_val = RETU_WDT_DEFAULT_TIMER;
22 -
23 struct retu_wdt_dev {
24 struct device *dev;
25 + unsigned int period_val; /* Current period of watchdog */
26 unsigned long users;
27 - struct miscdevice retu_wdt_miscdev;
28 + struct miscdevice miscdev;
29 struct delayed_work ping_work;
30 + struct mutex mutex;
31 };
32
33 -static struct retu_wdt_dev *retu_wdt;
34
35 -static int _retu_modify_counter(unsigned int new)
36 +static inline void _retu_modify_counter(struct retu_wdt_dev *wdev,
37 + unsigned int new)
38 {
39 - if (retu_wdt)
40 - retu_write_reg(retu_wdt->dev, RETU_REG_WATCHDOG, (u16)new);
41 -
42 - return 0;
43 + retu_write_reg(wdev->dev, RETU_REG_WATCHDOG, (u16)new);
44 }
45
46 -static int retu_modify_counter(unsigned int new)
47 +static int retu_modify_counter(struct retu_wdt_dev *wdev, unsigned int new)
48 {
49 if (new < RETU_WDT_MIN_TIMER || new > RETU_WDT_MAX_TIMER)
50 return -EINVAL;
51
52 - mutex_lock(&retu_wdt_mutex);
53 - period_val = new;
54 - _retu_modify_counter(period_val);
55 - mutex_unlock(&retu_wdt_mutex);
56 + mutex_lock(&wdev->mutex);
57 + wdev->period_val = new;
58 + _retu_modify_counter(wdev, wdev->period_val);
59 + mutex_unlock(&wdev->mutex);
60
61 return 0;
62 }
63 @@ -90,14 +86,14 @@ static int retu_modify_counter(unsigned
64 */
65 static void retu_wdt_ping_enable(struct retu_wdt_dev *wdev)
66 {
67 - _retu_modify_counter(RETU_WDT_MAX_TIMER);
68 + _retu_modify_counter(wdev, RETU_WDT_MAX_TIMER);
69 schedule_delayed_work(&wdev->ping_work,
70 round_jiffies_relative(RETU_WDT_DEFAULT_TIMER * HZ));
71 }
72
73 static void retu_wdt_ping_disable(struct retu_wdt_dev *wdev)
74 {
75 - _retu_modify_counter(RETU_WDT_MAX_TIMER);
76 + _retu_modify_counter(wdev, RETU_WDT_MAX_TIMER);
77 cancel_delayed_work_sync(&wdev->ping_work);
78 }
79
80 @@ -110,18 +106,21 @@ static void retu_wdt_ping_work(struct wo
81
82 static int retu_wdt_open(struct inode *inode, struct file *file)
83 {
84 - if (test_and_set_bit(0, &retu_wdt->users))
85 + struct miscdevice *mdev = file->private_data;
86 + struct retu_wdt_dev *wdev = container_of(mdev, struct retu_wdt_dev, miscdev);
87 +
88 + if (test_and_set_bit(0, &wdev->users))
89 return -EBUSY;
90
91 - file->private_data = (void *)retu_wdt;
92 - retu_wdt_ping_disable(retu_wdt);
93 + retu_wdt_ping_disable(wdev);
94
95 return nonseekable_open(inode, file);
96 }
97
98 static int retu_wdt_release(struct inode *inode, struct file *file)
99 {
100 - struct retu_wdt_dev *wdev = file->private_data;
101 + struct miscdevice *mdev = file->private_data;
102 + struct retu_wdt_dev *wdev = container_of(mdev, struct retu_wdt_dev, miscdev);
103
104 #ifndef CONFIG_WATCHDOG_NOWAYOUT
105 retu_wdt_ping_enable(wdev);
106 @@ -134,8 +133,11 @@ static int retu_wdt_release(struct inode
107 static ssize_t retu_wdt_write(struct file *file, const char __user *data,
108 size_t len, loff_t *ppos)
109 {
110 + struct miscdevice *mdev = file->private_data;
111 + struct retu_wdt_dev *wdev = container_of(mdev, struct retu_wdt_dev, miscdev);
112 +
113 if (len)
114 - retu_modify_counter(RETU_WDT_MAX_TIMER);
115 + retu_modify_counter(wdev, RETU_WDT_MAX_TIMER);
116
117 return len;
118 }
119 @@ -143,6 +145,8 @@ static ssize_t retu_wdt_write(struct fil
120 static long retu_wdt_ioctl(struct file *file, unsigned int cmd,
121 unsigned long arg)
122 {
123 + struct miscdevice *mdev = file->private_data;
124 + struct retu_wdt_dev *wdev = container_of(mdev, struct retu_wdt_dev, miscdev);
125 int new_margin;
126
127 static struct watchdog_info ident = {
128 @@ -167,15 +171,15 @@ static long retu_wdt_ioctl(struct file *
129 return put_user(omap_prcm_get_reset_sources(),
130 (int __user *)arg);
131 case WDIOC_KEEPALIVE:
132 - retu_modify_counter(RETU_WDT_MAX_TIMER);
133 + retu_modify_counter(wdev, RETU_WDT_MAX_TIMER);
134 break;
135 case WDIOC_SETTIMEOUT:
136 if (get_user(new_margin, (int __user *)arg))
137 return -EFAULT;
138 - retu_modify_counter(new_margin);
139 + retu_modify_counter(wdev, new_margin);
140 /* Fall through */
141 case WDIOC_GETTIMEOUT:
142 - return put_user(period_val, (int __user *)arg);
143 + return put_user(wdev->period_val, (int __user *)arg);
144 }
145
146 return 0;
147 @@ -199,15 +203,17 @@ static int __init retu_wdt_probe(struct
148 return -ENOMEM;
149
150 wdev->dev = &pdev->dev;
151 + wdev->period_val = RETU_WDT_DEFAULT_TIMER;
152 + mutex_init(&wdev->mutex);
153
154 platform_set_drvdata(pdev, wdev);
155 - retu_wdt = wdev;
156 - wdev->retu_wdt_miscdev.parent = &pdev->dev;
157 - wdev->retu_wdt_miscdev.minor = WATCHDOG_MINOR;
158 - wdev->retu_wdt_miscdev.name = "watchdog";
159 - wdev->retu_wdt_miscdev.fops = &retu_wdt_fops;
160
161 - ret = misc_register(&(wdev->retu_wdt_miscdev));
162 + wdev->miscdev.parent = &pdev->dev;
163 + wdev->miscdev.minor = WATCHDOG_MINOR;
164 + wdev->miscdev.name = "watchdog";
165 + wdev->miscdev.fops = &retu_wdt_fops;
166 +
167 + ret = misc_register(&wdev->miscdev);
168 if (ret)
169 goto err_free_wdev;
170
171 @@ -216,9 +222,9 @@ static int __init retu_wdt_probe(struct
172 /* Kick the watchdog for kernel booting to finish.
173 * If nowayout is not set, we start the ping work. */
174 #ifdef CONFIG_WATCHDOG_NOWAYOUT
175 - retu_modify_counter(RETU_WDT_MAX_TIMER);
176 + retu_modify_counter(wdev, RETU_WDT_MAX_TIMER);
177 #else
178 - retu_wdt_ping_enable(retu_wdt);
179 + retu_wdt_ping_enable(wdev);
180 #endif
181
182 return 0;
183 @@ -234,7 +240,7 @@ static int __devexit retu_wdt_remove(str
184 struct retu_wdt_dev *wdev;
185
186 wdev = platform_get_drvdata(pdev);
187 - misc_deregister(&wdev->retu_wdt_miscdev);
188 + misc_deregister(&wdev->miscdev);
189 cancel_delayed_work_sync(&wdev->ping_work);
190 kfree(wdev);
191
This page took 0.06073 seconds and 3 git commands to generate.