Subject: Re: USB power handler (was Re: Call for testers: ACPI
To: Jared D. McNeill <jmcneill@invisible.ca>
From: Matthias Drochner <M.Drochner@fz-juelich.de>
List: current-users
Date: 12/20/2007 21:16:58
This is a multipart MIME message.

--==_Exmh_62304535762980
Content-Type: text/plain; charset=us-ascii


jmcneill@invisible.ca said:
> the internal port (where  ugen attaches to a fingerprint reader) seems
> fine, but the external ports  lose

Does it make a difference whether the device connected is
a highspeed one or low/full? So we could know whether to
blame the ehci or uhci code.

The ehci_resume code is partially bogus, but I'm not sure
this is the source of your problems. There is at least
the write to USBCMD which is done twice -- it should be
only once, before the port de-suspend, and the loop polling
for the halt bit should follow immediately, so that the
controller is properly running before the ports are touched.
The should also be a ~10ms delay after the resume signaling
before devices are accessed.
All this is harmless on my box because the port desuspend
code doesn't do anything -- at the time the resume code
is called my ports are all disabled, and the port status
change bit is set, so that the standard reset sequence will be
executed later. This might be due to some ACPI actions, or it
happens within the PCI D3->D0 transition. (It is an ICH7,
82801GB/GR.)

I'll append a patch which does some primitive instrumentation
to track these things.
A kernel with USB_DEBUG enabled could also help.

best regards
Matthias





-------------------------------------------------------------------
-------------------------------------------------------------------
Forschungszentrum Juelich GmbH
52425 Juelich

Sitz der Gesellschaft: Juelich
Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498
Vorsitzende des Aufsichtsrats: MinDirig'in Baerbel Brumme-Bothe
Geschaeftsfuehrung: Prof. Dr. Achim Bachem (Vorsitzender),
Dr. Ulrich Krafft (stellv. Vorsitzender), Dr. Sebastian M. Schmidt
-------------------------------------------------------------------
-------------------------------------------------------------------

--==_Exmh_62304535762980
Content-Type: text/plain ; name="ehci.txt"; charset=us-ascii
Content-Description: ehci.txt
Content-Disposition: attachment; filename="ehci.txt"

#
# old_revision [79fcb10fc654029959a54b5ef022386d4cbda98c]
#
# patch "sys/dev/usb/ehci.c"
#  from [05056837be4c29c7355ddd93c94fb2308d37255e]
#    to [aca9b9a5ed3fbedff4fb6c7891ed1a03983b09bd]
#
============================================================
--- sys/dev/usb/ehci.c	05056837be4c29c7355ddd93c94fb2308d37255e
+++ sys/dev/usb/ehci.c	aca9b9a5ed3fbedff4fb6c7891ed1a03983b09bd
@@ -976,6 +976,7 @@ ehci_suspend(device_t dv)
 
 	for (i = 1; i <= sc->sc_noport; i++) {
 		cmd = EOREAD4(sc, EHCI_PORTSC(i));
+		printf("ehci(s) p%d stat %x\n", i, cmd);
 		if ((cmd & EHCI_PS_PO) == 0 && (cmd & EHCI_PS_PE) == EHCI_PS_PE)
 			EOWRITE4(sc, EHCI_PORTSC(i), cmd | EHCI_PS_SUSP);
 	}
@@ -1033,10 +1034,16 @@ ehci_resume(device_t dv)
 	EOWRITE4(sc, EHCI_USBINTR, sc->sc_eintrs);
 
 	EOWRITE4(sc, EHCI_USBCMD, sc->sc_cmd);
+	usb_delay_ms(&sc->sc_bus, 100);
+	hcr = EOREAD4(sc, EHCI_USBSTS);
+	printf("ehci: sts=%x\n", hcr);
+	hcr = EOREAD4(sc, EHCI_USBCMD);
+	printf("ehci: cmd=%x\n", hcr);
 
 	hcr = 0;
 	for (i = 1; i <= sc->sc_noport; i++) {
 		cmd = EOREAD4(sc, EHCI_PORTSC(i));
+		printf("ehci(1) p%d stat %x\n", i, cmd);
 		if ((cmd & EHCI_PS_PO) == 0 &&
 		    (cmd & EHCI_PS_SUSP) == EHCI_PS_SUSP) {
 			EOWRITE4(sc, EHCI_PORTSC(i), cmd | EHCI_PS_FPR);
@@ -1049,14 +1056,20 @@ ehci_resume(device_t dv)
 
 		for (i = 1; i <= sc->sc_noport; i++) {
 			cmd = EOREAD4(sc, EHCI_PORTSC(i));
+			printf("ehci(2) p%d stat %x\n", i, cmd);
 			if ((cmd & EHCI_PS_PO) == 0 &&
 			    (cmd & EHCI_PS_SUSP) == EHCI_PS_SUSP)
 				EOWRITE4(sc, EHCI_PORTSC(i),
 				    cmd & ~EHCI_PS_FPR);
+			cmd = EOREAD4(sc, EHCI_PORTSC(i));
+			printf("ehci(3) p%d stat %x\n", i, cmd);
+			usb_delay_ms(&sc->sc_bus, 2);
+			cmd = EOREAD4(sc, EHCI_PORTSC(i));
+			printf("ehci(4) p%d stat %x\n", i, cmd);
 		}
 	}
 
-	EOWRITE4(sc, EHCI_USBCMD, sc->sc_cmd);
+	/*EOWRITE4(sc, EHCI_USBCMD, sc->sc_cmd);*/
 
 	for (i = 0; i < 100; i++) {
 		hcr = EOREAD4(sc, EHCI_USBSTS) & EHCI_STS_HCH;

--==_Exmh_62304535762980--