blob: 1791f12c180bbe3264bc6c48849f1f6ed4aaecde [file] [log] [blame]
Marc Zyngier022c03a2012-01-11 17:25:17 +00001/*
2 * linux/arch/arm/kernel/arch_timer.c
3 *
4 * Copyright (C) 2011 ARM Ltd.
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/init.h>
Mark Rutland8a4da6e2012-11-12 14:33:44 +000012#include <linux/types.h>
Arnd Bergmannfe7dc722013-02-14 17:45:25 +010013#include <linux/errno.h>
Marc Zyngier022c03a2012-01-11 17:25:17 +000014
Jonathan Austin56942fe2012-09-21 18:51:44 +010015#include <asm/delay.h>
Marc Zyngier022c03a2012-01-11 17:25:17 +000016
Mark Rutland8a4da6e2012-11-12 14:33:44 +000017#include <clocksource/arm_arch_timer.h>
Marc Zyngierf48b5f12012-09-07 18:09:57 +010018
Mark Rutland8a4da6e2012-11-12 14:33:44 +000019static unsigned long arch_timer_read_counter_long(void)
20{
21 return arch_timer_read_counter();
22}
Marc Zyngierf48b5f12012-09-07 18:09:57 +010023
Jonathan Austin56942fe2012-09-21 18:51:44 +010024static struct delay_timer arch_delay_timer;
Will Deacond0a533b2012-07-06 15:47:17 +010025
Mark Rutland8a4da6e2012-11-12 14:33:44 +000026static void __init arch_timer_delay_timer_register(void)
Marc Zyngierf48b5f12012-09-07 18:09:57 +010027{
Jonathan Austin56942fe2012-09-21 18:51:44 +010028 /* Use the architected timer for the delay loop. */
Mark Rutland8a4da6e2012-11-12 14:33:44 +000029 arch_delay_timer.read_current_timer = arch_timer_read_counter_long;
30 arch_delay_timer.freq = arch_timer_get_rate();
Jonathan Austin56942fe2012-09-21 18:51:44 +010031 register_current_timer_delay(&arch_delay_timer);
Marc Zyngier022c03a2012-01-11 17:25:17 +000032}
Marc Zyngier3f61c802011-01-14 15:32:36 +000033
Rob Herring0583fe42013-04-10 18:27:51 -050034int __init arch_timer_arch_init(void)
Marc Zyngier3f61c802011-01-14 15:32:36 +000035{
Rob Herring023796b2013-03-11 16:23:46 -050036 u32 arch_timer_rate = arch_timer_get_rate();
37
38 if (arch_timer_rate == 0)
Mark Rutland8a4da6e2012-11-12 14:33:44 +000039 return -ENXIO;
Marc Zyngier3f61c802011-01-14 15:32:36 +000040
Rob Herring0583fe42013-04-10 18:27:51 -050041 arch_timer_delay_timer_register();
42
Marc Zyngier3f61c802011-01-14 15:32:36 +000043 return 0;
44}