Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 1 | /* |
| 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 Walleij | b1e3be06 | 2011-10-03 09:30:20 +0200 | [diff] [blame] | 8 | #include <linux/errno.h> |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 9 | #include <linux/clksrc-dbx500-prcmu.h> |
Lee Jones | 71de5c4 | 2012-03-16 09:53:24 +0000 | [diff] [blame] | 10 | #include <linux/of.h> |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 11 | |
Marc Zyngier | 08efd6c | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 12 | #include <asm/smp_twd.h> |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 13 | |
| 14 | #include <plat/mtu.h> |
| 15 | |
| 16 | #include <mach/setup.h> |
| 17 | #include <mach/hardware.h> |
Marc Zyngier | 218a280 | 2012-03-15 11:05:39 +0000 | [diff] [blame] | 18 | #include <mach/irqs.h> |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 19 | |
Marc Zyngier | 08efd6c | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 20 | #ifdef CONFIG_HAVE_ARM_TWD |
Marc Zyngier | 08efd6c | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 21 | static DEFINE_TWD_LOCAL_TIMER(u8500_twd_local_timer, |
| 22 | U8500_TWD_BASE, IRQ_LOCALTIMER); |
| 23 | |
| 24 | static void __init ux500_twd_init(void) |
| 25 | { |
| 26 | struct twd_local_timer *twd_local_timer; |
| 27 | int err; |
| 28 | |
Linus Walleij | 29746f4 | 2012-04-13 13:16:31 +0200 | [diff] [blame^] | 29 | /* Use this to switch local timer base if changed in new ASICs */ |
| 30 | twd_local_timer = &u8500_twd_local_timer; |
Marc Zyngier | 08efd6c | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 31 | |
Lee Jones | 71de5c4 | 2012-03-16 09:53:24 +0000 | [diff] [blame] | 32 | if (of_have_populated_dt()) |
| 33 | twd_local_timer_of_register(); |
| 34 | else { |
| 35 | err = twd_local_timer_register(twd_local_timer); |
| 36 | if (err) |
| 37 | pr_err("twd_local_timer_register failed %d\n", err); |
| 38 | } |
Marc Zyngier | 08efd6c | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 39 | } |
| 40 | #else |
| 41 | #define ux500_twd_init() do { } while(0) |
| 42 | #endif |
| 43 | |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 44 | static void __init ux500_timer_init(void) |
| 45 | { |
Linus Walleij | b957662 | 2012-01-11 09:46:59 +0100 | [diff] [blame] | 46 | void __iomem *mtu_timer_base; |
Linus Walleij | b1e3be06 | 2011-10-03 09:30:20 +0200 | [diff] [blame] | 47 | void __iomem *prcmu_timer_base; |
| 48 | |
Linus Walleij | 29746f4 | 2012-04-13 13:16:31 +0200 | [diff] [blame^] | 49 | if (cpu_is_u8500()) { |
Linus Walleij | b957662 | 2012-01-11 09:46:59 +0100 | [diff] [blame] | 50 | mtu_timer_base = __io_address(U8500_MTU0_BASE); |
Linus Walleij | b1e3be06 | 2011-10-03 09:30:20 +0200 | [diff] [blame] | 51 | prcmu_timer_base = __io_address(U8500_PRCMU_TIMER_4_BASE); |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 52 | } 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. |
Linus Walleij | 29746f4 | 2012-04-13 13:16:31 +0200 | [diff] [blame^] | 68 | * The PRCMU timer 4 register a clocksource and |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 69 | * sched_clock with higher rating then MTU since is always-on. |
| 70 | * |
| 71 | */ |
| 72 | |
Linus Walleij | b957662 | 2012-01-11 09:46:59 +0100 | [diff] [blame] | 73 | nmdk_timer_init(mtu_timer_base); |
Linus Walleij | b1e3be06 | 2011-10-03 09:30:20 +0200 | [diff] [blame] | 74 | clksrc_dbx500_prcmu_init(prcmu_timer_base); |
Marc Zyngier | 08efd6c | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 75 | ux500_twd_init(); |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 76 | } |
| 77 | |
Jonas Aaberg | bb219db | 2011-09-21 07:47:02 +0200 | [diff] [blame] | 78 | static void ux500_timer_reset(void) |
| 79 | { |
| 80 | nmdk_clkevt_reset(); |
| 81 | nmdk_clksrc_reset(); |
| 82 | } |
| 83 | |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 84 | struct sys_timer ux500_timer = { |
| 85 | .init = ux500_timer_init, |
Jonas Aaberg | bb219db | 2011-09-21 07:47:02 +0200 | [diff] [blame] | 86 | .resume = ux500_timer_reset, |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 87 | }; |