Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 1 | /* |
Felipe Balbi | 2817142 | 2008-09-20 04:14:01 +0300 | [diff] [blame] | 2 | * omap_wdt.c |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 3 | * |
Felipe Balbi | 2817142 | 2008-09-20 04:14:01 +0300 | [diff] [blame] | 4 | * Watchdog driver for the TI OMAP 16xx & 24xx/34xx 32KHz (non-secure) watchdog |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 5 | * |
| 6 | * Author: MontaVista Software, Inc. |
| 7 | * <gdavis@mvista.com> or <source@mvista.com> |
| 8 | * |
| 9 | * 2003 (c) MontaVista Software, Inc. This file is licensed under the |
| 10 | * terms of the GNU General Public License version 2. This program is |
| 11 | * licensed "as is" without any warranty of any kind, whether express |
| 12 | * or implied. |
| 13 | * |
| 14 | * History: |
| 15 | * |
| 16 | * 20030527: George G. Davis <gdavis@mvista.com> |
| 17 | * Initially based on linux-2.4.19-rmk7-pxa1/drivers/char/sa1100_wdt.c |
| 18 | * (c) Copyright 2000 Oleg Drokin <green@crimea.edu> |
Alan Cox | 29fa058 | 2008-10-27 15:17:56 +0000 | [diff] [blame] | 19 | * Based on SoftDog driver by Alan Cox <alan@lxorguk.ukuu.org.uk> |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 20 | * |
| 21 | * Copyright (c) 2004 Texas Instruments. |
| 22 | * 1. Modified to support OMAP1610 32-KHz watchdog timer |
| 23 | * 2. Ported to 2.6 kernel |
| 24 | * |
| 25 | * Copyright (c) 2005 David Brownell |
| 26 | * Use the driver model and standard identifiers; handle bigger timeouts. |
| 27 | */ |
| 28 | |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 29 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 30 | |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 31 | #include <linux/module.h> |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 32 | #include <linux/types.h> |
| 33 | #include <linux/kernel.h> |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 34 | #include <linux/mm.h> |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 35 | #include <linux/watchdog.h> |
| 36 | #include <linux/reboot.h> |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 37 | #include <linux/err.h> |
| 38 | #include <linux/platform_device.h> |
| 39 | #include <linux/moduleparam.h> |
Wim Van Sebroeck | 089ab07 | 2008-07-15 11:46:11 +0000 | [diff] [blame] | 40 | #include <linux/io.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 41 | #include <linux/slab.h> |
Varadarajan, Charulatha | 7ec5ad0 | 2010-09-23 20:02:43 +0530 | [diff] [blame] | 42 | #include <linux/pm_runtime.h> |
Paul Walmsley | 129f557 | 2012-10-29 20:49:44 -0600 | [diff] [blame] | 43 | #include <linux/platform_data/omap-wd-timer.h> |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 44 | |
| 45 | #include "omap_wdt.h" |
| 46 | |
Pali Rohár | 2dd7b24 | 2013-02-17 00:49:26 +0100 | [diff] [blame] | 47 | static bool nowayout = WATCHDOG_NOWAYOUT; |
| 48 | module_param(nowayout, bool, 0); |
| 49 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started " |
| 50 | "(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
| 51 | |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 52 | static unsigned timer_margin; |
| 53 | module_param(timer_margin, uint, 0); |
| 54 | MODULE_PARM_DESC(timer_margin, "initial watchdog timeout (in seconds)"); |
| 55 | |
Felipe Balbi | 2817142 | 2008-09-20 04:14:01 +0300 | [diff] [blame] | 56 | struct omap_wdt_dev { |
| 57 | void __iomem *base; /* physical */ |
| 58 | struct device *dev; |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 59 | bool omap_wdt_users; |
Felipe Balbi | 2817142 | 2008-09-20 04:14:01 +0300 | [diff] [blame] | 60 | struct resource *mem; |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 61 | int wdt_trgr_pattern; |
| 62 | struct mutex lock; /* to avoid races with PM */ |
Felipe Balbi | 2817142 | 2008-09-20 04:14:01 +0300 | [diff] [blame] | 63 | }; |
| 64 | |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 65 | static void omap_wdt_reload(struct omap_wdt_dev *wdev) |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 66 | { |
Felipe Balbi | 2817142 | 2008-09-20 04:14:01 +0300 | [diff] [blame] | 67 | void __iomem *base = wdev->base; |
Felipe Balbi | b311218 | 2008-09-20 04:14:03 +0300 | [diff] [blame] | 68 | |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 69 | /* wait for posted write to complete */ |
Victor Kamensky | 4a7e94a | 2013-11-16 02:01:05 +0200 | [diff] [blame] | 70 | while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x08) |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 71 | cpu_relax(); |
Felipe Balbi | b311218 | 2008-09-20 04:14:03 +0300 | [diff] [blame] | 72 | |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 73 | wdev->wdt_trgr_pattern = ~wdev->wdt_trgr_pattern; |
Victor Kamensky | 4a7e94a | 2013-11-16 02:01:05 +0200 | [diff] [blame] | 74 | writel_relaxed(wdev->wdt_trgr_pattern, (base + OMAP_WATCHDOG_TGR)); |
Felipe Balbi | b311218 | 2008-09-20 04:14:03 +0300 | [diff] [blame] | 75 | |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 76 | /* wait for posted write to complete */ |
Victor Kamensky | 4a7e94a | 2013-11-16 02:01:05 +0200 | [diff] [blame] | 77 | while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x08) |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 78 | cpu_relax(); |
| 79 | /* reloaded WCRR from WLDR */ |
| 80 | } |
| 81 | |
Felipe Balbi | 2817142 | 2008-09-20 04:14:01 +0300 | [diff] [blame] | 82 | static void omap_wdt_enable(struct omap_wdt_dev *wdev) |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 83 | { |
Felipe Balbi | b311218 | 2008-09-20 04:14:03 +0300 | [diff] [blame] | 84 | void __iomem *base = wdev->base; |
| 85 | |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 86 | /* Sequence to enable the watchdog */ |
Victor Kamensky | 4a7e94a | 2013-11-16 02:01:05 +0200 | [diff] [blame] | 87 | writel_relaxed(0xBBBB, base + OMAP_WATCHDOG_SPR); |
| 88 | while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x10) |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 89 | cpu_relax(); |
Felipe Balbi | b311218 | 2008-09-20 04:14:03 +0300 | [diff] [blame] | 90 | |
Victor Kamensky | 4a7e94a | 2013-11-16 02:01:05 +0200 | [diff] [blame] | 91 | writel_relaxed(0x4444, base + OMAP_WATCHDOG_SPR); |
| 92 | while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x10) |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 93 | cpu_relax(); |
| 94 | } |
| 95 | |
Felipe Balbi | 2817142 | 2008-09-20 04:14:01 +0300 | [diff] [blame] | 96 | static void omap_wdt_disable(struct omap_wdt_dev *wdev) |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 97 | { |
Felipe Balbi | b311218 | 2008-09-20 04:14:03 +0300 | [diff] [blame] | 98 | void __iomem *base = wdev->base; |
| 99 | |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 100 | /* sequence required to disable watchdog */ |
Victor Kamensky | 4a7e94a | 2013-11-16 02:01:05 +0200 | [diff] [blame] | 101 | writel_relaxed(0xAAAA, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */ |
| 102 | while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x10) |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 103 | cpu_relax(); |
Felipe Balbi | b311218 | 2008-09-20 04:14:03 +0300 | [diff] [blame] | 104 | |
Victor Kamensky | 4a7e94a | 2013-11-16 02:01:05 +0200 | [diff] [blame] | 105 | writel_relaxed(0x5555, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */ |
| 106 | while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x10) |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 107 | cpu_relax(); |
| 108 | } |
| 109 | |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 110 | static void omap_wdt_set_timer(struct omap_wdt_dev *wdev, |
| 111 | unsigned int timeout) |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 112 | { |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 113 | u32 pre_margin = GET_WLDR_VAL(timeout); |
Felipe Balbi | b311218 | 2008-09-20 04:14:03 +0300 | [diff] [blame] | 114 | void __iomem *base = wdev->base; |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 115 | |
| 116 | /* just count up at 32 KHz */ |
Victor Kamensky | 4a7e94a | 2013-11-16 02:01:05 +0200 | [diff] [blame] | 117 | while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x04) |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 118 | cpu_relax(); |
Felipe Balbi | b311218 | 2008-09-20 04:14:03 +0300 | [diff] [blame] | 119 | |
Victor Kamensky | 4a7e94a | 2013-11-16 02:01:05 +0200 | [diff] [blame] | 120 | writel_relaxed(pre_margin, base + OMAP_WATCHDOG_LDR); |
| 121 | while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x04) |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 122 | cpu_relax(); |
| 123 | } |
| 124 | |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 125 | static int omap_wdt_start(struct watchdog_device *wdog) |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 126 | { |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 127 | struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog); |
Felipe Balbi | b311218 | 2008-09-20 04:14:03 +0300 | [diff] [blame] | 128 | void __iomem *base = wdev->base; |
| 129 | |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 130 | mutex_lock(&wdev->lock); |
| 131 | |
| 132 | wdev->omap_wdt_users = true; |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 133 | |
Varadarajan, Charulatha | 7ec5ad0 | 2010-09-23 20:02:43 +0530 | [diff] [blame] | 134 | pm_runtime_get_sync(wdev->dev); |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 135 | |
| 136 | /* initialize prescaler */ |
Victor Kamensky | 4a7e94a | 2013-11-16 02:01:05 +0200 | [diff] [blame] | 137 | while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x01) |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 138 | cpu_relax(); |
Felipe Balbi | b311218 | 2008-09-20 04:14:03 +0300 | [diff] [blame] | 139 | |
Victor Kamensky | 4a7e94a | 2013-11-16 02:01:05 +0200 | [diff] [blame] | 140 | writel_relaxed((1 << 5) | (PTV << 2), base + OMAP_WATCHDOG_CNTRL); |
| 141 | while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x01) |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 142 | cpu_relax(); |
| 143 | |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 144 | omap_wdt_set_timer(wdev, wdog->timeout); |
| 145 | omap_wdt_reload(wdev); /* trigger loading of new timeout value */ |
Felipe Balbi | 2817142 | 2008-09-20 04:14:01 +0300 | [diff] [blame] | 146 | omap_wdt_enable(wdev); |
Felipe Balbi | b311218 | 2008-09-20 04:14:03 +0300 | [diff] [blame] | 147 | |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 148 | mutex_unlock(&wdev->lock); |
Felipe Balbi | b311218 | 2008-09-20 04:14:03 +0300 | [diff] [blame] | 149 | |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 150 | return 0; |
| 151 | } |
| 152 | |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 153 | static int omap_wdt_stop(struct watchdog_device *wdog) |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 154 | { |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 155 | struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog); |
Felipe Balbi | b311218 | 2008-09-20 04:14:03 +0300 | [diff] [blame] | 156 | |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 157 | mutex_lock(&wdev->lock); |
| 158 | omap_wdt_disable(wdev); |
| 159 | pm_runtime_put_sync(wdev->dev); |
| 160 | wdev->omap_wdt_users = false; |
| 161 | mutex_unlock(&wdev->lock); |
| 162 | return 0; |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 165 | static int omap_wdt_ping(struct watchdog_device *wdog) |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 166 | { |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 167 | struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog); |
Felipe Balbi | b311218 | 2008-09-20 04:14:03 +0300 | [diff] [blame] | 168 | |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 169 | mutex_lock(&wdev->lock); |
| 170 | omap_wdt_reload(wdev); |
| 171 | mutex_unlock(&wdev->lock); |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 172 | |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 173 | return 0; |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 176 | static int omap_wdt_set_timeout(struct watchdog_device *wdog, |
| 177 | unsigned int timeout) |
| 178 | { |
| 179 | struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog); |
| 180 | |
| 181 | mutex_lock(&wdev->lock); |
| 182 | omap_wdt_disable(wdev); |
| 183 | omap_wdt_set_timer(wdev, timeout); |
| 184 | omap_wdt_enable(wdev); |
| 185 | omap_wdt_reload(wdev); |
| 186 | wdog->timeout = timeout; |
| 187 | mutex_unlock(&wdev->lock); |
| 188 | |
| 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | static const struct watchdog_info omap_wdt_info = { |
| 193 | .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING, |
| 194 | .identity = "OMAP Watchdog", |
| 195 | }; |
| 196 | |
| 197 | static const struct watchdog_ops omap_wdt_ops = { |
| 198 | .owner = THIS_MODULE, |
| 199 | .start = omap_wdt_start, |
| 200 | .stop = omap_wdt_stop, |
| 201 | .ping = omap_wdt_ping, |
| 202 | .set_timeout = omap_wdt_set_timeout, |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 203 | }; |
| 204 | |
Bill Pemberton | 2d991a1 | 2012-11-19 13:21:41 -0500 | [diff] [blame] | 205 | static int omap_wdt_probe(struct platform_device *pdev) |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 206 | { |
Jingoo Han | bc8fdfb | 2013-07-30 19:58:51 +0900 | [diff] [blame] | 207 | struct omap_wd_timer_platform_data *pdata = dev_get_platdata(&pdev->dev); |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 208 | struct watchdog_device *omap_wdt; |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 209 | struct resource *res, *mem; |
Felipe Balbi | 2817142 | 2008-09-20 04:14:01 +0300 | [diff] [blame] | 210 | struct omap_wdt_dev *wdev; |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 211 | u32 rs; |
Felipe Balbi | b311218 | 2008-09-20 04:14:03 +0300 | [diff] [blame] | 212 | int ret; |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 213 | |
Aaro Koskinen | 4f4753d | 2012-10-10 23:23:33 +0300 | [diff] [blame] | 214 | omap_wdt = devm_kzalloc(&pdev->dev, sizeof(*omap_wdt), GFP_KERNEL); |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 215 | if (!omap_wdt) |
| 216 | return -ENOMEM; |
| 217 | |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 218 | /* reserve static register mappings */ |
| 219 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Aaro Koskinen | 4f4753d | 2012-10-10 23:23:33 +0300 | [diff] [blame] | 220 | if (!res) |
| 221 | return -ENOENT; |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 222 | |
Aaro Koskinen | 4f4753d | 2012-10-10 23:23:33 +0300 | [diff] [blame] | 223 | mem = devm_request_mem_region(&pdev->dev, res->start, |
| 224 | resource_size(res), pdev->name); |
| 225 | if (!mem) |
| 226 | return -EBUSY; |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 227 | |
Aaro Koskinen | 4f4753d | 2012-10-10 23:23:33 +0300 | [diff] [blame] | 228 | wdev = devm_kzalloc(&pdev->dev, sizeof(*wdev), GFP_KERNEL); |
| 229 | if (!wdev) |
| 230 | return -ENOMEM; |
Felipe Balbi | b311218 | 2008-09-20 04:14:03 +0300 | [diff] [blame] | 231 | |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 232 | wdev->omap_wdt_users = false; |
| 233 | wdev->mem = mem; |
| 234 | wdev->dev = &pdev->dev; |
| 235 | wdev->wdt_trgr_pattern = 0x1234; |
| 236 | mutex_init(&wdev->lock); |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 237 | |
Aaro Koskinen | 4f4753d | 2012-10-10 23:23:33 +0300 | [diff] [blame] | 238 | wdev->base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); |
| 239 | if (!wdev->base) |
| 240 | return -ENOMEM; |
Felipe Balbi | 9f69e3b | 2008-09-20 04:14:02 +0300 | [diff] [blame] | 241 | |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 242 | omap_wdt->info = &omap_wdt_info; |
| 243 | omap_wdt->ops = &omap_wdt_ops; |
| 244 | omap_wdt->min_timeout = TIMER_MARGIN_MIN; |
| 245 | omap_wdt->max_timeout = TIMER_MARGIN_MAX; |
| 246 | |
| 247 | if (timer_margin >= TIMER_MARGIN_MIN && |
| 248 | timer_margin <= TIMER_MARGIN_MAX) |
| 249 | omap_wdt->timeout = timer_margin; |
| 250 | else |
| 251 | omap_wdt->timeout = TIMER_MARGIN_DEFAULT; |
| 252 | |
| 253 | watchdog_set_drvdata(omap_wdt, wdev); |
| 254 | watchdog_set_nowayout(omap_wdt, nowayout); |
| 255 | |
| 256 | platform_set_drvdata(pdev, omap_wdt); |
Felipe Balbi | 2817142 | 2008-09-20 04:14:01 +0300 | [diff] [blame] | 257 | |
Varadarajan, Charulatha | 7ec5ad0 | 2010-09-23 20:02:43 +0530 | [diff] [blame] | 258 | pm_runtime_enable(wdev->dev); |
| 259 | pm_runtime_get_sync(wdev->dev); |
Ulrik Bech Hald | 789cd47 | 2009-06-12 16:18:32 -0500 | [diff] [blame] | 260 | |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 261 | if (pdata && pdata->read_reset_sources) |
| 262 | rs = pdata->read_reset_sources(); |
| 263 | else |
| 264 | rs = 0; |
| 265 | omap_wdt->bootstatus = (rs & (1 << OMAP_MPU_WD_RST_SRC_ID_SHIFT)) ? |
| 266 | WDIOF_CARDRESET : 0; |
| 267 | |
Felipe Balbi | 2817142 | 2008-09-20 04:14:01 +0300 | [diff] [blame] | 268 | omap_wdt_disable(wdev); |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 269 | |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 270 | ret = watchdog_register_device(omap_wdt); |
Aaro Koskinen | 1ba8538 | 2012-10-10 23:23:37 +0300 | [diff] [blame] | 271 | if (ret) { |
| 272 | pm_runtime_disable(wdev->dev); |
| 273 | return ret; |
| 274 | } |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 275 | |
Felipe Balbi | 2817142 | 2008-09-20 04:14:01 +0300 | [diff] [blame] | 276 | pr_info("OMAP Watchdog Timer Rev 0x%02x: initial timeout %d sec\n", |
Victor Kamensky | 4a7e94a | 2013-11-16 02:01:05 +0200 | [diff] [blame] | 277 | readl_relaxed(wdev->base + OMAP_WATCHDOG_REV) & 0xFF, |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 278 | omap_wdt->timeout); |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 279 | |
Varadarajan, Charulatha | 7ec5ad0 | 2010-09-23 20:02:43 +0530 | [diff] [blame] | 280 | pm_runtime_put_sync(wdev->dev); |
Ulrik Bech Hald | 789cd47 | 2009-06-12 16:18:32 -0500 | [diff] [blame] | 281 | |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 282 | return 0; |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | static void omap_wdt_shutdown(struct platform_device *pdev) |
| 286 | { |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 287 | struct watchdog_device *wdog = platform_get_drvdata(pdev); |
| 288 | struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog); |
Felipe Balbi | 2817142 | 2008-09-20 04:14:01 +0300 | [diff] [blame] | 289 | |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 290 | mutex_lock(&wdev->lock); |
Paul Walmsley | 0503add | 2011-03-10 22:40:05 -0700 | [diff] [blame] | 291 | if (wdev->omap_wdt_users) { |
Felipe Balbi | 2817142 | 2008-09-20 04:14:01 +0300 | [diff] [blame] | 292 | omap_wdt_disable(wdev); |
Paul Walmsley | 0503add | 2011-03-10 22:40:05 -0700 | [diff] [blame] | 293 | pm_runtime_put_sync(wdev->dev); |
| 294 | } |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 295 | mutex_unlock(&wdev->lock); |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Bill Pemberton | 4b12b89 | 2012-11-19 13:26:24 -0500 | [diff] [blame] | 298 | static int omap_wdt_remove(struct platform_device *pdev) |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 299 | { |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 300 | struct watchdog_device *wdog = platform_get_drvdata(pdev); |
| 301 | struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog); |
Felipe Balbi | 2817142 | 2008-09-20 04:14:01 +0300 | [diff] [blame] | 302 | |
Shubhrajyoti D | 12c583d | 2012-01-11 19:50:18 +0530 | [diff] [blame] | 303 | pm_runtime_disable(wdev->dev); |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 304 | watchdog_unregister_device(wdog); |
Felipe Balbi | b311218 | 2008-09-20 04:14:03 +0300 | [diff] [blame] | 305 | |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 306 | return 0; |
| 307 | } |
| 308 | |
| 309 | #ifdef CONFIG_PM |
| 310 | |
| 311 | /* REVISIT ... not clear this is the best way to handle system suspend; and |
| 312 | * it's very inappropriate for selective device suspend (e.g. suspending this |
| 313 | * through sysfs rather than by stopping the watchdog daemon). Also, this |
| 314 | * may not play well enough with NOWAYOUT... |
| 315 | */ |
| 316 | |
| 317 | static int omap_wdt_suspend(struct platform_device *pdev, pm_message_t state) |
| 318 | { |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 319 | struct watchdog_device *wdog = platform_get_drvdata(pdev); |
| 320 | struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog); |
Felipe Balbi | b311218 | 2008-09-20 04:14:03 +0300 | [diff] [blame] | 321 | |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 322 | mutex_lock(&wdev->lock); |
Paul Walmsley | 0503add | 2011-03-10 22:40:05 -0700 | [diff] [blame] | 323 | if (wdev->omap_wdt_users) { |
Felipe Balbi | 2817142 | 2008-09-20 04:14:01 +0300 | [diff] [blame] | 324 | omap_wdt_disable(wdev); |
Paul Walmsley | 0503add | 2011-03-10 22:40:05 -0700 | [diff] [blame] | 325 | pm_runtime_put_sync(wdev->dev); |
| 326 | } |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 327 | mutex_unlock(&wdev->lock); |
Felipe Balbi | b311218 | 2008-09-20 04:14:03 +0300 | [diff] [blame] | 328 | |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | static int omap_wdt_resume(struct platform_device *pdev) |
| 333 | { |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 334 | struct watchdog_device *wdog = platform_get_drvdata(pdev); |
| 335 | struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog); |
Felipe Balbi | b311218 | 2008-09-20 04:14:03 +0300 | [diff] [blame] | 336 | |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 337 | mutex_lock(&wdev->lock); |
Felipe Balbi | 2817142 | 2008-09-20 04:14:01 +0300 | [diff] [blame] | 338 | if (wdev->omap_wdt_users) { |
Paul Walmsley | 0503add | 2011-03-10 22:40:05 -0700 | [diff] [blame] | 339 | pm_runtime_get_sync(wdev->dev); |
Felipe Balbi | 2817142 | 2008-09-20 04:14:01 +0300 | [diff] [blame] | 340 | omap_wdt_enable(wdev); |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 341 | omap_wdt_reload(wdev); |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 342 | } |
Aaro Koskinen | 67c0f55 | 2012-10-10 23:23:32 +0300 | [diff] [blame] | 343 | mutex_unlock(&wdev->lock); |
Felipe Balbi | b311218 | 2008-09-20 04:14:03 +0300 | [diff] [blame] | 344 | |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | #else |
| 349 | #define omap_wdt_suspend NULL |
| 350 | #define omap_wdt_resume NULL |
| 351 | #endif |
| 352 | |
Xiao Jiang | e6ca04e | 2012-06-01 12:44:16 +0800 | [diff] [blame] | 353 | static const struct of_device_id omap_wdt_of_match[] = { |
| 354 | { .compatible = "ti,omap3-wdt", }, |
| 355 | {}, |
| 356 | }; |
| 357 | MODULE_DEVICE_TABLE(of, omap_wdt_of_match); |
| 358 | |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 359 | static struct platform_driver omap_wdt_driver = { |
| 360 | .probe = omap_wdt_probe, |
Bill Pemberton | 8226871 | 2012-11-19 13:21:12 -0500 | [diff] [blame] | 361 | .remove = omap_wdt_remove, |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 362 | .shutdown = omap_wdt_shutdown, |
| 363 | .suspend = omap_wdt_suspend, |
| 364 | .resume = omap_wdt_resume, |
| 365 | .driver = { |
| 366 | .owner = THIS_MODULE, |
| 367 | .name = "omap_wdt", |
Xiao Jiang | e6ca04e | 2012-06-01 12:44:16 +0800 | [diff] [blame] | 368 | .of_match_table = omap_wdt_of_match, |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 369 | }, |
| 370 | }; |
| 371 | |
Axel Lin | b8ec611 | 2011-11-29 13:56:27 +0800 | [diff] [blame] | 372 | module_platform_driver(omap_wdt_driver); |
Komal Shah | 7768a13 | 2006-09-29 01:59:18 -0700 | [diff] [blame] | 373 | |
| 374 | MODULE_AUTHOR("George G. Davis"); |
| 375 | MODULE_LICENSE("GPL"); |
Kay Sievers | f37d193 | 2008-04-10 21:29:23 -0700 | [diff] [blame] | 376 | MODULE_ALIAS("platform:omap_wdt"); |