timer.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2002
  4. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  5. * Marius Groeger <mgroeger@sysgo.de>
  6. *
  7. * (C) Copyright 2002
  8. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  9. * Alex Zuepke <azu@sysgo.de>
  10. *
  11. * (C) Copyright 2002
  12. * Gary Jennejohn, DENX Software Engineering, <gj@denx.de>
  13. *
  14. * (C) Copyright 2009
  15. * Ilya Yanok, Emcraft Systems Ltd, <yanok@emcraft.com>
  16. *
  17. * (C) Copyright 2009 DENX Software Engineering
  18. * Author: John Rigby <jrigby@gmail.com>
  19. * Add support for MX25
  20. */
  21. #include <common.h>
  22. #include <asm/io.h>
  23. #include <asm/arch/imx-regs.h>
  24. /* nothing really to do with interrupts, just starts up a counter. */
  25. /* The 32KHz 32-bit timer overruns in 134217 seconds */
  26. int timer_init(void)
  27. {
  28. int i;
  29. struct gpt_regs *gpt = (struct gpt_regs *)IMX_GPT1_BASE;
  30. struct ccm_regs *ccm = (struct ccm_regs *)IMX_CCM_BASE;
  31. /* setup GP Timer 1 */
  32. writel(GPT_CTRL_SWR, &gpt->ctrl);
  33. writel(readl(&ccm->cgr1) | CCM_CGR1_GPT1, &ccm->cgr1);
  34. for (i = 0; i < 100; i++)
  35. writel(0, &gpt->ctrl); /* We have no udelay by now */
  36. writel(0, &gpt->pre); /* prescaler = 1 */
  37. /* Freerun Mode, 32KHz input */
  38. writel(readl(&gpt->ctrl) | GPT_CTRL_CLKSOURCE_32 | GPT_CTRL_FRR,
  39. &gpt->ctrl);
  40. writel(readl(&gpt->ctrl) | GPT_CTRL_TEN, &gpt->ctrl);
  41. return 0;
  42. }