From: Mattijs Korpershoek <mkorpershoek@baylibre.com>
To: Sjoerd Simons <sjoerd@collabora.com>, u-boot@lists.denx.de
Cc: Martyn Welch <martyn.welch@collabora.com>,
Roger Quadros <rogerq@kernel.org>, Nishanth Menon <nm@ti.com>,
Caleb Connolly <caleb.connolly@linaro.org>,
Igor Prusov <ivprusov@salutedevices.com>,
Marek Vasut <marex@denx.de>,
Patrice Chotard <patrice.chotard@foss.st.com>,
Simon Glass <sjg@chromium.org>,
Svyatoslav Ryhel <clamor95@gmail.com>
Subject: Re: [PATCH v4 2/7] usb: dwc3: Switch to device mode on gadget start
Date: Tue, 16 Jan 2024 11:46:27 +0100 [thread overview]
Message-ID: <87mst54ku4.fsf@baylibre.com> (raw)
In-Reply-To: <20240112085317.1866449-3-sjoerd@collabora.com>
Hi Sjoerd,
Thank you for the patch.
On ven., janv. 12, 2024 at 09:52, Sjoerd Simons <sjoerd@collabora.com> wrote:
> When dr_mode is "otg" the dwc3 is initially configured in _OTG mode;
> However in this mode the gadget functionality doesn't work without
> further configuration. To resolve that on gadget start switch to _DEVICE
> mode globally and go back to _OTG on stop again.
>
> For this the dwc3_set_mode is renamed to dwc3_core_set_mode to avoid a
> conflict with the same function exposed by xhci-dwc3
>
> Signed-off-by: Sjoerd Simons <sjoerd@collabora.com>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
nitpick below.
>
> ---
>
> Changes in v4:
> - New patch
>
> drivers/usb/dwc3/core.c | 10 +++++-----
> drivers/usb/dwc3/core.h | 1 +
> drivers/usb/dwc3/gadget.c | 6 ++++++
> 3 files changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 4b4fcd8a22e..d22d4c4bb6a 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -42,7 +42,7 @@
> static LIST_HEAD(dwc3_list);
> /* -------------------------------------------------------------------------- */
>
> -static void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
> +void dwc3_core_set_mode(struct dwc3 *dwc, u32 mode)
> {
> u32 reg;
>
> @@ -736,7 +736,7 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
>
> switch (dwc->dr_mode) {
> case USB_DR_MODE_PERIPHERAL:
> - dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
> + dwc3_core_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
> ret = dwc3_gadget_init(dwc);
> if (ret) {
> dev_err(dwc->dev, "failed to initialize gadget\n");
> @@ -744,7 +744,7 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
> }
> break;
> case USB_DR_MODE_HOST:
> - dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST);
> + dwc3_core_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST);
> ret = dwc3_host_init(dwc);
> if (ret) {
> dev_err(dwc->dev, "failed to initialize host\n");
> @@ -752,7 +752,7 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
> }
> break;
> case USB_DR_MODE_OTG:
> - dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
> + dwc3_core_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
> ret = dwc3_host_init(dwc);
> if (ret) {
> dev_err(dwc->dev, "failed to initialize host\n");
> @@ -810,7 +810,7 @@ static void dwc3_core_exit_mode(struct dwc3 *dwc)
> * switch back to peripheral mode
> * This enables the phy to enter idle and then, if enabled, suspend.
> */
> - dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
> + dwc3_core_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
> dwc3_gadget_run(dwc);
> }
>
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index 4162a682298..1e7eda89a34 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -1057,6 +1057,7 @@ int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc);
> void dwc3_of_parse(struct dwc3 *dwc);
> int dwc3_init(struct dwc3 *dwc);
> void dwc3_remove(struct dwc3 *dwc);
> +void dwc3_core_set_mode(struct dwc3 *dwc, u32 mode);
>
> static inline int dwc3_host_init(struct dwc3 *dwc)
> { return 0; }
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 406d36ceafe..69d9fe40e2f 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -1468,6 +1468,9 @@ static int dwc3_gadget_start(struct usb_gadget *g,
>
> dwc->gadget_driver = driver;
>
Doesn't this bit deserves a comment ? When looking at the code it's not
obvious that we do this because PRTCAP_OTG is non-functional without any
additional configuration.
Maybe something in the lines of:
/**
* WORKAROUND: in OTG mode, gadget functionality is non-functional.
* Switch to gadget mode only to enable gadget mode
*/
?
> + if (dwc->dr_mode == DWC3_GCTL_PRTCAP_OTG)
> + dwc3_core_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
> +
> reg = dwc3_readl(dwc->regs, DWC3_DCFG);
> reg &= ~(DWC3_DCFG_SPEED_MASK);
>
> @@ -1559,6 +1562,9 @@ static int dwc3_gadget_stop(struct usb_gadget *g)
> __dwc3_gadget_ep_disable(dwc->eps[0]);
> __dwc3_gadget_ep_disable(dwc->eps[1]);
>
> + if (dwc->dr_mode == DWC3_GCTL_PRTCAP_OTG)
> + dwc3_core_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
> +
> dwc->gadget_driver = NULL;
>
> spin_unlock_irqrestore(&dwc->lock, flags);
> --
> 2.43.0
next prev parent reply other threads:[~2024-01-16 10:46 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-12 8:52 [PATCH v4 0/7] Add DFU and usb boot for TI am62x SK and beagleplay Sjoerd Simons
2024-01-12 8:52 ` [PATCH v4 1/7] usb: dwc3: Add dwc3 glue driver for am62 Sjoerd Simons
2024-01-16 10:22 ` Mattijs Korpershoek
2024-05-01 13:56 ` Martyn Welch
2024-05-02 7:03 ` Mattijs Korpershoek
2024-04-12 20:34 ` Sverdlin, Alexander
2024-01-12 8:52 ` [PATCH v4 2/7] usb: dwc3: Switch to device mode on gadget start Sjoerd Simons
2024-01-12 10:39 ` Roger Quadros
2024-01-12 11:06 ` Sjoerd Simons
2024-01-12 12:56 ` Roger Quadros
2024-01-12 14:18 ` Sjoerd Simons
2024-01-15 13:40 ` Roger Quadros
2024-01-12 12:55 ` Caleb Connolly
2024-01-16 10:55 ` Mattijs Korpershoek
2024-01-16 10:46 ` Mattijs Korpershoek [this message]
2024-04-12 20:33 ` Sverdlin, Alexander
2024-01-12 8:52 ` [PATCH v4 3/7] board: ti: am62x: am62x: include env for DFU Sjoerd Simons
2024-01-16 10:57 ` Mattijs Korpershoek
2024-04-12 20:31 ` Sverdlin, Alexander
2024-01-12 8:52 ` [PATCH v4 4/7] arm: dts: k3-am625-sk: Enable usb port in u-boot Sjoerd Simons
2024-01-16 11:17 ` Mattijs Korpershoek
2024-01-16 11:21 ` Sjoerd Simons
2024-04-12 20:30 ` Sverdlin, Alexander
2024-01-12 8:52 ` [PATCH v4 5/7] configs: am62x_evm_*: Enable USB and DFU support Sjoerd Simons
2024-01-12 9:58 ` Roger Quadros
2024-01-12 10:44 ` Sjoerd Simons
2024-01-12 10:55 ` Roger Quadros
2024-01-12 12:37 ` Nishanth Menon
2024-01-12 13:09 ` Sjoerd Simons
2024-01-12 13:19 ` Nishanth Menon
2024-01-12 15:06 ` Sjoerd Simons
2024-01-12 15:40 ` Nishanth Menon
2024-01-12 15:58 ` Sjoerd Simons
2024-01-12 16:03 ` Tom Rini
2024-02-08 10:33 ` Mattijs Korpershoek
2024-01-12 8:52 ` [PATCH v4 6/7] beagleplay: Add " Sjoerd Simons
2024-01-12 10:41 ` Roger Quadros
2024-01-12 10:47 ` Sjoerd Simons
2024-01-12 12:34 ` Nishanth Menon
2024-01-12 8:52 ` [PATCH v4 7/7] doc: board: Add document for DFU boot on am62x SoCs Sjoerd Simons
2024-01-12 12:36 ` Nishanth Menon
2024-01-12 12:58 ` Sjoerd Simons
2024-01-12 13:18 ` Mattijs Korpershoek
2024-01-16 11:12 ` Mattijs Korpershoek
2024-01-16 10:09 ` [PATCH v4 0/7] Add DFU and usb boot for TI am62x SK and beagleplay Mattijs Korpershoek
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=87mst54ku4.fsf@baylibre.com \
--to=mkorpershoek@baylibre.com \
--cc=caleb.connolly@linaro.org \
--cc=clamor95@gmail.com \
--cc=ivprusov@salutedevices.com \
--cc=marex@denx.de \
--cc=martyn.welch@collabora.com \
--cc=nm@ti.com \
--cc=patrice.chotard@foss.st.com \
--cc=rogerq@kernel.org \
--cc=sjg@chromium.org \
--cc=sjoerd@collabora.com \
--cc=u-boot@lists.denx.de \
/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