2023-08-27 03:58:03

by Daniel Golle

[permalink] [raw]
Subject: [PATCH] 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.

Signed-off-by: Daniel Golle <[email protected]>
---
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


2023-09-03 13:42:38

by Andi Shyti

[permalink] [raw]
Subject: Re: [PATCH] i2c: mt65xx: allow optional pmic clock

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 <[email protected]>
> ---
> 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 <[email protected]>

Andi

Subject: 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 <[email protected]>
> ---
> 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;
> }
>


2023-09-14 09:22:50

by Daniel Golle

[permalink] [raw]
Subject: Re: [PATCH] i2c: mt65xx: allow optional pmic clock

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 <[email protected]>
> > ---
> > 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;
> > }
>
>

Subject: Re: [PATCH] i2c: mt65xx: allow optional pmic clock

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 <[email protected]>
>>> ---
>>> 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 <[email protected]>


2023-09-19 20:03:23

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH] i2c: mt65xx: allow optional pmic clock

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 <[email protected]>

Applied to for-next, thanks!


Attachments:
(No filename) (594.00 B)
signature.asc (849.00 B)
Download all attachments