clk-imxrt1050.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
  2. /*
  3. * Copyright (C) 2021
  4. * Author(s):
  5. * Jesse Taube <[email protected]>
  6. * Giulio Benetti <[email protected]>
  7. */
  8. #include <linux/clk.h>
  9. #include <linux/of_address.h>
  10. #include <linux/of_irq.h>
  11. #include <linux/platform_device.h>
  12. #include <dt-bindings/clock/imxrt1050-clock.h>
  13. #include "clk.h"
  14. static const char * const pll_ref_sels[] = {"osc", "dummy", };
  15. static const char * const per_sels[] = {"ipg_pdof", "osc", };
  16. static const char * const pll1_bypass_sels[] = {"pll1_arm", "pll1_arm_ref_sel", };
  17. static const char * const pll2_bypass_sels[] = {"pll2_sys", "pll2_sys_ref_sel", };
  18. static const char * const pll3_bypass_sels[] = {"pll3_usb_otg", "pll3_usb_otg_ref_sel", };
  19. static const char * const pll5_bypass_sels[] = {"pll5_video", "pll5_video_ref_sel", };
  20. static const char *const pre_periph_sels[] = {
  21. "pll2_sys", "pll2_pfd2_396m", "pll2_pfd0_352m", "arm_podf", };
  22. static const char *const periph_sels[] = { "pre_periph_sel", "todo", };
  23. static const char *const usdhc_sels[] = { "pll2_pfd2_396m", "pll2_pfd0_352m", };
  24. static const char *const lpuart_sels[] = { "pll3_80m", "osc", };
  25. static const char *const lcdif_sels[] = {
  26. "pll2_sys", "pll3_pfd3_454_74m", "pll5_video", "pll2_pfd0_352m",
  27. "pll2_pfd1_594m", "pll3_pfd1_664_62m", };
  28. static const char *const semc_alt_sels[] = { "pll2_pfd2_396m", "pll3_pfd1_664_62m", };
  29. static const char *const semc_sels[] = { "periph_sel", "semc_alt_sel", };
  30. static struct clk_hw **hws;
  31. static struct clk_hw_onecell_data *clk_hw_data;
  32. static int imxrt1050_clocks_probe(struct platform_device *pdev)
  33. {
  34. void __iomem *ccm_base;
  35. void __iomem *pll_base;
  36. struct device *dev = &pdev->dev;
  37. struct device_node *np = dev->of_node;
  38. struct device_node *anp;
  39. int ret;
  40. clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws,
  41. IMXRT1050_CLK_END), GFP_KERNEL);
  42. if (WARN_ON(!clk_hw_data))
  43. return -ENOMEM;
  44. clk_hw_data->num = IMXRT1050_CLK_END;
  45. hws = clk_hw_data->hws;
  46. hws[IMXRT1050_CLK_OSC] = imx_obtain_fixed_clk_hw(np, "osc");
  47. anp = of_find_compatible_node(NULL, NULL, "fsl,imxrt-anatop");
  48. pll_base = devm_of_iomap(dev, anp, 0, NULL);
  49. of_node_put(anp);
  50. if (WARN_ON(IS_ERR(pll_base))) {
  51. ret = PTR_ERR(pll_base);
  52. goto unregister_hws;
  53. }
  54. /* Anatop clocks */
  55. hws[IMXRT1050_CLK_DUMMY] = imx_clk_hw_fixed("dummy", 0UL);
  56. hws[IMXRT1050_CLK_PLL1_REF_SEL] = imx_clk_hw_mux("pll1_arm_ref_sel",
  57. pll_base + 0x0, 14, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
  58. hws[IMXRT1050_CLK_PLL2_REF_SEL] = imx_clk_hw_mux("pll2_sys_ref_sel",
  59. pll_base + 0x30, 14, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
  60. hws[IMXRT1050_CLK_PLL3_REF_SEL] = imx_clk_hw_mux("pll3_usb_otg_ref_sel",
  61. pll_base + 0x10, 14, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
  62. hws[IMXRT1050_CLK_PLL5_REF_SEL] = imx_clk_hw_mux("pll5_video_ref_sel",
  63. pll_base + 0xa0, 14, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
  64. hws[IMXRT1050_CLK_PLL1_ARM] = imx_clk_hw_pllv3(IMX_PLLV3_SYS, "pll1_arm",
  65. "pll1_arm_ref_sel", pll_base + 0x0, 0x7f);
  66. hws[IMXRT1050_CLK_PLL2_SYS] = imx_clk_hw_pllv3(IMX_PLLV3_GENERIC, "pll2_sys",
  67. "pll2_sys_ref_sel", pll_base + 0x30, 0x1);
  68. hws[IMXRT1050_CLK_PLL3_USB_OTG] = imx_clk_hw_pllv3(IMX_PLLV3_USB, "pll3_usb_otg",
  69. "pll3_usb_otg_ref_sel", pll_base + 0x10, 0x1);
  70. hws[IMXRT1050_CLK_PLL5_VIDEO] = imx_clk_hw_pllv3(IMX_PLLV3_AV, "pll5_video",
  71. "pll5_video_ref_sel", pll_base + 0xa0, 0x7f);
  72. /* PLL bypass out */
  73. hws[IMXRT1050_CLK_PLL1_BYPASS] = imx_clk_hw_mux_flags("pll1_bypass", pll_base + 0x0, 16, 1,
  74. pll1_bypass_sels, ARRAY_SIZE(pll1_bypass_sels), CLK_SET_RATE_PARENT);
  75. hws[IMXRT1050_CLK_PLL2_BYPASS] = imx_clk_hw_mux_flags("pll2_bypass", pll_base + 0x30, 16, 1,
  76. pll2_bypass_sels, ARRAY_SIZE(pll2_bypass_sels), CLK_SET_RATE_PARENT);
  77. hws[IMXRT1050_CLK_PLL3_BYPASS] = imx_clk_hw_mux_flags("pll3_bypass", pll_base + 0x10, 16, 1,
  78. pll3_bypass_sels, ARRAY_SIZE(pll3_bypass_sels), CLK_SET_RATE_PARENT);
  79. hws[IMXRT1050_CLK_PLL5_BYPASS] = imx_clk_hw_mux_flags("pll5_bypass", pll_base + 0xa0, 16, 1,
  80. pll5_bypass_sels, ARRAY_SIZE(pll5_bypass_sels), CLK_SET_RATE_PARENT);
  81. hws[IMXRT1050_CLK_VIDEO_POST_DIV_SEL] = imx_clk_hw_divider("video_post_div_sel",
  82. "pll5_video", pll_base + 0xa0, 19, 2);
  83. hws[IMXRT1050_CLK_VIDEO_DIV] = imx_clk_hw_divider("video_div",
  84. "video_post_div_sel", pll_base + 0x170, 30, 2);
  85. hws[IMXRT1050_CLK_PLL3_80M] = imx_clk_hw_fixed_factor("pll3_80m", "pll3_usb_otg", 1, 6);
  86. hws[IMXRT1050_CLK_PLL2_PFD0_352M] = imx_clk_hw_pfd("pll2_pfd0_352m", "pll2_sys", pll_base + 0x100, 0);
  87. hws[IMXRT1050_CLK_PLL2_PFD1_594M] = imx_clk_hw_pfd("pll2_pfd1_594m", "pll2_sys", pll_base + 0x100, 1);
  88. hws[IMXRT1050_CLK_PLL2_PFD2_396M] = imx_clk_hw_pfd("pll2_pfd2_396m", "pll2_sys", pll_base + 0x100, 2);
  89. hws[IMXRT1050_CLK_PLL3_PFD1_664_62M] = imx_clk_hw_pfd("pll3_pfd1_664_62m", "pll3_usb_otg", pll_base + 0xf0, 1);
  90. hws[IMXRT1050_CLK_PLL3_PFD3_454_74M] = imx_clk_hw_pfd("pll3_pfd3_454_74m", "pll3_usb_otg", pll_base + 0xf0, 3);
  91. /* CCM clocks */
  92. ccm_base = devm_platform_ioremap_resource(pdev, 0);
  93. if (WARN_ON(IS_ERR(ccm_base))) {
  94. ret = PTR_ERR(ccm_base);
  95. goto unregister_hws;
  96. }
  97. hws[IMXRT1050_CLK_ARM_PODF] = imx_clk_hw_divider("arm_podf", "pll1_arm", ccm_base + 0x10, 0, 3);
  98. hws[IMXRT1050_CLK_PRE_PERIPH_SEL] = imx_clk_hw_mux("pre_periph_sel", ccm_base + 0x18, 18, 2,
  99. pre_periph_sels, ARRAY_SIZE(pre_periph_sels));
  100. hws[IMXRT1050_CLK_PERIPH_SEL] = imx_clk_hw_mux("periph_sel", ccm_base + 0x14, 25, 1,
  101. periph_sels, ARRAY_SIZE(periph_sels));
  102. hws[IMXRT1050_CLK_USDHC1_SEL] = imx_clk_hw_mux("usdhc1_sel", ccm_base + 0x1c, 16, 1,
  103. usdhc_sels, ARRAY_SIZE(usdhc_sels));
  104. hws[IMXRT1050_CLK_USDHC2_SEL] = imx_clk_hw_mux("usdhc2_sel", ccm_base + 0x1c, 17, 1,
  105. usdhc_sels, ARRAY_SIZE(usdhc_sels));
  106. hws[IMXRT1050_CLK_LPUART_SEL] = imx_clk_hw_mux("lpuart_sel", ccm_base + 0x24, 6, 1,
  107. lpuart_sels, ARRAY_SIZE(lpuart_sels));
  108. hws[IMXRT1050_CLK_LCDIF_SEL] = imx_clk_hw_mux("lcdif_sel", ccm_base + 0x38, 15, 3,
  109. lcdif_sels, ARRAY_SIZE(lcdif_sels));
  110. hws[IMXRT1050_CLK_PER_CLK_SEL] = imx_clk_hw_mux("per_sel", ccm_base + 0x1C, 6, 1,
  111. per_sels, ARRAY_SIZE(per_sels));
  112. hws[IMXRT1050_CLK_SEMC_ALT_SEL] = imx_clk_hw_mux("semc_alt_sel", ccm_base + 0x14, 7, 1,
  113. semc_alt_sels, ARRAY_SIZE(semc_alt_sels));
  114. hws[IMXRT1050_CLK_SEMC_SEL] = imx_clk_hw_mux_flags("semc_sel", ccm_base + 0x14, 6, 1,
  115. semc_sels, ARRAY_SIZE(semc_sels), CLK_IS_CRITICAL);
  116. hws[IMXRT1050_CLK_AHB_PODF] = imx_clk_hw_divider("ahb", "periph_sel", ccm_base + 0x14, 10, 3);
  117. hws[IMXRT1050_CLK_IPG_PDOF] = imx_clk_hw_divider("ipg", "ahb", ccm_base + 0x14, 8, 2);
  118. hws[IMXRT1050_CLK_PER_PDOF] = imx_clk_hw_divider("per", "per_sel", ccm_base + 0x1C, 0, 5);
  119. hws[IMXRT1050_CLK_USDHC1_PODF] = imx_clk_hw_divider("usdhc1_podf", "usdhc1_sel", ccm_base + 0x24, 11, 3);
  120. hws[IMXRT1050_CLK_USDHC2_PODF] = imx_clk_hw_divider("usdhc2_podf", "usdhc2_sel", ccm_base + 0x24, 16, 3);
  121. hws[IMXRT1050_CLK_LPUART_PODF] = imx_clk_hw_divider("lpuart_podf", "lpuart_sel", ccm_base + 0x24, 0, 6);
  122. hws[IMXRT1050_CLK_LCDIF_PRED] = imx_clk_hw_divider("lcdif_pred", "lcdif_sel", ccm_base + 0x38, 12, 3);
  123. hws[IMXRT1050_CLK_LCDIF_PODF] = imx_clk_hw_divider("lcdif_podf", "lcdif_pred", ccm_base + 0x18, 23, 3);
  124. hws[IMXRT1050_CLK_USDHC1] = imx_clk_hw_gate2("usdhc1", "usdhc1_podf", ccm_base + 0x80, 2);
  125. hws[IMXRT1050_CLK_USDHC2] = imx_clk_hw_gate2("usdhc2", "usdhc2_podf", ccm_base + 0x80, 4);
  126. hws[IMXRT1050_CLK_LPUART1] = imx_clk_hw_gate2("lpuart1", "lpuart_podf", ccm_base + 0x7c, 24);
  127. hws[IMXRT1050_CLK_LCDIF_APB] = imx_clk_hw_gate2("lcdif", "lcdif_podf", ccm_base + 0x70, 28);
  128. hws[IMXRT1050_CLK_DMA] = imx_clk_hw_gate("dma", "ipg", ccm_base + 0x7C, 6);
  129. hws[IMXRT1050_CLK_DMA_MUX] = imx_clk_hw_gate("dmamux0", "ipg", ccm_base + 0x7C, 7);
  130. imx_check_clk_hws(hws, IMXRT1050_CLK_END);
  131. ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_hw_data);
  132. if (ret < 0) {
  133. dev_err(dev, "Failed to register clks for i.MXRT1050.\n");
  134. goto unregister_hws;
  135. }
  136. return 0;
  137. unregister_hws:
  138. imx_unregister_hw_clocks(hws, IMXRT1050_CLK_END);
  139. return ret;
  140. }
  141. static const struct of_device_id imxrt1050_clk_of_match[] = {
  142. { .compatible = "fsl,imxrt1050-ccm" },
  143. { /* Sentinel */ }
  144. };
  145. MODULE_DEVICE_TABLE(of, imxrt1050_clk_of_match);
  146. static struct platform_driver imxrt1050_clk_driver = {
  147. .probe = imxrt1050_clocks_probe,
  148. .driver = {
  149. .name = "imxrt1050-ccm",
  150. .of_match_table = imxrt1050_clk_of_match,
  151. },
  152. };
  153. module_platform_driver(imxrt1050_clk_driver);