Blame view
drivers/cpufreq/davinci-cpufreq.c
4.56 KB
6601b8030
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
/* * CPU frequency scaling for DaVinci * * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ * * Based on linux/arch/arm/plat-omap/cpu-omap.c. Original Copyright follows: * * Copyright (C) 2005 Nokia Corporation * Written by Tony Lindgren <tony@atomide.com> * * Based on cpu-sa1110.c, Copyright (C) 2001 Russell King * * Copyright (C) 2007-2008 Texas Instruments, Inc. * Updated to support OMAP3 * Rajendra Nayak <rnayak@ti.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/types.h> #include <linux/cpufreq.h> #include <linux/init.h> #include <linux/err.h> #include <linux/clk.h> #include <linux/platform_device.h> |
dc28094b9
|
27 |
#include <linux/export.h> |
6601b8030
|
28 29 30 31 |
#include <mach/hardware.h> #include <mach/cpufreq.h> #include <mach/common.h> |
6601b8030
|
32 33 34 |
struct davinci_cpufreq { struct device *dev; struct clk *armclk; |
30a2c5d2f
|
35 36 |
struct clk *asyncclk; unsigned long asyncrate; |
6601b8030
|
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
}; static struct davinci_cpufreq cpufreq; static int davinci_verify_speed(struct cpufreq_policy *policy) { struct davinci_cpufreq_config *pdata = cpufreq.dev->platform_data; struct cpufreq_frequency_table *freq_table = pdata->freq_table; struct clk *armclk = cpufreq.armclk; if (freq_table) return cpufreq_frequency_table_verify(policy, freq_table); if (policy->cpu) return -EINVAL; |
be49e3465
|
51 |
cpufreq_verify_within_cpu_limits(policy); |
6601b8030
|
52 53 54 55 56 57 |
policy->min = clk_round_rate(armclk, policy->min * 1000) / 1000; policy->max = clk_round_rate(armclk, policy->max * 1000) / 1000; cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, policy->cpuinfo.max_freq); return 0; } |
9c0ebcf78
|
58 |
static int davinci_target(struct cpufreq_policy *policy, unsigned int idx) |
6601b8030
|
59 |
{ |
6601b8030
|
60 61 |
struct davinci_cpufreq_config *pdata = cpufreq.dev->platform_data; struct clk *armclk = cpufreq.armclk; |
d4019f0a9
|
62 63 |
unsigned int old_freq, new_freq; int ret = 0; |
6601b8030
|
64 |
|
652ed95d5
|
65 |
old_freq = policy->cur; |
d4019f0a9
|
66 |
new_freq = pdata->freq_table[idx].frequency; |
6601b8030
|
67 68 |
/* if moving to higher frequency, up the voltage beforehand */ |
d4019f0a9
|
69 |
if (pdata->set_voltage && new_freq > old_freq) { |
fca97b333
|
70 71 |
ret = pdata->set_voltage(idx); if (ret) |
d4019f0a9
|
72 |
return ret; |
fca97b333
|
73 |
} |
6601b8030
|
74 75 |
ret = clk_set_rate(armclk, idx); |
fca97b333
|
76 |
if (ret) |
d4019f0a9
|
77 |
return ret; |
6601b8030
|
78 |
|
30a2c5d2f
|
79 80 81 |
if (cpufreq.asyncclk) { ret = clk_set_rate(cpufreq.asyncclk, cpufreq.asyncrate); if (ret) |
d4019f0a9
|
82 |
return ret; |
30a2c5d2f
|
83 |
} |
6601b8030
|
84 |
/* if moving to lower freq, lower the voltage after lowering freq */ |
d4019f0a9
|
85 |
if (pdata->set_voltage && new_freq < old_freq) |
6601b8030
|
86 |
pdata->set_voltage(idx); |
d4019f0a9
|
87 |
return 0; |
6601b8030
|
88 |
} |
079db590f
|
89 |
static int davinci_cpu_init(struct cpufreq_policy *policy) |
6601b8030
|
90 91 92 93 94 95 96 |
{ int result = 0; struct davinci_cpufreq_config *pdata = cpufreq.dev->platform_data; struct cpufreq_frequency_table *freq_table = pdata->freq_table; if (policy->cpu != 0) return -EINVAL; |
13d5e27a4
|
97 98 99 100 101 102 |
/* Finish platform specific initialization */ if (pdata->init) { result = pdata->init(); if (result) return result; } |
652ed95d5
|
103 |
policy->clk = cpufreq.armclk; |
6601b8030
|
104 105 106 |
/* * Time measurement across the target() function yields ~1500-1800us * time taken with no drivers on notification list. |
25985edce
|
107 |
* Setting the latency to 2000 us to accommodate addition of drivers |
6601b8030
|
108 109 |
* to pre/post change notification list. */ |
af8c4cfab
|
110 |
return cpufreq_generic_init(policy, freq_table, 2000 * 1000); |
6601b8030
|
111 |
} |
6601b8030
|
112 |
static struct cpufreq_driver davinci_driver = { |
ae6b42713
|
113 |
.flags = CPUFREQ_STICKY | CPUFREQ_NEED_INITIAL_FREQ_CHECK, |
6601b8030
|
114 |
.verify = davinci_verify_speed, |
9c0ebcf78
|
115 |
.target_index = davinci_target, |
652ed95d5
|
116 |
.get = cpufreq_generic_get, |
6601b8030
|
117 |
.init = davinci_cpu_init, |
6601b8030
|
118 |
.name = "davinci", |
39d0c362b
|
119 |
.attr = cpufreq_generic_attr, |
6601b8030
|
120 121 122 123 124 |
}; static int __init davinci_cpufreq_probe(struct platform_device *pdev) { struct davinci_cpufreq_config *pdata = pdev->dev.platform_data; |
30a2c5d2f
|
125 |
struct clk *asyncclk; |
6601b8030
|
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
if (!pdata) return -EINVAL; if (!pdata->freq_table) return -EINVAL; cpufreq.dev = &pdev->dev; cpufreq.armclk = clk_get(NULL, "arm"); if (IS_ERR(cpufreq.armclk)) { dev_err(cpufreq.dev, "Unable to get ARM clock "); return PTR_ERR(cpufreq.armclk); } |
30a2c5d2f
|
140 141 142 143 144 |
asyncclk = clk_get(cpufreq.dev, "async"); if (!IS_ERR(asyncclk)) { cpufreq.asyncclk = asyncclk; cpufreq.asyncrate = clk_get_rate(asyncclk); } |
6601b8030
|
145 146 147 148 149 150 |
return cpufreq_register_driver(&davinci_driver); } static int __exit davinci_cpufreq_remove(struct platform_device *pdev) { clk_put(cpufreq.armclk); |
30a2c5d2f
|
151 152 |
if (cpufreq.asyncclk) clk_put(cpufreq.asyncclk); |
6601b8030
|
153 154 155 156 157 158 |
return cpufreq_unregister_driver(&davinci_driver); } static struct platform_driver davinci_cpufreq_driver = { .driver = { .name = "cpufreq-davinci", |
6601b8030
|
159 160 161 |
}, .remove = __exit_p(davinci_cpufreq_remove), }; |
3aa3e8407
|
162 |
int __init davinci_cpufreq_init(void) |
6601b8030
|
163 164 165 166 |
{ return platform_driver_probe(&davinci_cpufreq_driver, davinci_cpufreq_probe); } |
6601b8030
|
167 |