1 From c197a5a04d658da490de08636066a6bdbebf16c5 Mon Sep 17 00:00:00 2001
2 From: Linus Walleij <linus.walleij@linaro.org>
3 Date: Mon, 16 Oct 2017 22:54:24 +0200
4 Subject: [PATCH 18/31] watchdog: gemini/ftwdt010: rename driver and symbols
6 This renames all the driver files and symbols for the Gemini
7 watchdog to FTWDT010 as it has been revealed that this IP block
8 is a generic watchdog timer from Faraday Technology used in
11 Select this driver by default for the Gemini, it is a sensible
12 driver to always have enabled.
14 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
15 Reviewed-by: Guenter Roeck <linux@roeck-us.net>
16 Signed-off-by: Guenter Roeck <linux@roeck-us.net>
17 Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
19 drivers/watchdog/Kconfig | 14 +--
20 drivers/watchdog/Makefile | 2 +-
21 drivers/watchdog/{gemini_wdt.c => ftwdt010_wdt.c} | 117 +++++++++++-----------
22 3 files changed, 68 insertions(+), 65 deletions(-)
23 rename drivers/watchdog/{gemini_wdt.c => ftwdt010_wdt.c} (50%)
25 --- a/drivers/watchdog/Kconfig
26 +++ b/drivers/watchdog/Kconfig
27 @@ -321,16 +321,18 @@ config 977_WATCHDOG
29 Not sure? It's safe to say N.
31 -config GEMINI_WATCHDOG
32 - tristate "Gemini watchdog"
33 - depends on ARCH_GEMINI
34 +config FTWDT010_WATCHDOG
35 + tristate "Faraday Technology FTWDT010 watchdog"
36 + depends on ARM || COMPILE_TEST
40 - Say Y here if to include support for the watchdog timer
41 - embedded in the Cortina Systems Gemini family of devices.
42 + Say Y here if to include support for the Faraday Technology
43 + FTWDT010 watchdog timer embedded in the Cortina Systems Gemini
46 To compile this driver as a module, choose M here: the
47 - module will be called gemini_wdt.
48 + module will be called ftwdt010_wdt.
50 config IXP4XX_WATCHDOG
51 tristate "IXP4xx Watchdog"
52 --- a/drivers/watchdog/Makefile
53 +++ b/drivers/watchdog/Makefile
54 @@ -46,7 +46,7 @@ obj-$(CONFIG_OMAP_WATCHDOG) += omap_wdt.
55 obj-$(CONFIG_TWL4030_WATCHDOG) += twl4030_wdt.o
56 obj-$(CONFIG_21285_WATCHDOG) += wdt285.o
57 obj-$(CONFIG_977_WATCHDOG) += wdt977.o
58 -obj-$(CONFIG_GEMINI_WATCHDOG) += gemini_wdt.o
59 +obj-$(CONFIG_FTWDT010_WATCHDOG) += ftwdt010_wdt.o
60 obj-$(CONFIG_IXP4XX_WATCHDOG) += ixp4xx_wdt.o
61 obj-$(CONFIG_KS8695_WATCHDOG) += ks8695_wdt.o
62 obj-$(CONFIG_S3C2410_WATCHDOG) += s3c2410_wdt.o
63 --- a/drivers/watchdog/gemini_wdt.c
67 - * Watchdog driver for Cortina Systems Gemini SoC
69 - * Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org>
71 - * Inspired by the out-of-tree drivers from OpenWRT:
72 - * Copyright (C) 2009 Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
74 - * This program is free software; you can redistribute it and/or modify
75 - * it under the terms of the GNU General Public License version 2 as
76 - * published by the Free Software Foundation.
79 -#include <linux/bitops.h>
80 -#include <linux/init.h>
81 -#include <linux/interrupt.h>
82 -#include <linux/io.h>
83 -#include <linux/kernel.h>
84 -#include <linux/module.h>
85 -#include <linux/of_device.h>
86 -#include <linux/platform_device.h>
87 -#include <linux/slab.h>
88 -#include <linux/watchdog.h>
90 -#define GEMINI_WDCOUNTER 0x0
91 -#define GEMINI_WDLOAD 0x4
92 -#define GEMINI_WDRESTART 0x8
93 -#define GEMINI_WDCR 0xC
95 -#define WDRESTART_MAGIC 0x5AB9
97 -#define WDCR_CLOCK_5MHZ BIT(4)
98 -#define WDCR_SYS_RST BIT(1)
99 -#define WDCR_ENABLE BIT(0)
101 -#define WDT_CLOCK 5000000 /* 5 MHz */
104 - struct watchdog_device wdd;
105 - struct device *dev;
106 - void __iomem *base;
110 -struct gemini_wdt *to_gemini_wdt(struct watchdog_device *wdd)
112 - return container_of(wdd, struct gemini_wdt, wdd);
115 -static int gemini_wdt_start(struct watchdog_device *wdd)
117 - struct gemini_wdt *gwdt = to_gemini_wdt(wdd);
119 - writel(wdd->timeout * WDT_CLOCK, gwdt->base + GEMINI_WDLOAD);
120 - writel(WDRESTART_MAGIC, gwdt->base + GEMINI_WDRESTART);
121 - /* set clock before enabling */
122 - writel(WDCR_CLOCK_5MHZ | WDCR_SYS_RST,
123 - gwdt->base + GEMINI_WDCR);
124 - writel(WDCR_CLOCK_5MHZ | WDCR_SYS_RST | WDCR_ENABLE,
125 - gwdt->base + GEMINI_WDCR);
130 -static int gemini_wdt_stop(struct watchdog_device *wdd)
132 - struct gemini_wdt *gwdt = to_gemini_wdt(wdd);
134 - writel(0, gwdt->base + GEMINI_WDCR);
139 -static int gemini_wdt_ping(struct watchdog_device *wdd)
141 - struct gemini_wdt *gwdt = to_gemini_wdt(wdd);
143 - writel(WDRESTART_MAGIC, gwdt->base + GEMINI_WDRESTART);
148 -static int gemini_wdt_set_timeout(struct watchdog_device *wdd,
149 - unsigned int timeout)
151 - wdd->timeout = timeout;
152 - if (watchdog_active(wdd))
153 - gemini_wdt_start(wdd);
158 -static irqreturn_t gemini_wdt_interrupt(int irq, void *data)
160 - struct gemini_wdt *gwdt = data;
162 - watchdog_notify_pretimeout(&gwdt->wdd);
164 - return IRQ_HANDLED;
167 -static const struct watchdog_ops gemini_wdt_ops = {
168 - .start = gemini_wdt_start,
169 - .stop = gemini_wdt_stop,
170 - .ping = gemini_wdt_ping,
171 - .set_timeout = gemini_wdt_set_timeout,
172 - .owner = THIS_MODULE,
175 -static const struct watchdog_info gemini_wdt_info = {
176 - .options = WDIOF_KEEPALIVEPING
178 - | WDIOF_SETTIMEOUT,
179 - .identity = KBUILD_MODNAME,
183 -static int gemini_wdt_probe(struct platform_device *pdev)
185 - struct device *dev = &pdev->dev;
186 - struct resource *res;
187 - struct gemini_wdt *gwdt;
192 - gwdt = devm_kzalloc(dev, sizeof(*gwdt), GFP_KERNEL);
196 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
197 - gwdt->base = devm_ioremap_resource(dev, res);
198 - if (IS_ERR(gwdt->base))
199 - return PTR_ERR(gwdt->base);
201 - irq = platform_get_irq(pdev, 0);
206 - gwdt->wdd.info = &gemini_wdt_info;
207 - gwdt->wdd.ops = &gemini_wdt_ops;
208 - gwdt->wdd.min_timeout = 1;
209 - gwdt->wdd.max_timeout = 0xFFFFFFFF / WDT_CLOCK;
210 - gwdt->wdd.parent = dev;
213 - * If 'timeout-sec' unspecified in devicetree, assume a 13 second
216 - gwdt->wdd.timeout = 13U;
217 - watchdog_init_timeout(&gwdt->wdd, 0, dev);
219 - reg = readw(gwdt->base + GEMINI_WDCR);
220 - if (reg & WDCR_ENABLE) {
221 - /* Watchdog was enabled by the bootloader, disable it. */
222 - reg &= ~WDCR_ENABLE;
223 - writel(reg, gwdt->base + GEMINI_WDCR);
226 - ret = devm_request_irq(dev, irq, gemini_wdt_interrupt, 0,
227 - "watchdog bark", gwdt);
231 - ret = devm_watchdog_register_device(dev, &gwdt->wdd);
233 - dev_err(&pdev->dev, "failed to register watchdog\n");
237 - /* Set up platform driver data */
238 - platform_set_drvdata(pdev, gwdt);
239 - dev_info(dev, "Gemini watchdog driver enabled\n");
244 -static int __maybe_unused gemini_wdt_suspend(struct device *dev)
246 - struct gemini_wdt *gwdt = dev_get_drvdata(dev);
249 - reg = readw(gwdt->base + GEMINI_WDCR);
250 - reg &= ~WDCR_ENABLE;
251 - writel(reg, gwdt->base + GEMINI_WDCR);
256 -static int __maybe_unused gemini_wdt_resume(struct device *dev)
258 - struct gemini_wdt *gwdt = dev_get_drvdata(dev);
261 - if (watchdog_active(&gwdt->wdd)) {
262 - reg = readw(gwdt->base + GEMINI_WDCR);
263 - reg |= WDCR_ENABLE;
264 - writel(reg, gwdt->base + GEMINI_WDCR);
270 -static const struct dev_pm_ops gemini_wdt_dev_pm_ops = {
271 - SET_SYSTEM_SLEEP_PM_OPS(gemini_wdt_suspend,
276 -static const struct of_device_id gemini_wdt_match[] = {
277 - { .compatible = "cortina,gemini-watchdog" },
280 -MODULE_DEVICE_TABLE(of, gemini_wdt_match);
283 -static struct platform_driver gemini_wdt_driver = {
284 - .probe = gemini_wdt_probe,
286 - .name = "gemini-wdt",
287 - .of_match_table = of_match_ptr(gemini_wdt_match),
288 - .pm = &gemini_wdt_dev_pm_ops,
291 -module_platform_driver(gemini_wdt_driver);
292 -MODULE_AUTHOR("Linus Walleij");
293 -MODULE_DESCRIPTION("Watchdog driver for Gemini");
294 -MODULE_LICENSE("GPL");
296 +++ b/drivers/watchdog/ftwdt010_wdt.c
299 + * Watchdog driver for Faraday Technology FTWDT010
301 + * Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org>
303 + * Inspired by the out-of-tree drivers from OpenWRT:
304 + * Copyright (C) 2009 Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
306 + * This program is free software; you can redistribute it and/or modify
307 + * it under the terms of the GNU General Public License version 2 as
308 + * published by the Free Software Foundation.
311 +#include <linux/bitops.h>
312 +#include <linux/init.h>
313 +#include <linux/interrupt.h>
314 +#include <linux/io.h>
315 +#include <linux/kernel.h>
316 +#include <linux/module.h>
317 +#include <linux/of_device.h>
318 +#include <linux/platform_device.h>
319 +#include <linux/slab.h>
320 +#include <linux/watchdog.h>
322 +#define FTWDT010_WDCOUNTER 0x0
323 +#define FTWDT010_WDLOAD 0x4
324 +#define FTWDT010_WDRESTART 0x8
325 +#define FTWDT010_WDCR 0xC
327 +#define WDRESTART_MAGIC 0x5AB9
329 +#define WDCR_CLOCK_5MHZ BIT(4)
330 +#define WDCR_SYS_RST BIT(1)
331 +#define WDCR_ENABLE BIT(0)
333 +#define WDT_CLOCK 5000000 /* 5 MHz */
335 +struct ftwdt010_wdt {
336 + struct watchdog_device wdd;
337 + struct device *dev;
338 + void __iomem *base;
342 +struct ftwdt010_wdt *to_ftwdt010_wdt(struct watchdog_device *wdd)
344 + return container_of(wdd, struct ftwdt010_wdt, wdd);
347 +static int ftwdt010_wdt_start(struct watchdog_device *wdd)
349 + struct ftwdt010_wdt *gwdt = to_ftwdt010_wdt(wdd);
351 + writel(wdd->timeout * WDT_CLOCK, gwdt->base + FTWDT010_WDLOAD);
352 + writel(WDRESTART_MAGIC, gwdt->base + FTWDT010_WDRESTART);
353 + /* set clock before enabling */
354 + writel(WDCR_CLOCK_5MHZ | WDCR_SYS_RST,
355 + gwdt->base + FTWDT010_WDCR);
356 + writel(WDCR_CLOCK_5MHZ | WDCR_SYS_RST | WDCR_ENABLE,
357 + gwdt->base + FTWDT010_WDCR);
362 +static int ftwdt010_wdt_stop(struct watchdog_device *wdd)
364 + struct ftwdt010_wdt *gwdt = to_ftwdt010_wdt(wdd);
366 + writel(0, gwdt->base + FTWDT010_WDCR);
371 +static int ftwdt010_wdt_ping(struct watchdog_device *wdd)
373 + struct ftwdt010_wdt *gwdt = to_ftwdt010_wdt(wdd);
375 + writel(WDRESTART_MAGIC, gwdt->base + FTWDT010_WDRESTART);
380 +static int ftwdt010_wdt_set_timeout(struct watchdog_device *wdd,
381 + unsigned int timeout)
383 + wdd->timeout = timeout;
384 + if (watchdog_active(wdd))
385 + ftwdt010_wdt_start(wdd);
390 +static irqreturn_t ftwdt010_wdt_interrupt(int irq, void *data)
392 + struct ftwdt010_wdt *gwdt = data;
394 + watchdog_notify_pretimeout(&gwdt->wdd);
396 + return IRQ_HANDLED;
399 +static const struct watchdog_ops ftwdt010_wdt_ops = {
400 + .start = ftwdt010_wdt_start,
401 + .stop = ftwdt010_wdt_stop,
402 + .ping = ftwdt010_wdt_ping,
403 + .set_timeout = ftwdt010_wdt_set_timeout,
404 + .owner = THIS_MODULE,
407 +static const struct watchdog_info ftwdt010_wdt_info = {
408 + .options = WDIOF_KEEPALIVEPING
410 + | WDIOF_SETTIMEOUT,
411 + .identity = KBUILD_MODNAME,
415 +static int ftwdt010_wdt_probe(struct platform_device *pdev)
417 + struct device *dev = &pdev->dev;
418 + struct resource *res;
419 + struct ftwdt010_wdt *gwdt;
424 + gwdt = devm_kzalloc(dev, sizeof(*gwdt), GFP_KERNEL);
428 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
429 + gwdt->base = devm_ioremap_resource(dev, res);
430 + if (IS_ERR(gwdt->base))
431 + return PTR_ERR(gwdt->base);
433 + irq = platform_get_irq(pdev, 0);
438 + gwdt->wdd.info = &ftwdt010_wdt_info;
439 + gwdt->wdd.ops = &ftwdt010_wdt_ops;
440 + gwdt->wdd.min_timeout = 1;
441 + gwdt->wdd.max_timeout = 0xFFFFFFFF / WDT_CLOCK;
442 + gwdt->wdd.parent = dev;
445 + * If 'timeout-sec' unspecified in devicetree, assume a 13 second
448 + gwdt->wdd.timeout = 13U;
449 + watchdog_init_timeout(&gwdt->wdd, 0, dev);
451 + reg = readw(gwdt->base + FTWDT010_WDCR);
452 + if (reg & WDCR_ENABLE) {
453 + /* Watchdog was enabled by the bootloader, disable it. */
454 + reg &= ~WDCR_ENABLE;
455 + writel(reg, gwdt->base + FTWDT010_WDCR);
458 + ret = devm_request_irq(dev, irq, ftwdt010_wdt_interrupt, 0,
459 + "watchdog bark", gwdt);
463 + ret = devm_watchdog_register_device(dev, &gwdt->wdd);
465 + dev_err(&pdev->dev, "failed to register watchdog\n");
469 + /* Set up platform driver data */
470 + platform_set_drvdata(pdev, gwdt);
471 + dev_info(dev, "FTWDT010 watchdog driver enabled\n");
476 +static int __maybe_unused ftwdt010_wdt_suspend(struct device *dev)
478 + struct ftwdt010_wdt *gwdt = dev_get_drvdata(dev);
481 + reg = readw(gwdt->base + FTWDT010_WDCR);
482 + reg &= ~WDCR_ENABLE;
483 + writel(reg, gwdt->base + FTWDT010_WDCR);
488 +static int __maybe_unused ftwdt010_wdt_resume(struct device *dev)
490 + struct ftwdt010_wdt *gwdt = dev_get_drvdata(dev);
493 + if (watchdog_active(&gwdt->wdd)) {
494 + reg = readw(gwdt->base + FTWDT010_WDCR);
495 + reg |= WDCR_ENABLE;
496 + writel(reg, gwdt->base + FTWDT010_WDCR);
502 +static const struct dev_pm_ops ftwdt010_wdt_dev_pm_ops = {
503 + SET_SYSTEM_SLEEP_PM_OPS(ftwdt010_wdt_suspend,
504 + ftwdt010_wdt_resume)
508 +static const struct of_device_id ftwdt010_wdt_match[] = {
509 + { .compatible = "faraday,ftwdt010" },
510 + { .compatible = "cortina,gemini-watchdog" },
513 +MODULE_DEVICE_TABLE(of, ftwdt010_wdt_match);
516 +static struct platform_driver ftwdt010_wdt_driver = {
517 + .probe = ftwdt010_wdt_probe,
519 + .name = "ftwdt010-wdt",
520 + .of_match_table = of_match_ptr(ftwdt010_wdt_match),
521 + .pm = &ftwdt010_wdt_dev_pm_ops,
524 +module_platform_driver(ftwdt010_wdt_driver);
525 +MODULE_AUTHOR("Linus Walleij");
526 +MODULE_DESCRIPTION("Watchdog driver for Faraday Technology FTWDT010");
527 +MODULE_LICENSE("GPL");