linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Finn Thain <fthain@telegraphics.com.au>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Andreas Schwab <schwab@linux-m68k.org>,
	Arnd Bergmann <arnd@arndb.de>,
	Stephen N Chivers <schivers@csc.com.au>,
	Thomas Gleixner <tglx@linutronix.de>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Michael Schmitz <schmitzmic@gmail.com>,
	John Stultz <john.stultz@linaro.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org
Subject: [RFC PATCH v2 08/14] m68k: bvme6000: Convert to clocksource API
Date: Mon, 19 Nov 2018 12:10:38 +1100	[thread overview]
Message-ID: <6597648024f9005bc763222c557f90a73f79e225.1542589838.git.fthain@telegraphics.com.au> (raw)
In-Reply-To: <cover.1542589838.git.fthain@telegraphics.com.au>

Add a platform clocksource by adapting the existing arch_gettimeoffset
implementation.

Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
---
Changed since v1:
 - Moved clk_total access to within the irq lock.
---
 arch/m68k/bvme6000/config.c | 52 +++++++++++++++++++++++++++----------
 1 file changed, 38 insertions(+), 14 deletions(-)

diff --git a/arch/m68k/bvme6000/config.c b/arch/m68k/bvme6000/config.c
index c27c104ac7e7..9691d741e9dc 100644
--- a/arch/m68k/bvme6000/config.c
+++ b/arch/m68k/bvme6000/config.c
@@ -18,6 +18,7 @@
 #include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/tty.h>
+#include <linux/clocksource.h>
 #include <linux/console.h>
 #include <linux/linkage.h>
 #include <linux/init.h>
@@ -147,6 +148,21 @@ 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)
 {
@@ -158,6 +174,7 @@ static irqreturn_t bvme6000_timer_int (int irq, void *dev_id)
     local_irq_save(flags);
     msr = rtc->msr & 0xc0;
     rtc->msr = msr | 0x20;		/* Ack the interrupt */
+    clk_total += RTC_TIMER_CYCLES;
     timer_routine(0, NULL);
     local_irq_restore(flags);
 
@@ -180,13 +197,13 @@ void bvme6000_sched_init (irq_handler_t timer_routine)
 
     rtc->msr = 0;	/* Ensure timer registers accessible */
 
-    if (request_irq(BVME_IRQ_RTC, bvme6000_timer_int, 0,
-				"timer", timer_routine))
+    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,14 +215,14 @@ 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");
 }
 
 
-/* This is always executed with interrupts disabled.  */
-
 /*
  * NOTE:  Don't accept any readings within 5us of rollover, as
  * the T1INT bit may be a little slow getting set.  There is also
@@ -213,14 +230,18 @@ 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;
     volatile PitRegsPtr pit = (PitRegsPtr)BVME_PIT_BASE;
-    unsigned char msr = rtc->msr & 0xc0;
+    unsigned char msr;
     unsigned char t1int, t1op;
     u32 v = 800000, ov;
 
+    local_irq_save(flags);
+
+    msr = rtc->msr & 0xc0;
     rtc->msr = 0;	/* Ensure timer registers accessible */
 
     do {
@@ -233,17 +254,20 @@ 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;
 
-    return v * 1000;
+    v += clk_total;
+
+    local_irq_restore(flags);
+
+    return v;
 }
 
 /*
-- 
2.18.1


  parent reply	other threads:[~2018-11-19  1:22 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-19  1:10 [RFC PATCH v2 00/14] m68k: Drop arch_gettimeoffset and adopt clocksource API Finn Thain
2018-11-19  1:10 ` [RFC PATCH v2 09/14] m68k: hp300: Remove hp300_gettimeoffset() Finn Thain
2018-11-20  9:09   ` Kars de Jong
2018-11-20 23:13     ` Finn Thain
2018-11-21  8:10       ` Geert Uytterhoeven
2018-11-21  8:41         ` Finn Thain
2018-11-21  8:55           ` Geert Uytterhoeven
2018-11-21  9:47             ` Finn Thain
2018-11-21 10:02               ` Geert Uytterhoeven
2018-11-21 11:14                 ` Finn Thain
2018-11-25  1:15                   ` Finn Thain
2018-11-25  2:44                     ` Michael Schmitz
2018-11-25  3:25                       ` Finn Thain
2018-11-21  8:22       ` Kars de Jong
2018-11-19  1:10 ` [RFC PATCH v2 07/14] m68k: atari: Convert to clocksource API Finn Thain
2018-11-19  8:35   ` Michael Schmitz
2018-11-20  8:10   ` Linus Walleij
2018-11-20  8:19     ` Geert Uytterhoeven
2018-11-20  9:30     ` Finn Thain
2018-11-20  9:53       ` Linus Walleij
2018-11-20 10:02     ` Andreas Schwab
2018-11-24  2:03       ` Michael Schmitz
2018-11-24  3:08         ` Finn Thain
2018-11-19  1:10 ` Finn Thain [this message]
2018-11-19  1:10 ` [RFC PATCH v2 11/14] m68k: mvme147: " Finn Thain
2018-11-19  1:10 ` [RFC PATCH v2 10/14] m68k: mac: " Finn Thain
2018-11-20  8:15   ` Linus Walleij
2018-11-20  9:00     ` Finn Thain
2018-11-20  9:59       ` Linus Walleij
2018-11-19  1:10 ` [RFC PATCH v2 04/14] m68k: apollo, q40, sun3, sun3x: Remove arch_gettimeoffset implementations Finn Thain
2018-11-19  1:10 ` [RFC PATCH v2 01/14] m68k: Call timer_interrupt() with interrupts disabled Finn Thain
2018-11-19  1:10 ` [RFC PATCH v2 03/14] m68k: mac: Clean up unused timer definitions Finn Thain
2018-11-20  1:02   ` Finn Thain
2018-11-19  1:10 ` [RFC PATCH v2 12/14] m68k: mvme147: Handle timer counter overflow Finn Thain
2018-11-19  1:10 ` [RFC PATCH v2 13/14] m68k: mvme16x: Convert to clocksource API Finn Thain
2018-11-19  1:10 ` [RFC PATCH v2 02/14] m68k: mac: Fix VIA timer counter accesses Finn Thain
2018-11-19  1:10 ` [RFC PATCH v2 06/14] m68k: amiga: Convert to clocksource API Finn Thain
2018-11-20  8:04   ` Linus Walleij
2018-11-19  1:10 ` [RFC PATCH v2 05/14] m68k: Drop ARCH_USES_GETTIMEOFFSET Finn Thain
2018-11-19  1:10 ` [RFC PATCH v2 14/14] m68k: mvme16x: Handle timer counter overflow Finn Thain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6597648024f9005bc763222c557f90a73f79e225.1542589838.git.fthain@telegraphics.com.au \
    --to=fthain@telegraphics.com.au \
    --cc=arnd@arndb.de \
    --cc=daniel.lezcano@linaro.org \
    --cc=geert@linux-m68k.org \
    --cc=john.stultz@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-m68k@lists.linux-m68k.org \
    --cc=schivers@csc.com.au \
    --cc=schmitzmic@gmail.com \
    --cc=schwab@linux-m68k.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).