From: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
To: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
Cc: Russell King <linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org>,
Rob Herring <rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>,
Sascha Hauer <kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>,
Mike Turquette <mturquette-l0cyMroinI0@public.gmane.org>
Subject: [RFC v2 6/9] arm/dt: add devicetree support to sp804 timer support
Date: Mon, 12 Dec 2011 15:02:06 -0700 [thread overview]
Message-ID: <1323727329-4989-6-git-send-email-grant.likely@secretlab.ca> (raw)
In-Reply-To: <1323727329-4989-1-git-send-email-grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
This patch adds support to the sp804 code for retrieving timer
configuration from the device tree. sp804 channels can be used as
a clock event device or a clock source.
Signed-off-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
Cc: Russell King <linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org>
---
arch/arm/common/timer-sp.c | 72 ++++++++++++++++++++++++++---
arch/arm/include/asm/hardware/timer-sp.h | 2 +
2 files changed, 66 insertions(+), 8 deletions(-)
diff --git a/arch/arm/common/timer-sp.c b/arch/arm/common/timer-sp.c
index 2393b5b..93aed48 100644
--- a/arch/arm/common/timer-sp.c
+++ b/arch/arm/common/timer-sp.c
@@ -25,16 +25,18 @@
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_clk.h>
+#include <linux/of_irq.h>
#include <asm/hardware/arm_timer.h>
-static long __init sp804_get_clock_rate(const char *name)
+static long __init sp804_get_clock_rate(struct clk *clk, const char *name)
{
- struct clk *clk;
long rate;
int err;
- clk = clk_get_sys("sp804", name);
if (IS_ERR(clk)) {
pr_err("sp804: %s clock not found: %d\n", name,
(int)PTR_ERR(clk));
@@ -67,9 +69,10 @@ static long __init sp804_get_clock_rate(const char *name)
return rate;
}
-void __init sp804_clocksource_init(void __iomem *base, const char *name)
+static void __init __sp804_clocksource_init(void __iomem *base,
+ const char *name, struct clk *clk)
{
- long rate = sp804_get_clock_rate(name);
+ long rate = sp804_get_clock_rate(clk, name);
if (rate < 0)
return;
@@ -85,6 +88,10 @@ void __init sp804_clocksource_init(void __iomem *base, const char *name)
rate, 200, 32, clocksource_mmio_readl_down);
}
+void __init sp804_clocksource_init(void __iomem *base, const char *name)
+{
+ __sp804_clocksource_init(base, name, clk_get_sys("sp804", name));
+}
static void __iomem *clkevt_base;
static unsigned long clkevt_reload;
@@ -158,11 +165,11 @@ static struct irqaction sp804_timer_irq = {
.dev_id = &sp804_clockevent,
};
-void __init sp804_clockevents_init(void __iomem *base, unsigned int irq,
- const char *name)
+static void __init __sp804_clockevents_init(void __iomem *base,
+ unsigned int irq, const char *name, struct clk *clk)
{
struct clock_event_device *evt = &sp804_clockevent;
- long rate = sp804_get_clock_rate(name);
+ long rate = sp804_get_clock_rate(clk, name);
if (rate < 0)
return;
@@ -179,3 +186,52 @@ void __init sp804_clockevents_init(void __iomem *base, unsigned int irq,
setup_irq(irq, &sp804_timer_irq);
clockevents_register_device(evt);
}
+
+void __init sp804_clockevents_init(void __iomem *base, unsigned int irq,
+ const char *name)
+{
+ __sp804_clockevents_init(base, irq, name, clk_get_sys("sp804", name));
+}
+
+#ifdef CONFIG_OF
+void __init sp804_dt_setup(struct device_node *node)
+{
+ struct clk *clk;
+ unsigned int irq;
+ __iomem void * base;
+
+ pr_debug("%s(): Setting up sp804 clock %s\n", __func__, node->name);
+
+ /* Find the base address of the clock */
+ base = of_iomap(node, 0);
+ if (!base) {
+ pr_err("ERROR: Cannot get base address of sp804 %s\n",
+ node->full_name);
+ return;
+ }
+
+ writel(0, base + TIMER_CTRL); /* Disable the clock */
+
+ clk = of_clk_get(node, 0);
+ if (!clk) {
+ pr_err("ERROR: Cannot get clock for sp804 %s\n", node->name);
+ return;
+ }
+
+ /*
+ * Figure out how to use this clock
+ *
+ * Note: This is kind of ugly since it requires linux-specific
+ * properties in the device tree so that Linux knows which sp804
+ * channels can be used as the clock source and the clock events
+ * trigger. Something OS agnostic would be nicer, but it isn't
+ * obvious what that should look like.
+ */
+ if (of_get_property(node, "linux,clock-source", NULL)) {
+ __sp804_clocksource_init(base, node->full_name, clk);
+ } else if (of_get_property(node, "linux,clockevents-device", NULL)) {
+ irq = irq_of_parse_and_map(node, 0);
+ __sp804_clockevents_init(base, irq, node->full_name, clk);
+ };
+}
+#endif /* CONFIG_OF */
diff --git a/arch/arm/include/asm/hardware/timer-sp.h b/arch/arm/include/asm/hardware/timer-sp.h
index 4384d81..edd0ec3 100644
--- a/arch/arm/include/asm/hardware/timer-sp.h
+++ b/arch/arm/include/asm/hardware/timer-sp.h
@@ -1,2 +1,4 @@
+struct device_node;
void sp804_clocksource_init(void __iomem *, const char *);
void sp804_clockevents_init(void __iomem *, unsigned int, const char *);
+void sp804_dt_setup(struct device_node *node);
--
1.7.5.4
next prev parent reply other threads:[~2011-12-12 22:02 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-12 22:02 [RFC v2 1/9] arm/versatile*: merge all versatile struct clk definitions Grant Likely
[not found] ` <1323727329-4989-1-git-send-email-grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
2011-12-12 22:02 ` [RFC v2 2/9] arm/versatile*: Consolidate clk_ops and setvco implementations Grant Likely
2011-12-12 22:02 ` [RFC v2 3/9] of: Add of_property_match_string() to find index into a string list Grant Likely
2011-12-12 22:02 ` [RFC v2 4/9] of: add clock providers Grant Likely
[not found] ` <1323727329-4989-4-git-send-email-grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
2011-12-12 23:29 ` Jamie Iles
2011-12-13 17:54 ` Grant Likely
2011-12-13 18:01 ` Rob Herring
2011-12-13 18:03 ` Grant Likely
2011-12-15 13:51 ` Shawn Guo
[not found] ` <20111215135129.GA2831-+NayF8gZjK2ctlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2011-12-15 14:23 ` Rob Herring
2011-12-15 15:13 ` Shawn Guo
[not found] ` <20111215151335.GB2831-+NayF8gZjK2ctlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2011-12-15 17:37 ` Grant Likely
2012-01-10 21:33 ` Jamie Iles
2012-01-12 4:46 ` Grant Likely
2012-01-12 10:07 ` Jamie Iles
2012-01-12 18:44 ` Turquette, Mike
2012-01-12 19:16 ` Grant Likely
[not found] ` <CACxGe6vqb8AZcZb5WMvfmLsUZH7=SEtBrJCSfsFmDYpKX42MzA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-01-13 12:47 ` Shawn Guo
2012-01-14 4:30 ` Turquette, Mike
2012-01-14 5:40 ` Shawn Guo
2012-01-13 13:50 ` Shawn Guo
[not found] ` <20120113135036.GC17029-rvtDTF3kK1ictlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2012-01-13 14:05 ` Rob Herring
[not found] ` <4F103A21.1050403-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-01-13 14:38 ` Shawn Guo
2012-01-17 20:44 ` Stephen Warren
2012-01-17 22:47 ` Grant Likely
2012-01-17 23:37 ` Turquette, Mike
[not found] ` <CAJOA=zMgGsZKGQ-EfSnXDY_WoFrzG6XPZtuxANFKqdL8CAaYrw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-01-17 23:49 ` Grant Likely
2012-01-18 0:05 ` Stephen Warren
2011-12-12 22:02 ` Grant Likely [this message]
2011-12-12 23:54 ` [RFC v2 6/9] arm/dt: add devicetree support to sp804 timer support Rob Herring
[not found] ` <4EE69446.2060009-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-12-13 0:29 ` Grant Likely
2011-12-12 22:02 ` [RFC v2 9/9] arm/highbank: Use clock binding common support code Grant Likely
2011-12-12 22:02 ` [RFC v2 5/9] dt/clock: Add handling for fixed clocks and a clock node setup iterator Grant Likely
[not found] ` <1323727329-4989-5-git-send-email-grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
2011-12-15 15:19 ` Shawn Guo
2011-12-12 22:02 ` [RFC v2 7/9] arm/dt: Common plat-versatile support for icst and sp804 based system clocks Grant Likely
[not found] ` <1323727329-4989-7-git-send-email-grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
2012-01-17 21:05 ` Stephen Warren
2012-01-17 22:02 ` Rob Herring
2012-01-17 22:59 ` Grant Likely
2011-12-12 22:02 ` [RFC v2 8/9] dt/arm: versatile add clock parsing Grant Likely
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=1323727329-4989-6-git-send-email-grant.likely@secretlab.ca \
--to=grant.likely-s3s/wqlpoipyb63q8fvjnq@public.gmane.org \
--cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
--cc=kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org \
--cc=mturquette-l0cyMroinI0@public.gmane.org \
--cc=rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).