timer.c 1.3 KB

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