diff mbox

[2/2] clockevents: Add helpers to verify state of a clockevent device

Message ID a027ed39f07a494d971c3b30806a00bd4f65cd4b.1432112458.git.viresh.kumar@linaro.org
State New
Headers show

Commit Message

Viresh Kumar May 20, 2015, 9:06 a.m. UTC
Some clockevent drivers need to verify state of the clockevent device in
their callbacks or interrupt handler.

Because the symbols representing these states (defined by 'enum
clock_event_state') are internal to the core, they aren't accessible to
these driver.

Introduce helper routines that can verify state of clockevent device.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 include/linux/clockchips.h | 11 +++++++++++
 kernel/time/clockevents.c  | 31 +++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)
diff mbox

Patch

diff --git a/include/linux/clockchips.h b/include/linux/clockchips.h
index 62d3007f8a8c..b0aa9c7b96c4 100644
--- a/include/linux/clockchips.h
+++ b/include/linux/clockchips.h
@@ -189,6 +189,12 @@  static inline void tick_setup_hrtimer_broadcast(void) { }
 
 extern int clockevents_notify(unsigned long reason, void *arg);
 
+extern bool clockevent_state_detached(struct clock_event_device *evt);
+extern bool clockevent_state_shutdown(struct clock_event_device *evt);
+extern bool clockevent_state_periodic(struct clock_event_device *evt);
+extern bool clockevent_state_oneshot(struct clock_event_device *evt);
+extern bool clockevent_state_oneshot_stopped(struct clock_event_device *evt);
+
 #else /* !CONFIG_GENERIC_CLOCKEVENTS: */
 
 static inline void clockevents_suspend(void) { }
@@ -197,6 +203,11 @@  static inline int clockevents_notify(unsigned long reason, void *arg) { return 0
 static inline int tick_check_broadcast_expired(void) { return 0; }
 static inline void tick_setup_hrtimer_broadcast(void) { }
 
+static inline bool clockevent_state_detached(struct clock_event_device *evt) { return false; };
+static inline bool clockevent_state_shutdown(struct clock_event_device *evt) { return false; };
+static inline bool clockevent_state_periodic(struct clock_event_device *evt) { return false; };
+static inline bool clockevent_state_oneshot(struct clock_event_device *evt) { return false; };
+static inline bool clockevent_state_oneshot_stopped(struct clock_event_device *evt) { return false; };
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
 
 #endif /* _LINUX_CLOCKCHIPS_H */
diff --git a/kernel/time/clockevents.c b/kernel/time/clockevents.c
index 4922f1b805ea..ce9bb174d9bb 100644
--- a/kernel/time/clockevents.c
+++ b/kernel/time/clockevents.c
@@ -33,6 +33,37 @@  struct ce_unbind {
 	int res;
 };
 
+/* Helpers to verify state of a clockevent device */
+bool clockevent_state_detached(struct clock_event_device *evt)
+{
+	return evt->state == CLOCK_EVT_STATE_DETACHED;
+}
+EXPORT_SYMBOL_GPL(clockevent_state_detached);
+
+bool clockevent_state_shutdown(struct clock_event_device *evt)
+{
+	return evt->state == CLOCK_EVT_STATE_SHUTDOWN;
+}
+EXPORT_SYMBOL_GPL(clockevent_state_shutdown);
+
+bool clockevent_state_periodic(struct clock_event_device *evt)
+{
+	return evt->state == CLOCK_EVT_STATE_PERIODIC;
+}
+EXPORT_SYMBOL_GPL(clockevent_state_periodic);
+
+bool clockevent_state_oneshot(struct clock_event_device *evt)
+{
+	return evt->state == CLOCK_EVT_STATE_ONESHOT;
+}
+EXPORT_SYMBOL_GPL(clockevent_state_oneshot);
+
+bool clockevent_state_oneshot_stopped(struct clock_event_device *evt)
+{
+	return evt->state == CLOCK_EVT_STATE_ONESHOT_STOPPED;
+}
+EXPORT_SYMBOL_GPL(clockevent_state_oneshot_stopped);
+
 static u64 cev_delta2ns(unsigned long latch, struct clock_event_device *evt,
 			bool ismax)
 {