1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #include "fsl_dmamux.h"
10 
11 /*******************************************************************************
12  * Definitions
13  ******************************************************************************/
14 
15 /* Component ID definition, used by tools. */
16 #ifndef FSL_COMPONENT_ID
17 #define FSL_COMPONENT_ID "platform.drivers.dmamux"
18 #endif
19 
20 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
21 /*******************************************************************************
22  * Prototypes
23  ******************************************************************************/
24 
25 /*!
26  * @brief Get instance number for DMAMUX.
27  *
28  * @param base DMAMUX peripheral base address.
29  */
30 static uint32_t DMAMUX_GetInstance(DMAMUX_Type *base);
31 
32 /*******************************************************************************
33  * Variables
34  ******************************************************************************/
35 
36 /*! @brief Array to map DMAMUX instance number to base pointer. */
37 static DMAMUX_Type *const s_dmamuxBases[] = DMAMUX_BASE_PTRS;
38 
39 /*! @brief Array to map DMAMUX instance number to clock name. */
40 static const clock_ip_name_t s_dmamuxClockName[] = DMAMUX_CLOCKS;
41 
42 /*******************************************************************************
43  * Code
44  ******************************************************************************/
DMAMUX_GetInstance(DMAMUX_Type * base)45 static uint32_t DMAMUX_GetInstance(DMAMUX_Type *base)
46 {
47     uint32_t instance;
48 
49     /* Find the instance index from base address mappings. */
50     for (instance = 0; instance < ARRAY_SIZE(s_dmamuxBases); instance++)
51     {
52         if (s_dmamuxBases[instance] == base)
53         {
54             break;
55         }
56     }
57 
58     assert(instance < ARRAY_SIZE(s_dmamuxBases));
59 
60     return instance;
61 }
62 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
63 
64 /*!
65  * brief Initializes the DMAMUX peripheral.
66  *
67  * This function ungates the DMAMUX clock.
68  *
69  * param base DMAMUX peripheral base address.
70  *
71  */
DMAMUX_Init(DMAMUX_Type * base)72 void DMAMUX_Init(DMAMUX_Type *base)
73 {
74 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
75     CLOCK_EnableClock(s_dmamuxClockName[DMAMUX_GetInstance(base)]);
76 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
77 }
78 
79 /*!
80  * brief Deinitializes the DMAMUX peripheral.
81  *
82  * This function gates the DMAMUX clock.
83  *
84  * param base DMAMUX peripheral base address.
85  */
DMAMUX_Deinit(DMAMUX_Type * base)86 void DMAMUX_Deinit(DMAMUX_Type *base)
87 {
88 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
89     CLOCK_DisableClock(s_dmamuxClockName[DMAMUX_GetInstance(base)]);
90 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
91 }
92