timer.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. np = of_find_matching_node(NULL, prcmu_timer_of_match);
  56. if (!np)
  57. goto dt_fail;
  58. tmp_base = of_iomap(np, 0);
  59. if (!tmp_base)
  60. goto dt_fail;
  61. prcmu_timer_base = tmp_base;
  62. }
  63. dt_fail:
  64. /* Doing it the old fashioned way. */
  65. /*
  66. * Here we register the timerblocks active in the system.
  67. * Localtimers (twd) is started when both cpu is up and running.
  68. * MTU register a clocksource, clockevent and sched_clock.
  69. * Since the MTU is located in the VAPE power domain
  70. * it will be cleared in sleep which makes it unsuitable.
  71. * We however need it as a timer tick (clockevent)
  72. * during boot to calibrate delay until twd is started.
  73. * RTC-RTT have problems as timer tick during boot since it is
  74. * depending on delay which is not yet calibrated. RTC-RTT is in the
  75. * always-on powerdomain and is used as clockevent instead of twd when
  76. * sleeping.
  77. * The PRCMU timer 4 register a clocksource and
  78. * sched_clock with higher rating then MTU since is always-on.
  79. *
  80. */
  81. nmdk_timer_init(mtu_timer_base);
  82. clksrc_dbx500_prcmu_init(prcmu_timer_base);
  83. ux500_twd_init();
  84. }
  85. static void ux500_timer_reset(void)
  86. {
  87. nmdk_clkevt_reset();
  88. nmdk_clksrc_reset();
  89. }
  90. struct sys_timer ux500_timer = {
  91. .init = ux500_timer_init,
  92. .resume = ux500_timer_reset,
  93. };