linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: riic: Simplify reset handling
@ 2022-02-09 23:22 Lad Prabhakar
  2022-02-17 19:51 ` Wolfram Sang
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Lad Prabhakar @ 2022-02-09 23:22 UTC (permalink / raw)
  To: Geert Uytterhoeven, Chris Brandt, Philipp Zabel, linux-renesas-soc
  Cc: linux-i2c, linux-kernel, Prabhakar, Biju Das, Lad Prabhakar

Read reset phandle as optional instead of exclusive so that all the DT's
passing the reset phandle can be used to assert/deassert the reset line.
With this change we don't have to differentiate the RZ/G2L SoC.

With the above changes we no longer need the "renesas,riic-r9a07g044"
compatible string, so drop it from riic_i2c_dt_ids[]. No changes are
required to the r9a07g044.dtsi as we already have "renesas,riic-rz" as a
fallback compatible string.

While at it, check the return code of reset_control_deassert() as it might
fail and also add a devres action to assert the reset line.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
---
 drivers/i2c/busses/i2c-riic.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/i2c/busses/i2c-riic.c b/drivers/i2c/busses/i2c-riic.c
index 8dfd27dc6149..cded77e06670 100644
--- a/drivers/i2c/busses/i2c-riic.c
+++ b/drivers/i2c/busses/i2c-riic.c
@@ -88,11 +88,6 @@
 
 #define RIIC_INIT_MSG	-1
 
-enum riic_type {
-	RIIC_RZ_A,
-	RIIC_RZ_G2L,
-};
-
 struct riic_dev {
 	void __iomem *base;
 	u8 *buf;
@@ -396,6 +391,11 @@ static struct riic_irq_desc riic_irqs[] = {
 	{ .res_num = 5, .isr = riic_tend_isr, .name = "riic-nack" },
 };
 
+static void riic_reset_control_assert(void *data)
+{
+	reset_control_assert(data);
+}
+
 static int riic_i2c_probe(struct platform_device *pdev)
 {
 	struct riic_dev *riic;
@@ -404,7 +404,6 @@ static int riic_i2c_probe(struct platform_device *pdev)
 	struct i2c_timings i2c_t;
 	struct reset_control *rstc;
 	int i, ret;
-	enum riic_type type;
 
 	riic = devm_kzalloc(&pdev->dev, sizeof(*riic), GFP_KERNEL);
 	if (!riic)
@@ -421,16 +420,18 @@ static int riic_i2c_probe(struct platform_device *pdev)
 		return PTR_ERR(riic->clk);
 	}
 
-	type = (enum riic_type)of_device_get_match_data(&pdev->dev);
-	if (type == RIIC_RZ_G2L) {
-		rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
-		if (IS_ERR(rstc)) {
-			dev_err(&pdev->dev, "Error: missing reset ctrl\n");
-			return PTR_ERR(rstc);
-		}
+	rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, NULL);
+	if (IS_ERR(rstc))
+		return dev_err_probe(&pdev->dev, PTR_ERR(rstc),
+				     "Error: missing reset ctrl\n");
 
-		reset_control_deassert(rstc);
-	}
+	ret = reset_control_deassert(rstc);
+	if (ret)
+		return ret;
+
+	ret = devm_add_action_or_reset(&pdev->dev, riic_reset_control_assert, rstc);
+	if (ret)
+		return ret;
 
 	for (i = 0; i < ARRAY_SIZE(riic_irqs); i++) {
 		ret = platform_get_irq(pdev, riic_irqs[i].res_num);
@@ -492,8 +493,7 @@ static int riic_i2c_remove(struct platform_device *pdev)
 }
 
 static const struct of_device_id riic_i2c_dt_ids[] = {
-	{ .compatible = "renesas,riic-r9a07g044", .data = (void *)RIIC_RZ_G2L },
-	{ .compatible = "renesas,riic-rz", .data = (void *)RIIC_RZ_A },
+	{ .compatible = "renesas,riic-rz", },
 	{ /* Sentinel */ },
 };
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] i2c: riic: Simplify reset handling
  2022-02-09 23:22 [PATCH] i2c: riic: Simplify reset handling Lad Prabhakar
@ 2022-02-17 19:51 ` Wolfram Sang
  2022-02-18  8:44 ` Geert Uytterhoeven
  2022-03-01 15:07 ` Wolfram Sang
  2 siblings, 0 replies; 4+ messages in thread
From: Wolfram Sang @ 2022-02-17 19:51 UTC (permalink / raw)
  To: Lad Prabhakar, Chris Brandt, Philipp Zabel
  Cc: Geert Uytterhoeven, linux-renesas-soc, linux-i2c, linux-kernel,
	Prabhakar, Biju Das

[-- Attachment #1: Type: text/plain, Size: 3320 bytes --]

On Wed, Feb 09, 2022 at 11:22:32PM +0000, Lad Prabhakar wrote:
> Read reset phandle as optional instead of exclusive so that all the DT's
> passing the reset phandle can be used to assert/deassert the reset line.
> With this change we don't have to differentiate the RZ/G2L SoC.
> 
> With the above changes we no longer need the "renesas,riic-r9a07g044"
> compatible string, so drop it from riic_i2c_dt_ids[]. No changes are
> required to the r9a07g044.dtsi as we already have "renesas,riic-rz" as a
> fallback compatible string.
> 
> While at it, check the return code of reset_control_deassert() as it might
> fail and also add a devres action to assert the reset line.
> 
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Looks good to me. Chris, Philipp what do you think?

> ---
>  drivers/i2c/busses/i2c-riic.c | 34 +++++++++++++++++-----------------
>  1 file changed, 17 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-riic.c b/drivers/i2c/busses/i2c-riic.c
> index 8dfd27dc6149..cded77e06670 100644
> --- a/drivers/i2c/busses/i2c-riic.c
> +++ b/drivers/i2c/busses/i2c-riic.c
> @@ -88,11 +88,6 @@
>  
>  #define RIIC_INIT_MSG	-1
>  
> -enum riic_type {
> -	RIIC_RZ_A,
> -	RIIC_RZ_G2L,
> -};
> -
>  struct riic_dev {
>  	void __iomem *base;
>  	u8 *buf;
> @@ -396,6 +391,11 @@ static struct riic_irq_desc riic_irqs[] = {
>  	{ .res_num = 5, .isr = riic_tend_isr, .name = "riic-nack" },
>  };
>  
> +static void riic_reset_control_assert(void *data)
> +{
> +	reset_control_assert(data);
> +}
> +
>  static int riic_i2c_probe(struct platform_device *pdev)
>  {
>  	struct riic_dev *riic;
> @@ -404,7 +404,6 @@ static int riic_i2c_probe(struct platform_device *pdev)
>  	struct i2c_timings i2c_t;
>  	struct reset_control *rstc;
>  	int i, ret;
> -	enum riic_type type;
>  
>  	riic = devm_kzalloc(&pdev->dev, sizeof(*riic), GFP_KERNEL);
>  	if (!riic)
> @@ -421,16 +420,18 @@ static int riic_i2c_probe(struct platform_device *pdev)
>  		return PTR_ERR(riic->clk);
>  	}
>  
> -	type = (enum riic_type)of_device_get_match_data(&pdev->dev);
> -	if (type == RIIC_RZ_G2L) {
> -		rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
> -		if (IS_ERR(rstc)) {
> -			dev_err(&pdev->dev, "Error: missing reset ctrl\n");
> -			return PTR_ERR(rstc);
> -		}
> +	rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, NULL);
> +	if (IS_ERR(rstc))
> +		return dev_err_probe(&pdev->dev, PTR_ERR(rstc),
> +				     "Error: missing reset ctrl\n");
>  
> -		reset_control_deassert(rstc);
> -	}
> +	ret = reset_control_deassert(rstc);
> +	if (ret)
> +		return ret;
> +
> +	ret = devm_add_action_or_reset(&pdev->dev, riic_reset_control_assert, rstc);
> +	if (ret)
> +		return ret;
>  
>  	for (i = 0; i < ARRAY_SIZE(riic_irqs); i++) {
>  		ret = platform_get_irq(pdev, riic_irqs[i].res_num);
> @@ -492,8 +493,7 @@ static int riic_i2c_remove(struct platform_device *pdev)
>  }
>  
>  static const struct of_device_id riic_i2c_dt_ids[] = {
> -	{ .compatible = "renesas,riic-r9a07g044", .data = (void *)RIIC_RZ_G2L },
> -	{ .compatible = "renesas,riic-rz", .data = (void *)RIIC_RZ_A },
> +	{ .compatible = "renesas,riic-rz", },
>  	{ /* Sentinel */ },
>  };
>  
> -- 
> 2.17.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] i2c: riic: Simplify reset handling
  2022-02-09 23:22 [PATCH] i2c: riic: Simplify reset handling Lad Prabhakar
  2022-02-17 19:51 ` Wolfram Sang
@ 2022-02-18  8:44 ` Geert Uytterhoeven
  2022-03-01 15:07 ` Wolfram Sang
  2 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2022-02-18  8:44 UTC (permalink / raw)
  To: Lad Prabhakar
  Cc: Chris Brandt, Philipp Zabel, Linux-Renesas, Linux I2C,
	Linux Kernel Mailing List, Prabhakar, Biju Das

On Thu, Feb 10, 2022 at 12:22 AM Lad Prabhakar
<prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:
> Read reset phandle as optional instead of exclusive so that all the DT's
> passing the reset phandle can be used to assert/deassert the reset line.
> With this change we don't have to differentiate the RZ/G2L SoC.
>
> With the above changes we no longer need the "renesas,riic-r9a07g044"
> compatible string, so drop it from riic_i2c_dt_ids[]. No changes are
> required to the r9a07g044.dtsi as we already have "renesas,riic-rz" as a
> fallback compatible string.
>
> While at it, check the return code of reset_control_deassert() as it might
> fail and also add a devres action to assert the reset line.
>
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] i2c: riic: Simplify reset handling
  2022-02-09 23:22 [PATCH] i2c: riic: Simplify reset handling Lad Prabhakar
  2022-02-17 19:51 ` Wolfram Sang
  2022-02-18  8:44 ` Geert Uytterhoeven
@ 2022-03-01 15:07 ` Wolfram Sang
  2 siblings, 0 replies; 4+ messages in thread
From: Wolfram Sang @ 2022-03-01 15:07 UTC (permalink / raw)
  To: Lad Prabhakar
  Cc: Geert Uytterhoeven, Chris Brandt, Philipp Zabel,
	linux-renesas-soc, linux-i2c, linux-kernel, Prabhakar, Biju Das

[-- Attachment #1: Type: text/plain, Size: 796 bytes --]

On Wed, Feb 09, 2022 at 11:22:32PM +0000, Lad Prabhakar wrote:
> Read reset phandle as optional instead of exclusive so that all the DT's
> passing the reset phandle can be used to assert/deassert the reset line.
> With this change we don't have to differentiate the RZ/G2L SoC.
> 
> With the above changes we no longer need the "renesas,riic-r9a07g044"
> compatible string, so drop it from riic_i2c_dt_ids[]. No changes are
> required to the r9a07g044.dtsi as we already have "renesas,riic-rz" as a
> fallback compatible string.
> 
> While at it, check the return code of reset_control_deassert() as it might
> fail and also add a devres action to assert the reset line.
> 
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Applied to for-next, thanks!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-03-01 15:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-09 23:22 [PATCH] i2c: riic: Simplify reset handling Lad Prabhakar
2022-02-17 19:51 ` Wolfram Sang
2022-02-18  8:44 ` Geert Uytterhoeven
2022-03-01 15:07 ` Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).