[PATCH 3/3 v1] usb: fotg210: Select subdriver by mode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Check which mode the hardware is in, and selecte the peripheral
driver if the hardware is in explicit peripheral mode, otherwise
select host mode.

This should solve the immediate problem that both subdrivers
can get probed.

Cc: Fabian Vogt <fabian@xxxxxxxxxxxxxx>
Cc: Yuan-Hsin Chen <yhchen@xxxxxxxxxxxxxxxx>
Cc: Felipe Balbi <balbi@xxxxxxxxxx>
Signed-off-by: Linus Walleij <linus.walleij@xxxxxxxxxx>
---
 drivers/usb/fotg210/fotg210-core.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/fotg210/fotg210-core.c b/drivers/usb/fotg210/fotg210-core.c
index ab7b8974bc18..3d07ee46f6d1 100644
--- a/drivers/usb/fotg210/fotg210-core.c
+++ b/drivers/usb/fotg210/fotg210-core.c
@@ -10,30 +10,37 @@
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/usb.h>
+#include <linux/usb/otg.h>
 
 #include "fotg210.h"
 
 static int fotg210_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
+	enum usb_dr_mode mode;
 	int ret;
 
-	if (IS_ENABLED(CONFIG_USB_FOTG210_HCD)) {
-		ret = fotg210_hcd_probe(pdev);
-		if (ret)
-			return ret;
-	}
-	if (IS_ENABLED(CONFIG_USB_FOTG210_UDC))
+	mode = usb_get_dr_mode(dev);
+
+	if (mode == USB_DR_MODE_PERIPHERAL)
 		ret = fotg210_udc_probe(pdev);
+	else
+		ret = fotg210_hcd_probe(pdev);
 
 	return ret;
 }
 
 static int fotg210_remove(struct platform_device *pdev)
 {
-	if (IS_ENABLED(CONFIG_USB_FOTG210_HCD))
-		fotg210_hcd_remove(pdev);
-	if (IS_ENABLED(CONFIG_USB_FOTG210_UDC))
+	struct device *dev = &pdev->dev;
+	enum usb_dr_mode mode;
+
+	mode = usb_get_dr_mode(dev);
+
+	if (mode == USB_DR_MODE_PERIPHERAL)
 		fotg210_udc_remove(pdev);
+	else
+		fotg210_hcd_remove(pdev);
 
 	return 0;
 }
-- 
2.37.3




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux