From patchwork Thu Aug 30 16:37:58 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 1388511 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 A9AA5DF264 for ; Thu, 30 Aug 2012 16:48:12 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T77rg-0001V6-JI; Thu, 30 Aug 2012 16:45:08 +0000 Received: from bombadil.infradead.org ([2001:4830:2446:ff00:4687:fcff:fea6:5117]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T77re-0001Uu-40 for linux-arm-kernel@merlin.infradead.org; Thu, 30 Aug 2012 16:45:06 +0000 Received: from mail.df.lth.se ([194.47.250.12]) by bombadil.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T77rb-0006L7-Cw for linux-arm-kernel@lists.infradead.org; Thu, 30 Aug 2012 16:45:05 +0000 Received: from mer.df.lth.se (mer.df.lth.se [194.47.250.37]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.df.lth.se (Postfix) with ESMTPS id C445165D67; Thu, 30 Aug 2012 18:38:03 +0200 (CEST) Received: from mer.df.lth.se (triad@localhost.localdomain [127.0.0.1]) by mer.df.lth.se (8.14.3/8.14.3/Debian-9.4) with ESMTP id q7UGc3No018279; Thu, 30 Aug 2012 18:38:03 +0200 Received: (from triad@localhost) by mer.df.lth.se (8.14.3/8.14.3/Submit) id q7UGc2jF018278; Thu, 30 Aug 2012 18:38:02 +0200 From: Linus Walleij To: linux-arm-kernel@lists.infradead.org, Alexander Shiyan Subject: [PATCH] ARM: clps711x: convert to clocksource/clockevents Date: Thu, 30 Aug 2012 18:37:58 +0200 Message-Id: <1346344678-18248-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.7.2.5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20120830_124503_849865_6BD74593 X-CRM114-Status: GOOD ( 16.66 ) X-Spam-Score: -2.8 (--) X-Spam-Report: SpamAssassin version 3.3.2 on bombadil.infradead.org summary: Content analysis details: (-2.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [194.47.250.12 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.2 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Thomas Gleixner , arm@kernel.org, Linus Walleij 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 This converts the ageing clps711x timer driver to the modern clocksource/clockevent API. This was blind-coded using the datasheet, it'd be great if someone who has this machine could test it. Signed-off-by: Linus Walleij --- arch/arm/Kconfig | 3 +- arch/arm/mach-clps711x/common.c | 59 +++++++++++++++++++++++++++++--------- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 181b697..8a3da9e 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -383,8 +383,9 @@ config ARCH_HIGHBANK config ARCH_CLPS711X bool "Cirrus Logic CLPS711x/EP721x/EP731x-based" select CPU_ARM720T - select ARCH_USES_GETTIMEOFFSET select NEED_MACH_MEMORY_H + select GENERIC_CLOCKEVENTS + select CLKSRC_MMIO help Support for Cirrus Logic 711x/721x/731x based boards. diff --git a/arch/arm/mach-clps711x/common.c b/arch/arm/mach-clps711x/common.c index f15293b..850697f 100644 --- a/arch/arm/mach-clps711x/common.c +++ b/arch/arm/mach-clps711x/common.c @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include @@ -157,25 +159,42 @@ void __init clps711x_init_irq(void) clps_writel(0, KBDEOI); } -/* - * gettimeoffset() returns time since last timer tick, in usecs. - * - * 'LATCH' is hwclock ticks (see CLOCK_TICK_RATE in timex.h) per jiffy. - * 'tick' is usecs per jiffy. - */ -static unsigned long clps711x_gettimeoffset(void) +static void clps711x_set_mode(enum clock_event_mode mode, + struct clock_event_device *evt) { - unsigned long hwticks; - hwticks = LATCH - (clps_readl(TC2D) & 0xffff); /* since last underflow */ - return (hwticks * (tick_nsec / 1000)) / LATCH; + u32 syscon; + u32 period = DIV_ROUND_CLOSEST(512000, HZ); + + switch (mode) { + case CLOCK_EVT_MODE_PERIODIC: + case CLOCK_EVT_MODE_RESUME: + /* Go into prescaler mode, program frequency */ + syscon = clps_readl(SYSCON1); + syscon |= SYSCON1_TC2M; + clps_writel(syscon, SYSCON1); + clps_writel(period, TC2D); + break; + default: + break; + } } +static struct clock_event_device clockevent_clps711x = { + .name = "clps711x_tc2d", + .rating = 300, + /* Only support periodic mode */ + .features = CLOCK_EVT_FEAT_PERIODIC, + .set_mode = clps711x_set_mode, +}; + /* * IRQ handler for the timer */ static irqreturn_t p720t_timer_interrupt(int irq, void *dev_id) { - timer_tick(); + struct clock_event_device *evt = &clockevent_clps711x; + + evt->event_handler(evt); return IRQ_HANDLED; } @@ -190,17 +209,29 @@ static void __init clps711x_timer_init(void) unsigned int syscon; syscon = clps_readl(SYSCON1); - syscon |= SYSCON1_TC2S | SYSCON1_TC2M; + /* Timer 1 in free running mode */ + syscon &= ~(SYSCON1_TC1M); + /* Timer 2 in prescale mode */ + syscon |= SYSCON1_TC2M; + /* Set both timers to 512 kHz */ + syscon |= (SYSCON1_TC1S | SYSCON1_TC2S); clps_writel(syscon, SYSCON1); - clps_writel(LATCH-1, TC2D); /* 512kHz / 100Hz - 1 */ + /* Start timer 1 in free running mode */ + clps_writel(0xFFFFU, TC1D); + if (clocksource_mmio_init(CLPS711X_VIRT_BASE + TC1D, + "clps711x_tc1d", 512000, 300, 16, + clocksource_mmio_readl_down)) + pr_err("timer: failed to initialize clps711x clock source\n"); + /* Configure and register the clockevent */ + clockevents_config_and_register(&clockevent_clps711x, 512000, + 1, 0xFFFFU); setup_irq(IRQ_TC2OI, &clps711x_timer_irq); } struct sys_timer clps711x_timer = { .init = clps711x_timer_init, - .offset = clps711x_gettimeoffset, }; void clps711x_restart(char mode, const char *cmd)