blob: f9b14e6efd9ac226f56ca232812e61276266e090 [file] [log] [blame]
Alessandro Zummof52ac8f2006-03-25 03:06:37 -08001/*
2 * Watchdog driver for Cirrus Logic EP93xx family of devices.
3 *
4 * Copyright (c) 2004 Ray Lehtiniemi
5 * Copyright (c) 2006 Tower Technologies
6 * Based on ep93xx driver, bits from alim7101_wdt.c
7 *
8 * Authors: Ray Lehtiniemi <rayl@mail.com>,
9 * Alessandro Zummo <a.zummo@towertech.it>
10 *
H Hartley Sweetene12a6792012-03-14 10:31:50 -070011 * Copyright (c) 2012 H Hartley Sweeten <hsweeten@visionengravers.com>
12 * Convert to a platform device and use the watchdog framework API
13 *
Alessandro Zummof52ac8f2006-03-25 03:06:37 -080014 * This file is licensed under the terms of the GNU General Public
15 * License version 2. This program is licensed "as is" without any
16 * warranty of any kind, whether express or implied.
17 *
18 * This watchdog fires after 250msec, which is a too short interval
19 * for us to rely on the user space daemon alone. So we ping the
20 * wdt each ~200msec and eventually stop doing it if the user space
21 * daemon dies.
Alessandro Zummof52ac8f2006-03-25 03:06:37 -080022 */
23
H Hartley Sweeten3e0113a2012-03-13 09:48:16 +110024#include <linux/platform_device.h>
Alessandro Zummof52ac8f2006-03-25 03:06:37 -080025#include <linux/module.h>
Alessandro Zummof52ac8f2006-03-25 03:06:37 -080026#include <linux/watchdog.h>
Ryan Mallon2653d1d2009-07-15 21:33:22 +010027#include <linux/io.h>
Alessandro Zummof52ac8f2006-03-25 03:06:37 -080028
Alessandro Zummof52ac8f2006-03-25 03:06:37 -080029/* default timeout (secs) */
30#define WDT_TIMEOUT 30
31
Wim Van Sebroeck86a1e182012-03-05 16:51:11 +010032static bool nowayout = WATCHDOG_NOWAYOUT;
H Hartley Sweetene12a6792012-03-14 10:31:50 -070033module_param(nowayout, bool, 0);
34MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
35
H Hartley Sweeten91700362017-01-31 09:33:29 -070036static unsigned int timeout;
Wim Van Sebroeck2ca16062012-03-22 09:37:10 +010037module_param(timeout, uint, 0);
H Hartley Sweeten91700362017-01-31 09:33:29 -070038MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds.");
Alessandro Zummof52ac8f2006-03-25 03:06:37 -080039
H Hartley Sweeten3e0113a2012-03-13 09:48:16 +110040#define EP93XX_WATCHDOG 0x00
41#define EP93XX_WDSTATUS 0x04
Alessandro Zummof52ac8f2006-03-25 03:06:37 -080042
H Hartley Sweeten91700362017-01-31 09:33:29 -070043struct ep93xx_wdt_priv {
44 void __iomem *mmio;
45 struct watchdog_device wdd;
46};
Alessandro Zummof52ac8f2006-03-25 03:06:37 -080047
H Hartley Sweetene12a6792012-03-14 10:31:50 -070048static int ep93xx_wdt_start(struct watchdog_device *wdd)
49{
H Hartley Sweeten91700362017-01-31 09:33:29 -070050 struct ep93xx_wdt_priv *priv = watchdog_get_drvdata(wdd);
H Hartley Sweetene12a6792012-03-14 10:31:50 -070051
H Hartley Sweeten91700362017-01-31 09:33:29 -070052 writel(0xaaaa, priv->mmio + EP93XX_WATCHDOG);
H Hartley Sweetene12a6792012-03-14 10:31:50 -070053
54 return 0;
55}
56
57static int ep93xx_wdt_stop(struct watchdog_device *wdd)
58{
H Hartley Sweeten91700362017-01-31 09:33:29 -070059 struct ep93xx_wdt_priv *priv = watchdog_get_drvdata(wdd);
60
61 writel(0xaa55, priv->mmio + EP93XX_WATCHDOG);
H Hartley Sweetene12a6792012-03-14 10:31:50 -070062
63 return 0;
64}
65
H Hartley Sweeten91700362017-01-31 09:33:29 -070066static int ep93xx_wdt_ping(struct watchdog_device *wdd)
H Hartley Sweetene12a6792012-03-14 10:31:50 -070067{
H Hartley Sweeten91700362017-01-31 09:33:29 -070068 struct ep93xx_wdt_priv *priv = watchdog_get_drvdata(wdd);
69
70 writel(0x5555, priv->mmio + EP93XX_WATCHDOG);
H Hartley Sweetene12a6792012-03-14 10:31:50 -070071
72 return 0;
73}
74
75static const struct watchdog_info ep93xx_wdt_ident = {
76 .options = WDIOF_CARDRESET |
H Hartley Sweeten91700362017-01-31 09:33:29 -070077 WDIOF_SETTIMEOUT |
H Hartley Sweetene12a6792012-03-14 10:31:50 -070078 WDIOF_MAGICCLOSE |
79 WDIOF_KEEPALIVEPING,
80 .identity = "EP93xx Watchdog",
81};
82
Bhumika Goyalb893e342017-01-28 13:11:17 +053083static const struct watchdog_ops ep93xx_wdt_ops = {
H Hartley Sweetene12a6792012-03-14 10:31:50 -070084 .owner = THIS_MODULE,
85 .start = ep93xx_wdt_start,
86 .stop = ep93xx_wdt_stop,
H Hartley Sweeten91700362017-01-31 09:33:29 -070087 .ping = ep93xx_wdt_ping,
H Hartley Sweetene12a6792012-03-14 10:31:50 -070088};
89
Bill Pemberton2d991a12012-11-19 13:21:41 -050090static int ep93xx_wdt_probe(struct platform_device *pdev)
Alessandro Zummof52ac8f2006-03-25 03:06:37 -080091{
H Hartley Sweeten91700362017-01-31 09:33:29 -070092 struct ep93xx_wdt_priv *priv;
93 struct watchdog_device *wdd;
H Hartley Sweeten3e0113a2012-03-13 09:48:16 +110094 struct resource *res;
95 unsigned long val;
H Hartley Sweeten91700362017-01-31 09:33:29 -070096 int ret;
97
98 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
99 if (!priv)
100 return -ENOMEM;
Alessandro Zummof52ac8f2006-03-25 03:06:37 -0800101
H Hartley Sweeten3e0113a2012-03-13 09:48:16 +1100102 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
H Hartley Sweeten91700362017-01-31 09:33:29 -0700103 priv->mmio = devm_ioremap_resource(&pdev->dev, res);
104 if (IS_ERR(priv->mmio))
105 return PTR_ERR(priv->mmio);
H Hartley Sweeten3e0113a2012-03-13 09:48:16 +1100106
H Hartley Sweeten91700362017-01-31 09:33:29 -0700107 val = readl(priv->mmio + EP93XX_WATCHDOG);
Alessandro Zummof52ac8f2006-03-25 03:06:37 -0800108
H Hartley Sweeten91700362017-01-31 09:33:29 -0700109 wdd = &priv->wdd;
110 wdd->bootstatus = (val & 0x01) ? WDIOF_CARDRESET : 0;
111 wdd->info = &ep93xx_wdt_ident;
112 wdd->ops = &ep93xx_wdt_ops;
113 wdd->min_timeout = 1;
114 wdd->max_hw_heartbeat_ms = 200;
115 wdd->parent = &pdev->dev;
Wim Van Sebroeck697b41e2012-03-13 09:06:12 +0100116
H Hartley Sweeten91700362017-01-31 09:33:29 -0700117 watchdog_set_nowayout(wdd, nowayout);
Wim Van Sebroeck697b41e2012-03-13 09:06:12 +0100118
H Hartley Sweeten91700362017-01-31 09:33:29 -0700119 wdd->timeout = WDT_TIMEOUT;
120 watchdog_init_timeout(wdd, timeout, &pdev->dev);
Wim Van Sebroeck697b41e2012-03-13 09:06:12 +0100121
H Hartley Sweeten91700362017-01-31 09:33:29 -0700122 watchdog_set_drvdata(wdd, priv);
H Hartley Sweetene12a6792012-03-14 10:31:50 -0700123
H Hartley Sweeten91700362017-01-31 09:33:29 -0700124 ret = devm_watchdog_register_device(&pdev->dev, wdd);
125 if (ret)
126 return ret;
127
128 dev_info(&pdev->dev, "EP93XX watchdog driver %s\n",
Wim Van Sebroeck697b41e2012-03-13 09:06:12 +0100129 (val & 0x08) ? " (nCS1 disable detected)" : "");
H Hartley Sweetene12a6792012-03-14 10:31:50 -0700130
131 return 0;
Alessandro Zummof52ac8f2006-03-25 03:06:37 -0800132}
133
H Hartley Sweeten3e0113a2012-03-13 09:48:16 +1100134static struct platform_driver ep93xx_wdt_driver = {
135 .driver = {
H Hartley Sweeten3e0113a2012-03-13 09:48:16 +1100136 .name = "ep93xx-wdt",
137 },
138 .probe = ep93xx_wdt_probe,
H Hartley Sweeten3e0113a2012-03-13 09:48:16 +1100139};
140
141module_platform_driver(ep93xx_wdt_driver);
Alessandro Zummof52ac8f2006-03-25 03:06:37 -0800142
Jingoo Han5f5e1902014-02-27 14:41:42 +0900143MODULE_AUTHOR("Ray Lehtiniemi <rayl@mail.com>");
144MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
145MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
Alessandro Zummof52ac8f2006-03-25 03:06:37 -0800146MODULE_DESCRIPTION("EP93xx Watchdog");
147MODULE_LICENSE("GPL");