time-acorn.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:2k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  *  linux/arch/arm/kernel/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.  */
  15. #include <linux/sched.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/init.h>
  18. #include <asm/hardware.h>
  19. #include <asm/io.h>
  20. #include <asm/irq.h>
  21. #include <asm/hardware/ioc.h>
  22. extern unsigned long (*gettimeoffset)(void);
  23. static unsigned long ioctime_gettimeoffset(void)
  24. {
  25. unsigned int count1, count2, status1, status2;
  26. unsigned long offset = 0;
  27. status1 = ioc_readb(IOC_IRQREQA);
  28. barrier ();
  29. ioc_writeb (0, IOC_T0LATCH);
  30. barrier ();
  31. count1 = ioc_readb(IOC_T0CNTL) | (ioc_readb(IOC_T0CNTH) << 8);
  32. barrier ();
  33. status2 = ioc_readb(IOC_IRQREQA);
  34. barrier ();
  35. ioc_writeb (0, IOC_T0LATCH);
  36. barrier ();
  37. count2 = ioc_readb(IOC_T0CNTL) | (ioc_readb(IOC_T0CNTH) << 8);
  38. if (count2 < count1) {
  39. /*
  40.  * This means that we haven't just had an interrupt
  41.  * while reading into status2.
  42.  */
  43. if (status2 & (1 << 5))
  44. offset = tick;
  45. count1 = count2;
  46. } else if (count2 > count1) {
  47. /*
  48.  * We have just had another interrupt while reading
  49.  * status2.
  50.  */
  51. offset += tick;
  52. count1 = count2;
  53. }
  54. count1 = LATCH - count1;
  55. /*
  56.  * count1 = number of clock ticks since last interrupt
  57.  */
  58. offset += count1 * tick / LATCH;
  59. return offset;
  60. }
  61. void __init ioctime_init(void)
  62. {
  63. ioc_writeb(LATCH & 255, IOC_T0LTCHL);
  64. ioc_writeb(LATCH >> 8, IOC_T0LTCHH);
  65. ioc_writeb(0, IOC_T0GO);
  66. gettimeoffset = ioctime_gettimeoffset;
  67. }