timer_sync.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) 2015 - 2020, Broadcom
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch_helpers.h>
  7. #include <common/debug.h>
  8. #include <lib/mmio.h>
  9. #include <platform_def.h>
  10. #include <timer_sync.h>
  11. /*******************************************************************************
  12. * Defines related to time sync and satelite timers
  13. ******************************************************************************/
  14. #define TIME_SYNC_WR_ENA ((uint32_t)0xACCE55 << 8)
  15. #define IHOST_STA_TMR_CTRL 0x1800
  16. #define IHOST_SAT_TMR_INC_L 0x1814
  17. #define IHOST_SAT_TMR_INC_H 0x1818
  18. #define SAT_TMR_CYCLE_DELAY 2
  19. #define SAT_TMR_32BIT_WRAP_VAL (BIT_64(32) - SAT_TMR_CYCLE_DELAY)
  20. void ihost_enable_satellite_timer(unsigned int cluster_id)
  21. {
  22. uintptr_t ihost_base;
  23. uint32_t time_lx, time_h;
  24. uintptr_t ihost_enable;
  25. VERBOSE("Program iHost%u satellite timer\n", cluster_id);
  26. ihost_base = IHOST0_BASE + cluster_id * IHOST_ADDR_SPACE;
  27. /* this read starts the satellite timer counting from 0 */
  28. ihost_enable = CENTRAL_TIMER_GET_IHOST_ENA_BASE + cluster_id * 4;
  29. time_lx = mmio_read_32(ihost_enable);
  30. /*
  31. * Increment the satellite timer by the central timer plus 2
  32. * to accommodate for a 1 cycle delay through NOC
  33. * plus counter starting from 0.
  34. */
  35. mmio_write_32(ihost_base + IHOST_SAT_TMR_INC_L,
  36. time_lx + SAT_TMR_CYCLE_DELAY);
  37. /*
  38. * Read the latched upper data, if lx will wrap by adding 2 to it
  39. * we need to handle the wrap
  40. */
  41. time_h = mmio_read_32(CENTRAL_TIMER_GET_H);
  42. if (time_lx >= SAT_TMR_32BIT_WRAP_VAL)
  43. mmio_write_32(ihost_base + IHOST_SAT_TMR_INC_H, time_h + 1);
  44. else
  45. mmio_write_32(ihost_base + IHOST_SAT_TMR_INC_H, time_h);
  46. }
  47. void brcm_timer_sync_init(void)
  48. {
  49. unsigned int cluster_id;
  50. /* Get the Time Sync module out of reset */
  51. mmio_setbits_32(CDRU_MISC_RESET_CONTROL,
  52. BIT(CDRU_MISC_RESET_CONTROL_TS_RESET_N));
  53. /* Deassert the Central Timer TIMER_EN signal for all module */
  54. mmio_write_32(CENTRAL_TIMER_SAT_TMR_ENA, TIME_SYNC_WR_ENA);
  55. /* enables/programs iHost0 satellite timer*/
  56. cluster_id = MPIDR_AFFLVL1_VAL(read_mpidr());
  57. ihost_enable_satellite_timer(cluster_id);
  58. }