xref: /OK3568_Linux_fs/u-boot/drivers/sysreset/sysreset_psci.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 
psci_sysreset_request(struct udevice * dev,enum sysreset_t type)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 /* Add an 'a_' prefix so it comes the first sysreset path. */
39 U_BOOT_DRIVER(a_psci_sysreset) = {
40 	.name = "psci-sysreset",
41 	.id = UCLASS_SYSRESET,
42 	.ops = &psci_sysreset_ops,
43 };
44