2 * Copyright (c) 2013-2016 ARM Limited. All rights reserved.
\r
4 * SPDX-License-Identifier: Apache-2.0
\r
6 * Licensed under the Apache License, Version 2.0 (the License); you may
\r
7 * not use this file except in compliance with the License.
\r
8 * You may obtain a copy of the License at
\r
10 * http://www.apache.org/licenses/LICENSE-2.0
\r
12 * Unless required by applicable law or agreed to in writing, software
\r
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
\r
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
15 * See the License for the specific language governing permissions and
\r
16 * limitations under the License.
\r
18 * $Date: 16. May 2014
\r
21 * Project: MCI (Memory Card Interface) Driver definitions
\r
26 * Added timeout and error flags to ARM_MCI_STATUS
\r
27 * Added support for controlling optional RST_n pin (eMMC)
\r
28 * Removed explicit Clock Control (ARM_MCI_CONTROL_CLOCK)
\r
29 * Removed event ARM_MCI_EVENT_BOOT_ACK_TIMEOUT
\r
31 * Decoupled SPI mode from MCI driver
\r
32 * Replaced function ARM_MCI_CardSwitchRead with ARM_MCI_ReadCD and ARM_MCI_ReadWP
\r
34 * Added support for:
\r
35 * SD UHS-I (Ultra High Speed)
\r
37 * Read Wait (SD I/O)
\r
38 * Suspend/Resume (SD I/O)
\r
41 * Stream Data transfer (MMC)
\r
42 * VCCQ Power Supply Control (eMMC)
\r
43 * Command Completion Signal (CCS) for CE-ATA
\r
44 * Added ARM_MCI_Control function
\r
45 * Added ARM_MCI_GetStatus function
\r
46 * Removed ARM_MCI_BusMode, ARM_MCI_BusDataWidth, ARM_MCI_BusSingaling functions
\r
47 * (replaced by ARM_MCI_Control)
\r
48 * Changed ARM_MCI_CardPower function (voltage parameter)
\r
49 * Changed ARM_MCI_SendCommnad function (flags parameter)
\r
50 * Changed ARM_MCI_SetupTransfer function (mode parameter)
\r
51 * Removed ARM_MCI_ReadTransfer and ARM_MCI_WriteTransfer functions
\r
52 * Changed prefix ARM_DRV -> ARM_DRIVER
\r
53 * Changed return values of some functions to int32_t
\r
55 * Namespace prefix ARM_ added
\r
60 #ifndef __DRIVER_MCI_H
\r
61 #define __DRIVER_MCI_H
\r
63 #include "Driver_Common.h"
\r
65 #define ARM_MCI_API_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(2,02) /* API version */
\r
68 /****** MCI Send Command Flags *****/
\r
69 #define ARM_MCI_RESPONSE_Pos 0
\r
70 #define ARM_MCI_RESPONSE_Msk (3UL << ARM_MCI_RESPONSE_Pos)
\r
71 #define ARM_MCI_RESPONSE_NONE (0UL << ARM_MCI_RESPONSE_Pos) ///< No response expected (default)
\r
72 #define ARM_MCI_RESPONSE_SHORT (1UL << ARM_MCI_RESPONSE_Pos) ///< Short response (48-bit)
\r
73 #define ARM_MCI_RESPONSE_SHORT_BUSY (2UL << ARM_MCI_RESPONSE_Pos) ///< Short response with busy signal (48-bit)
\r
74 #define ARM_MCI_RESPONSE_LONG (3UL << ARM_MCI_RESPONSE_Pos) ///< Long response (136-bit)
\r
76 #define ARM_MCI_RESPONSE_INDEX (1UL << 2) ///< Check command index in response
\r
77 #define ARM_MCI_RESPONSE_CRC (1UL << 3) ///< Check CRC in response
\r
79 #define ARM_MCI_WAIT_BUSY (1UL << 4) ///< Wait until busy before sending the command
\r
81 #define ARM_MCI_TRANSFER_DATA (1UL << 5) ///< Activate Data transfer
\r
83 #define ARM_MCI_CARD_INITIALIZE (1UL << 6) ///< Execute Memory Card initialization sequence
\r
85 #define ARM_MCI_INTERRUPT_COMMAND (1UL << 7) ///< Send Interrupt command (CMD40 - MMC only)
\r
86 #define ARM_MCI_INTERRUPT_RESPONSE (1UL << 8) ///< Send Interrupt response (CMD40 - MMC only)
\r
88 #define ARM_MCI_BOOT_OPERATION (1UL << 9) ///< Execute Boot operation (MMC only)
\r
89 #define ARM_MCI_BOOT_ALTERNATIVE (1UL << 10) ///< Execute Alternative Boot operation (MMC only)
\r
90 #define ARM_MCI_BOOT_ACK (1UL << 11) ///< Expect Boot Acknowledge (MMC only)
\r
92 #define ARM_MCI_CCSD (1UL << 12) ///< Send Command Completion Signal Disable (CCSD) for CE-ATA device
\r
93 #define ARM_MCI_CCS (1UL << 13) ///< Expect Command Completion Signal (CCS) for CE-ATA device
\r
96 /****** MCI Setup Transfer Mode *****/
\r
97 #define ARM_MCI_TRANSFER_READ (0UL << 0) ///< Data Read Transfer (from MCI)
\r
98 #define ARM_MCI_TRANSFER_WRITE (1UL << 0) ///< Data Write Transfer (to MCI)
\r
99 #define ARM_MCI_TRANSFER_BLOCK (0UL << 1) ///< Block Data transfer (default)
\r
100 #define ARM_MCI_TRANSFER_STREAM (1UL << 1) ///< Stream Data transfer (MMC only)
\r
103 /****** MCI Control Codes *****/
\r
104 #define ARM_MCI_BUS_SPEED (0x01) ///< Set Bus Speed; arg = requested speed in bits/s; returns configured speed in bits/s
\r
105 #define ARM_MCI_BUS_SPEED_MODE (0x02) ///< Set Bus Speed Mode as specified with arg
\r
106 #define ARM_MCI_BUS_CMD_MODE (0x03) ///< Set CMD Line Mode as specified with arg
\r
107 #define ARM_MCI_BUS_DATA_WIDTH (0x04) ///< Set Bus Data Width as specified with arg
\r
108 #define ARM_MCI_DRIVER_STRENGTH (0x05) ///< Set SD UHS-I Driver Strength as specified with arg
\r
109 #define ARM_MCI_CONTROL_RESET (0x06) ///< Control optional RST_n Pin (eMMC); arg: 0=inactive, 1=active
\r
110 #define ARM_MCI_CONTROL_CLOCK_IDLE (0x07) ///< Control Clock generation on CLK Pin when idle; arg: 0=disabled, 1=enabled
\r
111 #define ARM_MCI_UHS_TUNING_OPERATION (0x08) ///< Sampling clock Tuning operation (SD UHS-I); arg: 0=reset, 1=execute
\r
112 #define ARM_MCI_UHS_TUNING_RESULT (0x09) ///< Sampling clock Tuning result (SD UHS-I); returns: 0=done, 1=in progress, -1=error
\r
113 #define ARM_MCI_DATA_TIMEOUT (0x0A) ///< Set Data timeout; arg = timeout in bus cycles
\r
114 #define ARM_MCI_CSS_TIMEOUT (0x0B) ///< Set Command Completion Signal (CCS) timeout; arg = timeout in bus cycles
\r
115 #define ARM_MCI_MONITOR_SDIO_INTERRUPT (0x0C) ///< Monitor SD I/O interrupt: arg: 0=disabled, 1=enabled
\r
116 #define ARM_MCI_CONTROL_READ_WAIT (0x0D) ///< Control Read/Wait for SD I/O; arg: 0=disabled, 1=enabled
\r
117 #define ARM_MCI_SUSPEND_TRANSFER (0x0E) ///< Suspend Data transfer (SD I/O); returns number of remaining bytes to transfer
\r
118 #define ARM_MCI_RESUME_TRANSFER (0x0F) ///< Resume Data transfer (SD I/O)
\r
120 /*----- MCI Bus Speed Mode -----*/
\r
121 #define ARM_MCI_BUS_DEFAULT_SPEED (0x00) ///< SD/MMC: Default Speed mode up to 25/26MHz
\r
122 #define ARM_MCI_BUS_HIGH_SPEED (0x01) ///< SD/MMC: High Speed mode up to 50/52MHz
\r
123 #define ARM_MCI_BUS_UHS_SDR12 (0x02) ///< SD: SDR12 (Single Data Rate) up to 25MHz, 12.5MB/s: UHS-I (Ultra High Speed) 1.8V signaling
\r
124 #define ARM_MCI_BUS_UHS_SDR25 (0x03) ///< SD: SDR25 (Single Data Rate) up to 50MHz, 25 MB/s: UHS-I (Ultra High Speed) 1.8V signaling
\r
125 #define ARM_MCI_BUS_UHS_SDR50 (0x04) ///< SD: SDR50 (Single Data Rate) up to 100MHz, 50 MB/s: UHS-I (Ultra High Speed) 1.8V signaling
\r
126 #define ARM_MCI_BUS_UHS_SDR104 (0x05) ///< SD: SDR104 (Single Data Rate) up to 208MHz, 104 MB/s: UHS-I (Ultra High Speed) 1.8V signaling
\r
127 #define ARM_MCI_BUS_UHS_DDR50 (0x06) ///< SD: DDR50 (Dual Data Rate) up to 50MHz, 50 MB/s: UHS-I (Ultra High Speed) 1.8V signaling
\r
129 /*----- MCI CMD Line Mode -----*/
\r
130 #define ARM_MCI_BUS_CMD_PUSH_PULL (0x00) ///< Push-Pull CMD line (default)
\r
131 #define ARM_MCI_BUS_CMD_OPEN_DRAIN (0x01) ///< Open Drain CMD line (MMC only)
\r
133 /*----- MCI Bus Data Width -----*/
\r
134 #define ARM_MCI_BUS_DATA_WIDTH_1 (0x00) ///< Bus data width: 1 bit (default)
\r
135 #define ARM_MCI_BUS_DATA_WIDTH_4 (0x01) ///< Bus data width: 4 bits
\r
136 #define ARM_MCI_BUS_DATA_WIDTH_8 (0x02) ///< Bus data width: 8 bits
\r
137 #define ARM_MCI_BUS_DATA_WIDTH_4_DDR (0x03) ///< Bus data width: 4 bits, DDR (Dual Data Rate) - MMC only
\r
138 #define ARM_MCI_BUS_DATA_WIDTH_8_DDR (0x04) ///< Bus data width: 8 bits, DDR (Dual Data Rate) - MMC only
\r
140 /*----- MCI Driver Strength -----*/
\r
141 #define ARM_MCI_DRIVER_TYPE_A (0x01) ///< SD UHS-I Driver Type A
\r
142 #define ARM_MCI_DRIVER_TYPE_B (0x00) ///< SD UHS-I Driver Type B (default)
\r
143 #define ARM_MCI_DRIVER_TYPE_C (0x02) ///< SD UHS-I Driver Type C
\r
144 #define ARM_MCI_DRIVER_TYPE_D (0x03) ///< SD UHS-I Driver Type D
\r
147 /****** MCI Card Power *****/
\r
148 #define ARM_MCI_POWER_VDD_Pos 0
\r
149 #define ARM_MCI_POWER_VDD_Msk (0x0FUL << ARM_MCI_POWER_VDD_Pos)
\r
150 #define ARM_MCI_POWER_VDD_OFF (0x01UL << ARM_MCI_POWER_VDD_Pos) ///< VDD (VCC) turned off
\r
151 #define ARM_MCI_POWER_VDD_3V3 (0x02UL << ARM_MCI_POWER_VDD_Pos) ///< VDD (VCC) = 3.3V
\r
152 #define ARM_MCI_POWER_VDD_1V8 (0x03UL << ARM_MCI_POWER_VDD_Pos) ///< VDD (VCC) = 1.8V
\r
153 #define ARM_MCI_POWER_VCCQ_Pos 4
\r
154 #define ARM_MCI_POWER_VCCQ_Msk (0x0FUL << ARM_MCI_POWER_VCCQ_Pos)
\r
155 #define ARM_MCI_POWER_VCCQ_OFF (0x01UL << ARM_MCI_POWER_VCCQ_Pos) ///< eMMC VCCQ turned off
\r
156 #define ARM_MCI_POWER_VCCQ_3V3 (0x02UL << ARM_MCI_POWER_VCCQ_Pos) ///< eMMC VCCQ = 3.3V
\r
157 #define ARM_MCI_POWER_VCCQ_1V8 (0x03UL << ARM_MCI_POWER_VCCQ_Pos) ///< eMMC VCCQ = 1.8V
\r
158 #define ARM_MCI_POWER_VCCQ_1V2 (0x04UL << ARM_MCI_POWER_VCCQ_Pos) ///< eMMC VCCQ = 1.2V
\r
164 typedef struct _ARM_MCI_STATUS {
\r
165 uint32_t command_active : 1; ///< Command active flag
\r
166 uint32_t command_timeout : 1; ///< Command timeout flag (cleared on start of next command)
\r
167 uint32_t command_error : 1; ///< Command error flag (cleared on start of next command)
\r
168 uint32_t transfer_active : 1; ///< Transfer active flag
\r
169 uint32_t transfer_timeout : 1; ///< Transfer timeout flag (cleared on start of next command)
\r
170 uint32_t transfer_error : 1; ///< Transfer error flag (cleared on start of next command)
\r
171 uint32_t sdio_interrupt : 1; ///< SD I/O Interrupt flag (cleared on start of monitoring)
\r
172 uint32_t ccs : 1; ///< CCS flag (cleared on start of next command)
\r
176 /****** MCI Card Event *****/
\r
177 #define ARM_MCI_EVENT_CARD_INSERTED (1UL << 0) ///< Memory Card inserted
\r
178 #define ARM_MCI_EVENT_CARD_REMOVED (1UL << 1) ///< Memory Card removed
\r
179 #define ARM_MCI_EVENT_COMMAND_COMPLETE (1UL << 2) ///< Command completed
\r
180 #define ARM_MCI_EVENT_COMMAND_TIMEOUT (1UL << 3) ///< Command timeout
\r
181 #define ARM_MCI_EVENT_COMMAND_ERROR (1UL << 4) ///< Command response error (CRC error or invalid response)
\r
182 #define ARM_MCI_EVENT_TRANSFER_COMPLETE (1UL << 5) ///< Data transfer completed
\r
183 #define ARM_MCI_EVENT_TRANSFER_TIMEOUT (1UL << 6) ///< Data transfer timeout
\r
184 #define ARM_MCI_EVENT_TRANSFER_ERROR (1UL << 7) ///< Data transfer CRC failed
\r
185 #define ARM_MCI_EVENT_SDIO_INTERRUPT (1UL << 8) ///< SD I/O Interrupt
\r
186 #define ARM_MCI_EVENT_CCS (1UL << 9) ///< Command Completion Signal (CCS)
\r
187 #define ARM_MCI_EVENT_CCS_TIMEOUT (1UL << 10) ///< Command Completion Signal (CCS) Timeout
\r
190 // Function documentation
\r
192 \fn ARM_DRIVER_VERSION ARM_MCI_GetVersion (void)
\r
193 \brief Get driver version.
\r
194 \return \ref ARM_DRIVER_VERSION
\r
197 \fn ARM_MCI_CAPABILITIES ARM_MCI_GetCapabilities (void)
\r
198 \brief Get driver capabilities.
\r
199 \return \ref ARM_MCI_CAPABILITIES
\r
202 \fn int32_t ARM_MCI_Initialize (ARM_MCI_SignalEvent_t cb_event)
\r
203 \brief Initialize the Memory Card Interface
\r
204 \param[in] cb_event Pointer to \ref ARM_MCI_SignalEvent
\r
205 \return \ref execution_status
\r
208 \fn int32_t ARM_MCI_Uninitialize (void)
\r
209 \brief De-initialize Memory Card Interface.
\r
210 \return \ref execution_status
\r
213 \fn int32_t ARM_MCI_PowerControl (ARM_POWER_STATE state)
\r
214 \brief Control Memory Card Interface Power.
\r
215 \param[in] state Power state \ref ARM_POWER_STATE
\r
216 \return \ref execution_status
\r
219 \fn int32_t ARM_MCI_CardPower (uint32_t voltage)
\r
220 \brief Set Memory Card Power supply voltage.
\r
221 \param[in] voltage Memory Card Power supply voltage
\r
222 \return \ref execution_status
\r
225 \fn int32_t ARM_MCI_ReadCD (void)
\r
226 \brief Read Card Detect (CD) state.
\r
227 \return 1:card detected, 0:card not detected, or error
\r
230 \fn int32_t ARM_MCI_ReadWP (void)
\r
231 \brief Read Write Protect (WP) state.
\r
232 \return 1:write protected, 0:not write protected, or error
\r
235 \fn int32_t ARM_MCI_SendCommand (uint32_t cmd,
\r
238 uint32_t *response)
\r
239 \brief Send Command to card and get the response.
\r
240 \param[in] cmd Memory Card command
\r
241 \param[in] arg Command argument
\r
242 \param[in] flags Command flags
\r
243 \param[out] response Pointer to buffer for response
\r
244 \return \ref execution_status
\r
247 \fn int32_t ARM_MCI_SetupTransfer (uint8_t *data,
\r
248 uint32_t block_count,
\r
249 uint32_t block_size,
\r
251 \brief Setup read or write transfer operation.
\r
252 \param[in,out] data Pointer to data block(s) to be written or read
\r
253 \param[in] block_count Number of blocks
\r
254 \param[in] block_size Size of a block in bytes
\r
255 \param[in] mode Transfer mode
\r
256 \return \ref execution_status
\r
259 \fn int32_t ARM_MCI_AbortTransfer (void)
\r
260 \brief Abort current read/write data transfer.
\r
261 \return \ref execution_status
\r
264 \fn int32_t ARM_MCI_Control (uint32_t control, uint32_t arg)
\r
265 \brief Control MCI Interface.
\r
266 \param[in] control Operation
\r
267 \param[in] arg Argument of operation (optional)
\r
268 \return \ref execution_status
\r
271 \fn ARM_MCI_STATUS ARM_MCI_GetStatus (void)
\r
272 \brief Get MCI status.
\r
273 \return MCI status \ref ARM_MCI_STATUS
\r
277 \fn void ARM_MCI_SignalEvent (uint32_t event)
\r
278 \brief Callback function that signals a MCI Card Event.
\r
279 \param[in] event \ref mci_event_gr
\r
283 typedef void (*ARM_MCI_SignalEvent_t) (uint32_t event); ///< Pointer to \ref ARM_MCI_SignalEvent : Signal MCI Card Event.
\r
287 \brief MCI Driver Capabilities.
\r
289 typedef struct _ARM_MCI_CAPABILITIES {
\r
290 uint32_t cd_state : 1; ///< Card Detect State available
\r
291 uint32_t cd_event : 1; ///< Signal Card Detect change event
\r
292 uint32_t wp_state : 1; ///< Write Protect State available
\r
293 uint32_t vdd : 1; ///< Supports VDD Card Power Supply Control
\r
294 uint32_t vdd_1v8 : 1; ///< Supports 1.8 VDD Card Power Supply
\r
295 uint32_t vccq : 1; ///< Supports VCCQ Card Power Supply Control (eMMC)
\r
296 uint32_t vccq_1v8 : 1; ///< Supports 1.8 VCCQ Card Power Supply (eMMC)
\r
297 uint32_t vccq_1v2 : 1; ///< Supports 1.2 VCCQ Card Power Supply (eMMC)
\r
298 uint32_t data_width_4 : 1; ///< Supports 4-bit data
\r
299 uint32_t data_width_8 : 1; ///< Supports 8-bit data
\r
300 uint32_t data_width_4_ddr : 1; ///< Supports 4-bit data, DDR (Dual Data Rate) - MMC only
\r
301 uint32_t data_width_8_ddr : 1; ///< Supports 8-bit data, DDR (Dual Data Rate) - MMC only
\r
302 uint32_t high_speed : 1; ///< Supports SD/MMC High Speed Mode
\r
303 uint32_t uhs_signaling : 1; ///< Supports SD UHS-I (Ultra High Speed) 1.8V signaling
\r
304 uint32_t uhs_tuning : 1; ///< Supports SD UHS-I tuning
\r
305 uint32_t uhs_sdr50 : 1; ///< Supports SD UHS-I SDR50 (Single Data Rate) up to 50MB/s
\r
306 uint32_t uhs_sdr104 : 1; ///< Supports SD UHS-I SDR104 (Single Data Rate) up to 104MB/s
\r
307 uint32_t uhs_ddr50 : 1; ///< Supports SD UHS-I DDR50 (Dual Data Rate) up to 50MB/s
\r
308 uint32_t uhs_driver_type_a : 1; ///< Supports SD UHS-I Driver Type A
\r
309 uint32_t uhs_driver_type_c : 1; ///< Supports SD UHS-I Driver Type C
\r
310 uint32_t uhs_driver_type_d : 1; ///< Supports SD UHS-I Driver Type D
\r
311 uint32_t sdio_interrupt : 1; ///< Supports SD I/O Interrupt
\r
312 uint32_t read_wait : 1; ///< Supports Read Wait (SD I/O)
\r
313 uint32_t suspend_resume : 1; ///< Supports Suspend/Resume (SD I/O)
\r
314 uint32_t mmc_interrupt : 1; ///< Supports MMC Interrupt
\r
315 uint32_t mmc_boot : 1; ///< Supports MMC Boot
\r
316 uint32_t rst_n : 1; ///< Supports RST_n Pin Control (eMMC)
\r
317 uint32_t ccs : 1; ///< Supports Command Completion Signal (CCS) for CE-ATA
\r
318 uint32_t ccs_timeout : 1; ///< Supports Command Completion Signal (CCS) timeout for CE-ATA
\r
319 } ARM_MCI_CAPABILITIES;
\r
323 \brief Access structure of the MCI Driver.
\r
325 typedef struct _ARM_DRIVER_MCI {
\r
326 ARM_DRIVER_VERSION (*GetVersion) (void); ///< Pointer to \ref ARM_MCI_GetVersion : Get driver version.
\r
327 ARM_MCI_CAPABILITIES (*GetCapabilities)(void); ///< Pointer to \ref ARM_MCI_GetCapabilities : Get driver capabilities.
\r
328 int32_t (*Initialize) (ARM_MCI_SignalEvent_t cb_event); ///< Pointer to \ref ARM_MCI_Initialize : Initialize MCI Interface.
\r
329 int32_t (*Uninitialize) (void); ///< Pointer to \ref ARM_MCI_Uninitialize : De-initialize MCI Interface.
\r
330 int32_t (*PowerControl) (ARM_POWER_STATE state); ///< Pointer to \ref ARM_MCI_PowerControl : Control MCI Interface Power.
\r
331 int32_t (*CardPower) (uint32_t voltage); ///< Pointer to \ref ARM_MCI_CardPower : Set card power supply voltage.
\r
332 int32_t (*ReadCD) (void); ///< Pointer to \ref ARM_MCI_ReadCD : Read Card Detect (CD) state.
\r
333 int32_t (*ReadWP) (void); ///< Pointer to \ref ARM_MCI_ReadWP : Read Write Protect (WP) state.
\r
334 int32_t (*SendCommand) (uint32_t cmd,
\r
337 uint32_t *response); ///< Pointer to \ref ARM_MCI_SendCommand : Send Command to card and get the response.
\r
338 int32_t (*SetupTransfer) (uint8_t *data,
\r
339 uint32_t block_count,
\r
340 uint32_t block_size,
\r
341 uint32_t mode); ///< Pointer to \ref ARM_MCI_SetupTransfer : Setup data transfer operation.
\r
342 int32_t (*AbortTransfer) (void); ///< Pointer to \ref ARM_MCI_AbortTransfer : Abort current data transfer.
\r
343 int32_t (*Control) (uint32_t control, uint32_t arg); ///< Pointer to \ref ARM_MCI_Control : Control MCI Interface.
\r
344 ARM_MCI_STATUS (*GetStatus) (void); ///< Pointer to \ref ARM_MCI_GetStatus : Get MCI status.
\r
345 } const ARM_DRIVER_MCI;
\r
347 #endif /* __DRIVER_MCI_H */
\r