imx_speed.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. *
  3. * (c) 2004 Sascha Hauer <sascha@saschahauer.de>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #if defined (CONFIG_IMX)
  25. #include <asm/arch/imx-regs.h>
  26. /* ------------------------------------------------------------------------- */
  27. /* NOTE: This describes the proper use of this file.
  28. *
  29. * CONFIG_SYS_CLK_FREQ should be defined as the input frequency of the PLL.
  30. * SH FIXME: 16780000 in our case
  31. * get_FCLK(), get_HCLK(), get_PCLK() and get_UCLK() return the clock of
  32. * the specified bus in HZ.
  33. */
  34. /* ------------------------------------------------------------------------- */
  35. ulong get_systemPLLCLK(void)
  36. {
  37. /* FIXME: We assume System_SEL = 0 here */
  38. u32 spctl0 = SPCTL0;
  39. u32 mfi = (spctl0 >> 10) & 0xf;
  40. u32 mfn = spctl0 & 0x3f;
  41. u32 mfd = (spctl0 >> 16) & 0x3f;
  42. u32 pd = (spctl0 >> 26) & 0xf;
  43. mfi = mfi<=5 ? 5 : mfi;
  44. return (2*(CONFIG_SYSPLL_CLK_FREQ>>10)*( (mfi<<10) + (mfn<<10)/(mfd+1)))/(pd+1);
  45. }
  46. ulong get_mcuPLLCLK(void)
  47. {
  48. /* FIXME: We assume System_SEL = 0 here */
  49. u32 mpctl0 = MPCTL0;
  50. u32 mfi = (mpctl0 >> 10) & 0xf;
  51. u32 mfn = mpctl0 & 0x3f;
  52. u32 mfd = (mpctl0 >> 16) & 0x3f;
  53. u32 pd = (mpctl0 >> 26) & 0xf;
  54. mfi = mfi<=5 ? 5 : mfi;
  55. return (2*(CONFIG_SYS_CLK_FREQ>>10)*( (mfi<<10) + (mfn<<10)/(mfd+1)))/(pd+1);
  56. }
  57. ulong get_FCLK(void)
  58. {
  59. return (( CSCR>>15)&1) ? get_mcuPLLCLK()>>1 : get_mcuPLLCLK();
  60. }
  61. /* return HCLK frequency */
  62. ulong get_HCLK(void)
  63. {
  64. u32 bclkdiv = (( CSCR >> 10 ) & 0xf) + 1;
  65. printf("bclkdiv: %d\n", bclkdiv);
  66. return get_systemPLLCLK() / bclkdiv;
  67. }
  68. /* return BCLK frequency */
  69. ulong get_BCLK(void)
  70. {
  71. return get_HCLK();
  72. }
  73. ulong get_PERCLK1(void)
  74. {
  75. return get_systemPLLCLK() / (((PCDR) & 0xf)+1);
  76. }
  77. ulong get_PERCLK2(void)
  78. {
  79. return get_systemPLLCLK() / (((PCDR>>4) & 0xf)+1);
  80. }
  81. ulong get_PERCLK3(void)
  82. {
  83. return get_systemPLLCLK() / (((PCDR>>16) & 0x7f)+1);
  84. }
  85. #endif /* defined (CONFIG_IMX) */