timer.c 2.4 KB

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