Thomas Gleixner | 97fb5e8 | 2019-05-29 07:17:58 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 2 | /* Copyright (c) 2014, The Linux Foundation. All rights reserved. |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 3 | */ |
Jorge Ramirez-Ortiz | 3637549 | 2019-09-06 22:54:10 +0200 | [diff] [blame] | 4 | #include <linux/bits.h> |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 5 | #include <linux/clk.h> |
Josh Cartwright | 05e487d | 2014-09-25 17:51:04 -0500 | [diff] [blame] | 6 | #include <linux/delay.h> |
Jorge Ramirez-Ortiz | 3637549 | 2019-09-06 22:54:10 +0200 | [diff] [blame] | 7 | #include <linux/interrupt.h> |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 8 | #include <linux/io.h> |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/of.h> |
| 12 | #include <linux/platform_device.h> |
| 13 | #include <linux/watchdog.h> |
Matthew McClintock | f0d9d0f | 2016-06-29 10:50:01 -0700 | [diff] [blame] | 14 | #include <linux/of_device.h> |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 15 | |
Matthew McClintock | f0d9d0f | 2016-06-29 10:50:01 -0700 | [diff] [blame] | 16 | enum wdt_reg { |
| 17 | WDT_RST, |
| 18 | WDT_EN, |
| 19 | WDT_STS, |
Matthew McClintock | 10073a2 | 2016-06-28 11:35:21 -0700 | [diff] [blame] | 20 | WDT_BARK_TIME, |
Matthew McClintock | f0d9d0f | 2016-06-29 10:50:01 -0700 | [diff] [blame] | 21 | WDT_BITE_TIME, |
| 22 | }; |
| 23 | |
Jorge Ramirez-Ortiz | 3637549 | 2019-09-06 22:54:10 +0200 | [diff] [blame] | 24 | #define QCOM_WDT_ENABLE BIT(0) |
Jorge Ramirez-Ortiz | 3637549 | 2019-09-06 22:54:10 +0200 | [diff] [blame] | 25 | |
Matthew McClintock | f0d9d0f | 2016-06-29 10:50:01 -0700 | [diff] [blame] | 26 | static const u32 reg_offset_data_apcs_tmr[] = { |
| 27 | [WDT_RST] = 0x38, |
| 28 | [WDT_EN] = 0x40, |
| 29 | [WDT_STS] = 0x44, |
Matthew McClintock | 10073a2 | 2016-06-28 11:35:21 -0700 | [diff] [blame] | 30 | [WDT_BARK_TIME] = 0x4C, |
Matthew McClintock | f0d9d0f | 2016-06-29 10:50:01 -0700 | [diff] [blame] | 31 | [WDT_BITE_TIME] = 0x5C, |
| 32 | }; |
| 33 | |
| 34 | static const u32 reg_offset_data_kpss[] = { |
| 35 | [WDT_RST] = 0x4, |
| 36 | [WDT_EN] = 0x8, |
| 37 | [WDT_STS] = 0xC, |
Matthew McClintock | 10073a2 | 2016-06-28 11:35:21 -0700 | [diff] [blame] | 38 | [WDT_BARK_TIME] = 0x10, |
Matthew McClintock | f0d9d0f | 2016-06-29 10:50:01 -0700 | [diff] [blame] | 39 | [WDT_BITE_TIME] = 0x14, |
| 40 | }; |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 41 | |
Ansuel Smith | 000de54 | 2020-02-04 20:56:48 +0100 | [diff] [blame] | 42 | struct qcom_wdt_match_data { |
| 43 | const u32 *offset; |
| 44 | bool pretimeout; |
| 45 | }; |
| 46 | |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 47 | struct qcom_wdt { |
| 48 | struct watchdog_device wdd; |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 49 | unsigned long rate; |
| 50 | void __iomem *base; |
Matthew McClintock | f0d9d0f | 2016-06-29 10:50:01 -0700 | [diff] [blame] | 51 | const u32 *layout; |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 52 | }; |
| 53 | |
Matthew McClintock | f0d9d0f | 2016-06-29 10:50:01 -0700 | [diff] [blame] | 54 | static void __iomem *wdt_addr(struct qcom_wdt *wdt, enum wdt_reg reg) |
| 55 | { |
| 56 | return wdt->base + wdt->layout[reg]; |
| 57 | } |
| 58 | |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 59 | static inline |
| 60 | struct qcom_wdt *to_qcom_wdt(struct watchdog_device *wdd) |
| 61 | { |
| 62 | return container_of(wdd, struct qcom_wdt, wdd); |
| 63 | } |
| 64 | |
Jorge Ramirez-Ortiz | 3637549 | 2019-09-06 22:54:10 +0200 | [diff] [blame] | 65 | static irqreturn_t qcom_wdt_isr(int irq, void *arg) |
| 66 | { |
| 67 | struct watchdog_device *wdd = arg; |
| 68 | |
| 69 | watchdog_notify_pretimeout(wdd); |
| 70 | |
| 71 | return IRQ_HANDLED; |
| 72 | } |
| 73 | |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 74 | static int qcom_wdt_start(struct watchdog_device *wdd) |
| 75 | { |
| 76 | struct qcom_wdt *wdt = to_qcom_wdt(wdd); |
Jorge Ramirez-Ortiz | 3637549 | 2019-09-06 22:54:10 +0200 | [diff] [blame] | 77 | unsigned int bark = wdd->timeout - wdd->pretimeout; |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 78 | |
Matthew McClintock | f0d9d0f | 2016-06-29 10:50:01 -0700 | [diff] [blame] | 79 | writel(0, wdt_addr(wdt, WDT_EN)); |
| 80 | writel(1, wdt_addr(wdt, WDT_RST)); |
Jorge Ramirez-Ortiz | 3637549 | 2019-09-06 22:54:10 +0200 | [diff] [blame] | 81 | writel(bark * wdt->rate, wdt_addr(wdt, WDT_BARK_TIME)); |
Matthew McClintock | f0d9d0f | 2016-06-29 10:50:01 -0700 | [diff] [blame] | 82 | writel(wdd->timeout * wdt->rate, wdt_addr(wdt, WDT_BITE_TIME)); |
Sai Prakash Ranjan | a4f3407 | 2021-01-26 20:32:41 +0530 | [diff] [blame] | 83 | writel(QCOM_WDT_ENABLE, wdt_addr(wdt, WDT_EN)); |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | static int qcom_wdt_stop(struct watchdog_device *wdd) |
| 88 | { |
| 89 | struct qcom_wdt *wdt = to_qcom_wdt(wdd); |
| 90 | |
Matthew McClintock | f0d9d0f | 2016-06-29 10:50:01 -0700 | [diff] [blame] | 91 | writel(0, wdt_addr(wdt, WDT_EN)); |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | static int qcom_wdt_ping(struct watchdog_device *wdd) |
| 96 | { |
| 97 | struct qcom_wdt *wdt = to_qcom_wdt(wdd); |
| 98 | |
Matthew McClintock | f0d9d0f | 2016-06-29 10:50:01 -0700 | [diff] [blame] | 99 | writel(1, wdt_addr(wdt, WDT_RST)); |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | static int qcom_wdt_set_timeout(struct watchdog_device *wdd, |
| 104 | unsigned int timeout) |
| 105 | { |
| 106 | wdd->timeout = timeout; |
| 107 | return qcom_wdt_start(wdd); |
| 108 | } |
| 109 | |
Jorge Ramirez-Ortiz | 3637549 | 2019-09-06 22:54:10 +0200 | [diff] [blame] | 110 | static int qcom_wdt_set_pretimeout(struct watchdog_device *wdd, |
| 111 | unsigned int timeout) |
| 112 | { |
| 113 | wdd->pretimeout = timeout; |
| 114 | return qcom_wdt_start(wdd); |
| 115 | } |
| 116 | |
Guenter Roeck | 4d8b229 | 2016-02-26 17:32:49 -0800 | [diff] [blame] | 117 | static int qcom_wdt_restart(struct watchdog_device *wdd, unsigned long action, |
| 118 | void *data) |
Josh Cartwright | 05e487d | 2014-09-25 17:51:04 -0500 | [diff] [blame] | 119 | { |
Damien Riegel | 80969a6 | 2015-11-16 12:28:09 -0500 | [diff] [blame] | 120 | struct qcom_wdt *wdt = to_qcom_wdt(wdd); |
Josh Cartwright | 05e487d | 2014-09-25 17:51:04 -0500 | [diff] [blame] | 121 | u32 timeout; |
| 122 | |
| 123 | /* |
| 124 | * Trigger watchdog bite: |
| 125 | * Setup BITE_TIME to be 128ms, and enable WDT. |
| 126 | */ |
| 127 | timeout = 128 * wdt->rate / 1000; |
| 128 | |
Matthew McClintock | f0d9d0f | 2016-06-29 10:50:01 -0700 | [diff] [blame] | 129 | writel(0, wdt_addr(wdt, WDT_EN)); |
| 130 | writel(1, wdt_addr(wdt, WDT_RST)); |
Matthew McClintock | 10073a2 | 2016-06-28 11:35:21 -0700 | [diff] [blame] | 131 | writel(timeout, wdt_addr(wdt, WDT_BARK_TIME)); |
Matthew McClintock | f0d9d0f | 2016-06-29 10:50:01 -0700 | [diff] [blame] | 132 | writel(timeout, wdt_addr(wdt, WDT_BITE_TIME)); |
Jorge Ramirez-Ortiz | 3637549 | 2019-09-06 22:54:10 +0200 | [diff] [blame] | 133 | writel(QCOM_WDT_ENABLE, wdt_addr(wdt, WDT_EN)); |
Josh Cartwright | 05e487d | 2014-09-25 17:51:04 -0500 | [diff] [blame] | 134 | |
| 135 | /* |
| 136 | * Actually make sure the above sequence hits hardware before sleeping. |
| 137 | */ |
| 138 | wmb(); |
| 139 | |
Manivannan Sadhasivam | 7948fab | 2020-12-07 11:30:05 +0530 | [diff] [blame] | 140 | mdelay(150); |
Damien Riegel | 80969a6 | 2015-11-16 12:28:09 -0500 | [diff] [blame] | 141 | return 0; |
Josh Cartwright | 05e487d | 2014-09-25 17:51:04 -0500 | [diff] [blame] | 142 | } |
| 143 | |
Robert Marko | 8650d0f | 2020-10-31 13:11:15 +0100 | [diff] [blame] | 144 | static int qcom_wdt_is_running(struct watchdog_device *wdd) |
| 145 | { |
| 146 | struct qcom_wdt *wdt = to_qcom_wdt(wdd); |
| 147 | |
| 148 | return (readl(wdt_addr(wdt, WDT_EN)) & QCOM_WDT_ENABLE); |
| 149 | } |
| 150 | |
Damien Riegel | 80969a6 | 2015-11-16 12:28:09 -0500 | [diff] [blame] | 151 | static const struct watchdog_ops qcom_wdt_ops = { |
| 152 | .start = qcom_wdt_start, |
| 153 | .stop = qcom_wdt_stop, |
| 154 | .ping = qcom_wdt_ping, |
| 155 | .set_timeout = qcom_wdt_set_timeout, |
Jorge Ramirez-Ortiz | 3637549 | 2019-09-06 22:54:10 +0200 | [diff] [blame] | 156 | .set_pretimeout = qcom_wdt_set_pretimeout, |
Damien Riegel | 80969a6 | 2015-11-16 12:28:09 -0500 | [diff] [blame] | 157 | .restart = qcom_wdt_restart, |
| 158 | .owner = THIS_MODULE, |
| 159 | }; |
| 160 | |
| 161 | static const struct watchdog_info qcom_wdt_info = { |
| 162 | .options = WDIOF_KEEPALIVEPING |
| 163 | | WDIOF_MAGICCLOSE |
Guenter Roeck | b6ef36d | 2016-04-04 17:37:46 -0700 | [diff] [blame] | 164 | | WDIOF_SETTIMEOUT |
| 165 | | WDIOF_CARDRESET, |
Damien Riegel | 80969a6 | 2015-11-16 12:28:09 -0500 | [diff] [blame] | 166 | .identity = KBUILD_MODNAME, |
| 167 | }; |
| 168 | |
Jorge Ramirez-Ortiz | 3637549 | 2019-09-06 22:54:10 +0200 | [diff] [blame] | 169 | static const struct watchdog_info qcom_wdt_pt_info = { |
| 170 | .options = WDIOF_KEEPALIVEPING |
| 171 | | WDIOF_MAGICCLOSE |
| 172 | | WDIOF_SETTIMEOUT |
| 173 | | WDIOF_PRETIMEOUT |
| 174 | | WDIOF_CARDRESET, |
| 175 | .identity = KBUILD_MODNAME, |
| 176 | }; |
| 177 | |
Guenter Roeck | bba07e6 | 2019-04-09 10:23:50 -0700 | [diff] [blame] | 178 | static void qcom_clk_disable_unprepare(void *data) |
| 179 | { |
| 180 | clk_disable_unprepare(data); |
| 181 | } |
| 182 | |
Ansuel Smith | 000de54 | 2020-02-04 20:56:48 +0100 | [diff] [blame] | 183 | static const struct qcom_wdt_match_data match_data_apcs_tmr = { |
| 184 | .offset = reg_offset_data_apcs_tmr, |
| 185 | .pretimeout = false, |
| 186 | }; |
| 187 | |
| 188 | static const struct qcom_wdt_match_data match_data_kpss = { |
| 189 | .offset = reg_offset_data_kpss, |
| 190 | .pretimeout = true, |
| 191 | }; |
| 192 | |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 193 | static int qcom_wdt_probe(struct platform_device *pdev) |
| 194 | { |
Guenter Roeck | bba07e6 | 2019-04-09 10:23:50 -0700 | [diff] [blame] | 195 | struct device *dev = &pdev->dev; |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 196 | struct qcom_wdt *wdt; |
| 197 | struct resource *res; |
Guenter Roeck | bba07e6 | 2019-04-09 10:23:50 -0700 | [diff] [blame] | 198 | struct device_node *np = dev->of_node; |
Ansuel Smith | 000de54 | 2020-02-04 20:56:48 +0100 | [diff] [blame] | 199 | const struct qcom_wdt_match_data *data; |
Mathieu Olivari | 0dfd582 | 2015-02-20 18:19:34 -0800 | [diff] [blame] | 200 | u32 percpu_offset; |
Jorge Ramirez-Ortiz | 3637549 | 2019-09-06 22:54:10 +0200 | [diff] [blame] | 201 | int irq, ret; |
Jorge Ramirez-Ortiz | 52a1421 | 2019-09-06 22:54:11 +0200 | [diff] [blame] | 202 | struct clk *clk; |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 203 | |
Ansuel Smith | 000de54 | 2020-02-04 20:56:48 +0100 | [diff] [blame] | 204 | data = of_device_get_match_data(dev); |
| 205 | if (!data) { |
Guenter Roeck | bba07e6 | 2019-04-09 10:23:50 -0700 | [diff] [blame] | 206 | dev_err(dev, "Unsupported QCOM WDT module\n"); |
Matthew McClintock | f0d9d0f | 2016-06-29 10:50:01 -0700 | [diff] [blame] | 207 | return -ENODEV; |
| 208 | } |
| 209 | |
Guenter Roeck | bba07e6 | 2019-04-09 10:23:50 -0700 | [diff] [blame] | 210 | wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 211 | if (!wdt) |
| 212 | return -ENOMEM; |
| 213 | |
| 214 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Fabio Estevam | 15210ad | 2017-07-22 13:04:33 -0300 | [diff] [blame] | 215 | if (!res) |
| 216 | return -ENOMEM; |
Mathieu Olivari | 0dfd582 | 2015-02-20 18:19:34 -0800 | [diff] [blame] | 217 | |
| 218 | /* We use CPU0's DGT for the watchdog */ |
| 219 | if (of_property_read_u32(np, "cpu-offset", &percpu_offset)) |
| 220 | percpu_offset = 0; |
| 221 | |
| 222 | res->start += percpu_offset; |
| 223 | res->end += percpu_offset; |
| 224 | |
Guenter Roeck | bba07e6 | 2019-04-09 10:23:50 -0700 | [diff] [blame] | 225 | wdt->base = devm_ioremap_resource(dev, res); |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 226 | if (IS_ERR(wdt->base)) |
| 227 | return PTR_ERR(wdt->base); |
| 228 | |
Jorge Ramirez-Ortiz | 52a1421 | 2019-09-06 22:54:11 +0200 | [diff] [blame] | 229 | clk = devm_clk_get(dev, NULL); |
| 230 | if (IS_ERR(clk)) { |
Guenter Roeck | bba07e6 | 2019-04-09 10:23:50 -0700 | [diff] [blame] | 231 | dev_err(dev, "failed to get input clock\n"); |
Jorge Ramirez-Ortiz | 52a1421 | 2019-09-06 22:54:11 +0200 | [diff] [blame] | 232 | return PTR_ERR(clk); |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 233 | } |
| 234 | |
Jorge Ramirez-Ortiz | 52a1421 | 2019-09-06 22:54:11 +0200 | [diff] [blame] | 235 | ret = clk_prepare_enable(clk); |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 236 | if (ret) { |
Guenter Roeck | bba07e6 | 2019-04-09 10:23:50 -0700 | [diff] [blame] | 237 | dev_err(dev, "failed to setup clock\n"); |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 238 | return ret; |
| 239 | } |
Jorge Ramirez-Ortiz | 52a1421 | 2019-09-06 22:54:11 +0200 | [diff] [blame] | 240 | ret = devm_add_action_or_reset(dev, qcom_clk_disable_unprepare, clk); |
Guenter Roeck | bba07e6 | 2019-04-09 10:23:50 -0700 | [diff] [blame] | 241 | if (ret) |
| 242 | return ret; |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 243 | |
| 244 | /* |
| 245 | * We use the clock rate to calculate the max timeout, so ensure it's |
| 246 | * not zero to avoid a divide-by-zero exception. |
| 247 | * |
| 248 | * WATCHDOG_CORE assumes units of seconds, if the WDT is clocked such |
| 249 | * that it would bite before a second elapses it's usefulness is |
| 250 | * limited. Bail if this is the case. |
| 251 | */ |
Jorge Ramirez-Ortiz | 52a1421 | 2019-09-06 22:54:11 +0200 | [diff] [blame] | 252 | wdt->rate = clk_get_rate(clk); |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 253 | if (wdt->rate == 0 || |
| 254 | wdt->rate > 0x10000000U) { |
Guenter Roeck | bba07e6 | 2019-04-09 10:23:50 -0700 | [diff] [blame] | 255 | dev_err(dev, "invalid clock rate\n"); |
| 256 | return -EINVAL; |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 257 | } |
| 258 | |
Jorge Ramirez-Ortiz | 3637549 | 2019-09-06 22:54:10 +0200 | [diff] [blame] | 259 | /* check if there is pretimeout support */ |
Sai Prakash Ranjan | e0b4f4e | 2019-12-13 12:19:34 +0530 | [diff] [blame] | 260 | irq = platform_get_irq_optional(pdev, 0); |
Ansuel Smith | 000de54 | 2020-02-04 20:56:48 +0100 | [diff] [blame] | 261 | if (data->pretimeout && irq > 0) { |
Stephen Boyd | cc9cc79 | 2020-02-19 16:20:47 -0800 | [diff] [blame] | 262 | ret = devm_request_irq(dev, irq, qcom_wdt_isr, 0, |
Jorge Ramirez-Ortiz | 3637549 | 2019-09-06 22:54:10 +0200 | [diff] [blame] | 263 | "wdt_bark", &wdt->wdd); |
| 264 | if (ret) |
| 265 | return ret; |
| 266 | |
| 267 | wdt->wdd.info = &qcom_wdt_pt_info; |
| 268 | wdt->wdd.pretimeout = 1; |
| 269 | } else { |
| 270 | if (irq == -EPROBE_DEFER) |
| 271 | return -EPROBE_DEFER; |
| 272 | |
| 273 | wdt->wdd.info = &qcom_wdt_info; |
| 274 | } |
| 275 | |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 276 | wdt->wdd.ops = &qcom_wdt_ops; |
| 277 | wdt->wdd.min_timeout = 1; |
| 278 | wdt->wdd.max_timeout = 0x10000000U / wdt->rate; |
Guenter Roeck | bba07e6 | 2019-04-09 10:23:50 -0700 | [diff] [blame] | 279 | wdt->wdd.parent = dev; |
Ansuel Smith | 000de54 | 2020-02-04 20:56:48 +0100 | [diff] [blame] | 280 | wdt->layout = data->offset; |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 281 | |
Christian Lamparter | f06f35c | 2016-11-14 02:11:16 +0100 | [diff] [blame] | 282 | if (readl(wdt_addr(wdt, WDT_STS)) & 1) |
Guenter Roeck | b6ef36d | 2016-04-04 17:37:46 -0700 | [diff] [blame] | 283 | wdt->wdd.bootstatus = WDIOF_CARDRESET; |
| 284 | |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 285 | /* |
| 286 | * If 'timeout-sec' unspecified in devicetree, assume a 30 second |
| 287 | * default, unless the max timeout is less than 30 seconds, then use |
| 288 | * the max instead. |
| 289 | */ |
| 290 | wdt->wdd.timeout = min(wdt->wdd.max_timeout, 30U); |
Guenter Roeck | bba07e6 | 2019-04-09 10:23:50 -0700 | [diff] [blame] | 291 | watchdog_init_timeout(&wdt->wdd, 0, dev); |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 292 | |
Robert Marko | 8650d0f | 2020-10-31 13:11:15 +0100 | [diff] [blame] | 293 | /* |
| 294 | * If WDT is already running, call WDT start which |
| 295 | * will stop the WDT, set timeouts as bootloader |
| 296 | * might use different ones and set running bit |
| 297 | * to inform the WDT subsystem to ping the WDT |
| 298 | */ |
| 299 | if (qcom_wdt_is_running(&wdt->wdd)) { |
| 300 | qcom_wdt_start(&wdt->wdd); |
| 301 | set_bit(WDOG_HW_RUNNING, &wdt->wdd.status); |
| 302 | } |
| 303 | |
Guenter Roeck | bba07e6 | 2019-04-09 10:23:50 -0700 | [diff] [blame] | 304 | ret = devm_watchdog_register_device(dev, &wdt->wdd); |
Wolfram Sang | ccbf872a | 2019-05-18 23:27:48 +0200 | [diff] [blame] | 305 | if (ret) |
Guenter Roeck | bba07e6 | 2019-04-09 10:23:50 -0700 | [diff] [blame] | 306 | return ret; |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 307 | |
| 308 | platform_set_drvdata(pdev, wdt); |
| 309 | return 0; |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 310 | } |
| 311 | |
Sai Prakash Ranjan | 671cdde | 2019-01-17 20:49:42 +0530 | [diff] [blame] | 312 | static int __maybe_unused qcom_wdt_suspend(struct device *dev) |
| 313 | { |
| 314 | struct qcom_wdt *wdt = dev_get_drvdata(dev); |
| 315 | |
| 316 | if (watchdog_active(&wdt->wdd)) |
| 317 | qcom_wdt_stop(&wdt->wdd); |
| 318 | |
| 319 | return 0; |
| 320 | } |
| 321 | |
| 322 | static int __maybe_unused qcom_wdt_resume(struct device *dev) |
| 323 | { |
| 324 | struct qcom_wdt *wdt = dev_get_drvdata(dev); |
| 325 | |
| 326 | if (watchdog_active(&wdt->wdd)) |
| 327 | qcom_wdt_start(&wdt->wdd); |
| 328 | |
| 329 | return 0; |
| 330 | } |
| 331 | |
Sai Prakash Ranjan | 8442ef6 | 2021-03-11 01:50:04 +0530 | [diff] [blame] | 332 | static const struct dev_pm_ops qcom_wdt_pm_ops = { |
| 333 | SET_LATE_SYSTEM_SLEEP_PM_OPS(qcom_wdt_suspend, qcom_wdt_resume) |
| 334 | }; |
Sai Prakash Ranjan | 671cdde | 2019-01-17 20:49:42 +0530 | [diff] [blame] | 335 | |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 336 | static const struct of_device_id qcom_wdt_of_table[] = { |
Ansuel Smith | 000de54 | 2020-02-04 20:56:48 +0100 | [diff] [blame] | 337 | { .compatible = "qcom,kpss-timer", .data = &match_data_apcs_tmr }, |
| 338 | { .compatible = "qcom,scss-timer", .data = &match_data_apcs_tmr }, |
| 339 | { .compatible = "qcom,kpss-wdt", .data = &match_data_kpss }, |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 340 | { }, |
| 341 | }; |
| 342 | MODULE_DEVICE_TABLE(of, qcom_wdt_of_table); |
| 343 | |
| 344 | static struct platform_driver qcom_watchdog_driver = { |
| 345 | .probe = qcom_wdt_probe, |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 346 | .driver = { |
| 347 | .name = KBUILD_MODNAME, |
| 348 | .of_match_table = qcom_wdt_of_table, |
Sai Prakash Ranjan | 671cdde | 2019-01-17 20:49:42 +0530 | [diff] [blame] | 349 | .pm = &qcom_wdt_pm_ops, |
Josh Cartwright | 1094ebe | 2014-09-25 17:51:02 -0500 | [diff] [blame] | 350 | }, |
| 351 | }; |
| 352 | module_platform_driver(qcom_watchdog_driver); |
| 353 | |
| 354 | MODULE_DESCRIPTION("QCOM KPSS Watchdog Driver"); |
| 355 | MODULE_LICENSE("GPL v2"); |