183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0
2*dc35900fSChia-Wei, Wang // SPDX-License-Identifier: GPL-2.0
34697abeaSmaxims@google.com /*
4*dc35900fSChia-Wei, Wang  * Copyright (C) ASPEED Technology Inc.
5*dc35900fSChia-Wei, Wang  * Chia-Wei Wang <chiawei_wang@aspeedtech.com>
64697abeaSmaxims@google.com  */
74697abeaSmaxims@google.com 
84697abeaSmaxims@google.com #include <common.h>
94697abeaSmaxims@google.com #include <dm.h>
104697abeaSmaxims@google.com #include <errno.h>
114697abeaSmaxims@google.com #include <sysreset.h>
1299f8ad73Smaxims@google.com #include <wdt.h>
134697abeaSmaxims@google.com #include <asm/io.h>
144697abeaSmaxims@google.com #include <linux/err.h>
154697abeaSmaxims@google.com 
ast_sysreset_request(struct udevice * dev,enum sysreset_t type)164697abeaSmaxims@google.com static int ast_sysreset_request(struct udevice *dev, enum sysreset_t type)
174697abeaSmaxims@google.com {
1899f8ad73Smaxims@google.com 	struct udevice *wdt;
1999f8ad73Smaxims@google.com 	int ret = uclass_first_device(UCLASS_WDT, &wdt);
204697abeaSmaxims@google.com 
2199f8ad73Smaxims@google.com 	if (ret)
2299f8ad73Smaxims@google.com 		return ret;
234697abeaSmaxims@google.com 
24*dc35900fSChia-Wei, Wang 	ret = wdt_expire_now(wdt, 0);
2599f8ad73Smaxims@google.com 	if (ret) {
2699f8ad73Smaxims@google.com 		debug("Sysreset failed: %d", ret);
2799f8ad73Smaxims@google.com 		return ret;
2899f8ad73Smaxims@google.com 	}
294697abeaSmaxims@google.com 
304697abeaSmaxims@google.com 	return -EINPROGRESS;
314697abeaSmaxims@google.com }
324697abeaSmaxims@google.com 
334697abeaSmaxims@google.com static struct sysreset_ops ast_sysreset = {
344697abeaSmaxims@google.com 	.request	= ast_sysreset_request,
354697abeaSmaxims@google.com };
364697abeaSmaxims@google.com 
374697abeaSmaxims@google.com U_BOOT_DRIVER(sysreset_ast) = {
384697abeaSmaxims@google.com 	.name	= "ast_sysreset",
394697abeaSmaxims@google.com 	.id	= UCLASS_SYSRESET,
404697abeaSmaxims@google.com 	.ops	= &ast_sysreset,
414697abeaSmaxims@google.com };
42