From patchwork Sun Oct 14 22:14:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Domenico Andreoli X-Patchwork-Id: 1591811 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 651E4E00AD for ; Sun, 14 Oct 2012 22:32:44 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TNWhg-0000Wm-0m; Sun, 14 Oct 2012 22:30:36 +0000 Received: from mail-wg0-f49.google.com ([74.125.82.49]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TNWha-0000V6-Nm for linux-arm-kernel@lists.infradead.org; Sun, 14 Oct 2012 22:30:31 +0000 Received: by mail-wg0-f49.google.com with SMTP id gg4so2697866wgb.18 for ; Sun, 14 Oct 2012 15:30:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:user-agent:date:from:to:cc:subject:references :content-disposition; bh=M8gYdYjktw+QaOhkAGJ+QNJzkoaLwB3LgtHI8dMYOBs=; b=U9VHPKMfCEoMV7ngc6fkH6vbZOVNF+/sfCTNxwuPfCh3voMEzogF0XygRDVSshLijj eaGQCq0mKleu3WtNn6nNnNknUo+ndXyOpiuL8VyZ2E62KrP8Rhw9KbIk4ezkKFzMe+Ql TqZUYnb1gcK815iDCUiQtSpzMdA3cHS47VozyaCfvXSR8r4w/u3XYgWbpOUX4+EeawaD Lmsezz+uqcBKzwYCao0nEsu6bZa3B8mBiH7MTRq1C+FpZJkzOG3sSu44eKcVIMLTrZXi atTZatf57Wk7NpeYmR7xMhjvFPrTlhDGYv/0U3rfy1pkXV99cjycz6qwF7d3W6f7fNrO XM7A== Received: by 10.216.135.24 with SMTP id t24mr5775208wei.147.1350253828777; Sun, 14 Oct 2012 15:30:28 -0700 (PDT) Received: from raptus.dandreoli.com (178-85-163-250.dynamic.upc.nl. [178.85.163.250]) by mx.google.com with ESMTPS id v3sm10890339wiw.7.2012.10.14.15.30.26 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 14 Oct 2012 15:30:27 -0700 (PDT) Received: by raptus.dandreoli.com (Postfix, from userid 1000) id C2B603F620A; Mon, 15 Oct 2012 00:30:24 +0200 (CEST) Message-Id: <20121014223024.488228120@gmail.com> User-Agent: quilt/0.60-1 Date: Mon, 15 Oct 2012 00:14:53 +0200 From: Domenico Andreoli To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 3/5] ARM: bcm476x: Add ripple counter References: <20121014221450.866288977@gmail.com> Content-Disposition: inline; filename=arm-bcm476x-add-ripple-counter.patch X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (cavokz[at]gmail.com) -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.49 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Domenico Andreoli , Olof Johansson X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Domenico Andreoli 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 Acked-by: Olof Johansson --- 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(+) 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 #include +#include + #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>;