diff options
-rw-r--r-- | arch/arm/Kconfig | 1 | ||||
-rw-r--r-- | arch/arm/mach-tegra/Makefile | 1 | ||||
-rw-r--r-- | arch/arm/mach-tegra/cpu-tegra.c | 185 |
3 files changed, 187 insertions, 0 deletions
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 3849887157e..fc6573d17a4 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig | |||
@@ -573,6 +573,7 @@ config ARCH_TEGRA | |||
573 | select HAVE_CLK | 573 | select HAVE_CLK |
574 | select COMMON_CLKDEV | 574 | select COMMON_CLKDEV |
575 | select ARCH_HAS_BARRIERS if CACHE_L2X0 | 575 | select ARCH_HAS_BARRIERS if CACHE_L2X0 |
576 | select ARCH_HAS_CPUFREQ | ||
576 | help | 577 | help |
577 | This enables support for NVIDIA Tegra based systems (Tegra APX, | 578 | This enables support for NVIDIA Tegra based systems (Tegra APX, |
578 | Tegra 6xx and Tegra 2 series). | 579 | Tegra 6xx and Tegra 2 series). |
diff --git a/arch/arm/mach-tegra/Makefile b/arch/arm/mach-tegra/Makefile index 3642e58e507..2a3762179cc 100644 --- a/arch/arm/mach-tegra/Makefile +++ b/arch/arm/mach-tegra/Makefile | |||
@@ -12,6 +12,7 @@ obj-$(CONFIG_ARCH_TEGRA_2x_SOC) += tegra2_dvfs.o | |||
12 | obj-$(CONFIG_ARCH_TEGRA_2x_SOC) += pinmux-t2-tables.o | 12 | obj-$(CONFIG_ARCH_TEGRA_2x_SOC) += pinmux-t2-tables.o |
13 | obj-$(CONFIG_SMP) += platsmp.o localtimer.o headsmp.o | 13 | obj-$(CONFIG_SMP) += platsmp.o localtimer.o headsmp.o |
14 | obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o | 14 | obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o |
15 | obj-$(CONFIG_CPU_FREQ) += cpu-tegra.o | ||
15 | 16 | ||
16 | obj-${CONFIG_MACH_HARMONY} += board-harmony.o | 17 | obj-${CONFIG_MACH_HARMONY} += board-harmony.o |
17 | obj-${CONFIG_MACH_HARMONY} += board-harmony-pinmux.o | 18 | obj-${CONFIG_MACH_HARMONY} += board-harmony-pinmux.o |
diff --git a/arch/arm/mach-tegra/cpu-tegra.c b/arch/arm/mach-tegra/cpu-tegra.c new file mode 100644 index 00000000000..fea5719c707 --- /dev/null +++ b/arch/arm/mach-tegra/cpu-tegra.c | |||
@@ -0,0 +1,185 @@ | |||
1 | /* | ||
2 | * arch/arm/mach-tegra/cpu-tegra.c | ||
3 | * | ||
4 | * Copyright (C) 2010 Google, Inc. | ||
5 | * | ||
6 | * Author: | ||
7 | * Colin Cross <ccross@google.com> | ||
8 | * Based on arch/arm/plat-omap/cpu-omap.c, (C) 2005 Nokia Corporation | ||
9 | * | ||
10 | * This software is licensed under the terms of the GNU General Public | ||
11 | * License version 2, as published by the Free Software Foundation, and | ||
12 | * may be copied, distributed, and modified under those terms. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | */ | ||
20 | |||
21 | #include <linux/kernel.h> | ||
22 | #include <linux/module.h> | ||
23 | #include <linux/types.h> | ||
24 | #include <linux/sched.h> | ||
25 | #include <linux/cpufreq.h> | ||
26 | #include <linux/delay.h> | ||
27 | #include <linux/init.h> | ||
28 | #include <linux/err.h> | ||
29 | #include <linux/clk.h> | ||
30 | #include <linux/io.h> | ||
31 | |||
32 | #include <asm/system.h> | ||
33 | |||
34 | #include <mach/hardware.h> | ||
35 | #include <mach/clk.h> | ||
36 | |||
37 | /* Frequency table index must be sequential starting at 0 */ | ||
38 | static struct cpufreq_frequency_table freq_table[] = { | ||
39 | { 0, 312000 }, | ||
40 | { 1, 456000 }, | ||
41 | { 2, 608000 }, | ||
42 | { 3, 760000 }, | ||
43 | { 4, 816000 }, | ||
44 | { 5, 912000 }, | ||
45 | { 6, 1000000 }, | ||
46 | { 7, CPUFREQ_TABLE_END }, | ||
47 | }; | ||
48 | |||
49 | #define NUM_CPUS 2 | ||
50 | |||
51 | static struct clk *cpu_clk; | ||
52 | |||
53 | static unsigned long target_cpu_speed[NUM_CPUS]; | ||
54 | |||
55 | int tegra_verify_speed(struct cpufreq_policy *policy) | ||
56 | { | ||
57 | return cpufreq_frequency_table_verify(policy, freq_table); | ||
58 | } | ||
59 | |||
60 | unsigned int tegra_getspeed(unsigned int cpu) | ||
61 | { | ||
62 | unsigned long rate; | ||
63 | |||
64 | if (cpu >= NUM_CPUS) | ||
65 | return 0; | ||
66 | |||
67 | rate = clk_get_rate(cpu_clk) / 1000; | ||
68 | return rate; | ||
69 | } | ||
70 | |||
71 | static int tegra_update_cpu_speed(void) | ||
72 | { | ||
73 | int i; | ||
74 | unsigned long rate = 0; | ||
75 | int ret = 0; | ||
76 | struct cpufreq_freqs freqs; | ||
77 | |||
78 | for_each_online_cpu(i) | ||
79 | rate = max(rate, target_cpu_speed[i]); | ||
80 | |||
81 | freqs.old = tegra_getspeed(0); | ||
82 | freqs.new = rate; | ||
83 | |||
84 | if (freqs.old == freqs.new) | ||
85 | return ret; | ||
86 | |||
87 | for_each_online_cpu(freqs.cpu) | ||
88 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
89 | |||
90 | #ifdef CONFIG_CPU_FREQ_DEBUG | ||
91 | printk(KERN_DEBUG "cpufreq-tegra: transition: %u --> %u\n", | ||
92 | freqs.old, freqs.new); | ||
93 | #endif | ||
94 | |||
95 | ret = clk_set_rate_cansleep(cpu_clk, freqs.new * 1000); | ||
96 | if (ret) { | ||
97 | pr_err("cpu-tegra: Failed to set cpu frequency to %d kHz\n", | ||
98 | freqs.new); | ||
99 | return ret; | ||
100 | } | ||
101 | |||
102 | for_each_online_cpu(freqs.cpu) | ||
103 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
104 | |||
105 | return 0; | ||
106 | } | ||
107 | |||
108 | static int tegra_target(struct cpufreq_policy *policy, | ||
109 | unsigned int target_freq, | ||
110 | unsigned int relation) | ||
111 | { | ||
112 | int idx; | ||
113 | unsigned int freq; | ||
114 | |||
115 | cpufreq_frequency_table_target(policy, freq_table, target_freq, | ||
116 | relation, &idx); | ||
117 | |||
118 | freq = freq_table[idx].frequency; | ||
119 | |||
120 | target_cpu_speed[policy->cpu] = freq; | ||
121 | |||
122 | return tegra_update_cpu_speed(); | ||
123 | } | ||
124 | |||
125 | static int tegra_cpu_init(struct cpufreq_policy *policy) | ||
126 | { | ||
127 | if (policy->cpu >= NUM_CPUS) | ||
128 | return -EINVAL; | ||
129 | |||
130 | cpu_clk = clk_get_sys(NULL, "cpu"); | ||
131 | if (IS_ERR(cpu_clk)) | ||
132 | return PTR_ERR(cpu_clk); | ||
133 | |||
134 | cpufreq_frequency_table_cpuinfo(policy, freq_table); | ||
135 | cpufreq_frequency_table_get_attr(freq_table, policy->cpu); | ||
136 | policy->cur = tegra_getspeed(policy->cpu); | ||
137 | target_cpu_speed[policy->cpu] = policy->cur; | ||
138 | |||
139 | /* FIXME: what's the actual transition time? */ | ||
140 | policy->cpuinfo.transition_latency = 300 * 1000; | ||
141 | |||
142 | policy->shared_type = CPUFREQ_SHARED_TYPE_ALL; | ||
143 | cpumask_copy(policy->related_cpus, cpu_possible_mask); | ||
144 | |||
145 | return 0; | ||
146 | } | ||
147 | |||
148 | static int tegra_cpu_exit(struct cpufreq_policy *policy) | ||
149 | { | ||
150 | cpufreq_frequency_table_cpuinfo(policy, freq_table); | ||
151 | clk_put(cpu_clk); | ||
152 | return 0; | ||
153 | } | ||
154 | |||
155 | static struct freq_attr *tegra_cpufreq_attr[] = { | ||
156 | &cpufreq_freq_attr_scaling_available_freqs, | ||
157 | NULL, | ||
158 | }; | ||
159 | |||
160 | static struct cpufreq_driver tegra_cpufreq_driver = { | ||
161 | .verify = tegra_verify_speed, | ||
162 | .target = tegra_target, | ||
163 | .get = tegra_getspeed, | ||
164 | .init = tegra_cpu_init, | ||
165 | .exit = tegra_cpu_exit, | ||
166 | .name = "tegra", | ||
167 | .attr = tegra_cpufreq_attr, | ||
168 | }; | ||
169 | |||
170 | static int __init tegra_cpufreq_init(void) | ||
171 | { | ||
172 | return cpufreq_register_driver(&tegra_cpufreq_driver); | ||
173 | } | ||
174 | |||
175 | static void __exit tegra_cpufreq_exit(void) | ||
176 | { | ||
177 | cpufreq_unregister_driver(&tegra_cpufreq_driver); | ||
178 | } | ||
179 | |||
180 | |||
181 | MODULE_AUTHOR("Colin Cross <ccross@android.com>"); | ||
182 | MODULE_DESCRIPTION("cpufreq driver for Nvidia Tegra2"); | ||
183 | MODULE_LICENSE("GPL"); | ||
184 | module_init(tegra_cpufreq_init); | ||
185 | module_exit(tegra_cpufreq_exit); | ||