timer16.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * linux/arch/h8300/kernel/timer/timer16.c
  3. *
  4. * Yoshinori Sato <ysato@users.sourcefoge.jp>
  5. *
  6. * 16bit Timer Handler
  7. *
  8. */
  9. #include <linux/errno.h>
  10. #include <linux/sched.h>
  11. #include <linux/kernel.h>
  12. #include <linux/param.h>
  13. #include <linux/string.h>
  14. #include <linux/mm.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/init.h>
  17. #include <linux/timex.h>
  18. #include <asm/segment.h>
  19. #include <asm/io.h>
  20. #include <asm/irq.h>
  21. #include <asm/regs306x.h>
  22. /* 16bit timer */
  23. #if CONFIG_H8300_TIMER16_CH == 0
  24. #define _16BASE 0xffff78
  25. #define _16IRQ 24
  26. #elif CONFIG_H8300_TIMER16_CH == 1
  27. #define _16BASE 0xffff80
  28. #define _16IRQ 28
  29. #elif CONFIG_H8300_TIMER16_CH == 2
  30. #define _16BASE 0xffff88
  31. #define _16IRQ 32
  32. #else
  33. #error Unknown timer channel.
  34. #endif
  35. #define TCR 0
  36. #define TIOR 1
  37. #define TCNT 2
  38. #define GRA 4
  39. #define GRB 6
  40. #define H8300_TIMER_FREQ CONFIG_CPU_CLOCK*10000 /* Timer input freq. */
  41. static irqreturn_t timer_interrupt(int irq, void *dev_id)
  42. {
  43. h8300_timer_tick();
  44. ctrl_bclr(CONFIG_H8300_TIMER16_CH, TISRA);
  45. return IRQ_HANDLED;
  46. }
  47. static struct irqaction timer16_irq = {
  48. .name = "timer-16",
  49. .handler = timer_interrupt,
  50. .flags = IRQF_DISABLED | IRQF_TIMER,
  51. };
  52. static const int __initdata divide_rate[] = {1, 2, 4, 8};
  53. void __init h8300_timer_setup(void)
  54. {
  55. unsigned int div;
  56. unsigned int cnt;
  57. calc_param(cnt, div, divide_rate, 0x10000);
  58. setup_irq(_16IRQ, &timer16_irq);
  59. /* initalize timer */
  60. ctrl_outb(0, TSTR);
  61. ctrl_outb(CCLR0 | div, _16BASE + TCR);
  62. ctrl_outw(cnt, _16BASE + GRA);
  63. ctrl_bset(4 + CONFIG_H8300_TIMER16_CH, TISRA);
  64. ctrl_bset(CONFIG_H8300_TIMER16_CH, TSTR);
  65. }