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