timer.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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>
  8. #include <linux/errno.h>
  9. #include <linux/clksrc-dbx500-prcmu.h>
  10. #include <linux/of.h>
  11. #include <linux/of_address.h>
  12. #include <asm/smp_twd.h>
  13. #include <plat/mtu.h>
  14. #include <mach/setup.h>
  15. #include <mach/hardware.h>
  16. #include <mach/irqs.h>
  17. #ifdef CONFIG_HAVE_ARM_TWD
  18. static DEFINE_TWD_LOCAL_TIMER(u5500_twd_local_timer,
  19. U5500_TWD_BASE, IRQ_LOCALTIMER);
  20. static DEFINE_TWD_LOCAL_TIMER(u8500_twd_local_timer,
  21. U8500_TWD_BASE, IRQ_LOCALTIMER);
  22. static void __init ux500_twd_init(void)
  23. {
  24. struct twd_local_timer *twd_local_timer;
  25. int err;
  26. twd_local_timer = cpu_is_u5500() ? &u5500_twd_local_timer :
  27. &u8500_twd_local_timer;
  28. if (of_have_populated_dt())
  29. twd_local_timer_of_register();
  30. else {
  31. err = twd_local_timer_register(twd_local_timer);
  32. if (err)
  33. pr_err("twd_local_timer_register failed %d\n", err);
  34. }
  35. }
  36. #else
  37. #define ux500_twd_init() do { } while(0)
  38. #endif
  39. const static struct of_device_id prcmu_timer_of_match[] __initconst = {
  40. { .compatible = "stericsson,db8500-prcmu-timer-4", },
  41. { },
  42. };
  43. static void __init ux500_timer_init(void)
  44. {
  45. void __iomem *mtu_timer_base;
  46. void __iomem *prcmu_timer_base;
  47. void __iomem *tmp_base;
  48. struct device_node *np;
  49. if (cpu_is_u5500()) {
  50. mtu_timer_base = __io_address(U5500_MTU0_BASE);
  51. prcmu_timer_base = __io_address(U5500_PRCMU_TIMER_3_BASE);
  52. } else if (cpu_is_u8500()) {
  53. mtu_timer_base = __io_address(U8500_MTU0_BASE);
  54. prcmu_timer_base = __io_address(U8500_PRCMU_TIMER_4_BASE);
  55. } else {
  56. ux500_unknown_soc();
  57. }
  58. /* TODO: Once MTU has been DT:ed place code above into else. */
  59. if (of_have_populated_dt()) {
  60. np = of_find_matching_node(NULL, prcmu_timer_of_match);
  61. if (!np)
  62. goto dt_fail;
  63. tmp_base = of_iomap(np, 0);
  64. if (!tmp_base)
  65. goto dt_fail;
  66. prcmu_timer_base = tmp_base;
  67. }
  68. dt_fail:
  69. /* Doing it the old fashioned way. */
  70. /*
  71. * Here we register the timerblocks active in the system.
  72. * Localtimers (twd) is started when both cpu is up and running.
  73. * MTU register a clocksource, clockevent and sched_clock.
  74. * Since the MTU is located in the VAPE power domain
  75. * it will be cleared in sleep which makes it unsuitable.
  76. * We however need it as a timer tick (clockevent)
  77. * during boot to calibrate delay until twd is started.
  78. * RTC-RTT have problems as timer tick during boot since it is
  79. * depending on delay which is not yet calibrated. RTC-RTT is in the
  80. * always-on powerdomain and is used as clockevent instead of twd when
  81. * sleeping.
  82. * The PRCMU timer 4(3 for DB5500) register a clocksource and
  83. * sched_clock with higher rating then MTU since is always-on.
  84. *
  85. */
  86. nmdk_timer_init(mtu_timer_base);
  87. clksrc_dbx500_prcmu_init(prcmu_timer_base);
  88. ux500_twd_init();
  89. }
  90. static void ux500_timer_reset(void)
  91. {
  92. nmdk_clkevt_reset();
  93. nmdk_clksrc_reset();
  94. }
  95. struct sys_timer ux500_timer = {
  96. .init = ux500_timer_init,
  97. .resume = ux500_timer_reset,
  98. };