aboutsummaryrefslogtreecommitdiffstats
path: root/arch/blackfin/kernel
diff options
context:
space:
mode:
authorMichael Hennerich <michael.hennerich@analog.com>2008-04-24 16:58:29 -0400
committerBryan Wu <cooloney@kernel.org>2008-04-24 16:58:29 -0400
commite6c91b64dd6e4c3adf39483c85a936eef9465e19 (patch)
treefb21af3166c55866dd587dd30c3807e9218054a9 /arch/blackfin/kernel
parentfe44193c55e26b9b835722b5ee2519972f59c540 (diff)
[Blackfin] arch: Functional power management support: Add support for cpu frequency scaling
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com> Signed-off-by: Bryan Wu <cooloney@kernel.org>
Diffstat (limited to 'arch/blackfin/kernel')
-rw-r--r--arch/blackfin/kernel/time-ts.c30
-rw-r--r--arch/blackfin/kernel/time.c19
2 files changed, 31 insertions, 18 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
24static unsigned long cyc2ns_scale; 48static 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
65static void 52static void
66time_sched_init(irq_handler_t timer_routine) 53time_sched_init(irq_handler_t timer_routine)
67{ 54{