]>
git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - arch/arm/mach-rpc/time.c
1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/arch/arm/common/time-acorn.c
5 * Copyright (c) 1996-2000 Russell King.
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
13 #include <linux/timex.h>
14 #include <linux/init.h>
15 #include <linux/interrupt.h>
16 #include <linux/irq.h>
19 #include <mach/hardware.h>
20 #include <asm/hardware/ioc.h>
22 #include <asm/mach/time.h>
24 #define RPC_CLOCK_FREQ 2000000
25 #define RPC_LATCH DIV_ROUND_CLOSEST(RPC_CLOCK_FREQ, HZ)
27 static u32
ioc_timer_gettimeoffset(void)
29 unsigned int count1
, count2
, status
;
32 ioc_writeb (0, IOC_T0LATCH
);
34 count1
= ioc_readb(IOC_T0CNTL
) | (ioc_readb(IOC_T0CNTH
) << 8);
36 status
= ioc_readb(IOC_IRQREQA
);
38 ioc_writeb (0, IOC_T0LATCH
);
40 count2
= ioc_readb(IOC_T0CNTL
) | (ioc_readb(IOC_T0CNTH
) << 8);
43 if (count2
< count1
) {
45 * We have not had an interrupt between reading count1
48 if (status
& (1 << 5))
50 } else if (count2
> count1
) {
52 * We have just had another interrupt between reading
58 offset
= (RPC_LATCH
- offset
) * (tick_nsec
/ 1000);
59 return DIV_ROUND_CLOSEST(offset
, RPC_LATCH
) * 1000;
62 void __init
ioctime_init(void)
64 ioc_writeb(RPC_LATCH
& 255, IOC_T0LTCHL
);
65 ioc_writeb(RPC_LATCH
>> 8, IOC_T0LTCHH
);
66 ioc_writeb(0, IOC_T0GO
);
70 ioc_timer_interrupt(int irq
, void *dev_id
)
76 static struct irqaction ioc_timer_irq
= {
78 .handler
= ioc_timer_interrupt
82 * Set up timer interrupt.
84 void __init
ioc_timer_init(void)
86 arch_gettimeoffset
= ioc_timer_gettimeoffset
;
88 setup_irq(IRQ_TIMER0
, &ioc_timer_irq
);