blob: 39b3f51d9a30a971eebccc1e98c5d679ecafa500 [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
22#include <linux/cpufreq.h>
23#include <linux/device.h>
24#include <linux/export.h>
25#include <linux/module.h>
Sudeep KarkadaNageshada0eb142013-06-17 15:51:44 +010026#include <linux/of_device.h>
Nishanth Menone4db1c72013-09-19 16:03:52 -050027#include <linux/pm_opp.h>
Viresh Kumar9076eac2013-05-20 09:57:17 +053028#include <linux/platform_device.h>
Viresh Kumar8a67f0e2013-04-01 12:57:49 +000029#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{
Sudeep KarkadaNageshada0eb142013-06-17 15:51:44 +010036 struct device_node *np = of_cpu_device_node_get(cpu);
Viresh Kumar8a67f0e2013-04-01 12:57:49 +000037
Sudeep KarkadaNageshada0eb142013-06-17 15:51:44 +010038 if (!of_get_property(np, "operating-points", NULL)) {
39 of_node_put(np);
40 np = NULL;
Viresh Kumar763f8c32013-04-15 07:05:24 +000041 }
42
Viresh Kumar92a9b5c2013-05-17 11:25:11 +000043 return np;
44}
45
Viresh Kumar92a9b5c2013-05-17 11:25:11 +000046static int dt_get_transition_latency(struct device *cpu_dev)
47{
48 struct device_node *np;
49 u32 transition_latency = CPUFREQ_ETERNAL;
50
Sudeep KarkadaNageshada0eb142013-06-17 15:51:44 +010051 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");
Viresh Kumar92a9b5c2013-05-17 11:25:11 +000054 return CPUFREQ_ETERNAL;
Sudeep KarkadaNageshada0eb142013-06-17 15:51:44 +010055 }
Viresh Kumar92a9b5c2013-05-17 11:25:11 +000056
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;
Viresh Kumar8a67f0e2013-04-01 12:57:49 +000062}
63
64static struct cpufreq_arm_bL_ops dt_bL_ops = {
65 .name = "dt-bl",
66 .get_transition_latency = dt_get_transition_latency,
Sudeep Hollad9975b02016-05-03 15:05:05 +010067 .init_opp_table = dev_pm_opp_of_cpumask_add_table,
68 .free_opp_table = dev_pm_opp_of_cpumask_remove_table,
Viresh Kumar8a67f0e2013-04-01 12:57:49 +000069};
70
Viresh Kumar9076eac2013-05-20 09:57:17 +053071static int generic_bL_probe(struct platform_device *pdev)
Viresh Kumar8a67f0e2013-04-01 12:57:49 +000072{
Viresh Kumar92a9b5c2013-05-17 11:25:11 +000073 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);
Viresh Kumar8a67f0e2013-04-01 12:57:49 +000080 return bL_cpufreq_register(&dt_bL_ops);
81}
Viresh Kumar8a67f0e2013-04-01 12:57:49 +000082
Viresh Kumar9076eac2013-05-20 09:57:17 +053083static int generic_bL_remove(struct platform_device *pdev)
Viresh Kumar8a67f0e2013-04-01 12:57:49 +000084{
Viresh Kumar9076eac2013-05-20 09:57:17 +053085 bL_cpufreq_unregister(&dt_bL_ops);
86 return 0;
Viresh Kumar8a67f0e2013-04-01 12:57:49 +000087}
Viresh Kumar9076eac2013-05-20 09:57:17 +053088
89static struct platform_driver generic_bL_platdrv = {
90 .driver = {
91 .name = "arm-bL-cpufreq-dt",
Viresh Kumar9076eac2013-05-20 09:57:17 +053092 },
93 .probe = generic_bL_probe,
94 .remove = generic_bL_remove,
95};
96module_platform_driver(generic_bL_platdrv);
Viresh Kumar8a67f0e2013-04-01 12:57:49 +000097
98MODULE_AUTHOR("Viresh Kumar <viresh.kumar@linaro.org>");
99MODULE_DESCRIPTION("Generic ARM big LITTLE cpufreq driver via DT");
Uwe Kleine-König39c8bba2014-08-08 08:56:30 +0200100MODULE_LICENSE("GPL v2");