Merge branch 'develop-3.10-next' of ssh://10.10.10.29/rk/kernel into develop-3.10...
[firefly-linux-kernel-4.4.55.git] / drivers / cpufreq / vexpress_big_little.c
1 /*
2  * Vexpress 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
22 #include <linux/cpufreq.h>
23 #include <linux/export.h>
24 #include <linux/opp.h>
25 #include <linux/module.h>
26 #include <linux/types.h>
27 #include <linux/vexpress.h>
28 #include "arm_big_little.h"
29
30 static int vexpress_init_opp_table(struct device *cpu_dev)
31 {
32         int i = -1, count, cluster = cpu_to_cluster(cpu_dev->id);
33         u32 *table;
34         int ret;
35
36         count = vexpress_spc_get_freq_table(cluster, &table);
37         if (!table || !count) {
38                 pr_err("SPC controller returned invalid freq table");
39                 return -EINVAL;
40         }
41
42         while (++i < count) {
43                 /* FIXME: Voltage value */
44                 ret = opp_add(cpu_dev, table[i] * 1000, 900000);
45                 if (ret) {
46                         dev_warn(cpu_dev, "%s: Failed to add OPP %d, err: %d\n",
47                                  __func__, table[i] * 1000, ret);
48                         return ret;
49                 }
50         }
51
52         return 0;
53 }
54
55 static int vexpress_get_transition_latency(struct device *cpu_dev)
56 {
57         /* 1 ms */
58         return 1000000;
59 }
60
61 static struct cpufreq_arm_bL_ops vexpress_bL_ops = {
62         .name   = "vexpress-bL",
63         .get_transition_latency = vexpress_get_transition_latency,
64         .init_opp_table = vexpress_init_opp_table,
65 };
66
67 static int vexpress_bL_init(void)
68 {
69         if (!vexpress_spc_check_loaded()) {
70                 pr_info("%s: No SPC found\n", __func__);
71                 return -ENOENT;
72         }
73
74         return bL_cpufreq_register(&vexpress_bL_ops);
75 }
76 module_init(vexpress_bL_init);
77
78 static void vexpress_bL_exit(void)
79 {
80         return bL_cpufreq_unregister(&vexpress_bL_ops);
81 }
82 module_exit(vexpress_bL_exit);
83
84 MODULE_AUTHOR("Viresh Kumar <viresh.kumar@linaro.org>");
85 MODULE_DESCRIPTION("ARM Vexpress big LITTLE cpufreq driver");
86 MODULE_LICENSE("GPL");