common.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright 2012 Freescale Semiconductor, Inc.
  3. * Author: Matthew McClintock <msm@freescale.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. *
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  19. * MA 02111-1307 USA
  20. *
  21. */
  22. #include <common.h>
  23. #include <asm/processor.h>
  24. #include <asm/global_data.h>
  25. DECLARE_GLOBAL_DATA_PTR;
  26. #ifndef CONFIG_SYS_FSL_TBCLK_DIV
  27. #define CONFIG_SYS_FSL_TBCLK_DIV 8
  28. #endif
  29. void udelay(unsigned long usec)
  30. {
  31. u32 ticks_per_usec = gd->bus_clk / (CONFIG_SYS_FSL_TBCLK_DIV * 1000000);
  32. u32 ticks = ticks_per_usec * usec;
  33. u32 s = mfspr(SPRN_TBRL);
  34. while ((mfspr(SPRN_TBRL) - s) < ticks);
  35. }