* [v3,0/1] i2c: mediatek: add runtime PM operations and bus regulator control
@ 2025-01-03 14:32 Zoie Lin
2025-01-03 14:32 ` [PATCH v3 1/1] " Zoie Lin
2025-01-07 21:28 ` [v3,0/1] " Andi Shyti
0 siblings, 2 replies; 4+ messages in thread
From: Zoie Lin @ 2025-01-03 14:32 UTC (permalink / raw)
To: Qii Wang, Andi Shyti, Matthias Brugger, AngeloGioacchino Del Regno
Cc: Project_Global_Chrome_Upstream_Group, linux-i2c, linux-kernel,
linux-arm-kernel, linux-mediatek, teddy.chen, Zoie Lin
This series is based on linux-next, tag: next-20241220
Changes in v3:
This patch removes the autosuspend functionality from the runtime
PM operations in the I2C driver. These changes have been tested on
the target platform and confirmed to work correctly without the
autosuspend functionality.
Additionally, the patch resumes the I2C bus in mtk_i2c_resume_noirq()
to fix the unbalanced disable issue.
Zoie Lin (1):
i2c: mediatek: add runtime PM operations and bus regulator control
drivers/i2c/busses/i2c-mt65xx.c | 75 +++++++++++++++++++++++++++------
1 file changed, 63 insertions(+), 12 deletions(-)
--
2.45.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v3 1/1] i2c: mediatek: add runtime PM operations and bus regulator control
2025-01-03 14:32 [v3,0/1] i2c: mediatek: add runtime PM operations and bus regulator control Zoie Lin
@ 2025-01-03 14:32 ` Zoie Lin
2025-01-07 21:50 ` Andi Shyti
2025-01-07 21:28 ` [v3,0/1] " Andi Shyti
1 sibling, 1 reply; 4+ messages in thread
From: Zoie Lin @ 2025-01-03 14:32 UTC (permalink / raw)
To: Qii Wang, Andi Shyti, Matthias Brugger, AngeloGioacchino Del Regno
Cc: Project_Global_Chrome_Upstream_Group, linux-i2c, linux-kernel,
linux-arm-kernel, linux-mediatek, teddy.chen, Zoie Lin
This commit introduces support for runtime PM operations in
the I2C driver, enabling runtime suspend and resume functionality.
Although in the most platforms, the bus power of i2c are always
on, some platforms disable the i2c bus power in order to meet
low power request.
This implementation includes bus regulator control to facilitate
proper handling of the bus power based on platform requirements.
Signed-off-by: Zoie Lin <zoie.lin@mediatek.com>
---
drivers/i2c/busses/i2c-mt65xx.c | 75 +++++++++++++++++++++++++++------
1 file changed, 63 insertions(+), 12 deletions(-)
diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c
index 5bd342047d59..307598a5f80e 100644
--- a/drivers/i2c/busses/i2c-mt65xx.c
+++ b/drivers/i2c/busses/i2c-mt65xx.c
@@ -21,6 +21,7 @@
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
#include <linux/scatterlist.h>
#include <linux/sched.h>
#include <linux/slab.h>
@@ -1245,8 +1246,8 @@ static int mtk_i2c_transfer(struct i2c_adapter *adap,
int left_num = num;
struct mtk_i2c *i2c = i2c_get_adapdata(adap);
- ret = clk_bulk_enable(I2C_MT65XX_CLK_MAX, i2c->clocks);
- if (ret)
+ ret = pm_runtime_resume_and_get(i2c->dev);
+ if (ret < 0)
return ret;
i2c->auto_restart = i2c->dev_comp->auto_restart;
@@ -1299,7 +1300,9 @@ static int mtk_i2c_transfer(struct i2c_adapter *adap,
ret = num;
err_exit:
- clk_bulk_disable(I2C_MT65XX_CLK_MAX, i2c->clocks);
+ pm_runtime_mark_last_busy(i2c->dev);
+ pm_runtime_put_sync(i2c->dev);
+
return ret;
}
@@ -1370,6 +1373,40 @@ static int mtk_i2c_parse_dt(struct device_node *np, struct mtk_i2c *i2c)
return 0;
}
+static int mtk_i2c_runtime_suspend(struct device *dev)
+{
+ struct mtk_i2c *i2c = dev_get_drvdata(dev);
+
+ clk_bulk_disable(I2C_MT65XX_CLK_MAX, i2c->clocks);
+ if (i2c->adap.bus_regulator)
+ regulator_disable(i2c->adap.bus_regulator);
+
+ return 0;
+}
+
+static int mtk_i2c_runtime_resume(struct device *dev)
+{
+ int ret = 0;
+ struct mtk_i2c *i2c = dev_get_drvdata(dev);
+
+ if (i2c->adap.bus_regulator) {
+ ret = regulator_enable(i2c->adap.bus_regulator);
+ if (ret) {
+ dev_err(dev, "enable regulator failed!\n");
+ return ret;
+ }
+ }
+
+ ret = clk_bulk_enable(I2C_MT65XX_CLK_MAX, i2c->clocks);
+ if (ret) {
+ if (i2c->adap.bus_regulator)
+ regulator_disable(i2c->adap.bus_regulator);
+ return ret;
+ }
+
+ return 0;
+}
+
static int mtk_i2c_probe(struct platform_device *pdev)
{
int ret = 0;
@@ -1472,13 +1509,18 @@ static int mtk_i2c_probe(struct platform_device *pdev)
}
}
- ret = clk_bulk_prepare_enable(I2C_MT65XX_CLK_MAX, i2c->clocks);
+ ret = clk_bulk_prepare(I2C_MT65XX_CLK_MAX, i2c->clocks);
if (ret) {
- dev_err(&pdev->dev, "clock enable failed!\n");
return ret;
}
+
+ platform_set_drvdata(pdev, i2c);
+
+ ret = mtk_i2c_runtime_resume(i2c->dev);
+ if (ret < 0)
+ goto err_clk_bulk_unprepare;
mtk_i2c_init_hw(i2c);
- clk_bulk_disable(I2C_MT65XX_CLK_MAX, i2c->clocks);
+ mtk_i2c_runtime_suspend(i2c->dev);
ret = devm_request_irq(&pdev->dev, irq, mtk_i2c_irq,
IRQF_NO_SUSPEND | IRQF_TRIGGER_NONE,
@@ -1486,19 +1528,20 @@ static int mtk_i2c_probe(struct platform_device *pdev)
if (ret < 0) {
dev_err(&pdev->dev,
"Request I2C IRQ %d fail\n", irq);
- goto err_bulk_unprepare;
+ goto err_clk_bulk_unprepare;
}
+ pm_runtime_enable(&pdev->dev);
i2c_set_adapdata(&i2c->adap, i2c);
ret = i2c_add_adapter(&i2c->adap);
if (ret)
- goto err_bulk_unprepare;
-
- platform_set_drvdata(pdev, i2c);
+ goto err_pm_runtime_disable;
return 0;
-err_bulk_unprepare:
+err_pm_runtime_disable:
+ pm_runtime_disable(&pdev->dev);
+err_clk_bulk_unprepare:
clk_bulk_unprepare(I2C_MT65XX_CLK_MAX, i2c->clocks);
return ret;
@@ -1510,6 +1553,7 @@ static void mtk_i2c_remove(struct platform_device *pdev)
i2c_del_adapter(&i2c->adap);
+ pm_runtime_disable(&pdev->dev);
clk_bulk_unprepare(I2C_MT65XX_CLK_MAX, i2c->clocks);
}
@@ -1518,6 +1562,10 @@ static int mtk_i2c_suspend_noirq(struct device *dev)
struct mtk_i2c *i2c = dev_get_drvdata(dev);
i2c_mark_adapter_suspended(&i2c->adap);
+
+ if (!pm_runtime_status_suspended(dev))
+ mtk_i2c_runtime_suspend(dev);
+
clk_bulk_unprepare(I2C_MT65XX_CLK_MAX, i2c->clocks);
return 0;
@@ -1536,7 +1584,8 @@ static int mtk_i2c_resume_noirq(struct device *dev)
mtk_i2c_init_hw(i2c);
- clk_bulk_disable(I2C_MT65XX_CLK_MAX, i2c->clocks);
+ if (pm_runtime_status_suspended(dev))
+ mtk_i2c_runtime_resume(dev);
i2c_mark_adapter_resumed(&i2c->adap);
@@ -1546,6 +1595,8 @@ static int mtk_i2c_resume_noirq(struct device *dev)
static const struct dev_pm_ops mtk_i2c_pm = {
NOIRQ_SYSTEM_SLEEP_PM_OPS(mtk_i2c_suspend_noirq,
mtk_i2c_resume_noirq)
+ SET_RUNTIME_PM_OPS(mtk_i2c_runtime_suspend, mtk_i2c_runtime_resume,
+ NULL)
};
static struct platform_driver mtk_i2c_driver = {
--
2.45.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [v3,0/1] i2c: mediatek: add runtime PM operations and bus regulator control
2025-01-03 14:32 [v3,0/1] i2c: mediatek: add runtime PM operations and bus regulator control Zoie Lin
2025-01-03 14:32 ` [PATCH v3 1/1] " Zoie Lin
@ 2025-01-07 21:28 ` Andi Shyti
1 sibling, 0 replies; 4+ messages in thread
From: Andi Shyti @ 2025-01-07 21:28 UTC (permalink / raw)
To: Zoie Lin
Cc: Qii Wang, Matthias Brugger, AngeloGioacchino Del Regno,
Project_Global_Chrome_Upstream_Group, linux-i2c, linux-kernel,
linux-arm-kernel, linux-mediatek, teddy.chen
Hi Zoie,
On Fri, Jan 03, 2025 at 10:32:33PM +0800, Zoie Lin wrote:
> This series is based on linux-next, tag: next-20241220
>
> Changes in v3:
>
> This patch removes the autosuspend functionality from the runtime
> PM operations in the I2C driver. These changes have been tested on
> the target platform and confirmed to work correctly without the
> autosuspend functionality.
Was the autosuspend delay not necessary, then?
Is there a specific reason you included it in the first place?
BTW, next time, please use the format [PATCH v3 0/1] for patches.
Also, for just one patch, a cover letter isn't really necessary.
You can include the changelog after the '---' section of the patch.
was, then, the autosuspend delay not necessary?
Andi
> Additionally, the patch resumes the I2C bus in mtk_i2c_resume_noirq()
> to fix the unbalanced disable issue.
>
>
> Zoie Lin (1):
> i2c: mediatek: add runtime PM operations and bus regulator control
>
> drivers/i2c/busses/i2c-mt65xx.c | 75 +++++++++++++++++++++++++++------
> 1 file changed, 63 insertions(+), 12 deletions(-)
>
> --
> 2.45.2
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3 1/1] i2c: mediatek: add runtime PM operations and bus regulator control
2025-01-03 14:32 ` [PATCH v3 1/1] " Zoie Lin
@ 2025-01-07 21:50 ` Andi Shyti
0 siblings, 0 replies; 4+ messages in thread
From: Andi Shyti @ 2025-01-07 21:50 UTC (permalink / raw)
To: Zoie Lin
Cc: Qii Wang, Matthias Brugger, AngeloGioacchino Del Regno,
Project_Global_Chrome_Upstream_Group, linux-i2c, linux-kernel,
linux-arm-kernel, linux-mediatek, teddy.chen
Hi Zoie,
On Fri, Jan 03, 2025 at 10:32:34PM +0800, Zoie Lin wrote:
> This commit introduces support for runtime PM operations in
> the I2C driver, enabling runtime suspend and resume functionality.
Please, don't start the commit log with "This patch...", please
use the informative form.
> Although in the most platforms, the bus power of i2c are always
/the//
/are/is/
> on, some platforms disable the i2c bus power in order to meet
> low power request.
>
> This implementation includes bus regulator control to facilitate
> proper handling of the bus power based on platform requirements.
>
> Signed-off-by: Zoie Lin <zoie.lin@mediatek.com>
...
> +static int mtk_i2c_runtime_resume(struct device *dev)
> +{
> + int ret = 0;
initialization is not needed.
> + struct mtk_i2c *i2c = dev_get_drvdata(dev);
> +
> + if (i2c->adap.bus_regulator) {
> + ret = regulator_enable(i2c->adap.bus_regulator);
> + if (ret) {
> + dev_err(dev, "enable regulator failed!\n");
> + return ret;
> + }
> + }
> +
> + ret = clk_bulk_enable(I2C_MT65XX_CLK_MAX, i2c->clocks);
> + if (ret) {
> + if (i2c->adap.bus_regulator)
> + regulator_disable(i2c->adap.bus_regulator);
> + return ret;
no need to return here...
> + }
... you can remove the brackets...
> + return 0;
... return ret;
Andi
> +}
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-01-07 21:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-03 14:32 [v3,0/1] i2c: mediatek: add runtime PM operations and bus regulator control Zoie Lin
2025-01-03 14:32 ` [PATCH v3 1/1] " Zoie Lin
2025-01-07 21:50 ` Andi Shyti
2025-01-07 21:28 ` [v3,0/1] " Andi Shyti
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®