1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * (C) Copyright 2016 Google, Inc 4 */ 5 6 #include <common.h> 7 #include <dm.h> 8 #include <errno.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 15 static int ast_sysreset_request(struct udevice *dev, enum sysreset_t type) 16 { 17 struct udevice *wdt; 18 u32 reset_mode; 19 int ret = uclass_first_device(UCLASS_WDT, &wdt); 20 21 if (ret) 22 return ret; 23 24 switch (type) { 25 case SYSRESET_WARM: 26 reset_mode = WDT_CTRL_RESET_CPU; 27 break; 28 case SYSRESET_COLD: 29 reset_mode = WDT_CTRL_RESET_CHIP; 30 break; 31 default: 32 return -EPROTONOSUPPORT; 33 } 34 35 ret = wdt_expire_now(wdt, reset_mode); 36 if (ret) { 37 debug("Sysreset failed: %d", ret); 38 return ret; 39 } 40 41 return -EINPROGRESS; 42 } 43 44 static struct sysreset_ops ast_sysreset = { 45 .request = ast_sysreset_request, 46 }; 47 48 U_BOOT_DRIVER(sysreset_ast) = { 49 .name = "ast_sysreset", 50 .id = UCLASS_SYSRESET, 51 .ops = &ast_sysreset, 52 }; 53