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> 10e6a1bb72SRalf Baechle 11e6a1bb72SRalf Baechle #include <asm/time.h> 12940f6b48SRalf Baechle 13940f6b48SRalf Baechle static cycle_t c0_hpt_read(void) 14940f6b48SRalf Baechle { 15940f6b48SRalf Baechle return read_c0_count(); 16940f6b48SRalf Baechle } 17940f6b48SRalf Baechle 18940f6b48SRalf Baechle static struct clocksource clocksource_mips = { 19940f6b48SRalf Baechle .name = "MIPS", 20940f6b48SRalf Baechle .read = c0_hpt_read, 21940f6b48SRalf Baechle .mask = CLOCKSOURCE_MASK(32), 22940f6b48SRalf Baechle .flags = CLOCK_SOURCE_IS_CONTINUOUS, 23940f6b48SRalf Baechle }; 24940f6b48SRalf Baechle 2569e634f1SRalf Baechle int __init init_mips_clocksource(void) 26940f6b48SRalf Baechle { 2769e634f1SRalf Baechle if (!cpu_has_counter || !mips_hpt_frequency) 2869e634f1SRalf Baechle return -ENXIO; 2969e634f1SRalf Baechle 30*664c4bbbSRalf Baechle /* Calculate a somewhat reasonable rating value */ 31940f6b48SRalf Baechle clocksource_mips.rating = 200 + mips_hpt_frequency / 10000000; 32940f6b48SRalf Baechle 33940f6b48SRalf Baechle clocksource_set_clock(&clocksource_mips, mips_hpt_frequency); 34940f6b48SRalf Baechle 35940f6b48SRalf Baechle clocksource_register(&clocksource_mips); 3669e634f1SRalf Baechle 3769e634f1SRalf Baechle return 0; 38940f6b48SRalf Baechle } 39