time.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2009
  4. * Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
  5. *
  6. * (C) Copyright 2007-2012
  7. * Nobobuhiro Iwamatsu <iwamatsu@nigauri.org>
  8. *
  9. * (C) Copyright 2003
  10. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  11. */
  12. #include <common.h>
  13. #include <asm/processor.h>
  14. #include <asm/io.h>
  15. #if defined(CONFIG_CPU_SH3)
  16. #define TSTR 0x2
  17. #define TCNT0 0x8
  18. #define TCR0 0xc
  19. #endif /* CONFIG_CPU_SH3 */
  20. #if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_RMOBILE)
  21. #define TSTR 0x4
  22. #define TCNT0 0xc
  23. #define TCR0 0x10
  24. #endif /* CONFIG_CPU_SH4 */
  25. #define TCR_TPSC 0x07
  26. #define TSTR_STR0 BIT(0)
  27. unsigned long get_tbclk(void)
  28. {
  29. #ifdef CONFIG_RCAR_GEN2
  30. return CONFIG_SYS_CLK_FREQ / 8;
  31. #else
  32. return CONFIG_SYS_CLK_FREQ / 4;
  33. #endif
  34. }
  35. unsigned long timer_read_counter(void)
  36. {
  37. return ~readl(TMU_BASE + TCNT0);
  38. }
  39. int timer_init(void)
  40. {
  41. writew(readw(TMU_BASE + TCR0) & ~TCR_TPSC, TMU_BASE + TCR0);
  42. writeb(readb(TMU_BASE + TSTR) & ~TSTR_STR0, TMU_BASE + TSTR);
  43. writeb(readb(TMU_BASE + TSTR) | TSTR_STR0, TMU_BASE + TSTR);
  44. return 0;
  45. }