@@ -6,3 +6,4 @@ obj-$(CONFIG_CS5535_CLOCK_EVENT_SRC) += cs5535-clockevt.o
obj-$(CONFIG_SH_TIMER_CMT) += sh_cmt.o
obj-$(CONFIG_SH_TIMER_MTU2) += sh_mtu2.o
obj-$(CONFIG_SH_TIMER_TMU) += sh_tmu.o
+obj-y += generictimer.o
new file mode 100644
@@ -0,0 +1,60 @@
+/*
+ * Simple generic hardware timer interface
+ *
+ * Copyright (C) 2010 STMicroelectronics Limited
+ * Authors: Giuseppe Cavallaro <peppe.cavallaro@st.com>
+ * Stuart Menefy <stuart.menefy@st.com>
+ *
+ * May be copied or modified under the terms of the GNU General Public
+ * License. See linux/COPYING for more information.
+ */
+
+#include <linux/kernel.h>
+#include <linux/mutex.h>
+#include <linux/list.h>
+#include <linux/generictimer.h>
+
+static DEFINE_MUTEX(gt_mutex);
+static LIST_HEAD(gt_list);
+
+void generic_timer_register_device(struct generic_timer *gt)
+{
+ mutex_lock(>_mutex);
+ list_add(>->list, >_list);
+ mutex_unlock(>_mutex);
+}
+
+struct generic_timer *generic_timer_claim(void (*handler) (void *), void *data)
+{
+ struct generic_timer *gt = NULL;
+
+ if (!handler) {
+ pr_err("%s: invalid handler\n", __func__);
+ return NULL;
+ }
+
+ mutex_lock(>_mutex);
+ if (!list_empty(>_list)) {
+ struct list_head *list = gt_list.next;
+ list_del(list);
+ gt = container_of(list, struct generic_timer, list);
+ }
+ mutex_unlock(>_mutex);
+
+ if (!gt)
+ return NULL;
+
+ /* Prepare the new handler */
+ gt->priv_handler = handler;
+ gt->data = data;
+
+ return gt;
+}
+
+void generic_timer_release(struct generic_timer *gt)
+{
+ /* Just in case... */
+ generic_timer_stop(gt);
+
+ generic_timer_register_device(gt);
+}
new file mode 100644
@@ -0,0 +1,41 @@
+#ifndef __STM_GENERIC_TIMER_H
+#define __STM_GENERIC_TIMER_H
+
+#include <linux/list.h>
+
+/* Generic timer device intrface */
+
+struct generic_timer {
+ char *name;
+ struct list_head list;
+ void (*priv_handler)(void *data);
+ void *data;
+ void (*timer_start)(struct generic_timer *gt);
+ void (*timer_stop)(struct generic_timer *gt);
+ void (*set_rate)(struct generic_timer *gt, unsigned long rate);
+};
+
+void generic_timer_register_device(struct generic_timer *gt);
+
+/* Driver interface */
+
+struct generic_timer *generic_timer_claim(void (*handler)(void *), void *data);
+void generic_timer_release(struct generic_timer *gt);
+
+static inline void generic_timer_start(struct generic_timer *gt)
+{
+ gt->timer_start(gt);
+}
+
+static inline void generic_timer_stop(struct generic_timer *gt)
+{
+ gt->timer_stop(gt);
+}
+
+static inline void generic_timer_set_rate(struct generic_timer *gt,
+ unsigned long rate)
+{
+ gt->set_rate(gt, rate);
+}
+
+#endif /* __STM_GENERIC_TIMER_H */