Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3660931imu; Sun, 11 Nov 2018 20:49:25 -0800 (PST) X-Google-Smtp-Source: AJdET5e2wq7nf7WZgPTHA2wkET6zpiYs0qk4wuF2lptzLxfA3QO5iMSCznCqdT/7HotuKXt5LGyQ X-Received: by 2002:a17:902:8bc6:: with SMTP id r6-v6mr18442651plo.194.1541998165801; Sun, 11 Nov 2018 20:49:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541998165; cv=none; d=google.com; s=arc-20160816; b=ealtj7XaO7svVIbYc4mDVc6wNwo2LTul5vcb55tQ0+58Vw3uhuTAEhjZFLNPRwErIJ eBihpiA3HR5ZTx1S+Ji21AD8oO2xZiPP8mo7J0DVYDKVYdZbT3G32aGXQJgZcDkDXx1R oOu3qA5QCYTfMQW/oFQ+o/ZR1mrXOZRI0rXacfELWxYzHU7WBVz+u5uEIQl+nHd1gha1 PTRZ/nPKOqHA0VElwnEcDhjxnsCwR9dotyZqm1L8xTjs/SrK45hNAS7Y2JQsN5iEuEre v4p51tetDoEYeOwsvIU0z4I1aQ7aDD4OrU02J7yC3GMLnCA3TVS4VcCFv6LkmnYF+16h qQBg== 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=ZzwlEBiXnok8QJAdZgQFEOPNP6NkKKO8uUqs6kgzCfo=; b=FzxEjULjDe6JtVwsZXwjGhSO/4/Vek/xBUbsv15CzRm43Hz9Dfg8LwSgJm/KYz+CyC M0oALHNF9VKi/d6jvZv7lrBo6FSiHqiExc6CPpN+p1ROakwLdh5h+EXDl+X8iDcbW0t9 PqLs84uf1BkdFprWwBregAsvExWDzbfuu2Th9vxZqz5DdZamnF0hrZt6+IhubhwQylFi xESzQ42l2zeK+Pz/hc8z58KOWzzyDcmuWVcqLWqEJJRdOz+qCdwIyNa1xwIUnYJAprxw gK1IIdN9l1y4RadrNxOmFAGb67yCSz/vAYF/y1JYshnjGNZsB+vxrayfhM3RnHUoRN3W 4SJA== 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 g12-v6si16377561pla.351.2018.11.11.20.49.10; Sun, 11 Nov 2018 20:49:25 -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 S1731265AbeKLOiu (ORCPT + 99 others); Mon, 12 Nov 2018 09:38:50 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:48684 "EHLO kvm5.telegraphics.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730848AbeKLOiX (ORCPT ); Mon, 12 Nov 2018 09:38:23 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 16745297EC; Sun, 11 Nov 2018 23:46:56 -0500 (EST) To: Geert Uytterhoeven Cc: Arnd Bergmann , Stephen N Chivers , Thomas Gleixner , Daniel Lezcano , John Stultz , linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org Message-Id: <6bb4fe390a5b45685f6a6a9a51f151f15d98a235.1541995959.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [RFC PATCH 09/13] m68k: bvme6000: Convert to clocksource API Date: Mon, 12 Nov 2018 15:12:39 +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 --- arch/m68k/bvme6000/config.c | 54 ++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/arch/m68k/bvme6000/config.c b/arch/m68k/bvme6000/config.c index 3bd56bd04690..099cc6edebc8 100644 --- a/arch/m68k/bvme6000/config.c +++ b/arch/m68k/bvme6000/config.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -43,12 +44,6 @@ extern int bvme6000_hwclk (int, struct rtc_time *); extern void bvme6000_reset (void); void bvme6000_set_vectors (void); -/* Save tick handler routine pointer, will point to xtime_update() in - * kernel/timer/timekeeping.c, called via bvme6000_process_int() */ - -static irq_handler_t tick_handler; - - int __init bvme6000_parse_bootinfo(const struct bi_record *bi) { if (be16_to_cpu(bi->tag) == BI_VME_TYPE) @@ -152,13 +147,34 @@ irqreturn_t bvme6000_abort_int (int irq, void *dev_id) return IRQ_HANDLED; } +static u64 bvme6000_read_clk(struct clocksource *cs); + +static struct clocksource bvme6000_clk = { + .name = "rtc", + .rating = 250, + .read = bvme6000_read_clk, + .mask = CLOCKSOURCE_MASK(32), + .flags = CLOCK_SOURCE_IS_CONTINUOUS, +}; + +static u32 clk_total; + +#define RTC_TIMER_CLOCK_FREQ 8000000 +#define RTC_TIMER_CYCLES (RTC_TIMER_CLOCK_FREQ / HZ) +#define RTC_TIMER_COUNT ((RTC_TIMER_CYCLES / 2) - 1) static irqreturn_t bvme6000_timer_int (int irq, void *dev_id) { + irq_handler_t tick_handler = dev_id; volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE; - unsigned char msr = rtc->msr & 0xc0; + unsigned char msr; + unsigned long flags; + local_irq_save(flags); + msr = rtc->msr & 0xc0; rtc->msr = msr | 0x20; /* Ack the interrupt */ + clk_total += RTC_TIMER_CYCLES; + local_irq_restore(flags); return tick_handler(irq, dev_id); } @@ -179,14 +195,13 @@ void bvme6000_sched_init (irq_handler_t timer_routine) rtc->msr = 0; /* Ensure timer registers accessible */ - tick_handler = timer_routine; - if (request_irq(BVME_IRQ_RTC, bvme6000_timer_int, 0, - "timer", bvme6000_timer_int)) + if (request_irq(BVME_IRQ_RTC, bvme6000_timer_int, IRQF_TIMER, + "timer", timer_routine)) panic ("Couldn't register timer int"); rtc->t1cr_omr = 0x04; /* Mode 2, ext clk */ - rtc->t1msb = 39999 >> 8; - rtc->t1lsb = 39999 & 0xff; + rtc->t1msb = RTC_TIMER_COUNT >> 8; + rtc->t1lsb = RTC_TIMER_COUNT & 0xff; rtc->irr_icr1 &= 0xef; /* Route timer 1 to INTR pin */ rtc->msr = 0x40; /* Access int.cntrl, etc */ rtc->pfr_icr0 = 0x80; /* Just timer 1 ints enabled */ @@ -198,6 +213,8 @@ void bvme6000_sched_init (irq_handler_t timer_routine) rtc->msr = msr; + clocksource_register_hz(&bvme6000_clk, RTC_TIMER_CLOCK_FREQ); + if (request_irq(BVME_IRQ_ABORT, bvme6000_abort_int, 0, "abort", bvme6000_abort_int)) panic ("Couldn't register abort int"); @@ -211,7 +228,7 @@ void bvme6000_sched_init (irq_handler_t timer_routine) * results... */ -u32 bvme6000_gettimeoffset(void) +static u64 bvme6000_read_clk(struct clocksource *cs) { unsigned long flags; volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE; @@ -235,19 +252,18 @@ u32 bvme6000_gettimeoffset(void) } while (t1int != (rtc->msr & 0x20) || t1op != (pit->pcdr & 0x04) || abs(ov-v) > 80 || - v > 39960); + v > RTC_TIMER_COUNT - (RTC_TIMER_COUNT / 100)); - v = 39999 - v; + v = RTC_TIMER_COUNT - v; if (!t1op) /* If in second half cycle.. */ - v += 40000; - v /= 8; /* Convert ticks to microseconds */ + v += RTC_TIMER_CYCLES / 2; if (t1int) - v += 10000; /* Int pending, + 10ms */ + v += RTC_TIMER_CYCLES; rtc->msr = msr; local_irq_restore(flags); - return v * 1000; + return clk_total + v; } /* -- 2.18.1