mbox series

[v3,0/3] Add the clock stretching i2c property

Message ID 20230312233613.303408-1-andi.shyti@kernel.org
Headers show
Series Add the clock stretching i2c property | expand

Message

Andi Shyti March 12, 2023, 11:36 p.m. UTC
Hello,

fter a discussion between Krzysztof and Ryan[1], it has become
apparent that the i2c binding is lacking the definition of a
property that needs to be added at a more generic level. This
property is also used by the mpc i2c controller, which has been
updated in the second patch.

The DTS schema change has been sent as github pull reqest[2].

Thanks Krzysztof and Chris for the reviews.

Thank you,
Andi

[1] https://lore.kernel.org/all/c41ee6b5-ddb4-1253-de54-a295b3bab2cc@linaro.org/
[2] https://github.com/devicetree-org/dt-schema/pull/102

Changelog
=========
v2 -> v3:
 - Chris recommended to use of_property_read_u32() instead of
   of_get_property(). Because there were two use of it I added
   the suggested cleanup in a separate patch.
 - Added Chris r-b in patch 3.

v1 -> v2:
 - Removed the binding patch and send through a different channel
 - To ensure back compatibility, which was broken in v1, the
   legacy "fsl,timeout" has not been removed and marked as
   deprecated. In the driver the that property is checked anyway
   as a fallback in case the main i2c-scl-clk-low-timeout-ms is
   missing.

Andi Shyti (3):
  dt-bindings: i2c: mpc: Mark "fsl,timeout" as deprecated
  i2c: mpc: Use of_property_read_u32 instead of of_get_property
  i2c: mpc: Use i2c-scl-clk-low-timeout-ms i2c property

 .../devicetree/bindings/i2c/i2c-mpc.yaml      |  3 +-
 drivers/i2c/busses/i2c-mpc.c                  | 35 ++++++++++++-------
 2 files changed, 25 insertions(+), 13 deletions(-)

Comments

Krzysztof Kozlowski March 14, 2023, 2:19 p.m. UTC | #1
On 14/03/2023 15:10, Rob Herring wrote:
> 
> On Mon, 13 Mar 2023 00:36:11 +0100, Andi Shyti wrote:
>> Now we have the i2c-scl-clk-low-timeout-ms property defined in
>> the i2c schema.
>>
>> Mark "fsl,timeout" as deprecated and update the example.
>>
>> Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
>> ---
>>  Documentation/devicetree/bindings/i2c/i2c-mpc.yaml | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
> 
> My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
> on your patch (DT_CHECKER_FLAGS is new in v5.13):
> 
> yamllint warnings/errors:
> 
> dtschema/dtc warnings/errors:
> /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/i2c/i2c-mpc.example.dtb: i2c@3100: Unevaluated properties are not allowed ('i2c-scl-clk-low-timeout-ms' was unexpected)

That's expected as it depends on:
https://github.com/devicetree-org/dt-schema/pull/102

Best regards,
Krzysztof
Krzysztof Kozlowski March 14, 2023, 2:22 p.m. UTC | #2
On 13/03/2023 00:36, Andi Shyti wrote:
> "fsl,timeout" is marked as deprecated and replaced by the
> "i2c-scl-clk-low-timeout-ms" i2c property.
> 
> Use this latter and, in case it is missing, for back
> compatibility, check whether we still have "fsl,timeout" defined.
> 
> Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
> Reviewed-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> ---
>  drivers/i2c/busses/i2c-mpc.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
> index 87e5c1725750..28f11e30ac50 100644
> --- a/drivers/i2c/busses/i2c-mpc.c
> +++ b/drivers/i2c/busses/i2c-mpc.c
> @@ -843,8 +843,18 @@ static int fsl_i2c_probe(struct platform_device *op)
>  			mpc_i2c_setup_8xxx(op->dev.of_node, i2c, clock);
>  	}
>  
> +	/*
> +	 * "fsl,timeout" has been marked as deprecated and, to maintain
> +	 * backward compatibility, we will only look for it if
> +	 * "i2c-scl-clk-low-timeout-ms" is not present.
> +	 */
>  	result = of_property_read_u32(op->dev.of_node,
> -				      "fsl,timeout", &mpc_ops.timeout);
> +				      "i2c-scl-clk-low-timeout-ms",
> +				      &mpc_ops.timeout);
> +	if (result == -EINVAL)
> +		result = of_property_read_u32(op->dev.of_node,
> +					      "fsl,timeout", &mpc_ops.timeout);

Wasn't old property in us and new one is in ms?

Best regards,
Krzysztof
Andi Shyti March 14, 2023, 2:36 p.m. UTC | #3
On Tue, Mar 14, 2023 at 03:22:19PM +0100, Krzysztof Kozlowski wrote:
> On 14/03/2023 15:21, Krzysztof Kozlowski wrote:
> > On 13/03/2023 00:36, Andi Shyti wrote:
> >> Now we have the i2c-scl-clk-low-timeout-ms property defined in
> >> the i2c schema.
> >>
> >> Mark "fsl,timeout" as deprecated and update the example.
> >>
> >> Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
> >> ---
> >>  Documentation/devicetree/bindings/i2c/i2c-mpc.yaml | 3 ++-
> >>  1 file changed, 2 insertions(+), 1 deletion(-)
> >>
> > 
> > Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> 
> ...
> 
> and unreviewed. Are you sure these are using same units? Old code used us.
> 
> Your example:
> 	i2c-scl-clk-low-timeout-ms = <10000>;
> 
> 10s timeout?

ops!

I will keep it ms, if anyone doesn't have anything against. The
clock stretching goes in order of milliseconds and in any case
doesn't need to be precisely that, as long as it's longer.

I don't see any need for it to be us... if it 12500us, let it be
13ms.

I will update the example.

Can I keep your r-b with:

	i2c-scl-clk-low-timeout-ms = <10>;

?

Thanks for noticing it, it would have been a wacky mistake,
Andi
Andi Shyti March 14, 2023, 8:48 p.m. UTC | #4
Hi Chris,

> >>> "fsl,timeout" is marked as deprecated and replaced by the
> >>> "i2c-scl-clk-low-timeout-ms" i2c property.
> >>>
> >>> Use this latter and, in case it is missing, for back
> >>> compatibility, check whether we still have "fsl,timeout" defined.
> >>>
> >>> Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
> >>> Reviewed-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> >>> ---
> >>>   drivers/i2c/busses/i2c-mpc.c | 12 +++++++++++-
> >>>   1 file changed, 11 insertions(+), 1 deletion(-)
> >>>
> >>> diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
> >>> index 87e5c1725750..28f11e30ac50 100644
> >>> --- a/drivers/i2c/busses/i2c-mpc.c
> >>> +++ b/drivers/i2c/busses/i2c-mpc.c
> >>> @@ -843,8 +843,18 @@ static int fsl_i2c_probe(struct platform_device *op)
> >>>   			mpc_i2c_setup_8xxx(op->dev.of_node, i2c, clock);
> >>>   	}
> >>>   
> >>> +	/*
> >>> +	 * "fsl,timeout" has been marked as deprecated and, to maintain
> >>> +	 * backward compatibility, we will only look for it if
> >>> +	 * "i2c-scl-clk-low-timeout-ms" is not present.
> >>> +	 */
> >>>   	result = of_property_read_u32(op->dev.of_node,
> >>> -				      "fsl,timeout", &mpc_ops.timeout);
> >>> +				      "i2c-scl-clk-low-timeout-ms",
> >>> +				      &mpc_ops.timeout);
> >>> +	if (result == -EINVAL)
> >>> +		result = of_property_read_u32(op->dev.of_node,
> >>> +					      "fsl,timeout", &mpc_ops.timeout);
> >> Wasn't old property in us and new one is in ms?
> > Thanks, Krzysztof! Good catch!
> >
> > Chris, you are the only user of this property, as of now. Is it
> > OK if we keep it ms? I will send a proper patch to do the
> > conversion.
> >
> > To me it doesn't make much sense to have the timeout defined in
> > us as that's of the same order of the raising and falling time
> > of the clock. Any opinion?

> I think it'd be easier to stick to us as then the same code can be used 
> to probe both the old property and the new one. However I won't object 
> if you adjust for the us to ms conversion between handling the new 
> property vs the old one.

yeah... indeed it became quite ugly.

OK, I will just rename it from "i2c-scl-clk-low-timeout-ms" to
"i2c-scl-clk-low-timeout-us", respin the schema pull request and
leave everything as it is.

Thanks for your input, Chris!

Andi