blob: d500d413261c2bfa4acd2e726c338dad3901ca81 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Álvaro Fernández Rojas0da081e2017-05-16 18:29:13 +02002/*
3 * Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
Álvaro Fernández Rojas0da081e2017-05-16 18:29:13 +02004 */
5
6#include <common.h>
7#include <dm.h>
8#include <errno.h>
9#include <sysreset.h>
10#include <wdt.h>
11
12struct wdt_reboot_priv {
13 struct udevice *wdt;
14};
15
16static 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
28static struct sysreset_ops wdt_reboot_ops = {
29 .request = wdt_reboot_request,
30};
31
32int 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 Yamada81e10422017-09-16 14:10:41 +090040 pr_err("unable to find wdt device\n");
Álvaro Fernández Rojas0da081e2017-05-16 18:29:13 +020041 return err;
42 }
43
44 return 0;
45}
46
47static const struct udevice_id wdt_reboot_ids[] = {
48 { .compatible = "wdt-reboot" },
49 { /* sentinel */ }
50};
51
52U_BOOT_DRIVER(wdt_reboot) = {
53 .name = "wdt_reboot",
54 .id = UCLASS_SYSRESET,
55 .of_match = wdt_reboot_ids,
56 .ops = &wdt_reboot_ops,
57 .priv_auto_alloc_size = sizeof(struct wdt_reboot_priv),
58 .probe = wdt_reboot_probe,
59};