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