fsl_reset.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  4. * Copyright (c) 2016, NXP
  5. * All rights reserved.
  6. *
  7. *
  8. * Redistribution and use in source and binary forms, with or without modification,
  9. * are permitted (subject to the limitations in the disclaimer below) provided
  10. * that the following conditions are met:
  11. *
  12. * o Redistributions of source code must retain the above copyright notice, this list
  13. * of conditions and the following disclaimer.
  14. *
  15. * o Redistributions in binary form must reproduce the above copyright notice, this
  16. * list of conditions and the following disclaimer in the documentation and/or
  17. * other materials provided with the distribution.
  18. *
  19. * o Neither the name of copyright holder nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  25. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  26. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  28. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  29. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  30. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  31. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include "fsl_common.h"
  36. #include "fsl_reset.h"
  37. /*******************************************************************************
  38. * Definitions
  39. ******************************************************************************/
  40. /* Component ID definition, used by tools. */
  41. #ifndef FSL_COMPONENT_ID
  42. #define FSL_COMPONENT_ID "platform.drivers.reset"
  43. #endif
  44. /*******************************************************************************
  45. * Variables
  46. ******************************************************************************/
  47. /*******************************************************************************
  48. * Prototypes
  49. ******************************************************************************/
  50. /*******************************************************************************
  51. * Code
  52. ******************************************************************************/
  53. #if ((defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0)) || \
  54. (defined(FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT) && (FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT > 0)))
  55. void RESET_SetPeripheralReset(reset_ip_name_t peripheral)
  56. {
  57. const uint32_t regIndex = ((uint32_t)peripheral & 0xFFFF0000u) >> 16;
  58. const uint32_t bitPos = ((uint32_t)peripheral & 0x0000FFFFu);
  59. const uint32_t bitMask = 1u << bitPos;
  60. assert(bitPos < 32u);
  61. /* ASYNC_SYSCON registers have offset 1024 */
  62. if (regIndex >= SYSCON_PRESETCTRL_COUNT)
  63. {
  64. /* reset register is in ASYNC_SYSCON */
  65. /* set bit */
  66. ASYNC_SYSCON->ASYNCPRESETCTRLSET = bitMask;
  67. /* wait until it reads 0b1 */
  68. while (0u == (ASYNC_SYSCON->ASYNCPRESETCTRL & bitMask))
  69. {
  70. }
  71. }
  72. else
  73. {
  74. /* reset register is in SYSCON */
  75. /* set bit */
  76. SYSCON->PRESETCTRLSET[regIndex] = bitMask;
  77. /* wait until it reads 0b1 */
  78. while (0u == (SYSCON->PRESETCTRL[regIndex] & bitMask))
  79. {
  80. }
  81. }
  82. }
  83. void RESET_ClearPeripheralReset(reset_ip_name_t peripheral)
  84. {
  85. const uint32_t regIndex = ((uint32_t)peripheral & 0xFFFF0000u) >> 16;
  86. const uint32_t bitPos = ((uint32_t)peripheral & 0x0000FFFFu);
  87. const uint32_t bitMask = 1u << bitPos;
  88. assert(bitPos < 32u);
  89. /* ASYNC_SYSCON registers have offset 1024 */
  90. if (regIndex >= SYSCON_PRESETCTRL_COUNT)
  91. {
  92. /* reset register is in ASYNC_SYSCON */
  93. /* clear bit */
  94. ASYNC_SYSCON->ASYNCPRESETCTRLCLR = bitMask;
  95. /* wait until it reads 0b0 */
  96. while (bitMask == (ASYNC_SYSCON->ASYNCPRESETCTRL & bitMask))
  97. {
  98. }
  99. }
  100. else
  101. {
  102. /* reset register is in SYSCON */
  103. /* clear bit */
  104. SYSCON->PRESETCTRLCLR[regIndex] = bitMask;
  105. /* wait until it reads 0b0 */
  106. while (bitMask == (SYSCON->PRESETCTRL[regIndex] & bitMask))
  107. {
  108. }
  109. }
  110. }
  111. void RESET_PeripheralReset(reset_ip_name_t peripheral)
  112. {
  113. RESET_SetPeripheralReset(peripheral);
  114. RESET_ClearPeripheralReset(peripheral);
  115. }
  116. void RESET_SetSlaveCoreReset(void)
  117. {
  118. uint32_t cpuctrl = (SYSCON->CPUCTRL & ~0x7F80U) | 0xC0C48000U;
  119. /* CM4 is the master. */
  120. if (cpuctrl & SYSCON_CPUCTRL_MASTERCPU_MASK)
  121. {
  122. SYSCON->CPUCTRL = cpuctrl | SYSCON_CPUCTRL_CM0RSTEN_MASK;
  123. }
  124. /* CM0 is the master. */
  125. else
  126. {
  127. SYSCON->CPUCTRL = cpuctrl | SYSCON_CPUCTRL_CM4RSTEN_MASK;
  128. }
  129. }
  130. void RESET_ClearSlaveCoreReset(void)
  131. {
  132. uint32_t cpuctrl = (SYSCON->CPUCTRL & ~0x7F80U) | 0xC0C48000U;
  133. /* CM4 is the master. */
  134. if (cpuctrl & SYSCON_CPUCTRL_MASTERCPU_MASK)
  135. {
  136. SYSCON->CPUCTRL = cpuctrl & ~SYSCON_CPUCTRL_CM0RSTEN_MASK;
  137. }
  138. /* CM0 is the master. */
  139. else
  140. {
  141. SYSCON->CPUCTRL = cpuctrl & ~SYSCON_CPUCTRL_CM4RSTEN_MASK;
  142. }
  143. }
  144. void RESET_SlaveCoreReset(uint32_t bootAddr, uint32_t bootStackPointer)
  145. {
  146. volatile uint32_t i = 10U;
  147. SYSCON->CPSTACK = bootStackPointer;
  148. SYSCON->CPBOOT = bootAddr;
  149. RESET_SetSlaveCoreReset();
  150. while(i--){}
  151. RESET_ClearSlaveCoreReset();
  152. }
  153. #endif /* FSL_FEATURE_SOC_SYSCON_COUNT || FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT */