2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-05-16 16:29:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
2021-11-04 03:55:14 +00:00
|
|
|
#include <dm/device-internal.h>
|
2017-05-16 16:29:13 +00:00
|
|
|
#include <errno.h>
|
2021-11-04 03:55:14 +00:00
|
|
|
#include <malloc.h>
|
2017-05-16 16:29:13 +00:00
|
|
|
#include <sysreset.h>
|
|
|
|
#include <wdt.h>
|
|
|
|
|
2021-11-04 03:55:13 +00:00
|
|
|
struct wdt_reboot_plat {
|
2017-05-16 16:29:13 +00:00
|
|
|
struct udevice *wdt;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int wdt_reboot_request(struct udevice *dev, enum sysreset_t type)
|
|
|
|
{
|
2021-11-04 03:55:13 +00:00
|
|
|
struct wdt_reboot_plat *plat = dev_get_plat(dev);
|
2017-05-16 16:29:13 +00:00
|
|
|
int ret;
|
|
|
|
|
2021-11-04 09:31:17 +00:00
|
|
|
switch (type) {
|
|
|
|
case SYSRESET_COLD:
|
|
|
|
case SYSRESET_WARM:
|
|
|
|
ret = wdt_expire_now(plat->wdt, 0);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
2017-05-16 16:29:13 +00:00
|
|
|
|
|
|
|
return -EINPROGRESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sysreset_ops wdt_reboot_ops = {
|
|
|
|
.request = wdt_reboot_request,
|
|
|
|
};
|
|
|
|
|
2021-11-04 03:55:13 +00:00
|
|
|
static int wdt_reboot_of_to_plat(struct udevice *dev)
|
2017-05-16 16:29:13 +00:00
|
|
|
{
|
2021-11-04 03:55:13 +00:00
|
|
|
struct wdt_reboot_plat *plat = dev_get_plat(dev);
|
2017-05-16 16:29:13 +00:00
|
|
|
int err;
|
|
|
|
|
|
|
|
err = uclass_get_device_by_phandle(UCLASS_WDT, dev,
|
2021-11-04 03:55:13 +00:00
|
|
|
"wdt", &plat->wdt);
|
2017-05-16 16:29:13 +00:00
|
|
|
if (err) {
|
2017-09-16 05:10:41 +00:00
|
|
|
pr_err("unable to find wdt device\n");
|
2017-05-16 16:29:13 +00:00
|
|
|
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,
|
2021-11-04 03:55:13 +00:00
|
|
|
.of_to_plat = wdt_reboot_of_to_plat,
|
|
|
|
.plat_auto = sizeof(struct wdt_reboot_plat),
|
2017-05-16 16:29:13 +00:00
|
|
|
.ops = &wdt_reboot_ops,
|
|
|
|
};
|
2021-11-04 03:55:14 +00:00
|
|
|
|
|
|
|
#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
|