diff mbox series

[v2,2/3] usb: dwc3: meson-g12a: fix shared reset control use

Message ID 20201201190100.17831-3-aouledameur@baylibre.com
State New
Headers show
Series usb: meson: fix shared reset control use | expand

Commit Message

Amjad Ouled-Ameur Dec. 1, 2020, 7 p.m. UTC
reset_control_(de)assert() calls are called on a shared reset line when
reset_control_reset has been used. This is not allowed by the reset
framework.

Use reset_control_rearm() call in suspend() and remove() as a way to state
that the resource is no longer used, hence the shared reset line
may be triggered again by other devices. Use reset_control_rearm() also in
case probe fails after reset() has been called.

reset_control_rearm() keeps use of triggered_count sane in the reset
framework, use of reset_control_reset() on shared reset line should be
balanced with reset_control_rearm().

Signed-off-by: Amjad Ouled-Ameur <aouledameur@baylibre.com>
Reported-by: Jerome Brunet <jbrunet@baylibre.com>
---
changes since v1: [1]
* None for this driver

IMPORTANT:
This patchset depends on this patch [2], it adds reset_control_rearm() call
to the reset framework API, it has been approved by the maintainer, and
will be applied to reset/next

There is currently an immutable branch with it [3]

[1]: https://lore.kernel.org/lkml/20201113000508.14702-1-aouledameur@baylibre.com/
[2]: https://lore.kernel.org/lkml/20201112230043.28987-1-aouledameur@baylibre.com/
[3]: git://git.pengutronix.de/git/pza/linux.git reset/shared-retrigger

 drivers/usb/dwc3/dwc3-meson-g12a.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

Comments

Martin Blumenstingl Dec. 5, 2020, 9:42 p.m. UTC | #1
Hello Amjad,

On Tue, Dec 1, 2020 at 8:01 PM Amjad Ouled-Ameur
<aouledameur@baylibre.com> wrote:
>

> reset_control_(de)assert() calls are called on a shared reset line when

> reset_control_reset has been used. This is not allowed by the reset

> framework.

>

> Use reset_control_rearm() call in suspend() and remove() as a way to state

> that the resource is no longer used, hence the shared reset line

> may be triggered again by other devices. Use reset_control_rearm() also in

> case probe fails after reset() has been called.

>

> reset_control_rearm() keeps use of triggered_count sane in the reset

> framework, use of reset_control_reset() on shared reset line should be

> balanced with reset_control_rearm().

I think this should be updated after [0] is applied
The goto from that patch needs to use err_rearm from this patch.


Best regards,
Martin


[0] https://patchwork.kernel.org/project/linux-usb/patch/20201111095256.10477-1-zhengzengkai@huawei.com/
Amjad Ouled-Ameur Dec. 10, 2020, 5:35 p.m. UTC | #2
Hi Martin


On 05/12/2020 22:42, Martin Blumenstingl wrote:

>    

> Hello Amjad,

>

> On Tue, Dec 1, 2020 at 8:01 PM Amjad Ouled-Ameur

> <aouledameur@baylibre.com> wrote:

>    

>> reset_control_(de)assert() calls are called on a shared reset line when

>> reset_control_reset has been used. This is not allowed by the reset

>> framework.

>>

>> Use reset_control_rearm() call in suspend() and remove() as a way to state

>> that the resource is no longer used, hence the shared reset line

>> may be triggered again by other devices. Use reset_control_rearm() also in

>> case probe fails after reset() has been called.

>>

>> reset_control_rearm() keeps use of triggered_count sane in the reset

>> framework, use of reset_control_reset() on shared reset line should be

>> balanced with reset_control_rearm().

>    

> I think this should be updated after [0] is applied

> The goto from that patch needs to use err_rearm from this patch.

>

>

> Best regards,

> Martin

>

>

> [0] https://patchwork.kernel.org/project/linux-usb/patch/20201111095256.10477-1-zhengzengkai@huawei.com/


Thank you Martin for reviewing this patchset.

I have reviewed the patch you mentioned, and I think as well that
we should use 'err_rearm' instead of 'err_disable_clks' to
cleanup things properly in case setup_regmaps fails.


Best,

Amjad
diff mbox series

Patch

diff --git a/drivers/usb/dwc3/dwc3-meson-g12a.c b/drivers/usb/dwc3/dwc3-meson-g12a.c
index 417e05381b5d..3fec8f591c93 100644
--- a/drivers/usb/dwc3/dwc3-meson-g12a.c
+++ b/drivers/usb/dwc3/dwc3-meson-g12a.c
@@ -750,7 +750,7 @@  static int dwc3_meson_g12a_probe(struct platform_device *pdev)
 
 	ret = dwc3_meson_g12a_get_phys(priv);
 	if (ret)
-		goto err_disable_clks;
+		goto err_rearm;
 
 	ret = priv->drvdata->setup_regmaps(priv, base);
 	if (ret)
@@ -759,7 +759,7 @@  static int dwc3_meson_g12a_probe(struct platform_device *pdev)
 	if (priv->vbus) {
 		ret = regulator_enable(priv->vbus);
 		if (ret)
-			goto err_disable_clks;
+			goto err_rearm;
 	}
 
 	/* Get dr_mode */
@@ -772,13 +772,13 @@  static int dwc3_meson_g12a_probe(struct platform_device *pdev)
 
 	ret = priv->drvdata->usb_init(priv);
 	if (ret)
-		goto err_disable_clks;
+		goto err_rearm;
 
 	/* Init PHYs */
 	for (i = 0 ; i < PHY_COUNT ; ++i) {
 		ret = phy_init(priv->phys[i]);
 		if (ret)
-			goto err_disable_clks;
+			goto err_rearm;
 	}
 
 	/* Set PHY Power */
@@ -816,6 +816,9 @@  static int dwc3_meson_g12a_probe(struct platform_device *pdev)
 	for (i = 0 ; i < PHY_COUNT ; ++i)
 		phy_exit(priv->phys[i]);
 
+err_rearm:
+	reset_control_rearm(priv->reset);
+
 err_disable_clks:
 	clk_bulk_disable_unprepare(priv->drvdata->num_clks,
 				   priv->drvdata->clks);
@@ -843,6 +846,8 @@  static int dwc3_meson_g12a_remove(struct platform_device *pdev)
 	pm_runtime_put_noidle(dev);
 	pm_runtime_set_suspended(dev);
 
+	reset_control_rearm(priv->reset);
+
 	clk_bulk_disable_unprepare(priv->drvdata->num_clks,
 				   priv->drvdata->clks);
 
@@ -883,7 +888,7 @@  static int __maybe_unused dwc3_meson_g12a_suspend(struct device *dev)
 		phy_exit(priv->phys[i]);
 	}
 
-	reset_control_assert(priv->reset);
+	reset_control_rearm(priv->reset);
 
 	return 0;
 }
@@ -893,7 +898,9 @@  static int __maybe_unused dwc3_meson_g12a_resume(struct device *dev)
 	struct dwc3_meson_g12a *priv = dev_get_drvdata(dev);
 	int i, ret;
 
-	reset_control_deassert(priv->reset);
+	ret = reset_control_reset(priv->reset);
+	if (ret)
+		return ret;
 
 	ret = priv->drvdata->usb_init(priv);
 	if (ret)