Skip to content

Commit

Permalink
[components][drivers][sdio] Fix minor issue in sdio driver
Browse files Browse the repository at this point in the history
- Corrected the HIGH_SPEED timing setting
- Adjusted the bus_width setting logic
- Avoided potential null derefence issue in rt_mmcsd_blk_remove function

Signed-off-by: Fan YANG <[email protected]>
  • Loading branch information
helloeagleyang committed Aug 2, 2023
1 parent 69d9431 commit 5ccea0e
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions components/drivers/sdio/mmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ static int mmc_compare_ext_csds(struct rt_mmcsd_card *card,
}

/*
* Select the bus width amoung 4-bit and 8-bit(SDR).
* Select the bus width among 4-bit and 8-bit(SDR).
* If the bus width is changed successfully, return the selected width value.
* Zero is returned instead of error value if the wide width is not supported.
*/
Expand Down Expand Up @@ -337,22 +337,21 @@ static int mmc_select_bus_width(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd)
ddr = 2;
}
/*
* Unlike SD, MMC cards dont have a configuration register to notify
* Unlike SD, MMC cards don't have a configuration register to notify
* supported bus width. So bus test command should be run to identify
* the supported bus width or compare the ext csd values of current
* bus width and ext csd values of 1 bit mode read earlier.
* the supported bus width or compare the EXT_CSD values of current
* bus width and EXT_CSD values of 1 bit mode read earlier.
*/
for (idx = 0; idx < sizeof(bus_widths) / sizeof(rt_uint32_t); idx++)
{
/*
* Host is capable of 8bit transfer, then switch
* 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. Meanwhile, mmc core would
* bail out early if corresponding bus capable wasn't
* set by drivers.
*/
* Determine BUS WIDTH mode according to the capability of host
*/
if (((ext_csd_bits[idx][0] == EXT_CSD_BUS_WIDTH_8) && ((host->flags & MMCSD_BUSWIDTH_8) == 0)) ||
((ext_csd_bits[idx][0] == EXT_CSD_BUS_WIDTH_4) && ((host->flags & MMCSD_BUSWIDTH_4) == 0)))
{
continue;
}
bus_width = bus_widths[idx];
if (bus_width == MMCSD_BUS_WIDTH_1)
{
Expand Down Expand Up @@ -507,7 +506,7 @@ static int mmc_select_timing(struct rt_mmcsd_card *card)
}
else
{
mmcsd_set_timing(card->host, MMCSD_TIMING_UHS_SDR50);
mmcsd_set_timing(card->host, MMCSD_TIMING_MMC_HS);
mmcsd_set_clock(card->host, card->hs_max_data_rate);
}

Expand Down

0 comments on commit 5ccea0e

Please sign in to comment.