diff options
Diffstat (limited to 'arch/m68knommu/platform/coldfire')
-rw-r--r-- | arch/m68knommu/platform/coldfire/Makefile | 2 | ||||
-rw-r--r-- | arch/m68knommu/platform/coldfire/dma_timer.c | 84 | ||||
-rw-r--r-- | arch/m68knommu/platform/coldfire/head.S | 3 | ||||
-rw-r--r-- | arch/m68knommu/platform/coldfire/pit.c | 91 |
4 files changed, 165 insertions, 15 deletions
diff --git a/arch/m68knommu/platform/coldfire/Makefile b/arch/m68knommu/platform/coldfire/Makefile index 40cf20be1b90..4f416a91a829 100644 --- a/arch/m68knommu/platform/coldfire/Makefile +++ b/arch/m68knommu/platform/coldfire/Makefile | |||
@@ -18,7 +18,7 @@ obj-$(CONFIG_COLDFIRE) += dma.o entry.o vectors.o | |||
18 | obj-$(CONFIG_M5206) += timers.o | 18 | obj-$(CONFIG_M5206) += timers.o |
19 | obj-$(CONFIG_M5206e) += timers.o | 19 | obj-$(CONFIG_M5206e) += timers.o |
20 | obj-$(CONFIG_M520x) += pit.o | 20 | obj-$(CONFIG_M520x) += pit.o |
21 | obj-$(CONFIG_M523x) += pit.o | 21 | obj-$(CONFIG_M523x) += pit.o dma_timer.o |
22 | obj-$(CONFIG_M5249) += timers.o | 22 | obj-$(CONFIG_M5249) += timers.o |
23 | obj-$(CONFIG_M527x) += pit.o | 23 | obj-$(CONFIG_M527x) += pit.o |
24 | obj-$(CONFIG_M5272) += timers.o | 24 | obj-$(CONFIG_M5272) += timers.o |
diff --git a/arch/m68knommu/platform/coldfire/dma_timer.c b/arch/m68knommu/platform/coldfire/dma_timer.c new file mode 100644 index 000000000000..772578b1084f --- /dev/null +++ b/arch/m68knommu/platform/coldfire/dma_timer.c | |||
@@ -0,0 +1,84 @@ | |||
1 | /* | ||
2 | * dma_timer.c -- Freescale ColdFire DMA Timer. | ||
3 | * | ||
4 | * Copyright (C) 2007, Benedikt Spranger <b.spranger@linutronix.de> | ||
5 | * Copyright (C) 2008. Sebastian Siewior, Linutronix | ||
6 | * | ||
7 | */ | ||
8 | |||
9 | #include <linux/clocksource.h> | ||
10 | #include <linux/io.h> | ||
11 | |||
12 | #include <asm/machdep.h> | ||
13 | #include <asm/coldfire.h> | ||
14 | #include <asm/mcfpit.h> | ||
15 | #include <asm/mcfsim.h> | ||
16 | |||
17 | #define DMA_TIMER_0 (0x00) | ||
18 | #define DMA_TIMER_1 (0x40) | ||
19 | #define DMA_TIMER_2 (0x80) | ||
20 | #define DMA_TIMER_3 (0xc0) | ||
21 | |||
22 | #define DTMR0 (MCF_IPSBAR + DMA_TIMER_0 + 0x400) | ||
23 | #define DTXMR0 (MCF_IPSBAR + DMA_TIMER_0 + 0x402) | ||
24 | #define DTER0 (MCF_IPSBAR + DMA_TIMER_0 + 0x403) | ||
25 | #define DTRR0 (MCF_IPSBAR + DMA_TIMER_0 + 0x404) | ||
26 | #define DTCR0 (MCF_IPSBAR + DMA_TIMER_0 + 0x408) | ||
27 | #define DTCN0 (MCF_IPSBAR + DMA_TIMER_0 + 0x40c) | ||
28 | |||
29 | #define DMA_FREQ ((MCF_CLK / 2) / 16) | ||
30 | |||
31 | /* DTMR */ | ||
32 | #define DMA_DTMR_RESTART (1 << 3) | ||
33 | #define DMA_DTMR_CLK_DIV_1 (1 << 1) | ||
34 | #define DMA_DTMR_CLK_DIV_16 (2 << 1) | ||
35 | #define DMA_DTMR_ENABLE (1 << 0) | ||
36 | |||
37 | static cycle_t cf_dt_get_cycles(void) | ||
38 | { | ||
39 | return __raw_readl(DTCN0); | ||
40 | } | ||
41 | |||
42 | static struct clocksource clocksource_cf_dt = { | ||
43 | .name = "coldfire_dma_timer", | ||
44 | .rating = 200, | ||
45 | .read = cf_dt_get_cycles, | ||
46 | .mask = CLOCKSOURCE_MASK(32), | ||
47 | .shift = 20, | ||
48 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, | ||
49 | }; | ||
50 | |||
51 | static int __init init_cf_dt_clocksource(void) | ||
52 | { | ||
53 | /* | ||
54 | * We setup DMA timer 0 in free run mode. This incrementing counter is | ||
55 | * used as a highly precious clock source. With MCF_CLOCK = 150 MHz we | ||
56 | * get a ~213 ns resolution and the 32bit register will overflow almost | ||
57 | * every 15 minutes. | ||
58 | */ | ||
59 | __raw_writeb(0x00, DTXMR0); | ||
60 | __raw_writeb(0x00, DTER0); | ||
61 | __raw_writel(0x00000000, DTRR0); | ||
62 | __raw_writew(DMA_DTMR_CLK_DIV_16 | DMA_DTMR_ENABLE, DTMR0); | ||
63 | clocksource_cf_dt.mult = clocksource_hz2mult(DMA_FREQ, | ||
64 | clocksource_cf_dt.shift); | ||
65 | return clocksource_register(&clocksource_cf_dt); | ||
66 | } | ||
67 | |||
68 | arch_initcall(init_cf_dt_clocksource); | ||
69 | |||
70 | #define CYC2NS_SCALE_FACTOR 10 /* 2^10, carefully chosen */ | ||
71 | #define CYC2NS_SCALE ((1000000 << CYC2NS_SCALE_FACTOR) / (DMA_FREQ / 1000)) | ||
72 | |||
73 | static unsigned long long cycles2ns(unsigned long cycl) | ||
74 | { | ||
75 | return (unsigned long long) ((unsigned long long)cycl * | ||
76 | CYC2NS_SCALE) >> CYC2NS_SCALE_FACTOR; | ||
77 | } | ||
78 | |||
79 | unsigned long long sched_clock(void) | ||
80 | { | ||
81 | unsigned long cycl = __raw_readl(DTCN0); | ||
82 | |||
83 | return cycles2ns(cycl); | ||
84 | } | ||
diff --git a/arch/m68knommu/platform/coldfire/head.S b/arch/m68knommu/platform/coldfire/head.S index b9aa0ca29bfb..2b0d73c0cc32 100644 --- a/arch/m68knommu/platform/coldfire/head.S +++ b/arch/m68knommu/platform/coldfire/head.S | |||
@@ -10,6 +10,7 @@ | |||
10 | 10 | ||
11 | #include <linux/sys.h> | 11 | #include <linux/sys.h> |
12 | #include <linux/linkage.h> | 12 | #include <linux/linkage.h> |
13 | #include <linux/init.h> | ||
13 | #include <asm/asm-offsets.h> | 14 | #include <asm/asm-offsets.h> |
14 | #include <asm/coldfire.h> | 15 | #include <asm/coldfire.h> |
15 | #include <asm/mcfcache.h> | 16 | #include <asm/mcfcache.h> |
@@ -126,7 +127,7 @@ _ramend: | |||
126 | 127 | ||
127 | /*****************************************************************************/ | 128 | /*****************************************************************************/ |
128 | 129 | ||
129 | .text | 130 | __HEAD |
130 | 131 | ||
131 | /* | 132 | /* |
132 | * This is the codes first entry point. This is where it all | 133 | * This is the codes first entry point. This is where it all |
diff --git a/arch/m68knommu/platform/coldfire/pit.c b/arch/m68knommu/platform/coldfire/pit.c index 4290638012e0..c5b916700b22 100644 --- a/arch/m68knommu/platform/coldfire/pit.c +++ b/arch/m68knommu/platform/coldfire/pit.c | |||
@@ -18,7 +18,7 @@ | |||
18 | #include <linux/init.h> | 18 | #include <linux/init.h> |
19 | #include <linux/interrupt.h> | 19 | #include <linux/interrupt.h> |
20 | #include <linux/irq.h> | 20 | #include <linux/irq.h> |
21 | #include <linux/clocksource.h> | 21 | #include <linux/clockchips.h> |
22 | #include <asm/machdep.h> | 22 | #include <asm/machdep.h> |
23 | #include <asm/io.h> | 23 | #include <asm/io.h> |
24 | #include <asm/coldfire.h> | 24 | #include <asm/coldfire.h> |
@@ -33,22 +33,86 @@ | |||
33 | #define FREQ ((MCF_CLK / 2) / 64) | 33 | #define FREQ ((MCF_CLK / 2) / 64) |
34 | #define TA(a) (MCF_IPSBAR + MCFPIT_BASE1 + (a)) | 34 | #define TA(a) (MCF_IPSBAR + MCFPIT_BASE1 + (a)) |
35 | #define INTC0 (MCF_IPSBAR + MCFICM_INTC0) | 35 | #define INTC0 (MCF_IPSBAR + MCFICM_INTC0) |
36 | #define PIT_CYCLES_PER_JIFFY (FREQ / HZ) | ||
36 | 37 | ||
37 | static u32 pit_cycles_per_jiffy; | ||
38 | static u32 pit_cnt; | 38 | static u32 pit_cnt; |
39 | 39 | ||
40 | /* | ||
41 | * Initialize the PIT timer. | ||
42 | * | ||
43 | * This is also called after resume to bring the PIT into operation again. | ||
44 | */ | ||
45 | |||
46 | static void init_cf_pit_timer(enum clock_event_mode mode, | ||
47 | struct clock_event_device *evt) | ||
48 | { | ||
49 | switch (mode) { | ||
50 | case CLOCK_EVT_MODE_PERIODIC: | ||
51 | |||
52 | __raw_writew(MCFPIT_PCSR_DISABLE, TA(MCFPIT_PCSR)); | ||
53 | __raw_writew(PIT_CYCLES_PER_JIFFY, TA(MCFPIT_PMR)); | ||
54 | __raw_writew(MCFPIT_PCSR_EN | MCFPIT_PCSR_PIE | \ | ||
55 | MCFPIT_PCSR_OVW | MCFPIT_PCSR_RLD | \ | ||
56 | MCFPIT_PCSR_CLK64, TA(MCFPIT_PCSR)); | ||
57 | break; | ||
58 | |||
59 | case CLOCK_EVT_MODE_SHUTDOWN: | ||
60 | case CLOCK_EVT_MODE_UNUSED: | ||
61 | |||
62 | __raw_writew(MCFPIT_PCSR_DISABLE, TA(MCFPIT_PCSR)); | ||
63 | break; | ||
64 | |||
65 | case CLOCK_EVT_MODE_ONESHOT: | ||
66 | |||
67 | __raw_writew(MCFPIT_PCSR_DISABLE, TA(MCFPIT_PCSR)); | ||
68 | __raw_writew(MCFPIT_PCSR_EN | MCFPIT_PCSR_PIE | \ | ||
69 | MCFPIT_PCSR_OVW | MCFPIT_PCSR_CLK64, \ | ||
70 | TA(MCFPIT_PCSR)); | ||
71 | break; | ||
72 | |||
73 | case CLOCK_EVT_MODE_RESUME: | ||
74 | /* Nothing to do here */ | ||
75 | break; | ||
76 | } | ||
77 | } | ||
78 | |||
79 | /* | ||
80 | * Program the next event in oneshot mode | ||
81 | * | ||
82 | * Delta is given in PIT ticks | ||
83 | */ | ||
84 | static int cf_pit_next_event(unsigned long delta, | ||
85 | struct clock_event_device *evt) | ||
86 | { | ||
87 | __raw_writew(delta, TA(MCFPIT_PMR)); | ||
88 | return 0; | ||
89 | } | ||
90 | |||
91 | struct clock_event_device cf_pit_clockevent = { | ||
92 | .name = "pit", | ||
93 | .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT, | ||
94 | .set_mode = init_cf_pit_timer, | ||
95 | .set_next_event = cf_pit_next_event, | ||
96 | .shift = 32, | ||
97 | .irq = MCFINT_VECBASE + MCFINT_PIT1, | ||
98 | }; | ||
99 | |||
100 | |||
101 | |||
40 | /***************************************************************************/ | 102 | /***************************************************************************/ |
41 | 103 | ||
42 | static irqreturn_t pit_tick(int irq, void *dummy) | 104 | static irqreturn_t pit_tick(int irq, void *dummy) |
43 | { | 105 | { |
106 | struct clock_event_device *evt = &cf_pit_clockevent; | ||
44 | u16 pcsr; | 107 | u16 pcsr; |
45 | 108 | ||
46 | /* Reset the ColdFire timer */ | 109 | /* Reset the ColdFire timer */ |
47 | pcsr = __raw_readw(TA(MCFPIT_PCSR)); | 110 | pcsr = __raw_readw(TA(MCFPIT_PCSR)); |
48 | __raw_writew(pcsr | MCFPIT_PCSR_PIF, TA(MCFPIT_PCSR)); | 111 | __raw_writew(pcsr | MCFPIT_PCSR_PIF, TA(MCFPIT_PCSR)); |
49 | 112 | ||
50 | pit_cnt += pit_cycles_per_jiffy; | 113 | pit_cnt += PIT_CYCLES_PER_JIFFY; |
51 | return arch_timer_interrupt(irq, dummy); | 114 | evt->event_handler(evt); |
115 | return IRQ_HANDLED; | ||
52 | } | 116 | } |
53 | 117 | ||
54 | /***************************************************************************/ | 118 | /***************************************************************************/ |
@@ -72,14 +136,14 @@ static cycle_t pit_read_clk(void) | |||
72 | cycles = pit_cnt; | 136 | cycles = pit_cnt; |
73 | local_irq_restore(flags); | 137 | local_irq_restore(flags); |
74 | 138 | ||
75 | return cycles + pit_cycles_per_jiffy - pcntr; | 139 | return cycles + PIT_CYCLES_PER_JIFFY - pcntr; |
76 | } | 140 | } |
77 | 141 | ||
78 | /***************************************************************************/ | 142 | /***************************************************************************/ |
79 | 143 | ||
80 | static struct clocksource pit_clk = { | 144 | static struct clocksource pit_clk = { |
81 | .name = "pit", | 145 | .name = "pit", |
82 | .rating = 250, | 146 | .rating = 100, |
83 | .read = pit_read_clk, | 147 | .read = pit_read_clk, |
84 | .shift = 20, | 148 | .shift = 20, |
85 | .mask = CLOCKSOURCE_MASK(32), | 149 | .mask = CLOCKSOURCE_MASK(32), |
@@ -92,6 +156,14 @@ void hw_timer_init(void) | |||
92 | { | 156 | { |
93 | u32 imr; | 157 | u32 imr; |
94 | 158 | ||
159 | cf_pit_clockevent.cpumask = cpumask_of_cpu(smp_processor_id()); | ||
160 | cf_pit_clockevent.mult = div_sc(FREQ, NSEC_PER_SEC, 32); | ||
161 | cf_pit_clockevent.max_delta_ns = | ||
162 | clockevent_delta2ns(0xFFFF, &cf_pit_clockevent); | ||
163 | cf_pit_clockevent.min_delta_ns = | ||
164 | clockevent_delta2ns(0x3f, &cf_pit_clockevent); | ||
165 | clockevents_register_device(&cf_pit_clockevent); | ||
166 | |||
95 | setup_irq(MCFINT_VECBASE + MCFINT_PIT1, &pit_irq); | 167 | setup_irq(MCFINT_VECBASE + MCFINT_PIT1, &pit_irq); |
96 | 168 | ||
97 | __raw_writeb(ICR_INTRCONF, INTC0 + MCFINTC_ICR0 + MCFINT_PIT1); | 169 | __raw_writeb(ICR_INTRCONF, INTC0 + MCFINTC_ICR0 + MCFINT_PIT1); |
@@ -99,13 +171,6 @@ void hw_timer_init(void) | |||
99 | imr &= ~MCFPIT_IMR_IBIT; | 171 | imr &= ~MCFPIT_IMR_IBIT; |
100 | __raw_writel(imr, INTC0 + MCFPIT_IMR); | 172 | __raw_writel(imr, INTC0 + MCFPIT_IMR); |
101 | 173 | ||
102 | /* Set up PIT timer 1 as poll clock */ | ||
103 | pit_cycles_per_jiffy = FREQ / HZ; | ||
104 | __raw_writew(MCFPIT_PCSR_DISABLE, TA(MCFPIT_PCSR)); | ||
105 | __raw_writew(pit_cycles_per_jiffy, TA(MCFPIT_PMR)); | ||
106 | __raw_writew(MCFPIT_PCSR_EN | MCFPIT_PCSR_PIE | MCFPIT_PCSR_OVW | | ||
107 | MCFPIT_PCSR_RLD | MCFPIT_PCSR_CLK64, TA(MCFPIT_PCSR)); | ||
108 | |||
109 | pit_clk.mult = clocksource_hz2mult(FREQ, pit_clk.shift); | 174 | pit_clk.mult = clocksource_hz2mult(FREQ, pit_clk.shift); |
110 | clocksource_register(&pit_clk); | 175 | clocksource_register(&pit_clk); |
111 | } | 176 | } |