.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * SBSA(Server Base System Architecture) Generic Watchdog driver |
---|
3 | 4 | * |
---|
.. | .. |
---|
6 | 7 | * Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com> |
---|
7 | 8 | * Al Stone <al.stone@linaro.org> |
---|
8 | 9 | * Timur Tabi <timur@codeaurora.org> |
---|
9 | | - * |
---|
10 | | - * This program is free software; you can redistribute it and/or modify |
---|
11 | | - * it under the terms of the GNU General Public License 2 as published |
---|
12 | | - * by the Free Software Foundation. |
---|
13 | | - * |
---|
14 | | - * This program is distributed in the hope that it will be useful, |
---|
15 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | | - * GNU General Public License for more details. |
---|
18 | 10 | * |
---|
19 | 11 | * ARM SBSA Generic Watchdog has two stage timeouts: |
---|
20 | 12 | * the first signal (WS0) is for alerting the system by interrupt, |
---|
.. | .. |
---|
46 | 38 | * by WOR, in the single stage mode, the timeout is (WOR * 2); in the two |
---|
47 | 39 | * stages mode, the timeout is WOR. The maximum timeout in the two stages mode |
---|
48 | 40 | * is half of that in the single stage mode. |
---|
49 | | - * |
---|
50 | 41 | */ |
---|
51 | 42 | |
---|
52 | 43 | #include <linux/io.h> |
---|
.. | .. |
---|
130 | 121 | struct sbsa_gwdt *gwdt = watchdog_get_drvdata(wdd); |
---|
131 | 122 | |
---|
132 | 123 | wdd->timeout = timeout; |
---|
| 124 | + timeout = clamp_t(unsigned int, timeout, 1, wdd->max_hw_heartbeat_ms / 1000); |
---|
133 | 125 | |
---|
134 | 126 | if (action) |
---|
135 | 127 | writel(gwdt->clk * timeout, |
---|
.. | .. |
---|
161 | 153 | timeleft += readl(gwdt->control_base + SBSA_GWDT_WOR); |
---|
162 | 154 | |
---|
163 | 155 | timeleft += lo_hi_readq(gwdt->control_base + SBSA_GWDT_WCV) - |
---|
164 | | - arch_counter_get_cntvct(); |
---|
| 156 | + arch_timer_read_counter(); |
---|
165 | 157 | |
---|
166 | 158 | do_div(timeleft, gwdt->clk); |
---|
167 | 159 | |
---|
.. | .. |
---|
231 | 223 | struct device *dev = &pdev->dev; |
---|
232 | 224 | struct watchdog_device *wdd; |
---|
233 | 225 | struct sbsa_gwdt *gwdt; |
---|
234 | | - struct resource *res; |
---|
235 | 226 | int ret, irq; |
---|
236 | 227 | u32 status; |
---|
237 | 228 | |
---|
.. | .. |
---|
240 | 231 | return -ENOMEM; |
---|
241 | 232 | platform_set_drvdata(pdev, gwdt); |
---|
242 | 233 | |
---|
243 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
244 | | - cf_base = devm_ioremap_resource(dev, res); |
---|
| 234 | + cf_base = devm_platform_ioremap_resource(pdev, 0); |
---|
245 | 235 | if (IS_ERR(cf_base)) |
---|
246 | 236 | return PTR_ERR(cf_base); |
---|
247 | 237 | |
---|
248 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
---|
249 | | - rf_base = devm_ioremap_resource(dev, res); |
---|
| 238 | + rf_base = devm_platform_ioremap_resource(pdev, 1); |
---|
250 | 239 | if (IS_ERR(rf_base)) |
---|
251 | 240 | return PTR_ERR(rf_base); |
---|
252 | 241 | |
---|
.. | .. |
---|
313 | 302 | */ |
---|
314 | 303 | sbsa_gwdt_set_timeout(wdd, wdd->timeout); |
---|
315 | 304 | |
---|
316 | | - ret = watchdog_register_device(wdd); |
---|
| 305 | + watchdog_stop_on_reboot(wdd); |
---|
| 306 | + ret = devm_watchdog_register_device(dev, wdd); |
---|
317 | 307 | if (ret) |
---|
318 | 308 | return ret; |
---|
319 | 309 | |
---|
320 | 310 | dev_info(dev, "Initialized with %ds timeout @ %u Hz, action=%d.%s\n", |
---|
321 | 311 | wdd->timeout, gwdt->clk, action, |
---|
322 | 312 | status & SBSA_GWDT_WCS_EN ? " [enabled]" : ""); |
---|
323 | | - |
---|
324 | | - return 0; |
---|
325 | | -} |
---|
326 | | - |
---|
327 | | -static void sbsa_gwdt_shutdown(struct platform_device *pdev) |
---|
328 | | -{ |
---|
329 | | - struct sbsa_gwdt *gwdt = platform_get_drvdata(pdev); |
---|
330 | | - |
---|
331 | | - sbsa_gwdt_stop(&gwdt->wdd); |
---|
332 | | -} |
---|
333 | | - |
---|
334 | | -static int sbsa_gwdt_remove(struct platform_device *pdev) |
---|
335 | | -{ |
---|
336 | | - struct sbsa_gwdt *gwdt = platform_get_drvdata(pdev); |
---|
337 | | - |
---|
338 | | - watchdog_unregister_device(&gwdt->wdd); |
---|
339 | 313 | |
---|
340 | 314 | return 0; |
---|
341 | 315 | } |
---|
.. | .. |
---|
385 | 359 | .of_match_table = sbsa_gwdt_of_match, |
---|
386 | 360 | }, |
---|
387 | 361 | .probe = sbsa_gwdt_probe, |
---|
388 | | - .remove = sbsa_gwdt_remove, |
---|
389 | | - .shutdown = sbsa_gwdt_shutdown, |
---|
390 | 362 | .id_table = sbsa_gwdt_pdev_match, |
---|
391 | 363 | }; |
---|
392 | 364 | |
---|