Skip to content

Commit

Permalink
am263x: mmcsd: add eMMC driver for am263x
Browse files Browse the repository at this point in the history
-add eMMC support for am263x-cc and lp
-update init method
-fix write and read issues
-validate on raw_io example

Fixes: MCUSDK-471

Signed-off-by: Punit Sharma <[email protected]>
  • Loading branch information
punitSharma committed Apr 17, 2023
1 parent 802657e commit e7e0684
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
1 change: 1 addition & 0 deletions source/drivers/.meta/mmcsd/v1/mmcsd_v1.syscfg.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ let mmcsd_module = {
default: "SD",
options: [
{ name: "SD" },
{ name: "EMMC" },
{ name: "NO_DEVICE" },
],
},
Expand Down
31 changes: 13 additions & 18 deletions source/drivers/mmcsd/v1/mmcsd_v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -1340,16 +1340,18 @@ static int32_t MMCSD_initEMMC(MMCSD_Handle handle)
/* Default */
uint8_t ecsdBusWidth = MMCSD_ECSD_BUS_WIDTH_1BIT;

/* Input parameter validation */
if(handle != NULL)
{
/* Get the pointer to the object and attrs */
/* Get the pointer to the object and hardware attrs */
obj = ((MMCSD_Config *)handle)->object;
attrs = ((MMCSD_Config *)handle)->attrs;

if((obj != NULL) && (attrs != NULL))
{
if(SystemP_SUCCESS == status)
{
/* Refer to the MMC Host and Bus Configuration steps in TRM controller reset */
status = MMCSD_softReset(attrs->baseAddr);
}

Expand Down Expand Up @@ -1381,7 +1383,6 @@ static int32_t MMCSD_initEMMC(MMCSD_Handle handle)

/* Bus power on */
status = ((int32_t)(MMCSD_busPowerOnCtrl(attrs->baseAddr, MMCSD_PWR_CTRL_ON)));
obj->switched_to_v18=CSL_FALSE;

if(SystemP_SUCCESS == status)
{
Expand Down Expand Up @@ -1461,27 +1462,26 @@ static int32_t MMCSD_initEMMC(MMCSD_Handle handle)
/* Send CMD3, to get the card relative address*/
trans.cmd = MMCSD_CMD(3U);
trans.flags = 0U;
trans.arg = 0U;
trans.arg = obj->rca << 16U;

status = MMCSD_transfer(handle, &trans);
obj->rca = MMCSD_RCA_ADDR(trans.response[0U]);
}
if(SystemP_SUCCESS == status)
{
/* Send CMD9, to get the card specific data */
trans.cmd = MMCSD_CMD(9U);
trans.flags = MMCSD_CMD(9U);
trans.flags = MMCSD_CMDRSP_136BITS;
trans.arg = obj->rca << 16U;

status = MMCSD_transfer(handle,&trans);
status = MMCSD_transfer(handle, &trans);

memcpy(obj->csd, trans.response, 16U);
}

if(SystemP_SUCCESS == status)
{
obj->tranSpeed = ((obj->csd[3] & 0x000000FFU));
obj->dataBlockSize = (((uint32_t)2U)<<(((obj->csd[0] & 0x03C00000U) >> 22)-1U));
obj->blockSize = (((uint32_t)2U)<<(((obj->csd[0] & 0x03C00000U) >> 22)-1U));

if(((obj->csd[3] & 0x3C000000U) >> 26) != 0x04U)
{
Expand Down Expand Up @@ -1516,11 +1516,11 @@ static int32_t MMCSD_initEMMC(MMCSD_Handle handle)

if(SystemP_SUCCESS == status)
{
obj->dataBlockCount = (((uint32_t)(obj->ecsd[215])) << 24) +
obj->blockCount = (((uint32_t)(obj->ecsd[215])) << 24) +
(((uint32_t)(obj->ecsd[214])) << 16) +
(((uint32_t)(obj->ecsd[213])) << 8) +
(((uint32_t)(obj->ecsd[212])));
obj->size = (obj->dataBlockCount * obj->dataBlockSize);
obj->size = (obj->blockCount * obj->blockSize);
obj->busWidth = MMCSD_BUS_WIDTH_8BIT;
obj->sdVer = obj->ecsd[192];
}
Expand Down Expand Up @@ -1565,12 +1565,7 @@ static int32_t MMCSD_initEMMC(MMCSD_Handle handle)
MMCSD_delay(100U);

/* Setting the bus width as per the allowed configuration */
if(attrs->supportedBusWidth & MMCSD_BUS_WIDTH_8BIT)
{
controllerBuswidth = MMCSD_BUS_WIDTH_8BIT;
ecsdBusWidth = MMCSD_ECSD_BUS_WIDTH_8BIT;
}
else if(attrs->supportedBusWidth & MMCSD_BUS_WIDTH_4BIT)
if(attrs->supportedBusWidth & MMCSD_BUS_WIDTH_4BIT)
{
controllerBuswidth = MMCSD_BUS_WIDTH_4BIT;
ecsdBusWidth = MMCSD_ECSD_BUS_WIDTH_4BIT;
Expand All @@ -1591,14 +1586,14 @@ static int32_t MMCSD_initEMMC(MMCSD_Handle handle)
obj->busWidth = controllerBuswidth;

/* Add delay */
MMCSD_delay(100U);
MMCSD_delay(150U);

if(SystemP_SUCCESS == status)
{
MMCSD_setBusWidth(attrs->baseAddr, controllerBuswidth);
}

MMCSD_delay(100U);
MMCSD_delay(150U);

if(SystemP_SUCCESS == status)
{
Expand All @@ -1608,7 +1603,7 @@ static int32_t MMCSD_initEMMC(MMCSD_Handle handle)
status = MMCSD_transfer(handle, &trans);
}

MMCSD_delay(100U);
MMCSD_delay(150U);
}
if(SystemP_FAILURE == status)
{
Expand Down

0 comments on commit e7e0684

Please sign in to comment.