diff options
author | Russell King <rmk+kernel@arm.linux.org.uk> | 2011-05-08 09:06:52 -0400 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2011-05-23 13:04:51 -0400 |
commit | 442c8176d2efa468577738e3a99a6e051f6e8e55 (patch) | |
tree | fcf309e5f23b60b96e95ef22d70bb5f0e473c512 /drivers/clocksource | |
parent | 1ba4c3cb171d9899a3eaa2e45fa171e0704c1377 (diff) |
clocksource: add common mmio clocksource
Add a generic mmio clocksource, covering both 32-bit and 16-bit register
access sizes, for up or down counters. This can be used to easily
create clocksources for simple counter-based implementations.
Cc: Alessandro Rubini <rubini@unipv.it>
Cc: Colin Cross <ccross@android.com>
Cc: Eric Miao <eric.y.miao@gmail.com>
Cc: Erik Gilling <konkers@android.com>
Acked-by: "Hans J. Koch" <hjk@hansjkoch.de>
Cc: Imre Kaloz <kaloz@openwrt.org>
Cc: Krzysztof Halasa <khc@pm.waw.pl>
Cc: Kukjin Kim <kgene.kim@samsung.com>
Cc: Lennert Buytenhek <kernel@wantstofly.org>
Cc: Linus Walleij <linus.walleij@stericsson.com>
Cc: linux-omap@vger.kernel.org
Acked-by: Nicolas Pitre <nico@fluxnic.net>
Cc: Olof Johansson <olof@lixom.net>
Tested-by: Sascha Hauer <s.hauer@pengutronix.de>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Viresh Kumar <viresh.kumar@st.com>
Cc: Wan ZongShun <mcuos.com@gmail.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'drivers/clocksource')
-rw-r--r-- | drivers/clocksource/Kconfig | 3 | ||||
-rw-r--r-- | drivers/clocksource/Makefile | 1 | ||||
-rw-r--r-- | drivers/clocksource/mmio.c | 73 |
3 files changed, 77 insertions, 0 deletions
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index 110aeeb52f9a..96c921910469 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig | |||
@@ -1,2 +1,5 @@ | |||
1 | config CLKSRC_I8253 | 1 | config CLKSRC_I8253 |
2 | bool | 2 | bool |
3 | |||
4 | config CLKSRC_MMIO | ||
5 | bool | ||
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile index cfb6383b543a..b995942a5060 100644 --- a/drivers/clocksource/Makefile +++ b/drivers/clocksource/Makefile | |||
@@ -7,3 +7,4 @@ obj-$(CONFIG_SH_TIMER_CMT) += sh_cmt.o | |||
7 | obj-$(CONFIG_SH_TIMER_MTU2) += sh_mtu2.o | 7 | obj-$(CONFIG_SH_TIMER_MTU2) += sh_mtu2.o |
8 | obj-$(CONFIG_SH_TIMER_TMU) += sh_tmu.o | 8 | obj-$(CONFIG_SH_TIMER_TMU) += sh_tmu.o |
9 | obj-$(CONFIG_CLKSRC_I8253) += i8253.o | 9 | obj-$(CONFIG_CLKSRC_I8253) += i8253.o |
10 | obj-$(CONFIG_CLKSRC_MMIO) += mmio.o | ||
diff --git a/drivers/clocksource/mmio.c b/drivers/clocksource/mmio.c new file mode 100644 index 000000000000..c0e25125a55e --- /dev/null +++ b/drivers/clocksource/mmio.c | |||
@@ -0,0 +1,73 @@ | |||
1 | /* | ||
2 | * Generic MMIO clocksource support | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 as | ||
6 | * published by the Free Software Foundation. | ||
7 | */ | ||
8 | #include <linux/clocksource.h> | ||
9 | #include <linux/errno.h> | ||
10 | #include <linux/init.h> | ||
11 | #include <linux/slab.h> | ||
12 | |||
13 | struct clocksource_mmio { | ||
14 | void __iomem *reg; | ||
15 | struct clocksource clksrc; | ||
16 | }; | ||
17 | |||
18 | static inline struct clocksource_mmio *to_mmio_clksrc(struct clocksource *c) | ||
19 | { | ||
20 | return container_of(c, struct clocksource_mmio, clksrc); | ||
21 | } | ||
22 | |||
23 | cycle_t clocksource_mmio_readl_up(struct clocksource *c) | ||
24 | { | ||
25 | return readl_relaxed(to_mmio_clksrc(c)->reg); | ||
26 | } | ||
27 | |||
28 | cycle_t clocksource_mmio_readl_down(struct clocksource *c) | ||
29 | { | ||
30 | return ~readl_relaxed(to_mmio_clksrc(c)->reg); | ||
31 | } | ||
32 | |||
33 | cycle_t clocksource_mmio_readw_up(struct clocksource *c) | ||
34 | { | ||
35 | return readw_relaxed(to_mmio_clksrc(c)->reg); | ||
36 | } | ||
37 | |||
38 | cycle_t clocksource_mmio_readw_down(struct clocksource *c) | ||
39 | { | ||
40 | return ~(unsigned)readw_relaxed(to_mmio_clksrc(c)->reg); | ||
41 | } | ||
42 | |||
43 | /** | ||
44 | * clocksource_mmio_init - Initialize a simple mmio based clocksource | ||
45 | * @base: Virtual address of the clock readout register | ||
46 | * @name: Name of the clocksource | ||
47 | * @hz: Frequency of the clocksource in Hz | ||
48 | * @rating: Rating of the clocksource | ||
49 | * @bits: Number of valid bits | ||
50 | * @read: One of clocksource_mmio_read*() above | ||
51 | */ | ||
52 | int __init clocksource_mmio_init(void __iomem *base, const char *name, | ||
53 | unsigned long hz, int rating, unsigned bits, | ||
54 | cycle_t (*read)(struct clocksource *)) | ||
55 | { | ||
56 | struct clocksource_mmio *cs; | ||
57 | |||
58 | if (bits > 32 || bits < 16) | ||
59 | return -EINVAL; | ||
60 | |||
61 | cs = kzalloc(sizeof(struct clocksource_mmio), GFP_KERNEL); | ||
62 | if (!cs) | ||
63 | return -ENOMEM; | ||
64 | |||
65 | cs->reg = base; | ||
66 | cs->clksrc.name = name; | ||
67 | cs->clksrc.rating = rating; | ||
68 | cs->clksrc.read = read; | ||
69 | cs->clksrc.mask = CLOCKSOURCE_MASK(bits); | ||
70 | cs->clksrc.flags = CLOCK_SOURCE_IS_CONTINUOUS; | ||
71 | |||
72 | return clocksource_register_hz(&cs->clksrc, hz); | ||
73 | } | ||