clk.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. void __init imx_check_clocks(struct clk *clks[], unsigned int count)
  9. {
  10. unsigned i;
  11. for (i = 0; i < count; i++)
  12. if (IS_ERR(clks[i]))
  13. pr_err("i.MX clk %u: register failed with %ld\n",
  14. i, PTR_ERR(clks[i]));
  15. }
  16. static struct clk * __init imx_obtain_fixed_clock_from_dt(const char *name)
  17. {
  18. struct of_phandle_args phandle;
  19. struct clk *clk = ERR_PTR(-ENODEV);
  20. char *path;
  21. path = kasprintf(GFP_KERNEL, "/clocks/%s", name);
  22. if (!path)
  23. return ERR_PTR(-ENOMEM);
  24. phandle.np = of_find_node_by_path(path);
  25. kfree(path);
  26. if (phandle.np) {
  27. clk = of_clk_get_from_provider(&phandle);
  28. of_node_put(phandle.np);
  29. }
  30. return clk;
  31. }
  32. struct clk * __init imx_obtain_fixed_clock(
  33. const char *name, unsigned long rate)
  34. {
  35. struct clk *clk;
  36. clk = imx_obtain_fixed_clock_from_dt(name);
  37. if (IS_ERR(clk))
  38. clk = imx_clk_fixed(name, rate);
  39. return clk;
  40. }
  41. /*
  42. * This fixups the register CCM_CSCMR1 write value.
  43. * The write/read/divider values of the aclk_podf field
  44. * of that register have the relationship described by
  45. * the following table:
  46. *
  47. * write value read value divider
  48. * 3b'000 3b'110 7
  49. * 3b'001 3b'111 8
  50. * 3b'010 3b'100 5
  51. * 3b'011 3b'101 6
  52. * 3b'100 3b'010 3
  53. * 3b'101 3b'011 4
  54. * 3b'110 3b'000 1
  55. * 3b'111 3b'001 2(default)
  56. *
  57. * That's why we do the xor operation below.
  58. */
  59. #define CSCMR1_FIXUP 0x00600000
  60. void imx_cscmr1_fixup(u32 *val)
  61. {
  62. *val ^= CSCMR1_FIXUP;
  63. return;
  64. }