From 2866da37a02dae72200e02ad87480718002760a5 Mon Sep 17 00:00:00 2001 From: zhuzhuzhu <945386260@qq.com> Date: Thu, 13 Jun 2024 17:06:46 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E4=BF=AE=E5=A4=8DART-PI=20smart?= =?UTF-8?q?=E5=9C=A8sd/emmc=E8=AF=BB=E5=8F=96=E4=B8=8D=E5=88=B0=E5=88=86?= =?UTF-8?q?=E5=8C=BA=E7=9A=84=E9=97=AE=E9=A2=98=20(#9058)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update sd.c --- components/drivers/sdio/sd.c | 50 ++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/components/drivers/sdio/sd.c b/components/drivers/sdio/sd.c index d2e18b2631..6e826d5af5 100644 --- a/components/drivers/sdio/sd.c +++ b/components/drivers/sdio/sd.c @@ -755,6 +755,31 @@ static rt_int32_t mmcsd_sd_init_card(struct rt_mmcsd_host *host, goto err1; } + mmcsd_set_timing(host, MMCSD_TIMING_LEGACY); + mmcsd_set_clock(host, 25000000); + /*switch bus width*/ + if ((host->flags & MMCSD_BUSWIDTH_4) && (card->scr.sd_bus_widths & SD_SCR_BUS_WIDTH_4)) + { + err = mmcsd_app_set_bus_width(card, MMCSD_BUS_WIDTH_4); + if (err) + goto err1; + + mmcsd_set_bus_width(host, MMCSD_BUS_WIDTH_4); + } + + /* Read and decode SD Status and check whether UHS mode is supported */ + union rt_sd_status sd_status; + err = mmcsd_read_sd_status(card, sd_status.status_words); + if (err) + goto err1; + if ((sd_status.uhs_speed_grade > 0) && (ocr & VDD_165_195)) + { + /* Assume the card supports all UHS-I modes because we cannot find any mainstreaming card + * that can support only part of the following modes. + */ + card->flags |= CARD_FLAG_SDR50 | CARD_FLAG_SDR104 | CARD_FLAG_DDR50; + } + /* * change SD card to the highest supported speed */ @@ -774,31 +799,6 @@ static rt_int32_t mmcsd_sd_init_card(struct rt_mmcsd_host *host, } mmcsd_set_clock(host, max_data_rate); - /*switch bus width*/ - if ((host->flags & MMCSD_BUSWIDTH_4) && (card->scr.sd_bus_widths & SD_SCR_BUS_WIDTH_4)) - { - err = mmcsd_app_set_bus_width(card, MMCSD_BUS_WIDTH_4); - if (err) - goto err1; - - mmcsd_set_bus_width(host, MMCSD_BUS_WIDTH_4); - } - mmcsd_set_timing(host, MMCSD_TIMING_LEGACY); - mmcsd_set_clock(host, 25000000); - - /* Read and decode SD Status and check whether UHS mode is supported */ - union rt_sd_status sd_status; - err = mmcsd_read_sd_status(card, sd_status.status_words); - if (err) - goto err1; - if ((sd_status.uhs_speed_grade > 0) && (ocr & VDD_165_195)) - { - /* Assume the card supports all UHS-I modes because we cannot find any mainstreaming card - * that can support only part of the following modes. - */ - card->flags |= CARD_FLAG_SDR50 | CARD_FLAG_SDR104 | CARD_FLAG_DDR50; - } - host->card = card; return 0;