Skip to content

Commit

Permalink
usb: hcd: Remove USB phy if needed
Browse files Browse the repository at this point in the history
This adds remove_phy flag to the HCD structure. If the flag is
set and if hcd->phy is valid, the phy is shutdown and released
whenever usb_add_hcd fails or usb_hcd_remove is called.
This can be used by the HCD drivers to auto-remove
the external USB phy when it is no longer needed.

Signed-off-by: Valentine Barshak <valentine.barshak@cogentembedded.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Valentine Barshak authored and Greg Kroah-Hartman committed Dec 9, 2013
1 parent e5fc70d commit 103e127
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion drivers/usb/core/hcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

#include <linux/usb.h>
#include <linux/usb/hcd.h>
#include <linux/usb/phy.h>

#include "usb.h"

Expand Down Expand Up @@ -2603,7 +2604,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
*/
if ((retval = hcd_buffer_create(hcd)) != 0) {
dev_dbg(hcd->self.controller, "pool alloc failed\n");
return retval;
goto err_remove_phy;
}

if ((retval = usb_register_bus(&hcd->self)) < 0)
Expand Down Expand Up @@ -2734,6 +2735,12 @@ int usb_add_hcd(struct usb_hcd *hcd,
usb_deregister_bus(&hcd->self);
err_register_bus:
hcd_buffer_destroy(hcd);
err_remove_phy:
if (hcd->remove_phy && hcd->phy) {
usb_phy_shutdown(hcd->phy);
usb_put_phy(hcd->phy);
hcd->phy = NULL;
}
return retval;
}
EXPORT_SYMBOL_GPL(usb_add_hcd);
Expand Down Expand Up @@ -2806,6 +2813,11 @@ void usb_remove_hcd(struct usb_hcd *hcd)
usb_put_dev(hcd->self.root_hub);
usb_deregister_bus(&hcd->self);
hcd_buffer_destroy(hcd);
if (hcd->remove_phy && hcd->phy) {
usb_phy_shutdown(hcd->phy);
usb_put_phy(hcd->phy);
hcd->phy = NULL;
}
}
EXPORT_SYMBOL_GPL(usb_remove_hcd);

Expand Down
1 change: 1 addition & 0 deletions include/linux/usb/hcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ struct usb_hcd {
unsigned rh_registered:1;/* is root hub registered? */
unsigned rh_pollable:1; /* may we poll the root hub? */
unsigned msix_enabled:1; /* driver has MSI-X enabled? */
unsigned remove_phy:1; /* auto-remove USB phy */

/* The next flag is a stopgap, to be removed when all the HCDs
* support the new root-hub polling mechanism. */
Expand Down

0 comments on commit 103e127

Please sign in to comment.