time-acorn.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 <linux/irq.h>
  20. #include <asm/hardware.h>
  21. #include <asm/io.h>
  22. #include <asm/hardware/ioc.h>
  23. #include <asm/mach/time.h>
  24. unsigned long ioc_timer_gettimeoffset(void)
  25. {
  26. unsigned int count1, count2, status;
  27. long offset;
  28. ioc_writeb (0, IOC_T0LATCH);
  29. barrier ();
  30. count1 = ioc_readb(IOC_T0CNTL) | (ioc_readb(IOC_T0CNTH) << 8);
  31. barrier ();
  32. status = ioc_readb(IOC_IRQREQA);
  33. barrier ();
  34. ioc_writeb (0, IOC_T0LATCH);
  35. barrier ();
  36. count2 = ioc_readb(IOC_T0CNTL) | (ioc_readb(IOC_T0CNTH) << 8);
  37. offset = count2;
  38. if (count2 < count1) {
  39. /*
  40. * We have not had an interrupt between reading count1
  41. * and count2.
  42. */
  43. if (status & (1 << 5))
  44. offset -= LATCH;
  45. } else if (count2 > count1) {
  46. /*
  47. * We have just had another interrupt between reading
  48. * count1 and count2.
  49. */
  50. offset -= LATCH;
  51. }
  52. offset = (LATCH - offset) * (tick_nsec / 1000);
  53. return (offset + LATCH/2) / LATCH;
  54. }
  55. void __init ioctime_init(void)
  56. {
  57. ioc_writeb(LATCH & 255, IOC_T0LTCHL);
  58. ioc_writeb(LATCH >> 8, IOC_T0LTCHH);
  59. ioc_writeb(0, IOC_T0GO);
  60. }
  61. static irqreturn_t
  62. ioc_timer_interrupt(int irq, void *dev_id)
  63. {
  64. write_seqlock(&xtime_lock);
  65. timer_tick();
  66. write_sequnlock(&xtime_lock);
  67. return IRQ_HANDLED;
  68. }
  69. static struct irqaction ioc_timer_irq = {
  70. .name = "timer",
  71. .flags = IRQF_DISABLED,
  72. .handler = ioc_timer_interrupt
  73. };
  74. /*
  75. * Set up timer interrupt.
  76. */
  77. static void __init ioc_timer_init(void)
  78. {
  79. ioctime_init();
  80. setup_irq(IRQ_TIMER, &ioc_timer_irq);
  81. }
  82. struct sys_timer ioc_timer = {
  83. .init = ioc_timer_init,
  84. .offset = ioc_timer_gettimeoffset,
  85. };