From: Jules Maselbas <jmaselbas@kalray.eu>
To: Barebox List <barebox@lists.infradead.org>
Cc: Jules Maselbas <jmaselbas@kalray.eu>,
Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v4 13/13] usb: dwc2: Use register_otg_device
Date: Tue, 11 Aug 2020 17:16:37 +0200 [thread overview]
Message-ID: <20200811151637.17705-14-jmaselbas@kalray.eu> (raw)
In-Reply-To: <20200811151637.17705-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 45be2c070..908d62479 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;
@@ -57,16 +78,18 @@ 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));
dev->priv = dwc2;
- 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
next prev parent reply other threads:[~2020-08-11 15:16 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-11 15:16 [PATCH v4 00/13] usb: dwc2: Add host and gadget driver Jules Maselbas
2020-08-11 15:16 ` [PATCH v4 01/13] Revert "usb: Add dwc2 host driver" Jules Maselbas
2020-08-11 15:16 ` [PATCH v4 02/13] usb: dwc2: Add host controller driver Jules Maselbas
2020-08-14 6:21 ` Sascha Hauer
2020-08-14 8:15 ` Jules Maselbas
2020-08-14 13:12 ` Sascha Hauer
2020-08-11 15:16 ` [PATCH v4 03/13] usb: dwc2: host: Read dr_mode from device tree Jules Maselbas
2020-08-11 15:16 ` [PATCH v4 04/13] usb: dwc2: Rework roothub interface Jules Maselbas
2020-08-11 15:16 ` [PATCH v4 05/13] usb: dwc2: Rework timeout Jules Maselbas
2020-08-11 15:16 ` [PATCH v4 06/13] usb: dwc2: host: Handle dma mapping errors Jules Maselbas
2020-08-11 15:16 ` [PATCH v4 07/13] usb: dwc2: host: Dynamic fifo size support from Linux Jules Maselbas
2020-08-11 15:16 ` [PATCH v4 08/13] usb: dwc2: host: Fix toggle reset Jules Maselbas
2020-08-11 15:16 ` [PATCH v4 09/13] usb: dwc2: host: Rewrite dwc2_hc_init Jules Maselbas
2020-08-11 15:16 ` [PATCH v4 10/13] usb: dwc2: Add function to flush tx fifo Jules Maselbas
2020-08-11 15:16 ` [PATCH v4 11/13] usb: dwc2: Add structure for gadget driver Jules Maselbas
2020-08-11 15:16 ` [PATCH v4 12/13] usb: dwc2: Add " Jules Maselbas
2020-08-11 15:16 ` Jules Maselbas [this message]
2020-08-14 13:12 ` [PATCH v4 00/13] usb: dwc2: Add host and " 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=20200811151637.17705-14-jmaselbas@kalray.eu \
--to=jmaselbas@kalray.eu \
--cc=a.fatoum@pengutronix.de \
--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