2024-02-15 16:54:38

by Théo Lebrun

[permalink] [raw]
Subject: [PATCH 09/13] i2c: nomadik: fetch timeout-usecs property from devicetree

Allow overriding the default timeout value (200ms) from devicetree,
using the timeout-usecs property.

The i2c_adapter->timeout field is an unaccurate jiffies amount;
i2c-nomadik uses hrtimers for timeouts below one jiffy.

Signed-off-by: Théo Lebrun <[email protected]>
---
drivers/i2c/busses/i2c-nomadik.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index afd54999bbbb..23e12c570457 100644
--- a/drivers/i2c/busses/i2c-nomadik.c
+++ b/drivers/i2c/busses/i2c-nomadik.c
@@ -964,6 +964,8 @@ static const struct i2c_algorithm nmk_i2c_algo = {
static void nmk_i2c_of_probe(struct device_node *np,
struct nmk_i2c_dev *priv)
{
+ u32 timeout_usecs;
+
/* Default to 100 kHz if no frequency is given in the node */
if (of_property_read_u32(np, "clock-frequency", &priv->clk_freq))
priv->clk_freq = I2C_MAX_STANDARD_MODE_FREQ;
@@ -975,7 +977,12 @@ static void nmk_i2c_of_probe(struct device_node *np,
priv->sm = I2C_FREQ_MODE_FAST;
priv->tft = 1; /* Tx FIFO threshold */
priv->rft = 8; /* Rx FIFO threshold */
- priv->timeout_usecs = 200 * USEC_PER_MSEC; /* Slave response timeout */
+
+ /* Slave response timeout */
+ if (!of_property_read_u32(np, "timeout-usecs", &timeout_usecs))
+ priv->timeout_usecs = timeout_usecs;
+ else
+ priv->timeout_usecs = 200 * USEC_PER_MSEC;
}

static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)

--
2.43.1



2024-02-19 14:23:11

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH 09/13] i2c: nomadik: fetch timeout-usecs property from devicetree

On Thu, Feb 15, 2024 at 5:52 PM Théo Lebrun <[email protected]> wrote:

> Allow overriding the default timeout value (200ms) from devicetree,
> using the timeout-usecs property.
>
> The i2c_adapter->timeout field is an unaccurate jiffies amount;
> i2c-nomadik uses hrtimers for timeouts below one jiffy.
>
> Signed-off-by: Théo Lebrun <[email protected]>

Once we agree on the binding name:

Reviewed-by: Linus Walleij <[email protected]>

Yours,
Linus Walleij

2024-02-27 12:20:12

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH 09/13] i2c: nomadik: fetch timeout-usecs property from devicetree


> + /* Slave response timeout */
> + if (!of_property_read_u32(np, "timeout-usecs", &timeout_usecs))
> + priv->timeout_usecs = timeout_usecs;
> + else
> + priv->timeout_usecs = 200 * USEC_PER_MSEC;

I could imagine to add 'transfer_timeout_us' to struct i2c_timings.
Then, you could use 'i2c_parse_fw_timings' to obtain the value. What
values/value range do you use here? I can't find them in the DTS
additions.


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

2024-02-27 13:40:18

by Théo Lebrun

[permalink] [raw]
Subject: Re: [PATCH 09/13] i2c: nomadik: fetch timeout-usecs property from devicetree

Hello,

On Tue Feb 27, 2024 at 1:14 PM CET, Wolfram Sang wrote:
> > + /* Slave response timeout */
> > + if (!of_property_read_u32(np, "timeout-usecs", &timeout_usecs))
> > + priv->timeout_usecs = timeout_usecs;
> > + else
> > + priv->timeout_usecs = 200 * USEC_PER_MSEC;
>
> I could imagine to add 'transfer_timeout_us' to struct i2c_timings.
> Then, you could use 'i2c_parse_fw_timings' to obtain the value. What
> values/value range do you use here? I can't find them in the DTS
> additions.

That sounds good. I have not used this prop in the DTS as it does not
make much sense for an eval board. The target is production boards.

An order of magnitude is a few transfers every 15ms. It means a timeout
of 15ms divided by "a few". I don't have more precise values, but I
could if you consider it useful.

I've done some testing at 50~100µs timeouts and it works as expected. At
those values timerslack is important to consider (default of 50µs).
This is at 400kHz clock frequency. Keep in mind the controllers support
up to 3.4MHz (not yet upstreamed) so timeouts could in theory go
lower if required by the usecase.

My upcoming question is how to move forward on this series. I can do the
patch to i2c_parse_fw_timings() in the next revision. That way it gets
added alongside the first user of this feature. Would it work for you?

Thanks,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com


2024-02-28 10:49:39

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH 09/13] i2c: nomadik: fetch timeout-usecs property from devicetree

Hi Théo,

> That sounds good. I have not used this prop in the DTS as it does not
> make much sense for an eval board. The target is production boards.

...

> My upcoming question is how to move forward on this series. I can do the
> patch to i2c_parse_fw_timings() in the next revision. That way it gets
> added alongside the first user of this feature. Would it work for you?

Hmmm, to be honest I have a bit of an issue with the 'no user' problem.
There is a driver which uses this feature, okay. But there is no
upstream hardware which uses this driver with this new feature. This
makes maintaining harder ("Who uses this feature?" - "Someone" - "How do
they use it? Can we modify it?" - "Dunno").

Kind regards,

Wolfram


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

2024-02-28 13:51:04

by Théo Lebrun

[permalink] [raw]
Subject: Re: [PATCH 09/13] i2c: nomadik: fetch timeout-usecs property from devicetree

Hello Wolfram,

On Wed Feb 28, 2024 at 11:49 AM CET, Wolfram Sang wrote:
> > That sounds good. I have not used this prop in the DTS as it does not
> > make much sense for an eval board. The target is production boards.
>
> ...
>
> > My upcoming question is how to move forward on this series. I can do the
> > patch to i2c_parse_fw_timings() in the next revision. That way it gets
> > added alongside the first user of this feature. Would it work for you?
>
> Hmmm, to be honest I have a bit of an issue with the 'no user' problem.
> There is a driver which uses this feature, okay. But there is no
> upstream hardware which uses this driver with this new feature. This
> makes maintaining harder ("Who uses this feature?" - "Someone" - "How do
> they use it? Can we modify it?" - "Dunno").

The alternative is that I keep going with a new revision of i2c-nomadik
that manually parses the prop. It'll be refactored if/when the I2C core
provides a better way to access the value. Is that OK?

Thanks,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com


2024-02-29 09:25:52

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH 09/13] i2c: nomadik: fetch timeout-usecs property from devicetree


> The alternative is that I keep going with a new revision of i2c-nomadik
> that manually parses the prop. It'll be refactored if/when the I2C core
> provides a better way to access the value. Is that OK?

That wouldn't have helped because there is still no user in-kernel of
that property, i.e. no DTS file with that property. But I just realized
that I need to convert i2c-mpc to avoid a deprecated binding, so we have
a user there. Lucky you ;)

I'll try to get the series done today.


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

2024-02-29 09:42:23

by Théo Lebrun

[permalink] [raw]
Subject: Re: [PATCH 09/13] i2c: nomadik: fetch timeout-usecs property from devicetree

Hello,

On Thu Feb 29, 2024 at 10:25 AM CET, Wolfram Sang wrote:
> > The alternative is that I keep going with a new revision of i2c-nomadik
> > that manually parses the prop. It'll be refactored if/when the I2C core
> > provides a better way to access the value. Is that OK?
>
> That wouldn't have helped because there is still no user in-kernel of
> that property, i.e. no DTS file with that property. But I just realized
> that I need to convert i2c-mpc to avoid a deprecated binding, so we have
> a user there. Lucky you ;)
>
> I'll try to get the series done today.

Lucky me indeed!

I just thought about it but I don't mind using the property in the eval
board DTS. The default 200ms timeout makes no sense for us. Using a
default of a few ms would be more sensible and make us the second user
of the prop.

Thanks,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com