v850e_timer_d.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * include/asm-v850/v850e_timer_d.c -- `Timer D' component often used
  3. * with V850E CPUs
  4. *
  5. * Copyright (C) 2001,02,03 NEC Electronics Corporation
  6. * Copyright (C) 2001,02,03 Miles Bader <miles@gnu.org>
  7. *
  8. * This file is subject to the terms and conditions of the GNU General
  9. * Public License. See the file COPYING in the main directory of this
  10. * archive for more details.
  11. *
  12. * Written by Miles Bader <miles@gnu.org>
  13. */
  14. #include <linux/kernel.h>
  15. #include <asm/v850e_utils.h>
  16. #include <asm/v850e_timer_d.h>
  17. /* Start interval timer TIMER (0-3). The timer will issue the
  18. corresponding INTCMD interrupt RATE times per second.
  19. This function does not enable the interrupt. */
  20. void v850e_timer_d_configure (unsigned timer, unsigned rate)
  21. {
  22. unsigned divlog2, count;
  23. /* Calculate params for timer. */
  24. if (! calc_counter_params (
  25. V850E_TIMER_D_BASE_FREQ, rate,
  26. V850E_TIMER_D_TMCD_CS_MIN, V850E_TIMER_D_TMCD_CS_MAX, 16,
  27. &divlog2, &count))
  28. printk (KERN_WARNING
  29. "Cannot find interval timer %d setting suitable"
  30. " for rate of %dHz.\n"
  31. "Using rate of %dHz instead.\n",
  32. timer, rate,
  33. (V850E_TIMER_D_BASE_FREQ >> divlog2) >> 16);
  34. /* Do the actual hardware timer initialization: */
  35. /* Enable timer. */
  36. V850E_TIMER_D_TMCD(timer) = V850E_TIMER_D_TMCD_CAE;
  37. /* Set clock divider. */
  38. V850E_TIMER_D_TMCD(timer)
  39. = V850E_TIMER_D_TMCD_CAE
  40. | V850E_TIMER_D_TMCD_CS(divlog2);
  41. /* Set timer compare register. */
  42. V850E_TIMER_D_CMD(timer) = count;
  43. /* Start counting. */
  44. V850E_TIMER_D_TMCD(timer)
  45. = V850E_TIMER_D_TMCD_CAE
  46. | V850E_TIMER_D_TMCD_CS(divlog2)
  47. | V850E_TIMER_D_TMCD_CE;
  48. }