1 From 517d8e6ba345620c6704ec3db5b23c56fde06392 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Thu, 20 Jun 2013 19:16:03 +0200
4 Subject: [PATCH 77/79] clocksource: add common of_clksrc_init() function
6 It is desirable to move all clocksource drivers to drivers/clocksource,
7 yet each requires its own initialization function. We'd rather not
8 pollute <linux/> with a header for each function. Instead, create a
9 single of_clksrc_init() function which will determine which clocksource
10 driver to initialize based on device tree.
12 Based on a similar patch for drivers/irqchip by Thomas Petazzoni.
14 Signed-off-by: Stephen Warren <swarren@nvidia.com>
16 drivers/clocksource/Kconfig | 3 +++
17 drivers/clocksource/Makefile | 1 +
18 drivers/clocksource/clksrc-of.c | 35 +++++++++++++++++++++++++++++++++++
19 include/asm-generic/vmlinux.lds.h | 9 +++++++++
20 include/linux/clocksource.h | 9 +++++++++
21 5 files changed, 57 insertions(+)
22 create mode 100644 drivers/clocksource/clksrc-of.c
24 diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
25 index 7fdcbd3..a32b7a9 100644
26 --- a/drivers/clocksource/Kconfig
27 +++ b/drivers/clocksource/Kconfig
35 diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
36 index f93453d..a33f792 100644
37 --- a/drivers/clocksource/Makefile
38 +++ b/drivers/clocksource/Makefile
40 +obj-$(CONFIG_CLKSRC_OF) += clksrc-of.o
41 obj-$(CONFIG_ATMEL_TCB_CLKSRC) += tcb_clksrc.o
42 obj-$(CONFIG_X86_CYCLONE_TIMER) += cyclone.o
43 obj-$(CONFIG_X86_PM_TIMER) += acpi_pm.o
44 diff --git a/drivers/clocksource/clksrc-of.c b/drivers/clocksource/clksrc-of.c
46 index 0000000..bdabdaa
48 +++ b/drivers/clocksource/clksrc-of.c
51 + * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
53 + * This program is free software; you can redistribute it and/or modify it
54 + * under the terms and conditions of the GNU General Public License,
55 + * version 2, as published by the Free Software Foundation.
57 + * This program is distributed in the hope it will be useful, but WITHOUT
58 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
59 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
62 + * You should have received a copy of the GNU General Public License
63 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
66 +#include <linux/init.h>
67 +#include <linux/of.h>
69 +extern struct of_device_id __clksrc_of_table[];
71 +static const struct of_device_id __clksrc_of_table_sentinel
72 + __used __section(__clksrc_of_table_end);
74 +void __init clocksource_of_init(void)
76 + struct device_node *np;
77 + const struct of_device_id *match;
78 + void (*init_func)(void);
80 + for_each_matching_node_and_match(np, __clksrc_of_table, &match) {
81 + init_func = match->data;
85 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
86 index d1ea7ce..1e744c5 100644
87 --- a/include/asm-generic/vmlinux.lds.h
88 +++ b/include/asm-generic/vmlinux.lds.h
90 #define TRACE_SYSCALLS()
93 +#ifdef CONFIG_CLKSRC_OF
94 +#define CLKSRC_OF_TABLES() . = ALIGN(8); \
95 + VMLINUX_SYMBOL(__clksrc_of_table) = .; \
96 + *(__clksrc_of_table) \
97 + *(__clksrc_of_table_end)
99 +#define CLKSRC_OF_TABLES()
102 #define KERNEL_DTB() \
105 DEV_DISCARD(init.rodata) \
106 CPU_DISCARD(init.rodata) \
107 MEM_DISCARD(init.rodata) \
108 + CLKSRC_OF_TABLES() \
112 diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
113 index 4dceaf8..7944f14 100644
114 --- a/include/linux/clocksource.h
115 +++ b/include/linux/clocksource.h
116 @@ -332,4 +332,13 @@ extern int clocksource_mmio_init(void __iomem *, const char *,
118 extern int clocksource_i8253_init(void);
120 +#ifdef CONFIG_CLKSRC_OF
121 +extern void clocksource_of_init(void);
123 +#define CLOCKSOURCE_OF_DECLARE(name, compat, fn) \
124 + static const struct of_device_id __clksrc_of_table_##name \
125 + __used __section(__clksrc_of_table) \
126 + = { .compatible = compat, .data = fn };
129 #endif /* _LINUX_CLOCKSOURCE_H */