diff options
Diffstat (limited to 'arch/blackfin/mach-common/cpufreq.c')
-rw-r--r-- | arch/blackfin/mach-common/cpufreq.c | 168 |
1 files changed, 105 insertions, 63 deletions
diff --git a/arch/blackfin/mach-common/cpufreq.c b/arch/blackfin/mach-common/cpufreq.c index 777582897253..4391d03dc845 100644 --- a/arch/blackfin/mach-common/cpufreq.c +++ b/arch/blackfin/mach-common/cpufreq.c | |||
@@ -11,10 +11,13 @@ | |||
11 | #include <linux/init.h> | 11 | #include <linux/init.h> |
12 | #include <linux/cpufreq.h> | 12 | #include <linux/cpufreq.h> |
13 | #include <linux/fs.h> | 13 | #include <linux/fs.h> |
14 | #include <linux/delay.h> | ||
14 | #include <asm/blackfin.h> | 15 | #include <asm/blackfin.h> |
15 | #include <asm/time.h> | 16 | #include <asm/time.h> |
16 | #include <asm/dpmc.h> | 17 | #include <asm/dpmc.h> |
17 | 18 | ||
19 | #define CPUFREQ_CPU 0 | ||
20 | |||
18 | /* this is the table of CCLK frequencies, in Hz */ | 21 | /* this is the table of CCLK frequencies, in Hz */ |
19 | /* .index is the entry in the auxillary dpm_state_table[] */ | 22 | /* .index is the entry in the auxillary dpm_state_table[] */ |
20 | static struct cpufreq_frequency_table bfin_freq_table[] = { | 23 | static struct cpufreq_frequency_table bfin_freq_table[] = { |
@@ -41,64 +44,124 @@ static struct bfin_dpm_state { | |||
41 | unsigned int tscale; /* change the divider on the core timer interrupt */ | 44 | unsigned int tscale; /* change the divider on the core timer interrupt */ |
42 | } dpm_state_table[3]; | 45 | } dpm_state_table[3]; |
43 | 46 | ||
47 | #if defined(CONFIG_CYCLES_CLOCKSOURCE) | ||
44 | /* | 48 | /* |
45 | normalized to maximum frequncy offset for CYCLES, | 49 | * normalized to maximum frequncy offset for CYCLES, |
46 | used in time-ts cycles clock source, but could be used | 50 | * used in time-ts cycles clock source, but could be used |
47 | somewhere also. | 51 | * somewhere also. |
48 | */ | 52 | */ |
49 | unsigned long long __bfin_cycles_off; | 53 | unsigned long long __bfin_cycles_off; |
50 | unsigned int __bfin_cycles_mod; | 54 | unsigned int __bfin_cycles_mod; |
55 | #endif | ||
51 | 56 | ||
52 | /**************************************************************************/ | 57 | /**************************************************************************/ |
58 | static void __init bfin_init_tables(unsigned long cclk, unsigned long sclk) | ||
59 | { | ||
53 | 60 | ||
54 | static unsigned int bfin_getfreq_khz(unsigned int cpu) | 61 | unsigned long csel, min_cclk; |
62 | int index; | ||
63 | |||
64 | /* Anomaly 273 seems to still exist on non-BF54x w/dcache turned on */ | ||
65 | #if ANOMALY_05000273 || ANOMALY_05000274 || \ | ||
66 | (!defined(CONFIG_BF54x) && defined(CONFIG_BFIN_EXTMEM_DCACHEABLE)) | ||
67 | min_cclk = sclk * 2; | ||
68 | #else | ||
69 | min_cclk = sclk; | ||
70 | #endif | ||
71 | csel = ((bfin_read_PLL_DIV() & CSEL) >> 4); | ||
72 | |||
73 | for (index = 0; (cclk >> index) >= min_cclk && csel <= 3; index++, csel++) { | ||
74 | bfin_freq_table[index].frequency = cclk >> index; | ||
75 | dpm_state_table[index].csel = csel << 4; /* Shift now into PLL_DIV bitpos */ | ||
76 | dpm_state_table[index].tscale = (TIME_SCALE / (1 << csel)) - 1; | ||
77 | |||
78 | pr_debug("cpufreq: freq:%d csel:0x%x tscale:%d\n", | ||
79 | bfin_freq_table[index].frequency, | ||
80 | dpm_state_table[index].csel, | ||
81 | dpm_state_table[index].tscale); | ||
82 | } | ||
83 | return; | ||
84 | } | ||
85 | |||
86 | static void bfin_adjust_core_timer(void *info) | ||
55 | { | 87 | { |
56 | /* The driver only support single cpu */ | 88 | unsigned int tscale; |
57 | if (cpu != 0) | 89 | unsigned int index = *(unsigned int *)info; |
58 | return -1; | ||
59 | 90 | ||
60 | return get_cclk() / 1000; | 91 | /* we have to adjust the core timer, because it is using cclk */ |
92 | tscale = dpm_state_table[index].tscale; | ||
93 | bfin_write_TSCALE(tscale); | ||
94 | return; | ||
61 | } | 95 | } |
62 | 96 | ||
97 | static unsigned int bfin_getfreq_khz(unsigned int cpu) | ||
98 | { | ||
99 | /* Both CoreA/B have the same core clock */ | ||
100 | return get_cclk() / 1000; | ||
101 | } | ||
63 | 102 | ||
64 | static int bfin_target(struct cpufreq_policy *policy, | 103 | static int bfin_target(struct cpufreq_policy *poli, |
65 | unsigned int target_freq, unsigned int relation) | 104 | unsigned int target_freq, unsigned int relation) |
66 | { | 105 | { |
67 | unsigned int index, plldiv, tscale; | 106 | unsigned int index, plldiv, cpu; |
68 | unsigned long flags, cclk_hz; | 107 | unsigned long flags, cclk_hz; |
69 | struct cpufreq_freqs freqs; | 108 | struct cpufreq_freqs freqs; |
109 | static unsigned long lpj_ref; | ||
110 | static unsigned int lpj_ref_freq; | ||
111 | |||
112 | #if defined(CONFIG_CYCLES_CLOCKSOURCE) | ||
70 | cycles_t cycles; | 113 | cycles_t cycles; |
114 | #endif | ||
71 | 115 | ||
72 | if (cpufreq_frequency_table_target(policy, bfin_freq_table, | 116 | for_each_online_cpu(cpu) { |
73 | target_freq, relation, &index)) | 117 | struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); |
74 | return -EINVAL; | 118 | |
75 | 119 | if (!policy) | |
76 | cclk_hz = bfin_freq_table[index].frequency; | 120 | continue; |
77 | 121 | ||
78 | freqs.old = bfin_getfreq_khz(0); | 122 | if (cpufreq_frequency_table_target(policy, bfin_freq_table, |
79 | freqs.new = cclk_hz; | 123 | target_freq, relation, &index)) |
80 | freqs.cpu = 0; | 124 | return -EINVAL; |
81 | 125 | ||
82 | pr_debug("cpufreq: changing cclk to %lu; target = %u, oldfreq = %u\n", | 126 | cclk_hz = bfin_freq_table[index].frequency; |
83 | cclk_hz, target_freq, freqs.old); | 127 | |
84 | 128 | freqs.old = bfin_getfreq_khz(0); | |
85 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | 129 | freqs.new = cclk_hz; |
86 | local_irq_save_hw(flags); | 130 | freqs.cpu = cpu; |
87 | plldiv = (bfin_read_PLL_DIV() & SSEL) | dpm_state_table[index].csel; | 131 | |
88 | tscale = dpm_state_table[index].tscale; | 132 | pr_debug("cpufreq: changing cclk to %lu; target = %u, oldfreq = %u\n", |
89 | bfin_write_PLL_DIV(plldiv); | 133 | cclk_hz, target_freq, freqs.old); |
90 | /* we have to adjust the core timer, because it is using cclk */ | 134 | |
91 | bfin_write_TSCALE(tscale); | 135 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); |
92 | cycles = get_cycles(); | 136 | if (cpu == CPUFREQ_CPU) { |
93 | SSYNC(); | 137 | local_irq_save_hw(flags); |
94 | cycles += 10; /* ~10 cycles we lose after get_cycles() */ | 138 | plldiv = (bfin_read_PLL_DIV() & SSEL) | |
95 | __bfin_cycles_off += (cycles << __bfin_cycles_mod) - (cycles << index); | 139 | dpm_state_table[index].csel; |
96 | __bfin_cycles_mod = index; | 140 | bfin_write_PLL_DIV(plldiv); |
97 | local_irq_restore_hw(flags); | 141 | on_each_cpu(bfin_adjust_core_timer, &index, 1); |
98 | /* TODO: just test case for cycles clock source, remove later */ | 142 | #if defined(CONFIG_CYCLES_CLOCKSOURCE) |
99 | pr_debug("cpufreq: done\n"); | 143 | cycles = get_cycles(); |
100 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | 144 | SSYNC(); |
145 | cycles += 10; /* ~10 cycles we lose after get_cycles() */ | ||
146 | __bfin_cycles_off += | ||
147 | (cycles << __bfin_cycles_mod) - (cycles << index); | ||
148 | __bfin_cycles_mod = index; | ||
149 | #endif | ||
150 | if (!lpj_ref_freq) { | ||
151 | lpj_ref = loops_per_jiffy; | ||
152 | lpj_ref_freq = freqs.old; | ||
153 | } | ||
154 | if (freqs.new != freqs.old) { | ||
155 | loops_per_jiffy = cpufreq_scale(lpj_ref, | ||
156 | lpj_ref_freq, freqs.new); | ||
157 | } | ||
158 | local_irq_restore_hw(flags); | ||
159 | } | ||
160 | /* TODO: just test case for cycles clock source, remove later */ | ||
161 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
162 | } | ||
101 | 163 | ||
164 | pr_debug("cpufreq: done\n"); | ||
102 | return 0; | 165 | return 0; |
103 | } | 166 | } |
104 | 167 | ||
@@ -110,37 +173,16 @@ static int bfin_verify_speed(struct cpufreq_policy *policy) | |||
110 | static int __init __bfin_cpu_init(struct cpufreq_policy *policy) | 173 | static int __init __bfin_cpu_init(struct cpufreq_policy *policy) |
111 | { | 174 | { |
112 | 175 | ||
113 | unsigned long cclk, sclk, csel, min_cclk; | 176 | unsigned long cclk, sclk; |
114 | int index; | ||
115 | |||
116 | if (policy->cpu != 0) | ||
117 | return -EINVAL; | ||
118 | 177 | ||
119 | cclk = get_cclk() / 1000; | 178 | cclk = get_cclk() / 1000; |
120 | sclk = get_sclk() / 1000; | 179 | sclk = get_sclk() / 1000; |
121 | 180 | ||
122 | #if ANOMALY_05000273 || ANOMALY_05000274 || \ | 181 | if (policy->cpu == CPUFREQ_CPU) |
123 | (!defined(CONFIG_BF54x) && defined(CONFIG_BFIN_EXTMEM_DCACHEABLE)) | 182 | bfin_init_tables(cclk, sclk); |
124 | min_cclk = sclk * 2; | ||
125 | #else | ||
126 | min_cclk = sclk; | ||
127 | #endif | ||
128 | csel = ((bfin_read_PLL_DIV() & CSEL) >> 4); | ||
129 | |||
130 | for (index = 0; (cclk >> index) >= min_cclk && csel <= 3; index++, csel++) { | ||
131 | bfin_freq_table[index].frequency = cclk >> index; | ||
132 | dpm_state_table[index].csel = csel << 4; /* Shift now into PLL_DIV bitpos */ | ||
133 | dpm_state_table[index].tscale = (TIME_SCALE / (1 << csel)) - 1; | ||
134 | |||
135 | pr_debug("cpufreq: freq:%d csel:0x%x tscale:%d\n", | ||
136 | bfin_freq_table[index].frequency, | ||
137 | dpm_state_table[index].csel, | ||
138 | dpm_state_table[index].tscale); | ||
139 | } | ||
140 | 183 | ||
141 | policy->cpuinfo.transition_latency = 50000; /* 50us assumed */ | 184 | policy->cpuinfo.transition_latency = 50000; /* 50us assumed */ |
142 | 185 | ||
143 | /*Now ,only support one cpu */ | ||
144 | policy->cur = cclk; | 186 | policy->cur = cclk; |
145 | cpufreq_frequency_table_get_attr(bfin_freq_table, policy->cpu); | 187 | cpufreq_frequency_table_get_attr(bfin_freq_table, policy->cpu); |
146 | return cpufreq_frequency_table_cpuinfo(policy, bfin_freq_table); | 188 | return cpufreq_frequency_table_cpuinfo(policy, bfin_freq_table); |