blob: d747ed00a7f68aeae61484ffadaf84f5571a4b02 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
maxims@google.com4697abe2017-01-18 13:44:55 -08002/*
3 * (C) Copyright 2016 Google, Inc
maxims@google.com4697abe2017-01-18 13:44:55 -08004 */
5
6#include <common.h>
7#include <dm.h>
8#include <errno.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06009#include <log.h>
maxims@google.com4697abe2017-01-18 13:44:55 -080010#include <sysreset.h>
maxims@google.com99f8ad72017-04-17 12:00:26 -070011#include <wdt.h>
maxims@google.com4697abe2017-01-18 13:44:55 -080012#include <asm/io.h>
13#include <asm/arch/wdt.h>
14#include <linux/err.h>
Chia-Wei, Wang4a84cf02020-12-14 13:54:28 +080015#include <hang.h>
maxims@google.com4697abe2017-01-18 13:44:55 -080016
maxims@google.com4697abe2017-01-18 13:44:55 -080017static int ast_sysreset_request(struct udevice *dev, enum sysreset_t type)
18{
maxims@google.com99f8ad72017-04-17 12:00:26 -070019 struct udevice *wdt;
20 u32 reset_mode;
21 int ret = uclass_first_device(UCLASS_WDT, &wdt);
maxims@google.com4697abe2017-01-18 13:44:55 -080022
maxims@google.com99f8ad72017-04-17 12:00:26 -070023 if (ret)
24 return ret;
maxims@google.com4697abe2017-01-18 13:44:55 -080025
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
Chia-Wei, Wang4a84cf02020-12-14 13:54:28 +080037#if !defined(CONFIG_SPL_BUILD)
maxims@google.com99f8ad72017-04-17 12:00:26 -070038 ret = wdt_expire_now(wdt, reset_mode);
39 if (ret) {
40 debug("Sysreset failed: %d", ret);
41 return ret;
42 }
Chia-Wei, Wang4a84cf02020-12-14 13:54:28 +080043#else
44 hang();
45#endif
maxims@google.com4697abe2017-01-18 13:44:55 -080046
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};