Skip to content

Commit 376bc27

Browse files
committed
clockevents: Add a clkevt-of mechanism like clksrc-of
The current code uses the CLOCKSOURCE_OF_DECLARE macro to fill the clksrc table with a t-uple (name, init_function). Unfortunately it ends up to the clockevent and the clocksource being both initialized with this macro. It is not a problem by itself but there is not a clear distinction between a clockevent and a clocksource in the code initialization path. Somebody can argue there are the same IP block and the same DT node. But conceptually from the software side, there are two distincts entities and as is they should be initialized separetely. Some drivers which do not have a clocksource end up by using the CLOCKSOURCE_OF_DECLARE macro to declare a clockevent. Another result is the fuzzy organization in the clocksource directory, where the clockevents are implemented in the same file than the clocksources or file labelled timer-something implementing a clocksource. This patch provides another macro to specifically declare a clockevent in the same way than the clocksource and gives the opportunity to write two separate drivers, one for the clocksource and another for the clockevents. Hopefully, that can help to do some housework in the directory, perhaps split the drivers in to entities, for example: - clksrc-rockchip.c - clkevt-rockchip.c Also, it gives the possibility to declare clocksources separately in the DT and then use a clocksource from IP block while while clockevents are used from another IP block. Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
1 parent 668802c commit 376bc27

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

drivers/clocksource/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@ config CLKSRC_OF
55
bool
66
select CLKSRC_PROBE
77

8+
config CLKEVT_OF
9+
bool
10+
select CLKEVT_PROBE
11+
812
config CLKSRC_ACPI
913
bool
1014
select CLKSRC_PROBE
1115

1216
config CLKSRC_PROBE
1317
bool
1418

19+
config CLKEVT_PROBE
20+
bool
21+
1522
config CLKSRC_I8253
1623
bool
1724

drivers/clocksource/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
obj-$(CONFIG_CLKSRC_PROBE) += clksrc-probe.o
2+
obj-$(CONFIG_CLKEVT_PROBE) += clkevt-probe.o
23
obj-$(CONFIG_ATMEL_PIT) += timer-atmel-pit.o
34
obj-$(CONFIG_ATMEL_ST) += timer-atmel-st.o
45
obj-$(CONFIG_ATMEL_TCB_CLKSRC) += tcb_clksrc.o

drivers/clocksource/clkevt-probe.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2016, Linaro Ltd. All rights reserved.
3+
* Daniel Lezcano <daniel.lezcano@linaro.org>
4+
*
5+
* This program is free software; you can redistribute it and/or modify it
6+
* under the terms and conditions of the GNU General Public License,
7+
* version 2, as published by the Free Software Foundation.
8+
*
9+
* This program is distributed in the hope it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12+
* more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#include <linux/init.h>
19+
#include <linux/of.h>
20+
#include <linux/clockchip.h>
21+
22+
extern struct of_device_id __clkevt_of_table[];
23+
24+
static const struct of_device_id __clkevt_of_table_sentinel
25+
__used __section(__clkevt_of_table_end);
26+
27+
int __init clockevent_probe(void)
28+
{
29+
struct device_node *np;
30+
const struct of_device_id *match;
31+
of_init_fn_1_ret init_func;
32+
int ret, clockevents = 0;
33+
34+
for_each_matching_node_and_match(np, __clkevt_of_table, &match) {
35+
if (!of_device_is_available(np))
36+
continue;
37+
38+
init_func = match->data;
39+
40+
ret = init_func(np);
41+
if (ret) {
42+
pr_warn("Failed to initialize '%s' (%d)\n",
43+
np->name, ret);
44+
continue;
45+
}
46+
47+
clockevents++;
48+
}
49+
50+
if (!clockevents) {
51+
pr_crit("%s: no matching clockevent found\n", __func__);
52+
return -ENODEV;
53+
}
54+
55+
return 0;
56+
}

include/linux/clockchips.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,13 @@ static inline void tick_setup_hrtimer_broadcast(void) { }
224224

225225
#endif /* !CONFIG_GENERIC_CLOCKEVENTS */
226226

227+
#define CLOCKEVENT_OF_DECLARE(name, compat, fn) \
228+
OF_DECLARE_1_RET(clkevt, name, compat, fn)
229+
230+
#ifdef CONFIG_CLKEVT_PROBE
231+
extern int clockevent_probe(void);
232+
#els
233+
static inline int clockevent_probe(void) { return 0; }
234+
#endif
235+
227236
#endif /* _LINUX_CLOCKCHIPS_H */

0 commit comments

Comments
 (0)