blob: bf30cbdcc2bf2d3ec47a7a5fd519015a7c77b931 [file] [log] [blame]
Uwe Kleine-König9918cda2007-02-16 15:36:55 +01001/*
2 * include/asm-arm/arch-ns9xxx/clock.h
3 *
4 * Copyright (C) 2007 by Digi International Inc.
5 * All rights reserved.
6 *
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.
10 */
11#ifndef __ASM_ARCH_CLOCK_H
12#define __ASM_ARCH_CLOCK_H
13
Uwe Kleine-Königf86bd612007-03-28 18:06:41 +010014#include <asm/arch-ns9xxx/regs-sys.h>
15
16#define CRYSTAL 29491200 /* Hz */
17
18/* The HRM calls this value f_vco */
Uwe Kleine-König9d5cf5a2007-02-23 20:52:19 +010019static inline u32 ns9xxx_systemclock(void) __attribute__((const));
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010020static inline u32 ns9xxx_systemclock(void)
21{
Uwe Kleine-Königf86bd612007-03-28 18:06:41 +010022 u32 pll = SYS_PLL;
23
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010024 /*
Uwe Kleine-Königf86bd612007-03-28 18:06:41 +010025 * The system clock should be a multiple of HZ * TIMERCLOCKSELECT (in
26 * time.c).
27 *
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
31 * - ND in {0 .. 31}
32 * - FS in {0 .. 3}
33 *
34 * Assuming the worst, we consider:
35 * - TIMERCLOCKSELECT == 64
36 * - ND == 0
37 * - FS == 3
38 *
39 * So HZ should be a divisor of:
40 * (CRYSTAL * (ND + 1) >> FS) / TIMERCLOCKSELECT
41 * == (2^17 * 3^2 * 5^2 * 1 >> 3) / 64
42 * == 2^8 * 3^2 * 5^2
43 * == 57600
44 *
45 * Currently HZ is defined to be 100 for this platform.
46 *
47 * Fine.
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010048 */
Uwe Kleine-Königf86bd612007-03-28 18:06:41 +010049 return CRYSTAL * (REGGET(pll, SYS_PLL, ND) + 1)
50 >> REGGET(pll, SYS_PLL, FS);
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010051}
52
Uwe Kleine-König9d5cf5a2007-02-23 20:52:19 +010053static inline u32 ns9xxx_cpuclock(void) __attribute__((const));
54static inline u32 ns9xxx_cpuclock(void)
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010055{
56 return ns9xxx_systemclock() / 2;
57}
58
Uwe Kleine-König9d5cf5a2007-02-23 20:52:19 +010059static inline u32 ns9xxx_ahbclock(void) __attribute__((const));
60static inline u32 ns9xxx_ahbclock(void)
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010061{
62 return ns9xxx_systemclock() / 4;
63}
64
Uwe Kleine-König9d5cf5a2007-02-23 20:52:19 +010065static inline u32 ns9xxx_bbusclock(void) __attribute__((const));
66static inline u32 ns9xxx_bbusclock(void)
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010067{
68 return ns9xxx_systemclock() / 8;
69}
70
71#endif /* ifndef __ASM_ARCH_CLOCK_H */