Ask the controller to reset itself during controller setup.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/hw/sdcard.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
diff --git a/src/hw/sdcard.c b/src/hw/sdcard.c index 10832b1..5f9ce4a 100644 --- a/src/hw/sdcard.c +++ b/src/hw/sdcard.c @@ -113,6 +113,11 @@ struct sdhci_s { #define SPC_V30 0x0c #define SPC_V33 0x0e
+// SDHCI software reset flags +#define SRF_ALL 0x01 +#define SRF_CMD 0x02 +#define SRF_DATA 0x04 + // SDHCI result flags #define SR_OCR_CCS (1<<30) #define SR_OCR_NOTBUSY (1<<31) @@ -153,6 +158,20 @@ sdcard_waitw(u16 *reg, u16 mask) } }
+// Send an sdhci reset +static int +sdcard_reset(struct sdhci_s *regs, int flags) +{ + writeb(®s->software_reset, flags); + u32 end = timer_calc(SDHCI_PIO_TIMEOUT); + while (readb(®s->software_reset)) + if (timer_check(end)) { + warn_timeout(); + return -1; + } + return 0; +} + // Send a command to the card. static int sdcard_pio(struct sdhci_s *regs, int cmd, u32 *param) @@ -403,6 +422,7 @@ sdcard_controller_setup(void *data) dprintf(3, "sdhci@%p ver=%x cap=%x %x\n", regs , readw(®s->controller_version) , readl(®s->cap_lo), readl(®s->cap_hi)); + sdcard_reset(regs, SRF_ALL); writew(®s->irq_signal, 0); writew(®s->irq_enable, 0xffff); writew(®s->error_signal, 0);