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