Viresh Kumar | 8a67f0e | 2013-04-01 12:57:49 +0000 | [diff] [blame] | 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 | { |
Viresh Kumar | 763f8c3 | 2013-04-15 07:05:24 +0000 | [diff] [blame] | 34 | struct device_node *np, *parent; |
Viresh Kumar | 8a67f0e | 2013-04-01 12:57:49 +0000 | [diff] [blame] | 35 | int count = 0, ret; |
| 36 | |
Viresh Kumar | 763f8c3 | 2013-04-15 07:05:24 +0000 | [diff] [blame] | 37 | parent = of_find_node_by_path("/cpus"); |
| 38 | if (!parent) { |
| 39 | pr_err("failed to find OF /cpus\n"); |
| 40 | return -ENOENT; |
| 41 | } |
| 42 | |
| 43 | for_each_child_of_node(parent, np) { |
Viresh Kumar | 8a67f0e | 2013-04-01 12:57:49 +0000 | [diff] [blame] | 44 | if (count++ != cpu_dev->id) |
| 45 | continue; |
Viresh Kumar | 763f8c3 | 2013-04-15 07:05:24 +0000 | [diff] [blame] | 46 | if (!of_get_property(np, "operating-points", NULL)) { |
| 47 | ret = -ENODATA; |
| 48 | } else { |
| 49 | cpu_dev->of_node = np; |
| 50 | ret = of_init_opp_table(cpu_dev); |
| 51 | } |
| 52 | of_node_put(np); |
| 53 | of_node_put(parent); |
Viresh Kumar | 8a67f0e | 2013-04-01 12:57:49 +0000 | [diff] [blame] | 54 | |
Viresh Kumar | 763f8c3 | 2013-04-15 07:05:24 +0000 | [diff] [blame] | 55 | return ret; |
Viresh Kumar | 8a67f0e | 2013-04-01 12:57:49 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | return -ENODEV; |
| 59 | } |
| 60 | |
| 61 | static int dt_get_transition_latency(struct device *cpu_dev) |
| 62 | { |
Viresh Kumar | 763f8c3 | 2013-04-15 07:05:24 +0000 | [diff] [blame] | 63 | struct device_node *np, *parent; |
Viresh Kumar | 8a67f0e | 2013-04-01 12:57:49 +0000 | [diff] [blame] | 64 | u32 transition_latency = CPUFREQ_ETERNAL; |
| 65 | int count = 0; |
| 66 | |
Viresh Kumar | 763f8c3 | 2013-04-15 07:05:24 +0000 | [diff] [blame] | 67 | parent = of_find_node_by_path("/cpus"); |
| 68 | if (!parent) { |
Viresh Kumar | 3c792e0 | 2013-04-29 13:24:46 +0000 | [diff] [blame] | 69 | pr_info("Failed to find OF /cpus. Use CPUFREQ_ETERNAL transition latency\n"); |
| 70 | return CPUFREQ_ETERNAL; |
Viresh Kumar | 763f8c3 | 2013-04-15 07:05:24 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | for_each_child_of_node(parent, np) { |
Viresh Kumar | 8a67f0e | 2013-04-01 12:57:49 +0000 | [diff] [blame] | 74 | if (count++ != cpu_dev->id) |
| 75 | continue; |
| 76 | |
| 77 | of_property_read_u32(np, "clock-latency", &transition_latency); |
Viresh Kumar | 763f8c3 | 2013-04-15 07:05:24 +0000 | [diff] [blame] | 78 | of_node_put(np); |
| 79 | of_node_put(parent); |
| 80 | |
Viresh Kumar | 996905f | 2013-04-29 13:24:45 +0000 | [diff] [blame] | 81 | return transition_latency; |
Viresh Kumar | 8a67f0e | 2013-04-01 12:57:49 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Viresh Kumar | 3c792e0 | 2013-04-29 13:24:46 +0000 | [diff] [blame] | 84 | pr_info("clock-latency isn't found, use CPUFREQ_ETERNAL transition latency\n"); |
| 85 | return CPUFREQ_ETERNAL; |
Viresh Kumar | 8a67f0e | 2013-04-01 12:57:49 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | static struct cpufreq_arm_bL_ops dt_bL_ops = { |
| 89 | .name = "dt-bl", |
| 90 | .get_transition_latency = dt_get_transition_latency, |
| 91 | .init_opp_table = dt_init_opp_table, |
| 92 | }; |
| 93 | |
| 94 | static int generic_bL_init(void) |
| 95 | { |
| 96 | return bL_cpufreq_register(&dt_bL_ops); |
| 97 | } |
| 98 | module_init(generic_bL_init); |
| 99 | |
| 100 | static void generic_bL_exit(void) |
| 101 | { |
| 102 | return bL_cpufreq_unregister(&dt_bL_ops); |
| 103 | } |
| 104 | module_exit(generic_bL_exit); |
| 105 | |
| 106 | MODULE_AUTHOR("Viresh Kumar <viresh.kumar@linaro.org>"); |
| 107 | MODULE_DESCRIPTION("Generic ARM big LITTLE cpufreq driver via DT"); |
| 108 | MODULE_LICENSE("GPL"); |