aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorSekhar Nori <nsekhar@ti.com>2009-09-22 11:44:00 -0400
committerKevin Hilman <khilman@deeprootsystems.com>2009-11-25 13:21:28 -0500
commit6601b8030de3e9c29930684eeac15302a59f991a (patch)
treeef425f3cad13bf1ab86060c5fa6e128345b9686d /arch
parenta75fd514f4871eb08aed41fc34ed716e0b78f750 (diff)
davinci: add generic CPUFreq driver for DaVinci
Adds a basic CPUFreq driver for DaVinci devices registering with the kernel CPUFreq infrastructure. Support is added for both frequency and voltage regulation. Signed-off-by: Sekhar Nori <nsekhar@ti.com> Signed-off-by: Kevin Hilman <khilman@deeprootsystems.com>
Diffstat (limited to 'arch')
-rw-r--r--arch/arm/mach-davinci/Kconfig1
-rw-r--r--arch/arm/mach-davinci/Makefile3
-rw-r--r--arch/arm/mach-davinci/cpufreq.c219
-rw-r--r--arch/arm/mach-davinci/include/mach/cpufreq.h25
4 files changed, 248 insertions, 0 deletions
diff --git a/arch/arm/mach-davinci/Kconfig b/arch/arm/mach-davinci/Kconfig
index 7b6dddf08e94..84b7c17e5677 100644
--- a/arch/arm/mach-davinci/Kconfig
+++ b/arch/arm/mach-davinci/Kconfig
@@ -37,6 +37,7 @@ config ARCH_DAVINCI_DA850
37 bool "DA850/OMAP-L138 based system" 37 bool "DA850/OMAP-L138 based system"
38 select CP_INTC 38 select CP_INTC
39 select ARCH_DAVINCI_DA8XX 39 select ARCH_DAVINCI_DA8XX
40 select ARCH_HAS_CPUFREQ
40 41
41config ARCH_DAVINCI_DA8XX 42config ARCH_DAVINCI_DA8XX
42 bool 43 bool
diff --git a/arch/arm/mach-davinci/Makefile b/arch/arm/mach-davinci/Makefile
index 2e11e847313b..be629c54e212 100644
--- a/arch/arm/mach-davinci/Makefile
+++ b/arch/arm/mach-davinci/Makefile
@@ -29,3 +29,6 @@ obj-$(CONFIG_MACH_DAVINCI_DM6467_EVM) += board-dm646x-evm.o
29obj-$(CONFIG_MACH_DAVINCI_DM365_EVM) += board-dm365-evm.o 29obj-$(CONFIG_MACH_DAVINCI_DM365_EVM) += board-dm365-evm.o
30obj-$(CONFIG_MACH_DAVINCI_DA830_EVM) += board-da830-evm.o 30obj-$(CONFIG_MACH_DAVINCI_DA830_EVM) += board-da830-evm.o
31obj-$(CONFIG_MACH_DAVINCI_DA850_EVM) += board-da850-evm.o 31obj-$(CONFIG_MACH_DAVINCI_DA850_EVM) += board-da850-evm.o
32
33# Power Management
34obj-$(CONFIG_CPU_FREQ) += cpufreq.o
diff --git a/arch/arm/mach-davinci/cpufreq.c b/arch/arm/mach-davinci/cpufreq.c
new file mode 100644
index 000000000000..8c8c07b12d87
--- /dev/null
+++ b/arch/arm/mach-davinci/cpufreq.c
@@ -0,0 +1,219 @@
1/*
2 * CPU frequency scaling for DaVinci
3 *
4 * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
5 *
6 * Based on linux/arch/arm/plat-omap/cpu-omap.c. Original Copyright follows:
7 *
8 * Copyright (C) 2005 Nokia Corporation
9 * Written by Tony Lindgren <tony@atomide.com>
10 *
11 * Based on cpu-sa1110.c, Copyright (C) 2001 Russell King
12 *
13 * Copyright (C) 2007-2008 Texas Instruments, Inc.
14 * Updated to support OMAP3
15 * Rajendra Nayak <rnayak@ti.com>
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License version 2 as
19 * published by the Free Software Foundation.
20 */
21#include <linux/types.h>
22#include <linux/cpufreq.h>
23#include <linux/init.h>
24#include <linux/err.h>
25#include <linux/clk.h>
26#include <linux/platform_device.h>
27
28#include <mach/hardware.h>
29#include <mach/cpufreq.h>
30#include <mach/common.h>
31
32#include "clock.h"
33
34struct davinci_cpufreq {
35 struct device *dev;
36 struct clk *armclk;
37};
38static struct davinci_cpufreq cpufreq;
39
40static int davinci_verify_speed(struct cpufreq_policy *policy)
41{
42 struct davinci_cpufreq_config *pdata = cpufreq.dev->platform_data;
43 struct cpufreq_frequency_table *freq_table = pdata->freq_table;
44 struct clk *armclk = cpufreq.armclk;
45
46 if (freq_table)
47 return cpufreq_frequency_table_verify(policy, freq_table);
48
49 if (policy->cpu)
50 return -EINVAL;
51
52 cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
53 policy->cpuinfo.max_freq);
54
55 policy->min = clk_round_rate(armclk, policy->min * 1000) / 1000;
56 policy->max = clk_round_rate(armclk, policy->max * 1000) / 1000;
57 cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
58 policy->cpuinfo.max_freq);
59 return 0;
60}
61
62static unsigned int davinci_getspeed(unsigned int cpu)
63{
64 if (cpu)
65 return 0;
66
67 return clk_get_rate(cpufreq.armclk) / 1000;
68}
69
70static int davinci_target(struct cpufreq_policy *policy,
71 unsigned int target_freq, unsigned int relation)
72{
73 int ret = 0;
74 unsigned int idx;
75 struct cpufreq_freqs freqs;
76 struct davinci_cpufreq_config *pdata = cpufreq.dev->platform_data;
77 struct clk *armclk = cpufreq.armclk;
78
79 /*
80 * Ensure desired rate is within allowed range. Some govenors
81 * (ondemand) will just pass target_freq=0 to get the minimum.
82 */
83 if (target_freq < policy->cpuinfo.min_freq)
84 target_freq = policy->cpuinfo.min_freq;
85 if (target_freq > policy->cpuinfo.max_freq)
86 target_freq = policy->cpuinfo.max_freq;
87
88 freqs.old = davinci_getspeed(0);
89 freqs.new = clk_round_rate(armclk, target_freq * 1000) / 1000;
90 freqs.cpu = 0;
91
92 if (freqs.old == freqs.new)
93 return ret;
94
95 cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER,
96 dev_driver_string(cpufreq.dev),
97 "transition: %u --> %u\n", freqs.old, freqs.new);
98
99 ret = cpufreq_frequency_table_target(policy, pdata->freq_table,
100 freqs.new, relation, &idx);
101 if (ret)
102 return -EINVAL;
103
104 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
105
106 /* if moving to higher frequency, up the voltage beforehand */
107 if (pdata->set_voltage && freqs.new > freqs.old)
108 pdata->set_voltage(idx);
109
110 ret = clk_set_rate(armclk, idx);
111
112 /* if moving to lower freq, lower the voltage after lowering freq */
113 if (pdata->set_voltage && freqs.new < freqs.old)
114 pdata->set_voltage(idx);
115
116 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
117
118 return ret;
119}
120
121static int __init davinci_cpu_init(struct cpufreq_policy *policy)
122{
123 int result = 0;
124 struct davinci_cpufreq_config *pdata = cpufreq.dev->platform_data;
125 struct cpufreq_frequency_table *freq_table = pdata->freq_table;
126
127 if (policy->cpu != 0)
128 return -EINVAL;
129
130 policy->cur = policy->min = policy->max = davinci_getspeed(0);
131
132 if (freq_table) {
133 result = cpufreq_frequency_table_cpuinfo(policy, freq_table);
134 if (!result)
135 cpufreq_frequency_table_get_attr(freq_table,
136 policy->cpu);
137 } else {
138 policy->cpuinfo.min_freq = policy->min;
139 policy->cpuinfo.max_freq = policy->max;
140 }
141
142 policy->min = policy->cpuinfo.min_freq;
143 policy->max = policy->cpuinfo.max_freq;
144 policy->cur = davinci_getspeed(0);
145
146 /*
147 * Time measurement across the target() function yields ~1500-1800us
148 * time taken with no drivers on notification list.
149 * Setting the latency to 2000 us to accomodate addition of drivers
150 * to pre/post change notification list.
151 */
152 policy->cpuinfo.transition_latency = 2000 * 1000;
153 return 0;
154}
155
156static int davinci_cpu_exit(struct cpufreq_policy *policy)
157{
158 cpufreq_frequency_table_put_attr(policy->cpu);
159 return 0;
160}
161
162static struct freq_attr *davinci_cpufreq_attr[] = {
163 &cpufreq_freq_attr_scaling_available_freqs,
164 NULL,
165};
166
167static struct cpufreq_driver davinci_driver = {
168 .flags = CPUFREQ_STICKY,
169 .verify = davinci_verify_speed,
170 .target = davinci_target,
171 .get = davinci_getspeed,
172 .init = davinci_cpu_init,
173 .exit = davinci_cpu_exit,
174 .name = "davinci",
175 .attr = davinci_cpufreq_attr,
176};
177
178static int __init davinci_cpufreq_probe(struct platform_device *pdev)
179{
180 struct davinci_cpufreq_config *pdata = pdev->dev.platform_data;
181
182 if (!pdata)
183 return -EINVAL;
184 if (!pdata->freq_table)
185 return -EINVAL;
186
187 cpufreq.dev = &pdev->dev;
188
189 cpufreq.armclk = clk_get(NULL, "arm");
190 if (IS_ERR(cpufreq.armclk)) {
191 dev_err(cpufreq.dev, "Unable to get ARM clock\n");
192 return PTR_ERR(cpufreq.armclk);
193 }
194
195 return cpufreq_register_driver(&davinci_driver);
196}
197
198static int __exit davinci_cpufreq_remove(struct platform_device *pdev)
199{
200 clk_put(cpufreq.armclk);
201
202 return cpufreq_unregister_driver(&davinci_driver);
203}
204
205static struct platform_driver davinci_cpufreq_driver = {
206 .driver = {
207 .name = "cpufreq-davinci",
208 .owner = THIS_MODULE,
209 },
210 .remove = __exit_p(davinci_cpufreq_remove),
211};
212
213static int __init davinci_cpufreq_init(void)
214{
215 return platform_driver_probe(&davinci_cpufreq_driver,
216 davinci_cpufreq_probe);
217}
218late_initcall(davinci_cpufreq_init);
219
diff --git a/arch/arm/mach-davinci/include/mach/cpufreq.h b/arch/arm/mach-davinci/include/mach/cpufreq.h
new file mode 100644
index 000000000000..442bdea44632
--- /dev/null
+++ b/arch/arm/mach-davinci/include/mach/cpufreq.h
@@ -0,0 +1,25 @@
1/*
2 * TI DaVinci CPUFreq platform support.
3 *
4 * Copyright (C) 2009 Texas Instruments, Inc. http://www.ti.com/
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation version 2.
9 *
10 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
11 * kind, whether express or implied; without even the implied warranty
12 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15#ifndef _MACH_DAVINCI_CPUFREQ_H
16#define _MACH_DAVINCI_CPUFREQ_H
17
18#include <linux/cpufreq.h>
19
20struct davinci_cpufreq_config {
21 struct cpufreq_frequency_table *freq_table;
22 int (*set_voltage) (unsigned int index);
23};
24
25#endif