Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 1 | /* |
Nicolas Pitre | 3b937a7 | 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 | 3b937a7 | 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 |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 39 | |
Thomas Reitmayr | 9e058d4 | 2009-02-24 14:59:22 -0800 | [diff] [blame] | 40 | #define WDT_MAX_CYCLE_COUNT 0xffffffff |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 41 | |
Wim Van Sebroeck | 86a1e18 | 2012-03-05 16:51:11 +0100 | [diff] [blame] | 42 | static bool nowayout = WATCHDOG_NOWAYOUT; |
Thomas Reitmayr | 9e058d4 | 2009-02-24 14:59:22 -0800 | [diff] [blame] | 43 | static int heartbeat = -1; /* module parameter (seconds) */ |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 44 | |
Ezequiel Garcia | 1924227 | 2014-02-10 20:00:29 -0300 | [diff] [blame^] | 45 | struct orion_watchdog; |
| 46 | |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 47 | struct orion_watchdog_data { |
| 48 | int wdt_counter_offset; |
| 49 | int wdt_enable_bit; |
| 50 | int rstout_enable_bit; |
Ezequiel Garcia | 1924227 | 2014-02-10 20:00:29 -0300 | [diff] [blame^] | 51 | int (*clock_init)(struct platform_device *, |
| 52 | struct orion_watchdog *); |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 53 | }; |
| 54 | |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 55 | struct orion_watchdog { |
| 56 | struct watchdog_device wdt; |
| 57 | void __iomem *reg; |
| 58 | void __iomem *rstout; |
| 59 | unsigned long clk_rate; |
| 60 | struct clk *clk; |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 61 | const struct orion_watchdog_data *data; |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 62 | }; |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 63 | |
Ezequiel Garcia | 1924227 | 2014-02-10 20:00:29 -0300 | [diff] [blame^] | 64 | static int orion_wdt_clock_init(struct platform_device *pdev, |
| 65 | struct orion_watchdog *dev) |
| 66 | { |
| 67 | int ret; |
| 68 | |
| 69 | dev->clk = devm_clk_get(&pdev->dev, NULL); |
| 70 | if (IS_ERR(dev->clk)) |
| 71 | return PTR_ERR(dev->clk); |
| 72 | ret = clk_prepare_enable(dev->clk); |
| 73 | if (ret) |
| 74 | return ret; |
| 75 | |
| 76 | dev->clk_rate = clk_get_rate(dev->clk); |
| 77 | return 0; |
| 78 | } |
| 79 | |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 80 | static int orion_wdt_ping(struct watchdog_device *wdt_dev) |
Thomas Reitmayr | df6707b | 2009-02-20 19:44:59 +0100 | [diff] [blame] | 81 | { |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 82 | struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev); |
Thomas Reitmayr | df6707b | 2009-02-20 19:44:59 +0100 | [diff] [blame] | 83 | /* Reload watchdog duration */ |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 84 | writel(dev->clk_rate * wdt_dev->timeout, |
| 85 | dev->reg + dev->data->wdt_counter_offset); |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 86 | return 0; |
Thomas Reitmayr | df6707b | 2009-02-20 19:44:59 +0100 | [diff] [blame] | 87 | } |
| 88 | |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 89 | static int orion_wdt_start(struct watchdog_device *wdt_dev) |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 90 | { |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 91 | struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev); |
| 92 | |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 93 | /* Set watchdog duration */ |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 94 | writel(dev->clk_rate * wdt_dev->timeout, |
| 95 | dev->reg + dev->data->wdt_counter_offset); |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 96 | |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 97 | /* Enable watchdog timer */ |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 98 | atomic_io_modify(dev->reg + TIMER_CTRL, dev->data->wdt_enable_bit, |
| 99 | dev->data->wdt_enable_bit); |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 100 | |
| 101 | /* Enable reset on watchdog */ |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 102 | atomic_io_modify(dev->rstout, dev->data->rstout_enable_bit, |
| 103 | dev->data->rstout_enable_bit); |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 104 | |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 105 | return 0; |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 106 | } |
| 107 | |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 108 | static int orion_wdt_stop(struct watchdog_device *wdt_dev) |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 109 | { |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 110 | struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev); |
| 111 | |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 112 | /* Disable reset on watchdog */ |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 113 | atomic_io_modify(dev->rstout, dev->data->rstout_enable_bit, 0); |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 114 | |
| 115 | /* Disable watchdog timer */ |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 116 | 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] | 117 | |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 118 | return 0; |
Wim Van Sebroeck | 6d0f0df | 2008-10-02 09:32:45 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 121 | static int orion_wdt_enabled(struct orion_watchdog *dev) |
Ezequiel Garcia | d9d0c53 | 2014-02-10 20:00:23 -0300 | [diff] [blame] | 122 | { |
| 123 | bool enabled, running; |
| 124 | |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 125 | enabled = readl(dev->rstout) & dev->data->rstout_enable_bit; |
| 126 | running = readl(dev->reg + TIMER_CTRL) & dev->data->wdt_enable_bit; |
Ezequiel Garcia | d9d0c53 | 2014-02-10 20:00:23 -0300 | [diff] [blame] | 127 | |
| 128 | return enabled && running; |
| 129 | } |
| 130 | |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 131 | 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] | 132 | { |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 133 | struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev); |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 134 | return readl(dev->reg + dev->data->wdt_counter_offset) / dev->clk_rate; |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | static int orion_wdt_set_timeout(struct watchdog_device *wdt_dev, |
| 138 | unsigned int timeout) |
| 139 | { |
| 140 | wdt_dev->timeout = timeout; |
Wim Van Sebroeck | 6d0f0df | 2008-10-02 09:32:45 +0000 | [diff] [blame] | 141 | return 0; |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 142 | } |
| 143 | |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 144 | static const struct watchdog_info orion_wdt_info = { |
| 145 | .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, |
| 146 | .identity = "Orion Watchdog", |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 147 | }; |
| 148 | |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 149 | static const struct watchdog_ops orion_wdt_ops = { |
| 150 | .owner = THIS_MODULE, |
| 151 | .start = orion_wdt_start, |
| 152 | .stop = orion_wdt_stop, |
| 153 | .ping = orion_wdt_ping, |
| 154 | .set_timeout = orion_wdt_set_timeout, |
| 155 | .get_timeleft = orion_wdt_get_timeleft, |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 156 | }; |
| 157 | |
Ezequiel Garcia | e97662e | 2014-02-10 20:00:24 -0300 | [diff] [blame] | 158 | static irqreturn_t orion_wdt_irq(int irq, void *devid) |
| 159 | { |
| 160 | panic("Watchdog Timeout"); |
| 161 | return IRQ_HANDLED; |
| 162 | } |
| 163 | |
Ezequiel Garcia | 868eb61 | 2014-02-10 20:00:25 -0300 | [diff] [blame] | 164 | /* |
| 165 | * The original devicetree binding for this driver specified only |
| 166 | * one memory resource, so in order to keep DT backwards compatibility |
| 167 | * we try to fallback to a hardcoded register address, if the resource |
| 168 | * is missing from the devicetree. |
| 169 | */ |
| 170 | static void __iomem *orion_wdt_ioremap_rstout(struct platform_device *pdev, |
| 171 | phys_addr_t internal_regs) |
| 172 | { |
| 173 | struct resource *res; |
| 174 | phys_addr_t rstout; |
| 175 | |
| 176 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 177 | if (res) |
| 178 | return devm_ioremap(&pdev->dev, res->start, |
| 179 | resource_size(res)); |
| 180 | |
| 181 | /* This workaround works only for "orion-wdt", DT-enabled */ |
| 182 | if (!of_device_is_compatible(pdev->dev.of_node, "marvell,orion-wdt")) |
| 183 | return NULL; |
| 184 | |
| 185 | rstout = internal_regs + ORION_RSTOUT_MASK_OFFSET; |
| 186 | |
| 187 | WARN(1, FW_BUG "falling back to harcoded RSTOUT reg 0x%x\n", rstout); |
| 188 | return devm_ioremap(&pdev->dev, rstout, 0x4); |
| 189 | } |
| 190 | |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 191 | static const struct orion_watchdog_data orion_data = { |
| 192 | .rstout_enable_bit = BIT(1), |
| 193 | .wdt_enable_bit = BIT(4), |
| 194 | .wdt_counter_offset = 0x24, |
Ezequiel Garcia | 1924227 | 2014-02-10 20:00:29 -0300 | [diff] [blame^] | 195 | .clock_init = orion_wdt_clock_init, |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | static const struct of_device_id orion_wdt_of_match_table[] = { |
| 199 | { |
| 200 | .compatible = "marvell,orion-wdt", |
| 201 | .data = &orion_data, |
| 202 | }, |
| 203 | {}, |
| 204 | }; |
| 205 | MODULE_DEVICE_TABLE(of, orion_wdt_of_match_table); |
| 206 | |
Bill Pemberton | 2d991a1 | 2012-11-19 13:21:41 -0500 | [diff] [blame] | 207 | static int orion_wdt_probe(struct platform_device *pdev) |
Thomas Reitmayr | 9e058d4 | 2009-02-24 14:59:22 -0800 | [diff] [blame] | 208 | { |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 209 | struct orion_watchdog *dev; |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 210 | const struct of_device_id *match; |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 211 | unsigned int wdt_max_duration; /* (seconds) */ |
Jason Cooper | a855a7c | 2012-03-15 00:33:26 +0000 | [diff] [blame] | 212 | struct resource *res; |
Ezequiel Garcia | e97662e | 2014-02-10 20:00:24 -0300 | [diff] [blame] | 213 | int ret, irq; |
Thomas Reitmayr | 9e058d4 | 2009-02-24 14:59:22 -0800 | [diff] [blame] | 214 | |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 215 | dev = devm_kzalloc(&pdev->dev, sizeof(struct orion_watchdog), |
| 216 | GFP_KERNEL); |
| 217 | if (!dev) |
| 218 | return -ENOMEM; |
| 219 | |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 220 | match = of_match_device(orion_wdt_of_match_table, &pdev->dev); |
| 221 | if (!match) |
| 222 | /* Default legacy match */ |
| 223 | match = &orion_wdt_of_match_table[0]; |
| 224 | |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 225 | dev->wdt.info = &orion_wdt_info; |
| 226 | dev->wdt.ops = &orion_wdt_ops; |
| 227 | dev->wdt.min_timeout = 1; |
Ezequiel Garcia | fc72385 | 2014-02-10 20:00:28 -0300 | [diff] [blame] | 228 | dev->data = match->data; |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 229 | |
Jason Cooper | a855a7c | 2012-03-15 00:33:26 +0000 | [diff] [blame] | 230 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Ezequiel Garcia | 1924227 | 2014-02-10 20:00:29 -0300 | [diff] [blame^] | 231 | if (!res) |
| 232 | return -ENODEV; |
Ezequiel Garcia | bb02c66 | 2014-02-10 20:00:20 -0300 | [diff] [blame] | 233 | |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 234 | dev->reg = devm_ioremap(&pdev->dev, res->start, |
| 235 | resource_size(res)); |
Ezequiel Garcia | 1924227 | 2014-02-10 20:00:29 -0300 | [diff] [blame^] | 236 | if (!dev->reg) |
| 237 | return -ENOMEM; |
Thomas Reitmayr | 9e058d4 | 2009-02-24 14:59:22 -0800 | [diff] [blame] | 238 | |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 239 | dev->rstout = orion_wdt_ioremap_rstout(pdev, res->start & |
| 240 | INTERNAL_REGS_MASK); |
Ezequiel Garcia | 1924227 | 2014-02-10 20:00:29 -0300 | [diff] [blame^] | 241 | if (!dev->rstout) |
| 242 | return -ENODEV; |
| 243 | |
| 244 | ret = dev->data->clock_init(pdev, dev); |
| 245 | if (ret) { |
| 246 | dev_err(&pdev->dev, "cannot initialize clock\n"); |
| 247 | return ret; |
Ezequiel Garcia | 868eb61 | 2014-02-10 20:00:25 -0300 | [diff] [blame] | 248 | } |
| 249 | |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 250 | wdt_max_duration = WDT_MAX_CYCLE_COUNT / dev->clk_rate; |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 251 | |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 252 | dev->wdt.timeout = wdt_max_duration; |
| 253 | dev->wdt.max_timeout = wdt_max_duration; |
| 254 | watchdog_init_timeout(&dev->wdt, heartbeat, &pdev->dev); |
| 255 | |
| 256 | platform_set_drvdata(pdev, &dev->wdt); |
| 257 | watchdog_set_drvdata(&dev->wdt, dev); |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 258 | |
Ezequiel Garcia | d9d0c53 | 2014-02-10 20:00:23 -0300 | [diff] [blame] | 259 | /* |
| 260 | * Let's make sure the watchdog is fully stopped, unless it's |
| 261 | * explicitly enabled. This may be the case if the module was |
| 262 | * removed and re-insterted, or if the bootloader explicitly |
| 263 | * set a running watchdog before booting the kernel. |
| 264 | */ |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 265 | if (!orion_wdt_enabled(dev)) |
| 266 | orion_wdt_stop(&dev->wdt); |
Ezequiel Garcia | d9d0c53 | 2014-02-10 20:00:23 -0300 | [diff] [blame] | 267 | |
Ezequiel Garcia | e97662e | 2014-02-10 20:00:24 -0300 | [diff] [blame] | 268 | /* Request the IRQ only after the watchdog is disabled */ |
| 269 | irq = platform_get_irq(pdev, 0); |
| 270 | if (irq > 0) { |
| 271 | /* |
| 272 | * Not all supported platforms specify an interrupt for the |
| 273 | * watchdog, so let's make it optional. |
| 274 | */ |
| 275 | ret = devm_request_irq(&pdev->dev, irq, orion_wdt_irq, 0, |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 276 | pdev->name, dev); |
Ezequiel Garcia | e97662e | 2014-02-10 20:00:24 -0300 | [diff] [blame] | 277 | if (ret < 0) { |
| 278 | dev_err(&pdev->dev, "failed to request IRQ\n"); |
| 279 | goto disable_clk; |
| 280 | } |
| 281 | } |
| 282 | |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 283 | watchdog_set_nowayout(&dev->wdt, nowayout); |
| 284 | ret = watchdog_register_device(&dev->wdt); |
Ezequiel Garcia | bb02c66 | 2014-02-10 20:00:20 -0300 | [diff] [blame] | 285 | if (ret) |
| 286 | goto disable_clk; |
Thomas Reitmayr | 9e058d4 | 2009-02-24 14:59:22 -0800 | [diff] [blame] | 287 | |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 288 | pr_info("Initial timeout %d sec%s\n", |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 289 | dev->wdt.timeout, nowayout ? ", nowayout" : ""); |
Thomas Reitmayr | 9e058d4 | 2009-02-24 14:59:22 -0800 | [diff] [blame] | 290 | return 0; |
Ezequiel Garcia | bb02c66 | 2014-02-10 20:00:20 -0300 | [diff] [blame] | 291 | |
| 292 | disable_clk: |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 293 | clk_disable_unprepare(dev->clk); |
Ezequiel Garcia | bb02c66 | 2014-02-10 20:00:20 -0300 | [diff] [blame] | 294 | return ret; |
Thomas Reitmayr | 9e058d4 | 2009-02-24 14:59:22 -0800 | [diff] [blame] | 295 | } |
| 296 | |
Bill Pemberton | 4b12b89 | 2012-11-19 13:26:24 -0500 | [diff] [blame] | 297 | static int orion_wdt_remove(struct platform_device *pdev) |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 298 | { |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 299 | struct watchdog_device *wdt_dev = platform_get_drvdata(pdev); |
| 300 | struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev); |
| 301 | |
| 302 | watchdog_unregister_device(wdt_dev); |
| 303 | clk_disable_unprepare(dev->clk); |
Axel Lin | 0dd6e48 | 2012-03-26 11:14:29 +0800 | [diff] [blame] | 304 | return 0; |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 305 | } |
| 306 | |
Nicolas Pitre | 3b937a7 | 2009-06-01 13:56:02 -0400 | [diff] [blame] | 307 | static void orion_wdt_shutdown(struct platform_device *pdev) |
Thomas Reitmayr | df6707b | 2009-02-20 19:44:59 +0100 | [diff] [blame] | 308 | { |
Ezequiel Garcia | b89a9c4 | 2014-02-10 20:00:27 -0300 | [diff] [blame] | 309 | struct watchdog_device *wdt_dev = platform_get_drvdata(pdev); |
| 310 | orion_wdt_stop(wdt_dev); |
Thomas Reitmayr | df6707b | 2009-02-20 19:44:59 +0100 | [diff] [blame] | 311 | } |
| 312 | |
Nicolas Pitre | 3b937a7 | 2009-06-01 13:56:02 -0400 | [diff] [blame] | 313 | static struct platform_driver orion_wdt_driver = { |
| 314 | .probe = orion_wdt_probe, |
Bill Pemberton | 8226871 | 2012-11-19 13:21:12 -0500 | [diff] [blame] | 315 | .remove = orion_wdt_remove, |
Nicolas Pitre | 3b937a7 | 2009-06-01 13:56:02 -0400 | [diff] [blame] | 316 | .shutdown = orion_wdt_shutdown, |
Thomas Reitmayr | 9e058d4 | 2009-02-24 14:59:22 -0800 | [diff] [blame] | 317 | .driver = { |
| 318 | .owner = THIS_MODULE, |
Nicolas Pitre | 3b937a7 | 2009-06-01 13:56:02 -0400 | [diff] [blame] | 319 | .name = "orion_wdt", |
Sachin Kamat | 85eee81 | 2013-09-30 10:12:51 +0530 | [diff] [blame] | 320 | .of_match_table = orion_wdt_of_match_table, |
Thomas Reitmayr | 9e058d4 | 2009-02-24 14:59:22 -0800 | [diff] [blame] | 321 | }, |
| 322 | }; |
| 323 | |
Axel Lin | b8ec611 | 2011-11-29 13:56:27 +0800 | [diff] [blame] | 324 | module_platform_driver(orion_wdt_driver); |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 325 | |
| 326 | MODULE_AUTHOR("Sylver Bruneau <sylver.bruneau@googlemail.com>"); |
Nicolas Pitre | 3b937a7 | 2009-06-01 13:56:02 -0400 | [diff] [blame] | 327 | MODULE_DESCRIPTION("Orion Processor Watchdog"); |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 328 | |
| 329 | module_param(heartbeat, int, 0); |
Thomas Reitmayr | df6707b | 2009-02-20 19:44:59 +0100 | [diff] [blame] | 330 | MODULE_PARM_DESC(heartbeat, "Initial watchdog heartbeat in seconds"); |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 331 | |
Wim Van Sebroeck | 86a1e18 | 2012-03-05 16:51:11 +0100 | [diff] [blame] | 332 | module_param(nowayout, bool, 0); |
Thomas Reitmayr | df6707b | 2009-02-20 19:44:59 +0100 | [diff] [blame] | 333 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" |
| 334 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
Sylver Bruneau | 22ac923 | 2008-06-26 10:47:45 +0200 | [diff] [blame] | 335 | |
| 336 | MODULE_LICENSE("GPL"); |
Lubomir Rintel | f3ea733 | 2013-01-04 15:06:28 +0100 | [diff] [blame] | 337 | MODULE_ALIAS("platform:orion_wdt"); |