timer.c 901 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) Marvell International Ltd. and its affiliates
  4. * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
  5. *
  6. * Copyright (C) 2015 Stefan Roese <sr@denx.de>
  7. */
  8. #include <common.h>
  9. #include <asm/io.h>
  10. #include <asm/arch/soc.h>
  11. #define TIMER_LOAD_VAL 0xffffffff
  12. static int init_done __attribute__((section(".data"))) = 0;
  13. /*
  14. * Timer initialization
  15. */
  16. int timer_init(void)
  17. {
  18. /* Only init the timer once */
  19. if (init_done)
  20. return 0;
  21. init_done = 1;
  22. /* load value into timer */
  23. writel(TIMER_LOAD_VAL, MVEBU_TIMER_BASE + 0x10);
  24. writel(TIMER_LOAD_VAL, MVEBU_TIMER_BASE + 0x14);
  25. #if defined(CONFIG_ARCH_MVEBU)
  26. /* On Armada XP / 38x ..., the 25MHz clock source needs to be enabled */
  27. setbits_le32(MVEBU_TIMER_BASE + 0x00, BIT(11));
  28. #endif
  29. /* enable timer in auto reload mode */
  30. setbits_le32(MVEBU_TIMER_BASE + 0x00, 0x3);
  31. return 0;
  32. }