Steven J. Hill | 778eeb1 | 2012-12-07 03:51:04 +0000 | [diff] [blame] | 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. |
| 5 | * |
| 6 | * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. |
| 7 | */ |
Steven J. Hill | 778eeb1 | 2012-12-07 03:51:04 +0000 | [diff] [blame] | 8 | #include <linux/init.h> |
Steven J. Hill | dfa762e | 2013-04-10 16:28:36 -0500 | [diff] [blame^] | 9 | #include <linux/time.h> |
Steven J. Hill | 778eeb1 | 2012-12-07 03:51:04 +0000 | [diff] [blame] | 10 | |
Steven J. Hill | 778eeb1 | 2012-12-07 03:51:04 +0000 | [diff] [blame] | 11 | #include <asm/gic.h> |
| 12 | |
| 13 | static cycle_t gic_hpt_read(struct clocksource *cs) |
| 14 | { |
Steven J. Hill | dfa762e | 2013-04-10 16:28:36 -0500 | [diff] [blame^] | 15 | return gic_read_count(); |
Steven J. Hill | 778eeb1 | 2012-12-07 03:51:04 +0000 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | static struct clocksource gic_clocksource = { |
| 19 | .name = "GIC", |
| 20 | .read = gic_hpt_read, |
| 21 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
| 22 | }; |
| 23 | |
| 24 | void __init gic_clocksource_init(unsigned int frequency) |
| 25 | { |
| 26 | unsigned int config, bits; |
| 27 | |
| 28 | /* Calculate the clocksource mask. */ |
| 29 | GICREAD(GIC_REG(SHARED, GIC_SH_CONFIG), config); |
| 30 | bits = 32 + ((config & GIC_SH_CONFIG_COUNTBITS_MSK) >> |
| 31 | (GIC_SH_CONFIG_COUNTBITS_SHF - 2)); |
| 32 | |
| 33 | /* Set clocksource mask. */ |
| 34 | gic_clocksource.mask = CLOCKSOURCE_MASK(bits); |
| 35 | |
| 36 | /* Calculate a somewhat reasonable rating value. */ |
| 37 | gic_clocksource.rating = 200 + frequency / 10000000; |
| 38 | |
| 39 | clocksource_register_hz(&gic_clocksource, frequency); |
| 40 | } |