timer.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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/clocksource.h>
  11. #include <linux/of.h>
  12. #include <linux/of_address.h>
  13. #include <linux/platform_data/clocksource-nomadik-mtu.h>
  14. #include <asm/smp_twd.h>
  15. #include "setup.h"
  16. #include "irqs.h"
  17. #include "db8500-regs.h"
  18. #include "id.h"
  19. #ifdef CONFIG_HAVE_ARM_TWD
  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. /* Use this to switch local timer base if changed in new ASICs */
  27. twd_local_timer = &u8500_twd_local_timer;
  28. if (of_have_populated_dt())
  29. clocksource_of_init();
  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. 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_u8500_family() || cpu_is_ux540_family()) {
  50. mtu_timer_base = __io_address(U8500_MTU0_BASE);
  51. prcmu_timer_base = __io_address(U8500_PRCMU_TIMER_4_BASE);
  52. } else {
  53. ux500_unknown_soc();
  54. }
  55. /* TODO: Once MTU has been DT:ed place code above into else. */
  56. if (of_have_populated_dt()) {
  57. #ifdef CONFIG_OF
  58. np = of_find_matching_node(NULL, prcmu_timer_of_match);
  59. if (!np)
  60. #endif
  61. goto dt_fail;
  62. tmp_base = of_iomap(np, 0);
  63. if (!tmp_base)
  64. goto dt_fail;
  65. prcmu_timer_base = tmp_base;
  66. }
  67. dt_fail:
  68. /* Doing it the old fashioned way. */
  69. /*
  70. * Here we register the timerblocks active in the system.
  71. * Localtimers (twd) is started when both cpu is up and running.
  72. * MTU register a clocksource, clockevent and sched_clock.
  73. * Since the MTU is located in the VAPE power domain
  74. * it will be cleared in sleep which makes it unsuitable.
  75. * We however need it as a timer tick (clockevent)
  76. * during boot to calibrate delay until twd is started.
  77. * RTC-RTT have problems as timer tick during boot since it is
  78. * depending on delay which is not yet calibrated. RTC-RTT is in the
  79. * always-on powerdomain and is used as clockevent instead of twd when
  80. * sleeping.
  81. * The PRCMU timer 4 register a clocksource and
  82. * sched_clock with higher rating then MTU since is always-on.
  83. *
  84. */
  85. nmdk_timer_init(mtu_timer_base, IRQ_MTU0);
  86. clksrc_dbx500_prcmu_init(prcmu_timer_base);
  87. ux500_twd_init();
  88. }