On Thu, 28 Jun 2012, Lan Tianyu wrote: > This patch is to add two attributes for each usb hub ports to control port's power. > Control port's power through setting or clearing PORT_POWER feature. > > control has two options. "auto", "on" and "off" > "on" - port power must be on. > "off" - port power must be off. > > state reports usb port's power state > "on" - power on > "off" - power off > "error" - can't get power state > > Signed-off-by: Lan Tianyu <tianyu.lan@xxxxxxxxx> > --- a/drivers/usb/core/hub.c > +++ b/drivers/usb/core/hub.c > @@ -848,7 +858,9 @@ static unsigned hub_power_on(struct usb_hub *hub, bool do_delay) > dev_dbg(hub->intfdev, "trying to enable port power on " > "non-switchable hub\n"); > for (port1 = 1; port1 <= hub->descriptor->bNbrPorts; port1++) > - set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER); > + if (hub->ports[port1 - 1]->port_power_policy > + == USB_PORT_POWER_ON) > + set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER); Since the last patch version, I realized that sometimes host controller drivers will turn on port power by themselves. To be safe, you should add else clear_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER); > +static ssize_t > +store_port_power_control(struct device *dev, struct device_attribute *attr, > + const char *buf, size_t count) Since you have to break the line anyway, you ought to put the function's name on the first line. > +{ > + struct usb_device *hdev = to_usb_device(dev->parent->parent); > + struct usb_port *hub_port = to_usb_port(dev); > + int port1, len = count; > + char *cp; > + > + sscanf(dev_name(dev), "port%d", &port1); > + cp = memchr(buf, '\n', count); > + if (cp) > + len = cp - buf; > + if (len == sizeof on_string - 1 > + && strncmp(buf, on_string, len) == 0) { > + hub_port->port_power_policy = USB_PORT_POWER_ON; > + set_port_feature(hdev, port1, USB_PORT_FEAT_POWER); > + } else if (len == sizeof off_string - 1 > + && strncmp(buf, off_string, len) == 0) { > + hub_port->port_power_policy = USB_PORT_POWER_OFF; > + clear_port_feature(hdev, port1, USB_PORT_FEAT_POWER); You should return -EIO if set_port_feature or clear_port_feature fails. Alan Stern -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html