blob: b6bd0efcbe64465bed83d2814e01f57483a03c92 [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>
Rob Herringda4a6862013-02-06 21:17:47 -060010#include <linux/clocksource.h>
Lee Jones71de5c42012-03-16 09:53:24 +000011#include <linux/of.h>
Lee Jonesc51423f2012-04-24 10:04:46 +010012#include <linux/of_address.h>
Linus Walleij694e33a2012-10-18 14:01:25 +020013#include <linux/platform_data/clocksource-nomadik-mtu.h>
Jonas Aaberg5f5663a2011-09-14 09:10:54 +020014
Marc Zyngier08efd6c2012-01-10 19:44:19 +000015#include <asm/smp_twd.h>
Jonas Aaberg5f5663a2011-09-14 09:10:54 +020016
Arnd Bergmanne657bcf2013-03-21 22:51:12 +010017#include "setup.h"
Arnd Bergmanneba52742013-03-21 22:51:08 +010018#include "irqs.h"
Jonas Aaberg5f5663a2011-09-14 09:10:54 +020019
Linus Walleij174e7792013-03-19 15:41:55 +010020#include "db8500-regs.h"
Linus Walleij7a4f2602012-09-19 19:31:19 +020021#include "id.h"
22
Marc Zyngier08efd6c2012-01-10 19:44:19 +000023#ifdef CONFIG_HAVE_ARM_TWD
Marc Zyngier08efd6c2012-01-10 19:44:19 +000024static DEFINE_TWD_LOCAL_TIMER(u8500_twd_local_timer,
25 U8500_TWD_BASE, IRQ_LOCALTIMER);
26
27static void __init ux500_twd_init(void)
28{
29 struct twd_local_timer *twd_local_timer;
30 int err;
31
Linus Walleij29746f42012-04-13 13:16:31 +020032 /* Use this to switch local timer base if changed in new ASICs */
33 twd_local_timer = &u8500_twd_local_timer;
Marc Zyngier08efd6c2012-01-10 19:44:19 +000034
Lee Jones71de5c42012-03-16 09:53:24 +000035 if (of_have_populated_dt())
Rob Herringda4a6862013-02-06 21:17:47 -060036 clocksource_of_init();
Lee Jones71de5c42012-03-16 09:53:24 +000037 else {
38 err = twd_local_timer_register(twd_local_timer);
39 if (err)
40 pr_err("twd_local_timer_register failed %d\n", err);
41 }
Marc Zyngier08efd6c2012-01-10 19:44:19 +000042}
43#else
44#define ux500_twd_init() do { } while(0)
45#endif
46
Lee Jonesc51423f2012-04-24 10:04:46 +010047const static struct of_device_id prcmu_timer_of_match[] __initconst = {
48 { .compatible = "stericsson,db8500-prcmu-timer-4", },
49 { },
50};
51
Stephen Warren6bb27d72012-11-08 12:40:59 -070052void __init ux500_timer_init(void)
Jonas Aaberg5f5663a2011-09-14 09:10:54 +020053{
Linus Walleijb9576622012-01-11 09:46:59 +010054 void __iomem *mtu_timer_base;
Linus Walleijb1e3be062011-10-03 09:30:20 +020055 void __iomem *prcmu_timer_base;
Lee Jonesc51423f2012-04-24 10:04:46 +010056 void __iomem *tmp_base;
57 struct device_node *np;
Linus Walleijb1e3be062011-10-03 09:30:20 +020058
Loic PALLARDY79964bc2012-09-03 15:10:23 +020059 if (cpu_is_u8500_family() || cpu_is_ux540_family()) {
Linus Walleijb9576622012-01-11 09:46:59 +010060 mtu_timer_base = __io_address(U8500_MTU0_BASE);
Linus Walleijb1e3be062011-10-03 09:30:20 +020061 prcmu_timer_base = __io_address(U8500_PRCMU_TIMER_4_BASE);
Jonas Aaberg5f5663a2011-09-14 09:10:54 +020062 } else {
63 ux500_unknown_soc();
64 }
65
Lee Jonesc51423f2012-04-24 10:04:46 +010066 /* TODO: Once MTU has been DT:ed place code above into else. */
67 if (of_have_populated_dt()) {
Lee Jonesc57920e2012-06-15 09:27:54 +010068#ifdef CONFIG_OF
Lee Jonesc51423f2012-04-24 10:04:46 +010069 np = of_find_matching_node(NULL, prcmu_timer_of_match);
70 if (!np)
Lee Jonesc57920e2012-06-15 09:27:54 +010071#endif
Lee Jonesc51423f2012-04-24 10:04:46 +010072 goto dt_fail;
73
74 tmp_base = of_iomap(np, 0);
75 if (!tmp_base)
76 goto dt_fail;
77
78 prcmu_timer_base = tmp_base;
79 }
80
81dt_fail:
82 /* Doing it the old fashioned way. */
83
Jonas Aaberg5f5663a2011-09-14 09:10:54 +020084 /*
85 * Here we register the timerblocks active in the system.
86 * Localtimers (twd) is started when both cpu is up and running.
87 * MTU register a clocksource, clockevent and sched_clock.
88 * Since the MTU is located in the VAPE power domain
89 * it will be cleared in sleep which makes it unsuitable.
90 * We however need it as a timer tick (clockevent)
91 * during boot to calibrate delay until twd is started.
92 * RTC-RTT have problems as timer tick during boot since it is
93 * depending on delay which is not yet calibrated. RTC-RTT is in the
94 * always-on powerdomain and is used as clockevent instead of twd when
95 * sleeping.
Linus Walleij29746f42012-04-13 13:16:31 +020096 * The PRCMU timer 4 register a clocksource and
Jonas Aaberg5f5663a2011-09-14 09:10:54 +020097 * sched_clock with higher rating then MTU since is always-on.
98 *
99 */
100
Linus Walleij08130692012-10-18 11:06:02 +0200101 nmdk_timer_init(mtu_timer_base, IRQ_MTU0);
Linus Walleijb1e3be062011-10-03 09:30:20 +0200102 clksrc_dbx500_prcmu_init(prcmu_timer_base);
Marc Zyngier08efd6c2012-01-10 19:44:19 +0000103 ux500_twd_init();
Jonas Aaberg5f5663a2011-09-14 09:10:54 +0200104}