isa-timer.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * linux/arch/arm/mach-footbridge/isa-timer.c
  3. *
  4. * Copyright (C) 1998 Russell King.
  5. * Copyright (C) 1998 Phil Blundell
  6. */
  7. #include <linux/init.h>
  8. #include <linux/interrupt.h>
  9. #include <linux/irq.h>
  10. #include <linux/io.h>
  11. #include <asm/irq.h>
  12. #include <asm/mach/time.h>
  13. #include "common.h"
  14. /*
  15. * ISA timer tick support
  16. */
  17. #define mSEC_10_from_14 ((14318180 + 100) / 200)
  18. static unsigned long isa_gettimeoffset(void)
  19. {
  20. int count;
  21. static int count_p = (mSEC_10_from_14/6); /* for the first call after boot */
  22. static unsigned long jiffies_p = 0;
  23. /*
  24. * cache volatile jiffies temporarily; we have IRQs turned off.
  25. */
  26. unsigned long jiffies_t;
  27. /* timer count may underflow right here */
  28. outb_p(0x00, 0x43); /* latch the count ASAP */
  29. count = inb_p(0x40); /* read the latched count */
  30. /*
  31. * We do this guaranteed double memory access instead of a _p
  32. * postfix in the previous port access. Wheee, hackady hack
  33. */
  34. jiffies_t = jiffies;
  35. count |= inb_p(0x40) << 8;
  36. /* Detect timer underflows. If we haven't had a timer tick since
  37. the last time we were called, and time is apparently going
  38. backwards, the counter must have wrapped during this routine. */
  39. if ((jiffies_t == jiffies_p) && (count > count_p))
  40. count -= (mSEC_10_from_14/6);
  41. else
  42. jiffies_p = jiffies_t;
  43. count_p = count;
  44. count = (((mSEC_10_from_14/6)-1) - count) * (tick_nsec / 1000);
  45. count = (count + (mSEC_10_from_14/6)/2) / (mSEC_10_from_14/6);
  46. return count;
  47. }
  48. static irqreturn_t
  49. isa_timer_interrupt(int irq, void *dev_id)
  50. {
  51. timer_tick();
  52. return IRQ_HANDLED;
  53. }
  54. static struct irqaction isa_timer_irq = {
  55. .name = "ISA timer tick",
  56. .handler = isa_timer_interrupt,
  57. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  58. };
  59. static void __init isa_timer_init(void)
  60. {
  61. isa_rtc_init();
  62. /* enable PIT timer */
  63. /* set for periodic (4) and LSB/MSB write (0x30) */
  64. outb(0x34, 0x43);
  65. outb((mSEC_10_from_14/6) & 0xFF, 0x40);
  66. outb((mSEC_10_from_14/6) >> 8, 0x40);
  67. setup_irq(IRQ_ISA_TIMER, &isa_timer_irq);
  68. }
  69. struct sys_timer isa_timer = {
  70. .init = isa_timer_init,
  71. .offset = isa_gettimeoffset,
  72. };