linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: mt65xx: allow optional pmic clock
@ 2023-08-27  2:13 Daniel Golle
  2023-09-02 23:49 ` Andi Shyti
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Daniel Golle @ 2023-08-27  2:13 UTC (permalink / raw)
  To: Qii Wang, Andi Shyti, Matthias Brugger,
	AngeloGioacchino Del Regno, linux-i2c, linux-kernel,
	linux-arm-kernel, linux-mediatek
  Cc: 郭小桥

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.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
 drivers/i2c/busses/i2c-mt65xx.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c
index 1a9b5a068ef1b..a8b5719c33729 100644
--- a/drivers/i2c/busses/i2c-mt65xx.c
+++ b/drivers/i2c/busses/i2c-mt65xx.c
@@ -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;
 	}
 
-- 
2.41.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] i2c: mt65xx: allow optional pmic clock
  2023-08-27  2:13 [PATCH] i2c: mt65xx: allow optional pmic clock Daniel Golle
@ 2023-09-02 23:49 ` Andi Shyti
  2023-09-13 14:00 ` AngeloGioacchino Del Regno
  2023-09-19 20:00 ` Wolfram Sang
  2 siblings, 0 replies; 7+ messages in thread
From: Andi Shyti @ 2023-09-02 23:49 UTC (permalink / raw)
  To: Daniel Golle
  Cc: Qii Wang, Matthias Brugger, AngeloGioacchino Del Regno, linux-i2c,
	linux-kernel, linux-arm-kernel, linux-mediatek,
	郭小桥

Hi Daniel,

On Sun, Aug 27, 2023 at 03:13:30AM +0100, Daniel Golle wrote:
> 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.
> 
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> ---
>  drivers/i2c/busses/i2c-mt65xx.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c
> index 1a9b5a068ef1b..a8b5719c33729 100644
> --- a/drivers/i2c/busses/i2c-mt65xx.c
> +++ b/drivers/i2c/busses/i2c-mt65xx.c
> @@ -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:

Reviewed-by: Andi Shyti <andi.shyti@kernel.org> 

Andi

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] i2c: mt65xx: allow optional pmic clock
  2023-08-27  2:13 [PATCH] i2c: mt65xx: allow optional pmic clock Daniel Golle
  2023-09-02 23:49 ` Andi Shyti
@ 2023-09-13 14:00 ` AngeloGioacchino Del Regno
  2023-09-14  9:07   ` Daniel Golle
  2025-08-07  5:42   ` 回复: " Qii Wang (王琪)
  2023-09-19 20:00 ` Wolfram Sang
  2 siblings, 2 replies; 7+ messages in thread
From: AngeloGioacchino Del Regno @ 2023-09-13 14:00 UTC (permalink / raw)
  To: Daniel Golle, Qii Wang, Andi Shyti, Matthias Brugger, linux-i2c,
	linux-kernel, linux-arm-kernel, linux-mediatek
  Cc: 郭小桥

Il 27/08/23 04:13, Daniel Golle ha scritto:
> 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.
> 
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> ---
>   drivers/i2c/busses/i2c-mt65xx.c | 12 ++++++++----
>   1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c
> index 1a9b5a068ef1b..a8b5719c33729 100644
> --- a/drivers/i2c/busses/i2c-mt65xx.c
> +++ b/drivers/i2c/busses/i2c-mt65xx.c
> @@ -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

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



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] i2c: mt65xx: allow optional pmic clock
  2023-09-13 14:00 ` AngeloGioacchino Del Regno
@ 2023-09-14  9:07   ` Daniel Golle
  2023-09-14  9:37     ` AngeloGioacchino Del Regno
  2025-08-07  5:42   ` 回复: " Qii Wang (王琪)
  1 sibling, 1 reply; 7+ messages in thread
From: Daniel Golle @ 2023-09-14  9:07 UTC (permalink / raw)
  To: AngeloGioacchino Del Regno
  Cc: Qii Wang, Andi Shyti, Matthias Brugger, linux-i2c, linux-kernel,
	linux-arm-kernel, linux-mediatek, 郭小桥

On Wed, Sep 13, 2023 at 04:00:53PM +0200, AngeloGioacchino Del Regno wrote:
> Il 27/08/23 04:13, Daniel Golle ha scritto:
> > 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.
> > 
> > Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> > ---
> >   drivers/i2c/busses/i2c-mt65xx.c | 12 ++++++++----
> >   1 file changed, 8 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c
> > index 1a9b5a068ef1b..a8b5719c33729 100644
> > --- a/drivers/i2c/busses/i2c-mt65xx.c
> > +++ b/drivers/i2c/busses/i2c-mt65xx.c
> > @@ -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?

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.

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] i2c: mt65xx: allow optional pmic clock
  2023-09-14  9:07   ` Daniel Golle
@ 2023-09-14  9:37     ` AngeloGioacchino Del Regno
  0 siblings, 0 replies; 7+ messages in thread
From: AngeloGioacchino Del Regno @ 2023-09-14  9:37 UTC (permalink / raw)
  To: Daniel Golle
  Cc: Qii Wang, Andi Shyti, Matthias Brugger, linux-i2c, linux-kernel,
	linux-arm-kernel, linux-mediatek, 郭小桥

Il 14/09/23 11:07, Daniel Golle ha scritto:
> On Wed, Sep 13, 2023 at 04:00:53PM +0200, AngeloGioacchino Del Regno wrote:
>> Il 27/08/23 04:13, Daniel Golle ha scritto:
>>> 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.
>>>
>>> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
>>> ---
>>>    drivers/i2c/busses/i2c-mt65xx.c | 12 ++++++++----
>>>    1 file changed, 8 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c
>>> index 1a9b5a068ef1b..a8b5719c33729 100644
>>> --- a/drivers/i2c/busses/i2c-mt65xx.c
>>> +++ b/drivers/i2c/busses/i2c-mt65xx.c
>>> @@ -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?
> 
> 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.

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] i2c: mt65xx: allow optional pmic clock
  2023-08-27  2:13 [PATCH] i2c: mt65xx: allow optional pmic clock Daniel Golle
  2023-09-02 23:49 ` Andi Shyti
  2023-09-13 14:00 ` AngeloGioacchino Del Regno
@ 2023-09-19 20:00 ` Wolfram Sang
  2 siblings, 0 replies; 7+ messages in thread
From: Wolfram Sang @ 2023-09-19 20:00 UTC (permalink / raw)
  To: Daniel Golle
  Cc: Qii Wang, Andi Shyti, Matthias Brugger,
	AngeloGioacchino Del Regno, linux-i2c, linux-kernel,
	linux-arm-kernel, linux-mediatek, 郭小桥

[-- Attachment #1: Type: text/plain, Size: 594 bytes --]

On Sun, Aug 27, 2023 at 03:13:30AM +0100, Daniel Golle wrote:
> 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.
> 
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>

Applied to for-next, thanks!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* 回复: [PATCH] i2c: mt65xx: allow optional pmic clock
  2023-09-13 14:00 ` AngeloGioacchino Del Regno
  2023-09-14  9:07   ` Daniel Golle
@ 2025-08-07  5:42   ` Qii Wang (王琪)
  1 sibling, 0 replies; 7+ messages in thread
From: Qii Wang (王琪) @ 2025-08-07  5:42 UTC (permalink / raw)
  To: AngeloGioacchino Del Regno, Daniel Golle, Andi Shyti,
	Matthias Brugger, linux-i2c@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org,
	Kewei Xu (许克伟),
	Shunchang Wang (王舜昌)
  Cc: 郭小桥

Add kewei and shunchang.

-----邮件原件-----
发件人: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> 
发送时间: 2023年9月13日 22:01
收件人: Daniel Golle <daniel@makrotopia.org>; Qii Wang (王琪) <Qii.Wang@mediatek.com>; Andi Shyti <andi.shyti@kernel.org>; Matthias Brugger <matthias.bgg@gmail.com>; linux-i2c@vger.kernel.org; linux-kernel@vger.kernel.org; linux-arm-kernel@lists.infradead.org; linux-mediatek@lists.infradead.org
抄送: 郭小桥 <joe@gainstrong.cn>
主题: Re: [PATCH] i2c: mt65xx: allow optional pmic clock

Il 27/08/23 04:13, Daniel Golle ha scritto:
> 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.
> 
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> ---
>   drivers/i2c/busses/i2c-mt65xx.c | 12 ++++++++----
>   1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-mt65xx.c 
> b/drivers/i2c/busses/i2c-mt65xx.c index 1a9b5a068ef1b..a8b5719c33729 
> 100644
> --- a/drivers/i2c/busses/i2c-mt65xx.c
> +++ b/drivers/i2c/busses/i2c-mt65xx.c
> @@ -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

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



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-08-07  5:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-27  2:13 [PATCH] i2c: mt65xx: allow optional pmic clock Daniel Golle
2023-09-02 23:49 ` Andi Shyti
2023-09-13 14:00 ` AngeloGioacchino Del Regno
2023-09-14  9:07   ` Daniel Golle
2023-09-14  9:37     ` AngeloGioacchino Del Regno
2025-08-07  5:42   ` 回复: " Qii Wang (王琪)
2023-09-19 20:00 ` Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).