blob: a8a41528a849304ca8ecfb7e604332f06991a96e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Masahiro Yamada836c55d2017-04-14 11:10:24 +09002/*
3 * Copyright (C) 2017 Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamada836c55d2017-04-14 11:10:24 +09004 */
5
Simon Glass51a3ec32017-05-17 17:18:07 -06006#include <common.h>
Simon Glass11c89f32017-05-17 17:18:03 -06007#include <dm.h>
Masahiro Yamada836c55d2017-04-14 11:10:24 +09008#include <sysreset.h>
9#include <linux/errno.h>
10#include <linux/psci.h>
11
Peng Fan18bcd4a2023-04-06 18:23:19 +080012__weak int psci_sysreset_get_status(struct udevice *dev, char *buf, int size)
13{
14 return -EOPNOTSUPP;
15}
16
Masahiro Yamada836c55d2017-04-14 11:10:24 +090017static int psci_sysreset_request(struct udevice *dev, enum sysreset_t type)
18{
Masahiro Yamada836c55d2017-04-14 11:10:24 +090019 switch (type) {
20 case SYSRESET_WARM:
21 case SYSRESET_COLD:
Igor Opaniuk7999cfd2021-04-01 02:01:54 +030022 psci_sys_reset(type);
Masahiro Yamada836c55d2017-04-14 11:10:24 +090023 break;
Urja Rannikko25394e72019-05-16 21:48:41 +000024 case SYSRESET_POWER_OFF:
Igor Opaniuk7999cfd2021-04-01 02:01:54 +030025 psci_sys_poweroff();
Masahiro Yamada836c55d2017-04-14 11:10:24 +090026 break;
27 default:
28 return -ENOSYS;
29 }
30
Masahiro Yamada836c55d2017-04-14 11:10:24 +090031 return -EINPROGRESS;
32}
33
34static struct sysreset_ops psci_sysreset_ops = {
35 .request = psci_sysreset_request,
Peng Fan18bcd4a2023-04-06 18:23:19 +080036 .get_status = psci_sysreset_get_status,
Masahiro Yamada836c55d2017-04-14 11:10:24 +090037};
38
39U_BOOT_DRIVER(psci_sysreset) = {
40 .name = "psci-sysreset",
41 .id = UCLASS_SYSRESET,
42 .ops = &psci_sysreset_ops,
Peng Fanbd6980b2023-04-06 18:23:18 +080043 .flags = DM_FLAG_PRE_RELOC,
Masahiro Yamada836c55d2017-04-14 11:10:24 +090044};