xref: /openbmc/linux/arch/mips/kernel/csrc-r4k.c (revision 75c4fd8c7862f37eeae5c80f33bbe4dce97571d4)
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 
138e19608eSMagnus Damm static cycle_t c0_hpt_read(struct clocksource *cs)
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 
25779e7d41SManuel Lauss int __init init_r4k_clocksource(void)
26940f6b48SRalf Baechle {
2769e634f1SRalf Baechle 	if (!cpu_has_counter || !mips_hpt_frequency)
2869e634f1SRalf Baechle 		return -ENXIO;
2969e634f1SRalf Baechle 
30664c4bbbSRalf Baechle 	/* Calculate a somewhat reasonable rating value */
31940f6b48SRalf Baechle 	clocksource_mips.rating = 200 + mips_hpt_frequency / 10000000;
32940f6b48SRalf Baechle 
33*75c4fd8cSJohn Stultz 	clocksource_register_hz(&clocksource_mips, mips_hpt_frequency);
3469e634f1SRalf Baechle 
3569e634f1SRalf Baechle 	return 0;
36940f6b48SRalf Baechle }
37