timer.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2007-2008
  4. * Stelian Pop <stelian@popies.net>
  5. * Lead Tech Design <www.leadtechdesign.com>
  6. */
  7. #include <common.h>
  8. #include <init.h>
  9. #include <time.h>
  10. #include <asm/global_data.h>
  11. #include <asm/io.h>
  12. #include <asm/arch/hardware.h>
  13. #include <asm/arch/at91_pit.h>
  14. #include <asm/arch/clk.h>
  15. #include <div64.h>
  16. #if !defined(CONFIG_AT91FAMILY)
  17. # error You need to define CONFIG_AT91FAMILY in your board config!
  18. #endif
  19. DECLARE_GLOBAL_DATA_PTR;
  20. /*
  21. * We're using the AT91CAP9/SAM9 PITC in 32 bit mode, by
  22. * setting the 20 bit counter period to its maximum (0xfffff).
  23. * (See the relevant data sheets to understand that this really works)
  24. *
  25. * We do also mimic the typical powerpc way of incrementing
  26. * two 32 bit registers called tbl and tbu.
  27. *
  28. * Those registers increment at 1/16 the main clock rate.
  29. */
  30. #define TIMER_LOAD_VAL 0xfffff
  31. /*
  32. * Use the PITC in full 32 bit incrementing mode
  33. */
  34. int timer_init(void)
  35. {
  36. at91_pit_t *pit = (at91_pit_t *) ATMEL_BASE_PIT;
  37. at91_periph_clk_enable(ATMEL_ID_SYS);
  38. /* Enable PITC */
  39. writel(TIMER_LOAD_VAL | AT91_PIT_MR_EN , &pit->mr);
  40. gd->arch.timer_rate_hz = gd->arch.mck_rate_hz / 16;
  41. return 0;
  42. }
  43. /*
  44. * Return the number of timer ticks per second.
  45. */
  46. ulong get_tbclk(void)
  47. {
  48. return gd->arch.timer_rate_hz;
  49. }