time-acorn.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * linux/arch/arm/common/time-acorn.c
  3. *
  4. * Copyright (c) 1996-2000 Russell King.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * Changelog:
  11. * 24-Sep-1996 RMK Created
  12. * 10-Oct-1996 RMK Brought up to date with arch-sa110eval
  13. * 04-Dec-1997 RMK Updated for new arch/arm/time.c
  14. * 13=Jun-2004 DS Moved to arch/arm/common b/c shared w/CLPS7500
  15. */
  16. #include <linux/timex.h>
  17. #include <linux/init.h>
  18. #include <linux/interrupt.h>
  19. #include <asm/hardware.h>
  20. #include <asm/io.h>
  21. #include <asm/hardware/ioc.h>
  22. #include <asm/mach/time.h>
  23. unsigned long ioc_timer_gettimeoffset(void)
  24. {
  25. unsigned int count1, count2, status;
  26. long offset;
  27. ioc_writeb (0, IOC_T0LATCH);
  28. barrier ();
  29. count1 = ioc_readb(IOC_T0CNTL) | (ioc_readb(IOC_T0CNTH) << 8);
  30. barrier ();
  31. status = ioc_readb(IOC_IRQREQA);
  32. barrier ();
  33. ioc_writeb (0, IOC_T0LATCH);
  34. barrier ();
  35. count2 = ioc_readb(IOC_T0CNTL) | (ioc_readb(IOC_T0CNTH) << 8);
  36. offset = count2;
  37. if (count2 < count1) {
  38. /*
  39. * We have not had an interrupt between reading count1
  40. * and count2.
  41. */
  42. if (status & (1 << 5))
  43. offset -= LATCH;
  44. } else if (count2 > count1) {
  45. /*
  46. * We have just had another interrupt between reading
  47. * count1 and count2.
  48. */
  49. offset -= LATCH;
  50. }
  51. offset = (LATCH - offset) * (tick_nsec / 1000);
  52. return (offset + LATCH/2) / LATCH;
  53. }
  54. void __init ioctime_init(void)
  55. {
  56. ioc_writeb(LATCH & 255, IOC_T0LTCHL);
  57. ioc_writeb(LATCH >> 8, IOC_T0LTCHH);
  58. ioc_writeb(0, IOC_T0GO);
  59. }
  60. static irqreturn_t
  61. ioc_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  62. {
  63. write_seqlock(&xtime_lock);
  64. timer_tick(regs);
  65. write_sequnlock(&xtime_lock);
  66. return IRQ_HANDLED;
  67. }
  68. static struct irqaction ioc_timer_irq = {
  69. .name = "timer",
  70. .flags = SA_INTERRUPT,
  71. .handler = ioc_timer_interrupt
  72. };
  73. /*
  74. * Set up timer interrupt.
  75. */
  76. static void __init ioc_timer_init(void)
  77. {
  78. ioctime_init();
  79. setup_irq(IRQ_TIMER, &ioc_timer_irq);
  80. }
  81. struct sys_timer ioc_timer = {
  82. .init = ioc_timer_init,
  83. .offset = ioc_timer_gettimeoffset,
  84. };