timer.c 930 B

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