diff mbox

[v4,3/4] ARM: bcm4760: Add ripple counter

Message ID 20130914152124.062337974@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Domenico Andreoli Sept. 14, 2013, 3:20 p.m. UTC
From: Domenico Andreoli <domenico.andreoli@linux.com>

The BCM4760's free runner counter is used as sched clock source.

v2,v3,v4:
* unchanged 

v1:
* initial release

Cc: John Stultz <john.stultz@linaro.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: devicetree@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Signed-off-by: Domenico Andreoli <domenico.andreoli@linux.com>
---
 Documentation/devicetree/bindings/timer/brcm,bcm4760-ripple-counter.txt |   17 ++++
 arch/arm/boot/dts/bcm4760.dtsi                                          |    5 +
 drivers/clocksource/bcm4760_timer.c                                     |   44 ++++++++++
 3 files changed, 66 insertions(+)
diff mbox

Patch

Index: b/Documentation/devicetree/bindings/timer/brcm,bcm4760-ripple-counter.txt
===================================================================
--- /dev/null
+++ b/Documentation/devicetree/bindings/timer/brcm,bcm4760-ripple-counter.txt
@@ -0,0 +1,17 @@ 
+Broadcom BCM4760 Ripple Counter device tree bindings
+----------------------------------------------------
+
+The BCM4760 provides a 63-bit free running counter driven by a separate
+32kHz clock line.
+
+Required properties:
+
+- compatible : should be "brcm,bcm4760-ripple-counter"
+- reg : Specifies base physical address and size of the registers.
+
+Example:
+
+ripple-counter {
+	compatible = "brcm,bcm4760-ripple-counter";
+	reg = <0xbc000 0x1000>;
+};
Index: b/drivers/clocksource/bcm4760_timer.c
===================================================================
--- a/drivers/clocksource/bcm4760_timer.c
+++ b/drivers/clocksource/bcm4760_timer.c
@@ -19,6 +19,7 @@ 
 #include <linux/slab.h>
 #include <linux/interrupt.h>
 #include <linux/clockchips.h>
+#include <linux/sched_clock.h>
 #include <linux/of_address.h>
 #include <linux/of_irq.h>
 #include <linux/of_platform.h>
@@ -46,6 +47,21 @@  struct bcm4760_timer {
 	struct irqaction act;
 };
 
+static void __iomem *ripple_counter __read_mostly;
+
+static u32 notrace bcm4760_sched_read(void)
+{
+	u32 lo, hi;
+
+	/* access to the counter must happen in the lo-hi order even if
+	 * only the lower 32-bit part is of interest
+	 */
+	lo = readl(ripple_counter);
+	hi = readl(ripple_counter + 4);
+
+	return lo;
+}
+
 static inline u32 bcm4760_readl(struct bcm4760_timer *timer, unsigned long reg)
 {
 	return readl(timer->base + reg);
@@ -105,6 +121,33 @@  static irqreturn_t bcm4760_timer_interru
 	return IRQ_HANDLED;
 }
 
+static const struct of_device_id bcm4760_ripple_counter_match[] __initconst = {
+	{ .compatible = "brcm,bcm4760-ripple-counter" },
+	{},
+};
+
+static void __init bcm4760_ripple_counter_init(void)
+{
+	struct device_node *node;
+	void __iomem *base;
+	int rate = 32000;
+
+	node = of_find_matching_node(NULL, bcm4760_ripple_counter_match);
+	if (!node) {
+		pr_info("No bcm4760 ripple counter node");
+		return;
+	}
+
+	base = of_iomap(node, 0);
+	if (!base) {
+		pr_err("Can't remap ripple counter registers");
+		return;
+	}
+
+	ripple_counter = base;
+	setup_sched_clock(bcm4760_sched_read, 32, rate);
+}
+
 static void __init bcm4760_init_time(struct device_node *node)
 {
 	void __iomem *base;
@@ -133,6 +176,7 @@  static void __init bcm4760_init_time(str
 	timer->evt.set_next_event = bcm4760_timer_set_next_event;
 	timer->evt.cpumask = cpumask_of(0);
 
+	bcm4760_ripple_counter_init();
 	clockevents_config_and_register(&timer->evt, freq, 0xf, 0xffffffff);
 
 	timer->act.name = node->name;
Index: b/arch/arm/boot/dts/bcm4760.dtsi
===================================================================
--- a/arch/arm/boot/dts/bcm4760.dtsi
+++ b/arch/arm/boot/dts/bcm4760.dtsi
@@ -34,6 +34,11 @@ 
 			interrupts = <4>, <11>;
 		};
 
+		ripple-counter {
+			compatible = "brcm,bcm4760-ripple-counter";
+			reg = <0xbc000 0x1000>;
+		};
+
 		vic0: interrupt-controller@80000 {
 			compatible = "brcm,bcm4760-pl192", "arm,pl192-vic", "arm,primecell";
 			reg = <0x80000 0x1000>;