isa-timer.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 <asm/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. write_seqlock(&xtime_lock);
  52. timer_tick();
  53. write_sequnlock(&xtime_lock);
  54. return IRQ_HANDLED;
  55. }
  56. static struct irqaction isa_timer_irq = {
  57. .name = "ISA timer tick",
  58. .handler = isa_timer_interrupt,
  59. .flags = IRQF_DISABLED | IRQF_TIMER,
  60. };
  61. static void __init isa_timer_init(void)
  62. {
  63. isa_rtc_init();
  64. /* enable PIT timer */
  65. /* set for periodic (4) and LSB/MSB write (0x30) */
  66. outb(0x34, 0x43);
  67. outb((mSEC_10_from_14/6) & 0xFF, 0x40);
  68. outb((mSEC_10_from_14/6) >> 8, 0x40);
  69. setup_irq(IRQ_ISA_TIMER, &isa_timer_irq);
  70. }
  71. struct sys_timer isa_timer = {
  72. .init = isa_timer_init,
  73. .offset = isa_gettimeoffset,
  74. };