pit.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /***************************************************************************/
  2. /*
  3. * pit.c -- Freescale ColdFire PIT timer. Currently this type of
  4. * hardware timer only exists in the Freescale ColdFire
  5. * 5270/5271, 5282 and 5208 CPUs. No doubt newer ColdFire
  6. * family members will probably use it too.
  7. *
  8. * Copyright (C) 1999-2008, Greg Ungerer (gerg@snapgear.com)
  9. * Copyright (C) 2001-2004, SnapGear Inc. (www.snapgear.com)
  10. */
  11. /***************************************************************************/
  12. #include <linux/kernel.h>
  13. #include <linux/sched.h>
  14. #include <linux/param.h>
  15. #include <linux/init.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/irq.h>
  18. #include <linux/clocksource.h>
  19. #include <asm/machdep.h>
  20. #include <asm/io.h>
  21. #include <asm/coldfire.h>
  22. #include <asm/mcfpit.h>
  23. #include <asm/mcfsim.h>
  24. /***************************************************************************/
  25. /*
  26. * By default use timer1 as the system clock timer.
  27. */
  28. #define FREQ ((MCF_CLK / 2) / 64)
  29. #define TA(a) (MCF_IPSBAR + MCFPIT_BASE1 + (a))
  30. #define INTC0 (MCF_IPSBAR + MCFICM_INTC0)
  31. static u32 pit_cycles_per_jiffy;
  32. static u32 pit_cnt;
  33. /***************************************************************************/
  34. static irqreturn_t pit_tick(int irq, void *dummy)
  35. {
  36. u16 pcsr;
  37. /* Reset the ColdFire timer */
  38. pcsr = __raw_readw(TA(MCFPIT_PCSR));
  39. __raw_writew(pcsr | MCFPIT_PCSR_PIF, TA(MCFPIT_PCSR));
  40. pit_cnt += pit_cycles_per_jiffy;
  41. return arch_timer_interrupt(irq, dummy);
  42. }
  43. /***************************************************************************/
  44. static struct irqaction pit_irq = {
  45. .name = "timer",
  46. .flags = IRQF_DISABLED | IRQF_TIMER,
  47. .handler = pit_tick,
  48. };
  49. /***************************************************************************/
  50. static cycle_t pit_read_clk(void)
  51. {
  52. unsigned long flags;
  53. u32 cycles;
  54. u16 pcntr;
  55. local_irq_save(flags);
  56. pcntr = __raw_readw(TA(MCFPIT_PCNTR));
  57. cycles = pit_cnt;
  58. local_irq_restore(flags);
  59. return cycles + pit_cycles_per_jiffy - pcntr;
  60. }
  61. /***************************************************************************/
  62. static struct clocksource pit_clk = {
  63. .name = "pit",
  64. .rating = 250,
  65. .read = pit_read_clk,
  66. .shift = 20,
  67. .mask = CLOCKSOURCE_MASK(32),
  68. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  69. };
  70. /***************************************************************************/
  71. void hw_timer_init(void)
  72. {
  73. u32 imr;
  74. setup_irq(MCFINT_VECBASE + MCFINT_PIT1, &pit_irq);
  75. __raw_writeb(ICR_INTRCONF, INTC0 + MCFINTC_ICR0 + MCFINT_PIT1);
  76. imr = __raw_readl(INTC0 + MCFPIT_IMR);
  77. imr &= ~MCFPIT_IMR_IBIT;
  78. __raw_writel(imr, INTC0 + MCFPIT_IMR);
  79. /* Set up PIT timer 1 as poll clock */
  80. pit_cycles_per_jiffy = FREQ / HZ;
  81. __raw_writew(MCFPIT_PCSR_DISABLE, TA(MCFPIT_PCSR));
  82. __raw_writew(pit_cycles_per_jiffy, TA(MCFPIT_PMR));
  83. __raw_writew(MCFPIT_PCSR_EN | MCFPIT_PCSR_PIE | MCFPIT_PCSR_OVW |
  84. MCFPIT_PCSR_RLD | MCFPIT_PCSR_CLK64, TA(MCFPIT_PCSR));
  85. pit_clk.mult = clocksource_hz2mult(FREQ, pit_clk.shift);
  86. clocksource_register(&pit_clk);
  87. }
  88. /***************************************************************************/