diff mbox series

[for-3.0,1/1] hw/sd/omap_mmc: Split 'pseudo-reset' from 'power-on-reset'

Message ID 20180706162155.8432-2-f4bug@amsat.org
State New
Headers show
Series [for-3.0,1/1] hw/sd/omap_mmc: Split 'pseudo-reset' from 'power-on-reset' | expand

Commit Message

Philippe Mathieu-Daudé July 6, 2018, 4:21 p.m. UTC
DeviceClass::reset models a "cold power-on" reset which can
also be use to powercycle a device; but there is no "hot reset"
(a.k.a. soft-reset) method available.

The OMAP MMC Power-Up Control bit is not designed to powercycle
a card, but to disable it without powering it off (pseudo-reset):

  Multimedia Card (MMC/SD/SDIO) Interface [SPRU765A]

  MMC_CON[11] Power-Up Control (POW)
  This bit must be set to 1 before any valid transaction to either
  MMC/SD or SPI memory cards.
  When 1, the card is considered powered-up and the controller core
  is enabled.
  When 0, the card is considered powered-down (system dependent),
  and the controller core logic is in pseudo-reset state. This is,
  the MMC_STAT flags and the FIFO pointers are reset, any access to
  MMC_DATA[DATA] has no effect, a write into the MMC.CMD register
  is ignored, and a setting of MMC_SPI[STR] to 1 is ignored.

By spliting the 'pseudo-reset' code out of the 'power-on' reset
function, this patch fixes a latent bug in omap_mmc_write(MMC_CON)i
recently exposed by ecd219f7abb.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
---
 hw/sd/omap_mmc.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Comments

Peter Maydell July 9, 2018, 1:07 p.m. UTC | #1
On 6 July 2018 at 17:21, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> DeviceClass::reset models a "cold power-on" reset which can
> also be use to powercycle a device; but there is no "hot reset"
> (a.k.a. soft-reset) method available.
>
> The OMAP MMC Power-Up Control bit is not designed to powercycle
> a card, but to disable it without powering it off (pseudo-reset):
>
>   Multimedia Card (MMC/SD/SDIO) Interface [SPRU765A]
>
>   MMC_CON[11] Power-Up Control (POW)
>   This bit must be set to 1 before any valid transaction to either
>   MMC/SD or SPI memory cards.
>   When 1, the card is considered powered-up and the controller core
>   is enabled.
>   When 0, the card is considered powered-down (system dependent),
>   and the controller core logic is in pseudo-reset state. This is,
>   the MMC_STAT flags and the FIFO pointers are reset, any access to
>   MMC_DATA[DATA] has no effect, a write into the MMC.CMD register
>   is ignored, and a setting of MMC_SPI[STR] to 1 is ignored.

This text says that the card "is considered powered-down (system
dependent)", so it's not entirely invalid to reset the card here.
Still, if the guests get confused by it I guess that the n8x0
systems didn't do that, and certainly resetting the other parts
of the controller state is wrong.

Strictly I guess we should also check the enable flag for the other
things this text calls out:
 * accesses to MMC_DATA[DATA]
 * writes to MMC.CMD (we already do this)
 * setting MMC_SPI[STR] to 1 (we don't emulate MMC_SPI)

but we should probably consider that a separate bug. (And the
n8x0 boards are pretty much unmaintained currently, so I don't
care very much whether we fix it or not. I don't have any working
test images -- I have one of uncertain vintage which seems to
be flaky when it gets to the mmc card init, but I think it
makes a bit more progress with this patch now.)

Applied to target-arm.next, thanks.

thanks
-- PMM
diff mbox series

Patch

diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c
index 671264b650..d0c98ca021 100644
--- a/hw/sd/omap_mmc.c
+++ b/hw/sd/omap_mmc.c
@@ -1,6 +1,8 @@ 
 /*
  * OMAP on-chip MMC/SD host emulation.
  *
+ * Datasheet: TI Multimedia Card (MMC/SD/SDIO) Interface (SPRU765A)
+ *
  * Copyright (C) 2006-2007 Andrzej Zaborowski  <balrog@zabor.org>
  *
  * This program is free software; you can redistribute it and/or
@@ -278,6 +280,12 @@  static void omap_mmc_update(void *opaque)
     omap_mmc_interrupts_update(s);
 }
 
+static void omap_mmc_pseudo_reset(struct omap_mmc_s *host)
+{
+    host->status = 0;
+    host->fifo_len = 0;
+}
+
 void omap_mmc_reset(struct omap_mmc_s *host)
 {
     host->last_cmd = 0;
@@ -286,11 +294,9 @@  void omap_mmc_reset(struct omap_mmc_s *host)
     host->dw = 0;
     host->mode = 0;
     host->enable = 0;
-    host->status = 0;
     host->mask = 0;
     host->cto = 0;
     host->dto = 0;
-    host->fifo_len = 0;
     host->blen = 0;
     host->blen_counter = 0;
     host->nblk = 0;
@@ -305,6 +311,8 @@  void omap_mmc_reset(struct omap_mmc_s *host)
     qemu_set_irq(host->coverswitch, host->cdet_state);
     host->clkdiv = 0;
 
+    omap_mmc_pseudo_reset(host);
+
     /* Since we're still using the legacy SD API the card is not plugged
      * into any bus, and we must reset it manually. When omap_mmc is
      * QOMified this must move into the QOM reset function.
@@ -459,7 +467,7 @@  static void omap_mmc_write(void *opaque, hwaddr offset,
         if (s->dw != 0 && s->lines < 4)
             printf("4-bit SD bus enabled\n");
         if (!s->enable)
-            omap_mmc_reset(s);
+            omap_mmc_pseudo_reset(s);
         break;
 
     case 0x10:	/* MMC_STAT */