2 * include/asm-arm/arch-ns9xxx/clock.h
4 * Copyright (C) 2007 by Digi International Inc.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
11 #ifndef __ASM_ARCH_CLOCK_H
12 #define __ASM_ARCH_CLOCK_H
14 #include <asm/arch-ns9xxx/regs-sys.h>
16 #define CRYSTAL 29491200 /* Hz */
18 /* The HRM calls this value f_vco */
19 static inline u32 ns9xxx_systemclock(void) __attribute__((const));
20 static inline u32 ns9xxx_systemclock(void)
22 u32 pll = __raw_readl(SYS_PLL);
25 * The system clock should be a multiple of HZ * TIMERCLOCKSELECT (in
28 * The following values are given:
29 * - TIMERCLOCKSELECT == 2^i for an i in {0 .. 6}
30 * - CRYSTAL == 29491200 == 2^17 * 3^2 * 5^2
34 * Assuming the worst, we consider:
35 * - TIMERCLOCKSELECT == 64
39 * So HZ should be a divisor of:
40 * (CRYSTAL * (ND + 1) >> FS) / TIMERCLOCKSELECT
41 * == (2^17 * 3^2 * 5^2 * 1 >> 3) / 64
45 * Currently HZ is defined to be 100 for this platform.
49 return CRYSTAL * (REGGETIM(pll, SYS_PLL, ND) + 1)
50 >> REGGETIM(pll, SYS_PLL, FS);
53 static inline u32 ns9xxx_cpuclock(void) __attribute__((const));
54 static inline u32 ns9xxx_cpuclock(void)
56 return ns9xxx_systemclock() / 2;
59 static inline u32 ns9xxx_ahbclock(void) __attribute__((const));
60 static inline u32 ns9xxx_ahbclock(void)
62 return ns9xxx_systemclock() / 4;
65 static inline u32 ns9xxx_bbusclock(void) __attribute__((const));
66 static inline u32 ns9xxx_bbusclock(void)
68 return ns9xxx_systemclock() / 8;
71 #endif /* ifndef __ASM_ARCH_CLOCK_H */