~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/arm/mach-rpc/time.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  *  linux/arch/arm/common/time-acorn.c
  4  *
  5  *  Copyright (c) 1996-2000 Russell King.
  6  *
  7  *  Changelog:
  8  *   24-Sep-1996        RMK     Created
  9  *   10-Oct-1996        RMK     Brought up to date with arch-sa110eval
 10  *   04-Dec-1997        RMK     Updated for new arch/arm/time.c
 11  *   13=Jun-2004        DS      Moved to arch/arm/common b/c shared w/CLPS7500
 12  */
 13 #include <linux/clocksource.h>
 14 #include <linux/init.h>
 15 #include <linux/interrupt.h>
 16 #include <linux/irq.h>
 17 #include <linux/io.h>
 18 
 19 #include <mach/hardware.h>
 20 #include <asm/hardware/ioc.h>
 21 
 22 #include <asm/mach/time.h>
 23 
 24 #define RPC_CLOCK_FREQ 2000000
 25 #define RPC_LATCH DIV_ROUND_CLOSEST(RPC_CLOCK_FREQ, HZ)
 26 
 27 static u32 ioc_time;
 28 
 29 static u64 ioc_timer_read(struct clocksource *cs)
 30 {
 31         unsigned int count1, count2, status;
 32         unsigned long flags;
 33         u32 ticks;
 34 
 35         local_irq_save(flags);
 36         ioc_writeb (0, IOC_T0LATCH);
 37         barrier ();
 38         count1 = ioc_readb(IOC_T0CNTL) | (ioc_readb(IOC_T0CNTH) << 8);
 39         barrier ();
 40         status = ioc_readb(IOC_IRQREQA);
 41         barrier ();
 42         ioc_writeb (0, IOC_T0LATCH);
 43         barrier ();
 44         count2 = ioc_readb(IOC_T0CNTL) | (ioc_readb(IOC_T0CNTH) << 8);
 45         ticks = ioc_time + RPC_LATCH - count2;
 46         local_irq_restore(flags);
 47 
 48         if (count2 < count1) {
 49                 /*
 50                  * The timer has not reloaded between reading count1 and
 51                  * count2, check whether an interrupt was actually pending.
 52                  */
 53                 if (status & (1 << 5))
 54                         ticks += RPC_LATCH;
 55         } else if (count2 > count1) {
 56                 /*
 57                  * The timer has reloaded, so count2 indicates the new
 58                  * count since the wrap.  The interrupt would not have
 59                  * been processed, so add the missed ticks.
 60                  */
 61                 ticks += RPC_LATCH;
 62         }
 63 
 64         return ticks;
 65 }
 66 
 67 static struct clocksource ioctime_clocksource = {
 68         .read = ioc_timer_read,
 69         .mask = CLOCKSOURCE_MASK(32),
 70         .rating = 100,
 71 };
 72 
 73 void __init ioctime_init(void)
 74 {
 75         ioc_writeb(RPC_LATCH & 255, IOC_T0LTCHL);
 76         ioc_writeb(RPC_LATCH >> 8, IOC_T0LTCHH);
 77         ioc_writeb(0, IOC_T0GO);
 78 }
 79 
 80 static irqreturn_t
 81 ioc_timer_interrupt(int irq, void *dev_id)
 82 {
 83         ioc_time += RPC_LATCH;
 84         legacy_timer_tick(1);
 85         return IRQ_HANDLED;
 86 }
 87 
 88 /*
 89  * Set up timer interrupt.
 90  */
 91 void __init ioc_timer_init(void)
 92 {
 93         WARN_ON(clocksource_register_hz(&ioctime_clocksource, RPC_CLOCK_FREQ));
 94         ioctime_init();
 95         if (request_irq(IRQ_TIMER0, ioc_timer_interrupt, 0, "timer", NULL))
 96                 pr_err("Failed to request irq %d (timer)\n", IRQ_TIMER0);
 97 }
 98 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php