Marcus Folkesson | 2e62c49 | 2018-03-16 16:14:11 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 2 | /* |
Michal Simek | 9419c07 | 2013-05-31 07:56:33 +0200 | [diff] [blame] | 3 | * Watchdog Device Driver for Xilinx axi/xps_timebase_wdt |
| 4 | * |
Michal Simek | d14fd96 | 2014-02-12 14:34:32 +0100 | [diff] [blame] | 5 | * (C) Copyright 2013 - 2014 Xilinx, Inc. |
Michal Simek | 9419c07 | 2013-05-31 07:56:33 +0200 | [diff] [blame] | 6 | * (C) Copyright 2011 (Alejandro Cabrera <aldaya@gmail.com>) |
Michal Simek | 9419c07 | 2013-05-31 07:56:33 +0200 | [diff] [blame] | 7 | */ |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 8 | |
Shubhrajyoti Datta | 9d6b4ef | 2016-08-12 12:17:01 +0530 | [diff] [blame] | 9 | #include <linux/clk.h> |
Michal Simek | f06cdfd | 2014-02-12 14:34:34 +0100 | [diff] [blame] | 10 | #include <linux/err.h> |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 11 | #include <linux/module.h> |
| 12 | #include <linux/types.h> |
| 13 | #include <linux/kernel.h> |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 14 | #include <linux/ioport.h> |
| 15 | #include <linux/watchdog.h> |
| 16 | #include <linux/io.h> |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 17 | #include <linux/of.h> |
| 18 | #include <linux/of_device.h> |
| 19 | #include <linux/of_address.h> |
| 20 | |
| 21 | /* Register offsets for the Wdt device */ |
| 22 | #define XWT_TWCSR0_OFFSET 0x0 /* Control/Status Register0 */ |
| 23 | #define XWT_TWCSR1_OFFSET 0x4 /* Control/Status Register1 */ |
| 24 | #define XWT_TBR_OFFSET 0x8 /* Timebase Register Offset */ |
| 25 | |
| 26 | /* Control/Status Register Masks */ |
| 27 | #define XWT_CSR0_WRS_MASK 0x00000008 /* Reset status */ |
| 28 | #define XWT_CSR0_WDS_MASK 0x00000004 /* Timer state */ |
| 29 | #define XWT_CSR0_EWDT1_MASK 0x00000002 /* Enable bit 1 */ |
| 30 | |
| 31 | /* Control/Status Register 0/1 bits */ |
| 32 | #define XWT_CSRX_EWDT2_MASK 0x00000001 /* Enable bit 2 */ |
| 33 | |
| 34 | /* SelfTest constants */ |
| 35 | #define XWT_MAX_SELFTEST_LOOP_COUNT 0x00010000 |
| 36 | #define XWT_TIMER_FAILED 0xFFFFFFFF |
| 37 | |
| 38 | #define WATCHDOG_NAME "Xilinx Watchdog" |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 39 | |
| 40 | struct xwdt_device { |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 41 | void __iomem *base; |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 42 | u32 wdt_interval; |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 43 | spinlock_t spinlock; |
| 44 | struct watchdog_device xilinx_wdt_wdd; |
Shubhrajyoti Datta | 9d6b4ef | 2016-08-12 12:17:01 +0530 | [diff] [blame] | 45 | struct clk *clk; |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 46 | }; |
| 47 | |
Michal Simek | d14fd96 | 2014-02-12 14:34:32 +0100 | [diff] [blame] | 48 | static int xilinx_wdt_start(struct watchdog_device *wdd) |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 49 | { |
Maulik Jodhani | b6bc416 | 2017-08-07 13:24:22 +0200 | [diff] [blame] | 50 | int ret; |
Michal Simek | 5cf4e69 | 2014-02-12 14:34:33 +0100 | [diff] [blame] | 51 | u32 control_status_reg; |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 52 | struct xwdt_device *xdev = watchdog_get_drvdata(wdd); |
Michal Simek | 5cf4e69 | 2014-02-12 14:34:33 +0100 | [diff] [blame] | 53 | |
Maulik Jodhani | b6bc416 | 2017-08-07 13:24:22 +0200 | [diff] [blame] | 54 | ret = clk_enable(xdev->clk); |
| 55 | if (ret) { |
| 56 | dev_err(wdd->parent, "Failed to enable clock\n"); |
| 57 | return ret; |
| 58 | } |
| 59 | |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 60 | spin_lock(&xdev->spinlock); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 61 | |
| 62 | /* Clean previous status and enable the watchdog timer */ |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 63 | control_status_reg = ioread32(xdev->base + XWT_TWCSR0_OFFSET); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 64 | control_status_reg |= (XWT_CSR0_WRS_MASK | XWT_CSR0_WDS_MASK); |
| 65 | |
| 66 | iowrite32((control_status_reg | XWT_CSR0_EWDT1_MASK), |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 67 | xdev->base + XWT_TWCSR0_OFFSET); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 68 | |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 69 | iowrite32(XWT_CSRX_EWDT2_MASK, xdev->base + XWT_TWCSR1_OFFSET); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 70 | |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 71 | spin_unlock(&xdev->spinlock); |
Michal Simek | d14fd96 | 2014-02-12 14:34:32 +0100 | [diff] [blame] | 72 | |
| 73 | return 0; |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Michal Simek | d14fd96 | 2014-02-12 14:34:32 +0100 | [diff] [blame] | 76 | static int xilinx_wdt_stop(struct watchdog_device *wdd) |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 77 | { |
Michal Simek | 5cf4e69 | 2014-02-12 14:34:33 +0100 | [diff] [blame] | 78 | u32 control_status_reg; |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 79 | struct xwdt_device *xdev = watchdog_get_drvdata(wdd); |
Michal Simek | 5cf4e69 | 2014-02-12 14:34:33 +0100 | [diff] [blame] | 80 | |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 81 | spin_lock(&xdev->spinlock); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 82 | |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 83 | control_status_reg = ioread32(xdev->base + XWT_TWCSR0_OFFSET); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 84 | |
| 85 | iowrite32((control_status_reg & ~XWT_CSR0_EWDT1_MASK), |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 86 | xdev->base + XWT_TWCSR0_OFFSET); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 87 | |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 88 | iowrite32(0, xdev->base + XWT_TWCSR1_OFFSET); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 89 | |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 90 | spin_unlock(&xdev->spinlock); |
Maulik Jodhani | b6bc416 | 2017-08-07 13:24:22 +0200 | [diff] [blame] | 91 | |
| 92 | clk_disable(xdev->clk); |
| 93 | |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 94 | pr_info("Stopped!\n"); |
Michal Simek | d14fd96 | 2014-02-12 14:34:32 +0100 | [diff] [blame] | 95 | |
| 96 | return 0; |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 97 | } |
| 98 | |
Michal Simek | d14fd96 | 2014-02-12 14:34:32 +0100 | [diff] [blame] | 99 | static int xilinx_wdt_keepalive(struct watchdog_device *wdd) |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 100 | { |
Michal Simek | 5cf4e69 | 2014-02-12 14:34:33 +0100 | [diff] [blame] | 101 | u32 control_status_reg; |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 102 | struct xwdt_device *xdev = watchdog_get_drvdata(wdd); |
Michal Simek | 5cf4e69 | 2014-02-12 14:34:33 +0100 | [diff] [blame] | 103 | |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 104 | spin_lock(&xdev->spinlock); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 105 | |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 106 | control_status_reg = ioread32(xdev->base + XWT_TWCSR0_OFFSET); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 107 | control_status_reg |= (XWT_CSR0_WRS_MASK | XWT_CSR0_WDS_MASK); |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 108 | iowrite32(control_status_reg, xdev->base + XWT_TWCSR0_OFFSET); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 109 | |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 110 | spin_unlock(&xdev->spinlock); |
Michal Simek | d14fd96 | 2014-02-12 14:34:32 +0100 | [diff] [blame] | 111 | |
| 112 | return 0; |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 113 | } |
| 114 | |
Michal Simek | d14fd96 | 2014-02-12 14:34:32 +0100 | [diff] [blame] | 115 | static const struct watchdog_info xilinx_wdt_ident = { |
| 116 | .options = WDIOF_MAGICCLOSE | |
| 117 | WDIOF_KEEPALIVEPING, |
| 118 | .firmware_version = 1, |
| 119 | .identity = WATCHDOG_NAME, |
| 120 | }; |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 121 | |
Michal Simek | d14fd96 | 2014-02-12 14:34:32 +0100 | [diff] [blame] | 122 | static const struct watchdog_ops xilinx_wdt_ops = { |
| 123 | .owner = THIS_MODULE, |
| 124 | .start = xilinx_wdt_start, |
| 125 | .stop = xilinx_wdt_stop, |
| 126 | .ping = xilinx_wdt_keepalive, |
| 127 | }; |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 128 | |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 129 | static u32 xwdt_selftest(struct xwdt_device *xdev) |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 130 | { |
| 131 | int i; |
| 132 | u32 timer_value1; |
| 133 | u32 timer_value2; |
| 134 | |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 135 | spin_lock(&xdev->spinlock); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 136 | |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 137 | timer_value1 = ioread32(xdev->base + XWT_TBR_OFFSET); |
| 138 | timer_value2 = ioread32(xdev->base + XWT_TBR_OFFSET); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 139 | |
| 140 | for (i = 0; |
| 141 | ((i <= XWT_MAX_SELFTEST_LOOP_COUNT) && |
| 142 | (timer_value2 == timer_value1)); i++) { |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 143 | timer_value2 = ioread32(xdev->base + XWT_TBR_OFFSET); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 144 | } |
| 145 | |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 146 | spin_unlock(&xdev->spinlock); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 147 | |
| 148 | if (timer_value2 != timer_value1) |
| 149 | return ~XWT_TIMER_FAILED; |
| 150 | else |
| 151 | return XWT_TIMER_FAILED; |
| 152 | } |
| 153 | |
Bill Pemberton | 2d991a1 | 2012-11-19 13:21:41 -0500 | [diff] [blame] | 154 | static int xwdt_probe(struct platform_device *pdev) |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 155 | { |
| 156 | int rc; |
Michal Simek | 8d6a140 | 2014-02-12 14:41:25 +0100 | [diff] [blame] | 157 | u32 pfreq = 0, enable_once = 0; |
Michal Simek | f06cdfd | 2014-02-12 14:34:34 +0100 | [diff] [blame] | 158 | struct resource *res; |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 159 | struct xwdt_device *xdev; |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 160 | struct watchdog_device *xilinx_wdt_wdd; |
| 161 | |
| 162 | xdev = devm_kzalloc(&pdev->dev, sizeof(*xdev), GFP_KERNEL); |
| 163 | if (!xdev) |
| 164 | return -ENOMEM; |
| 165 | |
| 166 | xilinx_wdt_wdd = &xdev->xilinx_wdt_wdd; |
| 167 | xilinx_wdt_wdd->info = &xilinx_wdt_ident; |
| 168 | xilinx_wdt_wdd->ops = &xilinx_wdt_ops; |
| 169 | xilinx_wdt_wdd->parent = &pdev->dev; |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 170 | |
Michal Simek | f06cdfd | 2014-02-12 14:34:34 +0100 | [diff] [blame] | 171 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 172 | xdev->base = devm_ioremap_resource(&pdev->dev, res); |
| 173 | if (IS_ERR(xdev->base)) |
| 174 | return PTR_ERR(xdev->base); |
Michal Simek | f06cdfd | 2014-02-12 14:34:34 +0100 | [diff] [blame] | 175 | |
Michal Simek | 2e79a36 | 2014-02-12 14:41:21 +0100 | [diff] [blame] | 176 | rc = of_property_read_u32(pdev->dev.of_node, "xlnx,wdt-interval", |
| 177 | &xdev->wdt_interval); |
Michal Simek | 8d6a140 | 2014-02-12 14:41:25 +0100 | [diff] [blame] | 178 | if (rc) |
Michal Simek | 4c7fbbc | 2014-02-12 14:41:20 +0100 | [diff] [blame] | 179 | dev_warn(&pdev->dev, |
| 180 | "Parameter \"xlnx,wdt-interval\" not found\n"); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 181 | |
Michal Simek | 2e79a36 | 2014-02-12 14:41:21 +0100 | [diff] [blame] | 182 | rc = of_property_read_u32(pdev->dev.of_node, "xlnx,wdt-enable-once", |
| 183 | &enable_once); |
| 184 | if (rc) |
Michal Simek | 4c7fbbc | 2014-02-12 14:41:20 +0100 | [diff] [blame] | 185 | dev_warn(&pdev->dev, |
| 186 | "Parameter \"xlnx,wdt-enable-once\" not found\n"); |
Michal Simek | 2e79a36 | 2014-02-12 14:41:21 +0100 | [diff] [blame] | 187 | |
| 188 | watchdog_set_nowayout(xilinx_wdt_wdd, enable_once); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 189 | |
Maulik Jodhani | b6bc416 | 2017-08-07 13:24:22 +0200 | [diff] [blame] | 190 | xdev->clk = devm_clk_get(&pdev->dev, NULL); |
| 191 | if (IS_ERR(xdev->clk)) { |
| 192 | if (PTR_ERR(xdev->clk) != -ENOENT) |
| 193 | return PTR_ERR(xdev->clk); |
| 194 | |
| 195 | /* |
| 196 | * Clock framework support is optional, continue on |
| 197 | * anyways if we don't find a matching clock. |
| 198 | */ |
| 199 | xdev->clk = NULL; |
| 200 | |
| 201 | rc = of_property_read_u32(pdev->dev.of_node, "clock-frequency", |
| 202 | &pfreq); |
| 203 | if (rc) |
| 204 | dev_warn(&pdev->dev, |
| 205 | "The watchdog clock freq cannot be obtained\n"); |
| 206 | } else { |
| 207 | pfreq = clk_get_rate(xdev->clk); |
| 208 | } |
| 209 | |
Michal Simek | 75b3c5a | 2014-02-12 14:41:22 +0100 | [diff] [blame] | 210 | /* |
| 211 | * Twice of the 2^wdt_interval / freq because the first wdt overflow is |
| 212 | * ignored (interrupt), reset is only generated at second wdt overflow |
| 213 | */ |
Michal Simek | 8d6a140 | 2014-02-12 14:41:25 +0100 | [diff] [blame] | 214 | if (pfreq && xdev->wdt_interval) |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 215 | xilinx_wdt_wdd->timeout = 2 * ((1 << xdev->wdt_interval) / |
Michal Simek | 2e79a36 | 2014-02-12 14:41:21 +0100 | [diff] [blame] | 216 | pfreq); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 217 | |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 218 | spin_lock_init(&xdev->spinlock); |
| 219 | watchdog_set_drvdata(xilinx_wdt_wdd, xdev); |
| 220 | |
Shubhrajyoti Datta | 9d6b4ef | 2016-08-12 12:17:01 +0530 | [diff] [blame] | 221 | rc = clk_prepare_enable(xdev->clk); |
| 222 | if (rc) { |
| 223 | dev_err(&pdev->dev, "unable to enable clock\n"); |
| 224 | return rc; |
| 225 | } |
| 226 | |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 227 | rc = xwdt_selftest(xdev); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 228 | if (rc == XWT_TIMER_FAILED) { |
Michal Simek | 4c7fbbc | 2014-02-12 14:41:20 +0100 | [diff] [blame] | 229 | dev_err(&pdev->dev, "SelfTest routine error\n"); |
Shubhrajyoti Datta | 9d6b4ef | 2016-08-12 12:17:01 +0530 | [diff] [blame] | 230 | goto err_clk_disable; |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 231 | } |
| 232 | |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 233 | rc = watchdog_register_device(xilinx_wdt_wdd); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 234 | if (rc) { |
Michal Simek | 4c7fbbc | 2014-02-12 14:41:20 +0100 | [diff] [blame] | 235 | dev_err(&pdev->dev, "Cannot register watchdog (err=%d)\n", rc); |
Shubhrajyoti Datta | 9d6b4ef | 2016-08-12 12:17:01 +0530 | [diff] [blame] | 236 | goto err_clk_disable; |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 237 | } |
| 238 | |
Maulik Jodhani | b6bc416 | 2017-08-07 13:24:22 +0200 | [diff] [blame] | 239 | clk_disable(xdev->clk); |
| 240 | |
Michal Simek | d14fd96 | 2014-02-12 14:34:32 +0100 | [diff] [blame] | 241 | dev_info(&pdev->dev, "Xilinx Watchdog Timer at %p with timeout %ds\n", |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 242 | xdev->base, xilinx_wdt_wdd->timeout); |
| 243 | |
| 244 | platform_set_drvdata(pdev, xdev); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 245 | |
| 246 | return 0; |
Shubhrajyoti Datta | 9d6b4ef | 2016-08-12 12:17:01 +0530 | [diff] [blame] | 247 | err_clk_disable: |
| 248 | clk_disable_unprepare(xdev->clk); |
| 249 | |
| 250 | return rc; |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 251 | } |
| 252 | |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 253 | static int xwdt_remove(struct platform_device *pdev) |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 254 | { |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 255 | struct xwdt_device *xdev = platform_get_drvdata(pdev); |
| 256 | |
| 257 | watchdog_unregister_device(&xdev->xilinx_wdt_wdd); |
Shubhrajyoti Datta | 9d6b4ef | 2016-08-12 12:17:01 +0530 | [diff] [blame] | 258 | clk_disable_unprepare(xdev->clk); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 259 | |
| 260 | return 0; |
| 261 | } |
| 262 | |
Michal Simek | 6f671c6 | 2017-08-07 13:24:23 +0200 | [diff] [blame] | 263 | /** |
| 264 | * xwdt_suspend - Suspend the device. |
| 265 | * |
| 266 | * @dev: handle to the device structure. |
| 267 | * Return: 0 always. |
| 268 | */ |
| 269 | static int __maybe_unused xwdt_suspend(struct device *dev) |
| 270 | { |
Wolfram Sang | 2074563 | 2018-04-19 16:06:29 +0200 | [diff] [blame^] | 271 | struct xwdt_device *xdev = dev_get_drvdata(dev); |
Michal Simek | 6f671c6 | 2017-08-07 13:24:23 +0200 | [diff] [blame] | 272 | |
| 273 | if (watchdog_active(&xdev->xilinx_wdt_wdd)) |
| 274 | xilinx_wdt_stop(&xdev->xilinx_wdt_wdd); |
| 275 | |
| 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * xwdt_resume - Resume the device. |
| 281 | * |
| 282 | * @dev: handle to the device structure. |
| 283 | * Return: 0 on success, errno otherwise. |
| 284 | */ |
| 285 | static int __maybe_unused xwdt_resume(struct device *dev) |
| 286 | { |
Wolfram Sang | 2074563 | 2018-04-19 16:06:29 +0200 | [diff] [blame^] | 287 | struct xwdt_device *xdev = dev_get_drvdata(dev); |
Michal Simek | 6f671c6 | 2017-08-07 13:24:23 +0200 | [diff] [blame] | 288 | int ret = 0; |
| 289 | |
| 290 | if (watchdog_active(&xdev->xilinx_wdt_wdd)) |
| 291 | ret = xilinx_wdt_start(&xdev->xilinx_wdt_wdd); |
| 292 | |
| 293 | return ret; |
| 294 | } |
| 295 | |
| 296 | static SIMPLE_DEV_PM_OPS(xwdt_pm_ops, xwdt_suspend, xwdt_resume); |
| 297 | |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 298 | /* Match table for of_platform binding */ |
Jingoo Han | 9ebf185 | 2014-05-07 17:42:22 +0900 | [diff] [blame] | 299 | static const struct of_device_id xwdt_of_match[] = { |
Michal Simek | 8fce9b3 | 2013-05-31 07:56:34 +0200 | [diff] [blame] | 300 | { .compatible = "xlnx,xps-timebase-wdt-1.00.a", }, |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 301 | { .compatible = "xlnx,xps-timebase-wdt-1.01.a", }, |
| 302 | {}, |
| 303 | }; |
| 304 | MODULE_DEVICE_TABLE(of, xwdt_of_match); |
| 305 | |
| 306 | static struct platform_driver xwdt_driver = { |
| 307 | .probe = xwdt_probe, |
Bill Pemberton | 8226871 | 2012-11-19 13:21:12 -0500 | [diff] [blame] | 308 | .remove = xwdt_remove, |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 309 | .driver = { |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 310 | .name = WATCHDOG_NAME, |
| 311 | .of_match_table = xwdt_of_match, |
Michal Simek | 6f671c6 | 2017-08-07 13:24:23 +0200 | [diff] [blame] | 312 | .pm = &xwdt_pm_ops, |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 313 | }, |
| 314 | }; |
| 315 | |
Axel Lin | b8ec611 | 2011-11-29 13:56:27 +0800 | [diff] [blame] | 316 | module_platform_driver(xwdt_driver); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 317 | |
| 318 | MODULE_AUTHOR("Alejandro Cabrera <aldaya@gmail.com>"); |
| 319 | MODULE_DESCRIPTION("Xilinx Watchdog driver"); |
Marcus Folkesson | 2e62c49 | 2018-03-16 16:14:11 +0100 | [diff] [blame] | 320 | MODULE_LICENSE("GPL"); |