timer.c 2.8 KB

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