diff options
| author | Viresh Kumar <viresh.kumar@linaro.org> | 2013-04-01 08:57:49 -0400 |
|---|---|---|
| committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-04-02 09:26:32 -0400 |
| commit | 8a67f0ef2b684b34162d39e8f436fe39e9635a19 (patch) | |
| tree | dc997ac3064c69e775485213b824e7c3efeb5b99 /drivers | |
| parent | eb2f50ff93f08c8001d0d7e1148948ba80989aaf (diff) | |
cpufreq: ARM big LITTLE: Add generic cpufreq driver and its DT glue
big LITTLE is ARM's new Architecture focussing power/performance needs of modern
world. More information about big LITTLE can be found here:
http://www.arm.com/products/processors/technologies/biglittleprocessing.php
http://lwn.net/Articles/481055/
In order to keep cpufreq support for all big LITTLE platforms simple/generic,
this patch tries to add a generic cpufreq driver layer for all big LITTLE
platforms.
The driver is divided into two parts:
- Core driver: Generic and shared across all big LITTLE SoC's
- Glue drivers: Per platform drivers providing ops to the core driver
This patch adds in a generic glue driver which would extract information from
Device Tree.
Future SoC's can either reuse the DT glue or write their own depending on the
need.
Signed-off-by: Sudeep KarkadaNagesha <sudeep.karkadanagesha@arm.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/cpufreq/Kconfig.arm | 12 | ||||
| -rw-r--r-- | drivers/cpufreq/Makefile | 5 | ||||
| -rw-r--r-- | drivers/cpufreq/arm_big_little.c | 282 | ||||
| -rw-r--r-- | drivers/cpufreq/arm_big_little.h | 40 | ||||
| -rw-r--r-- | drivers/cpufreq/arm_big_little_dt.c | 92 |
5 files changed, 431 insertions, 0 deletions
diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm index 030ddf6dd3f1..87b7e48698d0 100644 --- a/drivers/cpufreq/Kconfig.arm +++ b/drivers/cpufreq/Kconfig.arm | |||
| @@ -2,6 +2,18 @@ | |||
| 2 | # ARM CPU Frequency scaling drivers | 2 | # ARM CPU Frequency scaling drivers |
| 3 | # | 3 | # |
| 4 | 4 | ||
| 5 | config ARM_BIG_LITTLE_CPUFREQ | ||
| 6 | tristate | ||
| 7 | depends on ARM_CPU_TOPOLOGY | ||
| 8 | |||
| 9 | config ARM_DT_BL_CPUFREQ | ||
| 10 | tristate "Generic ARM big LITTLE CPUfreq driver probed via DT" | ||
| 11 | select ARM_BIG_LITTLE_CPUFREQ | ||
| 12 | depends on OF && HAVE_CLK | ||
| 13 | help | ||
| 14 | This enables the Generic CPUfreq driver for ARM big.LITTLE platform. | ||
| 15 | This gets frequency tables from DT. | ||
| 16 | |||
| 5 | config ARM_OMAP2PLUS_CPUFREQ | 17 | config ARM_OMAP2PLUS_CPUFREQ |
| 6 | bool "TI OMAP2+" | 18 | bool "TI OMAP2+" |
| 7 | depends on ARCH_OMAP2PLUS | 19 | depends on ARCH_OMAP2PLUS |
diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile index 863fd1865d45..ba9a3e1b1e69 100644 --- a/drivers/cpufreq/Makefile +++ b/drivers/cpufreq/Makefile | |||
| @@ -44,6 +44,11 @@ obj-$(CONFIG_X86_INTEL_PSTATE) += intel_pstate.o | |||
| 44 | 44 | ||
| 45 | ################################################################################## | 45 | ################################################################################## |
| 46 | # ARM SoC drivers | 46 | # ARM SoC drivers |
| 47 | obj-$(CONFIG_ARM_BIG_LITTLE_CPUFREQ) += arm_big_little.o | ||
| 48 | # big LITTLE per platform glues. Keep DT_BL_CPUFREQ as the last entry in all big | ||
| 49 | # LITTLE drivers, so that it is probed last. | ||
| 50 | obj-$(CONFIG_ARM_DT_BL_CPUFREQ) += arm_big_little_dt.o | ||
| 51 | |||
| 47 | obj-$(CONFIG_UX500_SOC_DB8500) += dbx500-cpufreq.o | 52 | obj-$(CONFIG_UX500_SOC_DB8500) += dbx500-cpufreq.o |
| 48 | obj-$(CONFIG_ARM_S3C2416_CPUFREQ) += s3c2416-cpufreq.o | 53 | obj-$(CONFIG_ARM_S3C2416_CPUFREQ) += s3c2416-cpufreq.o |
| 49 | obj-$(CONFIG_ARM_S3C64XX_CPUFREQ) += s3c64xx-cpufreq.o | 54 | obj-$(CONFIG_ARM_S3C64XX_CPUFREQ) += s3c64xx-cpufreq.o |
diff --git a/drivers/cpufreq/arm_big_little.c b/drivers/cpufreq/arm_big_little.c new file mode 100644 index 000000000000..1d29d1acbda7 --- /dev/null +++ b/drivers/cpufreq/arm_big_little.c | |||
| @@ -0,0 +1,282 @@ | |||
| 1 | /* | ||
| 2 | * ARM big.LITTLE Platforms CPUFreq support | ||
| 3 | * | ||
| 4 | * Copyright (C) 2013 ARM Ltd. | ||
| 5 | * Sudeep KarkadaNagesha <sudeep.karkadanagesha@arm.com> | ||
| 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/clk.h> | ||
| 23 | #include <linux/cpu.h> | ||
| 24 | #include <linux/cpufreq.h> | ||
| 25 | #include <linux/cpumask.h> | ||
| 26 | #include <linux/export.h> | ||
| 27 | #include <linux/of_platform.h> | ||
| 28 | #include <linux/opp.h> | ||
| 29 | #include <linux/slab.h> | ||
| 30 | #include <linux/topology.h> | ||
| 31 | #include <linux/types.h> | ||
| 32 | |||
| 33 | #include "arm_big_little.h" | ||
| 34 | |||
| 35 | /* Currently we support only two clusters */ | ||
| 36 | #define MAX_CLUSTERS 2 | ||
| 37 | |||
| 38 | static struct cpufreq_arm_bL_ops *arm_bL_ops; | ||
| 39 | static struct clk *clk[MAX_CLUSTERS]; | ||
| 40 | static struct cpufreq_frequency_table *freq_table[MAX_CLUSTERS]; | ||
| 41 | static atomic_t cluster_usage[MAX_CLUSTERS] = {ATOMIC_INIT(0), ATOMIC_INIT(0)}; | ||
| 42 | |||
| 43 | static int cpu_to_cluster(int cpu) | ||
| 44 | { | ||
| 45 | return topology_physical_package_id(cpu); | ||
| 46 | } | ||
| 47 | |||
| 48 | static unsigned int bL_cpufreq_get(unsigned int cpu) | ||
| 49 | { | ||
| 50 | u32 cur_cluster = cpu_to_cluster(cpu); | ||
| 51 | |||
| 52 | return clk_get_rate(clk[cur_cluster]) / 1000; | ||
| 53 | } | ||
| 54 | |||
| 55 | /* Validate policy frequency range */ | ||
| 56 | static int bL_cpufreq_verify_policy(struct cpufreq_policy *policy) | ||
| 57 | { | ||
| 58 | u32 cur_cluster = cpu_to_cluster(policy->cpu); | ||
| 59 | |||
| 60 | return cpufreq_frequency_table_verify(policy, freq_table[cur_cluster]); | ||
| 61 | } | ||
| 62 | |||
| 63 | /* Set clock frequency */ | ||
| 64 | static int bL_cpufreq_set_target(struct cpufreq_policy *policy, | ||
| 65 | unsigned int target_freq, unsigned int relation) | ||
| 66 | { | ||
| 67 | struct cpufreq_freqs freqs; | ||
| 68 | u32 cpu = policy->cpu, freq_tab_idx, cur_cluster; | ||
| 69 | int ret = 0; | ||
| 70 | |||
| 71 | cur_cluster = cpu_to_cluster(policy->cpu); | ||
| 72 | |||
| 73 | freqs.old = bL_cpufreq_get(policy->cpu); | ||
| 74 | |||
| 75 | /* Determine valid target frequency using freq_table */ | ||
| 76 | cpufreq_frequency_table_target(policy, freq_table[cur_cluster], | ||
| 77 | target_freq, relation, &freq_tab_idx); | ||
| 78 | freqs.new = freq_table[cur_cluster][freq_tab_idx].frequency; | ||
| 79 | |||
| 80 | freqs.cpu = policy->cpu; | ||
| 81 | |||
| 82 | pr_debug("%s: cpu: %d, cluster: %d, oldfreq: %d, target freq: %d, new freq: %d\n", | ||
| 83 | __func__, cpu, cur_cluster, freqs.old, target_freq, | ||
| 84 | freqs.new); | ||
| 85 | |||
| 86 | if (freqs.old == freqs.new) | ||
| 87 | return 0; | ||
| 88 | |||
| 89 | for_each_cpu(freqs.cpu, policy->cpus) | ||
| 90 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
| 91 | |||
| 92 | ret = clk_set_rate(clk[cur_cluster], freqs.new * 1000); | ||
| 93 | if (ret) { | ||
| 94 | pr_err("clk_set_rate failed: %d\n", ret); | ||
| 95 | return ret; | ||
| 96 | } | ||
| 97 | |||
| 98 | policy->cur = freqs.new; | ||
| 99 | |||
| 100 | for_each_cpu(freqs.cpu, policy->cpus) | ||
| 101 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
| 102 | |||
| 103 | return ret; | ||
| 104 | } | ||
| 105 | |||
| 106 | static void put_cluster_clk_and_freq_table(struct device *cpu_dev) | ||
| 107 | { | ||
| 108 | u32 cluster = cpu_to_cluster(cpu_dev->id); | ||
| 109 | |||
| 110 | if (!atomic_dec_return(&cluster_usage[cluster])) { | ||
| 111 | clk_put(clk[cluster]); | ||
| 112 | opp_free_cpufreq_table(cpu_dev, &freq_table[cluster]); | ||
| 113 | dev_dbg(cpu_dev, "%s: cluster: %d\n", __func__, cluster); | ||
| 114 | } | ||
| 115 | } | ||
| 116 | |||
| 117 | static int get_cluster_clk_and_freq_table(struct device *cpu_dev) | ||
| 118 | { | ||
| 119 | u32 cluster = cpu_to_cluster(cpu_dev->id); | ||
| 120 | char name[14] = "cpu-cluster."; | ||
| 121 | int ret; | ||
| 122 | |||
| 123 | if (atomic_inc_return(&cluster_usage[cluster]) != 1) | ||
| 124 | return 0; | ||
| 125 | |||
| 126 | ret = arm_bL_ops->init_opp_table(cpu_dev); | ||
| 127 | if (ret) { | ||
| 128 | dev_err(cpu_dev, "%s: init_opp_table failed, cpu: %d, err: %d\n", | ||
| 129 | __func__, cpu_dev->id, ret); | ||
| 130 | goto atomic_dec; | ||
| 131 | } | ||
| 132 | |||
| 133 | ret = opp_init_cpufreq_table(cpu_dev, &freq_table[cluster]); | ||
| 134 | if (ret) { | ||
| 135 | dev_err(cpu_dev, "%s: failed to init cpufreq table, cpu: %d, err: %d\n", | ||
| 136 | __func__, cpu_dev->id, ret); | ||
| 137 | goto atomic_dec; | ||
| 138 | } | ||
| 139 | |||
| 140 | name[12] = cluster + '0'; | ||
| 141 | clk[cluster] = clk_get_sys(name, NULL); | ||
| 142 | if (!IS_ERR(clk[cluster])) { | ||
| 143 | dev_dbg(cpu_dev, "%s: clk: %p & freq table: %p, cluster: %d\n", | ||
| 144 | __func__, clk[cluster], freq_table[cluster], | ||
| 145 | cluster); | ||
| 146 | return 0; | ||
| 147 | } | ||
| 148 | |||
| 149 | dev_err(cpu_dev, "%s: Failed to get clk for cpu: %d, cluster: %d\n", | ||
| 150 | __func__, cpu_dev->id, cluster); | ||
| 151 | ret = PTR_ERR(clk[cluster]); | ||
| 152 | opp_free_cpufreq_table(cpu_dev, &freq_table[cluster]); | ||
| 153 | |||
| 154 | atomic_dec: | ||
| 155 | atomic_dec(&cluster_usage[cluster]); | ||
| 156 | dev_err(cpu_dev, "%s: Failed to get data for cluster: %d\n", __func__, | ||
| 157 | cluster); | ||
| 158 | return ret; | ||
| 159 | } | ||
| 160 | |||
| 161 | /* Per-CPU initialization */ | ||
| 162 | static int bL_cpufreq_init(struct cpufreq_policy *policy) | ||
| 163 | { | ||
| 164 | u32 cur_cluster = cpu_to_cluster(policy->cpu); | ||
| 165 | struct device *cpu_dev; | ||
| 166 | int ret; | ||
| 167 | |||
| 168 | cpu_dev = get_cpu_device(policy->cpu); | ||
| 169 | if (!cpu_dev) { | ||
| 170 | pr_err("%s: failed to get cpu%d device\n", __func__, | ||
| 171 | policy->cpu); | ||
| 172 | return -ENODEV; | ||
| 173 | } | ||
| 174 | |||
| 175 | ret = get_cluster_clk_and_freq_table(cpu_dev); | ||
| 176 | if (ret) | ||
| 177 | return ret; | ||
| 178 | |||
| 179 | ret = cpufreq_frequency_table_cpuinfo(policy, freq_table[cur_cluster]); | ||
| 180 | if (ret) { | ||
| 181 | dev_err(cpu_dev, "CPU %d, cluster: %d invalid freq table\n", | ||
| 182 | policy->cpu, cur_cluster); | ||
| 183 | put_cluster_clk_and_freq_table(cpu_dev); | ||
| 184 | return ret; | ||
| 185 | } | ||
| 186 | |||
| 187 | cpufreq_frequency_table_get_attr(freq_table[cur_cluster], policy->cpu); | ||
| 188 | |||
| 189 | if (arm_bL_ops->get_transition_latency) | ||
| 190 | policy->cpuinfo.transition_latency = | ||
| 191 | arm_bL_ops->get_transition_latency(cpu_dev); | ||
| 192 | else | ||
| 193 | policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; | ||
| 194 | |||
| 195 | policy->cur = bL_cpufreq_get(policy->cpu); | ||
| 196 | |||
| 197 | cpumask_copy(policy->cpus, topology_core_cpumask(policy->cpu)); | ||
| 198 | |||
| 199 | dev_info(cpu_dev, "CPU %d initialized\n", policy->cpu); | ||
| 200 | return 0; | ||
| 201 | } | ||
| 202 | |||
| 203 | static int bL_cpufreq_exit(struct cpufreq_policy *policy) | ||
| 204 | { | ||
| 205 | struct device *cpu_dev; | ||
| 206 | |||
| 207 | cpu_dev = get_cpu_device(policy->cpu); | ||
| 208 | if (!cpu_dev) { | ||
| 209 | pr_err("%s: failed to get cpu%d device\n", __func__, | ||
| 210 | policy->cpu); | ||
| 211 | return -ENODEV; | ||
| 212 | } | ||
| 213 | |||
| 214 | put_cluster_clk_and_freq_table(cpu_dev); | ||
| 215 | dev_dbg(cpu_dev, "%s: Exited, cpu: %d\n", __func__, policy->cpu); | ||
| 216 | |||
| 217 | return 0; | ||
| 218 | } | ||
| 219 | |||
| 220 | /* Export freq_table to sysfs */ | ||
| 221 | static struct freq_attr *bL_cpufreq_attr[] = { | ||
| 222 | &cpufreq_freq_attr_scaling_available_freqs, | ||
| 223 | NULL, | ||
| 224 | }; | ||
| 225 | |||
| 226 | static struct cpufreq_driver bL_cpufreq_driver = { | ||
| 227 | .name = "arm-big-little", | ||
| 228 | .flags = CPUFREQ_STICKY, | ||
| 229 | .verify = bL_cpufreq_verify_policy, | ||
| 230 | .target = bL_cpufreq_set_target, | ||
| 231 | .get = bL_cpufreq_get, | ||
| 232 | .init = bL_cpufreq_init, | ||
| 233 | .exit = bL_cpufreq_exit, | ||
| 234 | .have_multiple_policies = true, | ||
| 235 | .attr = bL_cpufreq_attr, | ||
| 236 | }; | ||
| 237 | |||
| 238 | int bL_cpufreq_register(struct cpufreq_arm_bL_ops *ops) | ||
| 239 | { | ||
| 240 | int ret; | ||
| 241 | |||
| 242 | if (arm_bL_ops) { | ||
| 243 | pr_debug("%s: Already registered: %s, exiting\n", __func__, | ||
| 244 | arm_bL_ops->name); | ||
| 245 | return -EBUSY; | ||
| 246 | } | ||
| 247 | |||
| 248 | if (!ops || !strlen(ops->name) || !ops->init_opp_table) { | ||
| 249 | pr_err("%s: Invalid arm_bL_ops, exiting\n", __func__); | ||
| 250 | return -ENODEV; | ||
| 251 | } | ||
| 252 | |||
| 253 | arm_bL_ops = ops; | ||
| 254 | |||
| 255 | ret = cpufreq_register_driver(&bL_cpufreq_driver); | ||
| 256 | if (ret) { | ||
| 257 | pr_info("%s: Failed registering platform driver: %s, err: %d\n", | ||
| 258 | __func__, ops->name, ret); | ||
| 259 | arm_bL_ops = NULL; | ||
| 260 | } else { | ||
| 261 | pr_info("%s: Registered platform driver: %s\n", __func__, | ||
| 262 | ops->name); | ||
| 263 | } | ||
| 264 | |||
| 265 | return ret; | ||
| 266 | } | ||
| 267 | EXPORT_SYMBOL_GPL(bL_cpufreq_register); | ||
| 268 | |||
| 269 | void bL_cpufreq_unregister(struct cpufreq_arm_bL_ops *ops) | ||
| 270 | { | ||
| 271 | if (arm_bL_ops != ops) { | ||
| 272 | pr_err("%s: Registered with: %s, can't unregister, exiting\n", | ||
| 273 | __func__, arm_bL_ops->name); | ||
| 274 | return; | ||
| 275 | } | ||
| 276 | |||
| 277 | cpufreq_unregister_driver(&bL_cpufreq_driver); | ||
| 278 | pr_info("%s: Un-registered platform driver: %s\n", __func__, | ||
| 279 | arm_bL_ops->name); | ||
| 280 | arm_bL_ops = NULL; | ||
| 281 | } | ||
| 282 | EXPORT_SYMBOL_GPL(bL_cpufreq_unregister); | ||
diff --git a/drivers/cpufreq/arm_big_little.h b/drivers/cpufreq/arm_big_little.h new file mode 100644 index 000000000000..70f18fc12d4a --- /dev/null +++ b/drivers/cpufreq/arm_big_little.h | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | /* | ||
| 2 | * ARM big.LITTLE platform's CPUFreq header file | ||
| 3 | * | ||
| 4 | * Copyright (C) 2013 ARM Ltd. | ||
| 5 | * Sudeep KarkadaNagesha <sudeep.karkadanagesha@arm.com> | ||
| 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 | #ifndef CPUFREQ_ARM_BIG_LITTLE_H | ||
| 20 | #define CPUFREQ_ARM_BIG_LITTLE_H | ||
| 21 | |||
| 22 | #include <linux/cpufreq.h> | ||
| 23 | #include <linux/device.h> | ||
| 24 | #include <linux/types.h> | ||
| 25 | |||
| 26 | struct cpufreq_arm_bL_ops { | ||
| 27 | char name[CPUFREQ_NAME_LEN]; | ||
| 28 | int (*get_transition_latency)(struct device *cpu_dev); | ||
| 29 | |||
| 30 | /* | ||
| 31 | * This must set opp table for cpu_dev in a similar way as done by | ||
| 32 | * of_init_opp_table(). | ||
| 33 | */ | ||
| 34 | int (*init_opp_table)(struct device *cpu_dev); | ||
| 35 | }; | ||
| 36 | |||
| 37 | int bL_cpufreq_register(struct cpufreq_arm_bL_ops *ops); | ||
| 38 | void bL_cpufreq_unregister(struct cpufreq_arm_bL_ops *ops); | ||
| 39 | |||
| 40 | #endif /* CPUFREQ_ARM_BIG_LITTLE_H */ | ||
diff --git a/drivers/cpufreq/arm_big_little_dt.c b/drivers/cpufreq/arm_big_little_dt.c new file mode 100644 index 000000000000..452ff46f20b7 --- /dev/null +++ b/drivers/cpufreq/arm_big_little_dt.c | |||
| @@ -0,0 +1,92 @@ | |||
| 1 | /* | ||
| 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> | ||
| 26 | #include <linux/of.h> | ||
| 27 | #include <linux/opp.h> | ||
| 28 | #include <linux/slab.h> | ||
| 29 | #include <linux/types.h> | ||
| 30 | #include "arm_big_little.h" | ||
| 31 | |||
| 32 | static int dt_init_opp_table(struct device *cpu_dev) | ||
| 33 | { | ||
| 34 | struct device_node *np = NULL; | ||
| 35 | int count = 0, ret; | ||
| 36 | |||
| 37 | for_each_child_of_node(of_find_node_by_path("/cpus"), np) { | ||
| 38 | if (count++ != cpu_dev->id) | ||
| 39 | continue; | ||
| 40 | if (!of_get_property(np, "operating-points", NULL)) | ||
| 41 | return -ENODATA; | ||
| 42 | |||
| 43 | cpu_dev->of_node = np; | ||
| 44 | |||
| 45 | ret = of_init_opp_table(cpu_dev); | ||
| 46 | if (ret) | ||
| 47 | return ret; | ||
| 48 | |||
| 49 | return 0; | ||
| 50 | } | ||
| 51 | |||
| 52 | return -ENODEV; | ||
| 53 | } | ||
| 54 | |||
| 55 | static int dt_get_transition_latency(struct device *cpu_dev) | ||
| 56 | { | ||
| 57 | struct device_node *np = NULL; | ||
| 58 | u32 transition_latency = CPUFREQ_ETERNAL; | ||
| 59 | int count = 0; | ||
| 60 | |||
| 61 | for_each_child_of_node(of_find_node_by_path("/cpus"), np) { | ||
| 62 | if (count++ != cpu_dev->id) | ||
| 63 | continue; | ||
| 64 | |||
| 65 | of_property_read_u32(np, "clock-latency", &transition_latency); | ||
| 66 | return 0; | ||
| 67 | } | ||
| 68 | |||
| 69 | return -ENODEV; | ||
| 70 | } | ||
| 71 | |||
| 72 | static struct cpufreq_arm_bL_ops dt_bL_ops = { | ||
| 73 | .name = "dt-bl", | ||
| 74 | .get_transition_latency = dt_get_transition_latency, | ||
| 75 | .init_opp_table = dt_init_opp_table, | ||
| 76 | }; | ||
| 77 | |||
| 78 | static int generic_bL_init(void) | ||
| 79 | { | ||
| 80 | return bL_cpufreq_register(&dt_bL_ops); | ||
| 81 | } | ||
| 82 | module_init(generic_bL_init); | ||
| 83 | |||
| 84 | static void generic_bL_exit(void) | ||
| 85 | { | ||
| 86 | return bL_cpufreq_unregister(&dt_bL_ops); | ||
| 87 | } | ||
| 88 | module_exit(generic_bL_exit); | ||
| 89 | |||
| 90 | MODULE_AUTHOR("Viresh Kumar <viresh.kumar@linaro.org>"); | ||
| 91 | MODULE_DESCRIPTION("Generic ARM big LITTLE cpufreq driver via DT"); | ||
| 92 | MODULE_LICENSE("GPL"); | ||
