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 | |
Guenter Roeck | 801cdffe | 2019-04-09 10:23:48 -0700 | [diff] [blame] | 154 | static void xwdt_clk_disable_unprepare(void *data) |
| 155 | { |
| 156 | clk_disable_unprepare(data); |
| 157 | } |
| 158 | |
Bill Pemberton | 2d991a1 | 2012-11-19 13:21:41 -0500 | [diff] [blame] | 159 | static int xwdt_probe(struct platform_device *pdev) |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 160 | { |
Guenter Roeck | 801cdffe | 2019-04-09 10:23:48 -0700 | [diff] [blame] | 161 | struct device *dev = &pdev->dev; |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 162 | int rc; |
Michal Simek | 8d6a140 | 2014-02-12 14:41:25 +0100 | [diff] [blame] | 163 | u32 pfreq = 0, enable_once = 0; |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 164 | struct xwdt_device *xdev; |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 165 | struct watchdog_device *xilinx_wdt_wdd; |
| 166 | |
Guenter Roeck | 801cdffe | 2019-04-09 10:23:48 -0700 | [diff] [blame] | 167 | xdev = devm_kzalloc(dev, sizeof(*xdev), GFP_KERNEL); |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 168 | if (!xdev) |
| 169 | return -ENOMEM; |
| 170 | |
| 171 | xilinx_wdt_wdd = &xdev->xilinx_wdt_wdd; |
| 172 | xilinx_wdt_wdd->info = &xilinx_wdt_ident; |
| 173 | xilinx_wdt_wdd->ops = &xilinx_wdt_ops; |
Guenter Roeck | 801cdffe | 2019-04-09 10:23:48 -0700 | [diff] [blame] | 174 | xilinx_wdt_wdd->parent = dev; |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 175 | |
Guenter Roeck | 0f0a6a2 | 2019-04-02 12:01:53 -0700 | [diff] [blame] | 176 | xdev->base = devm_platform_ioremap_resource(pdev, 0); |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 177 | if (IS_ERR(xdev->base)) |
| 178 | return PTR_ERR(xdev->base); |
Michal Simek | f06cdfd | 2014-02-12 14:34:34 +0100 | [diff] [blame] | 179 | |
Guenter Roeck | 801cdffe | 2019-04-09 10:23:48 -0700 | [diff] [blame] | 180 | rc = of_property_read_u32(dev->of_node, "xlnx,wdt-interval", |
Michal Simek | 2e79a36 | 2014-02-12 14:41:21 +0100 | [diff] [blame] | 181 | &xdev->wdt_interval); |
Michal Simek | 8d6a140 | 2014-02-12 14:41:25 +0100 | [diff] [blame] | 182 | if (rc) |
Guenter Roeck | 801cdffe | 2019-04-09 10:23:48 -0700 | [diff] [blame] | 183 | dev_warn(dev, "Parameter \"xlnx,wdt-interval\" not found\n"); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 184 | |
Guenter Roeck | 801cdffe | 2019-04-09 10:23:48 -0700 | [diff] [blame] | 185 | rc = of_property_read_u32(dev->of_node, "xlnx,wdt-enable-once", |
Michal Simek | 2e79a36 | 2014-02-12 14:41:21 +0100 | [diff] [blame] | 186 | &enable_once); |
| 187 | if (rc) |
Guenter Roeck | 801cdffe | 2019-04-09 10:23:48 -0700 | [diff] [blame] | 188 | dev_warn(dev, |
Michal Simek | 4c7fbbc | 2014-02-12 14:41:20 +0100 | [diff] [blame] | 189 | "Parameter \"xlnx,wdt-enable-once\" not found\n"); |
Michal Simek | 2e79a36 | 2014-02-12 14:41:21 +0100 | [diff] [blame] | 190 | |
| 191 | watchdog_set_nowayout(xilinx_wdt_wdd, enable_once); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 192 | |
Guenter Roeck | 801cdffe | 2019-04-09 10:23:48 -0700 | [diff] [blame] | 193 | xdev->clk = devm_clk_get(dev, NULL); |
Maulik Jodhani | b6bc416 | 2017-08-07 13:24:22 +0200 | [diff] [blame] | 194 | if (IS_ERR(xdev->clk)) { |
| 195 | if (PTR_ERR(xdev->clk) != -ENOENT) |
| 196 | return PTR_ERR(xdev->clk); |
| 197 | |
| 198 | /* |
| 199 | * Clock framework support is optional, continue on |
| 200 | * anyways if we don't find a matching clock. |
| 201 | */ |
| 202 | xdev->clk = NULL; |
| 203 | |
Guenter Roeck | 801cdffe | 2019-04-09 10:23:48 -0700 | [diff] [blame] | 204 | rc = of_property_read_u32(dev->of_node, "clock-frequency", |
Maulik Jodhani | b6bc416 | 2017-08-07 13:24:22 +0200 | [diff] [blame] | 205 | &pfreq); |
| 206 | if (rc) |
Guenter Roeck | 801cdffe | 2019-04-09 10:23:48 -0700 | [diff] [blame] | 207 | dev_warn(dev, |
Maulik Jodhani | b6bc416 | 2017-08-07 13:24:22 +0200 | [diff] [blame] | 208 | "The watchdog clock freq cannot be obtained\n"); |
| 209 | } else { |
| 210 | pfreq = clk_get_rate(xdev->clk); |
| 211 | } |
| 212 | |
Michal Simek | 75b3c5a | 2014-02-12 14:41:22 +0100 | [diff] [blame] | 213 | /* |
| 214 | * Twice of the 2^wdt_interval / freq because the first wdt overflow is |
| 215 | * ignored (interrupt), reset is only generated at second wdt overflow |
| 216 | */ |
Michal Simek | 8d6a140 | 2014-02-12 14:41:25 +0100 | [diff] [blame] | 217 | if (pfreq && xdev->wdt_interval) |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 218 | xilinx_wdt_wdd->timeout = 2 * ((1 << xdev->wdt_interval) / |
Michal Simek | 2e79a36 | 2014-02-12 14:41:21 +0100 | [diff] [blame] | 219 | pfreq); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 220 | |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 221 | spin_lock_init(&xdev->spinlock); |
| 222 | watchdog_set_drvdata(xilinx_wdt_wdd, xdev); |
| 223 | |
Shubhrajyoti Datta | 9d6b4ef | 2016-08-12 12:17:01 +0530 | [diff] [blame] | 224 | rc = clk_prepare_enable(xdev->clk); |
| 225 | if (rc) { |
Guenter Roeck | 801cdffe | 2019-04-09 10:23:48 -0700 | [diff] [blame] | 226 | dev_err(dev, "unable to enable clock\n"); |
Shubhrajyoti Datta | 9d6b4ef | 2016-08-12 12:17:01 +0530 | [diff] [blame] | 227 | return rc; |
| 228 | } |
Guenter Roeck | 801cdffe | 2019-04-09 10:23:48 -0700 | [diff] [blame] | 229 | rc = devm_add_action_or_reset(dev, xwdt_clk_disable_unprepare, |
| 230 | xdev->clk); |
| 231 | if (rc) |
| 232 | return rc; |
Shubhrajyoti Datta | 9d6b4ef | 2016-08-12 12:17:01 +0530 | [diff] [blame] | 233 | |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 234 | rc = xwdt_selftest(xdev); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 235 | if (rc == XWT_TIMER_FAILED) { |
Guenter Roeck | 801cdffe | 2019-04-09 10:23:48 -0700 | [diff] [blame] | 236 | dev_err(dev, "SelfTest routine error\n"); |
| 237 | return rc; |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 238 | } |
| 239 | |
Guenter Roeck | 801cdffe | 2019-04-09 10:23:48 -0700 | [diff] [blame] | 240 | rc = devm_watchdog_register_device(dev, xilinx_wdt_wdd); |
Wolfram Sang | 0fa6cf7 | 2019-05-18 23:27:44 +0200 | [diff] [blame] | 241 | if (rc) |
Guenter Roeck | 801cdffe | 2019-04-09 10:23:48 -0700 | [diff] [blame] | 242 | return rc; |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 243 | |
Maulik Jodhani | b6bc416 | 2017-08-07 13:24:22 +0200 | [diff] [blame] | 244 | clk_disable(xdev->clk); |
| 245 | |
Guenter Roeck | 801cdffe | 2019-04-09 10:23:48 -0700 | [diff] [blame] | 246 | dev_info(dev, "Xilinx Watchdog Timer at %p with timeout %ds\n", |
Michal Simek | 9066317 | 2014-02-12 14:41:19 +0100 | [diff] [blame] | 247 | xdev->base, xilinx_wdt_wdd->timeout); |
| 248 | |
| 249 | platform_set_drvdata(pdev, xdev); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 250 | |
| 251 | return 0; |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 252 | } |
| 253 | |
Michal Simek | 6f671c6 | 2017-08-07 13:24:23 +0200 | [diff] [blame] | 254 | /** |
| 255 | * xwdt_suspend - Suspend the device. |
| 256 | * |
| 257 | * @dev: handle to the device structure. |
| 258 | * Return: 0 always. |
| 259 | */ |
| 260 | static int __maybe_unused xwdt_suspend(struct device *dev) |
| 261 | { |
Wolfram Sang | 2074563 | 2018-04-19 16:06:29 +0200 | [diff] [blame] | 262 | struct xwdt_device *xdev = dev_get_drvdata(dev); |
Michal Simek | 6f671c6 | 2017-08-07 13:24:23 +0200 | [diff] [blame] | 263 | |
| 264 | if (watchdog_active(&xdev->xilinx_wdt_wdd)) |
| 265 | xilinx_wdt_stop(&xdev->xilinx_wdt_wdd); |
| 266 | |
| 267 | return 0; |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * xwdt_resume - Resume the device. |
| 272 | * |
| 273 | * @dev: handle to the device structure. |
| 274 | * Return: 0 on success, errno otherwise. |
| 275 | */ |
| 276 | static int __maybe_unused xwdt_resume(struct device *dev) |
| 277 | { |
Wolfram Sang | 2074563 | 2018-04-19 16:06:29 +0200 | [diff] [blame] | 278 | struct xwdt_device *xdev = dev_get_drvdata(dev); |
Michal Simek | 6f671c6 | 2017-08-07 13:24:23 +0200 | [diff] [blame] | 279 | int ret = 0; |
| 280 | |
| 281 | if (watchdog_active(&xdev->xilinx_wdt_wdd)) |
| 282 | ret = xilinx_wdt_start(&xdev->xilinx_wdt_wdd); |
| 283 | |
| 284 | return ret; |
| 285 | } |
| 286 | |
| 287 | static SIMPLE_DEV_PM_OPS(xwdt_pm_ops, xwdt_suspend, xwdt_resume); |
| 288 | |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 289 | /* Match table for of_platform binding */ |
Jingoo Han | 9ebf185 | 2014-05-07 17:42:22 +0900 | [diff] [blame] | 290 | static const struct of_device_id xwdt_of_match[] = { |
Michal Simek | 8fce9b3 | 2013-05-31 07:56:34 +0200 | [diff] [blame] | 291 | { .compatible = "xlnx,xps-timebase-wdt-1.00.a", }, |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 292 | { .compatible = "xlnx,xps-timebase-wdt-1.01.a", }, |
| 293 | {}, |
| 294 | }; |
| 295 | MODULE_DEVICE_TABLE(of, xwdt_of_match); |
| 296 | |
| 297 | static struct platform_driver xwdt_driver = { |
| 298 | .probe = xwdt_probe, |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 299 | .driver = { |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 300 | .name = WATCHDOG_NAME, |
| 301 | .of_match_table = xwdt_of_match, |
Michal Simek | 6f671c6 | 2017-08-07 13:24:23 +0200 | [diff] [blame] | 302 | .pm = &xwdt_pm_ops, |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 303 | }, |
| 304 | }; |
| 305 | |
Axel Lin | b8ec611 | 2011-11-29 13:56:27 +0800 | [diff] [blame] | 306 | module_platform_driver(xwdt_driver); |
Alejandro Cabrera | e9659e6 | 2011-06-02 22:13:11 +0100 | [diff] [blame] | 307 | |
| 308 | MODULE_AUTHOR("Alejandro Cabrera <aldaya@gmail.com>"); |
| 309 | MODULE_DESCRIPTION("Xilinx Watchdog driver"); |
Marcus Folkesson | 2e62c49 | 2018-03-16 16:14:11 +0100 | [diff] [blame] | 310 | MODULE_LICENSE("GPL"); |