Alessandro Zummo | f52ac8f | 2006-03-25 03:06:37 -0800 | [diff] [blame] | 1 | /* |
| 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 Sweeten | e12a679 | 2012-03-14 10:31:50 -0700 | [diff] [blame] | 11 | * Copyright (c) 2012 H Hartley Sweeten <hsweeten@visionengravers.com> |
| 12 | * Convert to a platform device and use the watchdog framework API |
| 13 | * |
Alessandro Zummo | f52ac8f | 2006-03-25 03:06:37 -0800 | [diff] [blame] | 14 | * 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 Zummo | f52ac8f | 2006-03-25 03:06:37 -0800 | [diff] [blame] | 22 | */ |
| 23 | |
H Hartley Sweeten | 3e0113a | 2012-03-13 09:48:16 +1100 | [diff] [blame] | 24 | #include <linux/platform_device.h> |
Alessandro Zummo | f52ac8f | 2006-03-25 03:06:37 -0800 | [diff] [blame] | 25 | #include <linux/module.h> |
Alessandro Zummo | f52ac8f | 2006-03-25 03:06:37 -0800 | [diff] [blame] | 26 | #include <linux/watchdog.h> |
Ryan Mallon | 2653d1d | 2009-07-15 21:33:22 +0100 | [diff] [blame] | 27 | #include <linux/io.h> |
Alessandro Zummo | f52ac8f | 2006-03-25 03:06:37 -0800 | [diff] [blame] | 28 | |
Alessandro Zummo | f52ac8f | 2006-03-25 03:06:37 -0800 | [diff] [blame] | 29 | /* default timeout (secs) */ |
| 30 | #define WDT_TIMEOUT 30 |
| 31 | |
Wim Van Sebroeck | 86a1e18 | 2012-03-05 16:51:11 +0100 | [diff] [blame] | 32 | static bool nowayout = WATCHDOG_NOWAYOUT; |
H Hartley Sweeten | e12a679 | 2012-03-14 10:31:50 -0700 | [diff] [blame] | 33 | module_param(nowayout, bool, 0); |
| 34 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started"); |
| 35 | |
H Hartley Sweeten | 9170036 | 2017-01-31 09:33:29 -0700 | [diff] [blame] | 36 | static unsigned int timeout; |
Wim Van Sebroeck | 2ca1606 | 2012-03-22 09:37:10 +0100 | [diff] [blame] | 37 | module_param(timeout, uint, 0); |
H Hartley Sweeten | 9170036 | 2017-01-31 09:33:29 -0700 | [diff] [blame] | 38 | MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds."); |
Alessandro Zummo | f52ac8f | 2006-03-25 03:06:37 -0800 | [diff] [blame] | 39 | |
H Hartley Sweeten | 3e0113a | 2012-03-13 09:48:16 +1100 | [diff] [blame] | 40 | #define EP93XX_WATCHDOG 0x00 |
| 41 | #define EP93XX_WDSTATUS 0x04 |
Alessandro Zummo | f52ac8f | 2006-03-25 03:06:37 -0800 | [diff] [blame] | 42 | |
H Hartley Sweeten | 9170036 | 2017-01-31 09:33:29 -0700 | [diff] [blame] | 43 | struct ep93xx_wdt_priv { |
| 44 | void __iomem *mmio; |
| 45 | struct watchdog_device wdd; |
| 46 | }; |
Alessandro Zummo | f52ac8f | 2006-03-25 03:06:37 -0800 | [diff] [blame] | 47 | |
H Hartley Sweeten | e12a679 | 2012-03-14 10:31:50 -0700 | [diff] [blame] | 48 | static int ep93xx_wdt_start(struct watchdog_device *wdd) |
| 49 | { |
H Hartley Sweeten | 9170036 | 2017-01-31 09:33:29 -0700 | [diff] [blame] | 50 | struct ep93xx_wdt_priv *priv = watchdog_get_drvdata(wdd); |
H Hartley Sweeten | e12a679 | 2012-03-14 10:31:50 -0700 | [diff] [blame] | 51 | |
H Hartley Sweeten | 9170036 | 2017-01-31 09:33:29 -0700 | [diff] [blame] | 52 | writel(0xaaaa, priv->mmio + EP93XX_WATCHDOG); |
H Hartley Sweeten | e12a679 | 2012-03-14 10:31:50 -0700 | [diff] [blame] | 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | static int ep93xx_wdt_stop(struct watchdog_device *wdd) |
| 58 | { |
H Hartley Sweeten | 9170036 | 2017-01-31 09:33:29 -0700 | [diff] [blame] | 59 | struct ep93xx_wdt_priv *priv = watchdog_get_drvdata(wdd); |
| 60 | |
| 61 | writel(0xaa55, priv->mmio + EP93XX_WATCHDOG); |
H Hartley Sweeten | e12a679 | 2012-03-14 10:31:50 -0700 | [diff] [blame] | 62 | |
| 63 | return 0; |
| 64 | } |
| 65 | |
H Hartley Sweeten | 9170036 | 2017-01-31 09:33:29 -0700 | [diff] [blame] | 66 | static int ep93xx_wdt_ping(struct watchdog_device *wdd) |
H Hartley Sweeten | e12a679 | 2012-03-14 10:31:50 -0700 | [diff] [blame] | 67 | { |
H Hartley Sweeten | 9170036 | 2017-01-31 09:33:29 -0700 | [diff] [blame] | 68 | struct ep93xx_wdt_priv *priv = watchdog_get_drvdata(wdd); |
| 69 | |
| 70 | writel(0x5555, priv->mmio + EP93XX_WATCHDOG); |
H Hartley Sweeten | e12a679 | 2012-03-14 10:31:50 -0700 | [diff] [blame] | 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | static const struct watchdog_info ep93xx_wdt_ident = { |
| 76 | .options = WDIOF_CARDRESET | |
H Hartley Sweeten | 9170036 | 2017-01-31 09:33:29 -0700 | [diff] [blame] | 77 | WDIOF_SETTIMEOUT | |
H Hartley Sweeten | e12a679 | 2012-03-14 10:31:50 -0700 | [diff] [blame] | 78 | WDIOF_MAGICCLOSE | |
| 79 | WDIOF_KEEPALIVEPING, |
| 80 | .identity = "EP93xx Watchdog", |
| 81 | }; |
| 82 | |
Bhumika Goyal | b893e34 | 2017-01-28 13:11:17 +0530 | [diff] [blame] | 83 | static const struct watchdog_ops ep93xx_wdt_ops = { |
H Hartley Sweeten | e12a679 | 2012-03-14 10:31:50 -0700 | [diff] [blame] | 84 | .owner = THIS_MODULE, |
| 85 | .start = ep93xx_wdt_start, |
| 86 | .stop = ep93xx_wdt_stop, |
H Hartley Sweeten | 9170036 | 2017-01-31 09:33:29 -0700 | [diff] [blame] | 87 | .ping = ep93xx_wdt_ping, |
H Hartley Sweeten | e12a679 | 2012-03-14 10:31:50 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
Bill Pemberton | 2d991a1 | 2012-11-19 13:21:41 -0500 | [diff] [blame] | 90 | static int ep93xx_wdt_probe(struct platform_device *pdev) |
Alessandro Zummo | f52ac8f | 2006-03-25 03:06:37 -0800 | [diff] [blame] | 91 | { |
H Hartley Sweeten | 9170036 | 2017-01-31 09:33:29 -0700 | [diff] [blame] | 92 | struct ep93xx_wdt_priv *priv; |
| 93 | struct watchdog_device *wdd; |
H Hartley Sweeten | 3e0113a | 2012-03-13 09:48:16 +1100 | [diff] [blame] | 94 | struct resource *res; |
| 95 | unsigned long val; |
H Hartley Sweeten | 9170036 | 2017-01-31 09:33:29 -0700 | [diff] [blame] | 96 | int ret; |
| 97 | |
| 98 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
| 99 | if (!priv) |
| 100 | return -ENOMEM; |
Alessandro Zummo | f52ac8f | 2006-03-25 03:06:37 -0800 | [diff] [blame] | 101 | |
H Hartley Sweeten | 3e0113a | 2012-03-13 09:48:16 +1100 | [diff] [blame] | 102 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
H Hartley Sweeten | 9170036 | 2017-01-31 09:33:29 -0700 | [diff] [blame] | 103 | priv->mmio = devm_ioremap_resource(&pdev->dev, res); |
| 104 | if (IS_ERR(priv->mmio)) |
| 105 | return PTR_ERR(priv->mmio); |
H Hartley Sweeten | 3e0113a | 2012-03-13 09:48:16 +1100 | [diff] [blame] | 106 | |
H Hartley Sweeten | 9170036 | 2017-01-31 09:33:29 -0700 | [diff] [blame] | 107 | val = readl(priv->mmio + EP93XX_WATCHDOG); |
Alessandro Zummo | f52ac8f | 2006-03-25 03:06:37 -0800 | [diff] [blame] | 108 | |
H Hartley Sweeten | 9170036 | 2017-01-31 09:33:29 -0700 | [diff] [blame] | 109 | 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 Sebroeck | 697b41e | 2012-03-13 09:06:12 +0100 | [diff] [blame] | 116 | |
H Hartley Sweeten | 9170036 | 2017-01-31 09:33:29 -0700 | [diff] [blame] | 117 | watchdog_set_nowayout(wdd, nowayout); |
Wim Van Sebroeck | 697b41e | 2012-03-13 09:06:12 +0100 | [diff] [blame] | 118 | |
H Hartley Sweeten | 9170036 | 2017-01-31 09:33:29 -0700 | [diff] [blame] | 119 | wdd->timeout = WDT_TIMEOUT; |
| 120 | watchdog_init_timeout(wdd, timeout, &pdev->dev); |
Wim Van Sebroeck | 697b41e | 2012-03-13 09:06:12 +0100 | [diff] [blame] | 121 | |
H Hartley Sweeten | 9170036 | 2017-01-31 09:33:29 -0700 | [diff] [blame] | 122 | watchdog_set_drvdata(wdd, priv); |
H Hartley Sweeten | e12a679 | 2012-03-14 10:31:50 -0700 | [diff] [blame] | 123 | |
H Hartley Sweeten | 9170036 | 2017-01-31 09:33:29 -0700 | [diff] [blame] | 124 | 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 Sebroeck | 697b41e | 2012-03-13 09:06:12 +0100 | [diff] [blame] | 129 | (val & 0x08) ? " (nCS1 disable detected)" : ""); |
H Hartley Sweeten | e12a679 | 2012-03-14 10:31:50 -0700 | [diff] [blame] | 130 | |
| 131 | return 0; |
Alessandro Zummo | f52ac8f | 2006-03-25 03:06:37 -0800 | [diff] [blame] | 132 | } |
| 133 | |
H Hartley Sweeten | 3e0113a | 2012-03-13 09:48:16 +1100 | [diff] [blame] | 134 | static struct platform_driver ep93xx_wdt_driver = { |
| 135 | .driver = { |
H Hartley Sweeten | 3e0113a | 2012-03-13 09:48:16 +1100 | [diff] [blame] | 136 | .name = "ep93xx-wdt", |
| 137 | }, |
| 138 | .probe = ep93xx_wdt_probe, |
H Hartley Sweeten | 3e0113a | 2012-03-13 09:48:16 +1100 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | module_platform_driver(ep93xx_wdt_driver); |
Alessandro Zummo | f52ac8f | 2006-03-25 03:06:37 -0800 | [diff] [blame] | 142 | |
Jingoo Han | 5f5e190 | 2014-02-27 14:41:42 +0900 | [diff] [blame] | 143 | MODULE_AUTHOR("Ray Lehtiniemi <rayl@mail.com>"); |
| 144 | MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>"); |
| 145 | MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>"); |
Alessandro Zummo | f52ac8f | 2006-03-25 03:06:37 -0800 | [diff] [blame] | 146 | MODULE_DESCRIPTION("EP93xx Watchdog"); |
| 147 | MODULE_LICENSE("GPL"); |