Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Masahiro Yamada | 836c55d | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | 836c55d | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | 51a3ec3 | 2017-05-17 17:18:07 -0600 | [diff] [blame] | 6 | #include <common.h> |
Simon Glass | 11c89f3 | 2017-05-17 17:18:03 -0600 | [diff] [blame] | 7 | #include <dm.h> |
Masahiro Yamada | 836c55d | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 8 | #include <sysreset.h> |
| 9 | #include <linux/errno.h> |
| 10 | #include <linux/psci.h> |
| 11 | |
Peng Fan | 18bcd4a | 2023-04-06 18:23:19 +0800 | [diff] [blame] | 12 | __weak int psci_sysreset_get_status(struct udevice *dev, char *buf, int size) |
| 13 | { |
| 14 | return -EOPNOTSUPP; |
| 15 | } |
| 16 | |
Masahiro Yamada | 836c55d | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 17 | static int psci_sysreset_request(struct udevice *dev, enum sysreset_t type) |
| 18 | { |
Masahiro Yamada | 836c55d | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 19 | switch (type) { |
| 20 | case SYSRESET_WARM: |
| 21 | case SYSRESET_COLD: |
Igor Opaniuk | 7999cfd | 2021-04-01 02:01:54 +0300 | [diff] [blame] | 22 | psci_sys_reset(type); |
Masahiro Yamada | 836c55d | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 23 | break; |
Urja Rannikko | 25394e7 | 2019-05-16 21:48:41 +0000 | [diff] [blame] | 24 | case SYSRESET_POWER_OFF: |
Igor Opaniuk | 7999cfd | 2021-04-01 02:01:54 +0300 | [diff] [blame] | 25 | psci_sys_poweroff(); |
Masahiro Yamada | 836c55d | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 26 | break; |
| 27 | default: |
| 28 | return -ENOSYS; |
| 29 | } |
| 30 | |
Masahiro Yamada | 836c55d | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 31 | return -EINPROGRESS; |
| 32 | } |
| 33 | |
| 34 | static struct sysreset_ops psci_sysreset_ops = { |
| 35 | .request = psci_sysreset_request, |
Peng Fan | 18bcd4a | 2023-04-06 18:23:19 +0800 | [diff] [blame] | 36 | .get_status = psci_sysreset_get_status, |
Masahiro Yamada | 836c55d | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | U_BOOT_DRIVER(psci_sysreset) = { |
| 40 | .name = "psci-sysreset", |
| 41 | .id = UCLASS_SYSRESET, |
| 42 | .ops = &psci_sysreset_ops, |
Peng Fan | bd6980b | 2023-04-06 18:23:18 +0800 | [diff] [blame] | 43 | .flags = DM_FLAG_PRE_RELOC, |
Masahiro Yamada | 836c55d | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 44 | }; |