1940f6b48SRalf Baechle /* 2940f6b48SRalf Baechle * This file is subject to the terms and conditions of the GNU General Public 3940f6b48SRalf Baechle * License. See the file "COPYING" in the main directory of this archive 4940f6b48SRalf Baechle * for more details. 5940f6b48SRalf Baechle * 6940f6b48SRalf Baechle * Copyright (C) 2007 by Ralf Baechle 7940f6b48SRalf Baechle */ 8e6a1bb72SRalf Baechle #include <linux/clocksource.h> 9e6a1bb72SRalf Baechle #include <linux/init.h> 10*e9cef549SDeng-Cheng Zhu #include <linux/sched_clock.h> 11e6a1bb72SRalf Baechle 12e6a1bb72SRalf Baechle #include <asm/time.h> 13940f6b48SRalf Baechle 148e19608eSMagnus Damm static cycle_t c0_hpt_read(struct clocksource *cs) 15940f6b48SRalf Baechle { 16940f6b48SRalf Baechle return read_c0_count(); 17940f6b48SRalf Baechle } 18940f6b48SRalf Baechle 19940f6b48SRalf Baechle static struct clocksource clocksource_mips = { 20940f6b48SRalf Baechle .name = "MIPS", 21940f6b48SRalf Baechle .read = c0_hpt_read, 22940f6b48SRalf Baechle .mask = CLOCKSOURCE_MASK(32), 23940f6b48SRalf Baechle .flags = CLOCK_SOURCE_IS_CONTINUOUS, 24940f6b48SRalf Baechle }; 25940f6b48SRalf Baechle 26*e9cef549SDeng-Cheng Zhu static u64 notrace r4k_read_sched_clock(void) 27*e9cef549SDeng-Cheng Zhu { 28*e9cef549SDeng-Cheng Zhu return read_c0_count(); 29*e9cef549SDeng-Cheng Zhu } 30*e9cef549SDeng-Cheng Zhu 31779e7d41SManuel Lauss int __init init_r4k_clocksource(void) 32940f6b48SRalf Baechle { 3369e634f1SRalf Baechle if (!cpu_has_counter || !mips_hpt_frequency) 3469e634f1SRalf Baechle return -ENXIO; 3569e634f1SRalf Baechle 36664c4bbbSRalf Baechle /* Calculate a somewhat reasonable rating value */ 37940f6b48SRalf Baechle clocksource_mips.rating = 200 + mips_hpt_frequency / 10000000; 38940f6b48SRalf Baechle 3975c4fd8cSJohn Stultz clocksource_register_hz(&clocksource_mips, mips_hpt_frequency); 4069e634f1SRalf Baechle 41*e9cef549SDeng-Cheng Zhu sched_clock_register(r4k_read_sched_clock, 32, mips_hpt_frequency); 42*e9cef549SDeng-Cheng Zhu 4369e634f1SRalf Baechle return 0; 44940f6b48SRalf Baechle } 45