All of lore.kernel.org
 help / color / mirror / Atom feed
From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: linux-arm-kernel@lists.infradead.org,
	John Stultz <johnstul@us.ibm.com>,
	Thomas Gleixner <tglx@linutronix.de>
Cc: Alessandro Rubini <rubini@unipv.it>,
	Kukjin Kim <kgene.kim@samsung.com>,
	Eric Miao <eric.y.miao@gmail.com>,
	Linus Walleij <linus.walleij@stericsson.com>,
	Erik Gilling <konkers@android.com>,
	Nicolas Pitre <nico@fluxnic.net>,
	Tony Lindgren <tony@atomide.com>, Imre Kaloz <kaloz@openwrt.org>,
	"Hans J. Koch" <hjk@hansjkoch.de>,
	Sascha Hauer <kernel@pengutronix.de>,
	Colin Cross <ccross@android.com>, Olof Johansson <olof@lixom.net>,
	linux-omap@vger.kernel.org, Wan ZongShun <mcuos.com@gmail.com>,
	Lennert Buytenhek <kernel@wantstofly.org>,
	Krzysztof Halasa <khc@pm.waw.pl>
Subject: [PATCH 06/13 v2] clocksource: add common mmio clocksource
Date: Wed, 11 May 2011 09:35:52 +0100	[thread overview]
Message-ID: <20110511083552.GF15120@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <E1QJhNe-0000yh-HS@rmk-PC.arm.linux.org.uk>

Add a generic mmio clocksource, covering both 32-bit and 16-bit register
access sizes, for up or down counters.  This can be used to easily
create clocksources for simple counter-based implementations.

Cc: Alessandro Rubini <rubini@unipv.it>
Cc: Colin Cross <ccross@android.com>
Cc: Eric Miao <eric.y.miao@gmail.com>
Cc: Erik Gilling <konkers@android.com>
Acked-by: "Hans J. Koch" <hjk@hansjkoch.de>
Cc: Imre Kaloz <kaloz@openwrt.org>
Cc: Krzysztof Halasa <khc@pm.waw.pl>
Cc: Kukjin Kim <kgene.kim@samsung.com>
Cc: Lennert Buytenhek <kernel@wantstofly.org>
Cc: Linus Walleij <linus.walleij@stericsson.com>
Cc: linux-omap@vger.kernel.org
Cc: Nicolas Pitre <nico@fluxnic.net>
Cc: Olof Johansson <olof@lixom.net>
Tested-by: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Tony Lindgren <tony@atomide.com>
Reviewed-by: Viresh Kumar <viresh.kumar@st.com>
Cc: Wan ZongShun <mcuos.com@gmail.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
---

This is the version with cs->reg initialized.

 drivers/Kconfig              |    3 ++
 drivers/clocksource/Kconfig  |    2 +
 drivers/clocksource/Makefile |    1 +
 drivers/clocksource/mmio.c   |   73 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/clocksource.h  |    8 ++++
 5 files changed, 87 insertions(+), 0 deletions(-)
 create mode 100644 drivers/clocksource/Kconfig
 create mode 100644 drivers/clocksource/mmio.c

diff --git a/drivers/Kconfig b/drivers/Kconfig
index 177c7d1..557a469 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -119,4 +119,7 @@ source "drivers/platform/Kconfig"
 source "drivers/clk/Kconfig"
 
 source "drivers/hwspinlock/Kconfig"
+
+source "drivers/clocksource/Kconfig"
+
 endmenu
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
new file mode 100644
index 0000000..47f37b1
--- /dev/null
+++ b/drivers/clocksource/Kconfig
@@ -0,0 +1,2 @@
+config CLKSRC_MMIO
+	bool
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index be61ece..9b2ba29 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-$(CONFIG_CLKSRC_MMIO)	+= mmio.o
diff --git a/drivers/clocksource/mmio.c b/drivers/clocksource/mmio.c
new file mode 100644
index 0000000..c0e2512
--- /dev/null
+++ b/drivers/clocksource/mmio.c
@@ -0,0 +1,73 @@
+/*
+ * Generic MMIO clocksource support
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/clocksource.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+
+struct clocksource_mmio {
+	void __iomem *reg;
+	struct clocksource clksrc;
+};
+
+static inline struct clocksource_mmio *to_mmio_clksrc(struct clocksource *c)
+{
+	return container_of(c, struct clocksource_mmio, clksrc);
+}
+
+cycle_t clocksource_mmio_readl_up(struct clocksource *c)
+{
+	return readl_relaxed(to_mmio_clksrc(c)->reg);
+}
+
+cycle_t clocksource_mmio_readl_down(struct clocksource *c)
+{
+	return ~readl_relaxed(to_mmio_clksrc(c)->reg);
+}
+
+cycle_t clocksource_mmio_readw_up(struct clocksource *c)
+{
+	return readw_relaxed(to_mmio_clksrc(c)->reg);
+}
+
+cycle_t clocksource_mmio_readw_down(struct clocksource *c)
+{
+	return ~(unsigned)readw_relaxed(to_mmio_clksrc(c)->reg);
+}
+
+/**
+ * clocksource_mmio_init - Initialize a simple mmio based clocksource
+ * @base:	Virtual address of the clock readout register
+ * @name:	Name of the clocksource
+ * @hz:		Frequency of the clocksource in Hz
+ * @rating:	Rating of the clocksource
+ * @bits:	Number of valid bits
+ * @read:	One of clocksource_mmio_read*() above
+ */
+int __init clocksource_mmio_init(void __iomem *base, const char *name,
+	unsigned long hz, int rating, unsigned bits,
+	cycle_t (*read)(struct clocksource *))
+{
+	struct clocksource_mmio *cs;
+
+	if (bits > 32 || bits < 16)
+		return -EINVAL;
+
+	cs = kzalloc(sizeof(struct clocksource_mmio), GFP_KERNEL);
+	if (!cs)
+		return -ENOMEM;
+
+	cs->reg = base;
+	cs->clksrc.name = name;
+	cs->clksrc.rating = rating;
+	cs->clksrc.read = read;
+	cs->clksrc.mask = CLOCKSOURCE_MASK(bits);
+	cs->clksrc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+
+	return clocksource_register_hz(&cs->clksrc, hz);
+}
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index 94c1f38..a3558fd 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -341,4 +341,12 @@ static inline void update_vsyscall_tz(void)
 
 extern void timekeeping_notify(struct clocksource *clock);
 
+extern cycle_t clocksource_mmio_readl_up(struct clocksource *);
+extern cycle_t clocksource_mmio_readl_down(struct clocksource *);
+extern cycle_t clocksource_mmio_readw_up(struct clocksource *);
+extern cycle_t clocksource_mmio_readw_down(struct clocksource *);
+
+extern int clocksource_mmio_init(void __iomem *, const char *,
+	unsigned long, int, unsigned, cycle_t (*)(struct clocksource *));
+
 #endif /* _LINUX_CLOCKSOURCE_H */
-- 
1.7.4.4

WARNING: multiple messages have this Message-ID (diff)
From: linux@arm.linux.org.uk (Russell King - ARM Linux)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 06/13 v2] clocksource: add common mmio clocksource
Date: Wed, 11 May 2011 09:35:52 +0100	[thread overview]
Message-ID: <20110511083552.GF15120@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <E1QJhNe-0000yh-HS@rmk-PC.arm.linux.org.uk>

Add a generic mmio clocksource, covering both 32-bit and 16-bit register
access sizes, for up or down counters.  This can be used to easily
create clocksources for simple counter-based implementations.

Cc: Alessandro Rubini <rubini@unipv.it>
Cc: Colin Cross <ccross@android.com>
Cc: Eric Miao <eric.y.miao@gmail.com>
Cc: Erik Gilling <konkers@android.com>
Acked-by: "Hans J. Koch" <hjk@hansjkoch.de>
Cc: Imre Kaloz <kaloz@openwrt.org>
Cc: Krzysztof Halasa <khc@pm.waw.pl>
Cc: Kukjin Kim <kgene.kim@samsung.com>
Cc: Lennert Buytenhek <kernel@wantstofly.org>
Cc: Linus Walleij <linus.walleij@stericsson.com>
Cc: linux-omap at vger.kernel.org
Cc: Nicolas Pitre <nico@fluxnic.net>
Cc: Olof Johansson <olof@lixom.net>
Tested-by: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Tony Lindgren <tony@atomide.com>
Reviewed-by: Viresh Kumar <viresh.kumar@st.com>
Cc: Wan ZongShun <mcuos.com@gmail.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
---

This is the version with cs->reg initialized.

 drivers/Kconfig              |    3 ++
 drivers/clocksource/Kconfig  |    2 +
 drivers/clocksource/Makefile |    1 +
 drivers/clocksource/mmio.c   |   73 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/clocksource.h  |    8 ++++
 5 files changed, 87 insertions(+), 0 deletions(-)
 create mode 100644 drivers/clocksource/Kconfig
 create mode 100644 drivers/clocksource/mmio.c

diff --git a/drivers/Kconfig b/drivers/Kconfig
index 177c7d1..557a469 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -119,4 +119,7 @@ source "drivers/platform/Kconfig"
 source "drivers/clk/Kconfig"
 
 source "drivers/hwspinlock/Kconfig"
+
+source "drivers/clocksource/Kconfig"
+
 endmenu
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
new file mode 100644
index 0000000..47f37b1
--- /dev/null
+++ b/drivers/clocksource/Kconfig
@@ -0,0 +1,2 @@
+config CLKSRC_MMIO
+	bool
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index be61ece..9b2ba29 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-$(CONFIG_CLKSRC_MMIO)	+= mmio.o
diff --git a/drivers/clocksource/mmio.c b/drivers/clocksource/mmio.c
new file mode 100644
index 0000000..c0e2512
--- /dev/null
+++ b/drivers/clocksource/mmio.c
@@ -0,0 +1,73 @@
+/*
+ * Generic MMIO clocksource support
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/clocksource.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+
+struct clocksource_mmio {
+	void __iomem *reg;
+	struct clocksource clksrc;
+};
+
+static inline struct clocksource_mmio *to_mmio_clksrc(struct clocksource *c)
+{
+	return container_of(c, struct clocksource_mmio, clksrc);
+}
+
+cycle_t clocksource_mmio_readl_up(struct clocksource *c)
+{
+	return readl_relaxed(to_mmio_clksrc(c)->reg);
+}
+
+cycle_t clocksource_mmio_readl_down(struct clocksource *c)
+{
+	return ~readl_relaxed(to_mmio_clksrc(c)->reg);
+}
+
+cycle_t clocksource_mmio_readw_up(struct clocksource *c)
+{
+	return readw_relaxed(to_mmio_clksrc(c)->reg);
+}
+
+cycle_t clocksource_mmio_readw_down(struct clocksource *c)
+{
+	return ~(unsigned)readw_relaxed(to_mmio_clksrc(c)->reg);
+}
+
+/**
+ * clocksource_mmio_init - Initialize a simple mmio based clocksource
+ * @base:	Virtual address of the clock readout register
+ * @name:	Name of the clocksource
+ * @hz:		Frequency of the clocksource in Hz
+ * @rating:	Rating of the clocksource
+ * @bits:	Number of valid bits
+ * @read:	One of clocksource_mmio_read*() above
+ */
+int __init clocksource_mmio_init(void __iomem *base, const char *name,
+	unsigned long hz, int rating, unsigned bits,
+	cycle_t (*read)(struct clocksource *))
+{
+	struct clocksource_mmio *cs;
+
+	if (bits > 32 || bits < 16)
+		return -EINVAL;
+
+	cs = kzalloc(sizeof(struct clocksource_mmio), GFP_KERNEL);
+	if (!cs)
+		return -ENOMEM;
+
+	cs->reg = base;
+	cs->clksrc.name = name;
+	cs->clksrc.rating = rating;
+	cs->clksrc.read = read;
+	cs->clksrc.mask = CLOCKSOURCE_MASK(bits);
+	cs->clksrc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+
+	return clocksource_register_hz(&cs->clksrc, hz);
+}
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index 94c1f38..a3558fd 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -341,4 +341,12 @@ static inline void update_vsyscall_tz(void)
 
 extern void timekeeping_notify(struct clocksource *clock);
 
+extern cycle_t clocksource_mmio_readl_up(struct clocksource *);
+extern cycle_t clocksource_mmio_readl_down(struct clocksource *);
+extern cycle_t clocksource_mmio_readw_up(struct clocksource *);
+extern cycle_t clocksource_mmio_readw_down(struct clocksource *);
+
+extern int clocksource_mmio_init(void __iomem *, const char *,
+	unsigned long, int, unsigned, cycle_t (*)(struct clocksource *));
+
 #endif /* _LINUX_CLOCKSOURCE_H */
-- 
1.7.4.4

  parent reply	other threads:[~2011-05-11  8:35 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-10  7:27 [PATCH 00/13] Consolidate simple ARM MMIO clock sources Russell King - ARM Linux
2011-05-10  7:27 ` Russell King - ARM Linux
2011-05-10  7:27 ` [PATCH 01/13] Make clocksource name const Russell King - ARM Linux
2011-05-10  7:27   ` Russell King - ARM Linux
2011-05-10  7:27 ` [PATCH 02/13] ARM: s5p: consolidate selection of timer register Russell King - ARM Linux
2011-05-12  7:01   ` Kukjin Kim
2011-05-10  7:28 ` [PATCH 03/13] ARM: omap1: delete useless interrupt handler Russell King - ARM Linux
2011-05-10  7:28   ` Russell King - ARM Linux
2011-05-10 12:49   ` Kevin Hilman
2011-05-10 12:49     ` Kevin Hilman
2011-05-12  7:25     ` Tony Lindgren
2011-05-12  7:25       ` Tony Lindgren
2011-05-10  7:28 ` [PATCH 04/13] ARM: omap1: convert to using readl/writel instead of volatile struct Russell King - ARM Linux
2011-05-10  7:28   ` Russell King - ARM Linux
2011-05-12  7:45   ` Tony Lindgren
2011-05-12  7:45     ` Tony Lindgren
2011-05-10  7:28 ` [PATCH 05/13] ARM: update sa1100 to reflect PXA updates Russell King - ARM Linux
2011-05-10  7:29 ` [PATCH 06/13] clocksource: add common mmio clocksource Russell King - ARM Linux
2011-05-10  7:29   ` Russell King - ARM Linux
2011-05-10  8:38   ` Sascha Hauer
2011-05-10  8:38     ` Sascha Hauer
2011-05-10  8:46     ` Russell King - ARM Linux
2011-05-10  8:46       ` Russell King - ARM Linux
2011-05-12  7:43       ` Tony Lindgren
2011-05-12  7:43         ` Tony Lindgren
2011-05-10  9:59   ` Russell King - ARM Linux
2011-05-10  9:59     ` Russell King - ARM Linux
2011-05-11  8:15   ` viresh kumar
2011-05-11  8:15     ` viresh kumar
2011-05-11  8:35   ` Russell King - ARM Linux [this message]
2011-05-11  8:35     ` [PATCH 06/13 v2] " Russell King - ARM Linux
2011-05-12  8:03   ` [PATCH 06/13] " Thomas Gleixner
2011-05-12  8:03     ` Thomas Gleixner
2011-05-10  7:29 ` [PATCH 07/13] clocksource: convert ARM 32-bit up counting clocksources Russell King - ARM Linux
2011-05-10 21:10   ` Linus Walleij
2011-05-11  7:52     ` Russell King - ARM Linux
2011-05-11  0:16   ` Hans J. Koch
2011-05-11  7:52     ` Russell King - ARM Linux
2011-05-11  8:07       ` Hans J. Koch
2011-05-15  3:53   ` Colin Cross
2011-05-26  8:32   ` Richard Cochran
2011-05-10  7:31 ` [PATCH 08/13] clocksource: convert ARM 32-bit down " Russell King - ARM Linux
2011-05-10 12:39   ` Nicolas Pitre
2011-05-11  7:53     ` Russell King - ARM Linux
2011-05-11 13:45       ` Nicolas Pitre
2011-05-10 21:04   ` Linus Walleij
2011-05-11  7:53     ` Russell King - ARM Linux
2011-05-12 12:47   ` [PATCH 08/13 v2] " Russell King - ARM Linux
2011-05-13 14:30     ` Catalin Marinas
2011-05-10  7:31 ` [PATCH 09/13] clocksource: convert W90x900 24-bit down counting clocksource Russell King - ARM Linux
2011-05-10  7:31 ` [PATCH 10/13] clocksource: convert Integrator/AP 16-bit " Russell King - ARM Linux
2011-05-10  7:32 ` [PATCH 11/13] clocksource: convert SPEAr platforms 16-bit up " Russell King - ARM Linux
2011-05-11  3:31   ` viresh kumar
2011-05-11  7:53     ` Russell King - ARM Linux
2011-05-11  8:13       ` viresh kumar
2011-05-10  7:34 ` [PATCH 12/13] clocksource: convert MXS timrotv2 to 32-bit down " Russell King - ARM Linux
2011-05-16 14:31   ` Shawn Guo
2011-05-16 15:16     ` Shawn Guo
2011-05-16 17:18       ` Russell King - ARM Linux
2011-05-10  7:34 ` [PATCH 13/13] clocksource: convert OMAP1 " Russell King - ARM Linux
2011-05-10  7:34   ` Russell King - ARM Linux
2011-05-12  7:46   ` Tony Lindgren
2011-05-12  7:46     ` Tony Lindgren
2011-05-10  7:39 ` [PATCH 08/13] clocksource: convert ARM 32-bit down counting clocksources Alessandro Rubini
2011-05-10  8:07   ` Russell King - ARM Linux
2011-05-12 13:49 ` [PATCH 14/13] clocksource: ARM sp804: allow clocksource name to be specified Russell King - ARM Linux
2011-05-13 14:32   ` Catalin Marinas
2011-05-12 13:51 ` [PATCH 15/13] clocksource: ARM sp804: obtain sp804 timer rate via clks Russell King - ARM Linux
2011-05-13 15:01   ` Catalin Marinas

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=20110511083552.GF15120@n2100.arm.linux.org.uk \
    --to=linux@arm.linux.org.uk \
    --cc=ccross@android.com \
    --cc=eric.y.miao@gmail.com \
    --cc=hjk@hansjkoch.de \
    --cc=johnstul@us.ibm.com \
    --cc=kaloz@openwrt.org \
    --cc=kernel@pengutronix.de \
    --cc=kernel@wantstofly.org \
    --cc=kgene.kim@samsung.com \
    --cc=khc@pm.waw.pl \
    --cc=konkers@android.com \
    --cc=linus.walleij@stericsson.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=mcuos.com@gmail.com \
    --cc=nico@fluxnic.net \
    --cc=olof@lixom.net \
    --cc=rubini@unipv.it \
    --cc=tglx@linutronix.de \
    --cc=tony@atomide.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: link
Be 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.