time.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * (C) Copyright 2009
  3. * Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
  4. *
  5. * (C) Copyright 2007-2012
  6. * Nobobuhiro Iwamatsu <iwamatsu@nigauri.org>
  7. *
  8. * (C) Copyright 2003
  9. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  10. *
  11. * SPDX-License-Identifier: GPL-2.0+
  12. */
  13. #include <common.h>
  14. #include <asm/processor.h>
  15. #include <asm/io.h>
  16. #include <sh_tmu.h>
  17. #define TCR_TPSC 0x07
  18. static struct tmu_regs *tmu = (struct tmu_regs *)TMU_BASE;
  19. unsigned long get_tbclk(void)
  20. {
  21. u16 tmu_bit = (ffs(CONFIG_SYS_TMU_CLK_DIV) >> 1) - 1;
  22. return get_tmu0_clk_rate() >> ((tmu_bit + 1) * 2);
  23. }
  24. unsigned long timer_read_counter(void)
  25. {
  26. return ~readl(&tmu->tcnt0);
  27. }
  28. static void tmu_timer_start(unsigned int timer)
  29. {
  30. if (timer > 2)
  31. return;
  32. writeb(readb(&tmu->tstr) | (1 << timer), &tmu->tstr);
  33. }
  34. static void tmu_timer_stop(unsigned int timer)
  35. {
  36. if (timer > 2)
  37. return;
  38. writeb(readb(&tmu->tstr) & ~(1 << timer), &tmu->tstr);
  39. }
  40. int timer_init(void)
  41. {
  42. u16 tmu_bit = (ffs(CONFIG_SYS_TMU_CLK_DIV) >> 1) - 1;
  43. writew((readw(&tmu->tcr0) & ~TCR_TPSC) | tmu_bit, &tmu->tcr0);
  44. tmu_timer_stop(0);
  45. tmu_timer_start(0);
  46. return 0;
  47. }