1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * (C) Copyright 2016 Google, Inc
4 */
5
6 #include <dm.h>
7 #include <errno.h>
8 #include <log.h>
9 #include <sysreset.h>
10 #include <wdt.h>
11 #include <asm/io.h>
12 #include <asm/arch/wdt.h>
13 #include <linux/err.h>
14 #include <hang.h>
15
ast_sysreset_request(struct udevice * dev,enum sysreset_t type)16 static int ast_sysreset_request(struct udevice *dev, enum sysreset_t type)
17 {
18 struct udevice *wdt;
19 u32 reset_mode;
20 int ret = uclass_first_device_err(UCLASS_WDT, &wdt);
21
22 if (ret)
23 return ret;
24
25 switch (type) {
26 case SYSRESET_WARM:
27 reset_mode = WDT_CTRL_RESET_CPU;
28 break;
29 case SYSRESET_COLD:
30 reset_mode = WDT_CTRL_RESET_CHIP;
31 break;
32 default:
33 return -EPROTONOSUPPORT;
34 }
35
36 #if !defined(CONFIG_XPL_BUILD)
37 ret = wdt_expire_now(wdt, reset_mode);
38 if (ret) {
39 debug("Sysreset failed: %d", ret);
40 return ret;
41 }
42 #else
43 hang();
44 #endif
45
46 return -EINPROGRESS;
47 }
48
49 static struct sysreset_ops ast_sysreset = {
50 .request = ast_sysreset_request,
51 };
52
53 U_BOOT_DRIVER(sysreset_ast) = {
54 .name = "ast_sysreset",
55 .id = UCLASS_SYSRESET,
56 .ops = &ast_sysreset,
57 };
58