mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-12-26 21:13:48 +00:00
88c4cbedfb
The watchdog system reset driver can reboot the device but it cannot power
it off. If power off is requested, the driver should not reset the system
but leave powering off to one of the other system reset drivers.
As power cycling is typically not a feature of a watchdog driver the reset
types SYSRESET_POWER and SYSRESET_POWER_OFF shall both be excluded.
Fixes: 17a0c14164
("dm: sysreset: add watchdog-reboot driver")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Stefan Roese <sr@denx.de>
90 lines
1.7 KiB
C
90 lines
1.7 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
|
|
*/
|
|
|
|
#include <common.h>
|
|
#include <dm.h>
|
|
#include <dm/device-internal.h>
|
|
#include <errno.h>
|
|
#include <malloc.h>
|
|
#include <sysreset.h>
|
|
#include <wdt.h>
|
|
|
|
struct wdt_reboot_plat {
|
|
struct udevice *wdt;
|
|
};
|
|
|
|
static int wdt_reboot_request(struct udevice *dev, enum sysreset_t type)
|
|
{
|
|
struct wdt_reboot_plat *plat = dev_get_plat(dev);
|
|
int ret;
|
|
|
|
switch (type) {
|
|
case SYSRESET_COLD:
|
|
case SYSRESET_WARM:
|
|
ret = wdt_expire_now(plat->wdt, 0);
|
|
if (ret)
|
|
return ret;
|
|
break;
|
|
default:
|
|
return -ENOSYS;
|
|
}
|
|
|
|
return -EINPROGRESS;
|
|
}
|
|
|
|
static struct sysreset_ops wdt_reboot_ops = {
|
|
.request = wdt_reboot_request,
|
|
};
|
|
|
|
static int wdt_reboot_of_to_plat(struct udevice *dev)
|
|
{
|
|
struct wdt_reboot_plat *plat = dev_get_plat(dev);
|
|
int err;
|
|
|
|
err = uclass_get_device_by_phandle(UCLASS_WDT, dev,
|
|
"wdt", &plat->wdt);
|
|
if (err) {
|
|
pr_err("unable to find wdt device\n");
|
|
return err;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct udevice_id wdt_reboot_ids[] = {
|
|
{ .compatible = "wdt-reboot" },
|
|
{ /* sentinel */ }
|
|
};
|
|
|
|
U_BOOT_DRIVER(wdt_reboot) = {
|
|
.name = "wdt_reboot",
|
|
.id = UCLASS_SYSRESET,
|
|
.of_match = wdt_reboot_ids,
|
|
.of_to_plat = wdt_reboot_of_to_plat,
|
|
.plat_auto = sizeof(struct wdt_reboot_plat),
|
|
.ops = &wdt_reboot_ops,
|
|
};
|
|
|
|
#if IS_ENABLED(CONFIG_SYSRESET_WATCHDOG_AUTO)
|
|
int sysreset_register_wdt(struct udevice *dev)
|
|
{
|
|
struct wdt_reboot_plat *plat = malloc(sizeof(*plat));
|
|
int ret;
|
|
|
|
if (!plat)
|
|
return -ENOMEM;
|
|
|
|
plat->wdt = dev;
|
|
|
|
ret = device_bind(dev, DM_DRIVER_GET(wdt_reboot),
|
|
dev->name, plat, ofnode_null(), NULL);
|
|
if (ret) {
|
|
free(plat);
|
|
return ret;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
#endif
|