timer.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2007
  4. * Sascha Hauer, Pengutronix
  5. *
  6. * (C) Copyright 2008-2009 Freescale Semiconductor, Inc.
  7. */
  8. #include <common.h>
  9. #include <init.h>
  10. #include <asm/io.h>
  11. #include <asm/arch/imx-regs.h>
  12. #include <asm/arch/crm_regs.h>
  13. #include <asm/ptrace.h>
  14. /* General purpose timers bitfields */
  15. #define GPTCR_SWR (1<<15) /* Software reset */
  16. #define GPTCR_FRR (1<<9) /* Freerun / restart */
  17. #define GPTCR_CLKSOURCE_32 (4<<6) /* Clock source */
  18. #define GPTCR_TEN (1) /* Timer enable */
  19. /*
  20. * nothing really to do with interrupts, just starts up a counter.
  21. * The 32KHz 32-bit timer overruns in 134217 seconds
  22. */
  23. int timer_init(void)
  24. {
  25. int i;
  26. struct gpt_regs *gpt = (struct gpt_regs *)GPT1_BASE_ADDR;
  27. struct ccm_regs *ccm = (struct ccm_regs *)CCM_BASE_ADDR;
  28. /* setup GP Timer 1 */
  29. writel(GPTCR_SWR, &gpt->ctrl);
  30. writel(readl(&ccm->cgr1) | 3 << MXC_CCM_CGR1_GPT_OFFSET, &ccm->cgr1);
  31. for (i = 0; i < 100; i++)
  32. writel(0, &gpt->ctrl); /* We have no udelay by now */
  33. writel(0, &gpt->pre); /* prescaler = 1 */
  34. /* Freerun Mode, 32KHz input */
  35. writel(readl(&gpt->ctrl) | GPTCR_CLKSOURCE_32 | GPTCR_FRR,
  36. &gpt->ctrl);
  37. writel(readl(&gpt->ctrl) | GPTCR_TEN, &gpt->ctrl);
  38. return 0;
  39. }