Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Masahiro Yamada | 573a381 | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | 573a381 | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | 4af0d7e | 2017-05-17 17:18:07 -0600 | [diff] [blame] | 6 | #include <common.h> |
Simon Glass | 9d92245 | 2017-05-17 17:18:03 -0600 | [diff] [blame] | 7 | #include <dm.h> |
Masahiro Yamada | 573a381 | 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 | 6326519 | 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 | 573a381 | 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 | 573a381 | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 19 | switch (type) { |
| 20 | case SYSRESET_WARM: |
| 21 | case SYSRESET_COLD: |
Igor Opaniuk | 91f00ba | 2021-04-01 02:01:54 +0300 | [diff] [blame] | 22 | psci_sys_reset(type); |
Masahiro Yamada | 573a381 | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 23 | break; |
Urja Rannikko | 857f39d | 2019-05-16 21:48:41 +0000 | [diff] [blame] | 24 | case SYSRESET_POWER_OFF: |
Igor Opaniuk | 91f00ba | 2021-04-01 02:01:54 +0300 | [diff] [blame] | 25 | psci_sys_poweroff(); |
Masahiro Yamada | 573a381 | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 26 | break; |
| 27 | default: |
| 28 | return -ENOSYS; |
| 29 | } |
| 30 | |
Masahiro Yamada | 573a381 | 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 | 6326519 | 2023-04-06 18:23:19 +0800 | [diff] [blame] | 36 | .get_status = psci_sysreset_get_status, |
Masahiro Yamada | 573a381 | 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 | 439b938 | 2023-04-06 18:23:18 +0800 | [diff] [blame] | 43 | .flags = DM_FLAG_PRE_RELOC, |
Masahiro Yamada | 573a381 | 2017-04-14 11:10:24 +0900 | [diff] [blame] | 44 | }; |