clksrc-dbx500-prcmu.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) ST-Ericsson SA 2011
  4. *
  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.
  14. */
  15. #include <linux/of.h>
  16. #include <linux/of_address.h>
  17. #include <linux/clockchips.h>
  18. #define RATE_32K 32768
  19. #define TIMER_MODE_CONTINOUS 0x1
  20. #define TIMER_DOWNCOUNT_VAL 0xffffffff
  21. #define PRCMU_TIMER_REF 0
  22. #define PRCMU_TIMER_DOWNCOUNT 0x4
  23. #define PRCMU_TIMER_MODE 0x8
  24. static void __iomem *clksrc_dbx500_timer_base;
  25. static u64 notrace clksrc_dbx500_prcmu_read(struct clocksource *cs)
  26. {
  27. void __iomem *base = clksrc_dbx500_timer_base;
  28. u32 count, count2;
  29. do {
  30. count = readl_relaxed(base + PRCMU_TIMER_DOWNCOUNT);
  31. count2 = readl_relaxed(base + PRCMU_TIMER_DOWNCOUNT);
  32. } while (count2 != count);
  33. /* Negate because the timer is a decrementing counter */
  34. return ~count;
  35. }
  36. static struct clocksource clocksource_dbx500_prcmu = {
  37. .name = "dbx500-prcmu-timer",
  38. .rating = 100,
  39. .read = clksrc_dbx500_prcmu_read,
  40. .mask = CLOCKSOURCE_MASK(32),
  41. .flags = CLOCK_SOURCE_IS_CONTINUOUS | CLOCK_SOURCE_SUSPEND_NONSTOP,
  42. };
  43. static int __init clksrc_dbx500_prcmu_init(struct device_node *node)
  44. {
  45. clksrc_dbx500_timer_base = of_iomap(node, 0);
  46. /*
  47. * The A9 sub system expects the timer to be configured as
  48. * a continous looping timer.
  49. * The PRCMU should configure it but if it for some reason
  50. * don't we do it here.
  51. */
  52. if (readl(clksrc_dbx500_timer_base + PRCMU_TIMER_MODE) !=
  53. TIMER_MODE_CONTINOUS) {
  54. writel(TIMER_MODE_CONTINOUS,
  55. clksrc_dbx500_timer_base + PRCMU_TIMER_MODE);
  56. writel(TIMER_DOWNCOUNT_VAL,
  57. clksrc_dbx500_timer_base + PRCMU_TIMER_REF);
  58. }
  59. return clocksource_register_hz(&clocksource_dbx500_prcmu, RATE_32K);
  60. }
  61. TIMER_OF_DECLARE(dbx500_prcmu, "stericsson,db8500-prcmu-timer-4",
  62. clksrc_dbx500_prcmu_init);