timer.c 945 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 <init.h>
  10. #include <asm/io.h>
  11. #include <asm/arch/soc.h>
  12. #include <linux/bitops.h>
  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. }