blob: ef09440bbeffa209ede9d70d595eca1a6154eb4d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
maxims@google.comf57bd002017-01-18 13:44:55 -08002/*
3 * (C) Copyright 2016 Google, Inc
maxims@google.comf57bd002017-01-18 13:44:55 -08004 */
5
maxims@google.comf57bd002017-01-18 13:44:55 -08006#include <dm.h>
7#include <errno.h>
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
maxims@google.comf57bd002017-01-18 13:44:55 -08009#include <sysreset.h>
maxims@google.com0fdb11a2017-04-17 12:00:26 -070010#include <wdt.h>
maxims@google.comf57bd002017-01-18 13:44:55 -080011#include <asm/io.h>
12#include <asm/arch/wdt.h>
13#include <linux/err.h>
Chia-Wei, Wang8f7f4902020-12-14 13:54:28 +080014#include <hang.h>
maxims@google.comf57bd002017-01-18 13:44:55 -080015
maxims@google.comf57bd002017-01-18 13:44:55 -080016static int ast_sysreset_request(struct udevice *dev, enum sysreset_t type)
17{
maxims@google.com0fdb11a2017-04-17 12:00:26 -070018 struct udevice *wdt;
19 u32 reset_mode;
Michal Suchanekac12a2f2022-10-12 21:57:59 +020020 int ret = uclass_first_device_err(UCLASS_WDT, &wdt);
maxims@google.comf57bd002017-01-18 13:44:55 -080021
maxims@google.com0fdb11a2017-04-17 12:00:26 -070022 if (ret)
23 return ret;
maxims@google.comf57bd002017-01-18 13:44:55 -080024
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
Chia-Wei, Wang8f7f4902020-12-14 13:54:28 +080036#if !defined(CONFIG_SPL_BUILD)
maxims@google.com0fdb11a2017-04-17 12:00:26 -070037 ret = wdt_expire_now(wdt, reset_mode);
38 if (ret) {
39 debug("Sysreset failed: %d", ret);
40 return ret;
41 }
Chia-Wei, Wang8f7f4902020-12-14 13:54:28 +080042#else
43 hang();
44#endif
maxims@google.comf57bd002017-01-18 13:44:55 -080045
46 return -EINPROGRESS;
47}
48
49static struct sysreset_ops ast_sysreset = {
50 .request = ast_sysreset_request,
51};
52
53U_BOOT_DRIVER(sysreset_ast) = {
54 .name = "ast_sysreset",
55 .id = UCLASS_SYSRESET,
56 .ops = &ast_sysreset,
57};