Skip to contentSkip to conversation

usb: host: xhci: plat: add support for otg_set_host() call

RFC PATCH In review Manish Narani 2 participants 3 messages Dec 14, 2016 – Dec 15, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 usb: host: xhci: plat: add support for otg_set_host() call

This patch will add support for OTG host initialization. This will help OTG drivers to populate their host subsystem.

---
 drivers/usb/host/xhci-plat.c |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)
drivers/usb/host/xhci-plat.c +35 -0
index ddfab30..b4cadbd 100644
@@ -20,6 +20,10 @@
 #include <linux/slab.h>
 #include <linux/acpi.h>
 
+#ifdef CONFIG_USB_OTG
+#include <linux/usb/otg.h>
+#endif
+
 #include "xhci.h"
 #include "xhci-plat.h"
 #include "xhci-mvebu.h"
@@ -255,6 +259,24 @@ static int xhci_plat_probe(struct platform_device *pdev)
 	if (ret)
 		goto dealloc_usb2_hcd;
 
+#ifdef CONFIG_USB_OTG
+	hcd->usb_phy = usb_get_phy(USB_PHY_TYPE_USB3);
+	if (!IS_ERR_OR_NULL(hcd->usb_phy) && hcd->usb_phy->otg) {
+		dev_dbg(&pdev->dev, "%s otg support available\n", __func__);
+		ret = otg_set_host(hcd->usb_phy->otg, &hcd->self);
+		if (ret) {
+			dev_err(&pdev->dev, "%s otg_set_host failed\n",
+					__func__);
+			usb_put_phy(hcd->usb_phy);
+			hcd->usb_phy = NULL;
+			goto dealloc_usb2_hcd;
+		}
+	} else {
+		usb_put_phy(hcd->usb_phy);
+		hcd->usb_phy = NULL;
+	}
+#endif
+
 	return 0;
 
 
@@ -283,6 +305,19 @@ static int xhci_plat_remove(struct platform_device *dev)
 	struct xhci_hcd	*xhci = hcd_to_xhci(hcd);
 	struct clk *clk = xhci->clk;
 
+#ifdef CONFIG_USB_OTG
+	if (hcd->usb_phy) {
+		if (!IS_ERR(hcd->usb_phy)) {
+			if (hcd->usb_phy->otg)
+				otg_set_host(hcd->usb_phy->otg, NULL);
+			usb_put_phy(hcd->usb_phy);
+		}
+		hcd->usb_phy = NULL;
+		if (xhci->shared_hcd)
+			xhci->shared_hcd->usb_phy = NULL;
+	}
+#endif
+
 	usb_remove_hcd(xhci->shared_hcd);
 	usb_phy_shutdown(hcd->usb_phy);
 
Signature · 1 line
1.7.1
maintainer
#1 lore raw
Quoted 13 lines · Manish Narani

This patch will add support for OTG host initialization. This will help OTG drivers to populate their host subsystem.

---
 drivers/usb/host/xhci-plat.c |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)
drivers/usb/host/xhci-plat.c +0 -0
index ddfab30..b4cadbd 100644

drivers/usb/host/xhci-plat.c line 25

Quoted 6 lines
drivers/usb/host/xhci-plat.c +3 -0
@@ -20,6 +20,10 @@
 #include <linux/slab.h>
 #include <linux/acpi.h>
 
+#ifdef CONFIG_USB_OTG
+#include <linux/usb/otg.h>
+#endif

never use a #ifdef in a .c file if at all possible. Here you don't need it at all.

Quoted 15 lines
drivers/usb/host/xhci-plat.c +8 -0
+
 #include "xhci.h"
 #include "xhci-plat.h"
 #include "xhci-mvebu.h"
@@ -255,6 +259,24 @@ static int xhci_plat_probe(struct platform_device *pdev)
 	if (ret)
 		goto dealloc_usb2_hcd;
 
+#ifdef CONFIG_USB_OTG
+	hcd->usb_phy = usb_get_phy(USB_PHY_TYPE_USB3);
+	if (!IS_ERR_OR_NULL(hcd->usb_phy) && hcd->usb_phy->otg) {
+		dev_dbg(&pdev->dev, "%s otg support available\n", __func__);
+		ret = otg_set_host(hcd->usb_phy->otg, &hcd->self);
+		if (ret) {
+			dev_err(&pdev->dev, "%s otg_set_host failed\n",

drivers/usb/host/xhci-plat.c static int xhci_plat_probe(struct platform_device *pdev) · line 278

Quoted 10 lines
drivers/usb/host/xhci-plat.c +10 -0
+					__func__);
+			usb_put_phy(hcd->usb_phy);
+			hcd->usb_phy = NULL;
+			goto dealloc_usb2_hcd;
+		}
+	} else {
+		usb_put_phy(hcd->usb_phy);
+		hcd->usb_phy = NULL;
+	}
+#endif

Can't you wrap this in a function to get rid of this #ifdef mess?

Quoted 10 lines
drivers/usb/host/xhci-plat.c +3 -0
+
 	return 0;
 
 
@@ -283,6 +305,19 @@ static int xhci_plat_remove(struct platform_device *dev)
 	struct xhci_hcd	*xhci = hcd_to_xhci(hcd);
 	struct clk *clk = xhci->clk;
 
+#ifdef CONFIG_USB_OTG
+	if (hcd->usb_phy) {

drivers/usb/host/xhci-plat.c static int xhci_plat_remove(struct platform_device *dev) · line 319

Quoted 10 lines
drivers/usb/host/xhci-plat.c +10 -0
+		if (!IS_ERR(hcd->usb_phy)) {
+			if (hcd->usb_phy->otg)
+				otg_set_host(hcd->usb_phy->otg, NULL);
+			usb_put_phy(hcd->usb_phy);
+		}
+		hcd->usb_phy = NULL;
+		if (xhci->shared_hcd)
+			xhci->shared_hcd->usb_phy = NULL;
+	}
+#endif

same here.

thanks,

greg k-h

#2 lore raw

Thanks Greg. I have send another patch with changes as per your suggestions. Please review it and let me know if you have any concerns.

- Manish

-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Thursday, December 15, 2016 2:29 AM
To: Manish Narani <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Anurag Kumar Vulisha <[email protected]>; Punnaiah Choudary Kalluri <[email protected]>; Anirudha Sarangi <[email protected]>; Manish Narani <[email protected]>
Subject: Re: [RFC PATCH] usb: host: xhci: plat: add support for otg_set_host() call

Quoted 13 lines · Manish Narani

This patch will add support for OTG host initialization. This will help OTG drivers to populate their host subsystem.

---
 drivers/usb/host/xhci-plat.c |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)
(quoted diff) +0 -0

b/drivers/usb/host/xhci-plat.c index ddfab30..b4cadbd 100644

drivers/usb/host/xhci-plat.c line 25

Quoted 6 lines
drivers/usb/host/xhci-plat.c +3 -0
@@ -20,6 +20,10 @@
 #include <linux/slab.h>
 #include <linux/acpi.h>
 
+#ifdef CONFIG_USB_OTG
+#include <linux/usb/otg.h>
+#endif

never use a #ifdef in a .c file if at all possible. Here you don't need it at all.

Quoted 15 lines
drivers/usb/host/xhci-plat.c +8 -0
+
 #include "xhci.h"
 #include "xhci-plat.h"
 #include "xhci-mvebu.h"
@@ -255,6 +259,24 @@ static int xhci_plat_probe(struct platform_device *pdev)
      if (ret)
              goto dealloc_usb2_hcd;
 
+#ifdef CONFIG_USB_OTG
+     hcd->usb_phy = usb_get_phy(USB_PHY_TYPE_USB3);
+     if (!IS_ERR_OR_NULL(hcd->usb_phy) && hcd->usb_phy->otg) {
+             dev_dbg(&pdev->dev, "%s otg support available\n", __func__);
+             ret = otg_set_host(hcd->usb_phy->otg, &hcd->self);
+             if (ret) {
+                     dev_err(&pdev->dev, "%s otg_set_host failed\n",

drivers/usb/host/xhci-plat.c static int xhci_plat_probe(struct platform_device *pdev) · line 278

Quoted 10 lines
drivers/usb/host/xhci-plat.c +10 -0
+                                     __func__);
+                     usb_put_phy(hcd->usb_phy);
+                     hcd->usb_phy = NULL;
+                     goto dealloc_usb2_hcd;
+             }
+     } else {
+             usb_put_phy(hcd->usb_phy);
+             hcd->usb_phy = NULL;
+     }
+#endif

Can't you wrap this in a function to get rid of this #ifdef mess?

Quoted 10 lines
drivers/usb/host/xhci-plat.c +3 -0
+
      return 0;
 
 
@@ -283,6 +305,19 @@ static int xhci_plat_remove(struct platform_device *dev)
      struct xhci_hcd *xhci = hcd_to_xhci(hcd);
      struct clk *clk = xhci->clk;
 
+#ifdef CONFIG_USB_OTG
+     if (hcd->usb_phy) {

drivers/usb/host/xhci-plat.c static int xhci_plat_remove(struct platform_device *dev) · line 319

Quoted 10 lines
drivers/usb/host/xhci-plat.c +10 -0
+             if (!IS_ERR(hcd->usb_phy)) {
+                     if (hcd->usb_phy->otg)
+                             otg_set_host(hcd->usb_phy->otg, NULL);
+                     usb_put_phy(hcd->usb_phy);
+             }
+             hcd->usb_phy = NULL;
+             if (xhci->shared_hcd)
+                     xhci->shared_hcd->usb_phy = NULL;
+     }
+#endif

same here.

thanks,

greg k-h

This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.