Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 1 | /* |
| 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önig | f86bd61 | 2007-03-28 18:06:41 +0100 | [diff] [blame] | 14 | #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önig | 9d5cf5a | 2007-02-23 20:52:19 +0100 | [diff] [blame] | 19 | static inline u32 ns9xxx_systemclock(void) __attribute__((const)); |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 20 | static inline u32 ns9xxx_systemclock(void) |
| 21 | { |
Uwe Kleine-König | f86bd61 | 2007-03-28 18:06:41 +0100 | [diff] [blame] | 22 | u32 pll = SYS_PLL; |
| 23 | |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 24 | /* |
Uwe Kleine-König | f86bd61 | 2007-03-28 18:06:41 +0100 | [diff] [blame] | 25 | * 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önig | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 48 | */ |
Uwe Kleine-König | f86bd61 | 2007-03-28 18:06:41 +0100 | [diff] [blame] | 49 | return CRYSTAL * (REGGET(pll, SYS_PLL, ND) + 1) |
| 50 | >> REGGET(pll, SYS_PLL, FS); |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 51 | } |
| 52 | |
Uwe Kleine-König | 9d5cf5a | 2007-02-23 20:52:19 +0100 | [diff] [blame] | 53 | static inline u32 ns9xxx_cpuclock(void) __attribute__((const)); |
| 54 | static inline u32 ns9xxx_cpuclock(void) |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 55 | { |
| 56 | return ns9xxx_systemclock() / 2; |
| 57 | } |
| 58 | |
Uwe Kleine-König | 9d5cf5a | 2007-02-23 20:52:19 +0100 | [diff] [blame] | 59 | static inline u32 ns9xxx_ahbclock(void) __attribute__((const)); |
| 60 | static inline u32 ns9xxx_ahbclock(void) |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 61 | { |
| 62 | return ns9xxx_systemclock() / 4; |
| 63 | } |
| 64 | |
Uwe Kleine-König | 9d5cf5a | 2007-02-23 20:52:19 +0100 | [diff] [blame] | 65 | static inline u32 ns9xxx_bbusclock(void) __attribute__((const)); |
| 66 | static inline u32 ns9xxx_bbusclock(void) |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 67 | { |
| 68 | return ns9xxx_systemclock() / 8; |
| 69 | } |
| 70 | |
| 71 | #endif /* ifndef __ASM_ARCH_CLOCK_H */ |