diff mbox

[33/34] hw/usb-ohci.c: Implement remote wakeup

Message ID 1308049552-5744-3-git-send-email-kraxel@redhat.com
State New
Headers show

Commit Message

Gerd Hoffmann June 14, 2011, 11:05 a.m. UTC
From: Peter Maydell <peter.maydell@linaro.org>

Implement the wakeup callback in the OHCI USBPortOps, so that when
a downstream device wakes up it correctly causes the OHCI controller
to come out of suspend.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb-ohci.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

Comments

Peter Maydell June 15, 2011, 3:03 p.m. UTC | #1
On 14 June 2011 12:05, Gerd Hoffmann <kraxel@redhat.com> wrote:
> From: Peter Maydell <peter.maydell@linaro.org>
>
> Implement the wakeup callback in the OHCI USBPortOps, so that when
> a downstream device wakes up it correctly causes the OHCI controller
> to come out of suspend.

Just to let you know, this patch turns out to not be quite right:
 * if the port is suspended and the controller is not, we need to
   raise OHCI_INTR_RHSC
 * if the controller is suspended we need to put it into the
   resume state
 * the controller can be suspended when the port is not, so the
   check on s->ctl musn't be inside the port->ctrl if().

Sorry for the half-baked patch. I'll send a fixed version shortly.

-- PMM
diff mbox

Patch

diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c
index ab77434..832dcd6 100644
--- a/hw/usb-ohci.c
+++ b/hw/usb-ohci.c
@@ -367,6 +367,22 @@  static void ohci_detach(USBPort *port1)
         ohci_set_interrupt(s, OHCI_INTR_RHSC);
 }
 
+static void ohci_wakeup(USBDevice *dev)
+{
+    USBBus *bus = usb_bus_from_device(dev);
+    OHCIState *s = container_of(bus, OHCIState, bus);
+    int portnum = dev->port->index;
+    OHCIPort *port = &s->rhport[portnum];
+    if (port->ctrl & OHCI_PORT_PSS) {
+        DPRINTF("usb-ohci: port %d: wakeup\n", portnum);
+        port->ctrl |= OHCI_PORT_PSSC;
+        port->ctrl &= ~OHCI_PORT_PSS;
+        if ((s->ctl & OHCI_CTL_HCFS) == OHCI_USB_SUSPEND) {
+            ohci_set_interrupt(s, OHCI_INTR_RD);
+        }
+    }
+}
+
 /* Reset the controller */
 static void ohci_reset(void *opaque)
 {
@@ -1675,6 +1691,7 @@  static CPUWriteMemoryFunc * const ohci_writefn[3]={
 static USBPortOps ohci_port_ops = {
     .attach = ohci_attach,
     .detach = ohci_detach,
+    .wakeup = ohci_wakeup,
     .complete = ohci_async_complete_packet,
 };