[PATCH v2 1/4] i3c: renesas: Switch to clk_bulk API and store clocks in private data

Tommaso Merciai posted 4 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH v2 1/4] i3c: renesas: Switch to clk_bulk API and store clocks in private data
Posted by Tommaso Merciai 1 month, 1 week ago
Replace individual devm_clk_get_enabled() calls with the clk_bulk API
and store the clock handles in the driver's private data structure.

This simplifies the code, and prepares the driver for upcoming
suspend/resume support.

No functional change intended.

Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
v1->v2:
 - New patch.

 drivers/i3c/master/renesas-i3c.c | 42 +++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/drivers/i3c/master/renesas-i3c.c b/drivers/i3c/master/renesas-i3c.c
index 426a418f29b6..8ef6ff06df90 100644
--- a/drivers/i3c/master/renesas-i3c.c
+++ b/drivers/i3c/master/renesas-i3c.c
@@ -259,7 +259,8 @@ struct renesas_i3c {
 	u8 addrs[RENESAS_I3C_MAX_DEVS];
 	struct renesas_i3c_xferqueue xferqueue;
 	void __iomem *regs;
-	struct clk *tclk;
+	struct clk_bulk_data clks[3];
+	u8 num_clks;
 };
 
 struct renesas_i3c_i2c_dev_data {
@@ -276,6 +277,10 @@ struct renesas_i3c_config {
 	unsigned int has_pclkrw:1;
 };
 
+static const char * const renesas_i3c_clks[] = {
+	"pclk", "tclk", "pclkrw"
+};
+
 static inline void renesas_i3c_reg_update(void __iomem *reg, u32 mask, u32 val)
 {
 	u32 data = readl(reg);
@@ -489,7 +494,7 @@ static int renesas_i3c_bus_init(struct i3c_master_controller *m)
 	int od_high_ticks, od_low_ticks, i2c_total_ticks;
 	int ret;
 
-	rate = clk_get_rate(i3c->tclk);
+	rate = clk_get_rate(i3c->clks[1].clk);
 	if (!rate)
 		return -EINVAL;
 
@@ -1298,11 +1303,17 @@ static const struct renesas_i3c_irq_desc renesas_i3c_irqs[] = {
 	{ .name = "nack", .isr = renesas_i3c_tend_isr, .desc = "i3c-nack" },
 };
 
+static void renesas_i3c_clk_bulk_disable_unprepare(void *data)
+{
+	struct renesas_i3c *i3c = data;
+
+	clk_bulk_disable_unprepare(i3c->num_clks, i3c->clks);
+}
+
 static int renesas_i3c_probe(struct platform_device *pdev)
 {
 	struct renesas_i3c *i3c;
 	struct reset_control *reset;
-	struct clk *clk;
 	const struct renesas_i3c_config *config = of_device_get_match_data(&pdev->dev);
 	int ret, i;
 
@@ -1317,19 +1328,22 @@ static int renesas_i3c_probe(struct platform_device *pdev)
 	if (IS_ERR(i3c->regs))
 		return PTR_ERR(i3c->regs);
 
-	clk = devm_clk_get_enabled(&pdev->dev, "pclk");
-	if (IS_ERR(clk))
-		return PTR_ERR(clk);
+	i3c->num_clks = config->has_pclkrw ? 3 : 2;
 
-	if (config->has_pclkrw) {
-		clk = devm_clk_get_enabled(&pdev->dev, "pclkrw");
-		if (IS_ERR(clk))
-			return PTR_ERR(clk);
-	}
+	for (i = 0; i < i3c->num_clks; i++)
+		i3c->clks[i].id = renesas_i3c_clks[i];
 
-	i3c->tclk = devm_clk_get_enabled(&pdev->dev, "tclk");
-	if (IS_ERR(i3c->tclk))
-		return PTR_ERR(i3c->tclk);
+	ret = devm_clk_bulk_get(&pdev->dev, i3c->num_clks, i3c->clks);
+	if (ret)
+		return ret;
+
+	ret = clk_bulk_prepare_enable(i3c->num_clks, i3c->clks);
+	if (ret)
+		return ret;
+
+	ret = devm_add_action_or_reset(&pdev->dev, renesas_i3c_clk_bulk_disable_unprepare, i3c);
+	if (ret)
+		return ret;
 
 	reset = devm_reset_control_get_optional_exclusive_deasserted(&pdev->dev, "tresetn");
 	if (IS_ERR(reset))
-- 
2.43.0
Re: [PATCH v2 1/4] i3c: renesas: Switch to clk_bulk API and store clocks in private data
Posted by Frank Li 1 month, 1 week ago
On Tue, Dec 30, 2025 at 11:39:36AM +0100, Tommaso Merciai wrote:
> Replace individual devm_clk_get_enabled() calls with the clk_bulk API
> and store the clock handles in the driver's private data structure.
>
> This simplifies the code, and prepares the driver for upcoming
> suspend/resume support.
>
> No functional change intended.
>
> Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
> ---
> v1->v2:
>  - New patch.
>
>  drivers/i3c/master/renesas-i3c.c | 42 +++++++++++++++++++++-----------
>  1 file changed, 28 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/i3c/master/renesas-i3c.c b/drivers/i3c/master/renesas-i3c.c
> index 426a418f29b6..8ef6ff06df90 100644
> --- a/drivers/i3c/master/renesas-i3c.c
> +++ b/drivers/i3c/master/renesas-i3c.c
> @@ -259,7 +259,8 @@ struct renesas_i3c {
>  	u8 addrs[RENESAS_I3C_MAX_DEVS];
>  	struct renesas_i3c_xferqueue xferqueue;
>  	void __iomem *regs;
> -	struct clk *tclk;
> +	struct clk_bulk_data clks[3];
> +	u8 num_clks;
>  };
>
>  struct renesas_i3c_i2c_dev_data {
> @@ -276,6 +277,10 @@ struct renesas_i3c_config {
>  	unsigned int has_pclkrw:1;
>  };
>
> +static const char * const renesas_i3c_clks[] = {
> +	"pclk", "tclk", "pclkrw"
> +};
> +
>  static inline void renesas_i3c_reg_update(void __iomem *reg, u32 mask, u32 val)
>  {
>  	u32 data = readl(reg);
> @@ -489,7 +494,7 @@ static int renesas_i3c_bus_init(struct i3c_master_controller *m)
>  	int od_high_ticks, od_low_ticks, i2c_total_ticks;
>  	int ret;
>
> -	rate = clk_get_rate(i3c->tclk);
> +	rate = clk_get_rate(i3c->clks[1].clk);

Can you use macro of variable replace hardcode "1"

>  	if (!rate)
>  		return -EINVAL;
>
> @@ -1298,11 +1303,17 @@ static const struct renesas_i3c_irq_desc renesas_i3c_irqs[] = {
>  	{ .name = "nack", .isr = renesas_i3c_tend_isr, .desc = "i3c-nack" },
>  };
>
> +static void renesas_i3c_clk_bulk_disable_unprepare(void *data)
> +{
> +	struct renesas_i3c *i3c = data;
> +
> +	clk_bulk_disable_unprepare(i3c->num_clks, i3c->clks);
> +}
> +
>  static int renesas_i3c_probe(struct platform_device *pdev)
>  {
>  	struct renesas_i3c *i3c;
>  	struct reset_control *reset;
> -	struct clk *clk;
>  	const struct renesas_i3c_config *config = of_device_get_match_data(&pdev->dev);
>  	int ret, i;
>
> @@ -1317,19 +1328,22 @@ static int renesas_i3c_probe(struct platform_device *pdev)
>  	if (IS_ERR(i3c->regs))
>  		return PTR_ERR(i3c->regs);
>
> -	clk = devm_clk_get_enabled(&pdev->dev, "pclk");
> -	if (IS_ERR(clk))
> -		return PTR_ERR(clk);
> +	i3c->num_clks = config->has_pclkrw ? 3 : 2;
>
> -	if (config->has_pclkrw) {
> -		clk = devm_clk_get_enabled(&pdev->dev, "pclkrw");
> -		if (IS_ERR(clk))
> -			return PTR_ERR(clk);
> -	}
> +	for (i = 0; i < i3c->num_clks; i++)
> +		i3c->clks[i].id = renesas_i3c_clks[i];
>
> -	i3c->tclk = devm_clk_get_enabled(&pdev->dev, "tclk");
> -	if (IS_ERR(i3c->tclk))
> -		return PTR_ERR(i3c->tclk);
> +	ret = devm_clk_bulk_get(&pdev->dev, i3c->num_clks, i3c->clks);
> +	if (ret)
> +		return ret;
> +
> +	ret = clk_bulk_prepare_enable(i3c->num_clks, i3c->clks);
> +	if (ret)
> +		return ret;
> +
> +	ret = devm_add_action_or_reset(&pdev->dev, renesas_i3c_clk_bulk_disable_unprepare, i3c);
> +	if (ret)
> +		return ret;

Can you use devm_clk_bulk_get_all_enabled()? all dts already verified
by dt-schema.

Frank

>
>  	reset = devm_reset_control_get_optional_exclusive_deasserted(&pdev->dev, "tresetn");
>  	if (IS_ERR(reset))
> --
> 2.43.0
>
Re: [PATCH v2 1/4] i3c: renesas: Switch to clk_bulk API and store clocks in private data
Posted by Tommaso Merciai 1 month, 1 week ago
Hi Frank,
Thanks for your review!


On Tue, Dec 30, 2025 at 10:44:02AM -0500, Frank Li wrote:
> On Tue, Dec 30, 2025 at 11:39:36AM +0100, Tommaso Merciai wrote:
> > Replace individual devm_clk_get_enabled() calls with the clk_bulk API
> > and store the clock handles in the driver's private data structure.
> >
> > This simplifies the code, and prepares the driver for upcoming
> > suspend/resume support.
> >
> > No functional change intended.
> >
> > Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
> > ---
> > v1->v2:
> >  - New patch.
> >
> >  drivers/i3c/master/renesas-i3c.c | 42 +++++++++++++++++++++-----------
> >  1 file changed, 28 insertions(+), 14 deletions(-)
> >
> > diff --git a/drivers/i3c/master/renesas-i3c.c b/drivers/i3c/master/renesas-i3c.c
> > index 426a418f29b6..8ef6ff06df90 100644
> > --- a/drivers/i3c/master/renesas-i3c.c
> > +++ b/drivers/i3c/master/renesas-i3c.c
> > @@ -259,7 +259,8 @@ struct renesas_i3c {
> >  	u8 addrs[RENESAS_I3C_MAX_DEVS];
> >  	struct renesas_i3c_xferqueue xferqueue;
> >  	void __iomem *regs;
> > -	struct clk *tclk;
> > +	struct clk_bulk_data clks[3];
> > +	u8 num_clks;
> >  };
> >
> >  struct renesas_i3c_i2c_dev_data {
> > @@ -276,6 +277,10 @@ struct renesas_i3c_config {
> >  	unsigned int has_pclkrw:1;
> >  };
> >
> > +static const char * const renesas_i3c_clks[] = {
> > +	"pclk", "tclk", "pclkrw"
> > +};
> > +
> >  static inline void renesas_i3c_reg_update(void __iomem *reg, u32 mask, u32 val)
> >  {
> >  	u32 data = readl(reg);
> > @@ -489,7 +494,7 @@ static int renesas_i3c_bus_init(struct i3c_master_controller *m)
> >  	int od_high_ticks, od_low_ticks, i2c_total_ticks;
> >  	int ret;
> >
> > -	rate = clk_get_rate(i3c->tclk);
> > +	rate = clk_get_rate(i3c->clks[1].clk);
> 
> Can you use macro of variable replace hardcode "1"

Ack! I'd go for:

	i3c->rate = clk_get_rate(i3c->clks[RENESAS_I3C_TCLK_IDX].clk);

in v3, thanks.

> 
> >  	if (!rate)
> >  		return -EINVAL;
> >
> > @@ -1298,11 +1303,17 @@ static const struct renesas_i3c_irq_desc renesas_i3c_irqs[] = {
> >  	{ .name = "nack", .isr = renesas_i3c_tend_isr, .desc = "i3c-nack" },
> >  };
> >
> > +static void renesas_i3c_clk_bulk_disable_unprepare(void *data)
> > +{
> > +	struct renesas_i3c *i3c = data;
> > +
> > +	clk_bulk_disable_unprepare(i3c->num_clks, i3c->clks);
> > +}
> > +
> >  static int renesas_i3c_probe(struct platform_device *pdev)
> >  {
> >  	struct renesas_i3c *i3c;
> >  	struct reset_control *reset;
> > -	struct clk *clk;
> >  	const struct renesas_i3c_config *config = of_device_get_match_data(&pdev->dev);
> >  	int ret, i;
> >
> > @@ -1317,19 +1328,22 @@ static int renesas_i3c_probe(struct platform_device *pdev)
> >  	if (IS_ERR(i3c->regs))
> >  		return PTR_ERR(i3c->regs);
> >
> > -	clk = devm_clk_get_enabled(&pdev->dev, "pclk");
> > -	if (IS_ERR(clk))
> > -		return PTR_ERR(clk);
> > +	i3c->num_clks = config->has_pclkrw ? 3 : 2;
> >
> > -	if (config->has_pclkrw) {
> > -		clk = devm_clk_get_enabled(&pdev->dev, "pclkrw");
> > -		if (IS_ERR(clk))
> > -			return PTR_ERR(clk);
> > -	}
> > +	for (i = 0; i < i3c->num_clks; i++)
> > +		i3c->clks[i].id = renesas_i3c_clks[i];
> >
> > -	i3c->tclk = devm_clk_get_enabled(&pdev->dev, "tclk");
> > -	if (IS_ERR(i3c->tclk))
> > -		return PTR_ERR(i3c->tclk);
> > +	ret = devm_clk_bulk_get(&pdev->dev, i3c->num_clks, i3c->clks);
> > +	if (ret)
> > +		return ret;
> > +
> > +	ret = clk_bulk_prepare_enable(i3c->num_clks, i3c->clks);
> > +	if (ret)
> > +		return ret;
> > +
> > +	ret = devm_add_action_or_reset(&pdev->dev, renesas_i3c_clk_bulk_disable_unprepare, i3c);
> > +	if (ret)
> > +		return ret;
> 
> Can you use devm_clk_bulk_get_all_enabled()? all dts already verified
> by dt-schema.

Ack! I'd got for:

	i3c->num_clks = config->has_pclkrw ? 3 : 2;

	for (i = 0; i < i3c->num_clks; i++)
		i3c->clks[i].id = renesas_i3c_clks[i];

	ret = devm_clk_bulk_get_all_enabled(&pdev->dev, &i3c->clks);
	if (ret < 0)
		return ret;

In v3, Thanks.

> 
> Frank
> 
> >
> >  	reset = devm_reset_control_get_optional_exclusive_deasserted(&pdev->dev, "tresetn");
> >  	if (IS_ERR(reset))
> > --
> > 2.43.0
> >

Kind Regards,
Tommaso
Re: [PATCH v2 1/4] i3c: renesas: Switch to clk_bulk API and store clocks in private data
Posted by Tommaso Merciai 1 month, 1 week ago
Hi Frank,

On Tue, Dec 30, 2025 at 05:24:54PM +0100, Tommaso Merciai wrote:
> Hi Frank,
> Thanks for your review!
> 
> 
> On Tue, Dec 30, 2025 at 10:44:02AM -0500, Frank Li wrote:
> > On Tue, Dec 30, 2025 at 11:39:36AM +0100, Tommaso Merciai wrote:
> > > Replace individual devm_clk_get_enabled() calls with the clk_bulk API
> > > and store the clock handles in the driver's private data structure.
> > >
> > > This simplifies the code, and prepares the driver for upcoming
> > > suspend/resume support.
> > >
> > > No functional change intended.
> > >
> > > Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
> > > ---
> > > v1->v2:
> > >  - New patch.
> > >
> > >  drivers/i3c/master/renesas-i3c.c | 42 +++++++++++++++++++++-----------
> > >  1 file changed, 28 insertions(+), 14 deletions(-)
> > >
> > > diff --git a/drivers/i3c/master/renesas-i3c.c b/drivers/i3c/master/renesas-i3c.c
> > > index 426a418f29b6..8ef6ff06df90 100644
> > > --- a/drivers/i3c/master/renesas-i3c.c
> > > +++ b/drivers/i3c/master/renesas-i3c.c
> > > @@ -259,7 +259,8 @@ struct renesas_i3c {
> > >  	u8 addrs[RENESAS_I3C_MAX_DEVS];
> > >  	struct renesas_i3c_xferqueue xferqueue;
> > >  	void __iomem *regs;
> > > -	struct clk *tclk;
> > > +	struct clk_bulk_data clks[3];
> > > +	u8 num_clks;
> > >  };
> > >
> > >  struct renesas_i3c_i2c_dev_data {
> > > @@ -276,6 +277,10 @@ struct renesas_i3c_config {
> > >  	unsigned int has_pclkrw:1;
> > >  };
> > >
> > > +static const char * const renesas_i3c_clks[] = {
> > > +	"pclk", "tclk", "pclkrw"
> > > +};
> > > +
> > >  static inline void renesas_i3c_reg_update(void __iomem *reg, u32 mask, u32 val)
> > >  {
> > >  	u32 data = readl(reg);
> > > @@ -489,7 +494,7 @@ static int renesas_i3c_bus_init(struct i3c_master_controller *m)
> > >  	int od_high_ticks, od_low_ticks, i2c_total_ticks;
> > >  	int ret;
> > >
> > > -	rate = clk_get_rate(i3c->tclk);
> > > +	rate = clk_get_rate(i3c->clks[1].clk);
> > 
> > Can you use macro of variable replace hardcode "1"
> 
> Ack! I'd go for:
> 
> 	i3c->rate = clk_get_rate(i3c->clks[RENESAS_I3C_TCLK_IDX].clk);
> 
> in v3, thanks.
> 
> > 
> > >  	if (!rate)
> > >  		return -EINVAL;
> > >
> > > @@ -1298,11 +1303,17 @@ static const struct renesas_i3c_irq_desc renesas_i3c_irqs[] = {
> > >  	{ .name = "nack", .isr = renesas_i3c_tend_isr, .desc = "i3c-nack" },
> > >  };
> > >
> > > +static void renesas_i3c_clk_bulk_disable_unprepare(void *data)
> > > +{
> > > +	struct renesas_i3c *i3c = data;
> > > +
> > > +	clk_bulk_disable_unprepare(i3c->num_clks, i3c->clks);
> > > +}
> > > +
> > >  static int renesas_i3c_probe(struct platform_device *pdev)
> > >  {
> > >  	struct renesas_i3c *i3c;
> > >  	struct reset_control *reset;
> > > -	struct clk *clk;
> > >  	const struct renesas_i3c_config *config = of_device_get_match_data(&pdev->dev);
> > >  	int ret, i;
> > >
> > > @@ -1317,19 +1328,22 @@ static int renesas_i3c_probe(struct platform_device *pdev)
> > >  	if (IS_ERR(i3c->regs))
> > >  		return PTR_ERR(i3c->regs);
> > >
> > > -	clk = devm_clk_get_enabled(&pdev->dev, "pclk");
> > > -	if (IS_ERR(clk))
> > > -		return PTR_ERR(clk);
> > > +	i3c->num_clks = config->has_pclkrw ? 3 : 2;
> > >
> > > -	if (config->has_pclkrw) {
> > > -		clk = devm_clk_get_enabled(&pdev->dev, "pclkrw");
> > > -		if (IS_ERR(clk))
> > > -			return PTR_ERR(clk);
> > > -	}
> > > +	for (i = 0; i < i3c->num_clks; i++)
> > > +		i3c->clks[i].id = renesas_i3c_clks[i];
> > >
> > > -	i3c->tclk = devm_clk_get_enabled(&pdev->dev, "tclk");
> > > -	if (IS_ERR(i3c->tclk))
> > > -		return PTR_ERR(i3c->tclk);
> > > +	ret = devm_clk_bulk_get(&pdev->dev, i3c->num_clks, i3c->clks);
> > > +	if (ret)
> > > +		return ret;
> > > +
> > > +	ret = clk_bulk_prepare_enable(i3c->num_clks, i3c->clks);
> > > +	if (ret)
> > > +		return ret;
> > > +
> > > +	ret = devm_add_action_or_reset(&pdev->dev, renesas_i3c_clk_bulk_disable_unprepare, i3c);
> > > +	if (ret)
> > > +		return ret;
> > 
> > Can you use devm_clk_bulk_get_all_enabled()? all dts already verified
> > by dt-schema.
> 
> Ack! I'd got for:
> 
> 	i3c->num_clks = config->has_pclkrw ? 3 : 2;
> 
> 	for (i = 0; i < i3c->num_clks; i++)
> 		i3c->clks[i].id = renesas_i3c_clks[i];
> 
> 	ret = devm_clk_bulk_get_all_enabled(&pdev->dev, &i3c->clks);
> 	if (ret < 0)
> 		return ret;

Checking better I think we can directly use:

	ret = devm_clk_bulk_get_all_enabled(&pdev->dev, &i3c->clks);
	if (ret < 0)
		return ret;

	i3c->num_clks = ret;

In this way we can drop also empty_i3c_config and r9a09g047_i3c_config
that are no more required.

Thanks & Regards,
Tommaso

> 
> In v3, Thanks.
> 
> > 
> > Frank
> > 
> > >
> > >  	reset = devm_reset_control_get_optional_exclusive_deasserted(&pdev->dev, "tresetn");
> > >  	if (IS_ERR(reset))
> > > --
> > > 2.43.0
> > >
> 
> Kind Regards,
> Tommaso
> 
>