From: Kevin O'Connor Date: Tue, 11 Aug 2015 16:59:53 +0000 (-0400) Subject: sdcard: The card should never be in a busy state at start of sdcard_pio() X-Git-Tag: rel-1.9.0~60 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=34cc2fd4e8b0db6fdbeaea161b1cdb24ed559d33;p=seabios.git sdcard: The card should never be in a busy state at start of sdcard_pio() Return an error if the controller is busy at the start of a command instead of waiting. Signed-off-by: Kevin O'Connor --- diff --git a/src/hw/sdcard.c b/src/hw/sdcard.c index 4dd93cb..4cec423 100644 --- a/src/hw/sdcard.c +++ b/src/hw/sdcard.c @@ -157,15 +157,18 @@ waitw(u16 *reg, u16 mask, u16 value, u32 end) static int sdcard_pio(struct sdhci_s *regs, int cmd, u32 *param) { - u32 end = timer_calc(SDHCI_PIO_TIMEOUT); - u16 busyf = SP_CMD_INHIBIT | ((cmd & 0x03) == 0x03 ? SP_DAT_INHIBIT : 0); - int ret = waitw((u16*)®s->present_state, busyf, 0, end); - if (ret) - return ret; + u32 state = readl(®s->present_state); + dprintf(9, "sdcard_pio cmd %x %x %x\n", cmd, *param, state); + if ((state & SP_CMD_INHIBIT) + || ((cmd & 0x03) == 0x03 && state & SP_DAT_INHIBIT)) { + dprintf(1, "sdcard_pio not ready %x\n", state); + return -1; + } // Send command writel(®s->arg, *param); writew(®s->cmd, cmd); - ret = waitw(®s->irq_status, SI_CMD_COMPLETE, SI_CMD_COMPLETE, end); + u32 end = timer_calc(SDHCI_PIO_TIMEOUT); + int ret = waitw(®s->irq_status, SI_CMD_COMPLETE, SI_CMD_COMPLETE, end); if (ret) return ret; writew(®s->irq_status, SI_CMD_COMPLETE);