2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
8 * o Redistributions of source code must retain the above copyright notice, this list
9 * of conditions and the following disclaimer.
11 * o Redistributions in binary form must reproduce the above copyright notice, this
12 * list of conditions and the following disclaimer in the documentation and/or
13 * other materials provided with the distribution.
15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "fsl_sdhc_hal.h"
34 /*FUNCTION****************************************************************
36 * Function Name: SDHC_HAL_Init
37 * Description: Initialize sdhc hal
39 *END*********************************************************************/
40 void SDHC_HAL_Init(uint32_t baseAddr)
42 SDHC_HAL_SetSdClock(baseAddr, false);
43 SDHC_HAL_SetExternalDmaRequest(baseAddr, false);
44 SDHC_HAL_SetIntState(baseAddr, false, (uint32_t)-1);
45 SDHC_HAL_SetIntSignal(baseAddr, false, (uint32_t)-1);
48 /*FUNCTION****************************************************************
50 * Function Name: SDHC_HAL_SetIntSignal
51 * Description: Enable specified interrupts
53 *END*********************************************************************/
54 void SDHC_HAL_SetIntSignal(uint32_t baseAddr, bool enable, uint32_t mask)
58 HW_SDHC_IRQSIGEN_SET(baseAddr, mask);
62 HW_SDHC_IRQSIGEN_CLR(baseAddr, mask);
66 /*FUNCTION****************************************************************
68 * Function Name: SDHC_HAL_SetIntState
69 * Description: Enable specified interrupts' state
71 *END*********************************************************************/
72 void SDHC_HAL_SetIntState(uint32_t baseAddr, bool enable, uint32_t mask)
76 HW_SDHC_IRQSTATEN_SET(baseAddr, mask);
80 HW_SDHC_IRQSTATEN_CLR(baseAddr, mask);
84 /*FUNCTION****************************************************************
86 * Function Name: SDHC_HAL_GetResponse
87 * Description: get command response
89 *END*********************************************************************/
90 uint32_t SDHC_HAL_GetResponse(uint32_t baseAddr, uint32_t index)
99 ret = BR_SDHC_CMDRSP0_CMDRSP0(baseAddr);
102 ret = BR_SDHC_CMDRSP1_CMDRSP1(baseAddr);
105 ret = BR_SDHC_CMDRSP2_CMDRSP2(baseAddr);
108 ret = BR_SDHC_CMDRSP3_CMDRSP3(baseAddr);
117 /*FUNCTION****************************************************************
119 * Function Name: SDHC_HAL_InitCard
120 * Description: Initialize card by sending 80 clocks to card
122 *END*********************************************************************/
123 uint32_t SDHC_HAL_InitCard(uint32_t baseAddr, uint32_t timeout)
126 BW_SDHC_SYSCTL_INITA(baseAddr, 1);
127 while((!BR_SDHC_SYSCTL_INITA(baseAddr)))
138 /*FUNCTION****************************************************************
140 * Function Name: SDHC_HAL_Reset
141 * Description: Perform different kinds of reset
143 *END*********************************************************************/
144 uint32_t SDHC_HAL_Reset(uint32_t baseAddr, uint32_t type, uint32_t timeout)
148 mask = type & (BM_SDHC_SYSCTL_RSTA
149 | BM_SDHC_SYSCTL_RSTC
150 | BM_SDHC_SYSCTL_RSTD);
151 HW_SDHC_SYSCTL_SET(baseAddr, mask);
152 while (!(HW_SDHC_SYSCTL_RD(baseAddr) & mask))
163 #endif /* MBED_NO_SDHC */
165 /*************************************************************************************************
167 ************************************************************************************************/