clksrc-dbx500-prcmu.c 2.4 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. * Author: Sundar Iyer for ST-Ericsson
  7. * sched_clock implementation is based on:
  8. * plat-nomadik/timer.c Linus Walleij <linus.walleij@stericsson.com>
  9. *
  10. * DBx500-PRCMU Timer
  11. * The PRCMU has 5 timers which are available in a always-on
  12. * power domain. We use the Timer 4 for our always-on clock
  13. * source on DB8500 and Timer 3 on DB5500.
  14. */
  15. #include <linux/clockchips.h>
  16. #include <linux/clksrc-dbx500-prcmu.h>
  17. #include <asm/sched_clock.h>
  18. #include <mach/setup.h>
  19. #define RATE_32K 32768
  20. #define TIMER_MODE_CONTINOUS 0x1
  21. #define TIMER_DOWNCOUNT_VAL 0xffffffff
  22. #define PRCMU_TIMER_REF 0
  23. #define PRCMU_TIMER_DOWNCOUNT 0x4
  24. #define PRCMU_TIMER_MODE 0x8
  25. #define SCHED_CLOCK_MIN_WRAP 131072 /* 2^32 / 32768 */
  26. static void __iomem *clksrc_dbx500_timer_base;
  27. static cycle_t clksrc_dbx500_prcmu_read(struct clocksource *cs)
  28. {
  29. u32 count, count2;
  30. do {
  31. count = readl(clksrc_dbx500_timer_base +
  32. PRCMU_TIMER_DOWNCOUNT);
  33. count2 = readl(clksrc_dbx500_timer_base +
  34. PRCMU_TIMER_DOWNCOUNT);
  35. } while (count2 != count);
  36. /* Negate because the timer is a decrementing counter */
  37. return ~count;
  38. }
  39. static struct clocksource clocksource_dbx500_prcmu = {
  40. .name = "dbx500-prcmu-timer",
  41. .rating = 300,
  42. .read = clksrc_dbx500_prcmu_read,
  43. .mask = CLOCKSOURCE_MASK(32),
  44. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  45. };
  46. #ifdef CONFIG_CLKSRC_DBX500_PRCMU_SCHED_CLOCK
  47. static u32 notrace dbx500_prcmu_sched_clock_read(void)
  48. {
  49. if (unlikely(!clksrc_dbx500_timer_base))
  50. return 0;
  51. return clksrc_dbx500_prcmu_read(&clocksource_dbx500_prcmu);
  52. }
  53. #endif
  54. void __init clksrc_dbx500_prcmu_init(void __iomem *base)
  55. {
  56. clksrc_dbx500_timer_base = base;
  57. /*
  58. * The A9 sub system expects the timer to be configured as
  59. * a continous looping timer.
  60. * The PRCMU should configure it but if it for some reason
  61. * don't we do it here.
  62. */
  63. if (readl(clksrc_dbx500_timer_base + PRCMU_TIMER_MODE) !=
  64. TIMER_MODE_CONTINOUS) {
  65. writel(TIMER_MODE_CONTINOUS,
  66. clksrc_dbx500_timer_base + PRCMU_TIMER_MODE);
  67. writel(TIMER_DOWNCOUNT_VAL,
  68. clksrc_dbx500_timer_base + PRCMU_TIMER_REF);
  69. }
  70. #ifdef CONFIG_CLKSRC_DBX500_PRCMU_SCHED_CLOCK
  71. setup_sched_clock(dbx500_prcmu_sched_clock_read,
  72. 32, RATE_32K);
  73. #endif
  74. clocksource_register_hz(&clocksource_dbx500_prcmu, RATE_32K);
  75. }