1*fa5635a2SAndrew Bresticker /*
2*fa5635a2SAndrew Bresticker  * This file is subject to the terms and conditions of the GNU General Public
3*fa5635a2SAndrew Bresticker  * License.  See the file "COPYING" in the main directory of this archive
4*fa5635a2SAndrew Bresticker  * for more details.
5*fa5635a2SAndrew Bresticker  *
6*fa5635a2SAndrew Bresticker  * Copyright (C) 2012 MIPS Technologies, Inc.  All rights reserved.
7*fa5635a2SAndrew Bresticker  */
8*fa5635a2SAndrew Bresticker #include <linux/init.h>
9*fa5635a2SAndrew Bresticker #include <linux/irqchip/mips-gic.h>
10*fa5635a2SAndrew Bresticker #include <linux/time.h>
11*fa5635a2SAndrew Bresticker 
12*fa5635a2SAndrew Bresticker static cycle_t gic_hpt_read(struct clocksource *cs)
13*fa5635a2SAndrew Bresticker {
14*fa5635a2SAndrew Bresticker 	return gic_read_count();
15*fa5635a2SAndrew Bresticker }
16*fa5635a2SAndrew Bresticker 
17*fa5635a2SAndrew Bresticker static struct clocksource gic_clocksource = {
18*fa5635a2SAndrew Bresticker 	.name	= "GIC",
19*fa5635a2SAndrew Bresticker 	.read	= gic_hpt_read,
20*fa5635a2SAndrew Bresticker 	.flags	= CLOCK_SOURCE_IS_CONTINUOUS,
21*fa5635a2SAndrew Bresticker };
22*fa5635a2SAndrew Bresticker 
23*fa5635a2SAndrew Bresticker void __init gic_clocksource_init(unsigned int frequency)
24*fa5635a2SAndrew Bresticker {
25*fa5635a2SAndrew Bresticker 	/* Set clocksource mask. */
26*fa5635a2SAndrew Bresticker 	gic_clocksource.mask = CLOCKSOURCE_MASK(gic_get_count_width());
27*fa5635a2SAndrew Bresticker 
28*fa5635a2SAndrew Bresticker 	/* Calculate a somewhat reasonable rating value. */
29*fa5635a2SAndrew Bresticker 	gic_clocksource.rating = 200 + frequency / 10000000;
30*fa5635a2SAndrew Bresticker 
31*fa5635a2SAndrew Bresticker 	clocksource_register_hz(&gic_clocksource, frequency);
32*fa5635a2SAndrew Bresticker }
33