summaryrefslogtreecommitdiffstats
path: root/drivers/clocksource
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-07-23 19:31:31 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-07-23 19:31:31 -0400
commitf01b9b73f57f4f92d39bba0d9aa4a38f318212df (patch)
treeb815a4477af34f7f6c61dff0c04db6cb975cdd55 /drivers/clocksource
parentfde75430278130505cac21997cd9f90b7bb2670a (diff)
parent66314223aa5e862c9d1d068cb7186b4fd58ebeaa (diff)
Merge tag 'newsoc' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
Pull support for three new arm SoC types from Arnd Bergmann: - The mvebu platform includes Marvell's Armada XP and Armada 370 chips, made by the mvebu business unit inside of Marvell. Since the same group also made the older but similar platforms we call "orion5x", "kirkwood", "mv78xx0" and "dove", we plan to move all of them into the mach-mvebu directory in the future. - socfpga is Altera's platform based on Cortex-A9 cores and a lot of FPGA space. This is similar to the Xilinx zynq platform we already support. The code is particularly clean, which is helped by the fact that the hardware doesn't do much besides the parts that are expected to get added in the FPGA. - The OMAP subarchitecture gains support for the latest generation, the OMAP5 based on the new Cortex-A15 core. Support is rather rudimentary for now, but will be extended in the future. * tag 'newsoc' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc: (25 commits) ARM: socfpga: initial support for Altera's SOCFPGA platform arm: mvebu: generate DTBs for supported SoCs ARM: mvebu: MPIC: read number of interrupts from control register arm: mach-mvebu: add entry to MAINTAINERS arm: mach-mvebu: add compilation/configuration change arm: mach-mvebu: add defconfig arm: mach-mvebu: add documentation for new device tree bindings arm: mach-mvebu: add support for Armada 370 and Armada XP with DT arm: mach-mvebu: add source files arm: mach-mvebu: add header clocksource: time-armada-370-xp: Marvell Armada 370/XP SoC timer driver ARM: Kconfig update to support additional GPIOs in OMAP5 ARM: OMAP5: Add the build support arm/dts: OMAP5: Add omap5 dts files ARM: OMAP5: board-generic: Add device tree support ARM: omap2+: board-generic: clean up the irq data from board file ARM: OMAP5: Add SMP support ARM: OMAP5: Add the WakeupGen IP updates ARM: OMAP5: l3: Add l3 error handler support for omap5 ARM: OMAP5: gpmc: Update gpmc_init() ... Conflicts: Documentation/devicetree/bindings/arm/omap/omap.txt arch/arm/mach-omap2/Makefile drivers/clocksource/Kconfig drivers/clocksource/Makefile
Diffstat (limited to 'drivers/clocksource')
-rw-r--r--drivers/clocksource/Kconfig3
-rw-r--r--drivers/clocksource/Makefile3
-rw-r--r--drivers/clocksource/time-armada-370-xp.c226
3 files changed, 231 insertions, 1 deletions
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index e62bc7e9d49b..d53cd0afc200 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -19,6 +19,9 @@ config DW_APB_TIMER
19config DW_APB_TIMER_OF 19config DW_APB_TIMER_OF
20 bool 20 bool
21 21
22config ARMADA_370_XP_TIMER
23 bool
24
22config CLKSRC_DBX500_PRCMU 25config CLKSRC_DBX500_PRCMU
23 bool "Clocksource PRCMU Timer" 26 bool "Clocksource PRCMU Timer"
24 depends on UX500_SOC_DB8500 27 depends on UX500_SOC_DB8500
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index 2cdaf7d1019f..b65d0c56ab35 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -11,4 +11,5 @@ obj-$(CONFIG_CLKBLD_I8253) += i8253.o
11obj-$(CONFIG_CLKSRC_MMIO) += mmio.o 11obj-$(CONFIG_CLKSRC_MMIO) += mmio.o
12obj-$(CONFIG_DW_APB_TIMER) += dw_apb_timer.o 12obj-$(CONFIG_DW_APB_TIMER) += dw_apb_timer.o
13obj-$(CONFIG_DW_APB_TIMER_OF) += dw_apb_timer_of.o 13obj-$(CONFIG_DW_APB_TIMER_OF) += dw_apb_timer_of.o
14obj-$(CONFIG_CLKSRC_DBX500_PRCMU) += clksrc-dbx500-prcmu.o \ No newline at end of file 14obj-$(CONFIG_CLKSRC_DBX500_PRCMU) += clksrc-dbx500-prcmu.o
15obj-$(CONFIG_ARMADA_370_XP_TIMER) += time-armada-370-xp.o
diff --git a/drivers/clocksource/time-armada-370-xp.c b/drivers/clocksource/time-armada-370-xp.c
new file mode 100644
index 000000000000..4674f94957cd
--- /dev/null
+++ b/drivers/clocksource/time-armada-370-xp.c
@@ -0,0 +1,226 @@
1/*
2 * Marvell Armada 370/XP SoC timer handling.
3 *
4 * Copyright (C) 2012 Marvell
5 *
6 * Lior Amsalem <alior@marvell.com>
7 * Gregory CLEMENT <gregory.clement@free-electrons.com>
8 * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
9 *
10 * This file is licensed under the terms of the GNU General Public
11 * License version 2. This program is licensed "as is" without any
12 * warranty of any kind, whether express or implied.
13 *
14 * Timer 0 is used as free-running clocksource, while timer 1 is
15 * used as clock_event_device.
16 */
17
18#include <linux/init.h>
19#include <linux/platform_device.h>
20#include <linux/kernel.h>
21#include <linux/timer.h>
22#include <linux/clockchips.h>
23#include <linux/interrupt.h>
24#include <linux/of.h>
25#include <linux/of_irq.h>
26#include <linux/of_address.h>
27#include <linux/irq.h>
28#include <linux/module.h>
29#include <asm/sched_clock.h>
30
31/*
32 * Timer block registers.
33 */
34#define TIMER_CTRL_OFF 0x0000
35#define TIMER0_EN 0x0001
36#define TIMER0_RELOAD_EN 0x0002
37#define TIMER0_25MHZ 0x0800
38#define TIMER0_DIV(div) ((div) << 19)
39#define TIMER1_EN 0x0004
40#define TIMER1_RELOAD_EN 0x0008
41#define TIMER1_25MHZ 0x1000
42#define TIMER1_DIV(div) ((div) << 22)
43#define TIMER_EVENTS_STATUS 0x0004
44#define TIMER0_CLR_MASK (~0x1)
45#define TIMER1_CLR_MASK (~0x100)
46#define TIMER0_RELOAD_OFF 0x0010
47#define TIMER0_VAL_OFF 0x0014
48#define TIMER1_RELOAD_OFF 0x0018
49#define TIMER1_VAL_OFF 0x001c
50
51/* Global timers are connected to the coherency fabric clock, and the
52 below divider reduces their incrementing frequency. */
53#define TIMER_DIVIDER_SHIFT 5
54#define TIMER_DIVIDER (1 << TIMER_DIVIDER_SHIFT)
55
56/*
57 * SoC-specific data.
58 */
59static void __iomem *timer_base;
60static int timer_irq;
61
62/*
63 * Number of timer ticks per jiffy.
64 */
65static u32 ticks_per_jiffy;
66
67static u32 notrace armada_370_xp_read_sched_clock(void)
68{
69 return ~readl(timer_base + TIMER0_VAL_OFF);
70}
71
72/*
73 * Clockevent handling.
74 */
75static int
76armada_370_xp_clkevt_next_event(unsigned long delta,
77 struct clock_event_device *dev)
78{
79 u32 u;
80
81 /*
82 * Clear clockevent timer interrupt.
83 */
84 writel(TIMER1_CLR_MASK, timer_base + TIMER_EVENTS_STATUS);
85
86 /*
87 * Setup new clockevent timer value.
88 */
89 writel(delta, timer_base + TIMER1_VAL_OFF);
90
91 /*
92 * Enable the timer.
93 */
94 u = readl(timer_base + TIMER_CTRL_OFF);
95 u = ((u & ~TIMER1_RELOAD_EN) | TIMER1_EN |
96 TIMER1_DIV(TIMER_DIVIDER_SHIFT));
97 writel(u, timer_base + TIMER_CTRL_OFF);
98
99 return 0;
100}
101
102static void
103armada_370_xp_clkevt_mode(enum clock_event_mode mode,
104 struct clock_event_device *dev)
105{
106 u32 u;
107
108 if (mode == CLOCK_EVT_MODE_PERIODIC) {
109 /*
110 * Setup timer to fire at 1/HZ intervals.
111 */
112 writel(ticks_per_jiffy - 1, timer_base + TIMER1_RELOAD_OFF);
113 writel(ticks_per_jiffy - 1, timer_base + TIMER1_VAL_OFF);
114
115 /*
116 * Enable timer.
117 */
118 u = readl(timer_base + TIMER_CTRL_OFF);
119
120 writel((u | TIMER1_EN | TIMER1_RELOAD_EN |
121 TIMER1_DIV(TIMER_DIVIDER_SHIFT)),
122 timer_base + TIMER_CTRL_OFF);
123 } else {
124 /*
125 * Disable timer.
126 */
127 u = readl(timer_base + TIMER_CTRL_OFF);
128 writel(u & ~TIMER1_EN, timer_base + TIMER_CTRL_OFF);
129
130 /*
131 * ACK pending timer interrupt.
132 */
133 writel(TIMER1_CLR_MASK, timer_base + TIMER_EVENTS_STATUS);
134
135 }
136}
137
138static struct clock_event_device armada_370_xp_clkevt = {
139 .name = "armada_370_xp_tick",
140 .features = CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_PERIODIC,
141 .shift = 32,
142 .rating = 300,
143 .set_next_event = armada_370_xp_clkevt_next_event,
144 .set_mode = armada_370_xp_clkevt_mode,
145};
146
147static irqreturn_t armada_370_xp_timer_interrupt(int irq, void *dev_id)
148{
149 /*
150 * ACK timer interrupt and call event handler.
151 */
152
153 writel(TIMER1_CLR_MASK, timer_base + TIMER_EVENTS_STATUS);
154 armada_370_xp_clkevt.event_handler(&armada_370_xp_clkevt);
155
156 return IRQ_HANDLED;
157}
158
159static struct irqaction armada_370_xp_timer_irq = {
160 .name = "armada_370_xp_tick",
161 .flags = IRQF_DISABLED | IRQF_TIMER,
162 .handler = armada_370_xp_timer_interrupt
163};
164
165void __init armada_370_xp_timer_init(void)
166{
167 u32 u;
168 struct device_node *np;
169 unsigned int timer_clk;
170 int ret;
171 np = of_find_compatible_node(NULL, NULL, "marvell,armada-370-xp-timer");
172 timer_base = of_iomap(np, 0);
173 WARN_ON(!timer_base);
174
175 if (of_find_property(np, "marvell,timer-25Mhz", NULL)) {
176 /* The fixed 25MHz timer is available so let's use it */
177 u = readl(timer_base + TIMER_CTRL_OFF);
178 writel(u | TIMER0_25MHZ | TIMER1_25MHZ,
179 timer_base + TIMER_CTRL_OFF);
180 timer_clk = 25000000;
181 } else {
182 u32 clk = 0;
183 ret = of_property_read_u32(np, "clock-frequency", &clk);
184 WARN_ON(!clk || ret < 0);
185 u = readl(timer_base + TIMER_CTRL_OFF);
186 writel(u & ~(TIMER0_25MHZ | TIMER1_25MHZ),
187 timer_base + TIMER_CTRL_OFF);
188 timer_clk = clk / TIMER_DIVIDER;
189 }
190
191 /* We use timer 0 as clocksource, and timer 1 for
192 clockevents */
193 timer_irq = irq_of_parse_and_map(np, 1);
194
195 ticks_per_jiffy = (timer_clk + HZ / 2) / HZ;
196
197 /*
198 * Set scale and timer for sched_clock.
199 */
200 setup_sched_clock(armada_370_xp_read_sched_clock, 32, timer_clk);
201
202 /*
203 * Setup free-running clocksource timer (interrupts
204 * disabled).
205 */
206 writel(0xffffffff, timer_base + TIMER0_VAL_OFF);
207 writel(0xffffffff, timer_base + TIMER0_RELOAD_OFF);
208
209 u = readl(timer_base + TIMER_CTRL_OFF);
210
211 writel((u | TIMER0_EN | TIMER0_RELOAD_EN |
212 TIMER0_DIV(TIMER_DIVIDER_SHIFT)), timer_base + TIMER_CTRL_OFF);
213
214 clocksource_mmio_init(timer_base + TIMER0_VAL_OFF,
215 "armada_370_xp_clocksource",
216 timer_clk, 300, 32, clocksource_mmio_readl_down);
217
218 /*
219 * Setup clockevent timer (interrupt-driven).
220 */
221 setup_irq(timer_irq, &armada_370_xp_timer_irq);
222 armada_370_xp_clkevt.cpumask = cpumask_of(0);
223 clockevents_config_and_register(&armada_370_xp_clkevt,
224 timer_clk, 1, 0xfffffffe);
225}
226