2 * Copyright (C) 2017 Masahiro Yamada <yamada.masahiro@socionext.com>
4 * Based on drivers/firmware/psci.c from Linux:
5 * Copyright (C) 2015 ARM Limited
7 * SPDX-License-Identifier: GPL-2.0+
14 #include <linux/arm-smccc.h>
15 #include <linux/errno.h>
16 #include <linux/psci.h>
18 psci_fn *invoke_psci_fn;
20 static unsigned long __invoke_psci_fn_hvc(unsigned long function_id,
21 unsigned long arg0, unsigned long arg1,
24 struct arm_smccc_res res;
26 arm_smccc_hvc(function_id, arg0, arg1, arg2, 0, 0, 0, 0, &res);
30 static unsigned long __invoke_psci_fn_smc(unsigned long function_id,
31 unsigned long arg0, unsigned long arg1,
34 struct arm_smccc_res res;
36 arm_smccc_smc(function_id, arg0, arg1, arg2, 0, 0, 0, 0, &res);
40 static int psci_bind(struct udevice *dev)
42 /* No SYSTEM_RESET support for PSCI 0.1 */
43 if (device_is_compatible(dev, "arm,psci-0.2") ||
44 device_is_compatible(dev, "arm,psci-1.0")) {
47 /* bind psci-sysreset optionally */
48 ret = device_bind_driver(dev, "psci-sysreset", "psci-sysreset",
51 debug("PSCI System Reset was not bound.\n");
57 static int psci_probe(struct udevice *dev)
59 DECLARE_GLOBAL_DATA_PTR;
62 method = fdt_stringlist_get(gd->fdt_blob, dev_of_offset(dev), "method",
65 printf("missing \"method\" property\n");
69 if (!strcmp("hvc", method)) {
70 invoke_psci_fn = __invoke_psci_fn_hvc;
71 } else if (!strcmp("smc", method)) {
72 invoke_psci_fn = __invoke_psci_fn_smc;
74 printf("invalid \"method\" property: %s\n", method);
81 static const struct udevice_id psci_of_match[] = {
82 { .compatible = "arm,psci" },
83 { .compatible = "arm,psci-0.2" },
84 { .compatible = "arm,psci-1.0" },
88 U_BOOT_DRIVER(psci) = {
90 .id = UCLASS_FIRMWARE,
91 .of_match = psci_of_match,