clk-imx23.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright 2012 Freescale Semiconductor, Inc.
  3. *
  4. * The code contained herein is licensed under the GNU General Public
  5. * License. You may obtain a copy of the GNU General Public License
  6. * Version 2 or later at the following locations:
  7. *
  8. * http://www.opensource.org/licenses/gpl-license.html
  9. * http://www.gnu.org/copyleft/gpl.html
  10. */
  11. #include <linux/clk/mxs.h>
  12. #include <linux/clk.h>
  13. #include <linux/clk-provider.h>
  14. #include <linux/err.h>
  15. #include <linux/init.h>
  16. #include <linux/io.h>
  17. #include <linux/of.h>
  18. #include <linux/of_address.h>
  19. #include "clk.h"
  20. static void __iomem *clkctrl;
  21. static void __iomem *digctrl;
  22. #define CLKCTRL clkctrl
  23. #define DIGCTRL digctrl
  24. #define PLLCTRL0 (CLKCTRL + 0x0000)
  25. #define CPU (CLKCTRL + 0x0020)
  26. #define HBUS (CLKCTRL + 0x0030)
  27. #define XBUS (CLKCTRL + 0x0040)
  28. #define XTAL (CLKCTRL + 0x0050)
  29. #define PIX (CLKCTRL + 0x0060)
  30. #define SSP (CLKCTRL + 0x0070)
  31. #define GPMI (CLKCTRL + 0x0080)
  32. #define SPDIF (CLKCTRL + 0x0090)
  33. #define EMI (CLKCTRL + 0x00a0)
  34. #define SAIF (CLKCTRL + 0x00c0)
  35. #define TV (CLKCTRL + 0x00d0)
  36. #define ETM (CLKCTRL + 0x00e0)
  37. #define FRAC (CLKCTRL + 0x00f0)
  38. #define CLKSEQ (CLKCTRL + 0x0110)
  39. #define BP_CPU_INTERRUPT_WAIT 12
  40. #define BP_CLKSEQ_BYPASS_SAIF 0
  41. #define BP_CLKSEQ_BYPASS_SSP 5
  42. #define BP_SAIF_DIV_FRAC_EN 16
  43. #define BP_FRAC_IOFRAC 24
  44. static void __init clk_misc_init(void)
  45. {
  46. u32 val;
  47. /* Gate off cpu clock in WFI for power saving */
  48. writel_relaxed(1 << BP_CPU_INTERRUPT_WAIT, CPU + SET);
  49. /* Clear BYPASS for SAIF */
  50. writel_relaxed(1 << BP_CLKSEQ_BYPASS_SAIF, CLKSEQ + CLR);
  51. /* SAIF has to use frac div for functional operation */
  52. val = readl_relaxed(SAIF);
  53. val |= 1 << BP_SAIF_DIV_FRAC_EN;
  54. writel_relaxed(val, SAIF);
  55. /*
  56. * Source ssp clock from ref_io than ref_xtal,
  57. * as ref_xtal only provides 24 MHz as maximum.
  58. */
  59. writel_relaxed(1 << BP_CLKSEQ_BYPASS_SSP, CLKSEQ + CLR);
  60. /*
  61. * 480 MHz seems too high to be ssp clock source directly,
  62. * so set frac to get a 288 MHz ref_io.
  63. */
  64. writel_relaxed(0x3f << BP_FRAC_IOFRAC, FRAC + CLR);
  65. writel_relaxed(30 << BP_FRAC_IOFRAC, FRAC + SET);
  66. }
  67. static const char *const sel_pll[] __initconst = { "pll", "ref_xtal", };
  68. static const char *const sel_cpu[] __initconst = { "ref_cpu", "ref_xtal", };
  69. static const char *const sel_pix[] __initconst = { "ref_pix", "ref_xtal", };
  70. static const char *const sel_io[] __initconst = { "ref_io", "ref_xtal", };
  71. static const char *const cpu_sels[] __initconst = { "cpu_pll", "cpu_xtal", };
  72. static const char *const emi_sels[] __initconst = { "emi_pll", "emi_xtal", };
  73. enum imx23_clk {
  74. ref_xtal, pll, ref_cpu, ref_emi, ref_pix, ref_io, saif_sel,
  75. lcdif_sel, gpmi_sel, ssp_sel, emi_sel, cpu, etm_sel, cpu_pll,
  76. cpu_xtal, hbus, xbus, lcdif_div, ssp_div, gpmi_div, emi_pll,
  77. emi_xtal, etm_div, saif_div, clk32k_div, rtc, adc, spdif_div,
  78. clk32k, dri, pwm, filt, uart, ssp, gpmi, spdif, emi, saif,
  79. lcdif, etm, usb, usb_phy,
  80. clk_max
  81. };
  82. static struct clk *clks[clk_max];
  83. static struct clk_onecell_data clk_data;
  84. static enum imx23_clk clks_init_on[] __initdata = {
  85. cpu, hbus, xbus, emi, uart,
  86. };
  87. static void __init mx23_clocks_init(struct device_node *np)
  88. {
  89. struct device_node *dcnp;
  90. u32 i;
  91. dcnp = of_find_compatible_node(NULL, NULL, "fsl,imx23-digctl");
  92. digctrl = of_iomap(dcnp, 0);
  93. WARN_ON(!digctrl);
  94. of_node_put(dcnp);
  95. clkctrl = of_iomap(np, 0);
  96. WARN_ON(!clkctrl);
  97. clk_misc_init();
  98. clks[ref_xtal] = mxs_clk_fixed("ref_xtal", 24000000);
  99. clks[pll] = mxs_clk_pll("pll", "ref_xtal", PLLCTRL0, 16, 480000000);
  100. clks[ref_cpu] = mxs_clk_ref("ref_cpu", "pll", FRAC, 0);
  101. clks[ref_emi] = mxs_clk_ref("ref_emi", "pll", FRAC, 1);
  102. clks[ref_pix] = mxs_clk_ref("ref_pix", "pll", FRAC, 2);
  103. clks[ref_io] = mxs_clk_ref("ref_io", "pll", FRAC, 3);
  104. clks[saif_sel] = mxs_clk_mux("saif_sel", CLKSEQ, 0, 1, sel_pll, ARRAY_SIZE(sel_pll));
  105. clks[lcdif_sel] = mxs_clk_mux("lcdif_sel", CLKSEQ, 1, 1, sel_pix, ARRAY_SIZE(sel_pix));
  106. clks[gpmi_sel] = mxs_clk_mux("gpmi_sel", CLKSEQ, 4, 1, sel_io, ARRAY_SIZE(sel_io));
  107. clks[ssp_sel] = mxs_clk_mux("ssp_sel", CLKSEQ, 5, 1, sel_io, ARRAY_SIZE(sel_io));
  108. clks[emi_sel] = mxs_clk_mux("emi_sel", CLKSEQ, 6, 1, emi_sels, ARRAY_SIZE(emi_sels));
  109. clks[cpu] = mxs_clk_mux("cpu", CLKSEQ, 7, 1, cpu_sels, ARRAY_SIZE(cpu_sels));
  110. clks[etm_sel] = mxs_clk_mux("etm_sel", CLKSEQ, 8, 1, sel_cpu, ARRAY_SIZE(sel_cpu));
  111. clks[cpu_pll] = mxs_clk_div("cpu_pll", "ref_cpu", CPU, 0, 6, 28);
  112. clks[cpu_xtal] = mxs_clk_div("cpu_xtal", "ref_xtal", CPU, 16, 10, 29);
  113. clks[hbus] = mxs_clk_div("hbus", "cpu", HBUS, 0, 5, 29);
  114. clks[xbus] = mxs_clk_div("xbus", "ref_xtal", XBUS, 0, 10, 31);
  115. clks[lcdif_div] = mxs_clk_div("lcdif_div", "lcdif_sel", PIX, 0, 12, 29);
  116. clks[ssp_div] = mxs_clk_div("ssp_div", "ssp_sel", SSP, 0, 9, 29);
  117. clks[gpmi_div] = mxs_clk_div("gpmi_div", "gpmi_sel", GPMI, 0, 10, 29);
  118. clks[emi_pll] = mxs_clk_div("emi_pll", "ref_emi", EMI, 0, 6, 28);
  119. clks[emi_xtal] = mxs_clk_div("emi_xtal", "ref_xtal", EMI, 8, 4, 29);
  120. clks[etm_div] = mxs_clk_div("etm_div", "etm_sel", ETM, 0, 6, 29);
  121. clks[saif_div] = mxs_clk_frac("saif_div", "saif_sel", SAIF, 0, 16, 29);
  122. clks[clk32k_div] = mxs_clk_fixed_factor("clk32k_div", "ref_xtal", 1, 750);
  123. clks[rtc] = mxs_clk_fixed_factor("rtc", "ref_xtal", 1, 768);
  124. clks[adc] = mxs_clk_fixed_factor("adc", "clk32k", 1, 16);
  125. clks[spdif_div] = mxs_clk_fixed_factor("spdif_div", "pll", 1, 4);
  126. clks[clk32k] = mxs_clk_gate("clk32k", "clk32k_div", XTAL, 26);
  127. clks[dri] = mxs_clk_gate("dri", "ref_xtal", XTAL, 28);
  128. clks[pwm] = mxs_clk_gate("pwm", "ref_xtal", XTAL, 29);
  129. clks[filt] = mxs_clk_gate("filt", "ref_xtal", XTAL, 30);
  130. clks[uart] = mxs_clk_gate("uart", "ref_xtal", XTAL, 31);
  131. clks[ssp] = mxs_clk_gate("ssp", "ssp_div", SSP, 31);
  132. clks[gpmi] = mxs_clk_gate("gpmi", "gpmi_div", GPMI, 31);
  133. clks[spdif] = mxs_clk_gate("spdif", "spdif_div", SPDIF, 31);
  134. clks[emi] = mxs_clk_gate("emi", "emi_sel", EMI, 31);
  135. clks[saif] = mxs_clk_gate("saif", "saif_div", SAIF, 31);
  136. clks[lcdif] = mxs_clk_gate("lcdif", "lcdif_div", PIX, 31);
  137. clks[etm] = mxs_clk_gate("etm", "etm_div", ETM, 31);
  138. clks[usb] = mxs_clk_gate("usb", "usb_phy", DIGCTRL, 2);
  139. clks[usb_phy] = clk_register_gate(NULL, "usb_phy", "pll", 0, PLLCTRL0, 18, 0, &mxs_lock);
  140. for (i = 0; i < ARRAY_SIZE(clks); i++)
  141. if (IS_ERR(clks[i])) {
  142. pr_err("i.MX23 clk %d: register failed with %ld\n",
  143. i, PTR_ERR(clks[i]));
  144. return;
  145. }
  146. clk_data.clks = clks;
  147. clk_data.clk_num = ARRAY_SIZE(clks);
  148. of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data);
  149. for (i = 0; i < ARRAY_SIZE(clks_init_on); i++)
  150. clk_prepare_enable(clks[clks_init_on[i]]);
  151. }
  152. CLK_OF_DECLARE(imx23_clkctrl, "fsl,imx23-clkctrl", mx23_clocks_init);