[V2,07/18] i2c: imx-lpi2c: manage irq resource request/release in runtime pm

Message ID 20210406113306.2633595-8-xiaoning.wang@nxp.com
State New
Headers show
Series
  • i2c: imx-lpi2c: New features and bug fixes
Related show

Commit Message

Clark Wang April 6, 2021, 11:32 a.m.
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>
Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
---
V2 changes:
 - Change to use request_irq/free_irq.
---
 drivers/i2c/busses/i2c-imx-lpi2c.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

Comments

Aisheng Dong May 21, 2021, 6:38 a.m. | #1
> From: Clark Wang <xiaoning.wang@nxp.com>

> Sent: Tuesday, April 6, 2021 7:33 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>

> Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>

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


Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>


Regards
Aisheng

> ---

> V2 changes:

>  - Change to use request_irq/free_irq.

> ---

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

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

> 

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

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

> index 89b7b0795f51..333209ba81c1 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;

> @@ -571,7 +572,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)

> @@ -581,9 +582,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;

> @@ -609,13 +610,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, 0,

> -			       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);

> 

> @@ -668,6 +662,7 @@ static int __maybe_unused

> lpi2c_runtime_suspend(struct device *dev)  {

>  	struct lpi2c_imx_struct *lpi2c_imx = dev_get_drvdata(dev);

> 

> +	free_irq(lpi2c_imx->irq, lpi2c_imx);

>  	lpi2c_imx_clocks_unprepare(lpi2c_imx);

>  	pinctrl_pm_select_sleep_state(dev);

> 

> @@ -677,10 +672,21 @@ static int __maybe_unused

> lpi2c_runtime_suspend(struct device *dev)  static int __maybe_unused

> lpi2c_runtime_resume(struct device *dev)  {

>  	struct lpi2c_imx_struct *lpi2c_imx = dev_get_drvdata(dev);

> +	int ret = 0;

> 

>  	pinctrl_pm_select_default_state(dev);

> +	ret = lpi2c_imx_clocks_prepare(lpi2c_imx);

> +	if (ret)

> +		return ret;

> 

> -	return lpi2c_imx_clocks_prepare(lpi2c_imx);

> +	ret = request_irq(lpi2c_imx->irq, lpi2c_imx_isr, 0,

> +			       dev_name(dev), lpi2c_imx);

> +	if (ret) {

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

> +		return ret;

> +	}

> +

> +	return ret;

>  }

> 

>  static const struct dev_pm_ops lpi2c_pm_ops = {

> --

> 2.25.1

Patch

diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c
index 89b7b0795f51..333209ba81c1 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;
@@ -571,7 +572,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)
@@ -581,9 +582,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;
@@ -609,13 +610,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, 0,
-			       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);
 
@@ -668,6 +662,7 @@  static int __maybe_unused lpi2c_runtime_suspend(struct device *dev)
 {
 	struct lpi2c_imx_struct *lpi2c_imx = dev_get_drvdata(dev);
 
+	free_irq(lpi2c_imx->irq, lpi2c_imx);
 	lpi2c_imx_clocks_unprepare(lpi2c_imx);
 	pinctrl_pm_select_sleep_state(dev);
 
@@ -677,10 +672,21 @@  static int __maybe_unused lpi2c_runtime_suspend(struct device *dev)
 static int __maybe_unused lpi2c_runtime_resume(struct device *dev)
 {
 	struct lpi2c_imx_struct *lpi2c_imx = dev_get_drvdata(dev);
+	int ret = 0;
 
 	pinctrl_pm_select_default_state(dev);
+	ret = lpi2c_imx_clocks_prepare(lpi2c_imx);
+	if (ret)
+		return ret;
 
-	return lpi2c_imx_clocks_prepare(lpi2c_imx);
+	ret = request_irq(lpi2c_imx->irq, lpi2c_imx_isr, 0,
+			       dev_name(dev), lpi2c_imx);
+	if (ret) {
+		dev_err(dev, "can't claim irq %d\n", lpi2c_imx->irq);
+		return ret;
+	}
+
+	return ret;
 }
 
 static const struct dev_pm_ops lpi2c_pm_ops = {