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 | 11c89f3 | 2017-05-17 17:18:03 -0600 | [diff] [blame] | 6 | #include <dm.h> |
Masahiro Yamada | 836c55d | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 7 | #include <sysreset.h> |
| 8 | #include <linux/errno.h> |
| 9 | #include <linux/psci.h> |
| 10 | |
Peng Fan | 18bcd4a | 2023-04-06 18:23:19 +0800 | [diff] [blame] | 11 | __weak int psci_sysreset_get_status(struct udevice *dev, char *buf, int size) |
| 12 | { |
| 13 | return -EOPNOTSUPP; |
| 14 | } |
| 15 | |
Masahiro Yamada | 836c55d | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 16 | static int psci_sysreset_request(struct udevice *dev, enum sysreset_t type) |
| 17 | { |
Masahiro Yamada | 836c55d | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 18 | switch (type) { |
| 19 | case SYSRESET_WARM: |
| 20 | case SYSRESET_COLD: |
Igor Opaniuk | 7999cfd | 2021-04-01 02:01:54 +0300 | [diff] [blame] | 21 | psci_sys_reset(type); |
Masahiro Yamada | 836c55d | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 22 | break; |
Urja Rannikko | 25394e7 | 2019-05-16 21:48:41 +0000 | [diff] [blame] | 23 | case SYSRESET_POWER_OFF: |
Igor Opaniuk | 7999cfd | 2021-04-01 02:01:54 +0300 | [diff] [blame] | 24 | psci_sys_poweroff(); |
Masahiro Yamada | 836c55d | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 25 | break; |
| 26 | default: |
Paul Barker | bdb3a3f | 2023-11-08 08:51:10 +0000 | [diff] [blame] | 27 | return -EPROTONOSUPPORT; |
Masahiro Yamada | 836c55d | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 28 | } |
| 29 | |
Masahiro Yamada | 836c55d | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 30 | return -EINPROGRESS; |
| 31 | } |
| 32 | |
| 33 | static struct sysreset_ops psci_sysreset_ops = { |
| 34 | .request = psci_sysreset_request, |
Peng Fan | 18bcd4a | 2023-04-06 18:23:19 +0800 | [diff] [blame] | 35 | .get_status = psci_sysreset_get_status, |
Masahiro Yamada | 836c55d | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | U_BOOT_DRIVER(psci_sysreset) = { |
| 39 | .name = "psci-sysreset", |
| 40 | .id = UCLASS_SYSRESET, |
| 41 | .ops = &psci_sysreset_ops, |
Peng Fan | bd6980b | 2023-04-06 18:23:18 +0800 | [diff] [blame] | 42 | .flags = DM_FLAG_PRE_RELOC, |
Masahiro Yamada | 836c55d | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 43 | }; |