• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
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 
wdt_reboot_request(struct udevice * dev,enum sysreset_t type)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 
wdt_reboot_probe(struct udevice * dev)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) {
40 		pr_err("unable to find wdt device\n");
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,
57 	.priv_auto_alloc_size = sizeof(struct wdt_reboot_priv),
58 	.probe = wdt_reboot_probe,
59 };
60