fsl_reset.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  3. * Copyright (c) 2016, NXP
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * o Redistributions of source code must retain the above copyright notice, this list
  10. * of conditions and the following disclaimer.
  11. *
  12. * o Redistributions in binary form must reproduce the above copyright notice, this
  13. * list of conditions and the following disclaimer in the documentation and/or
  14. * other materials provided with the distribution.
  15. *
  16. * o Neither the name of copyright holder nor the names of its
  17. * contributors may be used to endorse or promote products derived from this
  18. * software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  21. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  22. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  24. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  25. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  26. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  27. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. #include "fsl_common.h"
  32. #include "fsl_reset.h"
  33. /*******************************************************************************
  34. * Definitions
  35. ******************************************************************************/
  36. /*******************************************************************************
  37. * Variables
  38. ******************************************************************************/
  39. /*******************************************************************************
  40. * Prototypes
  41. ******************************************************************************/
  42. /*******************************************************************************
  43. * Code
  44. ******************************************************************************/
  45. #if ((defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0)) || \
  46. (defined(FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT) && (FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT > 0)))
  47. void RESET_SetPeripheralReset(reset_ip_name_t peripheral)
  48. {
  49. const uint32_t regIndex = ((uint32_t)peripheral & 0xFFFF0000u) >> 16;
  50. const uint32_t bitPos = ((uint32_t)peripheral & 0x0000FFFFu);
  51. const uint32_t bitMask = 1u << bitPos;
  52. assert(bitPos < 32u);
  53. /* ASYNC_SYSCON registers have offset 1024 */
  54. if (regIndex >= SYSCON_PRESETCTRL_COUNT)
  55. {
  56. /* reset register is in ASYNC_SYSCON */
  57. /* set bit */
  58. ASYNC_SYSCON->ASYNCPRESETCTRLSET = bitMask;
  59. /* wait until it reads 0b1 */
  60. while (0u == (ASYNC_SYSCON->ASYNCPRESETCTRL & bitMask))
  61. {
  62. }
  63. }
  64. else
  65. {
  66. /* reset register is in SYSCON */
  67. /* set bit */
  68. SYSCON->PRESETCTRLSET[regIndex] = bitMask;
  69. /* wait until it reads 0b1 */
  70. while (0u == (SYSCON->PRESETCTRL[regIndex] & bitMask))
  71. {
  72. }
  73. }
  74. }
  75. void RESET_ClearPeripheralReset(reset_ip_name_t peripheral)
  76. {
  77. const uint32_t regIndex = ((uint32_t)peripheral & 0xFFFF0000u) >> 16;
  78. const uint32_t bitPos = ((uint32_t)peripheral & 0x0000FFFFu);
  79. const uint32_t bitMask = 1u << bitPos;
  80. assert(bitPos < 32u);
  81. /* ASYNC_SYSCON registers have offset 1024 */
  82. if (regIndex >= SYSCON_PRESETCTRL_COUNT)
  83. {
  84. /* reset register is in ASYNC_SYSCON */
  85. /* clear bit */
  86. ASYNC_SYSCON->ASYNCPRESETCTRLCLR = bitMask;
  87. /* wait until it reads 0b0 */
  88. while (bitMask == (ASYNC_SYSCON->ASYNCPRESETCTRL & bitMask))
  89. {
  90. }
  91. }
  92. else
  93. {
  94. /* reset register is in SYSCON */
  95. /* clear bit */
  96. SYSCON->PRESETCTRLCLR[regIndex] = bitMask;
  97. /* wait until it reads 0b0 */
  98. while (bitMask == (SYSCON->PRESETCTRL[regIndex] & bitMask))
  99. {
  100. }
  101. }
  102. }
  103. void RESET_PeripheralReset(reset_ip_name_t peripheral)
  104. {
  105. RESET_SetPeripheralReset(peripheral);
  106. RESET_ClearPeripheralReset(peripheral);
  107. }
  108. #endif /* FSL_FEATURE_SOC_SYSCON_COUNT || FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT */