summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorShawn Lin <[email protected]>2020-03-16 14:45:41 +0800
committerShawn Lin <[email protected]>2020-03-16 14:45:41 +0800
commit4c7106fa9d5871c6402c9a4f336504c9f1f78b60 (patch)
tree9cab1bcf11e9aceb57f18b9ebf6b203a8dfae016 /components
parenta7bcf90d78970f9a5e221133653331df158e9548 (diff)
component: sdio: fix potential ricky clock setting
Currently RTT mmc stack only support Highspeed mode or blow, which means the max speed should be 52MHz according to JEDEC spec. Two problems show here: (1) max_data_rate = (unsigned int)-1. The value of unsigned int depends on compilers/arch. Moreover, it makes no sense to assume cpu addressing width with IP clock rate limit. (1)hs_max_data_rate was set to 200MHz. So what should BSP drivers do if 52MHz < max_data_rate < 200MHz? Either it blindly sets a spec-violated clock rate to drive a Highspeed card, or just adjust the clock rate internally. Both cases are really bad for practice. If the card claims to support Highspeed, we set the clock to not to exceed 52MHz. Otherwise it should be set according to card->max_data_rate parsed by ext_csd. This patch fixes it as-is, and also simplify the code a lot. Signed-off-by: Shawn Lin <[email protected]>
Diffstat (limited to 'components')
-rw-r--r--components/drivers/sdio/mmc.c12
1 files changed, 3 insertions, 9 deletions
diff --git a/components/drivers/sdio/mmc.c b/components/drivers/sdio/mmc.c
index f77fbd959e..c1c56d37fd 100644
--- a/components/drivers/sdio/mmc.c
+++ b/components/drivers/sdio/mmc.c
@@ -191,7 +191,7 @@ static int mmc_parse_ext_csd(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd)
}
card->flags |= CARD_FLAG_HIGHSPEED;
- card->hs_max_data_rate = 200000000;
+ card->hs_max_data_rate = 52000000;
card_capacity = *((rt_uint32_t *)&ext_csd[EXT_CSD_SEC_CNT]);
card_capacity *= card->card_blksize;
@@ -513,16 +513,10 @@ static rt_int32_t mmcsd_mmc_init_card(struct rt_mmcsd_host *host,
card->flags |= CARD_FLAG_SDHC;
/* set bus speed */
- max_data_rate = (unsigned int)-1;
if (card->flags & CARD_FLAG_HIGHSPEED)
- {
- if (max_data_rate > card->hs_max_data_rate)
- max_data_rate = card->hs_max_data_rate;
- }
- else if (max_data_rate > card->max_data_rate)
- {
+ max_data_rate = card->hs_max_data_rate;
+ else
max_data_rate = card->max_data_rate;
- }
mmcsd_set_clock(host, max_data_rate);