blob: fbeed7e63393a097d4f9699c9046e8108d01eb3b [file] [log] [blame]
Jonas Aaberg5f5663a2011-09-14 09:10:54 +02001/*
2 * Copyright (C) ST-Ericsson SA 2011
3 *
4 * License Terms: GNU General Public License v2
5 * Author: Mattias Wallin <mattias.wallin@stericsson.com> for ST-Ericsson
6 */
7#include <linux/io.h>
Linus Walleijb1e3be062011-10-03 09:30:20 +02008#include <linux/errno.h>
Jonas Aaberg5f5663a2011-09-14 09:10:54 +02009#include <linux/clksrc-dbx500-prcmu.h>
10
Marc Zyngier08efd6c2012-01-10 19:44:19 +000011#include <asm/smp_twd.h>
Jonas Aaberg5f5663a2011-09-14 09:10:54 +020012
13#include <plat/mtu.h>
14
15#include <mach/setup.h>
16#include <mach/hardware.h>
17
Marc Zyngier08efd6c2012-01-10 19:44:19 +000018#ifdef CONFIG_HAVE_ARM_TWD
19static DEFINE_TWD_LOCAL_TIMER(u5500_twd_local_timer,
20 U5500_TWD_BASE, IRQ_LOCALTIMER);
21static DEFINE_TWD_LOCAL_TIMER(u8500_twd_local_timer,
22 U8500_TWD_BASE, IRQ_LOCALTIMER);
23
24static void __init ux500_twd_init(void)
25{
26 struct twd_local_timer *twd_local_timer;
27 int err;
28
29 twd_local_timer = cpu_is_u5500() ? &u5500_twd_local_timer :
30 &u8500_twd_local_timer;
31
32 err = twd_local_timer_register(twd_local_timer);
33 if (err)
34 pr_err("twd_local_timer_register failed %d\n", err);
35}
36#else
37#define ux500_twd_init() do { } while(0)
38#endif
39
Jonas Aaberg5f5663a2011-09-14 09:10:54 +020040static void __init ux500_timer_init(void)
41{
Linus Walleijb9576622012-01-11 09:46:59 +010042 void __iomem *mtu_timer_base;
Linus Walleijb1e3be062011-10-03 09:30:20 +020043 void __iomem *prcmu_timer_base;
Marc Zyngier08efd6c2012-01-10 19:44:19 +000044 int err;
Linus Walleijb1e3be062011-10-03 09:30:20 +020045
Jonas Aaberg5f5663a2011-09-14 09:10:54 +020046 if (cpu_is_u5500()) {
Linus Walleijb9576622012-01-11 09:46:59 +010047 mtu_timer_base = __io_address(U5500_MTU0_BASE);
Linus Walleijb1e3be062011-10-03 09:30:20 +020048 prcmu_timer_base = __io_address(U5500_PRCMU_TIMER_3_BASE);
Jonas Aaberg5f5663a2011-09-14 09:10:54 +020049 } else if (cpu_is_u8500()) {
Linus Walleijb9576622012-01-11 09:46:59 +010050 mtu_timer_base = __io_address(U8500_MTU0_BASE);
Linus Walleijb1e3be062011-10-03 09:30:20 +020051 prcmu_timer_base = __io_address(U8500_PRCMU_TIMER_4_BASE);
Jonas Aaberg5f5663a2011-09-14 09:10:54 +020052 } else {
53 ux500_unknown_soc();
54 }
55
56 /*
57 * Here we register the timerblocks active in the system.
58 * Localtimers (twd) is started when both cpu is up and running.
59 * MTU register a clocksource, clockevent and sched_clock.
60 * Since the MTU is located in the VAPE power domain
61 * it will be cleared in sleep which makes it unsuitable.
62 * We however need it as a timer tick (clockevent)
63 * during boot to calibrate delay until twd is started.
64 * RTC-RTT have problems as timer tick during boot since it is
65 * depending on delay which is not yet calibrated. RTC-RTT is in the
66 * always-on powerdomain and is used as clockevent instead of twd when
67 * sleeping.
68 * The PRCMU timer 4(3 for DB5500) register a clocksource and
69 * sched_clock with higher rating then MTU since is always-on.
70 *
71 */
72
Linus Walleijb9576622012-01-11 09:46:59 +010073 nmdk_timer_init(mtu_timer_base);
Linus Walleijb1e3be062011-10-03 09:30:20 +020074 clksrc_dbx500_prcmu_init(prcmu_timer_base);
Marc Zyngier08efd6c2012-01-10 19:44:19 +000075 ux500_twd_init();
Jonas Aaberg5f5663a2011-09-14 09:10:54 +020076}
77
Jonas Aabergbb219db2011-09-21 07:47:02 +020078static void ux500_timer_reset(void)
79{
80 nmdk_clkevt_reset();
81 nmdk_clksrc_reset();
82}
83
Jonas Aaberg5f5663a2011-09-14 09:10:54 +020084struct sys_timer ux500_timer = {
85 .init = ux500_timer_init,
Jonas Aabergbb219db2011-09-21 07:47:02 +020086 .resume = ux500_timer_reset,
Jonas Aaberg5f5663a2011-09-14 09:10:54 +020087};