diff --git a/arch/arm/mach-at91/at91sam926x_time.c b/arch/arm/mach-at91/at91sam926x_time.c index 5c090c9..39e2c73 100644 --- a/arch/arm/mach-at91/at91sam926x_time.c +++ b/arch/arm/mach-at91/at91sam926x_time.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -26,6 +27,9 @@ #define PIT_CPIV(x) ((x) & AT91_PIT_CPIV) #define PIT_PICNT(x) (((x) & AT91_PIT_PICNT) >> 20) +/* precalculated PIV */ +int piv; + /* * Returns number of microseconds since last timer interrupt. Note that interrupts * will have been disabled by do_gettimeofday() @@ -79,7 +83,7 @@ void at91sam926x_timer_reset(void) (void) at91_sys_read(AT91_PIT_PIVR); /* Set Period Interval timer and enable its interrupt */ - at91_sys_write(AT91_PIT_MR, (LATCH & AT91_PIT_PIV) | AT91_PIT_PITIEN | AT91_PIT_PITEN); + at91_sys_write(AT91_PIT_MR, (piv & AT91_PIT_PIV) | AT91_PIT_PITIEN | AT91_PIT_PITEN); } /* @@ -87,6 +91,16 @@ void at91sam926x_timer_reset(void) */ void __init at91sam926x_timer_init(void) { + struct clk *mck; + u64 temp; + + /* Precalculate PIV according to MCK */ + mck = clk_get(0, "mck"); + temp = clk_get_rate(mck); + temp *= LATCH; + do_div(temp, CLOCK_TICK_RATE * 16); + piv = temp; + /* Initialize and enable the timer */ at91sam926x_timer_reset();