blob: 27e2f45ccdd541f3d28e44d0035d70f1940ddf3c [file] [log] [blame]
Viresh Kumar8a67f0e2013-04-01 12:57:49 +00001/*
2 * Generic big.LITTLE CPUFreq Interface driver
3 *
4 * It provides necessary ops to arm_big_little cpufreq driver and gets
5 * Frequency information from Device Tree. Freq table in DT must be in KHz.
6 *
7 * Copyright (C) 2013 Linaro.
8 * Viresh Kumar <viresh.kumar@linaro.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
15 * kind, whether express or implied; without even the implied warranty
16 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */
19
20#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21
Viresh Kumar92a9b5c2013-05-17 11:25:11 +000022#include <linux/cpu.h>
Viresh Kumar8a67f0e2013-04-01 12:57:49 +000023#include <linux/cpufreq.h>
24#include <linux/device.h>
25#include <linux/export.h>
26#include <linux/module.h>
27#include <linux/of.h>
28#include <linux/opp.h>
29#include <linux/slab.h>
30#include <linux/types.h>
31#include "arm_big_little.h"
32
Viresh Kumar92a9b5c2013-05-17 11:25:11 +000033/* get cpu node with valid operating-points */
34static struct device_node *get_cpu_node_with_valid_op(int cpu)
Viresh Kumar8a67f0e2013-04-01 12:57:49 +000035{
Viresh Kumar92a9b5c2013-05-17 11:25:11 +000036 struct device_node *np = NULL, *parent;
Viresh Kumar8a67f0e2013-04-01 12:57:49 +000037 int count = 0;
38
Viresh Kumar763f8c32013-04-15 07:05:24 +000039 parent = of_find_node_by_path("/cpus");
40 if (!parent) {
Viresh Kumar92a9b5c2013-05-17 11:25:11 +000041 pr_err("failed to find OF /cpus\n");
42 return NULL;
Viresh Kumar763f8c32013-04-15 07:05:24 +000043 }
44
45 for_each_child_of_node(parent, np) {
Viresh Kumar92a9b5c2013-05-17 11:25:11 +000046 if (count++ != cpu)
Viresh Kumar8a67f0e2013-04-01 12:57:49 +000047 continue;
Viresh Kumar92a9b5c2013-05-17 11:25:11 +000048 if (!of_get_property(np, "operating-points", NULL)) {
49 of_node_put(np);
50 np = NULL;
51 }
Viresh Kumar8a67f0e2013-04-01 12:57:49 +000052
Viresh Kumar92a9b5c2013-05-17 11:25:11 +000053 break;
Viresh Kumar8a67f0e2013-04-01 12:57:49 +000054 }
55
Viresh Kumar92a9b5c2013-05-17 11:25:11 +000056 of_node_put(parent);
57 return np;
58}
59
60static int dt_init_opp_table(struct device *cpu_dev)
61{
62 struct device_node *np;
63 int ret;
64
65 np = get_cpu_node_with_valid_op(cpu_dev->id);
66 if (!np)
67 return -ENODATA;
68
69 cpu_dev->of_node = np;
70 ret = of_init_opp_table(cpu_dev);
71 of_node_put(np);
72
73 return ret;
74}
75
76static int dt_get_transition_latency(struct device *cpu_dev)
77{
78 struct device_node *np;
79 u32 transition_latency = CPUFREQ_ETERNAL;
80
81 np = get_cpu_node_with_valid_op(cpu_dev->id);
82 if (!np)
83 return CPUFREQ_ETERNAL;
84
85 of_property_read_u32(np, "clock-latency", &transition_latency);
86 of_node_put(np);
87
88 pr_debug("%s: clock-latency: %d\n", __func__, transition_latency);
89 return transition_latency;
Viresh Kumar8a67f0e2013-04-01 12:57:49 +000090}
91
92static struct cpufreq_arm_bL_ops dt_bL_ops = {
93 .name = "dt-bl",
94 .get_transition_latency = dt_get_transition_latency,
95 .init_opp_table = dt_init_opp_table,
96};
97
98static int generic_bL_init(void)
99{
Viresh Kumar92a9b5c2013-05-17 11:25:11 +0000100 struct device_node *np;
101
102 np = get_cpu_node_with_valid_op(0);
103 if (!np)
104 return -ENODEV;
105
106 of_node_put(np);
Viresh Kumar8a67f0e2013-04-01 12:57:49 +0000107 return bL_cpufreq_register(&dt_bL_ops);
108}
109module_init(generic_bL_init);
110
111static void generic_bL_exit(void)
112{
113 return bL_cpufreq_unregister(&dt_bL_ops);
114}
115module_exit(generic_bL_exit);
116
117MODULE_AUTHOR("Viresh Kumar <viresh.kumar@linaro.org>");
118MODULE_DESCRIPTION("Generic ARM big LITTLE cpufreq driver via DT");
119MODULE_LICENSE("GPL");