time.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * arch/arm/mach-netx/time.c
  3. *
  4. * Copyright (c) 2005 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
  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
  8. * as 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/init.h>
  20. #include <linux/interrupt.h>
  21. #include <asm/hardware.h>
  22. #include <asm/io.h>
  23. #include <asm/mach/time.h>
  24. #include <asm/arch/netx-regs.h>
  25. /*
  26. * Returns number of us since last clock interrupt. Note that interrupts
  27. * will have been disabled by do_gettimeoffset()
  28. */
  29. static unsigned long netx_gettimeoffset(void)
  30. {
  31. return readl(NETX_GPIO_COUNTER_CURRENT(0)) / 100;
  32. }
  33. /*
  34. * IRQ handler for the timer
  35. */
  36. static irqreturn_t
  37. netx_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  38. {
  39. write_seqlock(&xtime_lock);
  40. timer_tick(regs);
  41. write_sequnlock(&xtime_lock);
  42. /* acknowledge interrupt */
  43. writel(COUNTER_BIT(0), NETX_GPIO_IRQ);
  44. return IRQ_HANDLED;
  45. }
  46. static struct irqaction netx_timer_irq = {
  47. .name = "NetX Timer Tick",
  48. .flags = IRQF_DISABLED | IRQF_TIMER,
  49. .handler = netx_timer_interrupt,
  50. };
  51. /*
  52. * Set up timer interrupt
  53. */
  54. static void __init netx_timer_init(void)
  55. {
  56. /* disable timer initially */
  57. writel(0, NETX_GPIO_COUNTER_CTRL(0));
  58. /* Reset the timer value to zero */
  59. writel(0, NETX_GPIO_COUNTER_CURRENT(0));
  60. writel(LATCH, NETX_GPIO_COUNTER_MAX(0));
  61. /* acknowledge interrupt */
  62. writel(COUNTER_BIT(0), NETX_GPIO_IRQ);
  63. /* Enable the interrupt in the specific timer register and start timer */
  64. writel(COUNTER_BIT(0), NETX_GPIO_IRQ_ENABLE);
  65. writel(NETX_GPIO_COUNTER_CTRL_IRQ_EN | NETX_GPIO_COUNTER_CTRL_RUN,
  66. NETX_GPIO_COUNTER_CTRL(0));
  67. setup_irq(NETX_IRQ_TIMER0, &netx_timer_irq);
  68. }
  69. struct sys_timer netx_timer = {
  70. .init = netx_timer_init,
  71. .offset = netx_gettimeoffset,
  72. };