timer.c 2.7 KB

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