iio: adc: mcp320x: Fix scale of the MCP3301
PATCH v2 1/1 iio: adc: mcp320x: Fix scale of the MCP3301
mcp320x_read_raw() reports the scale as Vref / 2^resolution: it returns Vref in mV and chip_info->resolution as an IIO_VAL_FRACTIONAL_LOG2 pair, and the IIO core shifts right by the resolution.
The sign bit of the MCP3301 should not be counted toward resolution, so set it to 12.
Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/21700E.pdf
---
Notes:
Changes in v2:
- use a Datasheet: tag instead of Link: (Andy)
- add a trailing comma after .resolution (Andy)
- collect Reviewed-by (Arnav)
v1: https://lore.kernel.org/r/[email protected]
This is based on the datasheet (DS21700E) and the driver only. I do not have an MCP3301, so it is untested on hardware. Could someone with one measure a known input against in_voltage_raw * in_voltage_scale?
The scale reported to userspace for the MCP3301 doubles with this patch. I think that is right because the old value contradicts the datasheet (Section 5.3: 610 uV per LSB at 2.5 V, the driver gave 305 uV). I searched lore for mcp3301 and found no earlier discussion of the scale, and the commit that added the part does not say why 13 was chosen.
I did not add Cc: stable; please add it if you think it is warranted.
AI assistance: I used an AI assistant (Claude) to help read the datasheet and the driver and to draft this message. I checked the quoted datasheet lines and the code paths myself. Build-tested (W=1, C=1); not tested on hardware.
drivers/iio/adc/mcp320x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/mcp320x.c +1 -1
@@ -341,7 +341,7 @@ static const struct mcp320x_chip_info mcp320x_chip_infos[] = { [mcp3301] = { .channels = mcp3201_channels, .num_channels = ARRAY_SIZE(mcp3201_channels), - .resolution =13 + .resolution = 12, }, [mcp3550_50] = { .channels = mcp3201_channels,
base-commit: fba506008a5b548ad2708bc2765a039cb00a47ab
Signature · 1 line
2.47.3