On Thu, 28 Mar 2013, Lan Tianyu wrote:

> Some devices' firmware will be broken at some points. Power down
> and power on device can help device to rework in this case.
> 
> This patch is to add ioctl cmd USBDEVFS_POWER_RESET for usbfs node
> to repower usb device. First, call hub_port_logical_disconnect() to
> disconnect device. Second, Power down and up usb port.
> 
> This patch is also helpful fo some QAs who want to do hcd's memleak
> test(Plug and unplug device thousand times.)

This is not a bad idea, but it needs a little more work...

> --- a/drivers/usb/core/hub.c
> +++ b/drivers/usb/core/hub.c
> @@ -114,6 +114,7 @@ EXPORT_SYMBOL_GPL(ehci_cf_port_reset_rwsem);
>  #define HUB_DEBOUNCE_STABLE   100
>  
>  static int usb_reset_and_verify_device(struct usb_device *udev);
> +static void hub_port_logical_disconnect(struct usb_hub *hub, int port1);
>  
>  static inline char *portspeed(struct usb_hub *hub, int portstatus)
>  {
> @@ -741,6 +742,21 @@ int usb_hub_set_port_power(struct usb_device *hdev, int 
> port1,
>       return ret;
>  }
>  
> +int usb_hub_port_power_reset(struct usb_device *hdev, int port1)
> +{
> +     struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
> +     struct usb_interface *intf = to_usb_interface(hub->intfdev);
> +     int ret;
> +
> +     usb_autopm_get_interface(intf);

What happens if hdev is NULL?

> +     hub_port_logical_disconnect(hub, port1);
> +     ret = usb_hub_set_port_power(hdev, port1, false);

How long do you think the power should remain turned off?  This code
will leave it off for only a few milliseconds at most.  That may not
even be long enough for the voltage to drop all the way to 0.

The delay probably should be at least 100 ms.  Maybe more, I don't 
know.

> +     ret |= usb_hub_set_port_power(hdev, port1, true);

Don't use |=.  Skip the second call if the first one fails.

> +     usb_autopm_put_interface(intf);
> +
> +     return ret;
> +}

If you placed this function later on in the source file, you wouldn't 
need the forward declaration of hub_port_logical_disconnect().

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to