ar71xx: update to 3.10.1
[openwrt/openwrt.git] / target / linux / ramips / patches-3.8 / 0077-clocksource-add-common-of_clksrc_init-function.patch
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
5
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.
11
12 Based on a similar patch for drivers/irqchip by Thomas Petazzoni.
13
14 Signed-off-by: Stephen Warren <swarren@nvidia.com>
15 ---
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
23
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
28 @@ -1,3 +1,6 @@
29 +config CLKSRC_OF
30 + bool
31 +
32 config CLKSRC_I8253
33 bool
34
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
39 @@ -1,3 +1,4 @@
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
45 new file mode 100644
46 index 0000000..bdabdaa
47 --- /dev/null
48 +++ b/drivers/clocksource/clksrc-of.c
49 @@ -0,0 +1,35 @@
50 +/*
51 + * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
52 + *
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.
56 + *
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
60 + * more details.
61 + *
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/>.
64 + */
65 +
66 +#include <linux/init.h>
67 +#include <linux/of.h>
68 +
69 +extern struct of_device_id __clksrc_of_table[];
70 +
71 +static const struct of_device_id __clksrc_of_table_sentinel
72 + __used __section(__clksrc_of_table_end);
73 +
74 +void __init clocksource_of_init(void)
75 +{
76 + struct device_node *np;
77 + const struct of_device_id *match;
78 + void (*init_func)(void);
79 +
80 + for_each_matching_node_and_match(np, __clksrc_of_table, &match) {
81 + init_func = match->data;
82 + init_func();
83 + }
84 +}
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
89 @@ -149,6 +149,14 @@
90 #define TRACE_SYSCALLS()
91 #endif
92
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)
98 +#else
99 +#define CLKSRC_OF_TABLES()
100 +#endif
101
102 #define KERNEL_DTB() \
103 STRUCT_ALIGN(); \
104 @@ -493,6 +501,7 @@
105 DEV_DISCARD(init.rodata) \
106 CPU_DISCARD(init.rodata) \
107 MEM_DISCARD(init.rodata) \
108 + CLKSRC_OF_TABLES() \
109 KERNEL_DTB()
110
111 #define INIT_TEXT \
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 *,
117
118 extern int clocksource_i8253_init(void);
119
120 +#ifdef CONFIG_CLKSRC_OF
121 +extern void clocksource_of_init(void);
122 +
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 };
127 +#endif
128 +
129 #endif /* _LINUX_CLOCKSOURCE_H */
130 --
131 1.7.10.4
132