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/clocksource.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)
29 static u64
ioc_timer_read(struct clocksource
*cs
)
31 unsigned int count1
, count2
, status
;
35 local_irq_save(flags
);
36 ioc_writeb (0, IOC_T0LATCH
);
38 count1
= ioc_readb(IOC_T0CNTL
) | (ioc_readb(IOC_T0CNTH
) << 8);
40 status
= ioc_readb(IOC_IRQREQA
);
42 ioc_writeb (0, IOC_T0LATCH
);
44 count2
= ioc_readb(IOC_T0CNTL
) | (ioc_readb(IOC_T0CNTH
) << 8);
45 ticks
= ioc_time
+ RPC_LATCH
- count2
;
46 local_irq_restore(flags
);
48 if (count2
< count1
) {
50 * The timer has not reloaded between reading count1 and
51 * count2, check whether an interrupt was actually pending.
53 if (status
& (1 << 5))
55 } else if (count2
> count1
) {
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.
67 static struct clocksource ioctime_clocksource
= {
68 .read
= ioc_timer_read
,
69 .mask
= CLOCKSOURCE_MASK(32),
73 void __init
ioctime_init(void)
75 ioc_writeb(RPC_LATCH
& 255, IOC_T0LTCHL
);
76 ioc_writeb(RPC_LATCH
>> 8, IOC_T0LTCHH
);
77 ioc_writeb(0, IOC_T0GO
);
81 ioc_timer_interrupt(int irq
, void *dev_id
)
83 ioc_time
+= RPC_LATCH
;
88 static struct irqaction ioc_timer_irq
= {
90 .handler
= ioc_timer_interrupt
94 * Set up timer interrupt.
96 void __init
ioc_timer_init(void)
98 WARN_ON(clocksource_register_hz(&ioctime_clocksource
, RPC_CLOCK_FREQ
));
100 setup_irq(IRQ_TIMER0
, &ioc_timer_irq
);