diff options
| -rw-r--r-- | arch/blackfin/kernel/time-ts.c | 30 | ||||
| -rw-r--r-- | arch/blackfin/kernel/time.c | 19 | ||||
| -rw-r--r-- | arch/blackfin/mach-common/Makefile | 3 | ||||
| -rw-r--r-- | arch/blackfin/mach-common/cpufreq.c | 194 | ||||
| -rw-r--r-- | include/asm-blackfin/time.h | 36 |
5 files changed, 263 insertions, 19 deletions
diff --git a/arch/blackfin/kernel/time-ts.c b/arch/blackfin/kernel/time-ts.c index 1ce8cb1e4982..4482c47c09e5 100644 --- a/arch/blackfin/kernel/time-ts.c +++ b/arch/blackfin/kernel/time-ts.c | |||
| @@ -16,11 +16,35 @@ | |||
| 16 | #include <linux/irq.h> | 16 | #include <linux/irq.h> |
| 17 | #include <linux/clocksource.h> | 17 | #include <linux/clocksource.h> |
| 18 | #include <linux/clockchips.h> | 18 | #include <linux/clockchips.h> |
| 19 | #include <linux/cpufreq.h> | ||
| 19 | 20 | ||
| 20 | #include <asm/blackfin.h> | 21 | #include <asm/blackfin.h> |
| 22 | #include <asm/time.h> | ||
| 21 | 23 | ||
| 22 | #ifdef CONFIG_CYCLES_CLOCKSOURCE | 24 | #ifdef CONFIG_CYCLES_CLOCKSOURCE |
| 23 | 25 | ||
| 26 | /* Accelerators for sched_clock() | ||
| 27 | * convert from cycles(64bits) => nanoseconds (64bits) | ||
| 28 | * basic equation: | ||
| 29 | * ns = cycles / (freq / ns_per_sec) | ||
| 30 | * ns = cycles * (ns_per_sec / freq) | ||
| 31 | * ns = cycles * (10^9 / (cpu_khz * 10^3)) | ||
| 32 | * ns = cycles * (10^6 / cpu_khz) | ||
| 33 | * | ||
| 34 | * Then we use scaling math (suggested by george@mvista.com) to get: | ||
| 35 | * ns = cycles * (10^6 * SC / cpu_khz) / SC | ||
| 36 | * ns = cycles * cyc2ns_scale / SC | ||
| 37 | * | ||
| 38 | * And since SC is a constant power of two, we can convert the div | ||
| 39 | * into a shift. | ||
| 40 | * | ||
| 41 | * We can use khz divisor instead of mhz to keep a better precision, since | ||
| 42 | * cyc2ns_scale is limited to 10^6 * 2^10, which fits in 32 bits. | ||
| 43 | * (mathieu.desnoyers@polymtl.ca) | ||
| 44 | * | ||
| 45 | * -johnstul@us.ibm.com "math is hard, lets go shopping!" | ||
| 46 | */ | ||
| 47 | |||
| 24 | static unsigned long cyc2ns_scale; | 48 | static unsigned long cyc2ns_scale; |
| 25 | #define CYC2NS_SCALE_FACTOR 10 /* 2^10, carefully chosen */ | 49 | #define CYC2NS_SCALE_FACTOR 10 /* 2^10, carefully chosen */ |
| 26 | 50 | ||
| @@ -82,8 +106,9 @@ static void bfin_timer_set_mode(enum clock_event_mode mode, | |||
| 82 | { | 106 | { |
| 83 | switch (mode) { | 107 | switch (mode) { |
| 84 | case CLOCK_EVT_MODE_PERIODIC: { | 108 | case CLOCK_EVT_MODE_PERIODIC: { |
| 85 | unsigned long tcount = ((get_cclk() / (HZ * 1)) - 1); | 109 | unsigned long tcount = ((get_cclk() / (HZ * TIME_SCALE)) - 1); |
| 86 | bfin_write_TCNTL(TMPWR); | 110 | bfin_write_TCNTL(TMPWR); |
| 111 | bfin_write_TSCALE(TIME_SCALE - 1); | ||
| 87 | CSYNC(); | 112 | CSYNC(); |
| 88 | bfin_write_TPERIOD(tcount); | 113 | bfin_write_TPERIOD(tcount); |
| 89 | bfin_write_TCOUNT(tcount); | 114 | bfin_write_TCOUNT(tcount); |
| @@ -92,6 +117,7 @@ static void bfin_timer_set_mode(enum clock_event_mode mode, | |||
| 92 | break; | 117 | break; |
| 93 | } | 118 | } |
| 94 | case CLOCK_EVT_MODE_ONESHOT: | 119 | case CLOCK_EVT_MODE_ONESHOT: |
| 120 | bfin_write_TSCALE(0); | ||
| 95 | bfin_write_TCOUNT(0); | 121 | bfin_write_TCOUNT(0); |
| 96 | bfin_write_TCNTL(TMPWR | TMREN); | 122 | bfin_write_TCNTL(TMPWR | TMREN); |
| 97 | CSYNC(); | 123 | CSYNC(); |
| @@ -115,7 +141,7 @@ static void __init bfin_timer_init(void) | |||
| 115 | /* | 141 | /* |
| 116 | * the TSCALE prescaler counter. | 142 | * the TSCALE prescaler counter. |
| 117 | */ | 143 | */ |
| 118 | bfin_write_TSCALE(0); | 144 | bfin_write_TSCALE(TIME_SCALE - 1); |
| 119 | bfin_write_TPERIOD(0); | 145 | bfin_write_TPERIOD(0); |
| 120 | bfin_write_TCOUNT(0); | 146 | bfin_write_TCOUNT(0); |
| 121 | 147 | ||
diff --git a/arch/blackfin/kernel/time.c b/arch/blackfin/kernel/time.c index 715b3945e4c7..eb2352320454 100644 --- a/arch/blackfin/kernel/time.c +++ b/arch/blackfin/kernel/time.c | |||
| @@ -6,9 +6,10 @@ | |||
| 6 | * Created: | 6 | * Created: |
| 7 | * Description: This file contains the bfin-specific time handling details. | 7 | * Description: This file contains the bfin-specific time handling details. |
| 8 | * Most of the stuff is located in the machine specific files. | 8 | * Most of the stuff is located in the machine specific files. |
| 9 | * FIXME: (This file is subject for removal) | ||
| 9 | * | 10 | * |
| 10 | * Modified: | 11 | * Modified: |
| 11 | * Copyright 2004-2006 Analog Devices Inc. | 12 | * Copyright 2004-2008 Analog Devices Inc. |
| 12 | * | 13 | * |
| 13 | * Bugs: Enter bugs at http://blackfin.uclinux.org/ | 14 | * Bugs: Enter bugs at http://blackfin.uclinux.org/ |
| 14 | * | 15 | * |
| @@ -35,6 +36,7 @@ | |||
| 35 | #include <linux/irq.h> | 36 | #include <linux/irq.h> |
| 36 | 37 | ||
| 37 | #include <asm/blackfin.h> | 38 | #include <asm/blackfin.h> |
| 39 | #include <asm/time.h> | ||
| 38 | 40 | ||
| 39 | /* This is an NTP setting */ | 41 | /* This is an NTP setting */ |
| 40 | #define TICK_SIZE (tick_nsec / 1000) | 42 | #define TICK_SIZE (tick_nsec / 1000) |
| @@ -47,21 +49,6 @@ static struct irqaction bfin_timer_irq = { | |||
| 47 | .flags = IRQF_DISABLED | 49 | .flags = IRQF_DISABLED |
| 48 | }; | 50 | }; |
| 49 | 51 | ||
| 50 | /* | ||
| 51 | * The way that the Blackfin core timer works is: | ||
| 52 | * - CCLK is divided by a programmable 8-bit pre-scaler (TSCALE) | ||
| 53 | * - Every time TSCALE ticks, a 32bit is counted down (TCOUNT) | ||
| 54 | * | ||
| 55 | * If you take the fastest clock (1ns, or 1GHz to make the math work easier) | ||
| 56 | * 10ms is 10,000,000 clock ticks, which fits easy into a 32-bit counter | ||
| 57 | * (32 bit counter is 4,294,967,296ns or 4.2 seconds) so, we don't need | ||
| 58 | * to use TSCALE, and program it to zero (which is pass CCLK through). | ||
| 59 | * If you feel like using it, try to keep HZ * TIMESCALE to some | ||
| 60 | * value that divides easy (like power of 2). | ||
| 61 | */ | ||
| 62 | |||
| 63 | #define TIME_SCALE 1 | ||
| 64 | |||
| 65 | static void | 52 | static void |
| 66 | time_sched_init(irq_handler_t timer_routine) | 53 | time_sched_init(irq_handler_t timer_routine) |
| 67 | { | 54 | { |
diff --git a/arch/blackfin/mach-common/Makefile b/arch/blackfin/mach-common/Makefile index 15e33ca1ce80..393081e9b680 100644 --- a/arch/blackfin/mach-common/Makefile +++ b/arch/blackfin/mach-common/Makefile | |||
| @@ -6,4 +6,5 @@ obj-y := \ | |||
| 6 | cache.o cacheinit.o entry.o \ | 6 | cache.o cacheinit.o entry.o \ |
| 7 | interrupt.o lock.o irqpanic.o arch_checks.o ints-priority.o | 7 | interrupt.o lock.o irqpanic.o arch_checks.o ints-priority.o |
| 8 | 8 | ||
| 9 | obj-$(CONFIG_PM) += pm.o dpmc.o | 9 | obj-$(CONFIG_PM) += pm.o dpmc.o |
| 10 | obj-$(CONFIG_CPU_FREQ) += cpufreq.o | ||
diff --git a/arch/blackfin/mach-common/cpufreq.c b/arch/blackfin/mach-common/cpufreq.c new file mode 100644 index 000000000000..ed81e00d20e1 --- /dev/null +++ b/arch/blackfin/mach-common/cpufreq.c | |||
| @@ -0,0 +1,194 @@ | |||
| 1 | /* | ||
| 2 | * File: arch/blackfin/mach-common/cpufreq.c | ||
| 3 | * Based on: | ||
| 4 | * Author: | ||
| 5 | * | ||
| 6 | * Created: | ||
| 7 | * Description: Blackfin core clock scaling | ||
| 8 | * | ||
| 9 | * Modified: | ||
| 10 | * Copyright 2004-2008 Analog Devices Inc. | ||
| 11 | * | ||
| 12 | * Bugs: Enter bugs at http://blackfin.uclinux.org/ | ||
| 13 | * | ||
| 14 | * This program is free software; you can redistribute it and/or modify | ||
| 15 | * it under the terms of the GNU General Public License as published by | ||
| 16 | * the Free Software Foundation; either version 2 of the License, or | ||
| 17 | * (at your option) any later version. | ||
| 18 | * | ||
| 19 | * This program is distributed in the hope that it will be useful, | ||
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 22 | * GNU General Public License for more details. | ||
| 23 | * | ||
| 24 | * You should have received a copy of the GNU General Public License | ||
| 25 | * along with this program; if not, see the file COPYING, or write | ||
| 26 | * to the Free Software Foundation, Inc., | ||
| 27 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 28 | */ | ||
| 29 | |||
| 30 | #include <linux/kernel.h> | ||
| 31 | #include <linux/types.h> | ||
| 32 | #include <linux/init.h> | ||
| 33 | #include <linux/cpufreq.h> | ||
| 34 | #include <linux/fs.h> | ||
| 35 | #include <asm/blackfin.h> | ||
| 36 | #include <asm/time.h> | ||
| 37 | |||
| 38 | |||
| 39 | /* this is the table of CCLK frequencies, in Hz */ | ||
| 40 | /* .index is the entry in the auxillary dpm_state_table[] */ | ||
| 41 | static struct cpufreq_frequency_table bfin_freq_table[] = { | ||
| 42 | { | ||
| 43 | .frequency = CPUFREQ_TABLE_END, | ||
| 44 | .index = 0, | ||
| 45 | }, | ||
| 46 | { | ||
| 47 | .frequency = CPUFREQ_TABLE_END, | ||
| 48 | .index = 1, | ||
| 49 | }, | ||
| 50 | { | ||
| 51 | .frequency = CPUFREQ_TABLE_END, | ||
| 52 | .index = 2, | ||
| 53 | }, | ||
| 54 | { | ||
| 55 | .frequency = CPUFREQ_TABLE_END, | ||
| 56 | .index = 0, | ||
| 57 | }, | ||
| 58 | }; | ||
| 59 | |||
| 60 | static struct bfin_dpm_state { | ||
| 61 | unsigned int csel; /* system clock divider */ | ||
| 62 | unsigned int tscale; /* change the divider on the core timer interrupt */ | ||
| 63 | } dpm_state_table[3]; | ||
| 64 | |||
| 65 | /**************************************************************************/ | ||
| 66 | |||
| 67 | static unsigned int bfin_getfreq(unsigned int cpu) | ||
| 68 | { | ||
| 69 | /* The driver only support single cpu */ | ||
| 70 | if (cpu != 0) | ||
| 71 | return -1; | ||
| 72 | |||
| 73 | return get_cclk(); | ||
| 74 | } | ||
| 75 | |||
| 76 | |||
| 77 | static int bfin_target(struct cpufreq_policy *policy, | ||
| 78 | unsigned int target_freq, unsigned int relation) | ||
| 79 | { | ||
| 80 | unsigned int index, plldiv, tscale; | ||
| 81 | unsigned long flags, cclk_hz; | ||
| 82 | struct cpufreq_freqs freqs; | ||
| 83 | |||
| 84 | if (cpufreq_frequency_table_target(policy, bfin_freq_table, | ||
| 85 | target_freq, relation, &index)) | ||
| 86 | return -EINVAL; | ||
| 87 | |||
| 88 | cclk_hz = bfin_freq_table[index].frequency; | ||
| 89 | |||
| 90 | freqs.old = bfin_getfreq(0); | ||
| 91 | freqs.new = cclk_hz; | ||
| 92 | freqs.cpu = 0; | ||
| 93 | |||
| 94 | pr_debug("cpufreq: changing cclk to %lu; target = %u, oldfreq = %u\n", | ||
| 95 | cclk_hz, target_freq, freqs.old); | ||
| 96 | |||
| 97 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
| 98 | local_irq_save(flags); | ||
| 99 | plldiv = (bfin_read_PLL_DIV() & SSEL) | dpm_state_table[index].csel; | ||
| 100 | tscale = dpm_state_table[index].tscale; | ||
| 101 | bfin_write_PLL_DIV(plldiv); | ||
| 102 | /* we have to adjust the core timer, because it is using cclk */ | ||
| 103 | bfin_write_TSCALE(tscale); | ||
| 104 | SSYNC(); | ||
| 105 | local_irq_restore(flags); | ||
| 106 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
| 107 | |||
| 108 | return 0; | ||
| 109 | } | ||
| 110 | |||
| 111 | static int bfin_verify_speed(struct cpufreq_policy *policy) | ||
| 112 | { | ||
| 113 | return cpufreq_frequency_table_verify(policy, bfin_freq_table); | ||
| 114 | } | ||
| 115 | |||
| 116 | static int __init __bfin_cpu_init(struct cpufreq_policy *policy) | ||
| 117 | { | ||
| 118 | |||
| 119 | unsigned long cclk, sclk, csel, min_cclk; | ||
| 120 | int index; | ||
| 121 | |||
| 122 | #ifdef CONFIG_CYCLES_CLOCKSOURCE | ||
| 123 | /* | ||
| 124 | * Clocksource CYCLES is still CONTINUOUS but not longer MONOTONIC in case we enable | ||
| 125 | * CPU frequency scaling, since CYCLES runs off Core Clock. | ||
| 126 | */ | ||
| 127 | printk(KERN_WARNING "CPU frequency scaling not supported: Clocksource not suitable\n" | ||
| 128 | return -ENODEV; | ||
| 129 | #endif | ||
| 130 | |||
| 131 | if (policy->cpu != 0) | ||
| 132 | return -EINVAL; | ||
| 133 | |||
| 134 | cclk = get_cclk(); | ||
| 135 | sclk = get_sclk(); | ||
| 136 | |||
| 137 | #if ANOMALY_05000273 | ||
| 138 | min_cclk = sclk * 2; | ||
| 139 | #else | ||
| 140 | min_cclk = sclk; | ||
| 141 | #endif | ||
| 142 | csel = ((bfin_read_PLL_DIV() & CSEL) >> 4); | ||
| 143 | |||
| 144 | for (index = 0; (cclk >> index) >= min_cclk && csel <= 3; index++, csel++) { | ||
| 145 | bfin_freq_table[index].frequency = cclk >> index; | ||
| 146 | dpm_state_table[index].csel = csel << 4; /* Shift now into PLL_DIV bitpos */ | ||
| 147 | dpm_state_table[index].tscale = (TIME_SCALE / (1 << csel)) - 1; | ||
| 148 | |||
| 149 | pr_debug("cpufreq: freq:%d csel:%d tscale:%d\n", | ||
| 150 | bfin_freq_table[index].frequency, | ||
| 151 | dpm_state_table[index].csel, | ||
| 152 | dpm_state_table[index].tscale); | ||
| 153 | } | ||
| 154 | |||
| 155 | policy->governor = CPUFREQ_DEFAULT_GOVERNOR; | ||
| 156 | |||
| 157 | policy->cpuinfo.transition_latency = (bfin_read_PLL_LOCKCNT() / (sclk / 1000000)) * 1000; | ||
| 158 | /*Now ,only support one cpu */ | ||
| 159 | policy->cur = cclk; | ||
| 160 | cpufreq_frequency_table_get_attr(bfin_freq_table, policy->cpu); | ||
| 161 | return cpufreq_frequency_table_cpuinfo(policy, bfin_freq_table); | ||
| 162 | } | ||
| 163 | |||
| 164 | static struct freq_attr *bfin_freq_attr[] = { | ||
| 165 | &cpufreq_freq_attr_scaling_available_freqs, | ||
| 166 | NULL, | ||
| 167 | }; | ||
| 168 | |||
| 169 | static struct cpufreq_driver bfin_driver = { | ||
| 170 | .verify = bfin_verify_speed, | ||
| 171 | .target = bfin_target, | ||
| 172 | .get = bfin_getfreq, | ||
| 173 | .init = __bfin_cpu_init, | ||
| 174 | .name = "bfin cpufreq", | ||
| 175 | .owner = THIS_MODULE, | ||
| 176 | .attr = bfin_freq_attr, | ||
| 177 | }; | ||
| 178 | |||
| 179 | static int __init bfin_cpu_init(void) | ||
| 180 | { | ||
| 181 | return cpufreq_register_driver(&bfin_driver); | ||
| 182 | } | ||
| 183 | |||
| 184 | static void __exit bfin_cpu_exit(void) | ||
| 185 | { | ||
| 186 | cpufreq_unregister_driver(&bfin_driver); | ||
| 187 | } | ||
| 188 | |||
| 189 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); | ||
| 190 | MODULE_DESCRIPTION("cpufreq driver for Blackfin"); | ||
| 191 | MODULE_LICENSE("GPL"); | ||
| 192 | |||
| 193 | module_init(bfin_cpu_init); | ||
| 194 | module_exit(bfin_cpu_exit); | ||
diff --git a/include/asm-blackfin/time.h b/include/asm-blackfin/time.h new file mode 100644 index 000000000000..6e5859b6ea32 --- /dev/null +++ b/include/asm-blackfin/time.h | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | /* | ||
| 2 | * asm-blackfin/time.h: | ||
| 3 | * | ||
| 4 | * Copyright 2004-2008 Analog Devices Inc. | ||
| 5 | * | ||
| 6 | * Licensed under the GPL-2 or later. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #ifndef _ASM_BLACKFIN_TIME_H | ||
| 10 | #define _ASM_BLACKFIN_TIME_H | ||
| 11 | |||
| 12 | /* | ||
| 13 | * The way that the Blackfin core timer works is: | ||
| 14 | * - CCLK is divided by a programmable 8-bit pre-scaler (TSCALE) | ||
| 15 | * - Every time TSCALE ticks, a 32bit is counted down (TCOUNT) | ||
| 16 | * | ||
| 17 | * If you take the fastest clock (1ns, or 1GHz to make the math work easier) | ||
| 18 | * 10ms is 10,000,000 clock ticks, which fits easy into a 32-bit counter | ||
| 19 | * (32 bit counter is 4,294,967,296ns or 4.2 seconds) so, we don't need | ||
| 20 | * to use TSCALE, and program it to zero (which is pass CCLK through). | ||
| 21 | * If you feel like using it, try to keep HZ * TIMESCALE to some | ||
| 22 | * value that divides easy (like power of 2). | ||
| 23 | */ | ||
| 24 | |||
| 25 | #ifndef CONFIG_CPU_FREQ | ||
| 26 | #define TIME_SCALE 1 | ||
| 27 | #else | ||
| 28 | /* | ||
| 29 | * Blackfin CPU frequency scaling supports max Core Clock 1, 1/2 and 1/4 . | ||
| 30 | * Whenever we change the Core Clock frequency changes we immediately | ||
| 31 | * adjust the Core Timer Presale Register. This way we don't lose time. | ||
| 32 | */ | ||
| 33 | #define TIME_SCALE 4 | ||
| 34 | #endif | ||
| 35 | |||
| 36 | #endif | ||
