2 * Copyright (c) 2013-2020 Arm Limited. All rights reserved.
4 * SPDX-License-Identifier: Apache-2.0
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #include "Driver_MCI.h"
21 #define ARM_MCI_DRV_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(1, 0) /* driver version */
24 static const ARM_DRIVER_VERSION DriverVersion = {
29 /* Driver Capabilities */
30 static const ARM_MCI_CAPABILITIES DriverCapabilities = {
41 0, /* data_width_4_ddr */
42 0, /* data_width_8_ddr */
44 0, /* uhs_signaling */
49 0, /* uhs_driver_type_a */
50 0, /* uhs_driver_type_c */
51 0, /* uhs_driver_type_d */
52 0, /* sdio_interrupt */
54 0, /* suspend_resume */
55 0, /* mmc_interrupt */
67 static ARM_DRIVER_VERSION ARM_MCI_GetVersion(void)
72 static ARM_MCI_CAPABILITIES ARM_MCI_GetCapabilities(void)
74 return DriverCapabilities;
77 static int32_t ARM_MCI_Initialize(ARM_MCI_SignalEvent_t cb_event)
81 static int32_t ARM_MCI_Uninitialize(void)
85 static int32_t ARM_MCI_PowerControl(ARM_POWER_STATE state)
98 return ARM_DRIVER_ERROR_UNSUPPORTED;
101 static int32_t ARM_MCI_CardPower(uint32_t voltage)
103 switch (voltage & ARM_MCI_POWER_VDD_Msk)
105 case ARM_MCI_POWER_VDD_OFF:
106 return ARM_DRIVER_OK;
108 case ARM_MCI_POWER_VDD_3V3:
109 return ARM_DRIVER_OK;
114 return ARM_DRIVER_ERROR;
117 static int32_t ARM_MCI_ReadCD(void)
121 static int32_t ARM_MCI_ReadWP(void)
125 static int32_t ARM_MCI_SendCommand(uint32_t cmd, uint32_t arg, uint32_t flags, uint32_t *response)
129 static int32_t ARM_MCI_SetupTransfer(uint8_t *data, uint32_t block_count, uint32_t block_size, uint32_t mode)
133 static int32_t ARM_MCI_AbortTransfer(void)
137 static int32_t ARM_MCI_Control(uint32_t control, uint32_t arg)
141 case ARM_MCI_BUS_SPEED:
144 case ARM_MCI_BUS_SPEED_MODE:
147 case ARM_MCI_BUS_CMD_MODE:
148 /* Implement external pull-up control to support MMC cards in open-drain mode */
149 /* Default mode is push-pull and is configured in Driver_MCI0.Initialize() */
150 if (arg == ARM_MCI_BUS_CMD_PUSH_PULL)
152 /* Configure external circuit to work in push-pull mode */
154 else if (arg == ARM_MCI_BUS_CMD_OPEN_DRAIN)
156 /* Configure external circuit to work in open-drain mode */
160 return ARM_DRIVER_ERROR_UNSUPPORTED;
164 case ARM_MCI_BUS_DATA_WIDTH:
167 case ARM_MCI_BUS_DATA_WIDTH_1:
169 case ARM_MCI_BUS_DATA_WIDTH_4:
171 case ARM_MCI_BUS_DATA_WIDTH_8:
174 return ARM_DRIVER_ERROR_UNSUPPORTED;
178 case ARM_MCI_CONTROL_RESET:
181 case ARM_MCI_CONTROL_CLOCK_IDLE:
184 case ARM_MCI_DATA_TIMEOUT:
187 case ARM_MCI_MONITOR_SDIO_INTERRUPT:
190 case ARM_MCI_CONTROL_READ_WAIT:
193 case ARM_MCI_DRIVER_STRENGTH:
194 default: return ARM_DRIVER_ERROR_UNSUPPORTED;
198 static ARM_MCI_STATUS ARM_MCI_GetStatus(void)
202 static void ARM_MCI_SignalEvent(uint32_t event)
210 ARM_DRIVER_MCI Driver_MCI0;
211 ARM_DRIVER_MCI Driver_MCI0 = {
213 ARM_MCI_GetCapabilities,
215 ARM_MCI_Uninitialize,
216 ARM_MCI_PowerControl,
221 ARM_MCI_SetupTransfer,
222 ARM_MCI_AbortTransfer,