Linux 5.7.6
[linux/fpc-iii.git] / arch / c6x / kernel / time.c
blobf3ec91a87f4f6712657c1c15742952741c5ff814
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Port on Texas Instruments TMS320C6x architecture
5 * Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated
6 * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
7 */
9 #include <linux/kernel.h>
10 #include <linux/clocksource.h>
11 #include <linux/errno.h>
12 #include <linux/sched.h>
13 #include <linux/param.h>
14 #include <linux/string.h>
15 #include <linux/mm.h>
16 #include <linux/interrupt.h>
17 #include <linux/timex.h>
18 #include <linux/profile.h>
20 #include <asm/special_insns.h>
21 #include <asm/timer64.h>
23 static u32 sched_clock_multiplier;
24 #define SCHED_CLOCK_SHIFT 16
26 static u64 tsc_read(struct clocksource *cs)
28 return get_cycles();
31 static struct clocksource clocksource_tsc = {
32 .name = "timestamp",
33 .rating = 300,
34 .read = tsc_read,
35 .mask = CLOCKSOURCE_MASK(64),
36 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
40 * scheduler clock - returns current time in nanoseconds.
42 u64 sched_clock(void)
44 u64 tsc = get_cycles();
46 return (tsc * sched_clock_multiplier) >> SCHED_CLOCK_SHIFT;
49 void __init time_init(void)
51 u64 tmp = (u64)NSEC_PER_SEC << SCHED_CLOCK_SHIFT;
53 do_div(tmp, c6x_core_freq);
54 sched_clock_multiplier = tmp;
56 clocksource_register_hz(&clocksource_tsc, c6x_core_freq);
58 /* write anything into TSCL to enable counting */
59 set_creg(TSCL, 0);
61 /* probe for timer64 event timer */
62 timer64_init();