diff mbox series

[v2] reset: rzg2l-usbphy-ctrl: Move reset controller registration

Message ID 20240610164845.89666-1-biju.das.jz@bp.renesas.com (mailing list archive)
State Accepted
Delegated to: Geert Uytterhoeven
Headers show
Series [v2] reset: rzg2l-usbphy-ctrl: Move reset controller registration | expand

Commit Message

Biju Das June 10, 2024, 4:48 p.m. UTC
As soon as the reset controller is registered, it could be used by a
reset consumer. That means hardware setup to be done first and then the
registration of the reset controller. So move the registration of reset
controller at the end of probe().

While at it, fix the issue that the reset is not re-asserted in case
devm_reset_controller_register() fails and also use goto statements to
simplify the error path in probe().

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v1->v2:
 * Updated commit header and description
 * Moved reset controller registration at the end of the probe()
 * Fixed the issue that the reset is not re-asserted in case
   devm_reset_controller_register() fails
 * Used goto statements to simplify the error path in probe().
 * Restored the blank line before devm_reset_controller_register().
---
 drivers/reset/reset-rzg2l-usbphy-ctrl.c | 32 +++++++++++++++----------
 1 file changed, 19 insertions(+), 13 deletions(-)

Comments

Geert Uytterhoeven June 17, 2024, 8:14 a.m. UTC | #1
On Mon, Jun 10, 2024 at 6:48 PM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> As soon as the reset controller is registered, it could be used by a
> reset consumer. That means hardware setup to be done first and then the
> registration of the reset controller. So move the registration of reset
> controller at the end of probe().
>
> While at it, fix the issue that the reset is not re-asserted in case
> devm_reset_controller_register() fails and also use goto statements to
> simplify the error path in probe().
>
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> ---
> v1->v2:
>  * Updated commit header and description
>  * Moved reset controller registration at the end of the probe()
>  * Fixed the issue that the reset is not re-asserted in case
>    devm_reset_controller_register() fails
>  * Used goto statements to simplify the error path in probe().
>  * Restored the blank line before devm_reset_controller_register().

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert
diff mbox series

Patch

diff --git a/drivers/reset/reset-rzg2l-usbphy-ctrl.c b/drivers/reset/reset-rzg2l-usbphy-ctrl.c
index 8f6fbd978591..29b852a8ac5a 100644
--- a/drivers/reset/reset-rzg2l-usbphy-ctrl.c
+++ b/drivers/reset/reset-rzg2l-usbphy-ctrl.c
@@ -125,25 +125,14 @@  static int rzg2l_usbphy_ctrl_probe(struct platform_device *pdev)
 	if (error)
 		return error;
 
-	priv->rcdev.ops = &rzg2l_usbphy_ctrl_reset_ops;
-	priv->rcdev.of_reset_n_cells = 1;
-	priv->rcdev.nr_resets = NUM_PORTS;
-	priv->rcdev.of_node = dev->of_node;
-	priv->rcdev.dev = dev;
-
-	error = devm_reset_controller_register(dev, &priv->rcdev);
-	if (error)
-		return error;
-
 	spin_lock_init(&priv->lock);
 	dev_set_drvdata(dev, priv);
 
 	pm_runtime_enable(&pdev->dev);
 	error = pm_runtime_resume_and_get(&pdev->dev);
 	if (error < 0) {
-		pm_runtime_disable(&pdev->dev);
-		reset_control_assert(priv->rstc);
-		return dev_err_probe(&pdev->dev, error, "pm_runtime_resume_and_get failed");
+		dev_err_probe(&pdev->dev, error, "pm_runtime_resume_and_get failed");
+		goto err_pm_disable_reset_deassert;
 	}
 
 	/* put pll and phy into reset state */
@@ -153,7 +142,24 @@  static int rzg2l_usbphy_ctrl_probe(struct platform_device *pdev)
 	writel(val, priv->base + RESET);
 	spin_unlock_irqrestore(&priv->lock, flags);
 
+	priv->rcdev.ops = &rzg2l_usbphy_ctrl_reset_ops;
+	priv->rcdev.of_reset_n_cells = 1;
+	priv->rcdev.nr_resets = NUM_PORTS;
+	priv->rcdev.of_node = dev->of_node;
+	priv->rcdev.dev = dev;
+
+	error = devm_reset_controller_register(dev, &priv->rcdev);
+	if (error)
+		goto err_pm_runtime_put;
+
 	return 0;
+
+err_pm_runtime_put:
+	pm_runtime_put(&pdev->dev);
+err_pm_disable_reset_deassert:
+	pm_runtime_disable(&pdev->dev);
+	reset_control_assert(priv->rstc);
+	return error;
 }
 
 static void rzg2l_usbphy_ctrl_remove(struct platform_device *pdev)