From patchwork Tue Feb 22 10:17:41 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peppe CAVALLARO X-Patchwork-Id: 580131 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p1MAkBI9024535 for ; Tue, 22 Feb 2011 10:46:12 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753986Ab1BVKqI (ORCPT ); Tue, 22 Feb 2011 05:46:08 -0500 Received: from eu1sys200aog119.obsmtp.com ([207.126.144.147]:55816 "EHLO eu1sys200aog119.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753962Ab1BVKqH convert rfc822-to-8bit (ORCPT ); Tue, 22 Feb 2011 05:46:07 -0500 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 22 Feb 2011 10:46:12 +0000 (UTC) X-Greylist: delayed 1662 seconds by postgrey-1.27 at vger.kernel.org; Tue, 22 Feb 2011 05:46:06 EST Received: from source ([164.129.1.35]) (using TLSv1) by eu1sys200aob119.postini.com ([207.126.147.11]) with SMTP ID DSNKTWOT7OYgpupTOkluSBwenAOIQBqp8g0U@postini.com; Tue, 22 Feb 2011 10:46:06 UTC Received: from zeta.dmz-eu.st.com (ns2.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id C97751D7; Tue, 22 Feb 2011 10:18:09 +0000 (GMT) Received: from Webmail-eu.st.com (safex1hubcas3.st.com [10.75.90.18]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 476AD4714; Tue, 22 Feb 2011 10:18:09 +0000 (GMT) Received: from SAFEX1MAIL3.st.com ([10.75.90.7]) by SAFEX1HUBCAS3.st.com ([10.75.90.18]) with mapi; Tue, 22 Feb 2011 11:18:08 +0100 From: Peppe CAVALLARO To: "linux-sh@vger.kernel.org" , "netdev@vger.kernel.org" Cc: Stuart MENEFY Date: Tue, 22 Feb 2011 11:17:41 +0100 Subject: [PATCH (sh-2.6) 1/4] clksource: Generic timer infrastructure Thread-Topic: [PATCH (sh-2.6) 1/4] clksource: Generic timer infrastructure Thread-Index: AcvSec1zEj6uJL5WR/S2iDbZT/WyGg== Message-ID: <1298369864-24429-2-git-send-email-peppe.cavallaro@st.com> References: <1298369864-24429-1-git-send-email-peppe.cavallaro@st.com> In-Reply-To: <1298369864-24429-1-git-send-email-peppe.cavallaro@st.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US MIME-Version: 1.0 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org 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 + * Stuart Menefy + * + * May be copied or modified under the terms of the GNU General Public + * License. See linux/COPYING for more information. + */ + +#include +#include +#include +#include + +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 + +/* 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 */