blob: 66e7f00884ab4b4443d51f56c211ae7ac6385f49 [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>
Lee Jones71de5c42012-03-16 09:53:24 +000010#include <linux/of.h>
Lee Jonesc51423f2012-04-24 10:04:46 +010011#include <linux/of_address.h>
Jonas Aaberg5f5663a2011-09-14 09:10:54 +020012
Marc Zyngier08efd6c2012-01-10 19:44:19 +000013#include <asm/smp_twd.h>
Jonas Aaberg5f5663a2011-09-14 09:10:54 +020014
15#include <plat/mtu.h>
16
17#include <mach/setup.h>
18#include <mach/hardware.h>
Marc Zyngier218a2802012-03-15 11:05:39 +000019#include <mach/irqs.h>
Jonas Aaberg5f5663a2011-09-14 09:10:54 +020020
Marc Zyngier08efd6c2012-01-10 19:44:19 +000021#ifdef CONFIG_HAVE_ARM_TWD
Marc Zyngier08efd6c2012-01-10 19:44:19 +000022static DEFINE_TWD_LOCAL_TIMER(u8500_twd_local_timer,
23 U8500_TWD_BASE, IRQ_LOCALTIMER);
24
25static void __init ux500_twd_init(void)
26{
27 struct twd_local_timer *twd_local_timer;
28 int err;
29
Linus Walleij29746f42012-04-13 13:16:31 +020030 /* Use this to switch local timer base if changed in new ASICs */
31 twd_local_timer = &u8500_twd_local_timer;
Marc Zyngier08efd6c2012-01-10 19:44:19 +000032
Lee Jones71de5c42012-03-16 09:53:24 +000033 if (of_have_populated_dt())
34 twd_local_timer_of_register();
35 else {
36 err = twd_local_timer_register(twd_local_timer);
37 if (err)
38 pr_err("twd_local_timer_register failed %d\n", err);
39 }
Marc Zyngier08efd6c2012-01-10 19:44:19 +000040}
41#else
42#define ux500_twd_init() do { } while(0)
43#endif
44
Lee Jonesc51423f2012-04-24 10:04:46 +010045const static struct of_device_id prcmu_timer_of_match[] __initconst = {
46 { .compatible = "stericsson,db8500-prcmu-timer-4", },
47 { },
48};
49
Jonas Aaberg5f5663a2011-09-14 09:10:54 +020050static void __init ux500_timer_init(void)
51{
Linus Walleijb9576622012-01-11 09:46:59 +010052 void __iomem *mtu_timer_base;
Linus Walleijb1e3be062011-10-03 09:30:20 +020053 void __iomem *prcmu_timer_base;
Lee Jonesc51423f2012-04-24 10:04:46 +010054 void __iomem *tmp_base;
55 struct device_node *np;
Linus Walleijb1e3be062011-10-03 09:30:20 +020056
Arnd Bergmann815aceb2012-05-14 16:29:32 +020057 if (cpu_is_u8500_family()) {
Linus Walleijb9576622012-01-11 09:46:59 +010058 mtu_timer_base = __io_address(U8500_MTU0_BASE);
Linus Walleijb1e3be062011-10-03 09:30:20 +020059 prcmu_timer_base = __io_address(U8500_PRCMU_TIMER_4_BASE);
Jonas Aaberg5f5663a2011-09-14 09:10:54 +020060 } else {
61 ux500_unknown_soc();
62 }
63
Lee Jonesc51423f2012-04-24 10:04:46 +010064 /* TODO: Once MTU has been DT:ed place code above into else. */
65 if (of_have_populated_dt()) {
Lee Jonesc57920e2012-06-15 09:27:54 +010066#ifdef CONFIG_OF
Lee Jonesc51423f2012-04-24 10:04:46 +010067 np = of_find_matching_node(NULL, prcmu_timer_of_match);
68 if (!np)
Lee Jonesc57920e2012-06-15 09:27:54 +010069#endif
Lee Jonesc51423f2012-04-24 10:04:46 +010070 goto dt_fail;
71
72 tmp_base = of_iomap(np, 0);
73 if (!tmp_base)
74 goto dt_fail;
75
76 prcmu_timer_base = tmp_base;
77 }
78
79dt_fail:
80 /* Doing it the old fashioned way. */
81
Jonas Aaberg5f5663a2011-09-14 09:10:54 +020082 /*
83 * Here we register the timerblocks active in the system.
84 * Localtimers (twd) is started when both cpu is up and running.
85 * MTU register a clocksource, clockevent and sched_clock.
86 * Since the MTU is located in the VAPE power domain
87 * it will be cleared in sleep which makes it unsuitable.
88 * We however need it as a timer tick (clockevent)
89 * during boot to calibrate delay until twd is started.
90 * RTC-RTT have problems as timer tick during boot since it is
91 * depending on delay which is not yet calibrated. RTC-RTT is in the
92 * always-on powerdomain and is used as clockevent instead of twd when
93 * sleeping.
Linus Walleij29746f42012-04-13 13:16:31 +020094 * The PRCMU timer 4 register a clocksource and
Jonas Aaberg5f5663a2011-09-14 09:10:54 +020095 * sched_clock with higher rating then MTU since is always-on.
96 *
97 */
98
Linus Walleijb9576622012-01-11 09:46:59 +010099 nmdk_timer_init(mtu_timer_base);
Linus Walleijb1e3be062011-10-03 09:30:20 +0200100 clksrc_dbx500_prcmu_init(prcmu_timer_base);
Marc Zyngier08efd6c2012-01-10 19:44:19 +0000101 ux500_twd_init();
Jonas Aaberg5f5663a2011-09-14 09:10:54 +0200102}
103
Jonas Aabergbb219db2011-09-21 07:47:02 +0200104static void ux500_timer_reset(void)
105{
106 nmdk_clkevt_reset();
107 nmdk_clksrc_reset();
108}
109
Jonas Aaberg5f5663a2011-09-14 09:10:54 +0200110struct sys_timer ux500_timer = {
111 .init = ux500_timer_init,
Jonas Aabergbb219db2011-09-21 07:47:02 +0200112 .resume = ux500_timer_reset,
Jonas Aaberg5f5663a2011-09-14 09:10:54 +0200113};