atheros: indent fixes
[openwrt.git] / target / linux / atheros / patches-3.10 / 130-watchdog.patch
1 --- /dev/null
2 +++ b/drivers/watchdog/ar2315-wtd.c
3 @@ -0,0 +1,197 @@
4 +/*
5 + * This program is free software; you can redistribute it and/or modify
6 + * it under the terms of the GNU General Public License as published by
7 + * the Free Software Foundation; either version 2 of the License, or
8 + * (at your option) any later version.
9 + *
10 + * This program is distributed in the hope that it will be useful,
11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 + * GNU General Public License for more details.
14 + *
15 + * You should have received a copy of the GNU General Public License
16 + * along with this program; if not, write to the Free Software
17 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 + *
19 + * Copyright (C) 2008 John Crispin <blogic@openwrt.org>
20 + * Based on EP93xx and ifxmips wdt driver
21 + */
22 +
23 +#include <linux/interrupt.h>
24 +#include <linux/module.h>
25 +#include <linux/moduleparam.h>
26 +#include <linux/types.h>
27 +#include <linux/miscdevice.h>
28 +#include <linux/watchdog.h>
29 +#include <linux/fs.h>
30 +#include <linux/ioport.h>
31 +#include <linux/notifier.h>
32 +#include <linux/reboot.h>
33 +#include <linux/init.h>
34 +#include <linux/platform_device.h>
35 +#include <linux/io.h>
36 +#include <linux/uaccess.h>
37 +
38 +#include <ar231x_platform.h>
39 +#include <ar2315_regs.h>
40 +#include <ar231x.h>
41 +
42 +#define CLOCK_RATE 40000000
43 +#define HEARTBEAT(x) (x < 1 || x > 90 ? 20 : x)
44 +
45 +static int wdt_timeout = 20;
46 +static int started;
47 +static int in_use;
48 +
49 +static void
50 +ar2315_wdt_enable(void)
51 +{
52 +       ar231x_write_reg(AR2315_WD, wdt_timeout * CLOCK_RATE);
53 +       ar231x_write_reg(AR2315_ISR, 0x80);
54 +}
55 +
56 +static ssize_t
57 +ar2315_wdt_write(struct file *file, const char __user *data, size_t len, loff_t *ppos)
58 +{
59 +       if(len)
60 +               ar2315_wdt_enable();
61 +       return len;
62 +}
63 +
64 +static int
65 +ar2315_wdt_open(struct inode *inode, struct file *file)
66 +{
67 +       if(in_use)
68 +               return -EBUSY;
69 +       ar2315_wdt_enable();
70 +       in_use = started = 1;
71 +       return nonseekable_open(inode, file);
72 +}
73 +
74 +static int
75 +ar2315_wdt_release(struct inode *inode, struct file *file)
76 +{
77 +       in_use = 0;
78 +       return 0;
79 +}
80 +
81 +static irqreturn_t
82 +ar2315_wdt_interrupt(int irq, void *dev)
83 +{
84 +       struct platform_device *pdev = (struct platform_device *)dev;
85 +
86 +       if (started) {
87 +               dev_crit(&pdev->dev, "watchdog expired, rebooting system\n");
88 +               emergency_restart();
89 +       } else {
90 +               ar231x_write_reg(AR2315_WDC, 0);
91 +               ar231x_write_reg(AR2315_WD, 0);
92 +               ar231x_write_reg(AR2315_ISR, 0x80);
93 +       }
94 +       return IRQ_HANDLED;
95 +}
96 +
97 +static struct watchdog_info ident = {
98 +       .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
99 +       .identity = "ar2315 Watchdog",
100 +};
101 +
102 +static long
103 +ar2315_wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
104 +{
105 +       int new_wdt_timeout;
106 +       int ret = -ENOIOCTLCMD;
107 +
108 +       switch (cmd) {
109 +       case WDIOC_GETSUPPORT:
110 +               ret = copy_to_user((void __user *)arg, &ident, sizeof(ident)) ?
111 +                     -EFAULT : 0;
112 +               break;
113 +       case WDIOC_KEEPALIVE:
114 +               ar2315_wdt_enable();
115 +               ret = 0;
116 +               break;
117 +       case WDIOC_SETTIMEOUT:
118 +               ret = get_user(new_wdt_timeout, (int __user *)arg);
119 +               if (ret)
120 +                       break;
121 +               wdt_timeout = HEARTBEAT(new_wdt_timeout);
122 +               ar2315_wdt_enable();
123 +               break;
124 +       case WDIOC_GETTIMEOUT:
125 +               ret = put_user(wdt_timeout, (int __user *)arg);
126 +               break;
127 +       }
128 +       return ret;
129 +}
130 +
131 +static struct file_operations ar2315_wdt_fops = {
132 +       .owner          = THIS_MODULE,
133 +       .llseek         = no_llseek,
134 +       .write          = ar2315_wdt_write,
135 +       .unlocked_ioctl = ar2315_wdt_ioctl,
136 +       .open           = ar2315_wdt_open,
137 +       .release        = ar2315_wdt_release,
138 +};
139 +
140 +static struct miscdevice ar2315_wdt_miscdev = {
141 +       .minor  = WATCHDOG_MINOR,
142 +       .name   = "watchdog",
143 +       .fops   = &ar2315_wdt_fops,
144 +};
145 +
146 +static int
147 +ar2315_wdt_probe(struct platform_device *dev)
148 +{
149 +       int ret = 0;
150 +
151 +       ar2315_wdt_enable();
152 +       ret = request_irq(AR531X_MISC_IRQ_WATCHDOG, ar2315_wdt_interrupt,
153 +                         IRQF_DISABLED, "ar2315_wdt", dev);
154 +       if (ret) {
155 +               dev_err(&dev->dev, "failed to register inetrrupt\n");
156 +               goto out;
157 +       }
158 +
159 +       ret = misc_register(&ar2315_wdt_miscdev);
160 +       if(ret)
161 +               dev_err(&dev->dev, "failed to register miscdev\n");
162 +
163 +out:
164 +       return ret;
165 +}
166 +
167 +static int
168 +ar2315_wdt_remove(struct platform_device *dev)
169 +{
170 +       misc_deregister(&ar2315_wdt_miscdev);
171 +       free_irq(AR531X_MISC_IRQ_WATCHDOG, NULL);
172 +       return 0;
173 +}
174 +
175 +static struct platform_driver ar2315_wdt_driver = {
176 +       .probe = ar2315_wdt_probe,
177 +       .remove = ar2315_wdt_remove,
178 +       .driver = {
179 +               .name = "ar2315_wdt",
180 +               .owner = THIS_MODULE,
181 +       },
182 +};
183 +
184 +static int __init
185 +init_ar2315_wdt(void)
186 +{
187 +       int ret = platform_driver_register(&ar2315_wdt_driver);
188 +       if(ret)
189 +               pr_err("ar2315_wdt: error registering platfom driver!\n");
190 +       return ret;
191 +}
192 +
193 +static void __exit
194 +exit_ar2315_wdt(void)
195 +{
196 +       platform_driver_unregister(&ar2315_wdt_driver);
197 +}
198 +
199 +module_init(init_ar2315_wdt);
200 +module_exit(exit_ar2315_wdt);
201 --- a/drivers/watchdog/Kconfig
202 +++ b/drivers/watchdog/Kconfig
203 @@ -1113,6 +1113,12 @@ config LANTIQ_WDT
204         help
205           Hardware driver for the Lantiq SoC Watchdog Timer.
206  
207 +config ATHEROS_WDT
208 +       tristate "Atheros wisoc Watchdog Timer"
209 +       depends on ATHEROS_AR231X
210 +       help
211 +         Hardware driver for the Atheros wisoc Watchdog Timer.
212 +
213  # PARISC Architecture
214  
215  # POWERPC Architecture
216 --- a/drivers/watchdog/Makefile
217 +++ b/drivers/watchdog/Makefile
218 @@ -131,6 +131,7 @@ obj-$(CONFIG_GPIO_WDT) += gpio_wdt.o
219  obj-$(CONFIG_PNX833X_WDT) += pnx833x_wdt.o
220  obj-$(CONFIG_SIBYTE_WDOG) += sb_wdog.o
221  obj-$(CONFIG_AR7_WDT) += ar7_wdt.o
222 +obj-$(CONFIG_ATHEROS_WDT) += ar2315-wtd.o
223  obj-$(CONFIG_TXX9_WDT) += txx9wdt.o
224  obj-$(CONFIG_OCTEON_WDT) += octeon-wdt.o
225  octeon-wdt-y := octeon-wdt-main.o octeon-wdt-nmi.o