Skip to content

Commit edeec42

Browse files
vireshkrafaeljw
authored andcommitted
cpufreq: dt-platdev: Automatically create cpufreq device with OPP v2
The initial idea of creating the cpufreq-dt-platdev.c file was to keep a list of platforms that use the "operating-points" (V1) bindings and create cpufreq device for them only, as we weren't sure which platforms would want the device to get created automatically as some had their own cpufreq drivers as well, or wanted to initialize cpufreq after doing some stuff from platform code. But that wasn't the case with platforms using "operating-points-v2" property. We wanted the device to get created automatically without the need of adding them to the whitelist. Though, we will still have some exceptions where we don't want to create the device automatically. Rename the earlier platform list as *whitelist* and create a new *blacklist* as well. The cpufreq-dt device will get created if: - The platform is there in the whitelist OR - The platform has "operating-points-v2" property in CPU0's DT node and isn't part of the blacklist . Reported-by: Geert Uytterhoeven <[email protected]> Signed-off-by: Viresh Kumar <[email protected]> Tested-by: Simon Horman <[email protected]> Reviewed-by: Masahiro Yamada <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent ec4259a commit edeec42

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

drivers/cpufreq/cpufreq-dt-platdev.c

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@
99

1010
#include <linux/err.h>
1111
#include <linux/of.h>
12+
#include <linux/of_device.h>
1213
#include <linux/platform_device.h>
1314

1415
#include "cpufreq-dt.h"
1516

16-
static const struct of_device_id machines[] __initconst = {
17+
/*
18+
* Machines for which the cpufreq device is *always* created, mostly used for
19+
* platforms using "operating-points" (V1) property.
20+
*/
21+
static const struct of_device_id whitelist[] __initconst = {
1722
{ .compatible = "allwinner,sun4i-a10", },
1823
{ .compatible = "allwinner,sun5i-a10s", },
1924
{ .compatible = "allwinner,sun5i-a13", },
@@ -107,21 +112,51 @@ static const struct of_device_id machines[] __initconst = {
107112
{ }
108113
};
109114

115+
/*
116+
* Machines for which the cpufreq device is *not* created, mostly used for
117+
* platforms using "operating-points-v2" property.
118+
*/
119+
static const struct of_device_id blacklist[] __initconst = {
120+
{ }
121+
};
122+
123+
static bool __init cpu0_node_has_opp_v2_prop(void)
124+
{
125+
struct device_node *np = of_cpu_device_node_get(0);
126+
bool ret = false;
127+
128+
if (of_get_property(np, "operating-points-v2", NULL))
129+
ret = true;
130+
131+
of_node_put(np);
132+
return ret;
133+
}
134+
110135
static int __init cpufreq_dt_platdev_init(void)
111136
{
112137
struct device_node *np = of_find_node_by_path("/");
113138
const struct of_device_id *match;
139+
const void *data = NULL;
114140

115141
if (!np)
116142
return -ENODEV;
117143

118-
match = of_match_node(machines, np);
144+
match = of_match_node(whitelist, np);
145+
if (match) {
146+
data = match->data;
147+
goto create_pdev;
148+
}
149+
150+
if (cpu0_node_has_opp_v2_prop() && !of_match_node(blacklist, np))
151+
goto create_pdev;
152+
119153
of_node_put(np);
120-
if (!match)
121-
return -ENODEV;
154+
return -ENODEV;
122155

156+
create_pdev:
157+
of_node_put(np);
123158
return PTR_ERR_OR_ZERO(platform_device_register_data(NULL, "cpufreq-dt",
124-
-1, match->data,
159+
-1, data,
125160
sizeof(struct cpufreq_dt_platform_data)));
126161
}
127162
device_initcall(cpufreq_dt_platdev_init);

0 commit comments

Comments
 (0)