RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / mips / kernel / csrc-gic.c
blob96978f0f276c7f77cc6f1c5aa49122db972dd4ae
1 /*
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
4 * for more details.
6 * Copyright (C) 2011 MIPS Technologies, Inc.
7 */
8 #include <linux/clocksource.h>
9 #include <linux/init.h>
11 #include <asm/time.h>
12 #include <asm/gic.h>
14 static cycle_t gic_hpt_read(struct clocksource *cs)
16 unsigned int hi, hi2, lo;
18 do {
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);
22 } while (hi2 != hi);
24 return (((cycle_t) hi) << 32) + lo;
27 static struct clocksource gic_clocksource = {
28 .name = "GIC",
29 .read = gic_hpt_read,
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)
38 BUG();
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);