time.c 2.1 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/irq.h>
  23. #include <linux/sched.h>
  24. #include <linux/io.h>
  25. #include <mach/hardware.h>
  26. #include <asm/irq.h>
  27. #include <asm/leds.h>
  28. #include <asm/hardware/clps7111.h>
  29. #include <asm/mach/time.h>
  30. /*
  31. * gettimeoffset() returns time since last timer tick, in usecs.
  32. *
  33. * 'LATCH' is hwclock ticks (see CLOCK_TICK_RATE in timex.h) per jiffy.
  34. * 'tick' is usecs per jiffy.
  35. */
  36. static unsigned long clps711x_gettimeoffset(void)
  37. {
  38. unsigned long hwticks;
  39. hwticks = LATCH - (clps_readl(TC2D) & 0xffff); /* since last underflow */
  40. return (hwticks * (tick_nsec / 1000)) / LATCH;
  41. }
  42. /*
  43. * IRQ handler for the timer
  44. */
  45. static irqreturn_t
  46. p720t_timer_interrupt(int irq, void *dev_id)
  47. {
  48. timer_tick();
  49. return IRQ_HANDLED;
  50. }
  51. static struct irqaction clps711x_timer_irq = {
  52. .name = "CLPS711x Timer Tick",
  53. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  54. .handler = p720t_timer_interrupt,
  55. };
  56. static void __init clps711x_timer_init(void)
  57. {
  58. struct timespec tv;
  59. unsigned int syscon;
  60. syscon = clps_readl(SYSCON1);
  61. syscon |= SYSCON1_TC2S | SYSCON1_TC2M;
  62. clps_writel(syscon, SYSCON1);
  63. clps_writel(LATCH-1, TC2D); /* 512kHz / 100Hz - 1 */
  64. setup_irq(IRQ_TC2OI, &clps711x_timer_irq);
  65. tv.tv_nsec = 0;
  66. tv.tv_sec = clps_readl(RTCDR);
  67. do_settimeofday(&tv);
  68. }
  69. struct sys_timer clps711x_timer = {
  70. .init = clps711x_timer_init,
  71. .offset = clps711x_gettimeoffset,
  72. };