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> |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 12 | |
Marc Zyngier | 08efd6c | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 13 | #include <asm/smp_twd.h> |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 14 | |
| 15 | #include <plat/mtu.h> |
| 16 | |
| 17 | #include <mach/setup.h> |
| 18 | #include <mach/hardware.h> |
Marc Zyngier | 218a280 | 2012-03-15 11:05:39 +0000 | [diff] [blame] | 19 | #include <mach/irqs.h> |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 20 | |
Marc Zyngier | 08efd6c | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 21 | #ifdef CONFIG_HAVE_ARM_TWD |
| 22 | static DEFINE_TWD_LOCAL_TIMER(u5500_twd_local_timer, |
| 23 | U5500_TWD_BASE, IRQ_LOCALTIMER); |
| 24 | static DEFINE_TWD_LOCAL_TIMER(u8500_twd_local_timer, |
| 25 | U8500_TWD_BASE, IRQ_LOCALTIMER); |
| 26 | |
| 27 | static void __init ux500_twd_init(void) |
| 28 | { |
| 29 | struct twd_local_timer *twd_local_timer; |
| 30 | int err; |
| 31 | |
| 32 | twd_local_timer = cpu_is_u5500() ? &u5500_twd_local_timer : |
| 33 | &u8500_twd_local_timer; |
| 34 | |
Lee Jones | 71de5c4 | 2012-03-16 09:53:24 +0000 | [diff] [blame] | 35 | if (of_have_populated_dt()) |
| 36 | twd_local_timer_of_register(); |
| 37 | 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 Zyngier | 08efd6c | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 42 | } |
| 43 | #else |
| 44 | #define ux500_twd_init() do { } while(0) |
| 45 | #endif |
| 46 | |
Lee Jones | c51423f | 2012-04-24 10:04:46 +0100 | [diff] [blame^] | 47 | const static struct of_device_id prcmu_timer_of_match[] __initconst = { |
| 48 | { .compatible = "stericsson,db8500-prcmu-timer-4", }, |
| 49 | { }, |
| 50 | }; |
| 51 | |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 52 | static void __init ux500_timer_init(void) |
| 53 | { |
Linus Walleij | b957662 | 2012-01-11 09:46:59 +0100 | [diff] [blame] | 54 | void __iomem *mtu_timer_base; |
Linus Walleij | b1e3be06 | 2011-10-03 09:30:20 +0200 | [diff] [blame] | 55 | void __iomem *prcmu_timer_base; |
Lee Jones | c51423f | 2012-04-24 10:04:46 +0100 | [diff] [blame^] | 56 | void __iomem *tmp_base; |
| 57 | struct device_node *np; |
Linus Walleij | b1e3be06 | 2011-10-03 09:30:20 +0200 | [diff] [blame] | 58 | |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 59 | if (cpu_is_u5500()) { |
Linus Walleij | b957662 | 2012-01-11 09:46:59 +0100 | [diff] [blame] | 60 | mtu_timer_base = __io_address(U5500_MTU0_BASE); |
Linus Walleij | b1e3be06 | 2011-10-03 09:30:20 +0200 | [diff] [blame] | 61 | prcmu_timer_base = __io_address(U5500_PRCMU_TIMER_3_BASE); |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 62 | } else if (cpu_is_u8500()) { |
Linus Walleij | b957662 | 2012-01-11 09:46:59 +0100 | [diff] [blame] | 63 | mtu_timer_base = __io_address(U8500_MTU0_BASE); |
Linus Walleij | b1e3be06 | 2011-10-03 09:30:20 +0200 | [diff] [blame] | 64 | prcmu_timer_base = __io_address(U8500_PRCMU_TIMER_4_BASE); |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 65 | } else { |
| 66 | ux500_unknown_soc(); |
| 67 | } |
| 68 | |
Lee Jones | c51423f | 2012-04-24 10:04:46 +0100 | [diff] [blame^] | 69 | /* TODO: Once MTU has been DT:ed place code above into else. */ |
| 70 | if (of_have_populated_dt()) { |
| 71 | np = of_find_matching_node(NULL, prcmu_timer_of_match); |
| 72 | if (!np) |
| 73 | goto dt_fail; |
| 74 | |
| 75 | tmp_base = of_iomap(np, 0); |
| 76 | if (!tmp_base) |
| 77 | goto dt_fail; |
| 78 | |
| 79 | prcmu_timer_base = tmp_base; |
| 80 | } |
| 81 | |
| 82 | dt_fail: |
| 83 | /* Doing it the old fashioned way. */ |
| 84 | |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 85 | /* |
| 86 | * Here we register the timerblocks active in the system. |
| 87 | * Localtimers (twd) is started when both cpu is up and running. |
| 88 | * MTU register a clocksource, clockevent and sched_clock. |
| 89 | * Since the MTU is located in the VAPE power domain |
| 90 | * it will be cleared in sleep which makes it unsuitable. |
| 91 | * We however need it as a timer tick (clockevent) |
| 92 | * during boot to calibrate delay until twd is started. |
| 93 | * RTC-RTT have problems as timer tick during boot since it is |
| 94 | * depending on delay which is not yet calibrated. RTC-RTT is in the |
| 95 | * always-on powerdomain and is used as clockevent instead of twd when |
| 96 | * sleeping. |
| 97 | * The PRCMU timer 4(3 for DB5500) register a clocksource and |
| 98 | * sched_clock with higher rating then MTU since is always-on. |
| 99 | * |
| 100 | */ |
| 101 | |
Linus Walleij | b957662 | 2012-01-11 09:46:59 +0100 | [diff] [blame] | 102 | nmdk_timer_init(mtu_timer_base); |
Linus Walleij | b1e3be06 | 2011-10-03 09:30:20 +0200 | [diff] [blame] | 103 | clksrc_dbx500_prcmu_init(prcmu_timer_base); |
Marc Zyngier | 08efd6c | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 104 | ux500_twd_init(); |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 105 | } |
| 106 | |
Jonas Aaberg | bb219db | 2011-09-21 07:47:02 +0200 | [diff] [blame] | 107 | static void ux500_timer_reset(void) |
| 108 | { |
| 109 | nmdk_clkevt_reset(); |
| 110 | nmdk_clksrc_reset(); |
| 111 | } |
| 112 | |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 113 | struct sys_timer ux500_timer = { |
| 114 | .init = ux500_timer_init, |
Jonas Aaberg | bb219db | 2011-09-21 07:47:02 +0200 | [diff] [blame] | 115 | .resume = ux500_timer_reset, |
Jonas Aaberg | 5f5663a | 2011-09-14 09:10:54 +0200 | [diff] [blame] | 116 | }; |