510d4e12778c24fd8dc2a639cde6dc124a3bcaa8
[openwrt.git] / target / linux / lantiq / patches / 250-watchdog.patch
1 --- a/drivers/watchdog/Kconfig
2 +++ b/drivers/watchdog/Kconfig
3 @@ -930,6 +930,12 @@
4 To compile this driver as a loadable module, choose M here.
5 The module will be called bcm63xx_wdt.
6
7 +config LANTIQ_WDT
8 + bool "Lantiq SoC watchdog"
9 + depends on LANTIQ
10 + help
11 + Hardware driver for the Lantiq SoC Watchdog Timer.
12 +
13 # PARISC Architecture
14
15 # POWERPC Architecture
16 --- a/drivers/watchdog/Makefile
17 +++ b/drivers/watchdog/Makefile
18 @@ -119,6 +119,7 @@
19 obj-$(CONFIG_TXX9_WDT) += txx9wdt.o
20 obj-$(CONFIG_OCTEON_WDT) += octeon-wdt.o
21 octeon-wdt-y := octeon-wdt-main.o octeon-wdt-nmi.o
22 +obj-$(CONFIG_LANTIQ_WDT) += lantiq_wdt.o
23
24 # PARISC Architecture
25
26 --- /dev/null
27 +++ b/drivers/watchdog/lantiq_wdt.c
28 @@ -0,0 +1,218 @@
29 +/*
30 + * This program is free software; you can redistribute it and/or modify it
31 + * under the terms of the GNU General Public License version 2 as published
32 + * by the Free Software Foundation.
33 + *
34 + * Copyright (C) 2010 John Crispin <blogic@openwrt.org>
35 + * Based on EP93xx wdt driver
36 + */
37 +
38 +#include <linux/module.h>
39 +#include <linux/fs.h>
40 +#include <linux/miscdevice.h>
41 +#include <linux/miscdevice.h>
42 +#include <linux/watchdog.h>
43 +#include <linux/platform_device.h>
44 +#include <linux/uaccess.h>
45 +#include <linux/clk.h>
46 +
47 +#include <lantiq.h>
48 +
49 +#define LQ_WDT_PW1 0x00BE0000
50 +#define LQ_WDT_PW2 0x00DC0000
51 +
52 +#define LQ_BIU_WDT_CR 0x3F0
53 +#define LQ_BIU_WDT_SR 0x3F8
54 +
55 +#ifndef CONFIG_WATCHDOG_NOWAYOUT
56 +static int wdt_ok_to_close;
57 +#endif
58 +
59 +static int wdt_timeout = 30;
60 +static __iomem void *wdt_membase = NULL;
61 +static unsigned long io_region_clk = 0;
62 +
63 +static int
64 +lq_wdt_enable(unsigned int timeout)
65 +{
66 +/* printk("%s:%s[%d] %08X\n",
67 + __FILE__, __func__, __LINE__,
68 + lq_r32(wdt_membase + LQ_BIU_WDT_SR));
69 + if(!lq_r32(wdt_membase + LQ_BIU_WDT_SR))
70 + {
71 +*/ lq_w32(LQ_WDT_PW1, wdt_membase + LQ_BIU_WDT_CR);
72 + lq_w32(LQ_WDT_PW2 |
73 + (0x3 << 26) | /* PWL */
74 + (0x3 << 24) | /* CLKDIV */
75 + (0x1 << 31) | /* enable */
76 + ((timeout * (io_region_clk / 0x40000)) + 0x1000), /* reload */
77 + wdt_membase + LQ_BIU_WDT_CR);
78 +// }
79 + return 0;
80 +}
81 +
82 +static void
83 +lq_wdt_disable(void)
84 +{
85 +#ifndef CONFIG_WATCHDOG_NOWAYOUT
86 + wdt_ok_to_close = 0;
87 +#endif
88 + lq_w32(LQ_WDT_PW1, wdt_membase + LQ_BIU_WDT_CR);
89 + lq_w32(LQ_WDT_PW2, wdt_membase+ LQ_BIU_WDT_CR);
90 +}
91 +
92 +static ssize_t
93 +lq_wdt_write(struct file *file, const char __user *data,
94 + size_t len, loff_t *ppos)
95 +{
96 + size_t i;
97 +
98 + if (!len)
99 + return 0;
100 +
101 +#ifndef CONFIG_WATCHDOG_NOWAYOUT
102 + for (i = 0; i != len; i++) {
103 + char c;
104 + if (get_user(c, data + i))
105 + return -EFAULT;
106 + if (c == 'V')
107 + wdt_ok_to_close = 1;
108 + }
109 +#endif
110 + lq_wdt_enable(wdt_timeout);
111 + return len;
112 +}
113 +
114 +static struct watchdog_info ident = {
115 + .options = WDIOF_MAGICCLOSE,
116 + .identity = "lq_wdt",
117 +};
118 +
119 +static int
120 +lq_wdt_ioctl(struct file *file,
121 + unsigned int cmd, unsigned long arg)
122 +{
123 + int ret = -ENOTTY;
124 +
125 + switch (cmd) {
126 + case WDIOC_GETSUPPORT:
127 + ret = copy_to_user((struct watchdog_info __user *)arg, &ident,
128 + sizeof(ident)) ? -EFAULT : 0;
129 + break;
130 +
131 + case WDIOC_GETTIMEOUT:
132 + ret = put_user(wdt_timeout, (int __user *)arg);
133 + break;
134 +
135 + case WDIOC_SETTIMEOUT:
136 + ret = get_user(wdt_timeout, (int __user *)arg);
137 + break;
138 +
139 + case WDIOC_KEEPALIVE:
140 + lq_wdt_enable(wdt_timeout);
141 + ret = 0;
142 + break;
143 + }
144 + return ret;
145 +}
146 +
147 +static int
148 +lq_wdt_open(struct inode *inode, struct file *file)
149 +{
150 + lq_wdt_enable(wdt_timeout);
151 + return nonseekable_open(inode, file);
152 +}
153 +
154 +static int
155 +lq_wdt_release(struct inode *inode, struct file *file)
156 +{
157 +#ifndef CONFIG_WATCHDOG_NOWAYOUT
158 + if (wdt_ok_to_close)
159 + lq_wdt_disable();
160 + else
161 +#endif
162 + printk(KERN_ERR "lq_wdt: watchdog closed without warning,"
163 + " rebooting system\n");
164 + return 0;
165 +}
166 +
167 +static const struct file_operations lq_wdt_fops = {
168 + .owner = THIS_MODULE,
169 + .write = lq_wdt_write,
170 + .unlocked_ioctl = lq_wdt_ioctl,
171 + .open = lq_wdt_open,
172 + .release = lq_wdt_release,
173 +};
174 +
175 +static struct miscdevice lq_wdt_miscdev = {
176 + .minor = WATCHDOG_MINOR,
177 + .name = "watchdog",
178 + .fops = &lq_wdt_fops,
179 +};
180 +
181 +static int
182 +lq_wdt_probe(struct platform_device *pdev)
183 +{
184 + struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
185 + struct clk *clk;
186 + int ret = 0;
187 + if(!res)
188 + return -ENOENT;
189 + res = request_mem_region(res->start, resource_size(res),
190 + dev_name(&pdev->dev));
191 + if(!res)
192 + return -EBUSY;
193 + wdt_membase = ioremap_nocache(res->start, resource_size(res));
194 + if(!wdt_membase)
195 + {
196 + ret = -ENOMEM;
197 + goto err_release_mem_region;
198 + }
199 + clk = clk_get(&pdev->dev, "io");
200 + io_region_clk = clk_get_rate(clk);;
201 + ret = misc_register(&lq_wdt_miscdev);
202 + if(!ret)
203 + return 0;
204 +
205 + iounmap(wdt_membase);
206 +err_release_mem_region:
207 + release_mem_region(res->start, resource_size(res));
208 + return ret;
209 +}
210 +
211 +static int
212 +lq_wdt_remove(struct platform_device *dev)
213 +{
214 + lq_wdt_disable();
215 + misc_deregister(&lq_wdt_miscdev);
216 + return 0;
217 +}
218 +
219 +static struct platform_driver lq_wdt_driver = {
220 + .probe = lq_wdt_probe,
221 + .remove = lq_wdt_remove,
222 + .driver = {
223 + .name = "lq_wdt",
224 + .owner = THIS_MODULE,
225 + },
226 +};
227 +
228 +static int __init
229 +init_lq_wdt(void)
230 +{
231 + return platform_driver_register(&lq_wdt_driver);
232 +}
233 +
234 +static void __exit
235 +exit_lq_wdt(void)
236 +{
237 + platform_driver_unregister(&lq_wdt_driver);
238 +}
239 +
240 +module_init(init_lq_wdt);
241 +module_exit(exit_lq_wdt);
242 +
243 +MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
244 +MODULE_DESCRIPTION("ifxmips Watchdog");
245 +MODULE_LICENSE("GPL");
246 +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
This page took 0.059184 seconds and 3 git commands to generate.