imx_clock.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stdint.h>
  7. #include <stdbool.h>
  8. #include <arch.h>
  9. #include <lib/mmio.h>
  10. #include <imx_regs.h>
  11. #include <imx_clock.h>
  12. void imx_clock_target_set(unsigned int id, uint32_t val)
  13. {
  14. struct ccm *ccm = ((struct ccm *)CCM_BASE);
  15. uintptr_t addr;
  16. if (id > CCM_ROOT_CTRL_NUM)
  17. return;
  18. addr = (uintptr_t)&ccm->ccm_root_ctrl[id].ccm_target_root;
  19. mmio_write_32(addr, val);
  20. }
  21. void imx_clock_target_clr(unsigned int id, uint32_t val)
  22. {
  23. struct ccm *ccm = ((struct ccm *)CCM_BASE);
  24. uintptr_t addr;
  25. if (id > CCM_ROOT_CTRL_NUM)
  26. return;
  27. addr = (uintptr_t)&ccm->ccm_root_ctrl[id].ccm_target_root_clr;
  28. mmio_write_32(addr, val);
  29. }
  30. void imx_clock_gate_enable(unsigned int id, bool enable)
  31. {
  32. struct ccm *ccm = ((struct ccm *)CCM_BASE);
  33. uintptr_t addr;
  34. if (id > CCM_CLK_GATE_CTRL_NUM)
  35. return;
  36. /* TODO: add support for more than DOMAIN0 clocks */
  37. if (enable)
  38. addr = (uintptr_t)&ccm->ccm_clk_gate_ctrl[id].ccm_ccgr_set;
  39. else
  40. addr = (uintptr_t)&ccm->ccm_clk_gate_ctrl[id].ccm_ccgr_clr;
  41. mmio_write_32(addr, CCM_CCGR_SETTING0_DOM_CLK_ALWAYS);
  42. }
  43. void imx_clock_enable_uart(unsigned int uart_id, uint32_t uart_clk_en_bits)
  44. {
  45. unsigned int ccm_trgt_id = CCM_TRT_ID_UART1_CLK_ROOT + uart_id;
  46. unsigned int ccm_ccgr_id = CCM_CCGR_ID_UART1 + uart_id;
  47. /* Check for error */
  48. if (uart_id > MXC_MAX_UART_NUM)
  49. return;
  50. /* Set target register values */
  51. imx_clock_target_set(ccm_trgt_id, uart_clk_en_bits);
  52. /* Enable the clock gate */
  53. imx_clock_gate_enable(ccm_ccgr_id, true);
  54. }
  55. void imx_clock_disable_uart(unsigned int uart_id)
  56. {
  57. unsigned int ccm_trgt_id = CCM_TRT_ID_UART1_CLK_ROOT + uart_id;
  58. unsigned int ccm_ccgr_id = CCM_CCGR_ID_UART1 + uart_id;
  59. /* Check for error */
  60. if (uart_id > MXC_MAX_UART_NUM)
  61. return;
  62. /* Disable the clock gate */
  63. imx_clock_gate_enable(ccm_ccgr_id, false);
  64. /* Clear the target */
  65. imx_clock_target_clr(ccm_trgt_id, 0xFFFFFFFF);
  66. }
  67. void imx_clock_enable_usdhc(unsigned int usdhc_id, uint32_t usdhc_clk_en_bits)
  68. {
  69. unsigned int ccm_trgt_id = CCM_TRT_ID_USDHC1_CLK_ROOT + usdhc_id;
  70. unsigned int ccm_ccgr_id = CCM_CCGR_ID_USBHDC1 + usdhc_id;
  71. /* Check for error */
  72. if (usdhc_id > MXC_MAX_USDHC_NUM)
  73. return;
  74. /* Set target register values */
  75. imx_clock_target_set(ccm_trgt_id, usdhc_clk_en_bits);
  76. /* Enable the clock gate */
  77. imx_clock_gate_enable(ccm_ccgr_id, true);
  78. }
  79. void imx_clock_enable_wdog(unsigned int wdog_id)
  80. {
  81. unsigned int ccm_ccgr_id = CCM_CCGR_ID_WDOG1 + wdog_id;
  82. /* Check for error */
  83. if (wdog_id > MXC_MAX_WDOG_NUM)
  84. return;
  85. /* Enable the clock gate */
  86. imx_clock_gate_enable(ccm_ccgr_id, true);
  87. }
  88. void imx_clock_disable_wdog(unsigned int wdog_id)
  89. {
  90. unsigned int ccm_trgt_id = CCM_TRT_ID_WDOG_CLK_ROOT;
  91. unsigned int ccm_ccgr_id = CCM_CCGR_ID_WDOG1 + wdog_id;
  92. /* Check for error */
  93. if (wdog_id > MXC_MAX_WDOG_NUM)
  94. return;
  95. /* Disable the clock gate */
  96. imx_clock_gate_enable(ccm_ccgr_id, false);
  97. /* Clear the target */
  98. imx_clock_target_clr(ccm_trgt_id, 0xFFFFFFFF);
  99. }
  100. void imx_clock_set_wdog_clk_root_bits(uint32_t wdog_clk_root_en_bits)
  101. {
  102. /* Enable the common clock root just once */
  103. imx_clock_target_set(CCM_TRT_ID_WDOG_CLK_ROOT, wdog_clk_root_en_bits);
  104. }
  105. void imx_clock_enable_usb(unsigned int ccm_ccgr_usb_id)
  106. {
  107. /* Enable the clock gate */
  108. imx_clock_gate_enable(ccm_ccgr_usb_id, true);
  109. }
  110. void imx_clock_disable_usb(unsigned int ccm_ccgr_usb_id)
  111. {
  112. /* Disable the clock gate */
  113. imx_clock_gate_enable(ccm_ccgr_usb_id, false);
  114. }
  115. void imx_clock_set_usb_clk_root_bits(uint32_t usb_clk_root_en_bits)
  116. {
  117. /* Enable the common clock root just once */
  118. imx_clock_target_set(CCM_TRT_ID_USB_HSIC_CLK_ROOT, usb_clk_root_en_bits);
  119. }