summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2013-09-22 14:48:22 -0600
committerGregory Nutt <gnutt@nuttx.org>2013-09-22 14:48:22 -0600
commit560099443ce4381ff02e105e6e6d736f543e5f3c (patch)
tree5c3d4269c908d018473d2a579c7eb5822e9a99af
parent712c271d829ec46a075d45f9a55abbf3cd958ca7 (diff)
downloadnuttx-560099443ce4381ff02e105e6e6d736f543e5f3c.tar.gz
nuttx-560099443ce4381ff02e105e6e6d736f543e5f3c.tar.bz2
nuttx-560099443ce4381ff02e105e6e6d736f543e5f3c.zip
Cosmetic changes to comments and coding style fixes
-rw-r--r--nuttx/arch/arm/src/sama5/sam_hsmci.c2
-rw-r--r--nuttx/drivers/mmcsd/mmcsd_sdio.c209
2 files changed, 115 insertions, 96 deletions
diff --git a/nuttx/arch/arm/src/sama5/sam_hsmci.c b/nuttx/arch/arm/src/sama5/sam_hsmci.c
index df5fa0c41..c4b47210f 100644
--- a/nuttx/arch/arm/src/sama5/sam_hsmci.c
+++ b/nuttx/arch/arm/src/sama5/sam_hsmci.c
@@ -2361,7 +2361,7 @@ static sdio_eventset_t sam_eventwait(FAR struct sdio_dev_s *dev,
return SDIOWAIT_TIMEOUT;
}
- /* Start the watchdog timer. I am not sure why this is, but I am\
+ /* Start the watchdog timer. I am not sure why this is, but I am
* currently seeing some additional delays when DMA is used.
*/
diff --git a/nuttx/drivers/mmcsd/mmcsd_sdio.c b/nuttx/drivers/mmcsd/mmcsd_sdio.c
index b2a0e99d6..2332261fc 100644
--- a/nuttx/drivers/mmcsd/mmcsd_sdio.c
+++ b/nuttx/drivers/mmcsd/mmcsd_sdio.c
@@ -342,6 +342,7 @@ static int mmcsd_sendcmdpoll(FAR struct mmcsd_state_s *priv, uint32_t cmd,
fdbg("ERROR: Wait for response to cmd: %08x failed: %d\n", cmd, ret);
}
}
+
return ret;
}
@@ -381,6 +382,7 @@ static inline int mmcsd_sendcmd4(FAR struct mmcsd_state_s *priv)
up_udelay(MMCSD_DSR_DELAY);
}
#endif
+
return ret;
}
@@ -415,6 +417,7 @@ static int mmcsd_recvR1(FAR struct mmcsd_state_s *priv, uint32_t cmd)
ret = -EIO;
}
}
+
return ret;
}
@@ -525,6 +528,7 @@ static int mmcsd_getSCR(FAR struct mmcsd_state_s *priv, uint32_t scr[2])
{
fdbg("ERROR: mmcsd_eventwait for READ DATA failed: %d\n", ret);
}
+
return ret;
}
@@ -997,6 +1001,7 @@ static int mmcsd_getR1(FAR struct mmcsd_state_s *priv, FAR uint32_t *r1)
*r1 = localR1;
}
}
+
return ret;
}
@@ -1031,6 +1036,7 @@ static int mmcsd_verifystate(FAR struct mmcsd_state_s *priv, uint32_t state)
priv->wrbusy = false;
return OK;
}
+
return -EINVAL;
}
@@ -1188,6 +1194,7 @@ static int mmcsd_transferready(FAR struct mmcsd_state_s *priv)
elapsed = clock_systimer() - starttime;
}
while (elapsed < TICK_PER_SEC);
+
return -ETIMEDOUT;
}
@@ -1212,6 +1219,7 @@ static int mmcsd_stoptransmission(FAR struct mmcsd_state_s *priv)
{
fdbg("ERROR: mmcsd_recvR1 for CMD12 failed: %d\n", ret);
}
+
return ret;
}
#endif
@@ -1272,10 +1280,10 @@ static ssize_t mmcsd_readsingle(FAR struct mmcsd_state_s *priv,
/* Check if the card is locked */
if (priv->locked)
- {
- fdbg("ERROR: Card is locked\n");
- return -EPERM;
- }
+ {
+ fdbg("ERROR: Card is locked\n");
+ return -EPERM;
+ }
/* Verify that the card is ready for the transfer. The card may still be
* busy from the preceding write transfer. It would be simpler to check
@@ -1303,16 +1311,17 @@ static ssize_t mmcsd_readsingle(FAR struct mmcsd_state_s *priv,
{
offset = startblock << priv->blockshift;
}
+
fvdbg("offset=%d\n", offset);
/* Select the block size for the card */
ret = mmcsd_setblocklen(priv, priv->blocksize);
if (ret != OK)
- {
- fdbg("ERROR: mmcsd_setblocklen failed: %d\n", ret);
- return ret;
- }
+ {
+ fdbg("ERROR: mmcsd_setblocklen failed: %d\n", ret);
+ return ret;
+ }
/* Configure SDIO controller hardware for the read transfer */
@@ -1381,10 +1390,10 @@ static ssize_t mmcsd_readmultiple(FAR struct mmcsd_state_s *priv,
/* Check if the card is locked */
if (priv->locked)
- {
- fdbg("ERROR: Card is locked\n");
- return -EPERM;
- }
+ {
+ fdbg("ERROR: Card is locked\n");
+ return -EPERM;
+ }
/* Verify that the card is ready for the transfer. The card may still be
* busy from the preceding write transfer. It would be simpler to check
@@ -1562,10 +1571,10 @@ static ssize_t mmcsd_writesingle(FAR struct mmcsd_state_s *priv,
*/
if (mmcsd_wrprotected(priv))
- {
- fdbg("ERROR: Card is locked or write protected\n");
- return -EPERM;
- }
+ {
+ fdbg("ERROR: Card is locked or write protected\n");
+ return -EPERM;
+ }
/* Verify that the card is ready for the transfer. The card may still be
* busy from the preceding write transfer. It would be simpler to check
@@ -1593,6 +1602,7 @@ static ssize_t mmcsd_writesingle(FAR struct mmcsd_state_s *priv,
{
offset = startblock << priv->blockshift;
}
+
fvdbg("offset=%d\n", offset);
/* Select the block size for the card */
@@ -1675,10 +1685,10 @@ static ssize_t mmcsd_writemultiple(FAR struct mmcsd_state_s *priv,
*/
if (mmcsd_wrprotected(priv))
- {
- fdbg("ERROR: Card is locked or write protected\n");
- return -EPERM;
- }
+ {
+ fdbg("ERROR: Card is locked or write protected\n");
+ return -EPERM;
+ }
/* Verify that the card is ready for the transfer. The card may still be
* busy from the preceding write transfer. It would be simpler to check
@@ -1707,16 +1717,17 @@ static ssize_t mmcsd_writemultiple(FAR struct mmcsd_state_s *priv,
{
offset = startblock << priv->blockshift;
}
+
fvdbg("nbytes=%d byte offset=%d\n", nbytes, offset);
/* Select the block size for the card */
ret = mmcsd_setblocklen(priv, priv->blocksize);
if (ret != OK)
- {
- fdbg("ERROR: mmcsd_setblocklen failed: %d\n", ret);
- return ret;
- }
+ {
+ fdbg("ERROR: mmcsd_setblocklen failed: %d\n", ret);
+ return ret;
+ }
/* If this is an SD card, then send ACMD23 (SET_WR_BLK_COUNT) just before
* sending CMD25 (WRITE_MULTIPLE_BLOCK). This sets the number of write
@@ -2113,6 +2124,7 @@ static int mmcsd_geometry(FAR struct inode *inode, struct geometry *geometry)
priv->mediachanged = false;
ret = OK;
}
+
mmcsd_givesem(priv);
}
@@ -2259,52 +2271,52 @@ static int mmcsd_widebus(FAR struct mmcsd_state_s *priv)
if ((priv->buswidth & MMCSD_SCR_BUSWIDTH_4BIT) != 0)
{
- /* Disconnect any CD/DAT3 pull up using ACMD42. ACMD42 is optional and
- * need not be supported by all SD calls.
- *
- * First end CMD55 APP_CMD with argument as card's RCA.
- */
+ /* Disconnect any CD/DAT3 pull up using ACMD42. ACMD42 is optional and
+ * need not be supported by all SD calls.
+ *
+ * First end CMD55 APP_CMD with argument as card's RCA.
+ */
- mmcsd_sendcmdpoll(priv, SD_CMD55, (uint32_t)priv->rca << 16);
- ret = mmcsd_recvR1(priv, SD_CMD55);
- if (ret != OK)
- {
- fdbg("ERROR: RECVR1 for CMD55 of ACMD42: %d\n", ret);
- return ret;
- }
+ mmcsd_sendcmdpoll(priv, SD_CMD55, (uint32_t)priv->rca << 16);
+ ret = mmcsd_recvR1(priv, SD_CMD55);
+ if (ret != OK)
+ {
+ fdbg("ERROR: RECVR1 for CMD55 of ACMD42: %d\n", ret);
+ return ret;
+ }
- /* Then send ACMD42 with the argument to disconnect the CD/DAT3
- * pullup
- */
+ /* Then send ACMD42 with the argument to disconnect the CD/DAT3
+ * pullup
+ */
- mmcsd_sendcmdpoll(priv, SD_ACMD42, MMCSD_ACMD42_CD_DISCONNECT);
- ret = mmcsd_recvR1(priv, SD_ACMD42);
- if (ret != OK)
- {
- fvdbg("WARNING: SD card does not support ACMD42: %d\n", ret);
- return ret;
- }
+ mmcsd_sendcmdpoll(priv, SD_ACMD42, MMCSD_ACMD42_CD_DISCONNECT);
+ ret = mmcsd_recvR1(priv, SD_ACMD42);
+ if (ret != OK)
+ {
+ fvdbg("WARNING: SD card does not support ACMD42: %d\n", ret);
+ return ret;
+ }
- /* Now send ACMD6 to select wide, 4-bit bus operation, beginning
- * with CMD55, APP_CMD:
- */
+ /* Now send ACMD6 to select wide, 4-bit bus operation, beginning
+ * with CMD55, APP_CMD:
+ */
- mmcsd_sendcmdpoll(priv, SD_CMD55, (uint32_t)priv->rca << 16);
- ret = mmcsd_recvR1(priv, SD_CMD55);
- if (ret != OK)
- {
- fdbg("ERROR: RECVR1 for CMD55 of ACMD6: %d\n", ret);
- return ret;
- }
+ mmcsd_sendcmdpoll(priv, SD_CMD55, (uint32_t)priv->rca << 16);
+ ret = mmcsd_recvR1(priv, SD_CMD55);
+ if (ret != OK)
+ {
+ fdbg("ERROR: RECVR1 for CMD55 of ACMD6: %d\n", ret);
+ return ret;
+ }
- /* Then send ACMD6 */
+ /* Then send ACMD6 */
- mmcsd_sendcmdpoll(priv, SD_ACMD6, MMCSD_ACMD6_BUSWIDTH_4);
- ret = mmcsd_recvR1(priv, SD_ACMD6);
- if (ret != OK)
- {
- return ret;
- }
+ mmcsd_sendcmdpoll(priv, SD_ACMD6, MMCSD_ACMD6_BUSWIDTH_4);
+ ret = mmcsd_recvR1(priv, SD_ACMD6);
+ if (ret != OK)
+ {
+ return ret;
+ }
/* Configure the SDIO peripheral */
@@ -2365,6 +2377,7 @@ static int mmcsd_mmcinitialize(FAR struct mmcsd_state_s *priv)
fdbg("ERROR: SDIO_RECVR2 for MMC CID failed: %d\n", ret);
return ret;
}
+
mmcsd_decodeCID(priv, cid);
/* Send CMD3, SET_RELATIVE_ADDR. This command is used to assign a logical
@@ -2407,6 +2420,7 @@ static int mmcsd_mmcinitialize(FAR struct mmcsd_state_s *priv)
fdbg("ERROR: Could not get SD CSD register: %d\n", ret);
return ret;
}
+
mmcsd_decodeCSD(priv, csd);
/* Set the Driver Stage Register (DSR) if (1) a CONFIG_MMCSD_DSR has been
@@ -2464,6 +2478,7 @@ static int mmcsd_sdinitialize(FAR struct mmcsd_state_s *priv)
fdbg("ERROR: SDIO_RECVR2 for SD CID failed: %d\n", ret);
return ret;
}
+
mmcsd_decodeCID(priv, cid);
/* Send CMD3, SET_RELATIVE_ADDR. In both protocols, this command is used
@@ -2477,10 +2492,11 @@ static int mmcsd_sdinitialize(FAR struct mmcsd_state_s *priv)
mmcsd_sendcmdpoll(priv, SD_CMD3, 0);
ret = mmcsd_recvR6(priv, SD_CMD3);
if (ret != OK)
- {
- fdbg("ERROR: mmcsd_recvR2 for SD RCA failed: %d\n", ret);
- return ret;
- }
+ {
+ fdbg("ERROR: mmcsd_recvR2 for SD RCA failed: %d\n", ret);
+ return ret;
+ }
+
fvdbg("RCA: %04x\n", priv->rca);
/* This should have caused a transition to standby state. However, this will
@@ -2510,6 +2526,7 @@ static int mmcsd_sdinitialize(FAR struct mmcsd_state_s *priv)
fdbg("ERROR: Could not get SD CSD register(%d)\n", ret);
return ret;
}
+
mmcsd_decodeCSD(priv, csd);
/* Send CMD7 with the argument == RCA in order to select the card.
@@ -2548,6 +2565,7 @@ static int mmcsd_sdinitialize(FAR struct mmcsd_state_s *priv)
fdbg("ERROR: Could not get SD SCR register(%d)\n", ret);
return ret;
}
+
mmcsd_decodeSCR(priv, scr);
/* Select width (4-bit) bus operation (if the card supports it) */
@@ -2634,24 +2652,24 @@ static int mmcsd_cardidentify(FAR struct mmcsd_state_s *priv)
/* Were both the command sent and response received correctly? */
if (ret == OK)
- {
- /* CMD8 succeeded this is probably a SDHC card. Verify the operating
- * voltage and that the check pattern was correctly echoed
- */
+ {
+ /* CMD8 succeeded this is probably a SDHC card. Verify the operating
+ * voltage and that the check pattern was correctly echoed
+ */
- if (((response & MMCSD_R7VOLTAGE_MASK) == MMCSD_R7VOLTAGE_27) &&
- ((response & MMCSD_R7ECHO_MASK) == MMCSD_R7CHECKPATTERN))
- {
- fvdbg("SD V2.x card\n");
- priv->type = MMCSD_CARDTYPE_SDV2;
- sdcapacity = MMCSD_ACMD41_HIGHCAPACITY;
- }
- else
- {
- fdbg("ERROR: R7: %08x\n", response);
- return -EIO;
- }
- }
+ if (((response & MMCSD_R7VOLTAGE_MASK) == MMCSD_R7VOLTAGE_27) &&
+ ((response & MMCSD_R7ECHO_MASK) == MMCSD_R7CHECKPATTERN))
+ {
+ fvdbg("SD V2.x card\n");
+ priv->type = MMCSD_CARDTYPE_SDV2;
+ sdcapacity = MMCSD_ACMD41_HIGHCAPACITY;
+ }
+ else
+ {
+ fdbg("ERROR: R7: %08x\n", response);
+ return -EIO;
+ }
+ }
/* At this point, type is either UNKNOWN or SDV2. Try sending
* CMD55 and (maybe) ACMD41 for up to 1 second or until the card
@@ -2750,6 +2768,7 @@ static int mmcsd_cardidentify(FAR struct mmcsd_state_s *priv)
* MMC card. We can send the CMD1 to find out for sure. CMD1 is supported
* by MMC cards, but not by SD cards.
*/
+
#ifdef CONFIG_MMCSD_MMCSUPPORT
if (priv->type == MMCSD_CARDTYPE_UNKNOWN || priv->type == MMCSD_CARDTYPE_MMC)
{
@@ -2898,21 +2917,21 @@ static int mmcsd_probe(FAR struct mmcsd_state_s *priv)
fdbg("ERROR: Internal confusion: %d\n", priv->type);
ret = -EPERM;
break;
- };
+ }
- /* Was the card configured successfully? */
+ /* Was the card configured successfully? */
- if (ret == OK)
- {
- /* Yes... */
+ if (ret == OK)
+ {
+ /* Yes... */
- fvdbg("Capacity: %lu Kbytes\n", (unsigned long)(priv->capacity / 1024));
- priv->mediachanged = true;
+ fvdbg("Capacity: %lu Kbytes\n", (unsigned long)(priv->capacity / 1024));
+ priv->mediachanged = true;
- /* Set up to receive asynchronous, media removal events */
+ /* Set up to receive asynchronous, media removal events */
- SDIO_CALLBACKENABLE(priv->dev, SDIOMEDIA_EJECTED);
- }
+ SDIO_CALLBACKENABLE(priv->dev, SDIOMEDIA_EJECTED);
+ }
}
/* In any event, we have probed this card */
@@ -2962,7 +2981,7 @@ static int mmcsd_removed(FAR struct mmcsd_state_s *priv)
/* Go back to the default 1-bit data bus. */
SDIO_WIDEBUS(priv->dev, false);
- priv->widebus = false;
+ priv->widebus = false;
/* Disable clocking to the card */