timer.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 <asm/smp_twd.h>
  12. #include <plat/mtu.h>
  13. #include <mach/setup.h>
  14. #include <mach/hardware.h>
  15. #include <mach/irqs.h>
  16. #ifdef CONFIG_HAVE_ARM_TWD
  17. static DEFINE_TWD_LOCAL_TIMER(u5500_twd_local_timer,
  18. U5500_TWD_BASE, IRQ_LOCALTIMER);
  19. static DEFINE_TWD_LOCAL_TIMER(u8500_twd_local_timer,
  20. U8500_TWD_BASE, IRQ_LOCALTIMER);
  21. static void __init ux500_twd_init(void)
  22. {
  23. struct twd_local_timer *twd_local_timer;
  24. int err;
  25. twd_local_timer = cpu_is_u5500() ? &u5500_twd_local_timer :
  26. &u8500_twd_local_timer;
  27. if (of_have_populated_dt())
  28. twd_local_timer_of_register();
  29. else {
  30. err = twd_local_timer_register(twd_local_timer);
  31. if (err)
  32. pr_err("twd_local_timer_register failed %d\n", err);
  33. }
  34. }
  35. #else
  36. #define ux500_twd_init() do { } while(0)
  37. #endif
  38. static void __init ux500_timer_init(void)
  39. {
  40. void __iomem *mtu_timer_base;
  41. void __iomem *prcmu_timer_base;
  42. if (cpu_is_u5500()) {
  43. mtu_timer_base = __io_address(U5500_MTU0_BASE);
  44. prcmu_timer_base = __io_address(U5500_PRCMU_TIMER_3_BASE);
  45. } else if (cpu_is_u8500()) {
  46. mtu_timer_base = __io_address(U8500_MTU0_BASE);
  47. prcmu_timer_base = __io_address(U8500_PRCMU_TIMER_4_BASE);
  48. } else {
  49. ux500_unknown_soc();
  50. }
  51. /*
  52. * Here we register the timerblocks active in the system.
  53. * Localtimers (twd) is started when both cpu is up and running.
  54. * MTU register a clocksource, clockevent and sched_clock.
  55. * Since the MTU is located in the VAPE power domain
  56. * it will be cleared in sleep which makes it unsuitable.
  57. * We however need it as a timer tick (clockevent)
  58. * during boot to calibrate delay until twd is started.
  59. * RTC-RTT have problems as timer tick during boot since it is
  60. * depending on delay which is not yet calibrated. RTC-RTT is in the
  61. * always-on powerdomain and is used as clockevent instead of twd when
  62. * sleeping.
  63. * The PRCMU timer 4(3 for DB5500) register a clocksource and
  64. * sched_clock with higher rating then MTU since is always-on.
  65. *
  66. */
  67. nmdk_timer_init(mtu_timer_base);
  68. clksrc_dbx500_prcmu_init(prcmu_timer_base);
  69. ux500_twd_init();
  70. }
  71. static void ux500_timer_reset(void)
  72. {
  73. nmdk_clkevt_reset();
  74. nmdk_clksrc_reset();
  75. }
  76. struct sys_timer ux500_timer = {
  77. .init = ux500_timer_init,
  78. .resume = ux500_timer_reset,
  79. };