Re: [PATCH v3 3/3] iio: adc: hx711: add support for HX710B

Jonathan Cameron
2026-04-24T12:19:54Z

On Wed, 22 Apr 2026 23:29:10 +0530
Piyush Patle <piyushpatle228@gmail.com> wrote:

> Add support for the AVIA HX710B ADC, which shares the HX711 GPIO
> interface but has a fixed gain of 128 and uses trailing PD_SCK pulses
> to select between the differential input and the DVDD-AVDD supply
> monitor.
>
> Model the HX710B with its own channel specification and iio_info.
> Store the HX710B trailing pulse counts in chan->address and add
> fixed-gain handling so the HX711 selectable-gain path remains
> separate from the HX710B fixed-gain path.
>
> The HX710B datasheet documents a single fixed PGA gain of 128 and
> does not provide configurable gain selection like the HX711.
>
> Order hx711_chip_info as pointers first, then unsigned int fields, then
> bool. pahole then reports no internal holes in the structure; the
> remaining padding is tail padding from 8-byte alignment.
>
> Signed-off-by: Piyush Patle <piyushpatle228@gmail.com>
> ---
> Changes in v3:
> - Add HX710B support on top of the separate hx711_chip_info refactor.
> - Update channel_set only after hx711_read() and hx711_wait_for_ready()
> both succeed.
> - Keep a single HX710B fixed-gain scale based on the datasheet's fixed
> PGA gain of 128; do not apply the HX711 channel-B gain of 32 to the
> HX710B supply monitor path.

Just to confirm - you verified this? It does seem very odd as that
might well take a large value.

> diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c
> index a444a2872257..d7050bec53b4 100644
> --- a/drivers/iio/adc/hx711.c
> +++ b/drivers/iio/adc/hx711.c

> +static const struct iio_info hx710b_iio_info = {
> + .read_raw = hx711_read_raw,
> +};
> +
> static const struct iio_chan_spec hx711_chan_spec[] = {
> {
> .type = IIO_VOLTAGE,
> @@ -474,6 +522,48 @@ static const struct iio_chan_spec hx711_chan_spec[] = {
> IIO_CHAN_SOFT_TIMESTAMP(2),
> };
>
> +/*
> + * HX710B channels.
> + * Channel 0: differential input (IN+ vs IN-), 10 SPS, 1 trailing pulse.
> + * Channel 1: DVDD-AVDD supply monitor, 40 SPS, 2 trailing pulses.
> + * .address holds the trailing pulse count used by hx710b_set_channel().
> + */
> +static const struct iio_chan_spec hx710b_chan_spec[] = {
> + {
> + .type = IIO_VOLTAGE,
> + .differential = 1,
> + .channel = 0,
> + .channel2 = 1,
> + .indexed = 1,
> + .address = 1,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> + BIT(IIO_CHAN_INFO_SCALE),
> + .scan_index = 0,
> + .scan_type = {
> + .sign = 'u',
> + .realbits = 24,
> + .storagebits = 32,
> + .endianness = IIO_CPU,
> + },
> + },
> + {
> + .type = IIO_VOLTAGE,
> + .channel = 1,
Sashiko is winning today. See it's comment on the indexing wich is
spot on.

https://sashiko.dev/#/patchset/20260422175910.1258579-1-piyushpatle228%40gmail.com

This should be channel = 2 or given it's actually a differential measurement, maybe
invent channels 2 and 3 so you can represent it as that. If useful label
can be used to provide info on this magic channel to userspace.

> + .indexed = 1,
> + .address = 2,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> + BIT(IIO_CHAN_INFO_SCALE),
> + .scan_index = 1,
> + .scan_type = {
> + .sign = 'u',
> + .realbits = 24,
> + .storagebits = 32,
> + .endianness = IIO_CPU,
> + },
> + },
> + IIO_CHAN_SOFT_TIMESTAMP(2),
> +};

...

> +
> static int hx711_probe(struct platform_device *pdev)
> {
> struct device *dev = &pdev->dev;
> @@ -540,12 +639,16 @@ static int hx711_probe(struct platform_device *pdev)
> /* we need 10^-9 mV */
> ret *= 100;
>
> - for (i = 0; i < HX711_GAIN_MAX; i++)
> - hx711_gain_to_scale[i].scale =
> - ret / hx711_gain_to_scale[i].gain / 1678;
> + if (chip_info->fixed_gain) {
> + hx711_data->scale = ret / chip_info->fixed_gain_val / 1678;
> + } else {
> + for (i = 0; i < HX711_GAIN_MAX; i++)
> + hx711_gain_to_scale[i].scale =
> + ret / hx711_gain_to_scale[i].gain / 1678;

Just to point it out, this is the update of the global variable I mentioned
Sashiko spotting as broken in my reply to previous patch.

>