blob: a8a41528a849304ca8ecfb7e604332f06991a96e [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Masahiro Yamada573a3812017-04-14 11:10:24 +09002/*
3 * Copyright (C) 2017 Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamada573a3812017-04-14 11:10:24 +09004 */
5
Simon Glass4af0d7e2017-05-17 17:18:07 -06006#include <common.h>
Simon Glass9d922452017-05-17 17:18:03 -06007#include <dm.h>
Masahiro Yamada573a3812017-04-14 11:10:24 +09008#include <sysreset.h>
9#include <linux/errno.h>
10#include <linux/psci.h>
11
Peng Fan63265192023-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 Yamada573a3812017-04-14 11:10:24 +090017static int psci_sysreset_request(struct udevice *dev, enum sysreset_t type)
18{
Masahiro Yamada573a3812017-04-14 11:10:24 +090019 switch (type) {
20 case SYSRESET_WARM:
21 case SYSRESET_COLD:
Igor Opaniuk91f00ba2021-04-01 02:01:54 +030022 psci_sys_reset(type);
Masahiro Yamada573a3812017-04-14 11:10:24 +090023 break;
Urja Rannikko857f39d2019-05-16 21:48:41 +000024 case SYSRESET_POWER_OFF:
Igor Opaniuk91f00ba2021-04-01 02:01:54 +030025 psci_sys_poweroff();
Masahiro Yamada573a3812017-04-14 11:10:24 +090026 break;
27 default:
28 return -ENOSYS;
29 }
30
Masahiro Yamada573a3812017-04-14 11:10:24 +090031 return -EINPROGRESS;
32}
33
34static struct sysreset_ops psci_sysreset_ops = {
35 .request = psci_sysreset_request,
Peng Fan63265192023-04-06 18:23:19 +080036 .get_status = psci_sysreset_get_status,
Masahiro Yamada573a3812017-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 Fan439b9382023-04-06 18:23:18 +080043 .flags = DM_FLAG_PRE_RELOC,
Masahiro Yamada573a3812017-04-14 11:10:24 +090044};