[PATCH 5/9] clocksource: allow to have multiple device from clock source
Jean-Christophe PLAGNIOL-VILLARD
plagnioj at jcrosoft.com
Fri Mar 3 04:34:01 PST 2017
use the one with the most priority.
We can not select the clocksource at user level.
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
---
common/clock.c | 11 +++++++++++
include/clock.h | 3 ++-
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/common/clock.c b/common/clock.c
index 2c5dd91cc..1090b605f 100644
--- a/common/clock.c
+++ b/common/clock.c
@@ -213,6 +213,17 @@ EXPORT_SYMBOL(mdelay_non_interruptible);
int init_clock(struct clocksource *cs)
{
+ if (current_clock && cs->priority <= current_clock->priority)
+ return 0;
+
+ if (cs->init) {
+ int ret;
+
+ ret = cs->init(cs);
+ if (ret)
+ return ret;
+ }
+
current_clock = cs;
time_beginning = get_time_ns();
diff --git a/include/clock.h b/include/clock.h
index d65e404e8..5f2f53ab6 100644
--- a/include/clock.h
+++ b/include/clock.h
@@ -12,7 +12,8 @@ struct clocksource {
uint64_t (*read)(void);
uint64_t cycle_last;
uint64_t mask;
-
+ int priority;
+ int (*init)(struct clocksource*);
};
static inline uint32_t cyc2ns(struct clocksource *cs, uint64_t cycles)
--
2.11.0
More information about the barebox
mailing list