blob: 15321aa0bb940ce517b44be45c7604d15fb3718e [file] [log] [blame]
Sylver Bruneau22ac9232008-06-26 10:47:45 +02001/*
Nicolas Pitre3b937a7db2009-06-01 13:56:02 -04002 * drivers/watchdog/orion_wdt.c
Sylver Bruneau22ac9232008-06-26 10:47:45 +02003 *
Nicolas Pitre3b937a7db2009-06-01 13:56:02 -04004 * Watchdog driver for Orion/Kirkwood processors
Sylver Bruneau22ac9232008-06-26 10:47:45 +02005 *
6 * Author: Sylver Bruneau <sylver.bruneau@googlemail.com>
7 *
8 * This file is licensed under the terms of the GNU General Public
9 * License version 2. This program is licensed "as is" without any
10 * warranty of any kind, whether express or implied.
11 */
12
Joe Perches27c766a2012-02-15 15:06:19 -080013#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14
Sylver Bruneau22ac9232008-06-26 10:47:45 +020015#include <linux/module.h>
16#include <linux/moduleparam.h>
17#include <linux/types.h>
18#include <linux/kernel.h>
Thomas Reitmayr9e058d42009-02-24 14:59:22 -080019#include <linux/platform_device.h>
Sylver Bruneau22ac9232008-06-26 10:47:45 +020020#include <linux/watchdog.h>
21#include <linux/init.h>
Ezequiel Garciae97662e2014-02-10 20:00:24 -030022#include <linux/interrupt.h>
Sylver Bruneau22ac9232008-06-26 10:47:45 +020023#include <linux/io.h>
Andrew Lunn4f04be62012-03-04 16:57:31 +010024#include <linux/clk.h>
Axel Lin0dd6e482012-03-26 11:14:29 +080025#include <linux/err.h>
Andrew Lunn1e7bad02012-06-10 15:20:06 +020026#include <linux/of.h>
Ezequiel Garciafc723852014-02-10 20:00:28 -030027#include <linux/of_device.h>
Sylver Bruneau22ac9232008-06-26 10:47:45 +020028
Ezequiel Garcia868eb612014-02-10 20:00:25 -030029/* RSTOUT mask register physical address for Orion5x, Kirkwood and Dove */
30#define ORION_RSTOUT_MASK_OFFSET 0x20108
31
32/* Internal registers can be configured at any 1 MiB aligned address */
33#define INTERNAL_REGS_MASK ~(SZ_1M - 1)
34
Sylver Bruneau22ac9232008-06-26 10:47:45 +020035/*
36 * Watchdog timer block registers.
37 */
Jason Coopera855a7c2012-03-15 00:33:26 +000038#define TIMER_CTRL 0x0000
Ezequiel Garcia463f96e2014-02-10 20:00:31 -030039#define TIMER_A370_STATUS 0x04
Sylver Bruneau22ac9232008-06-26 10:47:45 +020040
Thomas Reitmayr9e058d42009-02-24 14:59:22 -080041#define WDT_MAX_CYCLE_COUNT 0xffffffff
Sylver Bruneau22ac9232008-06-26 10:47:45 +020042
Ezequiel Garcia463f96e2014-02-10 20:00:31 -030043#define WDT_A370_RATIO_MASK(v) ((v) << 16)
44#define WDT_A370_RATIO_SHIFT 5
45#define WDT_A370_RATIO (1 << WDT_A370_RATIO_SHIFT)
46
47#define WDT_AXP_FIXED_ENABLE_BIT BIT(10)
48#define WDT_A370_EXPIRED BIT(31)
49
Wim Van Sebroeck86a1e182012-03-05 16:51:11 +010050static bool nowayout = WATCHDOG_NOWAYOUT;
Thomas Reitmayr9e058d42009-02-24 14:59:22 -080051static int heartbeat = -1; /* module parameter (seconds) */
Ezequiel Garciab89a9c42014-02-10 20:00:27 -030052
Ezequiel Garcia19242272014-02-10 20:00:29 -030053struct orion_watchdog;
54
Ezequiel Garciafc723852014-02-10 20:00:28 -030055struct orion_watchdog_data {
56 int wdt_counter_offset;
57 int wdt_enable_bit;
58 int rstout_enable_bit;
Ezequiel Garcia19242272014-02-10 20:00:29 -030059 int (*clock_init)(struct platform_device *,
60 struct orion_watchdog *);
Ezequiel Garcia490d8e32014-02-10 20:00:30 -030061 int (*start)(struct watchdog_device *);
Ezequiel Garciafc723852014-02-10 20:00:28 -030062};
63
Ezequiel Garciab89a9c42014-02-10 20:00:27 -030064struct orion_watchdog {
65 struct watchdog_device wdt;
66 void __iomem *reg;
67 void __iomem *rstout;
68 unsigned long clk_rate;
69 struct clk *clk;
Ezequiel Garciafc723852014-02-10 20:00:28 -030070 const struct orion_watchdog_data *data;
Ezequiel Garciab89a9c42014-02-10 20:00:27 -030071};
Sylver Bruneau22ac9232008-06-26 10:47:45 +020072
Ezequiel Garcia19242272014-02-10 20:00:29 -030073static int orion_wdt_clock_init(struct platform_device *pdev,
74 struct orion_watchdog *dev)
75{
76 int ret;
77
Ezequiel Garcia463f96e2014-02-10 20:00:31 -030078 dev->clk = clk_get(&pdev->dev, NULL);
Ezequiel Garcia19242272014-02-10 20:00:29 -030079 if (IS_ERR(dev->clk))
80 return PTR_ERR(dev->clk);
81 ret = clk_prepare_enable(dev->clk);
Ezequiel Garcia463f96e2014-02-10 20:00:31 -030082 if (ret) {
83 clk_put(dev->clk);
Ezequiel Garcia19242272014-02-10 20:00:29 -030084 return ret;
Ezequiel Garcia463f96e2014-02-10 20:00:31 -030085 }
86
87 dev->clk_rate = clk_get_rate(dev->clk);
88 return 0;
89}
90
91static int armada370_wdt_clock_init(struct platform_device *pdev,
92 struct orion_watchdog *dev)
93{
94 int ret;
95
96 dev->clk = clk_get(&pdev->dev, NULL);
97 if (IS_ERR(dev->clk))
98 return PTR_ERR(dev->clk);
99 ret = clk_prepare_enable(dev->clk);
100 if (ret) {
101 clk_put(dev->clk);
102 return ret;
103 }
104
105 /* Setup watchdog input clock */
106 atomic_io_modify(dev->reg + TIMER_CTRL,
107 WDT_A370_RATIO_MASK(WDT_A370_RATIO_SHIFT),
108 WDT_A370_RATIO_MASK(WDT_A370_RATIO_SHIFT));
109
110 dev->clk_rate = clk_get_rate(dev->clk) / WDT_A370_RATIO;
111 return 0;
112}
113
114static int armadaxp_wdt_clock_init(struct platform_device *pdev,
115 struct orion_watchdog *dev)
116{
117 int ret;
118
119 dev->clk = of_clk_get_by_name(pdev->dev.of_node, "fixed");
120 if (IS_ERR(dev->clk))
121 return PTR_ERR(dev->clk);
122 ret = clk_prepare_enable(dev->clk);
123 if (ret) {
124 clk_put(dev->clk);
125 return ret;
126 }
127
128 /* Enable the fixed watchdog clock input */
129 atomic_io_modify(dev->reg + TIMER_CTRL,
130 WDT_AXP_FIXED_ENABLE_BIT,
131 WDT_AXP_FIXED_ENABLE_BIT);
Ezequiel Garcia19242272014-02-10 20:00:29 -0300132
133 dev->clk_rate = clk_get_rate(dev->clk);
134 return 0;
135}
136
Axel Lin0dd6e482012-03-26 11:14:29 +0800137static int orion_wdt_ping(struct watchdog_device *wdt_dev)
Thomas Reitmayrdf6707b2009-02-20 19:44:59 +0100138{
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300139 struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev);
Thomas Reitmayrdf6707b2009-02-20 19:44:59 +0100140 /* Reload watchdog duration */
Ezequiel Garciafc723852014-02-10 20:00:28 -0300141 writel(dev->clk_rate * wdt_dev->timeout,
142 dev->reg + dev->data->wdt_counter_offset);
Axel Lin0dd6e482012-03-26 11:14:29 +0800143 return 0;
Thomas Reitmayrdf6707b2009-02-20 19:44:59 +0100144}
145
Ezequiel Garcia463f96e2014-02-10 20:00:31 -0300146static int armada370_start(struct watchdog_device *wdt_dev)
147{
148 struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev);
149
150 /* Set watchdog duration */
151 writel(dev->clk_rate * wdt_dev->timeout,
152 dev->reg + dev->data->wdt_counter_offset);
153
154 /* Clear the watchdog expiration bit */
155 atomic_io_modify(dev->reg + TIMER_A370_STATUS, WDT_A370_EXPIRED, 0);
156
157 /* Enable watchdog timer */
158 atomic_io_modify(dev->reg + TIMER_CTRL, dev->data->wdt_enable_bit,
159 dev->data->wdt_enable_bit);
160
161 atomic_io_modify(dev->rstout, dev->data->rstout_enable_bit,
162 dev->data->rstout_enable_bit);
163 return 0;
164}
165
Ezequiel Garcia490d8e32014-02-10 20:00:30 -0300166static int orion_start(struct watchdog_device *wdt_dev)
Sylver Bruneau22ac9232008-06-26 10:47:45 +0200167{
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300168 struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev);
169
Sylver Bruneau22ac9232008-06-26 10:47:45 +0200170 /* Set watchdog duration */
Ezequiel Garciafc723852014-02-10 20:00:28 -0300171 writel(dev->clk_rate * wdt_dev->timeout,
172 dev->reg + dev->data->wdt_counter_offset);
Sylver Bruneau22ac9232008-06-26 10:47:45 +0200173
Sylver Bruneau22ac9232008-06-26 10:47:45 +0200174 /* Enable watchdog timer */
Ezequiel Garciafc723852014-02-10 20:00:28 -0300175 atomic_io_modify(dev->reg + TIMER_CTRL, dev->data->wdt_enable_bit,
176 dev->data->wdt_enable_bit);
Sylver Bruneau22ac9232008-06-26 10:47:45 +0200177
178 /* Enable reset on watchdog */
Ezequiel Garciafc723852014-02-10 20:00:28 -0300179 atomic_io_modify(dev->rstout, dev->data->rstout_enable_bit,
180 dev->data->rstout_enable_bit);
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300181
Axel Lin0dd6e482012-03-26 11:14:29 +0800182 return 0;
Sylver Bruneau22ac9232008-06-26 10:47:45 +0200183}
184
Ezequiel Garcia490d8e32014-02-10 20:00:30 -0300185static int orion_wdt_start(struct watchdog_device *wdt_dev)
186{
187 struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev);
188
189 /* There are some per-SoC quirks to handle */
190 return dev->data->start(wdt_dev);
191}
192
Axel Lin0dd6e482012-03-26 11:14:29 +0800193static int orion_wdt_stop(struct watchdog_device *wdt_dev)
Sylver Bruneau22ac9232008-06-26 10:47:45 +0200194{
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300195 struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev);
196
Sylver Bruneau22ac9232008-06-26 10:47:45 +0200197 /* Disable reset on watchdog */
Ezequiel Garciafc723852014-02-10 20:00:28 -0300198 atomic_io_modify(dev->rstout, dev->data->rstout_enable_bit, 0);
Sylver Bruneau22ac9232008-06-26 10:47:45 +0200199
200 /* Disable watchdog timer */
Ezequiel Garciafc723852014-02-10 20:00:28 -0300201 atomic_io_modify(dev->reg + TIMER_CTRL, dev->data->wdt_enable_bit, 0);
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300202
Axel Lin0dd6e482012-03-26 11:14:29 +0800203 return 0;
Wim Van Sebroeck6d0f0df2008-10-02 09:32:45 +0000204}
205
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300206static int orion_wdt_enabled(struct orion_watchdog *dev)
Ezequiel Garciad9d0c532014-02-10 20:00:23 -0300207{
208 bool enabled, running;
209
Ezequiel Garciafc723852014-02-10 20:00:28 -0300210 enabled = readl(dev->rstout) & dev->data->rstout_enable_bit;
211 running = readl(dev->reg + TIMER_CTRL) & dev->data->wdt_enable_bit;
Ezequiel Garciad9d0c532014-02-10 20:00:23 -0300212
213 return enabled && running;
214}
215
Axel Lin0dd6e482012-03-26 11:14:29 +0800216static unsigned int orion_wdt_get_timeleft(struct watchdog_device *wdt_dev)
Wim Van Sebroeck6d0f0df2008-10-02 09:32:45 +0000217{
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300218 struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev);
Ezequiel Garciafc723852014-02-10 20:00:28 -0300219 return readl(dev->reg + dev->data->wdt_counter_offset) / dev->clk_rate;
Axel Lin0dd6e482012-03-26 11:14:29 +0800220}
221
222static int orion_wdt_set_timeout(struct watchdog_device *wdt_dev,
223 unsigned int timeout)
224{
225 wdt_dev->timeout = timeout;
Wim Van Sebroeck6d0f0df2008-10-02 09:32:45 +0000226 return 0;
Sylver Bruneau22ac9232008-06-26 10:47:45 +0200227}
228
Axel Lin0dd6e482012-03-26 11:14:29 +0800229static const struct watchdog_info orion_wdt_info = {
230 .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
231 .identity = "Orion Watchdog",
Sylver Bruneau22ac9232008-06-26 10:47:45 +0200232};
233
Axel Lin0dd6e482012-03-26 11:14:29 +0800234static const struct watchdog_ops orion_wdt_ops = {
235 .owner = THIS_MODULE,
236 .start = orion_wdt_start,
237 .stop = orion_wdt_stop,
238 .ping = orion_wdt_ping,
239 .set_timeout = orion_wdt_set_timeout,
240 .get_timeleft = orion_wdt_get_timeleft,
Sylver Bruneau22ac9232008-06-26 10:47:45 +0200241};
242
Ezequiel Garciae97662e2014-02-10 20:00:24 -0300243static irqreturn_t orion_wdt_irq(int irq, void *devid)
244{
245 panic("Watchdog Timeout");
246 return IRQ_HANDLED;
247}
248
Ezequiel Garcia868eb612014-02-10 20:00:25 -0300249/*
250 * The original devicetree binding for this driver specified only
251 * one memory resource, so in order to keep DT backwards compatibility
252 * we try to fallback to a hardcoded register address, if the resource
253 * is missing from the devicetree.
254 */
255static void __iomem *orion_wdt_ioremap_rstout(struct platform_device *pdev,
256 phys_addr_t internal_regs)
257{
258 struct resource *res;
259 phys_addr_t rstout;
260
261 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
262 if (res)
263 return devm_ioremap(&pdev->dev, res->start,
264 resource_size(res));
265
266 /* This workaround works only for "orion-wdt", DT-enabled */
267 if (!of_device_is_compatible(pdev->dev.of_node, "marvell,orion-wdt"))
268 return NULL;
269
270 rstout = internal_regs + ORION_RSTOUT_MASK_OFFSET;
271
272 WARN(1, FW_BUG "falling back to harcoded RSTOUT reg 0x%x\n", rstout);
273 return devm_ioremap(&pdev->dev, rstout, 0x4);
274}
275
Ezequiel Garciafc723852014-02-10 20:00:28 -0300276static const struct orion_watchdog_data orion_data = {
277 .rstout_enable_bit = BIT(1),
278 .wdt_enable_bit = BIT(4),
279 .wdt_counter_offset = 0x24,
Ezequiel Garcia19242272014-02-10 20:00:29 -0300280 .clock_init = orion_wdt_clock_init,
Ezequiel Garcia490d8e32014-02-10 20:00:30 -0300281 .start = orion_start,
Ezequiel Garciafc723852014-02-10 20:00:28 -0300282};
283
Ezequiel Garcia463f96e2014-02-10 20:00:31 -0300284static const struct orion_watchdog_data armada370_data = {
285 .rstout_enable_bit = BIT(8),
286 .wdt_enable_bit = BIT(8),
287 .wdt_counter_offset = 0x34,
288 .clock_init = armada370_wdt_clock_init,
289 .start = armada370_start,
290};
291
292static const struct orion_watchdog_data armadaxp_data = {
293 .rstout_enable_bit = BIT(8),
294 .wdt_enable_bit = BIT(8),
295 .wdt_counter_offset = 0x34,
296 .clock_init = armadaxp_wdt_clock_init,
297 .start = armada370_start,
298};
299
Ezequiel Garciafc723852014-02-10 20:00:28 -0300300static const struct of_device_id orion_wdt_of_match_table[] = {
301 {
302 .compatible = "marvell,orion-wdt",
303 .data = &orion_data,
304 },
Ezequiel Garcia463f96e2014-02-10 20:00:31 -0300305 {
306 .compatible = "marvell,armada-370-wdt",
307 .data = &armada370_data,
308 },
309 {
310 .compatible = "marvell,armada-xp-wdt",
311 .data = &armadaxp_data,
312 },
Ezequiel Garciafc723852014-02-10 20:00:28 -0300313 {},
314};
315MODULE_DEVICE_TABLE(of, orion_wdt_of_match_table);
316
Bill Pemberton2d991a12012-11-19 13:21:41 -0500317static int orion_wdt_probe(struct platform_device *pdev)
Thomas Reitmayr9e058d42009-02-24 14:59:22 -0800318{
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300319 struct orion_watchdog *dev;
Ezequiel Garciafc723852014-02-10 20:00:28 -0300320 const struct of_device_id *match;
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300321 unsigned int wdt_max_duration; /* (seconds) */
Jason Coopera855a7c2012-03-15 00:33:26 +0000322 struct resource *res;
Ezequiel Garciae97662e2014-02-10 20:00:24 -0300323 int ret, irq;
Thomas Reitmayr9e058d42009-02-24 14:59:22 -0800324
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300325 dev = devm_kzalloc(&pdev->dev, sizeof(struct orion_watchdog),
326 GFP_KERNEL);
327 if (!dev)
328 return -ENOMEM;
329
Ezequiel Garciafc723852014-02-10 20:00:28 -0300330 match = of_match_device(orion_wdt_of_match_table, &pdev->dev);
331 if (!match)
332 /* Default legacy match */
333 match = &orion_wdt_of_match_table[0];
334
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300335 dev->wdt.info = &orion_wdt_info;
336 dev->wdt.ops = &orion_wdt_ops;
337 dev->wdt.min_timeout = 1;
Ezequiel Garciafc723852014-02-10 20:00:28 -0300338 dev->data = match->data;
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300339
Jason Coopera855a7c2012-03-15 00:33:26 +0000340 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Ezequiel Garcia19242272014-02-10 20:00:29 -0300341 if (!res)
342 return -ENODEV;
Ezequiel Garciabb02c662014-02-10 20:00:20 -0300343
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300344 dev->reg = devm_ioremap(&pdev->dev, res->start,
345 resource_size(res));
Ezequiel Garcia19242272014-02-10 20:00:29 -0300346 if (!dev->reg)
347 return -ENOMEM;
Thomas Reitmayr9e058d42009-02-24 14:59:22 -0800348
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300349 dev->rstout = orion_wdt_ioremap_rstout(pdev, res->start &
350 INTERNAL_REGS_MASK);
Ezequiel Garcia19242272014-02-10 20:00:29 -0300351 if (!dev->rstout)
352 return -ENODEV;
353
354 ret = dev->data->clock_init(pdev, dev);
355 if (ret) {
356 dev_err(&pdev->dev, "cannot initialize clock\n");
357 return ret;
Ezequiel Garcia868eb612014-02-10 20:00:25 -0300358 }
359
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300360 wdt_max_duration = WDT_MAX_CYCLE_COUNT / dev->clk_rate;
Axel Lin0dd6e482012-03-26 11:14:29 +0800361
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300362 dev->wdt.timeout = wdt_max_duration;
363 dev->wdt.max_timeout = wdt_max_duration;
364 watchdog_init_timeout(&dev->wdt, heartbeat, &pdev->dev);
365
366 platform_set_drvdata(pdev, &dev->wdt);
367 watchdog_set_drvdata(&dev->wdt, dev);
Axel Lin0dd6e482012-03-26 11:14:29 +0800368
Ezequiel Garciad9d0c532014-02-10 20:00:23 -0300369 /*
370 * Let's make sure the watchdog is fully stopped, unless it's
371 * explicitly enabled. This may be the case if the module was
372 * removed and re-insterted, or if the bootloader explicitly
373 * set a running watchdog before booting the kernel.
374 */
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300375 if (!orion_wdt_enabled(dev))
376 orion_wdt_stop(&dev->wdt);
Ezequiel Garciad9d0c532014-02-10 20:00:23 -0300377
Ezequiel Garciae97662e2014-02-10 20:00:24 -0300378 /* Request the IRQ only after the watchdog is disabled */
379 irq = platform_get_irq(pdev, 0);
380 if (irq > 0) {
381 /*
382 * Not all supported platforms specify an interrupt for the
383 * watchdog, so let's make it optional.
384 */
385 ret = devm_request_irq(&pdev->dev, irq, orion_wdt_irq, 0,
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300386 pdev->name, dev);
Ezequiel Garciae97662e2014-02-10 20:00:24 -0300387 if (ret < 0) {
388 dev_err(&pdev->dev, "failed to request IRQ\n");
389 goto disable_clk;
390 }
391 }
392
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300393 watchdog_set_nowayout(&dev->wdt, nowayout);
394 ret = watchdog_register_device(&dev->wdt);
Ezequiel Garciabb02c662014-02-10 20:00:20 -0300395 if (ret)
396 goto disable_clk;
Thomas Reitmayr9e058d42009-02-24 14:59:22 -0800397
Joe Perches27c766a2012-02-15 15:06:19 -0800398 pr_info("Initial timeout %d sec%s\n",
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300399 dev->wdt.timeout, nowayout ? ", nowayout" : "");
Thomas Reitmayr9e058d42009-02-24 14:59:22 -0800400 return 0;
Ezequiel Garciabb02c662014-02-10 20:00:20 -0300401
402disable_clk:
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300403 clk_disable_unprepare(dev->clk);
Ezequiel Garcia463f96e2014-02-10 20:00:31 -0300404 clk_put(dev->clk);
Ezequiel Garciabb02c662014-02-10 20:00:20 -0300405 return ret;
Thomas Reitmayr9e058d42009-02-24 14:59:22 -0800406}
407
Bill Pemberton4b12b892012-11-19 13:26:24 -0500408static int orion_wdt_remove(struct platform_device *pdev)
Sylver Bruneau22ac9232008-06-26 10:47:45 +0200409{
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300410 struct watchdog_device *wdt_dev = platform_get_drvdata(pdev);
411 struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev);
412
413 watchdog_unregister_device(wdt_dev);
414 clk_disable_unprepare(dev->clk);
Ezequiel Garcia463f96e2014-02-10 20:00:31 -0300415 clk_put(dev->clk);
Axel Lin0dd6e482012-03-26 11:14:29 +0800416 return 0;
Sylver Bruneau22ac9232008-06-26 10:47:45 +0200417}
418
Nicolas Pitre3b937a7db2009-06-01 13:56:02 -0400419static void orion_wdt_shutdown(struct platform_device *pdev)
Thomas Reitmayrdf6707b2009-02-20 19:44:59 +0100420{
Ezequiel Garciab89a9c42014-02-10 20:00:27 -0300421 struct watchdog_device *wdt_dev = platform_get_drvdata(pdev);
422 orion_wdt_stop(wdt_dev);
Thomas Reitmayrdf6707b2009-02-20 19:44:59 +0100423}
424
Nicolas Pitre3b937a7db2009-06-01 13:56:02 -0400425static struct platform_driver orion_wdt_driver = {
426 .probe = orion_wdt_probe,
Bill Pemberton82268712012-11-19 13:21:12 -0500427 .remove = orion_wdt_remove,
Nicolas Pitre3b937a7db2009-06-01 13:56:02 -0400428 .shutdown = orion_wdt_shutdown,
Thomas Reitmayr9e058d42009-02-24 14:59:22 -0800429 .driver = {
430 .owner = THIS_MODULE,
Nicolas Pitre3b937a7db2009-06-01 13:56:02 -0400431 .name = "orion_wdt",
Sachin Kamat85eee812013-09-30 10:12:51 +0530432 .of_match_table = orion_wdt_of_match_table,
Thomas Reitmayr9e058d42009-02-24 14:59:22 -0800433 },
434};
435
Axel Linb8ec6112011-11-29 13:56:27 +0800436module_platform_driver(orion_wdt_driver);
Sylver Bruneau22ac9232008-06-26 10:47:45 +0200437
438MODULE_AUTHOR("Sylver Bruneau <sylver.bruneau@googlemail.com>");
Nicolas Pitre3b937a7db2009-06-01 13:56:02 -0400439MODULE_DESCRIPTION("Orion Processor Watchdog");
Sylver Bruneau22ac9232008-06-26 10:47:45 +0200440
441module_param(heartbeat, int, 0);
Thomas Reitmayrdf6707b2009-02-20 19:44:59 +0100442MODULE_PARM_DESC(heartbeat, "Initial watchdog heartbeat in seconds");
Sylver Bruneau22ac9232008-06-26 10:47:45 +0200443
Wim Van Sebroeck86a1e182012-03-05 16:51:11 +0100444module_param(nowayout, bool, 0);
Thomas Reitmayrdf6707b2009-02-20 19:44:59 +0100445MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
446 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
Sylver Bruneau22ac9232008-06-26 10:47:45 +0200447
448MODULE_LICENSE("GPL");
Lubomir Rintelf3ea7332013-01-04 15:06:28 +0100449MODULE_ALIAS("platform:orion_wdt");