Author: hselasky
Date: Sat Dec 31 14:22:02 2011
New Revision: 229096
URL: http://svn.freebsd.org/changeset/base/229096

Log:
  MFC r229086, r228483 and r228640:
  Implement better support for USB controller suspend and resume.
  Fix some build issues in avr32dci.c

Added:
  stable/9/sys/modules/usb/avr32dci/
     - copied from r228483, head/sys/modules/usb/avr32dci/
Modified:
  stable/9/sys/arm/econa/ehci_ebus.c
  stable/9/sys/arm/econa/ohci_ec.c
  stable/9/sys/dev/usb/controller/at91dci.c
  stable/9/sys/dev/usb/controller/at91dci.h
  stable/9/sys/dev/usb/controller/at91dci_atmelarm.c
  stable/9/sys/dev/usb/controller/atmegadci.c
  stable/9/sys/dev/usb/controller/atmegadci.h
  stable/9/sys/dev/usb/controller/atmegadci_atmelarm.c
  stable/9/sys/dev/usb/controller/avr32dci.c
  stable/9/sys/dev/usb/controller/avr32dci.h
  stable/9/sys/dev/usb/controller/ehci.c
  stable/9/sys/dev/usb/controller/ehci.h
  stable/9/sys/dev/usb/controller/ehci_ixp4xx.c
  stable/9/sys/dev/usb/controller/ehci_mv.c
  stable/9/sys/dev/usb/controller/ehci_pci.c
  stable/9/sys/dev/usb/controller/musb_otg.c
  stable/9/sys/dev/usb/controller/musb_otg.h
  stable/9/sys/dev/usb/controller/musb_otg_atmelarm.c
  stable/9/sys/dev/usb/controller/ohci.c
  stable/9/sys/dev/usb/controller/ohci.h
  stable/9/sys/dev/usb/controller/ohci_atmelarm.c
  stable/9/sys/dev/usb/controller/ohci_pci.c
  stable/9/sys/dev/usb/controller/ohci_s3c24x0.c
  stable/9/sys/dev/usb/controller/uhci.c
  stable/9/sys/dev/usb/controller/uhci.h
  stable/9/sys/dev/usb/controller/uhci_pci.c
  stable/9/sys/dev/usb/controller/usb_controller.c
  stable/9/sys/dev/usb/controller/uss820dci.c
  stable/9/sys/dev/usb/controller/uss820dci.h
  stable/9/sys/dev/usb/controller/uss820dci_atmelarm.c
  stable/9/sys/dev/usb/controller/xhci.c
  stable/9/sys/dev/usb/controller/xhci.h
  stable/9/sys/dev/usb/controller/xhci_pci.c
  stable/9/sys/dev/usb/usb_bus.h
  stable/9/sys/dev/usb/usb_controller.h
  stable/9/sys/dev/usb/usb_if.m
  stable/9/sys/mips/atheros/ar71xx_ehci.c
  stable/9/sys/mips/atheros/ar71xx_ohci.c
  stable/9/sys/mips/cavium/usb/octusb.c
  stable/9/sys/mips/cavium/usb/octusb.h
  stable/9/sys/mips/cavium/usb/octusb_octeon.c
  stable/9/sys/mips/rmi/xls_ehci.c
  stable/9/sys/mips/rt305x/rt305x_dotg.c
  stable/9/sys/modules/usb/Makefile
  stable/9/sys/powerpc/ps3/ehci_ps3.c
  stable/9/sys/powerpc/ps3/ohci_ps3.c
Directory Properties:
  stable/9/sys/   (props changed)
  stable/9/sys/amd64/include/xen/   (props changed)
  stable/9/sys/boot/   (props changed)
  stable/9/sys/boot/i386/efi/   (props changed)
  stable/9/sys/boot/ia64/efi/   (props changed)
  stable/9/sys/boot/ia64/ski/   (props changed)
  stable/9/sys/boot/powerpc/boot1.chrp/   (props changed)
  stable/9/sys/boot/powerpc/ofw/   (props changed)
  stable/9/sys/cddl/contrib/opensolaris/   (props changed)
  stable/9/sys/conf/   (props changed)
  stable/9/sys/contrib/dev/acpica/   (props changed)
  stable/9/sys/contrib/octeon-sdk/   (props changed)
  stable/9/sys/contrib/pf/   (props changed)
  stable/9/sys/contrib/x86emu/   (props changed)

Modified: stable/9/sys/arm/econa/ehci_ebus.c
==============================================================================
--- stable/9/sys/arm/econa/ehci_ebus.c  Sat Dec 31 14:21:41 2011        
(r229095)
+++ stable/9/sys/arm/econa/ehci_ebus.c  Sat Dec 31 14:22:02 2011        
(r229096)
@@ -75,10 +75,6 @@ __FBSDID("$FreeBSD$");
 
 static device_attach_t ehci_ebus_attach;
 static device_detach_t ehci_ebus_detach;
-static device_shutdown_t ehci_ebus_shutdown;
-static device_suspend_t ehci_ebus_suspend;
-static device_resume_t ehci_ebus_resume;
-
 
 static void *ih_err;
 
@@ -86,45 +82,6 @@ static void *ih_err;
 #define        USB_BRIDGE_INTR_MASK   0x214
 
 static int
-ehci_ebus_suspend(device_t self)
-{
-       ehci_softc_t *sc = device_get_softc(self);
-       int err;
-
-       err = bus_generic_suspend(self);
-       if (err)
-               return (err);
-       ehci_suspend(sc);
-       return (0);
-}
-
-static int
-ehci_ebus_resume(device_t self)
-{
-       ehci_softc_t *sc = device_get_softc(self);
-
-       ehci_resume(sc);
-
-       bus_generic_resume(self);
-
-       return (0);
-}
-
-static int
-ehci_ebus_shutdown(device_t self)
-{
-       ehci_softc_t *sc = device_get_softc(self);
-       int err;
-
-       err = bus_generic_shutdown(self);
-       if (err)
-               return (err);
-       ehci_shutdown(sc);
-
-       return (0);
-}
-
-static int
 ehci_ebus_probe(device_t self)
 {
 
@@ -277,17 +234,17 @@ static device_method_t ehci_methods[] = 
        DEVMETHOD(device_probe, ehci_ebus_probe),
        DEVMETHOD(device_attach, ehci_ebus_attach),
        DEVMETHOD(device_detach, ehci_ebus_detach),
-       DEVMETHOD(device_suspend, ehci_ebus_suspend),
-       DEVMETHOD(device_resume, ehci_ebus_resume),
-       DEVMETHOD(device_shutdown, ehci_ebus_shutdown),
+       DEVMETHOD(device_suspend, bus_generic_suspend),
+       DEVMETHOD(device_resume, bus_generic_resume),
+       DEVMETHOD(device_shutdown, bus_generic_shutdown),
 
        DEVMETHOD_END
 };
 
 static driver_t ehci_driver = {
-       "ehci",
-       ehci_methods,
-       sizeof(ehci_softc_t),
+       .name = "ehci",
+       .methods = ehci_methods,
+       .size = sizeof(ehci_softc_t),
 };
 
 static devclass_t ehci_devclass;

Modified: stable/9/sys/arm/econa/ohci_ec.c
==============================================================================
--- stable/9/sys/arm/econa/ohci_ec.c    Sat Dec 31 14:21:41 2011        
(r229095)
+++ stable/9/sys/arm/econa/ohci_ec.c    Sat Dec 31 14:22:02 2011        
(r229096)
@@ -220,15 +220,17 @@ static device_method_t ohci_methods[] = 
        DEVMETHOD(device_probe, ohci_ec_probe),
        DEVMETHOD(device_attach, ohci_ec_attach),
        DEVMETHOD(device_detach, ohci_ec_detach),
+       DEVMETHOD(device_resume, bus_generic_resume),
+       DEVMETHOD(device_suspend, bus_generic_suspend),
        DEVMETHOD(device_shutdown, bus_generic_shutdown),
 
        DEVMETHOD_END
 };
 
 static driver_t ohci_driver = {
-       "ohci",
-       ohci_methods,
-       sizeof(struct ec_ohci_softc),
+       .name = "ohci",
+       .methods = ohci_methods,
+       .size = sizeof(struct ec_ohci_softc),
 };
 
 static devclass_t ohci_devclass;

Modified: stable/9/sys/dev/usb/controller/at91dci.c
==============================================================================
--- stable/9/sys/dev/usb/controller/at91dci.c   Sat Dec 31 14:21:41 2011        
(r229095)
+++ stable/9/sys/dev/usb/controller/at91dci.c   Sat Dec 31 14:22:02 2011        
(r229096)
@@ -1461,16 +1461,16 @@ at91dci_uninit(struct at91dci_softc *sc)
        USB_BUS_UNLOCK(&sc->sc_bus);
 }
 
-void
+static void
 at91dci_suspend(struct at91dci_softc *sc)
 {
-       return;
+       /* TODO */
 }
 
-void
+static void
 at91dci_resume(struct at91dci_softc *sc)
 {
-       return;
+       /* TODO */
 }
 
 static void
@@ -2306,6 +2306,26 @@ at91dci_ep_init(struct usb_device *udev,
        }
 }
 
+static void
+at91dci_set_hw_power_sleep(struct usb_bus *bus, uint32_t state)
+{
+       struct at91dci_softc *sc = AT9100_DCI_BUS2SC(bus);
+
+       switch (state) {
+       case USB_HW_POWER_SUSPEND:
+               at91dci_suspend(sc);
+               break;
+       case USB_HW_POWER_SHUTDOWN:
+               at91dci_uninit(sc);
+               break;
+       case USB_HW_POWER_RESUME:
+               at91dci_resume(sc);
+               break;
+       default:
+               break;
+       }
+}
+
 struct usb_bus_methods at91dci_bus_methods =
 {
        .endpoint_init = &at91dci_ep_init,
@@ -2316,4 +2336,5 @@ struct usb_bus_methods at91dci_bus_metho
        .clear_stall = &at91dci_clear_stall,
        .roothub_exec = &at91dci_roothub_exec,
        .xfer_poll = &at91dci_do_poll,
+       .set_hw_power_sleep = &at91dci_set_hw_power_sleep,
 };

Modified: stable/9/sys/dev/usb/controller/at91dci.h
==============================================================================
--- stable/9/sys/dev/usb/controller/at91dci.h   Sat Dec 31 14:21:41 2011        
(r229095)
+++ stable/9/sys/dev/usb/controller/at91dci.h   Sat Dec 31 14:22:02 2011        
(r229096)
@@ -235,8 +235,6 @@ struct at91dci_softc {
 
 usb_error_t at91dci_init(struct at91dci_softc *sc);
 void   at91dci_uninit(struct at91dci_softc *sc);
-void   at91dci_suspend(struct at91dci_softc *sc);
-void   at91dci_resume(struct at91dci_softc *sc);
 void   at91dci_interrupt(struct at91dci_softc *sc);
 void   at91dci_vbus_interrupt(struct at91dci_softc *sc, uint8_t is_on);
 

Modified: stable/9/sys/dev/usb/controller/at91dci_atmelarm.c
==============================================================================
--- stable/9/sys/dev/usb/controller/at91dci_atmelarm.c  Sat Dec 31 14:21:41 
2011        (r229095)
+++ stable/9/sys/dev/usb/controller/at91dci_atmelarm.c  Sat Dec 31 14:22:02 
2011        (r229096)
@@ -77,7 +77,6 @@ __FBSDID("$FreeBSD$");
 static device_probe_t at91_udp_probe;
 static device_attach_t at91_udp_attach;
 static device_detach_t at91_udp_detach;
-static device_shutdown_t at91_udp_shutdown;
 
 struct at91_udp_softc {
        struct at91dci_softc sc_dci;    /* must be first */
@@ -324,35 +323,22 @@ at91_udp_detach(device_t dev)
        return (0);
 }
 
-static int
-at91_udp_shutdown(device_t dev)
-{
-       struct at91_udp_softc *sc = device_get_softc(dev);
-       int err;
-
-       err = bus_generic_shutdown(dev);
-       if (err)
-               return (err);
-
-       at91dci_uninit(&sc->sc_dci);
-
-       return (0);
-}
-
 static device_method_t at91_udp_methods[] = {
        /* Device interface */
        DEVMETHOD(device_probe, at91_udp_probe),
        DEVMETHOD(device_attach, at91_udp_attach),
        DEVMETHOD(device_detach, at91_udp_detach),
-       DEVMETHOD(device_shutdown, at91_udp_shutdown),
+       DEVMETHOD(device_suspend, bus_generic_suspend),
+       DEVMETHOD(device_resume, bus_generic_resume),
+       DEVMETHOD(device_shutdown, bus_generic_shutdown),
 
        DEVMETHOD_END
 };
 
 static driver_t at91_udp_driver = {
-       "at91_udp",
-       at91_udp_methods,
-       sizeof(struct at91_udp_softc),
+       .name = "at91_udp",
+       .methods = at91_udp_methods,
+       .size = sizeof(struct at91_udp_softc),
 };
 
 static devclass_t at91_udp_devclass;

Modified: stable/9/sys/dev/usb/controller/atmegadci.c
==============================================================================
--- stable/9/sys/dev/usb/controller/atmegadci.c Sat Dec 31 14:21:41 2011        
(r229095)
+++ stable/9/sys/dev/usb/controller/atmegadci.c Sat Dec 31 14:22:02 2011        
(r229096)
@@ -1351,16 +1351,16 @@ atmegadci_uninit(struct atmegadci_softc 
        USB_BUS_UNLOCK(&sc->sc_bus);
 }
 
-void
+static void
 atmegadci_suspend(struct atmegadci_softc *sc)
 {
-       return;
+       /* TODO */
 }
 
-void
+static void
 atmegadci_resume(struct atmegadci_softc *sc)
 {
-       return;
+       /* TODO */
 }
 
 static void
@@ -2125,6 +2125,26 @@ atmegadci_ep_init(struct usb_device *ude
        }
 }
 
+static void
+atmegadci_set_hw_power_sleep(struct usb_bus *bus, uint32_t state)
+{
+       struct atmegadci_softc *sc = ATMEGA_BUS2SC(bus);
+
+       switch (state) {
+       case USB_HW_POWER_SUSPEND:
+               atmegadci_suspend(sc);
+               break;
+       case USB_HW_POWER_SHUTDOWN:
+               atmegadci_uninit(sc);
+               break;
+       case USB_HW_POWER_RESUME:
+               atmegadci_resume(sc);
+               break;
+       default:
+               break;
+       }
+}
+
 struct usb_bus_methods atmegadci_bus_methods =
 {
        .endpoint_init = &atmegadci_ep_init,
@@ -2135,4 +2155,5 @@ struct usb_bus_methods atmegadci_bus_met
        .clear_stall = &atmegadci_clear_stall,
        .roothub_exec = &atmegadci_roothub_exec,
        .xfer_poll = &atmegadci_do_poll,
+       .set_hw_power_sleep = &atmegadci_set_hw_power_sleep,
 };

Modified: stable/9/sys/dev/usb/controller/atmegadci.h
==============================================================================
--- stable/9/sys/dev/usb/controller/atmegadci.h Sat Dec 31 14:21:41 2011        
(r229095)
+++ stable/9/sys/dev/usb/controller/atmegadci.h Sat Dec 31 14:22:02 2011        
(r229096)
@@ -278,8 +278,6 @@ struct atmegadci_softc {
 
 usb_error_t atmegadci_init(struct atmegadci_softc *sc);
 void   atmegadci_uninit(struct atmegadci_softc *sc);
-void   atmegadci_suspend(struct atmegadci_softc *sc);
-void   atmegadci_resume(struct atmegadci_softc *sc);
 void   atmegadci_interrupt(struct atmegadci_softc *sc);
 
 #endif                                 /* _ATMEGADCI_H_ */

Modified: stable/9/sys/dev/usb/controller/atmegadci_atmelarm.c
==============================================================================
--- stable/9/sys/dev/usb/controller/atmegadci_atmelarm.c        Sat Dec 31 
14:21:41 2011        (r229095)
+++ stable/9/sys/dev/usb/controller/atmegadci_atmelarm.c        Sat Dec 31 
14:22:02 2011        (r229096)
@@ -62,7 +62,6 @@ __FBSDID("$FreeBSD$");
 static device_probe_t atmegadci_probe;
 static device_attach_t atmegadci_attach;
 static device_detach_t atmegadci_detach;
-static device_shutdown_t atmegadci_shutdown;
 
 struct atmegadci_super_softc {
        struct atmegadci_softc sc_otg;  /* must be first */
@@ -193,35 +192,22 @@ atmegadci_detach(device_t dev)
        return (0);
 }
 
-static int
-atmegadci_shutdown(device_t dev)
-{
-       struct atmegadci_super_softc *sc = device_get_softc(dev);
-       int err;
-
-       err = bus_generic_shutdown(dev);
-       if (err)
-               return (err);
-
-       atmegadci_uninit(&sc->sc_otg);
-
-       return (0);
-}
-
 static device_method_t atmegadci_methods[] = {
        /* Device interface */
        DEVMETHOD(device_probe, atmegadci_probe),
        DEVMETHOD(device_attach, atmegadci_attach),
        DEVMETHOD(device_detach, atmegadci_detach),
-       DEVMETHOD(device_shutdown, atmegadci_shutdown),
+       DEVMETHOD(device_suspend, bus_generic_suspend),
+       DEVMETHOD(device_resume, bus_generic_resume),
+       DEVMETHOD(device_shutdown, bus_generic_shutdown),
 
        DEVMETHOD_END
 };
 
 static driver_t atmegadci_driver = {
-       "atmegadci",
-       atmegadci_methods,
-       sizeof(struct atmegadci_super_softc),
+       .name = "atmegadci",
+       .methods = atmegadci_methods,
+       .size = sizeof(struct atmegadci_super_softc),
 };
 
 static devclass_t atmegadci_devclass;

Modified: stable/9/sys/dev/usb/controller/avr32dci.c
==============================================================================
--- stable/9/sys/dev/usb/controller/avr32dci.c  Sat Dec 31 14:21:41 2011        
(r229095)
+++ stable/9/sys/dev/usb/controller/avr32dci.c  Sat Dec 31 14:22:02 2011        
(r229096)
@@ -265,7 +265,7 @@ avr32dci_set_address(struct avr32dci_sof
 {
        DPRINTFN(5, "addr=%d\n", addr);
 
-       avr32dci_mod_ctrl(sc, AVR32_UDADDR_ADDEN | addr, 0);
+       avr32dci_mod_ctrl(sc, AVR32_CTRL_DEV_FADDR_EN | addr, 0);
 }
 
 static uint8_t
@@ -501,7 +501,7 @@ repeat:
        }
 
        /* allocate FIFO bank */
-       AVR32_WRITE_4(sc, AVR32_EPTCLRSTA(td->ep_no), AVR32_EPTSTA_TX_BK_RDY);
+       AVR32_WRITE_4(sc, AVR32_EPTCTL(td->ep_no), AVR32_EPTCTL_TX_PK_RDY);
 
        /* check remainder */
        if (td->remainder == 0) {
@@ -754,7 +754,7 @@ avr32dci_setup_standard_chain(struct usb
        uint8_t need_sync;
 
        DPRINTFN(9, "addr=%d endpt=%d sumlen=%d speed=%d\n",
-           xfer->address, UE_GET_ADDR(xfer->endpoint),
+           xfer->address, UE_GET_ADDR(xfer->endpointno),
            xfer->sumlen, usbd_get_speed(xfer->xroot->udev));
 
        temp.max_frame_size = xfer->max_frame_size;
@@ -773,7 +773,7 @@ avr32dci_setup_standard_chain(struct usb
        temp.did_stall = !xfer->flags_int.control_stall;
 
        sc = AVR32_BUS2SC(xfer->xroot->bus);
-       ep_no = (xfer->endpoint & UE_ADDR);
+       ep_no = (xfer->endpointno & UE_ADDR);
 
        /* check if we should prepend a setup message */
 
@@ -798,7 +798,7 @@ avr32dci_setup_standard_chain(struct usb
        }
 
        if (x != xfer->nframes) {
-               if (xfer->endpoint & UE_DIR_IN) {
+               if (xfer->endpointno & UE_DIR_IN) {
                        temp.func = &avr32dci_data_tx;
                        need_sync = 1;
                } else {
@@ -872,7 +872,7 @@ avr32dci_setup_standard_chain(struct usb
                         * Send a DATA1 message and invert the current
                         * endpoint direction.
                         */
-                       if (xfer->endpoint & UE_DIR_IN) {
+                       if (xfer->endpointno & UE_DIR_IN) {
                                temp.func = &avr32dci_data_rx;
                                need_sync = 0;
                        } else {
@@ -913,7 +913,8 @@ avr32dci_start_standard_chain(struct usb
 
        /* poll one time - will turn on interrupts */
        if (avr32dci_xfer_do_fifo(xfer)) {
-               uint8_t ep_no = xfer->endpoint & UE_ADDR_MASK;
+               uint8_t ep_no = xfer->endpointno & UE_ADDR;
+               struct avr32dci_softc *sc = AVR32_BUS2SC(xfer->xroot->bus);
 
                avr32dci_mod_ien(sc, AVR32_INT_EPT_INT(ep_no), 0);
 
@@ -1012,7 +1013,7 @@ avr32dci_standard_done(struct usb_xfer *
        usb_error_t err = 0;
 
        DPRINTFN(13, "xfer=%p pipe=%p transfer done\n",
-           xfer, xfer->pipe);
+           xfer, xfer->endpoint);
 
        /* reset scanner */
 
@@ -1064,10 +1065,10 @@ avr32dci_device_done(struct usb_xfer *xf
        USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
 
        DPRINTFN(9, "xfer=%p, pipe=%p, error=%d\n",
-           xfer, xfer->pipe, error);
+           xfer, xfer->endpoint, error);
 
        if (xfer->flags_int.usb_mode == USB_MODE_DEVICE) {
-               ep_no = (xfer->endpoint & UE_ADDR);
+               ep_no = (xfer->endpointno & UE_ADDR);
 
                /* disable endpoint interrupt */
                avr32dci_mod_ien(sc, 0, AVR32_INT_EPT_INT(ep_no));
@@ -1080,7 +1081,7 @@ avr32dci_device_done(struct usb_xfer *xf
 
 static void
 avr32dci_set_stall(struct usb_device *udev, struct usb_xfer *xfer,
-    struct usb_endpoint *ep, uint8_t *did_stall)
+    struct usb_endpoint *pipe, uint8_t *did_stall)
 {
        struct avr32dci_softc *sc;
        uint8_t ep_no;
@@ -1166,7 +1167,7 @@ avr32dci_clear_stall_sub(struct avr32dci
 }
 
 static void
-avr32dci_clear_stall(struct usb_device *udev, struct usb_endpoint *ep)
+avr32dci_clear_stall(struct usb_device *udev, struct usb_endpoint *pipe)
 {
        struct avr32dci_softc *sc;
        struct usb_endpoint_descriptor *ed;
@@ -1226,8 +1227,7 @@ avr32dci_init(struct avr32dci_softc *sc)
            AVR32_INT_ENDRESET, 0);
 
        /* reset all endpoints */
-/**INDENT** Warning@1207: Extra ) */
-       AVR32_WRITE_4(sc, AVR32_EPTRST, (1 << AVR32_EP_MAX) - 1));
+       AVR32_WRITE_4(sc, AVR32_EPTRST, (1 << AVR32_EP_MAX) - 1);
 
        /* disable all endpoints */
        for (n = 0; n != AVR32_EP_MAX; n++) {
@@ -1262,8 +1262,7 @@ avr32dci_uninit(struct avr32dci_softc *s
        avr32dci_mod_ien(sc, 0, 0xFFFFFFFF);
 
        /* reset all endpoints */
-/**INDENT** Warning@1242: Extra ) */
-       AVR32_WRITE_4(sc, AVR32_EPTRST, (1 << AVR32_EP_MAX) - 1));
+       AVR32_WRITE_4(sc, AVR32_EPTRST, (1 << AVR32_EP_MAX) - 1);
 
        /* disable all endpoints */
        for (n = 0; n != AVR32_EP_MAX; n++) {
@@ -1284,16 +1283,16 @@ avr32dci_uninit(struct avr32dci_softc *s
        USB_BUS_UNLOCK(&sc->sc_bus);
 }
 
-void
+static void
 avr32dci_suspend(struct avr32dci_softc *sc)
 {
-       return;
+       /* TODO */
 }
 
-void
+static void
 avr32dci_resume(struct avr32dci_softc *sc)
 {
-       return;
+       /* TODO */
 }
 
 static void
@@ -1369,10 +1368,10 @@ avr32dci_device_isoc_fs_enter(struct usb
        uint8_t ep_no;
 
        DPRINTFN(6, "xfer=%p next=%d nframes=%d\n",
-           xfer, xfer->pipe->isoc_next, xfer->nframes);
+           xfer, xfer->endpoint->isoc_next, xfer->nframes);
 
        /* get the current frame index */
-       ep_no = xfer->endpoint & UE_ADDR_MASK;
+       ep_no = xfer->endpointno & UE_ADDR;
        nframes = (AVR32_READ_4(sc, AVR32_FNUM) / 8);
 
        nframes &= AVR32_FRAME_MASK;
@@ -1381,9 +1380,9 @@ avr32dci_device_isoc_fs_enter(struct usb
         * check if the frame index is within the window where the frames
         * will be inserted
         */
-       temp = (nframes - xfer->pipe->isoc_next) & AVR32_FRAME_MASK;
+       temp = (nframes - xfer->endpoint->isoc_next) & AVR32_FRAME_MASK;
 
-       if ((xfer->pipe->is_synced == 0) ||
+       if ((xfer->endpoint->is_synced == 0) ||
            (temp < xfer->nframes)) {
                /*
                 * If there is data underflow or the pipe queue is
@@ -1391,15 +1390,15 @@ avr32dci_device_isoc_fs_enter(struct usb
                 * of the current frame position. Else two isochronous
                 * transfers might overlap.
                 */
-               xfer->pipe->isoc_next = (nframes + 3) & AVR32_FRAME_MASK;
-               xfer->pipe->is_synced = 1;
-               DPRINTFN(3, "start next=%d\n", xfer->pipe->isoc_next);
+               xfer->endpoint->isoc_next = (nframes + 3) & AVR32_FRAME_MASK;
+               xfer->endpoint->is_synced = 1;
+               DPRINTFN(3, "start next=%d\n", xfer->endpoint->isoc_next);
        }
        /*
         * compute how many milliseconds the insertion is ahead of the
         * current frame position:
         */
-       temp = (xfer->pipe->isoc_next - nframes) & AVR32_FRAME_MASK;
+       temp = (xfer->endpoint->isoc_next - nframes) & AVR32_FRAME_MASK;
 
        /*
         * pre-compute when the isochronous transfer will be finished:
@@ -1409,7 +1408,7 @@ avr32dci_device_isoc_fs_enter(struct usb
            xfer->nframes;
 
        /* compute frame number for next insertion */
-       xfer->pipe->isoc_next += xfer->nframes;
+       xfer->endpoint->isoc_next += xfer->nframes;
 
        /* setup TDs */
        avr32dci_setup_standard_chain(xfer);
@@ -1832,7 +1831,7 @@ tr_handle_clear_port_feature:
                AVR32_WRITE_4(sc, AVR32_EPTCLRSTA(0), AVR32_EPTSTA_FRCESTALL);
 
                /* configure */
-               AVR32_WRITE_4(sc, AVR32_EPTCFG(0), AVR32_EPTCFG_TYPE_CONTROL |
+               AVR32_WRITE_4(sc, AVR32_EPTCFG(0), AVR32_EPTCFG_TYPE_CTRL |
                    AVR32_EPTCFG_NBANK(1) | AVR32_EPTCFG_EPSIZE(6));
 
                temp = AVR32_READ_4(sc, AVR32_EPTCFG(0));
@@ -1974,7 +1973,7 @@ avr32dci_xfer_setup(struct usb_setup_par
        /*
         * compute maximum number of TDs
         */
-       if ((xfer->pipe->edesc->bmAttributes & UE_XFERTYPE) == UE_CONTROL) {
+       if ((xfer->endpoint->edesc->bmAttributes & UE_XFERTYPE) == UE_CONTROL) {
 
                ntd = xfer->nframes + 1 /* STATUS */ + 1        /* SYNC 1 */
                    + 1 /* SYNC 2 */ ;
@@ -1997,7 +1996,7 @@ avr32dci_xfer_setup(struct usb_setup_par
        /*
         * get profile stuff
         */
-       ep_no = xfer->endpoint & UE_ADDR;
+       ep_no = xfer->endpointno & UE_ADDR;
        avr32dci_get_hw_ep_profile(parm->udev, &pf, ep_no);
 
        if (pf == NULL) {
@@ -2045,7 +2044,7 @@ avr32dci_xfer_unsetup(struct usb_xfer *x
 
 static void
 avr32dci_ep_init(struct usb_device *udev, struct usb_endpoint_descriptor 
*edesc,
-    struct usb_endpoint *ep)
+    struct usb_endpoint *pipe)
 {
        struct avr32dci_softc *sc = AVR32_BUS2SC(udev->bus);
 
@@ -2072,6 +2071,26 @@ avr32dci_ep_init(struct usb_device *udev
        }
 }
 
+static void
+avr32dci_set_hw_power_sleep(struct usb_bus *bus, uint32_t state)
+{
+       struct avr32dci_softc *sc = AVR32_BUS2SC(bus);
+
+       switch (state) {
+       case USB_HW_POWER_SUSPEND:
+               avr32dci_suspend(sc);
+               break;
+       case USB_HW_POWER_SHUTDOWN:
+               avr32dci_uninit(sc);
+               break;
+       case USB_HW_POWER_RESUME:
+               avr32dci_resume(sc);
+               break;
+       default:
+               break;
+       }
+}
+
 struct usb_bus_methods avr32dci_bus_methods =
 {
        .endpoint_init = &avr32dci_ep_init,
@@ -2082,4 +2101,5 @@ struct usb_bus_methods avr32dci_bus_meth
        .clear_stall = &avr32dci_clear_stall,
        .roothub_exec = &avr32dci_roothub_exec,
        .xfer_poll = &avr32dci_do_poll,
+       .set_hw_power_sleep = &avr32dci_set_hw_power_sleep,
 };

Modified: stable/9/sys/dev/usb/controller/avr32dci.h
==============================================================================
--- stable/9/sys/dev/usb/controller/avr32dci.h  Sat Dec 31 14:21:41 2011        
(r229095)
+++ stable/9/sys/dev/usb/controller/avr32dci.h  Sat Dec 31 14:22:02 2011        
(r229096)
@@ -166,6 +166,7 @@ struct avr32dci_td {
        uint32_t offset;
        uint32_t remainder;
        uint16_t max_packet_size;
+       uint8_t bank_shift;
        uint8_t error:1;
        uint8_t alt_next:1;
        uint8_t short_pkt:1;
@@ -246,8 +247,6 @@ struct avr32dci_softc {
 
 usb_error_t avr32dci_init(struct avr32dci_softc *sc);
 void   avr32dci_uninit(struct avr32dci_softc *sc);
-void   avr32dci_suspend(struct avr32dci_softc *sc);
-void   avr32dci_resume(struct avr32dci_softc *sc);
 void   avr32dci_interrupt(struct avr32dci_softc *sc);
 void   avr32dci_vbus_interrupt(struct avr32dci_softc *sc, uint8_t is_on);
 

Modified: stable/9/sys/dev/usb/controller/ehci.c
==============================================================================
--- stable/9/sys/dev/usb/controller/ehci.c      Sat Dec 31 14:21:41 2011        
(r229095)
+++ stable/9/sys/dev/usb/controller/ehci.c      Sat Dec 31 14:22:02 2011        
(r229096)
@@ -188,7 +188,7 @@ ehci_reset(ehci_softc_t *sc)
 
        EOWRITE4(sc, EHCI_USBCMD, EHCI_CMD_HCRESET);
        for (i = 0; i < 100; i++) {
-               usb_pause_mtx(NULL, hz / 1000);
+               usb_pause_mtx(NULL, hz / 128);
                hcr = EOREAD4(sc, EHCI_USBCMD) & EHCI_CMD_HCRESET;
                if (!hcr) {
                        if (sc->sc_flags & (EHCI_SCFLG_SETMODE | 
EHCI_SCFLG_BIGEMMIO)) {
@@ -212,7 +212,7 @@ ehci_reset(ehci_softc_t *sc)
                        return (0);
                }
        }
-       device_printf(sc->sc_bus.bdev, "reset timeout\n");
+       device_printf(sc->sc_bus.bdev, "Reset timeout\n");
        return (USB_ERR_IOERROR);
 }
 
@@ -224,7 +224,7 @@ ehci_hcreset(ehci_softc_t *sc)
 
        EOWRITE4(sc, EHCI_USBCMD, 0);   /* Halt controller */
        for (i = 0; i < 100; i++) {
-               usb_pause_mtx(NULL, hz / 1000);
+               usb_pause_mtx(NULL, hz / 128);
                hcr = EOREAD4(sc, EHCI_USBSTS) & EHCI_STS_HCH;
                if (hcr)
                        break;
@@ -237,7 +237,60 @@ ehci_hcreset(ehci_softc_t *sc)
                  */
                device_printf(sc->sc_bus.bdev, "stop timeout\n");
 
-       return ehci_reset(sc);
+       return (ehci_reset(sc));
+}
+
+static int
+ehci_init_sub(struct ehci_softc *sc)
+{
+       struct usb_page_search buf_res;
+       uint32_t cparams;
+       uint32_t hcr;
+       uint8_t i;
+
+       cparams = EREAD4(sc, EHCI_HCCPARAMS);
+
+       DPRINTF("cparams=0x%x\n", cparams);
+
+       if (EHCI_HCC_64BIT(cparams)) {
+               DPRINTF("HCC uses 64-bit structures\n");
+
+               /* MUST clear segment register if 64 bit capable */
+               EWRITE4(sc, EHCI_CTRLDSSEGMENT, 0);
+       }
+
+       usbd_get_page(&sc->sc_hw.pframes_pc, 0, &buf_res);
+       EOWRITE4(sc, EHCI_PERIODICLISTBASE, buf_res.physaddr);
+
+       usbd_get_page(&sc->sc_hw.async_start_pc, 0, &buf_res);
+       EOWRITE4(sc, EHCI_ASYNCLISTADDR, buf_res.physaddr | EHCI_LINK_QH);
+
+       /* enable interrupts */
+       EOWRITE4(sc, EHCI_USBINTR, sc->sc_eintrs);
+
+       /* turn on controller */
+       EOWRITE4(sc, EHCI_USBCMD,
+           EHCI_CMD_ITC_1 |            /* 1 microframes interrupt delay */
+           (EOREAD4(sc, EHCI_USBCMD) & EHCI_CMD_FLS_M) |
+           EHCI_CMD_ASE |
+           EHCI_CMD_PSE |
+           EHCI_CMD_RS);
+
+       /* Take over port ownership */
+       EOWRITE4(sc, EHCI_CONFIGFLAG, EHCI_CONF_CF);
+
+       for (i = 0; i < 100; i++) {
+               usb_pause_mtx(NULL, hz / 128);
+               hcr = EOREAD4(sc, EHCI_USBSTS) & EHCI_STS_HCH;
+               if (!hcr) {
+                       break;
+               }
+       }
+       if (hcr) {
+               device_printf(sc->sc_bus.bdev, "Run timeout\n");
+               return (USB_ERR_IOERROR);
+       }
+       return (USB_ERR_NORMAL_COMPLETION);
 }
 
 usb_error_t
@@ -246,8 +299,6 @@ ehci_init(ehci_softc_t *sc)
        struct usb_page_search buf_res;
        uint32_t version;
        uint32_t sparams;
-       uint32_t cparams;
-       uint32_t hcr;
        uint16_t i;
        uint16_t x;
        uint16_t y;
@@ -279,15 +330,6 @@ ehci_init(ehci_softc_t *sc)
        DPRINTF("sparams=0x%x\n", sparams);
 
        sc->sc_noport = EHCI_HCS_N_PORTS(sparams);
-       cparams = EREAD4(sc, EHCI_HCCPARAMS);
-       DPRINTF("cparams=0x%x\n", cparams);
-
-       if (EHCI_HCC_64BIT(cparams)) {
-               DPRINTF("HCC uses 64-bit structures\n");
-
-               /* MUST clear segment register if 64 bit capable */
-               EWRITE4(sc, EHCI_CTRLDSSEGMENT, 0);
-       }
        sc->sc_bus.usbrev = USB_REV_2_0;
 
        /* Reset the controller */
@@ -464,9 +506,6 @@ ehci_init(ehci_softc_t *sc)
                            [i & (EHCI_VIRTUAL_FRAMELIST_COUNT - 1)]->itd_self;
                }
        }
-       /* setup sync list pointer */
-       EOWRITE4(sc, EHCI_PERIODICLISTBASE, buf_res.physaddr);
-
        usbd_get_page(&sc->sc_hw.async_start_pc, 0, &buf_res);
 
        if (1) {
@@ -511,35 +550,8 @@ ehci_init(ehci_softc_t *sc)
        }
 #endif
 
-       /* setup async list pointer */
-       EOWRITE4(sc, EHCI_ASYNCLISTADDR, buf_res.physaddr | EHCI_LINK_QH);
-
-
-       /* enable interrupts */
-       EOWRITE4(sc, EHCI_USBINTR, sc->sc_eintrs);
-
-       /* turn on controller */
-       EOWRITE4(sc, EHCI_USBCMD,
-           EHCI_CMD_ITC_1 |            /* 1 microframes interrupt delay */
-           (EOREAD4(sc, EHCI_USBCMD) & EHCI_CMD_FLS_M) |
-           EHCI_CMD_ASE |
-           EHCI_CMD_PSE |
-           EHCI_CMD_RS);
-
-       /* Take over port ownership */
-       EOWRITE4(sc, EHCI_CONFIGFLAG, EHCI_CONF_CF);
-
-       for (i = 0; i < 100; i++) {
-               usb_pause_mtx(NULL, hz / 1000);
-               hcr = EOREAD4(sc, EHCI_USBSTS) & EHCI_STS_HCH;
-               if (!hcr) {
-                       break;
-               }
-       }
-       if (hcr) {
-               device_printf(sc->sc_bus.bdev, "run timeout\n");
-               return (USB_ERR_IOERROR);
-       }
+       /* finial setup */
+       err = ehci_init_sub(sc);
 
        if (!err) {
                /* catch any lost interrupts */
@@ -573,137 +585,28 @@ ehci_detach(ehci_softc_t *sc)
        usb_callout_drain(&sc->sc_tmo_poll);
 }
 
-void
+static void
 ehci_suspend(ehci_softc_t *sc)
 {
-       uint32_t cmd;
-       uint32_t hcr;
-       uint8_t i;
-
-       USB_BUS_LOCK(&sc->sc_bus);
-
-       for (i = 1; i <= sc->sc_noport; i++) {
-               cmd = EOREAD4(sc, EHCI_PORTSC(i));
-               if (((cmd & EHCI_PS_PO) == 0) &&
-                   ((cmd & EHCI_PS_PE) == EHCI_PS_PE)) {
-                       EOWRITE4(sc, EHCI_PORTSC(i),
-                           cmd | EHCI_PS_SUSP);
-               }
-       }
-
-       sc->sc_cmd = EOREAD4(sc, EHCI_USBCMD);
-
-       cmd = sc->sc_cmd & ~(EHCI_CMD_ASE | EHCI_CMD_PSE);
-       EOWRITE4(sc, EHCI_USBCMD, cmd);
-
-       for (i = 0; i < 100; i++) {
-               hcr = EOREAD4(sc, EHCI_USBSTS) &
-                   (EHCI_STS_ASS | EHCI_STS_PSS);
-
-               if (hcr == 0) {
-                       break;
-               }
-               usb_pause_mtx(&sc->sc_bus.bus_mtx, hz / 1000);
-       }
-
-       if (hcr != 0) {
-               device_printf(sc->sc_bus.bdev, "reset timeout\n");
-       }
-       cmd &= ~EHCI_CMD_RS;
-       EOWRITE4(sc, EHCI_USBCMD, cmd);
-
-       for (i = 0; i < 100; i++) {
-               hcr = EOREAD4(sc, EHCI_USBSTS) & EHCI_STS_HCH;
-               if (hcr == EHCI_STS_HCH) {
-                       break;
-               }
-               usb_pause_mtx(&sc->sc_bus.bus_mtx, hz / 1000);
-       }
+       DPRINTF("stopping the HC\n");
 
-       if (hcr != EHCI_STS_HCH) {
-               device_printf(sc->sc_bus.bdev,
-                   "config timeout\n");
-       }
-       USB_BUS_UNLOCK(&sc->sc_bus);
+       /* reset HC */
+       ehci_hcreset(sc);
 }
 
-void
+static void
 ehci_resume(ehci_softc_t *sc)
 {
-       struct usb_page_search buf_res;
-       uint32_t cmd;
-       uint32_t hcr;
-       uint8_t i;
-
-       USB_BUS_LOCK(&sc->sc_bus);
+       /* reset HC */
+       ehci_hcreset(sc);
 
-       /* restore things in case the bios doesn't */
-       EOWRITE4(sc, EHCI_CTRLDSSEGMENT, 0);
-
-       usbd_get_page(&sc->sc_hw.pframes_pc, 0, &buf_res);
-       EOWRITE4(sc, EHCI_PERIODICLISTBASE, buf_res.physaddr);
-
-       usbd_get_page(&sc->sc_hw.async_start_pc, 0, &buf_res);
-       EOWRITE4(sc, EHCI_ASYNCLISTADDR, buf_res.physaddr | EHCI_LINK_QH);
-
-       EOWRITE4(sc, EHCI_USBINTR, sc->sc_eintrs);
-
-       hcr = 0;
-       for (i = 1; i <= sc->sc_noport; i++) {
-               cmd = EOREAD4(sc, EHCI_PORTSC(i));
-               if (((cmd & EHCI_PS_PO) == 0) &&
-                   ((cmd & EHCI_PS_SUSP) == EHCI_PS_SUSP)) {
-                       EOWRITE4(sc, EHCI_PORTSC(i),
-                           cmd | EHCI_PS_FPR);
-                       hcr = 1;
-               }
-       }
-
-       if (hcr) {
-               usb_pause_mtx(&sc->sc_bus.bus_mtx,
-                   USB_MS_TO_TICKS(USB_RESUME_WAIT));
-
-               for (i = 1; i <= sc->sc_noport; i++) {
-                       cmd = EOREAD4(sc, EHCI_PORTSC(i));
-                       if (((cmd & EHCI_PS_PO) == 0) &&
-                           ((cmd & EHCI_PS_SUSP) == EHCI_PS_SUSP)) {
-                               EOWRITE4(sc, EHCI_PORTSC(i),
-                                   cmd & ~EHCI_PS_FPR);
-                       }
-               }
-       }
-       EOWRITE4(sc, EHCI_USBCMD, sc->sc_cmd);
-
-       for (i = 0; i < 100; i++) {
-               hcr = EOREAD4(sc, EHCI_USBSTS) & EHCI_STS_HCH;
-               if (hcr != EHCI_STS_HCH) {
-                       break;
-               }
-               usb_pause_mtx(&sc->sc_bus.bus_mtx, hz / 1000);
-       }
-       if (hcr == EHCI_STS_HCH) {
-               device_printf(sc->sc_bus.bdev, "config timeout\n");
-       }
-
-       USB_BUS_UNLOCK(&sc->sc_bus);
-
-       usb_pause_mtx(NULL,
-           USB_MS_TO_TICKS(USB_RESUME_WAIT));
+       /* setup HC */
+       ehci_init_sub(sc);
 
        /* catch any lost interrupts */
        ehci_do_poll(&sc->sc_bus);
 }
 
-void
-ehci_shutdown(ehci_softc_t *sc)
-{
-       DPRINTF("stopping the HC\n");
-
-       if (ehci_hcreset(sc)) {
-               DPRINTF("reset failed!\n");
-       }
-}
-
 #ifdef USB_DEBUG
 static void
 ehci_dump_regs(ehci_softc_t *sc)
@@ -3908,8 +3811,24 @@ ehci_device_suspend(struct usb_device *u
        }
 
        USB_BUS_UNLOCK(udev->bus);
+}
 
-       return;
+static void
+ehci_set_hw_power_sleep(struct usb_bus *bus, uint32_t state)
+{
+       struct ehci_softc *sc = EHCI_BUS2SC(bus);
+
+       switch (state) {
+       case USB_HW_POWER_SUSPEND:
+       case USB_HW_POWER_SHUTDOWN:
+               ehci_suspend(sc);
+               break;
+       case USB_HW_POWER_RESUME:
+               ehci_resume(sc);
+               break;
+       default:
+               break;
+       }
 }
 
 static void
@@ -3955,6 +3874,7 @@ struct usb_bus_methods ehci_bus_methods 
        .device_resume = ehci_device_resume,
        .device_suspend = ehci_device_suspend,
        .set_hw_power = ehci_set_hw_power,
+       .set_hw_power_sleep = ehci_set_hw_power_sleep,
        .roothub_exec = ehci_roothub_exec,
        .xfer_poll = ehci_do_poll,
 };

Modified: stable/9/sys/dev/usb/controller/ehci.h
==============================================================================
--- stable/9/sys/dev/usb/controller/ehci.h      Sat Dec 31 14:21:41 2011        
(r229095)
+++ stable/9/sys/dev/usb/controller/ehci.h      Sat Dec 31 14:22:02 2011        
(r229096)
@@ -333,8 +333,6 @@ typedef struct ehci_softc {
 
        uint32_t sc_terminate_self;     /* TD short packet termination pointer 
*/
        uint32_t sc_eintrs;
-       uint32_t sc_cmd;                /* shadow of cmd register during
-                                        * suspend */
 
        uint16_t sc_intr_stat[EHCI_VIRTUAL_FRAMELIST_COUNT];
        uint16_t sc_id_vendor;          /* vendor ID for root hub */
@@ -445,9 +443,6 @@ usb_bus_mem_cb_t ehci_iterate_hw_softc;
 usb_error_t ehci_reset(ehci_softc_t *sc);
 usb_error_t ehci_init(ehci_softc_t *sc);
 void   ehci_detach(struct ehci_softc *sc);
-void   ehci_suspend(struct ehci_softc *sc);
-void   ehci_resume(struct ehci_softc *sc);
-void   ehci_shutdown(ehci_softc_t *sc);
 void   ehci_interrupt(ehci_softc_t *sc);
 
 #endif                                 /* _EHCI_H_ */

Modified: stable/9/sys/dev/usb/controller/ehci_ixp4xx.c
==============================================================================
--- stable/9/sys/dev/usb/controller/ehci_ixp4xx.c       Sat Dec 31 14:21:41 
2011        (r229095)

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to