pll.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* arch/arm/plat-s3c64xx/include/plat/pll.h
  2. *
  3. * Copyright 2008 Openmoko, Inc.
  4. * Copyright 2008 Simtec Electronics
  5. * Ben Dooks <ben@simtec.co.uk>
  6. * http://armlinux.simtec.co.uk/
  7. *
  8. * S3C64XX PLL code
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #define S3C6400_PLL_MDIV_MASK ((1 << (25-16+1)) - 1)
  15. #define S3C6400_PLL_PDIV_MASK ((1 << (13-8+1)) - 1)
  16. #define S3C6400_PLL_SDIV_MASK ((1 << (2-0+1)) - 1)
  17. #define S3C6400_PLL_MDIV_SHIFT (16)
  18. #define S3C6400_PLL_PDIV_SHIFT (8)
  19. #define S3C6400_PLL_SDIV_SHIFT (0)
  20. #include <asm/div64.h>
  21. static inline unsigned long s3c6400_get_pll(unsigned long baseclk,
  22. u32 pllcon)
  23. {
  24. u32 mdiv, pdiv, sdiv;
  25. u64 fvco = baseclk;
  26. mdiv = (pllcon >> S3C6400_PLL_MDIV_SHIFT) & S3C6400_PLL_MDIV_MASK;
  27. pdiv = (pllcon >> S3C6400_PLL_PDIV_SHIFT) & S3C6400_PLL_PDIV_MASK;
  28. sdiv = (pllcon >> S3C6400_PLL_SDIV_SHIFT) & S3C6400_PLL_SDIV_MASK;
  29. fvco *= mdiv;
  30. do_div(fvco, (pdiv << sdiv));
  31. return (unsigned long)fvco;
  32. }
  33. #define S3C6400_EPLL_MDIV_MASK ((1 << (23-16)) - 1)
  34. #define S3C6400_EPLL_PDIV_MASK ((1 << (13-8)) - 1)
  35. #define S3C6400_EPLL_SDIV_MASK ((1 << (2-0)) - 1)
  36. #define S3C6400_EPLL_MDIV_SHIFT (16)
  37. #define S3C6400_EPLL_PDIV_SHIFT (8)
  38. #define S3C6400_EPLL_SDIV_SHIFT (0)
  39. #define S3C6400_EPLL_KDIV_MASK (0xffff)
  40. static inline unsigned long s3c6400_get_epll(unsigned long baseclk)
  41. {
  42. unsigned long result;
  43. u32 epll0 = __raw_readl(S3C_EPLL_CON0);
  44. u32 epll1 = __raw_readl(S3C_EPLL_CON1);
  45. u32 mdiv, pdiv, sdiv, kdiv;
  46. u64 tmp;
  47. mdiv = (epll0 >> S3C6400_EPLL_MDIV_SHIFT) & S3C6400_EPLL_MDIV_MASK;
  48. pdiv = (epll0 >> S3C6400_EPLL_PDIV_SHIFT) & S3C6400_EPLL_PDIV_MASK;
  49. sdiv = (epll0 >> S3C6400_EPLL_SDIV_SHIFT) & S3C6400_EPLL_SDIV_MASK;
  50. kdiv = epll1 & S3C6400_EPLL_KDIV_MASK;
  51. /* We need to multiple baseclk by mdiv (the integer part) and kdiv
  52. * which is in 2^16ths, so shift mdiv up (does not overflow) and
  53. * add kdiv before multiplying. The use of tmp is to avoid any
  54. * overflows before shifting bac down into result when multipling
  55. * by the mdiv and kdiv pair.
  56. */
  57. tmp = baseclk;
  58. tmp *= (mdiv << 16) + kdiv;
  59. do_div(tmp, (pdiv << sdiv));
  60. result = tmp >> 16;
  61. return result;
  62. }