diff mbox series

[v3,1/2] i2c: rcar: reset controller is mandatory for Gen3+

Message ID 20230921125351.3954-2-wsa+renesas@sang-engineering.com (mailing list archive)
State Accepted
Delegated to: Geert Uytterhoeven
Headers show
Series i2c: rcar: improve Gen3 support | expand

Commit Message

Wolfram Sang Sept. 21, 2023, 12:53 p.m. UTC
Initially, we only needed a reset controller to make sure RXDMA works at
least once per transfer. Meanwhile, documentation has been updated. It
now says that a reset has to be performed prior every transaction, even
if it is non-DMA. So, make the reset controller a requirement instead of
being optional. And bail out if resetting fails.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---

Change since v2:
* properly bail out on errors using goto
  To make that easier, the reset controller is now probed after the
  handling of pm_runtime_put() is determined

 drivers/i2c/busses/i2c-rcar.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

Comments

Andi Shyti Sept. 21, 2023, 9:22 p.m. UTC | #1
Hi Wolfram,

[...]

>  		irqhandler = rcar_i2c_gen2_irq;
>  	}
>  
> -	if (priv->devtype == I2C_RCAR_GEN3) {
> -		priv->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
> -		if (!IS_ERR(priv->rstc)) {
> -			ret = reset_control_status(priv->rstc);
> -			if (ret < 0)
> -				priv->rstc = ERR_PTR(-ENOTSUPP);
> -		}
> -	}
> -
>  	/* Stay always active when multi-master to keep arbitration working */
>  	if (of_property_read_bool(dev->of_node, "multi-master"))
>  		priv->flags |= ID_P_PM_BLOCKED;
> @@ -1112,6 +1101,16 @@ static int rcar_i2c_probe(struct platform_device *pdev)
>  	if (of_property_read_bool(dev->of_node, "smbus"))
>  		priv->flags |= ID_P_HOST_NOTIFY;
>  
> +	if (priv->devtype == I2C_RCAR_GEN3) {
> +		priv->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
> +		if (IS_ERR(priv->rstc))
> +			goto out_pm_put;
> +
> +		ret = reset_control_status(priv->rstc);
> +		if (ret < 0)
> +			goto out_pm_put;
> +	}
> +

you moved this block to avoid the pm_runtime_put(dev);

Looks good!

Reviewed-by: Andi Shyti <andi.shyti@kernel.org> 

Andi
Geert Uytterhoeven Sept. 22, 2023, 7:05 a.m. UTC | #2
On Thu, 21 Sep 2023, Wolfram Sang wrote:
> Initially, we only needed a reset controller to make sure RXDMA works at
> least once per transfer. Meanwhile, documentation has been updated. It
> now says that a reset has to be performed prior every transaction, even
> if it is non-DMA. So, make the reset controller a requirement instead of
> being optional. And bail out if resetting fails.
>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
>
> Change since v2:
> * properly bail out on errors using goto
>  To make that easier, the reset controller is now probed after the
>  handling of pm_runtime_put() is determined

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

Gr{oetje,eeting}s,

 						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
 							    -- Linus Torvalds
Wolfram Sang Sept. 22, 2023, 9:55 a.m. UTC | #3
On Thu, Sep 21, 2023 at 02:53:49PM +0200, Wolfram Sang wrote:
> Initially, we only needed a reset controller to make sure RXDMA works at
> least once per transfer. Meanwhile, documentation has been updated. It
> now says that a reset has to be performed prior every transaction, even
> if it is non-DMA. So, make the reset controller a requirement instead of
> being optional. And bail out if resetting fails.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Applied to for-next, thanks!
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 5e97635faf78..6800059514bc 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -838,12 +838,10 @@  static int rcar_i2c_master_xfer(struct i2c_adapter *adap,
 
 	/* Gen3 needs a reset before allowing RXDMA once */
 	if (priv->devtype == I2C_RCAR_GEN3) {
-		priv->flags |= ID_P_NO_RXDMA;
-		if (!IS_ERR(priv->rstc)) {
-			ret = rcar_i2c_do_reset(priv);
-			if (ret == 0)
-				priv->flags &= ~ID_P_NO_RXDMA;
-		}
+		priv->flags &= ~ID_P_NO_RXDMA;
+		ret = rcar_i2c_do_reset(priv);
+		if (ret)
+			goto out;
 	}
 
 	rcar_i2c_init(priv);
@@ -1094,15 +1092,6 @@  static int rcar_i2c_probe(struct platform_device *pdev)
 		irqhandler = rcar_i2c_gen2_irq;
 	}
 
-	if (priv->devtype == I2C_RCAR_GEN3) {
-		priv->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
-		if (!IS_ERR(priv->rstc)) {
-			ret = reset_control_status(priv->rstc);
-			if (ret < 0)
-				priv->rstc = ERR_PTR(-ENOTSUPP);
-		}
-	}
-
 	/* Stay always active when multi-master to keep arbitration working */
 	if (of_property_read_bool(dev->of_node, "multi-master"))
 		priv->flags |= ID_P_PM_BLOCKED;
@@ -1112,6 +1101,16 @@  static int rcar_i2c_probe(struct platform_device *pdev)
 	if (of_property_read_bool(dev->of_node, "smbus"))
 		priv->flags |= ID_P_HOST_NOTIFY;
 
+	if (priv->devtype == I2C_RCAR_GEN3) {
+		priv->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
+		if (IS_ERR(priv->rstc))
+			goto out_pm_put;
+
+		ret = reset_control_status(priv->rstc);
+		if (ret < 0)
+			goto out_pm_put;
+	}
+
 	ret = platform_get_irq(pdev, 0);
 	if (ret < 0)
 		goto out_pm_put;