kernel: update kernel from 2.6.38.2 to 2.6.38.6 and refresh patches
[lede.git] / target / linux / omap24xx / patches-2.6.38 / 540-cbus-retu-wdt-remove-static-variables.patch
1 --- a/drivers/cbus/retu-wdt.c
2 +++ b/drivers/cbus/retu-wdt.c
3 @@ -7,6 +7,8 @@
4   *
5   * Written by Amit Kucheria <amit.kucheria@nokia.com>
6   *
7 + * Cleanups by Michael Buesch <mb@bu3sch.de> (C) 2011
8 + *
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.
12 @@ -48,37 +50,31 @@
13  #define RETU_WDT_DEFAULT_TIMER 32
14  #define RETU_WDT_MAX_TIMER 63
15  
16 -static DEFINE_MUTEX(retu_wdt_mutex);
17 -
18 -/* Current period of watchdog */
19 -static unsigned int period_val = RETU_WDT_DEFAULT_TIMER;
20 -
21  struct retu_wdt_dev {
22         struct device           *dev;
23 +       unsigned int            period_val;     /* Current period of watchdog */
24         unsigned long           users;
25 -       struct miscdevice       retu_wdt_miscdev;
26 +       struct miscdevice       miscdev;
27         struct delayed_work     ping_work;
28 +       struct mutex            mutex;
29  };
30  
31 -static struct retu_wdt_dev *retu_wdt;
32  
33 -static int _retu_modify_counter(unsigned int new)
34 +static inline void _retu_modify_counter(struct retu_wdt_dev *wdev,
35 +                                       unsigned int new)
36  {
37 -       if (retu_wdt)
38 -               retu_write_reg(retu_wdt->dev, RETU_REG_WATCHDOG, (u16)new);
39 -
40 -       return 0;
41 +       retu_write_reg(wdev->dev, RETU_REG_WATCHDOG, (u16)new);
42  }
43  
44 -static int retu_modify_counter(unsigned int new)
45 +static int retu_modify_counter(struct retu_wdt_dev *wdev, unsigned int new)
46  {
47         if (new < RETU_WDT_MIN_TIMER || new > RETU_WDT_MAX_TIMER)
48                 return -EINVAL;
49  
50 -       mutex_lock(&retu_wdt_mutex);
51 -       period_val = new;
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);
58  
59         return 0;
60  }
61 @@ -90,14 +86,14 @@ static int retu_modify_counter(unsigned
62   */
63  static void retu_wdt_ping_enable(struct retu_wdt_dev *wdev)
64  {
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));
69  }
70  
71  static void retu_wdt_ping_disable(struct retu_wdt_dev *wdev)
72  {
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);
76  }
77  
78 @@ -110,18 +106,21 @@ static void retu_wdt_ping_work(struct wo
79  
80  static int retu_wdt_open(struct inode *inode, struct file *file)
81  {
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);
85 +
86 +       if (test_and_set_bit(0, &wdev->users))
87                 return -EBUSY;
88  
89 -       file->private_data = (void *)retu_wdt;
90 -       retu_wdt_ping_disable(retu_wdt);
91 +       retu_wdt_ping_disable(wdev);
92  
93         return nonseekable_open(inode, file);
94  }
95  
96  static int retu_wdt_release(struct inode *inode, struct file *file)
97  {
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);
101  
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)
107  {
108 +       struct miscdevice *mdev = file->private_data;
109 +       struct retu_wdt_dev *wdev = container_of(mdev, struct retu_wdt_dev, miscdev);
110 +
111         if (len)
112 -               retu_modify_counter(RETU_WDT_MAX_TIMER);
113 +               retu_modify_counter(wdev, RETU_WDT_MAX_TIMER);
114  
115         return len;
116  }
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,
119                            unsigned long arg)
120  {
121 +       struct miscdevice *mdev = file->private_data;
122 +       struct retu_wdt_dev *wdev = container_of(mdev, struct retu_wdt_dev, miscdev);
123         int new_margin;
124  
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(),
128                                         (int __user *)arg);
129         case WDIOC_KEEPALIVE:
130 -               retu_modify_counter(RETU_WDT_MAX_TIMER);
131 +               retu_modify_counter(wdev, RETU_WDT_MAX_TIMER);
132                 break;
133         case WDIOC_SETTIMEOUT:
134                 if (get_user(new_margin, (int __user *)arg))
135                         return -EFAULT;
136 -               retu_modify_counter(new_margin);
137 +               retu_modify_counter(wdev, new_margin);
138                 /* Fall through */
139         case WDIOC_GETTIMEOUT:
140 -               return put_user(period_val, (int __user *)arg);
141 +               return put_user(wdev->period_val, (int __user *)arg);
142         }
143  
144         return 0;
145 @@ -199,15 +203,17 @@ static int __init retu_wdt_probe(struct
146                 return -ENOMEM;
147  
148         wdev->dev = &pdev->dev;
149 +       wdev->period_val = RETU_WDT_DEFAULT_TIMER;
150 +       mutex_init(&wdev->mutex);
151  
152         platform_set_drvdata(pdev, wdev);
153 -       retu_wdt = 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;
158  
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;
164 +
165 +       ret = misc_register(&wdev->miscdev);
166         if (ret)
167                 goto err_free_wdev;
168  
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);
175  #else
176 -       retu_wdt_ping_enable(retu_wdt);
177 +       retu_wdt_ping_enable(wdev);
178  #endif
179  
180         return 0;
181 @@ -234,7 +240,7 @@ static int __devexit retu_wdt_remove(str
182         struct retu_wdt_dev *wdev;
183  
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);
188         kfree(wdev);
189