Return an error if the controller is busy at the start of a command instead of waiting.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/hw/sdcard.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
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);