time.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 <linux/irq.h>
  22. #include <linux/clocksource.h>
  23. #include <linux/io.h>
  24. #include <mach/hardware.h>
  25. #include <asm/mach/time.h>
  26. #include <mach/netx-regs.h>
  27. #define TIMER_CLOCKSOURCE 1
  28. /*
  29. * IRQ handler for the timer
  30. */
  31. static irqreturn_t
  32. netx_timer_interrupt(int irq, void *dev_id)
  33. {
  34. timer_tick();
  35. /* acknowledge interrupt */
  36. writel(COUNTER_BIT(0), NETX_GPIO_IRQ);
  37. return IRQ_HANDLED;
  38. }
  39. static struct irqaction netx_timer_irq = {
  40. .name = "NetX Timer Tick",
  41. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  42. .handler = netx_timer_interrupt,
  43. };
  44. cycle_t netx_get_cycles(void)
  45. {
  46. return readl(NETX_GPIO_COUNTER_CURRENT(TIMER_CLOCKSOURCE));
  47. }
  48. static struct clocksource clocksource_netx = {
  49. .name = "netx_timer",
  50. .rating = 200,
  51. .read = netx_get_cycles,
  52. .mask = CLOCKSOURCE_MASK(32),
  53. .shift = 20,
  54. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  55. };
  56. /*
  57. * Set up timer interrupt
  58. */
  59. static void __init netx_timer_init(void)
  60. {
  61. /* disable timer initially */
  62. writel(0, NETX_GPIO_COUNTER_CTRL(0));
  63. /* Reset the timer value to zero */
  64. writel(0, NETX_GPIO_COUNTER_CURRENT(0));
  65. writel(LATCH, NETX_GPIO_COUNTER_MAX(0));
  66. /* acknowledge interrupt */
  67. writel(COUNTER_BIT(0), NETX_GPIO_IRQ);
  68. /* Enable the interrupt in the specific timer
  69. * register and start timer
  70. */
  71. writel(COUNTER_BIT(0), NETX_GPIO_IRQ_ENABLE);
  72. writel(NETX_GPIO_COUNTER_CTRL_IRQ_EN | NETX_GPIO_COUNTER_CTRL_RUN,
  73. NETX_GPIO_COUNTER_CTRL(0));
  74. setup_irq(NETX_IRQ_TIMER0, &netx_timer_irq);
  75. /* Setup timer one for clocksource */
  76. writel(0, NETX_GPIO_COUNTER_CTRL(TIMER_CLOCKSOURCE));
  77. writel(0, NETX_GPIO_COUNTER_CURRENT(TIMER_CLOCKSOURCE));
  78. writel(0xffffffff, NETX_GPIO_COUNTER_MAX(TIMER_CLOCKSOURCE));
  79. writel(NETX_GPIO_COUNTER_CTRL_RUN,
  80. NETX_GPIO_COUNTER_CTRL(TIMER_CLOCKSOURCE));
  81. clocksource_netx.mult =
  82. clocksource_hz2mult(CLOCK_TICK_RATE, clocksource_netx.shift);
  83. clocksource_register(&clocksource_netx);
  84. }
  85. struct sys_timer netx_timer = {
  86. .init = netx_timer_init,
  87. };