clk.c 808 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <linux/clk.h>
  2. #include <linux/err.h>
  3. #include <linux/of.h>
  4. #include <linux/slab.h>
  5. #include <linux/spinlock.h>
  6. #include "clk.h"
  7. DEFINE_SPINLOCK(imx_ccm_lock);
  8. static struct clk * __init imx_obtain_fixed_clock_from_dt(const char *name)
  9. {
  10. struct of_phandle_args phandle;
  11. struct clk *clk = ERR_PTR(-ENODEV);
  12. char *path;
  13. path = kasprintf(GFP_KERNEL, "/clocks/%s", name);
  14. if (!path)
  15. return ERR_PTR(-ENOMEM);
  16. phandle.np = of_find_node_by_path(path);
  17. kfree(path);
  18. if (phandle.np) {
  19. clk = of_clk_get_from_provider(&phandle);
  20. of_node_put(phandle.np);
  21. }
  22. return clk;
  23. }
  24. struct clk * __init imx_obtain_fixed_clock(
  25. const char *name, unsigned long rate)
  26. {
  27. struct clk *clk;
  28. clk = imx_obtain_fixed_clock_from_dt(name);
  29. if (IS_ERR(clk))
  30. clk = imx_clk_fixed(name, rate);
  31. return clk;
  32. }