diff mbox series

[04/11] i2c: imx-lpi2c: manage irq resource request/release in runtime pm

Message ID 20210317065359.3109394-5-xiaoning.wang@nxp.com
State New
Headers show
Series i2c: imx-lpi2c: New features and bug fixes | expand

Commit Message

Clark Wang March 17, 2021, 6:53 a.m. UTC
From: Fugang Duan <fugang.duan@nxp.com>

Manage irq resource request/release in runtime pm to save irq domain's
power.

Signed-off-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Fugang Duan <fugang.duan@nxp.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
---
 drivers/i2c/busses/i2c-imx-lpi2c.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

Comments

Aisheng Dong March 19, 2021, 4:53 a.m. UTC | #1
> From: Clark Wang <xiaoning.wang@nxp.com>

> Sent: Wednesday, March 17, 2021 2:54 PM

> 

> Manage irq resource request/release in runtime pm to save irq domain's

> power.

> 

> Signed-off-by: Frank Li <Frank.Li@nxp.com>

> Signed-off-by: Fugang Duan <fugang.duan@nxp.com>

> Reviewed-by: Frank Li <Frank.Li@nxp.com>

> ---

>  drivers/i2c/busses/i2c-imx-lpi2c.c | 26 ++++++++++++++------------

>  1 file changed, 14 insertions(+), 12 deletions(-)

> 

> diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c

> b/drivers/i2c/busses/i2c-imx-lpi2c.c

> index 664fcc0dba51..e718bb6b2387 100644

> --- a/drivers/i2c/busses/i2c-imx-lpi2c.c

> +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c

> @@ -94,6 +94,7 @@ enum lpi2c_imx_pincfg {

> 

>  struct lpi2c_imx_struct {

>  	struct i2c_adapter	adapter;

> +	int			irq;

>  	struct clk		*clk_per;

>  	struct clk		*clk_ipg;

>  	void __iomem		*base;

> @@ -543,7 +544,7 @@ static int lpi2c_imx_probe(struct platform_device

> *pdev)  {

>  	struct lpi2c_imx_struct *lpi2c_imx;

>  	unsigned int temp;

> -	int irq, ret;

> +	int ret;

> 

>  	lpi2c_imx = devm_kzalloc(&pdev->dev, sizeof(*lpi2c_imx), GFP_KERNEL);

>  	if (!lpi2c_imx)

> @@ -553,9 +554,9 @@ static int lpi2c_imx_probe(struct platform_device

> *pdev)

>  	if (IS_ERR(lpi2c_imx->base))

>  		return PTR_ERR(lpi2c_imx->base);

> 

> -	irq = platform_get_irq(pdev, 0);

> -	if (irq < 0)

> -		return irq;

> +	lpi2c_imx->irq = platform_get_irq(pdev, 0);

> +	if (lpi2c_imx->irq < 0)

> +		return lpi2c_imx->irq;

> 

>  	lpi2c_imx->adapter.owner	= THIS_MODULE;

>  	lpi2c_imx->adapter.algo		= &lpi2c_imx_algo;

> @@ -581,14 +582,6 @@ static int lpi2c_imx_probe(struct platform_device

> *pdev)

>  	if (ret)

>  		lpi2c_imx->bitrate = I2C_MAX_STANDARD_MODE_FREQ;

> 

> -	ret = devm_request_irq(&pdev->dev, irq, lpi2c_imx_isr,

> -			       IRQF_NO_SUSPEND,

> -			       pdev->name, lpi2c_imx);

> -	if (ret) {

> -		dev_err(&pdev->dev, "can't claim irq %d\n", irq);

> -		return ret;

> -	}

> -

>  	i2c_set_adapdata(&lpi2c_imx->adapter, lpi2c_imx);

>  	platform_set_drvdata(pdev, lpi2c_imx);

> 

> @@ -640,6 +633,7 @@ static int __maybe_unused

> lpi2c_runtime_suspend(struct device *dev)  {

>  	struct lpi2c_imx_struct *lpi2c_imx = dev_get_drvdata(dev);

> 

> +	devm_free_irq(dev, lpi2c_imx->irq, lpi2c_imx);

>  	clk_disable_unprepare(lpi2c_imx->clk_ipg);

>  	clk_disable_unprepare(lpi2c_imx->clk_per);

>  	pinctrl_pm_select_idle_state(dev);

> @@ -665,6 +659,14 @@ static int __maybe_unused

> lpi2c_runtime_resume(struct device *dev)

>  		dev_err(dev, "can't enable I2C ipg clock, ret=%d\n", ret);

>  	}

> 

> +	ret = devm_request_irq(dev, lpi2c_imx->irq, lpi2c_imx_isr,


I guess unnecessary to use devm in rpm

> +			       IRQF_NO_SUSPEND,

> +			       dev_name(dev), lpi2c_imx);

> +	if (ret) {

> +		dev_err(dev, "can't claim irq %d\n", lpi2c_imx->irq);

> +		return ret;

> +	}

> +

>  	return ret;

>  }

> 

> --

> 2.25.1
Clark Wang March 19, 2021, 7:03 a.m. UTC | #2
> -----Original Message-----

> From: Aisheng Dong <aisheng.dong@nxp.com>

> Sent: Friday, March 19, 2021 12:54

> To: Clark Wang <xiaoning.wang@nxp.com>; shawnguo@kernel.org;

> s.hauer@pengutronix.de

> Cc: kernel@pengutronix.de; festevam@gmail.com; dl-linux-imx <linux-

> imx@nxp.com>; sumit.semwal@linaro.org; christian.koenig@amd.com;

> linux-i2c@vger.kernel.org; linux-arm-kernel@lists.infradead.org; linux-

> kernel@vger.kernel.org

> Subject: RE: [PATCH 04/11] i2c: imx-lpi2c: manage irq resource

> request/release in runtime pm

> 

> > From: Clark Wang <xiaoning.wang@nxp.com>

> > Sent: Wednesday, March 17, 2021 2:54 PM

> >

> > Manage irq resource request/release in runtime pm to save irq domain's

> > power.

> >

> > Signed-off-by: Frank Li <Frank.Li@nxp.com>

> > Signed-off-by: Fugang Duan <fugang.duan@nxp.com>

> > Reviewed-by: Frank Li <Frank.Li@nxp.com>

> > ---

> >  drivers/i2c/busses/i2c-imx-lpi2c.c | 26 ++++++++++++++------------

> >  1 file changed, 14 insertions(+), 12 deletions(-)

> >

> > diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c

> > b/drivers/i2c/busses/i2c-imx-lpi2c.c

> > index 664fcc0dba51..e718bb6b2387 100644

> > --- a/drivers/i2c/busses/i2c-imx-lpi2c.c

> > +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c

> > @@ -94,6 +94,7 @@ enum lpi2c_imx_pincfg {

> >

> >  struct lpi2c_imx_struct {

> >  	struct i2c_adapter	adapter;

> > +	int			irq;

> >  	struct clk		*clk_per;

> >  	struct clk		*clk_ipg;

> >  	void __iomem		*base;

> > @@ -543,7 +544,7 @@ static int lpi2c_imx_probe(struct platform_device

> > *pdev)  {

> >  	struct lpi2c_imx_struct *lpi2c_imx;

> >  	unsigned int temp;

> > -	int irq, ret;

> > +	int ret;

> >

> >  	lpi2c_imx = devm_kzalloc(&pdev->dev, sizeof(*lpi2c_imx),

> GFP_KERNEL);

> >  	if (!lpi2c_imx)

> > @@ -553,9 +554,9 @@ static int lpi2c_imx_probe(struct platform_device

> > *pdev)

> >  	if (IS_ERR(lpi2c_imx->base))

> >  		return PTR_ERR(lpi2c_imx->base);

> >

> > -	irq = platform_get_irq(pdev, 0);

> > -	if (irq < 0)

> > -		return irq;

> > +	lpi2c_imx->irq = platform_get_irq(pdev, 0);

> > +	if (lpi2c_imx->irq < 0)

> > +		return lpi2c_imx->irq;

> >

> >  	lpi2c_imx->adapter.owner	= THIS_MODULE;

> >  	lpi2c_imx->adapter.algo		= &lpi2c_imx_algo;

> > @@ -581,14 +582,6 @@ static int lpi2c_imx_probe(struct platform_device

> > *pdev)

> >  	if (ret)

> >  		lpi2c_imx->bitrate = I2C_MAX_STANDARD_MODE_FREQ;

> >

> > -	ret = devm_request_irq(&pdev->dev, irq, lpi2c_imx_isr,

> > -			       IRQF_NO_SUSPEND,

> > -			       pdev->name, lpi2c_imx);

> > -	if (ret) {

> > -		dev_err(&pdev->dev, "can't claim irq %d\n", irq);

> > -		return ret;

> > -	}

> > -

> >  	i2c_set_adapdata(&lpi2c_imx->adapter, lpi2c_imx);

> >  	platform_set_drvdata(pdev, lpi2c_imx);

> >

> > @@ -640,6 +633,7 @@ static int __maybe_unused

> > lpi2c_runtime_suspend(struct device *dev)  {

> >  	struct lpi2c_imx_struct *lpi2c_imx = dev_get_drvdata(dev);

> >

> > +	devm_free_irq(dev, lpi2c_imx->irq, lpi2c_imx);

> >  	clk_disable_unprepare(lpi2c_imx->clk_ipg);

> >  	clk_disable_unprepare(lpi2c_imx->clk_per);

> >  	pinctrl_pm_select_idle_state(dev);

> > @@ -665,6 +659,14 @@ static int __maybe_unused

> > lpi2c_runtime_resume(struct device *dev)

> >  		dev_err(dev, "can't enable I2C ipg clock, ret=%d\n", ret);

> >  	}

> >

> > +	ret = devm_request_irq(dev, lpi2c_imx->irq, lpi2c_imx_isr,

> 

> I guess unnecessary to use devm in rpm


devm_request_irq() will use device resource management.
Other resource like clk and struct space are all managed by devres.
Maybe we can still use devm_ to let devres manage irq here?

Thanks.

Best Regards,
Clark Wang


> 

> > +			       IRQF_NO_SUSPEND,

> > +			       dev_name(dev), lpi2c_imx);

> > +	if (ret) {

> > +		dev_err(dev, "can't claim irq %d\n", lpi2c_imx->irq);

> > +		return ret;

> > +	}

> > +

> >  	return ret;

> >  }

> >

> > --

> > 2.25.1
Aisheng Dong March 19, 2021, 10:12 a.m. UTC | #3
> > > @@ -665,6 +659,14 @@ static int __maybe_unused

> > > lpi2c_runtime_resume(struct device *dev)

> > >  		dev_err(dev, "can't enable I2C ipg clock, ret=%d\n", ret);

> > >  	}

> > >

> > > +	ret = devm_request_irq(dev, lpi2c_imx->irq, lpi2c_imx_isr,

> >

> > I guess unnecessary to use devm in rpm

> 

> devm_request_irq() will use device resource management.

> Other resource like clk and struct space are all managed by devres.

> Maybe we can still use devm_ to let devres manage irq here?

> 


devm_xxx is usually used to auto free resources when probe fail,
driver unbound / device unregister and etc. Not for runtime pm.
I may prefer using request_irq/free_irq directly in runtime.

BTW, current lpi2c_imx_remove seems didn't ensure the device is
In runtime suspend state after removing.
If framework can't guarantee, the driver has to do it.
Anyway, that's another issue and need a separate patch.

Regards
Aisheng

> Thanks.

> 

> Best Regards,

> Clark Wang

> 

> 

> >

> > > +			       IRQF_NO_SUSPEND,

> > > +			       dev_name(dev), lpi2c_imx);

> > > +	if (ret) {

> > > +		dev_err(dev, "can't claim irq %d\n", lpi2c_imx->irq);

> > > +		return ret;

> > > +	}

> > > +

> > >  	return ret;

> > >  }

> > >

> > > --

> > > 2.25.1
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c
index 664fcc0dba51..e718bb6b2387 100644
--- a/drivers/i2c/busses/i2c-imx-lpi2c.c
+++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
@@ -94,6 +94,7 @@  enum lpi2c_imx_pincfg {
 
 struct lpi2c_imx_struct {
 	struct i2c_adapter	adapter;
+	int			irq;
 	struct clk		*clk_per;
 	struct clk		*clk_ipg;
 	void __iomem		*base;
@@ -543,7 +544,7 @@  static int lpi2c_imx_probe(struct platform_device *pdev)
 {
 	struct lpi2c_imx_struct *lpi2c_imx;
 	unsigned int temp;
-	int irq, ret;
+	int ret;
 
 	lpi2c_imx = devm_kzalloc(&pdev->dev, sizeof(*lpi2c_imx), GFP_KERNEL);
 	if (!lpi2c_imx)
@@ -553,9 +554,9 @@  static int lpi2c_imx_probe(struct platform_device *pdev)
 	if (IS_ERR(lpi2c_imx->base))
 		return PTR_ERR(lpi2c_imx->base);
 
-	irq = platform_get_irq(pdev, 0);
-	if (irq < 0)
-		return irq;
+	lpi2c_imx->irq = platform_get_irq(pdev, 0);
+	if (lpi2c_imx->irq < 0)
+		return lpi2c_imx->irq;
 
 	lpi2c_imx->adapter.owner	= THIS_MODULE;
 	lpi2c_imx->adapter.algo		= &lpi2c_imx_algo;
@@ -581,14 +582,6 @@  static int lpi2c_imx_probe(struct platform_device *pdev)
 	if (ret)
 		lpi2c_imx->bitrate = I2C_MAX_STANDARD_MODE_FREQ;
 
-	ret = devm_request_irq(&pdev->dev, irq, lpi2c_imx_isr,
-			       IRQF_NO_SUSPEND,
-			       pdev->name, lpi2c_imx);
-	if (ret) {
-		dev_err(&pdev->dev, "can't claim irq %d\n", irq);
-		return ret;
-	}
-
 	i2c_set_adapdata(&lpi2c_imx->adapter, lpi2c_imx);
 	platform_set_drvdata(pdev, lpi2c_imx);
 
@@ -640,6 +633,7 @@  static int __maybe_unused lpi2c_runtime_suspend(struct device *dev)
 {
 	struct lpi2c_imx_struct *lpi2c_imx = dev_get_drvdata(dev);
 
+	devm_free_irq(dev, lpi2c_imx->irq, lpi2c_imx);
 	clk_disable_unprepare(lpi2c_imx->clk_ipg);
 	clk_disable_unprepare(lpi2c_imx->clk_per);
 	pinctrl_pm_select_idle_state(dev);
@@ -665,6 +659,14 @@  static int __maybe_unused lpi2c_runtime_resume(struct device *dev)
 		dev_err(dev, "can't enable I2C ipg clock, ret=%d\n", ret);
 	}
 
+	ret = devm_request_irq(dev, lpi2c_imx->irq, lpi2c_imx_isr,
+			       IRQF_NO_SUSPEND,
+			       dev_name(dev), lpi2c_imx);
+	if (ret) {
+		dev_err(dev, "can't claim irq %d\n", lpi2c_imx->irq);
+		return ret;
+	}
+
 	return ret;
 }