1 // SPDX-License-Identifier: GPL-2.0
3 * linux/arch/arm/mach-footbridge/dc21285-timer.c
5 * Copyright (C) 1998 Russell King.
6 * Copyright (C) 1998 Phil Blundell
8 #include <linux/clockchips.h>
9 #include <linux/clocksource.h>
10 #include <linux/init.h>
11 #include <linux/interrupt.h>
12 #include <linux/irq.h>
13 #include <linux/sched_clock.h>
17 #include <asm/hardware/dec21285.h>
18 #include <asm/mach/time.h>
19 #include <asm/system_info.h>
23 static u64
cksrc_dc21285_read(struct clocksource
*cs
)
25 return cs
->mask
- *CSR_TIMER2_VALUE
;
28 static int cksrc_dc21285_enable(struct clocksource
*cs
)
30 *CSR_TIMER2_LOAD
= cs
->mask
;
32 *CSR_TIMER2_CNTL
= TIMER_CNTL_ENABLE
| TIMER_CNTL_DIV16
;
36 static void cksrc_dc21285_disable(struct clocksource
*cs
)
41 static struct clocksource cksrc_dc21285
= {
42 .name
= "dc21285_timer2",
44 .read
= cksrc_dc21285_read
,
45 .enable
= cksrc_dc21285_enable
,
46 .disable
= cksrc_dc21285_disable
,
47 .mask
= CLOCKSOURCE_MASK(24),
48 .flags
= CLOCK_SOURCE_IS_CONTINUOUS
,
51 static int ckevt_dc21285_set_next_event(unsigned long delta
,
52 struct clock_event_device
*c
)
55 *CSR_TIMER1_LOAD
= delta
;
56 *CSR_TIMER1_CNTL
= TIMER_CNTL_ENABLE
| TIMER_CNTL_DIV16
;
61 static int ckevt_dc21285_shutdown(struct clock_event_device
*c
)
67 static int ckevt_dc21285_set_periodic(struct clock_event_device
*c
)
70 *CSR_TIMER1_LOAD
= (mem_fclk_21285
+ 8 * HZ
) / (16 * HZ
);
71 *CSR_TIMER1_CNTL
= TIMER_CNTL_ENABLE
| TIMER_CNTL_AUTORELOAD
|
76 static struct clock_event_device ckevt_dc21285
= {
77 .name
= "dc21285_timer1",
78 .features
= CLOCK_EVT_FEAT_PERIODIC
|
79 CLOCK_EVT_FEAT_ONESHOT
,
82 .set_next_event
= ckevt_dc21285_set_next_event
,
83 .set_state_shutdown
= ckevt_dc21285_shutdown
,
84 .set_state_periodic
= ckevt_dc21285_set_periodic
,
85 .set_state_oneshot
= ckevt_dc21285_shutdown
,
86 .tick_resume
= ckevt_dc21285_set_periodic
,
89 static irqreturn_t
timer1_interrupt(int irq
, void *dev_id
)
91 struct clock_event_device
*ce
= dev_id
;
95 /* Stop the timer if in one-shot mode */
96 if (clockevent_state_oneshot(ce
))
99 ce
->event_handler(ce
);
104 static struct irqaction footbridge_timer_irq
= {
105 .name
= "dc21285_timer1",
106 .handler
= timer1_interrupt
,
107 .flags
= IRQF_TIMER
| IRQF_IRQPOLL
,
108 .dev_id
= &ckevt_dc21285
,
112 * Set up timer interrupt.
114 void __init
footbridge_timer_init(void)
116 struct clock_event_device
*ce
= &ckevt_dc21285
;
117 unsigned rate
= DIV_ROUND_CLOSEST(mem_fclk_21285
, 16);
119 clocksource_register_hz(&cksrc_dc21285
, rate
);
121 setup_irq(ce
->irq
, &footbridge_timer_irq
);
123 ce
->cpumask
= cpumask_of(smp_processor_id());
124 clockevents_config_and_register(ce
, rate
, 0x4, 0xffffff);
127 static u64 notrace
footbridge_read_sched_clock(void)
129 return ~*CSR_TIMER3_VALUE
;
132 void __init
footbridge_sched_clock(void)
134 unsigned rate
= DIV_ROUND_CLOSEST(mem_fclk_21285
, 16);
136 *CSR_TIMER3_LOAD
= 0;
138 *CSR_TIMER3_CNTL
= TIMER_CNTL_ENABLE
| TIMER_CNTL_DIV16
;
140 sched_clock_register(footbridge_read_sched_clock
, 24, rate
);