Skip to content

Commit 2c52f9e

Browse files
JordanYatesnashif
authored andcommitted
disk: sdmmc: power off card in DISK_IOCTL_CTRL_DEINIT
Power off the SD card in `DISK_IOCTL_CTRL_DEINIT`, instead of only waiting for the card to be idle then doing nothing. This is a safer state for `DISK_IOCTL_CTRL_DEINIT`, which is documented as preparing the disk to be removed from the system. It also has the advantage of lowering power consumption while de-initialized. Signed-off-by: Jordan Yates <[email protected]>
1 parent 6eb1e65 commit 2c52f9e

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

drivers/disk/sdmmc_subsys.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,9 @@ static int disk_sdmmc_access_ioctl(struct disk_info *disk, uint8_t cmd, void *bu
9393
case DISK_IOCTL_CTRL_INIT:
9494
return disk_sdmmc_access_init(disk);
9595
case DISK_IOCTL_CTRL_DEINIT:
96-
sdmmc_ioctl(&data->card, DISK_IOCTL_CTRL_SYNC, NULL);
97-
/* sd_init() will toggle power to SDMMC, so we can just mark
98-
* disk as uninitialized
99-
*/
96+
/* Card will be uninitialized after DEINIT */
10097
data->status = SD_UNINIT;
101-
return 0;
98+
return sdmmc_ioctl(&data->card, DISK_IOCTL_CTRL_DEINIT, NULL);
10299
default:
103100
return sdmmc_ioctl(&data->card, cmd, buf);
104101
}

subsys/sd/sd_ops.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,16 @@ int card_ioctl(struct sd_card *card, uint8_t cmd, void *buf)
795795
*/
796796
ret = sdmmc_wait_ready(card);
797797
break;
798+
case DISK_IOCTL_CTRL_DEINIT:
799+
/* Ensure card is not busy with data write */
800+
ret = sdmmc_wait_ready(card);
801+
if (ret < 0) {
802+
LOG_WRN("Card busy when powering off");
803+
}
804+
/* Power down the card */
805+
card->bus_io.power_mode = SDHC_POWER_OFF;
806+
ret = sdhc_set_io(card->sdhc, &card->bus_io);
807+
break;
798808
default:
799809
ret = -ENOTSUP;
800810
}

0 commit comments

Comments
 (0)