clk.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. }
  65. static int imx_keep_uart_clocks __initdata;
  66. static struct clk ** const *imx_uart_clocks __initdata;
  67. static int __init imx_keep_uart_clocks_param(char *str)
  68. {
  69. imx_keep_uart_clocks = 1;
  70. return 0;
  71. }
  72. __setup_param("earlycon", imx_keep_uart_earlycon,
  73. imx_keep_uart_clocks_param, 0);
  74. __setup_param("earlyprintk", imx_keep_uart_earlyprintk,
  75. imx_keep_uart_clocks_param, 0);
  76. void __init imx_register_uart_clocks(struct clk ** const clks[])
  77. {
  78. if (imx_keep_uart_clocks) {
  79. int i;
  80. imx_uart_clocks = clks;
  81. for (i = 0; imx_uart_clocks[i]; i++)
  82. clk_prepare_enable(*imx_uart_clocks[i]);
  83. }
  84. }
  85. static int __init imx_clk_disable_uart(void)
  86. {
  87. if (imx_keep_uart_clocks && imx_uart_clocks) {
  88. int i;
  89. for (i = 0; imx_uart_clocks[i]; i++)
  90. clk_disable_unprepare(*imx_uart_clocks[i]);
  91. }
  92. return 0;
  93. }
  94. late_initcall_sync(imx_clk_disable_uart);