diff mbox

[v2,3/5] ARM: bcm476x: Add ripple counter

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

Commit Message

Domenico Andreoli Oct. 14, 2012, 10:14 p.m. UTC
From: Domenico Andreoli <domenico.andreoli@linux.com>

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

v2:
* match DT with the specific product names instead of the generic bcm476x
* the counter rate is actually fixed, pulled the option out of DT 
* renamed to match upstream

v1:
* initial release

Signed-off-by: Domenico Andreoli <domenico.andreoli@linux.com>
Acked-by: Olof Johansson <olof@lixom.net>
---
 Documentation/devicetree/bindings/timer/brcm,bcm476x-ripple-counter.txt |   18 ++++
 arch/arm/boot/dts/bcm4760.dtsi                                          |    6 +
 arch/arm/boot/dts/bcm4761.dtsi                                          |    6 +
 drivers/clocksource/bcm476x_timer.c                                     |   46 ++++++++++
 4 files changed, 76 insertions(+)
diff mbox

Patch

Index: b/Documentation/devicetree/bindings/timer/brcm,bcm476x-ripple-counter.txt
===================================================================
--- /dev/null
+++ b/Documentation/devicetree/bindings/timer/brcm,bcm476x-ripple-counter.txt
@@ -0,0 +1,18 @@ 
+Broadcom BCM4760 and BCM4761 Ripple Counter device tree bindings
+----------------------------------------------------------------
+
+The BCM476x provides a 63-bit free running counter driven by a separate
+32kHz clock line.
+
+Required properties:
+
+- compatible : should be "brcm,bcm4760-ripple-counter" or
+                         "brcm,bcm4761-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/bcm476x_timer.c
===================================================================
--- a/drivers/clocksource/bcm476x_timer.c
+++ b/drivers/clocksource/bcm476x_timer.c
@@ -24,6 +24,8 @@ 
 #include <linux/of_platform.h>
 #include <linux/bcm476x_timer.h>
 
+#include <asm/sched_clock.h>
+
 #define TIMER_LOAD_OFFSET          0x00          /* load */
 #define TIMER_VALUE_OFFSET         0x04          /* value */
 #define TIMER_CONTROL_OFFSET       0x08          /* control */
@@ -47,6 +49,21 @@  struct bcm476x_timer {
 	struct irqaction act;
 };
 
+static void __iomem *ripple_counter __read_mostly;
+
+static u32 notrace bcm476x_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 bcm476x_timer *timer)
 {
 	return timer->base + TIMER_LOAD_OFFSET;
@@ -124,6 +141,34 @@  static irqreturn_t bcm476x_timer_interru
 	return IRQ_HANDLED;
 }
 
+static const struct of_device_id bcm476x_ripple_counter_match[] __initconst = {
+	{ .compatible = "brcm,bcm4760-ripple-counter" },
+	{ .compatible = "brcm,bcm4761-ripple-counter" },
+	{}
+};
+
+static void __init bcm476x_ripple_counter_init(void)
+{
+	struct device_node *node;
+	void __iomem *base;
+	int rate = 32000;
+
+	node = of_find_matching_node(NULL, bcm476x_ripple_counter_match);
+	if (!node) {
+		pr_info("No bcm476x 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(bcm476x_sched_read, 32, rate);
+}
+
 static const struct of_device_id bcm476x_timer_match[] __initconst = {
 	{ .compatible = "brcm,bcm4760-system-timer" },
 	{ .compatible = "brcm,bcm4761-system-timer" },
@@ -175,6 +220,7 @@  static void __init bcm476x_timer_init(vo
 	if (setup_irq(irq, &timer->act))
 		panic("Can't set up timer IRQ\n");
 
+	bcm476x_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,12 @@ 
 			clock-frequency = <24000000>;
 		};
 
+		ripple-counter {
+			compatible = "brcm,bcm4760-ripple-counter";
+			reg = <0xbc000 0x1000>;
+			clock-frequency = <32000>;
+		};
+
 		vic0: interrupt-controller@80000 {
 			compatible = "brcm,bcm4760-pl192", "arm,pl192-vic", "arm,primecell";
 			reg = <0x80000 0x1000>;
Index: b/arch/arm/boot/dts/bcm4761.dtsi
===================================================================
--- a/arch/arm/boot/dts/bcm4761.dtsi
+++ b/arch/arm/boot/dts/bcm4761.dtsi
@@ -18,6 +18,12 @@ 
 			clock-frequency = <24000000>;
 		};
 
+		ripple-counter {
+			compatible = "brcm,bcm4761-ripple-counter";
+			reg = <0xbc000 0x1000>;
+			clock-frequency = <32000>;
+		};
+
 		vic0: interrupt-controller@80000 {
 			compatible = "brcm,bcm4761-pl192", "arm,pl192-vic", "arm,primecell";
 			reg = <0x80000 0x1000>;