1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * arch/arm/plat-iop/time.c
5 * Timer code for IOP32x and IOP33x based systems
7 * Author: Deepak Saxena <dsaxena@mvista.com>
9 * Copyright 2002-2003 MontaVista Software Inc.
12 #include <linux/kernel.h>
13 #include <linux/interrupt.h>
14 #include <linux/time.h>
15 #include <linux/init.h>
16 #include <linux/timex.h>
18 #include <linux/clocksource.h>
19 #include <linux/clockchips.h>
20 #include <linux/export.h>
21 #include <linux/sched_clock.h>
22 #include <mach/hardware.h>
24 #include <linux/uaccess.h>
25 #include <asm/mach/irq.h>
26 #include <asm/mach/time.h>
27 #include <mach/time.h>
30 * Minimum clocksource/clockevent timer range in seconds
32 #define IOP_MIN_RANGE 4
35 * IOP clocksource (free-running timer 1).
37 static u64 notrace
iop_clocksource_read(struct clocksource
*unused
)
39 return 0xffffffffu
- read_tcr1();
42 static struct clocksource iop_clocksource
= {
45 .read
= iop_clocksource_read
,
46 .mask
= CLOCKSOURCE_MASK(32),
47 .flags
= CLOCK_SOURCE_IS_CONTINUOUS
,
51 * IOP sched_clock() implementation via its clocksource.
53 static u64 notrace
iop_read_sched_clock(void)
55 return 0xffffffffu
- read_tcr1();
59 * IOP clockevents (interrupting timer 0).
61 static int iop_set_next_event(unsigned long delta
,
62 struct clock_event_device
*unused
)
64 u32 tmr
= IOP_TMR_PRIVILEGED
| IOP_TMR_RATIO_1_1
;
67 write_tmr0(tmr
& ~(IOP_TMR_EN
| IOP_TMR_RELOAD
));
69 write_tmr0((tmr
& ~IOP_TMR_RELOAD
) | IOP_TMR_EN
);
74 static unsigned long ticks_per_jiffy
;
76 static int iop_set_periodic(struct clock_event_device
*evt
)
78 u32 tmr
= read_tmr0();
80 write_tmr0(tmr
& ~IOP_TMR_EN
);
81 write_tcr0(ticks_per_jiffy
- 1);
82 write_trr0(ticks_per_jiffy
- 1);
83 tmr
|= (IOP_TMR_RELOAD
| IOP_TMR_EN
);
89 static int iop_set_oneshot(struct clock_event_device
*evt
)
91 u32 tmr
= read_tmr0();
93 /* ->set_next_event sets period and enables timer */
94 tmr
&= ~(IOP_TMR_RELOAD
| IOP_TMR_EN
);
99 static int iop_shutdown(struct clock_event_device
*evt
)
101 u32 tmr
= read_tmr0();
108 static int iop_resume(struct clock_event_device
*evt
)
110 u32 tmr
= read_tmr0();
117 static struct clock_event_device iop_clockevent
= {
118 .name
= "iop_timer0",
119 .features
= CLOCK_EVT_FEAT_PERIODIC
|
120 CLOCK_EVT_FEAT_ONESHOT
,
122 .set_next_event
= iop_set_next_event
,
123 .set_state_shutdown
= iop_shutdown
,
124 .set_state_periodic
= iop_set_periodic
,
125 .tick_resume
= iop_resume
,
126 .set_state_oneshot
= iop_set_oneshot
,
130 iop_timer_interrupt(int irq
, void *dev_id
)
132 struct clock_event_device
*evt
= dev_id
;
135 evt
->event_handler(evt
);
139 static struct irqaction iop_timer_irq
= {
140 .name
= "IOP Timer Tick",
141 .handler
= iop_timer_interrupt
,
142 .flags
= IRQF_TIMER
| IRQF_IRQPOLL
,
143 .dev_id
= &iop_clockevent
,
146 static unsigned long iop_tick_rate
;
147 unsigned long get_iop_tick_rate(void)
149 return iop_tick_rate
;
151 EXPORT_SYMBOL(get_iop_tick_rate
);
153 void __init
iop_init_time(unsigned long tick_rate
)
157 sched_clock_register(iop_read_sched_clock
, 32, tick_rate
);
159 ticks_per_jiffy
= DIV_ROUND_CLOSEST(tick_rate
, HZ
);
160 iop_tick_rate
= tick_rate
;
162 timer_ctl
= IOP_TMR_EN
| IOP_TMR_PRIVILEGED
|
163 IOP_TMR_RELOAD
| IOP_TMR_RATIO_1_1
;
166 * Set up interrupting clockevent timer 0.
168 write_tmr0(timer_ctl
& ~IOP_TMR_EN
);
170 setup_irq(IRQ_IOP_TIMER0
, &iop_timer_irq
);
171 iop_clockevent
.cpumask
= cpumask_of(0);
172 clockevents_config_and_register(&iop_clockevent
, tick_rate
,
176 * Set up free-running clocksource timer 1.
178 write_trr1(0xffffffff);
179 write_tcr1(0xffffffff);
180 write_tmr1(timer_ctl
);
181 clocksource_register_hz(&iop_clocksource
, tick_rate
);