timer8.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * linux/arch/h8300/kernel/cpu/timer/timer8.c
  3. *
  4. * Yoshinori Sato <ysato@users.sourcefoge.jp>
  5. *
  6. * 8bit 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/profile.h>
  18. #include <asm/io.h>
  19. #include <asm/irq.h>
  20. #include <asm/timer.h>
  21. #if defined(CONFIG_CPU_H8300H)
  22. #include <asm/regs306x.h>
  23. #endif
  24. #if defined(CONFIG_CPU_H8S)
  25. #include <asm/regs267x.h>
  26. #endif
  27. /* 8bit timer x2 */
  28. #define CMFA 6
  29. #if defined(CONFIG_H8300_TIMER8_CH0)
  30. #define _8BASE _8TCR0
  31. #ifdef CONFIG_CPU_H8300H
  32. #define _8IRQ 36
  33. #endif
  34. #ifdef CONFIG_CPU_H8S
  35. #define _8IRQ 72
  36. #endif
  37. #elif defined(CONFIG_H8300_TIMER8_CH2)
  38. #ifdef CONFIG_CPU_H8300H
  39. #define _8BASE _8TCR2
  40. #define _8IRQ 40
  41. #endif
  42. #endif
  43. #ifndef _8BASE
  44. #error Unknown timer channel.
  45. #endif
  46. #define _8TCR 0
  47. #define _8TCSR 2
  48. #define TCORA 4
  49. #define TCORB 6
  50. #define _8TCNT 8
  51. #define CMIEA 0x40
  52. #define CCLR_CMA 0x08
  53. #define CKS2 0x04
  54. /*
  55. * timer_interrupt() needs to keep up the real-time clock,
  56. * as well as call the "do_timer()" routine every clocktick
  57. */
  58. static irqreturn_t timer_interrupt(int irq, void *dev_id)
  59. {
  60. h8300_timer_tick();
  61. ctrl_bclr(CMFA, _8BASE + _8TCSR);
  62. return IRQ_HANDLED;
  63. }
  64. static struct irqaction timer8_irq = {
  65. .name = "timer-8",
  66. .handler = timer_interrupt,
  67. .flags = IRQF_DISABLED | IRQF_TIMER,
  68. };
  69. static const int __initdata divide_rate[] = {8, 64, 8192};
  70. void __init h8300_timer_setup(void)
  71. {
  72. unsigned int div;
  73. unsigned int cnt;
  74. calc_param(cnt, div, divide_rate, 0x10000);
  75. div++;
  76. setup_irq(_8IRQ, &timer8_irq);
  77. #if defined(CONFIG_CPU_H8S)
  78. /* Timer module enable */
  79. ctrl_bclr(0, MSTPCRL)
  80. #endif
  81. /* initalize timer */
  82. ctrl_outw(cnt, _8BASE + TCORA);
  83. ctrl_outw(0x0000, _8BASE + _8TCSR);
  84. ctrl_outw((CMIEA|CCLR_CMA|CKS2) << 8 | div,
  85. _8BASE + _8TCR);
  86. }