mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jules Maselbas <jmaselbas@kalray.eu>
To: Barebox List <barebox@lists.infradead.org>
Cc: Jules Maselbas <jmaselbas@kalray.eu>
Subject: [PATCH v3 13/14] usb: dwc2: Use register_otg_device
Date: Tue, 21 Jul 2020 14:05:59 +0200	[thread overview]
Message-ID: <20200721120600.15114-14-jmaselbas@kalray.eu> (raw)
In-Reply-To: <20200721120600.15114-1-jmaselbas@kalray.eu>

Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
 drivers/usb/dwc2/dwc2.c | 29 ++++++++++++++++++++++++++---
 drivers/usb/dwc2/dwc2.h |  4 ++--
 2 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/dwc2/dwc2.c b/drivers/usb/dwc2/dwc2.c
index 2d14b218a..7a8ba6c4f 100644
--- a/drivers/usb/dwc2/dwc2.c
+++ b/drivers/usb/dwc2/dwc2.c
@@ -28,6 +28,27 @@ static void dwc2_uninit_common(struct dwc2 *dwc2)
 	dwc2_writel(dwc2, hprt0, HPRT0);
 }
 
+static int dwc2_set_mode(void *ctx, enum usb_dr_mode mode)
+{
+	struct dwc2 *dwc2 = ctx;
+	int ret = -ENODEV;
+
+	if (mode == USB_DR_MODE_HOST || mode == USB_DR_MODE_OTG) {
+		if (IS_ENABLED(CONFIG_USB_DWC2_HOST))
+			ret = dwc2_register_host(dwc2);
+		else
+			dwc2_err(dwc2, "Host support not available\n");
+	}
+	if (mode == USB_DR_MODE_PERIPHERAL || mode == USB_DR_MODE_OTG) {
+		if (IS_ENABLED(CONFIG_USB_DWC2_GADGET))
+			ret = dwc2_gadget_init(dwc2);
+		else
+			dwc2_err(dwc2, "Peripheral support not available\n");
+	}
+
+	return ret;
+}
+
 static int dwc2_probe(struct device_d *dev)
 {
 	struct resource *iores;
@@ -58,15 +79,17 @@ static int dwc2_probe(struct device_d *dev)
 	/* Detect config values from hardware */
 	dwc2_get_hwparams(dwc2);
 
-	dwc2_get_dr_mode(dwc2);
+	ret = dwc2_get_dr_mode(dwc2);
 
 	dwc2_set_default_params(dwc2);
 
 	dma_set_mask(dev, DMA_BIT_MASK(32));
 
-	ret = dwc2_register_host(dwc2);
+	if (dwc2->dr_mode == USB_DR_MODE_OTG)
+		ret = usb_register_otg_device(dwc2->dev, dwc2_set_mode, dwc2);
+	else
+		ret = dwc2_set_mode(dwc2, dwc2->dr_mode);
 
-	ret = dwc2_gadget_init(dwc2);
 error:
 	return ret;
 }
diff --git a/drivers/usb/dwc2/dwc2.h b/drivers/usb/dwc2/dwc2.h
index 0ec21a5ac..5e845f349 100644
--- a/drivers/usb/dwc2/dwc2.h
+++ b/drivers/usb/dwc2/dwc2.h
@@ -35,12 +35,12 @@ int dwc2_submit_roothub(struct dwc2 *dwc2, struct usb_device *dev,
 		struct devrequest *setup);
 int dwc2_register_host(struct dwc2 *dwc2);
 #else
-static inline int dwc2_register_host(struct dwc2 *dwc2) { return 0; }
+static inline int dwc2_register_host(struct dwc2 *dwc2) { return -ENODEV; }
 #endif
 
 /* Gadget functions */
 #ifdef CONFIG_USB_DWC2_GADGET
 int dwc2_gadget_init(struct dwc2 *dwc2);
 #else
-static inline int dwc2_gadget_init(struct dwc2 *dwc2) { return 0; }
+static inline int dwc2_gadget_init(struct dwc2 *dwc2) { return -ENODEV; }
 #endif
-- 
2.17.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2020-07-21 12:06 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-21 12:05 [PATCH v3 00/14] usb: dwc2: Add host and gadget driver Jules Maselbas
2020-07-21 12:05 ` [PATCH v3 01/14] Revert "usb: Add dwc2 host driver" Jules Maselbas
2020-07-21 12:05 ` [PATCH v3 02/14] usb: dwc2: Add host controller driver Jules Maselbas
2020-07-22  6:36   ` Ahmad Fatoum
2020-07-22  9:12     ` Jules Maselbas
2020-07-22  9:18       ` Ahmad Fatoum
2020-07-22  9:21         ` Jules Maselbas
2020-08-10 20:26   ` Sascha Hauer
2020-07-21 12:05 ` [PATCH v3 03/14] usb: dwc2: host: Read dr_mode from device tree Jules Maselbas
2020-07-21 12:05 ` [PATCH v3 04/14] usb: dwc2: Rework roothub interface Jules Maselbas
2020-07-21 12:05 ` [PATCH v3 05/14] usb: dwc2: Rework timeout Jules Maselbas
2020-07-21 12:05 ` [PATCH v3 06/14] usb: dwc2: host: Handle dma mapping errors Jules Maselbas
2020-07-21 12:05 ` [PATCH v3 07/14] usb: dwc2: host: Dynamic fifo size support from Linux Jules Maselbas
2020-07-21 12:05 ` [PATCH v3 08/14] usb: dwc2: host: Fix toggle reset Jules Maselbas
2020-07-21 12:05 ` [PATCH v3 09/14] usb: dwc2: host: Rewrite dwc2_hc_init Jules Maselbas
2020-07-21 12:05 ` [PATCH v3 10/14] usb: dwc2: Add function to flush tx fifo Jules Maselbas
2020-07-21 12:05 ` [PATCH v3 11/14] usb: dwc2: Add structure for gadget driver Jules Maselbas
2020-07-21 12:05 ` [PATCH v3 12/14] usb: dwc2: Add " Jules Maselbas
2020-07-21 12:05 ` Jules Maselbas [this message]
2020-07-21 12:06 ` [PATCH v3 14/14] usb: dwc2: Add ulpi phy function Jules Maselbas
2020-08-10 20:34   ` Sascha Hauer
2020-08-11  9:31     ` Jules Maselbas
2020-08-10 20:23 ` [PATCH v3 00/14] usb: dwc2: Add host and gadget driver Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200721120600.15114-14-jmaselbas@kalray.eu \
    --to=jmaselbas@kalray.eu \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox