1 --- a/drivers/watchdog/Kconfig
2 +++ b/drivers/watchdog/Kconfig
3 @@ -840,6 +840,12 @@ config TXX9_WDT
5 Hardware driver for the built-in watchdog timer on TXx9 MIPS SoCs.
8 + bool "Lantiq SoC watchdog"
11 + Hardware driver for the Lantiq SoC Watchdog Timer.
15 # POWERPC Architecture
16 --- a/drivers/watchdog/Makefile
17 +++ b/drivers/watchdog/Makefile
18 @@ -112,6 +112,7 @@ obj-$(CONFIG_PNX833X_WDT) += pnx833x_wdt
19 obj-$(CONFIG_SIBYTE_WDOG) += sb_wdog.o
20 obj-$(CONFIG_AR7_WDT) += ar7_wdt.o
21 obj-$(CONFIG_TXX9_WDT) += txx9wdt.o
22 +obj-$(CONFIG_LANTIQ_WDT) += lantiq_wdt.o
27 +++ b/drivers/watchdog/lantiq_wdt.c
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.
34 + * Copyright (C) 2010 John Crispin <blogic@openwrt.org>
35 + * Based on EP93xx wdt driver
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>
49 +#define LQ_WDT_PW1 0x00BE0000
50 +#define LQ_WDT_PW2 0x00DC0000
52 +#define LQ_BIU_WDT_CR 0x3F0
53 +#define LQ_BIU_WDT_SR 0x3F8
55 +#ifndef CONFIG_WATCHDOG_NOWAYOUT
56 +static int wdt_ok_to_close;
59 +static int wdt_timeout = 30;
60 +static __iomem void *wdt_membase = NULL;
61 +static unsigned long io_region_clk = 0;
64 +lq_wdt_enable(unsigned int timeout)
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))
71 +*/ lq_w32(LQ_WDT_PW1, wdt_membase + LQ_BIU_WDT_CR);
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);
85 +#ifndef CONFIG_WATCHDOG_NOWAYOUT
86 + wdt_ok_to_close = 0;
88 + lq_w32(LQ_WDT_PW1, wdt_membase + LQ_BIU_WDT_CR);
89 + lq_w32(LQ_WDT_PW2, wdt_membase+ LQ_BIU_WDT_CR);
93 +lq_wdt_write(struct file *file, const char __user *data,
94 + size_t len, loff_t *ppos)
101 +#ifndef CONFIG_WATCHDOG_NOWAYOUT
102 + for (i = 0; i != len; i++) {
104 + if (get_user(c, data + i))
107 + wdt_ok_to_close = 1;
110 + lq_wdt_enable(wdt_timeout);
114 +static struct watchdog_info ident = {
115 + .options = WDIOF_MAGICCLOSE,
116 + .identity = "lq_wdt",
120 +lq_wdt_ioctl(struct inode *inode, struct file *file,
121 + unsigned int cmd, unsigned long arg)
126 + case WDIOC_GETSUPPORT:
127 + ret = copy_to_user((struct watchdog_info __user *)arg, &ident,
128 + sizeof(ident)) ? -EFAULT : 0;
131 + case WDIOC_GETTIMEOUT:
132 + ret = put_user(wdt_timeout, (int __user *)arg);
135 + case WDIOC_SETTIMEOUT:
136 + ret = get_user(wdt_timeout, (int __user *)arg);
139 + case WDIOC_KEEPALIVE:
140 + lq_wdt_enable(wdt_timeout);
148 +lq_wdt_open(struct inode *inode, struct file *file)
150 + lq_wdt_enable(wdt_timeout);
151 + return nonseekable_open(inode, file);
155 +lq_wdt_release(struct inode *inode, struct file *file)
157 +#ifndef CONFIG_WATCHDOG_NOWAYOUT
158 + if (wdt_ok_to_close)
162 + printk(KERN_ERR "lq_wdt: watchdog closed without warning,"
163 + " rebooting system\n");
167 +static const struct file_operations lq_wdt_fops = {
168 + .owner = THIS_MODULE,
169 + .write = lq_wdt_write,
170 + .ioctl = lq_wdt_ioctl,
171 + .open = lq_wdt_open,
172 + .release = lq_wdt_release,
175 +static struct miscdevice lq_wdt_miscdev = {
176 + .minor = WATCHDOG_MINOR,
177 + .name = "watchdog",
178 + .fops = &lq_wdt_fops,
182 +lq_wdt_probe(struct platform_device *pdev)
184 + struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
189 + res = request_mem_region(res->start, resource_size(res),
190 + dev_name(&pdev->dev));
193 + wdt_membase = ioremap_nocache(res->start, resource_size(res));
197 + goto err_release_mem_region;
199 + clk = clk_get(&pdev->dev, "io");
200 + io_region_clk = clk_get_rate(clk);;
201 + ret = misc_register(&lq_wdt_miscdev);
205 + iounmap(wdt_membase);
206 +err_release_mem_region:
207 + release_mem_region(res->start, resource_size(res));
212 +lq_wdt_remove(struct platform_device *dev)
215 + misc_deregister(&lq_wdt_miscdev);
219 +static struct platform_driver lq_wdt_driver = {
220 + .probe = lq_wdt_probe,
221 + .remove = lq_wdt_remove,
224 + .owner = THIS_MODULE,
231 + return platform_driver_register(&lq_wdt_driver);
237 + platform_driver_unregister(&lq_wdt_driver);
240 +module_init(init_lq_wdt);
241 +module_exit(exit_lq_wdt);
243 +MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
244 +MODULE_DESCRIPTION("ifxmips Watchdog");
245 +MODULE_LICENSE("GPL");
246 +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);