a4911b7d8fff3b731b56c26d2b448a33bdbb17e0
[oweals/u-boot.git] / drivers / sysreset / sysreset_psci.c
1 /*
2  * Copyright (C) 2017 Masahiro Yamada <yamada.masahiro@socionext.com>
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6
7 #include <dm/device.h>
8 #include <sysreset.h>
9 #include <linux/errno.h>
10 #include <linux/psci.h>
11
12 static int psci_sysreset_request(struct udevice *dev, enum sysreset_t type)
13 {
14         unsigned long function_id;
15
16         switch (type) {
17         case SYSRESET_WARM:
18         case SYSRESET_COLD:
19                 function_id = PSCI_0_2_FN_SYSTEM_RESET;
20                 break;
21         case SYSRESET_POWER:
22                 function_id = PSCI_0_2_FN_SYSTEM_OFF;
23                 break;
24         default:
25                 return -ENOSYS;
26         }
27
28         invoke_psci_fn(function_id, 0, 0, 0);
29
30         return -EINPROGRESS;
31 }
32
33 static struct sysreset_ops psci_sysreset_ops = {
34         .request = psci_sysreset_request,
35 };
36
37 U_BOOT_DRIVER(psci_sysreset) = {
38         .name = "psci-sysreset",
39         .id = UCLASS_SYSRESET,
40         .ops = &psci_sysreset_ops,
41 };