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/*******************************************************************************
21 * Prototypes
22 ******************************************************************************/
23
24/*!
25 * @brief Get instance number for DMAMUX.
26 *
27 * @param base DMAMUX peripheral base address.
28 */
29static uint32_t DMAMUX_GetInstance(DMAMUX_Type *base);
30
31/*******************************************************************************
32 * Variables
33 ******************************************************************************/
34
35/*! @brief Array to map DMAMUX instance number to base pointer. */
36static DMAMUX_Type *const s_dmamuxBases[] = DMAMUX_BASE_PTRS;
37
38#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
39/*! @brief Array to map DMAMUX instance number to clock name. */
40static const clock_ip_name_t s_dmamuxClockName[] = DMAMUX_CLOCKS;
41#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
42
43/*******************************************************************************
44 * Code
45 ******************************************************************************/
46static uint32_t DMAMUX_GetInstance(DMAMUX_Type *base)
47{
48 uint32_t instance;
49
50 /* Find the instance index from base address mappings. */
51 for (instance = 0; instance < ARRAY_SIZE(s_dmamuxBases); instance++)
52 {
53 if (s_dmamuxBases[instance] == base)
54 {
55 break;
56 }
57 }
58
59 assert(instance < ARRAY_SIZE(s_dmamuxBases));
60
61 return instance;
62}
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 */
72void 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 */
86void 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