timer.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * (C) Copyright 2003
  3. * Texas Instruments <www.ti.com>
  4. *
  5. * (C) Copyright 2002
  6. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  7. * Marius Groeger <mgroeger@sysgo.de>
  8. *
  9. * (C) Copyright 2002
  10. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  11. * Alex Zuepke <azu@sysgo.de>
  12. *
  13. * (C) Copyright 2002-2004
  14. * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
  15. *
  16. * (C) Copyright 2004
  17. * Philippe Robin, ARM Ltd. <philippe.robin@arm.com>
  18. *
  19. * SPDX-License-Identifier: GPL-2.0+
  20. */
  21. #include <common.h>
  22. #define TIMER_ENABLE (1 << 7)
  23. #define TIMER_MODE_MSK (1 << 6)
  24. #define TIMER_MODE_FR (0 << 6)
  25. #define TIMER_MODE_PD (1 << 6)
  26. #define TIMER_INT_EN (1 << 5)
  27. #define TIMER_PRS_MSK (3 << 2)
  28. #define TIMER_PRS_8S (1 << 3)
  29. #define TIMER_SIZE_MSK (1 << 2)
  30. #define TIMER_ONE_SHT (1 << 0)
  31. int timer_init (void)
  32. {
  33. ulong tmr_ctrl_val;
  34. /* 1st disable the Timer */
  35. tmr_ctrl_val = *(volatile ulong *)(CONFIG_SYS_TIMERBASE + 8);
  36. tmr_ctrl_val &= ~TIMER_ENABLE;
  37. *(volatile ulong *)(CONFIG_SYS_TIMERBASE + 8) = tmr_ctrl_val;
  38. /*
  39. * The Timer Control Register has one Undefined/Shouldn't Use Bit
  40. * So we should do read/modify/write Operation
  41. */
  42. /*
  43. * Timer Mode : Free Running
  44. * Interrupt : Disabled
  45. * Prescale : 8 Stage, Clk/256
  46. * Tmr Siz : 16 Bit Counter
  47. * Tmr in Wrapping Mode
  48. */
  49. tmr_ctrl_val = *(volatile ulong *)(CONFIG_SYS_TIMERBASE + 8);
  50. tmr_ctrl_val &= ~(TIMER_MODE_MSK | TIMER_INT_EN | TIMER_PRS_MSK | TIMER_SIZE_MSK | TIMER_ONE_SHT );
  51. tmr_ctrl_val |= (TIMER_ENABLE | TIMER_PRS_8S);
  52. *(volatile ulong *)(CONFIG_SYS_TIMERBASE + 8) = tmr_ctrl_val;
  53. return 0;
  54. }