iio:adc mcp3422 initial config
Hello,
Looking in the mcp3422.c iio kernel driver I see a few issues with the initialization of the config word for the adc in mcp3422_probe().
1. It uses MCP3422_CHANNEL_VALUE(1). Why is channel 2 the default?
2. It tries to set MCP3422_CONT_SAMPLING, but if this first I2C transfer fails it will never be set again. The initial config is not stored in adc->config and adc->config is uninitialized! All subsequent writes will leave MCP3422_CONT_SAMPLING off.
3. The return value of mcp3422_update_config() is not checked. Not sure if it should though. I wouldn't want a single failure to disable the driver. It might even be that the adc is not available yet at linux boot time.
Number 2 is the most important one. We saw it fail because our I2C goes through an FPGA which was not loaded yet.
I can write a patch, but welcome some insights first.
Kind regards,
Maarten Brock
Hi Marteen,
2017-06-27 11:53 GMT+02:00 Maarten Brock <[email protected]>:
Quoted 6 lines
Hello,
Looking in the
mcp3422.ciio kernel driver I see a few issues with the initialization of the config word for the adc inmcp3422_probe().1. It uses
MCP3422_CHANNEL_VALUE(1). Why is channel 2 the default?
No particular reason here, it could be changed to channel 0 without problems.
Quoted 4 lines
2. It tries to set
MCP3422_CONT_SAMPLING, but if this first I2C transfer fails it will never be set again. The initial config is not stored inadc->configandadc->configis uninitialized! All subsequent writes will leaveMCP3422_CONT_SAMPLINGoff.
Unfortunately this is true. I had should use adc->config instead of config there.
Quoted 3 lines
3. The return value of
mcp3422_update_config()is not checked. Not sure if it should though. I wouldn't want a single failure to disable the driver. It might even be that the adc is not available yet at linux boot time.
And btw also the error condition should be checked.
Quoted 4 lines
Number 2 is the most important one. We saw it fail because our I2C goes through an FPGA which was not loaded yet.
I can write a patch, but welcome some insights first.
I'll fix these in minutes, thanks for spotting!
Quoted 4 lines
Kind regards,
Maarten Brock
Signature · 1 line
Profile: http://it.linkedin.com/in/compagnucciangelo