1 /*
2  * Copyright 2017, NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #include "fsl_common.h"
9 #include "fsl_reset.h"
10 
11 /*******************************************************************************
12  * Definitions
13  ******************************************************************************/
14 /* Component ID definition, used by tools. */
15 #ifndef FSL_COMPONENT_ID
16 #define FSL_COMPONENT_ID "platform.drivers.reset"
17 #endif
18 
19 /*******************************************************************************
20  * Variables
21  ******************************************************************************/
22 
23 /*******************************************************************************
24  * Prototypes
25  ******************************************************************************/
26 
27 /*!
28 * @brief Assert reset to peripheral.
29 *
30 * Asserts reset signal to specified peripheral module.
31 *
32 * @param peripheral Assert reset to this peripheral. The enum argument contains encoding of reset register
33 *                   and reset bit position in the reset register.
34 */
35 static void RESET_SetPeripheralReset(reset_ip_name_t peripheral);
36 
37 /*!
38  * @brief Clear reset to peripheral.
39  *
40  * Clears reset signal to specified peripheral module, allows it to operate.
41  *
42  * @param peripheral Clear reset to this peripheral. The enum argument contains encoding of reset register
43  *                   and reset bit position in the reset register.
44  */
45 static void RESET_ClearPeripheralReset(reset_ip_name_t peripheral);
46 
47 /*******************************************************************************
48  * Code
49  ******************************************************************************/
50 
51 #if ((defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0)) || \
52      (defined(FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT) && (FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT > 0)))
53 
RESET_SetPeripheralReset(reset_ip_name_t peripheral)54 static void RESET_SetPeripheralReset(reset_ip_name_t peripheral)
55 {
56     const uint32_t bitPos = ((uint32_t)peripheral & 0x0000FFFFu);
57     const uint32_t bitMask = 1UL << bitPos;
58 
59     assert(bitPos < 32UL);
60 
61     /* reset register is in SYSCON */
62     /* set bit */
63     SYSCON->PRESETCTRL &= ~bitMask;
64 }
65 
RESET_ClearPeripheralReset(reset_ip_name_t peripheral)66 static void RESET_ClearPeripheralReset(reset_ip_name_t peripheral)
67 {
68     const uint32_t bitPos = ((uint32_t)peripheral & 0x0000FFFFu);
69     const uint32_t bitMask = 1UL << bitPos;
70 
71     assert(bitPos < 32UL);
72 
73     /* reset register is in SYSCON */
74     /* clear bit */
75     SYSCON->PRESETCTRL |= bitMask;
76 }
77 
78 /*!
79  * brief Reset peripheral module.
80  *
81  * Reset peripheral module.
82  *
83  * param peripheral Peripheral to reset. The enum argument contains encoding of reset register
84  *                   and reset bit position in the reset register.
85  */
RESET_PeripheralReset(reset_ip_name_t peripheral)86 void RESET_PeripheralReset(reset_ip_name_t peripheral)
87 {
88     RESET_SetPeripheralReset(peripheral);
89     RESET_ClearPeripheralReset(peripheral);
90 }
91 
92 #endif /* FSL_FEATURE_SOC_SYSCON_COUNT || FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT */
93