tegra_delay_timer.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
  3. * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #include <arch.h>
  8. #include <drivers/delay_timer.h>
  9. #include <lib/mmio.h>
  10. #include <lib/utils_def.h>
  11. #include <plat/common/platform.h>
  12. #include <tegra_def.h>
  13. #include <tegra_private.h>
  14. static uint32_t tegra_timer_get_value(void)
  15. {
  16. /* enable cntps_tval_el1 timer, mask interrupt */
  17. write_cntps_ctl_el1(CNTP_CTL_IMASK_BIT | CNTP_CTL_ENABLE_BIT);
  18. /*
  19. * Generic delay timer implementation expects the timer to be a down
  20. * counter. The value is clipped from 64 to 32 bits.
  21. */
  22. return (uint32_t)(read_cntps_tval_el1());
  23. }
  24. /*
  25. * Initialise the architecture provided counter as the delay timer.
  26. */
  27. void tegra_delay_timer_init(void)
  28. {
  29. static timer_ops_t tegra_timer_ops;
  30. /* Value in ticks */
  31. uint32_t multiplier = MHZ_TICKS_PER_SEC;
  32. /* Value in ticks per second (Hz) */
  33. uint32_t divider = plat_get_syscnt_freq2();
  34. /* Reduce multiplier and divider by dividing them repeatedly by 10 */
  35. while (((multiplier % 10U) == 0U) && ((divider % 10U) == 0U)) {
  36. multiplier /= 10U;
  37. divider /= 10U;
  38. }
  39. /* enable cntps_tval_el1 timer, mask interrupt */
  40. write_cntps_ctl_el1(CNTP_CTL_IMASK_BIT | CNTP_CTL_ENABLE_BIT);
  41. /* register the timer */
  42. tegra_timer_ops.get_timer_value = tegra_timer_get_value;
  43. tegra_timer_ops.clk_mult = multiplier;
  44. tegra_timer_ops.clk_div = divider;
  45. timer_init(&tegra_timer_ops);
  46. }