From 9b77aa21d1f1ee57231a17d589c6c40ef3750a05 Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 4 Mar 2011 13:14:04 +0000 Subject: SDIO-based MMC/SD fixes from Uros Platise git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3334 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/drivers/mmcsd/mmcsd_sdio.c | 24 ++++++++++++++++++++---- nuttx/drivers/mmcsd/mmcsd_sdio.h | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) (limited to 'nuttx/drivers') diff --git a/nuttx/drivers/mmcsd/mmcsd_sdio.c b/nuttx/drivers/mmcsd/mmcsd_sdio.c index 2503685e1..e4994000a 100644 --- a/nuttx/drivers/mmcsd/mmcsd_sdio.c +++ b/nuttx/drivers/mmcsd/mmcsd_sdio.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/mmcsd/mmcsd_sdio.c * - * Copyright (C) 2009-2010 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -596,7 +596,9 @@ static void mmcsd_decodeCSD(FAR struct mmcsd_state_s *priv, uint32_t csd[4]) if (IS_BLOCK(priv->type)) { - /* C_SIZE: 69:64 from Word 2 and 63:48 from Word 3 + /* Block addressed SD: + * + * C_SIZE: 69:64 from Word 2 and 63:48 from Word 3 * * 512 = (1 << 9) * 1024 = (1 << 10) @@ -618,15 +620,29 @@ static void mmcsd_decodeCSD(FAR struct mmcsd_state_s *priv, uint32_t csd[4]) } else { - /* C_SIZE: 73:64 from Word 2 and 63:62 from Word 3 */ + /* Byte addressed SD: + * + * C_SIZE: 73:64 from Word 2 and 63:62 from Word 3 + */ uint16_t csize = ((csd[1] & 0x03ff) << 2) | ((csd[2] >> 30) & 3); uint8_t csizemult = (csd[2] >> 15) & 7; priv->nblocks = ((uint32_t)csize + 1) * (1 << (csizemult + 2)); + priv->capacity = (priv->nblocks << readbllen); + + /* Force the block size to 512 bytes in any event. Some devices, such + * as 2Gb report blocksizes larger than 512 bytes but still expect to be + * accessed with a 512 byte blocksize. + */ + +#if 0 priv->blockshift = readbllen; priv->blocksize = (1 << readbllen); - priv->capacity = (priv->nblocks << readbllen); +#else + priv->blockshift = 9; + priv->blocksize = (1 << 9); +#endif #if defined(CONFIG_DEBUG) && defined (CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_FS) if (IS_SD(priv->type)) diff --git a/nuttx/drivers/mmcsd/mmcsd_sdio.h b/nuttx/drivers/mmcsd/mmcsd_sdio.h index e4eb02b3c..75f09aae0 100644 --- a/nuttx/drivers/mmcsd/mmcsd_sdio.h +++ b/nuttx/drivers/mmcsd/mmcsd_sdio.h @@ -169,7 +169,7 @@ # define MMCSD_R6_STATE_RCV ((uint32_t)6 << MMCSD_R6_STATE_SHIFT) /* 6=Receiving data state */ # define MMCSD_R6_STATE_PRG ((uint32_t)7 << MMCSD_R6_STATE_SHIFT) /* 7=Programming state */ # define MMCSD_R6_STATE_DIS ((uint32_t) << MMCSD_R6_STATE_SHIFT) /* 8=Disconnect state */ -#define MMCSD_R6_ERRORMASK ((uint32_t)0x0000e00) /* Error mask */ +#define MMCSD_R6_ERRORMASK ((uint32_t)0x0000e000) /* Error mask */ /* SD Configuration Register (SCR) encoding */ -- cgit v1.2.3