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) 2012 MIPS Technologies, Inc. All rights reserved.
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(unsigned int frequency)
35 unsigned int config, bits;
37 /* Calculate the clocksource mask. */
38 GICREAD(GIC_REG(SHARED, GIC_SH_CONFIG), config);
39 bits = 32 + ((config & GIC_SH_CONFIG_COUNTBITS_MSK) >>
40 (GIC_SH_CONFIG_COUNTBITS_SHF - 2));
42 /* Set clocksource mask. */
43 gic_clocksource.mask = CLOCKSOURCE_MASK(bits);
45 /* Calculate a somewhat reasonable rating value. */
46 gic_clocksource.rating = 200 + frequency / 10000000;
48 clocksource_register_hz(&gic_clocksource, frequency);