Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* linux/drivers/char/watchdog/s3c2410_wdt.c |
| 2 | * |
| 3 | * Copyright (c) 2004 Simtec Electronics |
| 4 | * Ben Dooks <ben@simtec.co.uk> |
| 5 | * |
| 6 | * S3C2410 Watchdog Timer Support |
| 7 | * |
| 8 | * Based on, softdog.c by Alan Cox, |
Alan Cox | 29fa058 | 2008-10-27 15:17:56 +0000 | [diff] [blame] | 9 | * (c) Copyright 1996 Alan Cox <alan@lxorguk.ukuu.org.uk> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | */ |
| 25 | |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 26 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/module.h> |
| 29 | #include <linux/moduleparam.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/types.h> |
| 31 | #include <linux/timer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/watchdog.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/init.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 34 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/interrupt.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 36 | #include <linux/clk.h> |
Alan Cox | 41dc8b7 | 2008-08-04 17:54:46 +0100 | [diff] [blame] | 37 | #include <linux/uaccess.h> |
| 38 | #include <linux/io.h> |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 39 | #include <linux/cpufreq.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 40 | #include <linux/slab.h> |
Wolfram Sang | 25dc46e | 2011-09-26 15:40:14 +0200 | [diff] [blame] | 41 | #include <linux/err.h> |
Wim Van Sebroeck | 3016a55 | 2012-05-03 05:24:17 +0000 | [diff] [blame] | 42 | #include <linux/of.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Tomasz Figa | a8f5401 | 2013-06-17 23:45:24 +0900 | [diff] [blame] | 44 | #define S3C2410_WTCON 0x00 |
| 45 | #define S3C2410_WTDAT 0x04 |
| 46 | #define S3C2410_WTCNT 0x08 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Tomasz Figa | a8f5401 | 2013-06-17 23:45:24 +0900 | [diff] [blame] | 48 | #define S3C2410_WTCON_RSTEN (1 << 0) |
| 49 | #define S3C2410_WTCON_INTEN (1 << 2) |
| 50 | #define S3C2410_WTCON_ENABLE (1 << 5) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Tomasz Figa | a8f5401 | 2013-06-17 23:45:24 +0900 | [diff] [blame] | 52 | #define S3C2410_WTCON_DIV16 (0 << 3) |
| 53 | #define S3C2410_WTCON_DIV32 (1 << 3) |
| 54 | #define S3C2410_WTCON_DIV64 (2 << 3) |
| 55 | #define S3C2410_WTCON_DIV128 (3 << 3) |
| 56 | |
| 57 | #define S3C2410_WTCON_PRESCALE(x) ((x) << 8) |
| 58 | #define S3C2410_WTCON_PRESCALE_MASK (0xff << 8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #define CONFIG_S3C2410_WATCHDOG_ATBOOT (0) |
| 61 | #define CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME (15) |
| 62 | |
Wim Van Sebroeck | 86a1e18 | 2012-03-05 16:51:11 +0100 | [diff] [blame] | 63 | static bool nowayout = WATCHDOG_NOWAYOUT; |
Fabio Porcedda | c1fd5f6 | 2013-02-14 09:14:25 +0100 | [diff] [blame] | 64 | static int tmr_margin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | static int tmr_atboot = CONFIG_S3C2410_WATCHDOG_ATBOOT; |
Alan Cox | 41dc8b7 | 2008-08-04 17:54:46 +0100 | [diff] [blame] | 66 | static int soft_noboot; |
| 67 | static int debug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | module_param(tmr_margin, int, 0); |
| 70 | module_param(tmr_atboot, int, 0); |
Wim Van Sebroeck | 86a1e18 | 2012-03-05 16:51:11 +0100 | [diff] [blame] | 71 | module_param(nowayout, bool, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | module_param(soft_noboot, int, 0); |
| 73 | module_param(debug, int, 0); |
| 74 | |
Randy Dunlap | 76550d3 | 2010-05-01 09:46:15 -0700 | [diff] [blame] | 75 | MODULE_PARM_DESC(tmr_margin, "Watchdog tmr_margin in seconds. (default=" |
Alan Cox | 41dc8b7 | 2008-08-04 17:54:46 +0100 | [diff] [blame] | 76 | __MODULE_STRING(CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME) ")"); |
| 77 | MODULE_PARM_DESC(tmr_atboot, |
| 78 | "Watchdog is started at boot time if set to 1, default=" |
| 79 | __MODULE_STRING(CONFIG_S3C2410_WATCHDOG_ATBOOT)); |
| 80 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" |
| 81 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
Wim Van Sebroeck | a77dba7 | 2009-04-14 20:20:07 +0000 | [diff] [blame] | 82 | MODULE_PARM_DESC(soft_noboot, "Watchdog action, set to 1 to ignore reboots, " |
Randy Dunlap | 76550d3 | 2010-05-01 09:46:15 -0700 | [diff] [blame] | 83 | "0 to reboot (default 0)"); |
| 84 | MODULE_PARM_DESC(debug, "Watchdog debug, set to >1 for debug (default 0)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 86 | struct s3c2410_wdt { |
| 87 | struct device *dev; |
| 88 | struct clk *clock; |
| 89 | void __iomem *reg_base; |
| 90 | unsigned int count; |
| 91 | spinlock_t lock; |
| 92 | unsigned long wtcon_save; |
| 93 | unsigned long wtdat_save; |
| 94 | struct watchdog_device wdt_device; |
| 95 | struct notifier_block freq_transition; |
| 96 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
| 98 | /* watchdog control routines */ |
| 99 | |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 100 | #define DBG(fmt, ...) \ |
| 101 | do { \ |
| 102 | if (debug) \ |
| 103 | pr_info(fmt, ##__VA_ARGS__); \ |
| 104 | } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | /* functions */ |
| 107 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 108 | static inline struct s3c2410_wdt *freq_to_wdt(struct notifier_block *nb) |
| 109 | { |
| 110 | return container_of(nb, struct s3c2410_wdt, freq_transition); |
| 111 | } |
| 112 | |
Wolfram Sang | 25dc46e | 2011-09-26 15:40:14 +0200 | [diff] [blame] | 113 | static int s3c2410wdt_keepalive(struct watchdog_device *wdd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 115 | struct s3c2410_wdt *wdt = watchdog_get_drvdata(wdd); |
| 116 | |
| 117 | spin_lock(&wdt->lock); |
| 118 | writel(wdt->count, wdt->reg_base + S3C2410_WTCNT); |
| 119 | spin_unlock(&wdt->lock); |
Wolfram Sang | 25dc46e | 2011-09-26 15:40:14 +0200 | [diff] [blame] | 120 | |
| 121 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 124 | static void __s3c2410wdt_stop(struct s3c2410_wdt *wdt) |
Alan Cox | 41dc8b7 | 2008-08-04 17:54:46 +0100 | [diff] [blame] | 125 | { |
| 126 | unsigned long wtcon; |
| 127 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 128 | wtcon = readl(wdt->reg_base + S3C2410_WTCON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | wtcon &= ~(S3C2410_WTCON_ENABLE | S3C2410_WTCON_RSTEN); |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 130 | writel(wtcon, wdt->reg_base + S3C2410_WTCON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Wolfram Sang | 25dc46e | 2011-09-26 15:40:14 +0200 | [diff] [blame] | 133 | static int s3c2410wdt_stop(struct watchdog_device *wdd) |
Alan Cox | 41dc8b7 | 2008-08-04 17:54:46 +0100 | [diff] [blame] | 134 | { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 135 | struct s3c2410_wdt *wdt = watchdog_get_drvdata(wdd); |
| 136 | |
| 137 | spin_lock(&wdt->lock); |
| 138 | __s3c2410wdt_stop(wdt); |
| 139 | spin_unlock(&wdt->lock); |
Wolfram Sang | 25dc46e | 2011-09-26 15:40:14 +0200 | [diff] [blame] | 140 | |
| 141 | return 0; |
Alan Cox | 41dc8b7 | 2008-08-04 17:54:46 +0100 | [diff] [blame] | 142 | } |
| 143 | |
Wolfram Sang | 25dc46e | 2011-09-26 15:40:14 +0200 | [diff] [blame] | 144 | static int s3c2410wdt_start(struct watchdog_device *wdd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | { |
| 146 | unsigned long wtcon; |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 147 | struct s3c2410_wdt *wdt = watchdog_get_drvdata(wdd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 149 | spin_lock(&wdt->lock); |
Alan Cox | 41dc8b7 | 2008-08-04 17:54:46 +0100 | [diff] [blame] | 150 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 151 | __s3c2410wdt_stop(wdt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 153 | wtcon = readl(wdt->reg_base + S3C2410_WTCON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | wtcon |= S3C2410_WTCON_ENABLE | S3C2410_WTCON_DIV128; |
| 155 | |
| 156 | if (soft_noboot) { |
| 157 | wtcon |= S3C2410_WTCON_INTEN; |
| 158 | wtcon &= ~S3C2410_WTCON_RSTEN; |
| 159 | } else { |
| 160 | wtcon &= ~S3C2410_WTCON_INTEN; |
| 161 | wtcon |= S3C2410_WTCON_RSTEN; |
| 162 | } |
| 163 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 164 | DBG("%s: count=0x%08x, wtcon=%08lx\n", |
| 165 | __func__, wdt->count, wtcon); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 167 | writel(wdt->count, wdt->reg_base + S3C2410_WTDAT); |
| 168 | writel(wdt->count, wdt->reg_base + S3C2410_WTCNT); |
| 169 | writel(wtcon, wdt->reg_base + S3C2410_WTCON); |
| 170 | spin_unlock(&wdt->lock); |
Wolfram Sang | 25dc46e | 2011-09-26 15:40:14 +0200 | [diff] [blame] | 171 | |
| 172 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 175 | static inline int s3c2410wdt_is_running(struct s3c2410_wdt *wdt) |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 176 | { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 177 | return readl(wdt->reg_base + S3C2410_WTCON) & S3C2410_WTCON_ENABLE; |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Wolfram Sang | 25dc46e | 2011-09-26 15:40:14 +0200 | [diff] [blame] | 180 | static int s3c2410wdt_set_heartbeat(struct watchdog_device *wdd, unsigned timeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 182 | struct s3c2410_wdt *wdt = watchdog_get_drvdata(wdd); |
| 183 | unsigned long freq = clk_get_rate(wdt->clock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | unsigned int count; |
| 185 | unsigned int divisor = 1; |
| 186 | unsigned long wtcon; |
| 187 | |
| 188 | if (timeout < 1) |
| 189 | return -EINVAL; |
| 190 | |
Doug Anderson | 1786244 | 2013-11-26 16:57:19 -0800 | [diff] [blame^] | 191 | freq = DIV_ROUND_UP(freq, 128); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | count = timeout * freq; |
| 193 | |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 194 | DBG("%s: count=%d, timeout=%d, freq=%lu\n", |
Harvey Harrison | fa9363c | 2008-03-05 18:24:58 -0800 | [diff] [blame] | 195 | __func__, count, timeout, freq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
| 197 | /* if the count is bigger than the watchdog register, |
| 198 | then work out what we need to do (and if) we can |
| 199 | actually make this value |
| 200 | */ |
| 201 | |
| 202 | if (count >= 0x10000) { |
Doug Anderson | 1786244 | 2013-11-26 16:57:19 -0800 | [diff] [blame^] | 203 | divisor = DIV_ROUND_UP(count, 0xffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Doug Anderson | 1786244 | 2013-11-26 16:57:19 -0800 | [diff] [blame^] | 205 | if (divisor > 0x100) { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 206 | dev_err(wdt->dev, "timeout %d too big\n", timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | return -EINVAL; |
| 208 | } |
| 209 | } |
| 210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | DBG("%s: timeout=%d, divisor=%d, count=%d (%08x)\n", |
Doug Anderson | 1786244 | 2013-11-26 16:57:19 -0800 | [diff] [blame^] | 212 | __func__, timeout, divisor, count, DIV_ROUND_UP(count, divisor)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
Doug Anderson | 1786244 | 2013-11-26 16:57:19 -0800 | [diff] [blame^] | 214 | count = DIV_ROUND_UP(count, divisor); |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 215 | wdt->count = count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
| 217 | /* update the pre-scaler */ |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 218 | wtcon = readl(wdt->reg_base + S3C2410_WTCON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | wtcon &= ~S3C2410_WTCON_PRESCALE_MASK; |
| 220 | wtcon |= S3C2410_WTCON_PRESCALE(divisor-1); |
| 221 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 222 | writel(count, wdt->reg_base + S3C2410_WTDAT); |
| 223 | writel(wtcon, wdt->reg_base + S3C2410_WTCON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
Hans de Goede | 5f2430f | 2012-05-11 12:00:27 +0200 | [diff] [blame] | 225 | wdd->timeout = (count * divisor) / freq; |
Wim Van Sebroeck | 0197c1c | 2012-02-29 20:20:58 +0100 | [diff] [blame] | 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | return 0; |
| 228 | } |
| 229 | |
Wim Van Sebroeck | a77dba7 | 2009-04-14 20:20:07 +0000 | [diff] [blame] | 230 | #define OPTIONS (WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
Alan Cox | 41dc8b7 | 2008-08-04 17:54:46 +0100 | [diff] [blame] | 232 | static const struct watchdog_info s3c2410_wdt_ident = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | .options = OPTIONS, |
| 234 | .firmware_version = 0, |
| 235 | .identity = "S3C2410 Watchdog", |
| 236 | }; |
| 237 | |
Wolfram Sang | 25dc46e | 2011-09-26 15:40:14 +0200 | [diff] [blame] | 238 | static struct watchdog_ops s3c2410wdt_ops = { |
| 239 | .owner = THIS_MODULE, |
| 240 | .start = s3c2410wdt_start, |
| 241 | .stop = s3c2410wdt_stop, |
| 242 | .ping = s3c2410wdt_keepalive, |
| 243 | .set_timeout = s3c2410wdt_set_heartbeat, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | }; |
| 245 | |
Wolfram Sang | 25dc46e | 2011-09-26 15:40:14 +0200 | [diff] [blame] | 246 | static struct watchdog_device s3c2410_wdd = { |
| 247 | .info = &s3c2410_wdt_ident, |
| 248 | .ops = &s3c2410wdt_ops, |
Fabio Porcedda | c1fd5f6 | 2013-02-14 09:14:25 +0100 | [diff] [blame] | 249 | .timeout = CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | }; |
| 251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | /* interrupt handler code */ |
| 253 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 254 | static irqreturn_t s3c2410wdt_irq(int irqno, void *param) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 256 | struct s3c2410_wdt *wdt = platform_get_drvdata(param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 258 | dev_info(wdt->dev, "watchdog timer expired (irq)\n"); |
| 259 | |
| 260 | s3c2410wdt_keepalive(&wdt->wdt_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | return IRQ_HANDLED; |
| 262 | } |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 263 | |
Doug Anderson | 0f1dd98 | 2013-11-25 15:36:43 -0800 | [diff] [blame] | 264 | #ifdef CONFIG_ARM_S3C24XX_CPUFREQ |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 265 | |
| 266 | static int s3c2410wdt_cpufreq_transition(struct notifier_block *nb, |
| 267 | unsigned long val, void *data) |
| 268 | { |
| 269 | int ret; |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 270 | struct s3c2410_wdt *wdt = freq_to_wdt(nb); |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 271 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 272 | if (!s3c2410wdt_is_running(wdt)) |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 273 | goto done; |
| 274 | |
| 275 | if (val == CPUFREQ_PRECHANGE) { |
| 276 | /* To ensure that over the change we don't cause the |
| 277 | * watchdog to trigger, we perform an keep-alive if |
| 278 | * the watchdog is running. |
| 279 | */ |
| 280 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 281 | s3c2410wdt_keepalive(&wdt->wdt_device); |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 282 | } else if (val == CPUFREQ_POSTCHANGE) { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 283 | s3c2410wdt_stop(&wdt->wdt_device); |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 284 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 285 | ret = s3c2410wdt_set_heartbeat(&wdt->wdt_device, |
| 286 | wdt->wdt_device.timeout); |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 287 | |
| 288 | if (ret >= 0) |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 289 | s3c2410wdt_start(&wdt->wdt_device); |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 290 | else |
| 291 | goto err; |
| 292 | } |
| 293 | |
| 294 | done: |
| 295 | return 0; |
| 296 | |
| 297 | err: |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 298 | dev_err(wdt->dev, "cannot set new value for timeout %d\n", |
| 299 | wdt->wdt_device.timeout); |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 300 | return ret; |
| 301 | } |
| 302 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 303 | static inline int s3c2410wdt_cpufreq_register(struct s3c2410_wdt *wdt) |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 304 | { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 305 | wdt->freq_transition.notifier_call = s3c2410wdt_cpufreq_transition; |
| 306 | |
| 307 | return cpufreq_register_notifier(&wdt->freq_transition, |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 308 | CPUFREQ_TRANSITION_NOTIFIER); |
| 309 | } |
| 310 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 311 | static inline void s3c2410wdt_cpufreq_deregister(struct s3c2410_wdt *wdt) |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 312 | { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 313 | wdt->freq_transition.notifier_call = s3c2410wdt_cpufreq_transition; |
| 314 | |
| 315 | cpufreq_unregister_notifier(&wdt->freq_transition, |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 316 | CPUFREQ_TRANSITION_NOTIFIER); |
| 317 | } |
| 318 | |
| 319 | #else |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 320 | |
| 321 | static inline int s3c2410wdt_cpufreq_register(struct s3c2410_wdt *wdt) |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 322 | { |
| 323 | return 0; |
| 324 | } |
| 325 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 326 | static inline void s3c2410wdt_cpufreq_deregister(struct s3c2410_wdt *wdt) |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 327 | { |
| 328 | } |
| 329 | #endif |
| 330 | |
Bill Pemberton | 2d991a1 | 2012-11-19 13:21:41 -0500 | [diff] [blame] | 331 | static int s3c2410wdt_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | { |
Ben Dooks | e8ef92b | 2007-06-14 12:08:55 +0100 | [diff] [blame] | 333 | struct device *dev; |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 334 | struct s3c2410_wdt *wdt; |
| 335 | struct resource *wdt_mem; |
| 336 | struct resource *wdt_irq; |
Ben Dooks | 46b814d | 2007-06-14 12:08:54 +0100 | [diff] [blame] | 337 | unsigned int wtcon; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | int started = 0; |
| 339 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
Harvey Harrison | fa9363c | 2008-03-05 18:24:58 -0800 | [diff] [blame] | 341 | DBG("%s: probe=%p\n", __func__, pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
Ben Dooks | e8ef92b | 2007-06-14 12:08:55 +0100 | [diff] [blame] | 343 | dev = &pdev->dev; |
Ben Dooks | e8ef92b | 2007-06-14 12:08:55 +0100 | [diff] [blame] | 344 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 345 | wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); |
| 346 | if (!wdt) |
| 347 | return -ENOMEM; |
| 348 | |
| 349 | wdt->dev = &pdev->dev; |
| 350 | spin_lock_init(&wdt->lock); |
| 351 | wdt->wdt_device = s3c2410_wdd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
MyungJoo Ham | 78d3e00 | 2012-01-13 14:14:23 +0900 | [diff] [blame] | 353 | wdt_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 354 | if (wdt_irq == NULL) { |
| 355 | dev_err(dev, "no irq resource specified\n"); |
| 356 | ret = -ENOENT; |
| 357 | goto err; |
| 358 | } |
| 359 | |
| 360 | /* get the memory region for the watchdog timer */ |
Julia Lawall | bd5cc11 | 2013-08-14 11:11:24 +0200 | [diff] [blame] | 361 | wdt_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 362 | wdt->reg_base = devm_ioremap_resource(dev, wdt_mem); |
| 363 | if (IS_ERR(wdt->reg_base)) { |
| 364 | ret = PTR_ERR(wdt->reg_base); |
Jingoo Han | 04ecc7d | 2013-01-10 11:06:33 +0900 | [diff] [blame] | 365 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 368 | DBG("probe: mapped reg_base=%p\n", wdt->reg_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 370 | wdt->clock = devm_clk_get(dev, "watchdog"); |
| 371 | if (IS_ERR(wdt->clock)) { |
Ben Dooks | e8ef92b | 2007-06-14 12:08:55 +0100 | [diff] [blame] | 372 | dev_err(dev, "failed to find watchdog clock source\n"); |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 373 | ret = PTR_ERR(wdt->clock); |
Jingoo Han | 04ecc7d | 2013-01-10 11:06:33 +0900 | [diff] [blame] | 374 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 377 | clk_prepare_enable(wdt->clock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 379 | ret = s3c2410wdt_cpufreq_register(wdt); |
MyungJoo Ham | 78d3e00 | 2012-01-13 14:14:23 +0900 | [diff] [blame] | 380 | if (ret < 0) { |
Jingoo Han | 3828924 | 2013-03-14 10:30:21 +0900 | [diff] [blame] | 381 | dev_err(dev, "failed to register cpufreq\n"); |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 382 | goto err_clk; |
| 383 | } |
| 384 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 385 | watchdog_set_drvdata(&wdt->wdt_device, wdt); |
| 386 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | /* see if we can actually set the requested timer margin, and if |
| 388 | * not, try the default value */ |
| 389 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 390 | watchdog_init_timeout(&wdt->wdt_device, tmr_margin, &pdev->dev); |
| 391 | ret = s3c2410wdt_set_heartbeat(&wdt->wdt_device, |
| 392 | wdt->wdt_device.timeout); |
| 393 | if (ret) { |
| 394 | started = s3c2410wdt_set_heartbeat(&wdt->wdt_device, |
Alan Cox | 41dc8b7 | 2008-08-04 17:54:46 +0100 | [diff] [blame] | 395 | CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
Alan Cox | 41dc8b7 | 2008-08-04 17:54:46 +0100 | [diff] [blame] | 397 | if (started == 0) |
| 398 | dev_info(dev, |
| 399 | "tmr_margin value out of range, default %d used\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME); |
Alan Cox | 41dc8b7 | 2008-08-04 17:54:46 +0100 | [diff] [blame] | 401 | else |
Wim Van Sebroeck | a77dba7 | 2009-04-14 20:20:07 +0000 | [diff] [blame] | 402 | dev_info(dev, "default timer value is out of range, " |
| 403 | "cannot start\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Jingoo Han | 04ecc7d | 2013-01-10 11:06:33 +0900 | [diff] [blame] | 406 | ret = devm_request_irq(dev, wdt_irq->start, s3c2410wdt_irq, 0, |
| 407 | pdev->name, pdev); |
MyungJoo Ham | 78d3e00 | 2012-01-13 14:14:23 +0900 | [diff] [blame] | 408 | if (ret != 0) { |
| 409 | dev_err(dev, "failed to install irq (%d)\n", ret); |
| 410 | goto err_cpufreq; |
| 411 | } |
| 412 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 413 | watchdog_set_nowayout(&wdt->wdt_device, nowayout); |
Wim Van Sebroeck | ff0b3cd | 2011-11-29 16:24:16 +0100 | [diff] [blame] | 414 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 415 | ret = watchdog_register_device(&wdt->wdt_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | if (ret) { |
Wolfram Sang | 25dc46e | 2011-09-26 15:40:14 +0200 | [diff] [blame] | 417 | dev_err(dev, "cannot register watchdog (%d)\n", ret); |
Jingoo Han | 04ecc7d | 2013-01-10 11:06:33 +0900 | [diff] [blame] | 418 | goto err_cpufreq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | if (tmr_atboot && started == 0) { |
Ben Dooks | e8ef92b | 2007-06-14 12:08:55 +0100 | [diff] [blame] | 422 | dev_info(dev, "starting watchdog timer\n"); |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 423 | s3c2410wdt_start(&wdt->wdt_device); |
Ben Dooks | 655516c | 2006-04-19 23:02:56 +0100 | [diff] [blame] | 424 | } else if (!tmr_atboot) { |
| 425 | /* if we're not enabling the watchdog, then ensure it is |
| 426 | * disabled if it has been left running from the bootloader |
| 427 | * or other source */ |
| 428 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 429 | s3c2410wdt_stop(&wdt->wdt_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 432 | platform_set_drvdata(pdev, wdt); |
| 433 | |
Ben Dooks | 46b814d | 2007-06-14 12:08:54 +0100 | [diff] [blame] | 434 | /* print out a statement of readiness */ |
| 435 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 436 | wtcon = readl(wdt->reg_base + S3C2410_WTCON); |
Ben Dooks | 46b814d | 2007-06-14 12:08:54 +0100 | [diff] [blame] | 437 | |
Ben Dooks | e8ef92b | 2007-06-14 12:08:55 +0100 | [diff] [blame] | 438 | dev_info(dev, "watchdog %sactive, reset %sabled, irq %sabled\n", |
Ben Dooks | 46b814d | 2007-06-14 12:08:54 +0100 | [diff] [blame] | 439 | (wtcon & S3C2410_WTCON_ENABLE) ? "" : "in", |
Dmitry Artamonow | 20403e8 | 2011-11-16 12:46:13 +0400 | [diff] [blame] | 440 | (wtcon & S3C2410_WTCON_RSTEN) ? "en" : "dis", |
| 441 | (wtcon & S3C2410_WTCON_INTEN) ? "en" : "dis"); |
Alan Cox | 41dc8b7 | 2008-08-04 17:54:46 +0100 | [diff] [blame] | 442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | return 0; |
Ben Dooks | 0b6dd8a | 2006-12-18 10:31:32 +0000 | [diff] [blame] | 444 | |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 445 | err_cpufreq: |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 446 | s3c2410wdt_cpufreq_deregister(wdt); |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 447 | |
Ben Dooks | 0b6dd8a | 2006-12-18 10:31:32 +0000 | [diff] [blame] | 448 | err_clk: |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 449 | clk_disable_unprepare(wdt->clock); |
| 450 | wdt->clock = NULL; |
Ben Dooks | 0b6dd8a | 2006-12-18 10:31:32 +0000 | [diff] [blame] | 451 | |
MyungJoo Ham | 78d3e00 | 2012-01-13 14:14:23 +0900 | [diff] [blame] | 452 | err: |
Ben Dooks | 0b6dd8a | 2006-12-18 10:31:32 +0000 | [diff] [blame] | 453 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Bill Pemberton | 4b12b89 | 2012-11-19 13:26:24 -0500 | [diff] [blame] | 456 | static int s3c2410wdt_remove(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 458 | struct s3c2410_wdt *wdt = platform_get_drvdata(dev); |
Wim Van Sebroeck | 9a37256 | 2010-05-21 08:11:42 +0000 | [diff] [blame] | 459 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 460 | watchdog_unregister_device(&wdt->wdt_device); |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 461 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 462 | s3c2410wdt_cpufreq_deregister(wdt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 464 | clk_disable_unprepare(wdt->clock); |
| 465 | wdt->clock = NULL; |
| 466 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | return 0; |
| 468 | } |
| 469 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 470 | static void s3c2410wdt_shutdown(struct platform_device *dev) |
Ben Dooks | 94f1e9f | 2005-08-17 09:04:52 +0200 | [diff] [blame] | 471 | { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 472 | struct s3c2410_wdt *wdt = platform_get_drvdata(dev); |
| 473 | |
| 474 | s3c2410wdt_stop(&wdt->wdt_device); |
Ben Dooks | 94f1e9f | 2005-08-17 09:04:52 +0200 | [diff] [blame] | 475 | } |
| 476 | |
Jingoo Han | 0183984c | 2013-03-14 10:31:21 +0900 | [diff] [blame] | 477 | #ifdef CONFIG_PM_SLEEP |
Ben Dooks | af4bb82 | 2005-08-17 09:03:23 +0200 | [diff] [blame] | 478 | |
Jingoo Han | 0183984c | 2013-03-14 10:31:21 +0900 | [diff] [blame] | 479 | static int s3c2410wdt_suspend(struct device *dev) |
Ben Dooks | af4bb82 | 2005-08-17 09:03:23 +0200 | [diff] [blame] | 480 | { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 481 | struct s3c2410_wdt *wdt = dev_get_drvdata(dev); |
| 482 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 483 | /* Save watchdog state, and turn it off. */ |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 484 | wdt->wtcon_save = readl(wdt->reg_base + S3C2410_WTCON); |
| 485 | wdt->wtdat_save = readl(wdt->reg_base + S3C2410_WTDAT); |
Ben Dooks | af4bb82 | 2005-08-17 09:03:23 +0200 | [diff] [blame] | 486 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 487 | /* Note that WTCNT doesn't need to be saved. */ |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 488 | s3c2410wdt_stop(&wdt->wdt_device); |
Ben Dooks | af4bb82 | 2005-08-17 09:03:23 +0200 | [diff] [blame] | 489 | |
| 490 | return 0; |
| 491 | } |
| 492 | |
Jingoo Han | 0183984c | 2013-03-14 10:31:21 +0900 | [diff] [blame] | 493 | static int s3c2410wdt_resume(struct device *dev) |
Ben Dooks | af4bb82 | 2005-08-17 09:03:23 +0200 | [diff] [blame] | 494 | { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 495 | struct s3c2410_wdt *wdt = dev_get_drvdata(dev); |
Ben Dooks | af4bb82 | 2005-08-17 09:03:23 +0200 | [diff] [blame] | 496 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 497 | /* Restore watchdog state. */ |
| 498 | writel(wdt->wtdat_save, wdt->reg_base + S3C2410_WTDAT); |
| 499 | writel(wdt->wtdat_save, wdt->reg_base + S3C2410_WTCNT);/* Reset count */ |
| 500 | writel(wdt->wtcon_save, wdt->reg_base + S3C2410_WTCON); |
Ben Dooks | af4bb82 | 2005-08-17 09:03:23 +0200 | [diff] [blame] | 501 | |
Jingoo Han | 0183984c | 2013-03-14 10:31:21 +0900 | [diff] [blame] | 502 | dev_info(dev, "watchdog %sabled\n", |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 503 | (wdt->wtcon_save & S3C2410_WTCON_ENABLE) ? "en" : "dis"); |
Ben Dooks | af4bb82 | 2005-08-17 09:03:23 +0200 | [diff] [blame] | 504 | |
| 505 | return 0; |
| 506 | } |
Jingoo Han | 0183984c | 2013-03-14 10:31:21 +0900 | [diff] [blame] | 507 | #endif |
Ben Dooks | af4bb82 | 2005-08-17 09:03:23 +0200 | [diff] [blame] | 508 | |
Jingoo Han | 0183984c | 2013-03-14 10:31:21 +0900 | [diff] [blame] | 509 | static SIMPLE_DEV_PM_OPS(s3c2410wdt_pm_ops, s3c2410wdt_suspend, |
| 510 | s3c2410wdt_resume); |
Ben Dooks | af4bb82 | 2005-08-17 09:03:23 +0200 | [diff] [blame] | 511 | |
Thomas Abraham | 9487a9c | 2011-06-22 15:24:32 +0530 | [diff] [blame] | 512 | #ifdef CONFIG_OF |
| 513 | static const struct of_device_id s3c2410_wdt_match[] = { |
| 514 | { .compatible = "samsung,s3c2410-wdt" }, |
| 515 | {}, |
| 516 | }; |
| 517 | MODULE_DEVICE_TABLE(of, s3c2410_wdt_match); |
Thomas Abraham | 9487a9c | 2011-06-22 15:24:32 +0530 | [diff] [blame] | 518 | #endif |
Ben Dooks | af4bb82 | 2005-08-17 09:03:23 +0200 | [diff] [blame] | 519 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 520 | static struct platform_driver s3c2410wdt_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | .probe = s3c2410wdt_probe, |
Bill Pemberton | 8226871 | 2012-11-19 13:21:12 -0500 | [diff] [blame] | 522 | .remove = s3c2410wdt_remove, |
Ben Dooks | 94f1e9f | 2005-08-17 09:04:52 +0200 | [diff] [blame] | 523 | .shutdown = s3c2410wdt_shutdown, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 524 | .driver = { |
| 525 | .owner = THIS_MODULE, |
| 526 | .name = "s3c2410-wdt", |
Jingoo Han | 0183984c | 2013-03-14 10:31:21 +0900 | [diff] [blame] | 527 | .pm = &s3c2410wdt_pm_ops, |
Wim Van Sebroeck | 3016a55 | 2012-05-03 05:24:17 +0000 | [diff] [blame] | 528 | .of_match_table = of_match_ptr(s3c2410_wdt_match), |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 529 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | }; |
| 531 | |
Sachin Kamat | 6b761b2 | 2012-07-12 17:17:40 +0530 | [diff] [blame] | 532 | module_platform_driver(s3c2410wdt_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
Ben Dooks | af4bb82 | 2005-08-17 09:03:23 +0200 | [diff] [blame] | 534 | MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>, " |
| 535 | "Dimitry Andric <dimitry.andric@tomtom.com>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | MODULE_DESCRIPTION("S3C2410 Watchdog Device Driver"); |
| 537 | MODULE_LICENSE("GPL"); |
Kay Sievers | f37d193 | 2008-04-10 21:29:23 -0700 | [diff] [blame] | 538 | MODULE_ALIAS("platform:s3c2410-wdt"); |