14697abeaSmaxims@google.com /* 24697abeaSmaxims@google.com * (C) Copyright 2016 Google, Inc 34697abeaSmaxims@google.com * 44697abeaSmaxims@google.com * SPDX-License-Identifier: GPL-2.0 54697abeaSmaxims@google.com */ 64697abeaSmaxims@google.com 74697abeaSmaxims@google.com #include <common.h> 84697abeaSmaxims@google.com #include <dm.h> 94697abeaSmaxims@google.com #include <errno.h> 104697abeaSmaxims@google.com #include <sysreset.h> 11*99f8ad73Smaxims@google.com #include <wdt.h> 124697abeaSmaxims@google.com #include <asm/io.h> 134697abeaSmaxims@google.com #include <asm/arch/wdt.h> 144697abeaSmaxims@google.com #include <linux/err.h> 154697abeaSmaxims@google.com 164697abeaSmaxims@google.com static int ast_sysreset_request(struct udevice *dev, enum sysreset_t type) 174697abeaSmaxims@google.com { 18*99f8ad73Smaxims@google.com struct udevice *wdt; 19*99f8ad73Smaxims@google.com u32 reset_mode; 20*99f8ad73Smaxims@google.com int ret = uclass_first_device(UCLASS_WDT, &wdt); 214697abeaSmaxims@google.com 22*99f8ad73Smaxims@google.com if (ret) 23*99f8ad73Smaxims@google.com return ret; 244697abeaSmaxims@google.com 254697abeaSmaxims@google.com switch (type) { 264697abeaSmaxims@google.com case SYSRESET_WARM: 274697abeaSmaxims@google.com reset_mode = WDT_CTRL_RESET_CPU; 284697abeaSmaxims@google.com break; 294697abeaSmaxims@google.com case SYSRESET_COLD: 304697abeaSmaxims@google.com reset_mode = WDT_CTRL_RESET_CHIP; 314697abeaSmaxims@google.com break; 324697abeaSmaxims@google.com default: 334697abeaSmaxims@google.com return -EPROTONOSUPPORT; 344697abeaSmaxims@google.com } 354697abeaSmaxims@google.com 36*99f8ad73Smaxims@google.com ret = wdt_expire_now(wdt, reset_mode); 37*99f8ad73Smaxims@google.com if (ret) { 38*99f8ad73Smaxims@google.com debug("Sysreset failed: %d", ret); 39*99f8ad73Smaxims@google.com return ret; 40*99f8ad73Smaxims@google.com } 414697abeaSmaxims@google.com 424697abeaSmaxims@google.com return -EINPROGRESS; 434697abeaSmaxims@google.com } 444697abeaSmaxims@google.com 454697abeaSmaxims@google.com static struct sysreset_ops ast_sysreset = { 464697abeaSmaxims@google.com .request = ast_sysreset_request, 474697abeaSmaxims@google.com }; 484697abeaSmaxims@google.com 494697abeaSmaxims@google.com U_BOOT_DRIVER(sysreset_ast) = { 504697abeaSmaxims@google.com .name = "ast_sysreset", 514697abeaSmaxims@google.com .id = UCLASS_SYSRESET, 524697abeaSmaxims@google.com .ops = &ast_sysreset, 534697abeaSmaxims@google.com }; 54