time.c 998 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #include <sh_tmu.h>
  16. #define TCR_TPSC 0x07
  17. static struct tmu_regs *tmu = (struct tmu_regs *)TMU_BASE;
  18. unsigned long get_tbclk(void)
  19. {
  20. return get_tmu0_clk_rate() >> 2;
  21. }
  22. unsigned long timer_read_counter(void)
  23. {
  24. return ~readl(&tmu->tcnt0);
  25. }
  26. static void tmu_timer_start(unsigned int timer)
  27. {
  28. if (timer > 2)
  29. return;
  30. writeb(readb(&tmu->tstr) | (1 << timer), &tmu->tstr);
  31. }
  32. static void tmu_timer_stop(unsigned int timer)
  33. {
  34. if (timer > 2)
  35. return;
  36. writeb(readb(&tmu->tstr) & ~(1 << timer), &tmu->tstr);
  37. }
  38. int timer_init(void)
  39. {
  40. writew(readw(&tmu->tcr0) & ~TCR_TPSC, &tmu->tcr0);
  41. tmu_timer_stop(0);
  42. tmu_timer_start(0);
  43. return 0;
  44. }