Skip to contentSkip to conversation

i2c: mt65xx: allow optional pmic clock

PATCH Applied Daniel Golle 5 participants 7 messages Aug 27, 2023 – Aug 7, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: mt65xx: allow optional pmic clock

Using the I2C host controller on the MT7981 SoC requires 4 clocks to be enabled. One of them, the pmic clk, is only enabled in case 'mediatek,have-pmic' is also set which has other consequences which are not desired in this case.

Allow defining a pmic clk even in case the 'mediatek,have-pmic' propterty is not present and the bus is not used to connect to a pmic, but may still require to enable the pmic clock.

---
 drivers/i2c/busses/i2c-mt65xx.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-mt65xx.c +8 -4
index 1a9b5a068ef1b..a8b5719c33729 100644
@@ -1442,15 +1442,19 @@ static int mtk_i2c_probe(struct platform_device *pdev)
 	if (IS_ERR(i2c->clocks[I2C_MT65XX_CLK_ARB].clk))
 		return PTR_ERR(i2c->clocks[I2C_MT65XX_CLK_ARB].clk);
 
+	i2c->clocks[I2C_MT65XX_CLK_PMIC].clk = devm_clk_get_optional(&pdev->dev, "pmic");
+	if (IS_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk)) {
+		dev_err(&pdev->dev, "cannot get pmic clock\n");
+		return PTR_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk);
+	}
+
 	if (i2c->have_pmic) {
-		i2c->clocks[I2C_MT65XX_CLK_PMIC].clk = devm_clk_get(&pdev->dev, "pmic");
-		if (IS_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk)) {
+		if (!i2c->clocks[I2C_MT65XX_CLK_PMIC].clk) {
 			dev_err(&pdev->dev, "cannot get pmic clock\n");
-			return PTR_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk);
+			return -ENODEV;
 		}
 		speed_clk = I2C_MT65XX_CLK_PMIC;
 	} else {
-		i2c->clocks[I2C_MT65XX_CLK_PMIC].clk = NULL;
 		speed_clk = I2C_MT65XX_CLK_MAIN;
 	}
 
Signature · 1 line
2.41.0
maintainer Reviewed-by on v1 1/1
#1 lore raw

Hi Daniel,

Quoted 19 lines · Daniel Golle

Using the I2C host controller on the MT7981 SoC requires 4 clocks to be enabled. One of them, the pmic clk, is only enabled in case 'mediatek,have-pmic' is also set which has other consequences which are not desired in this case.

Allow defining a pmic clk even in case the 'mediatek,have-pmic' propterty is not present and the bus is not used to connect to a pmic, but may still require to enable the pmic clock.

---
 drivers/i2c/busses/i2c-mt65xx.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-mt65xx.c +0 -0
index 1a9b5a068ef1b..a8b5719c33729 100644

drivers/i2c/busses/i2c-mt65xx.c static int mtk_i2c_probe(struct platform_device *pdev) · line 1448

Quoted 7 lines
drivers/i2c/busses/i2c-mt65xx.c +4 -0
@@ -1442,15 +1442,19 @@ static int mtk_i2c_probe(struct platform_device *pdev)
 	if (IS_ERR(i2c->clocks[I2C_MT65XX_CLK_ARB].clk))
 		return PTR_ERR(i2c->clocks[I2C_MT65XX_CLK_ARB].clk);
 
+	i2c->clocks[I2C_MT65XX_CLK_PMIC].clk = devm_clk_get_optional(&pdev->dev, "pmic");
+	if (IS_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk)) {
+		dev_err(&pdev->dev, "cannot get pmic clock\n");
+		return PTR_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk);

you could have used dev_err_probe() here, but on the other hand it would be inconsistent because it's not used anywhere in this driver... so that it looks good to me:

Andi

#2 lore raw
In reply to Daniel Golle

Il 27/08/23 04:13, Daniel Golle ha scritto:

Quoted 19 lines

Using the I2C host controller on the MT7981 SoC requires 4 clocks to be enabled. One of them, the pmic clk, is only enabled in case 'mediatek,have-pmic' is also set which has other consequences which are not desired in this case.

Allow defining a pmic clk even in case the 'mediatek,have-pmic' propterty is not present and the bus is not used to connect to a pmic, but may still require to enable the pmic clock.

---
  drivers/i2c/busses/i2c-mt65xx.c | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-mt65xx.c +0 -0
index 1a9b5a068ef1b..a8b5719c33729 100644

drivers/i2c/busses/i2c-mt65xx.c static int mtk_i2c_probe(struct platform_device *pdev) · line 1451

Quoted 10 lines
drivers/i2c/busses/i2c-mt65xx.c +6 -0
@@ -1442,15 +1442,19 @@ static int mtk_i2c_probe(struct platform_device *pdev)
  	if (IS_ERR(i2c->clocks[I2C_MT65XX_CLK_ARB].clk))
  		return PTR_ERR(i2c->clocks[I2C_MT65XX_CLK_ARB].clk);
 
+	i2c->clocks[I2C_MT65XX_CLK_PMIC].clk = devm_clk_get_optional(&pdev->dev, "pmic");
+	if (IS_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk)) {
+		dev_err(&pdev->dev, "cannot get pmic clock\n");
+		return PTR_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk);
+	}
+
  	if (i2c->have_pmic) {

...but you're not changing speed_clk if !i2c->have_pmic, I'm not sure that this will work correctly. Perhaps you wanted to also set speed_clk if the clock is present?

if (IS_ERR...) {
error handling
} else if (clk is present)

	speed_clk = I2C_MT65XX_CLK_PMIC;

if (have_pmic && !clk_is_present)
error

Regards,
Angelo

Quoted 13 lines
drivers/i2c/busses/i2c-mt65xx.c +2 -4
-		i2c->clocks[I2C_MT65XX_CLK_PMIC].clk = devm_clk_get(&pdev->dev, "pmic");
-		if (IS_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk)) {
+		if (!i2c->clocks[I2C_MT65XX_CLK_PMIC].clk) {
  			dev_err(&pdev->dev, "cannot get pmic clock\n");
-			return PTR_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk);
+			return -ENODEV;
  		}
  		speed_clk = I2C_MT65XX_CLK_PMIC;
  	} else {
-		i2c->clocks[I2C_MT65XX_CLK_PMIC].clk = NULL;
  		speed_clk = I2C_MT65XX_CLK_MAIN;
  	}
 
#3 lore raw
Quoted 25 lines · AngeloGioacchino Del Regno

Il 27/08/23 04:13, Daniel Golle ha scritto:

Quoted 24 lines

Using the I2C host controller on the MT7981 SoC requires 4 clocks to be enabled. One of them, the pmic clk, is only enabled in case 'mediatek,have-pmic' is also set which has other consequences which are not desired in this case.

Allow defining a pmic clk even in case the 'mediatek,have-pmic' propterty is not present and the bus is not used to connect to a pmic, but may still require to enable the pmic clock.

---
  drivers/i2c/busses/i2c-mt65xx.c | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-mt65xx.c +3 -0
index 1a9b5a068ef1b..a8b5719c33729 100644
@@ -1442,15 +1442,19 @@ static int mtk_i2c_probe(struct platform_device *pdev)
  	if (IS_ERR(i2c->clocks[I2C_MT65XX_CLK_ARB].clk))
  		return PTR_ERR(i2c->clocks[I2C_MT65XX_CLK_ARB].clk);
+	i2c->clocks[I2C_MT65XX_CLK_PMIC].clk = devm_clk_get_optional(&pdev->dev, "pmic");
+	if (IS_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk)) {
+		dev_err(&pdev->dev, "cannot get pmic clock\n");
Quoted 8 lines

drivers/i2c/busses/i2c-mt65xx.c static int mtk_i2c_probe(struct platform_device *pdev) · line 1451

Quoted 4 lines
drivers/i2c/busses/i2c-mt65xx.c +3 -0
+		return PTR_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk);
+	}
+
  	if (i2c->have_pmic) {

...but you're not changing speed_clk if !i2c->have_pmic, I'm not sure that this will work correctly. Perhaps you wanted to also set speed_clk if the clock is present?

No, if I wanted that I could have used the existing 'mediatek,have-pmic' property -- however, all needed e.g. on MT7981 is to make sure the clock is enabled, but still use I2C_MT65XX_CLK_MAIN as speed_clk.

Quoted 26 lines

if (IS_ERR...) {
error handling
} else if (clk is present)

	speed_clk = I2C_MT65XX_CLK_PMIC;

if (have_pmic && !clk_is_present)
error

Regards,
Angelo

Quoted 12 lines
drivers/i2c/busses/i2c-mt65xx.c +2 -4
-		i2c->clocks[I2C_MT65XX_CLK_PMIC].clk = devm_clk_get(&pdev->dev, "pmic");
-		if (IS_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk)) {
+		if (!i2c->clocks[I2C_MT65XX_CLK_PMIC].clk) {
  			dev_err(&pdev->dev, "cannot get pmic clock\n");
-			return PTR_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk);
+			return -ENODEV;
  		}
  		speed_clk = I2C_MT65XX_CLK_PMIC;
  	} else {
-		i2c->clocks[I2C_MT65XX_CLK_PMIC].clk = NULL;
  		speed_clk = I2C_MT65XX_CLK_MAIN;
  	}
maintainer Reviewed-by
#4 lore raw

Il 14/09/23 11:07, Daniel Golle ha scritto:

Quoted 35 lines · AngeloGioacchino Del Regno
Quoted 25 lines

Il 27/08/23 04:13, Daniel Golle ha scritto:

Quoted 24 lines

Using the I2C host controller on the MT7981 SoC requires 4 clocks to be enabled. One of them, the pmic clk, is only enabled in case 'mediatek,have-pmic' is also set which has other consequences which are not desired in this case.

Allow defining a pmic clk even in case the 'mediatek,have-pmic' propterty is not present and the bus is not used to connect to a pmic, but may still require to enable the pmic clock.

---
   drivers/i2c/busses/i2c-mt65xx.c | 12 ++++++++----
   1 file changed, 8 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-mt65xx.c +3 -0
index 1a9b5a068ef1b..a8b5719c33729 100644
@@ -1442,15 +1442,19 @@ static int mtk_i2c_probe(struct platform_device *pdev)
   	if (IS_ERR(i2c->clocks[I2C_MT65XX_CLK_ARB].clk))
   		return PTR_ERR(i2c->clocks[I2C_MT65XX_CLK_ARB].clk);
+	i2c->clocks[I2C_MT65XX_CLK_PMIC].clk = devm_clk_get_optional(&pdev->dev, "pmic");
+	if (IS_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk)) {
+		dev_err(&pdev->dev, "cannot get pmic clock\n");
Quoted 8 lines

drivers/i2c/busses/i2c-mt65xx.c static int mtk_i2c_probe(struct platform_device *pdev) · line 1451

Quoted 4 lines
drivers/i2c/busses/i2c-mt65xx.c +3 -0
+		return PTR_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk);
+	}
+
   	if (i2c->have_pmic) {

...but you're not changing speed_clk if !i2c->have_pmic, I'm not sure that this will work correctly. Perhaps you wanted to also set speed_clk if the clock is present?

Quoted 4 lines

No, if I wanted that I could have used the existing 'mediatek,have-pmic' property -- however, all needed e.g. on MT7981 is to make sure the clock is enabled, but still use I2C_MT65XX_CLK_MAIN as speed_clk.

Sorry, I've misunderstood the intention and yes, I understand now.

#5 lore raw
In reply to AngeloGioacchino Del Regno

Add kewei and shunchang.

-----邮件原件-----
发件人: AngeloGioacchino Del Regno <[email protected]>
发送时间: 2023年9月13日 22:01
收件人: Daniel Golle <[email protected]>; Qii Wang (王琪) <[email protected]>; Andi Shyti <[email protected]>; Matthias Brugger <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected] 抄送: 郭小桥 <[email protected]>
主题: Re: [PATCH] i2c: mt65xx: allow optional pmic clock

Il 27/08/23 04:13, Daniel Golle ha scritto:

Quoted 20 lines

Using the I2C host controller on the MT7981 SoC requires 4 clocks to be enabled. One of them, the pmic clk, is only enabled in case 'mediatek,have-pmic' is also set which has other consequences which are not desired in this case.

Allow defining a pmic clk even in case the 'mediatek,have-pmic' propterty is not present and the bus is not used to connect to a pmic, but may still require to enable the pmic clock.

---
  drivers/i2c/busses/i2c-mt65xx.c | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/i2c/busses/i2c-mt65xx.c index 1a9b5a068ef1b..a8b5719c33729 100644

drivers/i2c/busses/i2c-mt65xx.c static int mtk_i2c_probe(struct platform_device *pdev) · line 1451

Quoted 10 lines
drivers/i2c/busses/i2c-mt65xx.c +6 -0
@@ -1442,15 +1442,19 @@ static int mtk_i2c_probe(struct platform_device *pdev)
  	if (IS_ERR(i2c->clocks[I2C_MT65XX_CLK_ARB].clk))
  		return PTR_ERR(i2c->clocks[I2C_MT65XX_CLK_ARB].clk);
 
+	i2c->clocks[I2C_MT65XX_CLK_PMIC].clk = devm_clk_get_optional(&pdev->dev, "pmic");
+	if (IS_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk)) {
+		dev_err(&pdev->dev, "cannot get pmic clock\n");
+		return PTR_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk);
+	}
+
  	if (i2c->have_pmic) {

...but you're not changing speed_clk if !i2c->have_pmic, I'm not sure that this will work correctly. Perhaps you wanted to also set speed_clk if the clock is present?

if (IS_ERR...) {
error handling
} else if (clk is present)

	speed_clk = I2C_MT65XX_CLK_PMIC;

if (have_pmic && !clk_is_present)
error

Regards,
Angelo

Quoted 13 lines
drivers/i2c/busses/i2c-mt65xx.c +2 -4
-		i2c->clocks[I2C_MT65XX_CLK_PMIC].clk = devm_clk_get(&pdev->dev, "pmic");
-		if (IS_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk)) {
+		if (!i2c->clocks[I2C_MT65XX_CLK_PMIC].clk) {
  			dev_err(&pdev->dev, "cannot get pmic clock\n");
-			return PTR_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk);
+			return -ENODEV;
  		}
  		speed_clk = I2C_MT65XX_CLK_PMIC;
  	} else {
-		i2c->clocks[I2C_MT65XX_CLK_PMIC].clk = NULL;
  		speed_clk = I2C_MT65XX_CLK_MAIN;
  	}
 
Applied
#6 lore raw
In reply to Daniel Golle
Quoted 10 lines · Daniel Golle

Using the I2C host controller on the MT7981 SoC requires 4 clocks to be enabled. One of them, the pmic clk, is only enabled in case 'mediatek,have-pmic' is also set which has other consequences which are not desired in this case.

Allow defining a pmic clk even in case the 'mediatek,have-pmic' propterty is not present and the bus is not used to connect to a pmic, but may still require to enable the pmic clock.

Applied to for-next, thanks!