tpu.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * linux/arch/h8300/kernel/timer/tpu.c
  3. *
  4. * Yoshinori Sato <ysato@users.sourceforge.jp>
  5. *
  6. * TPU Timer Handler
  7. *
  8. */
  9. #include <linux/config.h>
  10. #include <linux/errno.h>
  11. #include <linux/sched.h>
  12. #include <linux/kernel.h>
  13. #include <linux/param.h>
  14. #include <linux/string.h>
  15. #include <linux/mm.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/init.h>
  18. #include <linux/timex.h>
  19. #include <asm/segment.h>
  20. #include <asm/io.h>
  21. #include <asm/irq.h>
  22. #include <asm/regs267x.h>
  23. /* TPU */
  24. #if CONFIG_H8300_TPU_CH == 0
  25. #define TPUBASE 0xffffd0
  26. #define TPUIRQ 40
  27. #elif CONFIG_H8300_TPU_CH == 1
  28. #define TPUBASE 0xffffe0
  29. #define TPUIRQ 48
  30. #elif CONFIG_H8300_TPU_CH == 2
  31. #define TPUBASE 0xfffff0
  32. #define TPUIRQ 52
  33. #elif CONFIG_H8300_TPU_CH == 3
  34. #define TPUBASE 0xfffe80
  35. #define TPUIRQ 56
  36. #elif CONFIG_H8300_TPU_CH == 4
  37. #define TPUBASE 0xfffe90
  38. #define TPUIRQ 64
  39. #else
  40. #error Unknown timer channel.
  41. #endif
  42. #define _TCR 0
  43. #define _TMDR 1
  44. #define _TIOR 2
  45. #define _TIER 4
  46. #define _TSR 5
  47. #define _TCNT 6
  48. #define _GRA 8
  49. #define _GRB 10
  50. #define CCLR0 0x20
  51. static irqreturn_t timer_interrupt(int irq, void *dev_id)
  52. {
  53. h8300_timer_tick();
  54. ctrl_bclr(0, TPUBASE + _TSR);
  55. return IRQ_HANDLED;
  56. }
  57. static struct irqaction tpu_irq = {
  58. .name = "tpu",
  59. .handler = timer_interrupt,
  60. .flags = IRQF_DISABLED | IRQF_TIMER,
  61. };
  62. static const int __initdata divide_rate[] = {
  63. #if CONFIG_H8300_TPU_CH == 0
  64. 1,4,16,64,0,0,0,0,
  65. #elif (CONFIG_H8300_TPU_CH == 1) || (CONFIG_H8300_TPU_CH == 5)
  66. 1,4,16,64,0,0,256,0,
  67. #elif (CONFIG_H8300_TPU_CH == 2) || (CONFIG_H8300_TPU_CH == 4)
  68. 1,4,16,64,0,0,0,1024,
  69. #elif CONFIG_H8300_TPU_CH == 3
  70. 1,4,16,64,0,1024,256,4096,
  71. #endif
  72. };
  73. void __init h8300_timer_setup(void)
  74. {
  75. unsigned int cnt;
  76. unsigned int div;
  77. calc_param(cnt, div, divide_rate, 0x10000);
  78. setup_irq(TPUIRQ, &tpu_irq);
  79. /* TPU module enabled */
  80. ctrl_bclr(3, MSTPCRH);
  81. ctrl_outb(0, TSTR);
  82. ctrl_outb(CCLR0 | div, TPUBASE + _TCR);
  83. ctrl_outb(0, TPUBASE + _TMDR);
  84. ctrl_outw(0, TPUBASE + _TIOR);
  85. ctrl_outb(0x01, TPUBASE + _TIER);
  86. ctrl_outw(cnt, TPUBASE + _GRA);
  87. ctrl_bset(CONFIG_H8300_TPU_CH, TSTR);
  88. }