isa-timer.c 2.1 KB

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