Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
maxims@google.com | f57bd00 | 2017-01-18 13:44:55 -0800 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2016 Google, Inc |
maxims@google.com | f57bd00 | 2017-01-18 13:44:55 -0800 | [diff] [blame] | 4 | */ |
| 5 | |
maxims@google.com | f57bd00 | 2017-01-18 13:44:55 -0800 | [diff] [blame] | 6 | #include <dm.h> |
| 7 | #include <errno.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
maxims@google.com | f57bd00 | 2017-01-18 13:44:55 -0800 | [diff] [blame] | 9 | #include <sysreset.h> |
maxims@google.com | 0fdb11a | 2017-04-17 12:00:26 -0700 | [diff] [blame] | 10 | #include <wdt.h> |
maxims@google.com | f57bd00 | 2017-01-18 13:44:55 -0800 | [diff] [blame] | 11 | #include <asm/io.h> |
| 12 | #include <asm/arch/wdt.h> |
| 13 | #include <linux/err.h> |
Chia-Wei, Wang | 8f7f490 | 2020-12-14 13:54:28 +0800 | [diff] [blame] | 14 | #include <hang.h> |
maxims@google.com | f57bd00 | 2017-01-18 13:44:55 -0800 | [diff] [blame] | 15 | |
maxims@google.com | f57bd00 | 2017-01-18 13:44:55 -0800 | [diff] [blame] | 16 | static int ast_sysreset_request(struct udevice *dev, enum sysreset_t type) |
| 17 | { |
maxims@google.com | 0fdb11a | 2017-04-17 12:00:26 -0700 | [diff] [blame] | 18 | struct udevice *wdt; |
| 19 | u32 reset_mode; |
Michal Suchanek | ac12a2f | 2022-10-12 21:57:59 +0200 | [diff] [blame] | 20 | int ret = uclass_first_device_err(UCLASS_WDT, &wdt); |
maxims@google.com | f57bd00 | 2017-01-18 13:44:55 -0800 | [diff] [blame] | 21 | |
maxims@google.com | 0fdb11a | 2017-04-17 12:00:26 -0700 | [diff] [blame] | 22 | if (ret) |
| 23 | return ret; |
maxims@google.com | f57bd00 | 2017-01-18 13:44:55 -0800 | [diff] [blame] | 24 | |
| 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, Wang | 8f7f490 | 2020-12-14 13:54:28 +0800 | [diff] [blame] | 36 | #if !defined(CONFIG_SPL_BUILD) |
maxims@google.com | 0fdb11a | 2017-04-17 12:00:26 -0700 | [diff] [blame] | 37 | ret = wdt_expire_now(wdt, reset_mode); |
| 38 | if (ret) { |
| 39 | debug("Sysreset failed: %d", ret); |
| 40 | return ret; |
| 41 | } |
Chia-Wei, Wang | 8f7f490 | 2020-12-14 13:54:28 +0800 | [diff] [blame] | 42 | #else |
| 43 | hang(); |
| 44 | #endif |
maxims@google.com | f57bd00 | 2017-01-18 13:44:55 -0800 | [diff] [blame] | 45 | |
| 46 | return -EINPROGRESS; |
| 47 | } |
| 48 | |
| 49 | static struct sysreset_ops ast_sysreset = { |
| 50 | .request = ast_sysreset_request, |
| 51 | }; |
| 52 | |
| 53 | U_BOOT_DRIVER(sysreset_ast) = { |
| 54 | .name = "ast_sysreset", |
| 55 | .id = UCLASS_SYSRESET, |
| 56 | .ops = &ast_sysreset, |
| 57 | }; |