1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21
22#include <linux/cpufreq.h>
23#include <linux/device.h>
24#include <linux/export.h>
25#include <linux/module.h>
26#include <linux/of_device.h>
27#include <linux/pm_opp.h>
28#include <linux/platform_device.h>
29#include <linux/slab.h>
30#include <linux/types.h>
31#include "arm_big_little.h"
32
33
34static struct device_node *get_cpu_node_with_valid_op(int cpu)
35{
36 struct device_node *np = of_cpu_device_node_get(cpu);
37
38 if (!of_get_property(np, "operating-points", NULL)) {
39 of_node_put(np);
40 np = NULL;
41 }
42
43 return np;
44}
45
46static int dt_get_transition_latency(struct device *cpu_dev)
47{
48 struct device_node *np;
49 u32 transition_latency = CPUFREQ_ETERNAL;
50
51 np = of_node_get(cpu_dev->of_node);
52 if (!np) {
53 pr_info("Failed to find cpu node. Use CPUFREQ_ETERNAL transition latency\n");
54 return CPUFREQ_ETERNAL;
55 }
56
57 of_property_read_u32(np, "clock-latency", &transition_latency);
58 of_node_put(np);
59
60 pr_debug("%s: clock-latency: %d\n", __func__, transition_latency);
61 return transition_latency;
62}
63
64static const struct cpufreq_arm_bL_ops dt_bL_ops = {
65 .name = "dt-bl",
66 .get_transition_latency = dt_get_transition_latency,
67 .init_opp_table = dev_pm_opp_of_cpumask_add_table,
68 .free_opp_table = dev_pm_opp_of_cpumask_remove_table,
69};
70
71static int generic_bL_probe(struct platform_device *pdev)
72{
73 struct device_node *np;
74
75 np = get_cpu_node_with_valid_op(0);
76 if (!np)
77 return -ENODEV;
78
79 of_node_put(np);
80 return bL_cpufreq_register(&dt_bL_ops);
81}
82
83static int generic_bL_remove(struct platform_device *pdev)
84{
85 bL_cpufreq_unregister(&dt_bL_ops);
86 return 0;
87}
88
89static struct platform_driver generic_bL_platdrv = {
90 .driver = {
91 .name = "arm-bL-cpufreq-dt",
92 },
93 .probe = generic_bL_probe,
94 .remove = generic_bL_remove,
95};
96module_platform_driver(generic_bL_platdrv);
97
98MODULE_AUTHOR("Viresh Kumar <viresh.kumar@linaro.org>");
99MODULE_DESCRIPTION("Generic ARM big LITTLE cpufreq driver via DT");
100MODULE_LICENSE("GPL v2");
101