Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4408530imu; Fri, 30 Nov 2018 17:01:59 -0800 (PST) X-Google-Smtp-Source: AFSGD/VA9sef/SwR7VF/WyxYE/RvXL21TnxRGmRMaMIAhXkLseAPQWb9cRqKBnSkp65Y9dmDk0/k X-Received: by 2002:a17:902:bc3:: with SMTP id 61mr7772923plr.15.1543626119471; Fri, 30 Nov 2018 17:01:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543626119; cv=none; d=google.com; s=arc-20160816; b=kQhDyiTXDcVQBF+qAM0n43YW19mJ0wPsTCZp9oT5H/H2UsfbWZV4oZedMXY5HOZeaV 7XsHJlKJRb0RDH0sXvz0YB4nHraE5X4VgNpyBjg0CVLSA+zjvMZxK4/aeM1wSNLQYJ4G m00BNiWsLA9ieA3EolH4Qg2P+HzV0E5mvrqPMtu+Ie5SGOWKTMOMEK/12GJmXdICq5o5 4ZY60soygs8oFBl/eSqYS7NVdz1XeSfebzXzNptYXbYETcjNcDO5ctV8X8aKouqxZr1Z kyaJudyU1IducQfgPcKF7bCPJWj+kE2sOThFKwAkCZWyiIpIQY9QyhYsppSR5Fk7HNqq EMDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:subject:from:references:in-reply-to :message-id:cc:to; bh=EYjJT9ZA6Qb+M0RLMXOPeIpa0zVphaZ00Pad2VvGGts=; b=XIO6SyRGhmvJ9CsU5Eu0G7sI2+nhfYsBfZ+i9MFWdsEgX4G5AMuur3AuetRwbsH7mL 2whtrS5z4gOivJCgb4Z4E1kRaAQ7kXAU7/U1EPhmj4Woyune7TS26CqLxlfF4vVJhXbF xh5nGfgEIy4cclelUCO6YEcaOM48XTs9doS1axfsuiU4GhMwPAHRDjsQNfUH1D8ai6eY 8z69kww+VqrqDqCzEWmRqSdf08hV2oX70H6xVqcLkQZskfRna3htSCSFRUK4ARyCEZf2 g30OX6yjb0LA79W2EPLKHaJ1hqSHr4JGofjVW+/s17FmZCmZedjGr+1M6trVPDyvlmbb 1vTg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u188si6275556pfb.232.2018.11.30.17.01.44; Fri, 30 Nov 2018 17:01:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726893AbeLAML6 (ORCPT + 99 others); Sat, 1 Dec 2018 07:11:58 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:38148 "EHLO kvm5.telegraphics.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726808AbeLAMLb (ORCPT ); Sat, 1 Dec 2018 07:11:31 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 2F0E5281F4; Fri, 30 Nov 2018 20:00:15 -0500 (EST) To: Geert Uytterhoeven , Philip Blundell Cc: Andreas Schwab , Arnd Bergmann , Stephen N Chivers , Thomas Gleixner , Kars de Jong , Daniel Lezcano , Michael Schmitz , John Stultz , Linus Walleij , linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org Message-Id: <8cd8b5a25153ab7c744bd110aa47e73c6275ad97.1543625590.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH v4 08/14] m68k: hp300: Convert to clocksource API Date: Sat, 01 Dec 2018 11:53:10 +1100 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a platform clocksource by adapting the existing arch_gettimeoffset implementation. Signed-off-by: Finn Thain Acked-by: Linus Walleij --- Changed since v1: - Moved clk_total access to within the irq lock. - Use type u32 for tick counter. --- arch/m68k/hp300/time.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/arch/m68k/hp300/time.c b/arch/m68k/hp300/time.c index d30b03ea93a2..90982803a629 100644 --- a/arch/m68k/hp300/time.c +++ b/arch/m68k/hp300/time.c @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -19,6 +20,18 @@ #include #include +static u64 hp300_read_clk(struct clocksource *cs); + +static struct clocksource hp300_clk = { + .name = "timer", + .rating = 250, + .read = hp300_read_clk, + .mask = CLOCKSOURCE_MASK(32), + .flags = CLOCK_SOURCE_IS_CONTINUOUS, +}; + +static u32 clk_total; + /* Clock hardware definitions */ #define CLOCKBASE 0xf05f8000 @@ -32,9 +45,10 @@ #define CLKMSB3 0xD /* This is for machines which generate the exact clock. */ -#define USECS_PER_JIFFY (1000000/HZ) -#define INTVAL ((10000 / 4) - 1) +#define HP300_TIMER_CLOCK_FREQ 250000 +#define HP300_TIMER_CYCLES (HP300_TIMER_CLOCK_FREQ / HZ) +#define INTVAL (HP300_TIMER_CYCLES - 1) static irqreturn_t hp300_tick(int irq, void *dev_id) { @@ -45,6 +59,7 @@ static irqreturn_t hp300_tick(int irq, void *dev_id) local_irq_save(flags); in_8(CLOCKBASE + CLKSR); asm volatile ("movpw %1@(5),%0" : "=d" (tmp) : "a" (CLOCKBASE)); + clk_total += INTVAL; timer_routine(0, NULL); local_irq_restore(flags); @@ -53,20 +68,26 @@ static irqreturn_t hp300_tick(int irq, void *dev_id) return IRQ_HANDLED; } -u32 hp300_gettimeoffset(void) +static u64 hp300_read_clk(struct clocksource *cs) { - /* Read current timer 1 value */ + unsigned long flags; unsigned char lsb, msb1, msb2; - unsigned short ticks; + u32 ticks; + local_irq_save(flags); + /* Read current timer 1 value */ msb1 = in_8(CLOCKBASE + 5); lsb = in_8(CLOCKBASE + 7); msb2 = in_8(CLOCKBASE + 5); if (msb1 != msb2) /* A carry happened while we were reading. Read it again */ lsb = in_8(CLOCKBASE + 7); + ticks = INTVAL - ((msb2 << 8) | lsb); - return ((USECS_PER_JIFFY * ticks) / INTVAL) * 1000; + ticks += clk_total; + local_irq_restore(flags); + + return ticks; } void __init hp300_sched_init(irq_handler_t vector) @@ -76,9 +97,11 @@ void __init hp300_sched_init(irq_handler_t vector) asm volatile(" movpw %0,%1@(5)" : : "d" (INTVAL), "a" (CLOCKBASE)); - if (request_irq(IRQ_AUTO_6, hp300_tick, 0, "timer tick", vector)) + if (request_irq(IRQ_AUTO_6, hp300_tick, IRQF_TIMER, "timer tick", vector)) pr_err("Couldn't register timer interrupt\n"); out_8(CLOCKBASE + CLKCR2, 0x1); /* select CR1 */ out_8(CLOCKBASE + CLKCR1, 0x40); /* enable irq */ + + clocksource_register_hz(&hp300_clk, HP300_TIMER_CLOCK_FREQ); } -- 2.18.1