Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2161165imu; Sun, 18 Nov 2018 17:23:36 -0800 (PST) X-Google-Smtp-Source: AJdET5eUVz0RXt5NUyKthW8dfaow8fJLASJ+MZvGIUzIxW/JJ1q1SN+G3QysWvpGBF2eRnm8RCng X-Received: by 2002:a62:ed09:: with SMTP id u9-v6mr20443792pfh.188.1542590616370; Sun, 18 Nov 2018 17:23:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542590616; cv=none; d=google.com; s=arc-20160816; b=dG0ygqVPV6wnC4ewnITdssVMmG13AmvmfnNsj2cBuBC42dkcmsYT6yxugizIUKXr0t R+ZAHw+xwOGSerS8TIpZueqmUvnHSofk4zoqXZ1Khj73A7ve43VvVB+kjg+gT3ED1LEH V1HXcjLKdePrlDXq1lC7XiwFbONi1APjsbpSIu2sjeGEHUVjTBr/g16/mZwvR5bPtZgj DnIHG1tLyeqYhkEiVDyTGBleDCTCDAupc/ZQygioP5JQCpYBgh8BZnYUlR409bBMVWjf r61Swl1n5bNcpcqC7ncs8hbKRUTluhsft8p7e3QqRTeCbott8mn9Oh04nX8uhVYOlhOS zxbg== 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=HTcQgK8HKScEOL/iKv52Nlr0JDA8qIIvnn9Qbo+BTpc=; b=yN/w6mN255eoLsaOrIflvbSvBi8yJfbarzypa9ErV0Oae3uNtF74bllncozq8uIIU6 brQYjhz6E+Jcs+tPwUCUoLv22GiYREtS70ZZJeGig1AMhlahEyGv40g2QYHnst76cvJZ KKy89UWIHV4cPC0yrSEHPfq8/JzZSb99amjFB0tx560q0JdJpROxH+AC76aRSuhdGcS1 7ansnU8mYxWI9ali3F5psqx1u+xxzpQ8IR/1Sm6z7GQRFWS19ruS7iF51dJA1bydIJ/y L/IT4DFFAFap/src9DVQcpcU2LMr63Uj8xN/WF7H/5560k+L3nfQE6QxSr9LB+jaNwqW 1BLg== 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 o68si5804659pfo.140.2018.11.18.17.23.21; Sun, 18 Nov 2018 17:23:36 -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 S1728161AbeKSLoU (ORCPT + 99 others); Mon, 19 Nov 2018 06:44:20 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:49284 "EHLO kvm5.telegraphics.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728033AbeKSLoT (ORCPT ); Mon, 19 Nov 2018 06:44:19 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 2D37A29DFF; Sun, 18 Nov 2018 20:22:18 -0500 (EST) To: Geert Uytterhoeven , Joshua Thompson Cc: Andreas Schwab , Arnd Bergmann , Stephen N Chivers , Thomas Gleixner , Daniel Lezcano , Michael Schmitz , John Stultz , Linus Walleij , linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org Message-Id: In-Reply-To: References: From: Finn Thain Subject: [RFC PATCH v2 10/14] m68k: mac: Convert to clocksource API Date: Mon, 19 Nov 2018 12:10:38 +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 Tested-by: Stan Johnson --- Changed since v1: - Moved clk_total access to within the irq lock. - Use type u32 for tick counter. --- arch/m68k/mac/via.c | 46 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/arch/m68k/mac/via.c b/arch/m68k/mac/via.c index d1dbf9017300..de59a5cb4250 100644 --- a/arch/m68k/mac/via.c +++ b/arch/m68k/mac/via.c @@ -23,6 +23,7 @@ * */ +#include #include #include #include @@ -573,16 +574,40 @@ EXPORT_SYMBOL(via2_scsi_drq_pending); /* timer and clock source */ #define VIA_CLOCK_FREQ 783360 /* VIA "phase 2" clock in Hz */ -#define VIA_TIMER_INTERVAL (1000000 / HZ) /* microseconds per jiffy */ #define VIA_TIMER_CYCLES (VIA_CLOCK_FREQ / HZ) /* clock cycles per jiffy */ #define VIA_TC (VIA_TIMER_CYCLES - 2) /* including 0 and -1 */ #define VIA_TC_LOW (VIA_TC & 0xFF) #define VIA_TC_HIGH (VIA_TC >> 8) +static u64 mac_read_clk(struct clocksource *cs); + +static struct clocksource mac_clk = { + .name = "via1", + .rating = 250, + .read = mac_read_clk, + .mask = CLOCKSOURCE_MASK(32), + .flags = CLOCK_SOURCE_IS_CONTINUOUS, +}; + +static u32 clk_total; +static u32 clk_offset; + +static irqreturn_t via_timer_handler(int irq, void *dev_id) +{ + irq_handler_t timer_routine = dev_id; + + clk_total += VIA_TIMER_CYCLES; + clk_offset = 0; + timer_routine(0, NULL); + + return IRQ_HANDLED; +} + void __init via_init_clock(irq_handler_t timer_routine) { - if (request_irq(IRQ_MAC_TIMER_1, timer_routine, 0, "timer", NULL)) { + if (request_irq(IRQ_MAC_TIMER_1, via_timer_handler, IRQF_TIMER, "timer", + timer_routine)) { pr_err("Couldn't register %s interrupt\n", "timer"); return; } @@ -592,13 +617,16 @@ void __init via_init_clock(irq_handler_t timer_routine) via1[vT1CL] = VIA_TC_LOW; via1[vT1CH] = VIA_TC_HIGH; via1[vACR] |= 0x40; + + clocksource_register_hz(&mac_clk, VIA_CLOCK_FREQ); } -u32 mac_gettimeoffset(void) +static u64 mac_read_clk(struct clocksource *cs) { unsigned long flags; u8 count_high; - u16 count, offset = 0; + u16 count; + u32 ticks; /* * Timer counter wrap-around is detected with the timer interrupt flag @@ -617,11 +645,11 @@ u32 mac_gettimeoffset(void) /* spin */; } if (via1[vIFR] & VIA_TIMER_1_INT) - offset = VIA_TIMER_CYCLES; - local_irq_restore(flags); - + clk_offset = VIA_TIMER_CYCLES; count = count_high << 8; - count = VIA_TIMER_CYCLES - count + offset; + ticks = VIA_TIMER_CYCLES - count; + ticks += clk_offset + clk_total; + local_irq_restore(flags); - return ((count * VIA_TIMER_INTERVAL) / VIA_TIMER_CYCLES) * 1000; + return ticks; } -- 2.18.1