Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Álvaro Fernández Rojas | 0da081e | 2017-05-16 18:29:13 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com> |
Álvaro Fernández Rojas | 0da081e | 2017-05-16 18:29:13 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <errno.h> |
| 9 | #include <sysreset.h> |
| 10 | #include <wdt.h> |
| 11 | |
| 12 | struct wdt_reboot_priv { |
| 13 | struct udevice *wdt; |
| 14 | }; |
| 15 | |
| 16 | static int wdt_reboot_request(struct udevice *dev, enum sysreset_t type) |
| 17 | { |
| 18 | struct wdt_reboot_priv *priv = dev_get_priv(dev); |
| 19 | int ret; |
| 20 | |
| 21 | ret = wdt_expire_now(priv->wdt, 0); |
| 22 | if (ret) |
| 23 | return ret; |
| 24 | |
| 25 | return -EINPROGRESS; |
| 26 | } |
| 27 | |
| 28 | static struct sysreset_ops wdt_reboot_ops = { |
| 29 | .request = wdt_reboot_request, |
| 30 | }; |
| 31 | |
| 32 | int wdt_reboot_probe(struct udevice *dev) |
| 33 | { |
| 34 | struct wdt_reboot_priv *priv = dev_get_priv(dev); |
| 35 | int err; |
| 36 | |
| 37 | err = uclass_get_device_by_phandle(UCLASS_WDT, dev, |
| 38 | "wdt", &priv->wdt); |
| 39 | if (err) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 40 | pr_err("unable to find wdt device\n"); |
Álvaro Fernández Rojas | 0da081e | 2017-05-16 18:29:13 +0200 | [diff] [blame] | 41 | return err; |
| 42 | } |
| 43 | |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | static const struct udevice_id wdt_reboot_ids[] = { |
| 48 | { .compatible = "wdt-reboot" }, |
| 49 | { /* sentinel */ } |
| 50 | }; |
| 51 | |
| 52 | U_BOOT_DRIVER(wdt_reboot) = { |
| 53 | .name = "wdt_reboot", |
| 54 | .id = UCLASS_SYSRESET, |
| 55 | .of_match = wdt_reboot_ids, |
| 56 | .ops = &wdt_reboot_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 57 | .priv_auto = sizeof(struct wdt_reboot_priv), |
Álvaro Fernández Rojas | 0da081e | 2017-05-16 18:29:13 +0200 | [diff] [blame] | 58 | .probe = wdt_reboot_probe, |
| 59 | }; |