From 9ad45a693273abc5cabe5b9d6376753a1e3b907e Mon Sep 17 00:00:00 2001 From: Gabriel Somlo Date: Wed, 17 Jun 2020 17:21:33 -0400 Subject: [PATCH] liblitesdcard/[spi]sdcard: avoid redundant (re-)initialization --- litex/soc/software/liblitesdcard/sdcard.c | 3 ++- litex/soc/software/liblitesdcard/spisdcard.c | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/litex/soc/software/liblitesdcard/sdcard.c b/litex/soc/software/liblitesdcard/sdcard.c index f3108f8ac..abf8e7dbd 100644 --- a/litex/soc/software/liblitesdcard/sdcard.c +++ b/litex/soc/software/liblitesdcard/sdcard.c @@ -728,7 +728,8 @@ DSTATUS disk_status(uint8_t drv) { DSTATUS disk_initialize(uint8_t drv) { if (drv) return STA_NOINIT; - sdcardstatus = sdcard_init() ? 0 : STA_NOINIT; + if (sdcardstatus) + sdcardstatus = sdcard_init() ? 0 : STA_NOINIT; return sdcardstatus; } diff --git a/litex/soc/software/liblitesdcard/spisdcard.c b/litex/soc/software/liblitesdcard/spisdcard.c index 510c34fe7..7131d0830 100644 --- a/litex/soc/software/liblitesdcard/spisdcard.c +++ b/litex/soc/software/liblitesdcard/spisdcard.c @@ -277,8 +277,10 @@ DSTATUS disk_status(uint8_t drv) { DSTATUS disk_initialize(uint8_t drv) { if (drv) return STA_NOINIT; - spisdcardstatus = spisdcard_init() ? 0 : STA_NOINIT; - spisdcard_deselect(); + if (spisdcardstatus) { + spisdcardstatus = spisdcard_init() ? 0 : STA_NOINIT; + spisdcard_deselect(); + } return spisdcardstatus; }