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