From: Jonathan Cameron <jic23@kernel.org>
To: Piyush Patle <piyushpatle228@gmail.com>
Cc: ak@it-klinger.de, dlechner@baylibre.com, nuno.sa@analog.com,
andy@kernel.org, robh@kernel.org, krzk+dt@kernel.org,
conor+dt@kernel.org, linux-iio@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] iio: adc: hx711: add support for HX710B
Date: Tue, 21 Apr 2026 16:17:20 +0100 [thread overview]
Message-ID: <20260421161720.43dd97a3@jic23-huawei> (raw)
In-Reply-To: <20260419174654.683692-3-piyushpatle228@gmail.com>
On Sun, 19 Apr 2026 23:16:40 +0530
Piyush Patle <piyushpatle228@gmail.com> wrote:
> The HX711 uses trailing SCK pulses after each 24-bit conversion to
> select the channel and gain for the next measurement: 1 pulse gives
> channel A at gain 128, 2 pulses give channel B at gain 32, and 3 pulses
> give channel A at gain 64.
>
> The HX710B works differently: gain is fixed at 128 and the trailing
> pulses select only the channel. One trailing pulse selects the
> differential input (channel 0, 10 SPS) and two trailing pulses select
> the DVDD-AVDD supply monitor (channel 1, 40 SPS).
>
> Refactor the driver around a per-chip hx711_chip_info structure so both
> variants can share the same core. Each chip provides its own
> iio_chan_spec array and iio_info pointer. The HX710B stores per-channel
> trailing pulse counts in chan->address (1 for channel 0, 2 for
> channel 1) instead of a separate array. A bool fixed_gain flag and
> fixed_gain_val field in hx711_chip_info distinguish the fixed-gain path
> from the HX711's user-selectable gain path without conflating unrelated
> properties. The HX710B differential input channel is described with
> .differential=1 and .channel2=1 as required by the IIO ABI.
>
> Signed-off-by: Piyush Patle <piyushpatle228@gmail.com>
I'm slowly incorporating looking at the feedback that the sashiko LLM based
code review is providing. In amongst some stuff I'm fairly sure was
garbage it did raise some stuff that needs a closer look. See inline...
> @@ -246,27 +275,50 @@ static int hx711_set_gain_for_channel(struct hx711_data *hx711_data, int chan)
> return 0;
> }
>
> -static int hx711_reset_read(struct hx711_data *hx711_data, int chan)
> +/* Select HX710B channel for the next conversion. */
> +static int hx710b_set_channel(struct hx711_data *hx711_data,
> + const struct iio_chan_spec *chan)
> {
> int ret;
> - int val;
>
> - /*
> - * hx711_reset() must be called from here
> - * because it could be calling hx711_read() by itself
> - */
> + if (hx711_data->channel_set == chan->channel)
> + return 0;
> +
> + hx711_data->channel_set = chan->channel;
Sashiko raises what sound like a plausible issue here. If the read
that follows fails is the current channel updated? I.e. should we
set this or not?
https://sashiko.dev/#/patchset/20260419174654.683692-1-piyushpatle228%40gmail.com
(be careful with these AI reviews. Some of the other things it says are - I think
not true!)
> +
> + ret = hx711_read(hx711_data, chan->address);
> + if (ret < 0)
> + return ret;
> +
> + return hx711_wait_for_ready(hx711_data);
> +}
> static const struct iio_chan_spec hx711_chan_spec[] = {
> {
> .type = IIO_VOLTAGE,
> @@ -455,10 +516,69 @@ 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.
This triggered a sashiko question...
https://sashiko.dev/#/patchset/20260419174654.683692-1-piyushpatle228%40gmail.com
Specifically if the fixed scale is correct for the supply monitor or not.
It seems unlikely we'd want a large gain on a supply monitor.
> + * .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,
> + .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),
> +};
prev parent reply other threads:[~2026-04-21 15:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-19 17:46 [PATCH v2 0/2] iio: adc: hx711: add HX710B support Piyush Patle
2026-04-19 17:46 ` [PATCH v2 1/2] dt-bindings: iio: adc: avia-hx711: add avia,hx710b compatible Piyush Patle
2026-04-21 8:23 ` Krzysztof Kozlowski
2026-04-19 17:46 ` [PATCH v2 2/2] iio: adc: hx711: add support for HX710B Piyush Patle
2026-04-20 9:03 ` Andy Shevchenko
2026-04-21 15:17 ` Jonathan Cameron [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260421161720.43dd97a3@jic23-huawei \
--to=jic23@kernel.org \
--cc=ak@it-klinger.de \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=piyushpatle228@gmail.com \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox