summaryrefslogtreecommitdiffstats
path: root/arch/arm/cpu/psci-of.c
blob: ef83b0edee69c05b79735d69b9415a05359f8355 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: GPL-2.0

#define pr_fmt(fmt) "psci-of: " fmt

#include <common.h>
#include <of.h>
#include <asm/psci.h>
#include <linux/arm-smccc.h>

int of_psci_fixup(struct device_node *root, unsigned long psci_version)
{
	struct device_node *psci;
	int ret;
	const char *compat;
	struct device_node *cpus, *cpu;

	psci = of_create_node(root, "/psci");
	if (!psci)
		return -EINVAL;

	if (psci_version >= ARM_PSCI_VER_1_0) {
		compat = "arm,psci-1.0";
	} else if (psci_version >= ARM_PSCI_VER_0_2) {
		compat = "arm,psci-0.2";
	} else {
		pr_err("Unsupported PSCI version %ld\n", psci_version);
		return -EINVAL;
	}

	cpus = of_find_node_by_path_from(root, "/cpus");
	if (!cpus) {
		pr_err("Cannot find /cpus node, PSCI fixup aborting\n");
		return -EINVAL;
	}

	cpu = cpus;
	while (1) {
		cpu = of_find_node_by_type(cpu, "cpu");
		if (!cpu)
			break;
		of_property_write_string(cpu, "enable-method", "psci");
		pr_debug("Fixed %s\n", cpu->full_name);
	}

	ret = of_property_write_string(psci, "compatible", compat);
	if (ret)
		return ret;

	ret = of_property_write_string(psci, "method", "smc");
	if (ret)
		return ret;

	return 0;
}