diff mbox

[v2,4/5] ARM: bcm4760: Add ripple counter

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

Commit Message

Domenico Andreoli July 26, 2013, 2:56 p.m. UTC
From: Domenico Andreoli <domenico.andreoli@linux.com>

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

v2:
* 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 void __iomem *to_load(struct bcm4760_timer *timer)
 {
 	return timer->base + TIMER_LOAD_OFFSET;
@@ -123,6 +139,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;
@@ -164,6 +207,7 @@  static void __init bcm4760_init_time(str
 	if (setup_irq(irq, &timer->act))
 		panic("Can't set up timer IRQ\n");
 
+	bcm4760_ripple_counter_init();
 	clockevents_config_and_register(&timer->evt, freq, 0xf, 0xffffffff);
 }
 
Index: b/arch/arm/boot/dts/bcm4760.dtsi
===================================================================
--- a/arch/arm/boot/dts/bcm4760.dtsi
+++ b/arch/arm/boot/dts/bcm4760.dtsi
@@ -18,6 +18,11 @@ 
 			clock-frequency = <24000000>;
 		};
 
+		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>;