main.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Copyright 2011 Freescale Semiconductor, Inc.
  3. * Copyright 2011 Linaro Ltd.
  4. *
  5. * The code contained herein is licensed under the GNU General Public
  6. * License. You may obtain a copy of the GNU General Public License
  7. * Version 2 or later at the following locations:
  8. *
  9. * http://www.opensource.org/licenses/gpl-license.html
  10. * http://www.gnu.org/copyleft/gpl.html
  11. */
  12. #include <linux/init.h>
  13. #include <linux/types.h>
  14. #include <linux/clk.h>
  15. #include <linux/clkdev.h>
  16. #include <linux/err.h>
  17. #include <linux/io.h>
  18. #include <linux/of.h>
  19. #include <linux/of_address.h>
  20. #include <linux/of_irq.h>
  21. #include "clk.h"
  22. #include "common.h"
  23. #define CCGR0 0x68
  24. #define CCGR1 0x6c
  25. #define CCGR2 0x70
  26. #define CCGR3 0x74
  27. #define CCGR4 0x78
  28. #define CCGR5 0x7c
  29. #define CCGR6 0x80
  30. #define CCGR7 0x84
  31. #define CLPCR 0x54
  32. #define BP_CLPCR_LPM 0
  33. #define BM_CLPCR_LPM (0x3 << 0)
  34. #define BM_CLPCR_BYPASS_PMIC_READY (0x1 << 2)
  35. #define BM_CLPCR_ARM_CLK_DIS_ON_LPM (0x1 << 5)
  36. #define BM_CLPCR_SBYOS (0x1 << 6)
  37. #define BM_CLPCR_DIS_REF_OSC (0x1 << 7)
  38. #define BM_CLPCR_VSTBY (0x1 << 8)
  39. #define BP_CLPCR_STBY_COUNT 9
  40. #define BM_CLPCR_STBY_COUNT (0x3 << 9)
  41. #define BM_CLPCR_COSC_PWRDOWN (0x1 << 11)
  42. #define BM_CLPCR_WB_PER_AT_LPM (0x1 << 16)
  43. #define BM_CLPCR_WB_CORE_AT_LPM (0x1 << 17)
  44. #define BM_CLPCR_BYP_MMDC_CH0_LPM_HS (0x1 << 19)
  45. #define BM_CLPCR_BYP_MMDC_CH1_LPM_HS (0x1 << 21)
  46. #define BM_CLPCR_MASK_CORE0_WFI (0x1 << 22)
  47. #define BM_CLPCR_MASK_CORE1_WFI (0x1 << 23)
  48. #define BM_CLPCR_MASK_CORE2_WFI (0x1 << 24)
  49. #define BM_CLPCR_MASK_CORE3_WFI (0x1 << 25)
  50. #define BM_CLPCR_MASK_SCU_IDLE (0x1 << 26)
  51. #define BM_CLPCR_MASK_L2CC_IDLE (0x1 << 27)
  52. static void __iomem *ccm_base;
  53. void __init imx6q_clock_map_io(void) { }
  54. int imx6q_set_lpm(enum mxc_cpu_pwr_mode mode)
  55. {
  56. u32 val = readl_relaxed(ccm_base + CLPCR);
  57. val &= ~BM_CLPCR_LPM;
  58. switch (mode) {
  59. case WAIT_CLOCKED:
  60. break;
  61. case WAIT_UNCLOCKED:
  62. val |= 0x1 << BP_CLPCR_LPM;
  63. break;
  64. case STOP_POWER_ON:
  65. val |= 0x2 << BP_CLPCR_LPM;
  66. break;
  67. case WAIT_UNCLOCKED_POWER_OFF:
  68. val |= 0x1 << BP_CLPCR_LPM;
  69. val &= ~BM_CLPCR_VSTBY;
  70. val &= ~BM_CLPCR_SBYOS;
  71. break;
  72. case STOP_POWER_OFF:
  73. val |= 0x2 << BP_CLPCR_LPM;
  74. val |= 0x3 << BP_CLPCR_STBY_COUNT;
  75. val |= BM_CLPCR_VSTBY;
  76. val |= BM_CLPCR_SBYOS;
  77. break;
  78. default:
  79. return -EINVAL;
  80. }
  81. writel_relaxed(val, ccm_base + CLPCR);
  82. return 0;
  83. }
  84. static const char *step_sels[] = { "osc", "pll2_pfd2_396m", };
  85. static const char *pll1_sw_sels[] = { "pll1_sys", "step", };
  86. static const char *periph_pre_sels[] = { "pll2_bus", "pll2_pfd2_396m", "pll2_pfd0_352m", "pll2_198m", };
  87. static const char *periph_clk2_sels[] = { "pll3_usb_otg", "osc", };
  88. static const char *periph_sels[] = { "periph_pre", "periph_clk2", };
  89. static const char *periph2_sels[] = { "periph2_pre", "periph2_clk2", };
  90. static const char *axi_sels[] = { "periph", "pll2_pfd2_396m", "pll3_pfd1_540m", };
  91. static const char *audio_sels[] = { "pll4_audio", "pll3_pfd2_508m", "pll3_pfd3_454m", "pll3_usb_otg", };
  92. static const char *gpu_axi_sels[] = { "axi", "ahb", };
  93. static const char *gpu2d_core_sels[] = { "axi", "pll3_usb_otg", "pll2_pfd0_352m", "pll2_pfd2_396m", };
  94. static const char *gpu3d_core_sels[] = { "mmdc_ch0_axi", "pll3_usb_otg", "pll2_pfd1_594m", "pll2_pfd2_396m", };
  95. static const char *gpu3d_shader_sels[] = { "mmdc_ch0_axi", "pll3_usb_otg", "pll2_pfd1_594m", "pll2_pfd9_720m", };
  96. static const char *ipu_sels[] = { "mmdc_ch0_axi", "pll2_pfd2_396m", "pll3_120m", "pll3_pfd1_540m", };
  97. static const char *ldb_di_sels[] = { "pll5_video", "pll2_pfd0_352m", "pll2_pfd2_396m", "mmdc_ch1_axi", "pll3_pfd1_540m", };
  98. static const char *ipu_di_pre_sels[] = { "mmdc_ch0_axi", "pll3_usb_otg", "pll5_video", "pll2_pfd0_352m", "pll2_pfd2_396m", "pll3_pfd1_540m", };
  99. static const char *ipu1_di0_sels[] = { "ipu1_di0_pre", "dummy", "dummy", "ldb_di0", "ldb_di1", };
  100. static const char *ipu1_di1_sels[] = { "ipu1_di1_pre", "dummy", "dummy", "ldb_di0", "ldb_di1", };
  101. static const char *ipu2_di0_sels[] = { "ipu2_di0_pre", "dummy", "dummy", "ldb_di0", "ldb_di1", };
  102. static const char *ipu2_di1_sels[] = { "ipu2_di1_pre", "dummy", "dummy", "ldb_di0", "ldb_di1", };
  103. static const char *hsi_tx_sels[] = { "pll3_120m", "pll2_pfd2_396m", };
  104. static const char *pcie_axi_sels[] = { "axi", "ahb", };
  105. static const char *ssi_sels[] = { "pll3_pfd2_508m", "pll3_pfd3_454m", "pll4_audio", };
  106. static const char *usdhc_sels[] = { "pll2_pfd2_396m", "pll2_pfd0_352m", };
  107. static const char *enfc_sels[] = { "pll2_pfd0_352m", "pll2_bus", "pll3_usb_otg", "pll2_pfd2_396m", };
  108. static const char *emi_sels[] = { "axi", "pll3_usb_otg", "pll2_pfd2_396m", "pll2_pfd0_352m", };
  109. static const char *vdo_axi_sels[] = { "axi", "ahb", };
  110. static const char *vpu_axi_sels[] = { "axi", "pll2_pfd2_396m", "pll2_pfd0_352m", };
  111. static const char *cko1_sels[] = { "pll3_usb_otg", "pll2_bus", "pll1_sys", "pll5_video",
  112. "dummy", "axi", "enfc", "ipu1_di0", "ipu1_di1", "ipu2_di0",
  113. "ipu2_di1", "ahb", "ipg", "ipg_per", "ckil", "pll4_audio", };
  114. enum mx6q_clks {
  115. dummy, ckil, ckih, osc, pll2_pfd0_352m, pll2_pfd1_594m, pll2_pfd2_396m,
  116. pll3_pfd0_720m, pll3_pfd1_540m, pll3_pfd2_508m, pll3_pfd3_454m,
  117. pll2_198m, pll3_120m, pll3_80m, pll3_60m, twd, step, pll1_sw,
  118. periph_pre, periph2_pre, periph_clk2_sel, periph2_clk2_sel, axi_sel,
  119. esai_sel, asrc_sel, spdif_sel, gpu2d_axi, gpu3d_axi, gpu2d_core_sel,
  120. gpu3d_core_sel, gpu3d_shader_sel, ipu1_sel, ipu2_sel, ldb_di0_sel,
  121. ldb_di1_sel, ipu1_di0_pre_sel, ipu1_di1_pre_sel, ipu2_di0_pre_sel,
  122. ipu2_di1_pre_sel, ipu1_di0_sel, ipu1_di1_sel, ipu2_di0_sel,
  123. ipu2_di1_sel, hsi_tx_sel, pcie_axi_sel, ssi1_sel, ssi2_sel, ssi3_sel,
  124. usdhc1_sel, usdhc2_sel, usdhc3_sel, usdhc4_sel, enfc_sel, emi_sel,
  125. emi_slow_sel, vdo_axi_sel, vpu_axi_sel, cko1_sel, periph, periph2,
  126. periph_clk2, periph2_clk2, ipg, ipg_per, esai_pred, esai_podf,
  127. asrc_pred, asrc_podf, spdif_pred, spdif_podf, can_root, ecspi_root,
  128. gpu2d_core_podf, gpu3d_core_podf, gpu3d_shader, ipu1_podf, ipu2_podf,
  129. ldb_di0_podf, ldb_di1_podf, ipu1_di0_pre, ipu1_di1_pre, ipu2_di0_pre,
  130. ipu2_di1_pre, hsi_tx_podf, ssi1_pred, ssi1_podf, ssi2_pred, ssi2_podf,
  131. ssi3_pred, ssi3_podf, uart_serial_podf, usdhc1_podf, usdhc2_podf,
  132. usdhc3_podf, usdhc4_podf, enfc_pred, enfc_podf, emi_podf,
  133. emi_slow_podf, vpu_axi_podf, cko1_podf, axi, mmdc_ch0_axi_podf,
  134. mmdc_ch1_axi_podf, arm, ahb, apbh_dma, asrc, can1_ipg, can1_serial,
  135. can2_ipg, can2_serial, ecspi1, ecspi2, ecspi3, ecspi4, ecspi5, enet,
  136. esai, gpt_ipg, gpt_ipg_per, gpu2d_core, gpu3d_core, hdmi_iahb,
  137. hdmi_isfr, i2c1, i2c2, i2c3, iim, enfc, ipu1, ipu1_di0, ipu1_di1, ipu2,
  138. ipu2_di0, ldb_di0, ldb_di1, ipu2_di1, hsi_tx, mlb, mmdc_ch0_axi,
  139. mmdc_ch1_axi, ocram, openvg_axi, pcie_axi, pwm1, pwm2, pwm3, pwm4, per1_bch,
  140. gpmi_bch_apb, gpmi_bch, gpmi_io, gpmi_apb, sata, sdma, spba, ssi1,
  141. ssi2, ssi3, uart_ipg, uart_serial, usboh3, usdhc1, usdhc2, usdhc3,
  142. usdhc4, vdo_axi, vpu_axi, cko1, pll1_sys, pll2_bus, pll3_usb_otg,
  143. pll4_audio, pll5_video, pll8_mlb, pll7_usb_host, pll6_enet, ssi1_ipg,
  144. ssi2_ipg, ssi3_ipg, rom, usbphy1, usbphy2, ldb_di0_div_3_5, ldb_di1_div_3_5,
  145. sata_ref, sata_ref_100m, pcie_ref, pcie_ref_125m, enet_ref,
  146. clk_max
  147. };
  148. static struct clk *clk[clk_max];
  149. static struct clk_onecell_data clk_data;
  150. static enum mx6q_clks const clks_init_on[] __initconst = {
  151. mmdc_ch0_axi, rom,
  152. };
  153. static struct clk_div_table clk_enet_ref_table[] = {
  154. { .val = 0, .div = 20, },
  155. { .val = 1, .div = 10, },
  156. { .val = 2, .div = 5, },