1 From eb50d97682d78af68388d24956a74de4ab751cf7 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Mon, 2 Dec 2013 16:18:36 +0100
4 Subject: [PATCH 505/507] watchdog: add MT7621 support
6 Signed-off-by: John Crispin <blogic@openwrt.org>
8 drivers/watchdog/Kconfig | 7 ++
9 drivers/watchdog/Makefile | 1 +
10 drivers/watchdog/mt7621_wdt.c | 185 +++++++++++++++++++++++++++++++++++++++++
11 3 files changed, 193 insertions(+)
12 create mode 100644 drivers/watchdog/mt7621_wdt.c
14 Index: linux-3.10.21/drivers/watchdog/Kconfig
15 ===================================================================
16 --- linux-3.10.21.orig/drivers/watchdog/Kconfig 2013-12-09 19:56:09.360682007 +0100
17 +++ linux-3.10.21/drivers/watchdog/Kconfig 2013-12-09 19:59:20.636686594 +0100
18 @@ -1116,7 +1116,14 @@
20 tristate "Ralink SoC watchdog"
23 + depends on RALINK && !SOC_MT7621
25 + Hardware driver for the Ralink SoC Watchdog Timer.
28 + tristate "Mediatek SoC watchdog"
29 + select WATCHDOG_CORE
30 + depends on RALINK && SOC_MT7621
32 Hardware driver for the Ralink SoC Watchdog Timer.
34 Index: linux-3.10.21/drivers/watchdog/Makefile
35 ===================================================================
36 --- linux-3.10.21.orig/drivers/watchdog/Makefile 2013-12-09 19:56:09.360682007 +0100
37 +++ linux-3.10.21/drivers/watchdog/Makefile 2013-12-09 19:56:09.752682016 +0100
39 octeon-wdt-y := octeon-wdt-main.o octeon-wdt-nmi.o
40 obj-$(CONFIG_LANTIQ_WDT) += lantiq_wdt.o
41 obj-$(CONFIG_RALINK_WDT) += rt2880_wdt.o
42 +obj-$(CONFIG_MT7621_WDT) += mt7621_wdt.o
46 Index: linux-3.10.21/drivers/watchdog/mt7621_wdt.c
47 ===================================================================
48 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
49 +++ linux-3.10.21/drivers/watchdog/mt7621_wdt.c 2013-12-09 19:56:09.752682016 +0100
52 + * Ralink RT288x/RT3xxx/MT76xx built-in hardware watchdog timer
54 + * Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
55 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
57 + * This driver was based on: drivers/watchdog/softdog.c
59 + * This program is free software; you can redistribute it and/or modify it
60 + * under the terms of the GNU General Public License version 2 as published
61 + * by the Free Software Foundation.
64 +#include <linux/clk.h>
65 +#include <linux/reset.h>
66 +#include <linux/module.h>
67 +#include <linux/kernel.h>
68 +#include <linux/watchdog.h>
69 +#include <linux/miscdevice.h>
70 +#include <linux/moduleparam.h>
71 +#include <linux/platform_device.h>
73 +#include <asm/mach-ralink/ralink_regs.h>
75 +#define SYSC_RSTSTAT 0x38
76 +#define WDT_RST_CAUSE BIT(1)
78 +#define RALINK_WDT_TIMEOUT 30
80 +#define TIMER_REG_TMRSTAT 0x00
81 +#define TIMER_REG_TMR1LOAD 0x24
82 +#define TIMER_REG_TMR1CTL 0x20
84 +#define TMR1CTL_ENABLE BIT(7)
85 +#define TMR1CTL_RESTART BIT(9)
87 +static void __iomem *mt762x_wdt_base;
89 +static bool nowayout = WATCHDOG_NOWAYOUT;
90 +module_param(nowayout, bool, 0);
91 +MODULE_PARM_DESC(nowayout,
92 + "Watchdog cannot be stopped once started (default="
93 + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
95 +static inline void rt_wdt_w32(unsigned reg, u32 val)
97 + iowrite32(val, mt762x_wdt_base + reg);
100 +static inline u32 rt_wdt_r32(unsigned reg)
102 + return ioread32(mt762x_wdt_base + reg);
105 +static int mt762x_wdt_ping(struct watchdog_device *w)
107 + rt_wdt_w32(TIMER_REG_TMRSTAT, TMR1CTL_RESTART);
112 +static int mt762x_wdt_set_timeout(struct watchdog_device *w, unsigned int t)
115 + rt_wdt_w32(TIMER_REG_TMR1LOAD, t * 1000);
116 + mt762x_wdt_ping(w);
121 +static int mt762x_wdt_start(struct watchdog_device *w)
125 + rt_wdt_w32(TIMER_REG_TMR1CTL, 1000 << 16);
126 + mt762x_wdt_set_timeout(w, w->timeout);
128 + t = rt_wdt_r32(TIMER_REG_TMR1CTL);
129 + t |= TMR1CTL_ENABLE;
130 + rt_wdt_w32(TIMER_REG_TMR1CTL, t);
135 +static int mt762x_wdt_stop(struct watchdog_device *w)
139 + mt762x_wdt_ping(w);
141 + t = rt_wdt_r32(TIMER_REG_TMR1CTL);
142 + t &= ~TMR1CTL_ENABLE;
143 + rt_wdt_w32(TIMER_REG_TMR1CTL, t);
148 +static int mt762x_wdt_bootcause(void)
150 + if (rt_sysc_r32(SYSC_RSTSTAT) & WDT_RST_CAUSE)
151 + return WDIOF_CARDRESET;
156 +static struct watchdog_info mt762x_wdt_info = {
157 + .identity = "Mediatek Watchdog",
158 + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
161 +static struct watchdog_ops mt762x_wdt_ops = {
162 + .owner = THIS_MODULE,
163 + .start = mt762x_wdt_start,
164 + .stop = mt762x_wdt_stop,
165 + .ping = mt762x_wdt_ping,
166 + .set_timeout = mt762x_wdt_set_timeout,
169 +static struct watchdog_device mt762x_wdt_dev = {
170 + .info = &mt762x_wdt_info,
171 + .ops = &mt762x_wdt_ops,
175 +static int mt762x_wdt_probe(struct platform_device *pdev)
177 + struct resource *res;
180 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
181 + mt762x_wdt_base = devm_request_and_ioremap(&pdev->dev, res);
182 + if (IS_ERR(mt762x_wdt_base))
183 + return PTR_ERR(mt762x_wdt_base);
185 + device_reset(&pdev->dev);
187 + mt762x_wdt_dev.dev = &pdev->dev;
188 + mt762x_wdt_dev.bootstatus = mt762x_wdt_bootcause();
189 + mt762x_wdt_dev.max_timeout = (0xfffful / 1000);
190 + mt762x_wdt_dev.timeout = mt762x_wdt_dev.max_timeout;
192 + watchdog_set_nowayout(&mt762x_wdt_dev, nowayout);
194 + ret = watchdog_register_device(&mt762x_wdt_dev);
196 + dev_info(&pdev->dev, "Initialized\n");
201 +static int mt762x_wdt_remove(struct platform_device *pdev)
203 + watchdog_unregister_device(&mt762x_wdt_dev);
208 +static void mt762x_wdt_shutdown(struct platform_device *pdev)
210 + mt762x_wdt_stop(&mt762x_wdt_dev);
213 +static const struct of_device_id mt762x_wdt_match[] = {
214 + { .compatible = "mtk,mt7621-wdt" },
217 +MODULE_DEVICE_TABLE(of, mt762x_wdt_match);
219 +static struct platform_driver mt762x_wdt_driver = {
220 + .probe = mt762x_wdt_probe,
221 + .remove = mt762x_wdt_remove,
222 + .shutdown = mt762x_wdt_shutdown,
224 + .name = KBUILD_MODNAME,
225 + .owner = THIS_MODULE,
226 + .of_match_table = mt762x_wdt_match,
230 +module_platform_driver(mt762x_wdt_driver);
232 +MODULE_DESCRIPTION("MediaTek MT762x hardware watchdog driver");
233 +MODULE_AUTHOR("John Crispin <blogic@openwrt.org");
234 +MODULE_LICENSE("GPL v2");
235 +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);