blob: 89b4f2dcaec41a61430c17ca7f2ba05918e07802 [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 Glass11c89f32017-05-17 17:18:03 -06006#include <dm.h>
Masahiro Yamada836c55d2017-04-14 11:10:24 +09007#include <sysreset.h>
8#include <linux/errno.h>
9#include <linux/psci.h>
10
Peng Fan18bcd4a2023-04-06 18:23:19 +080011__weak int psci_sysreset_get_status(struct udevice *dev, char *buf, int size)
12{
13 return -EOPNOTSUPP;
14}
15
Masahiro Yamada836c55d2017-04-14 11:10:24 +090016static int psci_sysreset_request(struct udevice *dev, enum sysreset_t type)
17{
Masahiro Yamada836c55d2017-04-14 11:10:24 +090018 switch (type) {
19 case SYSRESET_WARM:
20 case SYSRESET_COLD:
Igor Opaniuk7999cfd2021-04-01 02:01:54 +030021 psci_sys_reset(type);
Masahiro Yamada836c55d2017-04-14 11:10:24 +090022 break;
Urja Rannikko25394e72019-05-16 21:48:41 +000023 case SYSRESET_POWER_OFF:
Igor Opaniuk7999cfd2021-04-01 02:01:54 +030024 psci_sys_poweroff();
Masahiro Yamada836c55d2017-04-14 11:10:24 +090025 break;
26 default:
Paul Barkerbdb3a3f2023-11-08 08:51:10 +000027 return -EPROTONOSUPPORT;
Masahiro Yamada836c55d2017-04-14 11:10:24 +090028 }
29
Masahiro Yamada836c55d2017-04-14 11:10:24 +090030 return -EINPROGRESS;
31}
32
33static struct sysreset_ops psci_sysreset_ops = {
34 .request = psci_sysreset_request,
Peng Fan18bcd4a2023-04-06 18:23:19 +080035 .get_status = psci_sysreset_get_status,
Masahiro Yamada836c55d2017-04-14 11:10:24 +090036};
37
38U_BOOT_DRIVER(psci_sysreset) = {
39 .name = "psci-sysreset",
40 .id = UCLASS_SYSRESET,
41 .ops = &psci_sysreset_ops,
Peng Fanbd6980b2023-04-06 18:23:18 +080042 .flags = DM_FLAG_PRE_RELOC,
Masahiro Yamada836c55d2017-04-14 11:10:24 +090043};