Suspend/Sleep/Stop USB device

Andriy Gapon avg at icyb.net.ua
Tue Mar 4 09:35:53 UTC 2008


Anish,

I once played with a similar idea - to power off a USB port once a UMASS
device (attached to it) is unmounted, similarly to how windows does it.
I haven't reached any completely satisfactory results, but I got some
results. I have a very faint memory of that now, but I think that either
of the following two should work for a port of a USB hub device:
usbd_clear_port_feature(dev, port, UHF_PORT_ENABLE);
usbd_clear_port_feature(dev, port, UHF_PORT_POWER);

I actually issued the request from user-land, but I think that a proper
solution would be to add a new ioctl for this purpose and a proper
handling of it in usb/uhub.

This is a snippet of the userland code that I still have around:
        if ((fd = open(device_name, O_RDWR, 0)) < 0) {
                error("%s", device_name);
                exit(EXIT_FAILURE);
        }

/*==============================================================*/
        ctlreq.ucr_addr = 1; /* XXX */

        ctlreq.ucr_request.bmRequestType = UT_WRITE_CLASS_OTHER;
        ctlreq.ucr_request.bRequest = UR_CLEAR_FEATURE;
        USETW(ctlreq.ucr_request.wValue, UHF_PORT_POWER);
        //USETW(ctlreq.ucr_request.wValue, UHF_PORT_ENABLE);
        USETW(ctlreq.ucr_request.wIndex, 8); /* XXX */
        USETW(ctlreq.ucr_request.wLength, 0);

        ctlreq.ucr_data = 0;
        ctlreq.ucr_flags = 0;
        ctlreq.ucr_actlen = 0;
/*==============================================================*/

        if (ioctl(fd, USB_REQUEST, &ctlreq) != 0) {
                error("ioctl USB_REQUEST");
                close(fd);
                exit(EXIT_FAILURE);
        }

-- 
Andriy Gapon


More information about the freebsd-usb mailing list