Loading...
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Port on Texas Instruments TMS320C6x architecture
4 *
5 * Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated
6 * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
7 */
8
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>
19
20#include <asm/special_insns.h>
21#include <asm/timer64.h>
22
23static u32 sched_clock_multiplier;
24#define SCHED_CLOCK_SHIFT 16
25
26static u64 tsc_read(struct clocksource *cs)
27{
28 return get_cycles();
29}
30
31static 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,
37};
38
39/*
40 * scheduler clock - returns current time in nanoseconds.
41 */
42u64 sched_clock(void)
43{
44 u64 tsc = get_cycles();
45
46 return (tsc * sched_clock_multiplier) >> SCHED_CLOCK_SHIFT;
47}
48
49void __init time_init(void)
50{
51 u64 tmp = (u64)NSEC_PER_SEC << SCHED_CLOCK_SHIFT;
52
53 do_div(tmp, c6x_core_freq);
54 sched_clock_multiplier = tmp;
55
56 clocksource_register_hz(&clocksource_tsc, c6x_core_freq);
57
58 /* write anything into TSCL to enable counting */
59 set_creg(TSCL, 0);
60
61 /* probe for timer64 event timer */
62 timer64_init();
63}
1/*
2 * Port on Texas Instruments TMS320C6x architecture
3 *
4 * Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated
5 * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/kernel.h>
13#include <linux/clocksource.h>
14#include <linux/errno.h>
15#include <linux/sched.h>
16#include <linux/param.h>
17#include <linux/string.h>
18#include <linux/mm.h>
19#include <linux/interrupt.h>
20#include <linux/timex.h>
21#include <linux/profile.h>
22
23#include <asm/special_insns.h>
24#include <asm/timer64.h>
25
26static u32 sched_clock_multiplier;
27#define SCHED_CLOCK_SHIFT 16
28
29static cycle_t tsc_read(struct clocksource *cs)
30{
31 return get_cycles();
32}
33
34static struct clocksource clocksource_tsc = {
35 .name = "timestamp",
36 .rating = 300,
37 .read = tsc_read,
38 .mask = CLOCKSOURCE_MASK(64),
39 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
40};
41
42/*
43 * scheduler clock - returns current time in nanoseconds.
44 */
45u64 sched_clock(void)
46{
47 u64 tsc = get_cycles();
48
49 return (tsc * sched_clock_multiplier) >> SCHED_CLOCK_SHIFT;
50}
51
52void time_init(void)
53{
54 u64 tmp = (u64)NSEC_PER_SEC << SCHED_CLOCK_SHIFT;
55
56 do_div(tmp, c6x_core_freq);
57 sched_clock_multiplier = tmp;
58
59 clocksource_register_hz(&clocksource_tsc, c6x_core_freq);
60
61 /* write anything into TSCL to enable counting */
62 set_creg(TSCL, 0);
63
64 /* probe for timer64 event timer */
65 timer64_init();
66}