From: Peppe CAVALLARO <peppe.cavallaro@st.com> To: "linux-sh@vger.kernel.org" <linux-sh@vger.kernel.org>, "netdev@vger.kernel.org" <netdev@vger.kernel.org> Cc: Stuart MENEFY <stuart.menefy@st.com> Subject: [PATCH (sh-2.6) 1/4] clksource: Generic timer infrastructure Date: Tue, 22 Feb 2011 10:17:41 +0000 [thread overview] Message-ID: <1298369864-24429-2-git-send-email-peppe.cavallaro@st.com> (raw) In-Reply-To: <1298369864-24429-1-git-send-email-peppe.cavallaro@st.com> From: Stuart Menefy <stuart.menefy@st.com> Many devices targeted at the embedded market provide a number of generic timers which are capable of generating interrupts at a requested rate. These can then be used in the implementation of drivers for other peripherals which require a timer interrupt, without having to provide an additional timer as part of that peripheral. A code provides a simple abstraction layer which allows a timer to be registered, and for a driver to request a timer. Currently this doesn't provide any of the additional information, such as precision or position in clock framework which might be required for a fully featured driver. Signed-off-by: Stuart Menefy <stuart.menefy@st.com> Hacked-by: Giuseppe Cavallaro <peppe.cavallaro@st.com> --- drivers/clocksource/Makefile | 1 + drivers/clocksource/generictimer.c | 60 ++++++++++++++++++++++++++++++++++++ include/linux/generictimer.h | 41 ++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 0 deletions(-) create mode 100644 drivers/clocksource/generictimer.c create mode 100644 include/linux/generictimer.h diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile index be61ece..b0be293 100644 --- a/drivers/clocksource/Makefile +++ b/drivers/clocksource/Makefile @@ -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 diff --git a/drivers/clocksource/generictimer.c b/drivers/clocksource/generictimer.c new file mode 100644 index 0000000..a74a87a --- /dev/null +++ b/drivers/clocksource/generictimer.c @@ -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); +} diff --git a/include/linux/generictimer.h b/include/linux/generictimer.h new file mode 100644 index 0000000..87fb656 --- /dev/null +++ b/include/linux/generictimer.h @@ -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 */ -- 1.7.4
WARNING: multiple messages have this Message-ID (diff)
From: Peppe CAVALLARO <peppe.cavallaro@st.com> To: "linux-sh@vger.kernel.org" <linux-sh@vger.kernel.org>, "netdev@vger.kernel.org" <netdev@vger.kernel.org> Cc: Stuart MENEFY <stuart.menefy@st.com> Subject: [PATCH (sh-2.6) 1/4] clksource: Generic timer infrastructure Date: Tue, 22 Feb 2011 11:17:41 +0100 [thread overview] Message-ID: <1298369864-24429-2-git-send-email-peppe.cavallaro@st.com> (raw) In-Reply-To: <1298369864-24429-1-git-send-email-peppe.cavallaro@st.com> From: Stuart Menefy <stuart.menefy@st.com> Many devices targeted at the embedded market provide a number of generic timers which are capable of generating interrupts at a requested rate. These can then be used in the implementation of drivers for other peripherals which require a timer interrupt, without having to provide an additional timer as part of that peripheral. A code provides a simple abstraction layer which allows a timer to be registered, and for a driver to request a timer. Currently this doesn't provide any of the additional information, such as precision or position in clock framework which might be required for a fully featured driver. Signed-off-by: Stuart Menefy <stuart.menefy@st.com> Hacked-by: Giuseppe Cavallaro <peppe.cavallaro@st.com> --- drivers/clocksource/Makefile | 1 + drivers/clocksource/generictimer.c | 60 ++++++++++++++++++++++++++++++++++++ include/linux/generictimer.h | 41 ++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 0 deletions(-) create mode 100644 drivers/clocksource/generictimer.c create mode 100644 include/linux/generictimer.h diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile index be61ece..b0be293 100644 --- a/drivers/clocksource/Makefile +++ b/drivers/clocksource/Makefile @@ -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 diff --git a/drivers/clocksource/generictimer.c b/drivers/clocksource/generictimer.c new file mode 100644 index 0000000..a74a87a --- /dev/null +++ b/drivers/clocksource/generictimer.c @@ -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); +} diff --git a/include/linux/generictimer.h b/include/linux/generictimer.h new file mode 100644 index 0000000..87fb656 --- /dev/null +++ b/include/linux/generictimer.h @@ -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 */ -- 1.7.4
next prev parent reply other threads:[~2011-02-22 10:17 UTC|newest] Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-02-22 10:17 [PATCH 0/4] simple generic timer infrastructure and stmmac example Peppe CAVALLARO 2011-02-22 10:17 ` Peppe CAVALLARO 2011-02-22 10:17 ` Peppe CAVALLARO [this message] 2011-02-22 10:17 ` [PATCH (sh-2.6) 1/4] clksource: Generic timer infrastructure Peppe CAVALLARO 2011-02-24 17:20 ` Arnd Bergmann 2011-02-24 17:20 ` Arnd Bergmann 2011-03-01 15:20 ` Stuart Menefy 2011-03-01 15:20 ` Stuart Menefy 2011-03-01 16:43 ` Arnd Bergmann 2011-03-01 16:43 ` Arnd Bergmann 2011-03-01 20:26 ` Russell King - ARM Linux 2011-03-01 20:26 ` Russell King - ARM Linux 2011-03-01 20:41 ` Arnd Bergmann 2011-03-01 20:41 ` Arnd Bergmann 2011-03-01 16:48 ` Thomas Gleixner 2011-03-01 16:48 ` Thomas Gleixner 2011-03-02 17:35 ` Peppe CAVALLARO 2011-03-02 17:35 ` Peppe CAVALLARO 2011-03-03 8:45 ` Arnd Bergmann 2011-03-03 8:45 ` Arnd Bergmann 2011-03-03 10:25 ` Peppe CAVALLARO 2011-03-03 10:25 ` Peppe CAVALLARO 2011-03-03 13:55 ` Arnd Bergmann 2011-03-03 13:55 ` Arnd Bergmann 2011-03-04 6:53 ` Peppe CAVALLARO 2011-03-04 6:53 ` Peppe CAVALLARO 2012-06-12 3:04 ` Paul Mundt 2012-06-12 3:04 ` Paul Mundt 2011-02-22 10:17 ` [PATCH (sh-2.6) 2/4] sh_timer: add the support to use the generic Peppe CAVALLARO 2011-02-22 10:17 ` [PATCH (sh-2.6) 2/4] sh_timer: add the support to use the generic timer Peppe CAVALLARO 2011-02-22 10:17 ` [PATCH (net-2.6) 3/4] stmmac: switch to use the new " Peppe CAVALLARO 2011-02-22 10:17 ` [PATCH (net-2.6) 3/4] stmmac: switch to use the new generic timer interface Peppe CAVALLARO 2011-02-22 10:17 ` [PATCH (net-2.6) 4/4] stmmac: rework and improvement the stmmac Peppe CAVALLARO 2011-02-22 10:17 ` [PATCH (net-2.6) 4/4] stmmac: rework and improvement the stmmac timer Peppe CAVALLARO
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1298369864-24429-2-git-send-email-peppe.cavallaro@st.com \ --to=peppe.cavallaro@st.com \ --cc=linux-sh@vger.kernel.org \ --cc=netdev@vger.kernel.org \ --cc=stuart.menefy@st.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.