Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 1 | /* |
Nicolas Pitre | 3b937a7db | 2009-06-01 13:56:02 -0400 | [diff] [blame] | 2 | * drivers/watchdog/orion_wdt.c |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 3 | * |
Nicolas Pitre | 3b937a7db | 2009-06-01 13:56:02 -0400 | [diff] [blame] | 4 | * Watchdog driver for Orion/Kirkwood processors |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 5 | * |
| 6 | * Author: Sylver Bruneau <sylver.bruneau@googlemail.com> |
| 7 | * |
| 8 | * This file is licensed under the terms of the GNU General Public |
| 9 | * License version 2. This program is licensed "as is" without any |
| 10 | * warranty of any kind, whether express or implied. |
| 11 | */ |
| 12 | |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 13 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 14 | |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 15 | #include <linux/module.h> |
| 16 | #include <linux/moduleparam.h> |
| 17 | #include <linux/types.h> |
| 18 | #include <linux/kernel.h> |
Thomas Reitmayr | 9e058d4 | 2009-02-24 14:59:22 -0800 | [diff] [blame] | 19 | #include <linux/platform_device.h> |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 20 | #include <linux/watchdog.h> |
| 21 | #include <linux/init.h> |
Ezequiel Garcia | e97662e | 2014-02-10 20:00:24 -0300 | [diff] [blame] | 22 | #include <linux/interrupt.h> |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 23 | #include <linux/io.h> |
Andrew Lunn | 4f04be6 | 2012-03-04 16:57:31 +0100 | [diff] [blame] | 24 | #include <linux/clk.h> |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 25 | #include <linux/err.h> |
Andrew Lunn | 1e7bad0 | 2012-06-10 15:20:06 +0200 | [diff] [blame] | 26 | #include <linux/of.h> |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 27 | #include <linux/of_device.h> |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 28 | |
Ezequiel Garcia | 868eb61 | 2014-02-10 20:00:25 -0300 | [diff] [blame] | 29 | /* RSTOUT mask register physical address for Orion5x, Kirkwood and Dove */ |
| 30 | #define ORION_RSTOUT_MASK_OFFSET 0x20108 |
| 31 | |
| 32 | /* Internal registers can be configured at any 1 MiB aligned address */ |
| 33 | #define INTERNAL_REGS_MASK ~(SZ_1M - 1) |
| 34 | |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 35 | /* |
| 36 | * Watchdog timer block registers. |
| 37 | */ |
Jason Cooper | a855a7c | 2012-03-15 00:33:26 +0000 | [diff] [blame] | 38 | #define TIMER_CTRL 0x0000 |
Ezequiel Garcia | 463f96e | 2014-02-10 20:00:31 -0300 | [diff] [blame^] | 39 | #define TIMER_A370_STATUS 0x04 |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 40 | |
Thomas Reitmayr | 9e058d4 | 2009-02-24 14:59:22 -0800 | [diff] [blame] | 41 | #define WDT_MAX_CYCLE_COUNT 0xffffffff |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 42 | |
Ezequiel Garcia | 463f96e | 2014-02-10 20:00:31 -0300 | [diff] [blame^] | 43 | #define WDT_A370_RATIO_MASK(v) ((v) << 16) |
| 44 | #define WDT_A370_RATIO_SHIFT 5 |
| 45 | #define WDT_A370_RATIO (1 << WDT_A370_RATIO_SHIFT) |
| 46 | |
| 47 | #define WDT_AXP_FIXED_ENABLE_BIT BIT(10) |
| 48 | #define WDT_A370_EXPIRED BIT(31) |
| 49 | |
Wim Van Sebroeck | 86a1e18 | 2012-03-05 16:51:11 +0100 | [diff] [blame] | 50 | static bool nowayout = WATCHDOG_NOWAYOUT; |
Thomas Reitmayr | 9e058d4 | 2009-02-24 14:59:22 -0800 | [diff] [blame] | 51 | static int heartbeat = -1; /* module parameter (seconds) */ |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 52 | |
Ezequiel Garcia | 1924227 | 2014-02-10 20:00:29 -0300 | [diff] [blame] | 53 | struct orion_watchdog; |
| 54 | |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 55 | struct orion_watchdog_data { |
| 56 | int wdt_counter_offset; |
| 57 | int wdt_enable_bit; |
| 58 | int rstout_enable_bit; |
Ezequiel Garcia | 1924227 | 2014-02-10 20:00:29 -0300 | [diff] [blame] | 59 | int (*clock_init)(struct platform_device *, |
| 60 | struct orion_watchdog *); |
Ezequiel Garcia | 490d8e3 | 2014-02-10 20:00:30 -0300 | [diff] [blame] | 61 | int (*start)(struct watchdog_device *); |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 62 | }; |
| 63 | |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 64 | struct orion_watchdog { |
| 65 | struct watchdog_device wdt; |
| 66 | void __iomem *reg; |
| 67 | void __iomem *rstout; |
| 68 | unsigned long clk_rate; |
| 69 | struct clk *clk; |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 70 | const struct orion_watchdog_data *data; |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 71 | }; |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 72 | |
Ezequiel Garcia | 1924227 | 2014-02-10 20:00:29 -0300 | [diff] [blame] | 73 | static int orion_wdt_clock_init(struct platform_device *pdev, |
| 74 | struct orion_watchdog *dev) |
| 75 | { |
| 76 | int ret; |
| 77 | |
Ezequiel Garcia | 463f96e | 2014-02-10 20:00:31 -0300 | [diff] [blame^] | 78 | dev->clk = clk_get(&pdev->dev, NULL); |
Ezequiel Garcia | 1924227 | 2014-02-10 20:00:29 -0300 | [diff] [blame] | 79 | if (IS_ERR(dev->clk)) |
| 80 | return PTR_ERR(dev->clk); |
| 81 | ret = clk_prepare_enable(dev->clk); |
Ezequiel Garcia | 463f96e | 2014-02-10 20:00:31 -0300 | [diff] [blame^] | 82 | if (ret) { |
| 83 | clk_put(dev->clk); |
Ezequiel Garcia | 1924227 | 2014-02-10 20:00:29 -0300 | [diff] [blame] | 84 | return ret; |
Ezequiel Garcia | 463f96e | 2014-02-10 20:00:31 -0300 | [diff] [blame^] | 85 | } |
| 86 | |
| 87 | dev->clk_rate = clk_get_rate(dev->clk); |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | static int armada370_wdt_clock_init(struct platform_device *pdev, |
| 92 | struct orion_watchdog *dev) |
| 93 | { |
| 94 | int ret; |
| 95 | |
| 96 | dev->clk = clk_get(&pdev->dev, NULL); |
| 97 | if (IS_ERR(dev->clk)) |
| 98 | return PTR_ERR(dev->clk); |
| 99 | ret = clk_prepare_enable(dev->clk); |
| 100 | if (ret) { |
| 101 | clk_put(dev->clk); |
| 102 | return ret; |
| 103 | } |
| 104 | |
| 105 | /* Setup watchdog input clock */ |
| 106 | atomic_io_modify(dev->reg + TIMER_CTRL, |
| 107 | WDT_A370_RATIO_MASK(WDT_A370_RATIO_SHIFT), |
| 108 | WDT_A370_RATIO_MASK(WDT_A370_RATIO_SHIFT)); |
| 109 | |
| 110 | dev->clk_rate = clk_get_rate(dev->clk) / WDT_A370_RATIO; |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | static int armadaxp_wdt_clock_init(struct platform_device *pdev, |
| 115 | struct orion_watchdog *dev) |
| 116 | { |
| 117 | int ret; |
| 118 | |
| 119 | dev->clk = of_clk_get_by_name(pdev->dev.of_node, "fixed"); |
| 120 | if (IS_ERR(dev->clk)) |
| 121 | return PTR_ERR(dev->clk); |
| 122 | ret = clk_prepare_enable(dev->clk); |
| 123 | if (ret) { |
| 124 | clk_put(dev->clk); |
| 125 | return ret; |
| 126 | } |
| 127 | |
| 128 | /* Enable the fixed watchdog clock input */ |
| 129 | atomic_io_modify(dev->reg + TIMER_CTRL, |
| 130 | WDT_AXP_FIXED_ENABLE_BIT, |
| 131 | WDT_AXP_FIXED_ENABLE_BIT); |
Ezequiel Garcia | 1924227 | 2014-02-10 20:00:29 -0300 | [diff] [blame] | 132 | |
| 133 | dev->clk_rate = clk_get_rate(dev->clk); |
| 134 | return 0; |
| 135 | } |
| 136 | |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 137 | static int orion_wdt_ping(struct watchdog_device *wdt_dev) |
Thomas Reitmayr | df6707b | 2009-02-20 19:44:59 +0100 | [diff] [blame] | 138 | { |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 139 | struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev); |
Thomas Reitmayr | df6707b | 2009-02-20 19:44:59 +0100 | [diff] [blame] | 140 | /* Reload watchdog duration */ |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 141 | writel(dev->clk_rate * wdt_dev->timeout, |
| 142 | dev->reg + dev->data->wdt_counter_offset); |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 143 | return 0; |
Thomas Reitmayr | df6707b | 2009-02-20 19:44:59 +0100 | [diff] [blame] | 144 | } |
| 145 | |
Ezequiel Garcia | 463f96e | 2014-02-10 20:00:31 -0300 | [diff] [blame^] | 146 | static int armada370_start(struct watchdog_device *wdt_dev) |
| 147 | { |
| 148 | struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev); |
| 149 | |
| 150 | /* Set watchdog duration */ |
| 151 | writel(dev->clk_rate * wdt_dev->timeout, |
| 152 | dev->reg + dev->data->wdt_counter_offset); |
| 153 | |
| 154 | /* Clear the watchdog expiration bit */ |
| 155 | atomic_io_modify(dev->reg + TIMER_A370_STATUS, WDT_A370_EXPIRED, 0); |
| 156 | |
| 157 | /* Enable watchdog timer */ |
| 158 | atomic_io_modify(dev->reg + TIMER_CTRL, dev->data->wdt_enable_bit, |
| 159 | dev->data->wdt_enable_bit); |
| 160 | |
| 161 | atomic_io_modify(dev->rstout, dev->data->rstout_enable_bit, |
| 162 | dev->data->rstout_enable_bit); |
| 163 | return 0; |
| 164 | } |
| 165 | |
Ezequiel Garcia | 490d8e3 | 2014-02-10 20:00:30 -0300 | [diff] [blame] | 166 | static int orion_start(struct watchdog_device *wdt_dev) |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 167 | { |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 168 | struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev); |
| 169 | |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 170 | /* Set watchdog duration */ |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 171 | writel(dev->clk_rate * wdt_dev->timeout, |
| 172 | dev->reg + dev->data->wdt_counter_offset); |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 173 | |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 174 | /* Enable watchdog timer */ |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 175 | atomic_io_modify(dev->reg + TIMER_CTRL, dev->data->wdt_enable_bit, |
| 176 | dev->data->wdt_enable_bit); |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 177 | |
| 178 | /* Enable reset on watchdog */ |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 179 | atomic_io_modify(dev->rstout, dev->data->rstout_enable_bit, |
| 180 | dev->data->rstout_enable_bit); |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 181 | |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 182 | return 0; |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 183 | } |
| 184 | |
Ezequiel Garcia | 490d8e3 | 2014-02-10 20:00:30 -0300 | [diff] [blame] | 185 | static int orion_wdt_start(struct watchdog_device *wdt_dev) |
| 186 | { |
| 187 | struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev); |
| 188 | |
| 189 | /* There are some per-SoC quirks to handle */ |
| 190 | return dev->data->start(wdt_dev); |
| 191 | } |
| 192 | |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 193 | static int orion_wdt_stop(struct watchdog_device *wdt_dev) |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 194 | { |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 195 | struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev); |
| 196 | |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 197 | /* Disable reset on watchdog */ |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 198 | atomic_io_modify(dev->rstout, dev->data->rstout_enable_bit, 0); |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 199 | |
| 200 | /* Disable watchdog timer */ |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 201 | atomic_io_modify(dev->reg + TIMER_CTRL, dev->data->wdt_enable_bit, 0); |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 202 | |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 203 | return 0; |
Wim Van Sebroeck | 6d0f0df | 2008-10-02 09:32:45 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 206 | static int orion_wdt_enabled(struct orion_watchdog *dev) |
Ezequiel Garcia | d9d0c53 | 2014-02-10 20:00:23 -0300 | [diff] [blame] | 207 | { |
| 208 | bool enabled, running; |
| 209 | |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 210 | enabled = readl(dev->rstout) & dev->data->rstout_enable_bit; |
| 211 | running = readl(dev->reg + TIMER_CTRL) & dev->data->wdt_enable_bit; |
Ezequiel Garcia | d9d0c53 | 2014-02-10 20:00:23 -0300 | [diff] [blame] | 212 | |
| 213 | return enabled && running; |
| 214 | } |
| 215 | |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 216 | static unsigned int orion_wdt_get_timeleft(struct watchdog_device *wdt_dev) |
Wim Van Sebroeck | 6d0f0df | 2008-10-02 09:32:45 +0000 | [diff] [blame] | 217 | { |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 218 | struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev); |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 219 | return readl(dev->reg + dev->data->wdt_counter_offset) / dev->clk_rate; |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | static int orion_wdt_set_timeout(struct watchdog_device *wdt_dev, |
| 223 | unsigned int timeout) |
| 224 | { |
| 225 | wdt_dev->timeout = timeout; |
Wim Van Sebroeck | 6d0f0df | 2008-10-02 09:32:45 +0000 | [diff] [blame] | 226 | return 0; |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 227 | } |
| 228 | |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 229 | static const struct watchdog_info orion_wdt_info = { |
| 230 | .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, |
| 231 | .identity = "Orion Watchdog", |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 232 | }; |
| 233 | |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 234 | static const struct watchdog_ops orion_wdt_ops = { |
| 235 | .owner = THIS_MODULE, |
| 236 | .start = orion_wdt_start, |
| 237 | .stop = orion_wdt_stop, |
| 238 | .ping = orion_wdt_ping, |
| 239 | .set_timeout = orion_wdt_set_timeout, |
| 240 | .get_timeleft = orion_wdt_get_timeleft, |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 241 | }; |
| 242 | |
Ezequiel Garcia | e97662e | 2014-02-10 20:00:24 -0300 | [diff] [blame] | 243 | static irqreturn_t orion_wdt_irq(int irq, void *devid) |
| 244 | { |
| 245 | panic("Watchdog Timeout"); |
| 246 | return IRQ_HANDLED; |
| 247 | } |
| 248 | |
Ezequiel Garcia | 868eb61 | 2014-02-10 20:00:25 -0300 | [diff] [blame] | 249 | /* |
| 250 | * The original devicetree binding for this driver specified only |
| 251 | * one memory resource, so in order to keep DT backwards compatibility |
| 252 | * we try to fallback to a hardcoded register address, if the resource |
| 253 | * is missing from the devicetree. |
| 254 | */ |
| 255 | static void __iomem *orion_wdt_ioremap_rstout(struct platform_device *pdev, |
| 256 | phys_addr_t internal_regs) |
| 257 | { |
| 258 | struct resource *res; |
| 259 | phys_addr_t rstout; |
| 260 | |
| 261 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 262 | if (res) |
| 263 | return devm_ioremap(&pdev->dev, res->start, |
| 264 | resource_size(res)); |
| 265 | |
| 266 | /* This workaround works only for "orion-wdt", DT-enabled */ |
| 267 | if (!of_device_is_compatible(pdev->dev.of_node, "marvell,orion-wdt")) |
| 268 | return NULL; |
| 269 | |
| 270 | rstout = internal_regs + ORION_RSTOUT_MASK_OFFSET; |
| 271 | |
| 272 | WARN(1, FW_BUG "falling back to harcoded RSTOUT reg 0x%x\n", rstout); |
| 273 | return devm_ioremap(&pdev->dev, rstout, 0x4); |
| 274 | } |
| 275 | |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 276 | static const struct orion_watchdog_data orion_data = { |
| 277 | .rstout_enable_bit = BIT(1), |
| 278 | .wdt_enable_bit = BIT(4), |
| 279 | .wdt_counter_offset = 0x24, |
Ezequiel Garcia | 1924227 | 2014-02-10 20:00:29 -0300 | [diff] [blame] | 280 | .clock_init = orion_wdt_clock_init, |
Ezequiel Garcia | 490d8e3 | 2014-02-10 20:00:30 -0300 | [diff] [blame] | 281 | .start = orion_start, |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 282 | }; |
| 283 | |
Ezequiel Garcia | 463f96e | 2014-02-10 20:00:31 -0300 | [diff] [blame^] | 284 | static const struct orion_watchdog_data armada370_data = { |
| 285 | .rstout_enable_bit = BIT(8), |
| 286 | .wdt_enable_bit = BIT(8), |
| 287 | .wdt_counter_offset = 0x34, |
| 288 | .clock_init = armada370_wdt_clock_init, |
| 289 | .start = armada370_start, |
| 290 | }; |
| 291 | |
| 292 | static const struct orion_watchdog_data armadaxp_data = { |
| 293 | .rstout_enable_bit = BIT(8), |
| 294 | .wdt_enable_bit = BIT(8), |
| 295 | .wdt_counter_offset = 0x34, |
| 296 | .clock_init = armadaxp_wdt_clock_init, |
| 297 | .start = armada370_start, |
| 298 | }; |
| 299 | |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 300 | static const struct of_device_id orion_wdt_of_match_table[] = { |
| 301 | { |
| 302 | .compatible = "marvell,orion-wdt", |
| 303 | .data = &orion_data, |
| 304 | }, |
Ezequiel Garcia | 463f96e | 2014-02-10 20:00:31 -0300 | [diff] [blame^] | 305 | { |
| 306 | .compatible = "marvell,armada-370-wdt", |
| 307 | .data = &armada370_data, |
| 308 | }, |
| 309 | { |
| 310 | .compatible = "marvell,armada-xp-wdt", |
| 311 | .data = &armadaxp_data, |
| 312 | }, |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 313 | {}, |
| 314 | }; |
| 315 | MODULE_DEVICE_TABLE(of, orion_wdt_of_match_table); |
| 316 | |
Bill Pemberton | 2d991a1 | 2012-11-19 13:21:41 -0500 | [diff] [blame] | 317 | static int orion_wdt_probe(struct platform_device *pdev) |
Thomas Reitmayr | 9e058d4 | 2009-02-24 14:59:22 -0800 | [diff] [blame] | 318 | { |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 319 | struct orion_watchdog *dev; |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 320 | const struct of_device_id *match; |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 321 | unsigned int wdt_max_duration; /* (seconds) */ |
Jason Cooper | a855a7c | 2012-03-15 00:33:26 +0000 | [diff] [blame] | 322 | struct resource *res; |
Ezequiel Garcia | e97662e | 2014-02-10 20:00:24 -0300 | [diff] [blame] | 323 | int ret, irq; |
Thomas Reitmayr | 9e058d4 | 2009-02-24 14:59:22 -0800 | [diff] [blame] | 324 | |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 325 | dev = devm_kzalloc(&pdev->dev, sizeof(struct orion_watchdog), |
| 326 | GFP_KERNEL); |
| 327 | if (!dev) |
| 328 | return -ENOMEM; |
| 329 | |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 330 | match = of_match_device(orion_wdt_of_match_table, &pdev->dev); |
| 331 | if (!match) |
| 332 | /* Default legacy match */ |
| 333 | match = &orion_wdt_of_match_table[0]; |
| 334 | |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 335 | dev->wdt.info = &orion_wdt_info; |
| 336 | dev->wdt.ops = &orion_wdt_ops; |
| 337 | dev->wdt.min_timeout = 1; |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 338 | dev->data = match->data; |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 339 | |
Jason Cooper | a855a7c | 2012-03-15 00:33:26 +0000 | [diff] [blame] | 340 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Ezequiel Garcia | 1924227 | 2014-02-10 20:00:29 -0300 | [diff] [blame] | 341 | if (!res) |
| 342 | return -ENODEV; |
Ezequiel Garcia | bb02c66 | 2014-02-10 20:00:20 -0300 | [diff] [blame] | 343 | |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 344 | dev->reg = devm_ioremap(&pdev->dev, res->start, |
| 345 | resource_size(res)); |
Ezequiel Garcia | 1924227 | 2014-02-10 20:00:29 -0300 | [diff] [blame] | 346 | if (!dev->reg) |
| 347 | return -ENOMEM; |
Thomas Reitmayr | 9e058d4 | 2009-02-24 14:59:22 -0800 | [diff] [blame] | 348 | |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 349 | dev->rstout = orion_wdt_ioremap_rstout(pdev, res->start & |
| 350 | INTERNAL_REGS_MASK); |
Ezequiel Garcia | 1924227 | 2014-02-10 20:00:29 -0300 | [diff] [blame] | 351 | if (!dev->rstout) |
| 352 | return -ENODEV; |
| 353 | |
| 354 | ret = dev->data->clock_init(pdev, dev); |
| 355 | if (ret) { |
| 356 | dev_err(&pdev->dev, "cannot initialize clock\n"); |
| 357 | return ret; |
Ezequiel Garcia | 868eb61 | 2014-02-10 20:00:25 -0300 | [diff] [blame] | 358 | } |
| 359 | |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 360 | wdt_max_duration = WDT_MAX_CYCLE_COUNT / dev->clk_rate; |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 361 | |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 362 | dev->wdt.timeout = wdt_max_duration; |
| 363 | dev->wdt.max_timeout = wdt_max_duration; |
| 364 | watchdog_init_timeout(&dev->wdt, heartbeat, &pdev->dev); |
| 365 | |
| 366 | platform_set_drvdata(pdev, &dev->wdt); |
| 367 | watchdog_set_drvdata(&dev->wdt, dev); |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 368 | |
Ezequiel Garcia | d9d0c53 | 2014-02-10 20:00:23 -0300 | [diff] [blame] | 369 | /* |
| 370 | * Let's make sure the watchdog is fully stopped, unless it's |
| 371 | * explicitly enabled. This may be the case if the module was |
| 372 | * removed and re-insterted, or if the bootloader explicitly |
| 373 | * set a running watchdog before booting the kernel. |
| 374 | */ |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 375 | if (!orion_wdt_enabled(dev)) |
| 376 | orion_wdt_stop(&dev->wdt); |
Ezequiel Garcia | d9d0c53 | 2014-02-10 20:00:23 -0300 | [diff] [blame] | 377 | |
Ezequiel Garcia | e97662e | 2014-02-10 20:00:24 -0300 | [diff] [blame] | 378 | /* Request the IRQ only after the watchdog is disabled */ |
| 379 | irq = platform_get_irq(pdev, 0); |
| 380 | if (irq > 0) { |
| 381 | /* |
| 382 | * Not all supported platforms specify an interrupt for the |
| 383 | * watchdog, so let's make it optional. |
| 384 | */ |
| 385 | ret = devm_request_irq(&pdev->dev, irq, orion_wdt_irq, 0, |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 386 | pdev->name, dev); |
Ezequiel Garcia | e97662e | 2014-02-10 20:00:24 -0300 | [diff] [blame] | 387 | if (ret < 0) { |
| 388 | dev_err(&pdev->dev, "failed to request IRQ\n"); |
| 389 | goto disable_clk; |
| 390 | } |
| 391 | } |
| 392 | |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 393 | watchdog_set_nowayout(&dev->wdt, nowayout); |
| 394 | ret = watchdog_register_device(&dev->wdt); |
Ezequiel Garcia | bb02c66 | 2014-02-10 20:00:20 -0300 | [diff] [blame] | 395 | if (ret) |
| 396 | goto disable_clk; |
Thomas Reitmayr | 9e058d4 | 2009-02-24 14:59:22 -0800 | [diff] [blame] | 397 | |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 398 | pr_info("Initial timeout %d sec%s\n", |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 399 | dev->wdt.timeout, nowayout ? ", nowayout" : ""); |
Thomas Reitmayr | 9e058d4 | 2009-02-24 14:59:22 -0800 | [diff] [blame] | 400 | return 0; |
Ezequiel Garcia | bb02c66 | 2014-02-10 20:00:20 -0300 | [diff] [blame] | 401 | |
| 402 | disable_clk: |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 403 | clk_disable_unprepare(dev->clk); |
Ezequiel Garcia | 463f96e | 2014-02-10 20:00:31 -0300 | [diff] [blame^] | 404 | clk_put(dev->clk); |
Ezequiel Garcia | bb02c66 | 2014-02-10 20:00:20 -0300 | [diff] [blame] | 405 | return ret; |
Thomas Reitmayr | 9e058d4 | 2009-02-24 14:59:22 -0800 | [diff] [blame] | 406 | } |
| 407 | |
Bill Pemberton | 4b12b89 | 2012-11-19 13:26:24 -0500 | [diff] [blame] | 408 | static int orion_wdt_remove(struct platform_device *pdev) |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 409 | { |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 410 | struct watchdog_device *wdt_dev = platform_get_drvdata(pdev); |
| 411 | struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev); |
| 412 | |
| 413 | watchdog_unregister_device(wdt_dev); |
| 414 | clk_disable_unprepare(dev->clk); |
Ezequiel Garcia | 463f96e | 2014-02-10 20:00:31 -0300 | [diff] [blame^] | 415 | clk_put(dev->clk); |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 416 | return 0; |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 417 | } |
| 418 | |
Nicolas Pitre | 3b937a7db | 2009-06-01 13:56:02 -0400 | [diff] [blame] | 419 | static void orion_wdt_shutdown(struct platform_device *pdev) |
Thomas Reitmayr | df6707b | 2009-02-20 19:44:59 +0100 | [diff] [blame] | 420 | { |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 421 | struct watchdog_device *wdt_dev = platform_get_drvdata(pdev); |
| 422 | orion_wdt_stop(wdt_dev); |
Thomas Reitmayr | df6707b | 2009-02-20 19:44:59 +0100 | [diff] [blame] | 423 | } |
| 424 | |
Nicolas Pitre | 3b937a7db | 2009-06-01 13:56:02 -0400 | [diff] [blame] | 425 | static struct platform_driver orion_wdt_driver = { |
| 426 | .probe = orion_wdt_probe, |
Bill Pemberton | 8226871 | 2012-11-19 13:21:12 -0500 | [diff] [blame] | 427 | .remove = orion_wdt_remove, |
Nicolas Pitre | 3b937a7db | 2009-06-01 13:56:02 -0400 | [diff] [blame] | 428 | .shutdown = orion_wdt_shutdown, |
Thomas Reitmayr | 9e058d4 | 2009-02-24 14:59:22 -0800 | [diff] [blame] | 429 | .driver = { |
| 430 | .owner = THIS_MODULE, |
Nicolas Pitre | 3b937a7db | 2009-06-01 13:56:02 -0400 | [diff] [blame] | 431 | .name = "orion_wdt", |
Sachin Kamat | 85eee81 | 2013-09-30 10:12:51 +0530 | [diff] [blame] | 432 | .of_match_table = orion_wdt_of_match_table, |
Thomas Reitmayr | 9e058d4 | 2009-02-24 14:59:22 -0800 | [diff] [blame] | 433 | }, |
| 434 | }; |
| 435 | |
Axel Lin | b8ec611 | 2011-11-29 13:56:27 +0800 | [diff] [blame] | 436 | module_platform_driver(orion_wdt_driver); |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 437 | |
| 438 | MODULE_AUTHOR("Sylver Bruneau <sylver.bruneau@googlemail.com>"); |
Nicolas Pitre | 3b937a7db | 2009-06-01 13:56:02 -0400 | [diff] [blame] | 439 | MODULE_DESCRIPTION("Orion Processor Watchdog"); |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 440 | |
| 441 | module_param(heartbeat, int, 0); |
Thomas Reitmayr | df6707b | 2009-02-20 19:44:59 +0100 | [diff] [blame] | 442 | MODULE_PARM_DESC(heartbeat, "Initial watchdog heartbeat in seconds"); |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 443 | |
Wim Van Sebroeck | 86a1e18 | 2012-03-05 16:51:11 +0100 | [diff] [blame] | 444 | module_param(nowayout, bool, 0); |
Thomas Reitmayr | df6707b | 2009-02-20 19:44:59 +0100 | [diff] [blame] | 445 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" |
| 446 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 447 | |
| 448 | MODULE_LICENSE("GPL"); |
Lubomir Rintel | f3ea733 | 2013-01-04 15:06:28 +0100 | [diff] [blame] | 449 | MODULE_ALIAS("platform:orion_wdt"); |