AM243x MCU+ SDK  08.01.00
mmcsd/v0/mmcsd.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
50 #ifndef MMCSD_H_
51 #define MMCSD_H_
52 
53 /* ========================================================================== */
54 /* Include Files */
55 /* ========================================================================== */
56 
57 #include <stdint.h>
58 #include <kernel/dpl/SystemP.h>
59 #include <kernel/dpl/SemaphoreP.h>
60 #include <kernel/dpl/HwiP.h>
61 #include <drivers/hw_include/csl_types.h>
62 #include <drivers/hw_include/cslr_mmcsd.h>
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 
68 /* ========================================================================== */
69 /* Macros & Typedefs */
70 /* ========================================================================== */
71 
72 #define MMCSD_CARD_TYPE_SD (0U)
73 #define MMCSD_CARD_TYPE_EMMC (1U)
74 #define MMCSD_CARD_TYPE_MMC (2U)
75 
76 /*
77 * \brief Macros that can be used for selecting the bus/data width
78 */
79 #define MMCSD_BUS_WIDTH_4BIT (0x4U)
80 #define MMCSD_BUS_WIDTH_8BIT (0x8U)
81 #define MMCSD_BUS_WIDTH_1BIT (0x1U)
82 
83 
84 /*
85 * \brief Macros that can be used for selecting the media transfer speed
86 */
87 #define MMCSD_TRANSPEED_25MBPS (0x32U)
88 #define MMCSD_TRANSPEED_50MBPS (0x5AU)
89 #define MMCSD_TRANSPEED_DEFAULT (0x32U)
90 #define MMCSD_TRANSPEED_HS (0x5AU)
91 #define MMCSD_TRANSPEED_SDR12 (0x32U)
92 #define MMCSD_TRANSPEED_SDR25 (0x5AU)
93 #define MMCSD_TRANSPEED_SDR50 (0xBU)
94 #define MMCSD_TRANSPEED_SDR104 (0x2BU)
95 #define MMCSD_TRANSPEED_DDR50 (0x3BU)
96 #define MMCSD_TRANSPEED_HS200 (0x2BU)
97 #define MMCSD_TRANSPEED_HS400 (0x4BU)
98 /*
99 * \brief Macros that can be used for selecting the bus voltage
100 */
101 #define MMCSD_BUS_VOLT_1_8V (0x5U) /* Embedded */
102 #define MMCSD_BUS_VOLT_3_0V (0x6U) /* Typical */
103 #define MMCSD_BUS_VOLT_3_3V (0x7U) /* Flattop */
104 
105 /*
106 * \brief Macros that can be used for selecting command types
107 */
108 #define MMCSD_CMD_TYPE_NORMAL (0U)
109 #define MMCSD_CMD_TYPE_BUS_SUSPEND (1U)
110 #define MMCSD_CMD_TYPE_FUNC_SEL (2U)
111 #define MMCSD_CMD_TYPE_IO_ABORT (3U)
112 
113 /*
114 * \brief Macros that can be used for selecting command response types
115 */
116 #define MMCSD_CMD_RSP_TYPE_NORSP (0U)
117 #define MMCSD_CMD_RSP_TYPE_L136 (1U)
118 #define MMCSD_CMD_RSP_TYPE_L48 (2U)
119 #define MMCSD_CMD_RSP_TYPE_L48_BUSY (3U)
120 
121 /*
122 * \brief Macros that can be used for selecting transfer types
123 */
124 #define MMCSD_CMD_XFER_TYPE_WRITE (0U)
125 #define MMCSD_CMD_XFER_TYPE_READ (1U)
126 
127 /*
128 * \brief Macros that can be used for selecting supported MMC modes
129 */
130 #define MMCSD_SUPPORT_MMC_DS (0x01U) /* DS (Up to 26Mhz) */
131 #define MMCSD_SUPPORT_MMC_HS_SDR (0x02U) /* HS (Up to 52Mhz) */
132 #define MMCSD_SUPPORT_MMC_HS_DDR (0x04U) /* HS (Up to 52Mhz) */
133 #define MMCSD_SUPPORT_MMC_HS200 (0x08U) /* HS200 (Up to 200Mhz) */
134 #define MMCSD_SUPPORT_MMC_HS400 (0x10U) /* HS400 (Up to 400Mhz) */
135 #define MMCSD_SUPPORT_MMC_HS400_ES (0x20U) /* HS400 Enhanced Strobe (Up to 400Mhz) */
136 #define MMCSD_SUPPORT_MMC_ALL (0xFFU) /* All modes */
137 
138 /*
139 * \brief Macros that can be used for selecting PHY types
140 */
141 #define MMCSD_PHY_TYPE_HW_PHY (0U)
142 #define MMCSD_PHY_TYPE_SW_PHY (1U)
143 #define MMCSD_PHY_TYPE_NO_PHY (2U)
144 
145 /*
146 * \brief Macros that can be used for selecting PHY tuning type
147 */
148 #define MMCSD_PHY_TUNING_TYPE_AUTO (0U)
149 #define MMCSD_PHY_TUNING_TYPE_MANUAL (1U)
150 
151 /*
152 * \brief Macros that can be used for selecting PHY modes
153 */
154 #define MMCSD_PHY_MODE_HS400 (1U)
155 #define MMCSD_PHY_MODE_HS200 (2U)
156 #define MMCSD_PHY_MODE_HSSDR50 (3U)
157 #define MMCSD_PHY_MODE_HSDDR50 (4U)
158 #define MMCSD_PHY_MODE_ENHANCED_STROBE (5U)
159 #define MMCSD_PHY_MODE_SDR104 (6U)
160 #define MMCSD_PHY_MODE_SDR50 (7U)
161 #define MMCSD_PHY_MODE_DDR50 (8U)
162 #define MMCSD_PHY_MODE_SDR25 (9U)
163 #define MMCSD_PHY_MODE_SDR12 (10U)
164 #define MMCSD_PHY_MODE_HS (11U)
165 #define MMCSD_PHY_MODE_DS (12U)
166 
167 /*
168 * \brief Macros that can be used for selecting UHS 1 modes
169 */
170 #define MMCSD_UHS_MODE_SDR12 (0U)
171 #define MMCSD_UHS_MODE_SDR25 (1U)
172 #define MMCSD_UHS_MODE_SDR50 (2U)
173 #define MMCSD_UHS_MODE_SDR104 (3U)
174 #define MMCSD_UHS_MODE_DDR50 (4U)
175 #define MMCSD_UHS_MODE_HS400 (5U)
176 #define MMCSD_UHS_MODE_UHS2 (7U)
177 
178 typedef void* MMCSD_Handle;
179 
180 /* ========================================================================== */
181 /* Structure Declarations */
182 /* ========================================================================== */
188 typedef struct
189 {
190  uint32_t rsvd;
191  /* Reserved parameter */
192 
193 } MMCSD_Params;
194 
202 typedef struct
203 {
204  uint32_t cmd;
207  uint32_t dir;
210  uint32_t arg;
213  void *dataBuf;
216  uint32_t blockSize;
219  uint32_t blockCount;
222  uint32_t autoCmdEn;
223  /* AutoCMD12 or AutoCMD23 or no AutoCMD */
224 
225  uint32_t enableDma;
226  /* Is DMA enabled for the command*/
227 
228  uint32_t isTuning;
229  /* Is transaction used for tuning */
230 
231  uint32_t response[4];
235 
240 typedef struct
241 {
242  uint32_t ctrlBaseAddr;
245  uint32_t ssBaseAddr;
248  uint32_t inputClkFreq;
251  uint32_t outputClkFreq;
254  uint32_t enableDma;
257  uint32_t intrEnable;
260  uint32_t intrNum;
263  uint32_t eventId;
266  uint32_t cardType;
269  uint32_t busWidth;
272  uint32_t supportedModes;
275  uint32_t busVoltage;
278  uint32_t isHS;
281  uint32_t phyType;
284  uint32_t tuningType;
287 } MMCSD_Attrs;
288 
293 typedef struct
294 {
298  uint32_t cardType;
301  uint32_t rca;
304  uint32_t scr[2];
307  uint32_t csd[4];
310  uint8_t ecsd[512];
313  uint32_t cid[4];
316  uint32_t ocr;
319  uint8_t sdVer;
322  uint32_t busWidth;
325  uint32_t transferSpeed;
328  uint32_t isHC;
331  uint32_t isUHS;
334  uint32_t isCmd23;
337  uint32_t is1_8V;
340  uint32_t isSwitch1_8V;
343  uint32_t blockSize;
346  uint64_t blockCount;
349  uint64_t mediaSize;
352  uint32_t enableDma;
355  uint32_t intrEnable;
358  volatile uint32_t cmdComp;
361  volatile uint32_t cmdTimeout;
362  /*< Command timeout flag */
363 
364  volatile uint32_t cmdCRCError;
365  /*< Command CRC error flag */
366 
367  volatile uint32_t cmdEBError;
368  /*< Command CRC error flag */
369 
370  volatile uint32_t cmdIndexError;
371  /*< Command Index error flag */
372 
373  volatile uint32_t dataCRCError;
374  /*< Data CRC error flag */
375 
376  volatile uint32_t dataEBError;
377  /*< Data end bit error */
378 
379  volatile uint32_t cmdError;
380  /*< Any error in processing of the command */
381 
382  volatile uint32_t xferInProgress;
383  /*< Command completion flag */
384 
385  volatile uint32_t xferComp;
386  /*< Transfer completion flag */
387 
388  volatile uint32_t xferTimeout;
389  /*< Transfer timeout flag */
390 
391  uint8_t *dataBufIdx;
392  uint32_t dataBlockCount;
393  uint32_t dataBlockSize;
394 
395  uint8_t *readBufIdx;
396  uint32_t readBlockCount;
397 
398  uint8_t *writeBufIdx;
399  uint32_t writeBlockCount;
400 
401  uint32_t isManualTuning;
404  uint32_t isOpen;
425 } MMCSD_Object;
426 
427 typedef struct
428 {
433 } MMCSD_Config;
434 
435 /* ========================================================================== */
436 /* Externs */
437 /* ========================================================================== */
438 
440 extern MMCSD_Config gMmcsdConfig[];
442 extern uint32_t gMmcsdConfigNum;
443 
444 /* ========================================================================== */
445 /* Internal/Private Structure Declarations */
446 /* ========================================================================== */
447 
448 /* ========================================================================== */
449 /* Function Declarations */
450 /* ========================================================================== */
451 
455 void MMCSD_init(void);
456 
460 void MMCSD_deinit(void);
461 
467 void MMCSD_Params_init(MMCSD_Params *mmcsdParams);
468 
483 MMCSD_Handle MMCSD_open(uint32_t index, const MMCSD_Params *openParams);
484 
495 
509 
523 int32_t MMCSD_read(MMCSD_Handle handle, uint8_t *buf, uint32_t startBlk, uint32_t numBlks);
524 
538 int32_t MMCSD_write(MMCSD_Handle handle, uint8_t *buf, uint32_t startBlk, uint32_t numBlks);
539 
557 int32_t MMCSD_ioctl(MMCSD_Handle handle, uint32_t cmd, void *arg);
558 
572 
575 #ifdef __cplusplus
576 }
577 #endif
578 
579 #endif /* MMCSD_H_ */
MMCSD_Attrs::intrEnable
uint32_t intrEnable
Definition: mmcsd/v0/mmcsd.h:257
MMCSD_open
MMCSD_Handle MMCSD_open(uint32_t index, const MMCSD_Params *openParams)
This function opens a given MMCSD peripheral.
MMCSD_Attrs::eventId
uint32_t eventId
Definition: mmcsd/v0/mmcsd.h:263
MMCSD_Object::isHC
uint32_t isHC
Definition: mmcsd/v0/mmcsd.h:328
MMCSD_Object::dataCopyCompleteSemObj
SemaphoreP_Object dataCopyCompleteSemObj
Definition: mmcsd/v0/mmcsd.h:416
MMCSD_Object::dataBlockSize
uint32_t dataBlockSize
Definition: mmcsd/v0/mmcsd.h:393
MMCSD_Params::rsvd
uint32_t rsvd
Definition: mmcsd/v0/mmcsd.h:190
MMCSD_Object::cmdEBError
volatile uint32_t cmdEBError
Definition: mmcsd/v0/mmcsd.h:367
MMCSD_Attrs::busVoltage
uint32_t busVoltage
Definition: mmcsd/v0/mmcsd.h:275
MMCSD_Object::isCmd23
uint32_t isCmd23
Definition: mmcsd/v0/mmcsd.h:334
MMCSD_Transaction::cmd
uint32_t cmd
Definition: mmcsd/v0/mmcsd.h:204
index
uint16_t index
Definition: tisci_rm_proxy.h:3
MMCSD_Object::cmdTimeout
volatile uint32_t cmdTimeout
Definition: mmcsd/v0/mmcsd.h:361
MMCSD_Transaction::blockSize
uint32_t blockSize
Definition: mmcsd/v0/mmcsd.h:216
SystemP.h
MMCSD_Object::xferMutex
SemaphoreP_Object xferMutex
Definition: mmcsd/v0/mmcsd.h:410
MMCSD_Object::cmdCompleteSemObj
SemaphoreP_Object cmdCompleteSemObj
Definition: mmcsd/v0/mmcsd.h:413
MMCSD_Object::writeBufIdx
uint8_t * writeBufIdx
Definition: mmcsd/v0/mmcsd.h:398
MMCSD_Transaction::isTuning
uint32_t isTuning
Definition: mmcsd/v0/mmcsd.h:228
MMCSD_Object::blockCount
uint64_t blockCount
Definition: mmcsd/v0/mmcsd.h:346
MMCSD_Object::isSwitch1_8V
uint32_t isSwitch1_8V
Definition: mmcsd/v0/mmcsd.h:340
MMCSD_Object::isManualTuning
uint32_t isManualTuning
Definition: mmcsd/v0/mmcsd.h:401
MMCSD_Object::dataEBError
volatile uint32_t dataEBError
Definition: mmcsd/v0/mmcsd.h:376
MMCSD_Object::busWidth
uint32_t busWidth
Definition: mmcsd/v0/mmcsd.h:322
MMCSD_Object::xferCompleteSemObj
SemaphoreP_Object xferCompleteSemObj
Definition: mmcsd/v0/mmcsd.h:419
MMCSD_Object::mediaSize
uint64_t mediaSize
Definition: mmcsd/v0/mmcsd.h:349
MMCSD_Attrs::ssBaseAddr
uint32_t ssBaseAddr
Definition: mmcsd/v0/mmcsd.h:245
SemaphoreP.h
MMCSD_Attrs::inputClkFreq
uint32_t inputClkFreq
Definition: mmcsd/v0/mmcsd.h:248
MMCSD_Object::isOpen
uint32_t isOpen
Definition: mmcsd/v0/mmcsd.h:404
MMCSD_Config::object
MMCSD_Object * object
Definition: mmcsd/v0/mmcsd.h:431
MMCSD_Object::cardType
uint32_t cardType
Definition: mmcsd/v0/mmcsd.h:298
MMCSD_init
void MMCSD_init(void)
This function initializes the MMCSD module.
MMCSD_Transaction::dir
uint32_t dir
Definition: mmcsd/v0/mmcsd.h:207
MMCSD_Attrs::busWidth
uint32_t busWidth
Definition: mmcsd/v0/mmcsd.h:269
MMCSD_Transaction
MMCSD transaction.
Definition: mmcsd/v0/mmcsd.h:203
MMCSD_Config::attrs
const MMCSD_Attrs * attrs
Definition: mmcsd/v0/mmcsd.h:429
MMCSD_Attrs::cardType
uint32_t cardType
Definition: mmcsd/v0/mmcsd.h:266
MMCSD_Object::cmdCRCError
volatile uint32_t cmdCRCError
Definition: mmcsd/v0/mmcsd.h:364
MMCSD_read
int32_t MMCSD_read(MMCSD_Handle handle, uint8_t *buf, uint32_t startBlk, uint32_t numBlks)
Function to perform block reads from the MMC/SD media.
gMmcsdConfigNum
uint32_t gMmcsdConfigNum
Externally defined driver configuration array size.
HwiP.h
MMCSD_Attrs::intrNum
uint32_t intrNum
Definition: mmcsd/v0/mmcsd.h:260
MMCSD_Object::isUHS
uint32_t isUHS
Definition: mmcsd/v0/mmcsd.h:331
MMCSD_Attrs::supportedModes
uint32_t supportedModes
Definition: mmcsd/v0/mmcsd.h:272
MMCSD_Object::hwiObj
HwiP_Object hwiObj
Definition: mmcsd/v0/mmcsd.h:422
MMCSD_Object::cmdError
volatile uint32_t cmdError
Definition: mmcsd/v0/mmcsd.h:379
MMCSD_Object::enableDma
uint32_t enableDma
Definition: mmcsd/v0/mmcsd.h:352
MMCSD_Object::is1_8V
uint32_t is1_8V
Definition: mmcsd/v0/mmcsd.h:337
MMCSD_Attrs::phyType
uint32_t phyType
Definition: mmcsd/v0/mmcsd.h:281
MMCSD_Attrs::ctrlBaseAddr
uint32_t ctrlBaseAddr
Definition: mmcsd/v0/mmcsd.h:242
MMCSD_Object::readBufIdx
uint8_t * readBufIdx
Definition: mmcsd/v0/mmcsd.h:395
MMCSD_Handle
void * MMCSD_Handle
Definition: mmcsd/v0/mmcsd.h:178
MMCSD_Object::xferInProgress
volatile uint32_t xferInProgress
Definition: mmcsd/v0/mmcsd.h:382
MMCSD_Params
MMCSD instance attributes - used during init time.
Definition: mmcsd/v0/mmcsd.h:189
MMCSD_getBlockSize
uint32_t MMCSD_getBlockSize(MMCSD_Handle handle)
This function returns the block size of the MMC/SD media connected to the MMCSD controller.
MMCSD_Object::dataBlockCount
uint32_t dataBlockCount
Definition: mmcsd/v0/mmcsd.h:392
MMCSD_deinit
void MMCSD_deinit(void)
This function de-initializes the MMCSD module.
MMCSD_Object
MMCSD driver object.
Definition: mmcsd/v0/mmcsd.h:294
MMCSD_Object::xferComp
volatile uint32_t xferComp
Definition: mmcsd/v0/mmcsd.h:385
MMCSD_Params_init
void MMCSD_Params_init(MMCSD_Params *mmcsdParams)
Initialize data structure with defaults.
MMCSD_Transaction::dataBuf
void * dataBuf
Definition: mmcsd/v0/mmcsd.h:213
HwiP_Object
Opaque Hwi object used with the Hwi APIs.
Definition: HwiP.h:91
MMCSD_Object::handle
MMCSD_Handle handle
Definition: mmcsd/v0/mmcsd.h:295
MMCSD_Transaction::enableDma
uint32_t enableDma
Definition: mmcsd/v0/mmcsd.h:225
MMCSD_Object::dataCRCError
volatile uint32_t dataCRCError
Definition: mmcsd/v0/mmcsd.h:373
MMCSD_Object::rca
uint32_t rca
Definition: mmcsd/v0/mmcsd.h:301
MMCSD_Attrs::outputClkFreq
uint32_t outputClkFreq
Definition: mmcsd/v0/mmcsd.h:251
MMCSD_Object::cmdIndexError
volatile uint32_t cmdIndexError
Definition: mmcsd/v0/mmcsd.h:370
MMCSD_Transaction::arg
uint32_t arg
Definition: mmcsd/v0/mmcsd.h:210
MMCSD_Object::sdVer
uint8_t sdVer
Definition: mmcsd/v0/mmcsd.h:319
MMCSD_Object::transferSpeed
uint32_t transferSpeed
Definition: mmcsd/v0/mmcsd.h:325
MMCSD_Config
Definition: mmcsd/v0/mmcsd.h:428
MMCSD_Transaction::blockCount
uint32_t blockCount
Definition: mmcsd/v0/mmcsd.h:219
SemaphoreP_Object
Opaque semaphore object used with the semaphore APIs.
Definition: SemaphoreP.h:59
MMCSD_Attrs::isHS
uint32_t isHS
Definition: mmcsd/v0/mmcsd.h:278
gMmcsdConfig
MMCSD_Config gMmcsdConfig[]
Externally defined driver configuration array.
MMCSD_Attrs::enableDma
uint32_t enableDma
Definition: mmcsd/v0/mmcsd.h:254
MMCSD_Attrs
MMCSD instance attributes - used during init time.
Definition: mmcsd/v0/mmcsd.h:241
MMCSD_close
void MMCSD_close(MMCSD_Handle handle)
Function to close a MMCSD peripheral specified by the MMCSD handle.
MMCSD_Transaction::autoCmdEn
uint32_t autoCmdEn
Definition: mmcsd/v0/mmcsd.h:222
MMCSD_Object::cmdMutex
SemaphoreP_Object cmdMutex
Definition: mmcsd/v0/mmcsd.h:407
MMCSD_ioctl
int32_t MMCSD_ioctl(MMCSD_Handle handle, uint32_t cmd, void *arg)
Function performs implementation specific features on a given MMCSD_Handle.
MMCSD_Object::xferTimeout
volatile uint32_t xferTimeout
Definition: mmcsd/v0/mmcsd.h:388
MMCSD_Object::ocr
uint32_t ocr
Definition: mmcsd/v0/mmcsd.h:316
MMCSD_Object::intrEnable
uint32_t intrEnable
Definition: mmcsd/v0/mmcsd.h:355
MMCSD_Object::readBlockCount
uint32_t readBlockCount
Definition: mmcsd/v0/mmcsd.h:396
MMCSD_write
int32_t MMCSD_write(MMCSD_Handle handle, uint8_t *buf, uint32_t startBlk, uint32_t numBlks)
Function to perform block writes to the MMC/SD media.
MMCSD_Object::cmdComp
volatile uint32_t cmdComp
Definition: mmcsd/v0/mmcsd.h:358
MMCSD_getHandle
MMCSD_Handle MMCSD_getHandle(uint32_t index)
This function returns the handle of an open MMCSD Instance from the instance index.
MMCSD_Object::dataBufIdx
uint8_t * dataBufIdx
Definition: mmcsd/v0/mmcsd.h:391
MMCSD_Object::writeBlockCount
uint32_t writeBlockCount
Definition: mmcsd/v0/mmcsd.h:399
MMCSD_Attrs::tuningType
uint32_t tuningType
Definition: mmcsd/v0/mmcsd.h:284
MMCSD_Object::blockSize
uint32_t blockSize
Definition: mmcsd/v0/mmcsd.h:343