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> |
Lee Jones | c51423f | 2012-04-24 10:04:46 +0100 | [diff] [blame] | 11 | #include <linux/of_address.h> |
Linus Walleij | 694e33a | 2012-10-18 14:01:25 +0200 | [diff] [blame] | 12 | #include <linux/platform_data/clocksource-nomadik-mtu.h> |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 13 | |
Marc Zyngier | 08efd6c | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 14 | #include <asm/smp_twd.h> |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 15 | |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 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 | |
Linus Walleij | 7a4f260 | 2012-09-19 19:31:19 +0200 | [diff] [blame] | 20 | #include "id.h" |
| 21 | |
Marc Zyngier | 08efd6c | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 22 | #ifdef CONFIG_HAVE_ARM_TWD |
Marc Zyngier | 08efd6c | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 23 | static DEFINE_TWD_LOCAL_TIMER(u8500_twd_local_timer, |
| 24 | U8500_TWD_BASE, IRQ_LOCALTIMER); |
| 25 | |
| 26 | static void __init ux500_twd_init(void) |
| 27 | { |
| 28 | struct twd_local_timer *twd_local_timer; |
| 29 | int err; |
| 30 | |
Linus Walleij | 29746f4 | 2012-04-13 13:16:31 +0200 | [diff] [blame] | 31 | /* Use this to switch local timer base if changed in new ASICs */ |
| 32 | twd_local_timer = &u8500_twd_local_timer; |
Marc Zyngier | 08efd6c | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 33 | |
Lee Jones | 71de5c4 | 2012-03-16 09:53:24 +0000 | [diff] [blame] | 34 | if (of_have_populated_dt()) |
| 35 | twd_local_timer_of_register(); |
| 36 | else { |
| 37 | err = twd_local_timer_register(twd_local_timer); |
| 38 | if (err) |
| 39 | pr_err("twd_local_timer_register failed %d\n", err); |
| 40 | } |
Marc Zyngier | 08efd6c | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 41 | } |
| 42 | #else |
| 43 | #define ux500_twd_init() do { } while(0) |
| 44 | #endif |
| 45 | |
Lee Jones | c51423f | 2012-04-24 10:04:46 +0100 | [diff] [blame] | 46 | const static struct of_device_id prcmu_timer_of_match[] __initconst = { |
| 47 | { .compatible = "stericsson,db8500-prcmu-timer-4", }, |
| 48 | { }, |
| 49 | }; |
| 50 | |
Stephen Warren | 6bb27d7 | 2012-11-08 12:40:59 -0700 | [diff] [blame] | 51 | void __init ux500_timer_init(void) |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 52 | { |
Linus Walleij | b957662 | 2012-01-11 09:46:59 +0100 | [diff] [blame] | 53 | void __iomem *mtu_timer_base; |
Linus Walleij | b1e3be06 | 2011-10-03 09:30:20 +0200 | [diff] [blame] | 54 | void __iomem *prcmu_timer_base; |
Lee Jones | c51423f | 2012-04-24 10:04:46 +0100 | [diff] [blame] | 55 | void __iomem *tmp_base; |
| 56 | struct device_node *np; |
Linus Walleij | b1e3be06 | 2011-10-03 09:30:20 +0200 | [diff] [blame] | 57 | |
Loic PALLARDY | 79964bc | 2012-09-03 15:10:23 +0200 | [diff] [blame] | 58 | if (cpu_is_u8500_family() || cpu_is_ux540_family()) { |
Linus Walleij | b957662 | 2012-01-11 09:46:59 +0100 | [diff] [blame] | 59 | mtu_timer_base = __io_address(U8500_MTU0_BASE); |
Linus Walleij | b1e3be06 | 2011-10-03 09:30:20 +0200 | [diff] [blame] | 60 | prcmu_timer_base = __io_address(U8500_PRCMU_TIMER_4_BASE); |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 61 | } else { |
| 62 | ux500_unknown_soc(); |
| 63 | } |
| 64 | |
Lee Jones | c51423f | 2012-04-24 10:04:46 +0100 | [diff] [blame] | 65 | /* TODO: Once MTU has been DT:ed place code above into else. */ |
| 66 | if (of_have_populated_dt()) { |
Lee Jones | c57920e | 2012-06-15 09:27:54 +0100 | [diff] [blame] | 67 | #ifdef CONFIG_OF |
Lee Jones | c51423f | 2012-04-24 10:04:46 +0100 | [diff] [blame] | 68 | np = of_find_matching_node(NULL, prcmu_timer_of_match); |
| 69 | if (!np) |
Lee Jones | c57920e | 2012-06-15 09:27:54 +0100 | [diff] [blame] | 70 | #endif |
Lee Jones | c51423f | 2012-04-24 10:04:46 +0100 | [diff] [blame] | 71 | goto dt_fail; |
| 72 | |
| 73 | tmp_base = of_iomap(np, 0); |
| 74 | if (!tmp_base) |
| 75 | goto dt_fail; |
| 76 | |
| 77 | prcmu_timer_base = tmp_base; |
| 78 | } |
| 79 | |
| 80 | dt_fail: |
| 81 | /* Doing it the old fashioned way. */ |
| 82 | |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 83 | /* |
| 84 | * Here we register the timerblocks active in the system. |
| 85 | * Localtimers (twd) is started when both cpu is up and running. |
| 86 | * MTU register a clocksource, clockevent and sched_clock. |
| 87 | * Since the MTU is located in the VAPE power domain |
| 88 | * it will be cleared in sleep which makes it unsuitable. |
| 89 | * We however need it as a timer tick (clockevent) |
| 90 | * during boot to calibrate delay until twd is started. |
| 91 | * RTC-RTT have problems as timer tick during boot since it is |
| 92 | * depending on delay which is not yet calibrated. RTC-RTT is in the |
| 93 | * always-on powerdomain and is used as clockevent instead of twd when |
| 94 | * sleeping. |
Linus Walleij | 29746f4 | 2012-04-13 13:16:31 +0200 | [diff] [blame] | 95 | * The PRCMU timer 4 register a clocksource and |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 96 | * sched_clock with higher rating then MTU since is always-on. |
| 97 | * |
| 98 | */ |
| 99 | |
Linus Walleij | 0813069 | 2012-10-18 11:06:02 +0200 | [diff] [blame] | 100 | nmdk_timer_init(mtu_timer_base, IRQ_MTU0); |
Linus Walleij | b1e3be06 | 2011-10-03 09:30:20 +0200 | [diff] [blame] | 101 | clksrc_dbx500_prcmu_init(prcmu_timer_base); |
Marc Zyngier | 08efd6c | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 102 | ux500_twd_init(); |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 103 | } |