1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2017 Masahiro Yamada <yamada.masahiro@socionext.com>
4 */
5
6 #include <common.h>
7 #include <dm.h>
8 #include <sysreset.h>
9 #include <linux/errno.h>
10 #include <linux/psci.h>
11
psci_sysreset_get_status(struct udevice * dev,char * buf,int size)12 __weak int psci_sysreset_get_status(struct udevice *dev, char *buf, int size)
13 {
14 return -EOPNOTSUPP;
15 }
16
psci_sysreset_request(struct udevice * dev,enum sysreset_t type)17 static int psci_sysreset_request(struct udevice *dev, enum sysreset_t type)
18 {
19 switch (type) {
20 case SYSRESET_WARM:
21 case SYSRESET_COLD:
22 psci_sys_reset(type);
23 break;
24 case SYSRESET_POWER_OFF:
25 psci_sys_poweroff();
26 break;
27 default:
28 return -ENOSYS;
29 }
30
31 return -EINPROGRESS;
32 }
33
34 static struct sysreset_ops psci_sysreset_ops = {
35 .request = psci_sysreset_request,
36 .get_status = psci_sysreset_get_status,
37 };
38
39 U_BOOT_DRIVER(psci_sysreset) = {
40 .name = "psci-sysreset",
41 .id = UCLASS_SYSRESET,
42 .ops = &psci_sysreset_ops,
43 .flags = DM_FLAG_PRE_RELOC,
44 };
45