clk-pllv1.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <linux/clk.h>
  2. #include <linux/clk-provider.h>
  3. #include <linux/io.h>
  4. #include <linux/slab.h>
  5. #include <linux/kernel.h>
  6. #include <linux/err.h>
  7. #include <mach/common.h>
  8. #include <mach/hardware.h>
  9. #include <mach/clock.h>
  10. #include "clk.h"
  11. /**
  12. * pll v1
  13. *
  14. * @clk_hw clock source
  15. * @parent the parent clock name
  16. * @base base address of pll registers
  17. *
  18. * PLL clock version 1, found on i.MX1/21/25/27/31/35
  19. */
  20. struct clk_pllv1 {
  21. struct clk_hw hw;
  22. void __iomem *base;
  23. };
  24. #define to_clk_pllv1(clk) (container_of(clk, struct clk_pllv1, clk))
  25. static unsigned long clk_pllv1_recalc_rate(struct clk_hw *hw,
  26. unsigned long parent_rate)
  27. {
  28. struct clk_pllv1 *pll = to_clk_pllv1(hw);
  29. return mxc_decode_pll(readl(pll->base), parent_rate);
  30. }
  31. struct clk_ops clk_pllv1_ops = {
  32. .recalc_rate = clk_pllv1_recalc_rate,
  33. };
  34. struct clk *imx_clk_pllv1(const char *name, const char *parent,
  35. void __iomem *base)
  36. {
  37. struct clk_pllv1 *pll;
  38. struct clk *clk;
  39. struct clk_init_data init;
  40. pll = kmalloc(sizeof(*pll), GFP_KERNEL);
  41. if (!pll)
  42. return ERR_PTR(-ENOMEM);
  43. pll->base = base;
  44. init.name = name;
  45. init.ops = &clk_pllv1_ops;
  46. init.flags = 0;
  47. init.parent_names = &parent;
  48. init.num_parents = 1;
  49. pll->hw.init = &init;
  50. clk = clk_register(NULL, &pll->hw);
  51. if (IS_ERR(clk))
  52. kfree(pll);
  53. return clk;
  54. }