From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754395AbbJIMUu (ORCPT ); Fri, 9 Oct 2015 08:20:50 -0400 Received: from mail1.bemta12.messagelabs.com ([216.82.251.8]:58555 "EHLO mail1.bemta12.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754261AbbJIMUs (ORCPT ); Fri, 9 Oct 2015 08:20:48 -0400 X-Greylist: delayed 409 seconds by postgrey-1.27 at vger.kernel.org; Fri, 09 Oct 2015 08:20:47 EDT X-Env-Sender: Marc_Gonzalez@sigmadesigns.com X-Msg-Ref: server-9.tower-219.messagelabs.com!1444392835!943252!1 X-Originating-IP: [195.215.56.170] X-StarScan-Received: X-StarScan-Version: 7.19.2; banners=-,-,- X-VirusChecked: Checked Subject: [PATCH v3] clocksource/drivers/tango_xtal: Add new timer for Tango SoCs To: Daniel Lezcano , Thomas Gleixner CC: Mason , LKML References: <5613E45C.5020208@sigmadesigns.com> <5614549F.2070002@linaro.org> <5614D66A.1060402@sigmadesigns.com> <56150369.2050609@sigmadesigns.com> <561510BF.7050207@linaro.org> <56151B5B.90404@sigmadesigns.com> <56154268.5060700@linaro.org> <56157CB9.7010105@free.fr> From: Marc Gonzalez Message-ID: <5617AF82.4000606@sigmadesigns.com> Date: Fri, 9 Oct 2015 14:13:54 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0 SeaMonkey/2.38 MIME-Version: 1.0 In-Reply-To: <56157CB9.7010105@free.fr> Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: 7bit X-Originating-IP: [172.27.0.114] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sigma Designs Tango platforms provide a 27 MHz crystal oscillator. Use it for clocksource, sched_clock, and delay_timer. Signed-off-by: Marc Gonzalez --- I have a nagging feeling that the QUIT_IF macro will get this patch NAKed ;-) My rationale: error-handling tends to take the focus away from the normal path, and put it on the error path. Hiding the details away in a macro helps to keep the error-handling noise to a minimum. --- drivers/clocksource/Kconfig | 4 +++ drivers/clocksource/Makefile | 1 + drivers/clocksource/tango_xtal.c | 61 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 drivers/clocksource/tango_xtal.c diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index 4e57730e0be4..63c878d4d9e3 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -275,6 +275,10 @@ config CLKSRC_MIPS_GIC depends on MIPS_GIC select CLKSRC_OF +config CLKSRC_TANGO_XTAL + bool + select CLKSRC_OF + config CLKSRC_PXA def_bool y if ARCH_PXA || ARCH_SA1100 select CLKSRC_OF if USE_OF diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile index f228354961ca..160970a3963b 100644 --- a/drivers/clocksource/Makefile +++ b/drivers/clocksource/Makefile @@ -55,6 +55,7 @@ obj-$(CONFIG_ARCH_KEYSTONE) += timer-keystone.o obj-$(CONFIG_ARCH_INTEGRATOR_AP) += timer-integrator-ap.o obj-$(CONFIG_CLKSRC_VERSATILE) += versatile.o obj-$(CONFIG_CLKSRC_MIPS_GIC) += mips-gic-timer.o +obj-$(CONFIG_CLKSRC_TANGO_XTAL) += tango_xtal.o obj-$(CONFIG_CLKSRC_IMX_GPT) += timer-imx-gpt.o obj-$(CONFIG_ASM9260_TIMER) += asm9260_timer.o obj-$(CONFIG_H8300) += h8300_timer8.o diff --git a/drivers/clocksource/tango_xtal.c b/drivers/clocksource/tango_xtal.c new file mode 100644 index 000000000000..a3c265eb7236 --- /dev/null +++ b/drivers/clocksource/tango_xtal.c @@ -0,0 +1,61 @@ +#include +#include +#include +#include +#include +#include + +#define QUIT_IF(cond, fmt, ...) do if (cond) { \ + static const char format[] __initconst = fmt; \ + pr_err(format, ## __VA_ARGS__); \ + return; \ +} while (0) + +static void __iomem *xtal_in_cnt; +static struct delay_timer delay_timer; + +static unsigned long notrace read_xtal_counter(void) +{ + return readl_relaxed(xtal_in_cnt); +} + +static u64 notrace read_sched_clock(void) +{ + return read_xtal_counter(); +} + +static cycle_t read_clocksource(struct clocksource *cs) +{ + return read_xtal_counter(); +} + +static struct clocksource tango_xtal = { + .name = "tango-xtal", + .rating = 350, + .read = read_clocksource, + .mask = CLOCKSOURCE_MASK(32), + .flags = CLOCK_SOURCE_IS_CONTINUOUS, +}; + +static void __init tango_clocksource_init(struct device_node *np) +{ + struct clk *clk; + int xtal_freq, err; + + xtal_in_cnt = of_iomap(np, 0); + QUIT_IF(xtal_in_cnt == NULL, "%s: invalid address\n", np->full_name); + + clk = of_clk_get(np, 0); + QUIT_IF(IS_ERR(clk), "%s: invalid clock\n", np->full_name); + + xtal_freq = clk_get_rate(clk); + delay_timer.freq = xtal_freq; + delay_timer.read_current_timer = read_xtal_counter; + + register_current_timer_delay(&delay_timer); + sched_clock_register(read_sched_clock, 32, xtal_freq); + err = clocksource_register_hz(&tango_xtal, xtal_freq); + QUIT_IF(err, "%s: registration failed\n", np->full_name); +} + +CLOCKSOURCE_OF_DECLARE(tango, "sigma,tick-counter", tango_clocksource_init); -- 2.4.5