From owner-freebsd-usb@FreeBSD.ORG  Tue Mar 27 10:03:50 2007
Return-Path: <owner-freebsd-usb@FreeBSD.ORG>
X-Original-To: freebsd-usb@freebsd.org
Delivered-To: freebsd-usb@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id BAABE16A405;
	Tue, 27 Mar 2007 10:03:50 +0000 (UTC)
	(envelope-from a.bittau@cs.ucl.ac.uk)
Received: from darkircop.org (thug.cs.ucl.ac.uk [128.16.68.86])
	by mx1.freebsd.org (Postfix) with ESMTP id 5F05813C4C6;
	Tue, 27 Mar 2007 10:03:50 +0000 (UTC)
	(envelope-from a.bittau@cs.ucl.ac.uk)
Received: by darkircop.org (Postfix, from userid 0)
	id 9A9266D732; Tue, 27 Mar 2007 10:53:01 +0100 (BST)
Date: Tue, 27 Mar 2007 10:53:01 +0100
From: Andrea Bittau <a.bittau@cs.ucl.ac.uk>
To: freebsd-usb@freebsd.org
Message-ID: <20070327095301.GA1439@shorty.sorbonet.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.4.2.1i
X-Echelon: Bush Bomb War KGB
Cc: iedowse@freebsd.org
Subject: fix uhci suspend
X-BeenThere: freebsd-usb@freebsd.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: FreeBSD support for USB <freebsd-usb.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-usb>,
	<mailto:freebsd-usb-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-usb>
List-Post: <mailto:freebsd-usb@freebsd.org>
List-Help: <mailto:freebsd-usb-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-usb>,
	<mailto:freebsd-usb-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Tue, 27 Mar 2007 10:03:50 -0000

To suspend, you need to:
1) stop the controller
2) set the global suspend bit

The current code does:
cmd = UREAD2(sc, UHCI_CMD);
...
uhci_run(sc, 0); /* stop the controller */
...
UHCICMD(sc, cmd | UHCI_CMD_EGSM); /* enter global suspend */

The problem is that cmd is not re-read after stopping the controller, so cmd
will still have the run bit set to 1 instead of 0.  Thus, when entering suspend,
the controller's run bit will be put back to 1 and the controller will freak
out.  The attached patch fixes this.  I don't know if the resume branch of the
code suffers from this problem too---I'm working on suspend for now.  With my
patch, I can get ICH7 82801G to suspend, otherwise, suspend would just hang the
box.

---

Index: uhci.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/usb/uhci.c,v
retrieving revision 1.172
diff -u -p -r1.172 uhci.c
--- uhci.c	19 Oct 2006 01:15:58 -0000	1.172
+++ uhci.c	27 Mar 2007 09:33:48 -0000
@@ -723,6 +723,7 @@ uhci_power(int why, void *v)
 			    sc->sc_intr_xfer);
 		sc->sc_bus.use_polling++;
 		uhci_run(sc, 0); /* stop the controller */
+		cmd &= ~UHCI_CMD_RS;
 
 		/* save some state if BIOS doesn't */
 		sc->sc_saved_frnum = UREAD2(sc, UHCI_FRNUM);