]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
17a0c141 ÁFR |
2 | /* |
3 | * Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com> | |
17a0c141 ÁFR |
4 | */ |
5 | ||
d678a59d | 6 | #include <common.h> |
17a0c141 | 7 | #include <dm.h> |
a8f63d18 | 8 | #include <dm/device-internal.h> |
17a0c141 | 9 | #include <errno.h> |
a8f63d18 | 10 | #include <malloc.h> |
17a0c141 ÁFR |
11 | #include <sysreset.h> |
12 | #include <wdt.h> | |
1e94b46f | 13 | #include <linux/printk.h> |
17a0c141 | 14 | |
5544a011 | 15 | struct wdt_reboot_plat { |
17a0c141 ÁFR |
16 | struct udevice *wdt; |
17 | }; | |
18 | ||
19 | static int wdt_reboot_request(struct udevice *dev, enum sysreset_t type) | |
20 | { | |
5544a011 | 21 | struct wdt_reboot_plat *plat = dev_get_plat(dev); |
17a0c141 ÁFR |
22 | int ret; |
23 | ||
88c4cbed HS |
24 | switch (type) { |
25 | case SYSRESET_COLD: | |
26 | case SYSRESET_WARM: | |
27 | ret = wdt_expire_now(plat->wdt, 0); | |
28 | if (ret) | |
29 | return ret; | |
30 | break; | |
31 | default: | |
da35ab68 | 32 | return -EPROTONOSUPPORT; |
88c4cbed | 33 | } |
17a0c141 ÁFR |
34 | |
35 | return -EINPROGRESS; | |
36 | } | |
37 | ||
38 | static struct sysreset_ops wdt_reboot_ops = { | |
39 | .request = wdt_reboot_request, | |
40 | }; | |
41 | ||
5544a011 | 42 | static int wdt_reboot_of_to_plat(struct udevice *dev) |
17a0c141 | 43 | { |
5544a011 | 44 | struct wdt_reboot_plat *plat = dev_get_plat(dev); |
17a0c141 ÁFR |
45 | int err; |
46 | ||
47 | err = uclass_get_device_by_phandle(UCLASS_WDT, dev, | |
5544a011 | 48 | "wdt", &plat->wdt); |
17a0c141 | 49 | if (err) { |
9b643e31 | 50 | pr_err("unable to find wdt device\n"); |
17a0c141 ÁFR |
51 | return err; |
52 | } | |
53 | ||
54 | return 0; | |
55 | } | |
56 | ||
57 | static const struct udevice_id wdt_reboot_ids[] = { | |
58 | { .compatible = "wdt-reboot" }, | |
59 | { /* sentinel */ } | |
60 | }; | |
61 | ||
62 | U_BOOT_DRIVER(wdt_reboot) = { | |
63 | .name = "wdt_reboot", | |
64 | .id = UCLASS_SYSRESET, | |
65 | .of_match = wdt_reboot_ids, | |
5544a011 SH |
66 | .of_to_plat = wdt_reboot_of_to_plat, |
67 | .plat_auto = sizeof(struct wdt_reboot_plat), | |
17a0c141 | 68 | .ops = &wdt_reboot_ops, |
17a0c141 | 69 | }; |
a8f63d18 SH |
70 | |
71 | #if IS_ENABLED(CONFIG_SYSRESET_WATCHDOG_AUTO) | |
72 | int sysreset_register_wdt(struct udevice *dev) | |
73 | { | |
74 | struct wdt_reboot_plat *plat = malloc(sizeof(*plat)); | |
75 | int ret; | |
76 | ||
77 | if (!plat) | |
78 | return -ENOMEM; | |
79 | ||
80 | plat->wdt = dev; | |
81 | ||
82 | ret = device_bind(dev, DM_DRIVER_GET(wdt_reboot), | |
83 | dev->name, plat, ofnode_null(), NULL); | |
84 | if (ret) { | |
85 | free(plat); | |
86 | return ret; | |
87 | } | |
88 | ||
89 | return 0; | |
90 | } | |
91 | #endif |