Thomas Gleixner | c942fdd | 2019-05-27 08:55:06 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Krzysztof Kozlowski | 08497f2 | 2017-03-13 21:07:26 +0200 | [diff] [blame] | 2 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Krzysztof Kozlowski | 08497f2 | 2017-03-13 21:07:26 +0200 | [diff] [blame] | 10 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/moduleparam.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/types.h> |
| 15 | #include <linux/timer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/watchdog.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 17 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/interrupt.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 19 | #include <linux/clk.h> |
Alan Cox | 41dc8b7 | 2008-08-04 17:54:46 +0100 | [diff] [blame] | 20 | #include <linux/uaccess.h> |
| 21 | #include <linux/io.h> |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 22 | #include <linux/cpufreq.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Wolfram Sang | 25dc46e | 2011-09-26 15:40:14 +0200 | [diff] [blame] | 24 | #include <linux/err.h> |
Wim Van Sebroeck | 3016a55 | 2012-05-03 05:24:17 +0000 | [diff] [blame] | 25 | #include <linux/of.h> |
Krzysztof Kozlowski | a9a02c4 | 2017-03-13 21:07:25 +0200 | [diff] [blame] | 26 | #include <linux/of_device.h> |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 27 | #include <linux/mfd/syscon.h> |
| 28 | #include <linux/regmap.h> |
Heiko Stuebner | f286e13 | 2014-08-19 17:45:36 -0700 | [diff] [blame] | 29 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
Tomasz Figa | a8f5401 | 2013-06-17 23:45:24 +0900 | [diff] [blame] | 31 | #define S3C2410_WTCON 0x00 |
| 32 | #define S3C2410_WTDAT 0x04 |
| 33 | #define S3C2410_WTCNT 0x08 |
Krzysztof Kozlowski | 0b44554 | 2017-02-24 17:11:16 +0200 | [diff] [blame] | 34 | #define S3C2410_WTCLRINT 0x0c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Javier Martinez Canillas | 882dec1 | 2016-03-01 13:45:17 -0300 | [diff] [blame] | 36 | #define S3C2410_WTCNT_MAXCNT 0xffff |
| 37 | |
Tomasz Figa | a8f5401 | 2013-06-17 23:45:24 +0900 | [diff] [blame] | 38 | #define S3C2410_WTCON_RSTEN (1 << 0) |
| 39 | #define S3C2410_WTCON_INTEN (1 << 2) |
| 40 | #define S3C2410_WTCON_ENABLE (1 << 5) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Tomasz Figa | a8f5401 | 2013-06-17 23:45:24 +0900 | [diff] [blame] | 42 | #define S3C2410_WTCON_DIV16 (0 << 3) |
| 43 | #define S3C2410_WTCON_DIV32 (1 << 3) |
| 44 | #define S3C2410_WTCON_DIV64 (2 << 3) |
| 45 | #define S3C2410_WTCON_DIV128 (3 << 3) |
| 46 | |
Javier Martinez Canillas | 882dec1 | 2016-03-01 13:45:17 -0300 | [diff] [blame] | 47 | #define S3C2410_WTCON_MAXDIV 0x80 |
| 48 | |
Tomasz Figa | a8f5401 | 2013-06-17 23:45:24 +0900 | [diff] [blame] | 49 | #define S3C2410_WTCON_PRESCALE(x) ((x) << 8) |
| 50 | #define S3C2410_WTCON_PRESCALE_MASK (0xff << 8) |
Javier Martinez Canillas | 882dec1 | 2016-03-01 13:45:17 -0300 | [diff] [blame] | 51 | #define S3C2410_WTCON_PRESCALE_MAX 0xff |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Krzysztof Kozlowski | 4f21195 | 2017-02-24 17:11:15 +0200 | [diff] [blame] | 53 | #define S3C2410_WATCHDOG_ATBOOT (0) |
| 54 | #define S3C2410_WATCHDOG_DEFAULT_TIME (15) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Doug Anderson | cffc9a6 | 2013-12-06 13:08:07 -0800 | [diff] [blame] | 56 | #define EXYNOS5_RST_STAT_REG_OFFSET 0x0404 |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 57 | #define EXYNOS5_WDT_DISABLE_REG_OFFSET 0x0408 |
| 58 | #define EXYNOS5_WDT_MASK_RESET_REG_OFFSET 0x040c |
Sam Protsenko | cd4eadf | 2021-11-21 18:56:47 +0200 | [diff] [blame] | 59 | #define EXYNOS850_CLUSTER0_NONCPU_OUT 0x1220 |
| 60 | #define EXYNOS850_CLUSTER0_NONCPU_INT_EN 0x1244 |
| 61 | #define EXYNOS850_CLUSTER1_NONCPU_OUT 0x1620 |
| 62 | #define EXYNOS850_CLUSTER1_NONCPU_INT_EN 0x1644 |
| 63 | |
| 64 | #define EXYNOS850_CLUSTER0_WDTRESET_BIT 24 |
| 65 | #define EXYNOS850_CLUSTER1_WDTRESET_BIT 23 |
Sam Protsenko | cf3fad4 | 2021-11-24 01:26:13 +0200 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * DOC: Quirk flags for different Samsung watchdog IP-cores |
| 69 | * |
| 70 | * This driver supports multiple Samsung SoCs, each of which might have |
| 71 | * different set of registers and features supported. As watchdog block |
| 72 | * sometimes requires modifying PMU registers for proper functioning, register |
| 73 | * differences in both watchdog and PMU IP-cores should be accounted for. Quirk |
| 74 | * flags described below serve the purpose of telling the driver about mentioned |
| 75 | * SoC traits, and can be specified in driver data for each particular supported |
| 76 | * device. |
| 77 | * |
| 78 | * %QUIRK_HAS_WTCLRINT_REG: Watchdog block has WTCLRINT register. It's used to |
| 79 | * clear the interrupt once the interrupt service routine is complete. It's |
| 80 | * write-only, writing any values to this register clears the interrupt, but |
| 81 | * reading is not permitted. |
| 82 | * |
| 83 | * %QUIRK_HAS_PMU_MASK_RESET: PMU block has the register for disabling/enabling |
| 84 | * WDT reset request. On old SoCs it's usually called MASK_WDT_RESET_REQUEST, |
| 85 | * new SoCs have CLUSTERx_NONCPU_INT_EN register, which 'mask_bit' value is |
| 86 | * inverted compared to the former one. |
| 87 | * |
| 88 | * %QUIRK_HAS_PMU_RST_STAT: PMU block has RST_STAT (reset status) register, |
| 89 | * which contains bits indicating the reason for most recent CPU reset. If |
| 90 | * present, driver will use this register to check if previous reboot was due to |
| 91 | * watchdog timer reset. |
| 92 | * |
| 93 | * %QUIRK_HAS_PMU_AUTO_DISABLE: PMU block has AUTOMATIC_WDT_RESET_DISABLE |
| 94 | * register. If 'mask_bit' bit is set, PMU will disable WDT reset when |
| 95 | * corresponding processor is in reset state. |
| 96 | * |
| 97 | * %QUIRK_HAS_PMU_CNT_EN: PMU block has some register (e.g. CLUSTERx_NONCPU_OUT) |
| 98 | * with "watchdog counter enable" bit. That bit should be set to make watchdog |
| 99 | * counter running. |
| 100 | */ |
| 101 | #define QUIRK_HAS_WTCLRINT_REG (1 << 0) |
| 102 | #define QUIRK_HAS_PMU_MASK_RESET (1 << 1) |
| 103 | #define QUIRK_HAS_PMU_RST_STAT (1 << 2) |
Sam Protsenko | 8d9fdf6 | 2021-11-21 18:56:40 +0200 | [diff] [blame] | 104 | #define QUIRK_HAS_PMU_AUTO_DISABLE (1 << 3) |
Sam Protsenko | aa220bc | 2021-11-21 18:56:43 +0200 | [diff] [blame] | 105 | #define QUIRK_HAS_PMU_CNT_EN (1 << 4) |
Doug Anderson | cffc9a6 | 2013-12-06 13:08:07 -0800 | [diff] [blame] | 106 | |
| 107 | /* These quirks require that we have a PMU register map */ |
Sam Protsenko | cf3fad4 | 2021-11-24 01:26:13 +0200 | [diff] [blame] | 108 | #define QUIRKS_HAVE_PMUREG \ |
| 109 | (QUIRK_HAS_PMU_MASK_RESET | QUIRK_HAS_PMU_RST_STAT | \ |
| 110 | QUIRK_HAS_PMU_AUTO_DISABLE | QUIRK_HAS_PMU_CNT_EN) |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 111 | |
Wim Van Sebroeck | 86a1e18 | 2012-03-05 16:51:11 +0100 | [diff] [blame] | 112 | static bool nowayout = WATCHDOG_NOWAYOUT; |
Fabio Porcedda | c1fd5f6 | 2013-02-14 09:14:25 +0100 | [diff] [blame] | 113 | static int tmr_margin; |
Krzysztof Kozlowski | 4f21195 | 2017-02-24 17:11:15 +0200 | [diff] [blame] | 114 | static int tmr_atboot = S3C2410_WATCHDOG_ATBOOT; |
Alan Cox | 41dc8b7 | 2008-08-04 17:54:46 +0100 | [diff] [blame] | 115 | static int soft_noboot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
| 117 | module_param(tmr_margin, int, 0); |
| 118 | module_param(tmr_atboot, int, 0); |
Wim Van Sebroeck | 86a1e18 | 2012-03-05 16:51:11 +0100 | [diff] [blame] | 119 | module_param(nowayout, bool, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | module_param(soft_noboot, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Randy Dunlap | 76550d3 | 2010-05-01 09:46:15 -0700 | [diff] [blame] | 122 | MODULE_PARM_DESC(tmr_margin, "Watchdog tmr_margin in seconds. (default=" |
Krzysztof Kozlowski | 4f21195 | 2017-02-24 17:11:15 +0200 | [diff] [blame] | 123 | __MODULE_STRING(S3C2410_WATCHDOG_DEFAULT_TIME) ")"); |
Alan Cox | 41dc8b7 | 2008-08-04 17:54:46 +0100 | [diff] [blame] | 124 | MODULE_PARM_DESC(tmr_atboot, |
| 125 | "Watchdog is started at boot time if set to 1, default=" |
Krzysztof Kozlowski | 4f21195 | 2017-02-24 17:11:15 +0200 | [diff] [blame] | 126 | __MODULE_STRING(S3C2410_WATCHDOG_ATBOOT)); |
Alan Cox | 41dc8b7 | 2008-08-04 17:54:46 +0100 | [diff] [blame] | 127 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" |
| 128 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
Krzysztof Kozlowski | 08497f2 | 2017-03-13 21:07:26 +0200 | [diff] [blame] | 129 | MODULE_PARM_DESC(soft_noboot, "Watchdog action, set to 1 to ignore reboots, 0 to reboot (default 0)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 131 | /** |
| 132 | * struct s3c2410_wdt_variant - Per-variant config data |
| 133 | * |
| 134 | * @disable_reg: Offset in pmureg for the register that disables the watchdog |
| 135 | * timer reset functionality. |
| 136 | * @mask_reset_reg: Offset in pmureg for the register that masks the watchdog |
| 137 | * timer reset functionality. |
Sam Protsenko | 370bc7f | 2021-11-21 18:56:42 +0200 | [diff] [blame] | 138 | * @mask_reset_inv: If set, mask_reset_reg value will have inverted meaning. |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 139 | * @mask_bit: Bit number for the watchdog timer in the disable register and the |
| 140 | * mask reset register. |
Doug Anderson | cffc9a6 | 2013-12-06 13:08:07 -0800 | [diff] [blame] | 141 | * @rst_stat_reg: Offset in pmureg for the register that has the reset status. |
| 142 | * @rst_stat_bit: Bit number in the rst_stat register indicating a watchdog |
| 143 | * reset. |
Sam Protsenko | aa220bc | 2021-11-21 18:56:43 +0200 | [diff] [blame] | 144 | * @cnt_en_reg: Offset in pmureg for the register that enables WDT counter. |
| 145 | * @cnt_en_bit: Bit number for "watchdog counter enable" in cnt_en register. |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 146 | * @quirks: A bitfield of quirks. |
| 147 | */ |
| 148 | |
| 149 | struct s3c2410_wdt_variant { |
| 150 | int disable_reg; |
| 151 | int mask_reset_reg; |
Sam Protsenko | 370bc7f | 2021-11-21 18:56:42 +0200 | [diff] [blame] | 152 | bool mask_reset_inv; |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 153 | int mask_bit; |
Doug Anderson | cffc9a6 | 2013-12-06 13:08:07 -0800 | [diff] [blame] | 154 | int rst_stat_reg; |
| 155 | int rst_stat_bit; |
Sam Protsenko | aa220bc | 2021-11-21 18:56:43 +0200 | [diff] [blame] | 156 | int cnt_en_reg; |
| 157 | int cnt_en_bit; |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 158 | u32 quirks; |
| 159 | }; |
| 160 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 161 | struct s3c2410_wdt { |
| 162 | struct device *dev; |
Sam Protsenko | e249d01 | 2021-11-21 18:56:45 +0200 | [diff] [blame] | 163 | struct clk *bus_clk; /* for register interface (PCLK) */ |
| 164 | struct clk *src_clk; /* for WDT counter */ |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 165 | void __iomem *reg_base; |
| 166 | unsigned int count; |
| 167 | spinlock_t lock; |
| 168 | unsigned long wtcon_save; |
| 169 | unsigned long wtdat_save; |
| 170 | struct watchdog_device wdt_device; |
| 171 | struct notifier_block freq_transition; |
Krzysztof Kozlowski | 58415ef | 2017-03-13 21:07:24 +0200 | [diff] [blame] | 172 | const struct s3c2410_wdt_variant *drv_data; |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 173 | struct regmap *pmureg; |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 174 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 176 | static const struct s3c2410_wdt_variant drv_data_s3c2410 = { |
| 177 | .quirks = 0 |
| 178 | }; |
| 179 | |
| 180 | #ifdef CONFIG_OF |
Krzysztof Kozlowski | 0b44554 | 2017-02-24 17:11:16 +0200 | [diff] [blame] | 181 | static const struct s3c2410_wdt_variant drv_data_s3c6410 = { |
| 182 | .quirks = QUIRK_HAS_WTCLRINT_REG, |
| 183 | }; |
| 184 | |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 185 | static const struct s3c2410_wdt_variant drv_data_exynos5250 = { |
| 186 | .disable_reg = EXYNOS5_WDT_DISABLE_REG_OFFSET, |
| 187 | .mask_reset_reg = EXYNOS5_WDT_MASK_RESET_REG_OFFSET, |
| 188 | .mask_bit = 20, |
Doug Anderson | cffc9a6 | 2013-12-06 13:08:07 -0800 | [diff] [blame] | 189 | .rst_stat_reg = EXYNOS5_RST_STAT_REG_OFFSET, |
| 190 | .rst_stat_bit = 20, |
Sam Protsenko | cf3fad4 | 2021-11-24 01:26:13 +0200 | [diff] [blame] | 191 | .quirks = QUIRK_HAS_WTCLRINT_REG | QUIRK_HAS_PMU_MASK_RESET | \ |
| 192 | QUIRK_HAS_PMU_RST_STAT | QUIRK_HAS_PMU_AUTO_DISABLE, |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 193 | }; |
| 194 | |
| 195 | static const struct s3c2410_wdt_variant drv_data_exynos5420 = { |
| 196 | .disable_reg = EXYNOS5_WDT_DISABLE_REG_OFFSET, |
| 197 | .mask_reset_reg = EXYNOS5_WDT_MASK_RESET_REG_OFFSET, |
| 198 | .mask_bit = 0, |
Doug Anderson | cffc9a6 | 2013-12-06 13:08:07 -0800 | [diff] [blame] | 199 | .rst_stat_reg = EXYNOS5_RST_STAT_REG_OFFSET, |
| 200 | .rst_stat_bit = 9, |
Sam Protsenko | cf3fad4 | 2021-11-24 01:26:13 +0200 | [diff] [blame] | 201 | .quirks = QUIRK_HAS_WTCLRINT_REG | QUIRK_HAS_PMU_MASK_RESET | \ |
| 202 | QUIRK_HAS_PMU_RST_STAT | QUIRK_HAS_PMU_AUTO_DISABLE, |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 203 | }; |
| 204 | |
Naveen Krishna Chatradhi | 2b9366b | 2014-08-27 15:17:11 +0530 | [diff] [blame] | 205 | static const struct s3c2410_wdt_variant drv_data_exynos7 = { |
| 206 | .disable_reg = EXYNOS5_WDT_DISABLE_REG_OFFSET, |
| 207 | .mask_reset_reg = EXYNOS5_WDT_MASK_RESET_REG_OFFSET, |
Abhilash Kesavan | 5476b2b | 2014-10-17 21:42:53 +0530 | [diff] [blame] | 208 | .mask_bit = 23, |
Naveen Krishna Chatradhi | 2b9366b | 2014-08-27 15:17:11 +0530 | [diff] [blame] | 209 | .rst_stat_reg = EXYNOS5_RST_STAT_REG_OFFSET, |
| 210 | .rst_stat_bit = 23, /* A57 WDTRESET */ |
Sam Protsenko | cf3fad4 | 2021-11-24 01:26:13 +0200 | [diff] [blame] | 211 | .quirks = QUIRK_HAS_WTCLRINT_REG | QUIRK_HAS_PMU_MASK_RESET | \ |
| 212 | QUIRK_HAS_PMU_RST_STAT | QUIRK_HAS_PMU_AUTO_DISABLE, |
Naveen Krishna Chatradhi | 2b9366b | 2014-08-27 15:17:11 +0530 | [diff] [blame] | 213 | }; |
| 214 | |
Sam Protsenko | cd4eadf | 2021-11-21 18:56:47 +0200 | [diff] [blame] | 215 | static const struct s3c2410_wdt_variant drv_data_exynos850_cl0 = { |
| 216 | .mask_reset_reg = EXYNOS850_CLUSTER0_NONCPU_INT_EN, |
| 217 | .mask_bit = 2, |
| 218 | .mask_reset_inv = true, |
| 219 | .rst_stat_reg = EXYNOS5_RST_STAT_REG_OFFSET, |
| 220 | .rst_stat_bit = EXYNOS850_CLUSTER0_WDTRESET_BIT, |
| 221 | .cnt_en_reg = EXYNOS850_CLUSTER0_NONCPU_OUT, |
| 222 | .cnt_en_bit = 7, |
| 223 | .quirks = QUIRK_HAS_WTCLRINT_REG | QUIRK_HAS_PMU_MASK_RESET | \ |
| 224 | QUIRK_HAS_PMU_RST_STAT | QUIRK_HAS_PMU_CNT_EN, |
| 225 | }; |
| 226 | |
| 227 | static const struct s3c2410_wdt_variant drv_data_exynos850_cl1 = { |
| 228 | .mask_reset_reg = EXYNOS850_CLUSTER1_NONCPU_INT_EN, |
| 229 | .mask_bit = 2, |
| 230 | .mask_reset_inv = true, |
| 231 | .rst_stat_reg = EXYNOS5_RST_STAT_REG_OFFSET, |
| 232 | .rst_stat_bit = EXYNOS850_CLUSTER1_WDTRESET_BIT, |
| 233 | .cnt_en_reg = EXYNOS850_CLUSTER1_NONCPU_OUT, |
| 234 | .cnt_en_bit = 7, |
| 235 | .quirks = QUIRK_HAS_WTCLRINT_REG | QUIRK_HAS_PMU_MASK_RESET | \ |
| 236 | QUIRK_HAS_PMU_RST_STAT | QUIRK_HAS_PMU_CNT_EN, |
| 237 | }; |
| 238 | |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 239 | static const struct of_device_id s3c2410_wdt_match[] = { |
| 240 | { .compatible = "samsung,s3c2410-wdt", |
| 241 | .data = &drv_data_s3c2410 }, |
Krzysztof Kozlowski | 0b44554 | 2017-02-24 17:11:16 +0200 | [diff] [blame] | 242 | { .compatible = "samsung,s3c6410-wdt", |
| 243 | .data = &drv_data_s3c6410 }, |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 244 | { .compatible = "samsung,exynos5250-wdt", |
| 245 | .data = &drv_data_exynos5250 }, |
| 246 | { .compatible = "samsung,exynos5420-wdt", |
| 247 | .data = &drv_data_exynos5420 }, |
Naveen Krishna Chatradhi | 2b9366b | 2014-08-27 15:17:11 +0530 | [diff] [blame] | 248 | { .compatible = "samsung,exynos7-wdt", |
| 249 | .data = &drv_data_exynos7 }, |
Sam Protsenko | cd4eadf | 2021-11-21 18:56:47 +0200 | [diff] [blame] | 250 | { .compatible = "samsung,exynos850-wdt", |
| 251 | .data = &drv_data_exynos850_cl0 }, |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 252 | {}, |
| 253 | }; |
| 254 | MODULE_DEVICE_TABLE(of, s3c2410_wdt_match); |
| 255 | #endif |
| 256 | |
| 257 | static const struct platform_device_id s3c2410_wdt_ids[] = { |
| 258 | { |
| 259 | .name = "s3c2410-wdt", |
| 260 | .driver_data = (unsigned long)&drv_data_s3c2410, |
| 261 | }, |
| 262 | {} |
| 263 | }; |
| 264 | MODULE_DEVICE_TABLE(platform, s3c2410_wdt_ids); |
| 265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | /* functions */ |
| 267 | |
Sam Protsenko | e249d01 | 2021-11-21 18:56:45 +0200 | [diff] [blame] | 268 | static inline unsigned long s3c2410wdt_get_freq(struct s3c2410_wdt *wdt) |
Javier Martinez Canillas | 882dec1 | 2016-03-01 13:45:17 -0300 | [diff] [blame] | 269 | { |
Sam Protsenko | e249d01 | 2021-11-21 18:56:45 +0200 | [diff] [blame] | 270 | return clk_get_rate(wdt->src_clk ? wdt->src_clk : wdt->bus_clk); |
| 271 | } |
| 272 | |
| 273 | static inline unsigned int s3c2410wdt_max_timeout(struct s3c2410_wdt *wdt) |
| 274 | { |
| 275 | const unsigned long freq = s3c2410wdt_get_freq(wdt); |
Javier Martinez Canillas | 882dec1 | 2016-03-01 13:45:17 -0300 | [diff] [blame] | 276 | |
| 277 | return S3C2410_WTCNT_MAXCNT / (freq / (S3C2410_WTCON_PRESCALE_MAX + 1) |
| 278 | / S3C2410_WTCON_MAXDIV); |
| 279 | } |
| 280 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 281 | static inline struct s3c2410_wdt *freq_to_wdt(struct notifier_block *nb) |
| 282 | { |
| 283 | return container_of(nb, struct s3c2410_wdt, freq_transition); |
| 284 | } |
| 285 | |
Sam Protsenko | 2bd33bb | 2021-11-21 18:56:41 +0200 | [diff] [blame] | 286 | static int s3c2410wdt_disable_wdt_reset(struct s3c2410_wdt *wdt, bool mask) |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 287 | { |
Sam Protsenko | 2bd33bb | 2021-11-21 18:56:41 +0200 | [diff] [blame] | 288 | const u32 mask_val = BIT(wdt->drv_data->mask_bit); |
| 289 | const u32 val = mask ? mask_val : 0; |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 290 | int ret; |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 291 | |
Sam Protsenko | 2bd33bb | 2021-11-21 18:56:41 +0200 | [diff] [blame] | 292 | ret = regmap_update_bits(wdt->pmureg, wdt->drv_data->disable_reg, |
| 293 | mask_val, val); |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 294 | if (ret < 0) |
| 295 | dev_err(wdt->dev, "failed to update reg(%d)\n", ret); |
| 296 | |
| 297 | return ret; |
| 298 | } |
| 299 | |
Sam Protsenko | 2bd33bb | 2021-11-21 18:56:41 +0200 | [diff] [blame] | 300 | static int s3c2410wdt_mask_wdt_reset(struct s3c2410_wdt *wdt, bool mask) |
| 301 | { |
| 302 | const u32 mask_val = BIT(wdt->drv_data->mask_bit); |
Sam Protsenko | 370bc7f | 2021-11-21 18:56:42 +0200 | [diff] [blame] | 303 | const bool val_inv = wdt->drv_data->mask_reset_inv; |
| 304 | const u32 val = (mask ^ val_inv) ? mask_val : 0; |
Sam Protsenko | 2bd33bb | 2021-11-21 18:56:41 +0200 | [diff] [blame] | 305 | int ret; |
| 306 | |
| 307 | ret = regmap_update_bits(wdt->pmureg, wdt->drv_data->mask_reset_reg, |
| 308 | mask_val, val); |
| 309 | if (ret < 0) |
| 310 | dev_err(wdt->dev, "failed to update reg(%d)\n", ret); |
| 311 | |
| 312 | return ret; |
| 313 | } |
| 314 | |
Sam Protsenko | aa220bc | 2021-11-21 18:56:43 +0200 | [diff] [blame] | 315 | static int s3c2410wdt_enable_counter(struct s3c2410_wdt *wdt, bool en) |
| 316 | { |
| 317 | const u32 mask_val = BIT(wdt->drv_data->cnt_en_bit); |
| 318 | const u32 val = en ? mask_val : 0; |
| 319 | int ret; |
| 320 | |
| 321 | ret = regmap_update_bits(wdt->pmureg, wdt->drv_data->cnt_en_reg, |
| 322 | mask_val, val); |
| 323 | if (ret < 0) |
| 324 | dev_err(wdt->dev, "failed to update reg(%d)\n", ret); |
| 325 | |
| 326 | return ret; |
| 327 | } |
| 328 | |
Sam Protsenko | cf3fad4 | 2021-11-24 01:26:13 +0200 | [diff] [blame] | 329 | static int s3c2410wdt_enable(struct s3c2410_wdt *wdt, bool en) |
Sam Protsenko | 2bd33bb | 2021-11-21 18:56:41 +0200 | [diff] [blame] | 330 | { |
| 331 | int ret; |
| 332 | |
| 333 | if (wdt->drv_data->quirks & QUIRK_HAS_PMU_AUTO_DISABLE) { |
Sam Protsenko | cf3fad4 | 2021-11-24 01:26:13 +0200 | [diff] [blame] | 334 | ret = s3c2410wdt_disable_wdt_reset(wdt, !en); |
Sam Protsenko | 2bd33bb | 2021-11-21 18:56:41 +0200 | [diff] [blame] | 335 | if (ret < 0) |
| 336 | return ret; |
| 337 | } |
| 338 | |
Sam Protsenko | cf3fad4 | 2021-11-24 01:26:13 +0200 | [diff] [blame] | 339 | if (wdt->drv_data->quirks & QUIRK_HAS_PMU_MASK_RESET) { |
| 340 | ret = s3c2410wdt_mask_wdt_reset(wdt, !en); |
Sam Protsenko | 2bd33bb | 2021-11-21 18:56:41 +0200 | [diff] [blame] | 341 | if (ret < 0) |
| 342 | return ret; |
| 343 | } |
| 344 | |
Sam Protsenko | aa220bc | 2021-11-21 18:56:43 +0200 | [diff] [blame] | 345 | if (wdt->drv_data->quirks & QUIRK_HAS_PMU_CNT_EN) { |
Sam Protsenko | cf3fad4 | 2021-11-24 01:26:13 +0200 | [diff] [blame] | 346 | ret = s3c2410wdt_enable_counter(wdt, en); |
Sam Protsenko | aa220bc | 2021-11-21 18:56:43 +0200 | [diff] [blame] | 347 | if (ret < 0) |
| 348 | return ret; |
| 349 | } |
| 350 | |
Sam Protsenko | 2bd33bb | 2021-11-21 18:56:41 +0200 | [diff] [blame] | 351 | return 0; |
| 352 | } |
| 353 | |
Wolfram Sang | 25dc46e | 2011-09-26 15:40:14 +0200 | [diff] [blame] | 354 | static int s3c2410wdt_keepalive(struct watchdog_device *wdd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 356 | struct s3c2410_wdt *wdt = watchdog_get_drvdata(wdd); |
| 357 | |
| 358 | spin_lock(&wdt->lock); |
| 359 | writel(wdt->count, wdt->reg_base + S3C2410_WTCNT); |
| 360 | spin_unlock(&wdt->lock); |
Wolfram Sang | 25dc46e | 2011-09-26 15:40:14 +0200 | [diff] [blame] | 361 | |
| 362 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 365 | static void __s3c2410wdt_stop(struct s3c2410_wdt *wdt) |
Alan Cox | 41dc8b7 | 2008-08-04 17:54:46 +0100 | [diff] [blame] | 366 | { |
| 367 | unsigned long wtcon; |
| 368 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 369 | wtcon = readl(wdt->reg_base + S3C2410_WTCON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | wtcon &= ~(S3C2410_WTCON_ENABLE | S3C2410_WTCON_RSTEN); |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 371 | writel(wtcon, wdt->reg_base + S3C2410_WTCON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Wolfram Sang | 25dc46e | 2011-09-26 15:40:14 +0200 | [diff] [blame] | 374 | static int s3c2410wdt_stop(struct watchdog_device *wdd) |
Alan Cox | 41dc8b7 | 2008-08-04 17:54:46 +0100 | [diff] [blame] | 375 | { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 376 | struct s3c2410_wdt *wdt = watchdog_get_drvdata(wdd); |
| 377 | |
| 378 | spin_lock(&wdt->lock); |
| 379 | __s3c2410wdt_stop(wdt); |
| 380 | spin_unlock(&wdt->lock); |
Wolfram Sang | 25dc46e | 2011-09-26 15:40:14 +0200 | [diff] [blame] | 381 | |
| 382 | return 0; |
Alan Cox | 41dc8b7 | 2008-08-04 17:54:46 +0100 | [diff] [blame] | 383 | } |
| 384 | |
Wolfram Sang | 25dc46e | 2011-09-26 15:40:14 +0200 | [diff] [blame] | 385 | static int s3c2410wdt_start(struct watchdog_device *wdd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | { |
| 387 | unsigned long wtcon; |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 388 | struct s3c2410_wdt *wdt = watchdog_get_drvdata(wdd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 390 | spin_lock(&wdt->lock); |
Alan Cox | 41dc8b7 | 2008-08-04 17:54:46 +0100 | [diff] [blame] | 391 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 392 | __s3c2410wdt_stop(wdt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 394 | wtcon = readl(wdt->reg_base + S3C2410_WTCON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | wtcon |= S3C2410_WTCON_ENABLE | S3C2410_WTCON_DIV128; |
| 396 | |
| 397 | if (soft_noboot) { |
| 398 | wtcon |= S3C2410_WTCON_INTEN; |
| 399 | wtcon &= ~S3C2410_WTCON_RSTEN; |
| 400 | } else { |
| 401 | wtcon &= ~S3C2410_WTCON_INTEN; |
| 402 | wtcon |= S3C2410_WTCON_RSTEN; |
| 403 | } |
| 404 | |
Krzysztof Kozlowski | 456f53d | 2017-02-24 23:07:40 +0200 | [diff] [blame] | 405 | dev_dbg(wdt->dev, "Starting watchdog: count=0x%08x, wtcon=%08lx\n", |
| 406 | wdt->count, wtcon); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 408 | writel(wdt->count, wdt->reg_base + S3C2410_WTDAT); |
| 409 | writel(wdt->count, wdt->reg_base + S3C2410_WTCNT); |
| 410 | writel(wtcon, wdt->reg_base + S3C2410_WTCON); |
| 411 | spin_unlock(&wdt->lock); |
Wolfram Sang | 25dc46e | 2011-09-26 15:40:14 +0200 | [diff] [blame] | 412 | |
| 413 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 416 | static inline int s3c2410wdt_is_running(struct s3c2410_wdt *wdt) |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 417 | { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 418 | return readl(wdt->reg_base + S3C2410_WTCON) & S3C2410_WTCON_ENABLE; |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Krzysztof Kozlowski | 08497f2 | 2017-03-13 21:07:26 +0200 | [diff] [blame] | 421 | static int s3c2410wdt_set_heartbeat(struct watchdog_device *wdd, |
| 422 | unsigned int timeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 424 | struct s3c2410_wdt *wdt = watchdog_get_drvdata(wdd); |
Sam Protsenko | e249d01 | 2021-11-21 18:56:45 +0200 | [diff] [blame] | 425 | unsigned long freq = s3c2410wdt_get_freq(wdt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | unsigned int count; |
| 427 | unsigned int divisor = 1; |
| 428 | unsigned long wtcon; |
| 429 | |
| 430 | if (timeout < 1) |
| 431 | return -EINVAL; |
| 432 | |
Doug Anderson | 1786244 | 2013-11-26 16:57:19 -0800 | [diff] [blame] | 433 | freq = DIV_ROUND_UP(freq, 128); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | count = timeout * freq; |
| 435 | |
Krzysztof Kozlowski | 456f53d | 2017-02-24 23:07:40 +0200 | [diff] [blame] | 436 | dev_dbg(wdt->dev, "Heartbeat: count=%d, timeout=%d, freq=%lu\n", |
| 437 | count, timeout, freq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
| 439 | /* if the count is bigger than the watchdog register, |
| 440 | then work out what we need to do (and if) we can |
| 441 | actually make this value |
| 442 | */ |
| 443 | |
| 444 | if (count >= 0x10000) { |
Doug Anderson | 1786244 | 2013-11-26 16:57:19 -0800 | [diff] [blame] | 445 | divisor = DIV_ROUND_UP(count, 0xffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
Doug Anderson | 1786244 | 2013-11-26 16:57:19 -0800 | [diff] [blame] | 447 | if (divisor > 0x100) { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 448 | dev_err(wdt->dev, "timeout %d too big\n", timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | return -EINVAL; |
| 450 | } |
| 451 | } |
| 452 | |
Krzysztof Kozlowski | 456f53d | 2017-02-24 23:07:40 +0200 | [diff] [blame] | 453 | dev_dbg(wdt->dev, "Heartbeat: timeout=%d, divisor=%d, count=%d (%08x)\n", |
| 454 | timeout, divisor, count, DIV_ROUND_UP(count, divisor)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
Doug Anderson | 1786244 | 2013-11-26 16:57:19 -0800 | [diff] [blame] | 456 | count = DIV_ROUND_UP(count, divisor); |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 457 | wdt->count = count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
| 459 | /* update the pre-scaler */ |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 460 | wtcon = readl(wdt->reg_base + S3C2410_WTCON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | wtcon &= ~S3C2410_WTCON_PRESCALE_MASK; |
| 462 | wtcon |= S3C2410_WTCON_PRESCALE(divisor-1); |
| 463 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 464 | writel(count, wdt->reg_base + S3C2410_WTDAT); |
| 465 | writel(wtcon, wdt->reg_base + S3C2410_WTCON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
Hans de Goede | 5f2430f | 2012-05-11 12:00:27 +0200 | [diff] [blame] | 467 | wdd->timeout = (count * divisor) / freq; |
Wim Van Sebroeck | 0197c1c | 2012-02-29 20:20:58 +0100 | [diff] [blame] | 468 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | return 0; |
| 470 | } |
| 471 | |
Guenter Roeck | 4d8b229 | 2016-02-26 17:32:49 -0800 | [diff] [blame] | 472 | static int s3c2410wdt_restart(struct watchdog_device *wdd, unsigned long action, |
| 473 | void *data) |
Damien Riegel | c71f5cd | 2015-11-16 12:28:10 -0500 | [diff] [blame] | 474 | { |
| 475 | struct s3c2410_wdt *wdt = watchdog_get_drvdata(wdd); |
| 476 | void __iomem *wdt_base = wdt->reg_base; |
| 477 | |
| 478 | /* disable watchdog, to be safe */ |
| 479 | writel(0, wdt_base + S3C2410_WTCON); |
| 480 | |
| 481 | /* put initial values into count and data */ |
| 482 | writel(0x80, wdt_base + S3C2410_WTCNT); |
| 483 | writel(0x80, wdt_base + S3C2410_WTDAT); |
| 484 | |
| 485 | /* set the watchdog to go and reset... */ |
| 486 | writel(S3C2410_WTCON_ENABLE | S3C2410_WTCON_DIV16 | |
| 487 | S3C2410_WTCON_RSTEN | S3C2410_WTCON_PRESCALE(0x20), |
| 488 | wdt_base + S3C2410_WTCON); |
| 489 | |
| 490 | /* wait for reset to assert... */ |
| 491 | mdelay(500); |
| 492 | |
| 493 | return 0; |
| 494 | } |
| 495 | |
Wim Van Sebroeck | a77dba7 | 2009-04-14 20:20:07 +0000 | [diff] [blame] | 496 | #define OPTIONS (WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | |
Alan Cox | 41dc8b7 | 2008-08-04 17:54:46 +0100 | [diff] [blame] | 498 | static const struct watchdog_info s3c2410_wdt_ident = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | .options = OPTIONS, |
| 500 | .firmware_version = 0, |
| 501 | .identity = "S3C2410 Watchdog", |
| 502 | }; |
| 503 | |
Bhumika Goyal | b893e34 | 2017-01-28 13:11:17 +0530 | [diff] [blame] | 504 | static const struct watchdog_ops s3c2410wdt_ops = { |
Wolfram Sang | 25dc46e | 2011-09-26 15:40:14 +0200 | [diff] [blame] | 505 | .owner = THIS_MODULE, |
| 506 | .start = s3c2410wdt_start, |
| 507 | .stop = s3c2410wdt_stop, |
| 508 | .ping = s3c2410wdt_keepalive, |
| 509 | .set_timeout = s3c2410wdt_set_heartbeat, |
Damien Riegel | c71f5cd | 2015-11-16 12:28:10 -0500 | [diff] [blame] | 510 | .restart = s3c2410wdt_restart, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | }; |
| 512 | |
Krzysztof Kozlowski | 58415ef | 2017-03-13 21:07:24 +0200 | [diff] [blame] | 513 | static const struct watchdog_device s3c2410_wdd = { |
Wolfram Sang | 25dc46e | 2011-09-26 15:40:14 +0200 | [diff] [blame] | 514 | .info = &s3c2410_wdt_ident, |
| 515 | .ops = &s3c2410wdt_ops, |
Krzysztof Kozlowski | 4f21195 | 2017-02-24 17:11:15 +0200 | [diff] [blame] | 516 | .timeout = S3C2410_WATCHDOG_DEFAULT_TIME, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | }; |
| 518 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | /* interrupt handler code */ |
| 520 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 521 | static irqreturn_t s3c2410wdt_irq(int irqno, void *param) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 523 | struct s3c2410_wdt *wdt = platform_get_drvdata(param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 525 | dev_info(wdt->dev, "watchdog timer expired (irq)\n"); |
| 526 | |
| 527 | s3c2410wdt_keepalive(&wdt->wdt_device); |
Krzysztof Kozlowski | 0b44554 | 2017-02-24 17:11:16 +0200 | [diff] [blame] | 528 | |
| 529 | if (wdt->drv_data->quirks & QUIRK_HAS_WTCLRINT_REG) |
| 530 | writel(0x1, wdt->reg_base + S3C2410_WTCLRINT); |
| 531 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | return IRQ_HANDLED; |
| 533 | } |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 534 | |
Doug Anderson | 0f1dd98 | 2013-11-25 15:36:43 -0800 | [diff] [blame] | 535 | #ifdef CONFIG_ARM_S3C24XX_CPUFREQ |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 536 | |
| 537 | static int s3c2410wdt_cpufreq_transition(struct notifier_block *nb, |
| 538 | unsigned long val, void *data) |
| 539 | { |
| 540 | int ret; |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 541 | struct s3c2410_wdt *wdt = freq_to_wdt(nb); |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 542 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 543 | if (!s3c2410wdt_is_running(wdt)) |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 544 | goto done; |
| 545 | |
| 546 | if (val == CPUFREQ_PRECHANGE) { |
| 547 | /* To ensure that over the change we don't cause the |
| 548 | * watchdog to trigger, we perform an keep-alive if |
| 549 | * the watchdog is running. |
| 550 | */ |
| 551 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 552 | s3c2410wdt_keepalive(&wdt->wdt_device); |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 553 | } else if (val == CPUFREQ_POSTCHANGE) { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 554 | s3c2410wdt_stop(&wdt->wdt_device); |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 555 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 556 | ret = s3c2410wdt_set_heartbeat(&wdt->wdt_device, |
| 557 | wdt->wdt_device.timeout); |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 558 | |
| 559 | if (ret >= 0) |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 560 | s3c2410wdt_start(&wdt->wdt_device); |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 561 | else |
| 562 | goto err; |
| 563 | } |
| 564 | |
| 565 | done: |
| 566 | return 0; |
| 567 | |
| 568 | err: |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 569 | dev_err(wdt->dev, "cannot set new value for timeout %d\n", |
| 570 | wdt->wdt_device.timeout); |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 571 | return ret; |
| 572 | } |
| 573 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 574 | static inline int s3c2410wdt_cpufreq_register(struct s3c2410_wdt *wdt) |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 575 | { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 576 | wdt->freq_transition.notifier_call = s3c2410wdt_cpufreq_transition; |
| 577 | |
| 578 | return cpufreq_register_notifier(&wdt->freq_transition, |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 579 | CPUFREQ_TRANSITION_NOTIFIER); |
| 580 | } |
| 581 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 582 | static inline void s3c2410wdt_cpufreq_deregister(struct s3c2410_wdt *wdt) |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 583 | { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 584 | wdt->freq_transition.notifier_call = s3c2410wdt_cpufreq_transition; |
| 585 | |
| 586 | cpufreq_unregister_notifier(&wdt->freq_transition, |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 587 | CPUFREQ_TRANSITION_NOTIFIER); |
| 588 | } |
| 589 | |
| 590 | #else |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 591 | |
| 592 | static inline int s3c2410wdt_cpufreq_register(struct s3c2410_wdt *wdt) |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 593 | { |
| 594 | return 0; |
| 595 | } |
| 596 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 597 | static inline void s3c2410wdt_cpufreq_deregister(struct s3c2410_wdt *wdt) |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 598 | { |
| 599 | } |
| 600 | #endif |
| 601 | |
Doug Anderson | cffc9a6 | 2013-12-06 13:08:07 -0800 | [diff] [blame] | 602 | static inline unsigned int s3c2410wdt_get_bootstatus(struct s3c2410_wdt *wdt) |
| 603 | { |
| 604 | unsigned int rst_stat; |
| 605 | int ret; |
| 606 | |
Sam Protsenko | cf3fad4 | 2021-11-24 01:26:13 +0200 | [diff] [blame] | 607 | if (!(wdt->drv_data->quirks & QUIRK_HAS_PMU_RST_STAT)) |
Doug Anderson | cffc9a6 | 2013-12-06 13:08:07 -0800 | [diff] [blame] | 608 | return 0; |
| 609 | |
| 610 | ret = regmap_read(wdt->pmureg, wdt->drv_data->rst_stat_reg, &rst_stat); |
| 611 | if (ret) |
| 612 | dev_warn(wdt->dev, "Couldn't get RST_STAT register\n"); |
| 613 | else if (rst_stat & BIT(wdt->drv_data->rst_stat_bit)) |
| 614 | return WDIOF_CARDRESET; |
| 615 | |
| 616 | return 0; |
| 617 | } |
| 618 | |
Krzysztof Kozlowski | 58415ef | 2017-03-13 21:07:24 +0200 | [diff] [blame] | 619 | static inline const struct s3c2410_wdt_variant * |
Krzysztof Kozlowski | e3a60ea | 2017-02-24 23:07:43 +0200 | [diff] [blame] | 620 | s3c2410_get_wdt_drv_data(struct platform_device *pdev) |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 621 | { |
Krzysztof Kozlowski | a9a02c4 | 2017-03-13 21:07:25 +0200 | [diff] [blame] | 622 | const struct s3c2410_wdt_variant *variant; |
Sam Protsenko | cd4eadf | 2021-11-21 18:56:47 +0200 | [diff] [blame] | 623 | struct device *dev = &pdev->dev; |
Krzysztof Kozlowski | a9a02c4 | 2017-03-13 21:07:25 +0200 | [diff] [blame] | 624 | |
Sam Protsenko | cd4eadf | 2021-11-21 18:56:47 +0200 | [diff] [blame] | 625 | variant = of_device_get_match_data(dev); |
Krzysztof Kozlowski | a9a02c4 | 2017-03-13 21:07:25 +0200 | [diff] [blame] | 626 | if (!variant) { |
| 627 | /* Device matched by platform_device_id */ |
| 628 | variant = (struct s3c2410_wdt_variant *) |
| 629 | platform_get_device_id(pdev)->driver_data; |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 630 | } |
Krzysztof Kozlowski | a9a02c4 | 2017-03-13 21:07:25 +0200 | [diff] [blame] | 631 | |
Sam Protsenko | cd4eadf | 2021-11-21 18:56:47 +0200 | [diff] [blame] | 632 | #ifdef CONFIG_OF |
| 633 | /* Choose Exynos850 driver data w.r.t. cluster index */ |
| 634 | if (variant == &drv_data_exynos850_cl0) { |
| 635 | u32 index; |
| 636 | int err; |
| 637 | |
| 638 | err = of_property_read_u32(dev->of_node, |
| 639 | "samsung,cluster-index", &index); |
| 640 | if (err) { |
| 641 | dev_err(dev, "failed to get cluster index\n"); |
| 642 | return NULL; |
| 643 | } |
| 644 | |
| 645 | switch (index) { |
| 646 | case 0: |
| 647 | return &drv_data_exynos850_cl0; |
| 648 | case 1: |
| 649 | return &drv_data_exynos850_cl1; |
| 650 | default: |
| 651 | dev_err(dev, "wrong cluster index: %u\n", index); |
| 652 | return NULL; |
| 653 | } |
| 654 | } |
| 655 | #endif |
| 656 | |
Krzysztof Kozlowski | a9a02c4 | 2017-03-13 21:07:25 +0200 | [diff] [blame] | 657 | return variant; |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 658 | } |
| 659 | |
Bill Pemberton | 2d991a1 | 2012-11-19 13:21:41 -0500 | [diff] [blame] | 660 | static int s3c2410wdt_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | { |
Krzysztof Kozlowski | 08497f2 | 2017-03-13 21:07:26 +0200 | [diff] [blame] | 662 | struct device *dev = &pdev->dev; |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 663 | struct s3c2410_wdt *wdt; |
Ben Dooks | 46b814d | 2007-06-14 12:08:54 +0100 | [diff] [blame] | 664 | unsigned int wtcon; |
Lad Prabhakar | a51f589 | 2021-12-16 21:47:47 +0000 | [diff] [blame] | 665 | int wdt_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 668 | wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); |
| 669 | if (!wdt) |
| 670 | return -ENOMEM; |
| 671 | |
Krzysztof Kozlowski | 08497f2 | 2017-03-13 21:07:26 +0200 | [diff] [blame] | 672 | wdt->dev = dev; |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 673 | spin_lock_init(&wdt->lock); |
| 674 | wdt->wdt_device = s3c2410_wdd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | |
Krzysztof Kozlowski | e3a60ea | 2017-02-24 23:07:43 +0200 | [diff] [blame] | 676 | wdt->drv_data = s3c2410_get_wdt_drv_data(pdev); |
Sam Protsenko | cd4eadf | 2021-11-21 18:56:47 +0200 | [diff] [blame] | 677 | if (!wdt->drv_data) |
| 678 | return -EINVAL; |
| 679 | |
Doug Anderson | cffc9a6 | 2013-12-06 13:08:07 -0800 | [diff] [blame] | 680 | if (wdt->drv_data->quirks & QUIRKS_HAVE_PMUREG) { |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 681 | wdt->pmureg = syscon_regmap_lookup_by_phandle(dev->of_node, |
| 682 | "samsung,syscon-phandle"); |
| 683 | if (IS_ERR(wdt->pmureg)) { |
| 684 | dev_err(dev, "syscon regmap lookup failed.\n"); |
| 685 | return PTR_ERR(wdt->pmureg); |
| 686 | } |
| 687 | } |
| 688 | |
Lad Prabhakar | a51f589 | 2021-12-16 21:47:47 +0000 | [diff] [blame] | 689 | wdt_irq = platform_get_irq(pdev, 0); |
| 690 | if (wdt_irq < 0) |
| 691 | return wdt_irq; |
MyungJoo Ham | 78d3e00 | 2012-01-13 14:14:23 +0900 | [diff] [blame] | 692 | |
| 693 | /* get the memory region for the watchdog timer */ |
Guenter Roeck | 0f0a6a2 | 2019-04-02 12:01:53 -0700 | [diff] [blame] | 694 | wdt->reg_base = devm_platform_ioremap_resource(pdev, 0); |
Sam Protsenko | 1a47cda | 2021-11-21 18:56:46 +0200 | [diff] [blame] | 695 | if (IS_ERR(wdt->reg_base)) |
| 696 | return PTR_ERR(wdt->reg_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | |
Sam Protsenko | e249d01 | 2021-11-21 18:56:45 +0200 | [diff] [blame] | 698 | wdt->bus_clk = devm_clk_get(dev, "watchdog"); |
| 699 | if (IS_ERR(wdt->bus_clk)) { |
| 700 | dev_err(dev, "failed to find bus clock\n"); |
Sam Protsenko | 1a47cda | 2021-11-21 18:56:46 +0200 | [diff] [blame] | 701 | return PTR_ERR(wdt->bus_clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | } |
| 703 | |
Sam Protsenko | e249d01 | 2021-11-21 18:56:45 +0200 | [diff] [blame] | 704 | ret = clk_prepare_enable(wdt->bus_clk); |
Sachin Kamat | 01b6af9 | 2014-03-04 15:04:35 +0530 | [diff] [blame] | 705 | if (ret < 0) { |
Sam Protsenko | e249d01 | 2021-11-21 18:56:45 +0200 | [diff] [blame] | 706 | dev_err(dev, "failed to enable bus clock\n"); |
Sachin Kamat | 01b6af9 | 2014-03-04 15:04:35 +0530 | [diff] [blame] | 707 | return ret; |
| 708 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | |
Sam Protsenko | e249d01 | 2021-11-21 18:56:45 +0200 | [diff] [blame] | 710 | /* |
| 711 | * "watchdog_src" clock is optional; if it's not present -- just skip it |
| 712 | * and use "watchdog" clock as both bus and source clock. |
| 713 | */ |
Sam Protsenko | f7bcb02 | 2021-12-12 19:02:47 +0200 | [diff] [blame] | 714 | wdt->src_clk = devm_clk_get_optional(dev, "watchdog_src"); |
| 715 | if (IS_ERR(wdt->src_clk)) { |
| 716 | dev_err_probe(dev, PTR_ERR(wdt->src_clk), |
| 717 | "failed to get source clock\n"); |
| 718 | ret = PTR_ERR(wdt->src_clk); |
| 719 | goto err_bus_clk; |
| 720 | } |
| 721 | |
| 722 | ret = clk_prepare_enable(wdt->src_clk); |
| 723 | if (ret) { |
| 724 | dev_err(dev, "failed to enable source clock\n"); |
| 725 | goto err_bus_clk; |
Sam Protsenko | e249d01 | 2021-11-21 18:56:45 +0200 | [diff] [blame] | 726 | } |
| 727 | |
Javier Martinez Canillas | 882dec1 | 2016-03-01 13:45:17 -0300 | [diff] [blame] | 728 | wdt->wdt_device.min_timeout = 1; |
Sam Protsenko | e249d01 | 2021-11-21 18:56:45 +0200 | [diff] [blame] | 729 | wdt->wdt_device.max_timeout = s3c2410wdt_max_timeout(wdt); |
Javier Martinez Canillas | 882dec1 | 2016-03-01 13:45:17 -0300 | [diff] [blame] | 730 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 731 | ret = s3c2410wdt_cpufreq_register(wdt); |
MyungJoo Ham | 78d3e00 | 2012-01-13 14:14:23 +0900 | [diff] [blame] | 732 | if (ret < 0) { |
Jingoo Han | 3828924 | 2013-03-14 10:30:21 +0900 | [diff] [blame] | 733 | dev_err(dev, "failed to register cpufreq\n"); |
Sam Protsenko | e249d01 | 2021-11-21 18:56:45 +0200 | [diff] [blame] | 734 | goto err_src_clk; |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 735 | } |
| 736 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 737 | watchdog_set_drvdata(&wdt->wdt_device, wdt); |
| 738 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | /* see if we can actually set the requested timer margin, and if |
| 740 | * not, try the default value */ |
| 741 | |
Krzysztof Kozlowski | 08497f2 | 2017-03-13 21:07:26 +0200 | [diff] [blame] | 742 | watchdog_init_timeout(&wdt->wdt_device, tmr_margin, dev); |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 743 | ret = s3c2410wdt_set_heartbeat(&wdt->wdt_device, |
| 744 | wdt->wdt_device.timeout); |
| 745 | if (ret) { |
Sam Protsenko | f197d47 | 2021-11-21 18:56:38 +0200 | [diff] [blame] | 746 | ret = s3c2410wdt_set_heartbeat(&wdt->wdt_device, |
| 747 | S3C2410_WATCHDOG_DEFAULT_TIME); |
| 748 | if (ret == 0) { |
| 749 | dev_warn(dev, "tmr_margin value out of range, default %d used\n", |
Krzysztof Kozlowski | 08497f2 | 2017-03-13 21:07:26 +0200 | [diff] [blame] | 750 | S3C2410_WATCHDOG_DEFAULT_TIME); |
Sam Protsenko | f197d47 | 2021-11-21 18:56:38 +0200 | [diff] [blame] | 751 | } else { |
| 752 | dev_err(dev, "failed to use default timeout\n"); |
| 753 | goto err_cpufreq; |
| 754 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | } |
| 756 | |
Lad Prabhakar | a51f589 | 2021-12-16 21:47:47 +0000 | [diff] [blame] | 757 | ret = devm_request_irq(dev, wdt_irq, s3c2410wdt_irq, 0, |
| 758 | pdev->name, pdev); |
MyungJoo Ham | 78d3e00 | 2012-01-13 14:14:23 +0900 | [diff] [blame] | 759 | if (ret != 0) { |
| 760 | dev_err(dev, "failed to install irq (%d)\n", ret); |
| 761 | goto err_cpufreq; |
| 762 | } |
| 763 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 764 | watchdog_set_nowayout(&wdt->wdt_device, nowayout); |
Damien Riegel | c71f5cd | 2015-11-16 12:28:10 -0500 | [diff] [blame] | 765 | watchdog_set_restart_priority(&wdt->wdt_device, 128); |
Wim Van Sebroeck | ff0b3cd | 2011-11-29 16:24:16 +0100 | [diff] [blame] | 766 | |
Doug Anderson | cffc9a6 | 2013-12-06 13:08:07 -0800 | [diff] [blame] | 767 | wdt->wdt_device.bootstatus = s3c2410wdt_get_bootstatus(wdt); |
Krzysztof Kozlowski | 08497f2 | 2017-03-13 21:07:26 +0200 | [diff] [blame] | 768 | wdt->wdt_device.parent = dev; |
Doug Anderson | cffc9a6 | 2013-12-06 13:08:07 -0800 | [diff] [blame] | 769 | |
Sam Protsenko | a90102e | 2021-11-21 18:56:39 +0200 | [diff] [blame] | 770 | /* |
| 771 | * If "tmr_atboot" param is non-zero, start the watchdog right now. Also |
| 772 | * set WDOG_HW_RUNNING bit, so that watchdog core can kick the watchdog. |
| 773 | * |
| 774 | * If we're not enabling the watchdog, then ensure it is disabled if it |
| 775 | * has been left running from the bootloader or other source. |
| 776 | */ |
| 777 | if (tmr_atboot) { |
| 778 | dev_info(dev, "starting watchdog timer\n"); |
| 779 | s3c2410wdt_start(&wdt->wdt_device); |
| 780 | set_bit(WDOG_HW_RUNNING, &wdt->wdt_device.status); |
| 781 | } else { |
| 782 | s3c2410wdt_stop(&wdt->wdt_device); |
| 783 | } |
| 784 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 785 | ret = watchdog_register_device(&wdt->wdt_device); |
Wolfram Sang | 386f465 | 2019-05-18 23:27:50 +0200 | [diff] [blame] | 786 | if (ret) |
Jingoo Han | 04ecc7d | 2013-01-10 11:06:33 +0900 | [diff] [blame] | 787 | goto err_cpufreq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | |
Sam Protsenko | cf3fad4 | 2021-11-24 01:26:13 +0200 | [diff] [blame] | 789 | ret = s3c2410wdt_enable(wdt, true); |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 790 | if (ret < 0) |
| 791 | goto err_unregister; |
| 792 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 793 | platform_set_drvdata(pdev, wdt); |
| 794 | |
Ben Dooks | 46b814d | 2007-06-14 12:08:54 +0100 | [diff] [blame] | 795 | /* print out a statement of readiness */ |
| 796 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 797 | wtcon = readl(wdt->reg_base + S3C2410_WTCON); |
Ben Dooks | 46b814d | 2007-06-14 12:08:54 +0100 | [diff] [blame] | 798 | |
Ben Dooks | e8ef92b | 2007-06-14 12:08:55 +0100 | [diff] [blame] | 799 | dev_info(dev, "watchdog %sactive, reset %sabled, irq %sabled\n", |
Ben Dooks | 46b814d | 2007-06-14 12:08:54 +0100 | [diff] [blame] | 800 | (wtcon & S3C2410_WTCON_ENABLE) ? "" : "in", |
Dmitry Artamonow | 20403e8 | 2011-11-16 12:46:13 +0400 | [diff] [blame] | 801 | (wtcon & S3C2410_WTCON_RSTEN) ? "en" : "dis", |
| 802 | (wtcon & S3C2410_WTCON_INTEN) ? "en" : "dis"); |
Alan Cox | 41dc8b7 | 2008-08-04 17:54:46 +0100 | [diff] [blame] | 803 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | return 0; |
Ben Dooks | 0b6dd8a | 2006-12-18 10:31:32 +0000 | [diff] [blame] | 805 | |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 806 | err_unregister: |
| 807 | watchdog_unregister_device(&wdt->wdt_device); |
| 808 | |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 809 | err_cpufreq: |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 810 | s3c2410wdt_cpufreq_deregister(wdt); |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 811 | |
Sam Protsenko | e249d01 | 2021-11-21 18:56:45 +0200 | [diff] [blame] | 812 | err_src_clk: |
| 813 | clk_disable_unprepare(wdt->src_clk); |
| 814 | |
| 815 | err_bus_clk: |
| 816 | clk_disable_unprepare(wdt->bus_clk); |
Ben Dooks | 0b6dd8a | 2006-12-18 10:31:32 +0000 | [diff] [blame] | 817 | |
Ben Dooks | 0b6dd8a | 2006-12-18 10:31:32 +0000 | [diff] [blame] | 818 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | } |
| 820 | |
Bill Pemberton | 4b12b89 | 2012-11-19 13:26:24 -0500 | [diff] [blame] | 821 | static int s3c2410wdt_remove(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | { |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 823 | int ret; |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 824 | struct s3c2410_wdt *wdt = platform_get_drvdata(dev); |
Wim Van Sebroeck | 9a37256 | 2010-05-21 08:11:42 +0000 | [diff] [blame] | 825 | |
Sam Protsenko | cf3fad4 | 2021-11-24 01:26:13 +0200 | [diff] [blame] | 826 | ret = s3c2410wdt_enable(wdt, false); |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 827 | if (ret < 0) |
| 828 | return ret; |
| 829 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 830 | watchdog_unregister_device(&wdt->wdt_device); |
Ben Dooks | e02f838 | 2009-10-30 00:30:25 +0000 | [diff] [blame] | 831 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 832 | s3c2410wdt_cpufreq_deregister(wdt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | |
Sam Protsenko | e249d01 | 2021-11-21 18:56:45 +0200 | [diff] [blame] | 834 | clk_disable_unprepare(wdt->src_clk); |
| 835 | clk_disable_unprepare(wdt->bus_clk); |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 836 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | return 0; |
| 838 | } |
| 839 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 840 | static void s3c2410wdt_shutdown(struct platform_device *dev) |
Ben Dooks | 94f1e9f | 2005-08-17 09:04:52 +0200 | [diff] [blame] | 841 | { |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 842 | struct s3c2410_wdt *wdt = platform_get_drvdata(dev); |
| 843 | |
Sam Protsenko | cf3fad4 | 2021-11-24 01:26:13 +0200 | [diff] [blame] | 844 | s3c2410wdt_enable(wdt, false); |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 845 | s3c2410wdt_stop(&wdt->wdt_device); |
Ben Dooks | 94f1e9f | 2005-08-17 09:04:52 +0200 | [diff] [blame] | 846 | } |
| 847 | |
Jingoo Han | 0183984c | 2013-03-14 10:31:21 +0900 | [diff] [blame] | 848 | #ifdef CONFIG_PM_SLEEP |
Ben Dooks | af4bb82 | 2005-08-17 09:03:23 +0200 | [diff] [blame] | 849 | |
Jingoo Han | 0183984c | 2013-03-14 10:31:21 +0900 | [diff] [blame] | 850 | static int s3c2410wdt_suspend(struct device *dev) |
Ben Dooks | af4bb82 | 2005-08-17 09:03:23 +0200 | [diff] [blame] | 851 | { |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 852 | int ret; |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 853 | struct s3c2410_wdt *wdt = dev_get_drvdata(dev); |
| 854 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 855 | /* Save watchdog state, and turn it off. */ |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 856 | wdt->wtcon_save = readl(wdt->reg_base + S3C2410_WTCON); |
| 857 | wdt->wtdat_save = readl(wdt->reg_base + S3C2410_WTDAT); |
Ben Dooks | af4bb82 | 2005-08-17 09:03:23 +0200 | [diff] [blame] | 858 | |
Sam Protsenko | cf3fad4 | 2021-11-24 01:26:13 +0200 | [diff] [blame] | 859 | ret = s3c2410wdt_enable(wdt, false); |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 860 | if (ret < 0) |
| 861 | return ret; |
| 862 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 863 | /* Note that WTCNT doesn't need to be saved. */ |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 864 | s3c2410wdt_stop(&wdt->wdt_device); |
Ben Dooks | af4bb82 | 2005-08-17 09:03:23 +0200 | [diff] [blame] | 865 | |
| 866 | return 0; |
| 867 | } |
| 868 | |
Jingoo Han | 0183984c | 2013-03-14 10:31:21 +0900 | [diff] [blame] | 869 | static int s3c2410wdt_resume(struct device *dev) |
Ben Dooks | af4bb82 | 2005-08-17 09:03:23 +0200 | [diff] [blame] | 870 | { |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 871 | int ret; |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 872 | struct s3c2410_wdt *wdt = dev_get_drvdata(dev); |
Ben Dooks | af4bb82 | 2005-08-17 09:03:23 +0200 | [diff] [blame] | 873 | |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 874 | /* Restore watchdog state. */ |
| 875 | writel(wdt->wtdat_save, wdt->reg_base + S3C2410_WTDAT); |
| 876 | writel(wdt->wtdat_save, wdt->reg_base + S3C2410_WTCNT);/* Reset count */ |
| 877 | writel(wdt->wtcon_save, wdt->reg_base + S3C2410_WTCON); |
Ben Dooks | af4bb82 | 2005-08-17 09:03:23 +0200 | [diff] [blame] | 878 | |
Sam Protsenko | cf3fad4 | 2021-11-24 01:26:13 +0200 | [diff] [blame] | 879 | ret = s3c2410wdt_enable(wdt, true); |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 880 | if (ret < 0) |
| 881 | return ret; |
| 882 | |
Jingoo Han | 0183984c | 2013-03-14 10:31:21 +0900 | [diff] [blame] | 883 | dev_info(dev, "watchdog %sabled\n", |
Leela Krishna Amudala | af4ea63 | 2013-08-27 15:36:03 +0530 | [diff] [blame] | 884 | (wdt->wtcon_save & S3C2410_WTCON_ENABLE) ? "en" : "dis"); |
Ben Dooks | af4bb82 | 2005-08-17 09:03:23 +0200 | [diff] [blame] | 885 | |
| 886 | return 0; |
| 887 | } |
Jingoo Han | 0183984c | 2013-03-14 10:31:21 +0900 | [diff] [blame] | 888 | #endif |
Ben Dooks | af4bb82 | 2005-08-17 09:03:23 +0200 | [diff] [blame] | 889 | |
Jingoo Han | 0183984c | 2013-03-14 10:31:21 +0900 | [diff] [blame] | 890 | static SIMPLE_DEV_PM_OPS(s3c2410wdt_pm_ops, s3c2410wdt_suspend, |
| 891 | s3c2410wdt_resume); |
Ben Dooks | af4bb82 | 2005-08-17 09:03:23 +0200 | [diff] [blame] | 892 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 893 | static struct platform_driver s3c2410wdt_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | .probe = s3c2410wdt_probe, |
Bill Pemberton | 8226871 | 2012-11-19 13:21:12 -0500 | [diff] [blame] | 895 | .remove = s3c2410wdt_remove, |
Ben Dooks | 94f1e9f | 2005-08-17 09:04:52 +0200 | [diff] [blame] | 896 | .shutdown = s3c2410wdt_shutdown, |
Leela Krishna Amudala | 4f1f653 | 2013-12-06 11:17:47 +0530 | [diff] [blame] | 897 | .id_table = s3c2410_wdt_ids, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 898 | .driver = { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 899 | .name = "s3c2410-wdt", |
Jingoo Han | 0183984c | 2013-03-14 10:31:21 +0900 | [diff] [blame] | 900 | .pm = &s3c2410wdt_pm_ops, |
Wim Van Sebroeck | 3016a55 | 2012-05-03 05:24:17 +0000 | [diff] [blame] | 901 | .of_match_table = of_match_ptr(s3c2410_wdt_match), |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 902 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | }; |
| 904 | |
Sachin Kamat | 6b761b2 | 2012-07-12 17:17:40 +0530 | [diff] [blame] | 905 | module_platform_driver(s3c2410wdt_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | |
Krzysztof Kozlowski | 08497f2 | 2017-03-13 21:07:26 +0200 | [diff] [blame] | 907 | MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>, Dimitry Andric <dimitry.andric@tomtom.com>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | MODULE_DESCRIPTION("S3C2410 Watchdog Device Driver"); |
| 909 | MODULE_LICENSE("GPL"); |