2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2011 MIPS Technologies, Inc.
8 #include <linux/clocksource.h>
9 #include <linux/init.h>
14 static cycle_t
gic_hpt_read(struct clocksource
*cs
)
16 unsigned int hi
, hi2
, lo
;
19 GICREAD(GIC_REG(SHARED
, GIC_SH_COUNTER_63_32
), hi
);
20 GICREAD(GIC_REG(SHARED
, GIC_SH_COUNTER_31_00
), lo
);
21 GICREAD(GIC_REG(SHARED
, GIC_SH_COUNTER_63_32
), hi2
);
24 return (((cycle_t
) hi
) << 32) + lo
;
27 static struct clocksource gic_clocksource
= {
30 .flags
= CLOCK_SOURCE_IS_CONTINUOUS
,
33 void __init
gic_clocksource_init(void)
35 unsigned int config
, bits
;
37 if (!cpu_has_counter
|| !mips_hpt_frequency
)
40 /* Calculate the clocksource mask. */
41 GICREAD(GIC_REG(SHARED
, GIC_SH_CONFIG
), config
);
42 bits
= 32 + ((config
& GIC_SH_CONFIG_COUNTBITS_MSK
) >>
43 (GIC_SH_CONFIG_COUNTBITS_SHF
- 2));
45 /* Set clocksource mask. */
46 gic_clocksource
.mask
= CLOCKSOURCE_MASK(bits
);
48 /* Calculate a somewhat reasonable rating value. */
49 gic_clocksource
.rating
= 200 + (mips_hpt_frequency
* 2) / 10000000;
51 clocksource_set_clock(&gic_clocksource
, mips_hpt_frequency
);
52 clocksource_register(&gic_clocksource
);