Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: hcd: Remove USB phy if needed

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>

authored by

Valentine Barshak and committed by
Greg Kroah-Hartman
103e127d e5fc70d5

+14 -1
+13 -1
drivers/usb/core/hcd.c
··· 44 44 45 45 #include <linux/usb.h> 46 46 #include <linux/usb/hcd.h> 47 + #include <linux/usb/phy.h> 47 48 48 49 #include "usb.h" 49 50 ··· 2604 2603 */ 2605 2604 if ((retval = hcd_buffer_create(hcd)) != 0) { 2606 2605 dev_dbg(hcd->self.controller, "pool alloc failed\n"); 2607 - return retval; 2606 + goto err_remove_phy; 2608 2607 } 2609 2608 2610 2609 if ((retval = usb_register_bus(&hcd->self)) < 0) ··· 2735 2734 usb_deregister_bus(&hcd->self); 2736 2735 err_register_bus: 2737 2736 hcd_buffer_destroy(hcd); 2737 + err_remove_phy: 2738 + if (hcd->remove_phy && hcd->phy) { 2739 + usb_phy_shutdown(hcd->phy); 2740 + usb_put_phy(hcd->phy); 2741 + hcd->phy = NULL; 2742 + } 2738 2743 return retval; 2739 2744 } 2740 2745 EXPORT_SYMBOL_GPL(usb_add_hcd); ··· 2813 2806 usb_put_dev(hcd->self.root_hub); 2814 2807 usb_deregister_bus(&hcd->self); 2815 2808 hcd_buffer_destroy(hcd); 2809 + if (hcd->remove_phy && hcd->phy) { 2810 + usb_phy_shutdown(hcd->phy); 2811 + usb_put_phy(hcd->phy); 2812 + hcd->phy = NULL; 2813 + } 2816 2814 } 2817 2815 EXPORT_SYMBOL_GPL(usb_remove_hcd); 2818 2816
+1
include/linux/usb/hcd.h
··· 134 134 unsigned rh_registered:1;/* is root hub registered? */ 135 135 unsigned rh_pollable:1; /* may we poll the root hub? */ 136 136 unsigned msix_enabled:1; /* driver has MSI-X enabled? */ 137 + unsigned remove_phy:1; /* auto-remove USB phy */ 137 138 138 139 /* The next flag is a stopgap, to be removed when all the HCDs 139 140 * support the new root-hub polling mechanism. */