time.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * linux/arch/arm/mach-clps711x/time.c
  3. *
  4. * Copyright (C) 2001 Deep Blue Solutions Ltd.
  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. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <linux/timex.h>
  20. #include <linux/init.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/sched.h>
  23. #include <asm/hardware.h>
  24. #include <asm/irq.h>
  25. #include <asm/leds.h>
  26. #include <asm/io.h>
  27. #include <asm/hardware/clps7111.h>
  28. #include <asm/mach/time.h>
  29. /*
  30. * gettimeoffset() returns time since last timer tick, in usecs.
  31. *
  32. * 'LATCH' is hwclock ticks (see CLOCK_TICK_RATE in timex.h) per jiffy.
  33. * 'tick' is usecs per jiffy.
  34. */
  35. static unsigned long clps711x_gettimeoffset(void)
  36. {
  37. unsigned long hwticks;
  38. hwticks = LATCH - (clps_readl(TC2D) & 0xffff); /* since last underflow */
  39. return (hwticks * (tick_nsec / 1000)) / LATCH;
  40. }
  41. /*
  42. * IRQ handler for the timer
  43. */
  44. static irqreturn_t
  45. p720t_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  46. {
  47. write_seqlock(&xtime_lock);
  48. timer_tick(regs);
  49. write_sequnlock(&xtime_lock);
  50. return IRQ_HANDLED;
  51. }
  52. static struct irqaction clps711x_timer_irq = {
  53. .name = "CLPS711x Timer Tick",
  54. .flags = SA_INTERRUPT | SA_TIMER,
  55. .handler = p720t_timer_interrupt,
  56. };
  57. static void __init clps711x_timer_init(void)
  58. {
  59. struct timespec tv;
  60. unsigned int syscon;
  61. syscon = clps_readl(SYSCON1);
  62. syscon |= SYSCON1_TC2S | SYSCON1_TC2M;
  63. clps_writel(syscon, SYSCON1);
  64. clps_writel(LATCH-1, TC2D); /* 512kHz / 100Hz - 1 */
  65. setup_irq(IRQ_TC2OI, &clps711x_timer_irq);
  66. tv.tv_nsec = 0;
  67. tv.tv_sec = clps_readl(RTCDR);
  68. do_settimeofday(&tv);
  69. }
  70. struct sys_timer clps711x_timer = {
  71. .init = clps711x_timer_init,
  72. .offset = clps711x_gettimeoffset,
  73. };