time.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * linux/arch/arm/mach-nuc93x/time.c
  3. *
  4. * Copyright (c) 2009 Nuvoton technology corporation.
  5. *
  6. * Wan ZongShun <mcuos.com@gmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/sched.h>
  16. #include <linux/init.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/err.h>
  19. #include <linux/clk.h>
  20. #include <linux/io.h>
  21. #include <linux/leds.h>
  22. #include <asm/mach-types.h>
  23. #include <asm/mach/irq.h>
  24. #include <asm/mach/time.h>
  25. #include <mach/system.h>
  26. #include <mach/map.h>
  27. #include <mach/regs-timer.h>
  28. #define RESETINT 0x01
  29. #define PERIOD (0x01 << 27)
  30. #define ONESHOT (0x00 << 27)
  31. #define COUNTEN (0x01 << 30)
  32. #define INTEN (0x01 << 29)
  33. #define TICKS_PER_SEC 100
  34. #define PRESCALE 0x63 /* Divider = prescale + 1 */
  35. unsigned int timer0_load;
  36. static unsigned long nuc93x_gettimeoffset(void)
  37. {
  38. return 0;
  39. }
  40. /*IRQ handler for the timer*/
  41. static irqreturn_t nuc93x_timer_interrupt(int irq, void *dev_id)
  42. {
  43. timer_tick();
  44. __raw_writel(0x01, REG_TISR); /* clear TIF0 */
  45. return IRQ_HANDLED;
  46. }
  47. static struct irqaction nuc93x_timer_irq = {
  48. .name = "nuc93x Timer Tick",
  49. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  50. .handler = nuc93x_timer_interrupt,
  51. };
  52. /*Set up timer reg.*/
  53. static void nuc93x_timer_setup(void)
  54. {
  55. struct clk *ck_ext = clk_get(NULL, "ext");
  56. struct clk *ck_timer = clk_get(NULL, "timer");
  57. unsigned int rate, val = 0;
  58. BUG_ON(IS_ERR(ck_ext) || IS_ERR(ck_timer));
  59. clk_enable(ck_timer);
  60. rate = clk_get_rate(ck_ext);
  61. clk_put(ck_ext);
  62. rate = rate / (PRESCALE + 0x01);
  63. /* set a known state */
  64. __raw_writel(0x00, REG_TCSR0);
  65. __raw_writel(RESETINT, REG_TISR);
  66. timer0_load = (rate / TICKS_PER_SEC);
  67. __raw_writel(timer0_load, REG_TICR0);
  68. val |= (PERIOD | COUNTEN | INTEN | PRESCALE);;
  69. __raw_writel(val, REG_TCSR0);
  70. }
  71. static void __init nuc93x_timer_init(void)
  72. {
  73. nuc93x_timer_setup();
  74. setup_irq(IRQ_TIMER0, &nuc93x_timer_irq);
  75. }
  76. struct sys_timer nuc93x_timer = {
  77. .init = nuc93x_timer_init,
  78. .offset = nuc93x_gettimeoffset,
  79. .resume = nuc93x_timer_setup
  80. };