clock.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include <asm/arch-ns9xxx/regs-sys.h>
  14. #define CRYSTAL 29491200 /* Hz */
  15. /* The HRM calls this value f_vco */
  16. static inline u32 ns9xxx_systemclock(void) __attribute__((const));
  17. static inline u32 ns9xxx_systemclock(void)
  18. {
  19. u32 pll = SYS_PLL;
  20. /*
  21. * The system clock should be a multiple of HZ * TIMERCLOCKSELECT (in
  22. * time.c).
  23. *
  24. * The following values are given:
  25. * - TIMERCLOCKSELECT == 2^i for an i in {0 .. 6}
  26. * - CRYSTAL == 29491200 == 2^17 * 3^2 * 5^2
  27. * - ND in {0 .. 31}
  28. * - FS in {0 .. 3}
  29. *
  30. * Assuming the worst, we consider:
  31. * - TIMERCLOCKSELECT == 64
  32. * - ND == 0
  33. * - FS == 3
  34. *
  35. * So HZ should be a divisor of:
  36. * (CRYSTAL * (ND + 1) >> FS) / TIMERCLOCKSELECT
  37. * == (2^17 * 3^2 * 5^2 * 1 >> 3) / 64
  38. * == 2^8 * 3^2 * 5^2
  39. * == 57600
  40. *
  41. * Currently HZ is defined to be 100 for this platform.
  42. *
  43. * Fine.
  44. */
  45. return CRYSTAL * (REGGET(pll, SYS_PLL, ND) + 1)
  46. >> REGGET(pll, SYS_PLL, FS);
  47. }
  48. static inline u32 ns9xxx_cpuclock(void) __attribute__((const));
  49. static inline u32 ns9xxx_cpuclock(void)
  50. {
  51. return ns9xxx_systemclock() / 2;
  52. }
  53. static inline u32 ns9xxx_ahbclock(void) __attribute__((const));
  54. static inline u32 ns9xxx_ahbclock(void)
  55. {
  56. return ns9xxx_systemclock() / 4;
  57. }
  58. static inline u32 ns9xxx_bbusclock(void) __attribute__((const));
  59. static inline u32 ns9xxx_bbusclock(void)
  60. {
  61. return ns9xxx_systemclock() / 8;
  62. }
  63. #endif /* ifndef __ASM_ARCH_CLOCK_H */