diff options
| author | xph <[email protected]> | 2020-04-09 16:35:28 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-04-09 16:35:28 +0800 |
| commit | ca7f01d79b3e0a997c771cec298e4ebd65b75809 (patch) | |
| tree | 3d2c48aae7203b14038ba7b98b500b5343ed7f2a /components/drivers/sdio | |
| parent | f763f8e7284b0492c5a65ad0abf94ee1963d7dcc (diff) | |
| parent | baa3145bfe61b3330b6a160523cc5470fa5db3a7 (diff) | |
Merge pull request #1 from RT-Thread/master
sync rtt
Diffstat (limited to 'components/drivers/sdio')
| -rw-r--r-- | components/drivers/sdio/block_dev.c | 19 | ||||
| -rw-r--r-- | components/drivers/sdio/mmc.c | 44 | ||||
| -rw-r--r-- | components/drivers/sdio/mmcsd_core.c | 20 | ||||
| -rw-r--r-- | components/drivers/sdio/sd.c | 46 | ||||
| -rw-r--r-- | components/drivers/sdio/sdio.c | 18 |
5 files changed, 58 insertions, 89 deletions
diff --git a/components/drivers/sdio/block_dev.c b/components/drivers/sdio/block_dev.c index 9bef67d950..602acb9aa7 100644 --- a/components/drivers/sdio/block_dev.c +++ b/components/drivers/sdio/block_dev.c @@ -13,14 +13,12 @@ #include <drivers/mmcsd_core.h> -#define DBG_ENABLE -#define DBG_SECTION_NAME "[SDIO]" +#define DBG_TAG "SDIO" #ifdef RT_SDIO_DEBUG -#define DBG_LEVEL DBG_LOG +#define DBG_LVL DBG_LOG #else -#define DBG_LEVEL DBG_INFO +#define DBG_LVL DBG_INFO #endif /* RT_SDIO_DEBUG */ -#define DBG_COLOR #include <rtdbg.h> static rt_list_t blk_devices = RT_LIST_OBJECT_INIT(blk_devices); @@ -369,7 +367,7 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card) return err; } - LOG_I("probe mmcsd block device!"); + LOG_D("probe mmcsd block device!"); /* get the first sector to read partition table */ sector = (rt_uint8_t *)rt_malloc(SECTOR_SIZE); @@ -462,8 +460,6 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card) rt_device_register(&blk_dev->dev, "sd0", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE); rt_list_insert_after(&blk_devices, &blk_dev->list); - - break; } else { @@ -474,7 +470,7 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card) } #ifdef RT_USING_DFS_MNTTABLE - if (0) // if (blk_dev) + if (blk_dev) { LOG_I("try to mount file system!"); /* try to mount file system on this block device */ @@ -509,9 +505,10 @@ void rt_mmcsd_blk_remove(struct rt_mmcsd_card *card) const char * mounted_path = dfs_filesystem_get_mounted_path(&(blk_dev->dev)); if (mounted_path) { - dfs_unmount(mounted_path); + dfs_unmount(mounted_path); + LOG_D("unmount file system %s for device %s.\r\n", mounted_path, blk_dev->dev.parent.name); } - + rt_sem_delete(blk_dev->part.lock); rt_device_unregister(&blk_dev->dev); rt_list_remove(&blk_dev->list); rt_free(blk_dev); diff --git a/components/drivers/sdio/mmc.c b/components/drivers/sdio/mmc.c index 7ad01e1153..c1c56d37fd 100644 --- a/components/drivers/sdio/mmc.c +++ b/components/drivers/sdio/mmc.c @@ -4,21 +4,19 @@ * SPDX-License-Identifier: Apache-2.0 * * Change Logs: - * Date Author Notes - * 2015-06-15 hichard first version + * Date Author Notes + * 2015-06-15 hichard first version */ #include <drivers/mmcsd_core.h> #include <drivers/mmc.h> -#define DBG_ENABLE -#define DBG_SECTION_NAME "[SDIO]" +#define DBG_TAG "SDIO" #ifdef RT_SDIO_DEBUG -#define DBG_LEVEL DBG_LOG +#define DBG_LVL DBG_LOG #else -#define DBG_LEVEL DBG_INFO +#define DBG_LVL DBG_INFO #endif /* RT_SDIO_DEBUG */ -#define DBG_COLOR #include <rtdbg.h> static const rt_uint32_t tran_unit[] = @@ -184,6 +182,8 @@ static int mmc_get_ext_csd(struct rt_mmcsd_card *card, rt_uint8_t **new_ext_csd) */ static int mmc_parse_ext_csd(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd) { + rt_uint64_t card_capacity = 0; + if(card == RT_NULL || ext_csd == RT_NULL) { LOG_E("emmc parse ext csd fail, invaild args"); @@ -191,11 +191,12 @@ 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->card_capacity = *((rt_uint32_t *)&ext_csd[EXT_CSD_SEC_CNT]); - card->card_capacity *= card->card_blksize; - card->card_capacity >>= 10; /* unit:KB */ + card_capacity = *((rt_uint32_t *)&ext_csd[EXT_CSD_SEC_CNT]); + card_capacity *= card->card_blksize; + card_capacity >>= 10; /* unit:KB */ + card->card_capacity = card_capacity; LOG_I("emmc card capacity %d KB.", card->card_capacity); return 0; @@ -317,8 +318,17 @@ static int mmc_select_bus_width(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd) * the device to work in 8bit transfer mode. If the * mmc switch command returns error then switch to * 4bit transfer mode. On success set the corresponding - * bus width on the host. + * bus width on the host. Meanwhile, mmc core would + * bail out early if corresponding bus capable wasn't + * set by drivers. */ + if ((!(host->flags & MMCSD_BUSWIDTH_8) && + ext_csd_bits[idx] == EXT_CSD_BUS_WIDTH_8) || + (!(host->flags & MMCSD_BUSWIDTH_4) && + (ext_csd_bits[idx] == EXT_CSD_BUS_WIDTH_4 || + ext_csd_bits[idx] == EXT_CSD_BUS_WIDTH_8))) + continue; + err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, ext_csd_bits[idx]); @@ -503,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); diff --git a/components/drivers/sdio/mmcsd_core.c b/components/drivers/sdio/mmcsd_core.c index 29a8ba239b..99bc6ce744 100644 --- a/components/drivers/sdio/mmcsd_core.c +++ b/components/drivers/sdio/mmcsd_core.c @@ -14,14 +14,12 @@ #include <drivers/mmc.h> #include <drivers/sdio.h> -#define DBG_ENABLE -#define DBG_SECTION_NAME "[SDIO]" +#define DBG_TAG "SDIO" #ifdef RT_SDIO_DEBUG -#define DBG_LEVEL DBG_LOG +#define DBG_LVL DBG_LOG #else -#define DBG_LEVEL DBG_INFO +#define DBG_LVL DBG_INFO #endif /* RT_SDIO_DEBUG */ -#define DBG_COLOR #include <rtdbg.h> #ifndef RT_MMCSD_STACK_SIZE @@ -595,7 +593,7 @@ static void mmcsd_power_off(struct rt_mmcsd_host *host) int mmcsd_wait_cd_changed(rt_int32_t timeout) { struct rt_mmcsd_host *host; - if (rt_mb_recv(&mmcsd_hotpluge_mb, (rt_uint32_t*)&host, timeout) == RT_EOK) + if (rt_mb_recv(&mmcsd_hotpluge_mb, (rt_ubase_t *)&host, timeout) == RT_EOK) { if(host->card == RT_NULL) { @@ -612,7 +610,7 @@ RTM_EXPORT(mmcsd_wait_cd_changed); void mmcsd_change(struct rt_mmcsd_host *host) { - rt_mb_send(&mmcsd_detect_mb, (rt_uint32_t)host); + rt_mb_send(&mmcsd_detect_mb, (rt_ubase_t)host); } void mmcsd_detect(void *param) @@ -623,7 +621,7 @@ void mmcsd_detect(void *param) while (1) { - if (rt_mb_recv(&mmcsd_detect_mb, (rt_uint32_t*)&host, RT_WAITING_FOREVER) == RT_EOK) + if (rt_mb_recv(&mmcsd_detect_mb, (rt_ubase_t *)&host, RT_WAITING_FOREVER) == RT_EOK) { if (host->card == RT_NULL) { @@ -651,7 +649,7 @@ void mmcsd_detect(void *param) if (init_sd(host, ocr)) mmcsd_power_off(host); mmcsd_host_unlock(host); - rt_mb_send(&mmcsd_hotpluge_mb, (rt_uint32_t)host); + rt_mb_send(&mmcsd_hotpluge_mb, (rt_ubase_t)host); continue; } @@ -664,7 +662,7 @@ void mmcsd_detect(void *param) if (init_mmc(host, ocr)) mmcsd_power_off(host); mmcsd_host_unlock(host); - rt_mb_send(&mmcsd_hotpluge_mb, (rt_uint32_t)host); + rt_mb_send(&mmcsd_hotpluge_mb, (rt_ubase_t)host); continue; } mmcsd_host_unlock(host); @@ -685,7 +683,7 @@ void mmcsd_detect(void *param) host->card = RT_NULL; } mmcsd_host_unlock(host); - rt_mb_send(&mmcsd_hotpluge_mb, (rt_uint32_t)host); + rt_mb_send(&mmcsd_hotpluge_mb, (rt_ubase_t)host); } } } diff --git a/components/drivers/sdio/sd.c b/components/drivers/sdio/sd.c index 338ecfa7c5..f7e4e46720 100644 --- a/components/drivers/sdio/sd.c +++ b/components/drivers/sdio/sd.c @@ -11,14 +11,12 @@ #include <drivers/mmcsd_core.h> #include <drivers/sd.h> -#define DBG_ENABLE -#define DBG_SECTION_NAME "[SDIO]" +#define DBG_TAG "SDIO" #ifdef RT_SDIO_DEBUG -#define DBG_LEVEL DBG_LOG +#define DBG_LVL DBG_LOG #else -#define DBG_LEVEL DBG_INFO +#define DBG_LVL DBG_INFO #endif /* RT_SDIO_DEBUG */ -#define DBG_COLOR #include <rtdbg.h> static const rt_uint32_t tran_unit[] = @@ -95,25 +93,6 @@ static rt_int32_t mmcsd_parse_csd(struct rt_mmcsd_card *card) card->tacc_ns = (tacc_uint[csd->taac&0x07] * tacc_value[(csd->taac&0x78)>>3] + 9) / 10; card->max_data_rate = tran_unit[csd->tran_speed&0x07] * tran_value[(csd->tran_speed&0x78)>>3]; - #if 0 - val = GET_BITS(resp, 115, 4); - unit = GET_BITS(resp, 112, 3); - csd->tacc_ns = (tacc_uint[unit] * tacc_value[val] + 9) / 10; - csd->tacc_clks = GET_BITS(resp, 104, 8) * 100; - - val = GET_BITS(resp, 99, 4); - unit = GET_BITS(resp, 96, 3); - csd->max_data_rate = tran_unit[unit] * tran_value[val]; - csd->ccc = GET_BITS(resp, 84, 12); - - unit = GET_BITS(resp, 47, 3); - val = GET_BITS(resp, 62, 12); - csd->device_size = (1 + val) << (unit + 2); - - csd->read_bl_len = GET_BITS(resp, 80, 4); - csd->write_bl_len = GET_BITS(resp, 22, 4); - csd->r2w_factor = GET_BITS(resp, 26, 3); - #endif break; case 1: card->flags |= CARD_FLAG_SDHC; @@ -144,23 +123,6 @@ static rt_int32_t mmcsd_parse_csd(struct rt_mmcsd_card *card) card->tacc_ns = 0; card->max_data_rate = tran_unit[csd->tran_speed&0x07] * tran_value[(csd->tran_speed&0x78)>>3]; - #if 0 - csd->tacc_ns = 0; - csd->tacc_clks = 0; - - val = GET_BITS(resp, 99, 4); - unit = GET_BITS(resp, 96, 3); - csd->max_data_rate = tran_unit[unit] * tran_value[val]; - csd->ccc = GET_BITS(resp, 84, 12); - - val = GET_BITS(resp, 48, 22); - csd->device_size = (1 + val) << 10; - - csd->read_bl_len = 9; - csd->write_bl_len = 9; - /* host should not use this factor and should use 250ms for write timeout */ - csd->r2w_factor = 2; - #endif break; default: LOG_E("unrecognised CSD structure version %d!", csd->csd_structure); @@ -266,7 +228,7 @@ static rt_int32_t mmcsd_switch(struct rt_mmcsd_card *card) if ((buf[16] & 0xF) != 1) { - LOG_E("switching card to high speed failed!"); + LOG_I("switching card to high speed failed!"); goto err; } diff --git a/components/drivers/sdio/sdio.c b/components/drivers/sdio/sdio.c index 7eeb312f6f..65bf87b895 100644 --- a/components/drivers/sdio/sdio.c +++ b/components/drivers/sdio/sdio.c @@ -12,14 +12,12 @@ #include <drivers/sdio.h> #include <drivers/sd.h> -#define DBG_ENABLE -#define DBG_SECTION_NAME "[SDIO]" +#define DBG_TAG "SDIO" #ifdef RT_SDIO_DEBUG -#define DBG_LEVEL DBG_LOG +#define DBG_LVL DBG_LOG #else -#define DBG_LEVEL DBG_INFO +#define DBG_LVL DBG_INFO #endif /* RT_SDIO_DEBUG */ -#define DBG_COLOR #include <rtdbg.h> #ifndef RT_SDIO_STACK_SIZE @@ -711,6 +709,16 @@ static rt_int32_t sdio_initialize_function(struct rt_mmcsd_card *card, if (ret) goto err1; + /* + * product/manufacturer id is optional for function CIS, so + * copy it from the card structure as needed. + */ + if (func->product == 0) + { + func->manufacturer = card->cis.manufacturer; + func->product = card->cis.product; + } + card->sdio_function[func_num] = func; return 0; |
