1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2015 Numascale AS. All rights reserved.
7 #include <linux/clockchips.h>
10 #include <asm/numachip/numachip.h>
11 #include <asm/numachip/numachip_csr.h>
13 static DEFINE_PER_CPU(struct clock_event_device
, numachip2_ced
);
15 static cycles_t
numachip2_timer_read(struct clocksource
*cs
)
17 return numachip2_read64_lcsr(NUMACHIP2_TIMER_NOW
);
20 static struct clocksource numachip2_clocksource
= {
23 .read
= numachip2_timer_read
,
24 .mask
= CLOCKSOURCE_MASK(64),
25 .flags
= CLOCK_SOURCE_IS_CONTINUOUS
,
30 static int numachip2_set_next_event(unsigned long delta
, struct clock_event_device
*ced
)
32 numachip2_write64_lcsr(NUMACHIP2_TIMER_DEADLINE
+ numachip2_timer(),
37 static const struct clock_event_device numachip2_clockevent __initconst
= {
40 .set_next_event
= numachip2_set_next_event
,
41 .features
= CLOCK_EVT_FEAT_ONESHOT
,
45 .min_delta_ticks
= 1250,
46 .max_delta_ns
= LONG_MAX
,
47 .max_delta_ticks
= LONG_MAX
,
50 static void numachip_timer_interrupt(void)
52 struct clock_event_device
*ced
= this_cpu_ptr(&numachip2_ced
);
54 ced
->event_handler(ced
);
57 static __init
void numachip_timer_each(struct work_struct
*work
)
59 unsigned local_apicid
= __this_cpu_read(x86_cpu_to_apicid
) & 0xff;
60 struct clock_event_device
*ced
= this_cpu_ptr(&numachip2_ced
);
62 /* Setup IPI vector to local core and relative timing mode */
63 numachip2_write64_lcsr(NUMACHIP2_TIMER_INT
+ numachip2_timer(),
64 (3 << 22) | (X86_PLATFORM_IPI_VECTOR
<< 14) |
67 *ced
= numachip2_clockevent
;
68 ced
->cpumask
= cpumask_of(smp_processor_id());
69 clockevents_register_device(ced
);
72 static int __init
numachip_timer_init(void)
74 if (numachip_system
!= 2)
78 numachip2_write64_lcsr(NUMACHIP2_TIMER_RESET
, 0);
79 clocksource_register_hz(&numachip2_clocksource
, NSEC_PER_SEC
);
81 /* Setup per-cpu clockevents */
82 x86_platform_ipi_callback
= numachip_timer_interrupt
;
83 schedule_on_each_cpu(&numachip_timer_each
);
88 arch_initcall(numachip_timer_init
);