iio: adc: ti-ads1015: support deferred probe
PATCH 1/1 iio: adc: ti-ads1015: support deferred probe
Support deferred probe for cases where communication on i2c bus fails. These failures could happen for a variety of reasons including bus arbitration error or power failure.
--- drivers/iio/adc/ti-ads1015.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/iio/adc/ti-ads1015.c +7 -2
@@ -1062,7 +1062,7 @@ static int ads1015_probe(struct i2c_client *client) ret =regmap_update_bits (data->regmap,ADS1015_CFG_REG , cfg_comp_mask, cfg_comp);if (ret) -return ret; + goto out; ret = devm_request_threaded_irq(&client->dev, client->irq, NULL, ads1015_event_handler,
@@ -1074,7 +1074,7 @@ static int ads1015_probe(struct i2c_client *client) ret =ads1015_set_conv_mode (data,ADS1015_CONTINUOUS );if (ret) -return ret; + goto out; data->conv_invalid = true;
@@ -1092,6 +1092,11 @@ static int ads1015_probe(struct i2c_client *client) }return 0 ; + +out: +if ((ret == -EAGAIN ) || (ret == -ENXIO )) +return -EPROBE_DEFER ; +return ret; }static void ads1015_remove (struct i2c_client *client)
Signature · 1 line
2.39.2
drivers/iio/adc/ti-ads1015.c static int ads1015_probe(struct i2c_client *client) · line 1099
Quoted 8 lines · Tomas Melin
Support deferred probe for cases where communication on i2c bus fails. These failures could happen for a variety of reasons including bus arbitration error or power failure.
drivers/iio/adc/ti-ads1015.c +4
-0+out: +if ((ret == -EAGAIN ) || (ret == -ENXIO )) +return -EPROBE_DEFER ; +return ret;
Oh my... This looks so-o hackish.
If anything, it has to be fixed on the level of regmap I2C APIs or so.
Maybe something like regmap_i2c_try_write()/try_read() new APIs that will provide the above. Otherwise you want to fix _every single driver_ in the Linux kernel
...
$ git grep -lw builtin_i2c_driver | wc
5 5 123
$ git grep -lw module_i2c_driver | wc
1164 1164 35240(and more that don't use either of the above macros).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 11 lines · On Mon, 4 Sep 2023 14:23:29 +0300 Andy Shevchenko…
drivers/iio/adc/ti-ads1015.c static int ads1015_probe(struct i2c_client *client) · line 1099
Quoted 8 lines · Tomas Melin
Support deferred probe for cases where communication on i2c bus fails. These failures could happen for a variety of reasons including bus arbitration error or power failure.
drivers/iio/adc/ti-ads1015.c +4
-0+out: +if ((ret == -EAGAIN ) || (ret == -ENXIO )) +return -EPROBE_DEFER ; +return ret;Oh my... This looks so-o hackish.
Agreed. This is a non starter.
Quoted 5 lines
If anything, it has to be fixed on the level of regmap I2C APIs or so.
Maybe something like regmap_i2c_try_write()/try_read() new APIs that will provide the above. Otherwise you want to fix
_everysingledriver_in the Linux kernel
Any probe ordering dependencies should be described by the firmware and the driver should 'get' the relevant resource. If there is anything not describable today then that is what we need to fix, not paper over the holes.
So can we have specifics of what is happening here?
If it's arbitration with some other entity then fix the arbitration locking / hand over. If it's power, then make sure the relevant regulator get gotten and turned on + has the right delays etc.
Jonathan
Quoted 10 lines
...
$ git grep -lw builtin_i2c_driver | wc 5 5 123 $ git grep -lw module_i2c_driver | wc 1164 1164 35240(and more that don't use either of the above macros).
Hi,
Quoted 28 lines · Jonathan Cameron
Quoted 11 lines · On Mon, 4 Sep 2023 14:23:29 +0300 Andy Shevchenko…
drivers/iio/adc/ti-ads1015.c static int ads1015_probe(struct i2c_client *client) · line 1099
Quoted 8 lines · Tomas Melin
Support deferred probe for cases where communication on i2c bus fails. These failures could happen for a variety of reasons including bus arbitration error or power failure.
drivers/iio/adc/ti-ads1015.c +4
-0+out: +if ((ret == -EAGAIN ) || (ret == -ENXIO )) +return -EPROBE_DEFER ; +return ret;Oh my... This looks so-o hackish.
Agreed. This is a non starter.
Quoted 5 lines
If anything, it has to be fixed on the level of regmap I2C APIs or so.
Maybe something like regmap_i2c_try_write()/try_read() new APIs that will provide the above. Otherwise you want to fix
_everysingledriver_in the Linux kernelAny probe ordering dependencies should be described by the firmware and the driver should 'get' the relevant resource. If there is anything not describable today then that is what we need to fix, not paper over the holes
Quoted 5 lines
So can we have specifics of what is happening here?
If it's arbitration with some other entity then fix the arbitration locking / hand over. If it's power, then make sure the relevant regulator get gotten and turned on + has the right delays etc.
Yes, right. In this use case, the ads1015 is connected to a channel of a i2c multiplexer. When the mux is probed, it also enumerates all the multiplexed buses and probes devices connected to them.
For some reason, it behaves so that the ads1015 is not detected on the first attempt. Since it's a mux, connected to main i2c line, perhaps there really is some bus arbitration issue, or then something else.
Anyways, when deferring the probe for the ads1015, and attempting later again it probes fine.
So, it might be I've taken the wrong angle at this issue, but it does solve the issue at hand. Obviously, there could be some issue with the i2c mux driver, or then on hardware level too.
Point is, that if the communication to the i2c bus has some temporary error like EAGAIN, why could it not be reasonable to try again at a later time instead of giving up completely.
Thanks,
Tomas
Quoted 14 lines
Jonathan
Quoted 10 lines
...
$ git grep -lw builtin_i2c_driver | wc 5 5 123 $ git grep -lw module_i2c_driver | wc 1164 1164 35240(and more that don't use either of the above macros).
Quoted 42 lines · Tomas Melin
Hi,
Quoted 24 lines · Jonathan Cameron
Quoted 9 lines · On Mon, 4 Sep 2023 14:23:29 +0300 Andy Shevchenko…
drivers/iio/adc/ti-ads1015.c static int ads1015_probe(struct i2c_client *client) · line 1099
Quoted 7 lines · Tomas Melin
Support deferred probe for cases where communication on i2c bus fails. These failures could happen for a variety of reasons including bus arbitration error or power failure.
drivers/iio/adc/ti-ads1015.c +4
-0+out: +if ((ret == -EAGAIN ) || (ret == -ENXIO )) +return -EPROBE_DEFER ; +return ret;Oh my... This looks so-o hackish.
Agreed. This is a non starter.
Quoted 5 lines
If anything, it has to be fixed on the level of regmap I2C APIs or so.
Maybe something like regmap_i2c_try_write()/try_read() new APIs that will provide the above. Otherwise you want to fix
_everysingledriver_in the Linux kernelAny probe ordering dependencies should be described by the firmware and the driver should 'get' the relevant resource. If there is anything not describable today then that is what we need to fix, not paper over the holes
Quoted 5 lines
So can we have specifics of what is happening here?
If it's arbitration with some other entity then fix the arbitration locking / hand over. If it's power, then make sure the relevant regulator get gotten and turned on + has the right delays etc.
Yes, right. In this use case, the ads1015 is connected to a channel of a i2c multiplexer. When the mux is probed, it also enumerates all the multiplexed buses and probes devices connected to them.
For some reason, it behaves so that the ads1015 is not detected on the first attempt. Since it's a mux, connected to main i2c line, perhaps there really is some bus arbitration issue, or then something else.Anyways, when deferring the probe for the ads1015, and attempting later again it probes fine.
Quoted 7 lines
So, it might be I've taken the wrong angle at this issue, but it does solve the issue at hand. Obviously, there could be some issue with the i2c mux driver, or then on hardware level too.
Point is, that if the communication to the i2c bus has some temporary error like EAGAIN, why could it not be reasonable to try again at a later time instead of giving up completely.
The way probe deferral works, or is supposed to work, is that if a driver detects that it is missing a resource to initialize the device it can return EPROBE_DEFER to try again later. Once a new resource becomes available it will try again. In your case there is no resource dependency, but just a random failure. So there is no guarantee that probe will actually be called again since there might not be any new resources that become available.
The solution you've implemented might work on your specific platform, but it does not work by design, it only works by chance. Returning EPROBE_DEFER for things like IO errors is not the right approach. If you need a quick hack you can for example write a small userspace script that will trigger re-probe of the device at system startup.
Quoted 15 lines · Lars-Peter Clausen
Quoted 5 lines · Tomas Melin
Hi,
Point is, that if the communication to the i2c bus has some temporary error like EAGAIN, why could it not be reasonable to try again at a later time instead of giving up completely.
The way probe deferral works, or is supposed to work, is that if a driver detects that it is missing a resource to initialize the device it can return
EPROBE_DEFERto try again later. Once a new resource becomes available it will try again. In your case there is no resource dependency, but just a random failure. So there is no guarantee that probe will actually be called again since there might not be any new resources that become available.
Quoted 5 lines
The solution you've implemented might work on your specific platform, but it does not work by design, it only works by chance. Returning
EPROBE_DEFERfor things like IO errors is not the right approach. If you need a quick hack you can for example write a small userspace script that will trigger re-probe of the device at system startup.
Right, I will need to take a different approach with this. Thanks for the input!
Tomas
Quoted 2 lines
+Cc: Peter to look from the i2c mux point of view on the issue.
Quoted 8 lines · Tomas Melin
Quoted 7 lines · Jonathan Cameron
Quoted 5 lines · On Mon, 4 Sep 2023 14:23:29 +0300 Andy Shevchenko…
Quoted 3 lines · Tomas Melin
Support deferred probe for cases where communication on i2c bus fails. These failures could happen for a variety of reasons including bus arbitration error or power failure.
...
Quoted 43 lines
Quoted 20 lines
Quoted 6 lines
drivers/iio/adc/ti-ads1015.c static int ads1015_probe(struct i2c_client *client) · line 1099
Quoted 4 lines
drivers/iio/adc/ti-ads1015.c +4
-0+out: +if ((ret == -EAGAIN ) || (ret == -ENXIO )) +return -EPROBE_DEFER ; +return ret;Oh my... This looks so-o hackish.
Agreed. This is a non starter.
Quoted 5 lines
If anything, it has to be fixed on the level of regmap I2C APIs or so.
Maybe something like regmap_i2c_try_write()/try_read() new APIs that will provide the above. Otherwise you want to fix
_everysingledriver_in the Linux kernelAny probe ordering dependencies should be described by the firmware and the driver should 'get' the relevant resource. If there is anything not describable today then that is what we need to fix, not paper over the holes
Quoted 5 lines
So can we have specifics of what is happening here?
If it's arbitration with some other entity then fix the arbitration locking / hand over. If it's power, then make sure the relevant regulator get gotten and turned on + has the right delays etc.
Yes, right. In this use case, the ads1015 is connected to a channel of a i2c multiplexer. When the mux is probed, it also enumerates all the multiplexed buses and probes devices connected to them.
For some reason, it behaves so that the ads1015 is not detected on the first attempt. Since it's a mux, connected to main i2c line, perhaps there really is some bus arbitration issue, or then something else.Anyways, when deferring the probe for the ads1015, and attempting later again it probes fine.
So, it might be I've taken the wrong angle at this issue, but it does solve the issue at hand. Obviously, there could be some issue with the i2c mux driver, or then on hardware level too.
Point is, that if the communication to the i2c bus has some temporary error like EAGAIN, why could it not be reasonable to try again at a later time instead of giving up completely.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
Quoted 11 lines · Andy Shevchenko
drivers/iio/adc/ti-ads1015.c static int ads1015_probe(struct i2c_client *client) · line 1099
Quoted 8 lines · Tomas Melin
Support deferred probe for cases where communication on i2c bus fails. These failures could happen for a variety of reasons including bus arbitration error or power failure.
drivers/iio/adc/ti-ads1015.c +4
-0+out: +if ((ret == -EAGAIN ) || (ret == -ENXIO )) +return -EPROBE_DEFER ; +return ret;Oh my... This looks so-o hackish.> If anything, it has to be fixed on the level of regmap I2C APIs or
so.As such this does fix a real world issue. Providing some helpers for this on regmap level would probably be great. To add such an API I suspect there should first be existing users for it, and this would be one example.
Until there would be such an generic API, I'm not sure if there are many other alternatives than to check for invalid returns and defer the probe.
Thanks,
Tomas
Quoted 13 lines
Maybe something like regmap_i2c_try_write()/try_read() new APIs that will provide the above. Otherwise you want to fix
_everysingledriver_in the Linux kern>
...$ git grep -lw builtin_i2c_driver | wc 5 5 123 $ git grep -lw module_i2c_driver | wc 1164 1164 35240(and more that don't use either of the above macros).
Quoted 2 lines · Tomas Melin
Quoted 1 line · Andy Shevchenko
On Mon, Sep 04, 2023 at 01:15:22PM +0300, Tomas Melin wrote:
...
Quoted 6 lines
Quoted 6 lines
drivers/iio/adc/ti-ads1015.c static int ads1015_probe(struct i2c_client *client) · line 1099
Quoted 4 lines
drivers/iio/adc/ti-ads1015.c +4
-0+out: +if ((ret == -EAGAIN ) || (ret == -ENXIO )) +return -EPROBE_DEFER ; +return ret;Oh my... This looks so-o hackish.> If anything, it has to be fixed on the level of regmap I2C APIs or
Quoted 6 lines
so.As such this does fix a real world issue. Providing some helpers for this on regmap level would probably be great. To add such an API I suspect there should first be existing users for it, and this would be one example.
Until there would be such an generic API, I'm not sure if there are many other alternatives than to check for invalid returns and defer the probe.
As Jonathan said, please try to elaborate better what the real word issue is, how it can be reproduced, etc.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 4 lines · Andy Shevchenko
As Jonathan said, please try to elaborate better what the real word issue is, how it can be reproduced, etc.
Thanks for mentioning, for some reason the message from Jonathan had been filtered out, found it now.
thanks,
Tomas