Skip to content

Commit a16bfb3

Browse files
JordanYateskartben
authored andcommitted
sdhc: spi: power card before 74 clock signals
Power on the SD card before sending the required 74 clock signals. Signed-off-by: Jordan Yates <[email protected]>
1 parent 017cb3a commit a16bfb3

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

drivers/sdhc/sdhc_spi.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -722,20 +722,21 @@ static int sdhc_spi_set_io(const struct device *dev, struct sdhc_io *ios)
722722
}
723723
if (data->power_mode != ios->power_mode) {
724724
if (ios->power_mode == SDHC_POWER_ON) {
725+
if (cfg->pwr_gpio.port) {
726+
if (gpio_pin_set_dt(&cfg->pwr_gpio, 1)) {
727+
return -EIO;
728+
}
729+
730+
LOG_INF("Powered up");
731+
}
732+
725733
/* Send 74 clock cycles to start card */
726734
if (sdhc_spi_init_card(dev) != 0) {
727735
LOG_ERR("Card SCLK init sequence failed");
728736
return -EIO;
729737
}
730-
}
731-
if (cfg->pwr_gpio.port) {
732-
/* If power control GPIO is defined, toggle SD power */
733-
if (ios->power_mode == SDHC_POWER_ON) {
734-
if (gpio_pin_set_dt(&cfg->pwr_gpio, 1)) {
735-
return -EIO;
736-
}
737-
LOG_INF("Powered up");
738-
} else {
738+
} else {
739+
if (cfg->pwr_gpio.port) {
739740
if (gpio_pin_set_dt(&cfg->pwr_gpio, 0)) {
740741
return -EIO;
741742
}

0 commit comments

Comments
 (0)