af02f92e25fbe02f22ee59ffda3e238526f178e1
[openwrt/svn-archive/archive.git] / target / linux / ramips / patches-3.10 / 0505-watchdog-add-MT7621-support.patch
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
5
6 Signed-off-by: John Crispin <blogic@openwrt.org>
7 ---
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
13
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 @@
19 config RALINK_WDT
20 tristate "Ralink SoC watchdog"
21 select WATCHDOG_CORE
22 - depends on RALINK
23 + depends on RALINK && !SOC_MT7621
24 + help
25 + Hardware driver for the Ralink SoC Watchdog Timer.
26 +
27 +config MT7621_WDT
28 + tristate "Mediatek SoC watchdog"
29 + select WATCHDOG_CORE
30 + depends on RALINK && SOC_MT7621
31 help
32 Hardware driver for the Ralink SoC Watchdog Timer.
33
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
38 @@ -136,6 +136,7 @@
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
43
44 # PARISC Architecture
45
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
50 @@ -0,0 +1,185 @@
51 +/*
52 + * Ralink RT288x/RT3xxx/MT76xx built-in hardware watchdog timer
53 + *
54 + * Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
55 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
56 + *
57 + * This driver was based on: drivers/watchdog/softdog.c
58 + *
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.
62 + */
63 +
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>
72 +
73 +#include <asm/mach-ralink/ralink_regs.h>
74 +
75 +#define SYSC_RSTSTAT 0x38
76 +#define WDT_RST_CAUSE BIT(1)
77 +
78 +#define RALINK_WDT_TIMEOUT 30
79 +
80 +#define TIMER_REG_TMRSTAT 0x00
81 +#define TIMER_REG_TMR1LOAD 0x24
82 +#define TIMER_REG_TMR1CTL 0x20
83 +
84 +#define TMR1CTL_ENABLE BIT(7)
85 +#define TMR1CTL_RESTART BIT(9)
86 +
87 +static void __iomem *mt762x_wdt_base;
88 +
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) ")");
94 +
95 +static inline void rt_wdt_w32(unsigned reg, u32 val)
96 +{
97 + iowrite32(val, mt762x_wdt_base + reg);
98 +}
99 +
100 +static inline u32 rt_wdt_r32(unsigned reg)
101 +{
102 + return ioread32(mt762x_wdt_base + reg);
103 +}
104 +
105 +static int mt762x_wdt_ping(struct watchdog_device *w)
106 +{
107 + rt_wdt_w32(TIMER_REG_TMRSTAT, TMR1CTL_RESTART);
108 +
109 + return 0;
110 +}
111 +
112 +static int mt762x_wdt_set_timeout(struct watchdog_device *w, unsigned int t)
113 +{
114 + w->timeout = t;
115 + rt_wdt_w32(TIMER_REG_TMR1LOAD, t * 1000);
116 + mt762x_wdt_ping(w);
117 +
118 + return 0;
119 +}
120 +
121 +static int mt762x_wdt_start(struct watchdog_device *w)
122 +{
123 + u32 t;
124 +
125 + rt_wdt_w32(TIMER_REG_TMR1CTL, 1000 << 16);
126 + mt762x_wdt_set_timeout(w, w->timeout);
127 +
128 + t = rt_wdt_r32(TIMER_REG_TMR1CTL);
129 + t |= TMR1CTL_ENABLE;
130 + rt_wdt_w32(TIMER_REG_TMR1CTL, t);
131 +
132 + return 0;
133 +}
134 +
135 +static int mt762x_wdt_stop(struct watchdog_device *w)
136 +{
137 + u32 t;
138 +
139 + mt762x_wdt_ping(w);
140 +
141 + t = rt_wdt_r32(TIMER_REG_TMR1CTL);
142 + t &= ~TMR1CTL_ENABLE;
143 + rt_wdt_w32(TIMER_REG_TMR1CTL, t);
144 +
145 + return 0;
146 +}
147 +
148 +static int mt762x_wdt_bootcause(void)
149 +{
150 + if (rt_sysc_r32(SYSC_RSTSTAT) & WDT_RST_CAUSE)
151 + return WDIOF_CARDRESET;
152 +
153 + return 0;
154 +}
155 +
156 +static struct watchdog_info mt762x_wdt_info = {
157 + .identity = "Mediatek Watchdog",
158 + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
159 +};
160 +
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,
167 +};
168 +
169 +static struct watchdog_device mt762x_wdt_dev = {
170 + .info = &mt762x_wdt_info,
171 + .ops = &mt762x_wdt_ops,
172 + .min_timeout = 1,
173 +};
174 +
175 +static int mt762x_wdt_probe(struct platform_device *pdev)
176 +{
177 + struct resource *res;
178 + int ret;
179 +
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);
184 +
185 + device_reset(&pdev->dev);
186 +
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;
191 +
192 + watchdog_set_nowayout(&mt762x_wdt_dev, nowayout);
193 +
194 + ret = watchdog_register_device(&mt762x_wdt_dev);
195 + if (!ret)
196 + dev_info(&pdev->dev, "Initialized\n");
197 +
198 + return 0;
199 +}
200 +
201 +static int mt762x_wdt_remove(struct platform_device *pdev)
202 +{
203 + watchdog_unregister_device(&mt762x_wdt_dev);
204 +
205 + return 0;
206 +}
207 +
208 +static void mt762x_wdt_shutdown(struct platform_device *pdev)
209 +{
210 + mt762x_wdt_stop(&mt762x_wdt_dev);
211 +}
212 +
213 +static const struct of_device_id mt762x_wdt_match[] = {
214 + { .compatible = "mtk,mt7621-wdt" },
215 + {},
216 +};
217 +MODULE_DEVICE_TABLE(of, mt762x_wdt_match);
218 +
219 +static struct platform_driver mt762x_wdt_driver = {
220 + .probe = mt762x_wdt_probe,
221 + .remove = mt762x_wdt_remove,
222 + .shutdown = mt762x_wdt_shutdown,
223 + .driver = {
224 + .name = KBUILD_MODNAME,
225 + .owner = THIS_MODULE,
226 + .of_match_table = mt762x_wdt_match,
227 + },
228 +};
229 +
230 +module_platform_driver(mt762x_wdt_driver);
231 +
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);