diff mbox series

[v1,12/14] usb: dwc2: Clear fifo_map when resetting core.

Message ID abd6b3cf465aac7c4e0dd3274ab1549980601c6d.1555672441.git.arturp@synopsys.com (mailing list archive)
State New, archived
Headers show
Series usb: dwc2: Fix and improve power saving modes. | expand

Commit Message

Artur Petrosyan April 19, 2019, 11:25 a.m. UTC
If core enters host hibernation when switching from
device mode to host mode disconnection of host cable
asserts a WARNING in dwc2_hsotg_init_fifo() that
fifo_map is not cleared.

To avoid the WARNING, fifo_map should be cleared
in dwc2_core_reset() function.

- Cleared fifo_map when resetting the core.

Signed-off-by: Artur Petrosyan <arturp@synopsys.com>
---
 drivers/usb/dwc2/core.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Doug Anderson April 26, 2019, 8:51 p.m. UTC | #1
Hi,

On Fri, Apr 19, 2019 at 1:06 PM Artur Petrosyan
<Arthur.Petrosyan@synopsys.com> wrote:
>
> If core enters host hibernation when switching from
> device mode to host mode disconnection of host cable
> asserts a WARNING in dwc2_hsotg_init_fifo() that
> fifo_map is not cleared.
>
> To avoid the WARNING, fifo_map should be cleared
> in dwc2_core_reset() function.
>
> - Cleared fifo_map when resetting the core.
>
> Signed-off-by: Artur Petrosyan <arturp@synopsys.com>
> ---
>  drivers/usb/dwc2/core.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
> index fb471d18a3de..fbbd6a2f10ad 100644
> --- a/drivers/usb/dwc2/core.c
> +++ b/drivers/usb/dwc2/core.c
> @@ -532,6 +532,12 @@ int dwc2_core_reset(struct dwc2_hsotg *hsotg, bool skip_wait)
>         greset |= GRSTCTL_CSFTRST;
>         dwc2_writel(hsotg, greset, GRSTCTL);
>
> +       /* Clear fifo_map */
> +       #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
> +               IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
> +       hsotg->fifo_map = 0;
> +       #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */

Please please no sprinkling "#if" statements in code like this.  Here
lies the way to madness.  The right way to do this in the style of the
Linux kernel is to add a function that is a "static inline" no-op when
the options are compiled out.

As one example you can see my recent patch:

https://lkml.kernel.org/r/20190425154021.4465-1-dianders@chromium.org



-Doug
diff mbox series

Patch

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index fb471d18a3de..fbbd6a2f10ad 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -532,6 +532,12 @@  int dwc2_core_reset(struct dwc2_hsotg *hsotg, bool skip_wait)
 	greset |= GRSTCTL_CSFTRST;
 	dwc2_writel(hsotg, greset, GRSTCTL);
 
+	/* Clear fifo_map */
+	#if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
+		IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
+	hsotg->fifo_map = 0;
+	#endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
+
 	if (dwc2_hsotg_wait_bit_clear(hsotg, GRSTCTL, GRSTCTL_CSFTRST, 50)) {
 		dev_warn(hsotg->dev, "%s: HANG! Soft Reset timeout GRSTCTL GRSTCTL_CSFTRST\n",
 			 __func__);