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