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