speed.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * (C) Copyright 2001-2004
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * (C) Copyright 2002
  6. * David Mueller, ELSOFT AG, d.mueller@elsoft.ch
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <lh7a40x.h>
  28. /* ------------------------------------------------------------------------- */
  29. /* NOTE: This describes the proper use of this file.
  30. *
  31. * CONFIG_SYS_CLK_FREQ should be defined as the input frequency of the PLL.
  32. *
  33. * get_FCLK(), get_HCLK(), get_PCLK() return the clock of
  34. * the specified bus in HZ.
  35. */
  36. /* ------------------------------------------------------------------------- */
  37. ulong get_PLLCLK (void)
  38. {
  39. return CONFIG_SYS_CLK_FREQ;
  40. }
  41. /* return FCLK frequency */
  42. ulong get_FCLK (void)
  43. {
  44. LH7A40X_CSC_PTR (csc);
  45. ulong maindiv1, maindiv2, prediv, ps;
  46. /*
  47. * from userguide 6.1.1.2
  48. *
  49. * FCLK = ((MAINDIV1 +2) * (MAINDIV2 +2) * 14.7456MHz) /
  50. * ((PREDIV+2) * (2^PS))
  51. */
  52. maindiv2 = (csc->clkset & CLKSET_MAINDIV2) >> 11;
  53. maindiv1 = (csc->clkset & CLKSET_MAINDIV1) >> 7;
  54. prediv = (csc->clkset & CLKSET_PREDIV) >> 2;
  55. ps = (csc->clkset & CLKSET_PS) >> 16;
  56. return (((maindiv2 + 2) * (maindiv1 + 2) * CONFIG_SYS_CLK_FREQ) /
  57. ((prediv + 2) * (1 << ps)));
  58. }
  59. /* return HCLK frequency */
  60. ulong get_HCLK (void)
  61. {
  62. LH7A40X_CSC_PTR (csc);
  63. return (get_FCLK () / ((csc->clkset & CLKSET_HCLKDIV) + 1));
  64. }
  65. /* return PCLK frequency */
  66. ulong get_PCLK (void)
  67. {
  68. LH7A40X_CSC_PTR (csc);
  69. return (get_HCLK () /
  70. (1 << (((csc->clkset & CLKSET_PCLKDIV) >> 16) + 1)));
  71. }