diff options
author | Alessandro Rubini <rubini@gnudd.com> | 2010-03-05 06:38:51 -0500 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2010-03-19 14:31:51 -0400 |
commit | b102c01faed5e0083a4e6d29a2d61f6b57716e94 (patch) | |
tree | 2988fc53122d3b2ddea58791bf7bb4a819b07b0c /arch/arm/plat-nomadik | |
parent | 94bdc0e2d76c5f2467346bf14e7e16d6d8e0395d (diff) |
ARM: 5978/1: plat-nomadik: use one-shot clock events
This is a complete rewrite of the MTU driver, using one-shot
for events and a free-running timer for stamping. It allows
CONFIG_NO_HZ and CONFIG_HIGH_RES_TIMERS to work on Nomadik and Ux500.
Signed-off-by: Alessandro Rubini <rubini@unipv.it>
Acked-by: Linus Walleij <linus.walleij@stericsson.com>
Acked-by: Andrea Gallo <andrea.gallo@stericsson.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'arch/arm/plat-nomadik')
-rw-r--r-- | arch/arm/plat-nomadik/timer.c | 125 |
1 files changed, 63 insertions, 62 deletions
diff --git a/arch/arm/plat-nomadik/timer.c b/arch/arm/plat-nomadik/timer.c index fa7cb3a57cbf..db67402518a6 100644 --- a/arch/arm/plat-nomadik/timer.c +++ b/arch/arm/plat-nomadik/timer.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * linux/arch/arm/mach-nomadik/timer.c | 2 | * linux/arch/arm/mach-nomadik/timer.c |
3 | * | 3 | * |
4 | * Copyright (C) 2008 STMicroelectronics | 4 | * Copyright (C) 2008 STMicroelectronics |
5 | * Copyright (C) 2009 Alessandro Rubini, somewhat based on at91sam926x | 5 | * Copyright (C) 2010 Alessandro Rubini |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License version 2, as | 8 | * it under the terms of the GNU General Public License version 2, as |
@@ -18,123 +18,124 @@ | |||
18 | 18 | ||
19 | #include <plat/mtu.h> | 19 | #include <plat/mtu.h> |
20 | 20 | ||
21 | static u32 nmdk_count; /* accumulated count */ | 21 | void __iomem *mtu_base; /* ssigned by machine code */ |
22 | static u32 nmdk_cycle; /* write-once */ | ||
23 | 22 | ||
24 | /* setup by the platform code */ | 23 | /* clocksource: MTU decrements, so we negate the value being read. */ |
25 | void __iomem *mtu_base; | ||
26 | |||
27 | /* | ||
28 | * clocksource: the MTU device is a decrementing counters, so we negate | ||
29 | * the value being read. | ||
30 | */ | ||
31 | static cycle_t nmdk_read_timer(struct clocksource *cs) | 24 | static cycle_t nmdk_read_timer(struct clocksource *cs) |
32 | { | 25 | { |
33 | u32 count = readl(mtu_base + MTU_VAL(0)); | 26 | return -readl(mtu_base + MTU_VAL(0)); |
34 | return nmdk_count + nmdk_cycle - count; | ||
35 | |||
36 | } | 27 | } |
37 | 28 | ||
38 | static struct clocksource nmdk_clksrc = { | 29 | static struct clocksource nmdk_clksrc = { |
39 | .name = "mtu_0", | 30 | .name = "mtu_0", |
40 | .rating = 120, | 31 | .rating = 200, |
41 | .read = nmdk_read_timer, | 32 | .read = nmdk_read_timer, |
33 | .mask = CLOCKSOURCE_MASK(32), | ||
42 | .shift = 20, | 34 | .shift = 20, |
43 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, | 35 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
44 | }; | 36 | }; |
45 | 37 | ||
46 | /* | 38 | /* Clockevent device: use one-shot mode */ |
47 | * Clockevent device: currently only periodic mode is supported | ||
48 | */ | ||
49 | static void nmdk_clkevt_mode(enum clock_event_mode mode, | 39 | static void nmdk_clkevt_mode(enum clock_event_mode mode, |
50 | struct clock_event_device *dev) | 40 | struct clock_event_device *dev) |
51 | { | 41 | { |
42 | u32 cr; | ||
43 | |||
52 | switch (mode) { | 44 | switch (mode) { |
53 | case CLOCK_EVT_MODE_PERIODIC: | 45 | case CLOCK_EVT_MODE_PERIODIC: |
54 | /* count current value? */ | 46 | pr_err("%s: periodic mode not supported\n", __func__); |
55 | writel(readl(mtu_base + MTU_IMSC) | 1, mtu_base + MTU_IMSC); | ||
56 | break; | 47 | break; |
57 | case CLOCK_EVT_MODE_ONESHOT: | 48 | case CLOCK_EVT_MODE_ONESHOT: |
58 | BUG(); /* Not supported, yet */ | 49 | /* Load highest value, enable device, enable interrupts */ |
59 | /* FALLTHROUGH */ | 50 | cr = readl(mtu_base + MTU_CR(1)); |
51 | writel(0, mtu_base + MTU_LR(1)); | ||
52 | writel(cr | MTU_CRn_ENA, mtu_base + MTU_CR(1)); | ||
53 | writel(0x2, mtu_base + MTU_IMSC); | ||
54 | break; | ||
60 | case CLOCK_EVT_MODE_SHUTDOWN: | 55 | case CLOCK_EVT_MODE_SHUTDOWN: |
61 | case CLOCK_EVT_MODE_UNUSED: | 56 | case CLOCK_EVT_MODE_UNUSED: |
62 | writel(readl(mtu_base + MTU_IMSC) & ~1, mtu_base + MTU_IMSC); | 57 | /* disable irq */ |
58 | writel(0, mtu_base + MTU_IMSC); | ||
63 | break; | 59 | break; |
64 | case CLOCK_EVT_MODE_RESUME: | 60 | case CLOCK_EVT_MODE_RESUME: |
65 | break; | 61 | break; |
66 | } | 62 | } |
67 | } | 63 | } |
68 | 64 | ||
65 | static int nmdk_clkevt_next(unsigned long evt, struct clock_event_device *ev) | ||
66 | { | ||
67 | /* writing the value has immediate effect */ | ||
68 | writel(evt, mtu_base + MTU_LR(1)); | ||
69 | return 0; | ||
70 | } | ||
71 | |||
69 | static struct clock_event_device nmdk_clkevt = { | 72 | static struct clock_event_device nmdk_clkevt = { |
70 | .name = "mtu_0", | 73 | .name = "mtu_1", |
71 | .features = CLOCK_EVT_FEAT_PERIODIC, | 74 | .features = CLOCK_EVT_FEAT_ONESHOT, |
72 | .shift = 32, | 75 | .shift = 32, |
73 | .rating = 100, | 76 | .rating = 200, |
74 | .set_mode = nmdk_clkevt_mode, | 77 | .set_mode = nmdk_clkevt_mode, |
78 | .set_next_event = nmdk_clkevt_next, | ||
75 | }; | 79 | }; |
76 | 80 | ||
77 | /* | 81 | /* |
78 | * IRQ Handler for the timer 0 of the MTU block. The irq is not shared | 82 | * IRQ Handler for timer 1 of the MTU block. |
79 | * as we are the only users of mtu0 by now. | ||
80 | */ | 83 | */ |
81 | static irqreturn_t nmdk_timer_interrupt(int irq, void *dev_id) | 84 | static irqreturn_t nmdk_timer_interrupt(int irq, void *dev_id) |
82 | { | 85 | { |
83 | /* ack: "interrupt clear register" */ | 86 | struct clock_event_device *evdev = dev_id; |
84 | writel(1 << 0, mtu_base + MTU_ICR); | ||
85 | |||
86 | /* we can't count lost ticks, unfortunately */ | ||
87 | nmdk_count += nmdk_cycle; | ||
88 | nmdk_clkevt.event_handler(&nmdk_clkevt); | ||
89 | 87 | ||
88 | writel(1 << 1, mtu_base + MTU_ICR); /* Interrupt clear reg */ | ||
89 | evdev->event_handler(evdev); | ||
90 | return IRQ_HANDLED; | 90 | return IRQ_HANDLED; |
91 | } | 91 | } |
92 | 92 | ||
93 | /* | ||
94 | * Set up timer interrupt, and return the current time in seconds. | ||
95 | */ | ||
96 | static struct irqaction nmdk_timer_irq = { | 93 | static struct irqaction nmdk_timer_irq = { |
97 | .name = "Nomadik Timer Tick", | 94 | .name = "Nomadik Timer Tick", |
98 | .flags = IRQF_DISABLED | IRQF_TIMER, | 95 | .flags = IRQF_DISABLED | IRQF_TIMER, |
99 | .handler = nmdk_timer_interrupt, | 96 | .handler = nmdk_timer_interrupt, |
97 | .dev_id = &nmdk_clkevt, | ||
100 | }; | 98 | }; |
101 | 99 | ||
102 | static void nmdk_timer_reset(void) | ||
103 | { | ||
104 | u32 cr; | ||
105 | |||
106 | writel(0, mtu_base + MTU_CR(0)); /* off */ | ||
107 | |||
108 | /* configure load and background-load, and fire it up */ | ||
109 | writel(nmdk_cycle, mtu_base + MTU_LR(0)); | ||
110 | writel(nmdk_cycle, mtu_base + MTU_BGLR(0)); | ||
111 | cr = MTU_CRn_PERIODIC | MTU_CRn_PRESCALE_1 | MTU_CRn_32BITS; | ||
112 | writel(cr, mtu_base + MTU_CR(0)); | ||
113 | writel(cr | MTU_CRn_ENA, mtu_base + MTU_CR(0)); | ||
114 | } | ||
115 | |||
116 | void __init nmdk_timer_init(void) | 100 | void __init nmdk_timer_init(void) |
117 | { | 101 | { |
118 | unsigned long rate; | 102 | unsigned long rate; |
119 | int bits; | 103 | u32 cr = MTU_CRn_32BITS;; |
120 | 104 | ||
121 | rate = CLOCK_TICK_RATE; /* 2.4MHz */ | 105 | /* |
122 | nmdk_cycle = (rate + HZ/2) / HZ; | 106 | * Tick rate is 2.4MHz for Nomadik and 110MHz for ux500: |
107 | * use a divide-by-16 counter if it's more than 16MHz | ||
108 | */ | ||
109 | rate = CLOCK_TICK_RATE; | ||
110 | if (rate > 16 << 20) { | ||
111 | rate /= 16; | ||
112 | cr |= MTU_CRn_PRESCALE_16; | ||
113 | } else { | ||
114 | cr |= MTU_CRn_PRESCALE_1; | ||
115 | } | ||
123 | 116 | ||
124 | /* Init the timer and register clocksource */ | 117 | /* Timer 0 is the free running clocksource */ |
125 | nmdk_timer_reset(); | 118 | writel(cr, mtu_base + MTU_CR(0)); |
119 | writel(0, mtu_base + MTU_LR(0)); | ||
120 | writel(0, mtu_base + MTU_BGLR(0)); | ||
121 | writel(cr | MTU_CRn_ENA, mtu_base + MTU_CR(0)); | ||
126 | 122 | ||
127 | nmdk_clksrc.mult = clocksource_hz2mult(rate, nmdk_clksrc.shift); | 123 | nmdk_clksrc.mult = clocksource_hz2mult(rate, nmdk_clksrc.shift); |
128 | bits = 8*sizeof(nmdk_count); | ||
129 | nmdk_clksrc.mask = CLOCKSOURCE_MASK(bits); | ||
130 | 124 | ||
131 | if (clocksource_register(&nmdk_clksrc)) | 125 | if (clocksource_register(&nmdk_clksrc)) |
132 | printk(KERN_ERR "timer: failed to initialize clock " | 126 | pr_err("timer: failed to initialize clock source %s\n", |
133 | "source %s\n", nmdk_clksrc.name); | 127 | nmdk_clksrc.name); |
128 | |||
129 | /* Timer 1 is used for events, fix according to rate */ | ||
130 | writel(cr | MTU_CRn_ONESHOT, mtu_base + MTU_CR(1)); /* off, currently */ | ||
131 | nmdk_clkevt.mult = div_sc(rate, NSEC_PER_SEC, nmdk_clkevt.shift); | ||
132 | nmdk_clkevt.max_delta_ns = | ||
133 | clockevent_delta2ns(0xffffffff, &nmdk_clkevt); | ||
134 | nmdk_clkevt.min_delta_ns = | ||
135 | clockevent_delta2ns(0x00000002, &nmdk_clkevt); | ||
136 | nmdk_clkevt.cpumask = cpumask_of(0); | ||
134 | 137 | ||
135 | /* Register irq and clockevents */ | 138 | /* Register irq and clockevents */ |
136 | setup_irq(IRQ_MTU0, &nmdk_timer_irq); | 139 | setup_irq(IRQ_MTU0, &nmdk_timer_irq); |
137 | nmdk_clkevt.mult = div_sc(rate, NSEC_PER_SEC, nmdk_clkevt.shift); | ||
138 | nmdk_clkevt.cpumask = cpumask_of(0); | ||
139 | clockevents_register_device(&nmdk_clkevt); | 140 | clockevents_register_device(&nmdk_clkevt); |
140 | } | 141 | } |