s32cc_early_clks.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * Copyright 2024 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <drivers/clk.h>
  7. #include <platform_def.h>
  8. #include <s32cc-clk-drv.h>
  9. #include <s32cc-clk-ids.h>
  10. #include <s32cc-clk-utils.h>
  11. #define S32CC_FXOSC_FREQ (40U * MHZ)
  12. #define S32CC_ARM_PLL_VCO_FREQ (2U * GHZ)
  13. #define S32CC_ARM_PLL_PHI0_FREQ (1U * GHZ)
  14. #define S32CC_A53_FREQ (1U * GHZ)
  15. #define S32CC_XBAR_2X_FREQ (800U * MHZ)
  16. #define S32CC_PERIPH_PLL_VCO_FREQ (2U * GHZ)
  17. #define S32CC_PERIPH_PLL_PHI3_FREQ UART_CLOCK_HZ
  18. #define S32CC_DDR_PLL_VCO_FREQ (1600U * MHZ)
  19. #define S32CC_DDR_PLL_PHI0_FREQ (800U * MHZ)
  20. static int setup_fxosc(void)
  21. {
  22. int ret;
  23. ret = clk_set_rate(S32CC_CLK_FXOSC, S32CC_FXOSC_FREQ, NULL);
  24. if (ret != 0) {
  25. return ret;
  26. }
  27. return ret;
  28. }
  29. static int setup_arm_pll(void)
  30. {
  31. int ret;
  32. ret = clk_set_parent(S32CC_CLK_ARM_PLL_MUX, S32CC_CLK_FXOSC);
  33. if (ret != 0) {
  34. return ret;
  35. }
  36. ret = clk_set_rate(S32CC_CLK_ARM_PLL_VCO, S32CC_ARM_PLL_VCO_FREQ, NULL);
  37. if (ret != 0) {
  38. return ret;
  39. }
  40. ret = clk_set_rate(S32CC_CLK_ARM_PLL_PHI0, S32CC_ARM_PLL_PHI0_FREQ, NULL);
  41. if (ret != 0) {
  42. return ret;
  43. }
  44. return ret;
  45. }
  46. static int setup_periph_pll(void)
  47. {
  48. int ret;
  49. ret = clk_set_parent(S32CC_CLK_PERIPH_PLL_MUX, S32CC_CLK_FXOSC);
  50. if (ret != 0) {
  51. return ret;
  52. }
  53. ret = clk_set_rate(S32CC_CLK_PERIPH_PLL_VCO, S32CC_PERIPH_PLL_VCO_FREQ, NULL);
  54. if (ret != 0) {
  55. return ret;
  56. }
  57. ret = clk_set_rate(S32CC_CLK_PERIPH_PLL_PHI3, S32CC_PERIPH_PLL_PHI3_FREQ, NULL);
  58. if (ret != 0) {
  59. return ret;
  60. }
  61. return ret;
  62. }
  63. static int enable_a53_clk(void)
  64. {
  65. int ret;
  66. ret = clk_set_parent(S32CC_CLK_MC_CGM1_MUX0, S32CC_CLK_ARM_PLL_PHI0);
  67. if (ret != 0) {
  68. return ret;
  69. }
  70. ret = clk_set_rate(S32CC_CLK_A53_CORE, S32CC_A53_FREQ, NULL);
  71. if (ret != 0) {
  72. return ret;
  73. }
  74. ret = clk_enable(S32CC_CLK_A53_CORE);
  75. if (ret != 0) {
  76. return ret;
  77. }
  78. return ret;
  79. }
  80. static int enable_xbar_clk(void)
  81. {
  82. int ret;
  83. ret = clk_set_parent(S32CC_CLK_MC_CGM0_MUX0, S32CC_CLK_ARM_PLL_DFS1);
  84. if (ret != 0) {
  85. return ret;
  86. }
  87. ret = clk_set_rate(S32CC_CLK_XBAR_2X, S32CC_XBAR_2X_FREQ, NULL);
  88. if (ret != 0) {
  89. return ret;
  90. }
  91. ret = clk_enable(S32CC_CLK_ARM_PLL_DFS1);
  92. if (ret != 0) {
  93. return ret;
  94. }
  95. ret = clk_enable(S32CC_CLK_XBAR_2X);
  96. if (ret != 0) {
  97. return ret;
  98. }
  99. return ret;
  100. }
  101. static int enable_uart_clk(void)
  102. {
  103. int ret;
  104. ret = clk_set_parent(S32CC_CLK_MC_CGM0_MUX8, S32CC_CLK_PERIPH_PLL_PHI3);
  105. if (ret != 0) {
  106. return ret;
  107. }
  108. ret = clk_enable(S32CC_CLK_LINFLEX_BAUD);
  109. if (ret != 0) {
  110. return ret;
  111. }
  112. return ret;
  113. }
  114. static int setup_ddr_pll(void)
  115. {
  116. int ret;
  117. ret = clk_set_parent(S32CC_CLK_DDR_PLL_MUX, S32CC_CLK_FXOSC);
  118. if (ret != 0) {
  119. return ret;
  120. }
  121. ret = clk_set_rate(S32CC_CLK_DDR_PLL_VCO, S32CC_DDR_PLL_VCO_FREQ, NULL);
  122. if (ret != 0) {
  123. return ret;
  124. }
  125. ret = clk_set_rate(S32CC_CLK_DDR_PLL_PHI0, S32CC_DDR_PLL_PHI0_FREQ, NULL);
  126. if (ret != 0) {
  127. return ret;
  128. }
  129. return ret;
  130. }
  131. static int enable_ddr_clk(void)
  132. {
  133. int ret;
  134. ret = clk_set_parent(S32CC_CLK_MC_CGM5_MUX0, S32CC_CLK_DDR_PLL_PHI0);
  135. if (ret != 0) {
  136. return ret;
  137. }
  138. ret = clk_enable(S32CC_CLK_DDR);
  139. if (ret != 0) {
  140. return ret;
  141. }
  142. return ret;
  143. }
  144. int s32cc_init_early_clks(void)
  145. {
  146. int ret;
  147. s32cc_clk_register_drv();
  148. ret = setup_fxosc();
  149. if (ret != 0) {
  150. return ret;
  151. }
  152. ret = setup_arm_pll();
  153. if (ret != 0) {
  154. return ret;
  155. }
  156. ret = enable_a53_clk();
  157. if (ret != 0) {
  158. return ret;
  159. }
  160. ret = enable_xbar_clk();
  161. if (ret != 0) {
  162. return ret;
  163. }
  164. ret = setup_periph_pll();
  165. if (ret != 0) {
  166. return ret;
  167. }
  168. ret = enable_uart_clk();
  169. if (ret != 0) {
  170. return ret;
  171. }
  172. ret = setup_ddr_pll();
  173. if (ret != 0) {
  174. return ret;
  175. }
  176. ret = enable_ddr_clk();
  177. if (ret != 0) {
  178. return ret;
  179. }
  180. return ret;
  181. }