]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
usb: hcd: add generic PHY support
authorSergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Wed, 24 Sep 2014 19:09:44 +0000 (23:09 +0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 29 Sep 2014 15:54:02 +0000 (11:54 -0400)
Add the generic PHY support, analogous to the USB PHY support. Intended it to be
used with the PCI EHCI/OHCI drivers and the xHCI platform driver.

Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/core/hcd.c
include/linux/usb/hcd.h

index 2c56252b9ff8e1f3bd6a0487761830d96507cbb7..b84fb141e122f7f0d60d9e4ba09642c7c9e15492 100644 (file)
@@ -42,6 +42,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/types.h>
 
+#include <linux/phy/phy.h>
 #include <linux/usb.h>
 #include <linux/usb/hcd.h>
 #include <linux/usb/phy.h>
@@ -2647,6 +2648,29 @@ int usb_add_hcd(struct usb_hcd *hcd,
                }
        }
 
+       if (IS_ENABLED(CONFIG_GENERIC_PHY)) {
+               struct phy *phy = phy_get(hcd->self.controller, "usb");
+
+               if (IS_ERR(phy)) {
+                       retval = PTR_ERR(phy);
+                       if (retval == -EPROBE_DEFER)
+                               goto err_phy;
+               } else {
+                       retval = phy_init(phy);
+                       if (retval) {
+                               phy_put(phy);
+                               goto err_phy;
+                       }
+                       retval = phy_power_on(phy);
+                       if (retval) {
+                               phy_exit(phy);
+                               phy_put(phy);
+                               goto err_phy;
+                       }
+                       hcd->phy = phy;
+               }
+       }
+
        dev_info(hcd->self.controller, "%s\n", hcd->product_desc);
 
        /* Keep old behaviour if authorized_default is not in [0, 1]. */
@@ -2662,7 +2686,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");
-               goto err_remove_phy;
+               goto err_create_buf;
        }
 
        if ((retval = usb_register_bus(&hcd->self)) < 0)
@@ -2789,7 +2813,14 @@ err_allocate_root_hub:
        usb_deregister_bus(&hcd->self);
 err_register_bus:
        hcd_buffer_destroy(hcd);
-err_remove_phy:
+err_create_buf:
+       if (IS_ENABLED(CONFIG_GENERIC_PHY) && hcd->phy) {
+               phy_power_off(hcd->phy);
+               phy_exit(hcd->phy);
+               phy_put(hcd->phy);
+               hcd->phy = NULL;
+       }
+err_phy:
        if (hcd->remove_phy && hcd->usb_phy) {
                usb_phy_shutdown(hcd->usb_phy);
                usb_put_phy(hcd->usb_phy);
@@ -2866,6 +2897,13 @@ void usb_remove_hcd(struct usb_hcd *hcd)
 
        usb_deregister_bus(&hcd->self);
        hcd_buffer_destroy(hcd);
+
+       if (IS_ENABLED(CONFIG_GENERIC_PHY) && hcd->phy) {
+               phy_power_off(hcd->phy);
+               phy_exit(hcd->phy);
+               phy_put(hcd->phy);
+               hcd->phy = NULL;
+       }
        if (hcd->remove_phy && hcd->usb_phy) {
                usb_phy_shutdown(hcd->usb_phy);
                usb_put_phy(hcd->usb_phy);
index 788059a108e5f0205f4f73229134567b30c17968..cd96a2bc3388973f59b221f13187a30c4177b2d3 100644 (file)
@@ -107,6 +107,7 @@ struct usb_hcd {
         * other external phys should be software-transparent
         */
        struct usb_phy          *usb_phy;
+       struct phy              *phy;
 
        /* Flags that need to be manipulated atomically because they can
         * change while the host controller is running.  Always use